Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
patricklx committed Nov 8, 2023
1 parent d545258 commit 4682e9c
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
32 changes: 28 additions & 4 deletions lib/parsers/gjs-gts-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,30 @@ function preprocessGlimmerTemplates(info, code) {
n.loc.start = codeLines.offsetToPosition(tpl.templateRange[0]);
n.loc.end = codeLines.offsetToPosition(tpl.templateRange[1]);
}
if (n.type === 'ElementNode') {
n.name = n.tag;
n.parts = [];
let start = n.range[0];
let codeSlice = code.slice(...n.range);
for (const part of n.tag.split('.')) {
const regex = new RegExp(`\\b${part}\\b`);
const match = codeSlice.match(regex);
const range = [start + match.index, 0];
range[1] = range[0] + part.length;
codeSlice = code.slice(range[1], n.range[1]);
start = range[1];
n.parts.push({
type: 'ElementNodePart',
name: part,
range,
parent: n,
loc: {
start: codeLines.offsetToPosition(range[0]),
end: codeLines.offsetToPosition(range[1]),
},
});
}
}
if ('blockParams' in n) {
n.params = [];
}
Expand Down Expand Up @@ -389,10 +413,10 @@ function convertAst(result, preprocessedResult, visitorKeys) {
}
}
if (node.type === 'GlimmerElementNode') {
node.name = node.tag;
const { scope, variable } = findVarInParentScopes(result.scopeManager, path, node.tag) || {};
if (scope && (variable || isUpperCase(node.tag[0]))) {
registerNodeInScope(node, scope, variable);
const n = node.parts.length > 1 ? node.parts[0] : node;
const { scope, variable } = findVarInParentScopes(result.scopeManager, path, n.name) || {};
if (scope && (variable || isUpperCase(n.name[0]) || node.name.includes('.'))) {
registerNodeInScope(n, scope, variable);
}
}

Expand Down
1 change: 1 addition & 0 deletions tests/lib/rules-preprocessor/gjs-gts-parser-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ const invalid = [
{{#let 'x' as |noop notUsed usedEl|}}
{{noop}}
<usedEl />
<usedE2.x />
{{/let}}
</template>
`,
Expand Down

0 comments on commit 4682e9c

Please sign in to comment.