eng - throw if minified output contains non-ascii characters (#178590)

This commit is contained in:
Benjamin Pasero 2023-03-30 09:26:11 +02:00 committed by GitHub
parent 9e1375620e
commit 95917c1376
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 7 deletions

File diff suppressed because one or more lines are too long

View file

@ -406,10 +406,16 @@ export function minifyTask(src: string, sourceMapBaseUrl?: string): (cb: any) =>
const jsFile = res.outputFiles.find(f => /\.js$/.test(f.path))!;
const sourceMapFile = res.outputFiles.find(f => /\.js\.map$/.test(f.path))!;
f.contents = Buffer.from(jsFile.contents);
f.sourceMap = JSON.parse(sourceMapFile.text);
const contents = Buffer.from(jsFile.contents);
const unicodeMatch = contents.toString().match(/[^\x00-\xFF]+/g);
if (unicodeMatch) {
cb(new Error(`Found non-ascii character ${unicodeMatch[0]} in the minified output of ${f.path}. Non-ASCII characters in the output can cause performance problems when loading. Please review if you have introduced a regular expression that esbuild is not automatically converting and convert it to using unicode escape sequences.`));
} else {
f.contents = contents;
f.sourceMap = JSON.parse(sourceMapFile.text);
cb(undefined, f);
cb(undefined, f);
}
}, cb);
}),
jsFilter.restore,