@sebbro/paraglide-lite 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bundler-plugins/per-locale-build/index.js +5 -3
- package/dist/bundler-plugins/per-locale-build/index.js.map +1 -1
- package/dist/bundler-plugins/per-locale-build/vite-environments.js +12 -7
- package/dist/bundler-plugins/per-locale-build/vite-environments.js.map +1 -1
- package/dist/bundler-plugins/plugin-core.d.ts +38 -2
- package/dist/bundler-plugins/plugin-core.js +198 -11
- package/dist/bundler-plugins/plugin-core.js.map +1 -1
- package/dist/bundler-plugins/rolldown.test.js +15 -6
- package/dist/bundler-plugins/rolldown.test.js.map +1 -1
- package/dist/bundler-plugins/unplugin.js +5 -0
- package/dist/bundler-plugins/unplugin.js.map +1 -1
- package/dist/bundler-plugins/unplugin.test.js +67 -0
- package/dist/bundler-plugins/unplugin.test.js.map +1 -1
- package/dist/bundler-plugins/virtual-modules.test.js +64 -1
- package/dist/bundler-plugins/virtual-modules.test.js.map +1 -1
- package/dist/cli/commands/compile/command.js +8 -1
- package/dist/cli/commands/compile/command.js.map +1 -1
- package/dist/cli/commands/compile/command.test.js +51 -0
- package/dist/cli/commands/compile/command.test.js.map +1 -1
- package/dist/compiler/compile-annotation.d.ts +2 -2
- package/dist/compiler/compile-annotation.js +9 -9
- package/dist/compiler/compile-annotation.js.map +1 -1
- package/dist/compiler/compile-local-variable.d.ts +2 -1
- package/dist/compiler/compile-local-variable.js +4 -4
- package/dist/compiler/compile-local-variable.js.map +1 -1
- package/dist/compiler/compile-local-variable.test.js +82 -0
- package/dist/compiler/compile-local-variable.test.js.map +1 -1
- package/dist/compiler/compile-message.js +10 -2
- package/dist/compiler/compile-message.js.map +1 -1
- package/dist/compiler/compile-message.test.js +132 -2
- package/dist/compiler/compile-message.test.js.map +1 -1
- package/dist/compiler/compile-pattern.js +4 -2
- package/dist/compiler/compile-pattern.js.map +1 -1
- package/dist/compiler/compile-pattern.test.js +31 -0
- package/dist/compiler/compile-pattern.test.js.map +1 -1
- package/dist/compiler/compile.bench.js +1 -1
- package/dist/compiler/compile.bench.js.map +1 -1
- package/dist/compiler/compile.test.js +14 -0
- package/dist/compiler/compile.test.js.map +1 -1
- package/dist/compiler/compiler-options.d.ts +9 -1
- package/dist/compiler/compiler-options.js.map +1 -1
- package/dist/compiler/runtime/create-runtime.d.ts +1 -0
- package/dist/compiler/runtime/create-runtime.js +11 -0
- package/dist/compiler/runtime/create-runtime.js.map +1 -1
- package/dist/compiler/runtime/exec-url-pattern.d.ts +9 -0
- package/dist/compiler/runtime/exec-url-pattern.js +31 -0
- package/dist/compiler/runtime/exec-url-pattern.js.map +1 -0
- package/dist/compiler/runtime/extract-locale-from-url.js +9 -4
- package/dist/compiler/runtime/extract-locale-from-url.js.map +1 -1
- package/dist/compiler/runtime/generate-static-localized-urls.js +13 -6
- package/dist/compiler/runtime/generate-static-localized-urls.js.map +1 -1
- package/dist/compiler/runtime/generate-static-localized-urls.test.js +38 -0
- package/dist/compiler/runtime/generate-static-localized-urls.test.js.map +1 -1
- package/dist/compiler/runtime/localize-href.bench.d.ts +1 -0
- package/dist/compiler/runtime/localize-href.bench.js +68 -0
- package/dist/compiler/runtime/localize-href.bench.js.map +1 -0
- package/dist/compiler/runtime/localize-href.test.js +35 -0
- package/dist/compiler/runtime/localize-href.test.js.map +1 -1
- package/dist/compiler/runtime/localize-url.d.ts +14 -0
- package/dist/compiler/runtime/localize-url.js +338 -19
- package/dist/compiler/runtime/localize-url.js.map +1 -1
- package/dist/compiler/runtime/localize-url.test.js +139 -0
- package/dist/compiler/runtime/localize-url.test.js.map +1 -1
- package/dist/compiler/runtime/normalize-trailing-slash.d.ts +10 -0
- package/dist/compiler/runtime/normalize-trailing-slash.js +23 -0
- package/dist/compiler/runtime/normalize-trailing-slash.js.map +1 -0
- package/dist/compiler/runtime/route-strategy.js +4 -2
- package/dist/compiler/runtime/route-strategy.js.map +1 -1
- package/dist/compiler/runtime/should-redirect.js +4 -1
- package/dist/compiler/runtime/should-redirect.js.map +1 -1
- package/dist/compiler/runtime/should-redirect.test.js +26 -2
- package/dist/compiler/runtime/should-redirect.test.js.map +1 -1
- package/dist/compiler/runtime/type.d.ts +1 -0
- package/dist/compiler/runtime/type.js.map +1 -1
- package/dist/compiler/runtime/url-pattern.d.ts +11 -0
- package/dist/compiler/runtime/url-pattern.js +39 -1
- package/dist/compiler/runtime/url-pattern.js.map +1 -1
- package/dist/compiler/runtime/variables.d.ts +6 -0
- package/dist/compiler/runtime/variables.js +6 -0
- package/dist/compiler/runtime/variables.js.map +1 -1
- package/dist/compiler/server/create-server-file.js +18 -4
- package/dist/compiler/server/create-server-file.js.map +1 -1
- package/dist/compiler/server/create-server-file.test.js +76 -0
- package/dist/compiler/server/create-server-file.test.js.map +1 -1
- package/dist/compiler/server/middleware.js +6 -2
- package/dist/compiler/server/middleware.js.map +1 -1
- package/dist/compiler/server/middleware.test.js +30 -0
- package/dist/compiler/server/middleware.test.js.map +1 -1
- package/dist/compiler/variable-access.d.ts +2 -0
- package/dist/compiler/variable-access.js +6 -0
- package/dist/compiler/variable-access.js.map +1 -1
- package/dist/index.test.d.ts +1 -0
- package/dist/index.test.js +9 -0
- package/dist/index.test.js.map +1 -0
- package/dist/messages/load-messages.js +4 -5
- package/dist/messages/load-messages.js.map +1 -1
- package/dist/services/env-variables/index.js +1 -1
- package/dist/services/env-variables/index.js.map +1 -1
- package/dist/services/file-handling/write-output.bench.d.ts +1 -0
- package/dist/services/file-handling/write-output.bench.js +24 -0
- package/dist/services/file-handling/write-output.bench.js.map +1 -0
- package/dist/services/file-handling/write-output.d.ts +5 -0
- package/dist/services/file-handling/write-output.js +54 -9
- package/dist/services/file-handling/write-output.js.map +1 -1
- package/dist/services/file-handling/write-output.test.js +27 -0
- package/dist/services/file-handling/write-output.test.js.map +1 -1
- package/dist/services/logger/index.js +2 -0
- package/dist/services/logger/index.js.map +1 -1
- package/package.json +86 -86
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"command.js","sourceRoot":"","sources":["../../../../src/cli/commands/compile/command.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC;AAC1D,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAC9C,OAAO,EAAE,MAAM,EAAE,MAAM,mCAAmC,CAAC;AAC3D,OAAO,EAAE,mBAAmB,EAAE,eAAe,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAC3G,OAAO,EAAE,OAAO,EAA0B,MAAM,8BAA8B,CAAC;AAC/E,OAAO,EAAE,iCAAiC,EAAE,MAAM,gDAAgD,CAAC;AACnG,OAAO,EACN,sBAAsB,GAEtB,MAAM,uCAAuC,CAAC;AAC/C,OAAO,EACN,eAAe,EACf,eAAe,GACf,MAAM,+CAA+C,CAAC;AAEvD,MAAM,oBAAoB,GAAG,CAC5B,KAAa,EACqC,EAAE;IACpD,IAAI,KAAK,KAAK,iBAAiB,IAAI,KAAK,KAAK,gBAAgB,EAAE,CAAC;QAC/D,OAAO,KAAK,CAAC;IACd,CAAC;IACD,MAAM,IAAI,oBAAoB,CAC7B,6BAA6B,KAAK,oDAAoD,CACtF,CAAC;AACH,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,cAAc,GAAG,IAAI,OAAO,EAAE;KACzC,IAAI,CAAC,SAAS,CAAC;KACf,OAAO,CAAC,uCAAuC,CAAC;KAChD,MAAM,CACN,mBAAmB,EACnB,oEAAoE,EACpE,gBAAgB,CAChB;KACA,MAAM,CACN,sBAAsB,EACtB,8CAA8C,EAC9C,CAAC,GAAG,eAAe,CAAC,CACpB;KACA,MAAM,CACN,wBAAwB,EACxB,2BAA2B,EAC3B,mBAAmB,CACnB;KACA,cAAc,CACd,iBAAiB,EACjB,8DAA8D,EAC9D,cAAc,CACd;K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H,MAAM,UAAU,EAAE,CAAC;IACnB,MAAM,CAAC,IAAI,CAAC,yBAAyB,CAAC,CAAC;AACxC,CAAC,CACD,CAAC","sourcesContent":["import { Command, InvalidArgumentError } from \"commander\";\nimport fs from \"node:fs\";\nimport { resolve, relative } from \"node:path\";\nimport { Logger } from \"../../../services/logger/index.js\";\nimport { DEFAULT_BASE_LOCALE, DEFAULT_LOCALES, DEFAULT_MESSAGES, DEFAULT_OUTDIR } from \"../../defaults.js\";\nimport { compile, type CompilationResult } from \"../../../compiler/compile.js\";\nimport { seedPreviousCompilationFromOutdir } from \"../../../compiler/seed-previous-compilation.js\";\nimport {\n\tdefaultCompilerOptions,\n\ttype CompilerOptions,\n} from \"../../../compiler/compiler-options.js\";\nimport {\n\tcreateTrackedFs,\n\tgetWatchTargets,\n} from \"../../../services/file-watching/tracked-fs.js\";\n\nconst parseOutputStructure = (\n\tvalue: string\n): NonNullable<CompilerOptions[\"outputStructure\"]> => {\n\tif (value === \"message-modules\" || value === \"locale-modules\") {\n\t\treturn value;\n\t}\n\tthrow new InvalidArgumentError(\n\t\t`Invalid output structure \"${value}\". Expected \"message-modules\" or \"locale-modules\".`\n\t);\n};\n\nexport const compileCommand = new Command()\n\t.name(\"compile\")\n\t.summary(\"Compiles paraglide-lite message files\")\n\t.option(\n\t\t\"--messages <path>\",\n\t\t'Path pattern for locale files. Example: \"./messages/{locale}.json\"',\n\t\tDEFAULT_MESSAGES\n\t)\n\t.option(\n\t\t\"--locales <items...>\",\n\t\t\"Locales to compile. Example: --locales en de\",\n\t\t[...DEFAULT_LOCALES]\n\t)\n\t.option(\n\t\t\"--base-locale <locale>\",\n\t\t\"Base locale for fallbacks\",\n\t\tDEFAULT_BASE_LOCALE\n\t)\n\t.requiredOption(\n\t\t\"--outdir <path>\",\n\t\t'The path to the output directory. Example: \"./src/paraglide\"',\n\t\tDEFAULT_OUTDIR\n\t)\n\t.option(\n\t\t\"--strategy <items...>\",\n\t\t[\n\t\t\t\"The strategy to be used.\",\n\t\t\t\"\",\n\t\t\t\"Example: --strategy cookie globalVariable baseLocale\",\n\t\t\t\"Upstream docs: https://paraglidejs.com/strategy\",\n\t\t].join(\"\\n\")\n\t)\n\t.requiredOption(\"--silent\", \"Only log errors to the console\", false)\n\t.option(\n\t\t\"--emit-ts-declarations\",\n\t\t\"Emit .d.ts files for the generated output (requires the typescript package)\",\n\t\tdefaultCompilerOptions.emitTsDeclarations\n\t)\n\t.option(\n\t\t\"--no-emit-ts-declarations\",\n\t\t\"Do not emit .d.ts files for the generated output\"\n\t)\n\t.option(\n\t\t\"--emit-git-ignore\",\n\t\t\"Emit a .gitignore in the output directory\",\n\t\tdefaultCompilerOptions.emitGitIgnore\n\t)\n\t.option(\n\t\t\"--no-emit-git-ignore\",\n\t\t\"Do not emit a .gitignore in the output directory\"\n\t)\n\t.option(\n\t\t\"--emit-prettier-ignore\",\n\t\t\"Emit a .prettierignore in the output directory\",\n\t\tdefaultCompilerOptions.emitPrettierIgnore\n\t)\n\t.option(\n\t\t\"--no-emit-prettier-ignore\",\n\t\t\"Do not emit a .prettierignore in the output directory\"\n\t)\n\t.option(\n\t\t\"--emit-readme\",\n\t\t\"Emit a README.md in the output directory (helps LLMs understand the generated code)\",\n\t\tdefaultCompilerOptions.emitReadme\n\t)\n\t.option(\n\t\t\"--no-emit-readme\",\n\t\t\"Do not emit README.md in the output directory\"\n\t)\n\t.option(\n\t\t\"--is-server <expression>\",\n\t\t[\n\t\t\t\"JavaScript expression for runtime `isServer` (enables server/client tree-shaking).\",\n\t\t\t'Quote if the expression contains spaces, e.g. --is-server \\'typeof window === \"undefined\"\\'.',\n\t\t\t\"Vite SSR example: --is-server 'import.meta.env.SSR'\",\n\t\t].join(\" \")\n\t)\n\t.option(\n\t\t\"--output-structure <structure>\",\n\t\t[\n\t\t\t'The output structure for compiled messages. Either \"message-modules\" or \"locale-modules\".',\n\t\t\t\"\",\n\t\t\t'\"message-modules\" gives each message its own module (better tree-shaking).',\n\t\t\t'\"locale-modules\" bundles messages per locale (fewer files, better for large projects in dev).',\n\t\t].join(\"\\n\"),\n\t\tparseOutputStructure,\n\t\tdefaultCompilerOptions.outputStructure\n\t)\n\t.option(\"--watch\", \"Watch message files and recompile on change\", false)\n\t.action(\n\t\tasync (options: {\n\t\t\tsilent: boolean;\n\t\t\tmessages: string;\n\t\t\tlocales: string[];\n\t\t\tbaseLocale: string;\n\t\t\toutdir: string;\n\t\t\tstrategy?: CompilerOptions[\"strategy\"];\n\t\t\temitTsDeclarations?: CompilerOptions[\"emitTsDeclarations\"];\n\t\t\temitGitIgnore?: CompilerOptions[\"emitGitIgnore\"];\n\t\t\temitPrettierIgnore?: CompilerOptions[\"emitPrettierIgnore\"];\n\t\t\temitReadme?: CompilerOptions[\"emitReadme\"];\n\t\t\tisServer?: CompilerOptions[\"isServer\"];\n\t\t\toutputStructure?: CompilerOptions[\"outputStructure\"];\n\t\t\twatch?: boolean;\n\t\t}) => {\n\t\t\tconst logger = new Logger({ silent: options.silent, prefix: true });\n\n\t\t\tconst compileOptions = {\n\t\t\t\tmessages: options.messages,\n\t\t\t\tlocales: options.locales,\n\t\t\t\tbaseLocale: options.baseLocale,\n\t\t\t\toutdir: options.outdir,\n\t\t\t\tstrategy: options.strategy ?? defaultCompilerOptions.strategy,\n\t\t\t\temitTsDeclarations:\n\t\t\t\t\toptions.emitTsDeclarations ??\n\t\t\t\t\tdefaultCompilerOptions.emitTsDeclarations,\n\t\t\t\temitGitIgnore:\n\t\t\t\t\toptions.emitGitIgnore ?? defaultCompilerOptions.emitGitIgnore,\n\t\t\t\temitPrettierIgnore:\n\t\t\t\t\toptions.emitPrettierIgnore ??\n\t\t\t\t\tdefaultCompilerOptions.emitPrettierIgnore,\n\t\t\t\temitReadme: options.emitReadme ?? defaultCompilerOptions.emitReadme,\n\t\t\t\tisServer: options.isServer ?? defaultCompilerOptions.isServer,\n\t\t\t\toutputStructure:\n\t\t\t\t\toptions.outputStructure ??\n\t\t\t\t\tdefaultCompilerOptions.outputStructure,\n\t\t\t\t// CLI always writes the full output tree to disk.\n\t\t\t\temitFiles: true as const,\n\t\t\t};\n\n\t\t\tif (!options.watch) {\n\t\t\t\tlogger.info(`Compiling messages ...`);\n\n\t\t\t\ttry {\n\t\t\t\t\tawait compile(compileOptions);\n\t\t\t\t} catch (e) {\n\t\t\t\t\tlogger.error(\"Error while compiling messages.\");\n\t\t\t\t\tlogger.error(e);\n\t\t\t\t\tprocess.exit(1);\n\t\t\t\t}\n\n\t\t\t\tlogger.success(`Successfully compiled messages.`);\n\n\t\t\t\tprocess.exit(0);\n\t\t\t}\n\n\t\t\tconst { fs: trackedFs, readFiles, clearReadFiles } = createTrackedFs();\n\t\t\tconst fileWatchers = new Map<string, fs.FSWatcher>();\n\t\t\tconst directoryWatchers = new Map<string, fs.FSWatcher>();\n\t\t\tlet previousCompilation: CompilationResult | undefined;\n\t\t\tlet compileTimer: NodeJS.Timeout | undefined;\n\t\t\tlet compileInProgress = false;\n\t\t\tlet compileRequested = false;\n\n\t\t\tconst updateWatchers = (files: Set<string>) => {\n\t\t\t\tconst {\n\t\t\t\t\tfiles: nextFiles,\n\t\t\t\t\tdirectories: nextDirectories,\n\t\t\t\t\tisIgnoredPath,\n\t\t\t\t} = getWatchTargets(files, { outdir: options.outdir });\n\n\t\t\t\tfor (const [filePath, watcher] of fileWatchers) {\n\t\t\t\t\tif (!nextFiles.has(filePath)) {\n\t\t\t\t\t\twatcher.close();\n\t\t\t\t\t\tfileWatchers.delete(filePath);\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tfor (const [directoryPath, watcher] of directoryWatchers) {\n\t\t\t\t\tif (!nextDirectories.has(directoryPath)) {\n\t\t\t\t\t\twatcher.close();\n\t\t\t\t\t\tdirectoryWatchers.delete(directoryPath);\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tconst attachWatcherErrorHandler = (\n\t\t\t\t\twatcher: fs.FSWatcher,\n\t\t\t\t\ttargetPath: string,\n\t\t\t\t\ttargetType: \"file\" | \"directory\"\n\t\t\t\t) => {\n\t\t\t\t\twatcher.on(\"error\", (error) => {\n\t\t\t\t\t\tlogger.warn(\n\t\t\t\t\t\t\t`Watch ${targetType} error for ${targetPath}: ${(error as Error).message}`\n\t\t\t\t\t\t);\n\t\t\t\t\t});\n\t\t\t\t};\n\n\t\t\t\tfor (const filePath of nextFiles) {\n\t\t\t\t\tif (fileWatchers.has(filePath)) {\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\n\t\t\t\t\ttry {\n\t\t\t\t\t\tconst watcher = fs.watch(filePath, () => {\n\t\t\t\t\t\t\tscheduleCompile(filePath);\n\t\t\t\t\t\t});\n\t\t\t\t\t\tattachWatcherErrorHandler(watcher, filePath, \"file\");\n\t\t\t\t\t\tfileWatchers.set(filePath, watcher);\n\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\tlogger.warn(`Failed to watch file: ${filePath}`);\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tfor (const directoryPath of nextDirectories) {\n\t\t\t\t\tif (directoryWatchers.has(directoryPath)) {\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\n\t\t\t\t\ttry {\n\t\t\t\t\t\tconst watcher = fs.watch(directoryPath, (eventType, filename) => {\n\t\t\t\t\t\t\tif (!filename) {\n\t\t\t\t\t\t\t\tscheduleCompile(directoryPath);\n\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tconst changedPath = resolve(directoryPath, filename.toString());\n\t\t\t\t\t\t\tif (isIgnoredPath(changedPath)) {\n\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tscheduleCompile(changedPath);\n\t\t\t\t\t\t});\n\t\t\t\t\t\tattachWatcherErrorHandler(watcher, directoryPath, \"directory\");\n\t\t\t\t\t\tdirectoryWatchers.set(directoryPath, watcher);\n\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\tlogger.warn(`Failed to watch directory: ${directoryPath}`);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t};\n\n\t\t\tconst runCompile = async (changedPath?: string) => {\n\t\t\t\tif (compileInProgress) {\n\t\t\t\t\tcompileRequested = true;\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tcompileInProgress = true;\n\t\t\t\tconst previouslyReadFiles = new Set(readFiles);\n\t\t\t\tclearReadFiles();\n\n\t\t\t\tif (changedPath) {\n\t\t\t\t\tlogger.info(\n\t\t\t\t\t\t`Re-compiling messages... File \"${relative(process.cwd(), changedPath)}\" has changed.`\n\t\t\t\t\t);\n\t\t\t\t} else {\n\t\t\t\t\tlogger.info(\"Compiling messages ...\");\n\t\t\t\t}\n\n\t\t\t\ttry {\n\t\t\t\t\tconst seededPrevious =\n\t\t\t\t\t\tpreviousCompilation ??\n\t\t\t\t\t\t(await seedPreviousCompilationFromOutdir({\n\t\t\t\t\t\t\toutdir: compileOptions.outdir,\n\t\t\t\t\t\t}));\n\n\t\t\t\t\tpreviousCompilation = await compile({\n\t\t\t\t\t\t...compileOptions,\n\t\t\t\t\t\tfs: trackedFs,\n\t\t\t\t\t\tpreviousCompilation: seededPrevious,\n\t\t\t\t\t\tcleanOutdir: false,\n\t\t\t\t\t});\n\n\t\t\t\t\tif (changedPath) {\n\t\t\t\t\t\tlogger.success(\"Re-compilation complete.\");\n\t\t\t\t\t} else {\n\t\t\t\t\t\tlogger.success(\"Successfully compiled messages.\");\n\t\t\t\t\t}\n\t\t\t\t} catch (e) {\n\t\t\t\t\tif (previouslyReadFiles.size > 0) {\n\t\t\t\t\t\tclearReadFiles();\n\t\t\t\t\t\tfor (const filePath of previouslyReadFiles) {\n\t\t\t\t\t\t\treadFiles.add(filePath);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tpreviousCompilation = undefined;\n\t\t\t\t\tlogger.error(\"Error while compiling messages.\");\n\t\t\t\t\tlogger.error(e);\n\t\t\t\t} finally {\n\t\t\t\t\tupdateWatchers(readFiles);\n\t\t\t\t\tcompileInProgress = false;\n\t\t\t\t\tif (compileRequested) {\n\t\t\t\t\t\tcompileRequested = false;\n\t\t\t\t\t\trunCompile();\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t};\n\n\t\t\tconst scheduleCompile = (changedPath?: string) => {\n\t\t\t\tif (compileTimer) {\n\t\t\t\t\tclearTimeout(compileTimer);\n\t\t\t\t}\n\t\t\t\tcompileTimer = setTimeout(() => {\n\t\t\t\t\trunCompile(changedPath);\n\t\t\t\t}, 100);\n\t\t\t};\n\n\t\t\tconst closeWatchers = () => {\n\t\t\t\tfor (const watcher of fileWatchers.values()) {\n\t\t\t\t\twatcher.close();\n\t\t\t\t}\n\t\t\t\tfor (const watcher of directoryWatchers.values()) {\n\t\t\t\t\twatcher.close();\n\t\t\t\t}\n\t\t\t\tfileWatchers.clear();\n\t\t\t\tdirectoryWatchers.clear();\n\t\t\t};\n\n\t\t\tprocess.on(\"SIGINT\", () => {\n\t\t\t\tcloseWatchers();\n\t\t\t\tprocess.exit(0);\n\t\t\t});\n\n\t\t\tawait runCompile();\n\t\t\tlogger.info(\"Watching for changes...\");\n\t\t}\n\t);\n"]}
|
|
1
|
+
{"version":3,"file":"command.js","sourceRoot":"","sources":["../../../../src/cli/commands/compile/command.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC;AAC1D,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAC9C,OAAO,EAAE,MAAM,EAAE,MAAM,mCAAmC,CAAC;AAC3D,OAAO,EAAE,mBAAmB,EAAE,eAAe,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAC3G,OAAO,EAAE,OAAO,EAA0B,MAAM,8BAA8B,CAAC;AAC/E,OAAO,EAAE,iCAAiC,EAAE,MAAM,gDAAgD,CA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AAgB,EAAE,CAAC;gBACtB,gBAAgB,GAAG,KAAK,CAAC;gBACzB,UAAU,EAAE,CAAC;YACd,CAAC;QACF,CAAC;IACF,CAAC,CAAC;IAEF,MAAM,eAAe,GAAG,CAAC,WAAoB,EAAE,EAAE;QAChD,IAAI,YAAY,EAAE,CAAC;YAClB,YAAY,CAAC,YAAY,CAAC,CAAC;QAC5B,CAAC;QACD,YAAY,GAAG,UAAU,CAAC,GAAG,EAAE;YAC9B,UAAU,CAAC,WAAW,CAAC,CAAC;QACzB,CAAC,EAAE,GAAG,CAAC,CAAC;IACT,CAAC,CAAC;IAEF,MAAM,aAAa,GAAG,GAAG,EAAE;QAC1B,KAAK,MAAM,OAAO,IAAI,YAAY,CAAC,MAAM,EAAE,EAAE,CAAC;YAC7C,OAAO,CAAC,KAAK,EAAE,CAAC;QACjB,CAAC;QACD,KAAK,MAAM,OAAO,IAAI,iBAAiB,CAAC,MAAM,EAAE,EAAE,CAAC;YAClD,OAAO,CAAC,KAAK,EAAE,CAAC;QACjB,CAAC;QACD,YAAY,CAAC,KAAK,EAAE,CAAC;QACrB,iBAAiB,CAAC,KAAK,EAAE,CAAC;IAC3B,CAAC,CAAC;IAEF,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE,GAAG,EAAE;QACzB,aAAa,EAAE,CAAC;QAChB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACjB,CAAC,CAAC,CAAC;IAEH,MAAM,UAAU,EAAE,CAAC;IACnB,MAAM,CAAC,IAAI,CAAC,yBAAyB,CAAC,CAAC;AACxC,CAAC,CACD,CAAC","sourcesContent":["import { Command, InvalidArgumentError } from \"commander\";\nimport fs from \"node:fs\";\nimport { resolve, relative } from \"node:path\";\nimport { Logger } from \"../../../services/logger/index.js\";\nimport { DEFAULT_BASE_LOCALE, DEFAULT_LOCALES, DEFAULT_MESSAGES, DEFAULT_OUTDIR } from \"../../defaults.js\";\nimport { compile, type CompilationResult } from \"../../../compiler/compile.js\";\nimport { seedPreviousCompilationFromOutdir } from \"../../../compiler/seed-previous-compilation.js\";\nimport {\n\tdefaultCompilerOptions,\n\ttype CompilerOptions,\n} from \"../../../compiler/compiler-options.js\";\nimport {\n\tcreateTrackedFs,\n\tgetWatchTargets,\n} from \"../../../services/file-watching/tracked-fs.js\";\n\nconst parseOutputStructure = (\n\tvalue: string\n): NonNullable<CompilerOptions[\"outputStructure\"]> => {\n\tif (value === \"message-modules\" || value === \"locale-modules\") {\n\t\treturn value;\n\t}\n\tthrow new InvalidArgumentError(\n\t\t`Invalid output structure \"${value}\". Expected \"message-modules\" or \"locale-modules\".`\n\t);\n};\n\nexport const compileCommand = new Command()\n\t.name(\"compile\")\n\t.summary(\"Compiles paraglide-lite message files\")\n\t.option(\n\t\t\"--messages <path>\",\n\t\t'Path pattern for locale files. Example: \"./messages/{locale}.json\"',\n\t\tDEFAULT_MESSAGES\n\t)\n\t.option(\n\t\t\"--locales <items...>\",\n\t\t\"Locales to compile. Example: --locales en de\",\n\t\t[...DEFAULT_LOCALES]\n\t)\n\t.option(\n\t\t\"--base-locale <locale>\",\n\t\t\"Base locale for fallbacks\",\n\t\tDEFAULT_BASE_LOCALE\n\t)\n\t.requiredOption(\n\t\t\"--outdir <path>\",\n\t\t'The path to the output directory. Example: \"./src/paraglide\"',\n\t\tDEFAULT_OUTDIR\n\t)\n\t.option(\n\t\t\"--strategy <items...>\",\n\t\t[\n\t\t\t\"The strategy to be used.\",\n\t\t\t\"\",\n\t\t\t\"Example: --strategy cookie globalVariable baseLocale\",\n\t\t\t\"Upstream docs: https://paraglidejs.com/strategy\",\n\t\t].join(\"\\n\")\n\t)\n\t.requiredOption(\"--silent\", \"Only log errors to the console\", false)\n\t.option(\n\t\t\"--emit-ts-declarations\",\n\t\t\"Emit .d.ts files for the generated output (requires the typescript package)\",\n\t\tdefaultCompilerOptions.emitTsDeclarations\n\t)\n\t.option(\n\t\t\"--no-emit-ts-declarations\",\n\t\t\"Do not emit .d.ts files for the generated output\"\n\t)\n\t.option(\n\t\t\"--emit-git-ignore\",\n\t\t\"Emit a .gitignore in the output directory\",\n\t\tdefaultCompilerOptions.emitGitIgnore\n\t)\n\t.option(\n\t\t\"--no-emit-git-ignore\",\n\t\t\"Do not emit a .gitignore in the output directory\"\n\t)\n\t.option(\n\t\t\"--emit-prettier-ignore\",\n\t\t\"Emit a .prettierignore in the output directory\",\n\t\tdefaultCompilerOptions.emitPrettierIgnore\n\t)\n\t.option(\n\t\t\"--no-emit-prettier-ignore\",\n\t\t\"Do not emit a .prettierignore in the output directory\"\n\t)\n\t.option(\n\t\t\"--emit-readme\",\n\t\t\"Emit a README.md in the output directory (helps LLMs understand the generated code)\",\n\t\tdefaultCompilerOptions.emitReadme\n\t)\n\t.option(\n\t\t\"--no-emit-readme\",\n\t\t\"Do not emit README.md in the output directory\"\n\t)\n\t.option(\n\t\t\"--is-server <expression>\",\n\t\t[\n\t\t\t\"JavaScript expression for runtime `isServer` (enables server/client tree-shaking).\",\n\t\t\t'Quote if the expression contains spaces, e.g. --is-server \\'typeof window === \"undefined\"\\'.',\n\t\t\t\"Vite SSR example: --is-server 'import.meta.env.SSR'\",\n\t\t].join(\" \")\n\t)\n\t.option(\n\t\t\"--output-structure <structure>\",\n\t\t[\n\t\t\t'The output structure for compiled messages. Either \"message-modules\" or \"locale-modules\".',\n\t\t\t\"\",\n\t\t\t'\"message-modules\" gives each message its own module (better tree-shaking).',\n\t\t\t'\"locale-modules\" bundles messages per locale (fewer files, better for large projects in dev).',\n\t\t].join(\"\\n\"),\n\t\tparseOutputStructure,\n\t\tdefaultCompilerOptions.outputStructure\n\t)\n\t.option(\"--watch\", \"Watch message files and recompile on change\", false)\n\t.action(\n\t\tasync (options: {\n\t\t\tsilent: boolean;\n\t\t\tmessages: string;\n\t\t\tlocales: string[];\n\t\t\tbaseLocale: string;\n\t\t\toutdir: string;\n\t\t\tstrategy?: CompilerOptions[\"strategy\"];\n\t\t\temitTsDeclarations?: CompilerOptions[\"emitTsDeclarations\"];\n\t\t\temitGitIgnore?: CompilerOptions[\"emitGitIgnore\"];\n\t\t\temitPrettierIgnore?: CompilerOptions[\"emitPrettierIgnore\"];\n\t\t\temitReadme?: CompilerOptions[\"emitReadme\"];\n\t\t\tisServer?: CompilerOptions[\"isServer\"];\n\t\t\toutputStructure?: CompilerOptions[\"outputStructure\"];\n\t\t\twatch?: boolean;\n\t\t}) => {\n\t\t\tconst logger = new Logger({ silent: options.silent, prefix: true });\n\n\t\t\tconst compileOptions = {\n\t\t\t\tmessages: options.messages,\n\t\t\t\tlocales: options.locales,\n\t\t\t\tbaseLocale: options.baseLocale,\n\t\t\t\toutdir: options.outdir,\n\t\t\t\tstrategy: options.strategy ?? defaultCompilerOptions.strategy,\n\t\t\t\temitTsDeclarations:\n\t\t\t\t\toptions.emitTsDeclarations ??\n\t\t\t\t\tdefaultCompilerOptions.emitTsDeclarations,\n\t\t\t\temitGitIgnore:\n\t\t\t\t\toptions.emitGitIgnore ?? defaultCompilerOptions.emitGitIgnore,\n\t\t\t\temitPrettierIgnore:\n\t\t\t\t\toptions.emitPrettierIgnore ??\n\t\t\t\t\tdefaultCompilerOptions.emitPrettierIgnore,\n\t\t\t\temitReadme: options.emitReadme ?? defaultCompilerOptions.emitReadme,\n\t\t\t\tisServer: options.isServer ?? defaultCompilerOptions.isServer,\n\t\t\t\toutputStructure:\n\t\t\t\t\toptions.outputStructure ??\n\t\t\t\t\tdefaultCompilerOptions.outputStructure,\n\t\t\t\t// CLI always writes the full output tree to disk.\n\t\t\t\temitFiles: true as const,\n\t\t\t};\n\n\t\t\tif (!options.watch) {\n\t\t\t\tlogger.info(`Compiling messages ...`);\n\n\t\t\t\ttry {\n\t\t\t\t\tconst previousCompilation = await seedPreviousCompilationFromOutdir({\n\t\t\t\t\t\toutdir: compileOptions.outdir,\n\t\t\t\t\t});\n\n\t\t\t\t\tawait compile({\n\t\t\t\t\t\t...compileOptions,\n\t\t\t\t\t\tpreviousCompilation,\n\t\t\t\t\t\tcleanOutdir: false,\n\t\t\t\t\t});\n\t\t\t\t} catch (e) {\n\t\t\t\t\tlogger.error(\"Error while compiling messages.\");\n\t\t\t\t\tlogger.error(e);\n\t\t\t\t\tprocess.exit(1);\n\t\t\t\t}\n\n\t\t\t\tlogger.success(`Successfully compiled messages.`);\n\n\t\t\t\tprocess.exit(0);\n\t\t\t}\n\n\t\t\tconst { fs: trackedFs, readFiles, clearReadFiles } = createTrackedFs();\n\t\t\tconst fileWatchers = new Map<string, fs.FSWatcher>();\n\t\t\tconst directoryWatchers = new Map<string, fs.FSWatcher>();\n\t\t\tlet previousCompilation: CompilationResult | undefined;\n\t\t\tlet compileTimer: NodeJS.Timeout | undefined;\n\t\t\tlet compileInProgress = false;\n\t\t\tlet compileRequested = false;\n\n\t\t\tconst updateWatchers = (files: Set<string>) => {\n\t\t\t\tconst {\n\t\t\t\t\tfiles: nextFiles,\n\t\t\t\t\tdirectories: nextDirectories,\n\t\t\t\t\tisIgnoredPath,\n\t\t\t\t} = getWatchTargets(files, { outdir: options.outdir });\n\n\t\t\t\tfor (const [filePath, watcher] of fileWatchers) {\n\t\t\t\t\tif (!nextFiles.has(filePath)) {\n\t\t\t\t\t\twatcher.close();\n\t\t\t\t\t\tfileWatchers.delete(filePath);\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tfor (const [directoryPath, watcher] of directoryWatchers) {\n\t\t\t\t\tif (!nextDirectories.has(directoryPath)) {\n\t\t\t\t\t\twatcher.close();\n\t\t\t\t\t\tdirectoryWatchers.delete(directoryPath);\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tconst attachWatcherErrorHandler = (\n\t\t\t\t\twatcher: fs.FSWatcher,\n\t\t\t\t\ttargetPath: string,\n\t\t\t\t\ttargetType: \"file\" | \"directory\"\n\t\t\t\t) => {\n\t\t\t\t\twatcher.on(\"error\", (error) => {\n\t\t\t\t\t\tlogger.warn(\n\t\t\t\t\t\t\t`Watch ${targetType} error for ${targetPath}: ${(error as Error).message}`\n\t\t\t\t\t\t);\n\t\t\t\t\t});\n\t\t\t\t};\n\n\t\t\t\tfor (const filePath of nextFiles) {\n\t\t\t\t\tif (fileWatchers.has(filePath)) {\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\n\t\t\t\t\ttry {\n\t\t\t\t\t\tconst watcher = fs.watch(filePath, () => {\n\t\t\t\t\t\t\tscheduleCompile(filePath);\n\t\t\t\t\t\t});\n\t\t\t\t\t\tattachWatcherErrorHandler(watcher, filePath, \"file\");\n\t\t\t\t\t\tfileWatchers.set(filePath, watcher);\n\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\tlogger.warn(`Failed to watch file: ${filePath}`);\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tfor (const directoryPath of nextDirectories) {\n\t\t\t\t\tif (directoryWatchers.has(directoryPath)) {\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\n\t\t\t\t\ttry {\n\t\t\t\t\t\tconst watcher = fs.watch(directoryPath, (eventType, filename) => {\n\t\t\t\t\t\t\tif (!filename) {\n\t\t\t\t\t\t\t\tscheduleCompile(directoryPath);\n\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tconst changedPath = resolve(directoryPath, filename.toString());\n\t\t\t\t\t\t\tif (isIgnoredPath(changedPath)) {\n\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tscheduleCompile(changedPath);\n\t\t\t\t\t\t});\n\t\t\t\t\t\tattachWatcherErrorHandler(watcher, directoryPath, \"directory\");\n\t\t\t\t\t\tdirectoryWatchers.set(directoryPath, watcher);\n\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\tlogger.warn(`Failed to watch directory: ${directoryPath}`);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t};\n\n\t\t\tconst runCompile = async (changedPath?: string) => {\n\t\t\t\tif (compileInProgress) {\n\t\t\t\t\tcompileRequested = true;\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tcompileInProgress = true;\n\t\t\t\tconst previouslyReadFiles = new Set(readFiles);\n\t\t\t\tclearReadFiles();\n\n\t\t\t\tif (changedPath) {\n\t\t\t\t\tlogger.info(\n\t\t\t\t\t\t`Re-compiling messages... File \"${relative(process.cwd(), changedPath)}\" has changed.`\n\t\t\t\t\t);\n\t\t\t\t} else {\n\t\t\t\t\tlogger.info(\"Compiling messages ...\");\n\t\t\t\t}\n\n\t\t\t\ttry {\n\t\t\t\t\tconst seededPrevious =\n\t\t\t\t\t\tpreviousCompilation ??\n\t\t\t\t\t\t(await seedPreviousCompilationFromOutdir({\n\t\t\t\t\t\t\toutdir: compileOptions.outdir,\n\t\t\t\t\t\t}));\n\n\t\t\t\t\tpreviousCompilation = await compile({\n\t\t\t\t\t\t...compileOptions,\n\t\t\t\t\t\tfs: trackedFs,\n\t\t\t\t\t\tpreviousCompilation: seededPrevious,\n\t\t\t\t\t\tcleanOutdir: false,\n\t\t\t\t\t});\n\n\t\t\t\t\tif (changedPath) {\n\t\t\t\t\t\tlogger.success(\"Re-compilation complete.\");\n\t\t\t\t\t} else {\n\t\t\t\t\t\tlogger.success(\"Successfully compiled messages.\");\n\t\t\t\t\t}\n\t\t\t\t} catch (e) {\n\t\t\t\t\tif (previouslyReadFiles.size > 0) {\n\t\t\t\t\t\tclearReadFiles();\n\t\t\t\t\t\tfor (const filePath of previouslyReadFiles) {\n\t\t\t\t\t\t\treadFiles.add(filePath);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tpreviousCompilation = undefined;\n\t\t\t\t\tlogger.error(\"Error while compiling messages.\");\n\t\t\t\t\tlogger.error(e);\n\t\t\t\t} finally {\n\t\t\t\t\tupdateWatchers(readFiles);\n\t\t\t\t\tcompileInProgress = false;\n\t\t\t\t\tif (compileRequested) {\n\t\t\t\t\t\tcompileRequested = false;\n\t\t\t\t\t\trunCompile();\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t};\n\n\t\t\tconst scheduleCompile = (changedPath?: string) => {\n\t\t\t\tif (compileTimer) {\n\t\t\t\t\tclearTimeout(compileTimer);\n\t\t\t\t}\n\t\t\t\tcompileTimer = setTimeout(() => {\n\t\t\t\t\trunCompile(changedPath);\n\t\t\t\t}, 100);\n\t\t\t};\n\n\t\t\tconst closeWatchers = () => {\n\t\t\t\tfor (const watcher of fileWatchers.values()) {\n\t\t\t\t\twatcher.close();\n\t\t\t\t}\n\t\t\t\tfor (const watcher of directoryWatchers.values()) {\n\t\t\t\t\twatcher.close();\n\t\t\t\t}\n\t\t\t\tfileWatchers.clear();\n\t\t\t\tdirectoryWatchers.clear();\n\t\t\t};\n\n\t\t\tprocess.on(\"SIGINT\", () => {\n\t\t\t\tcloseWatchers();\n\t\t\t\tprocess.exit(0);\n\t\t\t});\n\n\t\t\tawait runCompile();\n\t\t\tlogger.info(\"Watching for changes...\");\n\t\t}\n\t);\n"]}
|
|
@@ -11,6 +11,7 @@ beforeEach(() => {
|
|
|
11
11
|
initialSigintListeners = process.listeners("SIGINT");
|
|
12
12
|
});
|
|
13
13
|
afterEach(async () => {
|
|
14
|
+
vi.restoreAllMocks();
|
|
14
15
|
for (const listener of process.listeners("SIGINT")) {
|
|
15
16
|
if (!initialSigintListeners.includes(listener)) {
|
|
16
17
|
process.removeListener("SIGINT", listener);
|
|
@@ -20,6 +21,56 @@ afterEach(async () => {
|
|
|
20
21
|
await rm(directory, { recursive: true, force: true });
|
|
21
22
|
}
|
|
22
23
|
});
|
|
24
|
+
test("compile seeds existing outdir and disables cleaning (#743)", async () => {
|
|
25
|
+
const testDirectory = await mkdtemp(path.join(tmpdir(), "paraglide-cli-"));
|
|
26
|
+
testDirectories.push(testDirectory);
|
|
27
|
+
const outdir = path.join(testDirectory, "output");
|
|
28
|
+
const { writeOutput } = await import("../../../services/file-handling/write-output.js");
|
|
29
|
+
await writeOutput({
|
|
30
|
+
directory: outdir,
|
|
31
|
+
output: {
|
|
32
|
+
"runtime.js": "export const runtime = true;",
|
|
33
|
+
},
|
|
34
|
+
fs: nodeFs,
|
|
35
|
+
});
|
|
36
|
+
const compileMock = vi.fn().mockResolvedValue({
|
|
37
|
+
outputHashes: {
|
|
38
|
+
"runtime.js": "next-hash",
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
vi.doMock("../../../compiler/compile.js", () => ({
|
|
42
|
+
compile: compileMock,
|
|
43
|
+
}));
|
|
44
|
+
const exitError = new Error("process.exit");
|
|
45
|
+
const exitMock = vi.spyOn(process, "exit").mockImplementation(() => {
|
|
46
|
+
throw exitError;
|
|
47
|
+
});
|
|
48
|
+
const { compileCommand } = await import("./command.js");
|
|
49
|
+
await expect(compileCommand.parseAsync([
|
|
50
|
+
"--messages",
|
|
51
|
+
"./messages/{locale}.json",
|
|
52
|
+
"--locales",
|
|
53
|
+
"en",
|
|
54
|
+
"de",
|
|
55
|
+
"--base-locale",
|
|
56
|
+
"en",
|
|
57
|
+
"--outdir",
|
|
58
|
+
outdir,
|
|
59
|
+
"--silent",
|
|
60
|
+
], { from: "user" })).rejects.toBe(exitError);
|
|
61
|
+
expect(compileMock).toHaveBeenCalledTimes(1);
|
|
62
|
+
expect(compileMock).toHaveBeenCalledWith(expect.objectContaining({
|
|
63
|
+
outdir,
|
|
64
|
+
cleanOutdir: false,
|
|
65
|
+
previousCompilation: {
|
|
66
|
+
outputHashes: {
|
|
67
|
+
"runtime.js": expect.any(String),
|
|
68
|
+
},
|
|
69
|
+
output: {},
|
|
70
|
+
},
|
|
71
|
+
}));
|
|
72
|
+
expect(exitMock).toHaveBeenCalledWith(0);
|
|
73
|
+
});
|
|
23
74
|
test("compile --watch seeds existing outdir and disables cleaning on first compile (#688)", async () => {
|
|
24
75
|
const testDirectory = await mkdtemp(path.join(tmpdir(), "paraglide-cli-"));
|
|
25
76
|
testDirectories.push(testDirectory);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"command.test.js","sourceRoot":"","sources":["../../../../src/c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\"node:fs/promises\";\nimport * as nodeFs from \"node:fs/promises\";\nimport { tmpdir } from \"node:os\";\nimport path from \"node:path\";\nimport { afterEach, beforeEach, expect, test, vi } from \"vitest\";\n\nlet testDirectories: string[] = [];\nlet initialSigintListeners: NodeJS.SignalsListener[] = [];\n\nbeforeEach(() => {\n\tvi.resetModules();\n\ttestDirectories = [];\n\tinitialSigintListeners = process.listeners(\"SIGINT\");\n});\n\nafterEach(async () => {\n\tfor (const listener of process.listeners(\"SIGINT\")) {\n\t\tif (!initialSigintListeners.includes(listener)) {\n\t\t\tprocess.removeListener(\"SIGINT\", listener);\n\t\t}\n\t}\n\tfor (const directory of testDirectories) {\n\t\tawait rm(directory, { recursive: true, force: true });\n\t}\n});\n\ntest(\"compile --watch seeds existing outdir and disables cleaning on first compile (#688)\", async () => {\n\tconst testDirectory = await mkdtemp(path.join(tmpdir(), \"paraglide-cli-\"));\n\ttestDirectories.push(testDirectory);\n\tconst outdir = path.join(testDirectory, \"output\");\n\tconst { writeOutput } = await import(\n\t\t\"../../../services/file-handling/write-output.js\"\n\t);\n\tawait writeOutput({\n\t\tdirectory: outdir,\n\t\toutput: {\n\t\t\t\"runtime.js\": \"export const runtime = true;\",\n\t\t},\n\t\tfs: nodeFs,\n\t});\n\n\tconst compileMock = vi.fn().mockResolvedValue({\n\t\toutputHashes: {\n\t\t\t\"runtime.js\": \"next-hash\",\n\t\t},\n\t});\n\tvi.doMock(\"../../../compiler/compile.js\", () => ({\n\t\tcompile: compileMock,\n\t}));\n\n\tconst { compileCommand } = await import(\"./command.js\");\n\n\tawait compileCommand.parseAsync(\n\t\t[\n\t\t\t\"--messages\",\n\t\t\t\"./messages/{locale}.json\",\n\t\t\t\"--locales\",\n\t\t\t\"en\",\n\t\t\t\"de\",\n\t\t\t\"--base-locale\",\n\t\t\t\"en\",\n\t\t\t\"--outdir\",\n\t\t\toutdir,\n\t\t\t\"--watch\",\n\t\t\t\"--silent\",\n\t\t],\n\t\t{ from: \"user\" }\n\t);\n\n\texpect(compileMock).toHaveBeenCalledTimes(1);\n\texpect(compileMock).toHaveBeenCalledWith(\n\t\texpect.objectContaining({\n\t\t\toutdir,\n\t\t\tcleanOutdir: false,\n\t\t\tpreviousCompilation: {\n\t\t\t\toutputHashes: {\n\t\t\t\t\t\"runtime.js\": expect.any(String),\n\t\t\t\t},\n\t\t\t\toutput: {},\n\t\t\t},\n\t\t})\n\t);\n});\n"]}
|
|
1
|
+
{"version":3,"file":"command.test.js","sourceRoot":"","sources":["../../../../src/cli/commands/compile/command.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,EAAE,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,KAAK,MAAM,MAAM,kBAAkB,CAAC;AAC3C,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAEjE,IAAI,eAAe,GAAa,EAAE,CAAC;AACnC,IAAI,sBAAsB,GAA6B,EAAE,CAAC;AAE1D,UAAU,CAAC,GAAG,EAAE;IACf,EAAE,CAAC,YAAY,EAAE,CAAC;IAClB,eAAe,GAAG,EAAE,CAAC;IACrB,sBAAsB,GAAG,OAAO,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;AACtD,CAAC,CAAC,CAAC;AAEH,SAAS,CAAC,KAAK,IAAI,EAAE;IACpB,EAAE,CAAC,eAAe,EAAE,CAAC;IACrB,KAAK,MAAM,QAAQ,IAAI,OAAO,CAAC,SAAS,CAAC,QAAQ,CAAC,EAAE,CAAC;QACpD,IAAI,CAAC,sBAAsB,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC;YAChD,OAAO,CAAC,cAAc,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;QAC5C,CAAC;IACF,CAAC;IACD,KAAK,MAAM,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;QAC7C,YAAY,EAAE;YACb,YAAY,EAAE,WAAW;SACzB;KACD,CAAC,CAAC;IACH,EAAE,CAAC,MAAM,CAAC,8BAA8B,EAAE,GAAG,EAAE,CAAC,CAAC;QAChD,OAAO,EAAE,WAAW;KACpB,CAAC,CAAC,CAAC;IAEJ,MAAM,EAAE,cAAc,EAAE,GAAG,MAAM,MAAM,CAAC,cAAc,CAAC,CAAC;IAExD,MAAM,cAAc,CAAC,UAAU,CAC9B;QACC,YAAY;QACZ,0BAA0B;QAC1B,WAAW;QACX,IAAI;QACJ,IAAI;QACJ,eAAe;QACf,IAAI;QACJ,UAAU;QACV,MAAM;QACN,SAAS;QACT,UAAU;KACV,EACD,EAAE,IAAI,EAAE,MAAM,EAAE,CAChB,CAAC;IAEF,MAAM,CAAC,WAAW,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC;IAC7C,MAAM,CAAC,WAAW,CAAC,CAAC,oBAAoB,CACvC,MAAM,CAAC,gBAAgB,CAAC;QACvB,MAAM;QACN,WAAW,EAAE,KAAK;QAClB,mBAAmB,EAAE;YACpB,YAAY,EAAE;gBACb,YAAY,EAAE,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC;aAChC;YACD,MAAM,EAAE,EAAE;SACV;KACD,CAAC,CACF,CAAC;AACH,CAAC,CAAC,CAAC","sourcesContent":["import { mkdtemp, rm } from \"node:fs/promises\";\nimport * as nodeFs from \"node:fs/promises\";\nimport { tmpdir } from \"node:os\";\nimport path from \"node:path\";\nimport { afterEach, beforeEach, expect, test, vi } from \"vitest\";\n\nlet testDirectories: string[] = [];\nlet initialSigintListeners: NodeJS.SignalsListener[] = [];\n\nbeforeEach(() => {\n\tvi.resetModules();\n\ttestDirectories = [];\n\tinitialSigintListeners = process.listeners(\"SIGINT\");\n});\n\nafterEach(async () => {\n\tvi.restoreAllMocks();\n\tfor (const listener of process.listeners(\"SIGINT\")) {\n\t\tif (!initialSigintListeners.includes(listener)) {\n\t\t\tprocess.removeListener(\"SIGINT\", listener);\n\t\t}\n\t}\n\tfor (const directory of testDirectories) {\n\t\tawait rm(directory, { recursive: true, force: true });\n\t}\n});\n\ntest(\"compile seeds existing outdir and disables cleaning (#743)\", async () => {\n\tconst testDirectory = await mkdtemp(path.join(tmpdir(), \"paraglide-cli-\"));\n\ttestDirectories.push(testDirectory);\n\tconst outdir = path.join(testDirectory, \"output\");\n\tconst { writeOutput } = await import(\n\t\t\"../../../services/file-handling/write-output.js\"\n\t);\n\tawait writeOutput({\n\t\tdirectory: outdir,\n\t\toutput: {\n\t\t\t\"runtime.js\": \"export const runtime = true;\",\n\t\t},\n\t\tfs: nodeFs,\n\t});\n\n\tconst compileMock = vi.fn().mockResolvedValue({\n\t\toutputHashes: {\n\t\t\t\"runtime.js\": \"next-hash\",\n\t\t},\n\t});\n\tvi.doMock(\"../../../compiler/compile.js\", () => ({\n\t\tcompile: compileMock,\n\t}));\n\tconst exitError = new Error(\"process.exit\");\n\tconst exitMock = vi.spyOn(process, \"exit\").mockImplementation(() => {\n\t\tthrow exitError;\n\t});\n\n\tconst { compileCommand } = await import(\"./command.js\");\n\n\tawait expect(\n\t\tcompileCommand.parseAsync(\n\t\t\t[\n\t\t\t\t\"--messages\",\n\t\t\t\t\"./messages/{locale}.json\",\n\t\t\t\t\"--locales\",\n\t\t\t\t\"en\",\n\t\t\t\t\"de\",\n\t\t\t\t\"--base-locale\",\n\t\t\t\t\"en\",\n\t\t\t\t\"--outdir\",\n\t\t\t\toutdir,\n\t\t\t\t\"--silent\",\n\t\t\t],\n\t\t\t{ from: \"user\" }\n\t\t)\n\t).rejects.toBe(exitError);\n\n\texpect(compileMock).toHaveBeenCalledTimes(1);\n\texpect(compileMock).toHaveBeenCalledWith(\n\t\texpect.objectContaining({\n\t\t\toutdir,\n\t\t\tcleanOutdir: false,\n\t\t\tpreviousCompilation: {\n\t\t\t\toutputHashes: {\n\t\t\t\t\t\"runtime.js\": expect.any(String),\n\t\t\t\t},\n\t\t\t\toutput: {},\n\t\t\t},\n\t\t})\n\t);\n\texpect(exitMock).toHaveBeenCalledWith(0);\n});\n\ntest(\"compile --watch seeds existing outdir and disables cleaning on first compile (#688)\", async () => {\n\tconst testDirectory = await mkdtemp(path.join(tmpdir(), \"paraglide-cli-\"));\n\ttestDirectories.push(testDirectory);\n\tconst outdir = path.join(testDirectory, \"output\");\n\tconst { writeOutput } = await import(\n\t\t\"../../../services/file-handling/write-output.js\"\n\t);\n\tawait writeOutput({\n\t\tdirectory: outdir,\n\t\toutput: {\n\t\t\t\"runtime.js\": \"export const runtime = true;\",\n\t\t},\n\t\tfs: nodeFs,\n\t});\n\n\tconst compileMock = vi.fn().mockResolvedValue({\n\t\toutputHashes: {\n\t\t\t\"runtime.js\": \"next-hash\",\n\t\t},\n\t});\n\tvi.doMock(\"../../../compiler/compile.js\", () => ({\n\t\tcompile: compileMock,\n\t}));\n\n\tconst { compileCommand } = await import(\"./command.js\");\n\n\tawait compileCommand.parseAsync(\n\t\t[\n\t\t\t\"--messages\",\n\t\t\t\"./messages/{locale}.json\",\n\t\t\t\"--locales\",\n\t\t\t\"en\",\n\t\t\t\"de\",\n\t\t\t\"--base-locale\",\n\t\t\t\"en\",\n\t\t\t\"--outdir\",\n\t\t\toutdir,\n\t\t\t\"--watch\",\n\t\t\t\"--silent\",\n\t\t],\n\t\t{ from: \"user\" }\n\t);\n\n\texpect(compileMock).toHaveBeenCalledTimes(1);\n\texpect(compileMock).toHaveBeenCalledWith(\n\t\texpect.objectContaining({\n\t\t\toutdir,\n\t\t\tcleanOutdir: false,\n\t\t\tpreviousCompilation: {\n\t\t\t\toutputHashes: {\n\t\t\t\t\t\"runtime.js\": expect.any(String),\n\t\t\t\t},\n\t\t\t\toutput: {},\n\t\t\t},\n\t\t})\n\t);\n});\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { FunctionReference } from "../messages/ast.js";
|
|
1
|
+
import type { Declaration, FunctionReference } from "../messages/ast.js";
|
|
2
2
|
export declare function isRegistryFunction(name: string): boolean;
|
|
3
3
|
export declare function registryFunctionNamesForDisplay(): string;
|
|
4
4
|
/**
|
|
@@ -9,4 +9,4 @@ export declare function registryFunctionNamesForDisplay(): string;
|
|
|
9
9
|
* compileAnnotation("i?.count", "en", { type: "function-reference", name: "number", options: [] })
|
|
10
10
|
* >> 'registry.number("en", i?.count, {})'
|
|
11
11
|
*/
|
|
12
|
-
export declare function compileAnnotation(str: string, locale: string, annotation?: FunctionReference): string;
|
|
12
|
+
export declare function compileAnnotation(str: string, locale: string, annotation?: FunctionReference, declarations?: Declaration[]): string;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { compileVariableAccess } from "./variable-access.js";
|
|
2
2
|
import { escapeForDoubleQuoteString } from "../services/codegen/escape.js";
|
|
3
3
|
/**
|
|
4
4
|
* The functions shipped in the generated registry.js file.
|
|
@@ -25,20 +25,20 @@ export function registryFunctionNamesForDisplay() {
|
|
|
25
25
|
* compileAnnotation("i?.count", "en", { type: "function-reference", name: "number", options: [] })
|
|
26
26
|
* >> 'registry.number("en", i?.count, {})'
|
|
27
27
|
*/
|
|
28
|
-
export function compileAnnotation(str, locale, annotation) {
|
|
28
|
+
export function compileAnnotation(str, locale, annotation, declarations) {
|
|
29
29
|
if (!annotation) {
|
|
30
30
|
return str;
|
|
31
31
|
}
|
|
32
32
|
if (annotation.name === "relativetime") {
|
|
33
33
|
validateRelativeTimeOptions(annotation);
|
|
34
34
|
}
|
|
35
|
-
return `registry.${annotation.name}("${locale}", ${str}, ${compileOptions(annotation.name, annotation.options)})`;
|
|
35
|
+
return `registry.${annotation.name}("${locale}", ${str}, ${compileOptions(annotation.name, annotation.options, declarations)})`;
|
|
36
36
|
}
|
|
37
|
-
function compileOptions(annotationName, options) {
|
|
37
|
+
function compileOptions(annotationName, options, declarations) {
|
|
38
38
|
if (options.length === 0) {
|
|
39
39
|
return "{}";
|
|
40
40
|
}
|
|
41
|
-
const entries = options.map((option) => `${option.name}: ${compileOptionLiteralOrVarRef(annotationName, option.name, option.value)}`);
|
|
41
|
+
const entries = options.map((option) => `${option.name}: ${compileOptionLiteralOrVarRef(annotationName, option.name, option.value, declarations)}`);
|
|
42
42
|
const code = "{ " + entries.join(", ") + " }";
|
|
43
43
|
return code;
|
|
44
44
|
}
|
|
@@ -65,17 +65,17 @@ const booleanOptionNamesByAnnotation = {
|
|
|
65
65
|
datetime: new Set(["hour12"]),
|
|
66
66
|
};
|
|
67
67
|
const jsNonNegativeIntegerPattern = /^(?:0|[1-9]\d*)$/;
|
|
68
|
-
function compileOptionLiteralOrVarRef(annotationName, optionName, value) {
|
|
68
|
+
function compileOptionLiteralOrVarRef(annotationName, optionName, value, declarations) {
|
|
69
69
|
if (value.type === "variable-reference") {
|
|
70
70
|
if (annotationName === "relativetime" && optionName === "unit") {
|
|
71
|
-
return `/** @type {import("../registry.js").RelativeTimeFormatUnit} */ (${
|
|
71
|
+
return `/** @type {import("../registry.js").RelativeTimeFormatUnit} */ (${compileVariableAccess(value.name, declarations)})`;
|
|
72
72
|
}
|
|
73
|
-
return
|
|
73
|
+
return compileVariableAccess(value.name, declarations);
|
|
74
74
|
}
|
|
75
75
|
if (annotationName === "relativetime" &&
|
|
76
76
|
optionName === "unit" &&
|
|
77
77
|
isDollarVariableReference(value.value)) {
|
|
78
|
-
return `/** @type {import("../registry.js").RelativeTimeFormatUnit} */ (${
|
|
78
|
+
return `/** @type {import("../registry.js").RelativeTimeFormatUnit} */ (${compileVariableAccess(value.value.slice(1), declarations)})`;
|
|
79
79
|
}
|
|
80
80
|
if (shouldEmitNumberLiteral(annotationName, optionName, value.value)) {
|
|
81
81
|
return value.value;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compile-annotation.js","sourceRoot":"","sources":["../../src/compiler/compile-annotation.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"compile-annotation.js","sourceRoot":"","sources":["../../src/compiler/compile-annotation.ts"],"names":[],"mappings":"AAMA,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M,CAAC,IAAI,KAAK,MAAM,CAClC,CAAC;IAEF,IAAI,WAAW,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC9B,MAAM,IAAI,KAAK,CAAC,wDAAwD,CAAC,CAAC;IAC3E,CAAC;IAED,IAAI,WAAW,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC5B,MAAM,IAAI,KAAK,CACd,kEAAkE,CAClE,CAAC;IACH,CAAC;IAED,MAAM,CAAC,UAAU,CAAC,GAAG,WAAW,CAAC;IACjC,IAAI,CAAC,UAAU,IAAI,UAAU,CAAC,KAAK,CAAC,IAAI,KAAK,oBAAoB,EAAE,CAAC;QACnE,OAAO;IACR,CAAC;IAED,IAAI,yBAAyB,CAAC,UAAU,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC;QACvD,OAAO;IACR,CAAC;IAED,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC,UAAU,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC;QACpD,MAAM,IAAI,KAAK,CACd,gCAAgC,UAAU,CAAC,KAAK,CAAC,KAAK,uBAAuB,KAAK,CAAC,IAAI,CACtF,iBAAiB,CACjB,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CACf,CAAC;IACH,CAAC;AACF,CAAC;AAED,SAAS,yBAAyB,CAAC,KAAa;IAC/C,OAAO,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC;AAClD,CAAC","sourcesContent":["import type {\n\tDeclaration,\n\tFunctionReference,\n\tLiteral,\n\tVariableReference,\n} from \"../messages/ast.js\";\nimport { compileVariableAccess } from \"./variable-access.js\";\nimport { escapeForDoubleQuoteString } from \"../services/codegen/escape.js\";\n\n/**\n * The functions shipped in the generated registry.js file.\n *\n * @see createRegistry()\n */\nconst registryFunctionNames = new Set([\n\t\"plural\",\n\t\"number\",\n\t\"datetime\",\n\t\"relativetime\",\n]);\n\nexport function isRegistryFunction(name: string): boolean {\n\treturn registryFunctionNames.has(name);\n}\n\nexport function registryFunctionNamesForDisplay(): string {\n\treturn Array.from(registryFunctionNames).join(\", \");\n}\n\n/**\n * Wraps a compiled expression value in a `registry.*` call if an\n * annotation is present.\n *\n * @example\n * compileAnnotation(\"i?.count\", \"en\", { type: \"function-reference\", name: \"number\", options: [] })\n * >> 'registry.number(\"en\", i?.count, {})'\n */\nexport function compileAnnotation(\n\tstr: string,\n\tlocale: string,\n\tannotation?: FunctionReference,\n\tdeclarations?: Declaration[]\n): string {\n\tif (!annotation) {\n\t\treturn str;\n\t}\n\tif (annotation.name === \"relativetime\") {\n\t\tvalidateRelativeTimeOptions(annotation);\n\t}\n\treturn `registry.${annotation.name}(\"${locale}\", ${str}, ${compileOptions(annotation.name, annotation.options, declarations)})`;\n}\n\nfunction compileOptions(\n\tannotationName: string,\n\toptions: FunctionReference[\"options\"],\n\tdeclarations?: Declaration[]\n): string {\n\tif (options.length === 0) {\n\t\treturn \"{}\";\n\t}\n\tconst entries: string[] = options.map(\n\t\t(option) =>\n\t\t\t`${option.name}: ${compileOptionLiteralOrVarRef(\n\t\t\t\tannotationName,\n\t\t\t\toption.name,\n\t\t\t\toption.value,\n\t\t\t\tdeclarations\n\t\t\t)}`\n\t);\n\tconst code = \"{ \" + entries.join(\", \") + \" }\";\n\n\treturn code;\n}\n\nconst numericOptionNamesByAnnotation: Record<string, ReadonlySet<string>> = {\n\tnumber: new Set([\n\t\t\"minimumIntegerDigits\",\n\t\t\"minimumFractionDigits\",\n\t\t\"maximumFractionDigits\",\n\t\t\"minimumSignificantDigits\",\n\t\t\"maximumSignificantDigits\",\n\t\t\"roundingIncrement\",\n\t]),\n\tplural: new Set([\n\t\t\"minimumIntegerDigits\",\n\t\t\"minimumFractionDigits\",\n\t\t\"maximumFractionDigits\",\n\t\t\"minimumSignificantDigits\",\n\t\t\"maximumSignificantDigits\",\n\t]),\n\tdatetime: new Set([\"fractionalSecondDigits\"]),\n};\n\nconst booleanOptionNamesByAnnotation: Record<string, ReadonlySet<string>> = {\n\tnumber: new Set([\"useGrouping\"]),\n\tdatetime: new Set([\"hour12\"]),\n};\n\nconst jsNonNegativeIntegerPattern = /^(?:0|[1-9]\\d*)$/;\n\nfunction compileOptionLiteralOrVarRef(\n\tannotationName: string,\n\toptionName: string,\n\tvalue: Literal | VariableReference,\n\tdeclarations?: Declaration[]\n): string {\n\tif (value.type === \"variable-reference\") {\n\t\tif (annotationName === \"relativetime\" && optionName === \"unit\") {\n\t\t\treturn `/** @type {import(\"../registry.js\").RelativeTimeFormatUnit} */ (${compileVariableAccess(value.name, declarations)})`;\n\t\t}\n\t\treturn compileVariableAccess(value.name, declarations);\n\t}\n\n\tif (\n\t\tannotationName === \"relativetime\" &&\n\t\toptionName === \"unit\" &&\n\t\tisDollarVariableReference(value.value)\n\t) {\n\t\treturn `/** @type {import(\"../registry.js\").RelativeTimeFormatUnit} */ (${compileVariableAccess(value.value.slice(1), declarations)})`;\n\t}\n\n\tif (shouldEmitNumberLiteral(annotationName, optionName, value.value)) {\n\t\treturn value.value;\n\t}\n\n\tif (shouldEmitBooleanLiteral(annotationName, optionName, value.value)) {\n\t\treturn value.value;\n\t}\n\n\treturn `\"${escapeForDoubleQuoteString(value.value)}\"`;\n}\n\nfunction shouldEmitNumberLiteral(\n\tannotationName: string,\n\toptionName: string,\n\tliteral: string\n): boolean {\n\treturn (\n\t\tnumericOptionNamesByAnnotation[annotationName]?.has(optionName) === true &&\n\t\tjsNonNegativeIntegerPattern.test(literal)\n\t);\n}\n\nfunction shouldEmitBooleanLiteral(\n\tannotationName: string,\n\toptionName: string,\n\tliteral: string\n): boolean {\n\treturn (\n\t\tbooleanOptionNamesByAnnotation[annotationName]?.has(optionName) === true &&\n\t\t(literal === \"true\" || literal === \"false\")\n\t);\n}\n\nconst relativeTimeUnits = new Set([\n\t\"year\",\n\t\"years\",\n\t\"quarter\",\n\t\"quarters\",\n\t\"month\",\n\t\"months\",\n\t\"week\",\n\t\"weeks\",\n\t\"day\",\n\t\"days\",\n\t\"hour\",\n\t\"hours\",\n\t\"minute\",\n\t\"minutes\",\n\t\"second\",\n\t\"seconds\",\n]);\n\nfunction validateRelativeTimeOptions(annotation: FunctionReference): void {\n\tconst unitOptions = annotation.options.filter(\n\t\t(option) => option.name === \"unit\"\n\t);\n\n\tif (unitOptions.length === 0) {\n\t\tthrow new Error('The \"relativetime\" formatter requires a \"unit\" option.');\n\t}\n\n\tif (unitOptions.length > 1) {\n\t\tthrow new Error(\n\t\t\t'The \"relativetime\" formatter requires exactly one \"unit\" option.'\n\t\t);\n\t}\n\n\tconst [unitOption] = unitOptions;\n\tif (!unitOption || unitOption.value.type === \"variable-reference\") {\n\t\treturn;\n\t}\n\n\tif (isDollarVariableReference(unitOption.value.value)) {\n\t\treturn;\n\t}\n\n\tif (!relativeTimeUnits.has(unitOption.value.value)) {\n\t\tthrow new Error(\n\t\t\t`Invalid \"relativetime\" unit \"${unitOption.value.value}\". Expected one of: ${Array.from(\n\t\t\t\trelativeTimeUnits\n\t\t\t).join(\", \")}.`\n\t\t);\n\t}\n}\n\nfunction isDollarVariableReference(value: string): boolean {\n\treturn value.startsWith(\"$\") && value.length > 1;\n}\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { LocalVariable } from "../messages/ast.js";
|
|
1
|
+
import type { Declaration, LocalVariable } from "../messages/ast.js";
|
|
2
2
|
/**
|
|
3
3
|
* Compiles a local variable.
|
|
4
4
|
*
|
|
@@ -13,4 +13,5 @@ import type { LocalVariable } from "../messages/ast.js";
|
|
|
13
13
|
export declare function compileLocalVariable(args: {
|
|
14
14
|
locale: string;
|
|
15
15
|
declaration: LocalVariable;
|
|
16
|
+
declarations?: Declaration[];
|
|
16
17
|
}): string;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { compileVariableAccess } from "./variable-access.js";
|
|
2
2
|
import { escapeForDoubleQuoteString } from "../services/codegen/escape.js";
|
|
3
3
|
import { compileAnnotation } from "./compile-annotation.js";
|
|
4
4
|
/**
|
|
@@ -14,15 +14,15 @@ import { compileAnnotation } from "./compile-annotation.js";
|
|
|
14
14
|
*/
|
|
15
15
|
export function compileLocalVariable(args) {
|
|
16
16
|
const annotation = args.declaration.value.annotation;
|
|
17
|
-
const value = compileAnnotation(compileLiteralOrVarRef(args.declaration.value.arg), args.locale, annotation);
|
|
17
|
+
const value = compileAnnotation(compileLiteralOrVarRef(args.declaration.value.arg, args.declarations), args.locale, annotation, args.declarations);
|
|
18
18
|
return `const ${args.declaration.name} = ${value};`;
|
|
19
19
|
}
|
|
20
|
-
function compileLiteralOrVarRef(value) {
|
|
20
|
+
function compileLiteralOrVarRef(value, declarations) {
|
|
21
21
|
switch (value.type) {
|
|
22
22
|
case "literal":
|
|
23
23
|
return `"${escapeForDoubleQuoteString(value.value)}"`;
|
|
24
24
|
case "variable-reference":
|
|
25
|
-
return
|
|
25
|
+
return compileVariableAccess(value.name, declarations);
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
28
|
//# sourceMappingURL=compile-local-variable.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compile-local-variable.js","sourceRoot":"","sources":["../../src/compiler/compile-local-variable.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"compile-local-variable.js","sourceRoot":"","sources":["../../src/compiler/compile-local-variable.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAC7D,OAAO,EAAE,0BAA0B,EAAE,MAAM,+BAA+B,CAAC;AAC3E,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAE5D;;;;;;;;;;GAUG;AACH,MAAM,UAAU,oBAAoB,CAAC,IAIpC;IACA,MAAM,UAAU,GAAG,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,UAAU,CAAC;IAErD,MAAM,KAAK,GAAG,iBAAiB,CAC9B,sBAAsB,CAAC,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,GAAG,EAAE,IAAI,CAAC,YAAY,CAAC,EACrE,IAAI,CAAC,MAAM,EACX,UAAU,EACV,IAAI,CAAC,YAAY,CACjB,CAAC;IAEF,OAAO,SAAS,IAAI,CAAC,WAAW,CAAC,IAAI,MAAM,KAAK,GAAG,CAAC;AACrD,CAAC;AAED,SAAS,sBAAsB,CAC9B,KAAkC,EAClC,YAA4B;IAE5B,QAAQ,KAAK,CAAC,IAAI,EAAE,CAAC;QACpB,KAAK,SAAS;YACb,OAAO,IAAI,0BAA0B,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC;QACvD,KAAK,oBAAoB;YACxB,OAAO,qBAAqB,CAAC,KAAK,CAAC,IAAI,EAAE,YAAY,CAAC,CAAC;IACzD,CAAC;AACF,CAAC","sourcesContent":["import type {\n\tDeclaration,\n\tLiteral,\n\tLocalVariable,\n\tVariableReference,\n} from \"../messages/ast.js\";\nimport { compileVariableAccess } from \"./variable-access.js\";\nimport { escapeForDoubleQuoteString } from \"../services/codegen/escape.js\";\nimport { compileAnnotation } from \"./compile-annotation.js\";\n\n/**\n * Compiles a local variable.\n *\n * @example\n * const code = compileLocalVariable({\n * type: \"local-variable\",\n * name: \"myVar\",\n * value: { type: \"literal\", value: \"Hello\" }\n * });\n * >> code === \"const myVar = 'Hello';\"\n */\nexport function compileLocalVariable(args: {\n\tlocale: string;\n\tdeclaration: LocalVariable;\n\tdeclarations?: Declaration[];\n}): string {\n\tconst annotation = args.declaration.value.annotation;\n\n\tconst value = compileAnnotation(\n\t\tcompileLiteralOrVarRef(args.declaration.value.arg, args.declarations),\n\t\targs.locale,\n\t\tannotation,\n\t\targs.declarations\n\t);\n\n\treturn `const ${args.declaration.name} = ${value};`;\n}\n\nfunction compileLiteralOrVarRef(\n\tvalue: Literal | VariableReference,\n\tdeclarations?: Declaration[]\n): string {\n\tswitch (value.type) {\n\t\tcase \"literal\":\n\t\t\treturn `\"${escapeForDoubleQuoteString(value.value)}\"`;\n\t\tcase \"variable-reference\":\n\t\t\treturn compileVariableAccess(value.name, declarations);\n\t}\n}\n"]}
|
|
@@ -25,6 +25,27 @@ test("compiles a variable reference local variable", () => {
|
|
|
25
25
|
});
|
|
26
26
|
expect(code).toEqual("const myVar = i?.name;");
|
|
27
27
|
});
|
|
28
|
+
test("compiles a variable reference to an earlier local variable", () => {
|
|
29
|
+
const code = compileLocalVariable({
|
|
30
|
+
locale: "en",
|
|
31
|
+
declarations: [
|
|
32
|
+
{
|
|
33
|
+
type: "local-variable",
|
|
34
|
+
name: "earlierLocal",
|
|
35
|
+
value: { type: "expression", arg: { type: "literal", value: "42" } },
|
|
36
|
+
},
|
|
37
|
+
],
|
|
38
|
+
declaration: {
|
|
39
|
+
type: "local-variable",
|
|
40
|
+
name: "myVar",
|
|
41
|
+
value: {
|
|
42
|
+
type: "expression",
|
|
43
|
+
arg: { type: "variable-reference", name: "earlierLocal" },
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
});
|
|
47
|
+
expect(code).toEqual("const myVar = earlierLocal;");
|
|
48
|
+
});
|
|
28
49
|
test("compiles a variable reference local variable with a non-identifier name", () => {
|
|
29
50
|
const code = compileLocalVariable({
|
|
30
51
|
locale: "en",
|
|
@@ -83,6 +104,38 @@ test("compiles a local variable with an annotation and options", () => {
|
|
|
83
104
|
});
|
|
84
105
|
expect(code).toEqual('const myVar = registry.myFunction("en", "Hello", { option1: "value1", option2: i?.varRef });');
|
|
85
106
|
});
|
|
107
|
+
test("compiles formatter options referencing earlier local variables", () => {
|
|
108
|
+
const code = compileLocalVariable({
|
|
109
|
+
locale: "en",
|
|
110
|
+
declarations: [
|
|
111
|
+
{ type: "input-variable", name: "amount" },
|
|
112
|
+
{
|
|
113
|
+
type: "local-variable",
|
|
114
|
+
name: "digits",
|
|
115
|
+
value: { type: "expression", arg: { type: "literal", value: "2" } },
|
|
116
|
+
},
|
|
117
|
+
],
|
|
118
|
+
declaration: {
|
|
119
|
+
type: "local-variable",
|
|
120
|
+
name: "formattedAmount",
|
|
121
|
+
value: {
|
|
122
|
+
type: "expression",
|
|
123
|
+
arg: { type: "variable-reference", name: "amount" },
|
|
124
|
+
annotation: {
|
|
125
|
+
type: "function-reference",
|
|
126
|
+
name: "number",
|
|
127
|
+
options: [
|
|
128
|
+
{
|
|
129
|
+
name: "minimumFractionDigits",
|
|
130
|
+
value: { type: "variable-reference", name: "digits" },
|
|
131
|
+
},
|
|
132
|
+
],
|
|
133
|
+
},
|
|
134
|
+
},
|
|
135
|
+
},
|
|
136
|
+
});
|
|
137
|
+
expect(code).toEqual('const formattedAmount = registry.number("en", i?.amount, { minimumFractionDigits: digits });');
|
|
138
|
+
});
|
|
86
139
|
test("compiles number formatter fraction digit options as numeric literals", () => {
|
|
87
140
|
const code = compileLocalVariable({
|
|
88
141
|
locale: "en",
|
|
@@ -332,6 +385,35 @@ test("accepts dollar-prefixed relative time formatter unit options from message
|
|
|
332
385
|
});
|
|
333
386
|
expect(code).toEqual('const formattedDuration = registry.relativetime("en", i?.duration, { unit: /** @type {import("../registry.js").RelativeTimeFormatUnit} */ (i?.unit) });');
|
|
334
387
|
});
|
|
388
|
+
test("compiles dollar-prefixed relative time units referencing local variables", () => {
|
|
389
|
+
const code = compileLocalVariable({
|
|
390
|
+
locale: "en",
|
|
391
|
+
declarations: [
|
|
392
|
+
{ type: "input-variable", name: "duration" },
|
|
393
|
+
{
|
|
394
|
+
type: "local-variable",
|
|
395
|
+
name: "localUnit",
|
|
396
|
+
value: { type: "expression", arg: { type: "literal", value: "day" } },
|
|
397
|
+
},
|
|
398
|
+
],
|
|
399
|
+
declaration: {
|
|
400
|
+
type: "local-variable",
|
|
401
|
+
name: "formattedDuration",
|
|
402
|
+
value: {
|
|
403
|
+
type: "expression",
|
|
404
|
+
arg: { type: "variable-reference", name: "duration" },
|
|
405
|
+
annotation: {
|
|
406
|
+
type: "function-reference",
|
|
407
|
+
name: "relativetime",
|
|
408
|
+
options: [
|
|
409
|
+
{ name: "unit", value: { type: "literal", value: "$localUnit" } },
|
|
410
|
+
],
|
|
411
|
+
},
|
|
412
|
+
},
|
|
413
|
+
},
|
|
414
|
+
});
|
|
415
|
+
expect(code).toEqual('const formattedDuration = registry.relativetime("en", i?.duration, { unit: /** @type {import("../registry.js").RelativeTimeFormatUnit} */ (localUnit) });');
|
|
416
|
+
});
|
|
335
417
|
test("accepts dollar-prefixed relative time formatter unit options with non-identifier input names", () => {
|
|
336
418
|
const code = compileLocalVariable({
|
|
337
419
|
locale: "en",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compile-local-variable.test.js","sourceRoot":"","sources":["../../src/compiler/compile-local-variable.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AAEnE,IAAI,CAAC,mCAAmC,EAAE,GAAG,EAAE;IAC9C,MAAM,IAAI,GAAG,oBAAoB,CAAC;QACjC,MAAM,EAAE,IAAI;QACZ,WAAW,EAAE;YACZ,IAAI,EAAE,gBAAgB;YACtB,IAAI,EAAE,OAAO;YACb,KAAK,EAAE,EAAE,IAAI,EAAE,YAAY,EAAE,GAAG,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE;SACvE;KACD,CAAC,CAAC;IACH,MAAM,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,wBAAwB,CAAC,CAAC;AAChD,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,8CAA8C,EAAE,GAAG,EAAE;IACzD,MAAM,IAAI,GAAG,oBAAoB,CAAC;QACjC,MAAM,EAAE,IAAI;QACZ,WAAW,EAAE;YACZ,IAAI,EAAE,gBAAgB;YACtB,IAAI,EAAE,OAAO;YACb,KAAK,EAAE;gBACN,IAAI,EAAE,YAAY;gBAClB,GAAG,EAAE,EAAE,IAAI,EAAE,oBAAoB,EAA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YACZ,IAAI,EAAE,gBAAgB;YACtB,IAAI,EAAE,mBAAmB;YACzB,KAAK,EAAE;gBACN,IAAI,EAAE,YAAY;gBAClB,GAAG,EAAE,EAAE,IAAI,EAAE,oBAAoB,EAAE,IAAI,EAAE,UAAU,EAAE;gBACrD,UAAU,EAAE;oBACX,IAAI,EAAE,oBAAoB;oBAC1B,IAAI,EAAE,cAAc;oBACpB,OAAO,EAAE;wBACR,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE;qBAC5D;iBACD;aACD;SACD;KACD,CAAC,CAAC;IAEH,MAAM,CAAC,IAAI,CAAC,CAAC,OAAO,CACnB,yJAAyJ,CACzJ,CAAC;AACH,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,8FAA8F,EAAE,GAAG,EAAE;IACzG,MAAM,IAAI,GAAG,oBAAoB,CAAC;QACjC,MAAM,EAAE,IAAI;QACZ,WAAW,EAAE;YACZ,IAAI,EAAE,gBAAgB;YACtB,IAAI,EAAE,mBAAmB;YACzB,KAAK,EAAE;gBACN,IAAI,EAAE,YAAY;gBAClB,GAAG,EAAE,EAAE,IAAI,EAAE,oBAAoB,EAAE,IAAI,EAAE,UAAU,EAAE;gBACrD,UAAU,EAAE;oBACX,IAAI,EAAE,oBAAoB;oBAC1B,IAAI,EAAE,cAAc;oBACpB,OAAO,EAAE;wBACR;4BACC,IAAI,EAAE,MAAM;4BACZ,KAAK,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,gBAAgB,EAAE;yBACnD;qBACD;iBACD;aACD;SACD;KACD,CAAC,CAAC;IAEH,MAAM,CAAC,IAAI,CAAC,CAAC,OAAO,CACnB,sKAAsK,CACtK,CAAC;AACH,CAAC,CAAC,CAAC","sourcesContent":["import { test, expect } from \"vitest\";\nimport { compileLocalVariable } from \"./compile-local-variable.js\";\n\ntest(\"compiles a literal local variable\", () => {\n\tconst code = compileLocalVariable({\n\t\tlocale: \"en\",\n\t\tdeclaration: {\n\t\t\ttype: \"local-variable\",\n\t\t\tname: \"myVar\",\n\t\t\tvalue: { type: \"expression\", arg: { type: \"literal\", value: \"Hello\" } },\n\t\t},\n\t});\n\texpect(code).toEqual('const myVar = \"Hello\";');\n});\n\ntest(\"compiles a variable reference local variable\", () => {\n\tconst code = compileLocalVariable({\n\t\tlocale: \"en\",\n\t\tdeclaration: {\n\t\t\ttype: \"local-variable\",\n\t\t\tname: \"myVar\",\n\t\t\tvalue: {\n\t\t\t\ttype: \"expression\",\n\t\t\t\targ: { type: \"variable-reference\", name: \"name\" },\n\t\t\t},\n\t\t},\n\t});\n\texpect(code).toEqual(\"const myVar = i?.name;\");\n});\n\ntest(\"compiles a variable reference local variable with a non-identifier name\", () => {\n\tconst code = compileLocalVariable({\n\t\tlocale: \"en\",\n\t\tdeclaration: {\n\t\t\ttype: \"local-variable\",\n\t\t\tname: \"myVar\",\n\t\t\tvalue: {\n\t\t\t\ttype: \"expression\",\n\t\t\t\targ: { type: \"variable-reference\", name: \"half!\" },\n\t\t\t},\n\t\t},\n\t});\n\texpect(code).toEqual('const myVar = i?.[\"half!\"];');\n});\n\ntest(\"compiles a local variable with an annotation and empty options\", () => {\n\tconst code = compileLocalVariable({\n\t\tlocale: \"en\",\n\t\tdeclaration: {\n\t\t\ttype: \"local-variable\",\n\t\t\tname: \"myVar\",\n\t\t\tvalue: {\n\t\t\t\ttype: \"expression\",\n\t\t\t\targ: { type: \"literal\", value: \"Hello\" },\n\t\t\t\tannotation: {\n\t\t\t\t\ttype: \"function-reference\",\n\t\t\t\t\tname: \"myFunction\",\n\t\t\t\t\toptions: [],\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t});\n\texpect(code).toEqual('const myVar = registry.myFunction(\"en\", \"Hello\", {});');\n});\n\ntest(\"compiles a local variable with an annotation and options\", () => {\n\tconst code = compileLocalVariable({\n\t\tlocale: \"en\",\n\t\tdeclaration: {\n\t\t\ttype: \"local-variable\",\n\t\t\tname: \"myVar\",\n\t\t\tvalue: {\n\t\t\t\ttype: \"expression\",\n\t\t\t\targ: { type: \"literal\", value: \"Hello\" },\n\t\t\t\tannotation: {\n\t\t\t\t\ttype: \"function-reference\",\n\t\t\t\t\tname: \"myFunction\",\n\t\t\t\t\toptions: [\n\t\t\t\t\t\t{ name: \"option1\", value: { type: \"literal\", value: \"value1\" } },\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tname: \"option2\",\n\t\t\t\t\t\t\tvalue: { type: \"variable-reference\", name: \"varRef\" },\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t});\n\texpect(code).toEqual(\n\t\t'const myVar = registry.myFunction(\"en\", \"Hello\", { option1: \"value1\", option2: i?.varRef });'\n\t);\n});\n\ntest(\"compiles number formatter fraction digit options as numeric literals\", () => {\n\tconst code = compileLocalVariable({\n\t\tlocale: \"en\",\n\t\tdeclaration: {\n\t\t\ttype: \"local-variable\",\n\t\t\tname: \"formattedValue\",\n\t\t\tvalue: {\n\t\t\t\ttype: \"expression\",\n\t\t\t\targ: { type: \"variable-reference\", name: \"value\" },\n\t\t\t\tannotation: {\n\t\t\t\t\ttype: \"function-reference\",\n\t\t\t\t\tname: \"number\",\n\t\t\t\t\toptions: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tname: \"minimumFractionDigits\",\n\t\t\t\t\t\t\tvalue: { type: \"literal\", value: \"1\" },\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tname: \"maximumFractionDigits\",\n\t\t\t\t\t\t\tvalue: { type: \"literal\", value: \"1\" },\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t});\n\n\texpect(code).toEqual(\n\t\t'const formattedValue = registry.number(\"en\", i?.value, { minimumFractionDigits: 1, maximumFractionDigits: 1 });'\n\t);\n});\n\ntest(\"compiles number formatter useGrouping option as boolean literal\", () => {\n\tconst code = compileLocalVariable({\n\t\tlocale: \"en\",\n\t\tdeclaration: {\n\t\t\ttype: \"local-variable\",\n\t\t\tname: \"formattedValue\",\n\t\t\tvalue: {\n\t\t\t\ttype: \"expression\",\n\t\t\t\targ: { type: \"variable-reference\", name: \"value\" },\n\t\t\t\tannotation: {\n\t\t\t\t\ttype: \"function-reference\",\n\t\t\t\t\tname: \"number\",\n\t\t\t\t\toptions: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tname: \"useGrouping\",\n\t\t\t\t\t\t\tvalue: { type: \"literal\", value: \"false\" },\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t});\n\n\texpect(code).toEqual(\n\t\t'const formattedValue = registry.number(\"en\", i?.value, { useGrouping: false });'\n\t);\n});\n\ntest(\"keeps negative digit options as strings to avoid emitting invalid numeric literals\", () => {\n\tconst code = compileLocalVariable({\n\t\tlocale: \"en\",\n\t\tdeclaration: {\n\t\t\ttype: \"local-variable\",\n\t\t\tname: \"formattedValue\",\n\t\t\tvalue: {\n\t\t\t\ttype: \"expression\",\n\t\t\t\targ: { type: \"variable-reference\", name: \"value\" },\n\t\t\t\tannotation: {\n\t\t\t\t\ttype: \"function-reference\",\n\t\t\t\t\tname: \"number\",\n\t\t\t\t\toptions: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tname: \"minimumFractionDigits\",\n\t\t\t\t\t\t\tvalue: { type: \"literal\", value: \"-1\" },\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t});\n\n\texpect(code).toEqual(\n\t\t'const formattedValue = registry.number(\"en\", i?.value, { minimumFractionDigits: \"-1\" });'\n\t);\n});\n\ntest(\"compiles relative time formatter with a literal unit\", () => {\n\tconst code = compileLocalVariable({\n\t\tlocale: \"en\",\n\t\tdeclaration: {\n\t\t\ttype: \"local-variable\",\n\t\t\tname: \"formattedDuration\",\n\t\t\tvalue: {\n\t\t\t\ttype: \"expression\",\n\t\t\t\targ: { type: \"variable-reference\", name: \"duration\" },\n\t\t\t\tannotation: {\n\t\t\t\t\ttype: \"function-reference\",\n\t\t\t\t\tname: \"relativetime\",\n\t\t\t\t\toptions: [\n\t\t\t\t\t\t{ name: \"unit\", value: { type: \"literal\", value: \"day\" } },\n\t\t\t\t\t\t{ name: \"numeric\", value: { type: \"literal\", value: \"auto\" } },\n\t\t\t\t\t\t{ name: \"style\", value: { type: \"literal\", value: \"short\" } },\n\t\t\t\t\t],\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t});\n\n\texpect(code).toEqual(\n\t\t'const formattedDuration = registry.relativetime(\"en\", i?.duration, { unit: \"day\", numeric: \"auto\", style: \"short\" });'\n\t);\n});\n\ntest(\"compiles relative time formatter with a dynamic unit cast\", () => {\n\tconst code = compileLocalVariable({\n\t\tlocale: \"en\",\n\t\tdeclaration: {\n\t\t\ttype: \"local-variable\",\n\t\t\tname: \"formattedDuration\",\n\t\t\tvalue: {\n\t\t\t\ttype: \"expression\",\n\t\t\t\targ: { type: \"variable-reference\", name: \"duration\" },\n\t\t\t\tannotation: {\n\t\t\t\t\ttype: \"function-reference\",\n\t\t\t\t\tname: \"relativetime\",\n\t\t\t\t\toptions: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tname: \"unit\",\n\t\t\t\t\t\t\tvalue: { type: \"variable-reference\", name: \"unit\" },\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{ name: \"style\", value: { type: \"literal\", value: \"short\" } },\n\t\t\t\t\t],\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t});\n\n\texpect(code).toEqual(\n\t\t'const formattedDuration = registry.relativetime(\"en\", i?.duration, { unit: /** @type {import(\"../registry.js\").RelativeTimeFormatUnit} */ (i?.unit), style: \"short\" });'\n\t);\n});\n\ntest(\"throws if relative time formatter is missing a unit option\", () => {\n\texpect(() =>\n\t\tcompileLocalVariable({\n\t\t\tlocale: \"en\",\n\t\t\tdeclaration: {\n\t\t\t\ttype: \"local-variable\",\n\t\t\t\tname: \"formattedDuration\",\n\t\t\t\tvalue: {\n\t\t\t\t\ttype: \"expression\",\n\t\t\t\t\targ: { type: \"variable-reference\", name: \"duration\" },\n\t\t\t\t\tannotation: {\n\t\t\t\t\t\ttype: \"function-reference\",\n\t\t\t\t\t\tname: \"relativetime\",\n\t\t\t\t\t\toptions: [],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t})\n\t).toThrow('The \"relativetime\" formatter requires a \"unit\" option.');\n});\n\ntest(\"throws if relative time formatter has duplicate unit options\", () => {\n\texpect(() =>\n\t\tcompileLocalVariable({\n\t\t\tlocale: \"en\",\n\t\t\tdeclaration: {\n\t\t\t\ttype: \"local-variable\",\n\t\t\t\tname: \"formattedDuration\",\n\t\t\t\tvalue: {\n\t\t\t\t\ttype: \"expression\",\n\t\t\t\t\targ: { type: \"variable-reference\", name: \"duration\" },\n\t\t\t\t\tannotation: {\n\t\t\t\t\t\ttype: \"function-reference\",\n\t\t\t\t\t\tname: \"relativetime\",\n\t\t\t\t\t\toptions: [\n\t\t\t\t\t\t\t{ name: \"unit\", value: { type: \"literal\", value: \"day\" } },\n\t\t\t\t\t\t\t{ name: \"unit\", value: { type: \"literal\", value: \"hour\" } },\n\t\t\t\t\t\t],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t})\n\t).toThrow('The \"relativetime\" formatter requires exactly one \"unit\" option.');\n});\n\ntest(\"throws if relative time formatter has an invalid literal unit\", () => {\n\texpect(() =>\n\t\tcompileLocalVariable({\n\t\t\tlocale: \"en\",\n\t\t\tdeclaration: {\n\t\t\t\ttype: \"local-variable\",\n\t\t\t\tname: \"formattedDuration\",\n\t\t\t\tvalue: {\n\t\t\t\t\ttype: \"expression\",\n\t\t\t\t\targ: { type: \"variable-reference\", name: \"duration\" },\n\t\t\t\t\tannotation: {\n\t\t\t\t\t\ttype: \"function-reference\",\n\t\t\t\t\t\tname: \"relativetime\",\n\t\t\t\t\t\toptions: [\n\t\t\t\t\t\t\t{ name: \"unit\", value: { type: \"literal\", value: \"century\" } },\n\t\t\t\t\t\t],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t})\n\t).toThrow('Invalid \"relativetime\" unit \"century\".');\n});\n\ntest(\"accepts plural relative time formatter units\", () => {\n\tconst code = compileLocalVariable({\n\t\tlocale: \"en\",\n\t\tdeclaration: {\n\t\t\ttype: \"local-variable\",\n\t\t\tname: \"formattedDuration\",\n\t\t\tvalue: {\n\t\t\t\ttype: \"expression\",\n\t\t\t\targ: { type: \"variable-reference\", name: \"duration\" },\n\t\t\t\tannotation: {\n\t\t\t\t\ttype: \"function-reference\",\n\t\t\t\t\tname: \"relativetime\",\n\t\t\t\t\toptions: [\n\t\t\t\t\t\t{ name: \"unit\", value: { type: \"literal\", value: \"days\" } },\n\t\t\t\t\t],\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t});\n\n\texpect(code).toEqual(\n\t\t'const formattedDuration = registry.relativetime(\"en\", i?.duration, { unit: \"days\" });'\n\t);\n});\n\ntest(\"accepts dynamic relative time formatter units\", () => {\n\tconst code = compileLocalVariable({\n\t\tlocale: \"en\",\n\t\tdeclaration: {\n\t\t\ttype: \"local-variable\",\n\t\t\tname: \"formattedDuration\",\n\t\t\tvalue: {\n\t\t\t\ttype: \"expression\",\n\t\t\t\targ: { type: \"variable-reference\", name: \"duration\" },\n\t\t\t\tannotation: {\n\t\t\t\t\ttype: \"function-reference\",\n\t\t\t\t\tname: \"relativetime\",\n\t\t\t\t\toptions: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tname: \"unit\",\n\t\t\t\t\t\t\tvalue: { type: \"variable-reference\", name: \"unit\" },\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t});\n\n\texpect(code).toEqual(\n\t\t'const formattedDuration = registry.relativetime(\"en\", i?.duration, { unit: /** @type {import(\"../registry.js\").RelativeTimeFormatUnit} */ (i?.unit) });'\n\t);\n});\n\ntest(\"accepts dollar-prefixed relative time formatter unit options from message files\", () => {\n\tconst code = compileLocalVariable({\n\t\tlocale: \"en\",\n\t\tdeclaration: {\n\t\t\ttype: \"local-variable\",\n\t\t\tname: \"formattedDuration\",\n\t\t\tvalue: {\n\t\t\t\ttype: \"expression\",\n\t\t\t\targ: { type: \"variable-reference\", name: \"duration\" },\n\t\t\t\tannotation: {\n\t\t\t\t\ttype: \"function-reference\",\n\t\t\t\t\tname: \"relativetime\",\n\t\t\t\t\toptions: [\n\t\t\t\t\t\t{ name: \"unit\", value: { type: \"literal\", value: \"$unit\" } },\n\t\t\t\t\t],\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t});\n\n\texpect(code).toEqual(\n\t\t'const formattedDuration = registry.relativetime(\"en\", i?.duration, { unit: /** @type {import(\"../registry.js\").RelativeTimeFormatUnit} */ (i?.unit) });'\n\t);\n});\n\ntest(\"accepts dollar-prefixed relative time formatter unit options with non-identifier input names\", () => {\n\tconst code = compileLocalVariable({\n\t\tlocale: \"en\",\n\t\tdeclaration: {\n\t\t\ttype: \"local-variable\",\n\t\t\tname: \"formattedDuration\",\n\t\t\tvalue: {\n\t\t\t\ttype: \"expression\",\n\t\t\t\targ: { type: \"variable-reference\", name: \"duration\" },\n\t\t\t\tannotation: {\n\t\t\t\t\ttype: \"function-reference\",\n\t\t\t\t\tname: \"relativetime\",\n\t\t\t\t\toptions: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tname: \"unit\",\n\t\t\t\t\t\t\tvalue: { type: \"literal\", value: \"$relative-unit\" },\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t});\n\n\texpect(code).toEqual(\n\t\t'const formattedDuration = registry.relativetime(\"en\", i?.duration, { unit: /** @type {import(\"../registry.js\").RelativeTimeFormatUnit} */ (i?.[\"relative-unit\"]) });'\n\t);\n});\n"]}
|
|
1
|
+
{"version":3,"file":"compile-local-variable.test.js","sourceRoot":"","sources":["../../src/compiler/compile-local-variable.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AAEnE,IAAI,CAAC,mCAAmC,EAAE,GAAG,EAAE;IAC9C,MAAM,IAAI,GAAG,oBAAoB,CAAC;QACjC,MAAM,EAAE,IAAI;QACZ,WAAW,EAAE;YACZ,IAAI,EAAE,gBAAgB;YACtB,IAAI,EAAE,OAAO;YACb,KAAK,EAAE,EAAE,IAAI,EAAE,YAAY,EAAE,GAAG,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE;SACvE;KACD,CAAC,CAAC;IACH,MAAM,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,wBAAwB,CAAC,CAAC;AAChD,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,8CAA8C,EAAE,GAAG,EAAE;IACzD,MAAM,IAAI,GAAG,oBAAoB,CAAC;QACjC,MAAM,EAAE,IAAI;QACZ,WAAW,EAAE;YACZ,IAAI,EAAE,gBAAgB;YACtB,IAAI,EAAE,OAAO;YACb,KAAK,EAAE;gBACN,IAAI,EAAE,YAAY;gBAClB,GAAG,EAAE,EAAE,IAAI,EAAE,oBAAoB,EAAE,IAAI,EAAE,MAAM,EAAE;aACjD;SACD;KACD,CAAC,CAAC;IACH,MAAM,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,wBAAwB,CAAC,CAAC;AAChD,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,4DAA4D,EAAE,GAAG,EAAE;IACvE,MAAM,IAAI,GAAG,oBAAoB,CAAC;QACjC,MAAM,EAAE,IAAI;QACZ,YAAY,EAAE;YACb;gBACC,IAAI,EAAE,gBAAgB;gBACtB,IAAI,EAAE,cAAc;gBACpB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;qBACjE;iBACD;aACD;SACD;KACD,CAAC,CAAC;IAEH,MAAM,CAAC,IAAI,CAAC,CAAC,OAAO,CACnB,2JAA2J,CAC3J,CAAC;AACH,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,8FAA8F,EAAE,GAAG,EAAE;IACzG,MAAM,IAAI,GAAG,oBAAoB,CAAC;QACjC,MAAM,EAAE,IAAI;QACZ,WAAW,EAAE;YACZ,IAAI,EAAE,gBAAgB;YACtB,IAAI,EAAE,mBAAmB;YACzB,KAAK,EAAE;gBACN,IAAI,EAAE,YAAY;gBAClB,GAAG,EAAE,EAAE,IAAI,EAAE,oBAAoB,EAAE,IAAI,EAAE,UAAU,EAAE;gBACrD,UAAU,EAAE;oBACX,IAAI,EAAE,oBAAoB;oBAC1B,IAAI,EAAE,cAAc;oBACpB,OAAO,EAAE;wBACR;4BACC,IAAI,EAAE,MAAM;4BACZ,KAAK,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,gBAAgB,EAAE;yBACnD;qBACD;iBACD;aACD;SACD;KACD,CAAC,CAAC;IAEH,MAAM,CAAC,IAAI,CAAC,CAAC,OAAO,CACnB,sKAAsK,CACtK,CAAC;AACH,CAAC,CAAC,CAAC","sourcesContent":["import { test, expect } from \"vitest\";\nimport { compileLocalVariable } from \"./compile-local-variable.js\";\n\ntest(\"compiles a literal local variable\", () => {\n\tconst code = compileLocalVariable({\n\t\tlocale: \"en\",\n\t\tdeclaration: {\n\t\t\ttype: \"local-variable\",\n\t\t\tname: \"myVar\",\n\t\t\tvalue: { type: \"expression\", arg: { type: \"literal\", value: \"Hello\" } },\n\t\t},\n\t});\n\texpect(code).toEqual('const myVar = \"Hello\";');\n});\n\ntest(\"compiles a variable reference local variable\", () => {\n\tconst code = compileLocalVariable({\n\t\tlocale: \"en\",\n\t\tdeclaration: {\n\t\t\ttype: \"local-variable\",\n\t\t\tname: \"myVar\",\n\t\t\tvalue: {\n\t\t\t\ttype: \"expression\",\n\t\t\t\targ: { type: \"variable-reference\", name: \"name\" },\n\t\t\t},\n\t\t},\n\t});\n\texpect(code).toEqual(\"const myVar = i?.name;\");\n});\n\ntest(\"compiles a variable reference to an earlier local variable\", () => {\n\tconst code = compileLocalVariable({\n\t\tlocale: \"en\",\n\t\tdeclarations: [\n\t\t\t{\n\t\t\t\ttype: \"local-variable\",\n\t\t\t\tname: \"earlierLocal\",\n\t\t\t\tvalue: { type: \"expression\", arg: { type: \"literal\", value: \"42\" } },\n\t\t\t},\n\t\t],\n\t\tdeclaration: {\n\t\t\ttype: \"local-variable\",\n\t\t\tname: \"myVar\",\n\t\t\tvalue: {\n\t\t\t\ttype: \"expression\",\n\t\t\t\targ: { type: \"variable-reference\", name: \"earlierLocal\" },\n\t\t\t},\n\t\t},\n\t});\n\n\texpect(code).toEqual(\"const myVar = earlierLocal;\");\n});\n\ntest(\"compiles a variable reference local variable with a non-identifier name\", () => {\n\tconst code = compileLocalVariable({\n\t\tlocale: \"en\",\n\t\tdeclaration: {\n\t\t\ttype: \"local-variable\",\n\t\t\tname: \"myVar\",\n\t\t\tvalue: {\n\t\t\t\ttype: \"expression\",\n\t\t\t\targ: { type: \"variable-reference\", name: \"half!\" },\n\t\t\t},\n\t\t},\n\t});\n\texpect(code).toEqual('const myVar = i?.[\"half!\"];');\n});\n\ntest(\"compiles a local variable with an annotation and empty options\", () => {\n\tconst code = compileLocalVariable({\n\t\tlocale: \"en\",\n\t\tdeclaration: {\n\t\t\ttype: \"local-variable\",\n\t\t\tname: \"myVar\",\n\t\t\tvalue: {\n\t\t\t\ttype: \"expression\",\n\t\t\t\targ: { type: \"literal\", value: \"Hello\" },\n\t\t\t\tannotation: {\n\t\t\t\t\ttype: \"function-reference\",\n\t\t\t\t\tname: \"myFunction\",\n\t\t\t\t\toptions: [],\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t});\n\texpect(code).toEqual('const myVar = registry.myFunction(\"en\", \"Hello\", {});');\n});\n\ntest(\"compiles a local variable with an annotation and options\", () => {\n\tconst code = compileLocalVariable({\n\t\tlocale: \"en\",\n\t\tdeclaration: {\n\t\t\ttype: \"local-variable\",\n\t\t\tname: \"myVar\",\n\t\t\tvalue: {\n\t\t\t\ttype: \"expression\",\n\t\t\t\targ: { type: \"literal\", value: \"Hello\" },\n\t\t\t\tannotation: {\n\t\t\t\t\ttype: \"function-reference\",\n\t\t\t\t\tname: \"myFunction\",\n\t\t\t\t\toptions: [\n\t\t\t\t\t\t{ name: \"option1\", value: { type: \"literal\", value: \"value1\" } },\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tname: \"option2\",\n\t\t\t\t\t\t\tvalue: { type: \"variable-reference\", name: \"varRef\" },\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t});\n\texpect(code).toEqual(\n\t\t'const myVar = registry.myFunction(\"en\", \"Hello\", { option1: \"value1\", option2: i?.varRef });'\n\t);\n});\n\ntest(\"compiles formatter options referencing earlier local variables\", () => {\n\tconst code = compileLocalVariable({\n\t\tlocale: \"en\",\n\t\tdeclarations: [\n\t\t\t{ type: \"input-variable\", name: \"amount\" },\n\t\t\t{\n\t\t\t\ttype: \"local-variable\",\n\t\t\t\tname: \"digits\",\n\t\t\t\tvalue: { type: \"expression\", arg: { type: \"literal\", value: \"2\" } },\n\t\t\t},\n\t\t],\n\t\tdeclaration: {\n\t\t\ttype: \"local-variable\",\n\t\t\tname: \"formattedAmount\",\n\t\t\tvalue: {\n\t\t\t\ttype: \"expression\",\n\t\t\t\targ: { type: \"variable-reference\", name: \"amount\" },\n\t\t\t\tannotation: {\n\t\t\t\t\ttype: \"function-reference\",\n\t\t\t\t\tname: \"number\",\n\t\t\t\t\toptions: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tname: \"minimumFractionDigits\",\n\t\t\t\t\t\t\tvalue: { type: \"variable-reference\", name: \"digits\" },\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t});\n\n\texpect(code).toEqual(\n\t\t'const formattedAmount = registry.number(\"en\", i?.amount, { minimumFractionDigits: digits });'\n\t);\n});\n\ntest(\"compiles number formatter fraction digit options as numeric literals\", () => {\n\tconst code = compileLocalVariable({\n\t\tlocale: \"en\",\n\t\tdeclaration: {\n\t\t\ttype: \"local-variable\",\n\t\t\tname: \"formattedValue\",\n\t\t\tvalue: {\n\t\t\t\ttype: \"expression\",\n\t\t\t\targ: { type: \"variable-reference\", name: \"value\" },\n\t\t\t\tannotation: {\n\t\t\t\t\ttype: \"function-reference\",\n\t\t\t\t\tname: \"number\",\n\t\t\t\t\toptions: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tname: \"minimumFractionDigits\",\n\t\t\t\t\t\t\tvalue: { type: \"literal\", value: \"1\" },\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tname: \"maximumFractionDigits\",\n\t\t\t\t\t\t\tvalue: { type: \"literal\", value: \"1\" },\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t});\n\n\texpect(code).toEqual(\n\t\t'const formattedValue = registry.number(\"en\", i?.value, { minimumFractionDigits: 1, maximumFractionDigits: 1 });'\n\t);\n});\n\ntest(\"compiles number formatter useGrouping option as boolean literal\", () => {\n\tconst code = compileLocalVariable({\n\t\tlocale: \"en\",\n\t\tdeclaration: {\n\t\t\ttype: \"local-variable\",\n\t\t\tname: \"formattedValue\",\n\t\t\tvalue: {\n\t\t\t\ttype: \"expression\",\n\t\t\t\targ: { type: \"variable-reference\", name: \"value\" },\n\t\t\t\tannotation: {\n\t\t\t\t\ttype: \"function-reference\",\n\t\t\t\t\tname: \"number\",\n\t\t\t\t\toptions: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tname: \"useGrouping\",\n\t\t\t\t\t\t\tvalue: { type: \"literal\", value: \"false\" },\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t});\n\n\texpect(code).toEqual(\n\t\t'const formattedValue = registry.number(\"en\", i?.value, { useGrouping: false });'\n\t);\n});\n\ntest(\"keeps negative digit options as strings to avoid emitting invalid numeric literals\", () => {\n\tconst code = compileLocalVariable({\n\t\tlocale: \"en\",\n\t\tdeclaration: {\n\t\t\ttype: \"local-variable\",\n\t\t\tname: \"formattedValue\",\n\t\t\tvalue: {\n\t\t\t\ttype: \"expression\",\n\t\t\t\targ: { type: \"variable-reference\", name: \"value\" },\n\t\t\t\tannotation: {\n\t\t\t\t\ttype: \"function-reference\",\n\t\t\t\t\tname: \"number\",\n\t\t\t\t\toptions: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tname: \"minimumFractionDigits\",\n\t\t\t\t\t\t\tvalue: { type: \"literal\", value: \"-1\" },\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t});\n\n\texpect(code).toEqual(\n\t\t'const formattedValue = registry.number(\"en\", i?.value, { minimumFractionDigits: \"-1\" });'\n\t);\n});\n\ntest(\"compiles relative time formatter with a literal unit\", () => {\n\tconst code = compileLocalVariable({\n\t\tlocale: \"en\",\n\t\tdeclaration: {\n\t\t\ttype: \"local-variable\",\n\t\t\tname: \"formattedDuration\",\n\t\t\tvalue: {\n\t\t\t\ttype: \"expression\",\n\t\t\t\targ: { type: \"variable-reference\", name: \"duration\" },\n\t\t\t\tannotation: {\n\t\t\t\t\ttype: \"function-reference\",\n\t\t\t\t\tname: \"relativetime\",\n\t\t\t\t\toptions: [\n\t\t\t\t\t\t{ name: \"unit\", value: { type: \"literal\", value: \"day\" } },\n\t\t\t\t\t\t{ name: \"numeric\", value: { type: \"literal\", value: \"auto\" } },\n\t\t\t\t\t\t{ name: \"style\", value: { type: \"literal\", value: \"short\" } },\n\t\t\t\t\t],\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t});\n\n\texpect(code).toEqual(\n\t\t'const formattedDuration = registry.relativetime(\"en\", i?.duration, { unit: \"day\", numeric: \"auto\", style: \"short\" });'\n\t);\n});\n\ntest(\"compiles relative time formatter with a dynamic unit cast\", () => {\n\tconst code = compileLocalVariable({\n\t\tlocale: \"en\",\n\t\tdeclaration: {\n\t\t\ttype: \"local-variable\",\n\t\t\tname: \"formattedDuration\",\n\t\t\tvalue: {\n\t\t\t\ttype: \"expression\",\n\t\t\t\targ: { type: \"variable-reference\", name: \"duration\" },\n\t\t\t\tannotation: {\n\t\t\t\t\ttype: \"function-reference\",\n\t\t\t\t\tname: \"relativetime\",\n\t\t\t\t\toptions: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tname: \"unit\",\n\t\t\t\t\t\t\tvalue: { type: \"variable-reference\", name: \"unit\" },\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{ name: \"style\", value: { type: \"literal\", value: \"short\" } },\n\t\t\t\t\t],\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t});\n\n\texpect(code).toEqual(\n\t\t'const formattedDuration = registry.relativetime(\"en\", i?.duration, { unit: /** @type {import(\"../registry.js\").RelativeTimeFormatUnit} */ (i?.unit), style: \"short\" });'\n\t);\n});\n\ntest(\"throws if relative time formatter is missing a unit option\", () => {\n\texpect(() =>\n\t\tcompileLocalVariable({\n\t\t\tlocale: \"en\",\n\t\t\tdeclaration: {\n\t\t\t\ttype: \"local-variable\",\n\t\t\t\tname: \"formattedDuration\",\n\t\t\t\tvalue: {\n\t\t\t\t\ttype: \"expression\",\n\t\t\t\t\targ: { type: \"variable-reference\", name: \"duration\" },\n\t\t\t\t\tannotation: {\n\t\t\t\t\t\ttype: \"function-reference\",\n\t\t\t\t\t\tname: \"relativetime\",\n\t\t\t\t\t\toptions: [],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t})\n\t).toThrow('The \"relativetime\" formatter requires a \"unit\" option.');\n});\n\ntest(\"throws if relative time formatter has duplicate unit options\", () => {\n\texpect(() =>\n\t\tcompileLocalVariable({\n\t\t\tlocale: \"en\",\n\t\t\tdeclaration: {\n\t\t\t\ttype: \"local-variable\",\n\t\t\t\tname: \"formattedDuration\",\n\t\t\t\tvalue: {\n\t\t\t\t\ttype: \"expression\",\n\t\t\t\t\targ: { type: \"variable-reference\", name: \"duration\" },\n\t\t\t\t\tannotation: {\n\t\t\t\t\t\ttype: \"function-reference\",\n\t\t\t\t\t\tname: \"relativetime\",\n\t\t\t\t\t\toptions: [\n\t\t\t\t\t\t\t{ name: \"unit\", value: { type: \"literal\", value: \"day\" } },\n\t\t\t\t\t\t\t{ name: \"unit\", value: { type: \"literal\", value: \"hour\" } },\n\t\t\t\t\t\t],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t})\n\t).toThrow('The \"relativetime\" formatter requires exactly one \"unit\" option.');\n});\n\ntest(\"throws if relative time formatter has an invalid literal unit\", () => {\n\texpect(() =>\n\t\tcompileLocalVariable({\n\t\t\tlocale: \"en\",\n\t\t\tdeclaration: {\n\t\t\t\ttype: \"local-variable\",\n\t\t\t\tname: \"formattedDuration\",\n\t\t\t\tvalue: {\n\t\t\t\t\ttype: \"expression\",\n\t\t\t\t\targ: { type: \"variable-reference\", name: \"duration\" },\n\t\t\t\t\tannotation: {\n\t\t\t\t\t\ttype: \"function-reference\",\n\t\t\t\t\t\tname: \"relativetime\",\n\t\t\t\t\t\toptions: [\n\t\t\t\t\t\t\t{ name: \"unit\", value: { type: \"literal\", value: \"century\" } },\n\t\t\t\t\t\t],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t})\n\t).toThrow('Invalid \"relativetime\" unit \"century\".');\n});\n\ntest(\"accepts plural relative time formatter units\", () => {\n\tconst code = compileLocalVariable({\n\t\tlocale: \"en\",\n\t\tdeclaration: {\n\t\t\ttype: \"local-variable\",\n\t\t\tname: \"formattedDuration\",\n\t\t\tvalue: {\n\t\t\t\ttype: \"expression\",\n\t\t\t\targ: { type: \"variable-reference\", name: \"duration\" },\n\t\t\t\tannotation: {\n\t\t\t\t\ttype: \"function-reference\",\n\t\t\t\t\tname: \"relativetime\",\n\t\t\t\t\toptions: [\n\t\t\t\t\t\t{ name: \"unit\", value: { type: \"literal\", value: \"days\" } },\n\t\t\t\t\t],\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t});\n\n\texpect(code).toEqual(\n\t\t'const formattedDuration = registry.relativetime(\"en\", i?.duration, { unit: \"days\" });'\n\t);\n});\n\ntest(\"accepts dynamic relative time formatter units\", () => {\n\tconst code = compileLocalVariable({\n\t\tlocale: \"en\",\n\t\tdeclaration: {\n\t\t\ttype: \"local-variable\",\n\t\t\tname: \"formattedDuration\",\n\t\t\tvalue: {\n\t\t\t\ttype: \"expression\",\n\t\t\t\targ: { type: \"variable-reference\", name: \"duration\" },\n\t\t\t\tannotation: {\n\t\t\t\t\ttype: \"function-reference\",\n\t\t\t\t\tname: \"relativetime\",\n\t\t\t\t\toptions: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tname: \"unit\",\n\t\t\t\t\t\t\tvalue: { type: \"variable-reference\", name: \"unit\" },\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t});\n\n\texpect(code).toEqual(\n\t\t'const formattedDuration = registry.relativetime(\"en\", i?.duration, { unit: /** @type {import(\"../registry.js\").RelativeTimeFormatUnit} */ (i?.unit) });'\n\t);\n});\n\ntest(\"accepts dollar-prefixed relative time formatter unit options from message files\", () => {\n\tconst code = compileLocalVariable({\n\t\tlocale: \"en\",\n\t\tdeclaration: {\n\t\t\ttype: \"local-variable\",\n\t\t\tname: \"formattedDuration\",\n\t\t\tvalue: {\n\t\t\t\ttype: \"expression\",\n\t\t\t\targ: { type: \"variable-reference\", name: \"duration\" },\n\t\t\t\tannotation: {\n\t\t\t\t\ttype: \"function-reference\",\n\t\t\t\t\tname: \"relativetime\",\n\t\t\t\t\toptions: [\n\t\t\t\t\t\t{ name: \"unit\", value: { type: \"literal\", value: \"$unit\" } },\n\t\t\t\t\t],\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t});\n\n\texpect(code).toEqual(\n\t\t'const formattedDuration = registry.relativetime(\"en\", i?.duration, { unit: /** @type {import(\"../registry.js\").RelativeTimeFormatUnit} */ (i?.unit) });'\n\t);\n});\n\ntest(\"compiles dollar-prefixed relative time units referencing local variables\", () => {\n\tconst code = compileLocalVariable({\n\t\tlocale: \"en\",\n\t\tdeclarations: [\n\t\t\t{ type: \"input-variable\", name: \"duration\" },\n\t\t\t{\n\t\t\t\ttype: \"local-variable\",\n\t\t\t\tname: \"localUnit\",\n\t\t\t\tvalue: { type: \"expression\", arg: { type: \"literal\", value: \"day\" } },\n\t\t\t},\n\t\t],\n\t\tdeclaration: {\n\t\t\ttype: \"local-variable\",\n\t\t\tname: \"formattedDuration\",\n\t\t\tvalue: {\n\t\t\t\ttype: \"expression\",\n\t\t\t\targ: { type: \"variable-reference\", name: \"duration\" },\n\t\t\t\tannotation: {\n\t\t\t\t\ttype: \"function-reference\",\n\t\t\t\t\tname: \"relativetime\",\n\t\t\t\t\toptions: [\n\t\t\t\t\t\t{ name: \"unit\", value: { type: \"literal\", value: \"$localUnit\" } },\n\t\t\t\t\t],\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t});\n\n\texpect(code).toEqual(\n\t\t'const formattedDuration = registry.relativetime(\"en\", i?.duration, { unit: /** @type {import(\"../registry.js\").RelativeTimeFormatUnit} */ (localUnit) });'\n\t);\n});\n\ntest(\"accepts dollar-prefixed relative time formatter unit options with non-identifier input names\", () => {\n\tconst code = compileLocalVariable({\n\t\tlocale: \"en\",\n\t\tdeclaration: {\n\t\t\ttype: \"local-variable\",\n\t\t\tname: \"formattedDuration\",\n\t\t\tvalue: {\n\t\t\t\ttype: \"expression\",\n\t\t\t\targ: { type: \"variable-reference\", name: \"duration\" },\n\t\t\t\tannotation: {\n\t\t\t\t\ttype: \"function-reference\",\n\t\t\t\t\tname: \"relativetime\",\n\t\t\t\t\toptions: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tname: \"unit\",\n\t\t\t\t\t\t\tvalue: { type: \"literal\", value: \"$relative-unit\" },\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t});\n\n\texpect(code).toEqual(\n\t\t'const formattedDuration = registry.relativetime(\"en\", i?.duration, { unit: /** @type {import(\"../registry.js\").RelativeTimeFormatUnit} */ (i?.[\"relative-unit\"]) });'\n\t);\n});\n"]}
|