Skip to content

Commit 7ff8876

Browse files
committed
Merge branch 'object-spread' into object-rest-syntax
2 parents 9d4ddb6 + 7a2c7ad commit 7ff8876

30 files changed

Lines changed: 410 additions & 1405 deletions

src/compiler/checker.ts

Lines changed: 54 additions & 298 deletions
Large diffs are not rendered by default.

src/compiler/declarationEmitter.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1138,13 +1138,6 @@ namespace ts {
11381138
writeLine();
11391139
}
11401140

1141-
function emitSpreadTypeElement(type: SpreadTypeElement) {
1142-
write("...");
1143-
emitType(type.type);
1144-
write(";");
1145-
writeLine();
1146-
}
1147-
11481141
function emitVariableDeclaration(node: VariableDeclaration | PropertyDeclaration | PropertySignature | ParameterDeclaration) {
11491142
// If we are emitting property it isn't moduleElement and hence we already know it needs to be emitted
11501143
// so there is no check needed to see if declaration is visible
@@ -1729,8 +1722,6 @@ namespace ts {
17291722
case SyntaxKind.PropertyDeclaration:
17301723
case SyntaxKind.PropertySignature:
17311724
return emitPropertyDeclaration(<PropertyDeclaration>node);
1732-
case SyntaxKind.SpreadTypeElement:
1733-
return emitSpreadTypeElement(node as SpreadTypeElement);
17341725
case SyntaxKind.EnumMember:
17351726
return emitEnumMemberDeclaration(<EnumMember>node);
17361727
case SyntaxKind.ExportAssignment:

src/compiler/diagnosticMessages.json

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1983,14 +1983,10 @@
19831983
"category": "Error",
19841984
"code": 2697
19851985
},
1986-
"Interface declaration cannot contain a spread property.": {
1986+
"Spread types may only be created from object types.": {
19871987
"category": "Error",
19881988
"code": 2698
19891989
},
1990-
"Type literals with spreads cannot contain index, call or construct signatures.": {
1991-
"category": "Error",
1992-
"code": 2699
1993-
},
19941990
"Rest types may only be created from object types.": {
19951991
"category": "Error",
19961992
"code": 2700

src/compiler/parser.ts

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,6 @@ namespace ts {
7676
visitNode(cbNode, (<ShorthandPropertyAssignment>node).objectAssignmentInitializer);
7777
case SyntaxKind.SpreadElementExpression:
7878
return visitNode(cbNode, (<SpreadElementExpression>node).expression);
79-
case SyntaxKind.SpreadTypeElement:
80-
return visitNode(cbNode, (node as SpreadTypeElement).type);
8179
case SyntaxKind.Parameter:
8280
case SyntaxKind.PropertyDeclaration:
8381
case SyntaxKind.PropertySignature:
@@ -2353,10 +2351,6 @@ namespace ts {
23532351
if (token() === SyntaxKind.OpenBracketToken) {
23542352
return true;
23552353
}
2356-
// spread elements are type members
2357-
if (token() === SyntaxKind.DotDotDotToken) {
2358-
return true;
2359-
}
23602354
// Try to get the first property-like token following all modifiers
23612355
if (isLiteralPropertyName()) {
23622356
idToken = token();
@@ -2382,9 +2376,6 @@ namespace ts {
23822376
if (token() === SyntaxKind.NewKeyword && lookAhead(isStartOfConstructSignature)) {
23832377
return parseSignatureMember(SyntaxKind.ConstructSignature);
23842378
}
2385-
if (token() === SyntaxKind.DotDotDotToken) {
2386-
return parseSpreadTypeElement();
2387-
}
23882379
const fullStart = getNodePos();
23892380
const modifiers = parseModifiers();
23902381
if (isIndexSignature()) {
@@ -2393,14 +2384,6 @@ namespace ts {
23932384
return parsePropertyOrMethodSignature(fullStart, modifiers);
23942385
}
23952386

2396-
function parseSpreadTypeElement() {
2397-
const element = createNode(SyntaxKind.SpreadTypeElement, scanner.getStartPos()) as SpreadTypeElement;
2398-
parseTokenNode<Node>(); // parse `...`
2399-
element.type = parseType();
2400-
parseTypeMemberSemicolon();
2401-
return finishNode(element);
2402-
}
2403-
24042387
function isStartOfConstructSignature() {
24052388
nextToken();
24062389
return token() === SyntaxKind.OpenParenToken || token() === SyntaxKind.LessThanToken;

src/compiler/types.ts

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -321,8 +321,6 @@ namespace ts {
321321
PropertyAssignment,
322322
ShorthandPropertyAssignment,
323323
SpreadElementExpression,
324-
SpreadTypeElement,
325-
326324

327325
// Enum
328326
EnumMember,
@@ -665,11 +663,6 @@ namespace ts {
665663
initializer?: Expression; // Optional initializer
666664
}
667665

668-
// @kind(SyntaxKind.SpreadTypeElement)
669-
export interface SpreadTypeElement extends TypeElement {
670-
type: TypeNode;
671-
}
672-
673666
// @kind(SyntaxKind.PropertyDeclaration)
674667
export interface PropertyDeclaration extends ClassElement {
675668
kind: SyntaxKind.PropertyDeclaration;
@@ -2522,7 +2515,7 @@ namespace ts {
25222515
Merged = 0x02000000, // Merged symbol (created during program binding)
25232516
Transient = 0x04000000, // Transient symbol (created during type check)
25242517
Prototype = 0x08000000, // Prototype property (no source representation)
2525-
SyntheticProperty = 0x10000000, // Property in union, intersection or spread type
2518+
SyntheticProperty = 0x10000000, // Property in union or intersection type
25262519
Optional = 0x20000000, // Optional property
25272520
ExportStar = 0x40000000, // Export * declaration
25282521

@@ -2712,7 +2705,6 @@ namespace ts {
27122705
ContainsObjectLiteral = 1 << 22, // Type is or contains object literal type
27132706
/* @internal */
27142707
ContainsAnyFunctionType = 1 << 23, // Type is or contains object literal type
2715-
Spread = 1 << 24, // Spread types
27162708

27172709
/* @internal */
27182710
Nullable = Undefined | Null,
@@ -2730,12 +2722,12 @@ namespace ts {
27302722
BooleanLike = Boolean | BooleanLiteral,
27312723
EnumLike = Enum | EnumLiteral,
27322724
UnionOrIntersection = Union | Intersection,
2733-
StructuredType = Object | Union | Intersection | Spread,
2725+
StructuredType = Object | Union | Intersection,
27342726
StructuredOrTypeParameter = StructuredType | TypeParameter,
27352727

27362728
// 'Narrowable' types are types where narrowing actually narrows.
27372729
// This *should* be every type other than null, undefined, void, and never
2738-
Narrowable = Any | StructuredType | TypeParameter | Index | IndexedAccess | StringLike | NumberLike | BooleanLike | ESSymbol | Spread,
2730+
Narrowable = Any | StructuredType | TypeParameter | Index | IndexedAccess | StringLike | NumberLike | BooleanLike | ESSymbol,
27392731
NotUnionOrUnit = Any | ESSymbol | Object,
27402732
/* @internal */
27412733
RequiresWidening = ContainsWideningType | ContainsObjectLiteral,
@@ -2850,12 +2842,6 @@ namespace ts {
28502842

28512843
export type StructuredType = ObjectType | UnionType | IntersectionType;
28522844

2853-
/* @internal */
2854-
export interface SpreadType extends Type {
2855-
left: SpreadType | ResolvedType;
2856-
right: TypeParameter | IntersectionType | IndexType | IndexedAccessType | ResolvedType;
2857-
}
2858-
28592845
/* @internal */
28602846
// An instantiated anonymous type has a target and a mapper
28612847
export interface AnonymousType extends ObjectType {
@@ -2869,7 +2855,7 @@ namespace ts {
28692855
}
28702856

28712857
/* @internal */
2872-
// Resolved object, spread, union, or intersection type
2858+
// Resolved object, union, or intersection type
28732859
export interface ResolvedType extends ObjectType, UnionOrIntersectionType {
28742860
members: SymbolTable; // Properties by name
28752861
properties: Symbol[]; // Properties

src/lib/es2015.core.d.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ interface ObjectConstructor {
278278
* @param target The target object to copy to.
279279
* @param source The source object from which to copy properties.
280280
*/
281-
assign<T, U>(target: T, source: U): { ...T, ...U };
281+
assign<T, U>(target: T, source: U): T & U;
282282

283283
/**
284284
* Copy the values of all of the enumerable own properties from one or more source objects to a
@@ -287,7 +287,7 @@ interface ObjectConstructor {
287287
* @param source1 The first source object from which to copy properties.
288288
* @param source2 The second source object from which to copy properties.
289289
*/
290-
assign<T, U, V>(target: T, source1: U, source2: V): { ...T, ...U, ...V };
290+
assign<T, U, V>(target: T, source1: U, source2: V): T & U & V;
291291

292292
/**
293293
* Copy the values of all of the enumerable own properties from one or more source objects to a
@@ -297,7 +297,7 @@ interface ObjectConstructor {
297297
* @param source2 The second source object from which to copy properties.
298298
* @param source3 The third source object from which to copy properties.
299299
*/
300-
assign<T, U, V, W>(target: T, source1: U, source2: V, source3: W): { ...T, ...U, ...V, ...W };
300+
assign<T, U, V, W>(target: T, source1: U, source2: V, source3: W): T & U & V & W;
301301

302302
/**
303303
* Copy the values of all of the enumerable own properties from one or more source objects to a

tests/baselines/reference/objectSpread.js

Lines changed: 2 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,8 @@ let getter: { a: number, c: number } =
3535
{ ...op, c: 7 }
3636
getter.a = 12;
3737

38-
// null, undefined, functions and primitives result in { }
39-
let spreadNull = { ...null };
40-
let spreadUndefind = { ...undefined };
41-
let spreadNum = { ...12 };
42-
let spreadBool = { ...false };
38+
// functions result in { }
4339
let spreadFunc = { ...(function () { }) };
44-
let spreadStr = { ...'foo' };
4540

4641
// methods are not enumerable
4742
class C { p = 1; m() { } }
@@ -80,22 +75,6 @@ let computedAfter: { a: number, b: string, "at the end": number } =
8075
let a = 12;
8176
let shortCutted: { a: number, b: string } = { ...o, a }
8277

83-
// generics
84-
function f<T, U>(t: T, u: U): { ...T, ...U, id: string } {
85-
return { ...t, ...u, id: 'id' };
86-
}
87-
let exclusive: { id: string, a: number, b: string, c: string, d: boolean } =
88-
f({ a: 1, b: 'yes' }, { c: 'no', d: false })
89-
let overlap: { id: string, a: number, b: string } =
90-
f({ a: 1 }, { a: 2, b: 'extra' })
91-
let overlapConflict: { id:string, a: string } =
92-
f({ a: 1 }, { a: 'mismatch' })
93-
let overwriteId: { id: string, a: number, c: number, d: string } =
94-
f({ a: 1, id: true }, { c: 1, d: 'no' })
95-
96-
class D { m() { }; q = 2; }
97-
let classesAreWrong: { id: string, ...C, ...D } =
98-
f(new C(), new D())
9978

10079

10180
//// [objectSpread.js]
@@ -128,13 +107,8 @@ var propertyNested = __assign({ a: __assign({}, o) });
128107
var op = { get a() { return 6; } };
129108
var getter = __assign({}, op, { c: 7 });
130109
getter.a = 12;
131-
// null, undefined, functions and primitives result in { }
132-
var spreadNull = __assign({}, null);
133-
var spreadUndefind = __assign({}, undefined);
134-
var spreadNum = __assign({}, 12);
135-
var spreadBool = __assign({}, false);
110+
// functions result in { }
136111
var spreadFunc = __assign({}, (function () { }));
137-
var spreadStr = __assign({}, 'foo');
138112
// methods are not enumerable
139113
var C = (function () {
140114
function C() {
@@ -167,21 +141,4 @@ var computedAfter = __assign({}, o, (_c = { b: 'yeah' }, _c['at the end'] = 14,
167141
// shortcut syntax
168142
var a = 12;
169143
var shortCutted = __assign({}, o, { a: a });
170-
// generics
171-
function f(t, u) {
172-
return __assign({}, t, u, { id: 'id' });
173-
}
174-
var exclusive = f({ a: 1, b: 'yes' }, { c: 'no', d: false });
175-
var overlap = f({ a: 1 }, { a: 2, b: 'extra' });
176-
var overlapConflict = f({ a: 1 }, { a: 'mismatch' });
177-
var overwriteId = f({ a: 1, id: true }, { c: 1, d: 'no' });
178-
var D = (function () {
179-
function D() {
180-
this.q = 2;
181-
}
182-
D.prototype.m = function () { };
183-
;
184-
return D;
185-
}());
186-
var classesAreWrong = f(new C(), new D());
187144
var _a, _b, _c;

0 commit comments

Comments
 (0)