From 1561d0a811c95bef0f8e93a2c7e456a611c98261 Mon Sep 17 00:00:00 2001 From: shangbin Date: Thu, 2 Dec 2021 16:45:58 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=AF=B9Vue=E6=96=87=E4=BB=B6=E7=BC=96?= =?UTF-8?q?=E8=AF=91=E5=A2=9E=E5=BC=BA=E9=B2=81=E6=A3=92=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/script/compileComponent.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/script/compileComponent.js b/src/script/compileComponent.js index 58e2c2b..5894c70 100644 --- a/src/script/compileComponent.js +++ b/src/script/compileComponent.js @@ -95,12 +95,22 @@ function convert2Map(jsonObj) { } } +function findProperty(properties, findWhoStructure) { + return properties.find(item=>{ + if(item.key.name === findWhoStructure){ + return true; + } + }) +} + // 对JS代码进行编译 function compileJsCode(code, onEncounterDuplicateDeclared = () => { }) { const ast = espree.parse(code, { ecmaVersion: 6, sourceType: "module" }); // 提取data中返回的对象结构, 如果文件引入了其它文件, 则body[0]为import语句。 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); // 这里编译的组件内部应当只包含data和method,不应该包含其它属性