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"
|
workertype === "module"
|
||||||
);
|
);
|
||||||
if (flagEnabled("sourcemaps", meta.base) && map) {
|
if (flagEnabled("sourcemaps", meta.base) && map) {
|
||||||
js =
|
if (js instanceof Uint8Array) {
|
||||||
`${globalThis.$scramjet.config.globals.pushsourcemapfn}([${map.join(",")}], "${tag}");` +
|
js = new TextDecoder().decode(js);
|
||||||
(js instanceof Uint8Array ? new TextDecoder().decode(js) : 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;
|
return js as unknown as ArrayBuffer;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue