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

Fix class properties tdz decorator interop #7475

Conversation

maurobringolf
Copy link
Contributor

@maurobringolf maurobringolf commented Mar 3, 2018

Q                       A
Fixed Issues? Closes #7452, fixes #7705
Patch: Bug Fix? yes
Major: Breaking Change? no
Minor: New Feature? no
Tests Added + Pass? Yes
Documentation PR
Any Dependency Changes?
License MIT

The decorators plugin does some renaming and rearranging of classes which can break my code from #6855 . I figured out that I am unnecessarily recomputing the class binding via ref.name when I can get it directly via path.scope.getBinding(path.node.id.name). I left ref untouched and renamed the class binding used in the TDZ check to classBinding.

I am not sure what's the best Git way of doing this. I added @buschtoens commit with the test case to my fork, so this PR contains his too.

@maurobringolf maurobringolf changed the title Class properties tdz decorator interop Fix class properties tdz decorator interop Mar 3, 2018
@babel-bot
Copy link
Collaborator

babel-bot commented Mar 3, 2018

Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/7088/

@@ -0,0 +1,7 @@
function dec() {}
Copy link
Member

Choose a reason for hiding this comment

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

could we test something here? it seems that this show only the output, so technically could be just a fixture test, u dont actually evaluate the output right now so i think it doesnt justify using exec.js

Copy link
Contributor

Choose a reason for hiding this comment

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

Before the fix exec.js incorrectly threw a runtime error. There was no way to determine the correct output.js fixture back then. Personally, I would add the (currently defunct) proposal-decoratoras transform to make sure that once #6107 lands, independently of how both transforms interplay, they still yield valid, executable code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Converting to a fixture makes sense to me. I renamed to input.js but was unable to get an output generated locally. Committed to see what the CI does.

Also I noticed that some other tests are called input.js but executed? For example https://github.com/babel/babel/tree/master/packages/babel-plugin-proposal-class-properties/test/fixtures/static-property-tdz-edgest-case.

EDIT: figured out how to organize test files correctly. I generated an output.js and converted to fixture test.

@existentialism
Copy link
Member

Can we remove the yarn.lock?

@maurobringolf
Copy link
Contributor Author

@existentialism Sure, I removed it

@danez danez added Spec: Decorators PR: Bug Fix 🐛 A type of pull request used for our changelog categories labels Mar 5, 2018
@maurobringolf
Copy link
Contributor Author

Do you need anything from me for this one? I'd really like to get this in, since there are a lot of potential bugs with renamed classes with the current code.

@jsg2021
Copy link

jsg2021 commented Jul 3, 2018

Is there a plan for this?

@nicolo-ribaudo
Copy link
Member

Yeah sorry, currently bugs related to the old decorators specification aren't getting much attention. We are working on implementing the new decorators proposal (#7976) which shouldn't be affected by many of these bugs.

@jsg2021
Copy link

jsg2021 commented Jul 3, 2018

Thats understandable. Thanks for the reply.

@JSteunou
Copy link

JSteunou commented Jul 25, 2018

@nicolo-ribaudo but the issue is still present with @babel/plugin-proposal-decorators which is the new babel decorators plugin, isnt it?

Update: I'm responding to myself: it's a new name, but under the hood it still use the legacy decorators until the new one are available.

@@ -33,7 +33,7 @@ export default function(api, options) {
},

ReferencedIdentifier(path) {
if (this.classRef === path.scope.getBinding(path.node.name)) {
if (this.classBinding === path.scope.getBinding(path.node.name)) {
Copy link
Member

Choose a reason for hiding this comment

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

Instead of relying on false as a special value to indicate that the class doen't have an id, I think that we should check this.classBinding && this.classBinding === ... here, so that it is more obvious that it is not always defined.

@nicolo-ribaudo
Copy link
Member

Merged in #8463. Thank you!

@lock lock bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Oct 4, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Oct 4, 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: Bug Fix 🐛 A type of pull request used for our changelog categories Spec: Decorators (Legacy)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Symbol.iterator fails when decorators and class-properties are used in Babel 7
9 participants