Merge branch 'master' of github.com:babel/babel

This commit is contained in:
Sebastian McKenzie
2015-11-17 22:59:23 -08:00
11 changed files with 79 additions and 1 deletions

View File

@@ -0,0 +1,19 @@
var res = transform('', {
plugins: function (b) {
var t = b.types;
return {
visitor: {
Program: function(path) {
if (this.done) return;
// if (false) { if (true) 42; } else 23;
var inner = t.ifStatement(t.booleanLiteral(true), t.expressionStatement(t.numericLiteral(42)), null);
var outer = t.ifStatement(t.booleanLiteral(false), inner, t.expressionStatement(t.numericLiteral(23)));
path.replaceWith(t.program([outer]));
this.done = true;
}
}
}
}
});
assert.equal(eval(res.code), 23);

View File

@@ -16,8 +16,21 @@ export function IfStatement(node: Object) {
this.push(")");
this.space();
let needsBlock = node.alternate && t.isIfStatement(node.consequent);
if (needsBlock) {
this.push("{");
this.newline();
this.indent();
}
this.printAndIndentOnComments(node.consequent, node);
if (needsBlock) {
this.dedent();
this.newline();
this.push("}");
}
if (node.alternate) {
if (this.isLast("}")) this.space();
this.push("else ");

View File

@@ -1,5 +1,5 @@
export default function ({ types: t }) {
let JSX_ANNOTATION_REGEX = /^\*\s*@jsx\s+([^\s]+)/;
let JSX_ANNOTATION_REGEX = /\*?\s*@jsx\s+([^\s]+)/;
let visitor = require("babel-helper-builder-react-jsx")({
pre(state) {

View File

@@ -0,0 +1,10 @@
/**
* @jsx React.DOM
*/
<Foo></Foo>;
var profile = <div>
<img src="avatar.png" className="profile" />
<h3>{[user.firstName, user.lastName].join(" ")}</h3>
</div>;

View File

@@ -0,0 +1,3 @@
{
"throws": "The @jsx React.DOM pragma has been deprecated as of React 0.12"
}

View File

@@ -0,0 +1,8 @@
/* @jsx React.DOM */
<Foo></Foo>;
var profile = <div>
<img src="avatar.png" className="profile" />
<h3>{[user.firstName, user.lastName].join(" ")}</h3>
</div>;

View File

@@ -0,0 +1,3 @@
{
"throws": "The @jsx React.DOM pragma has been deprecated as of React 0.12"
}

View File

@@ -0,0 +1,8 @@
// @jsx React.DOM
<Foo></Foo>;
var profile = <div>
<img src="avatar.png" className="profile" />
<h3>{[user.firstName, user.lastName].join(" ")}</h3>
</div>;

View File

@@ -0,0 +1,3 @@
{
"throws": "The @jsx React.DOM pragma has been deprecated as of React 0.12"
}

View File

@@ -0,0 +1,8 @@
/** @jsx React.DOM */
<Foo></Foo>;
var profile = <div>
<img src="avatar.png" className="profile" />
<h3>{[user.firstName, user.lastName].join(" ")}</h3>
</div>;

View File

@@ -0,0 +1,3 @@
{
"throws": "The @jsx React.DOM pragma has been deprecated as of React 0.12"
}