Skip to content

Commit cca68ad

Browse files
committed
Import helpers skips __assign when target >= ES6
Instead, Object.assign is emitted.
1 parent 46cdac1 commit cca68ad

File tree

5 files changed

+28
-13
lines changed

5 files changed

+28
-13
lines changed

src/compiler/checker.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -11721,7 +11721,7 @@ namespace ts {
1172111721
member = prop;
1172211722
}
1172311723
else if (memberDecl.kind === SyntaxKind.SpreadAssignment) {
11724-
if (languageVersion < ScriptTarget.ESNext) {
11724+
if (languageVersion < ScriptTarget.ES2015) {
1172511725
checkExternalEmitHelpers(memberDecl, ExternalEmitHelpers.Assign);
1172611726
}
1172711727
if (propertiesArray.length > 0) {

tests/baselines/reference/importHelpersES6.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@ declare var dec: any;
55
@dec export class A {
66

77
}
8+
9+
const o = { a: 1 };
10+
const y = { ...o };
811

912
//// [tslib.d.ts]
1013
export declare function __extends(d: Function, b: Function): void;
11-
export declare function __assign(t: any, ...sources: any[]): any;
1214
export declare function __decorate(decorators: Function[], target: any, key?: string | symbol, desc?: any): any;
1315
export declare function __param(paramIndex: number, decorator: Function): Function;
1416
export declare function __metadata(metadataKey: any, metadataValue: any): Function;
@@ -23,3 +25,5 @@ A = tslib_1.__decorate([
2325
dec
2426
], A);
2527
export { A };
28+
const o = { a: 1 };
29+
const y = Object.assign({}, o);

tests/baselines/reference/importHelpersES6.symbols

+8-5
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@ declare var dec: any;
88

99
}
1010

11+
const o = { a: 1 };
12+
>o : Symbol(o, Decl(a.ts, 5, 5))
13+
>a : Symbol(a, Decl(a.ts, 5, 11))
14+
15+
const y = { ...o };
16+
>y : Symbol(y, Decl(a.ts, 6, 5))
17+
>o : Symbol(o, Decl(a.ts, 5, 5))
18+
1119
=== tests/cases/compiler/tslib.d.ts ===
1220
export declare function __extends(d: Function, b: Function): void;
1321
>__extends : Symbol(__extends, Decl(tslib.d.ts, --, --))
@@ -16,11 +24,6 @@ export declare function __extends(d: Function, b: Function): void;
1624
>b : Symbol(b, Decl(tslib.d.ts, --, --))
1725
>Function : Symbol(Function, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --))
1826

19-
export declare function __assign(t: any, ...sources: any[]): any;
20-
>__assign : Symbol(__assign, Decl(tslib.d.ts, --, --))
21-
>t : Symbol(t, Decl(tslib.d.ts, --, --))
22-
>sources : Symbol(sources, Decl(tslib.d.ts, --, --))
23-
2427
export declare function __decorate(decorators: Function[], target: any, key?: string | symbol, desc?: any): any;
2528
>__decorate : Symbol(__decorate, Decl(tslib.d.ts, --, --))
2629
>decorators : Symbol(decorators, Decl(tslib.d.ts, --, --))

tests/baselines/reference/importHelpersES6.types

+11-5
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,17 @@ declare var dec: any;
88

99
}
1010

11+
const o = { a: 1 };
12+
>o : { a: number; }
13+
>{ a: 1 } : { a: number; }
14+
>a : number
15+
>1 : 1
16+
17+
const y = { ...o };
18+
>y : { a: number; }
19+
>{ ...o } : { a: number; }
20+
>o : { a: number; }
21+
1122
=== tests/cases/compiler/tslib.d.ts ===
1223
export declare function __extends(d: Function, b: Function): void;
1324
>__extends : (d: Function, b: Function) => void
@@ -16,11 +27,6 @@ export declare function __extends(d: Function, b: Function): void;
1627
>b : Function
1728
>Function : Function
1829

19-
export declare function __assign(t: any, ...sources: any[]): any;
20-
>__assign : (t: any, ...sources: any[]) => any
21-
>t : any
22-
>sources : any[]
23-
2430
export declare function __decorate(decorators: Function[], target: any, key?: string | symbol, desc?: any): any;
2531
>__decorate : (decorators: Function[], target: any, key?: string | symbol, desc?: any) => any
2632
>decorators : Function[]

tests/cases/compiler/importHelpersES6.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@ declare var dec: any;
77

88
}
99

10+
const o = { a: 1 };
11+
const y = { ...o };
12+
1013
// @filename: tslib.d.ts
1114
export declare function __extends(d: Function, b: Function): void;
12-
export declare function __assign(t: any, ...sources: any[]): any;
1315
export declare function __decorate(decorators: Function[], target: any, key?: string | symbol, desc?: any): any;
1416
export declare function __param(paramIndex: number, decorator: Function): Function;
1517
export declare function __metadata(metadataKey: any, metadataValue: any): Function;

0 commit comments

Comments
 (0)