Enable no-case-declarations to prevent bugs and remove if (true)
This commit is contained in:
parent
dfb279f478
commit
aec1bdb359
@ -5,7 +5,8 @@
|
||||
"prettier"
|
||||
],
|
||||
"rules": {
|
||||
"prettier/prettier": ["error", { "trailingComma": "all" }]
|
||||
"prettier/prettier": ["error", { "trailingComma": "all" }],
|
||||
"no-case-declarations": "error"
|
||||
},
|
||||
"env": {
|
||||
"node": true
|
||||
|
||||
@ -676,7 +676,7 @@ export default class ExpressionParser extends LValParser {
|
||||
case tt._yield:
|
||||
if (this.state.inGenerator) this.unexpected();
|
||||
|
||||
case tt.name:
|
||||
case tt.name: {
|
||||
node = this.startNode();
|
||||
const allowAwait = this.state.value === "await" && this.state.inAsync;
|
||||
const allowYield = this.shouldAllowYieldIdentifier();
|
||||
@ -705,29 +705,29 @@ export default class ExpressionParser extends LValParser {
|
||||
}
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
case tt._do:
|
||||
// TODO
|
||||
if (true) {
|
||||
this.expectPlugin("doExpressions");
|
||||
const node = this.startNode();
|
||||
this.next();
|
||||
const oldInFunction = this.state.inFunction;
|
||||
const oldLabels = this.state.labels;
|
||||
this.state.labels = [];
|
||||
this.state.inFunction = false;
|
||||
node.body = this.parseBlock(false);
|
||||
this.state.inFunction = oldInFunction;
|
||||
this.state.labels = oldLabels;
|
||||
return this.finishNode(node, "DoExpression");
|
||||
}
|
||||
case tt._do: {
|
||||
this.expectPlugin("doExpressions");
|
||||
const node = this.startNode();
|
||||
this.next();
|
||||
const oldInFunction = this.state.inFunction;
|
||||
const oldLabels = this.state.labels;
|
||||
this.state.labels = [];
|
||||
this.state.inFunction = false;
|
||||
node.body = this.parseBlock(false);
|
||||
this.state.inFunction = oldInFunction;
|
||||
this.state.labels = oldLabels;
|
||||
return this.finishNode(node, "DoExpression");
|
||||
}
|
||||
|
||||
case tt.regexp:
|
||||
case tt.regexp: {
|
||||
const value = this.state.value;
|
||||
node = this.parseLiteral(value.value, "RegExpLiteral");
|
||||
node.pattern = value.pattern;
|
||||
node.flags = value.flags;
|
||||
return node;
|
||||
}
|
||||
|
||||
case tt.num:
|
||||
return this.parseLiteral(this.state.value, "NumericLiteral");
|
||||
@ -781,7 +781,7 @@ export default class ExpressionParser extends LValParser {
|
||||
case tt.backQuote:
|
||||
return this.parseTemplate(false);
|
||||
|
||||
case tt.doubleColon:
|
||||
case tt.doubleColon: {
|
||||
node = this.startNode();
|
||||
this.next();
|
||||
node.object = null;
|
||||
@ -794,6 +794,7 @@ export default class ExpressionParser extends LValParser {
|
||||
"Binding should be performed on object property.",
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
default:
|
||||
throw this.unexpected();
|
||||
|
||||
@ -69,13 +69,14 @@ export default class LValParser extends NodeUtils {
|
||||
this.toAssignable(node.value, isBinding, contextDescription);
|
||||
break;
|
||||
|
||||
case "SpreadElement":
|
||||
case "SpreadElement": {
|
||||
this.checkToRestConversion(node);
|
||||
|
||||
node.type = "RestElement";
|
||||
const arg = node.argument;
|
||||
this.toAssignable(arg, isBinding, contextDescription);
|
||||
break;
|
||||
}
|
||||
|
||||
case "ArrayExpression":
|
||||
node.type = "ArrayPattern";
|
||||
@ -211,11 +212,12 @@ export default class LValParser extends NodeUtils {
|
||||
case tt.name:
|
||||
return this.parseBindingIdentifier();
|
||||
|
||||
case tt.bracketL:
|
||||
case tt.bracketL: {
|
||||
const node = this.startNode();
|
||||
this.next();
|
||||
node.elements = this.parseBindingList(tt.bracketR, true);
|
||||
return this.finishNode(node, "ArrayPattern");
|
||||
}
|
||||
|
||||
case tt.braceL:
|
||||
return this.parseObj(true);
|
||||
|
||||
@ -540,7 +540,7 @@ export default (superClass: Class<Parser>): Class<Parser> =>
|
||||
switch (this.state.type) {
|
||||
case tt.name:
|
||||
case tt._void:
|
||||
case tt._null:
|
||||
case tt._null: {
|
||||
const type = this.match(tt._void)
|
||||
? "TSVoidKeyword"
|
||||
: this.match(tt._null)
|
||||
@ -552,6 +552,7 @@ export default (superClass: Class<Parser>): Class<Parser> =>
|
||||
return this.finishNode(node, type);
|
||||
}
|
||||
return this.tsParseTypeReference();
|
||||
}
|
||||
case tt.string:
|
||||
case tt.num:
|
||||
case tt._true:
|
||||
@ -573,13 +574,14 @@ export default (superClass: Class<Parser>): Class<Parser> =>
|
||||
return this.finishNode(node, "TSLiteralType");
|
||||
}
|
||||
break;
|
||||
case tt._this:
|
||||
case tt._this: {
|
||||
const thisKeyword = this.tsParseThisTypeNode();
|
||||
if (this.isContextual("is") && !this.hasPrecedingLineBreak()) {
|
||||
return this.tsParseThisTypePredicate(thisKeyword);
|
||||
} else {
|
||||
return thisKeyword;
|
||||
}
|
||||
}
|
||||
case tt._typeof:
|
||||
return this.tsParseTypeQuery();
|
||||
case tt.braceL:
|
||||
@ -1038,13 +1040,14 @@ export default (superClass: Class<Parser>): Class<Parser> =>
|
||||
case tt._var:
|
||||
case tt._let:
|
||||
return this.parseVarStatement(nany, this.state.type);
|
||||
case tt.name:
|
||||
case tt.name: {
|
||||
const value = this.state.value;
|
||||
if (value === "global") {
|
||||
return this.tsParseAmbientExternalModuleDeclaration(nany);
|
||||
} else {
|
||||
return this.tsParseDeclaration(nany, value, /* next */ true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1064,14 +1067,14 @@ export default (superClass: Class<Parser>): Class<Parser> =>
|
||||
|
||||
tsParseExpressionStatement(node: any, expr: N.Identifier): ?N.Declaration {
|
||||
switch (expr.name) {
|
||||
case "declare":
|
||||
case "declare": {
|
||||
const declaration = this.tsTryParseDeclare(node);
|
||||
if (declaration) {
|
||||
declaration.declare = true;
|
||||
return declaration;
|
||||
}
|
||||
break;
|
||||
|
||||
}
|
||||
case "global":
|
||||
// `global { }` (with no `declare`) may appear inside an ambient module declaration.
|
||||
// Would like to use tsParseAmbientExternalModuleDeclaration here, but already ran past "global".
|
||||
|
||||
@ -595,11 +595,13 @@ export default class Tokenizer extends LocationParser {
|
||||
++this.state.pos;
|
||||
return this.finishToken(tt.backQuote);
|
||||
|
||||
case 48: // '0'
|
||||
case 48: {
|
||||
// '0'
|
||||
const next = this.input.charCodeAt(this.state.pos + 1);
|
||||
if (next === 120 || next === 88) return this.readRadixNumber(16); // '0x', '0X' - hex number
|
||||
if (next === 111 || next === 79) return this.readRadixNumber(8); // '0o', '0O' - octal number
|
||||
if (next === 98 || next === 66) return this.readRadixNumber(2); // '0b', '0B' - binary number
|
||||
}
|
||||
// Anything else beginning with a digit is an integer, octal
|
||||
// number, or float.
|
||||
case 49:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user