Skip to content

Commit 205ce32

Browse files
authored
Merge pull request #12154 from Microsoft/import-helpers-reports-errors-for-__rest
Import helpers reports errors for __rest
2 parents 3ecb601 + ba6e5a0 commit 205ce32

File tree

6 files changed

+31
-6
lines changed

6 files changed

+31
-6
lines changed

src/compiler/binder.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1553,7 +1553,7 @@ namespace ts {
15531553
const seen = createMap<ElementKind>();
15541554

15551555
for (const prop of node.properties) {
1556-
if (prop.name.kind !== SyntaxKind.Identifier) {
1556+
if (prop.kind === SyntaxKind.SpreadAssignment || prop.name.kind !== SyntaxKind.Identifier) {
15571557
continue;
15581558
}
15591559

src/compiler/checker.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -19970,9 +19970,13 @@ namespace ts {
1997019970
if (requestedExternalEmitHelpers & NodeFlags.HasClassExtends && languageVersion < ScriptTarget.ES2015) {
1997119971
verifyHelperSymbol(exports, "__extends", SymbolFlags.Value);
1997219972
}
19973-
if (requestedExternalEmitHelpers & NodeFlags.HasSpreadAttribute && compilerOptions.jsx !== JsxEmit.Preserve) {
19973+
if (requestedExternalEmitHelpers & NodeFlags.HasSpreadAttribute &&
19974+
(languageVersion < ScriptTarget.ESNext || compilerOptions.jsx === JsxEmit.React)) {
1997419975
verifyHelperSymbol(exports, "__assign", SymbolFlags.Value);
1997519976
}
19977+
if (languageVersion < ScriptTarget.ESNext && requestedExternalEmitHelpers & NodeFlags.HasRestAttribute) {
19978+
verifyHelperSymbol(exports, "__rest", SymbolFlags.Value);
19979+
}
1997619980
if (requestedExternalEmitHelpers & NodeFlags.HasDecorators) {
1997719981
verifyHelperSymbol(exports, "__decorate", SymbolFlags.Value);
1997819982
if (compilerOptions.emitDecoratorMetadata) {

src/compiler/types.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ namespace ts {
433433
BlockScoped = Let | Const,
434434

435435
ReachabilityCheckFlags = HasImplicitReturn | HasExplicitReturn,
436-
EmitHelperFlags = HasClassExtends | HasDecorators | HasParamDecorators | HasAsyncFunctions | HasSpreadAttribute,
436+
EmitHelperFlags = HasClassExtends | HasDecorators | HasParamDecorators | HasAsyncFunctions | HasSpreadAttribute | HasRestAttribute,
437437
ReachabilityAndEmitFlags = ReachabilityCheckFlags | EmitHelperFlags,
438438

439439
// Parsing context flags

tests/baselines/reference/importHelpersNoHelpers.errors.txt

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
1+
error TS2305: Module 'tslib' has no exported member '__assign'.
12
error TS2305: Module 'tslib' has no exported member '__decorate'.
23
error TS2305: Module 'tslib' has no exported member '__extends'.
34
error TS2305: Module 'tslib' has no exported member '__metadata'.
45
error TS2305: Module 'tslib' has no exported member '__param'.
6+
error TS2305: Module 'tslib' has no exported member '__rest'.
57

68

9+
!!! error TS2305: Module 'tslib' has no exported member '__assign'.
710
!!! error TS2305: Module 'tslib' has no exported member '__decorate'.
811
!!! error TS2305: Module 'tslib' has no exported member '__extends'.
912
!!! error TS2305: Module 'tslib' has no exported member '__metadata'.
1013
!!! error TS2305: Module 'tslib' has no exported member '__param'.
14+
!!! error TS2305: Module 'tslib' has no exported member '__rest'.
1115
==== tests/cases/compiler/external.ts (0 errors) ====
1216
export class A { }
1317
export class B extends A { }
@@ -20,6 +24,10 @@ error TS2305: Module 'tslib' has no exported member '__param'.
2024
}
2125
}
2226

27+
const o = { a: 1 };
28+
const y = { ...o };
29+
const { ...x } = y;
30+
2331
==== tests/cases/compiler/script.ts (0 errors) ====
2432
class A { }
2533
class B extends A { }
@@ -33,4 +41,5 @@ error TS2305: Module 'tslib' has no exported member '__param'.
3341
}
3442

3543
==== tests/cases/compiler/tslib.d.ts (0 errors) ====
36-
export {}
44+
export {}
45+

tests/baselines/reference/importHelpersNoHelpers.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ class C {
1111
method(@dec x: number) {
1212
}
1313
}
14+
15+
const o = { a: 1 };
16+
const y = { ...o };
17+
const { ...x } = y;
1418

1519
//// [script.ts]
1620
class A { }
@@ -25,7 +29,8 @@ class C {
2529
}
2630

2731
//// [tslib.d.ts]
28-
export {}
32+
export {}
33+
2934

3035
//// [external.js]
3136
"use strict";
@@ -61,6 +66,9 @@ C = tslib_1.__decorate([
6166
dec,
6267
tslib_1.__metadata("design:paramtypes", [])
6368
], C);
69+
var o = { a: 1 };
70+
var y = __assign({}, o);
71+
var x = __rest(y, []);
6472
//// [script.js]
6573
var __extends = (this && this.__extends) || function (d, b) {
6674
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];

tests/cases/compiler/importHelpersNoHelpers.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ class C {
1616
}
1717
}
1818

19+
const o = { a: 1 };
20+
const y = { ...o };
21+
const { ...x } = y;
22+
1923
// @filename: script.ts
2024
class A { }
2125
class B extends A { }
@@ -29,4 +33,4 @@ class C {
2933
}
3034

3135
// @filename: tslib.d.ts
32-
export {}
36+
export {}

0 commit comments

Comments
 (0)