@@ -28,53 +28,64 @@ export default function transform(root: AST.Node, { customHelpers, resolver }: O
28
28
} ,
29
29
} ;
30
30
31
- function handleParams ( params : AST . Expression [ ] ) {
32
- for ( const param of params ) {
33
- if ( param . type !== 'PathExpression' ) continue ;
34
- handlePathExpression ( param ) ;
35
- }
36
- }
37
-
38
- function handleHash ( hash : AST . Hash ) {
39
- for ( const pair of hash . pairs ) {
40
- if ( pair . value . type !== 'PathExpression' ) continue ;
41
- handlePathExpression ( pair . value ) ;
42
- }
43
- }
31
+ function isAmbiguous (
32
+ node : AST . PathExpression
33
+ ) : node is AST . PathExpression & { head : AST . VarHead } {
34
+ const { head } = node ;
44
35
45
- function handlePathExpression ( node : AST . PathExpression ) {
46
36
// skip this.foo
47
- if ( node . this ) {
37
+ if ( head . type === 'ThisHead' ) {
48
38
debug ( `Skipping \`%s\` because it is already prefixed with \`this.\`` , node . original ) ;
49
- return ;
39
+ return false ;
50
40
}
51
41
52
42
// skip @foo
53
- if ( node . data ) {
43
+ if ( head . type === 'AtHead' ) {
54
44
debug ( `Skipping \`%s\` because it is already prefixed with \`@\`` , node . original ) ;
55
- return ;
45
+ return false ;
46
+ }
47
+
48
+ // FIXME: Why special-case this rather than handle it in keywords.ts?
49
+ // skip `hasBlock` keyword
50
+ if ( node . original === 'hasBlock' ) {
51
+ debug ( `Skipping \`%s\` because it is a keyword` , node . original ) ;
52
+ return false ;
56
53
}
57
54
58
55
// skip {#foo as |bar|} }{{bar}}{{/foo}}
59
56
// skip <Foo as |bar|>{{bar}}</Foo>
60
- const firstPart = node . parts [ 0 ] ;
61
- if ( firstPart && scopedParams . includes ( firstPart ) ) {
57
+ if ( scopedParams . includes ( head . name ) ) {
62
58
debug ( `Skipping \`%s\` because it is a scoped variable` , node . original ) ;
63
- return ;
59
+ return false ;
64
60
}
65
61
66
- // skip `hasBlock` keyword
67
- if ( node . original === 'hasBlock' ) {
68
- debug ( `Skipping \`%s\` because it is a keyword` , node . original ) ;
69
- return ;
62
+ return true ;
63
+ }
64
+
65
+ function handleParams ( params : AST . Expression [ ] ) {
66
+ for ( const param of params ) {
67
+ if ( param . type === 'PathExpression' && isAmbiguous ( param ) ) {
68
+ handleThisFallback ( param ) ;
69
+ }
70
+ }
71
+ }
72
+
73
+ function handleHash ( hash : AST . Hash ) {
74
+ for ( const pair of hash . pairs ) {
75
+ if ( pair . value . type === 'PathExpression' && isAmbiguous ( pair . value ) ) {
76
+ handleThisFallback ( pair . value ) ;
77
+ }
70
78
}
79
+ }
71
80
81
+ function handleThisFallback ( node : AST . PathExpression ) {
72
82
// add `this.` prefix
73
83
debug ( `Transforming \`%s\` to \`this.%s\`` , node . original , node . original ) ;
74
84
Object . assign ( node , b . path ( `this.${ node . original } ` ) ) ;
75
85
}
76
86
77
- function isHelper ( name : string ) {
87
+ function hasHelper ( name : string ) {
88
+ // FIXME: Move to resolver
78
89
if ( customHelpers . includes ( name ) ) {
79
90
debug ( `Skipping \`%s\` because it is a custom configured helper` , name ) ;
80
91
return true ;
@@ -89,9 +100,15 @@ export default function transform(root: AST.Node, { customHelpers, resolver }: O
89
100
return false ;
90
101
}
91
102
92
- function isComponent ( name : string ) {
93
- if ( resolver . has ( 'component' , name ) ) {
94
- const message = `Skipping \`%s\` because it appears to be a component from the telemetry data: %s` ;
103
+ function hasAmbiguous ( name : string ) {
104
+ // FIXME: Move to resolver
105
+ if ( customHelpers . includes ( name ) ) {
106
+ debug ( `Skipping \`%s\` because it is a custom configured helper` , name ) ;
107
+ return true ;
108
+ }
109
+
110
+ if ( resolver . has ( 'ambiguous' , name ) ) {
111
+ const message = `Skipping \`%s\` because it appears to be a component or helper from the telemetry data: %s` ;
95
112
debug ( message , name ) ;
96
113
return true ;
97
114
}
@@ -129,8 +146,8 @@ export default function transform(root: AST.Node, { customHelpers, resolver }: O
129
146
// {{FOO}}
130
147
if ( path . type === 'PathExpression' && ! hasParams && ! hasHashPairs ) {
131
148
// {{FOO.bar}}
132
- if ( path . parts . length > 1 ) {
133
- handlePathExpression ( path ) ;
149
+ if ( path . tail . length > 0 && isAmbiguous ( path ) ) {
150
+ handleThisFallback ( path ) ;
134
151
return ;
135
152
}
136
153
@@ -142,13 +159,15 @@ export default function transform(root: AST.Node, { customHelpers, resolver }: O
142
159
return ;
143
160
}
144
161
145
- // skip helpers
146
- if ( isHelper ( path . original ) ) return ;
162
+ if ( isAmbiguous ( path ) ) {
163
+ if ( inAttrNode && hasHelper ( path . original ) ) {
164
+ return ;
165
+ } else if ( ! inAttrNode && hasAmbiguous ( path . original ) ) {
166
+ return ;
167
+ }
147
168
148
- // skip components
149
- if ( ! inAttrNode && isComponent ( path . original ) ) return ;
150
-
151
- handlePathExpression ( path ) ;
169
+ handleThisFallback ( path ) ;
170
+ }
152
171
}
153
172
} ,
154
173
0 commit comments