acornjs / acorn-jsx

Alternative, faster React.js JSX parser
MIT License
648 stars 72 forks source link

update to use Parser.acorn #102

Closed mysticatea closed 4 years ago

mysticatea commented 4 years ago

This PR updates acorn-jsx to use Parser.acorn property that acorn@7.1.0 added. This is to solve the problem https://github.com/acornjs/acorn/pull/870 describes.

The require("acorn-jsx").tokTypes property is as-is, the JSX token types for the acorn of the peer dependency.

This PR adds a static property acornJsx to the enhanced Parser class.

const acorn = require("acorn")
const acornJsx = require("acorn-jsx")
const JsxParser = acorn.Parser.extend(acornJsx())

console.log(JsxParser.acornJsx) //→ an object { tokContexts: {...}, tokTypes: {...} }

That static property exposes the actual JSX token types to other plugins that want to modify JSX tokens. The JsxParser.acornJsx and require("acorn-jsx").tokTypes are the same instance in most situation. But those can be different in the special situation https://github.com/acornjs/acorn/pull/870 describes.

Espree will use the JsxParser.acornJsx to modify tokens.

mysticatea commented 4 years ago

@marijnh @RReverser Would you take a look at this PR?

marijnh commented 4 years ago

@RReverser Would you be open to moving the npm package to the acorn org, so that I can publish updates? I'm unlikely to seriously maintain it, but I'm willing to merge and publish PRs like this one.

RReverser commented 4 years ago

I still don't really understand this change on either Acorn side or Acorn-JSX side, but if you're happy with it and it helps, it's fine by me.

RReverser commented 4 years ago

@marijnh Done (I think).

RReverser commented 4 years ago

I'm not sure if I'm in that org though?

marijnh commented 4 years ago

@rreverser It seems our org is called acornjs, not acorn (sorry)... and now this org has it. Can you still reassign that or should I contact the owner of that org and ask if they reassign it?

ljharb commented 4 years ago

I would immediately email npm support about that one.

marijnh commented 4 years ago

Well, this finally got released (5.1.0) just now

mysticatea commented 4 years ago

Thank you very much!