Skip to content

Commit 01a7ba8

Browse files
authored
Merge pull request #13189 from Microsoft/Fix12724
Do not report helper module errors in ambient contexts for Rest helper
2 parents 4fa8118 + 5928f60 commit 01a7ba8

File tree

5 files changed

+378
-2
lines changed

5 files changed

+378
-2
lines changed

src/compiler/checker.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/// <reference path="moduleNameResolver.ts"/>
1+
/// <reference path="moduleNameResolver.ts"/>
22
/// <reference path="binder.ts"/>
33

44
/* @internal */
@@ -17244,7 +17244,7 @@ namespace ts {
1724417244
}
1724517245

1724617246
if (node.kind === SyntaxKind.BindingElement) {
17247-
if (node.parent.kind === SyntaxKind.ObjectBindingPattern && languageVersion < ScriptTarget.ESNext) {
17247+
if (node.parent.kind === SyntaxKind.ObjectBindingPattern && languageVersion < ScriptTarget.ESNext && !isInAmbientContext(node)) {
1724817248
checkExternalEmitHelpers(node, ExternalEmitHelpers.Rest);
1724917249
}
1725017250
// check computed properties inside property names of binding elements
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
//// [tests/cases/compiler/importHelpersInAmbientContext.ts] ////
2+
3+
//// [a.d.ts]
4+
5+
export { };
6+
7+
// Extends
8+
declare class C { }
9+
declare class D extends C { }
10+
11+
// Destructuring
12+
interface I {
13+
({descendants, read}?: {
14+
descendants?: boolean;
15+
read?: any;
16+
}): any;
17+
}
18+
19+
20+
// Object Rest
21+
interface Foo {
22+
a: number; b: string;
23+
}
24+
export var { a, ...x } : Foo;
25+
26+
//// [b.ts]
27+
export {};
28+
declare namespace N {
29+
// Extends
30+
class C { }
31+
class D extends C { }
32+
33+
// Destructuring
34+
interface I {
35+
({descendants, read}?: {
36+
descendants?: boolean;
37+
read?: any;
38+
}): any;
39+
}
40+
41+
42+
// Object Rest
43+
interface Foo {
44+
a: number; b: string;
45+
}
46+
export var { a, ...x } : Foo;
47+
}
48+
49+
//// [tslib.d.ts]
50+
export declare function __extends(d: Function, b: Function): void;
51+
export declare function __assign(t: any, ...sources: any[]): any;
52+
export declare function __decorate(decorators: Function[], target: any, key?: string | symbol, desc?: any): any;
53+
export declare function __param(paramIndex: number, decorator: Function): Function;
54+
export declare function __metadata(metadataKey: any, metadataValue: any): Function;
55+
export declare function __awaiter(thisArg: any, _arguments: any, P: Function, generator: Function): any;
56+
57+
58+
//// [b.js]
59+
"use strict";
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
=== tests/cases/compiler/a.d.ts ===
2+
3+
export { };
4+
5+
// Extends
6+
declare class C { }
7+
>C : Symbol(C, Decl(a.d.ts, 1, 11))
8+
9+
declare class D extends C { }
10+
>D : Symbol(D, Decl(a.d.ts, 4, 19))
11+
>C : Symbol(C, Decl(a.d.ts, 1, 11))
12+
13+
// Destructuring
14+
interface I {
15+
>I : Symbol(I, Decl(a.d.ts, 5, 29))
16+
17+
({descendants, read}?: {
18+
>descendants : Symbol(descendants, Decl(a.d.ts, 9, 6))
19+
>read : Symbol(read, Decl(a.d.ts, 9, 18))
20+
21+
descendants?: boolean;
22+
>descendants : Symbol(descendants, Decl(a.d.ts, 9, 28))
23+
24+
read?: any;
25+
>read : Symbol(read, Decl(a.d.ts, 10, 30))
26+
27+
}): any;
28+
}
29+
30+
31+
// Object Rest
32+
interface Foo {
33+
>Foo : Symbol(Foo, Decl(a.d.ts, 13, 1))
34+
35+
a: number; b: string;
36+
>a : Symbol(Foo.a, Decl(a.d.ts, 17, 15))
37+
>b : Symbol(Foo.b, Decl(a.d.ts, 18, 14))
38+
}
39+
export var { a, ...x } : Foo;
40+
>a : Symbol(a, Decl(a.d.ts, 20, 12))
41+
>x : Symbol(x, Decl(a.d.ts, 20, 15))
42+
>Foo : Symbol(Foo, Decl(a.d.ts, 13, 1))
43+
44+
=== tests/cases/compiler/b.ts ===
45+
export {};
46+
declare namespace N {
47+
>N : Symbol(N, Decl(b.ts, 0, 10))
48+
49+
// Extends
50+
class C { }
51+
>C : Symbol(C, Decl(b.ts, 1, 21))
52+
53+
class D extends C { }
54+
>D : Symbol(D, Decl(b.ts, 3, 12))
55+
>C : Symbol(C, Decl(b.ts, 1, 21))
56+
57+
// Destructuring
58+
interface I {
59+
>I : Symbol(I, Decl(b.ts, 4, 22))
60+
61+
({descendants, read}?: {
62+
>descendants : Symbol(descendants, Decl(b.ts, 8, 4))
63+
>read : Symbol(read, Decl(b.ts, 8, 16))
64+
65+
descendants?: boolean;
66+
>descendants : Symbol(descendants, Decl(b.ts, 8, 26))
67+
68+
read?: any;
69+
>read : Symbol(read, Decl(b.ts, 9, 25))
70+
71+
}): any;
72+
}
73+
74+
75+
// Object Rest
76+
interface Foo {
77+
>Foo : Symbol(Foo, Decl(b.ts, 12, 2))
78+
79+
a: number; b: string;
80+
>a : Symbol(Foo.a, Decl(b.ts, 16, 16))
81+
>b : Symbol(Foo.b, Decl(b.ts, 17, 12))
82+
}
83+
export var { a, ...x } : Foo;
84+
>a : Symbol(a, Decl(b.ts, 19, 13))
85+
>x : Symbol(x, Decl(b.ts, 19, 16))
86+
>Foo : Symbol(Foo, Decl(b.ts, 12, 2))
87+
}
88+
89+
=== tests/cases/compiler/tslib.d.ts ===
90+
export declare function __extends(d: Function, b: Function): void;
91+
>__extends : Symbol(__extends, Decl(tslib.d.ts, --, --))
92+
>d : Symbol(d, Decl(tslib.d.ts, --, --))
93+
>Function : Symbol(Function, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
94+
>b : Symbol(b, Decl(tslib.d.ts, --, --))
95+
>Function : Symbol(Function, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
96+
97+
export declare function __assign(t: any, ...sources: any[]): any;
98+
>__assign : Symbol(__assign, Decl(tslib.d.ts, --, --))
99+
>t : Symbol(t, Decl(tslib.d.ts, --, --))
100+
>sources : Symbol(sources, Decl(tslib.d.ts, --, --))
101+
102+
export declare function __decorate(decorators: Function[], target: any, key?: string | symbol, desc?: any): any;
103+
>__decorate : Symbol(__decorate, Decl(tslib.d.ts, --, --))
104+
>decorators : Symbol(decorators, Decl(tslib.d.ts, --, --))
105+
>Function : Symbol(Function, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
106+
>target : Symbol(target, Decl(tslib.d.ts, --, --))
107+
>key : Symbol(key, Decl(tslib.d.ts, --, --))
108+
>desc : Symbol(desc, Decl(tslib.d.ts, --, --))
109+
110+
export declare function __param(paramIndex: number, decorator: Function): Function;
111+
>__param : Symbol(__param, Decl(tslib.d.ts, --, --))
112+
>paramIndex : Symbol(paramIndex, Decl(tslib.d.ts, --, --))
113+
>decorator : Symbol(decorator, Decl(tslib.d.ts, --, --))
114+
>Function : Symbol(Function, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
115+
>Function : Symbol(Function, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
116+
117+
export declare function __metadata(metadataKey: any, metadataValue: any): Function;
118+
>__metadata : Symbol(__metadata, Decl(tslib.d.ts, --, --))
119+
>metadataKey : Symbol(metadataKey, Decl(tslib.d.ts, --, --))
120+
>metadataValue : Symbol(metadataValue, Decl(tslib.d.ts, --, --))
121+
>Function : Symbol(Function, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
122+
123+
export declare function __awaiter(thisArg: any, _arguments: any, P: Function, generator: Function): any;
124+
>__awaiter : Symbol(__awaiter, Decl(tslib.d.ts, --, --))
125+
>thisArg : Symbol(thisArg, Decl(tslib.d.ts, --, --))
126+
>_arguments : Symbol(_arguments, Decl(tslib.d.ts, --, --))
127+
>P : Symbol(P, Decl(tslib.d.ts, --, --))
128+
>Function : Symbol(Function, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
129+
>generator : Symbol(generator, Decl(tslib.d.ts, --, --))
130+
>Function : Symbol(Function, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
131+
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
=== tests/cases/compiler/a.d.ts ===
2+
3+
export { };
4+
5+
// Extends
6+
declare class C { }
7+
>C : C
8+
9+
declare class D extends C { }
10+
>D : D
11+
>C : C
12+
13+
// Destructuring
14+
interface I {
15+
>I : I
16+
17+
({descendants, read}?: {
18+
>descendants : boolean
19+
>read : any
20+
21+
descendants?: boolean;
22+
>descendants : boolean
23+
24+
read?: any;
25+
>read : any
26+
27+
}): any;
28+
}
29+
30+
31+
// Object Rest
32+
interface Foo {
33+
>Foo : Foo
34+
35+
a: number; b: string;
36+
>a : number
37+
>b : string
38+
}
39+
export var { a, ...x } : Foo;
40+
>a : number
41+
>x : { b: string; }
42+
>Foo : Foo
43+
44+
=== tests/cases/compiler/b.ts ===
45+
export {};
46+
declare namespace N {
47+
>N : typeof N
48+
49+
// Extends
50+
class C { }
51+
>C : C
52+
53+
class D extends C { }
54+
>D : D
55+
>C : C
56+
57+
// Destructuring
58+
interface I {
59+
>I : I
60+
61+
({descendants, read}?: {
62+
>descendants : boolean
63+
>read : any
64+
65+
descendants?: boolean;
66+
>descendants : boolean
67+
68+
read?: any;
69+
>read : any
70+
71+
}): any;
72+
}
73+
74+
75+
// Object Rest
76+
interface Foo {
77+
>Foo : Foo
78+
79+
a: number; b: string;
80+
>a : number
81+
>b : string
82+
}
83+
export var { a, ...x } : Foo;
84+
>a : number
85+
>x : { b: string; }
86+
>Foo : Foo
87+
}
88+
89+
=== tests/cases/compiler/tslib.d.ts ===
90+
export declare function __extends(d: Function, b: Function): void;
91+
>__extends : (d: Function, b: Function) => void
92+
>d : Function
93+
>Function : Function
94+
>b : Function
95+
>Function : Function
96+
97+
export declare function __assign(t: any, ...sources: any[]): any;
98+
>__assign : (t: any, ...sources: any[]) => any
99+
>t : any
100+
>sources : any[]
101+
102+
export declare function __decorate(decorators: Function[], target: any, key?: string | symbol, desc?: any): any;
103+
>__decorate : (decorators: Function[], target: any, key?: string | symbol, desc?: any) => any
104+
>decorators : Function[]
105+
>Function : Function
106+
>target : any
107+
>key : string | symbol
108+
>desc : any
109+
110+
export declare function __param(paramIndex: number, decorator: Function): Function;
111+
>__param : (paramIndex: number, decorator: Function) => Function
112+
>paramIndex : number
113+
>decorator : Function
114+
>Function : Function
115+
>Function : Function
116+
117+
export declare function __metadata(metadataKey: any, metadataValue: any): Function;
118+
>__metadata : (metadataKey: any, metadataValue: any) => Function
119+
>metadataKey : any
120+
>metadataValue : any
121+
>Function : Function
122+
123+
export declare function __awaiter(thisArg: any, _arguments: any, P: Function, generator: Function): any;
124+
>__awaiter : (thisArg: any, _arguments: any, P: Function, generator: Function) => any
125+
>thisArg : any
126+
>_arguments : any
127+
>P : Function
128+
>Function : Function
129+
>generator : Function
130+
>Function : Function
131+
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// @importHelpers: true
2+
// @target: es5
3+
4+
// @filename: a.d.ts
5+
export { };
6+
7+
// Extends
8+
declare class C { }
9+
declare class D extends C { }
10+
11+
// Destructuring
12+
interface I {
13+
({descendants, read}?: {
14+
descendants?: boolean;
15+
read?: any;
16+
}): any;
17+
}
18+
19+
20+
// Object Rest
21+
interface Foo {
22+
a: number; b: string;
23+
}
24+
export var { a, ...x } : Foo;
25+
26+
// @filename: b.ts
27+
export {};
28+
declare namespace N {
29+
// Extends
30+
class C { }
31+
class D extends C { }
32+
33+
// Destructuring
34+
interface I {
35+
({descendants, read}?: {
36+
descendants?: boolean;
37+
read?: any;
38+
}): any;
39+
}
40+
41+
42+
// Object Rest
43+
interface Foo {
44+
a: number; b: string;
45+
}
46+
export var { a, ...x } : Foo;
47+
}
48+
49+
// @filename: tslib.d.ts
50+
export declare function __extends(d: Function, b: Function): void;
51+
export declare function __assign(t: any, ...sources: any[]): any;
52+
export declare function __decorate(decorators: Function[], target: any, key?: string | symbol, desc?: any): any;
53+
export declare function __param(paramIndex: number, decorator: Function): Function;
54+
export declare function __metadata(metadataKey: any, metadataValue: any): Function;
55+
export declare function __awaiter(thisArg: any, _arguments: any, P: Function, generator: Function): any;

0 commit comments

Comments
 (0)