diff --git a/deno/ts_morph.d.ts b/deno/ts_morph.d.ts index b122416b5..f80e063f8 100644 --- a/deno/ts_morph.d.ts +++ b/deno/ts_morph.d.ts @@ -3096,6 +3096,8 @@ export declare class Node { static readonly isInferKeyword: (node: Node | undefined) => node is Node>; /** Gets if the node is a InterfaceDeclaration. */ static readonly isInterfaceDeclaration: (node: Node | undefined) => node is InterfaceDeclaration; + /** Gets if the node is a JSDoc. */ + static readonly isJSDoc: (node: Node | undefined) => node is JSDoc; /** Gets if the node is a JSDocAllType. */ static readonly isJSDocAllType: (node: Node | undefined) => node is JSDocAllType; /** Gets if the node is a JSDocAugmentsTag. */ @@ -4151,11 +4153,6 @@ export declare class Node { * @param node - Node to check. */ static isIterationStatement(node: Node | undefined): node is IterationStatement; - /** - * Gets if the node is a JSDoc. - * @param node - Node to check. - */ - static isJSDoc(node: Node | undefined): node is JSDoc; /** * Gets if the node is a JSDocableNode. * @param node - Node to check. @@ -7353,7 +7350,7 @@ export declare class ImportDeclaration extends ImportDeclarationBase>; } -declare const ImportEqualsDeclarationBase: Constructor & Constructor & typeof Statement; +declare const ImportEqualsDeclarationBase: Constructor & Constructor & Constructor & Constructor & typeof Statement; export declare class ImportEqualsDeclaration extends ImportEqualsDeclarationBase { /** Gets if this import equals declaration is type only. */ diff --git a/deno/ts_morph.js b/deno/ts_morph.js index 3eee322c3..f515e0ab5 100644 --- a/deno/ts_morph.js +++ b/deno/ts_morph.js @@ -4247,6 +4247,7 @@ class Node { case SyntaxKind.ClassDeclaration: case SyntaxKind.EnumDeclaration: case SyntaxKind.FunctionDeclaration: + case SyntaxKind.ImportEqualsDeclaration: case SyntaxKind.InterfaceDeclaration: case SyntaxKind.ModuleDeclaration: case SyntaxKind.TypeAliasDeclaration: @@ -4261,6 +4262,7 @@ class Node { case SyntaxKind.ClassDeclaration: case SyntaxKind.EnumDeclaration: case SyntaxKind.FunctionDeclaration: + case SyntaxKind.ImportEqualsDeclaration: case SyntaxKind.InterfaceDeclaration: case SyntaxKind.ModuleDeclaration: case SyntaxKind.TypeAliasDeclaration: @@ -4484,9 +4486,6 @@ class Node { return false; } } - static isJSDoc(node) { - return (node === null || node === void 0 ? void 0 : node.getKind()) === SyntaxKind.JSDoc; - } static isJSDocable(node) { switch (node === null || node === void 0 ? void 0 : node.getKind()) { case SyntaxKind.ArrowFunction: @@ -4734,6 +4733,7 @@ class Node { case SyntaxKind.FunctionDeclaration: case SyntaxKind.FunctionExpression: case SyntaxKind.GetAccessor: + case SyntaxKind.ImportEqualsDeclaration: case SyntaxKind.IndexSignature: case SyntaxKind.InterfaceDeclaration: case SyntaxKind.MethodDeclaration: @@ -5523,6 +5523,7 @@ Node.isImportSpecifier = Node.is(SyntaxKind.ImportSpecifier); Node.isImportTypeAssertionContainer = Node.is(SyntaxKind.ImportTypeAssertionContainer); Node.isInferKeyword = Node.is(SyntaxKind.InferKeyword); Node.isInterfaceDeclaration = Node.is(SyntaxKind.InterfaceDeclaration); +Node.isJSDoc = Node.is(SyntaxKind.JSDoc); Node.isJSDocAllType = Node.is(SyntaxKind.JSDocAllType); Node.isJSDocAugmentsTag = Node.is(SyntaxKind.JSDocAugmentsTag); Node.isJSDocAuthorTag = Node.is(SyntaxKind.JSDocAuthorTag); @@ -12615,7 +12616,7 @@ function getErrorWhenNamespaceImportsExist() { return new errors.InvalidOperationError("Cannot add a named import to an import declaration that has a namespace import."); } -const createBase$r = (ctor) => JSDocableNode(NamedNode(ctor)); +const createBase$r = (ctor) => ExportableNode(ModifierableNode(JSDocableNode(NamedNode(ctor)))); const ImportEqualsDeclarationBase = createBase$r(Statement); class ImportEqualsDeclaration extends ImportEqualsDeclarationBase { isTypeOnly() { diff --git a/packages/ts-morph/lib/ts-morph.d.ts b/packages/ts-morph/lib/ts-morph.d.ts index e5bc1c08a..52bd921fc 100644 --- a/packages/ts-morph/lib/ts-morph.d.ts +++ b/packages/ts-morph/lib/ts-morph.d.ts @@ -3096,6 +3096,8 @@ export declare class Node { static readonly isInferKeyword: (node: Node | undefined) => node is Node>; /** Gets if the node is a InterfaceDeclaration. */ static readonly isInterfaceDeclaration: (node: Node | undefined) => node is InterfaceDeclaration; + /** Gets if the node is a JSDoc. */ + static readonly isJSDoc: (node: Node | undefined) => node is JSDoc; /** Gets if the node is a JSDocAllType. */ static readonly isJSDocAllType: (node: Node | undefined) => node is JSDocAllType; /** Gets if the node is a JSDocAugmentsTag. */ @@ -4151,11 +4153,6 @@ export declare class Node { * @param node - Node to check. */ static isIterationStatement(node: Node | undefined): node is IterationStatement; - /** - * Gets if the node is a JSDoc. - * @param node - Node to check. - */ - static isJSDoc(node: Node | undefined): node is JSDoc; /** * Gets if the node is a JSDocableNode. * @param node - Node to check. @@ -7353,7 +7350,7 @@ export declare class ImportDeclaration extends ImportDeclarationBase>; } -declare const ImportEqualsDeclarationBase: Constructor & Constructor & typeof Statement; +declare const ImportEqualsDeclarationBase: Constructor & Constructor & Constructor & Constructor & typeof Statement; export declare class ImportEqualsDeclaration extends ImportEqualsDeclarationBase { /** Gets if this import equals declaration is type only. */ diff --git a/packages/ts-morph/src/compiler/ast/common/Node.ts b/packages/ts-morph/src/compiler/ast/common/Node.ts index f4611334a..b8323437b 100644 --- a/packages/ts-morph/src/compiler/ast/common/Node.ts +++ b/packages/ts-morph/src/compiler/ast/common/Node.ts @@ -2591,6 +2591,7 @@ export class Node { case SyntaxKind.ClassDeclaration: case SyntaxKind.EnumDeclaration: case SyntaxKind.FunctionDeclaration: + case SyntaxKind.ImportEqualsDeclaration: case SyntaxKind.InterfaceDeclaration: case SyntaxKind.ModuleDeclaration: case SyntaxKind.TypeAliasDeclaration: @@ -2615,6 +2616,7 @@ export class Node { case SyntaxKind.ClassDeclaration: case SyntaxKind.EnumDeclaration: case SyntaxKind.FunctionDeclaration: + case SyntaxKind.ImportEqualsDeclaration: case SyntaxKind.InterfaceDeclaration: case SyntaxKind.ModuleDeclaration: case SyntaxKind.TypeAliasDeclaration: @@ -2987,13 +2989,8 @@ export class Node { } } - /** - * Gets if the node is a JSDoc. - * @param node - Node to check. - */ - static isJSDoc(node: compiler.Node | undefined): node is compiler.JSDoc { - return node?.getKind() === SyntaxKind.JSDoc; - } + /** Gets if the node is a JSDoc. */ + static readonly isJSDoc: (node: compiler.Node | undefined) => node is compiler.JSDoc = Node.is(SyntaxKind.JSDoc); /** * Gets if the node is a JSDocableNode. @@ -3440,6 +3437,7 @@ export class Node { case SyntaxKind.FunctionDeclaration: case SyntaxKind.FunctionExpression: case SyntaxKind.GetAccessor: + case SyntaxKind.ImportEqualsDeclaration: case SyntaxKind.IndexSignature: case SyntaxKind.InterfaceDeclaration: case SyntaxKind.MethodDeclaration: diff --git a/packages/ts-morph/src/compiler/ast/module/ImportEqualsDeclaration.ts b/packages/ts-morph/src/compiler/ast/module/ImportEqualsDeclaration.ts index c8386f439..14a5d31f3 100644 --- a/packages/ts-morph/src/compiler/ast/module/ImportEqualsDeclaration.ts +++ b/packages/ts-morph/src/compiler/ast/module/ImportEqualsDeclaration.ts @@ -1,12 +1,12 @@ import { errors, ts } from "@ts-morph/common"; import { insertIntoParentTextRange, removeChildren } from "../../../manipulation"; import { ModuleReference } from "../aliases"; -import { JSDocableNode, NamedNode } from "../base"; +import { ExportableNode, JSDocableNode, ModifierableNode, NamedNode } from "../base"; import { Node } from "../common"; import { Statement } from "../statement"; import { SourceFile } from "./SourceFile"; -const createBase = (ctor: T) => JSDocableNode(NamedNode(ctor)); +const createBase = (ctor: T) => ExportableNode(ModifierableNode(JSDocableNode(NamedNode(ctor)))); export const ImportEqualsDeclarationBase = createBase(Statement); export class ImportEqualsDeclaration extends ImportEqualsDeclarationBase { /** Gets if this import equals declaration is type only. */ diff --git a/packages/ts-morph/src/tests/compiler/ast/module/importEqualsDeclarationTests.ts b/packages/ts-morph/src/tests/compiler/ast/module/importEqualsDeclarationTests.ts index 12efc8e89..fdef20250 100644 --- a/packages/ts-morph/src/tests/compiler/ast/module/importEqualsDeclarationTests.ts +++ b/packages/ts-morph/src/tests/compiler/ast/module/importEqualsDeclarationTests.ts @@ -200,4 +200,29 @@ describe("ImportEqualsDeclaration", () => { .to.throw(); }); }); + + describe(nameof("hasExportKeyword"), () => { + function doTest(text: string, expected: boolean) { + const { firstChild } = getInfoFromText(text); + expect(firstChild.hasExportKeyword()).to.equal(expected); + } + + it("should get if has export keyword", () => { + doTest("import test = Namespace.Test;", false); + doTest("export import test = Namespace.Test;", true); + }); + }); + + describe(nameof("setIsExported"), () => { + function doTest(text: string, value: boolean, expected: string) { + const { firstChild, sourceFile } = getInfoFromText(text); + firstChild.setIsExported(value); + expect(sourceFile.getText()).to.equal(expected); + } + + it("should add and remove", () => { + doTest("import test = Namespace.Test;", true, "export import test = Namespace.Test;"); + doTest("export import test = Namespace.Test;", false, "import test = Namespace.Test;"); + }); + }); });