Skip to content

Commit

Permalink
update with custom parser from ember eslint plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
patricklx committed Nov 23, 2023
1 parent dcfb56f commit a796125
Show file tree
Hide file tree
Showing 24 changed files with 5,560 additions and 3,308 deletions.
11 changes: 6 additions & 5 deletions design.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# The Plan

1. Run `Preprocessor.process` from content-tag 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>
Expand Down
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/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
Loading

0 comments on commit a796125

Please sign in to comment.