mirror of
https://github.com/zebrajr/node.git
synced 2025-12-06 00:20:08 +01:00
PR-URL: https://github.com/nodejs/node/pull/57704 Reviewed-By: Jacob Smith <jacob@frende.me> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
35 lines
1.0 KiB
JavaScript
35 lines
1.0 KiB
JavaScript
"use strict";
|
|
import { fileURLToPath } from "node:url";
|
|
import { isSwcError, wrapAndReThrowSwcError } from "./errors.js";
|
|
import { transformSync } from "./index.js";
|
|
export async function load(url, context, nextLoad) {
|
|
const { format } = context;
|
|
if (format?.endsWith("-typescript")) {
|
|
try {
|
|
const { source } = await nextLoad(url, {
|
|
...context,
|
|
format: "module"
|
|
});
|
|
const { code } = transformSync(source.toString(), {
|
|
mode: "strip-only",
|
|
filename: fileURLToPath(url)
|
|
});
|
|
return {
|
|
format: format.replace("-typescript", ""),
|
|
// Source map is not necessary in strip-only mode. However, to map the source
|
|
// file in debuggers to the original TypeScript source, add a sourceURL magic
|
|
// comment to hint that it is a generated source.
|
|
source: `${code}
|
|
|
|
//# sourceURL=${url}`
|
|
};
|
|
} catch (error) {
|
|
if (isSwcError(error)) {
|
|
wrapAndReThrowSwcError(error);
|
|
}
|
|
throw error;
|
|
}
|
|
}
|
|
return nextLoad(url, context);
|
|
}
|