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

Should the strict-mode status of a file be dependent on its external module status #4963

Closed
weswigham opened this issue Sep 25, 2015 · 2 comments
Labels
Fixed A PR has been merged for this issue Suggestion An idea for TypeScript

Comments

@weswigham
Copy link
Member

With #4811 merged we've decoupled ES6 module emit from the ES6 language level, allowing us to emit other module forms when targeting ES6. This brings up another interesting question - we parse all external modules in strict mode, ES6 or not, when this is only a requirement for ES6 modules. Should we fix this and make the parse dependent on the module selection? Or should we emit "use strict"; in non-ES6 forms so reality matches the parser? Even before #4811 we've actually had this wrong:

import * as foo from "./foo";

with (foo) {

}

We forbid the with as per strict mode, but we're emitting an amd module without a "use strict"; indicator. To be correct, when not targeting es6 modules, we should either disable strict mode when parsing or emit a "use strict";.

@DanielRosenwasser DanielRosenwasser added In Discussion Not yet reached consensus Question An issue which isn't directly actionable in code labels Sep 25, 2015
@danquirk danquirk added the Suggestion An idea for TypeScript label Sep 25, 2015
@RyanCavanaugh RyanCavanaugh removed the Question An issue which isn't directly actionable in code label Sep 28, 2015
@kitsonk
Copy link
Contributor

kitsonk commented Oct 1, 2015

If in fact you are parsing all modules in strict mode, irrespective of the target, then it makes sense in my mind to emit the prolog in other module targets. My comment in #3576 was of a worry that it might cause breakage or surprises, but since essentially if external modules have always been parsed in strict mode, if there is breakage, then it was in theory a bad emit and should break so it can be addressed.

@IgorMinar
Copy link

+1 for emitting "use strict" when the code is parsed in strict mode.

@weswigham weswigham self-assigned this Nov 23, 2015
@mhegazy mhegazy added Fixed A PR has been merged for this issue and removed In Discussion Not yet reached consensus labels Dec 1, 2015
@mhegazy mhegazy added this to the TypeScript 1.8 milestone Dec 1, 2015
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Fixed A PR has been merged for this issue Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

7 participants