-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Some ES6 constructs force an implicit 'strict' context within them. #1135
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
Comments
Features that enable strict mode: Module Declarations |
Just as a note. It does not have to be a breaking change. The rule can only be enforced when you are targeting es6. This should only affect users moving to es6. |
@mhegazy That's still a breaking change :) Having your code break when moving forward means that TypeScript+ES6 is breaking over TypeScript+ES5. |
Not really. Octal literals is a similar example. |
I think when we generally say "breaking change", we mean it to say that
then that's a breaking change. We never shipped ES6 mode so I don't see this as a breaking change. Still, we should document this explicitly irrespective of the semantics of what constitutes a breaking change (which I could not care less about (except just enough to give a list-based predicate defining it in this response)). |
Those are not the semantics that DevDiv have ever followed when deciding if something is a breaking change. Breaking changes are breaking changes if you move forward (including through language/program version options) and your code no longer compiles. You'll note that C# has taken great pains to avoid this sort of issue (though though they even occasionally makes breaks). For example, there was a decision made to require you to use C# clearly avoided this (though your above approach was an option), and this was because they wanted to make sure your existing code could move forward without breaking to new versions of the language. *** Note also: ScriptTarget affects the code we are generating. i.e. if we're going to emit ES3, ES5, or ES6. It does not affect our actual understanding of your code. You are getting the latest version of our language no matter what the final script target option is. An important reason for this is we want to ensure that any code you have means the same thing, regardless what version of the compiler you have. i.e. once you have a version of the compiler that supports that feature, then the interpretation of that feature should not change. As we have supported classes since V1, it's a break if we change our interpretation of what a class is later. Now, personally, i think it's likely fine for us to make that break. I'm just being explicit that this is what it is so we can document things properly as per our requirements. *** Note: C# has made explicit breaking changes when it deemed it valuable enough. For example, if you had |
Note: to clarify: ScriptTarget affects your final JavaScript. i.e. should an ArrowFunction get rewritten to a FunctionExpression, or should it stay as an ArrowFunction. (Same with things like Templates/Classes/Modules/etc.). ScriptTarget does not change our interpretation of the code. Nor should it. That's why we call it 'script target'. It is the option to specify what sort of 'script' you are 'target'ing :) We only use the script target for two purposes.
We have never gone down the route of saying that we will change the semantics of hte language between script versions except for where ECMAScript has made that decisions themselves. |
I think technically Cyrus is right. Currently, unless you specify "use strict;" in your code (impressed we got this right ), you can use identifiers such as "private" and "interface" inside classes and modules. If this is going to be invalid code in ES6, then we can't emit it when targeting ES6, it has to be an error. I expect the code this will break will be minimal, as strict mode only really impacts TypeScript in the area of these future reserved keywords, and very little code uses identifier names such as "yield" or "static". If it only occurs when targeting ES6 output, it seems palatable to need to fix a couple of identifier names while you are changing your compiler switches. We probably don't want to make this an error in non-ES6 targeted output as a) Builds will break just from an upgrade of the compiler, and b) It is valid code in <= ES5 output. |
ES6 with Implicit Strict Mode Context
|
PR#3517 covered parsing module declaration in strict mode |
For example, inside the body of a class, you are implicitly in strict mode. Implementing this will be a breaking change for existing code that uses classes today and uses some identifier (like 'yield') that becomes a keyword in strict mode.
The text was updated successfully, but these errors were encountered: