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

angular.js templates problem-custom components are converted to self-closing tags #5436

Closed
capaj opened this issue Nov 10, 2018 · 5 comments
Closed
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.

Comments

@capaj
Copy link

capaj commented Nov 10, 2018

So I guess my question is-is this intentional? Prettier doesn't support angular.js?
Because only way to write a custom component in an Angular.js template is to use both opening and closing tag.

@j-f1
Copy link
Member

j-f1 commented Nov 10, 2018

From #1882 (comment):

I just updated to prettier 1.15.2 and I get this when I format our angular.js templates:
image

this totally breaks our angular.js app.
Guess it's back to the old 1.14.x version for us.
Can't you make the conversion to self-closing tags configurable?

@j-f1 j-f1 added status:needs discussion Issues needing discussion and a decision to be made before action can be taken lang:angular Issues affecting Angular template (not general JS/TS issues used for Angular) labels Nov 10, 2018
@capaj
Copy link
Author

capaj commented Nov 10, 2018

BTW I don't mind if prettier says-hey let's not support that archaic framework. I can't wait until we can refactor it all to react in our app.
If this is the case for prettier-it would be nice to document this incompatibility in the readme or somewhere. Especially given the fact that angular.js doesn't give you any errors or warnings when it's compiling your templates. It's just chugging along ignoring the rest of your html happily. So it's really easy to miss the breakage when developing.

@capaj capaj mentioned this issue Nov 10, 2018
@emilio-martinez
Copy link

This isn't a framework issue. Custom elements cannot be self-closing, otherwise known as void elements in the spec: https://html.spec.whatwg.org/multipage/syntax.html#void-elements.

@ikatyang
Copy link
Member

ikatyang commented Nov 10, 2018

It seems you're using --parser babylon, which treats it as JSX:

Prettier 1.15.2
Playground link

--parser babylon

Input:

<analytics-top-resources
  ng-if="analytics.isTabSelected( 'resources' )"
></analytics-top-resources>

Output:

<analytics-top-resources ng-if="analytics.isTabSelected( 'resources' )" />;

Though we did not support angular.js (e.g., format ng-if), but at least it won't break your code with --parser html:

Prettier 1.15.2
Playground link

--parser html

Input:

<analytics-top-resources
  ng-if="analytics.isTabSelected( 'resources' )"
></analytics-top-resources>

Output:

<analytics-top-resources
  ng-if="analytics.isTabSelected( 'resources' )"
></analytics-top-resources>

(Please provide text example next time.)

@ikatyang ikatyang added status:awaiting response Issues that require answers to questions from maintainers before action can be taken and removed status:needs discussion Issues needing discussion and a decision to be made before action can be taken labels Nov 10, 2018
@capaj
Copy link
Author

capaj commented Nov 11, 2018

@ikatyang oh my I am so sorry! I ran the command using my global installation of prettier and didn't notice it until today. 1.15.x works beautifully and it even uncovered cases where we currently have templates with a bad syntax:
image

Accept my humble apologies. I am gonna go and uninstall it now. Global installs are a pain.

Maybe come tho think of it-wouldn't it be nice to show a warning(with a current version printed out) when running prettier from a global install instead of a local one?

@capaj capaj closed this as completed Nov 11, 2018
@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 11, 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 9, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Feb 9, 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.
Projects
None yet
Development

No branches or pull requests

4 participants