Skip to content

Commit 1719d02

Browse files
committed
fix: externalize prettier/plugins/estree to prevent bundling stale code
The vite config listed `prettier/plugins/estree.js` as external, but the source imports `prettier/plugins/estree` (no .js extension). This mismatch caused vite to bundle prettier's estree printer into the plugin instead of keeping it external. When the user installs a newer version of prettier (e.g. 3.6.2), the plugin still uses the old bundled estree code whose `canAttachComment` function expects 2 arguments, while prettier 3.6+'s core calls it with 1 argument. This causes a crash: TypeError: undefined is not iterable (cannot read property Symbol(Symbol.iterator)) when formatting any .gts file that contains both a comment and a <template> tag. The fix removes the .js extension from the external config so it matches the actual import paths. Also adds a regression test case. Closes #424
1 parent a4bff8f commit 1719d02

5 files changed

Lines changed: 30 additions & 2 deletions

File tree

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// A comment before template
2+
<template>
3+
<div>hello</div>
4+
</template>

tests/unit-tests/__snapshots__/format.test.ts.snap

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,14 @@ const three = <template>{{if true "true"}}</template>;
295295
"
296296
`;
297297
298+
exports[`format > config > default > it formats ../cases/gts/comment-with-template.gts 1`] = `
299+
"// A comment before template
300+
<template>
301+
<div>hello</div>
302+
</template>
303+
"
304+
`;
305+
298306
exports[`format > config > default > it formats ../cases/gts/complex.gts 1`] = `
299307
"import { on } from "@ember/modifier";
300308
import { service } from "@ember/service";

tests/unit-tests/config/__snapshots__/semi-false.test.ts.snap

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,14 @@ const three = <template>{{if true "true"}}</template>
295295
"
296296
`;
297297
298+
exports[`config > semi: false > it formats ../cases/gts/comment-with-template.gts 1`] = `
299+
"// A comment before template
300+
<template>
301+
<div>hello</div>
302+
</template>
303+
"
304+
`;
305+
298306
exports[`config > semi: false > it formats ../cases/gts/complex.gts 1`] = `
299307
"import { on } from "@ember/modifier"
300308
import { service } from "@ember/service"

tests/unit-tests/config/__snapshots__/template-export-default.test.ts.snap

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,14 @@ const three = <template>{{if true "true"}}</template>;
295295
"
296296
`;
297297
298+
exports[`config > templateExportDefault: true > it formats ../cases/gts/comment-with-template.gts 1`] = `
299+
"// A comment before template
300+
<template>
301+
<div>hello</div>
302+
</template>
303+
"
304+
`;
305+
298306
exports[`config > templateExportDefault: true > it formats ../cases/gts/complex.gts 1`] = `
299307
"import { on } from "@ember/modifier";
300308
import { service } from "@ember/service";

vite.config.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ export default defineConfig({
66
external: [
77
'content-tag',
88
'prettier',
9-
'prettier/plugins/estree.js',
10-
'prettier/plugins/babel.js',
9+
'prettier/plugins/estree',
10+
'prettier/plugins/babel',
1111
],
1212
},
1313
lib: {

0 commit comments

Comments
 (0)