Skip to content

Commit

Permalink
Merge pull request #15 from NullVoxPopuli/fix-named-block
Browse files Browse the repository at this point in the history
fix named block
  • Loading branch information
patricklx authored Dec 29, 2023
2 parents 93bc92d + 71085b5 commit 58d18b8
Showing 1 changed file with 19 additions and 17 deletions.
36 changes: 19 additions & 17 deletions src/parser/transforms.js
Original file line number Diff line number Diff line change
Expand Up @@ -267,12 +267,12 @@ module.exports.preprocessGlimmerTemplates = function preprocessGlimmerTemplates(
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`);
let pattern = `\\b${part}\\b`;
if (part.startsWith(':')) {
pattern = `${part}\\b`;
}
const regex = new RegExp(pattern);
const match = codeSlice.match(regex);

// named-blocks are not ElementNodes
if (!match && part.startsWith(':')) continue;

const range = [start + match.index, 0];
range[1] = range[0] + part.length;
codeSlice = code.slice(range[1], n.range[1]);
Expand Down Expand Up @@ -426,21 +426,23 @@ module.exports.convertAst = function convertAst(result, preprocessedResult, visi
// always reference first part of tag name, this also has the advantage
// that errors regarding this tag will only mark the tag name instead of
// the whole tag + children
//
// However, with plain <footer> type nodes, there will be no "parts"
const n = node.parts?.[0] ?? node;

const name = n?.name ?? n.tag;

if (htmlTags.includes(name)) {
return null;
}

const n = node.parts[0];
const { scope, variable } = findVarInParentScopes(result.scopeManager, path, n.name) || {};
/*
register a node in scope if we found a variable
we ignore named-blocks as we know that it doesn't reference anything in current scope
if we do not find a variable we register it with a missing variable if
* it starts with upper case, it should be a component with a reference
* it includes a dot, it's a path which should have a reference
* it's NOT a standard html tag, it should have a referenced variable
*/
if (
!n.name.startsWith(':') &&
scope &&
!name.startsWith(':') &&
(variable || isUpperCase(n.name[0]) || name.includes('.') || !htmlTags.includes(name))
(variable ||
isUpperCase(n.name[0]) ||
node.name.includes('.') ||
!htmlTags.includes(node.name))
) {
registerNodeInScope(n, scope, variable);
}
Expand Down

0 comments on commit 58d18b8

Please sign in to comment.