Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F91627196
SourceListMap.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
Tue, Nov 12, 21:22
Size
3 KB
Mime Type
text/x-c++
Expires
Thu, Nov 14, 21:22 (2 d)
Engine
blob
Format
Raw Data
Handle
22282925
Attached To
rOACCT Open Access Compliance Check Tool (OACCT)
SourceListMap.js
View Options
/*
MIT License http://www.opensource.org/licenses/mit-license.php
Author Tobias Koppers @sokra
*/
"use strict"
;
const
CodeNode
=
require
(
"./CodeNode"
);
const
SourceNode
=
require
(
"./SourceNode"
);
const
MappingsContext
=
require
(
"./MappingsContext"
);
const
getNumberOfLines
=
require
(
"./helpers"
).
getNumberOfLines
;
class
SourceListMap
{
constructor
(
generatedCode
,
source
,
originalSource
)
{
if
(
Array
.
isArray
(
generatedCode
))
{
this
.
children
=
generatedCode
;
}
else
{
this
.
children
=
[];
if
(
generatedCode
||
source
)
this
.
add
(
generatedCode
,
source
,
originalSource
);
}
}
add
(
generatedCode
,
source
,
originalSource
)
{
if
(
typeof
generatedCode
===
"string"
)
{
if
(
source
)
{
this
.
children
.
push
(
new
SourceNode
(
generatedCode
,
source
,
originalSource
));
}
else
if
(
this
.
children
.
length
>
0
&&
this
.
children
[
this
.
children
.
length
-
1
]
instanceof
CodeNode
)
{
this
.
children
[
this
.
children
.
length
-
1
].
addGeneratedCode
(
generatedCode
);
}
else
{
this
.
children
.
push
(
new
CodeNode
(
generatedCode
));
}
}
else
if
(
generatedCode
.
getMappings
&&
generatedCode
.
getGeneratedCode
)
{
this
.
children
.
push
(
generatedCode
);
}
else
if
(
generatedCode
.
children
)
{
generatedCode
.
children
.
forEach
(
function
(
sln
)
{
this
.
children
.
push
(
sln
);
},
this
);
}
else
{
throw
new
Error
(
"Invalid arguments to SourceListMap.protfotype.add: Expected string, Node or SourceListMap"
);
}
};
preprend
(
generatedCode
,
source
,
originalSource
)
{
if
(
typeof
generatedCode
===
"string"
)
{
if
(
source
)
{
this
.
children
.
unshift
(
new
SourceNode
(
generatedCode
,
source
,
originalSource
));
}
else
if
(
this
.
children
.
length
>
0
&&
this
.
children
[
this
.
children
.
length
-
1
].
preprendGeneratedCode
)
{
this
.
children
[
this
.
children
.
length
-
1
].
preprendGeneratedCode
(
generatedCode
);
}
else
{
this
.
children
.
unshift
(
new
CodeNode
(
generatedCode
));
}
}
else
if
(
generatedCode
.
getMappings
&&
generatedCode
.
getGeneratedCode
)
{
this
.
children
.
unshift
(
generatedCode
);
}
else
if
(
generatedCode
.
children
)
{
generatedCode
.
children
.
slice
().
reverse
().
forEach
(
function
(
sln
)
{
this
.
children
.
unshift
(
sln
);
},
this
);
}
else
{
throw
new
Error
(
"Invalid arguments to SourceListMap.protfotype.prerend: Expected string, Node or SourceListMap"
);
}
};
mapGeneratedCode
(
fn
)
{
const
normalizedNodes
=
[];
this
.
children
.
forEach
(
function
(
sln
)
{
sln
.
getNormalizedNodes
().
forEach
(
function
(
newNode
)
{
normalizedNodes
.
push
(
newNode
);
});
});
const
optimizedNodes
=
[];
normalizedNodes
.
forEach
(
function
(
sln
)
{
sln
=
sln
.
mapGeneratedCode
(
fn
);
if
(
optimizedNodes
.
length
===
0
)
{
optimizedNodes
.
push
(
sln
);
}
else
{
const
last
=
optimizedNodes
[
optimizedNodes
.
length
-
1
];
const
mergedNode
=
last
.
merge
(
sln
);
if
(
mergedNode
)
{
optimizedNodes
[
optimizedNodes
.
length
-
1
]
=
mergedNode
;
}
else
{
optimizedNodes
.
push
(
sln
);
}
}
});
return
new
SourceListMap
(
optimizedNodes
);
};
toString
()
{
return
this
.
children
.
map
(
function
(
sln
)
{
return
sln
.
getGeneratedCode
();
}).
join
(
""
);
};
toStringWithSourceMap
(
options
)
{
const
mappingsContext
=
new
MappingsContext
();
const
source
=
this
.
children
.
map
(
function
(
sln
)
{
return
sln
.
getGeneratedCode
();
}).
join
(
""
);
const
mappings
=
this
.
children
.
map
(
function
(
sln
)
{
return
sln
.
getMappings
(
mappingsContext
);
}).
join
(
""
);
const
arrays
=
mappingsContext
.
getArrays
();
return
{
source
,
map
:
{
version
:
3
,
file
:
options
&&
options
.
file
,
sources
:
arrays
.
sources
,
sourcesContent
:
mappingsContext
.
hasSourceContent
?
arrays
.
sourcesContent
:
undefined
,
mappings
:
mappings
}
};
}
}
module
.
exports
=
SourceListMap
;
Event Timeline
Log In to Comment