-
-
Notifications
You must be signed in to change notification settings - Fork 127
chore(runtime): replace traverse dependency #2160
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 12 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
c27d8c4
chore(runtime): add full traverse raw library
DoctorFTB bf9cf9d
chore(runtime): remove unused traverse code
DoctorFTB 1d95698
chore(runtime): make traverse more readable
DoctorFTB 7f38c08
chore(runtime): make minimal needed traverse version
DoctorFTB e36f0d6
chore(runtime): move traverse to raw ts
DoctorFTB 278c3ec
chore(runtime): add traverse some types
DoctorFTB cc41135
chore(runtime): remove traverse state, make clean function callback
DoctorFTB 68e5a62
chore(runtime): reindent traverse file tabs to spaces
DoctorFTB c5dca8a
chore(runtime): traverse naming and exports
DoctorFTB e9c546d
chore(runtime): renaming traverse file
DoctorFTB 5a973a4
chore(runtime): add export, remove traverse dependency
DoctorFTB 184aa74
chore(runtime): use custom traverse
DoctorFTB ce850db
fix(runtime): key undefined
DoctorFTB 41ca3cc
fix(runtime): traverse node not updated
DoctorFTB File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,60 @@ | ||
| /* eslint-disable @typescript-eslint/no-explicit-any */ | ||
|
|
||
| type Cb = ( | ||
| data: { | ||
| path: readonly string[]; | ||
| key: string; | ||
| value: any; | ||
| update: (nextValue: any) => void; | ||
| } | ||
| ) => void; | ||
|
|
||
| export function simpleTraverse<T>(root: T, cb: Cb) { | ||
| const path: string[] = []; | ||
| const parents: any[] = []; | ||
|
|
||
| function walker(node: any) { | ||
| const isObject = typeof node === 'object' && node !== null; | ||
| const isCircular = isObject && parents.some((p) => p === node); | ||
| const key = path[path.length - 1]; | ||
DoctorFTB marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| let keepGoing = true; | ||
|
|
||
| function update(nextValue: any) { | ||
| if (path.length) { | ||
| const parent = parents[parents.length - 1]; | ||
| parent[key] = nextValue; | ||
| node = nextValue; | ||
| } | ||
|
|
||
| keepGoing = false; | ||
| } | ||
|
|
||
| cb({ | ||
| path: [...path], | ||
| key, | ||
| value: node, | ||
| update, | ||
| }); | ||
|
|
||
| if (!keepGoing) return node; | ||
|
|
||
| if (isObject && !isCircular) { | ||
| parents.push(node); | ||
|
|
||
| Object.keys(node).forEach((key) => { | ||
| path.push(key); | ||
|
|
||
| walker(node[key]); | ||
|
|
||
| path.pop(); | ||
| }); | ||
|
|
||
| parents.pop(); | ||
| } | ||
|
|
||
| return node; | ||
| } | ||
|
|
||
| return walker(root); | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.