Skip to content
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

Expressions with nested pipes do not output all BindingPipes as AST nodes #337

Closed
detljh opened this issue Feb 11, 2021 · 2 comments
Closed
Labels
bug Something isn't working

Comments

@detljh
Copy link
Contributor

detljh commented Feb 11, 2021

In expressions with nested pipes, currently only the last pipe appears as an AST node. The other pipes will appear as an exp property of the AST node meaning when creating custom ESLint rules, using the BindingPipe node as the selector will not catch the inner pipes.

convertAnnotatedSourceToFailureCase({
  description: 'should fail when async pipe is used with multiple pipes' ,
  annotatedSource: `
    {{ foo | async | number }}
        ~~~~~~~~~~~~~~~
  `,
  messageId: noAsyncPipe
}),
create(context) {
  return {
    BindingPipe(node: any) {
      console.log(node)
    }
  }
}

Outputs only one BindingPipe node, ie. the last number pipe.

BindingPipe {
  span: ParseSpan { start: 4, end: 24 },
  sourceSpan: AbsoluteSourceSpan { start: 11, end: 31 },
  nameSpan: AbsoluteSourceSpan { start: 25, end: 31 },
  exp: BindingPipe {
    span: ParseSpan { start: 4, end: 15 },
    sourceSpan: AbsoluteSourceSpan { start: 11, end: 22 },
    nameSpan: AbsoluteSourceSpan { start: 17, end: 22 },
    exp: PropertyRead {
      span: [ParseSpan],
      sourceSpan: [AbsoluteSourceSpan],
      nameSpan: [AbsoluteSourceSpan],
      receiver: [ImplicitReceiver],
      name: 'foo'
    },
    name: 'async',
    args: []
  },
  name: 'number',
  args: [],
  type: 'BindingPipe',
  parent: <ref *2> Interpolation {
    span: ParseSpan { start: 0, end: 28 },
    sourceSpan: AbsoluteSourceSpan { start: 7, end: 35 },
    strings: [ ' ', ' ' ],
    expressions: [ [Circular *1] ],
    type: 'Interpolation',
    parent: ASTWithSource {
      span: [ParseSpan],
      sourceSpan: [AbsoluteSourceSpan],
      ast: [Circular *2],
      source: ' {{ foo | async | number }} ',
      location: '<input>@1:6',
      errors: [],
      type: 'ASTWithSource',
      parent: [BoundText]
    }
  }
}

@JamesHenry
Copy link
Member

Thanks @detljh, looks like we are missing BindingPipe: ['exp'] in our visitor keys in the template-parser to make this work.

Would you like to open a PR for that?

@JamesHenry
Copy link
Member

The fix was merged and will be available in the canary release automatically straight after

This was referenced Mar 15, 2021
This was referenced Mar 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants