File tree Expand file tree Collapse file tree 3 files changed +92
-68
lines changed Expand file tree Collapse file tree 3 files changed +92
-68
lines changed Original file line number Diff line number Diff line change @@ -416,15 +416,34 @@ class Transformer extends Source {
416416 ) ;
417417 }
418418
419- if ( node instanceof angular . PrefixNot ) {
419+ const isPrefixNot = node instanceof angular . PrefixNot ;
420+ if ( isPrefixNot || node instanceof angular . TypeofExpression ) {
420421 const expression = this . #transform< babel . Expression > ( node . expression ) ;
422+
423+ const operator = isPrefixNot ? '!' : 'typeof' ;
424+ let { start, end } = node . sourceSpan ;
425+
426+ if ( ! isPrefixNot ) {
427+ const index = this . text . lastIndexOf ( operator , start ) ;
428+
429+ if ( index === - 1 ) {
430+ throw new Error (
431+ `Cannot find operator ${ operator } from index ${ start } in ${ JSON . stringify (
432+ this . text ,
433+ ) } `,
434+ ) ;
435+ }
436+
437+ start = index ;
438+ }
439+
421440 return this . #create< babel . UnaryExpression > (
422441 {
423442 type : 'UnaryExpression' ,
424443 prefix : true ,
425- operator : '!' ,
444+ operator,
426445 argument : expression ,
427- start : node . sourceSpan . start , // !
446+ start,
428447 end : getOuterEnd ( expression ) ,
429448 } ,
430449 { hasParentParens : isInParentParens } ,
@@ -535,6 +554,7 @@ class Transformer extends Source {
535554// SafeCall
536555// EmptyExpr
537556// PrefixNot
557+ // TypeofExpression
538558function transform ( node : angular . AST , text : string ) : NGNode {
539559 return new Transformer ( node , text ) . node ;
540560}
Original file line number Diff line number Diff line change @@ -156,6 +156,7 @@ const KNOWN_AST_TYPES = [
156156 'ImplicitReceiver' ,
157157 'KeyedRead' ,
158158 'SafeKeyedRead' ,
159+ 'TypeofExpression' ,
159160 'KeyedWrite' ,
160161 'LiteralArray' ,
161162 'LiteralMap' ,
You can’t perform that action at this time.
0 commit comments