How do Visual Studio recognize the 'use Strict' directive?

Asked

Viewed 492 times

7

Apparently Visual Studio does not recognize the directive 'use strict', because I typed the code below that assigns value to a variable that has not been declared (something prohibited in Strict mode) and there was no complaint from Intellisense.

'use strict';

a = 1;

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

How to make Visual Studio recognize 'use strict' and point out errors in the code, for example in this case above?

  • What if you use a linter? For example http://visualstudiogallery.msdn.microsoft.com/1a417c37-4d6f-43ca-b753-6ea6eb5041fd, http://blog.stevensanderson.com/2012/08/17/using-jshint-inside-visual-studio-the-basics/

  • @bfavaretto this could be a good solution, but is there any option that can be activated inside Visual Studio? Since Javascript is a language supported by the IDE for making Windows Store applications, there should be some option for this.

  • I don’t know, I suggested it because it’s in my comfort zone. I don’t know any other solution, I only use Windows once in a while, and vs less yet...

1 answer

3


The 'Strict mode' is an error checking mechanism at runtime, and so he is not identified by Intellisense. This information is available at documentation of the new features of Visual Studio 2012:

Introduce 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 no news about.)

The Javascript Intellisense do VS is quite cool, but it can only identify problems (or make suggestions) related to the syntax of the code (according to the definition of Ecmascript 5). Identifying whether a variable used in an assignment was defined or not would require a more complex analysis process (probably similar to a compilation), and so makes sense the 'Strict mode' only work during the execution of the programme.

What Visual Studio is able to do (without using plugins) is to display a dialog for the generated exception during the run thanks to the use of the clause "use Strict;" as illustrated in the following image:

inserir a descrição da imagem aqui

As already mentioned, perhaps some of the available plugins provide more interesting indications directly in Intellisense, but I honestly can not say. That one OS thread in English can be of some help in indicating plugins for this.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.