Skip to content

Commit 5252c54

Browse files
committed
Support VoidExpression
1 parent 8c8e375 commit 5252c54

File tree

2 files changed

+88
-75
lines changed

2 files changed

+88
-75
lines changed

src/transform-node.ts

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -427,20 +427,31 @@ class Transformer extends Source {
427427
);
428428
}
429429

430-
const isPrefixNot = node instanceof angular.PrefixNot;
431-
if (isPrefixNot || node instanceof angular.TypeofExpression) {
430+
if (
431+
node instanceof angular.PrefixNot ||
432+
node instanceof angular.TypeofExpression ||
433+
node instanceof angular.VoidExpression
434+
) {
432435
const expression = this.#transform<babel.Expression>(node.expression);
433436

434-
const operator = isPrefixNot ? '!' : 'typeof';
437+
const operator =
438+
node instanceof angular.PrefixNot
439+
? '!'
440+
: node instanceof angular.TypeofExpression
441+
? 'typeof'
442+
: node instanceof angular.VoidExpression
443+
? 'void'
444+
: undefined;
445+
435446
let { start } = node.sourceSpan;
436447

437-
if (!isPrefixNot) {
448+
if (operator === 'typeof' || operator === 'void') {
438449
const index = this.text.lastIndexOf(operator, start);
439450

440451
// istanbul ignore next 7
441452
if (index === -1) {
442453
throw new Error(
443-
`Cannot find operator ${operator} from index ${start} in ${JSON.stringify(
454+
`Cannot find operator '${operator}' from index ${start} in ${JSON.stringify(
444455
this.text,
445456
)}`,
446457
);
@@ -619,6 +630,7 @@ type SupportedNodes =
619630
| angular.EmptyExpr
620631
| angular.PrefixNot
621632
| angular.TypeofExpression
633+
| angular.VoidExpression
622634
| angular.TemplateLiteral; // Including `TemplateLiteralElement`
623635
function transform(node: SupportedNodes, text: string): NGNode {
624636
return new Transformer(node, text).node;

0 commit comments

Comments
 (0)