full site update

This commit is contained in:
2025-07-24 18:46:24 +02:00
parent bfe2b90d8d
commit 37a6e0ab31
6912 changed files with 540482 additions and 361712 deletions

View File

@@ -0,0 +1,49 @@
import type { AlternativeElementNode, AlternativeNode, CharacterClassElementNode, Node, ParentNode, RegexNode } from '../parser/parse.js';
type ContainerElementNode = AlternativeNode | AlternativeElementNode | CharacterClassElementNode;
type Path<N = Node, Root = RegexNode> = {
node: N;
parent: N extends RegexNode ? null : ParentNode;
key: N extends RegexNode ? null : number | string;
container: N extends RegexNode ? null : Array<ContainerElementNode> | null;
root: Root;
remove: () => void;
removeAllNextSiblings: () => Array<Node>;
removeAllPrevSiblings: () => Array<Node>;
replaceWith: (newNode: Node, options?: {
traverse?: boolean;
}) => void;
replaceWithMultiple: (newNodes: Array<Node>, options?: {
traverse?: boolean;
}) => void;
skip: () => void;
};
type Visitor<State extends object | null = null, Root extends Node = RegexNode> = {
[N in Node as N['type']]?: VisitorNodeFn<Path<N, Root>, State> | {
enter?: VisitorNodeFn<Path<N, Root>, State>;
exit?: VisitorNodeFn<Path<N, Root>, State>;
};
} & {
'*'?: VisitorNodeFn<Path<Node, Root>, State> | {
enter?: VisitorNodeFn<Path<Node, Root>, State>;
exit?: VisitorNodeFn<Path<Node, Root>, State>;
};
};
type VisitorNodeFn<P, State> = (path: P, state: State) => void;
/**
Traverses an AST and calls the provided `visitor`'s node function for each node. Returns the same
object, possibly modified.
Visitor node functions can modify the AST in place and use methods on the `path` (provided as their
first argument) to help modify the AST. Provided `state` is passed through to all visitor node
functions as their second argument.
Visitor node functions are called in the following order:
1. `enter` function of the `'*'` node type (if any)
2. `enter` function of the given node's type (if any)
3. [The node's kids (if any) are traversed recursively, unless `skip` is called]
4. `exit` function of the given node's type (if any)
5. `exit` function of the `'*'` node type (if any)
*/
declare function traverse<State extends object | null = null, Root extends Node = RegexNode>(root: Root, visitor: Visitor<State, Root>, state?: State | null): Root;
export { type Path, type Visitor, traverse, };
//# sourceMappingURL=traverse.d.ts.map

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.length;t++){const r=n(e[t],s,t,e);t=Math.max(-1,t+r)}}function n(e,s=null,t=null,r=null){let i=0,c=!1;const d={node:e,parent:s,key:t,container:r,root:a,remove(){f(r).splice(Math.max(0,l(t)+i),1),i--,c=!0},removeAllNextSiblings(){return f(r).splice(l(t)+1)},removeAllPrevSiblings(){const o=l(t)+i;return i-=o,f(r).splice(0,Math.max(0,o))},replaceWith(o,y={}){const b=!!y.traverse;r?r[Math.max(0,l(t)+i)]=o:A(s,"Can't replace root node")[t]=o,b&&n(o,s,t,r),c=!0},replaceWithMultiple(o,y={}){const b=!!y.traverse;if(f(r).splice(Math.max(0,l(t)+i),1,...o),i+=o.length-1,b){let g=0;for(let x=0;x<o.length;x++)g+=n(o[x],s,l(t)+x+g,r)}c=!0},skip(){c=!0}},{type:m}=e,h=v["*"],p=v[m],R=typeof h=="function"?h:h?.enter,P=typeof p=="function"?p:p?.enter;if(R?.(d,N),P?.(d,N),!c)switch(m){case"AbsenceFunction":case"CapturingGroup":case"Group":u(e.body,e);break;case"Alternative":case"CharacterClass":u(e.body,e);break;case"Assertion":case"Backreference":case"Character":case"CharacterSet":case"Directive":case"Flags":case"NamedCallout":case"Subroutine":break;case"CharacterClassRange":n(e.min,e,"min"),n(e.max,e,"max");break;case"LookaroundAssertion":u(e.body,e);break;case"Quantifier":n(e.body,e,"body");break;case"Regex":u(e.body,e),n(e.flags,e,"flags");break;default:throw new Error(`Unexpected node type "${m}"`)}return p?.exit?.(d,N),h?.exit?.(d,N),i}return n(a),a}function f(a){if(!Array.isArray(a))throw new Error("Container expected");return a}function l(a){if(typeof a!="number")throw new Error("Numeric key expected");return a}export{S as traverse};
//# sourceMappingURL=traverse.js.map

File diff suppressed because one or more lines are too long