Skip to content

Update Class Fields to Stage 3 and change default behavior#6076

Merged
hzoo merged 4 commits intobabel:7.0from
noahlemen:7.0
Aug 10, 2017
Merged

Update Class Fields to Stage 3 and change default behavior#6076
hzoo merged 4 commits intobabel:7.0from
noahlemen:7.0

Conversation

@noahlemen
Copy link
Copy Markdown
Member

@noahlemen noahlemen commented Aug 9, 2017

Q A
Patch: Bug Fix?
Major: Breaking Change? ✔️ (change to transform option)
Minor: New Feature?
Deprecations?
Spec Compliancy? ✔️
Tests Added/Pass?
Fixed Tickets Fixes #6073
License MIT
Doc PR
Dependency Changes

@noahlemen
Copy link
Copy Markdown
Member Author

noahlemen commented Aug 9, 2017

i added the {"loose": true} option to tests that were previously defaulting to non-spec mode. would it be better to update those tests' expected.js to use spec mode's output instead?

`boolean`, defaults to `false`.

Class properties are compiled to use `Object.defineProperty`. Static fields are now defined even if they are not initialized.
Class properties are compiled use an assignment expression instead of `Object.defineProperty`. Static fields are now not defined if they are not initialized.
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure how confident i am of the language here. does this capture the intended behavior?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can put the code example here to be more clear.

so an example of the defineProperty vs. this.x = a and also this.x = undefined

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added an example, though it may be a bit lengthy. let me know if you think we can trim it down a bit!


// In non-spec mode, all properties without values are ignored.
// In loose mode, all properties without values are ignored.
// In spec mode, *static* properties without values are still defined (see below).
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIUC, in spec mode, all properties should be defined. This may also be a new change on the stage-3 version.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep, looks like it to me too! i'll change that here.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

think i covered these now. if you've got a chance to take another look, let me know if anything is missing!

@@ -36,7 +36,7 @@ export default function({ types: t }) {
VALUE: value ? value : t.identifier("undefined"),
Copy link
Copy Markdown
Member

@Jessidhia Jessidhia Aug 9, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably better to use t.unaryExpression('void', t.numericLiteral(0)) to avoid any potential shadowing issues (fix out of scope maybe?)

Copy link
Copy Markdown
Member

@hzoo hzoo Aug 9, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we have a method for it path.scope.buildUndefinedNode( - btw this should be a linting rule in babel/run against babel?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 i'll replace with buildUndefinedNode here

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hzoo regarding linting, would the rule be to always disallow t.identifier("undefined") in favor of path.scope.buildUndefinedNode()?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think so at least for us (that can be another pr, can do an inline plugin in the babelrc.js if we wanted), not sure the best way

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gotcha. cool, maybe i'll take a swing at that after this PR

@hzoo hzoo added the PR: Spec Compliance 👓 A type of pull request used for our changelog categories label Aug 9, 2017
`boolean`, defaults to `false`.

Class properties are compiled to use `Object.defineProperty`. Static fields are now defined even if they are not initialized.
Class properties are compiled use an assignment expression instead of `Object.defineProperty`. Static fields are now not defined if they are not initialized.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are static fields not initialized? They should be undefined, too.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think it was never added for the default mode (which is now changing to loose)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, i just kept the behavior that existed as default for the new "loose" mode -- should this be changed?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes.

…ior to always define both static and nonstatic class properties regardless of spec/loose mode; update tests
@hzoo
Copy link
Copy Markdown
Member

hzoo commented Aug 10, 2017

Amazing work @kedromelon!

@noahlemen
Copy link
Copy Markdown
Member Author

😄 thanks for the help everyone!

@hzoo
Copy link
Copy Markdown
Member

hzoo commented Aug 10, 2017

Was a pretty big refactor! Also unforunately all the PRs will conflict since we are changing 3 different plugins to stage 2/3

@hzoo hzoo merged commit 4fdd756 into babel:7.0 Aug 10, 2017
@hzoo
Copy link
Copy Markdown
Member

hzoo commented Aug 10, 2017

@kedromelon also I noticed you were branching off of 7.0? I would suggest making a new branch for each PR in case you have multiple, and easier to manage

@noahlemen
Copy link
Copy Markdown
Member Author

@hzoo yeah, i probably will do that in the future! just didn't bother yet since i haven't had more than one PR going

@hzoo hzoo mentioned this pull request Sep 12, 2017
10 tasks
@lock lock bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Oct 6, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Oct 6, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

outdated A closed issue/PR that is archived due to age. Recommended to make a new issue PR: Spec Compliance 👓 A type of pull request used for our changelog categories Priority: High

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants