New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More

@vuedx/template-ast-types

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@vuedx/template-ast-types - npm Package Compare versions

Comparing version

to
0.1.5

@@ -20,3 +20,22 @@ import { Node, RootNode, ElementNode, PlainElementNode, ComponentNode, SlotOutletNode, TemplateNode, TextNode, IfNode, ForNode, CommentNode, SimpleExpressionNode, InterpolationNode, AttributeNode, DirectiveNode, CompoundExpressionNode } from '@vue/compiler-core';

export { isAttributeNode, isCommentNode, isComponentNode, isCompoundExpressionNode, isDirectiveNode, isElementNode, isForNode, isIfNode, isInterpolationNode, isNode, isPlainElementNode, isRootNode, isSimpleExpressionNode, isSlotNode, isTemplateNode, isTextNode };
declare type TraversalAncestors = Array<{
node: Node;
key: string;
index?: number;
}>;
declare type TraversalHandler<T> = (node: Node, ancestors: TraversalAncestors, state: T) => void;
declare type TraversalHandlers<T> = {
enter?: TraversalHandler<T>;
exit?: TraversalHandler<T>;
};
/**
* A general AST traversal with both prefix and postfix handlers, and a
* state object. Exposes ancestry data to each handler so that more complex
* AST data can be taken into account.
*/
declare function traverse<T>(node: Node, handlers: TraversalHandler<T> | TraversalHandlers<T>, state?: T): void;
declare function traverseDepth<T>(node: object, enter: (node: Node, ancestors: TraversalAncestors, state: T) => boolean, state?: any, ancestors?: TraversalAncestors): void;
declare function traverseFast<T = any>(node: object, enter: (node: Node, state: T) => void, state?: T): void;
export { TraversalAncestors, TraversalHandler, TraversalHandlers, isAttributeNode, isCommentNode, isComponentNode, isCompoundExpressionNode, isDirectiveNode, isElementNode, isForNode, isIfNode, isInterpolationNode, isNode, isPlainElementNode, isRootNode, isSimpleExpressionNode, isSlotNode, isTemplateNode, isTextNode, traverse, traverseDepth, traverseFast };
//# sourceMappingURL=template-ast-types.d.ts.map

@@ -50,3 +50,115 @@ function isNode(node) {

export { isAttributeNode, isCommentNode, isComponentNode, isCompoundExpressionNode, isDirectiveNode, isElementNode, isForNode, isIfNode, isInterpolationNode, isNode, isPlainElementNode, isRootNode, isSimpleExpressionNode, isSlotNode, isTemplateNode, isTextNode };
const VISITOR_KEYS = [
['children'],
['props', 'children'],
[],
[],
[],
['content'],
['value'],
['exp', 'arg'],
];
/**
* A general AST traversal with both prefix and postfix handlers, and a
* state object. Exposes ancestry data to each handler so that more complex
* AST data can be taken into account.
*/
function traverse(node, handlers, state) {
if (typeof handlers === 'function') {
handlers = { enter: handlers };
}
const { enter, exit } = handlers;
traverseSimpleImpl(node, enter, exit, state, []);
}
function traverseSimpleImpl(node, enter, exit, state, ancestors) {
if (!isNode(node))
return;
const keys = VISITOR_KEYS[node.type];
if (!keys)
return;
if (enter)
enter(node, ancestors, state);
for (const key of keys) {
const subNode = node[key];
if (Array.isArray(subNode)) {
for (let i = 0; i < subNode.length; i++) {
const child = subNode[i];
if (!child)
continue;
ancestors.push({
node,
key,
index: i,
});
traverseSimpleImpl(child, enter, exit, state, ancestors);
ancestors.pop();
}
}
else if (subNode) {
ancestors.push({
node,
key,
});
traverseSimpleImpl(subNode, enter, exit, state, ancestors);
ancestors.pop();
}
}
if (exit)
exit(node, ancestors, state);
}
function traverseDepth(node, enter, state, ancestors = []) {
if (!isNode(node))
return;
const keys = VISITOR_KEYS[node.type];
if (!keys)
return;
if (enter(node, ancestors, state)) {
for (const key of keys) {
const subNode = node[key];
if (Array.isArray(subNode)) {
for (let i = 0; i < subNode.length; i++) {
const child = subNode[i];
if (!child)
continue;
ancestors.push({
node,
key,
index: i,
});
traverseDepth(child, enter, state, ancestors);
ancestors.pop();
}
}
else if (isNode(subNode)) {
ancestors.push({
node,
key,
});
traverseDepth(subNode, enter, state, ancestors);
ancestors.pop();
}
}
}
}
function traverseFast(node, enter, state) {
if (!isNode(node))
return;
const keys = VISITOR_KEYS[node.type];
if (!keys)
return;
enter(node, state);
for (const key of keys) {
const subNode = node[key];
if (Array.isArray(subNode)) {
for (const node of subNode) {
traverseFast(node, enter, state);
}
}
else if (isNode(subNode)) {
traverseFast(subNode, enter, state);
}
}
}
export { isAttributeNode, isCommentNode, isComponentNode, isCompoundExpressionNode, isDirectiveNode, isElementNode, isForNode, isIfNode, isInterpolationNode, isNode, isPlainElementNode, isRootNode, isSimpleExpressionNode, isSlotNode, isTemplateNode, isTextNode, traverse, traverseDepth, traverseFast };
//# sourceMappingURL=template-ast-types.esm.js.map

@@ -54,2 +54,114 @@ 'use strict';

const VISITOR_KEYS = [
['children'],
['props', 'children'],
[],
[],
[],
['content'],
['value'],
['exp', 'arg'],
];
/**
* A general AST traversal with both prefix and postfix handlers, and a
* state object. Exposes ancestry data to each handler so that more complex
* AST data can be taken into account.
*/
function traverse(node, handlers, state) {
if (typeof handlers === 'function') {
handlers = { enter: handlers };
}
const { enter, exit } = handlers;
traverseSimpleImpl(node, enter, exit, state, []);
}
function traverseSimpleImpl(node, enter, exit, state, ancestors) {
if (!isNode(node))
return;
const keys = VISITOR_KEYS[node.type];
if (!keys)
return;
if (enter)
enter(node, ancestors, state);
for (const key of keys) {
const subNode = node[key];
if (Array.isArray(subNode)) {
for (let i = 0; i < subNode.length; i++) {
const child = subNode[i];
if (!child)
continue;
ancestors.push({
node,
key,
index: i,
});
traverseSimpleImpl(child, enter, exit, state, ancestors);
ancestors.pop();
}
}
else if (subNode) {
ancestors.push({
node,
key,
});
traverseSimpleImpl(subNode, enter, exit, state, ancestors);
ancestors.pop();
}
}
if (exit)
exit(node, ancestors, state);
}
function traverseDepth(node, enter, state, ancestors = []) {
if (!isNode(node))
return;
const keys = VISITOR_KEYS[node.type];
if (!keys)
return;
if (enter(node, ancestors, state)) {
for (const key of keys) {
const subNode = node[key];
if (Array.isArray(subNode)) {
for (let i = 0; i < subNode.length; i++) {
const child = subNode[i];
if (!child)
continue;
ancestors.push({
node,
key,
index: i,
});
traverseDepth(child, enter, state, ancestors);
ancestors.pop();
}
}
else if (isNode(subNode)) {
ancestors.push({
node,
key,
});
traverseDepth(subNode, enter, state, ancestors);
ancestors.pop();
}
}
}
}
function traverseFast(node, enter, state) {
if (!isNode(node))
return;
const keys = VISITOR_KEYS[node.type];
if (!keys)
return;
enter(node, state);
for (const key of keys) {
const subNode = node[key];
if (Array.isArray(subNode)) {
for (const node of subNode) {
traverseFast(node, enter, state);
}
}
else if (isNode(subNode)) {
traverseFast(subNode, enter, state);
}
}
}
exports.isAttributeNode = isAttributeNode;

@@ -71,2 +183,5 @@ exports.isCommentNode = isCommentNode;

exports.isTextNode = isTextNode;
exports.traverse = traverse;
exports.traverseDepth = traverseDepth;
exports.traverseFast = traverseFast;
//# sourceMappingURL=template-ast-types.js.map
{
"name": "@vuedx/template-ast-types",
"version": "0.1.4",
"version": "0.1.5",
"description": "Helper functions for Vue template AST",

@@ -27,3 +27,3 @@ "main": "dist/template-ast-types.js",

"dependencies": {
"@vue/compiler-core": "^3.0.0-rc.4"
"@vue/compiler-core": "^3.0.0-rc.5"
},

@@ -30,0 +30,0 @@ "devDependencies": {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet