fix: false positive not exists error if sourceCode is empty (#17434)

* fix: false positive not exists error if sourceCode is empty

* Return empty array for empty sourceCode

* lint

---------

Co-authored-by: syuilo <4439005+syuilo@users.noreply.github.com>
This commit is contained in:
anatawa12 2026-05-19 15:55:53 +09:00 committed by GitHub
commit 3a27ae0757
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 2 additions and 1 deletions

View file

@ -80,7 +80,7 @@ export class LocaleInliner {
await fs.mkdir(path.join(this.outputDir, localeName), { recursive: true });
const localeLogger = localeName === 'ja-JP' ? this.logger : blankLogger; // we want to log for single locale only
for (const chunk of this.chunks) {
if (!chunk.sourceCode || !chunk.modifications) {
if (chunk.sourceCode == null || !chunk.modifications) {
throw new Error(`Source code or modifications for ${chunk.fileName} is not available.`);
}
const fileLogger = localeLogger.prefixed(`${chunk.fileName} (${chunk.chunkName}): `);

View file

@ -18,6 +18,7 @@ interface WalkerContext {
}
export function collectModifications(sourceCode: string, fileName: string, fileLogger: Logger, inliner: LocaleInliner): TextModification[] {
if (sourceCode === '') return [];
let programNode: RolldownESTree.Program;
try {
programNode = parseAst(sourceCode);