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
336ff739
Commit
336ff739
authored
Feb 11, 2021
by
aniket-engg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
linting for astwalker done
parent
0bdf8214
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
40 additions
and
41 deletions
+40
-41
.eslintrc
libs/remix-astwalker/.eslintrc
+2
-1
astWalker.ts
libs/remix-astwalker/src/astWalker.ts
+0
-0
sourceMappings.ts
libs/remix-astwalker/src/sourceMappings.ts
+36
-38
types.ts
libs/remix-astwalker/src/types.ts
+2
-2
No files found.
libs/remix-astwalker/.eslintrc
View file @
336ff739
...
...
@@ -2,7 +2,8 @@
"extends": "../../.eslintrc",
"rules": {
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/prefer-namespace-keyword": "off"
"@typescript-eslint/prefer-namespace-keyword": "off",
"no-unused-vars": "off"
},
"ignorePatterns": ["!**/*"]
}
libs/remix-astwalker/src/astWalker.ts
View file @
336ff739
This diff is collapsed.
Click to expand it.
libs/remix-astwalker/src/sourceMappings.ts
View file @
336ff739
import
{
isAstNode
,
isYulAstNode
,
AstWalker
}
from
'./astWalker'
;
import
{
AstNode
,
LineColPosition
,
LineColRange
,
Location
}
from
"./types"
;
import
{
util
}
from
"@remix-project/remix-lib"
;
import
{
isAstNode
,
isYulAstNode
,
AstWalker
}
from
'./astWalker'
import
{
AstNode
,
LineColPosition
,
LineColRange
,
Location
}
from
'./types'
import
{
util
}
from
'@remix-project/remix-lib'
export
declare
interface
SourceMappings
{
// eslint-disable-next-line @typescript-eslint/no-misused-new
...
...
@@ -12,12 +12,12 @@ export declare interface SourceMappings {
*
* @param offset The character offset to convert.
*/
export
function
lineColPositionFromOffset
(
offset
:
number
,
lineBreaks
:
Array
<
number
>
):
LineColPosition
{
let
line
:
number
=
util
.
findLowerBound
(
offset
,
lineBreaks
)
;
export
function
lineColPositionFromOffset
(
offset
:
number
,
lineBreaks
:
Array
<
number
>
):
LineColPosition
{
let
line
:
number
=
util
.
findLowerBound
(
offset
,
lineBreaks
)
if
(
lineBreaks
[
line
]
!==
offset
)
{
line
+=
1
;
line
+=
1
}
const
beginColumn
=
line
===
0
?
0
:
(
lineBreaks
[
line
-
1
]
+
1
)
;
const
beginColumn
=
line
===
0
?
0
:
(
lineBreaks
[
line
-
1
]
+
1
)
return
<
LineColPosition
>
{
line
:
line
+
1
,
character
:
(
offset
-
beginColumn
)
+
1
...
...
@@ -30,11 +30,11 @@ export function lineColPositionFromOffset(offset: number, lineBreaks: Array<numb
*
* @param astNode The object to convert.
*/
export
function
sourceLocationFromAstNode
(
astNode
:
AstNode
):
Location
|
null
{
export
function
sourceLocationFromAstNode
(
astNode
:
AstNode
):
Location
|
null
{
if
(
isAstNode
(
astNode
)
&&
isYulAstNode
(
astNode
)
&&
astNode
.
src
)
{
return
sourceLocationFromSrc
(
astNode
.
src
)
}
return
null
;
return
null
}
/**
...
...
@@ -45,7 +45,7 @@ export function sourceLocationFromAstNode(astNode: AstNode): Location | null {
* @param src A solc "src" field.
* @returns {Location}
*/
export
function
sourceLocationFromSrc
(
src
:
string
):
Location
{
export
function
sourceLocationFromSrc
(
src
:
string
):
Location
{
const
split
=
src
.
split
(
':'
)
return
<
Location
>
{
start
:
parseInt
(
split
[
0
],
10
),
...
...
@@ -59,20 +59,19 @@ export function sourceLocationFromSrc(src: string): Location {
* includng "src' information.
*/
export
class
SourceMappings
{
readonly
source
:
string
;
readonly
lineBreaks
:
Array
<
number
>
;
constructor
(
source
:
string
)
{
this
.
source
=
source
;
constructor
(
source
:
string
)
{
this
.
source
=
source
// Create a list of line offsets which will be used to map between
// character offset and line/column positions.
const
lineBreaks
:
Array
<
number
>
=
[]
;
const
lineBreaks
:
Array
<
number
>
=
[]
for
(
let
pos
=
source
.
indexOf
(
'
\
n'
);
pos
>=
0
;
pos
=
source
.
indexOf
(
'
\
n'
,
pos
+
1
))
{
lineBreaks
.
push
(
pos
)
}
this
.
lineBreaks
=
lineBreaks
;
this
.
lineBreaks
=
lineBreaks
};
/**
...
...
@@ -81,23 +80,23 @@ export class SourceMappings {
* @param astNodeType Type of node to return or null.
* @param position Character offset where AST node should be located.
*/
nodesAtPosition
(
astNodeType
:
string
|
null
,
position
:
Location
,
ast
:
AstNode
):
Array
<
AstNode
>
{
nodesAtPosition
(
astNodeType
:
string
|
null
,
position
:
Location
,
ast
:
AstNode
):
Array
<
AstNode
>
{
const
astWalker
=
new
AstWalker
()
const
found
:
Array
<
AstNode
>
=
[]
;
const
found
:
Array
<
AstNode
>
=
[]
const
callback
=
function
(
node
:
AstNode
):
boolean
{
const
nodeLocation
=
sourceLocationFromAstNode
(
node
)
;
const
callback
=
function
(
node
:
AstNode
):
boolean
{
const
nodeLocation
=
sourceLocationFromAstNode
(
node
)
if
(
nodeLocation
&&
nodeLocation
.
start
==
position
.
start
&&
nodeLocation
.
length
==
position
.
length
)
{
nodeLocation
.
start
==
=
position
.
start
&&
nodeLocation
.
length
==
=
position
.
length
)
{
if
(
!
astNodeType
||
astNodeType
===
node
.
nodeType
)
{
found
.
push
(
node
)
}
}
return
true
;
return
true
}
astWalker
.
walkFull
(
ast
,
callback
)
;
return
found
;
astWalker
.
walkFull
(
ast
,
callback
)
return
found
}
/**
...
...
@@ -106,25 +105,25 @@ export class SourceMappings {
* @param astNodeType nodeType that a found ASTNode must be. Use "null" if any ASTNode can match.
* @param sourceLocation "src" location that the AST node must match.
*/
findNodeAtSourceLocation
(
astNodeType
:
string
|
undefined
,
sourceLocation
:
Location
,
ast
:
AstNode
|
null
):
AstNode
|
null
{
findNodeAtSourceLocation
(
astNodeType
:
string
|
undefined
,
sourceLocation
:
Location
,
ast
:
AstNode
|
null
):
AstNode
|
null
{
const
astWalker
=
new
AstWalker
()
let
found
=
null
;
let
found
=
null
/* FIXME: Looking at AST walker code,
I don't understand a need to return a boolean. */
const
callback
=
function
(
node
:
AstNode
)
{
const
nodeLocation
=
sourceLocationFromAstNode
(
node
)
;
const
callback
=
function
(
node
:
AstNode
)
{
const
nodeLocation
=
sourceLocationFromAstNode
(
node
)
if
(
nodeLocation
&&
nodeLocation
.
start
==
sourceLocation
.
start
&&
nodeLocation
.
length
==
sourceLocation
.
length
)
{
if
(
astNodeType
==
undefined
||
astNodeType
===
node
.
nodeType
)
{
found
=
node
;
nodeLocation
.
start
==
=
sourceLocation
.
start
&&
nodeLocation
.
length
==
=
sourceLocation
.
length
)
{
if
(
astNodeType
==
=
undefined
||
astNodeType
===
node
.
nodeType
)
{
found
=
node
}
}
return
true
;
return
true
}
astWalker
.
walkFull
(
ast
,
callback
)
;
return
found
;
astWalker
.
walkFull
(
ast
,
callback
)
return
found
}
/**
...
...
@@ -132,8 +131,8 @@ export class SourceMappings {
*
* @param src Solc "src" object containing attributes {source} and {length}.
*/
srcToLineColumnRange
(
src
:
string
):
LineColRange
{
const
sourceLocation
=
sourceLocationFromSrc
(
src
)
;
srcToLineColumnRange
(
src
:
string
):
LineColRange
{
const
sourceLocation
=
sourceLocationFromSrc
(
src
)
if
(
sourceLocation
.
start
>=
0
&&
sourceLocation
.
length
>=
0
)
{
return
<
LineColRange
>
{
start
:
lineColPositionFromOffset
(
sourceLocation
.
start
,
this
.
lineBreaks
),
...
...
@@ -146,5 +145,4 @@ export class SourceMappings {
}
}
}
}
libs/remix-astwalker/src/types.ts
View file @
336ff739
...
...
@@ -3,7 +3,7 @@
export
interface
Location
{
start
:
number
;
length
:
number
;
file
:
number
;
// Would it be clearer to call this a file index?
file
:
number
;
// Would it be clearer to call this a file index?
}
// This is intended to be compatibile with VScode's Position.
...
...
@@ -31,7 +31,7 @@ export interface Node {
export
interface
AstNode
{
/* The following fields are essential, and indicates an that object
is an AST node. */
id
:
number
;
// This is unique across all nodes in an AST tree
id
:
number
;
// This is unique across all nodes in an AST tree
nodeType
:
string
;
src
:
string
;
...
...
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