generated from bywhitebird/starter-node
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #68 from bywhitebird/67-bad-expression-transformat…
…ion-in-vue 67 bad expression transformation in vue
- Loading branch information
Showing
44 changed files
with
740 additions
and
382 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import type { z } from 'zod' | ||
|
||
import type * as schemas from '../types/KazAst' | ||
|
||
type AllSchemas = typeof schemas[keyof typeof schemas] | ||
type AllInferedSchemas = Extract<z.infer<AllSchemas>, { $type: string }> | ||
type Visitor = { | ||
[T in AllInferedSchemas['$type']]?: (node: Extract<AllInferedSchemas, { $type: T }>) => void | ||
} & { | ||
enter?: (node: AllInferedSchemas) => void | ||
} | ||
|
||
export const traverse = (ast: AllInferedSchemas, visitor: Visitor) => { | ||
const traverse = (node: AllInferedSchemas) => { | ||
(visitor[node.$type] ?? visitor.enter)?.(node as never) | ||
|
||
for (const key in node) { | ||
const value = node[key as keyof typeof node] as unknown | ||
|
||
if (Array.isArray(value)) { | ||
for (const item of value) { | ||
if (typeof item === 'object' && item !== null) | ||
traverse(item) | ||
} | ||
} | ||
else if (typeof value === 'object' && value !== null && '$type' in value) { | ||
traverse(value as AllInferedSchemas) | ||
} | ||
} | ||
} | ||
|
||
traverse(ast) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.