aboutsummaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorMatthew Petro <[email protected]>2023-01-17 14:19:45 -0700
committerGitHub <[email protected]>2023-01-17 21:19:45 +0000
commit0ac998992c87f9bfd5c1fae3c59ca6b79ef5b4b9 (patch)
tree8a1884f25de66a477f9e0070fda36c63197cafef /scripts
parentcc0b034bac165363c3e77977c7e01a5ef9d508b9 (diff)
downloadfaker-0ac998992c87f9bfd5c1fae3c59ca6b79ef5b4b9.tar.xz
faker-0ac998992c87f9bfd5c1fae3c59ca6b79ef5b4b9.zip
build: escape locale import names if they match the module name (#1737)
Diffstat (limited to 'scripts')
-rw-r--r--scripts/generateLocales.ts14
1 files changed, 8 insertions, 6 deletions
diff --git a/scripts/generateLocales.ts b/scripts/generateLocales.ts
index 37f21ec9..07cf47e7 100644
--- a/scripts/generateLocales.ts
+++ b/scripts/generateLocales.ts
@@ -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;
@@ -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};`);