Skip to content

Commit

Permalink
add virtual js nodes to support more eslint rules (#88)
Browse files Browse the repository at this point in the history
* add virtual js nodes

* add virtual js nodes
  • Loading branch information
patricklx authored May 21, 2024
1 parent dcd8f1f commit 845afd6
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/parser/transforms.js
Original file line number Diff line number Diff line change
Expand Up @@ -512,13 +512,29 @@ module.exports.convertAst = function convertAst(result, preprocessedResult, visi
result.scopeManager.declaredVariables || result.scopeManager.__declaredVariables;
const vars = [];
declaredVariables.set(node, vars);
const virtualJSParentNode = {
type: 'FunctionDeclaration',
params: node.params,
range: node.range,
loc: node.loc,
parent: path.parent,
};
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', b, node, node, i, 'Block Param'));
scope.variables.push(v);
scope.set.set(b.name, v);
vars.push(v);

const virtualJSNode = {
type: 'Identifier',
name: b.name,
range: b.range,
loc: b.loc,
parent: virtualJSParentNode,
};
v.defs.push(new Definition('Parameter', virtualJSNode, node, node, i, 'Block Param'));
v.defs.push(new Definition('Parameter', b, node, node, i, 'Block Param'));
}
}
return null;
Expand Down
4 changes: 4 additions & 0 deletions test-projects/gts/.eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ module.exports = {
project: true,
tsconfigRootDir: __dirname
},
rules: {
'no-use-before-define': ['error'],
'no-unused-vars': ['error'],
},
overrides: [
{
files: ['**/*.{js,ts}'],
Expand Down
9 changes: 9 additions & 0 deletions test-projects/gts/src/domain.gts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import Item from 'a';

export const DomainAliases = <template>
<Item>
{{#each @items as |unused domain|}}
{{domain}}
{{/each}}
</Item>
</template>

0 comments on commit 845afd6

Please sign in to comment.