Sync latest JSX transform - all children passed as separate arguments

This was a part of e1fe13d0cb upstream.
This commit is contained in:
Paul O’Shannessy
2013-06-13 18:18:54 -07:00
parent 770ec5946a
commit 06cff60bc1
3 changed files with 15 additions and 15 deletions
+7 -1
View File
@@ -91,7 +91,13 @@ function walker(traverse, object, path, state) {
}
function runPass(source, visitors, options) {
var ast = esprima.parse(source, { comment: true, loc: true, range: true });
var ast;
try {
ast = esprima.parse(source, { comment: true, loc: true, range: true });
} catch (e) {
e.message = 'Parse Error: ' + e.message;
throw e;
}
var state = createState(source, options);
state.g.originalProgramAST = ast;
state.g.visitors = visitors;
+6 -1
View File
@@ -54,7 +54,12 @@ function runCli(argv) {
source += chunk;
});
process.stdin.on('end', function () {
source = transformAll(source, options, excludes);
try {
source = transformAll(source, options, excludes);
} catch (e) {
console.error(e.stack);
process.exit(1);
}
process.stdout.write(source.code);
});
}
+2 -13
View File
@@ -136,14 +136,10 @@ function visitReactTag(traverse, object, path, state) {
move(object.openingElement.range[1], state);
}
// separate props and children arguments
append(', ', state);
// filter out whitespace
if (childrenToRender.length > 0) {
if (childrenToRender.length > 1) {
append('[', state);
}
append(', ', state);
object.children.forEach(function(child) {
if (child.type === Syntax.Literal && !child.value.match(/\S/)) {
return;
@@ -166,8 +162,6 @@ function visitReactTag(traverse, object, path, state) {
catchup(child.range[1], state);
});
} else {
append('null', state);
}
if (object.selfClosing) {
@@ -180,11 +174,6 @@ function visitReactTag(traverse, object, path, state) {
move(object.closingElement.range[1], state);
}
if (childrenToRender.length > 0) {
if (childrenToRender.length > 1) {
append(']', state);
}
}
append(')', state);
return false;
}