Astro+Directus(Visual-Editing)+Snipcart Test-Stack
This commit is contained in:
commit
1459e99cb0
10119 files changed
+1499318
No files matched your search
+49
@@ -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
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"traverse.d.ts","sourceRoot":"","sources":["../../src/traverser/traverse.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,sBAAsB,EAAE,eAAe,EAAE,yBAAyB,EAAE,IAAI,EAAE,UAAU,EAAE,SAAS,EAAC,MAAM,oBAAoB,CAAC;AAGxI,KAAK,oBAAoB,GAEvB,eAAe,GAEf,sBAAsB,GAEtB,yBAAyB,CAAC;AAE5B,KAAK,IAAI,CAAC,CAAC,GAAG,IAAI,EAAE,IAAI,GAAG,SAAS,IAAI;IAEtC,IAAI,EAAE,CAAC,CAAC;IAER,MAAM,EAAE,CAAC,SAAS,SAAS,GAAG,IAAI,GAAG,UAAU,CAAC;IAGhD,GAAG,EAAE,CAAC,SAAS,SAAS,GAAG,IAAI,GAAG,MAAM,GAAG,MAAM,CAAC;IAGlD,SAAS,EAAE,CAAC,SAAS,SAAS,GAAG,IAAI,GAAG,KAAK,CAAC,oBAAoB,CAAC,GAAG,IAAI,CAAC;IAG3E,IAAI,EAAE,IAAI,CAAC;IAEX,MAAM,EAAE,MAAM,IAAI,CAAC;IAGnB,qBAAqB,EAAE,MAAM,KAAK,CAAC,IAAI,CAAC,CAAC;IAGzC,qBAAqB,EAAE,MAAM,KAAK,CAAC,IAAI,CAAC,CAAC;IAGzC,WAAW,EAAE,CAAC,OAAO,EAAE,IAAI,EAAE,OAAO,CAAC,EAAE;QAAC,QAAQ,CAAC,EAAE,OAAO,CAAA;KAAC,KAAK,IAA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S,EACjF,IAAI,EAAE,IAAI,EACV,OAAO,EAAE,OAAO,CAAC,KAAK,EAAE,IAAI,CAAC,EAC7B,KAAK,GAAE,KAAK,GAAG,IAAW,GACzB,IAAI,CA0HN;AAgBD,OAAO,EACL,KAAK,IAAI,EACT,KAAK,OAAO,EACZ,QAAQ,GACT,CAAC"}
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
"use strict";import{throwIfNullish as A}from"../utils.js";function S(a,v,N=null){function b(e,s){for(let t=0;t<e.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(){x(r).splice(Math.max(0,l(t)+i),1),i--,c=!0},removeAllNextSiblings(){return x(r).splice(l(t)+1)},removeAllPrevSiblings(){const o=l(t)+i;return i-=o,x(r).splice(0,Math.max(0,o))},replaceWith(o,m={}){const y=!!m.traverse;r?r[Math.max(0,l(t)+i)]=o:A(s,"Can't replace root node")[t]=o,y&&n(o,s,t,r),c=!0},replaceWithMultiple(o,m={}){const y=!!m.traverse;if(x(r).splice(Math.max(0,l(t)+i),1,...o),i+=o.length-1,y){let g=0;for(let p=0;p<o.length;p++)g+=n(o[p],s,l(t)+p+g,r)}c=!0},skip(){c=!0}},{type:f}=e,u=v["*"],h=v[f],R=typeof u=="function"?u:u?.enter,P=typeof h=="function"?h:h?.enter;if(R?.(d,N),P?.(d,N),!c)switch(f){case"AbsenceFunction":case"Alternative":case"CapturingGroup":case"CharacterClass":case"Group":case"LookaroundAssertion":b(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"Quantifier":n(e.body,e,"body");break;case"Regex":b(e.body,e),n(e.flags,e,"flags");break;default:throw new Error(`Unexpected node type "${f}"`)}return h?.exit?.(d,N),u?.exit?.(d,N),i}return n(a),a}function x(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
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"version": 3,
|
||||
"sources": ["../../src/traverser/traverse.ts"],
|
||||
"sourcesContent": ["import type {AlternativeElementNode, AlternativeNode, CharacterClassElementNode, Node, ParentNode, RegexNode} from '../parser/parse.js';\nimport {throwIfNullish} from '../utils.js';\n\ntype ContainerElementNode =\n // Used within the `body` container of any `AlternativeContainerNode`\n AlternativeNode |\n // Any node type used within the `body` container of an `AlternativeNode`\n AlternativeElementNode |\n // Any node type used within the `body` container of a `CharacterClassNode`\n CharacterClassElementNode;\n\ntype Path<N = Node, Root = RegexNode> = {\n // The current node being traversed\n node: N;\n // Parent node of the current node\n parent: N extends RegexNode ? null : ParentNode;\n // String property where the current node in held by the parent node, or numeric index in the\n // parent's `container` array\n key: N extends RegexNode ? null : number | string;\n // Container array holding the current node in the parent node; `null` if the parent isn't a type\n // that contains a list of nodes\n container: N extends RegexNode ? null : Array<ContainerElementNode> | null;\n // Starting node of the AST being traversed; usually a `RegexNode` but can be any node type if\n // traversing from a midpoint\n root: Root;\n // Removes the current node; its kids won't be traversed\n remove: () => void;\n // Removes all siblings to the right of the current node, without traversing them; returns the\n // removed nodes\n removeAllNextSiblings: () => Array<Node>;\n // Removes all siblings to the left of the current node, which have already been traversed;\n // returns the removed nodes\n removeAllPrevSiblings: () => Array<Node>;\n // Replaces the current node with a new node; kids of the replaced node won't be traversed;\n // optionally traverses the new node\n replaceWith: (newNode: Node, options?: {traverse?: boolean}) => void;\n // Replaces the current node with multiple new nodes; kids of the replaced node won't be\n // traversed; optionally traverses the new nodes\n replaceWithMultiple: (newNodes: Array<Node>, options?: {traverse?: boolean}) => void;\n // Skips traversing kids of the current node\n skip: () => void;\n};\n\n// `VisitorNodeFn() {\u2026}` is shorthand for `VisitorNodeFn: {enter() {\u2026}}`.\ntype Visitor<State extends object | null = null, Root extends Node = RegexNode> = {\n [N in Node as N['type']]?: VisitorNodeFn<Path<N, Root>, State> | {\n enter?: VisitorNodeFn<Path<N, Root>, State>;\n exit?: VisitorNodeFn<Path<N, Root>, State>;\n };\n} & {\n '*'?: VisitorNodeFn<Path<Node, Root>, State> | {\n enter?: VisitorNodeFn<Path<Node, Root>, State>;\n exit?: VisitorNodeFn<Path<Node, Root>, State>;\n };\n};\n\ntype VisitorNodeFn<P, State> = (path: P, state: State) => void;\n\n/**\nTraverses an AST and calls the provided `visitor`'s node function for each node. Returns the same\nobject, possibly modified.\n\nVisitor node functions can modify the AST in place and use methods on the `path` (provided as their\nfirst argument) to help modify the AST. Provided `state` is passed through to all visitor node\nfunctions as their second argument.\n\nVisitor node functions are called in the following order:\n1. `enter` function of the `'*'` node type (if any)\n2. `enter` function of the given node's type (if any)\n3. [The node's kids (if any) are traversed recursively, unless `skip` is called]\n4. `exit` function of the given node's type (if any)\n5. `exit` function of the `'*'` node type (if any)\n*/\nfunction traverse<State extends object | null = null, Root extends Node = RegexNode>(\n root: Root,\n visitor: Visitor<State, Root>,\n state: State | null = null\n): Root {\n function traverseArray(array: NonNullable<Path['container']>, parent: Path['parent']) {\n for (let i = 0; i < array.length; i++) {\n const keyShift = traverseNode(array[i], parent, i, array);\n i = Math.max(-1, i + keyShift);\n }\n }\n function traverseNode(\n node: Path['node'],\n parent: Path['parent'] = null,\n key: Path['key'] = null,\n container: Path['container'] = null\n ): number {\n let keyShift = 0;\n let skipTraversingKidsOfPath = false;\n const path: Path = {\n node,\n parent,\n key,\n container,\n root: root as RegexNode,\n remove() {\n arrayContainer(container).splice(Math.max(0, numericKey(key) + keyShift), 1);\n keyShift--;\n skipTraversingKidsOfPath = true;\n },\n removeAllNextSiblings() {\n return arrayContainer(container).splice(numericKey(key) + 1);\n },\n removeAllPrevSiblings() {\n const shifted = numericKey(key) + keyShift;\n keyShift -= shifted;\n return arrayContainer(container).splice(0, Math.max(0, shifted));\n },\n replaceWith(newNode, options = {}) {\n const traverseNew = !!options.traverse;\n if (container) {\n container[Math.max(0, numericKey(key) + keyShift)] = newNode as Line truncated
|
||||
"mappings": "aACA,OAAQ,kBAAAA,MAAqB,cAwE7B,SAASC,EACPC,EACAC,EACAC,EAAsB,KAChB,CACN,SAASC,EAAcC,EAAuCC,EAAwB,CACpF,QAASC,EAAI,EAAGA,EAAIF,EAAM,OAAQE,IAAK,CACrC,MAAMC,EAAWC,EAAaJ,EAAME,CAAC,EAAGD,EAAQC,EAAGF,CAAK,EACxDE,EAAI,KAAK,IAAI,GAAIA,EAAIC,CAAQ,CAC/B,CACF,CACA,SAASC,EACPC,EACAJ,EAAyB,KACzBK,EAAmB,KACnBC,EAA+B,KACvB,CACR,IAAIJ,EAAW,EACXK,EAA2B,GAC/B,MAAMC,EAAa,CACjB,KAAAJ,EACA,OAAAJ,EACA,IAAAK,EACA,UAAAC,EACA,KAAMX,EACN,QAAS,CACPc,EAAeH,CAAS,EAAE,OAAO,KAAK,IAAI,EAAGI,EAAWL,CAAG,EAAIH,CAAQ,EAAG,CAAC,EAC3EA,IACAK,EAA2B,EAC7B,EACA,uBAAwB,CACtB,OAAOE,EAAeH,CAAS,EAAE,OAAOI,EAAWL,CAAG,EAAI,CAAC,CAC7D,EACA,uBAAwB,CACtB,MAAMM,EAAUD,EAAWL,CAAG,EAAIH,EAClC,OAAAA,GAAYS,EACLF,EAAeH,CAAS,EAAE,OAAO,EAAG,KAAK,IAAI,EAAGK,CAAO,CAAC,CACjE,EACA,YAAYC,EAASC,EAAU,CAAC,EAAG,CACjC,MAAMC,EAAc,CAAC,CAACD,EAAQ,SAC1BP,EACFA,EAAU,KAAK,IAAI,EAAGI,EAAWL,CAAG,EAAIH,CAAQ,CAAC,EAAIU,EAOrDnB,EAAeO,EAAQ,yBAAyB,EAAEK,CAAa,EAAIO,EAEjEE,GACFX,EAAaS,EAASZ,EAAQK,EAAKC,CAAS,EAE9CC,EAA2B,EAC7B,EACA,oBAAoB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,CACpD,CAIF,OAACE,GAA+D,OAAOX,EAAMX,CAAK,EAEjFqB,GAA6D,OAAOV,EAAMX,CAAK,EACzEK,CACT,CACA,OAAAC,EAAaR,CAAI,EACVA,CACT,CAEA,SAASc,EAAea,EAA6B,CACnD,GAAI,CAAC,MAAM,QAAQA,CAAK,EACtB,MAAM,IAAI,MAAM,oBAAoB,EAEtC,OAAOA,CACT,CAEA,SAASZ,EAAWY,EAAwB,CAC1C,GAAI,OAAOA,GAAU,SACnB,MAAM,IAAI,MAAM,sBAAsB,EAExC,OAAOA,CACT,CAEA,OAGE5B,KAAA",
|
||||
"names": ["throwIfNullish", "traverse", "root", "visitor", "state", "traverseArray", "array", "parent", "i", "keyShift", "traverseNode", "node", "key", "container", "skipTraversingKidsOfPath", "path", "arrayContainer", "numericKey", "shifted", "newNode", "options", "traverseNew", "newNodes", "keyShiftInLoop", "type", "anyTypeVisitor", "thisTypeVisitor", "enterAllFn", "enterThisFn", "value"]
|
||||
}
|
||||
Reference in new issue
Block a user