Skip to content

Commit e68cbc8

Browse files
committed
Simplify isImplicitReceiver detection
1 parent fb154af commit e68cbc8

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

src/transform-node.ts

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -365,27 +365,23 @@ class Transformer extends Source {
365365
const isOptional =
366366
node instanceof angular.SafeKeyedRead ||
367367
node instanceof angular.SafePropertyRead;
368-
369368
const { receiver } = node;
370-
371-
let isImplicitThis;
369+
const isImplicitReceiver =
370+
receiver instanceof angular.ImplicitReceiver &&
371+
!(receiver instanceof angular.ThisReceiver);
372372

373373
let property;
374374
if (isComputed) {
375-
isImplicitThis = node.sourceSpan.start === node.key.sourceSpan.start;
376375
property = transformChild<babel.Expression>(node.key);
377376
} else {
378-
const { name, nameSpan } = node;
379-
380-
isImplicitThis = node.sourceSpan.start === nameSpan.start;
381377
property = createNode<babel.Identifier>(
382-
{ type: 'Identifier', name },
378+
{ type: 'Identifier', name: node.name },
383379
node.nameSpan,
384-
isImplicitThis ? ancestors : [],
380+
isImplicitReceiver ? ancestors : [],
385381
);
386382
}
387383

388-
if (isImplicitThis) {
384+
if (isImplicitReceiver) {
389385
return property;
390386
}
391387

@@ -473,7 +469,8 @@ type SupportedNodes =
473469
| angular.LiteralPrimitive
474470
| angular.Unary
475471
| angular.Binary
476-
| angular.ThisReceiver // Not handled
472+
| angular.ThisReceiver
473+
| angular.ImplicitReceiver
477474
| angular.KeyedRead
478475
| angular.Chain
479476
| angular.LiteralMap

tests/transform.test.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,12 @@ const testCases: TestCase[] = [
191191
{
192192
expectedAngularType: 'ThisReceiver',
193193
expectedEstreeType: 'ThisExpression',
194-
text: ' this ',
194+
text: ' ( ( this ) ) ',
195+
},
196+
{
197+
expectedAngularType: 'PropertyRead',
198+
expectedEstreeType: 'MemberExpression',
199+
text: ' ( ( this.a ) ) ',
195200
},
196201
{
197202
expectedAngularType: 'LiteralArray',

0 commit comments

Comments
 (0)