Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add usestrict option to include 'use strict'; in output #58

Merged
merged 2 commits into from
Dec 1, 2013
Merged

Add usestrict option to include 'use strict'; in output #58

merged 2 commits into from
Dec 1, 2013

Conversation

terraflubb
Copy link
Contributor

Problem

I concatenate the output from ngtemplates into my application file. Part of my building process is to run JSHint after the concatenation, just in case. This step was failing because the generated function did not have 'use strict'; in there. I thought this might be helpful to other people, too!

Solution

I added an option called usestrict (convention is no-underscores / all lowercase, right?) and if it is true then the generated function starts with a 'use strict';. I also added a test case and updated the README.

Updated tests and README.
@ericclemmons
Copy link
Owner

How do you feel about just having "use strct" at the top of the file by default, no option needed? Since the output should be linted without a problem, I don't see the harm in having it in all the time...

@terraflubb
Copy link
Contributor Author

I love that idea! Should I update the PR to do that (fix tests, etc...)?

@ericclemmons
Copy link
Owner

If you have the time, that'd be great. I can't see how this would even be a BC break. I'll handle the tagging & publishing afterwards...

@terraflubb
Copy link
Contributor Author

Just made the change, it will always add 'use strict'; now. The tests still pass, and my name is now on all of them :P.

ericclemmons added a commit that referenced this pull request Dec 1, 2013
Add usestrict option to include `'use strict';` in output
@ericclemmons ericclemmons merged commit 147a9ad into ericclemmons:master Dec 1, 2013
@ericclemmons
Copy link
Owner

v0.4.8 now.

@gregtzar
Copy link

Ironically enough... this change actually caused my output file to start breaking in jshint. Up until this change I had been adding the "use strict" statement plus some comments to the top of the output file via the bootstrap option, and now jshint is complaining about having two of those statements in the file. So I took out my manual addition. Now the "use strict" statement is nested inside of the angular.module block rather than at the top of the file. Jshint doesn't seem to care, but shouldn't it be at the top of the file?

@ericclemmons
Copy link
Owner

@gtczap It used to be that JSHint approved of the "use strict" at the top of the file (as I did the same thing), but then started complaining about that being outside of a function scope and could potentially cause issues for concatenated files.

At least for now, the compiled templates should be jshint-compatible, and you shouldn't have to explicitly declare it anymore. If it is a big problem, then I can make strict an option to disable.

@0x3333
Copy link

0x3333 commented Oct 22, 2015

@ericclemmons Same issue here as @gtczap. This should be an option.

All my js are concatenated and the use strict causes jshint complain.

'use strict';

var someApp = angular.module('someApp', []);

angular.module('someApp').controller('homeController', ["$scope", function($scope) {
}]);

angular.module('someApp').run(['$templateCache', function($templateCache) {
  'use strict';

  $templateCache.put('home/view.html',
    ""
  );
}]);
Running "jshint:build" (jshint) task

   tmp/.concat/app.js
     9 |  'use strict';
           ^ Unnecessary directive "use strict".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants