Skip to content

Commit

Permalink
Use a switch statement in validateVar, avoiding Array.prototype.indexOf
Browse files Browse the repository at this point in the history
  • Loading branch information
fstirlitz committed Oct 20, 2019
1 parent 382bebb commit b74beab
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion luaparse.js
Original file line number Diff line number Diff line change
Expand Up @@ -1978,7 +1978,12 @@

function validateVar(node) {
// @TODO we need something not dependent on the exact AST used. see also isCallExpression()
if (node.inParens || (['Identifier', 'MemberExpression', 'IndexExpression'].indexOf(node.type) === -1)) {
switch (node.inParens ? null : node.type) {
case 'Identifier':
case 'MemberExpression':
case 'IndexExpression':
return;
default:
raise(token, errors.invalidVar, token.value);
}
}
Expand Down

0 comments on commit b74beab

Please sign in to comment.