diff --git a/src/plugins/jsx/index.js b/src/plugins/jsx/index.js index c12a46777b..385e907ab8 100644 --- a/src/plugins/jsx/index.js +++ b/src/plugins/jsx/index.js @@ -431,9 +431,9 @@ export default function(instance) { if (this.match(tt.braceL)) { let curContext = this.curContext(); if (curContext === tc.j_oTag) { - this.state.context.push(tc.b_expr); + this.state.context.push(tc.braceExpression); } else if (curContext === tc.j_expr) { - this.state.context.push(tc.b_tmpl); + this.state.context.push(tc.templateQuasi); } else { inner.call(this, prevType); } diff --git a/src/tokenizer/context.js b/src/tokenizer/context.js index 600b11403c..ad34b328c2 100644 --- a/src/tokenizer/context.js +++ b/src/tokenizer/context.js @@ -27,13 +27,13 @@ export class TokContext { export const types: { [key: string]: TokContext; } = { - b_stat: new TokContext("{", false), - b_expr: new TokContext("{", true), - b_tmpl: new TokContext("${", true), - p_stat: new TokContext("(", false), - p_expr: new TokContext("(", true), - q_tmpl: new TokContext("`", true, true, (p) => p.readTmplToken()), - f_expr: new TokContext("function", true) + braceStatement: new TokContext("{", false), + braceExpression: new TokContext("{", true), + templateQuasi: new TokContext("${", true), + parenStatement: new TokContext("(", false), + parenExpression: new TokContext("(", true), + template: new TokContext("`", true, true, (p) => p.readTmplToken()), + functionExpression: new TokContext("function", true) }; // Token-specific context update code @@ -45,10 +45,10 @@ tt.parenR.updateContext = tt.braceR.updateContext = function () { } let out = this.state.context.pop(); - if (out === types.b_stat && this.curContext() === types.f_expr) { + if (out === types.braceStatement && this.curContext() === types.functionExpression) { this.state.context.pop(); this.state.exprAllowed = false; - } else if (out === types.b_tmpl) { + } else if (out === types.templateQuasi) { this.state.exprAllowed = true; } else { this.state.exprAllowed = !out.isExpr; @@ -66,19 +66,19 @@ tt.name.updateContext = function (prevType) { }; tt.braceL.updateContext = function (prevType) { - this.state.context.push(this.braceIsBlock(prevType) ? types.b_stat : types.b_expr); + this.state.context.push(this.braceIsBlock(prevType) ? types.braceStatement : types.braceExpression); this.state.exprAllowed = true; }; tt.dollarBraceL.updateContext = function () { - this.state.context.push(types.b_tmpl); + this.state.context.push(types.templateQuasi); this.state.exprAllowed = true; }; tt.parenL.updateContext = function (prevType) { let statementParens = prevType === tt._if || prevType === tt._for || prevType === tt._with || prevType === tt._while; - this.state.context.push(statementParens ? types.p_stat : types.p_expr); + this.state.context.push(statementParens ? types.parenStatement : types.parenExpression); this.state.exprAllowed = true; }; @@ -87,18 +87,18 @@ tt.incDec.updateContext = function () { }; tt._function.updateContext = function () { - if (this.curContext() !== types.b_stat) { - this.state.context.push(types.f_expr); + if (this.curContext() !== types.braceStatement) { + this.state.context.push(types.functionExpression); } this.state.exprAllowed = false; }; tt.backQuote.updateContext = function () { - if (this.curContext() === types.q_tmpl) { + if (this.curContext() === types.template) { this.state.context.pop(); } else { - this.state.context.push(types.q_tmpl); + this.state.context.push(types.template); } this.state.exprAllowed = false; }; diff --git a/src/tokenizer/index.js b/src/tokenizer/index.js index a029fee07b..1cd5b5c1fc 100644 --- a/src/tokenizer/index.js +++ b/src/tokenizer/index.js @@ -767,7 +767,7 @@ export default class Tokenizer { braceIsBlock(prevType) { if (prevType === tt.colon) { let parent = this.curContext(); - if (parent === ct.b_stat || parent === ct.b_expr) { + if (parent === ct.braceStatement || parent === ct.braceExpression) { return !parent.isExpr; } } @@ -781,7 +781,7 @@ export default class Tokenizer { } if (prevType === tt.braceL) { - return this.curContext() === ct.b_stat; + return this.curContext() === ct.braceStatement; } return !this.state.exprAllowed; diff --git a/src/tokenizer/state.js b/src/tokenizer/state.js index 68104ae947..942c10413e 100644 --- a/src/tokenizer/state.js +++ b/src/tokenizer/state.js @@ -37,7 +37,7 @@ export default class State { this.lastTokEndLoc = this.lastTokStartLoc = null; this.lastTokStart = this.lastTokEnd = this.pos; - this.context = [ct.b_stat]; + this.context = [ct.braceStatement]; this.exprAllowed = true; this.containsEsc = this.containsOctal = false; diff --git a/test/fixtures/jsx/options.json b/test/fixtures/jsx/options.json index de157b98ca..698e766850 100644 --- a/test/fixtures/jsx/options.json +++ b/test/fixtures/jsx/options.json @@ -1,3 +1,3 @@ { - "plugins": ["jsx"] + "plugins": ["jsx", "flow"] }