Skip to content

Commit

Permalink
Add support �analyzing vue-class-component and vue-property-decorator
Browse files Browse the repository at this point in the history
  • Loading branch information
yoyo930021 committed Jun 7, 2019
1 parent 753c27b commit d954ea9
Show file tree
Hide file tree
Showing 3 changed files with 300 additions and 104 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ docs/.vuepress/dist

.nyc_output
coverage.lcov
server/tsconfig.tsbuildinfo
41 changes: 32 additions & 9 deletions server/src/modes/script/childComponents.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as ts from 'typescript';
import { getLastChild, buildDocumentation, getObjectLiteralExprFromExportExpr } from './componentInfo';
import { getLastChild, buildDocumentation, getNodeFromExportNode } from './componentInfo';
import { T_TypeScript } from '../../services/dependencyService';

interface InternalChildComponent {
Expand All @@ -10,7 +10,7 @@ interface InternalChildComponent {
start: number;
end: number;
};
defaultExportExpr?: ts.Node;
defaultExportNode?: ts.Node;
}

export function getChildComponents(
Expand All @@ -19,7 +19,15 @@ export function getChildComponents(
checker: ts.TypeChecker,
tagCasing = 'kebab'
): InternalChildComponent[] | undefined {
const componentsSymbol = checker.getPropertyOfType(defaultExportType, 'components');
let type = defaultExportType;
if (defaultExportType.isClass()) {
// get decorator argument type when class
type = checker.getTypeAtLocation(
(defaultExportType.symbol.declarations[0].decorators![0].expression as ts.CallExpression).arguments[0]
);
}

const componentsSymbol = checker.getPropertyOfType(type, 'components');
if (!componentsSymbol || !componentsSymbol.valueDeclaration) {
return undefined;
}
Expand Down Expand Up @@ -56,22 +64,37 @@ export function getChildComponents(
}

if (objectLiteralSymbol.flags & tsModule.SymbolFlags.Alias) {
const definitionObjectLiteralSymbol = checker.getAliasedSymbol(objectLiteralSymbol);
if (definitionObjectLiteralSymbol.valueDeclaration) {
const defaultExportExpr = getLastChild(definitionObjectLiteralSymbol.valueDeclaration);
const definitionSymbol = checker.getAliasedSymbol(objectLiteralSymbol);
// definitionObjectLiteralSymbol.
if (tsModule.isClassDeclaration(
definitionSymbol.valueDeclaration
)) {
const defaultExportNode = definitionSymbol.valueDeclaration;
result.push({
name: componentName,
documentation: buildDocumentation(tsModule, definitionSymbol, checker),
definition: {
path: definitionSymbol.valueDeclaration.getSourceFile().fileName,
start: defaultExportNode.getStart(undefined, true),
end: defaultExportNode.getEnd()
},
defaultExportNode: getNodeFromExportNode(tsModule, defaultExportNode)
});
} else if (definitionSymbol.valueDeclaration) {
const defaultExportExpr = getLastChild(definitionSymbol.valueDeclaration);
if (!defaultExportExpr) {
return;
}

result.push({
name: componentName,
documentation: buildDocumentation(tsModule, definitionObjectLiteralSymbol, checker),
documentation: buildDocumentation(tsModule, definitionSymbol, checker),
definition: {
path: definitionObjectLiteralSymbol.valueDeclaration.getSourceFile().fileName,
path: definitionSymbol.valueDeclaration.getSourceFile().fileName,
start: defaultExportExpr.getStart(undefined, true),
end: defaultExportExpr.getEnd()
},
defaultExportExpr: getObjectLiteralExprFromExportExpr(tsModule, defaultExportExpr)
defaultExportNode: getNodeFromExportNode(tsModule, defaultExportExpr)
});
}
}
Expand Down
Loading

0 comments on commit d954ea9

Please sign in to comment.