Skip to content

Commit 60d5195

Browse files
committed
Update baselines, fix assignment check for object rest.
1 parent 4577227 commit 60d5195

File tree

11 files changed

+27
-56
lines changed

11 files changed

+27
-56
lines changed

Jakefile.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -640,7 +640,7 @@ task("importDefinitelyTypedTests", [importDefinitelyTypedTestsJs], function () {
640640

641641
// Local target to build the compiler and services
642642
var tscFile = path.join(builtLocalDirectory, compilerFilename);
643-
compileFile(tscFile, compilerSources, [builtLocalDirectory, copyright].concat(compilerSources), [copyright], /*useBuiltCompiler:*/ false);
643+
compileFile(tscFile, compilerSources, [builtLocalDirectory, copyright].concat(compilerSources), [copyright], /*useBuiltCompiler:*/ false, { noMapRoot: true });
644644

645645
var servicesFile = path.join(builtLocalDirectory, "typescriptServices.js");
646646
var servicesFileInBrowserTest = path.join(builtLocalDirectory, "typescriptServicesInBrowserTest.js");

src/compiler/checker.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}
@@ -14199,9 +14199,7 @@ namespace ts {
1419914199
}
1420014200
}
1420114201
else if (property.kind === SyntaxKind.SpreadAssignment) {
14202-
if (property.expression.kind !== SyntaxKind.Identifier) {
14203-
error(property.expression, Diagnostics.An_object_rest_element_must_be_an_identifier);
14204-
}
14202+
checkReferenceExpression(property.expression, Diagnostics.The_target_of_an_object_rest_assignment_must_be_a_variable_or_a_property_access);
1420514203
}
1420614204
else {
1420714205
error(property, Diagnostics.Property_assignment_expected);

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: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3284,9 +3284,9 @@ namespace ts {
32843284
return bindingElement.right;
32853285
}
32863286

3287-
if (isSpreadExpression(bindingElement) && isBindingOrAssignmentElement(bindingElement.expression)) {
3287+
if (isSpreadExpression(bindingElement)) {
32883288
// Recovery consistent with existing emit.
3289-
return getInitializerOfBindingOrAssignmentElement(bindingElement.expression);
3289+
return getInitializerOfBindingOrAssignmentElement(<BindingOrAssignmentElement>bindingElement.expression);
32903290
}
32913291
}
32923292

@@ -3327,9 +3327,7 @@ namespace ts {
33273327
// `b.c` in `({ a: b.c = 1 } = ...)`
33283328
// `b[0]` in `({ a: b[0] } = ...)`
33293329
// `b[0]` in `({ a: b[0] = 1 } = ...)`
3330-
return isBindingOrAssignmentElement(bindingElement.initializer)
3331-
? getTargetOfBindingOrAssignmentElement(bindingElement.initializer)
3332-
: undefined;
3330+
return getTargetOfBindingOrAssignmentElement(<BindingOrAssignmentElement>bindingElement.initializer);
33333331

33343332
case SyntaxKind.ShorthandPropertyAssignment:
33353333
// `a` in `({ a } = ...)`
@@ -3338,9 +3336,7 @@ namespace ts {
33383336

33393337
case SyntaxKind.SpreadAssignment:
33403338
// `a` in `({ ...a } = ...)`
3341-
return isBindingOrAssignmentElement(bindingElement.expression)
3342-
? getTargetOfBindingOrAssignmentElement(bindingElement.expression)
3343-
: undefined;
3339+
return getTargetOfBindingOrAssignmentElement(<BindingOrAssignmentElement>bindingElement.expression);
33443340
}
33453341

33463342
// no target
@@ -3353,16 +3349,12 @@ namespace ts {
33533349
// `[a]` in `[[a] = 1] = ...`
33543350
// `a.b` in `[a.b = 1] = ...`
33553351
// `a[0]` in `[a[0] = 1] = ...`
3356-
return isBindingOrAssignmentElement(bindingElement.left)
3357-
? getTargetOfBindingOrAssignmentElement(bindingElement.left)
3358-
: undefined;
3352+
return getTargetOfBindingOrAssignmentElement(<BindingOrAssignmentElement>bindingElement.left);
33593353
}
33603354

33613355
if (isSpreadExpression(bindingElement)) {
33623356
// `a` in `[...a] = ...`
3363-
return isBindingOrAssignmentElement(bindingElement.expression)
3364-
? getTargetOfBindingOrAssignmentElement(bindingElement.expression)
3365-
: undefined;
3357+
return getTargetOfBindingOrAssignmentElement(<BindingOrAssignmentElement>bindingElement.expression);
33663358
}
33673359

33683360
// `a` in `[a] = ...`
@@ -3442,18 +3434,14 @@ namespace ts {
34423434
case SyntaxKind.ArrayLiteralExpression:
34433435
// `a` in `{a}`
34443436
// `a` in `[a]`
3445-
return map(name.elements, convertToBindingOrAssignmentElement);
3437+
return <BindingOrAssignmentElement[]>name.elements;
34463438

34473439
case SyntaxKind.ObjectLiteralExpression:
34483440
// `a` in `{a}`
3449-
return filter(name.properties, isBindingOrAssignmentElement);
3441+
return <BindingOrAssignmentElement[]>name.properties;
34503442
}
34513443
}
34523444

3453-
function convertToBindingOrAssignmentElement(node: Node) {
3454-
return isBindingOrAssignmentElement(node) ? node : createOmittedExpression(node);
3455-
}
3456-
34573445
export function convertToArrayAssignmentElement(element: BindingOrAssignmentElement) {
34583446
if (isBindingElement(element)) {
34593447
if (element.dotDotDotToken) {

src/compiler/transformers/destructuring.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,10 @@ namespace ts {
292292
// can perform the ObjectRest destructuring in a different declaration
293293
if (element.transformFlags & TransformFlags.ContainsObjectRest) {
294294
const temp = createTempVariable(/*recordTempVariable*/ undefined);
295+
if (!host.recordTempVariablesInLine) {
296+
host.context.hoistVariableDeclaration(temp);
297+
}
298+
295299
restContainingElements = append(restContainingElements, <[Identifier, BindingOrAssignmentElement]>[temp, element]);
296300
bindingElements = append(bindingElements, host.createArrayBindingOrAssignmentElement(temp));
297301
}

src/compiler/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -734,7 +734,7 @@ namespace ts {
734734
elements: NodeArray<ArrayBindingElement>;
735735
}
736736

737-
export type BindingPattern = (ObjectBindingPattern | ArrayBindingPattern) & { elements: NodeArray<ArrayBindingElement>; };
737+
export type BindingPattern = ObjectBindingPattern | ArrayBindingPattern;
738738

739739
export type ArrayBindingElement = BindingElement | OmittedExpression;
740740

src/compiler/utilities.ts

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3975,29 +3975,6 @@ namespace ts {
39753975
return false;
39763976
}
39773977

3978-
/**
3979-
* Determines whether a node is a BindingOrAssignmentElement
3980-
*/
3981-
export function isBindingOrAssignmentElement(node: Node): node is BindingOrAssignmentElement {
3982-
switch (node.kind) {
3983-
case SyntaxKind.VariableDeclaration:
3984-
case SyntaxKind.Parameter:
3985-
case SyntaxKind.BindingElement:
3986-
case SyntaxKind.PropertyAssignment:
3987-
case SyntaxKind.ShorthandPropertyAssignment:
3988-
case SyntaxKind.SpreadAssignment:
3989-
case SyntaxKind.OmittedExpression:
3990-
case SyntaxKind.ArrayLiteralExpression:
3991-
case SyntaxKind.ObjectLiteralExpression:
3992-
case SyntaxKind.PropertyAccessExpression:
3993-
case SyntaxKind.ElementAccessExpression:
3994-
case SyntaxKind.Identifier:
3995-
case SyntaxKind.SpreadElement:
3996-
return true;
3997-
}
3998-
return isAssignmentExpression(node, /*excludeCompoundAssignment*/ true);
3999-
}
4000-
40013978
/**
40023979
* Determines whether a node is a BindingOrAssignmentPattern
40033980
*/

src/harness/runner.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ function createRunner(kind: TestRunnerKind): RunnerBase {
6161
}
6262
}
6363

64+
if (Harness.IO.tryEnableSourceMapsForHost && /^development$/i.test(Harness.IO.getEnvironmentVariable("NODE_ENV"))) {
65+
Harness.IO.tryEnableSourceMapsForHost();
66+
}
67+
6468
// users can define tests to run in mytest.config that will override cmd line args, otherwise use cmd line args (test.config), otherwise no options
6569

6670
const mytestconfigFileName = "mytest.config";

tests/baselines/reference/objectRestAssignment.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,6 @@ let complex;
3030
// should be:
3131
let overEmit;
3232
// var _g = overEmit.a, [_h, ...y] = _g, nested2 = __rest(_h, []), _j = overEmit.b, { z } = _j, c = __rest(_j, ["z"]), rest2 = __rest(overEmit, ["a", "b"]);
33-
var _b = overEmit.a, [_c, ...y] = _b, nested2 = __rest(_c, []), _d = overEmit.b, { z } = _d, c = __rest(_d, ["z"]), rest2 = __rest(overEmit, ["a", "b"]);
34-
(_e = overEmit.a, [_f, ...y] = _e, nested2 = __rest(_f, []), _g = overEmit.b, { z } = _g, c = __rest(_g, ["z"]), rest2 = __rest(overEmit, ["a", "b"]));
35-
var _a, _e, _g;
33+
var [_b, ...y] = overEmit.a, nested2 = __rest(_b, []), _c = overEmit.b, { z } = _c, c = __rest(_c, ["z"]), rest2 = __rest(overEmit, ["a", "b"]);
34+
([_d, ...y] = overEmit.a, nested2 = __rest(_d, []), _e = overEmit.b, { z } = _e, c = __rest(_e, ["z"]), rest2 = __rest(overEmit, ["a", "b"]));
35+
var _a, _d, _e;

tests/baselines/reference/objectRestNegative.errors.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
tests/cases/conformance/types/rest/objectRestNegative.ts(2,10): error TS2462: A rest element must be last in a destructuring pattern
22
tests/cases/conformance/types/rest/objectRestNegative.ts(3,31): error TS2462: A rest element must be last in a destructuring pattern
33
tests/cases/conformance/types/rest/objectRestNegative.ts(6,17): error TS2700: Rest types may only be created from object types.
4-
tests/cases/conformance/types/rest/objectRestNegative.ts(11,9): error TS2701: An object rest element must be an identifier.
4+
tests/cases/conformance/types/rest/objectRestNegative.ts(11,9): error TS2701: The target of an object rest assignment must be a variable or a property access.
55

66

77
==== tests/cases/conformance/types/rest/objectRestNegative.ts (4 errors) ====
@@ -23,5 +23,5 @@ tests/cases/conformance/types/rest/objectRestNegative.ts(11,9): error TS2701: An
2323
let rest: { b: string }
2424
({a, ...rest.b + rest.b} = o);
2525
~~~~~~~~~~~~~~~
26-
!!! error TS2701: An object rest element must be an identifier.
26+
!!! error TS2701: The target of an object rest assignment must be a variable or a property access.
2727

0 commit comments

Comments
 (0)