fix: skip merging large input sourcemaps (#10890)
This commit is contained in:
parent
80e95d0c83
commit
e85c9b9ec8
@ -178,7 +178,7 @@ declare module "convert-source-map" {
|
|||||||
SourceMap: SourceMap,
|
SourceMap: SourceMap,
|
||||||
Converter: Converter,
|
Converter: Converter,
|
||||||
fromObject(obj: SourceMap | SourceMapGenerator): Converter,
|
fromObject(obj: SourceMap | SourceMapGenerator): Converter,
|
||||||
fromJSON(str: string): Converter,
|
fromJSON(str: string | Buffer): Converter,
|
||||||
fromBase64(str: string): Converter,
|
fromBase64(str: string): Converter,
|
||||||
fromComment(str: string): Converter,
|
fromComment(str: string): Converter,
|
||||||
fromMapFileComment(str: string, dir: string): Converter,
|
fromMapFileComment(str: string, dir: string): Converter,
|
||||||
|
|||||||
@ -13,6 +13,7 @@ import File from "./file/file";
|
|||||||
import generateMissingPluginMessage from "./util/missing-plugin-helper";
|
import generateMissingPluginMessage from "./util/missing-plugin-helper";
|
||||||
|
|
||||||
const debug = buildDebug("babel:transform:file");
|
const debug = buildDebug("babel:transform:file");
|
||||||
|
const LARGE_INPUT_SOURCEMAP_THRESHOLD = 1_000_000;
|
||||||
|
|
||||||
export type NormalizedFile = {
|
export type NormalizedFile = {
|
||||||
code: string,
|
code: string,
|
||||||
@ -65,14 +66,18 @@ export default function normalizeFile(
|
|||||||
const lastComment = extractComments(EXTERNAL_SOURCEMAP_REGEX, ast);
|
const lastComment = extractComments(EXTERNAL_SOURCEMAP_REGEX, ast);
|
||||||
if (typeof options.filename === "string" && lastComment) {
|
if (typeof options.filename === "string" && lastComment) {
|
||||||
try {
|
try {
|
||||||
const match = EXTERNAL_SOURCEMAP_REGEX.exec(lastComment);
|
// when `lastComment` is non-null, EXTERNAL_SOURCEMAP_REGEX must have matches
|
||||||
if (!match) throw new Error("Invalid source map comment format.");
|
const match: [string, string] = (EXTERNAL_SOURCEMAP_REGEX.exec(
|
||||||
inputMap = convertSourceMap.fromJSON(
|
lastComment,
|
||||||
fs.readFileSync(
|
): any);
|
||||||
|
const inputMapContent: Buffer = fs.readFileSync(
|
||||||
path.resolve(path.dirname(options.filename), match[1]),
|
path.resolve(path.dirname(options.filename), match[1]),
|
||||||
"utf8",
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
if (inputMapContent.length > LARGE_INPUT_SOURCEMAP_THRESHOLD) {
|
||||||
|
debug("skip merging input map > 1 MB");
|
||||||
|
} else {
|
||||||
|
inputMap = convertSourceMap.fromJSON(inputMapContent);
|
||||||
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
debug("discarding unknown file input sourcemap", err);
|
debug("discarding unknown file input sourcemap", err);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user