Skip to content
This repository was archived by the owner on Jan 18, 2022. It is now read-only.

Commit 21b28ee

Browse files
committed
Fix bug in template parsing
Fix #25
1 parent beb75a4 commit 21b28ee

File tree

5 files changed

+50
-2
lines changed

5 files changed

+50
-2
lines changed

example/README.md

+10
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,18 @@ Example bundling an UMD package with one `vue` file and exporting stylus and CSS
55

66
## Building
77

8+
### With build script
9+
810
```
911
cd example
1012
node build.js
1113
ls dist
1214
```
15+
16+
### With rollup cli
17+
18+
```
19+
cd example
20+
npm i -g rollup
21+
rollup -c --input Hello.vue --output dist/bundle.js
22+
```

example/rollup.config.js

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Simple rollup config file.
2+
3+
const vue = require('../dist/rollup-plugin-vue.common.js');
4+
5+
export default {
6+
plugins: [ vue() ],
7+
};

src/vueTransform.js

+9-2
Original file line numberDiff line numberDiff line change
@@ -99,14 +99,21 @@ function injectTemplate(script, template, lang) {
9999
* @param {*} options
100100
*/
101101
function processTemplate(node, filePath, content, options) {
102-
const template = deIndent(parse5.serialize(node.content));
103-
const warnings = validateTemplate(node.content, content);
102+
node = node.content;
103+
const warnings = validateTemplate(node, content);
104104
if (warnings) {
105105
const relativePath = relative(process.cwd(), filePath);
106106
warnings.forEach((msg) => {
107107
console.warn(`\n Warning in ${relativePath}:\n ${msg}`);
108108
});
109109
}
110+
111+
/* eslint-disable no-underscore-dangle */
112+
const start = node.childNodes[0].__location.startOffset;
113+
const end = node.childNodes[node.childNodes.length - 1].__location.endOffset;
114+
const template = deIndent(content.slice(start, end));
115+
/* eslint-enable no-underscore-dangle */
116+
110117
return htmlMinifier.minify(template, options.htmlMinifier);
111118
}
112119

test/expects/expression.js

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
var expression = { template: "<ol class=options v-show=\"foo && bar === 1\"></ol>",
2+
data() {
3+
return {
4+
foo: false,
5+
bar: 2,
6+
};
7+
},
8+
};
9+
10+
export default expression;

test/fixtures/expression.vue

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<template>
2+
<ol class="options" v-show="foo && bar === 1"></ol>
3+
</template>
4+
5+
<script>
6+
export default {
7+
data() {
8+
return {
9+
foo: false,
10+
bar: 2,
11+
};
12+
},
13+
};
14+
</script>

0 commit comments

Comments
 (0)