Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions _packages/api/test/async/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ import {
createIdentifier,
createKeywordTypeNode,
createParameterDeclaration,
createToken,
createTypeAliasDeclaration,
createTypeReferenceNode,
createUnionTypeNode,
} from "@typescript/ast/factory";
Expand Down Expand Up @@ -2354,6 +2356,28 @@ doThing();
}
});

test("Factory ModifierList auto-conversion", async () => {
const api = spawnAPI();
try {
const snapshot = await api.updateSnapshot({ openProject: "/tsconfig.json" });
const project = snapshot.getProject("/tsconfig.json")!;
const node = createTypeAliasDeclaration(
[createToken(SyntaxKind.ExportKeyword)],
createIdentifier("Test"),
undefined,
createKeywordTypeNode(SyntaxKind.AnyKeyword),
);

assert.equal(await project.emitter.printNode(node), "export type Test = any;");

const cloned = getSynthesizedDeepClone(node);
assert.equal(await project.emitter.printNode(cloned), "export type Test = any;");
}
finally {
await api.close();
}
});

test("Parse-clone-emit roundtrip", async () => {
const tsSource = fileURLToPath(new URL("../../../../_submodules/TypeScript/src", import.meta.url).toString());
const api = new API({
Expand Down
24 changes: 24 additions & 0 deletions _packages/api/test/sync/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ import {
createIdentifier,
createKeywordTypeNode,
createParameterDeclaration,
createToken,
createTypeAliasDeclaration,
createTypeReferenceNode,
createUnionTypeNode,
} from "@typescript/ast/factory";
Expand Down Expand Up @@ -2362,6 +2364,28 @@ doThing();
}
});

test("Factory ModifierList auto-conversion", () => {
const api = spawnAPI();
try {
const snapshot = api.updateSnapshot({ openProject: "/tsconfig.json" });
const project = snapshot.getProject("/tsconfig.json")!;
const node = createTypeAliasDeclaration(
[createToken(SyntaxKind.ExportKeyword)],
createIdentifier("Test"),
undefined,
createKeywordTypeNode(SyntaxKind.AnyKeyword),
);

assert.equal(project.emitter.printNode(node), "export type Test = any;");

const cloned = getSynthesizedDeepClone(node);
assert.equal(project.emitter.printNode(cloned), "export type Test = any;");
}
finally {
api.close();
}
});

test("Parse-clone-emit roundtrip", () => {
const tsSource = fileURLToPath(new URL("../../../../_submodules/TypeScript/src", import.meta.url).toString());
const api = new API({
Expand Down
Loading
Loading