How to make Visual Studio recognize the 'use strict' directive?

7

Apparently Visual Studio does not recognize the 'use strict' directive, because I typed the code below that assigns a value to a variable that was not declared (something prohibited in strict mode ) and there was no part of IntelliSense.

'use strict';

a = 1;

I do not know if it makes any difference, but the code was written in a JavaScript file and not inside an HTML document. So the editor used was the "Source Code (Text) Editor" and not the "HTML Editor".

How do Visual Studio recognize 'use strict' and point errors in code, such as above in this case?

    
asked by anonymous 04.01.2014 / 18:10

1 answer

3

'strict mode ' is a run-time error checking mechanism , so it is not identified by IntelliSense . This information is available in documentation of the new Visual Studio 2012 features :

  

Enter additional run-time constraints and error-checking into your   code For more information, see Strict Mode (JavaScript).

(And in the new features of VS 2013 there is nothing new about it.)

The Javascript IntelliSense from VS is pretty cool, but it can only spot problems (or make suggestions) regarding the syntax of the code (as defined by the ECMAScript 5 ). Identifying whether or not a variable used in an assignment would require a more complex parsing process (probably similar to a build), so it makes sense for ' strict mode ' to work only when executing program.

What Visual Studio is able to do (without the use of plugins) is to display a dialog for the generated exception at runtime using the "use strict;" clause, as illustrated the following image:

Asalreadymentioned,perhapssomeoftheavailablepluginsprovidemoreinterestinginsightsdirectlyinIntelliSense,butIhonestlycannotsay.This English OS thread might be of some help in indicate plugins for this.

    
13.01.2014 / 15:19