0.7.4 • Published 2 years ago

@vuedx/template-ast-types v0.7.4

Weekly downloads
5,315
License
MIT
Repository
github
Last release
2 years ago

Support

This package is part of VueDX project, maintained by Rahul Kadyan. You can 💖 sponsor him for continued development of this package and other VueDX tools.

Usage

npm add @vuedx/template-ast-types

API

createSimpleExpression

Create AST Node

Signature:

declare function createSimpleExpression(content: SimpleExpressionNode['content'], isStatic: SimpleExpressionNode['isStatic'], loc?: SourceLocation, isConstant?: boolean): SimpleExpressionNode;
ParameterTypeDescription
contentSimpleExpressionNode'content'-
isStaticSimpleExpressionNode'isStatic'-
locSourceLocation-
isConstantboolean-

findParentNode

Find the parent element node.

Signature:

declare function findParentNode(ast: RootNode, node: Node): ElementNode | undefined;
ParameterTypeDescription
astRootNode-
nodeNode-

findTemplateChildNodeAt

Find a child (element, component, text, interpolation, or comment) node containing the given position.

Signature:

declare function findTemplateChildNodeAt(ast: RootNode, position: number, mode?: 'start' | 'end'): SearchResult;
ParameterTypeDescription
astRootNode-
positionnumber-
mode'start' | 'end'Open/close range comparison mode: • undefined - position in start, end • 'start' — position in start, end) • 'end' - position in (start, end

findTemplateChildrenInRange

Get all child (element, component, text, interpolation, or comment) nodes contained in given range. (partial overlaps are ignored)

Signature:

declare function findTemplateChildrenInRange(ast: RootNode, start: number, end: number): Node[];
ParameterTypeDescription
astRootNode-
startnumber-
endnumber-

findTemplateNodeAt

Find the deepest node containing the given position.

Signature:

declare function findTemplateNodeAt(ast: RootNode, position: number): SearchResult;
ParameterTypeDescription
astRootNode-
positionnumber-

findTemplateNodeInRange

Find the deepest node containing the given position.

Signature:

declare function findTemplateNodeInRange(ast: RootNode, start: number, end: number, mode?: 'start' | 'end'): SearchResult;
ParameterTypeDescription
astRootNode-
startnumber-
endnumber-
mode'start' | 'end'Open/close range comparison mode: • undefined - position in start, end • 'start' — position in start, end) • 'end' - position in (start, end

findTemplateNodesInRange

Get all nodes contained in given range. (partial overlaps are ignored)

Signature:

declare function findTemplateNodesInRange(ast: RootNode, start: number, end: number): Node[];
ParameterTypeDescription
astRootNode-
startnumber-
endnumber-

isAttributeNode

Checks if it is an AST AttributeNode.

Signature:

declare function isAttributeNode(node: unknown): node is AttributeNode;
ParameterTypeDescription
nodeunknown-

isCommentNode

Checks if it is an AST CommentNode.

Signature:

declare function isCommentNode(node: unknown): node is CommentNode;
ParameterTypeDescription
nodeunknown-

isComponentNode

Checks if it is an AST ComponentNode.

Signature:

declare function isComponentNode(node: unknown): node is ComponentNode;
ParameterTypeDescription
nodeunknown-

isDirectiveNode

Checks if it is an AST DirectiveNode.

Signature:

declare function isDirectiveNode(node: unknown): node is DirectiveNode;
ParameterTypeDescription
nodeunknown-

isElementNode

Checks if it is an AST ElementNode.

Signature:

declare function isElementNode(node: unknown): node is ElementNode;
ParameterTypeDescription
nodeunknown-

isInterpolationNode

Checks if it is an AST InterpolationNode.

Signature:

declare function isInterpolationNode(node: unknown): node is InterpolationNode;
ParameterTypeDescription
nodeunknown-

isNode

Checks if it is Vue template AST Node.

Signature:

declare function isNode(node: unknown): node is Node;
ParameterTypeDescription
nodeunknown-

isPlainElementNode

Checks if it is an AST PlainElementNode.

Signature:

declare function isPlainElementNode(node: unknown): node is PlainElementNode;
ParameterTypeDescription
nodeunknown-

isRootNode

Checks if it is an AST RootNode.

Signature:

declare function isRootNode(node: unknown): node is RootNode;
ParameterTypeDescription
nodeunknown-

isSimpleExpressionNode

Checks if it is an AST ExpressionNode.

Signature:

declare function isSimpleExpressionNode(node: unknown): node is SimpleExpressionNode;
ParameterTypeDescription
nodeunknown-

isSimpleIdentifier

Checks if it is a valid JavaScript identifers.

Signature:

declare function isSimpleIdentifier(content: string): boolean;
ParameterTypeDescription
contentstring-

isTemplateNode

Checks if it is an AST TemplateNode.

Signature:

declare function isTemplateNode(node: unknown): node is TemplateNode;
ParameterTypeDescription
nodeunknown-

isTextNode

Checks if it is an AST TextNode.

Signature:

declare function isTextNode(node: unknown): node is TextNode;
ParameterTypeDescription
nodeunknown-

stringify

Convert template AST to template code.

Signature:

declare function stringify(node: Node | Node[], options?: Partial<StringifyOptions>): string;
ParameterTypeDescription
nodeNode | Node[]-
optionsPartial<StringifyOptions>-

traverse

A general AST traversal utility 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.

Signature:

declare function traverse<T>(node: Node, handlers: TraversalHandler<T> | TraversalHandlers<T>, state?: T): void;
ParameterTypeDescription
nodeNode-
handlersTraversalHandler | TraversalHandlers-
stateT-

traverseEvery

An abortable AST traversal utility. Return false (or falsy value) to stop traversal.

Signature:

declare function traverseEvery<T>(node: Node, enter: (node: Node, ancestors: TraversalAncestors, state: T) => boolean, state?: any, ancestors?: TraversalAncestors): void;
ParameterTypeDescription
nodeNode-
enter(node: Node, ancestors: TraversalAncestors, state: T) => boolean-
stateany-
ancestorsTraversalAncestors-

traverseFast

A faster AST traversal utility. It behaves same as traverse() but there is no ancestory data.

Signature:

declare function traverseFast<T = any>(node: object, enter: (node: Node, state: T, stop: () => void) => void, state?: T): void;
ParameterTypeDescription
nodeobject-
enter(node: Node, state: T, stop: () => void) => void-
stateT-

Types

SearchResult

interface SearchResult {
  ancestors: TraversalAncestors;
  node: Node | null;
}

StringifyOptions

interface StringifyOptions {
  directive: 'shorthand' | 'longhand';
  indent: number;
  initialIndent: number;
  replaceNodes: Map<Node, Node | null>;
}

TraversalHandlers

interface TraversalHandlers<T> {
  enter?: TraversalHandler<T>;
  exit?: TraversalHandler<T>;
}
0.7.4

2 years ago

0.7.3

2 years ago

0.7.2

3 years ago

0.7.1

3 years ago

0.7.0

3 years ago

0.6.2

3 years ago

0.6.0

3 years ago

0.5.0

3 years ago

0.4.1

3 years ago

0.4.0

3 years ago

0.2.4-0

4 years ago

0.2.1

4 years ago

0.2.0

4 years ago

0.2.3

4 years ago

0.2.2

4 years ago

0.1.5

4 years ago

0.1.2

4 years ago

0.1.4

4 years ago

0.1.3

4 years ago

0.1.1

4 years ago

0.1.0-alpha.13

4 years ago