mirror of
https://github.com/sahadev/vue-component-creater-ui.git
synced 2025-06-07 21:54:05 +08:00
fix: 对Vue文件编译增强鲁棒性
This commit is contained in:
parent
66731861d7
commit
1561d0a811
@ -95,12 +95,22 @@ function convert2Map(jsonObj) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function findProperty(properties, findWhoStructure) {
|
||||||
|
return properties.find(item=>{
|
||||||
|
if(item.key.name === findWhoStructure){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// 对JS代码进行编译
|
// 对JS代码进行编译
|
||||||
function compileJsCode(code, onEncounterDuplicateDeclared = () => { }) {
|
function compileJsCode(code, onEncounterDuplicateDeclared = () => { }) {
|
||||||
const ast = espree.parse(code, { ecmaVersion: 6, sourceType: "module" });
|
const ast = espree.parse(code, { ecmaVersion: 6, sourceType: "module" });
|
||||||
// 提取data中返回的对象结构, 如果文件引入了其它文件, 则body[0]为import语句。
|
// 提取data中返回的对象结构, 如果文件引入了其它文件, 则body[0]为import语句。
|
||||||
if (ast.body[0].declaration) {
|
if (ast.body[0].declaration) {
|
||||||
const dataAst = ast.body[0].declaration.properties[0].value.body.body[0].argument;
|
const properties = ast.body[0].declaration.properties;
|
||||||
|
const dataProperty = findProperty(properties, 'data');
|
||||||
|
const dataAst = dataProperty.value.body.body[0].argument;
|
||||||
const newCode = escodegen.generate(dataAst);
|
const newCode = escodegen.generate(dataAst);
|
||||||
|
|
||||||
// 这里编译的组件内部应当只包含data和method,不应该包含其它属性
|
// 这里编译的组件内部应当只包含data和method,不应该包含其它属性
|
||||||
|
Loading…
x
Reference in New Issue
Block a user