Skip to content

Commit

Permalink
🐛 fix crash on invalid filters (fixes #37)
Browse files Browse the repository at this point in the history
  • Loading branch information
mysticatea committed Dec 31, 2018
1 parent b599764 commit e44fc8b
Show file tree
Hide file tree
Showing 5 changed files with 1,077 additions and 1 deletion.
24 changes: 23 additions & 1 deletion src/script/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -485,10 +485,32 @@ function parseFilter(
parserOptions,
)
const statement = ast.body[0] as ESLintExpressionStatement
const callExpression = statement.expression as ESLintCallExpression
const callExpression = statement.expression

ast.tokens!.shift()

if (
callExpression.type !== "CallExpression" ||
callExpression.callee.type !== "Literal"
) {
// Report the next token of `)`.
let nestCount = 1
for (const token of ast.tokens!.slice(1)) {
if (nestCount === 0) {
return throwUnexpectedTokenError(token.value, token)
}
if (token.type === "Punctuator" && token.value === "(") {
nestCount += 1
}
if (token.type === "Punctuator" && token.value === ")") {
nestCount -= 1
}
}

const token = last(ast.tokens)!
return throwUnexpectedTokenError(token.value, token)
}

for (const argument of callExpression.arguments) {
argument.parent = expression
expression.arguments.push(argument)
Expand Down
Loading

0 comments on commit e44fc8b

Please sign in to comment.