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

content tag #162

Merged
merged 2 commits into from
Dec 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/ISSUE_TEMPLATE/1-bug-report.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ A clear and concise description of what you expected to happen.
### 🌍 Environment

- prettier-plugin-ember-template-tag version: -
- ember-template-imports version: -
- ember-template-imports version (if applicable): -
- content-tag version (if applicable): -
- eslint-plugin-ember version (if applicable): -

### ➕ Additional Context

Expand Down
13 changes: 6 additions & 7 deletions design.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
# The Plan

1. Run `preprocessEmbeddedTemplates` from ember-template-imports to convert gjs files with `<template>` tags into valid JS. The `<template>` tag gets converted into something like `[__GLIMMER_TEMPLATE('<h1> Hello </h1>', { strictMode: true })]`.
1. Run the `estree` Prettier printer, which formats the valid JS above.
1. Grab template contents from `GLIMMER_TEMPLATE` AST node described above.
1. Run the hbs Prettier printer against the template contents.
1. Replace the `GLIMMER_TEMPLATE` AST node with the results from above, wrapped in `<template>`, like so:
1. Run `Preprocessor.parse` from content-tag to get template locations. manually convert gjs files with `<template>` tags into valid JS, which doesn't change location. The `<template>` tag gets converted into empty strings.
2. convert empty string to a custom `Template` Ast node, which holds the template content.
3. Run the `estree` Prettier printer, which formats the valid JS above.
4. Grab template contents from `Template` AST node described above.
5. Run the hbs Prettier printer against the template contents.
6. Replace the `Template` AST node with the results from above, wrapped in `<template>`, like so:

```gts
<template>
<h1>Hello</h1>
</template>
```

Unfortunately, this will likely involve either monkey-patching or re-implementing the estree printer due to this issue: https://github.com/prettier/prettier/issues/10259
3 changes: 2 additions & 1 deletion examples/bin/test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ const run = async () => {
}
console.log('💅 Running Prettier...');
const prettier = spawn(
'prettier',
'node',
[
'./node_modules/prettier/bin/prettier.cjs',
'.',
'--write',
'--plugin',
Expand Down
2 changes: 1 addition & 1 deletion examples/expected-output/example.gts
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ export interface Signature {
module top level component. Explicit default export module top level
component. Explicit default export module top level component. Explicit
default export module top level component.
</template> as TemplateOnlyComponent<Signature>
</template> as TemplateOnlyComponent<Signature>;
2 changes: 1 addition & 1 deletion examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"scripts": {
"example": "pnpm exec prettier . --write --plugin prettier-plugin-ember-template-tag",
"example-debug": "pnpm exec prettier . --write --plugin prettier-plugin-ember-template-tag --log-level debug",
"test": "./bin/test.mjs"
"test": "node ./bin/test.mjs"
},
"dependencies": {
"prettier": "^3.0.3",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
"@babel/core": "^7.23.2",
"@glimmer/syntax": "^0.84.3",
"ember-cli-htmlbars": "^6.3.0",
"ember-template-imports": "^3.4.2",
"prettier": "^3.0.3"
},
"devDependencies": {
Expand All @@ -67,6 +66,7 @@
"@typescript-eslint/parser": "^6.8.0",
"@vitest/ui": "^0.34.6",
"concurrently": "^8.2.2",
"content-tag": "^1.1.2",
"eslint": "^8.51.0",
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-eslint-comments": "^3.2.0",
Expand Down
Loading