Skip to content

Commit

Permalink
feat: Implement JSDocReadonlyTag and others
Browse files Browse the repository at this point in the history
* Initial commit adding new tags.

* Output of `yarn code-generate`

* Remove `.only` on test.
  • Loading branch information
dsherret committed Aug 9, 2020
2 parents 825bf8c + d67b466 commit abbf208
Show file tree
Hide file tree
Showing 10 changed files with 133 additions and 97 deletions.
145 changes: 58 additions & 87 deletions packages/ts-morph/src/compiler/ast/common/Node.ts

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions packages/ts-morph/src/compiler/ast/doc/JSDocPrivateTag.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { ts } from "@ts-morph/common";
import { JSDocTag } from "./JSDocTag";

/**
* JS doc private tag node.
*/
export class JSDocPrivateTag extends JSDocTag<ts.JSDocPrivateTag> {
}
8 changes: 8 additions & 0 deletions packages/ts-morph/src/compiler/ast/doc/JSDocProtectedTag.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { ts } from "@ts-morph/common";
import { JSDocTag } from "./JSDocTag";

/**
* JS doc protected tag node.
*/
export class JSDocProtectedTag extends JSDocTag<ts.JSDocProtectedTag> {
}
8 changes: 8 additions & 0 deletions packages/ts-morph/src/compiler/ast/doc/JSDocPublicTag.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { ts } from "@ts-morph/common";
import { JSDocTag } from "./JSDocTag";

/**
* JS doc public tag node.
*/
export class JSDocPublicTag extends JSDocTag<ts.JSDocPublicTag> {
}
8 changes: 8 additions & 0 deletions packages/ts-morph/src/compiler/ast/doc/JSDocReadonlyTag.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { ts } from "@ts-morph/common";
import { JSDocTag } from "./JSDocTag";

/**
* JS doc readonly tag node.
*/
export class JSDocReadonlyTag extends JSDocTag<ts.JSDocReadonlyTag> {
}
4 changes: 4 additions & 0 deletions packages/ts-morph/src/compiler/ast/doc/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ export * from "./JSDocAugmentsTag";
export * from "./JSDocClassTag";
export * from "./JSDocFunctionType";
export * from "./JSDocParameterTag";
export * from "./JSDocPrivateTag";
export * from "./JSDocPropertyTag";
export * from "./JSDocProtectedTag";
export * from "./JSDocPublicTag";
export * from "./JSDocReadonlyTag";
export * from "./JSDocReturnTag";
export * from "./JSDocSignature";
export * from "./JSDocTag";
Expand Down
8 changes: 6 additions & 2 deletions packages/ts-morph/src/compiler/ast/kindToNodeMappings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,20 @@ export interface ImplementedKindToNodeMappings {
[SyntaxKind.JSDocAugmentsTag]: compiler.JSDocAugmentsTag;
[SyntaxKind.JSDocClassTag]: compiler.JSDocClassTag;
[SyntaxKind.JSDocFunctionType]: compiler.JSDocFunctionType;
[SyntaxKind.JSDocParameterTag]: compiler.JSDocParameterTag;
[SyntaxKind.JSDocPrivateTag]: compiler.JSDocPrivateTag;
[SyntaxKind.JSDocPropertyTag]: compiler.JSDocPropertyTag;
[SyntaxKind.JSDocProtectedTag]: compiler.JSDocProtectedTag;
[SyntaxKind.JSDocPublicTag]: compiler.JSDocPublicTag;
[SyntaxKind.JSDocReturnTag]: compiler.JSDocReturnTag;
[SyntaxKind.JSDocReadonlyTag]: compiler.JSDocReadonlyTag;
[SyntaxKind.JSDocSignature]: compiler.JSDocSignature;
[SyntaxKind.JSDocTag]: compiler.JSDocUnknownTag;
[SyntaxKind.JSDocTemplateTag]: compiler.JSDocTemplateTag;
[SyntaxKind.JSDocThisTag]: compiler.JSDocThisTag;
[SyntaxKind.JSDocTypeExpression]: compiler.JSDocTypeExpression;
[SyntaxKind.JSDocTypeTag]: compiler.JSDocTypeTag;
[SyntaxKind.JSDocTypedefTag]: compiler.JSDocTypedefTag;
[SyntaxKind.JSDocParameterTag]: compiler.JSDocParameterTag;
[SyntaxKind.JSDocPropertyTag]: compiler.JSDocPropertyTag;
[SyntaxKind.JsxAttribute]: compiler.JsxAttribute;
[SyntaxKind.JsxClosingElement]: compiler.JsxClosingElement;
[SyntaxKind.JsxClosingFragment]: compiler.JsxClosingFragment;
Expand Down
8 changes: 6 additions & 2 deletions packages/ts-morph/src/factories/kindToWrapperMappings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,20 @@ export const kindToWrapperMappings: { [key: number]: unknown; } = {
[SyntaxKind.JSDocAugmentsTag]: compiler.JSDocAugmentsTag,
[SyntaxKind.JSDocClassTag]: compiler.JSDocClassTag,
[SyntaxKind.JSDocFunctionType]: compiler.JSDocFunctionType,
[SyntaxKind.JSDocParameterTag]: compiler.JSDocParameterTag,
[SyntaxKind.JSDocPrivateTag]: compiler.JSDocPrivateTag,
[SyntaxKind.JSDocPropertyTag]: compiler.JSDocPropertyTag,
[SyntaxKind.JSDocProtectedTag]: compiler.JSDocProtectedTag,
[SyntaxKind.JSDocPublicTag]: compiler.JSDocPublicTag,
[SyntaxKind.JSDocReturnTag]: compiler.JSDocReturnTag,
[SyntaxKind.JSDocReadonlyTag]: compiler.JSDocReadonlyTag,
[SyntaxKind.JSDocSignature]: compiler.JSDocSignature,
[SyntaxKind.JSDocTag]: compiler.JSDocUnknownTag,
[SyntaxKind.JSDocTemplateTag]: compiler.JSDocTemplateTag,
[SyntaxKind.JSDocThisTag]: compiler.JSDocThisTag,
[SyntaxKind.JSDocTypeExpression]: compiler.JSDocTypeExpression,
[SyntaxKind.JSDocTypeTag]: compiler.JSDocTypeTag,
[SyntaxKind.JSDocTypedefTag]: compiler.JSDocTypedefTag,
[SyntaxKind.JSDocParameterTag]: compiler.JSDocParameterTag,
[SyntaxKind.JSDocPropertyTag]: compiler.JSDocPropertyTag,
[SyntaxKind.JsxAttribute]: compiler.JsxAttribute,
[SyntaxKind.JsxClosingElement]: compiler.JsxClosingElement,
[SyntaxKind.JsxClosingFragment]: compiler.JsxClosingFragment,
Expand Down
19 changes: 19 additions & 0 deletions packages/ts-morph/src/tests/issues/844tests.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { expect } from "chai";
import { Project } from "../../Project";

describe("tests for issue #844", () => {
it("should not throw an error getting structure", () => {
const project = new Project({ useInMemoryFileSystem: true });
const sourceFile = project.createSourceFile("src/file.ts", `class MyClass {
constructor(renderer: MYNAMESPACE.Renderer);
/**
* A flag
* @member {boolean}
* @readonly
*/
readonly isActive: boolean;
}`);

expect(() => sourceFile.getStructure()).to.not.throw();
});
});
14 changes: 8 additions & 6 deletions packages/ts-morph/wrapped-nodes.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ The disadvantage to a node not being wrapped is that it won't have helper method

## Exist

**Total:** 183
**Total:** 187

* [ArrayBindingPattern](src/compiler/ast/binding/ArrayBindingPattern.ts)
* :heavy_check_mark: elements
Expand Down Expand Up @@ -196,7 +196,11 @@ The disadvantage to a node not being wrapped is that it won't have helper method
* [JSDocClassTag](src/compiler/ast/doc/JSDocClassTag.ts)
* [JSDocFunctionType](src/compiler/ast/doc/JSDocFunctionType.ts)
* [JSDocParameterTag](src/compiler/ast/doc/JSDocParameterTag.ts)
* [JSDocPrivateTag](src/compiler/ast/doc/JSDocPrivateTag.ts)
* [JSDocPropertyTag](src/compiler/ast/doc/JSDocPropertyTag.ts)
* [JSDocProtectedTag](src/compiler/ast/doc/JSDocProtectedTag.ts)
* [JSDocPublicTag](src/compiler/ast/doc/JSDocPublicTag.ts)
* [JSDocReadonlyTag](src/compiler/ast/doc/JSDocReadonlyTag.ts)
* [JSDocReturnTag](src/compiler/ast/doc/JSDocReturnTag.ts)
* :heavy_check_mark: typeExpression
* [JSDocSignature](src/compiler/ast/doc/JSDocSignature.ts)
Expand Down Expand Up @@ -463,7 +467,7 @@ The disadvantage to a node not being wrapped is that it won't have helper method

## Not Exist

**Total:** 58
**Total:** 56

* Bundle
* CallChain
Expand All @@ -477,16 +481,13 @@ The disadvantage to a node not being wrapped is that it won't have helper method
* JSDocAuthorTag
* JSDocCallbackTag
* JSDocEnumTag
* JSDocImplementsTag
* JSDocNamepathType
* JSDocNamespaceDeclaration
* JSDocNonNullableType
* JSDocNullableType
* JSDocOptionalType
* JSDocPrivateTag
* JSDocPropertyLikeTag
* JSDocProtectedTag
* JSDocPublicTag
* JSDocReadonlyTag
* JSDocTypeLiteral
* JSDocUnknownType
* JSDocVariadicType
Expand All @@ -502,6 +503,7 @@ The disadvantage to a node not being wrapped is that it won't have helper method
* ModuleDeclaration
* NamespaceExportDeclaration
* NodeWithTypeArguments
* NonNullChain
* ObjectLiteralExpressionBase
* OptionalTypeNode
* PropertyAccessChain
Expand Down

0 comments on commit abbf208

Please sign in to comment.