Skip to content

Commit

Permalink
fix(declarations): add workaround for TypeScript issue 40361 for olde…
Browse files Browse the repository at this point in the history
…r TypeScript versions. Closes #108
  • Loading branch information
wessberg committed Sep 2, 2020
1 parent 874777c commit 659775f
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export function deconflictConstructorDeclaration(options: DeconflicterVisitorOpt
// The body and parameters share the same lexical environment
const nextContinuationOptions: ContinuationOptions = {lexicalEnvironment: cloneLexicalEnvironment(lexicalEnvironment)};

const parametersContResult = node.parameters.map(parameter => continuation(parameter, nextContinuationOptions));
const parametersContResult = node.parameters?.map(parameter => continuation(parameter, nextContinuationOptions)) ?? [];
const bodyContResult = node.body == null ? undefined : continuation(node.body, nextContinuationOptions);

const isIdentical = nodeArraysAreEqual(parametersContResult, node.parameters) && bodyContResult === node.body;
Expand Down
32 changes: 32 additions & 0 deletions test/declaration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -746,3 +746,35 @@ test("Flattens declarations. #16", async (t, {typescript}) => {
`)
);
});

test("Flattens declarations. #17", async (t, {typescript}) => {
const bundle = await generateRollupBundle(
[
{
entry: true,
fileName: "index.ts",
text: `\
export class Singleton {
private constructor() {}
}
`
}
],
{
typescript,
debug: false
}
);
const {
declarations: [file]
} = bundle;
t.deepEqual(
formatCode(file.code),
formatCode(`\
declare class Singleton {
private constructor();
}
export {Singleton};
`)
);
});

0 comments on commit 659775f

Please sign in to comment.