Comments (4)
Fixed in 4de2cf5
from babel-transform-js-to-jsx.
Do you have docs or a test that shows how this works?
from babel-transform-js-to-jsx.
I use this project with a project specific wrapper, you can see towards the end we pass in some options to the babel transform including the component list:
#!/usr/bin/env node
var fs = require("fs");
var path = require("path");
var parseArgs = require('minimist');
var argv = parseArgs(process.argv.slice(2), { default: { format: true } });
var filename = argv._[0];
require("babel-register")({ only: /babel-js-to-jsx/ });
var livescript = require("livescript");
var esformatter = require("esformatter");
if (!filename) {
console.error("Usage: js-to-jsx <filename>");
console.error("Use the --no-format flag to disable esformatter");
process.exit(1);
}
var original = fs.readFileSync(filename, 'utf8');
var components = fs.readFileSync(path.resolve(__dirname, "../components.txt"), "utf8").split("\n");
var es5 = livescript.compile(original, { header: false, bare: true });
var es6 = transpileToES6(es5, components).replace(/\'/g, '"');
if (!argv.format) {
console.log(es6);
process.exit(0);
}
var formatted = esformatter.format(es6, {
"plugins": [
"esformatter-jsx",
"esformatter-quotes"
],
"quotes": {
"type": "double"
},
"jsx": {
"formatJSX": true,
"attrsOnSameLineAsTag": true,
"maxAttrsOnTag": 1,
"firstAttributeOnSameLine": false,
"spaceInJSXExpressionContainers": " ",
"alignWithFirstAttribute": true,
"htmlOptions": {
"brace_style": "collapse",
"indent_char": " ",
"indent_size": 2,
"max_preserve_newlines": 2,
"preserve_newlines": true
}
}
});
console.log(formatted);
function transpileToES6(es5, components) {
return require("babel-core").transform(es5, {
plugins: [
["babel-js-to-jsx", { components: components }],
"babel-js-to-jsx/es6/arrow-functions",
"babel-js-to-jsx/es6/modules",
"babel-js-to-jsx/es6/remove-dom-shim",
"babel-js-to-jsx/es6/unhoist-variables"
]
}).code;
}
from babel-transform-js-to-jsx.
Thank you!
from babel-transform-js-to-jsx.
Related Issues (13)
- Join Declaration/Assignment HOT 7
- 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
- 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.