refactor(reference): reuse the import UTF-8 decoder (#17356)

This commit is contained in:
Vincent Koc
2026-12-06 10:31:03 +08:00
committed by GitHub
parent 2827a327d6
commit 9088c8d426
+4 -6
View File
@@ -35,7 +35,7 @@ import {
isTSModuleDeclaration,
} from "@babel/types";
import type { HistoricalSourceGraph } from "./referenceSourceGraph.js";
import { decodeStrictUtf8 } from "./strictUtf8.js";
import { decodeUtf8PreservingBomOrNull } from "./strictUtf8.js";
interface ReferenceSourceImportRelationship extends Readonly<
Pick<
@@ -305,11 +305,9 @@ export const parseReferenceSourceImports = (
if (language !== null && !PARSEABLE_REFERENCE_SOURCE_LANGUAGES.has(language))
return { relationships: [], parse_failures: [], limitations: [] };
let source: string;
try {
// The shared parser owns loader-specific BOM/hashbang preprocessing.
source = decodeStrictUtf8(bytes, "preserve");
} catch {
// The shared parser owns loader-specific BOM/hashbang preprocessing.
const source = decodeUtf8PreservingBomOrNull(bytes);
if (source === null) {
return {
relationships: [],
parse_failures: [