From 60d5195112ee7ab80ba01a3fbd874b7566158c01 Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Mon, 14 Nov 2016 16:56:59 -0800 Subject: [PATCH] Update baselines, fix assignment check for object rest. --- Jakefile.js | 2 +- src/compiler/checker.ts | 6 ++-- src/compiler/diagnosticMessages.json | 2 +- src/compiler/factory.ts | 28 ++++++------------- src/compiler/transformers/destructuring.ts | 4 +++ src/compiler/types.ts | 2 +- src/compiler/utilities.ts | 23 --------------- src/harness/runner.ts | 4 +++ .../reference/objectRestAssignment.js | 6 ++-- .../reference/objectRestNegative.errors.txt | 4 +-- .../baselines/reference/objectRestNegative.js | 2 +- 11 files changed, 27 insertions(+), 56 deletions(-) diff --git a/Jakefile.js b/Jakefile.js index 2e5d660c4f..132a99e508 100644 --- a/Jakefile.js +++ b/Jakefile.js @@ -640,7 +640,7 @@ task("importDefinitelyTypedTests", [importDefinitelyTypedTestsJs], function () { // Local target to build the compiler and services var tscFile = path.join(builtLocalDirectory, compilerFilename); -compileFile(tscFile, compilerSources, [builtLocalDirectory, copyright].concat(compilerSources), [copyright], /*useBuiltCompiler:*/ false); +compileFile(tscFile, compilerSources, [builtLocalDirectory, copyright].concat(compilerSources), [copyright], /*useBuiltCompiler:*/ false, { noMapRoot: true }); var servicesFile = path.join(builtLocalDirectory, "typescriptServices.js"); var servicesFileInBrowserTest = path.join(builtLocalDirectory, "typescriptServicesInBrowserTest.js"); diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 396715bfa4..730a435e67 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -3081,7 +3081,7 @@ namespace ts { } const literalMembers: PropertyName[] = []; for (const element of pattern.elements) { - if (element.kind !== SyntaxKind.OmittedExpression && !(element as BindingElement).dotDotDotToken) { + if (!(element as BindingElement).dotDotDotToken) { literalMembers.push(element.propertyName || element.name as Identifier); } } @@ -14199,9 +14199,7 @@ namespace ts { } } else if (property.kind === SyntaxKind.SpreadAssignment) { - if (property.expression.kind !== SyntaxKind.Identifier) { - error(property.expression, Diagnostics.An_object_rest_element_must_be_an_identifier); - } + checkReferenceExpression(property.expression, Diagnostics.The_target_of_an_object_rest_assignment_must_be_a_variable_or_a_property_access); } else { error(property, Diagnostics.Property_assignment_expected); diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index be33335021..a163a3bb64 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -1991,7 +1991,7 @@ "category": "Error", "code": 2700 }, - "An object rest element must be an identifier.": { + "The target of an object rest assignment must be a variable or a property access.": { "category": "Error", "code": 2701 }, diff --git a/src/compiler/factory.ts b/src/compiler/factory.ts index c107263b9d..d690eb84c7 100644 --- a/src/compiler/factory.ts +++ b/src/compiler/factory.ts @@ -3284,9 +3284,9 @@ namespace ts { return bindingElement.right; } - if (isSpreadExpression(bindingElement) && isBindingOrAssignmentElement(bindingElement.expression)) { + if (isSpreadExpression(bindingElement)) { // Recovery consistent with existing emit. - return getInitializerOfBindingOrAssignmentElement(bindingElement.expression); + return getInitializerOfBindingOrAssignmentElement(bindingElement.expression); } } @@ -3327,9 +3327,7 @@ namespace ts { // `b.c` in `({ a: b.c = 1 } = ...)` // `b[0]` in `({ a: b[0] } = ...)` // `b[0]` in `({ a: b[0] = 1 } = ...)` - return isBindingOrAssignmentElement(bindingElement.initializer) - ? getTargetOfBindingOrAssignmentElement(bindingElement.initializer) - : undefined; + return getTargetOfBindingOrAssignmentElement(bindingElement.initializer); case SyntaxKind.ShorthandPropertyAssignment: // `a` in `({ a } = ...)` @@ -3338,9 +3336,7 @@ namespace ts { case SyntaxKind.SpreadAssignment: // `a` in `({ ...a } = ...)` - return isBindingOrAssignmentElement(bindingElement.expression) - ? getTargetOfBindingOrAssignmentElement(bindingElement.expression) - : undefined; + return getTargetOfBindingOrAssignmentElement(bindingElement.expression); } // no target @@ -3353,16 +3349,12 @@ namespace ts { // `[a]` in `[[a] = 1] = ...` // `a.b` in `[a.b = 1] = ...` // `a[0]` in `[a[0] = 1] = ...` - return isBindingOrAssignmentElement(bindingElement.left) - ? getTargetOfBindingOrAssignmentElement(bindingElement.left) - : undefined; + return getTargetOfBindingOrAssignmentElement(bindingElement.left); } if (isSpreadExpression(bindingElement)) { // `a` in `[...a] = ...` - return isBindingOrAssignmentElement(bindingElement.expression) - ? getTargetOfBindingOrAssignmentElement(bindingElement.expression) - : undefined; + return getTargetOfBindingOrAssignmentElement(bindingElement.expression); } // `a` in `[a] = ...` @@ -3442,18 +3434,14 @@ namespace ts { case SyntaxKind.ArrayLiteralExpression: // `a` in `{a}` // `a` in `[a]` - return map(name.elements, convertToBindingOrAssignmentElement); + return name.elements; case SyntaxKind.ObjectLiteralExpression: // `a` in `{a}` - return filter(name.properties, isBindingOrAssignmentElement); + return name.properties; } } - function convertToBindingOrAssignmentElement(node: Node) { - return isBindingOrAssignmentElement(node) ? node : createOmittedExpression(node); - } - export function convertToArrayAssignmentElement(element: BindingOrAssignmentElement) { if (isBindingElement(element)) { if (element.dotDotDotToken) { diff --git a/src/compiler/transformers/destructuring.ts b/src/compiler/transformers/destructuring.ts index b8da29ae29..433305ca6b 100644 --- a/src/compiler/transformers/destructuring.ts +++ b/src/compiler/transformers/destructuring.ts @@ -292,6 +292,10 @@ namespace ts { // can perform the ObjectRest destructuring in a different declaration if (element.transformFlags & TransformFlags.ContainsObjectRest) { const temp = createTempVariable(/*recordTempVariable*/ undefined); + if (!host.recordTempVariablesInLine) { + host.context.hoistVariableDeclaration(temp); + } + restContainingElements = append(restContainingElements, <[Identifier, BindingOrAssignmentElement]>[temp, element]); bindingElements = append(bindingElements, host.createArrayBindingOrAssignmentElement(temp)); } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 52b8eeb0fd..8a6e74030d 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -734,7 +734,7 @@ namespace ts { elements: NodeArray; } - export type BindingPattern = (ObjectBindingPattern | ArrayBindingPattern) & { elements: NodeArray; }; + export type BindingPattern = ObjectBindingPattern | ArrayBindingPattern; export type ArrayBindingElement = BindingElement | OmittedExpression; diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 52efb88f8c..317cad49de 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -3975,29 +3975,6 @@ namespace ts { return false; } - /** - * Determines whether a node is a BindingOrAssignmentElement - */ - export function isBindingOrAssignmentElement(node: Node): node is BindingOrAssignmentElement { - switch (node.kind) { - case SyntaxKind.VariableDeclaration: - case SyntaxKind.Parameter: - case SyntaxKind.BindingElement: - case SyntaxKind.PropertyAssignment: - case SyntaxKind.ShorthandPropertyAssignment: - case SyntaxKind.SpreadAssignment: - case SyntaxKind.OmittedExpression: - case SyntaxKind.ArrayLiteralExpression: - case SyntaxKind.ObjectLiteralExpression: - case SyntaxKind.PropertyAccessExpression: - case SyntaxKind.ElementAccessExpression: - case SyntaxKind.Identifier: - case SyntaxKind.SpreadElement: - return true; - } - return isAssignmentExpression(node, /*excludeCompoundAssignment*/ true); - } - /** * Determines whether a node is a BindingOrAssignmentPattern */ diff --git a/src/harness/runner.ts b/src/harness/runner.ts index 3db1da627b..3ad6269e52 100644 --- a/src/harness/runner.ts +++ b/src/harness/runner.ts @@ -61,6 +61,10 @@ function createRunner(kind: TestRunnerKind): RunnerBase { } } +if (Harness.IO.tryEnableSourceMapsForHost && /^development$/i.test(Harness.IO.getEnvironmentVariable("NODE_ENV"))) { + Harness.IO.tryEnableSourceMapsForHost(); +} + // 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 const mytestconfigFileName = "mytest.config"; diff --git a/tests/baselines/reference/objectRestAssignment.js b/tests/baselines/reference/objectRestAssignment.js index d4d266d3fe..50d38c178a 100644 --- a/tests/baselines/reference/objectRestAssignment.js +++ b/tests/baselines/reference/objectRestAssignment.js @@ -30,6 +30,6 @@ let complex; // should be: let overEmit; // var _g = overEmit.a, [_h, ...y] = _g, nested2 = __rest(_h, []), _j = overEmit.b, { z } = _j, c = __rest(_j, ["z"]), rest2 = __rest(overEmit, ["a", "b"]); -var _b = overEmit.a, [_c, ...y] = _b, nested2 = __rest(_c, []), _d = overEmit.b, { z } = _d, c = __rest(_d, ["z"]), rest2 = __rest(overEmit, ["a", "b"]); -(_e = overEmit.a, [_f, ...y] = _e, nested2 = __rest(_f, []), _g = overEmit.b, { z } = _g, c = __rest(_g, ["z"]), rest2 = __rest(overEmit, ["a", "b"])); -var _a, _e, _g; +var [_b, ...y] = overEmit.a, nested2 = __rest(_b, []), _c = overEmit.b, { z } = _c, c = __rest(_c, ["z"]), rest2 = __rest(overEmit, ["a", "b"]); +([_d, ...y] = overEmit.a, nested2 = __rest(_d, []), _e = overEmit.b, { z } = _e, c = __rest(_e, ["z"]), rest2 = __rest(overEmit, ["a", "b"])); +var _a, _d, _e; diff --git a/tests/baselines/reference/objectRestNegative.errors.txt b/tests/baselines/reference/objectRestNegative.errors.txt index b8144e3209..793a7d31fc 100644 --- a/tests/baselines/reference/objectRestNegative.errors.txt +++ b/tests/baselines/reference/objectRestNegative.errors.txt @@ -1,7 +1,7 @@ tests/cases/conformance/types/rest/objectRestNegative.ts(2,10): error TS2462: A rest element must be last in a destructuring pattern tests/cases/conformance/types/rest/objectRestNegative.ts(3,31): error TS2462: A rest element must be last in a destructuring pattern tests/cases/conformance/types/rest/objectRestNegative.ts(6,17): error TS2700: Rest types may only be created from object types. -tests/cases/conformance/types/rest/objectRestNegative.ts(11,9): error TS2701: An object rest element must be an identifier. +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. ==== 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 let rest: { b: string } ({a, ...rest.b + rest.b} = o); ~~~~~~~~~~~~~~~ -!!! error TS2701: An object rest element must be an identifier. +!!! error TS2701: The target of an object rest assignment must be a variable or a property access. \ No newline at end of file diff --git a/tests/baselines/reference/objectRestNegative.js b/tests/baselines/reference/objectRestNegative.js index 76e3cd765d..c9f0dba32c 100644 --- a/tests/baselines/reference/objectRestNegative.js +++ b/tests/baselines/reference/objectRestNegative.js @@ -29,4 +29,4 @@ function generic(t) { return rest; } var rest; -(a = o.a, o, o); +(a = o.a, o, rest.b + rest.b = __rest(o, ["a"]));