Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
B
baas-ide
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
guxukai
baas-ide
Commits
ac818121
Commit
ac818121
authored
Oct 01, 2020
by
aniket-engg
Committed by
Aniket
Oct 06, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
AST walk method updated
parent
58b27d5b
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
53 deletions
+30
-53
astWalker.ts
libs/remix-astwalker/src/astWalker.ts
+30
-53
No files found.
libs/remix-astwalker/src/astWalker.ts
View file @
ac818121
...
...
@@ -58,62 +58,43 @@ export class AstWalker extends EventEmitter {
}
}
}
getASTNodeChildren
(
ast
:
AstNode
):
AstNode
[]
{
const
nodes
=
ast
.
nodes
||
(
ast
.
body
&&
ast
.
body
.
statements
)
||
ast
.
declarations
||
[]
if
(
ast
.
body
&&
ast
.
initializationExpression
)
{
// 'for' loop handling
nodes
.
push
(
ast
.
initializationExpression
)
}
return
nodes
}
// eslint-disable-next-line @typescript-eslint/ban-types, @typescript-eslint/explicit-module-boundary-types
walk
(
ast
:
AstNodeLegacy
|
AstNode
,
callback
?:
Function
|
Record
<
string
,
unknown
>
)
{
if
(
callback
)
{
if
(
callback
instanceof
Function
)
{
callback
=
Object
({
"*"
:
callback
});
}
if
(
!
(
"*"
in
callback
))
{
callback
[
"*"
]
=
function
()
{
return
true
;
};
}
if
(
<
AstNodeLegacy
>
ast
)
{
if
(
this
.
manageCallback
(
<
AstNodeLegacy
>
ast
,
callback
)
&&
(
<
AstNodeLegacy
>
ast
).
children
&&
(
<
AstNodeLegacy
>
ast
).
children
.
length
>
0
)
{
for
(
const
k
in
(
<
AstNodeLegacy
>
ast
).
children
)
{
const
child
=
(
<
AstNodeLegacy
>
ast
).
children
[
k
];
this
.
walk
(
child
,
callback
);
}
walk
(
ast
:
AstNode
,
callback
?:
Function
|
Record
<
string
,
unknown
>
)
{
if
(
ast
)
{
const
children
:
AstNode
[]
=
this
.
getASTNodeChildren
(
ast
)
if
(
callback
)
{
if
(
callback
instanceof
Function
)
{
callback
=
Object
({
"*"
:
callback
});
}
}
else
if
(
<
AstNode
>
ast
)
{
if
(
this
.
manageCallback
(
<
AstNode
>
ast
,
callback
)
&&
(
<
AstNode
>
ast
).
nodes
&&
(
<
AstNode
>
ast
).
nodes
.
length
>
0
)
{
for
(
const
k
in
(
<
AstNode
>
ast
).
nodes
)
{
const
child
=
(
<
AstNode
>
ast
).
nodes
[
k
];
this
.
walk
(
child
,
callback
);
}
if
(
!
(
"*"
in
callback
))
{
callback
[
"*"
]
=
function
()
{
return
true
;
};
}
}
}
else
{
if
(
<
AstNodeLegacy
>
ast
)
{
if
(
(
<
AstNodeLegacy
>
ast
).
children
&&
(
<
AstNodeLegacy
>
ast
).
children
.
length
>
0
)
{
for
(
const
k
in
(
<
AstNodeLegacy
>
ast
).
children
)
{
const
child
=
(
<
AstNodeLegacy
>
ast
).
children
[
k
];
this
.
emit
(
"node"
,
child
);
this
.
walk
(
child
);
if
(
this
.
manageCallback
(
ast
,
callback
)
&&
children
?.
length
)
{
for
(
const
k
in
children
)
{
const
child
=
children
[
k
];
this
.
walk
(
child
,
callback
);
}
}
}
if
(
<
AstNode
>
ast
)
{
if
((
<
AstNode
>
ast
).
nodes
&&
(
<
AstNode
>
ast
).
nodes
.
length
>
0
)
{
for
(
const
k
in
(
<
AstNode
>
ast
).
nodes
)
{
const
child
=
(
<
AstNode
>
ast
).
nodes
[
k
]
;
this
.
emit
(
"node"
,
child
);
this
.
walk
(
child
);
}
else
{
if
(
children
?.
length
)
{
for
(
const
k
in
children
)
{
const
child
=
children
[
k
];
this
.
emit
(
"node"
,
child
)
;
this
.
walk
(
child
);
}
}
}
}
}
}
// eslint-disable-next-line @typescript-eslint/ban-types, @typescript-eslint/explicit-module-boundary-types
...
...
@@ -151,14 +132,10 @@ export class AstWalker extends EventEmitter {
if
(
cb
)
{
if
(
sourcesList
.
ast
)
{
this
.
walk
(
sourcesList
.
ast
,
cb
);
}
else
{
this
.
walk
(
sourcesList
.
legacyAST
,
cb
);
}
}
else
{
if
(
sourcesList
.
ast
)
{
this
.
walk
(
sourcesList
.
ast
);
}
else
{
this
.
walk
(
sourcesList
.
legacyAST
);
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment