Преглед изворни кода

decode html entities in text nodes

Evan You пре 10 година
родитељ
комит
e918476447
5 измењених фајлова са 28 додато и 19 уклоњено
  1. 14 17
      build/build.js
  2. 1 2
      package.json
  3. 6 0
      src/compiler/entity-decoder.js
  4. 2 0
      src/compiler/html-parser.js
  5. 5 0
      webpack.config.js

+ 14 - 17
build/build.js

@@ -3,9 +3,8 @@ var zlib = require('zlib')
 var rollup = require('rollup')
 var uglify = require('uglify-js')
 var babel = require('rollup-plugin-babel')
-var node = require('rollup-plugin-node-resolve')
-var commonjs = require('rollup-plugin-commonjs')
 var replace = require('rollup-plugin-replace')
+var alias = require('rollup-plugin-alias')
 var version = process.env.VERSION || require('../package.json').version
 
 var banner =
@@ -21,16 +20,6 @@ var main = fs
   .replace(/Vue\.version = '[\d\.]+'/, "Vue.version = '" + version + "'")
 fs.writeFileSync('src/index.js', main)
 
-var plugins = [
-  node(),
-  commonjs({
-    include: 'node_modules/**'
-  }),
-  babel({
-    exclude: 'node_modules/**'
-  })
-]
-
 // CommonJS build.
 // this is used as the "main" field in package.json
 // and used by bundlers like Webpack and Browserify.
@@ -38,7 +27,7 @@ var plugins = [
 // used with vue-loader which pre-compiles the template.
 rollup.rollup({
   entry: 'src/index.js',
-  plugins: plugins
+  plugins: [babel()]
 })
 .then(function (bundle) {
   return write('dist/vue.common.js', bundle.generate({
@@ -51,10 +40,14 @@ rollup.rollup({
   return rollup.rollup({
     entry: 'src/with-compiler.js',
     plugins: [
+      alias({
+        entities: './entity-decoder'
+      }),
       replace({
         'process.env.NODE_ENV': "'development'"
-      })
-    ].concat(plugins)
+      }),
+      babel()
+    ]
   })
   .then(function (bundle) {
     return write('dist/vue.js', bundle.generate({
@@ -69,10 +62,14 @@ rollup.rollup({
   return rollup.rollup({
     entry: 'src/with-compiler.js',
     plugins: [
+      alias({
+        entities: './entity-decoder'
+      }),
       replace({
         'process.env.NODE_ENV': "'production'"
-      })
-    ].concat(plugins)
+      }),
+      babel()
+    ]
   })
   .then(function (bundle) {
     var code = bundle.generate({

+ 1 - 2
package.json

@@ -28,9 +28,8 @@
     "babel-preset-es2015-rollup": "^1.1.1",
     "babel-preset-stage-2": "^6.0.0",
     "rollup": "^0.25.8",
+    "rollup-plugin-alias": "^1.0.2",
     "rollup-plugin-babel": "^2.4.0",
-    "rollup-plugin-commonjs": "^2.2.1",
-    "rollup-plugin-node-resolve": "^1.5.0",
     "rollup-plugin-replace": "^1.1.0",
     "uglify-js": "^2.6.2",
     "webpack": "^1.12.14"

+ 6 - 0
src/compiler/entity-decoder.js

@@ -0,0 +1,6 @@
+const decoder = document.createElement('div')
+
+export function decodeHTML (html) {
+  decoder.innerHTML = html
+  return decoder.textContent
+}

+ 2 - 0
src/compiler/html-parser.js

@@ -1,4 +1,5 @@
 import config from '../config'
+import { decodeHTML } from 'entities'
 
 /**
  * Convert HTML string to AST
@@ -37,6 +38,7 @@ export function parse (html) {
       currentParent = stack[stack.length - 1]
     },
     chars (text) {
+      text = decodeHTML(text)
       text = currentParent.tag === 'pre'
         ? text
         : text.trim()

+ 5 - 0
webpack.config.js

@@ -8,6 +8,11 @@ module.exports = {
     library: 'Vue',
     libraryTarget: 'umd'
   },
+  resolve: {
+    alias: {
+      entities: './entity-decoder'
+    }
+  },
   module: {
     loaders: [
       { test: /\.js/, loader: 'babel', exclude: /node_modules/ }