Skip to content

Commit

Permalink
Refactor code
Browse files Browse the repository at this point in the history
  • Loading branch information
yoyo930021 committed Aug 14, 2020
1 parent caa59c0 commit 9043eda
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions server/src/modes/script/componentInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -412,12 +412,16 @@ export function getClassDecoratorArgumentType(
defaultExportNode: ts.Type,
checker: ts.TypeChecker
) {
const decorators = defaultExportNode.symbol.declarations[0].decorators;
const decorators = defaultExportNode.symbol.valueDeclaration.decorators;
if (!decorators || decorators.length === 0) {
return undefined;
}

const decoratorArguments = (decorators[0].expression as ts.CallExpression).arguments;
if (!tsModule.isCallExpression(decorators?.[0].expression)) {
return undefined;
}

const decoratorArguments = decorators?.[0].expression?.arguments;
if (!decoratorArguments || decoratorArguments.length === 0) {
return undefined;
}
Expand Down Expand Up @@ -450,11 +454,7 @@ function getPropertyDecoratorNames(property: ts.Symbol, checkSyntaxKind: ts.Synt
return [];
}

if (property.declarations.length === 0) {
return [];
}

const decorators = property.declarations[0].decorators;
const decorators = property?.valueDeclaration?.decorators;
if (decorators === undefined) {
return [];
}
Expand All @@ -474,12 +474,9 @@ export function buildDocumentation(tsModule: T_TypeScript, s: ts.Symbol, checker
documentation += '\n';

if (s.valueDeclaration) {
if (s.valueDeclaration.kind === tsModule.SyntaxKind.PropertyAssignment) {
documentation += `\`\`\`js\n${formatJSLikeDocumentation(s.valueDeclaration.getText())}\n\`\`\`\n`;
} else {
documentation += `\`\`\`js\n${formatJSLikeDocumentation(s.valueDeclaration.getText())}\n\`\`\`\n`;
}
documentation += `\`\`\`js\n${formatJSLikeDocumentation(s.valueDeclaration.getText())}\n\`\`\`\n`;
}

return documentation;
}

Expand Down

0 comments on commit 9043eda

Please sign in to comment.