Merge branch 'master' of github.com:babel/babel
This commit is contained in:
19
packages/babel-core/test/fixtures/plugins/nested-if-alternate/exec.js
vendored
Normal file
19
packages/babel-core/test/fixtures/plugins/nested-if-alternate/exec.js
vendored
Normal 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);
|
||||
@@ -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 ");
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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>;
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"throws": "The @jsx React.DOM pragma has been deprecated as of React 0.12"
|
||||
}
|
||||
@@ -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>;
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"throws": "The @jsx React.DOM pragma has been deprecated as of React 0.12"
|
||||
}
|
||||
@@ -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>;
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"throws": "The @jsx React.DOM pragma has been deprecated as of React 0.12"
|
||||
}
|
||||
@@ -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>;
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"throws": "The @jsx React.DOM pragma has been deprecated as of React 0.12"
|
||||
}
|
||||
Reference in New Issue
Block a user