File tree Expand file tree Collapse file tree 3 files changed +93
-68
lines changed Expand file tree Collapse file tree 3 files changed +93
-68
lines changed Original file line number Diff line number Diff line change @@ -416,15 +416,35 @@ class Transformer extends Source {
416
416
) ;
417
417
}
418
418
419
- if ( node instanceof angular . PrefixNot ) {
419
+ const isPrefixNot = node instanceof angular . PrefixNot ;
420
+ if ( isPrefixNot || node instanceof angular . TypeofExpression ) {
420
421
const expression = this . #transform< babel . Expression > ( node . expression ) ;
422
+
423
+ const operator = isPrefixNot ? '!' : 'typeof' ;
424
+ let { start } = node . sourceSpan ;
425
+
426
+ if ( ! isPrefixNot ) {
427
+ const index = this . text . lastIndexOf ( operator , start ) ;
428
+
429
+ // istanbul ignore next 7
430
+ if ( index === - 1 ) {
431
+ throw new Error (
432
+ `Cannot find operator ${ operator } from index ${ start } in ${ JSON . stringify (
433
+ this . text ,
434
+ ) } `,
435
+ ) ;
436
+ }
437
+
438
+ start = index ;
439
+ }
440
+
421
441
return this . #create< babel . UnaryExpression > (
422
442
{
423
443
type : 'UnaryExpression' ,
424
444
prefix : true ,
425
- operator : '!' ,
445
+ operator,
426
446
argument : expression ,
427
- start : node . sourceSpan . start , // !
447
+ start,
428
448
end : getOuterEnd ( expression ) ,
429
449
} ,
430
450
{ hasParentParens : isInParentParens } ,
@@ -535,6 +555,7 @@ class Transformer extends Source {
535
555
// SafeCall
536
556
// EmptyExpr
537
557
// PrefixNot
558
+ // TypeofExpression
538
559
function transform ( node : angular . AST , text : string ) : NGNode {
539
560
return new Transformer ( node , text ) . node ;
540
561
}
Original file line number Diff line number Diff line change @@ -156,6 +156,7 @@ const KNOWN_AST_TYPES = [
156
156
'ImplicitReceiver' ,
157
157
'KeyedRead' ,
158
158
'SafeKeyedRead' ,
159
+ 'TypeofExpression' ,
159
160
'KeyedWrite' ,
160
161
'LiteralArray' ,
161
162
'LiteralMap' ,
You can’t perform that action at this time.
0 commit comments