angular-estree-parser
Advanced tools
Comparing version
@@ -10,4 +10,4 @@ import * as angular from '@angular/compiler'; | ||
} | ||
type SupportedNodes = angular.ASTWithSource | angular.PropertyRead | angular.PropertyWrite | angular.KeyedWrite | angular.Call | angular.LiteralPrimitive | angular.Unary | angular.Binary | angular.ThisReceiver | angular.KeyedRead | angular.Chain | angular.LiteralMap | angular.LiteralArray | angular.Conditional | angular.NonNullAssert | angular.BindingPipe | angular.SafeKeyedRead | angular.SafePropertyRead | angular.SafeCall | angular.EmptyExpr | angular.PrefixNot | angular.TypeofExpression | angular.TemplateLiteral; | ||
type SupportedNodes = angular.ASTWithSource | angular.PropertyRead | angular.PropertyWrite | angular.KeyedWrite | angular.Call | angular.LiteralPrimitive | angular.Unary | angular.Binary | angular.ThisReceiver | angular.KeyedRead | angular.Chain | angular.LiteralMap | angular.LiteralArray | angular.Conditional | angular.NonNullAssert | angular.BindingPipe | angular.SafeKeyedRead | angular.SafePropertyRead | angular.SafeCall | angular.EmptyExpr | angular.PrefixNot | angular.TypeofExpression | angular.VoidExpression | angular.TemplateLiteral | angular.TaggedTemplateLiteral | angular.ParenthesizedExpression; | ||
declare function transform(node: SupportedNodes, text: string): NGNode; | ||
export { transform, Transformer }; |
@@ -71,3 +71,3 @@ import * as angular from '@angular/compiler'; | ||
const { expressions } = node; | ||
// istanbul ignore next 3 | ||
/* c8 ignore next 3 */ | ||
if (expressions.length !== 1) { | ||
@@ -229,3 +229,3 @@ throw new Error("Unexpected 'Interpolation'"); | ||
return this.#create({ type: 'Identifier', name: 'undefined', ...node.sourceSpan }, { hasParentParens: isInParentParens }); | ||
// istanbul ignore next | ||
/* c8 ignore next 4 */ | ||
default: | ||
@@ -268,15 +268,27 @@ throw new Error(`Unexpected LiteralPrimitive value type ${typeof value}`); | ||
} | ||
const isPrefixNot = node instanceof angular.PrefixNot; | ||
if (isPrefixNot || node instanceof angular.TypeofExpression) { | ||
const expression = this.#transform(node.expression); | ||
const operator = isPrefixNot ? '!' : 'typeof'; | ||
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.'); | ||
} | ||
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(this.text)}`); | ||
throw new Error(`Cannot find operator '${operator}' from index ${start} in ${JSON.stringify(this.text)}`); | ||
} | ||
start = index; | ||
} | ||
const expression = this.#transform(node.expression); | ||
return this.#create({ | ||
@@ -349,2 +361,10 @@ type: 'UnaryExpression', | ||
} | ||
if (node instanceof angular.TaggedTemplateLiteral) { | ||
return this.#create({ | ||
type: 'TaggedTemplateExpression', | ||
tag: this.#transform(node.tag), | ||
quasi: this.#transform(node.template), | ||
...node.sourceSpan, | ||
}); | ||
} | ||
if (node instanceof angular.TemplateLiteral) { | ||
@@ -378,3 +398,6 @@ const { elements, expressions } = node; | ||
} | ||
// istanbul ignore next | ||
if (node instanceof angular.ParenthesizedExpression) { | ||
return this.#transformNode(node.expression); | ||
} | ||
/* c8 ignore next */ | ||
throw new Error(`Unexpected node type '${node.constructor.name}'`); | ||
@@ -381,0 +404,0 @@ } |
@@ -113,3 +113,2 @@ import { ExpressionBinding as NGExpressionBinding, VariableBinding as NGVariableBinding, } from '@angular/compiler'; | ||
const lastNode = body.pop(); | ||
// istanbul ignore else | ||
if (lastNode.type === 'NGMicrosyntaxExpression') { | ||
@@ -123,2 +122,3 @@ body.push(updateExpressionAlias(lastNode)); | ||
else { | ||
/* c8 ignore next 2 */ | ||
throw new Error(`Unexpected type ${lastNode.type}`); | ||
@@ -125,0 +125,0 @@ } |
@@ -64,2 +64,3 @@ function stripSurroundingSpaces({ start: startIndex, end: endIndex }, text) { | ||
} | ||
/* c8 ignore next 4 */ | ||
throw new Error(`Cannot find front char ${pattern} from index ${fromIndex} in ${JSON.stringify(text)}`); | ||
@@ -66,0 +67,0 @@ } |
{ | ||
"name": "angular-estree-parser", | ||
"version": "11.1.1", | ||
"version": "11.2.0", | ||
"description": "A parser that converts Angular source code into an ESTree-compatible form", | ||
@@ -27,6 +27,6 @@ "keywords": [], | ||
"build": "yarn clean && tsc -p ./tsconfig.build.json", | ||
"release": "yarn build && standard-version" | ||
"release": "release-it" | ||
}, | ||
"devDependencies": { | ||
"@angular/compiler": "19.2.2", | ||
"@angular/compiler": "20.0.0-next.8", | ||
"@babel/code-frame": "7.26.2", | ||
@@ -48,3 +48,3 @@ "@babel/parser": "7.26.10", | ||
"prettier": "3.5.3", | ||
"standard-version": "9.5.0", | ||
"release-it": "19.0.1", | ||
"typescript": "5.8.2", | ||
@@ -55,3 +55,3 @@ "typescript-eslint": "8.26.1", | ||
"peerDependencies": { | ||
"@angular/compiler": ">=19.2.2" | ||
"@angular/compiler": ">=19.2.2 || ^20.0.0" | ||
}, | ||
@@ -58,0 +58,0 @@ "engines": { |
46721
2.27%1014
2.53%