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
Support printing embedded handlebars in javascript files #8647
base: main
Are you sure you want to change the base?
Conversation
Prettier pr-8647 --parser babel Input: hbs`\``;
html`\``; Output: hbs```;
html`\``; |
Prettier pr-8647 --parser babel Input: hbs`${a}`;
html`${a}`; Output: hbs``;
html`${a}`; |
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please see this comment: #5993 (comment)
9086702
to
5865ea4
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
@dcyriller "The idea is to design a way to use this option to specify the correspondence between template tags, special comments, etc. and embedded syntaxes whereas the default behavior won't be extended anymore." This PR extends the defautl behavior. |
**technical details** javascript's `TaggedTemplateExpression`s with the tag `hbs` will be printed using glimmer printer. **credit** The implementation is taken from html's. It is adapted in two ways: - `hbs` doesn't support printing <script> tags - `hbs` doesn't support interpolation with ${} **usages** `hbs` is provided by the [ember-cli-htmlbars library](https://github.com/ember-cli/ember-cli-htmlbars). The first usage is in tests, where components are rendered: ```js import { hbs } from 'ember-cli-htmlbars'; await render(hbs` <MyComponent /> `); ``` A second usage can be with Storybook: ```js import { text } from '@storybook/addon-knobs'; import hbs from 'htmlbars-inline-precompile'; export default { title: 'Components/Checkbox', }; export const checkbox = () => { return { template: hbs`<Checkbox @Label={{this.label}} {{on "click" this.toggleCheckbox}} />`, context: { label: text('title', 'Welcome to storybook'), toggleCheckbox() {}, }, }; }; checkbox.story = { name: '...', }; ```
To have a consistent implementation with other embed functions. Indeed, a PR is proposing to strip all the finnl new lines in textToDoc function.
e1b3ea0
to
de1b74a
Compare
hbs
hbs
hbs
@thorn0 I read carefully the linked PR and the various issues. I understand well the problem with formatting embedded snippets and that the 1st goal of Prettier is correctness. So I've narrowed this implementation to only format:
Previously it would also format:
If an user selects the option I'm not sure what else I should do. 🤔 |
Any reason why this change is not being merged? If #5588 then why not moving that as well? We're using ember in a large project and would also like to introduce prettier and this is the only stopper. |
@dcyriller 👋 Do you still work on this stuff? Any idea if this can be pushed forward somehow? Thanks! |
Description
hbs
usageshbs
is provided by the ember-cli-htmlbars library.The first usage is in tests, where components are rendered:
A second usage can be with Storybook:
technical details
javascript's
TaggedTemplateExpression
s with the taghbs
will be printed using glimmer printer.credit
This implementation mimicks html's.
It is adapted in two ways:
hbs
doesn't support printing <script> tagshbs
doesn't support interpolation with ${}Links / Related
hbs
#8642Checklist
docs/
directory)changelog_unreleased/*/pr-XXXX.md
file followingchangelog_unreleased/TEMPLATE.md
.✨Try the playground for this PR✨