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

bug in angular parser/formatter - puts brackets in wrong place which breaks the logic #5475

Closed
kirillgroshkov opened this issue Nov 14, 2018 · 9 comments
Labels
lang:angular Issues affecting Angular template (not general JS/TS issues used for Angular) locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting. type:question Questions and support requests. Please use Stack Overflow for them, not the issue tracker.

Comments

@kirillgroshkov
Copy link

Prettier puts brackets in such place that breaks the angular pipe logic.

Prettier 1.15.2
Playground link

--parser angular

Input:

  <app-submit-button
      class="registrationCodeResult__signupButton"
      >{{
        (cart | async).totalPrice.amount ? 'code-accept' : 'code-accept-free'
          | tmd: (cart | async)
          | stripTags
      }}</app-submit-button
    >

Output:

<app-submit-button
  class="registrationCodeResult__signupButton"
  >{{
    (cart | async).totalPrice.amount
      ? "code-accept"
      : ("code-accept-free" | tmd: (cart | async) | stripTags)
  }}</app-submit-button
>

Expected behavior:

<app-submit-button
  class="registrationCodeResult__signupButton"
  >{{
    (cart | async).totalPrice.amount
      ? "code-accept"
      : "code-accept-free" | tmd: (cart | async) | stripTags
  }}</app-submit-button
>
@ikatyang
Copy link
Member

I tried it on the official Angular parser (@angular/compiler/src/expression_parser) and they look the same:

image

image

@ikatyang ikatyang added status:awaiting response Issues that require answers to questions from maintainers before action can be taken lang:angular Issues affecting Angular template (not general JS/TS issues used for Angular) labels Nov 14, 2018
@kirillgroshkov
Copy link
Author

@ikatyang what does it mean? That the bug is in @angular/compiler/src/expression_parser?

I'm sure that the code before and after Prettier behaves differently.

Before prettier it applies tmd and stripTags pipes for both cases of ternary.

After prettier it applies pipes only for second case of ternary.

@dyatko @ryangibbsnc do you guys confirm the different behaviour?

@no-response no-response bot removed the status:awaiting response Issues that require answers to questions from maintainers before action can be taken label Nov 14, 2018
@ghost

This comment has been minimized.

@ghost

This comment has been minimized.

@ikatyang
Copy link
Member

@kirillgroshkov Since it's the official one, its behavior should be exactly the same as you compiled. The only possible issue I can think of is the version, I got the same result on both Angular 6 and 7, what version of Angular are you using?

@ikatyang

This comment has been minimized.

@ikatyang ikatyang added the status:awaiting response Issues that require answers to questions from maintainers before action can be taken label Nov 14, 2018
@kirillgroshkov
Copy link
Author

@ikatyang We're using Angular 7 there.

yarn list @angular/*
├─ @angular/animations@7.0.3
├─ @angular/cli@7.0.5
├─ @angular/common@7.0.3
├─ @angular/compiler-cli@7.0.3
├─ @angular/compiler@7.0.3
├─ @angular/core@7.0.3
├─ @angular/forms@7.0.3
├─ @angular/language-service@7.0.3
├─ @angular/platform-browser-dynamic@7.0.3
├─ @angular/platform-browser@7.0.3
└─ @angular/router@7.0.3

But. I'm just trying to understand your line of thought. We can both see that issue is reproducible in Prettier playground that shows 1.15.2. I don't know which version of Angular is used there (in the playground). But it produces the same result as for us locally.

@no-response no-response bot removed the status:awaiting response Issues that require answers to questions from maintainers before action can be taken label Nov 14, 2018
@ikatyang
Copy link
Member

We use the parser from Angular 6, but there should be no difference given that there's only a typo fix commit between Angular 6.1.10 (Oct 11) and 7.0.3 (Nov 8), and also I've tested it locally using Angular 7.

Would you mind to run this code in your project? If the output is Conditional (this is the expected output, same as ours) then it must be something wrong in the compiling instead of the parsing. If the output is BindingPipe, ...I can't think of a reason how it can happen.

const ast = require("@angular/compiler").parseTemplate(`{{

    (cart | async).totalPrice.amount ? 'code-accept' : 'code-accept-free'
          | tmd: (cart | async)
          | stripTags

}}`)

console.log(ast.nodes[0].value.ast.expressions[0].constructor.name)

@kirillgroshkov
Copy link
Author

Ok, finally I understand, sorry.

I tried it here and actually confirmed that you were right - that behaviour of prettier doesn't change functionality in Angular. I was wrong.

https://stackblitz.com/edit/angular-playground?file=app%2Fapp.component.html

I expected that this name === 'Angular' ? 'ang' : 'not_ang' | uppercase }} would uppercase the string in both cases of ternary. But it only uppercases in second case.

The root issue we had was actually what was fixed there: #5387 #5397

And I confirm that is not reproducible any more in 1.15.2 (but did exist in 1.15.1).

Closing.

Thanks a lot for clarification!

Too bad it made a lot of noise for us internally because of this breakage.

@ikatyang ikatyang added the type:question Questions and support requests. Please use Stack Overflow for them, not the issue tracker. label Nov 14, 2018
@lock lock bot added the locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting. label Feb 12, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Feb 12, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lang:angular Issues affecting Angular template (not general JS/TS issues used for Angular) locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting. type:question Questions and support requests. Please use Stack Overflow for them, not the issue tracker.
Projects
None yet
Development

No branches or pull requests

2 participants