Skip to content

Commit

Permalink
优化vue模板类型提取
Browse files Browse the repository at this point in the history
  • Loading branch information
chenglie33 committed Jul 12, 2020
1 parent 0d07ba9 commit 9114408
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
7 changes: 6 additions & 1 deletion kiwi-cli/src/extract/findChineseText.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,6 @@ function findTextInHtml(code) {
*/
function findTextInVue (code: string) {
const vueObejct = compilerVue.compile(code.toString(),{outputSourceRange: true});
debugger
let TextaArr = findVueText(vueObejct.ast)
const sfc = compilerVue.parseComponent(code.toString());
let vueTemp = findTextInVueTs(sfc.script.content, 'fileName', sfc.script.start)
Expand Down Expand Up @@ -251,6 +250,12 @@ function findVueText (ast) {
if (varInStr) itemText.match(DOUBLE_BYTE_REGEX)&&arr.push({text:' ' + itemText,range:{start:ast.start+2,end:ast.end-2},isString: true})
else itemText.match(DOUBLE_BYTE_REGEX)&&arr.push({text:itemText,range:{start:ast.start,end:ast.end},isString: false})
})
} else {
ast.tokens && ast.tokens.forEach(element => {
if (typeof(element) === 'string' && element.match(DOUBLE_BYTE_REGEX)) {
arr.push({text:element,range:{start:ast.start + ast.text.indexOf(element),end:ast.start + ast.text.indexOf(element)+element.length},isString: false})
}
});
}
} else if (!ast.expression&&ast.text) {
ast.text.match(DOUBLE_BYTE_REGEX)&&arr.push({text:ast.text,range:{start:ast.start,end:ast.end},isString: false})
Expand Down
5 changes: 2 additions & 3 deletions kiwi-demo/src/vuePage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
<span>vue中文文案测试</span>
<span attrs='中间'>{{`中文${pageName}`}}</span>
<span @click='meth("按钮")'>按钮中文</span>
<span @click='meth("按钮")'>{{`可以的`}}</span>
`可以的`
<span @click='meth("按钮")'>{{`可以的`}}</span>
<span @click='meth("按钮")'>{{`可以${pageName}的`}}</span>
<span @click='meth("按钮")'>测试{{this.pageName}}翻译</span>
</div>
</template>
<script>
Expand Down

0 comments on commit 9114408

Please sign in to comment.