Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F100643107
wrap.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
Sat, Feb 1, 10:49
Size
1 KB
Mime Type
text/x-java
Expires
Mon, Feb 3, 10:49 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
24001731
Attached To
rOACCT Open Access Compliance Check Tool (OACCT)
wrap.js
View Options
import
types
from
'./types/index.js'
;
import
BlockStatement
from
'./BlockStatement.js'
;
import
Node
from
'./Node.js'
;
import
keys
from
'./keys.js'
;
const
statementsWithBlocks
=
{
IfStatement
:
'consequent'
,
ForStatement
:
'body'
,
ForInStatement
:
'body'
,
ForOfStatement
:
'body'
,
WhileStatement
:
'body'
,
DoWhileStatement
:
'body'
,
ArrowFunctionExpression
:
'body'
};
export
default
function
wrap
(
raw
,
parent
)
{
if
(
!
raw
)
return
;
if
(
'length'
in
raw
)
{
let
i
=
raw
.
length
;
while
(
i
--
)
wrap
(
raw
[
i
],
parent
);
return
;
}
// with e.g. shorthand properties, key and value are
// the same node. We don't want to wrap an object twice
if
(
raw
.
__wrapped
)
return
;
raw
.
__wrapped
=
true
;
if
(
!
keys
[
raw
.
type
])
{
keys
[
raw
.
type
]
=
Object
.
keys
(
raw
).
filter
(
key
=>
typeof
raw
[
key
]
===
'object'
);
}
// special case – body-less if/for/while statements. TODO others?
const
bodyType
=
statementsWithBlocks
[
raw
.
type
];
if
(
bodyType
&&
raw
[
bodyType
].
type
!==
'BlockStatement'
)
{
const
expression
=
raw
[
bodyType
];
// create a synthetic block statement, otherwise all hell
// breaks loose when it comes to block scoping
raw
[
bodyType
]
=
{
start
:
expression
.
start
,
end
:
expression
.
end
,
type
:
'BlockStatement'
,
body
:
[
expression
],
synthetic
:
true
};
}
raw
.
parent
=
parent
;
raw
.
program
=
parent
.
program
||
parent
;
raw
.
depth
=
parent
.
depth
+
1
;
raw
.
keys
=
keys
[
raw
.
type
];
raw
.
indentation
=
undefined
;
for
(
const
key
of
keys
[
raw
.
type
])
{
wrap
(
raw
[
key
],
raw
);
}
raw
.
program
.
magicString
.
addSourcemapLocation
(
raw
.
start
);
raw
.
program
.
magicString
.
addSourcemapLocation
(
raw
.
end
);
const
type
=
(
raw
.
type
===
'BlockStatement'
?
BlockStatement
:
types
[
raw
.
type
])
||
Node
;
raw
.
__proto__
=
type
.
prototype
;
}
Event Timeline
Log In to Comment