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

Handle string properties after computed properties correctly #91

Merged
merged 2 commits into from
Jan 12, 2018

Conversation

StephanHoyer
Copy link
Contributor

it currently compiles to

var obj;
foo(( obj = {}, obj['computed'] = 1, obj.'some-var' = 2, obj ));

@StephanHoyer
Copy link
Contributor Author

Sorry for the syntax error. I try to fix this and also try to add a fix for this issue this weekend.

And BTW: thanks for this great tool!

it currently compiles to
```js
var obj;
foo(( obj = {}, obj['computed'] = 1, obj.'some-var' = 2, obj ));
```
@StephanHoyer
Copy link
Contributor Author

StephanHoyer commented Jan 7, 2018

Not the most elegant way to fix this.

Any tipps are appreciated.

@adrianheine
Copy link
Member

Thanks for the patch, this looks alright!

@@ -175,7 +175,15 @@ export default class ObjectExpression extends Node {
while (code.original[c] !== ']') c += 1;
c += 1;
}
if (prop.shorthand) {
if (prop.key.type === 'Literal' && !prop.computed) {
console.log('' + code)
Copy link
Member

Choose a reason for hiding this comment

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

I removed that in a follow-up

prop.key.end + 1,
'[' + code.slice(prop.start, prop.key.end) + '] = '
);
console.log('' + code)
Copy link
Member

Choose a reason for hiding this comment

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

Removed that, too.

code.overwrite(
prop.start,
prop.key.end + 1,
'[' + code.slice(prop.start, prop.key.end) + '] = '
Copy link
Member

Choose a reason for hiding this comment

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

I think it would be better to remove the trailing whitespace, since hypothetical whitespace between the colon and the property value would be preserved, anyway.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants