Skip to content
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"release": "yarn build && standard-version"
},
"devDependencies": {
"@angular/compiler": "19.2.1",
"@angular/compiler": "20.0.0-next.1",
"@babel/code-frame": "7.26.2",
"@babel/parser": "7.26.9",
"@babel/types": "7.26.9",
Expand All @@ -50,7 +50,7 @@
"vitest": "3.0.8"
},
"peerDependencies": {
"@angular/compiler": "^19.0.0"
"@angular/compiler": "^19.0.0 || ^20.0.0"
},
"engines": {
"node": ">= 20"
Expand Down
50 changes: 39 additions & 11 deletions src/transform-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ class Transformer extends Source {
if (node instanceof angular.Interpolation) {
const { expressions } = node;

// istanbul ignore next 3
/* c8 ignore next 3 */
if (expressions.length !== 1) {
throw new Error("Unexpected 'Interpolation'");
}
Expand Down Expand Up @@ -373,7 +373,7 @@ class Transformer extends Source {
{ type: 'Identifier', name: 'undefined', ...node.sourceSpan },
{ hasParentParens: isInParentParens },
);
// istanbul ignore next
/* c8 ignore next 4 */
default:
throw new Error(
`Unexpected LiteralPrimitive value type ${typeof value}`,
Expand Down Expand Up @@ -427,20 +427,35 @@ class Transformer extends Source {
);
}

const isPrefixNot = node instanceof angular.PrefixNot;
if (isPrefixNot || node instanceof angular.TypeofExpression) {
const expression = this.#transform<babel.Expression>(node.expression);
if (
node instanceof angular.PrefixNot ||
node instanceof angular.TypeofExpression ||
node instanceof angular.VoidExpression
) {
const operator =
node instanceof angular.PrefixNot
? '!'
: node instanceof angular.TypeofExpression
? 'typeof'
: node instanceof angular.VoidExpression
? 'void'
: /* c8 ignore next */
undefined;

/* c8 ignore next 3 */
if (!operator) {
throw new Error('Unexpected expression.');
}

const operator = isPrefixNot ? '!' : 'typeof';
let { start } = node.sourceSpan;

if (!isPrefixNot) {
if (operator === 'typeof' || operator === 'void') {
const index = this.text.lastIndexOf(operator, start);

// istanbul ignore next 7
/* c8 ignore next 7 */
if (index === -1) {
throw new Error(
`Cannot find operator ${operator} from index ${start} in ${JSON.stringify(
`Cannot find operator '${operator}' from index ${start} in ${JSON.stringify(
this.text,
)}`,
);
Expand All @@ -449,6 +464,8 @@ class Transformer extends Source {
start = index;
}

const expression = this.#transform<babel.Expression>(node.expression);

return this.#create<babel.UnaryExpression>(
{
type: 'UnaryExpression',
Expand Down Expand Up @@ -539,6 +556,15 @@ class Transformer extends Source {
);
}

if (node instanceof angular.TaggedTemplateLiteral) {
return this.#create<babel.TaggedTemplateExpression>({
type: 'TaggedTemplateExpression',
tag: this.#transform(node.tag) as babel.Expression,
quasi: this.#transform(node.template) as babel.TemplateLiteral,
...node.sourceSpan,
});
}

if (node instanceof angular.TemplateLiteral) {
const { elements, expressions } = node;

Expand Down Expand Up @@ -590,7 +616,7 @@ class Transformer extends Source {
);
}

// istanbul ignore next
/* c8 ignore next */
throw new Error(`Unexpected node type '${node.constructor.name}'`);
}
}
Expand Down Expand Up @@ -619,7 +645,9 @@ type SupportedNodes =
| angular.EmptyExpr
| angular.PrefixNot
| angular.TypeofExpression
| angular.TemplateLiteral; // Including `TemplateLiteralElement`
| angular.VoidExpression
| angular.TemplateLiteral // Including `TemplateLiteralElement`
| angular.TaggedTemplateLiteral;
function transform(node: SupportedNodes, text: string): NGNode {
return new Transformer(node, text).node;
}
Expand Down
3 changes: 2 additions & 1 deletion src/transform-template-binding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,13 +168,14 @@ class Transformer extends NodeTransformer {
});

const lastNode = body.pop()!;
// istanbul ignore else

if (lastNode.type === 'NGMicrosyntaxExpression') {
body.push(updateExpressionAlias(lastNode));
} else if (lastNode.type === 'NGMicrosyntaxKeyedExpression') {
const expression = updateExpressionAlias(lastNode.expression);
body.push(updateSpanEnd({ ...lastNode, expression }, expression.end));
} else {
/* c8 ignore next 2 */
throw new Error(`Unexpected type ${lastNode.type}`);
}
} else {
Expand Down
1 change: 1 addition & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ export function getCharacterLastIndex(
}
}

/* c8 ignore next 4 */
throw new Error(
`Cannot find front char ${pattern} from index ${fromIndex} in ${JSON.stringify(
text,
Expand Down
Loading