Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16499,7 +16499,13 @@ namespace ts {
}

checkExpression(node.expression);
error(node.expression, Diagnostics.All_symbols_within_a_with_block_will_be_resolved_to_any);

const sourceFile = getSourceFileOfNode(node);
if (!hasParseDiagnostics(sourceFile)) {
const start = getSpanOfTokenAtPosition(sourceFile, node.pos).start;
const end = node.statement.pos;
grammarErrorAtPos(sourceFile, start, end - start, Diagnostics.The_with_statement_is_not_supported_All_symbols_in_a_with_block_will_have_type_any);
}
}

function checkSwitchStatement(node: SwitchStatement) {
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/diagnosticMessages.json
Original file line number Diff line number Diff line change
Expand Up @@ -1279,7 +1279,7 @@
"category": "Error",
"code": 2409
},
"All symbols within a 'with' block will be resolved to 'any'.": {
"The 'with' statement is not supported. All symbols in a 'with' block will have type 'any'.": {
"category": "Error",
"code": 2410
},
Expand Down
6 changes: 3 additions & 3 deletions tests/baselines/reference/ambientWithStatements.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ tests/cases/compiler/ambientWithStatements.ts(2,5): error TS1036: Statements are
tests/cases/compiler/ambientWithStatements.ts(3,5): error TS1104: A 'continue' statement can only be used within an enclosing iteration statement.
tests/cases/compiler/ambientWithStatements.ts(7,15): error TS2407: The right-hand side of a 'for...in' statement must be of type 'any', an object type or a type parameter.
tests/cases/compiler/ambientWithStatements.ts(11,5): error TS1108: A 'return' statement can only be used within a function body.
tests/cases/compiler/ambientWithStatements.ts(25,11): error TS2410: All symbols within a 'with' block will be resolved to 'any'.
tests/cases/compiler/ambientWithStatements.ts(25,5): error TS2410: The 'with' statement is not supported. All symbols in a 'with' block will have type 'any'.


==== tests/cases/compiler/ambientWithStatements.ts (5 errors) ====
Expand Down Expand Up @@ -39,7 +39,7 @@ tests/cases/compiler/ambientWithStatements.ts(25,11): error TS2410: All symbols
finally {
}
with (x) {
~
!!! error TS2410: All symbols within a 'with' block will be resolved to 'any'.
~~~~~~~~
!!! error TS2410: The 'with' statement is not supported. All symbols in a 'with' block will have type 'any'.
}
}
12 changes: 6 additions & 6 deletions tests/baselines/reference/arrowFunctionContexts.errors.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
tests/cases/conformance/expressions/functions/arrowFunctionContexts.ts(3,1): error TS2410: The 'with' statement is not supported. All symbols in a 'with' block will have type 'any'.
tests/cases/conformance/expressions/functions/arrowFunctionContexts.ts(3,7): error TS2304: Cannot find name 'window'.
tests/cases/conformance/expressions/functions/arrowFunctionContexts.ts(3,7): error TS2410: All symbols within a 'with' block will be resolved to 'any'.
tests/cases/conformance/expressions/functions/arrowFunctionContexts.ts(19,1): error TS2304: Cannot find name 'window'.
tests/cases/conformance/expressions/functions/arrowFunctionContexts.ts(31,9): error TS2322: Type '() => number' is not assignable to type 'E'.
tests/cases/conformance/expressions/functions/arrowFunctionContexts.ts(32,16): error TS2332: 'this' cannot be referenced in current location.
tests/cases/conformance/expressions/functions/arrowFunctionContexts.ts(44,5): error TS2410: The 'with' statement is not supported. All symbols in a 'with' block will have type 'any'.
tests/cases/conformance/expressions/functions/arrowFunctionContexts.ts(44,11): error TS2304: Cannot find name 'window'.
tests/cases/conformance/expressions/functions/arrowFunctionContexts.ts(44,11): error TS2410: All symbols within a 'with' block will be resolved to 'any'.
tests/cases/conformance/expressions/functions/arrowFunctionContexts.ts(60,5): error TS2304: Cannot find name 'window'.
tests/cases/conformance/expressions/functions/arrowFunctionContexts.ts(72,13): error TS2322: Type '() => number' is not assignable to type 'E'.
tests/cases/conformance/expressions/functions/arrowFunctionContexts.ts(73,20): error TS2332: 'this' cannot be referenced in current location.
Expand All @@ -14,10 +14,10 @@ tests/cases/conformance/expressions/functions/arrowFunctionContexts.ts(73,20): e

// Arrow function used in with statement
with (window) {
~~~~~~~~~~~~~
!!! error TS2410: The 'with' statement is not supported. All symbols in a 'with' block will have type 'any'.
~~~~~~
!!! error TS2304: Cannot find name 'window'.
~~~~~~
!!! error TS2410: All symbols within a 'with' block will be resolved to 'any'.
var p = () => this;
}

Expand Down Expand Up @@ -65,10 +65,10 @@ tests/cases/conformance/expressions/functions/arrowFunctionContexts.ts(73,20): e
module M2 {
// Arrow function used in with statement
with (window) {
~~~~~~~~~~~~~
!!! error TS2410: The 'with' statement is not supported. All symbols in a 'with' block will have type 'any'.
~~~~~~
!!! error TS2304: Cannot find name 'window'.
~~~~~~
!!! error TS2410: All symbols within a 'with' block will be resolved to 'any'.
var p = () => this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ tests/cases/compiler/constDeclarations-invalidContexts.ts(4,5): error TS1156: 'c
tests/cases/compiler/constDeclarations-invalidContexts.ts(6,5): error TS1156: 'const' declarations can only be declared inside a block.
tests/cases/compiler/constDeclarations-invalidContexts.ts(9,5): error TS1156: 'const' declarations can only be declared inside a block.
tests/cases/compiler/constDeclarations-invalidContexts.ts(12,5): error TS1156: 'const' declarations can only be declared inside a block.
tests/cases/compiler/constDeclarations-invalidContexts.ts(16,7): error TS2410: All symbols within a 'with' block will be resolved to 'any'.
tests/cases/compiler/constDeclarations-invalidContexts.ts(16,1): error TS2410: The 'with' statement is not supported. All symbols in a 'with' block will have type 'any'.
tests/cases/compiler/constDeclarations-invalidContexts.ts(20,5): error TS1156: 'const' declarations can only be declared inside a block.
tests/cases/compiler/constDeclarations-invalidContexts.ts(23,5): error TS1156: 'const' declarations can only be declared inside a block.
tests/cases/compiler/constDeclarations-invalidContexts.ts(26,12): error TS1156: 'const' declarations can only be declared inside a block.
Expand Down Expand Up @@ -34,8 +34,8 @@ tests/cases/compiler/constDeclarations-invalidContexts.ts(29,29): error TS1156:

var obj;
with (obj)
~~~
!!! error TS2410: All symbols within a 'with' block will be resolved to 'any'.
~~~~~~~~~~
!!! error TS2410: The 'with' statement is not supported. All symbols in a 'with' block will have type 'any'.
const c5 = 0; // No Error will be reported here since we turn off all type checking

for (var i = 0; i < 10; i++)
Expand Down
6 changes: 3 additions & 3 deletions tests/baselines/reference/constDeclarations-scopes.errors.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
tests/cases/compiler/constDeclarations-scopes.ts(13,5): error TS7027: Unreachable code detected.
tests/cases/compiler/constDeclarations-scopes.ts(22,1): error TS7027: Unreachable code detected.
tests/cases/compiler/constDeclarations-scopes.ts(28,7): error TS2410: All symbols within a 'with' block will be resolved to 'any'.
tests/cases/compiler/constDeclarations-scopes.ts(28,1): error TS2410: The 'with' statement is not supported. All symbols in a 'with' block will have type 'any'.


==== tests/cases/compiler/constDeclarations-scopes.ts (3 errors) ====
Expand Down Expand Up @@ -36,8 +36,8 @@ tests/cases/compiler/constDeclarations-scopes.ts(28,7): error TS2410: All symbol

var obj;
with (obj) {
~~~
!!! error TS2410: All symbols within a 'with' block will be resolved to 'any'.
~~~~~~~~~~
!!! error TS2410: The 'with' statement is not supported. All symbols in a 'with' block will have type 'any'.
const c = 0;
n = c;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
tests/cases/compiler/constDeclarations-validContexts.ts(20,7): error TS2410: All symbols within a 'with' block will be resolved to 'any'.
tests/cases/compiler/constDeclarations-validContexts.ts(20,1): error TS2410: The 'with' statement is not supported. All symbols in a 'with' block will have type 'any'.


==== tests/cases/compiler/constDeclarations-validContexts.ts (1 errors) ====
Expand All @@ -22,8 +22,8 @@ tests/cases/compiler/constDeclarations-validContexts.ts(20,7): error TS2410: All

var obj;
with (obj) {
~~~
!!! error TS2410: All symbols within a 'with' block will be resolved to 'any'.
~~~~~~~~~~
!!! error TS2410: The 'with' statement is not supported. All symbols in a 'with' block will have type 'any'.
const c5 = 0;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
tests/cases/compiler/es5-asyncFunctionWithStatements.ts(4,5): error TS1300: 'with' statements are not allowed in an async function block.
tests/cases/compiler/es5-asyncFunctionWithStatements.ts(4,11): error TS2410: All symbols within a 'with' block will be resolved to 'any'.
tests/cases/compiler/es5-asyncFunctionWithStatements.ts(4,5): error TS2410: The 'with' statement is not supported. All symbols in a 'with' block will have type 'any'.
tests/cases/compiler/es5-asyncFunctionWithStatements.ts(10,5): error TS1300: 'with' statements are not allowed in an async function block.
tests/cases/compiler/es5-asyncFunctionWithStatements.ts(10,11): error TS2410: All symbols within a 'with' block will be resolved to 'any'.
tests/cases/compiler/es5-asyncFunctionWithStatements.ts(10,5): error TS2410: The 'with' statement is not supported. All symbols in a 'with' block will have type 'any'.
tests/cases/compiler/es5-asyncFunctionWithStatements.ts(16,5): error TS1300: 'with' statements are not allowed in an async function block.
tests/cases/compiler/es5-asyncFunctionWithStatements.ts(16,11): error TS2410: All symbols within a 'with' block will be resolved to 'any'.
tests/cases/compiler/es5-asyncFunctionWithStatements.ts(16,5): error TS2410: The 'with' statement is not supported. All symbols in a 'with' block will have type 'any'.
tests/cases/compiler/es5-asyncFunctionWithStatements.ts(24,5): error TS1300: 'with' statements are not allowed in an async function block.
tests/cases/compiler/es5-asyncFunctionWithStatements.ts(24,11): error TS2410: All symbols within a 'with' block will be resolved to 'any'.
tests/cases/compiler/es5-asyncFunctionWithStatements.ts(24,5): error TS2410: The 'with' statement is not supported. All symbols in a 'with' block will have type 'any'.


==== tests/cases/compiler/es5-asyncFunctionWithStatements.ts (8 errors) ====
Expand All @@ -15,8 +15,8 @@ tests/cases/compiler/es5-asyncFunctionWithStatements.ts(24,11): error TS2410: Al
with (x) {
~~~~
!!! error TS1300: 'with' statements are not allowed in an async function block.
~
!!! error TS2410: All symbols within a 'with' block will be resolved to 'any'.
~~~~~~~~
!!! error TS2410: The 'with' statement is not supported. All symbols in a 'with' block will have type 'any'.
y;
}
}
Expand All @@ -25,8 +25,8 @@ tests/cases/compiler/es5-asyncFunctionWithStatements.ts(24,11): error TS2410: Al
with (await x) {
~~~~
!!! error TS1300: 'with' statements are not allowed in an async function block.
~~~~~~~
!!! error TS2410: All symbols within a 'with' block will be resolved to 'any'.
~~~~~~~~~~~~~~
!!! error TS2410: The 'with' statement is not supported. All symbols in a 'with' block will have type 'any'.
y;
}
}
Expand All @@ -35,8 +35,8 @@ tests/cases/compiler/es5-asyncFunctionWithStatements.ts(24,11): error TS2410: Al
with (x) {
~~~~
!!! error TS1300: 'with' statements are not allowed in an async function block.
~
!!! error TS2410: All symbols within a 'with' block will be resolved to 'any'.
~~~~~~~~
!!! error TS2410: The 'with' statement is not supported. All symbols in a 'with' block will have type 'any'.
a;
await y;
b;
Expand All @@ -47,8 +47,8 @@ tests/cases/compiler/es5-asyncFunctionWithStatements.ts(24,11): error TS2410: Al
with (x) {
~~~~
!!! error TS1300: 'with' statements are not allowed in an async function block.
~
!!! error TS2410: All symbols within a 'with' block will be resolved to 'any'.
~~~~~~~~
!!! error TS2410: The 'with' statement is not supported. All symbols in a 'with' block will have type 'any'.
with (z) {
a;
await y;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
tests/cases/compiler/functionExpressionInWithBlock.ts(2,7): error TS2410: All symbols within a 'with' block will be resolved to 'any'.
tests/cases/compiler/functionExpressionInWithBlock.ts(2,2): error TS2410: The 'with' statement is not supported. All symbols in a 'with' block will have type 'any'.


==== tests/cases/compiler/functionExpressionInWithBlock.ts (1 errors) ====
function x() {
with({}) {
~~
!!! error TS2410: All symbols within a 'with' block will be resolved to 'any'.
~~~~~~~~
!!! error TS2410: The 'with' statement is not supported. All symbols in a 'with' block will have type 'any'.
function f() {
() => this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ tests/cases/compiler/letDeclarations-invalidContexts.ts(5,5): error TS1157: 'let
tests/cases/compiler/letDeclarations-invalidContexts.ts(7,5): error TS1157: 'let' declarations can only be declared inside a block.
tests/cases/compiler/letDeclarations-invalidContexts.ts(10,5): error TS1157: 'let' declarations can only be declared inside a block.
tests/cases/compiler/letDeclarations-invalidContexts.ts(13,5): error TS1157: 'let' declarations can only be declared inside a block.
tests/cases/compiler/letDeclarations-invalidContexts.ts(17,7): error TS2410: All symbols within a 'with' block will be resolved to 'any'.
tests/cases/compiler/letDeclarations-invalidContexts.ts(17,1): error TS2410: The 'with' statement is not supported. All symbols in a 'with' block will have type 'any'.
tests/cases/compiler/letDeclarations-invalidContexts.ts(21,5): error TS1157: 'let' declarations can only be declared inside a block.
tests/cases/compiler/letDeclarations-invalidContexts.ts(24,5): error TS1157: 'let' declarations can only be declared inside a block.
tests/cases/compiler/letDeclarations-invalidContexts.ts(27,12): error TS1157: 'let' declarations can only be declared inside a block.
Expand Down Expand Up @@ -35,8 +35,8 @@ tests/cases/compiler/letDeclarations-invalidContexts.ts(30,29): error TS1157: 'l

var obj;
with (obj)
~~~
!!! error TS2410: All symbols within a 'with' block will be resolved to 'any'.
~~~~~~~~~~
!!! error TS2410: The 'with' statement is not supported. All symbols in a 'with' block will have type 'any'.
let l5 = 0;

for (var i = 0; i < 10; i++)
Expand Down
6 changes: 3 additions & 3 deletions tests/baselines/reference/letDeclarations-scopes.errors.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
tests/cases/compiler/letDeclarations-scopes.ts(29,7): error TS2410: All symbols within a 'with' block will be resolved to 'any'.
tests/cases/compiler/letDeclarations-scopes.ts(29,1): error TS2410: The 'with' statement is not supported. All symbols in a 'with' block will have type 'any'.


==== tests/cases/compiler/letDeclarations-scopes.ts (1 errors) ====
Expand Down Expand Up @@ -31,8 +31,8 @@ tests/cases/compiler/letDeclarations-scopes.ts(29,7): error TS2410: All symbols

var obj;
with (obj) {
~~~
!!! error TS2410: All symbols within a 'with' block will be resolved to 'any'.
~~~~~~~~~~
!!! error TS2410: The 'with' statement is not supported. All symbols in a 'with' block will have type 'any'.
let l = 0;
n = l;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
tests/cases/compiler/letDeclarations-validContexts.ts(21,7): error TS2410: All symbols within a 'with' block will be resolved to 'any'.
tests/cases/compiler/letDeclarations-validContexts.ts(21,1): error TS2410: The 'with' statement is not supported. All symbols in a 'with' block will have type 'any'.


==== tests/cases/compiler/letDeclarations-validContexts.ts (1 errors) ====
Expand All @@ -23,8 +23,8 @@ tests/cases/compiler/letDeclarations-validContexts.ts(21,7): error TS2410: All s

var obj;
with (obj) {
~~~
!!! error TS2410: All symbols within a 'with' block will be resolved to 'any'.
~~~~~~~~~~
!!! error TS2410: The 'with' statement is not supported. All symbols in a 'with' block will have type 'any'.
let l5 = 0;
}

Expand Down
6 changes: 3 additions & 3 deletions tests/baselines/reference/parserStrictMode14.errors.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
tests/cases/conformance/parser/ecmascript5/StrictMode/parserStrictMode14.ts(2,1): error TS1101: 'with' statements are not allowed in strict mode.
tests/cases/conformance/parser/ecmascript5/StrictMode/parserStrictMode14.ts(2,1): error TS2410: The 'with' statement is not supported. All symbols in a 'with' block will have type 'any'.
tests/cases/conformance/parser/ecmascript5/StrictMode/parserStrictMode14.ts(2,7): error TS2304: Cannot find name 'a'.
tests/cases/conformance/parser/ecmascript5/StrictMode/parserStrictMode14.ts(2,7): error TS2410: All symbols within a 'with' block will be resolved to 'any'.


==== tests/cases/conformance/parser/ecmascript5/StrictMode/parserStrictMode14.ts (3 errors) ====
"use strict";
with (a) {
~~~~
!!! error TS1101: 'with' statements are not allowed in strict mode.
~~~~~~~~
!!! error TS2410: The 'with' statement is not supported. All symbols in a 'with' block will have type 'any'.
~
!!! error TS2304: Cannot find name 'a'.
~
!!! error TS2410: All symbols within a 'with' block will be resolved to 'any'.
}
6 changes: 3 additions & 3 deletions tests/baselines/reference/parserWithStatement1.d.errors.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
tests/cases/conformance/parser/ecmascript5/Statements/parserWithStatement1.d.ts(1,1): error TS1036: Statements are not allowed in ambient contexts.
tests/cases/conformance/parser/ecmascript5/Statements/parserWithStatement1.d.ts(1,1): error TS2410: The 'with' statement is not supported. All symbols in a 'with' block will have type 'any'.
tests/cases/conformance/parser/ecmascript5/Statements/parserWithStatement1.d.ts(1,7): error TS2304: Cannot find name 'foo'.
tests/cases/conformance/parser/ecmascript5/Statements/parserWithStatement1.d.ts(1,7): error TS2410: All symbols within a 'with' block will be resolved to 'any'.


==== tests/cases/conformance/parser/ecmascript5/Statements/parserWithStatement1.d.ts (3 errors) ====
with (foo) {
~~~~
!!! error TS1036: Statements are not allowed in ambient contexts.
~~~~~~~~~~
!!! error TS2410: The 'with' statement is not supported. All symbols in a 'with' block will have type 'any'.
~~~
!!! error TS2304: Cannot find name 'foo'.
~~~
!!! error TS2410: All symbols within a 'with' block will be resolved to 'any'.
}
6 changes: 3 additions & 3 deletions tests/baselines/reference/parserWithStatement2.errors.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
tests/cases/conformance/parser/ecmascript5/Statements/parserWithStatement2.ts(1,7): error TS2410: All symbols within a 'with' block will be resolved to 'any'.
tests/cases/conformance/parser/ecmascript5/Statements/parserWithStatement2.ts(1,1): error TS2410: The 'with' statement is not supported. All symbols in a 'with' block will have type 'any'.


==== tests/cases/conformance/parser/ecmascript5/Statements/parserWithStatement2.ts (1 errors) ====
with (1)
~
!!! error TS2410: All symbols within a 'with' block will be resolved to 'any'.
~~~~~~~~
!!! error TS2410: The 'with' statement is not supported. All symbols in a 'with' block will have type 'any'.
return;
Loading