Skip to content

修复TS识别as的情况 #22

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 17, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions lib/mp-compiler/parse-ts.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@ let ts
try {
ts = require('typescript')
} catch (e) {

// console.error(e)
}

function parseComponentsDeps (scriptContent) {
if (ts === null) {
throw new Error('Please run `npm install -S typescript` to install TypeScript.')
}
const sourceFile = ts.createSourceFile('test', scriptContent, ts.ScriptTarget.ESNext, /* setParentNodes */ true)
return delint(sourceFile)
}
Expand All @@ -21,7 +24,10 @@ function delint (sourceFile) {
if (node.expression.expression && node.expression.expression.escapedText === 'Component') {
const compArgs = node.expression.arguments
if (compArgs && compArgs.length === 1) {
const vueClassArg = compArgs[0]
let vueClassArg = compArgs[0]
if (vueClassArg.kind === ts.SyntaxKind.AsExpression) { // @Component({ components: ...,} as any)
vueClassArg = vueClassArg.expression
}
if (vueClassArg.properties) {
vueClassArg.properties.forEach((classProp) => {
// 处理components属性
Expand Down