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

Does not support properties that must be quoted #291

Closed
sudowork opened this issue Jul 3, 2018 · 4 comments
Closed

Does not support properties that must be quoted #291

sudowork opened this issue Jul 3, 2018 · 4 comments

Comments

@sudowork
Copy link
Contributor

sudowork commented Jul 3, 2018

I was trying to use sucrase to transform a library that makes use of kebab-case props (e.g. aria-hidden). Sucrase produces invalid JavaScript when trying to transform that property.

Example source:

<Foo aria-hidden />

Sucrase output:

"use strict";const _jsxFileName = "sample.tsx";React.createElement(Foo, { aria-hidden: true, __self: this, __source: {fileName: _jsxFileName, lineNumber: 1}} )

The invalid output is the unquoted object property since aria-hidden is not a valid identifier.

For reference, here is the Babel output:

"use strict";

var _jsxFileName = "sample.tsx";
React.createElement(Foo, {
  "aria-hidden": true,
  __source: {
    fileName: _jsxFileName,
    lineNumber: 1
  },
  __self: void 0
});
@sudowork
Copy link
Contributor Author

sudowork commented Jul 3, 2018

Hmm, actually ignore this... I must have been using an older version of sucrase. I just cloned this repo and added a test and it does appear to quote they property key per https://github.com/alangpierce/sucrase/blob/c77dcfe/src/transformers/JSXTransformer.ts#L101

@sudowork sudowork closed this as completed Jul 3, 2018
@alangpierce
Copy link
Owner

Thanks for reporting, it looks like this actually is broken: Playground link

Looks like the quoting happens when the property has an =, but not with the shorthand property like in your original example.

@alangpierce alangpierce reopened this Jul 3, 2018
@sudowork
Copy link
Contributor Author

sudowork commented Jul 3, 2018

Ah, good call! I thought I was misremembering things for a second :).

@sudowork
Copy link
Contributor Author

sudowork commented Jul 3, 2018

Took a shot at resolving this: #292

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

No branches or pull requests

2 participants