Type check the expression of the 'with' statement

This commit is contained in:
Jason Freeman 2014-07-22 13:37:37 -07:00
parent 8cbe88b501
commit f79cba2225
4 changed files with 12 additions and 3 deletions

View file

@ -5195,6 +5195,7 @@ module ts {
}
function checkWithStatement(node: WithStatement) {
checkExpression(node.expression);
error(node.expression, Diagnostics.All_symbols_within_a_with_block_will_be_resolved_to_any);
}

View file

@ -1,9 +1,11 @@
==== tests/cases/conformance/expressions/functions/arrowFunctionContexts.ts (8 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;
}
@ -53,6 +55,8 @@
with (window) {
~~~~~~
!!! All symbols within a 'with' block will be resolved to 'any'.
~~~~~~
!!! Cannot find name 'window'.
var p = () => this;
}

View file

@ -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'.
}

View file

@ -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'.
}