Skip to content

Commit f27fc6e

Browse files
NullVoxPopuliclaude
andcommitted
Fix content range: pass inner content without <template> tags
preprocessGlimmerTemplates now extracts contentRange and passes inner template content (without <template>/<template> tags) to toTree. Fixes the 10-column position offset that caused eslint-plugin-ember test failures. Template root range is fixed up to cover the full <template>...</template> range afterward. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
1 parent 1c67413 commit f27fc6e

2 files changed

Lines changed: 356 additions & 425 deletions

File tree

src/parser/transforms.js

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,20 +173,32 @@ function isUpperCase(char) {
173173
export function preprocessGlimmerTemplates(info, code) {
174174
const templateInfos = info.templateInfos.map((r) => ({
175175
utf16Range: [r.range.startUtf16Codepoint, r.range.endUtf16Codepoint],
176+
contentRange: [r.contentRange.startUtf16Codepoint, r.contentRange.endUtf16Codepoint],
176177
}));
177178
const codeLines = new DocumentLines(code);
178179
const allComments = [];
179180

180181
for (const tpl of templateInfos) {
181-
const template = code.slice(...tpl.utf16Range);
182+
// Pass inner content only (without <template> tags) to avoid
183+
// glimmer wrapping it in a spurious ElementNode(tag: "template")
184+
const templateContent = code.slice(...tpl.contentRange);
182185

183-
const { ast, comments } = toTree(template, {
186+
const { ast, comments } = toTree(templateContent, {
184187
templateOnly: true,
185188
codeLines,
186-
templateRange: [...tpl.utf16Range],
189+
templateRange: [...tpl.contentRange],
187190
});
188191

189-
ast.content = template;
192+
// Fix the Template root to cover the full <template>...</template> range
193+
ast.range = [...tpl.utf16Range];
194+
ast.start = tpl.utf16Range[0];
195+
ast.end = tpl.utf16Range[1];
196+
ast.loc = {
197+
start: codeLines.offsetToPosition(tpl.utf16Range[0]),
198+
end: codeLines.offsetToPosition(tpl.utf16Range[1]),
199+
};
200+
201+
ast.content = code.slice(...tpl.utf16Range);
190202
allComments.push(...comments);
191203
tpl.ast = ast;
192204
}

0 commit comments

Comments
 (0)