diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 6a112ec06e2d0..3c994fc3fe44e 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -5284,7 +5284,7 @@ module ts { function checkWithStatement(node: WithStatement) { checkExpression(node.expression); - checkSourceElement(node.statement); + error(node.expression, Diagnostics.All_symbols_within_a_with_block_will_be_resolved_to_any); } function checkSwitchStatement(node: SwitchStatement) { diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index 1abf98883468f..8f58d9f30429f 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -123,6 +123,7 @@ module ts { Setters_cannot_return_a_value: { code: 2122, category: DiagnosticCategory.Error, key: "Setters cannot return a value." }, Invalid_left_hand_side_of_assignment_expression: { code: 2130, category: DiagnosticCategory.Error, key: "Invalid left-hand side of assignment expression." }, Subsequent_variable_declarations_must_have_the_same_type_Variable_0_must_be_of_type_1_but_here_has_type_2: { code: 2134, category: DiagnosticCategory.Error, key: "Subsequent variable declarations must have the same type. Variable '{0}' must be of type '{1}', but here has type '{2}'." }, + All_symbols_within_a_with_block_will_be_resolved_to_any: { code: 2135, category: DiagnosticCategory.Error, key: "All symbols within a 'with' block will be resolved to 'any'." }, The_operand_of_an_increment_or_decrement_operator_must_be_a_variable_property_or_indexer: { code: 2139, category: DiagnosticCategory.Error, key: "The operand of an increment or decrement operator must be a variable, property or indexer." }, Overload_signatures_must_all_be_public_or_private: { code: 2150, category: DiagnosticCategory.Error, key: "Overload signatures must all be public or private." }, Overload_signatures_must_all_be_exported_or_not_exported: { code: 2151, category: DiagnosticCategory.Error, key: "Overload signatures must all be exported or not exported." }, diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 58b6d41099842..b418ec7a404c8 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -485,6 +485,10 @@ "category": "Error", "code": 2134 }, + "All symbols within a 'with' block will be resolved to 'any'.": { + "category": "Error", + "code": 2135 + }, "The operand of an increment or decrement operator must be a variable, property or indexer.": { "category": "Error", "code": 2139 diff --git a/tests/baselines/reference/ambientWithStatements.errors.txt b/tests/baselines/reference/ambientWithStatements.errors.txt index f201851049195..9f0927d076512 100644 --- a/tests/baselines/reference/ambientWithStatements.errors.txt +++ b/tests/baselines/reference/ambientWithStatements.errors.txt @@ -1,4 +1,4 @@ -==== tests/cases/compiler/ambientWithStatements.ts (14 errors) ==== +==== tests/cases/compiler/ambientWithStatements.ts (15 errors) ==== declare module M { break; ~~~~~ @@ -52,5 +52,7 @@ with (x) { ~~~~ !!! Statements are not allowed in ambient contexts. + ~ +!!! All symbols within a 'with' block will be resolved to 'any'. } } \ No newline at end of file diff --git a/tests/baselines/reference/arrowFunctionContexts.errors.txt b/tests/baselines/reference/arrowFunctionContexts.errors.txt index 35b52144102be..b768abb8575a8 100644 --- a/tests/baselines/reference/arrowFunctionContexts.errors.txt +++ b/tests/baselines/reference/arrowFunctionContexts.errors.txt @@ -1,8 +1,10 @@ -==== tests/cases/conformance/expressions/functions/arrowFunctionContexts.ts (9 errors) ==== +==== tests/cases/conformance/expressions/functions/arrowFunctionContexts.ts (10 errors) ==== // Arrow function used in with statement with (window) { ~~~~~~ +!!! All symbols within a 'with' block will be resolved to 'any'. + ~~~~~~ !!! Cannot find name 'window'. var p = () => this; } @@ -52,10 +54,10 @@ // Arrow function used in with statement with (window) { ~~~~~~ +!!! All symbols within a 'with' block will be resolved to 'any'. + ~~~~~~ !!! Cannot find name 'window'. var p = () => this; - ~~~~ -!!! 'this' cannot be referenced in a module body. } // Arrow function as argument to super call diff --git a/tests/baselines/reference/arrowFunctionContexts.js b/tests/baselines/reference/arrowFunctionContexts.js index 635de47f40297..24b928c784267 100644 --- a/tests/baselines/reference/arrowFunctionContexts.js +++ b/tests/baselines/reference/arrowFunctionContexts.js @@ -103,9 +103,8 @@ var __extends = this.__extends || function (d, b) { __.prototype = b.prototype; d.prototype = new __(); }; -var _this = this; with (window) { - var p = function () { return _this; }; + var p = function () { return this; }; } var Base = (function () { function Base(n) { @@ -137,9 +136,8 @@ var M; })(M || (M = {})); var M2; (function (M2) { - var _this = this; with (window) { - var p = function () { return _this; }; + var p = function () { return this; }; } var Base = (function () { function Base(n) { diff --git a/tests/baselines/reference/functionExpressionInWithBlock.errors.txt b/tests/baselines/reference/functionExpressionInWithBlock.errors.txt new file mode 100644 index 0000000000000..6a0947e95b2d0 --- /dev/null +++ b/tests/baselines/reference/functionExpressionInWithBlock.errors.txt @@ -0,0 +1,10 @@ +==== tests/cases/compiler/functionExpressionInWithBlock.ts (1 errors) ==== + function x() { + with({}) { + ~~ +!!! All symbols within a 'with' block will be resolved to 'any'. + function f() { + () => this; + } + } + } \ No newline at end of file diff --git a/tests/baselines/reference/functionExpressionInWithBlock.js b/tests/baselines/reference/functionExpressionInWithBlock.js index 2fae2384313e6..f2353412d5cd7 100644 --- a/tests/baselines/reference/functionExpressionInWithBlock.js +++ b/tests/baselines/reference/functionExpressionInWithBlock.js @@ -11,8 +11,7 @@ function x() { function x() { with ({}) { function f() { - var _this = this; - (function () { return _this; }); + (function () { return this; }); } } } diff --git a/tests/baselines/reference/parserStrictMode14.errors.txt b/tests/baselines/reference/parserStrictMode14.errors.txt index 6c5793f2772fa..2291ebd80b767 100644 --- a/tests/baselines/reference/parserStrictMode14.errors.txt +++ b/tests/baselines/reference/parserStrictMode14.errors.txt @@ -1,6 +1,8 @@ -==== tests/cases/conformance/parser/ecmascript5/StrictMode/parserStrictMode14.ts (1 errors) ==== +==== tests/cases/conformance/parser/ecmascript5/StrictMode/parserStrictMode14.ts (2 errors) ==== "use strict"; with (a) { ~ +!!! All symbols within a 'with' block will be resolved to 'any'. + ~ !!! Cannot find name 'a'. } \ No newline at end of file diff --git a/tests/baselines/reference/parserWithStatement1.d.errors.txt b/tests/baselines/reference/parserWithStatement1.d.errors.txt index 8c6efa440cc3d..b56589d2e0076 100644 --- a/tests/baselines/reference/parserWithStatement1.d.errors.txt +++ b/tests/baselines/reference/parserWithStatement1.d.errors.txt @@ -1,7 +1,9 @@ -==== tests/cases/conformance/parser/ecmascript5/Statements/parserWithStatement1.d.ts (2 errors) ==== +==== tests/cases/conformance/parser/ecmascript5/Statements/parserWithStatement1.d.ts (3 errors) ==== with (foo) { ~~~~ !!! Statements are not allowed in ambient contexts. ~~~ +!!! All symbols within a 'with' block will be resolved to 'any'. + ~~~ !!! Cannot find name 'foo'. } \ No newline at end of file diff --git a/tests/baselines/reference/parserWithStatement2.errors.txt b/tests/baselines/reference/parserWithStatement2.errors.txt new file mode 100644 index 0000000000000..aa87edfd36c6c --- /dev/null +++ b/tests/baselines/reference/parserWithStatement2.errors.txt @@ -0,0 +1,5 @@ +==== tests/cases/conformance/parser/ecmascript5/Statements/parserWithStatement2.ts (1 errors) ==== + with (1) + ~ +!!! All symbols within a 'with' block will be resolved to 'any'. + return; \ No newline at end of file diff --git a/tests/baselines/reference/sourceMapValidationStatements.errors.txt b/tests/baselines/reference/sourceMapValidationStatements.errors.txt new file mode 100644 index 0000000000000..4ca4140beba79 --- /dev/null +++ b/tests/baselines/reference/sourceMapValidationStatements.errors.txt @@ -0,0 +1,86 @@ +==== tests/cases/compiler/sourceMapValidationStatements.ts (1 errors) ==== + function f() { + var y; + var x = 0; + for (var i = 0; i < 10; i++) { + x += i; + x *= 0; + } + if (x > 17) { + x /= 9; + } else { + x += 10; + x++; + } + var a = [ + 1, + 2, + 3 + ]; + var obj = { + z: 1, + q: "hello" + }; + for (var j in a) { + obj.z = a[j]; + var v = 10; + } + try { + obj.q = "ohhh"; + } catch (e) { + if (obj.z < 10) { + obj.z = 12; + } else { + obj.q = "hmm"; + } + } + try { + throw new Error(); + } catch (e1) { + var b = e1; + } finally { + y = 70; + } + with (obj) { + ~~~ +!!! All symbols within a 'with' block will be resolved to 'any'. + i = 2; + z = 10; + } + switch (obj.z) { + case 0: { + x++; + break; + + } + case 1: { + x--; + break; + + } + default: { + x *= 2; + x = 50; + break; + + } + } + while (x < 10) { + x++; + } + do { + x--; + } while (x > 4) + x = y; + var z = (x == 1) ? x + 1 : x - 1; + (x == 1) ? x + 1 : x - 1; + x === 1; + x = z = 40; + eval("y"); + return; + } + var b = function () { + var x = 10; + x = x + 1; + }; + f(); \ No newline at end of file diff --git a/tests/baselines/reference/superCallsInConstructor.errors.txt b/tests/baselines/reference/superCallsInConstructor.errors.txt index e1d382543ac48..ec6f39b7afe80 100644 --- a/tests/baselines/reference/superCallsInConstructor.errors.txt +++ b/tests/baselines/reference/superCallsInConstructor.errors.txt @@ -1,4 +1,4 @@ -==== tests/cases/compiler/superCallsInConstructor.ts (2 errors) ==== +==== tests/cases/compiler/superCallsInConstructor.ts (1 errors) ==== class C { foo() {} bar() {} @@ -11,13 +11,11 @@ class Derived extends Base { constructor() { with(new C()) { + ~~~~~~~ +!!! All symbols within a 'with' block will be resolved to 'any'. foo(); - ~~~ -!!! Cannot find name 'foo'. super(); bar(); - ~~~ -!!! Cannot find name 'bar'. } try {} catch(e) { super(); } diff --git a/tests/baselines/reference/withStatement.errors.txt b/tests/baselines/reference/withStatement.errors.txt index 518426370dd0d..8ffedf2abe6cf 100644 --- a/tests/baselines/reference/withStatement.errors.txt +++ b/tests/baselines/reference/withStatement.errors.txt @@ -1,13 +1,11 @@ -==== tests/cases/compiler/withStatement.ts (2 errors) ==== +==== tests/cases/compiler/withStatement.ts (1 errors) ==== declare var ooo:any; with (ooo.eee.oo.ah_ah.ting.tang.walla.walla) { // error + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! All symbols within a 'with' block will be resolved to 'any'. bing = true; // no error - ~~~~ -!!! Cannot find name 'bing'. bang = true; // no error - ~~~~ -!!! Cannot find name 'bang'. function bar() {} diff --git a/tests/baselines/reference/withStatementErrors.errors.txt b/tests/baselines/reference/withStatementErrors.errors.txt index f6f2eaa74366e..c72d318015944 100644 --- a/tests/baselines/reference/withStatementErrors.errors.txt +++ b/tests/baselines/reference/withStatementErrors.errors.txt @@ -1,13 +1,11 @@ -==== tests/cases/compiler/withStatementErrors.ts (4 errors) ==== +==== tests/cases/compiler/withStatementErrors.ts (3 errors) ==== declare var ooo:any; with (ooo.eee.oo.ah_ah.ting.tang.walla.walla) { // error + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! All symbols within a 'with' block will be resolved to 'any'. bing = true; // no error - ~~~~ -!!! Cannot find name 'bing'. bang = true; // no error - ~~~~ -!!! Cannot find name 'bang'. function bar() {} // no error diff --git a/tests/baselines/reference/withStatementNestedScope.errors.txt b/tests/baselines/reference/withStatementNestedScope.errors.txt new file mode 100644 index 0000000000000..141385a1098d4 --- /dev/null +++ b/tests/baselines/reference/withStatementNestedScope.errors.txt @@ -0,0 +1,11 @@ +==== tests/cases/compiler/withStatementNestedScope.ts (1 errors) ==== + var x = 1; + with (x) { + ~ +!!! All symbols within a 'with' block will be resolved to 'any'. + function f(a: number) { + return 1; + } + // should be any + var r = f(1); + } \ No newline at end of file diff --git a/tests/baselines/reference/withStatements.errors.txt b/tests/baselines/reference/withStatements.errors.txt index 15e965da6c2a6..65577ab4c672b 100644 --- a/tests/baselines/reference/withStatements.errors.txt +++ b/tests/baselines/reference/withStatements.errors.txt @@ -1,10 +1,8 @@ -==== tests/cases/conformance/statements/withStatements/withStatements.ts (2 errors) ==== +==== tests/cases/conformance/statements/withStatements/withStatements.ts (1 errors) ==== var x = 12; with (x) { + ~ +!!! All symbols within a 'with' block will be resolved to 'any'. name = 'twelve' - ~~~~ -!!! Cannot find name 'name'. id = 12 - ~~ -!!! Cannot find name 'id'. } \ No newline at end of file