Skip to content

Commit

Permalink
fix location for block params
Browse files Browse the repository at this point in the history
  • Loading branch information
patricklx authored Aug 1, 2023
1 parent 9599f89 commit 39930fa
Showing 1 changed file with 30 additions and 10 deletions.
40 changes: 30 additions & 10 deletions lib/parsers/gjs-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,33 @@ function preprocessGlimmerTemplates(info, code) {
n.loc.start = codeLines.offsetToPosition(tpl.templateRange[0]);
n.loc.end = codeLines.offsetToPosition(tpl.templateRange[1]);
}
if ('blockParams' in node) {

Check failure on line 162 in lib/parsers/gjs-parser.js

View workflow job for this annotation

GitHub Actions / build (ubuntu, 18.x)

Delete `·`

Check failure on line 162 in lib/parsers/gjs-parser.js

View workflow job for this annotation

GitHub Actions / build (ubuntu, 18.x)

'node' is not defined
node.params = [];

Check failure on line 163 in lib/parsers/gjs-parser.js

View workflow job for this annotation

GitHub Actions / build (ubuntu, 18.x)

'node' is not defined
let part = code.slice(...node.range);

Check failure on line 164 in lib/parsers/gjs-parser.js

View workflow job for this annotation

GitHub Actions / build (ubuntu, 18.x)

'node' is not defined
let start = node.range[0];

Check failure on line 165 in lib/parsers/gjs-parser.js

View workflow job for this annotation

GitHub Actions / build (ubuntu, 18.x)

'node' is not defined
let idx = part.indexOf('|');
start += idx;
part = part.slice(idx, -1);
idx = part.indexOf('|');
part = part.slice(idx, -1);

Check failure on line 171 in lib/parsers/gjs-parser.js

View workflow job for this annotation

GitHub Actions / build (ubuntu, 18.x)

Delete `········`
for (const param in node.blockParams) {

Check failure on line 172 in lib/parsers/gjs-parser.js

View workflow job for this annotation

GitHub Actions / build (ubuntu, 18.x)

'node' is not defined
const regex = new RegExp(`\\w${param}\\w`);
const match = part.match(regex);
const range = [start + match.index, 0];
range[1] = range[0] + param.length;
node.params.push({

Check failure on line 177 in lib/parsers/gjs-parser.js

View workflow job for this annotation

GitHub Actions / build (ubuntu, 18.x)

'node' is not defined
type: 'BlockParam',
name: param,
range,
parent: node,

Check failure on line 181 in lib/parsers/gjs-parser.js

View workflow job for this annotation

GitHub Actions / build (ubuntu, 18.x)

'node' is not defined
loc: {
start: codeLines.offsetToPosition(range[0]),
end: codeLines.offsetToPosition(range[1])

Check failure on line 184 in lib/parsers/gjs-parser.js

View workflow job for this annotation

GitHub Actions / build (ubuntu, 18.x)

Insert `,`
}
});
}
}
n.type = `Glimmer__${n.type}`;
allNodeTypes.add(n.type);
}
Expand All @@ -168,7 +195,6 @@ function preprocessGlimmerTemplates(info, code) {
for (const [k, v] of Object.entries(glimmerVisitorKeys)) {
templateVisitorKeys[`Glimmer__${k}`] = [...v];
}
templateVisitorKeys['Glimmer__PathExpression']?.push('identifier', 'member');
return {
templateVisitorKeys,
templateInfos,
Expand Down Expand Up @@ -209,15 +235,9 @@ function convertAst(result, preprocessedResult, visitorKeys) {
const scope = result.isTypescript
? new TypescriptScope.BlockScope(result.scopeManager, upperScope, node)
: new Scope(result.scopeManager, 'block', upperScope, node);
for (const [i, b] of node.blockParams.entries()) {
const v = new Variable(b, scope);
const nameNode = {
type: 'BlockParam',
loc: node.loc,
parent: node,
name: b,
};
v.identifiers.push(nameNode);
for (const [i, b] of node.params.entries()) {
const v = new Variable(b.name, scope);
v.identifiers.push(b);
v.defs.push(new Definition('Parameter', nameNode, node, node, i, 'Block Param'));
scope.variables.push(v);
scope.set.set(b, v);
Expand Down

0 comments on commit 39930fa

Please sign in to comment.