-
Notifications
You must be signed in to change notification settings - Fork 24.3k
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
Document that we're using Babel #274
Comments
Aha, I was just trying to find this out! Is this optional, is it possible to swap in babel or similar? |
Right now it's backed in but we want to allow other transforms down the line. We secretly hoped that someone from the community would help :) |
All the transformation is done by the worker https://github.com/facebook/react-native/blob/master/packager/transformer.js |
Once the initial rush settles down and the issues take some shape it'd be good to have a bit of a roadmap for larger goals like that - I'm keen to get stuck in :) |
I managed to swap in babel and it works 95%. For some reason even though it transforms import statements to requires they don't seem to work. Does react-native crawl the requires BEFORE the transform occurs? |
Yes, I'd say avoid es6 modules for now. Can you share your code for others On Thursday, March 26, 2015, Stanislav Vishnevskiy notifications@github.com
|
No problem. I just installed 'use strict';
var babel = require('babel-core');
module.exports = function(data, callback) {
var result;
try {
result = babel.transform(data.sourceCode, {
filename: data.filename,
// Remove the interopRequire
modules: 'commonStrict'
});
result = {
// Removing interopRequire causes it to try to get default.
// Not nessessary for react-native so strip it.
code: result.code.replace(/\)\["default"]/g, ')')
};
} catch (e) {
return callback(null, {
error: {
lineNumber: e.loc.line,
column: e.loc.column,
message: e.message,
stack: e.stack,
description: e.description
}
});
}
callback(null, result);
}; I don't seem to see how to provide the source map but it works otherwise. I would really love advise how where I might be able to mod code to fix import statements because that is blocking me from using existing Flux stores and action creators from another react project. |
Why are you using |
Yup souremaps are currently hardcoded in the packager for speed and assume line/col numbers are preserved (jstransform) (this hack made things orders of magnitude faster for us) because source map generation is usually the most expensive part of packagers. But will try to have a better answer for this soon. |
@sebmck For some reason the packager does not like the |
Here's my solution: Add the following code to the top of var babel = require('babel');
if (!/node_modules\/react-native\//.test(data.filename)) {
try {
var result = babel.transform(data.sourceCode, {
ast: false,
comments: false,
filename: data.filename
});
return callback(null, {
code: result.code
});
} catch (e) {
return callback(null, {
error: {
lineNumber: e.loc.line,
column: e.loc.column,
message: e.message,
stack: e.stack,
description: e.description
}
});
}
} It transforms I was also able to solve the ES6 Please share if you discover any issue other than the known issue with |
Yes please! I spent about an hour trying to find this documentation, what ES6 features I could use and what not. Thanx @tadeuzagallo for pointing me to this issue. |
Working on a PR for documentation. |
PR for review at #1449. If we want this documented before the official release is out, I can update it to reference both transformers. |
FYI the packager can now consume |
https://github.com/facebook/jstransform/tree/master/visitors
The text was updated successfully, but these errors were encountered: