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

Fix idempotence of script tags with backticks and Liquid in 'em #163

Merged
merged 1 commit into from
Oct 11, 2023

Conversation

charlespwd
Copy link
Contributor

@charlespwd charlespwd commented Oct 10, 2023

What are you adding in this PR?

  • Fixes the idempotence of pretty printing script tags with Liquid and backticks in them.
    • We were wrapping the contents in new lines and that wasn't the desired behaviour.

Fixes #162

before

before.mp4

after

after.mp4

Before you deploy

  • This PR fixes a bug
    • I included a patch bump changeset to this PR

@charlespwd charlespwd force-pushed the fix/162-prettier-script-backticks branch from 0d9c079 to ef163a0 Compare October 10, 2023 14:53
if (shouldIndentBody) {
return [indent([hardline, body]), hardline];
} else {
return [dedentToRoot([hardline, body]), hardline];
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Had to duplicate this logic slightly because it's complicated to explain 😓.

Basically the parent node would not know if we were able to embed or not (i.e. switch rendering from this plugin's to JS, or TypeScript, or whatever). But we need to know if it failed in order to remove the hardlines and print as is without the surrounding hardlines (which we do on line 231).

@@ -228,17 +228,30 @@ function printNode(
};

if (isRawMarkupIdentationSensitive()) {
return node.value;
return [node.value.trimEnd(), hardline];
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This small difference makes the endtag indent properly.

@charlespwd
Copy link
Contributor Author

Tests pass 🔥

@charlespwd charlespwd merged commit bec7ee0 into main Oct 11, 2023
8 checks passed
@charlespwd charlespwd deleted the fix/162-prettier-script-backticks branch December 2, 2023 19:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

New lines keep being added within script block
1 participant