diff --git a/packages/babylon/src/plugins/jsx/index.js b/packages/babylon/src/plugins/jsx/index.js index 3ff0cc0c7c..6f1163e3f9 100644 --- a/packages/babylon/src/plugins/jsx/index.js +++ b/packages/babylon/src/plugins/jsx/index.js @@ -349,6 +349,7 @@ pp.jsxParseElementAt = function(startPos, startLoc) { this.unexpected(); } } + if (getQualifiedJSXName(closingElement.name) !== getQualifiedJSXName(openingElement.name)) { this.raise( closingElement.start, @@ -377,12 +378,13 @@ pp.jsxParseElement = function() { export default function(instance) { instance.extend("parseExprAtom", function(inner) { return function(refShortHandDefaultPos) { - if (this.match(tt.jsxText)) + if (this.match(tt.jsxText)) { return this.parseLiteral(this.state.value); - else if (this.match(tt.jsxTagStart)) + } else if (this.match(tt.jsxTagStart)) { return this.jsxParseElement(); - else + } else { return inner.call(this, refShortHandDefaultPos); + } }; }); @@ -390,24 +392,30 @@ export default function(instance) { return function(code) { var context = this.curContext(); - if (context === tc.j_expr) return this.jsxReadToken(); + if (context === tc.j_expr) { + return this.jsxReadToken(); + } if (context === tc.j_oTag || context === tc.j_cTag) { - if (isIdentifierStart(code)) return this.jsxReadWord(); + if (isIdentifierStart(code)) { + return this.jsxReadWord(); + } if (code === 62) { ++this.state.pos; return this.finishToken(tt.jsxTagEnd); } - if ((code === 34 || code === 39) && context === tc.j_oTag) + if ((code === 34 || code === 39) && context === tc.j_oTag) { return this.jsxReadString(code); + } } if (code === 60 && this.state.exprAllowed) { ++this.state.pos; return this.finishToken(tt.jsxTagStart); } + return inner.call(this, code); }; }); @@ -416,9 +424,13 @@ export default function(instance) { return function(prevType) { if (this.match(tt.braceL)) { var curContext = this.curContext(); - if (curContext === tc.j_oTag) this.state.context.push(tc.b_expr); - else if (curContext === tc.j_expr) this.state.context.push(tc.b_tmpl); - else inner.call(this, prevType); + if (curContext === tc.j_oTag) { + this.state.context.push(tc.b_expr); + } else if (curContext === tc.j_expr) { + this.state.context.push(tc.b_tmpl); + } else { + inner.call(this, prevType); + } this.state.exprAllowed = true; } else if (this.match(tt.slash) && prevType === tt.jsxTagStart) { this.state.context.length -= 2; // do not consider JSX expr -> JSX open tag -> ... anymore diff --git a/packages/babylon/src/tokenizer/index.js b/packages/babylon/src/tokenizer/index.js index f75f720a7f..1d52bcee58 100644 --- a/packages/babylon/src/tokenizer/index.js +++ b/packages/babylon/src/tokenizer/index.js @@ -267,7 +267,9 @@ export default class Tokenizer { // readToken_dot() { let next = this.input.charCodeAt(this.state.pos + 1); - if (next >= 48 && next <= 57) return this.readNumber(true); + if (next >= 48 && next <= 57) { + return this.readNumber(true); + } let next2 = this.input.charCodeAt(this.state.pos + 2); if (next === 46 && next2 === 46) { // 46 = dot '.' @@ -280,13 +282,17 @@ export default class Tokenizer { } readToken_slash() { // '/' - let next = this.input.charCodeAt(this.state.pos + 1); if (this.state.exprAllowed) { ++this.state.pos; return this.readRegexp(); } - if (next === 61) return this.finishOp(tt.assign, 2); - return this.finishOp(tt.slash, 1); + + let next = this.input.charCodeAt(this.state.pos + 1); + if (next === 61) { + return this.finishOp(tt.assign, 2); + } else { + return this.finishOp(tt.slash, 1); + } } readToken_mult_modulo(code) { // '%*' @@ -537,10 +543,15 @@ export default class Tokenizer { let start = this.state.pos, total = 0; for (let i = 0, e = len == null ? Infinity : len; i < e; ++i) { let code = this.input.charCodeAt(this.state.pos), val; - if (code >= 97) val = code - 97 + 10; // a - else if (code >= 65) val = code - 65 + 10; // A - else if (code >= 48 && code <= 57) val = code - 48; // 0-9 - else val = Infinity; + if (code >= 97) { + val = code - 97 + 10; // a + } else if (code >= 65) { + val = code - 65 + 10; // A + } else if (code >= 48 && code <= 57) { + val = code - 48; // 0-9 + } else { + val = Infinity; + } if (val >= radix) break; ++this.state.pos; total = total * radix + val; @@ -579,10 +590,15 @@ export default class Tokenizer { if (isIdentifierStart(this.fullCharCodeAtPos())) this.raise(this.state.pos, "Identifier directly after number"); let str = this.input.slice(start, this.state.pos), val; - if (isFloat) val = parseFloat(str); - else if (!octal || str.length === 1) val = parseInt(str, 10); - else if (/[89]/.test(str) || this.strict) this.raise(start, "Invalid number"); - else val = parseInt(str, 8); + if (isFloat) { + val = parseFloat(str); + } else if (!octal || str.length === 1) { + val = parseInt(str, 10); + } else if (/[89]/.test(str) || this.strict) { + this.raise(start, "Invalid number"); + } else { + val = parseInt(str, 8); + } return this.finishToken(tt.num, val); }