1+ function isInAttrPosition ( node ) {
2+ let p = node . parent ;
3+ while ( p ) {
4+ if ( p . type === 'GlimmerAttrNode' ) {
5+ return true ;
6+ }
7+ if ( p . type === 'GlimmerConcatStatement' ) {
8+ p = p . parent ;
9+ continue ;
10+ }
11+ if (
12+ p . type === 'GlimmerElementNode' ||
13+ p . type === 'GlimmerTemplate' ||
14+ p . type === 'GlimmerBlockStatement' ||
15+ p . type === 'GlimmerBlock'
16+ ) {
17+ return false ;
18+ }
19+ p = p . parent ;
20+ }
21+ return false ;
22+ }
23+
124/** @type {import('eslint').Rule.RuleModule } */
225module . exports = {
326 meta : {
@@ -36,37 +59,28 @@ module.exports = {
3659
3760 function isLocal ( name ) {
3861 for ( const scope of localScopes ) {
39- if ( scope . has ( name ) ) { return true ; }
62+ if ( scope . has ( name ) ) {
63+ return true ;
64+ }
4065 }
4166 return false ;
4267 }
4368
4469 function isDynamicPath ( path ) {
45- if ( ! path || path . type !== 'GlimmerPathExpression' ) { return false ; }
46- if ( path . head ?. type === 'AtHead' ) { return true ; }
47- if ( path . head ?. type === 'ThisHead' ) { return true ; }
48- if ( path . original && path . original . includes ( '.' ) ) { return true ; }
49- if ( path . original && isLocal ( path . original ) ) { return true ; }
50- return false ;
51- }
52-
53- function isInAttrPosition ( node ) {
54- let p = node . parent ;
55- while ( p ) {
56- if ( p . type === 'GlimmerAttrNode' ) { return true ; }
57- if ( p . type === 'GlimmerConcatStatement' ) {
58- p = p . parent ;
59- continue ;
60- }
61- if (
62- p . type === 'GlimmerElementNode' ||
63- p . type === 'GlimmerTemplate' ||
64- p . type === 'GlimmerBlockStatement' ||
65- p . type === 'GlimmerBlock'
66- ) {
67- return false ;
68- }
69- p = p . parent ;
70+ if ( ! path || path . type !== 'GlimmerPathExpression' ) {
71+ return false ;
72+ }
73+ if ( path . head ?. type === 'AtHead' ) {
74+ return true ;
75+ }
76+ if ( path . head ?. type === 'ThisHead' ) {
77+ return true ;
78+ }
79+ if ( path . original && path . original . includes ( '.' ) ) {
80+ return true ;
81+ }
82+ if ( path . original && isLocal ( path . original ) ) {
83+ return true ;
7084 }
7185 return false ;
7286 }
@@ -95,11 +109,7 @@ module.exports = {
95109 } ,
96110
97111 GlimmerSubExpression ( node ) {
98- if (
99- node . path &&
100- node . path . type === 'GlimmerPathExpression' &&
101- isDynamicPath ( node . path )
102- ) {
112+ if ( node . path && node . path . type === 'GlimmerPathExpression' && isDynamicPath ( node . path ) ) {
103113 context . report ( {
104114 node,
105115 messageId : 'noDynamicSubexpressionInvocations' ,
@@ -108,11 +118,7 @@ module.exports = {
108118 } ,
109119
110120 GlimmerElementModifierStatement ( node ) {
111- if (
112- node . path &&
113- node . path . type === 'GlimmerPathExpression' &&
114- isDynamicPath ( node . path )
115- ) {
121+ if ( node . path && node . path . type === 'GlimmerPathExpression' && isDynamicPath ( node . path ) ) {
116122 context . report ( {
117123 node,
118124 messageId : 'noDynamicSubexpressionInvocations' ,
@@ -121,10 +127,7 @@ module.exports = {
121127 } ,
122128
123129 GlimmerMustacheStatement ( node ) {
124- if (
125- node . path &&
126- node . path . type === 'GlimmerPathExpression'
127- ) {
130+ if ( node . path && node . path . type === 'GlimmerPathExpression' ) {
128131 const inAttr = isInAttrPosition ( node ) ;
129132 const hasArgs =
130133 ( node . params && node . params . length > 0 ) ||
0 commit comments