Skip to content

Commit 75831fe

Browse files
committed
fix: unnecessary down-leveled declarations written
The test that assesses whether down-leveled declarations are necessary or not accounted for the possible presence of duplicated references to `node` types being injected by the TypeScript compiler (microsoft/TypeScript#48143), however in some cases the reference is present more than twice, which was not correctly accounted for; resulting in emission of redundant down-level declarations.
1 parent 84cd655 commit 75831fe

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/downlevel-dts.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ function semanticallyEqualDeclarations(left: string, right: string): boolean {
185185
// TypeScript may emit duplicated reference declarations... which are absent from Downlevel-DTS' output...
186186
// https://github.com/microsoft/TypeScript/issues/48143
187187
const REFERENCES_TYPES_NODE = '/// <reference types="node" />';
188-
if (normalized.startsWith(`${REFERENCES_TYPES_NODE}\n${REFERENCES_TYPES_NODE}`)) {
188+
while (normalized.startsWith(`${REFERENCES_TYPES_NODE}\n${REFERENCES_TYPES_NODE}`)) {
189189
normalized = normalized.slice(REFERENCES_TYPES_NODE.length + 1);
190190
}
191191

0 commit comments

Comments
 (0)