Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F86933434
index.js
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Wed, Oct 9, 12:17
Size
1 KB
Mime Type
text/x-java
Expires
Fri, Oct 11, 12:17 (2 d)
Engine
blob
Format
Raw Data
Handle
21506177
Attached To
rOACCT Open Access Compliance Check Tool (OACCT)
index.js
View Options
function
_typeof
(
obj
)
{
if
(
typeof
Symbol
===
"function"
&&
typeof
Symbol
.
iterator
===
"symbol"
)
{
_typeof
=
function
_typeof
(
obj
)
{
return
typeof
obj
;
};
}
else
{
_typeof
=
function
_typeof
(
obj
)
{
return
obj
&&
typeof
Symbol
===
"function"
&&
obj
.
constructor
===
Symbol
&&
obj
!==
Symbol
.
prototype
?
"symbol"
:
typeof
obj
;
};
}
return
_typeof
(
obj
);
}
import
{
print
}
from
"@webassemblyjs/wast-printer"
;
var
SHOW_LINES_AROUND_POINTER
=
5
;
function
repeat
(
char
,
nb
)
{
return
Array
(
nb
).
fill
(
char
).
join
(
""
);
}
// TODO(sven): allow arbitrary ast nodes
export
function
codeFrameFromAst
(
ast
,
loc
)
{
return
codeFrameFromSource
(
print
(
ast
),
loc
);
}
export
function
codeFrameFromSource
(
source
,
loc
)
{
var
start
=
loc
.
start
,
end
=
loc
.
end
;
var
length
=
1
;
if
(
_typeof
(
end
)
===
"object"
)
{
length
=
end
.
column
-
start
.
column
+
1
;
}
return
source
.
split
(
"\n"
).
reduce
(
function
(
acc
,
line
,
lineNbr
)
{
if
(
Math
.
abs
(
start
.
line
-
lineNbr
)
<
SHOW_LINES_AROUND_POINTER
)
{
acc
+=
line
+
"\n"
;
}
// Add a new line with the pointer padded left
if
(
lineNbr
===
start
.
line
-
1
)
{
acc
+=
repeat
(
" "
,
start
.
column
-
1
);
acc
+=
repeat
(
"^"
,
length
);
acc
+=
"\n"
;
}
return
acc
;
},
""
);
}
Event Timeline
Log In to Comment