How to use the Babel plugin?
See original GitHub issueI couldn’t find any instructions on how to use the plugin in the documentation. I tried the following:
// .babelrc.json
{
"plugins": [
"babel-plugin-jsx-dom-expressions"
]
}
And I run it with @babel/cli:
npx babel index.js -o compiled.js
But I keep getting a syntax error because of the JSX:
TypeError: /home/me/library/index.js: Property left of AssignmentExpression expected node to be of a type [“LVal”] but instead got “ArrowFunctionExpression”
How do I use this with Babel?
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Plugins - Babel.js
Using a Plugin. If the plugin is on npm, you can pass in the name of the plugin and Babel will check that...
Read more >Step-by-step guide for writing a custom babel transformation
Babel is a JavaScript compiler that is mainly used to convert ECMAScript 2015+ code into backward compatible version of JavaScript in current ...
Read more >Introduction to custom Babel Plugins | by Kashyap Mukkamala
Babel is a JavaScript compiler which allows us to use the latest and greatest version of JavaScript by converting it into code that...
Read more >BabelJS - Babel Plugins - Tutorialspoint
BabelJS - Babel Plugins, BabelJS is a javascript compiler that changes the syntax of the code given based on presets and plugins available....
Read more >What are Babel "plugins" and "presets"? (And how to use them)
In Babel, a preset is a set of plugins used to support particular language features. The two presets Babel uses by default: ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I actually can change this. I was worried about this case:
If props.ref isn’t passed in I can’t tell if the intention is to assign it or simply it’s missing. But I realized since props are readonly, even if it gets assigned who cares. It just doesn’t update. Right now that scenario is compiled to:
I can change it to:
While it is meaningless in this case if isn’t passed in. This will also work for a simple ref:
Overall it’s more code but it only runs once on creation and I don’t think it makes that much of a difference on size.
Thank you, I must’ve missed that part in the docs and just made the assumption. It’d be ideal if it takes both vars and callbacks, but I understand that may be a limitation currently.