Skip to content

Commit

Permalink
chore: move declaration modifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
atanasster committed Jul 15, 2021
1 parent 7ca0098 commit a59b3d3
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 20 deletions.
23 changes: 3 additions & 20 deletions misc/structured-types/src/SymbolParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import {
ISymbolParser,
getInitializer,
typeKind,
declarationModifiers,
} from './ts-utils';
import {
cleanJSDocText,
Expand Down Expand Up @@ -510,26 +511,8 @@ export class SymbolParser implements ISymbolParser {

const declaration = symbolDeclaration;

if ((declaration as ts.ParameterDeclaration).questionToken) {
prop.optional = true;
}
if (declaration?.modifiers) {
for (const m of declaration.modifiers) {
if (m.kind === ts.SyntaxKind.PrivateKeyword) {
prop.visibility = 'private';
} else if (m.kind === ts.SyntaxKind.ProtectedKeyword) {
prop.visibility = 'protected';
} else if (m.kind === ts.SyntaxKind.PublicKeyword) {
prop.visibility = 'public';
} else if (m.kind === ts.SyntaxKind.StaticKeyword) {
prop.static = true;
} else if (m.kind === ts.SyntaxKind.ReadonlyKeyword) {
prop.readonly = true;
} else if (m.kind === ts.SyntaxKind.AbstractKeyword) {
prop.abstract = true;
}
}
}
declarationModifiers(prop, declaration);

if (declaration) {
prop.displayName = getDeclarationName(declaration);
}
Expand Down
29 changes: 29 additions & 0 deletions misc/structured-types/src/ts-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,35 @@ export const getInitializer = (
type NodeCallback = (m: ts.PropertyDeclaration) => boolean;
type NodeFind = (callback: NodeCallback) => ts.PropertyDeclaration | undefined;

export const declarationModifiers = (
prop: PropType,
declaration?: ts.Declaration,
): PropType => {
if (declaration) {
if ((declaration as ts.ParameterDeclaration).questionToken) {
prop.optional = true;
}
if (declaration.modifiers) {
for (const m of declaration.modifiers) {
if (m.kind === ts.SyntaxKind.PrivateKeyword) {
prop.visibility = 'private';
} else if (m.kind === ts.SyntaxKind.ProtectedKeyword) {
prop.visibility = 'protected';
} else if (m.kind === ts.SyntaxKind.PublicKeyword) {
prop.visibility = 'public';
} else if (m.kind === ts.SyntaxKind.StaticKeyword) {
prop.static = true;
} else if (m.kind === ts.SyntaxKind.ReadonlyKeyword) {
prop.readonly = true;
} else if (m.kind === ts.SyntaxKind.AbstractKeyword) {
prop.abstract = true;
}
}
}
}
return prop;
};

const findFileNode = (node: ts.Node): ts.SourceFile | undefined => {
if (ts.isSourceFile(node)) {
return node;
Expand Down

0 comments on commit a59b3d3

Please sign in to comment.