Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

angular-estree-parser

Package Overview
Dependencies
Maintainers
3
Versions
44
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

angular-estree-parser - npm Package Compare versions

Comparing version 5.0.2 to 6.0.0

CHANGELOG.md

0

lib/context.d.ts

@@ -0,0 +0,0 @@ export declare class Context {

@@ -0,0 +0,0 @@ import { LinesAndColumns } from 'lines-and-columns';

3

lib/index.d.ts

@@ -5,4 +5,5 @@ import type { NGMicrosyntax, NGNode } from './types.js';

export declare function parseSimpleBinding(input: string): NGNode;
export declare function parseInterpolation(input: string): NGNode;
export declare function parseInterpolationExpression(input: string): NGNode;
export declare function parseAction(input: string): NGNode;
export declare function parseTemplateBindings(input: string): NGMicrosyntax;
export declare const parseInterpolation: typeof parseInterpolationExpression;
import { Context } from './context.js';
import { transform } from './transform.js';
import { transformTemplateBindings } from './transform-microsyntax.js';
import { parseNgAction, parseNgBinding, parseNgInterpolation, parseNgSimpleBinding, parseNgTemplateBindings, } from './utils.js';
import { parseNgAction, parseNgBinding, parseNgInterpolationExpression, parseNgSimpleBinding, parseNgTemplateBindings, } from './utils.js';
function parse(input, parseNg) {

@@ -19,4 +19,4 @@ const { ast: rawNgAst, comments } = parseNg(input);

}
export function parseInterpolation(input) {
return parse(input, parseNgInterpolation);
export function parseInterpolationExpression(input) {
return parse(input, parseNgInterpolationExpression);
}

@@ -29,1 +29,3 @@ export function parseAction(input) {

}
// TODO: Remove this in next major
export const parseInterpolation = parseInterpolationExpression;

@@ -0,0 +0,0 @@ import type * as ng from '@angular/compiler';

@@ -0,0 +0,0 @@ import { ExpressionBinding as NGExpressionBinding, VariableBinding as NGVariableBinding, } from '@angular/compiler';

@@ -0,0 +0,0 @@ import type * as ng from '@angular/compiler';

@@ -12,3 +12,3 @@ import { findBackChar, findFrontChar, fitSpans, getLast, getNgType, } from './utils.js';

operator: operator,
}, node.span, { hasParentParens: isInParentParens });
}, node.sourceSpan, { hasParentParens: isInParentParens });
}

@@ -45,7 +45,7 @@ case 'Binary': {

const { expressions } = node;
return _c('NGChainedExpression', { expressions: expressions.map(_t) }, node.span, { hasParentParens: isInParentParens });
return _c('NGChainedExpression', { expressions: expressions.map(_t) }, node.sourceSpan, { hasParentParens: isInParentParens });
}
case 'Comment': {
const { value } = node;
return _c('CommentLine', { value }, node.span, {
return _c('CommentLine', { value }, node.sourceSpan, {
processSpan: false,

@@ -66,7 +66,7 @@ });

case 'EmptyExpr':
return _c('NGEmptyExpression', {}, node.span, {
return _c('NGEmptyExpression', {}, node.sourceSpan, {
hasParentParens: isInParentParens,
});
case 'ImplicitReceiver': {
return _c('ThisExpression', {}, node.span, {
return _c('ThisExpression', {}, node.sourceSpan, {
hasParentParens: isInParentParens,

@@ -86,3 +86,3 @@ });

}, {
end: node.span.end,
end: node.sourceSpan.end,
hasParentParens: isInParentParens,

@@ -93,3 +93,3 @@ });

const { expressions } = node;
return _c('ArrayExpression', { elements: expressions.map(_t) }, node.span, { hasParentParens: isInParentParens });
return _c('ArrayExpression', { elements: expressions.map(_t) }, node.sourceSpan, { hasParentParens: isInParentParens });
}

@@ -104,3 +104,3 @@ case 'LiteralMap': {

const keyStart = _findBackChar(/\S/, index === 0
? node.span.start + 1 // {
? node.sourceSpan.start + 1 // {
: _findBackChar(/,/, _getOuterEnd(tValues[index - 1])) + 1);

@@ -123,3 +123,3 @@ const keyEnd = valueStart === keyStart

});
return _c('ObjectExpression', { properties: tProperties }, node.span, { hasParentParens: isInParentParens });
return _c('ObjectExpression', { properties: tProperties }, node.sourceSpan, { hasParentParens: isInParentParens });
}

@@ -130,19 +130,19 @@ case 'LiteralPrimitive': {

case 'boolean':
return _c('BooleanLiteral', { value }, node.span, {
return _c('BooleanLiteral', { value }, node.sourceSpan, {
hasParentParens: isInParentParens,
});
case 'number':
return _c('NumericLiteral', { value }, node.span, {
return _c('NumericLiteral', { value }, node.sourceSpan, {
hasParentParens: isInParentParens,
});
case 'object':
return _c('NullLiteral', {}, node.span, {
return _c('NullLiteral', {}, node.sourceSpan, {
hasParentParens: isInParentParens,
});
case 'string':
return _c('StringLiteral', { value }, node.span, {
return _c('StringLiteral', { value }, node.sourceSpan, {
hasParentParens: isInParentParens,
});
case 'undefined':
return _c('Identifier', { name: 'undefined' }, node.span, { hasParentParens: isInParentParens });
return _c('Identifier', { name: 'undefined' }, node.sourceSpan, { hasParentParens: isInParentParens });
// istanbul ignore next

@@ -171,3 +171,3 @@ default:

start: _getOuterStart(tReceiver),
end: node.span.end, // )
end: node.sourceSpan.end, // )
}, { hasParentParens: isInParentParens });

@@ -180,3 +180,3 @@ }

start: _getOuterStart(tExpression),
end: node.span.end, // !
end: node.sourceSpan.end, // !
}, { hasParentParens: isInParentParens });

@@ -192,3 +192,3 @@ }

}, {
start: node.span.start,
start: node.sourceSpan.start,
end: _getOuterEnd(tExpression),

@@ -201,3 +201,3 @@ }, { hasParentParens: isInParentParens });

const { receiver, name } = node;
const nameEnd = _findFrontChar(/\S/, node.span.end - 1) + 1;
const nameEnd = _findFrontChar(/\S/, node.sourceSpan.end - 1) + 1;
const tName = _c('Identifier', { name }, { start: nameEnd - name.length, end: nameEnd }, _isImplicitThis(receiver) ? { hasParentParens: isInParentParens } : {});

@@ -295,3 +295,4 @@ return _transformReceiverAndName(receiver, tName, {

function _transformReceiverAndName(receiver, tName, props, { end = _getOuterEnd(tName), hasParentParens = false } = {}) {
if (_isImplicitThis(receiver) || receiver.span.start === tName.start) {
if (_isImplicitThis(receiver) ||
receiver.sourceSpan.start === tName.start) {
return tName;

@@ -321,4 +322,4 @@ }

function _isImplicitThis(n) {
return (n.span.start >= n.span.end ||
/^\s+$/.test(context.text.slice(n.span.start, n.span.end)));
return (n.sourceSpan.start >= n.sourceSpan.end ||
/^\s+$/.test(context.text.slice(n.sourceSpan.start, n.sourceSpan.end)));
}

@@ -325,0 +326,0 @@ function _isOptionalReceiver(n) {

@@ -32,3 +32,3 @@ import type * as b from '@babel/types';

value: string;
span: RawNGSpan;
sourceSpan: RawNGSpan;
}

@@ -35,0 +35,0 @@ export interface RawNGSpan {

export {};

@@ -16,7 +16,7 @@ import * as ng from '@angular/compiler';

};
export declare function parseNgTemplateBindings(input: string): ng.TemplateBinding[];
export declare function parseNgInterpolation(input: string): {
ast: any;
export declare function parseNgInterpolationExpression(input: string): {
ast: ng.AST;
comments: RawNGComment[];
};
export declare function parseNgTemplateBindings(input: string): ng.TemplateBinding[];
export declare function getNgType(node: (ng.AST | RawNGComment) & {

@@ -23,0 +23,0 @@ type?: string;

@@ -29,2 +29,9 @@ import * as ng from '@angular/compiler';

}
export function parseNgInterpolationExpression(input) {
return parseNg(input, (astInput, ngParser) => {
const result = ngParser.parseInterpolationExpression(astInput, ...NG_PARSE_SHARED_PARAMS);
result.ast = result.ast.expressions[0];
return result;
});
}
export function parseNgTemplateBindings(input) {

@@ -36,37 +43,2 @@ const ngParser = createNgParser();

}
export function parseNgInterpolation(input) {
const ngParser = createNgParser();
const { astInput, comments } = extractComments(input, ngParser);
const prefix = '{{';
const suffix = '}}';
const { ast: rawAst, errors } = ngParser.parseInterpolation(prefix + astInput + suffix, ...NG_PARSE_SHARED_PARAMS, null);
assertAstErrors(errors);
const ast = rawAst.expressions[0];
const visited = new Set();
visitSpan(ast, (span) => {
if (!visited.has(span)) {
span.start -= prefix.length;
span.end -= prefix.length;
visited.add(span);
}
});
return { ast, comments };
}
function visitSpan(ast, fn) {
if (!ast || typeof ast !== 'object') {
return;
}
if (Array.isArray(ast)) {
return ast.forEach((value) => visitSpan(value, fn));
}
for (const key of Object.keys(ast)) {
const value = ast[key];
if (key === 'span') {
fn(value);
}
else {
visitSpan(value, fn);
}
}
}
function assertAstErrors(errors) {

@@ -89,3 +61,3 @@ if (errors.length !== 0) {

value: input.slice(commentStart + '//'.length),
span: { start: commentStart, end: input.length },
sourceSpan: { start: commentStart, end: input.length },
},

@@ -92,0 +64,0 @@ ],

{
"name": "angular-estree-parser",
"version": "5.0.2",
"version": "6.0.0",
"description": "A parser that converts Angular source code into an ESTree-compatible form",

@@ -17,12 +17,12 @@ "keywords": [],

"scripts": {
"clean": "del-cli ./lib",
"prepare": "yarn run build",
"test": "node --experimental-vm-modules node_modules/jest/bin/jest.js",
"lint": "run-p lint:*",
"lint": "run-p \"lint:*\"",
"lint:eslint": "eslint --ext=.ts,.js,.cjs .",
"lint:prettier": "prettier --check src",
"fix": "run-s fix:*",
"fix": "run-s \"fix:*\"",
"fix:eslint": "yarn lint:eslint --fix",
"fix:prettier": "yarn lint:prettier --write",
"prebuild": "del-cli ./lib",
"build": "tsc -p ./tsconfig.build.json",
"build": "yarn clean && tsc -p ./tsconfig.build.json",
"release": "yarn build && standard-version"

@@ -32,20 +32,20 @@ },

"lines-and-columns": "^2.0.3",
"tslib": "^2.4.1"
"tslib": "^2.5.0"
},
"devDependencies": {
"@angular/compiler": "15.1.0",
"@angular/compiler": "15.1.2",
"@babel/code-frame": "7.18.6",
"@babel/parser": "7.20.7",
"@babel/parser": "7.20.13",
"@babel/types": "7.20.7",
"@types/babel-types": "7.0.11",
"@types/babel__code-frame": "7.0.3",
"@types/jest": "29.2.5",
"@types/jest": "29.4.0",
"@types/prettier": "2.7.2",
"@typescript-eslint/eslint-plugin": "5.48.2",
"@typescript-eslint/parser": "5.48.2",
"@typescript-eslint/eslint-plugin": "5.49.0",
"@typescript-eslint/parser": "5.49.0",
"del-cli": "5.0.0",
"eslint": "8.32.0",
"eslint": "8.33.0",
"eslint-config-prettier": "8.6.0",
"eslint-plugin-import": "2.27.5",
"jest": "29.3.1",
"jest": "29.4.1",
"jest-snapshot-serializer-raw": "1.2.0",

@@ -71,3 +71,4 @@ "npm-run-all": "4.1.5",

"registry": "https://registry.npmjs.org/"
}
},
"packageManager": "yarn@3.3.1"
}

@@ -34,3 +34,3 @@ # angular-estree-parser

- `parseBinding(input: string): AST` for `[target]="input"`
- `parseInterpolation(input: string): AST` for `{{input}}`
- `parseInterpolationExpression(input: string): AST` for `{{input}}`
- `parseTemplateBindings(input: string): AST` for `*directive="input"`

@@ -37,0 +37,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc