2

I have an ASP.NET web forms application (using VS2013, targeting .NET4.5). I've added the use strict directive to the top of my .js files to enforce Javascript hygiene.

However, I'm having trouble finding documentation of where in the build process use strict is enforced. It doesn't seem like something that would be integrated into csc.exe, as it's all about Javascript. It also appears to be occurring before my post-build events.

Can anyone point me to some documentation this?


To clarify, I am not asking for documentation on the Javascript feature, I am asking when the build process for my web application is checking this. I am getting build errors for violations of "use strict", but I am not sure when in the pipeline this is happening. Is pre-scanning for strict violations a feature of ASP.NET projects?

enter image description here


Solution

I had Microsoft AJAX Minifier enabled on the project, and when I turned it off, I stopped getting the Javascript errors.

Another great reason to use the AJAX Minifier!

http://ajaxmin.codeplex.com/

JamesFaix
  • 8,050
  • 9
  • 37
  • 73
  • http://stackoverflow.com/questions/1335851/what-does-use-strict-do-in-javascript-and-what-is-the-reasoning-behind-it – Roland Starke Sep 08 '16 at 14:16
  • `It also appears to be occurring before my post-build events` - what is occurring? "use strict" is a javascript "directive" for the javascript engine - it has no impact on compiling in ASP.NET – Jaromanda X Sep 08 '16 at 14:19
  • hard to tell I would assume you made a loop declaring i bur forgot to make it var i = 0 instead you made i =0 – Aaron Rabinowitz Sep 08 '16 at 16:26
  • What version of Visual studio are you using? It's probably the built in javascript debugging engine – Liam Sep 08 '16 at 16:30
  • @AaronRabinowitz, there are multiple for loop errors because there were multiple for loops, each declared like `for(i = 0...` rather than `for(var i = 0...`. Logically I understand why the errors are there, and I enabled "strict" so that I could see these errors. I'm just looking for the build tool that is actually notifying me of these errors. – JamesFaix Sep 08 '16 at 16:35
  • @Liam, using VS 2013 Professional – JamesFaix Sep 08 '16 at 16:36

1 Answers1

0

Looks like you got what you asked for :).

This answer assumes you want to suppress the errors, not fix them at the current moment

Now seriously - what you probably need is to stop treating syntax error warnings as errors and start treating them as warnings instead for javascript files (this will affect all types of syntax errors for javascript files so be cautious).

The errors you see are caused by IntelliSense going through your files constantly and trying to validate them, not the build itself.

Please try the following in Visual Studio:

  1. Go to Tools => Options => Text Editor => JavaScript => IntelliSense
  2. Make sure "Show errors as warning" under "Show syntax errors" is not checked.

This way your errors should appear in the Warnings tab.

Pavel Donchev
  • 1,809
  • 1
  • 17
  • 29
  • I actually like that they are treated as errors, not warnings. I want to avoid any possible global variable issues. I found the checkbox in the options menu, but it does not change the error/warning status when I uncheck. Thanks though, for pointing out the intellisense connection. – JamesFaix Sep 08 '16 at 17:10
  • Okay, then maybe you should also look if your project properties has "Threat errors as warnings" with value of "All", cause this will turn back warnings to errors (go figure). I think this is not likely though. I don't recall seeing a project that survives long enough with this option switched on. It gets switched off at some point. – Pavel Donchev Sep 08 '16 at 17:14