From bd5c6905e53da018eb36b14f65aaa065fc99aa45 Mon Sep 17 00:00:00 2001 From: Julian Rosse Date: Thu, 2 Jan 2020 18:02:22 -0700 Subject: [PATCH 1/3] 0() -> f() --- src/script/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/script/index.ts b/src/script/index.ts index c5d9e2f8..ee1a3bc1 100644 --- a/src/script/index.ts +++ b/src/script/index.ts @@ -364,11 +364,11 @@ function parseExpressionBody( parserOptions: any, allowEmpty = false, ): ExpressionParseResult { - debug('[script] parse expression: "0(%s)"', code) + debug('[script] parse expression: "f(%s)"', code) try { const ast = parseScriptFragment( - `0(${code})`, + `f(${code})`, locationCalculator.getSubCalculatorAfter(-2), parserOptions, ).ast From 9433aa0e9904c07748b9ced979586a1f95e8e4c1 Mon Sep 17 00:00:00 2001 From: Julian Rosse Date: Thu, 2 Jan 2020 20:20:21 -0700 Subject: [PATCH 2/3] use array instead --- src/script/index.ts | 17 ++++++++--------- .../fixtures/ast/error-message-outside/ast.json | 4 ++-- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/script/index.ts b/src/script/index.ts index ee1a3bc1..8aded5ef 100644 --- a/src/script/index.ts +++ b/src/script/index.ts @@ -9,7 +9,7 @@ import sortedIndexBy from "lodash/sortedIndexBy" import { traverseNodes, ESLintArrayPattern, - ESLintCallExpression, + ESLintArrayExpression, ESLintExpression, ESLintExpressionStatement, ESLintExtendedProgram, @@ -368,16 +368,16 @@ function parseExpressionBody( try { const ast = parseScriptFragment( - `f(${code})`, - locationCalculator.getSubCalculatorAfter(-2), + `[${code}]`, + locationCalculator.getSubCalculatorAfter(-1), parserOptions, ).ast const tokens = ast.tokens || [] const comments = ast.comments || [] const references = analyzeExternalReferences(ast, parserOptions) const statement = ast.body[0] as ESLintExpressionStatement - const callExpression = statement.expression as ESLintCallExpression - const expression = callExpression.arguments[0] + const arrayExpression = statement.expression as ESLintArrayExpression + const expression = arrayExpression.elements[0] if (!allowEmpty && !expression) { return throwEmptyError(locationCalculator, "an expression") @@ -385,16 +385,15 @@ function parseExpressionBody( if (expression && expression.type === "SpreadElement") { return throwUnexpectedTokenError("...", expression) } - if (callExpression.arguments[1]) { - const node = callExpression.arguments[1] + if (arrayExpression.elements[1]) { + const node = arrayExpression.elements[1] return throwUnexpectedTokenError( ",", getCommaTokenBeforeNode(tokens, node) || node, ) } - // Remove parens. - tokens.shift() + // Remove braces. tokens.shift() tokens.pop() diff --git a/test/fixtures/ast/error-message-outside/ast.json b/test/fixtures/ast/error-message-outside/ast.json index 4d4be9bf..f74636a3 100644 --- a/test/fixtures/ast/error-message-outside/ast.json +++ b/test/fixtures/ast/error-message-outside/ast.json @@ -1345,9 +1345,9 @@ }, { "message": "Unexpected end of expression.", - "index": 76, + "index": 75, "lineNumber": 4, - "column": 24 + "column": 23 }, { "message": "Unexpected end of expression.", From 82c2139bceb4a683fe130b3236cd7dd561807dd9 Mon Sep 17 00:00:00 2001 From: Julian Rosse Date: Thu, 2 Jan 2020 20:28:16 -0700 Subject: [PATCH 3/3] update debug string --- src/script/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/script/index.ts b/src/script/index.ts index 8aded5ef..0d8134f8 100644 --- a/src/script/index.ts +++ b/src/script/index.ts @@ -364,7 +364,7 @@ function parseExpressionBody( parserOptions: any, allowEmpty = false, ): ExpressionParseResult { - debug('[script] parse expression: "f(%s)"', code) + debug('[script] parse expression: "[%s]"', code) try { const ast = parseScriptFragment(