Comments (7)
@paulroper you had a possible solution for this? Want to PR it?
from babel-transform-js-to-jsx.
I didn't hit a solution for multi-line declarations unfortunately, only single line. 😞
from babel-transform-js-to-jsx.
Can you share the AST explorer sample you had? We can adapt it for multi-line and deal with scoping.
from babel-transform-js-to-jsx.
...I didn't save it because I dumb am 👍
from babel-transform-js-to-jsx.
I had a mess around in the AST Explorer again and came up with this:
export default function ({types: t}) {
return {
visitor: {
ExpressionStatement(path) {
if (path.node.expression.type !== "AssignmentExpression") { return; }
const left = path.node.expression.left;
const binding = path.scope.bindings[left.name];
if (binding && !binding.path.shouldSkip) {
path.replaceWith(
t.variableDeclaration("var", [t.VariableDeclarator(left, path.node.expression.right)])
);
binding.path.remove();
}
}
}
};
}
It'll turn:
var a, b, c;
a = 1;
b = 3;
c = 4;
Into:
var a = 1;
var b = 3;
var c = 4;
from babel-transform-js-to-jsx.
Great! Can you look into a good way to check the scope?
from babel-transform-js-to-jsx.
Check the scope of the transformed variable assignments?
from babel-transform-js-to-jsx.
Related Issues (13)
- Certain Case where UnhoistVariables Plugin and Modules Plugin Won't Play Nicely HOT 3
- TypeError: unknown HOT 4
- babel-plugin naming HOT 1
- SyntaxError: Unexpected token { HOT 1
- Convert Fully Qualified Import + Field Statements HOT 3
- command line example
- Refine ESFormatter options
- Feed in component names as an option HOT 4
- Naming conflict with <map> and map() HOT 1
- ESLint integration
- SyntaxError: Unexpected token { HOT 4
- JSX Text is quoted
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from babel-transform-js-to-jsx.