Add "ignoreUninitialized" option to "@babel/proposal-class-properties"#9141
Closed
nicolo-ribaudo wants to merge 1 commit intobabel:masterfrom
Closed
Add "ignoreUninitialized" option to "@babel/proposal-class-properties"#9141nicolo-ribaudo wants to merge 1 commit intobabel:masterfrom
nicolo-ribaudo wants to merge 1 commit intobabel:masterfrom
Conversation
When this option is set to true, Babel ignores public class fields
without an initializer. e.g. This code:
class A { x; }
becomes
class A {}
This behavior, althought it diverges from the class fields proposal and
thus isn't reccomended, matches Flow and TypeScript's behavior.
9778059 to
f4f7a62
Compare
Collaborator
|
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/9606/ |
|
Is this going to be merged? Whether or not typescript changes their uninitialized field behavior, it will take quite some time for libraries to be updated for the breaking change. So to make @babel/typescript feasible today there needs to be a way to match tsc. |
This was referenced May 14, 2019
Member
Author
|
I'm closing this plugin since we are not going to diverge from the spec on pourpouse. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR introduces a new option to the
@babel/plugin-proposal-class-propertiesplugin:ignoreUninitialized. When it is enabled,foo;andfoo: type;are removed instead of being (correctly) transpiled as if they werefoo = undefined;.This is needed to support the non-standard behavior of Flow and TypeScript, which use uninitialized fields as build-time-only type annotations instead of undefined fields (as mandated by the proposal). This bug has already been reported to those projects (microsoft/TypeScript#12437, facebook/flow#6811).
When documenting this option we must add a warning that if you are using this option, your code will be incompatible with fields natively implemented by JS engines. We should propose this as an option to make the Flow/TypeScript -> Babel migration easer, but we should encurage users to refactor their code to follow the current proposal.
cc @babel/typescript @babel/flow