UNPKG

@inlang/paraglide-js

Version:

[![NPM Downloads](https://img.shields.io/npm/dw/%40inlang%2Fparaglide-js?logo=npm&logoColor=red&label=npm%20downloads)](https://www.npmjs.com/package/@inlang/paraglide-js) [![GitHub Issues](https://img.shields.io/github/issues-closed/opral/paraglide-js?lo

28 lines 1.02 kB
import { compileInputAccess } from "./variable-access.js"; import { escapeForDoubleQuoteString } from "../services/codegen/escape.js"; import { compileAnnotation } from "./compile-annotation.js"; /** * Compiles a local variable. * * @example * const code = compileLocalVariable({ * type: "local-variable", * name: "myVar", * value: { type: "literal", value: "Hello" } * }); * >> code === "const myVar = 'Hello';" */ export function compileLocalVariable(args) { const annotation = args.declaration.value.annotation; const value = compileAnnotation(compileLiteralOrVarRef(args.declaration.value.arg), args.locale, annotation); return `const ${args.declaration.name} = ${value};`; } function compileLiteralOrVarRef(value) { switch (value.type) { case "literal": return `"${escapeForDoubleQuoteString(value.value)}"`; case "variable-reference": return compileInputAccess(value.name); } } //# sourceMappingURL=compile-local-variable.js.map