Skip to content
This repository has been archived by the owner on Mar 25, 2021. It is now read-only.

use-strict is (partially?) obsolete #678

Closed
jklmli opened this issue Sep 21, 2015 · 9 comments
Closed

use-strict is (partially?) obsolete #678

jklmli opened this issue Sep 21, 2015 · 9 comments

Comments

@jklmli
Copy link

jklmli commented Sep 21, 2015

Due to https://github.com/Microsoft/TypeScript/wiki/Breaking-Changes#module-bodies-are-parsed-in-strict-mode

@adidahiya
Copy link
Contributor

cool, looks like we can deprecate the use-strict rule soon

@ArturDorochowicz
Copy link
Contributor

@adidahiya

IMO use strict rule is very much not obsolete and I would urge you not to remove it.

The fact that the compiler parses some code applying strict mode constraints has little to do with the runtime strict mode and this is what the use strict rule is really about.

Parsing and runtime is only equivalent when compiler output is ES6 and the code is in a module or class. In all other cases (ES5, ES3, "global" code) these are two different things and we still need a rule to enforce use strict directive to have runtime strict mode.

@tsvetomir
Copy link

@ArturDorochowicz the compiler will output "use strict"; on the module level where it applies to all the functions in the module.

@ArturDorochowicz
Copy link
Contributor

@tsvetomir Yes, that is correct now, but wasn't when I commented on the issue. This has been introduced in TypeScript 1.8, see:
https://github.com/Microsoft/TypeScript/wiki/What's-new-in-TypeScript#modules-are-now-emitted-with-a-use-strict-prologue

@adidahiya adidahiya modified the milestone: TSLint v4.0 Aug 10, 2016
adidahiya added a commit that referenced this issue Oct 9, 2016
Resolves #678. This rule is obsolete as of TypeScript v1.8.
adidahiya added a commit that referenced this issue Oct 9, 2016
Resolves #678. This rule is obsolete as of TypeScript v1.8.
@rcollette
Copy link

rcollette commented Nov 22, 2016

I'm not sure why this rule was removed. When compiling with internal modules (namespaces) use strict is not generated in the output. If the developer forgets it, then browser JIT optimizations do not occur.

For example this source:

// tslint:disable use-strict
namespace app.precache {
  angular.module('app.precache', ['ngResource', 'app.config']);
}
// tslint:enable use-strict

Becomes

// tslint:disable use-strict
var app;
(function (app) {
    var precache;
    (function (precache) {
        angular.module('app.precache', ['ngResource', 'app.config']);
    })(precache = app.precache || (app.precache = {}));
})(app || (app = {}));
// tslint:enable use-strict

There is no auto-generated 'use strict'; statement in this case and none is assumed by the browser.

I could be wrong, but that is my current understanding.

@nchen63
Copy link
Contributor

nchen63 commented Nov 22, 2016

The TypeScript release notes says it should be generated, so this may be a regression or oversight on their side

@adidahiya
Copy link
Contributor

@nchen63 the release notes say it is generated for modules, not scripts. @rcollette seems to be right here, but at this point I would just suggest using use-strict as a custom rule -- I don't want to bring it back into the core rules since its usage seems pretty low.

@adidahiya
Copy link
Contributor

actually, TS 2.1+ now has a --alwaysStrict option to emit "use strict" for everything. Try it out @rcollette microsoft/TypeScript#11473

@rcollette
Copy link

Fair enough.  We're dealing with a pre web pack app.  Starting new I would be using external modules.
On Nov 22, 2016 6:44 PM, Adi Dahiya notifications@github.com wrote:@nchen63 the release notes say it is generated for modules, not scripts. @rcollette seems to be right here, but at this point I would just suggest using use-strict as a custom rule -- I don't want to bring it back into the core rules since its usage seems pretty low.

—You are receiving this because you were mentioned.Reply to this email directly, view it on GitHub, or mute the thread.

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

No branches or pull requests

6 participants