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
fa6da75f
Commit
fa6da75f
authored
Oct 05, 2020
by
aniket-engg
Committed by
Aniket
Oct 06, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tests
parent
c71e8249
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
40 additions
and
7 deletions
+40
-7
astWalker.ts
libs/remix-astwalker/src/astWalker.ts
+8
-6
newTests.ts
libs/remix-astwalker/tests/newTests.ts
+32
-1
No files found.
libs/remix-astwalker/src/astWalker.ts
View file @
fa6da75f
...
@@ -80,6 +80,7 @@ export class AstWalker extends EventEmitter {
...
@@ -80,6 +80,7 @@ export class AstWalker extends EventEmitter {
}
}
getASTNodeChildren
(
ast
:
AstNode
):
AstNode
[]
{
getASTNodeChildren
(
ast
:
AstNode
):
AstNode
[]
{
let
nodes
=
ast
.
nodes
// for ContractDefinition
let
nodes
=
ast
.
nodes
// for ContractDefinition
||
ast
.
body
// for FunctionDefinition, ModifierDefinition, WhileStatement, DoWhileStatement, ForStatement
||
ast
.
body
// for FunctionDefinition, ModifierDefinition, WhileStatement, DoWhileStatement, ForStatement
||
ast
.
statements
// for Block, YulBlock
||
ast
.
statements
// for Block, YulBlock
...
@@ -100,11 +101,13 @@ export class AstWalker extends EventEmitter {
...
@@ -100,11 +101,13 @@ export class AstWalker extends EventEmitter {
nodes
=
tempArr
nodes
=
tempArr
}
}
if
(
ast
.
body
&&
ast
.
overrides
&&
ast
.
parameters
&&
ast
.
returnParameters
&&
ast
.
modifiers
)
{
// for FunctionDefinition
if
(
ast
.
nodes
&&
ast
.
baseContracts
?.
length
)
{
// for ContractDefinition
nodes
.
push
(
ast
.
overrides
)
nodes
.
push
(...
ast
.
baseContracts
)
nodes
.
push
(
ast
.
parameters
)
}
else
if
(
ast
.
body
&&
ast
.
overrides
&&
ast
.
parameters
&&
ast
.
returnParameters
&&
ast
.
modifiers
)
{
// for FunctionDefinition
nodes
.
push
(
ast
.
returnParameters
)
nodes
.
push
(
ast
.
overrides
)
nodes
.
push
(
ast
.
modifiers
)
nodes
.
push
(
ast
.
parameters
)
nodes
.
push
(
ast
.
returnParameters
)
nodes
.
push
(
ast
.
modifiers
)
}
else
if
(
ast
.
typeName
)
{
// for VariableDeclaration, NewExpression, ElementaryTypeNameExpression
}
else
if
(
ast
.
typeName
)
{
// for VariableDeclaration, NewExpression, ElementaryTypeNameExpression
nodes
.
push
(
ast
.
typeName
)
nodes
.
push
(
ast
.
typeName
)
}
else
if
(
ast
.
body
&&
ast
.
overrides
&&
ast
.
parameters
)
{
// for ModifierDefinition
}
else
if
(
ast
.
body
&&
ast
.
overrides
&&
ast
.
parameters
)
{
// for ModifierDefinition
...
@@ -194,7 +197,6 @@ export class AstWalker extends EventEmitter {
...
@@ -194,7 +197,6 @@ export class AstWalker extends EventEmitter {
}
}
// eslint-disable-next-line @typescript-eslint/ban-types, @typescript-eslint/explicit-module-boundary-types
// eslint-disable-next-line @typescript-eslint/ban-types, @typescript-eslint/explicit-module-boundary-types
walkFullInternal
(
ast
:
AstNode
,
callback
:
Function
)
{
walkFullInternal
(
ast
:
AstNode
,
callback
:
Function
)
{
if
(
isAstNode
(
ast
))
{
if
(
isAstNode
(
ast
))
{
// console.log(`XXX id ${ast.id}, nodeType: ${ast.nodeType}, src: ${ast.src}`);
// console.log(`XXX id ${ast.id}, nodeType: ${ast.nodeType}, src: ${ast.src}`);
callback
(
ast
);
callback
(
ast
);
...
...
libs/remix-astwalker/tests/newTests.ts
View file @
fa6da75f
...
@@ -6,6 +6,7 @@ import legacyNode from "./resources/legacyAST";
...
@@ -6,6 +6,7 @@ import legacyNode from "./resources/legacyAST";
tape
(
"New ASTWalker"
,
(
t
:
tape
.
Test
)
=>
{
tape
(
"New ASTWalker"
,
(
t
:
tape
.
Test
)
=>
{
// New Ast Object
// New Ast Object
const
astWalker
=
new
AstWalker
();
const
astWalker
=
new
AstWalker
();
const
latestAST
=
node
.
ast
t
.
test
(
"ASTWalker.walk && .walkastList"
,
(
st
:
tape
.
Test
)
=>
{
t
.
test
(
"ASTWalker.walk && .walkastList"
,
(
st
:
tape
.
Test
)
=>
{
st
.
plan
(
24
);
st
.
plan
(
24
);
// EventListener
// EventListener
...
@@ -52,11 +53,41 @@ tape("New ASTWalker", (t: tape.Test) => {
...
@@ -52,11 +53,41 @@ tape("New ASTWalker", (t: tape.Test) => {
});
});
st
.
end
();
st
.
end
();
});
});
// t.test("ASTWalker.getASTNodeChildren", (st: tape.Test) => {
// st.plan(11);
// st.equal(node.ast.nodeType, 'SourceUnit')
// let subNodes1 = astWalker.getASTNodeChildren(node.ast)
// st.equal(subNodes1.length, 3)
// st.equal(subNodes1[0].nodeType, 'PragmaDirective')
// st.equal(subNodes1[1].nodeType, 'ImportDirective')
// st.equal(subNodes1[2].nodeType, 'ContractDefinition')
// let subNodes2 = astWalker.getASTNodeChildren(subNodes1[0])
// st.equal(subNodes2.length, 0)
// subNodes2 = astWalker.getASTNodeChildren(subNodes1[1])
// st.equal(subNodes2.length, 0)
// console.log('subNodes-1-->', subNodes1[2])
// subNodes2 = astWalker.getASTNodeChildren(subNodes1[2])
// console.log('subNodes-3-->', subNodes2)
// st.equal(subNodes2.length, 4)
// st.equal(subNodes2[1].nodeType, 'VariableDeclaration')
// st.equal(subNodes2[2].nodeType, 'FunctionDefinition')
// st.equal(subNodes2[3].nodeType, 'FunctionDefinition')
// st.end();
// });
t
.
test
(
"ASTWalkFull"
,
(
st
:
tape
.
Test
)
=>
{
t
.
test
(
"ASTWalkFull"
,
(
st
:
tape
.
Test
)
=>
{
const
astNodeCount
=
26
;
const
astNodeCount
=
26
;
st
.
plan
(
2
+
astNodeCount
);
st
.
plan
(
2
+
astNodeCount
);
let
count
:
number
=
0
;
let
count
:
number
=
0
;
astWalker
.
walkFull
(
node
.
ast
,
(
node
:
AstNode
)
=>
{
astWalker
.
walkFull
(
latestAST
,
(
node
:
AstNode
)
=>
{
// console.log('nodes inside walkfull-------------------------->>>', node)
st
.
ok
(
isAstNode
(
node
),
"passed an ast node"
);
st
.
ok
(
isAstNode
(
node
),
"passed an ast node"
);
count
+=
1
;
count
+=
1
;
});
});
...
...
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