Skip to content

Commit 409dddc

Browse files
committed
do not hoist ambient declarations
1 parent c8dd04b commit 409dddc

File tree

5 files changed

+224
-0
lines changed

5 files changed

+224
-0
lines changed

src/compiler/emitter.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5146,6 +5146,10 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
51465146
return exportedDeclarations;
51475147

51485148
function visit(node: Node): void {
5149+
if (node.flags & NodeFlags.Ambient) {
5150+
return;
5151+
}
5152+
51495153
if (node.kind === SyntaxKind.FunctionDeclaration) {
51505154
if (!hoistedFunctionDeclarations) {
51515155
hoistedFunctionDeclarations = [];
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
//// [tests/cases/compiler/systemModuleAmbientDeclarations.ts] ////
2+
3+
//// [file1.ts]
4+
5+
declare class Promise { }
6+
declare function Foo(): void;
7+
declare class C {}
8+
declare enum E {X = 1};
9+
10+
export var promise = Promise;
11+
export var foo = Foo;
12+
export var c = C;
13+
export var e = E;
14+
15+
//// [file2.ts]
16+
export declare function foo();
17+
18+
//// [file3.ts]
19+
export declare class C {}
20+
21+
//// [file4.ts]
22+
export declare var v: number;
23+
24+
//// [file5.ts]
25+
export declare enum E {X = 1}
26+
27+
//// [file6.ts]
28+
export declare module M { var v: number; }
29+
30+
31+
//// [file1.js]
32+
System.register([], function(exports_1) {
33+
var promise, foo, c, e;
34+
return {
35+
setters:[],
36+
execute: function() {
37+
;
38+
exports_1("promise", promise = Promise);
39+
exports_1("foo", foo = Foo);
40+
exports_1("c", c = C);
41+
exports_1("e", e = E);
42+
}
43+
}
44+
});
45+
//// [file2.js]
46+
System.register([], function(exports_1) {
47+
return {
48+
setters:[],
49+
execute: function() {
50+
}
51+
}
52+
});
53+
//// [file3.js]
54+
System.register([], function(exports_1) {
55+
return {
56+
setters:[],
57+
execute: function() {
58+
}
59+
}
60+
});
61+
//// [file4.js]
62+
System.register([], function(exports_1) {
63+
return {
64+
setters:[],
65+
execute: function() {
66+
}
67+
}
68+
});
69+
//// [file5.js]
70+
System.register([], function(exports_1) {
71+
return {
72+
setters:[],
73+
execute: function() {
74+
}
75+
}
76+
});
77+
//// [file6.js]
78+
System.register([], function(exports_1) {
79+
return {
80+
setters:[],
81+
execute: function() {
82+
}
83+
}
84+
});
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
=== tests/cases/compiler/file1.ts ===
2+
3+
declare class Promise { }
4+
>Promise : Symbol(Promise, Decl(file1.ts, 0, 0))
5+
6+
declare function Foo(): void;
7+
>Foo : Symbol(Foo, Decl(file1.ts, 1, 25))
8+
9+
declare class C {}
10+
>C : Symbol(C, Decl(file1.ts, 2, 29))
11+
12+
declare enum E {X = 1};
13+
>E : Symbol(E, Decl(file1.ts, 3, 18))
14+
>X : Symbol(E.X, Decl(file1.ts, 4, 16))
15+
16+
export var promise = Promise;
17+
>promise : Symbol(promise, Decl(file1.ts, 6, 10))
18+
>Promise : Symbol(Promise, Decl(file1.ts, 0, 0))
19+
20+
export var foo = Foo;
21+
>foo : Symbol(foo, Decl(file1.ts, 7, 10))
22+
>Foo : Symbol(Foo, Decl(file1.ts, 1, 25))
23+
24+
export var c = C;
25+
>c : Symbol(c, Decl(file1.ts, 8, 10))
26+
>C : Symbol(C, Decl(file1.ts, 2, 29))
27+
28+
export var e = E;
29+
>e : Symbol(e, Decl(file1.ts, 9, 10))
30+
>E : Symbol(E, Decl(file1.ts, 3, 18))
31+
32+
=== tests/cases/compiler/file2.ts ===
33+
export declare function foo();
34+
>foo : Symbol(foo, Decl(file2.ts, 0, 0))
35+
36+
=== tests/cases/compiler/file3.ts ===
37+
export declare class C {}
38+
>C : Symbol(C, Decl(file3.ts, 0, 0))
39+
40+
=== tests/cases/compiler/file4.ts ===
41+
export declare var v: number;
42+
>v : Symbol(v, Decl(file4.ts, 0, 18))
43+
44+
=== tests/cases/compiler/file5.ts ===
45+
export declare enum E {X = 1}
46+
>E : Symbol(E, Decl(file5.ts, 0, 0))
47+
>X : Symbol(E.X, Decl(file5.ts, 0, 23))
48+
49+
=== tests/cases/compiler/file6.ts ===
50+
export declare module M { var v: number; }
51+
>M : Symbol(M, Decl(file6.ts, 0, 0))
52+
>v : Symbol(v, Decl(file6.ts, 0, 29))
53+
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
=== tests/cases/compiler/file1.ts ===
2+
3+
declare class Promise { }
4+
>Promise : Promise
5+
6+
declare function Foo(): void;
7+
>Foo : () => void
8+
9+
declare class C {}
10+
>C : C
11+
12+
declare enum E {X = 1};
13+
>E : E
14+
>X : E
15+
>1 : number
16+
17+
export var promise = Promise;
18+
>promise : typeof Promise
19+
>Promise : typeof Promise
20+
21+
export var foo = Foo;
22+
>foo : () => void
23+
>Foo : () => void
24+
25+
export var c = C;
26+
>c : typeof C
27+
>C : typeof C
28+
29+
export var e = E;
30+
>e : typeof E
31+
>E : typeof E
32+
33+
=== tests/cases/compiler/file2.ts ===
34+
export declare function foo();
35+
>foo : () => any
36+
37+
=== tests/cases/compiler/file3.ts ===
38+
export declare class C {}
39+
>C : C
40+
41+
=== tests/cases/compiler/file4.ts ===
42+
export declare var v: number;
43+
>v : number
44+
45+
=== tests/cases/compiler/file5.ts ===
46+
export declare enum E {X = 1}
47+
>E : E
48+
>X : E
49+
>1 : number
50+
51+
=== tests/cases/compiler/file6.ts ===
52+
export declare module M { var v: number; }
53+
>M : typeof M
54+
>v : number
55+
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// @module: system
2+
// @separateCompilation: true
3+
4+
// @filename: file1.ts
5+
declare class Promise { }
6+
declare function Foo(): void;
7+
declare class C {}
8+
declare enum E {X = 1};
9+
10+
export var promise = Promise;
11+
export var foo = Foo;
12+
export var c = C;
13+
export var e = E;
14+
15+
// @filename: file2.ts
16+
export declare function foo();
17+
18+
// @filename: file3.ts
19+
export declare class C {}
20+
21+
// @filename: file4.ts
22+
export declare var v: number;
23+
24+
// @filename: file5.ts
25+
export declare enum E {X = 1}
26+
27+
// @filename: file6.ts
28+
export declare module M { var v: number; }

0 commit comments

Comments
 (0)