Skip to content

a bug about parseFilter #37

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
marzk opened this issue Dec 25, 2018 · 5 comments
Closed

a bug about parseFilter #37

marzk opened this issue Dec 25, 2018 · 5 comments

Comments

@marzk
Copy link

marzk commented Dec 25, 2018

try eslint to reproduce the bug.

<template>
  <div>{{ 1 | identity() || 0 }}</div>
</template>

<script>
export default {};
</script>

This is because identity() || 0 is LogicalExpression but not CallExpression.

This is the bug code.

//  `parseFilter` in `./src/script/index.ts`

if (argsCode != null) {
    const { ast } = parseScriptFragment(
        `0${argsCode}`,
        locationCalculator.getSubCalculatorAfter(paren - 1),
        parserOptions,
    )
    const statement = ast.body[0] as ESLintExpressionStatement
    const callExpression = statement.expression as ESLintCallExpression

    ast.tokens!.shift()
    
    // this is LogicalExpression
    for (const argument of callExpression.arguments) {
        argument.parent = expression
        expression.arguments.push(argument)
    }
    
    // ...
}

im not good at parser, and I dont know how to fix this bug. So i only create an issue but not a pr.

@mysticatea
Copy link
Member

Thank you for this report.

It doesn't look a documented behavior (https://vuejs.org/v2/guide/filters.html). Would you explain how it works?

cc: @yyx990803 @michalsnik

@marzk
Copy link
Author

marzk commented Dec 29, 2018

Vue parse {{ 1 | identity() || 0 }} as _f("identity")(1,) || 0, its what i means. demo

This is not a standard usage about filter, obviously. But we may make a mistake sometimes, and it can not be debugged easily, because eslint just provide an error 0:0 error Parsing error: callExpression.arguments is not iterable without stack trace.

@mysticatea
Copy link
Member

You are right. We should fix this.

@yyx990803 I'd like to ask the specification. Should we go which way?

  1. ESLint allows that filters usage.
  2. ESLint reports it as a syntax error.

@yyx990803
Copy link
Member

I think this should be a syntax error.

@mysticatea
Copy link
Member

@yyx990803 Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants