Skip to content

Commit 0d1cd59

Browse files
committed
fix: enhance parsing error detection
1 parent acdde64 commit 0d1cd59

File tree

2 files changed

+19
-23
lines changed

2 files changed

+19
-23
lines changed

src/utils/getVueConfigObject.js

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,24 @@ import evalInContext from "./evalInContext";
22
import requireAtRuntime from "./requireAtRuntime";
33

44
export default function getVueConfigObject(compiledCode, listVars, requires) {
5-
const exampleComponentCode = `
6-
let __component__ = {}
7-
8-
// When we do new Vue({name: 'MyComponent'}) the comfig object
9-
// is set to __component__
10-
function Vue(params){ __component__ = params; }
11-
eval(${JSON.stringify(
12-
`${
13-
// run script for SFC and full scripts
14-
// and set config object in __component__
15-
// if the structure is vsg mode, define local variables
16-
// to set them up in the next step
17-
compiledCode
18-
};__component__.data = __component__.data || function() {return {${
19-
// add local vars in data
20-
// this is done through an object like {varName: varName}
21-
// since each varName is defined in compiledCode, it can be used to init
22-
// the data object here
23-
listVars.map(varName => `${varName}: ${varName}`).join(",")
24-
}};};`
25-
)});
26-
return __component__;`;
5+
const exampleComponentCode = `let __component__ = {};${
6+
// run script for SFC and full scripts
7+
// and set config object in __component__
8+
// if the structure is vsg mode, define local variables
9+
// to set them up in the next step
10+
compiledCode
11+
};__component__.data = __component__.data || function() {return {${
12+
// add local vars in data
13+
// this is done through an object like {varName: varName}
14+
// since each varName is defined in compiledCode, it can be used to init
15+
// the data object here
16+
listVars.map(varName => `${varName}: ${varName}`).join(",")
17+
}}};${
18+
// When we do new Vue({name: 'MyComponent'}) the comfig object
19+
// is set to __component__
20+
`function Vue(params){ __component__ = params; }
21+
return __component__;`
22+
}`;
2723
return evalInContext(exampleComponentCode, filepath =>
2824
requireAtRuntime(requires, filepath)
2925
);

src/utils/normalizeSfcComponent.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const buildStyles = function(styles) {
2222
};
2323

2424
function getSingleFileComponentParts(code) {
25-
const parts = vueCompiler.parseComponent(code);
25+
const parts = vueCompiler.parseComponent(code, { pad: "line" });
2626
if (parts.script)
2727
parts.script.content = parts.script.content.replace(
2828
/\/\*[\s\S]*?\*\/|([^:]|^)\/\/.*$/gm,

0 commit comments

Comments
 (0)