Skip to content

Commit

Permalink
build: escape locale import names if they match the module name (#1737)
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewpetro authored Jan 17, 2023
1 parent cc0b034 commit 0ac9989
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions scripts/generateLocales.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,16 +90,16 @@ function removeTsSuffix(files: string[]): string[] {
return files.map((file) => file.replace('.ts', ''));
}

function escapeImport(module: string): string {
if (['name', 'type', 'switch'].includes(module)) {
function escapeImport(parent: string, module: string): string {
if (['name', 'type', 'switch', parent].includes(module)) {
return `${module}_`;
} else {
return module;
}
}

function escapeField(module: string): string {
if (['name', 'type', 'switch'].includes(module)) {
function escapeField(parent: string, module: string): string {
if (['name', 'type', 'switch', parent].includes(module)) {
return `${module}: ${module}_`;
} else {
return module;
Expand Down Expand Up @@ -181,12 +181,14 @@ function generateLocalesIndexFile(
}

content.push(
...modules.map((m) => `import ${escapeImport(m)} from './${m}';`)
...modules.map(
(module) => `import ${escapeImport(name, module)} from './${module}';`
)
);

content.push(`\nconst ${name}${fieldType} = {
${extra}
${modules.map((module) => `${escapeField(module)},`).join('\n')}
${modules.map((module) => `${escapeField(name, module)},`).join('\n')}
};\n`);

content.push(`export default ${name};`);
Expand Down

0 comments on commit 0ac9989

Please sign in to comment.