Skip to content

Commit fb154af

Browse files
committed
Fix transform of ThisReceiver
1 parent 5faad2f commit fb154af

File tree

3 files changed

+5
-37
lines changed

3 files changed

+5
-37
lines changed

src/transform-node.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ class Transformer extends Source {
171171
return createNode<NGEmptyExpression>({ type: 'NGEmptyExpression' });
172172
}
173173

174-
if (node instanceof angular.ImplicitReceiver) {
174+
if (node instanceof angular.ThisReceiver) {
175175
return createNode<babel.ThisExpression>({ type: 'ThisExpression' });
176176
}
177177

tests/helpers.ts

Lines changed: 3 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -110,42 +110,10 @@ function visitAst(ast: any, fn: (node: any) => void) {
110110
Object.keys(ast).forEach((key) => visitAst(ast[key], fn));
111111
}
112112

113-
const KNOWN_AST_TYPES = [
114-
'ASTWithSource',
115-
'Unary',
116-
'Binary',
117-
'BindingPipe',
118-
'Call',
119-
'Chain',
120-
'Conditional',
121-
'EmptyExpr',
122-
'ImplicitReceiver',
123-
'KeyedRead',
124-
'SafeKeyedRead',
125-
'TypeofExpression',
126-
'LiteralArray',
127-
'LiteralMap',
128-
'LiteralPrimitive',
129-
'NonNullAssert',
130-
'PrefixNot',
131-
'PropertyRead',
132-
'SafeCall',
133-
'SafePropertyRead',
134-
'ThisReceiver',
135-
'Interpolation',
136-
'VoidExpression',
137-
'TemplateLiteral',
138-
'TaggedTemplateLiteral',
139-
'ParenthesizedExpression',
140-
] as const;
141-
142113
export function getAngularNodeType(node: angular.AST) {
143-
if (node instanceof angular.ParenthesizedExpression) {
144-
return getAngularNodeType(node.expression);
114+
while (node instanceof angular.ParenthesizedExpression) {
115+
node = node.expression;
145116
}
146117

147-
return (
148-
KNOWN_AST_TYPES.find((type) => node instanceof angular[type]) ??
149-
node.constructor.name
150-
);
118+
return node.constructor.name;
151119
}

tests/transform.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ const testCases: TestCase[] = [
189189
text: ' a ?. b () ?. [ c ] ',
190190
},
191191
{
192-
expectedAngularType: 'ImplicitReceiver',
192+
expectedAngularType: 'ThisReceiver',
193193
expectedEstreeType: 'ThisExpression',
194194
text: ' this ',
195195
},

0 commit comments

Comments
 (0)