Skip to content

Commit ec95f4f

Browse files
committed
Merge branch 'streamlineDestructuring' into emitHelper
2 parents 346d488 + ba4f52c commit ec95f4f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+3030
-2582
lines changed

src/compiler/binder.ts

Lines changed: 99 additions & 51 deletions
Large diffs are not rendered by default.

src/compiler/checker.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3030,7 +3030,7 @@ namespace ts {
30303030
}
30313031

30323032
function isComputedNonLiteralName(name: PropertyName): boolean {
3033-
return name.kind === SyntaxKind.ComputedPropertyName && !isStringOrNumericLiteral((<ComputedPropertyName>name).expression.kind);
3033+
return name.kind === SyntaxKind.ComputedPropertyName && !isStringOrNumericLiteral((<ComputedPropertyName>name).expression);
30343034
}
30353035

30363036
function getRestType(source: Type, properties: PropertyName[], symbol: Symbol): Type {
@@ -3081,7 +3081,7 @@ namespace ts {
30813081
}
30823082
const literalMembers: PropertyName[] = [];
30833083
for (const element of pattern.elements) {
3084-
if (element.kind !== SyntaxKind.OmittedExpression && !(element as BindingElement).dotDotDotToken) {
3084+
if (!(element as BindingElement).dotDotDotToken) {
30853085
literalMembers.push(element.propertyName || element.name as Identifier);
30863086
}
30873087
}
@@ -8927,7 +8927,7 @@ namespace ts {
89278927
return type;
89288928
}
89298929

8930-
function getTypeOfDestructuredProperty(type: Type, name: Identifier | LiteralExpression | ComputedPropertyName) {
8930+
function getTypeOfDestructuredProperty(type: Type, name: PropertyName) {
89318931
const text = getTextOfPropertyName(name);
89328932
return getTypeOfPropertyOfType(type, text) ||
89338933
isNumericLiteralName(text) && getIndexTypeOfType(type, IndexKind.Number) ||
@@ -14221,9 +14221,7 @@ namespace ts {
1422114221
}
1422214222
}
1422314223
else if (property.kind === SyntaxKind.SpreadAssignment) {
14224-
if (property.expression.kind !== SyntaxKind.Identifier) {
14225-
error(property.expression, Diagnostics.An_object_rest_element_must_be_an_identifier);
14226-
}
14224+
checkReferenceExpression(property.expression, Diagnostics.The_target_of_an_object_rest_assignment_must_be_a_variable_or_a_property_access);
1422714225
}
1422814226
else {
1422914227
error(property, Diagnostics.Property_assignment_expected);

src/compiler/core.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -826,6 +826,13 @@ namespace ts {
826826
}
827827
}
828828

829+
export function appendProperty<T>(map: Map<T>, key: string | number, value: T): Map<T> {
830+
if (key === undefined || value === undefined) return map;
831+
if (map === undefined) map = createMap<T>();
832+
map[key] = value;
833+
return map;
834+
}
835+
829836
export function assign<T1 extends MapLike<{}>, T2, T3>(t: T1, arg1: T2, arg2: T3): T1 & T2 & T3;
830837
export function assign<T1 extends MapLike<{}>, T2>(t: T1, arg1: T2): T1 & T2;
831838
export function assign<T1 extends MapLike<{}>>(t: T1, ...args: any[]): any;

src/compiler/diagnosticMessages.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1991,7 +1991,7 @@
19911991
"category": "Error",
19921992
"code": 2700
19931993
},
1994-
"An object rest element must be an identifier.": {
1994+
"The target of an object rest assignment must be a variable or a property access.": {
19951995
"category": "Error",
19961996
"code": 2701
19971997
},

src/compiler/factory.ts

Lines changed: 267 additions & 505 deletions
Large diffs are not rendered by default.

src/compiler/parser.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1168,7 +1168,7 @@ namespace ts {
11681168

11691169
function parsePropertyNameWorker(allowComputedPropertyNames: boolean): PropertyName {
11701170
if (token() === SyntaxKind.StringLiteral || token() === SyntaxKind.NumericLiteral) {
1171-
return parseLiteralNode(/*internName*/ true);
1171+
return <StringLiteral | NumericLiteral>parseLiteralNode(/*internName*/ true);
11721172
}
11731173
if (allowComputedPropertyNames && token() === SyntaxKind.OpenBracketToken) {
11741174
return parseComputedPropertyName();
@@ -5514,7 +5514,7 @@ namespace ts {
55145514
node.flags |= NodeFlags.GlobalAugmentation;
55155515
}
55165516
else {
5517-
node.name = parseLiteralNode(/*internName*/ true);
5517+
node.name = <StringLiteral>parseLiteralNode(/*internName*/ true);
55185518
}
55195519

55205520
if (token() === SyntaxKind.OpenBraceToken) {

src/compiler/transformer.ts

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -236,20 +236,6 @@ namespace ts {
236236
}
237237
}
238238

239-
/** Suspends the current lexical environment, usually after visiting a parameter list. */
240-
function suspendLexicalEnvironment(): void {
241-
Debug.assert(!scopeModificationDisabled, "Cannot suspend a lexical environment during the print phase.");
242-
Debug.assert(!lexicalEnvironmentSuspended, "Lexical environment is already suspended.");
243-
lexicalEnvironmentSuspended = true;
244-
}
245-
246-
/** Resumes a suspended lexical environment, usually before visiting a function body. */
247-
function resumeLexicalEnvironment(): void {
248-
Debug.assert(!scopeModificationDisabled, "Cannot resume a lexical environment during the print phase.");
249-
Debug.assert(lexicalEnvironmentSuspended, "Lexical environment is not suspended suspended.");
250-
lexicalEnvironmentSuspended = false;
251-
}
252-
253239
/**
254240
* Starts a new lexical environment. Any existing hoisted variable or function declarations
255241
* are pushed onto a stack, and the related storage variables are reset.
@@ -269,6 +255,20 @@ namespace ts {
269255
lexicalEnvironmentFunctionDeclarations = undefined;
270256
}
271257

258+
/** Suspends the current lexical environment, usually after visiting a parameter list. */
259+
function suspendLexicalEnvironment(): void {
260+
Debug.assert(!scopeModificationDisabled, "Cannot suspend a lexical environment during the print phase.");
261+
Debug.assert(!lexicalEnvironmentSuspended, "Lexical environment is already suspended.");
262+
lexicalEnvironmentSuspended = true;
263+
}
264+
265+
/** Resumes a suspended lexical environment, usually before visiting a function body. */
266+
function resumeLexicalEnvironment(): void {
267+
Debug.assert(!scopeModificationDisabled, "Cannot resume a lexical environment during the print phase.");
268+
Debug.assert(lexicalEnvironmentSuspended, "Lexical environment is not suspended suspended.");
269+
lexicalEnvironmentSuspended = false;
270+
}
271+
272272
/**
273273
* Ends a lexical environment. The previous set of hoisted declarations are restored and
274274
* any hoisted declarations added in this environment are returned.
@@ -306,7 +306,6 @@ namespace ts {
306306
lexicalEnvironmentVariableDeclarationsStack = [];
307307
lexicalEnvironmentFunctionDeclarationsStack = [];
308308
}
309-
310309
return statements;
311310
}
312311

0 commit comments

Comments
 (0)