Skip to content

Commit f850470

Browse files
authored
fix(44377): omit type alias declarations from JavaScript (#44378)
1 parent 8d3125b commit f850470

File tree

8 files changed

+160
-5
lines changed

8 files changed

+160
-5
lines changed

src/compiler/transformers/ts.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -411,11 +411,11 @@ namespace ts {
411411

412412
case SyntaxKind.Decorator:
413413
// TypeScript decorators are elided. They will be emitted as part of visitClassDeclaration.
414-
// falls through
414+
return undefined;
415415

416416
case SyntaxKind.TypeAliasDeclaration:
417417
// TypeScript type-only declarations are elided.
418-
return undefined;
418+
return factory.createNotEmittedStatement(node);
419419

420420
case SyntaxKind.PropertyDeclaration:
421421
// TypeScript property declarations are elided. However their names are still visited, and can potentially be retained if they could have sideeffects

tests/baselines/reference/labeledStatementWithLabel.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,4 @@ label: var b = 1;
7878
label: var c = 1;
7979
label: ;
8080
label: ;
81-
label:
81+
label: ;

tests/baselines/reference/labeledStatementWithLabel_es2015.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,4 @@ label: let b = 1;
4242
label: const c = 1;
4343
label: ;
4444
label: ;
45-
label:
45+
label: ;

tests/baselines/reference/labeledStatementWithLabel_strict.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,4 @@ label: let b = 1;
4444
label: const c = 1;
4545
label: ;
4646
label: ;
47-
label:
47+
label: ;
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
//// [typeAliasDeclarationEmit3.ts]
2+
function f1(): void {
3+
for (let i = 0; i < 1; i++)
4+
type foo = [];
5+
console.log('f1');
6+
}
7+
8+
function f2(): void {
9+
while (true)
10+
type foo = [];
11+
console.log('f2');
12+
}
13+
14+
function f3(): void {
15+
if (true)
16+
type foo = [];
17+
console.log('f3');
18+
}
19+
20+
21+
//// [typeAliasDeclarationEmit3.js]
22+
function f1() {
23+
for (var i = 0; i < 1; i++)
24+
;
25+
console.log('f1');
26+
}
27+
function f2() {
28+
while (true)
29+
;
30+
console.log('f2');
31+
}
32+
function f3() {
33+
if (true)
34+
;
35+
console.log('f3');
36+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
=== tests/cases/compiler/typeAliasDeclarationEmit3.ts ===
2+
function f1(): void {
3+
>f1 : Symbol(f1, Decl(typeAliasDeclarationEmit3.ts, 0, 0))
4+
5+
for (let i = 0; i < 1; i++)
6+
>i : Symbol(i, Decl(typeAliasDeclarationEmit3.ts, 1, 12))
7+
>i : Symbol(i, Decl(typeAliasDeclarationEmit3.ts, 1, 12))
8+
>i : Symbol(i, Decl(typeAliasDeclarationEmit3.ts, 1, 12))
9+
10+
type foo = [];
11+
>foo : Symbol(foo, Decl(typeAliasDeclarationEmit3.ts, 1, 31))
12+
13+
console.log('f1');
14+
>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
15+
>console : Symbol(console, Decl(lib.dom.d.ts, --, --))
16+
>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
17+
}
18+
19+
function f2(): void {
20+
>f2 : Symbol(f2, Decl(typeAliasDeclarationEmit3.ts, 4, 1))
21+
22+
while (true)
23+
type foo = [];
24+
>foo : Symbol(foo, Decl(typeAliasDeclarationEmit3.ts, 7, 16))
25+
26+
console.log('f2');
27+
>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
28+
>console : Symbol(console, Decl(lib.dom.d.ts, --, --))
29+
>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
30+
}
31+
32+
function f3(): void {
33+
>f3 : Symbol(f3, Decl(typeAliasDeclarationEmit3.ts, 10, 1))
34+
35+
if (true)
36+
type foo = [];
37+
>foo : Symbol(foo, Decl(typeAliasDeclarationEmit3.ts, 13, 13))
38+
39+
console.log('f3');
40+
>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
41+
>console : Symbol(console, Decl(lib.dom.d.ts, --, --))
42+
>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
43+
}
44+
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
=== tests/cases/compiler/typeAliasDeclarationEmit3.ts ===
2+
function f1(): void {
3+
>f1 : () => void
4+
5+
for (let i = 0; i < 1; i++)
6+
>i : number
7+
>0 : 0
8+
>i < 1 : boolean
9+
>i : number
10+
>1 : 1
11+
>i++ : number
12+
>i : number
13+
14+
type foo = [];
15+
>foo : []
16+
17+
console.log('f1');
18+
>console.log('f1') : void
19+
>console.log : (...data: any[]) => void
20+
>console : Console
21+
>log : (...data: any[]) => void
22+
>'f1' : "f1"
23+
}
24+
25+
function f2(): void {
26+
>f2 : () => void
27+
28+
while (true)
29+
>true : true
30+
31+
type foo = [];
32+
>foo : []
33+
34+
console.log('f2');
35+
>console.log('f2') : void
36+
>console.log : (...data: any[]) => void
37+
>console : Console
38+
>log : (...data: any[]) => void
39+
>'f2' : "f2"
40+
}
41+
42+
function f3(): void {
43+
>f3 : () => void
44+
45+
if (true)
46+
>true : true
47+
48+
type foo = [];
49+
>foo : []
50+
51+
console.log('f3');
52+
>console.log('f3') : void
53+
>console.log : (...data: any[]) => void
54+
>console : Console
55+
>log : (...data: any[]) => void
56+
>'f3' : "f3"
57+
}
58+
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
function f1(): void {
2+
for (let i = 0; i < 1; i++)
3+
type foo = [];
4+
console.log('f1');
5+
}
6+
7+
function f2(): void {
8+
while (true)
9+
type foo = [];
10+
console.log('f2');
11+
}
12+
13+
function f3(): void {
14+
if (true)
15+
type foo = [];
16+
console.log('f3');
17+
}

0 commit comments

Comments
 (0)