mirror of
https://github.com/MercuryWorkshop/scramjet.git
synced 2025-05-13 06:20:02 -04:00
fix strict mode sourcemap handling
This commit is contained in:
parent
a47e416193
commit
3cd17070ab
1 changed files with 10 additions and 3 deletions
|
@ -366,9 +366,16 @@ async function rewriteBody(
|
|||
workertype === "module"
|
||||
);
|
||||
if (flagEnabled("sourcemaps", meta.base) && map) {
|
||||
js =
|
||||
`${globalThis.$scramjet.config.globals.pushsourcemapfn}([${map.join(",")}], "${tag}");` +
|
||||
(js instanceof Uint8Array ? new TextDecoder().decode(js) : js);
|
||||
if (js instanceof Uint8Array) {
|
||||
js = new TextDecoder().decode(js);
|
||||
}
|
||||
const sourcemapfn = `${globalThis.$scramjet.config.globals.pushsourcemapfn}([${map.join(",")}], "${tag}");`;
|
||||
const strictMode = /^\s*(['"])use strict\1;?/;
|
||||
if (strictMode.test(js)) {
|
||||
js = js.replace(strictMode, `$&\n${sourcemapfn}`);
|
||||
} else {
|
||||
js = `${sourcemapfn}\n${js}`;
|
||||
}
|
||||
}
|
||||
|
||||
return js as unknown as ArrayBuffer;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue