Skip to content

Use Coffeescript-compatible template expression wrapper #61

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 9 additions & 10 deletions src/script/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import sortedIndexBy from "lodash/sortedIndexBy"
import {
traverseNodes,
ESLintArrayPattern,
ESLintCallExpression,
ESLintArrayExpression,
ESLintExpression,
ESLintExpressionStatement,
ESLintExtendedProgram,
Expand Down Expand Up @@ -364,37 +364,36 @@ function parseExpressionBody(
parserOptions: any,
allowEmpty = false,
): ExpressionParseResult<ESLintExpression> {
debug('[script] parse expression: "0(%s)"', code)
debug('[script] parse expression: "[%s]"', code)

try {
const ast = parseScriptFragment(
`0(${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")
}
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()

Expand Down
4 changes: 2 additions & 2 deletions test/fixtures/ast/error-message-outside/ast.json
Original file line number Diff line number Diff line change
Expand Up @@ -1345,9 +1345,9 @@
},
{
"message": "Unexpected end of expression.",
"index": 76,
"index": 75,
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This appears to be the accurate location data for the trailing 1 in the expression abc + (1 in test/fixtures/ast/error-message-outside/source.vue

"lineNumber": 4,
"column": 24
"column": 23
},
{
"message": "Unexpected end of expression.",
Expand Down