remove gross acorn conditional statement styling

This commit is contained in:
Sebastian McKenzie 2015-07-26 05:22:33 +01:00
parent 18e610820f
commit d65c29b60a
2 changed files with 49 additions and 21 deletions

View File

@ -349,6 +349,7 @@ pp.jsxParseElementAt = function(startPos, startLoc) {
this.unexpected(); this.unexpected();
} }
} }
if (getQualifiedJSXName(closingElement.name) !== getQualifiedJSXName(openingElement.name)) { if (getQualifiedJSXName(closingElement.name) !== getQualifiedJSXName(openingElement.name)) {
this.raise( this.raise(
closingElement.start, closingElement.start,
@ -377,12 +378,13 @@ pp.jsxParseElement = function() {
export default function(instance) { export default function(instance) {
instance.extend("parseExprAtom", function(inner) { instance.extend("parseExprAtom", function(inner) {
return function(refShortHandDefaultPos) { return function(refShortHandDefaultPos) {
if (this.match(tt.jsxText)) if (this.match(tt.jsxText)) {
return this.parseLiteral(this.state.value); return this.parseLiteral(this.state.value);
else if (this.match(tt.jsxTagStart)) } else if (this.match(tt.jsxTagStart)) {
return this.jsxParseElement(); return this.jsxParseElement();
else } else {
return inner.call(this, refShortHandDefaultPos); return inner.call(this, refShortHandDefaultPos);
}
}; };
}); });
@ -390,24 +392,30 @@ export default function(instance) {
return function(code) { return function(code) {
var context = this.curContext(); 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 (context === tc.j_oTag || context === tc.j_cTag) {
if (isIdentifierStart(code)) return this.jsxReadWord(); if (isIdentifierStart(code)) {
return this.jsxReadWord();
}
if (code === 62) { if (code === 62) {
++this.state.pos; ++this.state.pos;
return this.finishToken(tt.jsxTagEnd); 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); return this.jsxReadString(code);
} }
}
if (code === 60 && this.state.exprAllowed) { if (code === 60 && this.state.exprAllowed) {
++this.state.pos; ++this.state.pos;
return this.finishToken(tt.jsxTagStart); return this.finishToken(tt.jsxTagStart);
} }
return inner.call(this, code); return inner.call(this, code);
}; };
}); });
@ -416,9 +424,13 @@ export default function(instance) {
return function(prevType) { return function(prevType) {
if (this.match(tt.braceL)) { if (this.match(tt.braceL)) {
var curContext = this.curContext(); var curContext = this.curContext();
if (curContext === tc.j_oTag) this.state.context.push(tc.b_expr); if (curContext === tc.j_oTag) {
else if (curContext === tc.j_expr) this.state.context.push(tc.b_tmpl); this.state.context.push(tc.b_expr);
else inner.call(this, prevType); } else if (curContext === tc.j_expr) {
this.state.context.push(tc.b_tmpl);
} else {
inner.call(this, prevType);
}
this.state.exprAllowed = true; this.state.exprAllowed = true;
} else if (this.match(tt.slash) && prevType === tt.jsxTagStart) { } else if (this.match(tt.slash) && prevType === tt.jsxTagStart) {
this.state.context.length -= 2; // do not consider JSX expr -> JSX open tag -> ... anymore this.state.context.length -= 2; // do not consider JSX expr -> JSX open tag -> ... anymore

View File

@ -267,7 +267,9 @@ export default class Tokenizer {
// //
readToken_dot() { readToken_dot() {
let next = this.input.charCodeAt(this.state.pos + 1); 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); let next2 = this.input.charCodeAt(this.state.pos + 2);
if (next === 46 && next2 === 46) { // 46 = dot '.' if (next === 46 && next2 === 46) { // 46 = dot '.'
@ -280,14 +282,18 @@ export default class Tokenizer {
} }
readToken_slash() { // '/' readToken_slash() { // '/'
let next = this.input.charCodeAt(this.state.pos + 1);
if (this.state.exprAllowed) { if (this.state.exprAllowed) {
++this.state.pos; ++this.state.pos;
return this.readRegexp(); return this.readRegexp();
} }
if (next === 61) return this.finishOp(tt.assign, 2);
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); return this.finishOp(tt.slash, 1);
} }
}
readToken_mult_modulo(code) { // '%*' readToken_mult_modulo(code) { // '%*'
var type = code === 42 ? tt.star : tt.modulo; var type = code === 42 ? tt.star : tt.modulo;
@ -537,10 +543,15 @@ export default class Tokenizer {
let start = this.state.pos, total = 0; let start = this.state.pos, total = 0;
for (let i = 0, e = len == null ? Infinity : len; i < e; ++i) { for (let i = 0, e = len == null ? Infinity : len; i < e; ++i) {
let code = this.input.charCodeAt(this.state.pos), val; let code = this.input.charCodeAt(this.state.pos), val;
if (code >= 97) val = code - 97 + 10; // a if (code >= 97) {
else if (code >= 65) val = code - 65 + 10; // A val = code - 97 + 10; // a
else if (code >= 48 && code <= 57) val = code - 48; // 0-9 } else if (code >= 65) {
else val = Infinity; val = code - 65 + 10; // A
} else if (code >= 48 && code <= 57) {
val = code - 48; // 0-9
} else {
val = Infinity;
}
if (val >= radix) break; if (val >= radix) break;
++this.state.pos; ++this.state.pos;
total = total * radix + val; 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"); if (isIdentifierStart(this.fullCharCodeAtPos())) this.raise(this.state.pos, "Identifier directly after number");
let str = this.input.slice(start, this.state.pos), val; let str = this.input.slice(start, this.state.pos), val;
if (isFloat) val = parseFloat(str); if (isFloat) {
else if (!octal || str.length === 1) val = parseInt(str, 10); val = parseFloat(str);
else if (/[89]/.test(str) || this.strict) this.raise(start, "Invalid number"); } else if (!octal || str.length === 1) {
else val = parseInt(str, 8); 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); return this.finishToken(tt.num, val);
} }