@parlajs/compiler 0.0.0-stage → 0.0.0
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/LICENSE +21 -0
- package/README.md +21 -2
- package/build/build.d.ts +18 -0
- package/build/build.d.ts.map +1 -0
- package/build/build.js +10 -0
- package/build/cli.d.ts +3 -0
- package/build/cli.d.ts.map +1 -0
- package/build/cli.js +8 -0
- package/build/command.d.ts +13 -0
- package/build/command.d.ts.map +1 -0
- package/build/command.js +156 -0
- package/build/compile/code.d.ts +13 -0
- package/build/compile/code.d.ts.map +1 -0
- package/build/compile/code.js +42 -0
- package/build/compile/compile.d.ts +11 -0
- package/build/compile/compile.d.ts.map +1 -0
- package/build/compile/compile.js +244 -0
- package/build/compile/error.d.ts +4 -0
- package/build/compile/error.d.ts.map +1 -0
- package/build/compile/error.js +3 -0
- package/build/compile/info.d.ts +49 -0
- package/build/compile/info.d.ts.map +1 -0
- package/build/compile/info.js +22 -0
- package/build/compile/scope.d.ts +7 -0
- package/build/compile/scope.d.ts.map +1 -0
- package/build/compile/scope.js +14 -0
- package/build/compile/single.d.ts +11 -0
- package/build/compile/single.d.ts.map +1 -0
- package/build/compile/single.js +36 -0
- package/build/compile/variants.d.ts +16 -0
- package/build/compile/variants.d.ts.map +1 -0
- package/build/compile/variants.js +48 -0
- package/build/compile.d.ts +61 -0
- package/build/compile.d.ts.map +1 -0
- package/build/compile.js +385 -0
- package/build/config/checks.d.ts +21 -0
- package/build/config/checks.d.ts.map +1 -0
- package/build/config/checks.js +97 -0
- package/build/config/config.d.ts +71 -0
- package/build/config/config.d.ts.map +1 -0
- package/build/config/config.js +7 -0
- package/build/config/fallbacks.d.ts +6 -0
- package/build/config/fallbacks.d.ts.map +1 -0
- package/build/config/fallbacks.js +13 -0
- package/build/config/import.d.ts +31 -0
- package/build/config/import.d.ts.map +1 -0
- package/build/config/import.js +115 -0
- package/build/config/load.d.ts +13 -0
- package/build/config/load.d.ts.map +1 -0
- package/build/config/load.js +59 -0
- package/build/config.d.ts +77 -0
- package/build/config.d.ts.map +1 -0
- package/build/config.js +223 -0
- package/build/diagnostics.d.ts +31 -0
- package/build/diagnostics.d.ts.map +1 -0
- package/build/diagnostics.js +41 -0
- package/build/generate/checks.d.ts +9 -0
- package/build/generate/checks.d.ts.map +1 -0
- package/build/generate/checks.js +93 -0
- package/build/generate/chunk.d.ts +11 -0
- package/build/generate/chunk.d.ts.map +1 -0
- package/build/generate/chunk.js +57 -0
- package/build/generate/digits.d.ts +8 -0
- package/build/generate/digits.d.ts.map +1 -0
- package/build/generate/digits.js +57 -0
- package/build/generate/files.d.ts +7 -0
- package/build/generate/files.d.ts.map +1 -0
- package/build/generate/files.js +59 -0
- package/build/generate/locale.d.ts +21 -0
- package/build/generate/locale.d.ts.map +1 -0
- package/build/generate/locale.js +108 -0
- package/build/generate/modules.d.ts +27 -0
- package/build/generate/modules.d.ts.map +1 -0
- package/build/generate/modules.js +61 -0
- package/build/generate/namespace.d.ts +19 -0
- package/build/generate/namespace.d.ts.map +1 -0
- package/build/generate/namespace.js +65 -0
- package/build/generate/namespaces.d.ts +5 -0
- package/build/generate/namespaces.d.ts.map +1 -0
- package/build/generate/namespaces.js +41 -0
- package/build/generate/read.d.ts +21 -0
- package/build/generate/read.d.ts.map +1 -0
- package/build/generate/read.js +115 -0
- package/build/index.d.ts +9 -0
- package/build/index.d.ts.map +1 -0
- package/build/index.js +7 -0
- package/build/init/detect.d.ts +43 -0
- package/build/init/detect.d.ts.map +1 -0
- package/build/init/detect.js +69 -0
- package/build/init/init.d.ts +12 -0
- package/build/init/init.d.ts.map +1 -0
- package/build/init/init.js +126 -0
- package/build/options/date.d.ts +3 -0
- package/build/options/date.d.ts.map +1 -0
- package/build/options/date.js +77 -0
- package/build/options/literal.d.ts +10 -0
- package/build/options/literal.d.ts.map +1 -0
- package/build/options/literal.js +11 -0
- package/build/options/names.d.ts +5 -0
- package/build/options/names.d.ts.map +1 -0
- package/build/options/names.js +56 -0
- package/build/options/number.d.ts +3 -0
- package/build/options/number.d.ts.map +1 -0
- package/build/options/number.js +17 -0
- package/build/options/options.d.ts +7 -0
- package/build/options/options.d.ts.map +1 -0
- package/build/options/options.js +66 -0
- package/build/options.d.ts +9 -0
- package/build/options.d.ts.map +1 -0
- package/build/options.js +214 -0
- package/build/plurals.d.ts +6 -0
- package/build/plurals.d.ts.map +1 -0
- package/build/plurals.js +50 -0
- package/build/types/names.d.ts +9 -0
- package/build/types/names.d.ts.map +1 -0
- package/build/types/names.js +109 -0
- package/build/types/namespace.d.ts +17 -0
- package/build/types/namespace.d.ts.map +1 -0
- package/build/types/namespace.js +113 -0
- package/build/types/signature.d.ts +8 -0
- package/build/types/signature.d.ts.map +1 -0
- package/build/types/signature.js +87 -0
- package/build/types.d.ts +25 -0
- package/build/types.d.ts.map +1 -0
- package/build/types.js +250 -0
- package/build/vite.d.ts +9 -0
- package/build/vite.d.ts.map +1 -0
- package/build/vite.js +125 -0
- package/build/watch.d.ts +12 -0
- package/build/watch.d.ts.map +1 -0
- package/build/watch.js +93 -0
- package/package.json +84 -3
- package/src/build.ts +31 -0
- package/src/cli.ts +9 -0
- package/src/command.ts +195 -0
- package/src/compile/code.ts +51 -0
- package/src/compile/compile.ts +289 -0
- package/src/compile/error.ts +3 -0
- package/src/compile/info.ts +63 -0
- package/src/compile/scope.ts +14 -0
- package/src/compile/single.ts +46 -0
- package/src/compile/variants.ts +68 -0
- package/src/config/checks.ts +140 -0
- package/src/config/config.ts +83 -0
- package/src/config/fallbacks.ts +18 -0
- package/src/config/import.ts +146 -0
- package/src/config/load.ts +75 -0
- package/src/diagnostics.ts +98 -0
- package/src/generate/checks.ts +103 -0
- package/src/generate/chunk.ts +73 -0
- package/src/generate/digits.ts +74 -0
- package/src/generate/files.ts +83 -0
- package/src/generate/locale.ts +145 -0
- package/src/generate/modules.ts +94 -0
- package/src/generate/namespace.ts +119 -0
- package/src/generate/namespaces.ts +59 -0
- package/src/generate/read.ts +159 -0
- package/src/index.ts +27 -0
- package/src/init/detect.ts +103 -0
- package/src/init/init.ts +158 -0
- package/src/options/date.ts +87 -0
- package/src/options/literal.ts +21 -0
- package/src/options/names.ts +64 -0
- package/src/options/number.ts +20 -0
- package/src/options/options.ts +75 -0
- package/src/plurals.ts +68 -0
- package/src/types/names.ts +115 -0
- package/src/types/namespace.ts +148 -0
- package/src/types/signature.ts +111 -0
- package/src/vite.ts +143 -0
- package/src/watch.ts +115 -0
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
const NUMERIC = new Set(['number', 'integer', 'currency', 'percent', 'unit', 'offset']);
|
|
2
|
+
/** MF2 gives the other number functions no selection. */
|
|
3
|
+
export const SELECTS = new Set(['number', 'integer', 'percent']);
|
|
4
|
+
const DATES = new Set(['date', 'time', 'datetime']);
|
|
5
|
+
/** The built-in message functions; the config's `functions` add to them. */
|
|
6
|
+
export const BUILTIN_FUNCTIONS = new Set([...NUMERIC, ...DATES, 'string']);
|
|
7
|
+
export function kindOf(fn, custom) {
|
|
8
|
+
if (!fn) {
|
|
9
|
+
return { kind: 'any' };
|
|
10
|
+
}
|
|
11
|
+
const declared = custom.get(fn.name);
|
|
12
|
+
if (declared) {
|
|
13
|
+
return { kind: declared };
|
|
14
|
+
}
|
|
15
|
+
if (NUMERIC.has(fn.name)) {
|
|
16
|
+
return { kind: 'number' };
|
|
17
|
+
}
|
|
18
|
+
if (DATES.has(fn.name)) {
|
|
19
|
+
return { kind: 'date' };
|
|
20
|
+
}
|
|
21
|
+
return { kind: 'string' };
|
|
22
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scope.d.ts","sourceRoot":"","sources":["../../src/compile/scope.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,qBAAa,WAAW;IACtB,QAAQ,CAAC,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC,CAAM;IACpC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAA6B;IAClD,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAQ1B;CACF"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/** Module-level constants shared by every message in one generated chunk. */
|
|
2
|
+
export class ModuleScope {
|
|
3
|
+
consts = [];
|
|
4
|
+
seen = new Map();
|
|
5
|
+
hoist(code) {
|
|
6
|
+
let name = this.seen.get(code);
|
|
7
|
+
if (!name) {
|
|
8
|
+
name = `v${this.consts.length}`;
|
|
9
|
+
this.consts.push(`const ${name} = ${code};`);
|
|
10
|
+
this.seen.set(code, name);
|
|
11
|
+
}
|
|
12
|
+
return name;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export interface Selector {
|
|
2
|
+
numeric: boolean;
|
|
3
|
+
raw: string;
|
|
4
|
+
options: string;
|
|
5
|
+
}
|
|
6
|
+
/** One selector needs no `pick`: exact numbers first, then the category or text, then the catch-all. */
|
|
7
|
+
export declare function single({ numeric, raw, options }: Selector, variants: ReadonlyArray<{
|
|
8
|
+
key: string | null;
|
|
9
|
+
code: string;
|
|
10
|
+
}>): string;
|
|
11
|
+
//# sourceMappingURL=single.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"single.d.ts","sourceRoot":"","sources":["../../src/compile/single.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,QAAQ;IACvB,OAAO,EAAE,OAAO,CAAC;IACjB,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,EAAE,MAAM,CAAC;CACjB;AAOD,wGAAwG;AACxG,wBAAgB,MAAM,CACpB,EAAE,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE,QAAQ,EACnC,QAAQ,EAAE,aAAa,CAAC;IAAE,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC,GAC5D,MAAM,CA8BR"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
function switchOn(value, cases) {
|
|
2
|
+
const body = [...cases].map(([key, code]) => `case ${key}: return ${code};`);
|
|
3
|
+
return body.length > 0 ? `switch (${value}) { ${body.join(' ')} } ` : '';
|
|
4
|
+
}
|
|
5
|
+
/** One selector needs no `pick`: exact numbers first, then the category or text, then the catch-all. */
|
|
6
|
+
export function single({ numeric, raw, options }, variants) {
|
|
7
|
+
const exact = new Map();
|
|
8
|
+
const named = new Map();
|
|
9
|
+
let rest;
|
|
10
|
+
for (const { key, code } of variants) {
|
|
11
|
+
if (key === null) {
|
|
12
|
+
rest ??= code;
|
|
13
|
+
continue;
|
|
14
|
+
}
|
|
15
|
+
// A letter starts a category, never a number.
|
|
16
|
+
const isExact = numeric && (key.codePointAt(0) ?? 65) < 65;
|
|
17
|
+
const cases = isExact ? exact : named;
|
|
18
|
+
const literal = isExact ? String(Number(key)) : JSON.stringify(key);
|
|
19
|
+
cases.set(literal, cases.get(literal) ?? code);
|
|
20
|
+
}
|
|
21
|
+
// Both formats require a catch-all; without one, `pick` takes the last variant too.
|
|
22
|
+
rest ??= variants.at(-1)?.code ?? '""';
|
|
23
|
+
const number = `Number(${raw})`;
|
|
24
|
+
const value = numeric ? `$.c(${raw}${options})` : `$.s(${raw})`;
|
|
25
|
+
if (exact.size > 1 || named.size > 1) {
|
|
26
|
+
return `{ ${switchOn(number, exact)}${switchOn(value, named)}return ${rest}; }`;
|
|
27
|
+
}
|
|
28
|
+
let code = rest;
|
|
29
|
+
for (const [key, matched] of named) {
|
|
30
|
+
code = `${value} === ${key} ? ${matched} : ${code}`;
|
|
31
|
+
}
|
|
32
|
+
for (const [key, matched] of exact) {
|
|
33
|
+
code = `${number} === ${key} ? ${matched} : ${code}`;
|
|
34
|
+
}
|
|
35
|
+
return code;
|
|
36
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Model } from 'messageformat';
|
|
2
|
+
/** The keys the variants give selector `at`, and whether one is the catch-all `*`. */
|
|
3
|
+
export declare function keysAt(msg: Model.SelectMessage, at: number): {
|
|
4
|
+
keys: Set<string>;
|
|
5
|
+
open: boolean;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* The params each key of the `:string` selector `at` needs, `null` for any other string; `undefined`
|
|
9
|
+
* when every key needs the same. `shared` are read outside any variant, `reads` by each variant.
|
|
10
|
+
*/
|
|
11
|
+
export declare function branchNeeds(msg: Model.SelectMessage, { at, shared, reads, }: {
|
|
12
|
+
at: number;
|
|
13
|
+
shared: ReadonlySet<string>;
|
|
14
|
+
reads: ReadonlyArray<Set<string>>;
|
|
15
|
+
}): Map<string | null, Set<string>> | undefined;
|
|
16
|
+
//# sourceMappingURL=variants.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"variants.d.ts","sourceRoot":"","sources":["../../src/compile/variants.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAE3C,sFAAsF;AACtF,wBAAgB,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,aAAa,EAAE,EAAE,EAAE,MAAM,GAAG;IAAE,IAAI,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IAAC,IAAI,EAAE,OAAO,CAAA;CAAE,CAYjG;AAED;;;GAGG;AACH,wBAAgB,WAAW,CACzB,GAAG,EAAE,KAAK,CAAC,aAAa,EACxB,EACE,EAAE,EACF,MAAM,EACN,KAAK,GACN,EAAE;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;IAAC,KAAK,EAAE,aAAa,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAA;CAAE,GAChF,GAAG,CAAC,MAAM,GAAG,IAAI,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC,GAAG,SAAS,CAuC7C"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/** The keys the variants give selector `at`, and whether one is the catch-all `*`. */
|
|
2
|
+
export function keysAt(msg, at) {
|
|
3
|
+
const keys = new Set();
|
|
4
|
+
let open = false;
|
|
5
|
+
for (const v of msg.variants) {
|
|
6
|
+
const key = v.keys[at];
|
|
7
|
+
if (key?.type === '*') {
|
|
8
|
+
open = true;
|
|
9
|
+
}
|
|
10
|
+
else if (key) {
|
|
11
|
+
keys.add(key.value);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
return { keys, open };
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* The params each key of the `:string` selector `at` needs, `null` for any other string; `undefined`
|
|
18
|
+
* when every key needs the same. `shared` are read outside any variant, `reads` by each variant.
|
|
19
|
+
*/
|
|
20
|
+
export function branchNeeds(msg, { at, shared, reads, }) {
|
|
21
|
+
const keyOf = (v) => {
|
|
22
|
+
const key = v.keys[at];
|
|
23
|
+
return !key || key.type === '*' ? null : key.value;
|
|
24
|
+
};
|
|
25
|
+
const readBy = (match) => {
|
|
26
|
+
const out = new Set(shared);
|
|
27
|
+
for (const [n, v] of msg.variants.entries()) {
|
|
28
|
+
for (const param of match(v) ? (reads[n] ?? []) : []) {
|
|
29
|
+
out.add(param);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return out;
|
|
33
|
+
};
|
|
34
|
+
const needs = new Map();
|
|
35
|
+
for (const key of new Set(msg.variants.map(keyOf))) {
|
|
36
|
+
if (key === null) {
|
|
37
|
+
needs.set(null, readBy((v) => keyOf(v) === null));
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
// First, the selector decides alone where a variant has `*` for every other selector.
|
|
41
|
+
const covered = at === 0 &&
|
|
42
|
+
msg.variants.some((v) => keyOf(v) === key && v.keys.every((k, j) => j === 0 || k.type === '*'));
|
|
43
|
+
needs.set(key, readBy((v) => keyOf(v) === key || (!covered && keyOf(v) === null)));
|
|
44
|
+
}
|
|
45
|
+
const sets = [...needs.values()];
|
|
46
|
+
const differ = sets.some((set) => set.size !== sets[0]?.size || [...set].some((p) => !sets[0]?.has(p)));
|
|
47
|
+
return differ ? needs : undefined;
|
|
48
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import type { Model } from 'messageformat';
|
|
2
|
+
/** What a custom function's value is: it types the param. */
|
|
3
|
+
export type FunctionKind = 'string' | 'number' | 'date';
|
|
4
|
+
/** Message functions beyond the built-in ones, by what their value is. */
|
|
5
|
+
export type CustomFunctions = Readonly<Record<string, FunctionKind>>;
|
|
6
|
+
/** The built-in message functions; the config's `functions` add to them. */
|
|
7
|
+
export declare const BUILTIN_FUNCTIONS: ReadonlySet<string>;
|
|
8
|
+
/** What a message needs from one parameter. `any` is an unannotated placeholder. */
|
|
9
|
+
export type ParamKind = {
|
|
10
|
+
kind: 'number';
|
|
11
|
+
} | {
|
|
12
|
+
kind: 'date';
|
|
13
|
+
} | {
|
|
14
|
+
kind: 'string';
|
|
15
|
+
} | {
|
|
16
|
+
kind: 'any';
|
|
17
|
+
} | {
|
|
18
|
+
kind: 'select';
|
|
19
|
+
keys: Array<string>;
|
|
20
|
+
open: boolean;
|
|
21
|
+
};
|
|
22
|
+
export interface MessageInfo {
|
|
23
|
+
params: Map<string, Array<ParamKind>>;
|
|
24
|
+
markup: Set<string>;
|
|
25
|
+
rich: boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Set when a `:string` selector's value decides which params a call needs: the params each key
|
|
28
|
+
* needs, `null` for any other string. Unset when every key needs the same.
|
|
29
|
+
*/
|
|
30
|
+
branches?: {
|
|
31
|
+
param: string;
|
|
32
|
+
needs: Map<string | null, Set<string>>;
|
|
33
|
+
};
|
|
34
|
+
/** Each selector that picks by plural category, with the keys its variants name. */
|
|
35
|
+
plurals: Array<{
|
|
36
|
+
type: Intl.PluralRuleType;
|
|
37
|
+
keys: Set<string>;
|
|
38
|
+
}>;
|
|
39
|
+
}
|
|
40
|
+
export interface CompiledMessage {
|
|
41
|
+
/** A function body reading params from `p` and the runtime from `$`. */
|
|
42
|
+
body: string;
|
|
43
|
+
info: MessageInfo;
|
|
44
|
+
}
|
|
45
|
+
export declare class CompileError extends Error {
|
|
46
|
+
name: string;
|
|
47
|
+
}
|
|
48
|
+
/** Module-level constants shared by every message in one generated chunk. */
|
|
49
|
+
export declare class ModuleScope {
|
|
50
|
+
readonly consts: Array<string>;
|
|
51
|
+
private readonly seen;
|
|
52
|
+
hoist(code: string): string;
|
|
53
|
+
}
|
|
54
|
+
export interface CompileOptions {
|
|
55
|
+
readonly scope?: ModuleScope;
|
|
56
|
+
readonly custom?: CustomFunctions;
|
|
57
|
+
/** The locale whose plural rules apply, when not the chunk's. */
|
|
58
|
+
readonly pluralsOf?: string | undefined;
|
|
59
|
+
}
|
|
60
|
+
export declare function compileMessage(msg: Model.Message, options?: CompileOptions): CompiledMessage;
|
|
61
|
+
//# sourceMappingURL=compile.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compile.d.ts","sourceRoot":"","sources":["../src/compile.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAI3C,6DAA6D;AAC7D,MAAM,MAAM,YAAY,GAAG,QAAQ,GAAG,QAAQ,GAAG,MAAM,CAAC;AAExD,0EAA0E;AAC1E,MAAM,MAAM,eAAe,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC,CAAC;AAMrE,4EAA4E;AAC5E,eAAO,MAAM,iBAAiB,EAAE,WAAW,CAAC,MAAM,CAA6C,CAAC;AAEhG,oFAAoF;AACpF,MAAM,MAAM,SAAS,GACjB;IAAE,IAAI,EAAE,QAAQ,CAAA;CAAE,GAClB;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,GAChB;IAAE,IAAI,EAAE,QAAQ,CAAA;CAAE,GAClB;IAAE,IAAI,EAAE,KAAK,CAAA;CAAE,GACf;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,IAAI,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IAAC,IAAI,EAAE,OAAO,CAAA;CAAE,CAAC;AAE3D,MAAM,WAAW,WAAW;IAC1B,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC;IACtC,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IACpB,IAAI,EAAE,OAAO,CAAC;IACd;;;OAGG;IACH,QAAQ,CAAC,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,GAAG,CAAC,MAAM,GAAG,IAAI,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC,CAAA;KAAE,CAAC;IACrE,oFAAoF;IACpF,OAAO,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,IAAI,CAAC,cAAc,CAAC;QAAC,IAAI,EAAE,GAAG,CAAC,MAAM,CAAC,CAAA;KAAE,CAAC,CAAC;CAClE;AAED,MAAM,WAAW,eAAe;IAC9B,wEAAwE;IACxE,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,WAAW,CAAC;CACnB;AAED,qBAAa,YAAa,SAAQ,KAAK;IAC5B,IAAI,SAAkB;CAChC;AAED,6EAA6E;AAC7E,qBAAa,WAAW;IACtB,QAAQ,CAAC,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC,CAAM;IACpC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAA6B;IAClD,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAQ1B;CACF;AAiHD,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,KAAK,CAAC,EAAE,WAAW,CAAC;IAC7B,QAAQ,CAAC,MAAM,CAAC,EAAE,eAAe,CAAC;IAClC,iEAAiE;IACjE,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CACzC;AAwSD,wBAAgB,cAAc,CAAC,GAAG,EAAE,KAAK,CAAC,OAAO,EAAE,OAAO,GAAE,cAAmB,GAAG,eAAe,CAOhG"}
|
package/build/compile.js
ADDED
|
@@ -0,0 +1,385 @@
|
|
|
1
|
+
import { inheritedOptions, intlOptions } from './options.js';
|
|
2
|
+
const NUMERIC = new Set(['number', 'integer', 'currency', 'percent', 'unit', 'offset']);
|
|
3
|
+
/** MF2 gives the other number functions no selection. */
|
|
4
|
+
const SELECTS = new Set(['number', 'integer', 'percent']);
|
|
5
|
+
const DATES = new Set(['date', 'time', 'datetime']);
|
|
6
|
+
/** The built-in message functions; the config's `functions` add to them. */
|
|
7
|
+
export const BUILTIN_FUNCTIONS = new Set([...NUMERIC, ...DATES, 'string']);
|
|
8
|
+
export class CompileError extends Error {
|
|
9
|
+
name = 'CompileError';
|
|
10
|
+
}
|
|
11
|
+
/** Module-level constants shared by every message in one generated chunk. */
|
|
12
|
+
export class ModuleScope {
|
|
13
|
+
consts = [];
|
|
14
|
+
seen = new Map();
|
|
15
|
+
hoist(code) {
|
|
16
|
+
let name = this.seen.get(code);
|
|
17
|
+
if (!name) {
|
|
18
|
+
name = `v${this.consts.length}`;
|
|
19
|
+
this.consts.push(`const ${name} = ${code};`);
|
|
20
|
+
this.seen.set(code, name);
|
|
21
|
+
}
|
|
22
|
+
return name;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
function literalValue(value) {
|
|
26
|
+
if (/^-?\d+(?:\.\d+)?$/.test(value)) {
|
|
27
|
+
// `02` would be a legacy octal literal: a syntax error in the chunk, which is a module
|
|
28
|
+
return String(Number(value));
|
|
29
|
+
}
|
|
30
|
+
if (value === 'true' || value === 'false') {
|
|
31
|
+
return value;
|
|
32
|
+
}
|
|
33
|
+
return JSON.stringify(value);
|
|
34
|
+
}
|
|
35
|
+
/** Where markup finds its callback, without what objects inherit: a check at run time costs 30%. */
|
|
36
|
+
const params = (markup) => markup in Object.prototype ? '{ __proto__: null, ...p }' : 'p';
|
|
37
|
+
/** A call's `{ __proto__: value }` sets the object's prototype, so the message would never get it. */
|
|
38
|
+
function checkName(name) {
|
|
39
|
+
if (name === '__proto__') {
|
|
40
|
+
throw new CompileError('a param or markup cannot be named "__proto__": rename it');
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
function kindOf(fn, custom) {
|
|
44
|
+
if (!fn) {
|
|
45
|
+
return { kind: 'any' };
|
|
46
|
+
}
|
|
47
|
+
const declared = custom.get(fn.name);
|
|
48
|
+
if (declared) {
|
|
49
|
+
return { kind: declared };
|
|
50
|
+
}
|
|
51
|
+
if (NUMERIC.has(fn.name)) {
|
|
52
|
+
return { kind: 'number' };
|
|
53
|
+
}
|
|
54
|
+
if (DATES.has(fn.name)) {
|
|
55
|
+
return { kind: 'date' };
|
|
56
|
+
}
|
|
57
|
+
return { kind: 'string' };
|
|
58
|
+
}
|
|
59
|
+
/** `:offset`'s `add` or `subtract`, as an operation. */
|
|
60
|
+
function offsetBy({ options = {} }) {
|
|
61
|
+
const [[name, value] = [], ...rest] = Object.entries(options);
|
|
62
|
+
const isDigits = value?.type === 'literal' && /^\d+$/.test(value.value);
|
|
63
|
+
if (!isDigits || rest.length > 0 || (name !== 'add' && name !== 'subtract')) {
|
|
64
|
+
throw new CompileError(':offset needs one literal integer, add or subtract');
|
|
65
|
+
}
|
|
66
|
+
return `${name === 'add' ? '+' : '-'} ${Number(value.value)}`;
|
|
67
|
+
}
|
|
68
|
+
/** The number a selector picks by: the one its function writes. */
|
|
69
|
+
function selected(name, raw) {
|
|
70
|
+
if (name === 'integer') {
|
|
71
|
+
return `Math.round(Number(${raw}))`;
|
|
72
|
+
}
|
|
73
|
+
// Rounded, as 0.29 * 100 is 28.999999999999996.
|
|
74
|
+
return name === 'percent' ? `Math.round(Number(${raw}) * 1e4) / 100` : raw;
|
|
75
|
+
}
|
|
76
|
+
function switchOn(value, cases) {
|
|
77
|
+
const body = [...cases].map(([key, code]) => `case ${key}: return ${code};`);
|
|
78
|
+
return body.length > 0 ? `switch (${value}) { ${body.join(' ')} } ` : '';
|
|
79
|
+
}
|
|
80
|
+
/** One selector needs no `pick`: exact numbers first, then the category or text, then the catch-all. */
|
|
81
|
+
function single({ numeric, raw, options }, variants) {
|
|
82
|
+
const exact = new Map();
|
|
83
|
+
const named = new Map();
|
|
84
|
+
let rest;
|
|
85
|
+
for (const { key, code } of variants) {
|
|
86
|
+
if (key === null) {
|
|
87
|
+
rest ??= code;
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
// A letter starts a category, never a number.
|
|
91
|
+
const isExact = numeric && (key.codePointAt(0) ?? 65) < 65;
|
|
92
|
+
const cases = isExact ? exact : named;
|
|
93
|
+
const literal = isExact ? String(Number(key)) : JSON.stringify(key);
|
|
94
|
+
cases.set(literal, cases.get(literal) ?? code);
|
|
95
|
+
}
|
|
96
|
+
// Both formats require a catch-all; without one, `pick` takes the last variant too.
|
|
97
|
+
rest ??= variants.at(-1)?.code ?? '""';
|
|
98
|
+
const number = `Number(${raw})`;
|
|
99
|
+
const value = numeric ? `$.c(${raw}${options})` : `$.s(${raw})`;
|
|
100
|
+
if (exact.size > 1 || named.size > 1) {
|
|
101
|
+
return `{ ${switchOn(number, exact)}${switchOn(value, named)}return ${rest}; }`;
|
|
102
|
+
}
|
|
103
|
+
let code = rest;
|
|
104
|
+
for (const [key, matched] of named) {
|
|
105
|
+
code = `${value} === ${key} ? ${matched} : ${code}`;
|
|
106
|
+
}
|
|
107
|
+
for (const [key, matched] of exact) {
|
|
108
|
+
code = `${number} === ${key} ? ${matched} : ${code}`;
|
|
109
|
+
}
|
|
110
|
+
return code;
|
|
111
|
+
}
|
|
112
|
+
class MessageCompiler {
|
|
113
|
+
vars = new Map();
|
|
114
|
+
scope;
|
|
115
|
+
custom;
|
|
116
|
+
info = { params: new Map(), markup: new Set(), rich: false, plurals: [] };
|
|
117
|
+
/** The params read outside any variant, and those the variant being compiled reads. */
|
|
118
|
+
shared = new Set();
|
|
119
|
+
reads;
|
|
120
|
+
pluralsOf;
|
|
121
|
+
constructor({ scope = new ModuleScope(), custom = {}, pluralsOf }) {
|
|
122
|
+
this.scope = scope;
|
|
123
|
+
this.custom = new Map(Object.entries(custom));
|
|
124
|
+
this.pluralsOf = pluralsOf;
|
|
125
|
+
}
|
|
126
|
+
record(param, kind) {
|
|
127
|
+
checkName(param);
|
|
128
|
+
const list = this.info.params.get(param) ?? [];
|
|
129
|
+
list.push(kind);
|
|
130
|
+
this.info.params.set(param, list);
|
|
131
|
+
(this.reads ?? this.shared).add(param);
|
|
132
|
+
}
|
|
133
|
+
resolve(name) {
|
|
134
|
+
return this.vars.get(name) ?? { raw: `p[${JSON.stringify(name)}]`, param: name };
|
|
135
|
+
}
|
|
136
|
+
options(fn, extra = {}) {
|
|
137
|
+
const entries = Object.entries({ ...this.resolved(fn), ...extra });
|
|
138
|
+
if (entries.length === 0) {
|
|
139
|
+
return '';
|
|
140
|
+
}
|
|
141
|
+
const parts = entries.map(([k, v]) => `${JSON.stringify(k)}: ${v.type === 'literal' ? literalValue(v.value) : this.variable(v)}`);
|
|
142
|
+
const code = `{ ${parts.join(', ')} }`;
|
|
143
|
+
const constant = entries.every(([, v]) => v.type === 'literal');
|
|
144
|
+
return `, ${constant ? this.scope.hoist(code) : code}`;
|
|
145
|
+
}
|
|
146
|
+
/** An option's variable, which the call then needs as it does any placeholder. */
|
|
147
|
+
variable({ name }) {
|
|
148
|
+
const { raw, param } = this.resolve(name);
|
|
149
|
+
if (param) {
|
|
150
|
+
this.record(param, { kind: 'any' });
|
|
151
|
+
}
|
|
152
|
+
return raw;
|
|
153
|
+
}
|
|
154
|
+
resolved(fn) {
|
|
155
|
+
if (this.custom.has(fn.name)) {
|
|
156
|
+
return fn.options ?? {};
|
|
157
|
+
}
|
|
158
|
+
try {
|
|
159
|
+
return intlOptions(fn);
|
|
160
|
+
}
|
|
161
|
+
catch (error) {
|
|
162
|
+
throw new CompileError(error.message, { cause: error });
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
effective(expr) {
|
|
166
|
+
let binding;
|
|
167
|
+
if (expr.arg?.type === 'literal') {
|
|
168
|
+
binding = { raw: JSON.stringify(expr.arg.value) };
|
|
169
|
+
}
|
|
170
|
+
else if (expr.arg?.type === 'variable') {
|
|
171
|
+
binding = { ...this.resolve(expr.arg.name) };
|
|
172
|
+
}
|
|
173
|
+
else {
|
|
174
|
+
binding = { raw: 'undefined' };
|
|
175
|
+
}
|
|
176
|
+
const own = expr.functionRef;
|
|
177
|
+
if (own) {
|
|
178
|
+
if (!BUILTIN_FUNCTIONS.has(own.name) && !this.custom.has(own.name)) {
|
|
179
|
+
throw new CompileError(`unknown function :${own.name}`);
|
|
180
|
+
}
|
|
181
|
+
const { name } = own;
|
|
182
|
+
const isOffset = name === 'offset' && !this.custom.has(name);
|
|
183
|
+
const inherited = binding.fn ? inheritedOptions(binding.fn, isOffset ? 'number' : name) : {};
|
|
184
|
+
if (isOffset) {
|
|
185
|
+
binding.raw = `(Number(${binding.raw}) ${offsetBy(own)})`;
|
|
186
|
+
binding.fn = { type: 'function', name: 'number', options: inherited };
|
|
187
|
+
}
|
|
188
|
+
else {
|
|
189
|
+
binding.fn = { ...own, options: { ...inherited, ...own.options } };
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
return binding;
|
|
193
|
+
}
|
|
194
|
+
declare(decl) {
|
|
195
|
+
const binding = this.effective(decl.value);
|
|
196
|
+
if (decl.type === 'input') {
|
|
197
|
+
binding.param = decl.name;
|
|
198
|
+
}
|
|
199
|
+
this.vars.set(decl.name, binding);
|
|
200
|
+
if (binding.param && binding.fn) {
|
|
201
|
+
this.record(binding.param, kindOf(binding.fn, this.custom));
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
expression(expr) {
|
|
205
|
+
const b = this.effective(expr);
|
|
206
|
+
if (b.param) {
|
|
207
|
+
this.record(b.param, kindOf(b.fn, this.custom));
|
|
208
|
+
}
|
|
209
|
+
if (!b.fn) {
|
|
210
|
+
return `$.str(${b.raw})`;
|
|
211
|
+
}
|
|
212
|
+
const options = this.options(b.fn);
|
|
213
|
+
if (b.fn.name === 'number' && !options) {
|
|
214
|
+
return `$.n(${b.raw})`;
|
|
215
|
+
}
|
|
216
|
+
return `$.f(${JSON.stringify(b.fn.name)}, ${b.raw}${options})`;
|
|
217
|
+
}
|
|
218
|
+
pattern(pattern) {
|
|
219
|
+
const root = [];
|
|
220
|
+
const stack = [];
|
|
221
|
+
let rich = false;
|
|
222
|
+
const top = () => stack.at(-1)?.items ?? root;
|
|
223
|
+
for (const part of pattern) {
|
|
224
|
+
if (typeof part === 'string') {
|
|
225
|
+
if (part) {
|
|
226
|
+
top().push(JSON.stringify(part));
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
else if (part.type === 'expression') {
|
|
230
|
+
top().push(this.expression(part));
|
|
231
|
+
}
|
|
232
|
+
else {
|
|
233
|
+
rich = true;
|
|
234
|
+
checkName(part.name);
|
|
235
|
+
this.info.markup.add(part.name);
|
|
236
|
+
if (part.kind === 'open') {
|
|
237
|
+
stack.push({ name: part.name, items: [] });
|
|
238
|
+
}
|
|
239
|
+
else if (part.kind === 'standalone') {
|
|
240
|
+
top().push(`$.tag(${params(part.name)}, ${JSON.stringify(part.name)}, [])`);
|
|
241
|
+
}
|
|
242
|
+
else {
|
|
243
|
+
const open = stack.pop();
|
|
244
|
+
if (open?.name !== part.name) {
|
|
245
|
+
throw new CompileError(`closing markup {/${part.name}} has no matching open`);
|
|
246
|
+
}
|
|
247
|
+
top().push(`$.tag(${params(part.name)}, ${JSON.stringify(part.name)}, [${open.items.join(', ')}])`);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
const unclosed = stack.at(-1);
|
|
252
|
+
if (unclosed) {
|
|
253
|
+
throw new CompileError(`markup {#${unclosed.name}} is never closed`);
|
|
254
|
+
}
|
|
255
|
+
if (rich) {
|
|
256
|
+
this.info.rich = true;
|
|
257
|
+
return { code: `$.rich([${root.join(', ')}])`, rich };
|
|
258
|
+
}
|
|
259
|
+
return { code: root.length > 0 ? root.join(' + ') : '""', rich };
|
|
260
|
+
}
|
|
261
|
+
select(msg) {
|
|
262
|
+
const selectors = msg.selectors.map((sel, i) => {
|
|
263
|
+
const b = this.resolve(sel.name);
|
|
264
|
+
if (!b.fn) {
|
|
265
|
+
throw new CompileError(`selector $${sel.name} needs an annotation such as :number or :string`);
|
|
266
|
+
}
|
|
267
|
+
if (SELECTS.has(b.fn.name)) {
|
|
268
|
+
if (b.param) {
|
|
269
|
+
this.record(b.param, { kind: 'number' });
|
|
270
|
+
}
|
|
271
|
+
const raw = selected(b.fn.name, b.raw);
|
|
272
|
+
return { numeric: true, raw, options: this.plural(b.fn, msg, i) };
|
|
273
|
+
}
|
|
274
|
+
if (b.fn.name === 'string') {
|
|
275
|
+
if (b.param) {
|
|
276
|
+
const keys = new Set();
|
|
277
|
+
let open = false;
|
|
278
|
+
for (const v of msg.variants) {
|
|
279
|
+
const key = v.keys[i];
|
|
280
|
+
if (key?.type === '*') {
|
|
281
|
+
open = true;
|
|
282
|
+
}
|
|
283
|
+
else if (key) {
|
|
284
|
+
keys.add(key.value);
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
this.record(b.param, { kind: 'select', keys: [...keys], open });
|
|
288
|
+
}
|
|
289
|
+
return { numeric: false, raw: b.raw, options: '' };
|
|
290
|
+
}
|
|
291
|
+
throw new CompileError(`:${b.fn.name} cannot be used as a selector`);
|
|
292
|
+
});
|
|
293
|
+
const reads = [];
|
|
294
|
+
const codes = msg.variants.map((v) => {
|
|
295
|
+
this.reads = new Set();
|
|
296
|
+
reads.push(this.reads);
|
|
297
|
+
return this.pattern(v.value).code;
|
|
298
|
+
});
|
|
299
|
+
this.reads = undefined;
|
|
300
|
+
this.branch(msg, reads);
|
|
301
|
+
const keys = msg.variants.map((v) => v.keys.map((k) => (k.type === '*' ? null : k.value)));
|
|
302
|
+
const [only] = selectors;
|
|
303
|
+
if (only && selectors.length === 1) {
|
|
304
|
+
return single(only, keys.map(([key = null], i) => ({ key, code: codes[i] ?? '""' })));
|
|
305
|
+
}
|
|
306
|
+
const values = selectors.map((s) => `$.${s.numeric ? 'sn' : 'ss'}(${s.raw}${s.options})`);
|
|
307
|
+
const pick = `$.pick([${values.join(', ')}], ${this.scope.hoist(JSON.stringify(keys))})`;
|
|
308
|
+
// `one`/`other` is the commonest select, and a ternary a fraction of a switch's size.
|
|
309
|
+
if (codes.length === 2) {
|
|
310
|
+
const [first, second] = codes;
|
|
311
|
+
return `${pick} ? ${second} : ${first}`;
|
|
312
|
+
}
|
|
313
|
+
const cases = codes.map((code, i) => `case ${i}: return ${code};`);
|
|
314
|
+
return `{ switch (${pick}) { ${cases.join(' ')} } }`;
|
|
315
|
+
}
|
|
316
|
+
/** A numeric selector's options, noting the categories it picks by. */
|
|
317
|
+
plural(fn, msg, at) {
|
|
318
|
+
const keys = new Set();
|
|
319
|
+
for (const { keys: own } of msg.variants) {
|
|
320
|
+
const key = own[at];
|
|
321
|
+
if (key && key.type !== '*') {
|
|
322
|
+
keys.add(key.value);
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
const select = fn.options?.['select'];
|
|
326
|
+
const kind = select?.type === 'literal' ? select.value : 'cardinal';
|
|
327
|
+
if (kind === 'exact') {
|
|
328
|
+
return this.options(fn);
|
|
329
|
+
}
|
|
330
|
+
const type = kind === 'ordinal' ? 'ordinal' : 'cardinal';
|
|
331
|
+
this.info.plurals.push({ type, keys });
|
|
332
|
+
const { pluralsOf } = this;
|
|
333
|
+
return this.options(fn, pluralsOf ? { locale: { type: 'literal', value: pluralsOf } } : {});
|
|
334
|
+
}
|
|
335
|
+
/** Fills `info.branches` when exactly one selector is a `:string` param's. */
|
|
336
|
+
branch(msg, reads) {
|
|
337
|
+
const strings = msg.selectors.flatMap((sel, i) => {
|
|
338
|
+
const b = this.resolve(sel.name);
|
|
339
|
+
return b.fn?.name === 'string' && b.param ? [{ i, param: b.param }] : [];
|
|
340
|
+
});
|
|
341
|
+
const [only] = strings;
|
|
342
|
+
const kinds = only && this.info.params.get(only.param);
|
|
343
|
+
if (strings.length !== 1 ||
|
|
344
|
+
!only ||
|
|
345
|
+
kinds?.some((k) => k.kind !== 'select' && k.kind !== 'string' && k.kind !== 'any')) {
|
|
346
|
+
return;
|
|
347
|
+
}
|
|
348
|
+
const keyOf = (v) => {
|
|
349
|
+
const key = v.keys[only.i];
|
|
350
|
+
return !key || key.type === '*' ? null : key.value;
|
|
351
|
+
};
|
|
352
|
+
const readBy = (match) => {
|
|
353
|
+
const out = new Set(this.shared);
|
|
354
|
+
for (const [n, v] of msg.variants.entries()) {
|
|
355
|
+
for (const param of match(v) ? (reads[n] ?? []) : []) {
|
|
356
|
+
out.add(param);
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
return out;
|
|
360
|
+
};
|
|
361
|
+
const needs = new Map();
|
|
362
|
+
for (const key of new Set(msg.variants.map(keyOf))) {
|
|
363
|
+
if (key === null) {
|
|
364
|
+
needs.set(null, readBy((v) => keyOf(v) === null));
|
|
365
|
+
continue;
|
|
366
|
+
}
|
|
367
|
+
// First, the selector decides alone where a variant has `*` for every other selector.
|
|
368
|
+
const covered = only.i === 0 &&
|
|
369
|
+
msg.variants.some((v) => keyOf(v) === key && v.keys.every((k, j) => j === 0 || k.type === '*'));
|
|
370
|
+
needs.set(key, readBy((v) => keyOf(v) === key || (!covered && keyOf(v) === null)));
|
|
371
|
+
}
|
|
372
|
+
const sets = [...needs.values()];
|
|
373
|
+
if (sets.some((set) => set.size !== sets[0]?.size || [...set].some((p) => !sets[0]?.has(p)))) {
|
|
374
|
+
this.info.branches = { param: only.param, needs };
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
export function compileMessage(msg, options = {}) {
|
|
379
|
+
const c = new MessageCompiler(options);
|
|
380
|
+
for (const decl of msg.declarations) {
|
|
381
|
+
c.declare(decl);
|
|
382
|
+
}
|
|
383
|
+
const body = msg.type === 'message' ? c.pattern(msg.pattern).code : c.select(msg);
|
|
384
|
+
return { body, info: c.info };
|
|
385
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { FunctionKind } from '../compile/info.ts';
|
|
2
|
+
import type { NamespaceConfig, ResolvedNamespace } from './config.ts';
|
|
3
|
+
export declare function checkFunctions(functions: Record<string, FunctionKind>): Record<string, FunctionKind>;
|
|
4
|
+
/** A fallback outside `locales` lends no text, only its `Intl` formats. */
|
|
5
|
+
export declare function checkFallbacks(fallbacks: Record<string, Array<string>>, { locales, hasCatalog, }: {
|
|
6
|
+
readonly locales: ReadonlyArray<string>;
|
|
7
|
+
readonly hasCatalog: (locale: string) => boolean;
|
|
8
|
+
}): void;
|
|
9
|
+
/** Every tag `Intl` takes, each locale once, and the source locale among them. */
|
|
10
|
+
export declare function checkLocales({ locales, sourceLocale, fallbacks, }: {
|
|
11
|
+
locales: ReadonlyArray<string>;
|
|
12
|
+
sourceLocale: string;
|
|
13
|
+
fallbacks: Record<string, Array<string>>;
|
|
14
|
+
}): void;
|
|
15
|
+
/** The config's namespaces, each with its catalogs' paths, none of them in `outDir`. */
|
|
16
|
+
export declare function resolveNamespaces(namespaces: Record<string, NamespaceConfig>, { root, outDir, locales }: {
|
|
17
|
+
root: string;
|
|
18
|
+
outDir: string;
|
|
19
|
+
locales: ReadonlyArray<string>;
|
|
20
|
+
}): Array<ResolvedNamespace>;
|
|
21
|
+
//# sourceMappingURL=checks.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"checks.d.ts","sourceRoot":"","sources":["../../src/config/checks.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAGvD,OAAO,KAAK,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAEtE,wBAAgB,cAAc,CAC5B,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,GACtC,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAQ9B;AAsCD,2EAA2E;AAC3E,wBAAgB,cAAc,CAC5B,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC,EACxC,EACE,OAAO,EACP,UAAU,GACX,EAAE;IACD,QAAQ,CAAC,OAAO,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;IACxC,QAAQ,CAAC,UAAU,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC;CAClD,GACA,IAAI,CAkBN;AAED,kFAAkF;AAClF,wBAAgB,YAAY,CAAC,EAC3B,OAAO,EACP,YAAY,EACZ,SAAS,GACV,EAAE;IACD,OAAO,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;IAC/B,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC;CAC1C,GAAG,IAAI,CAeP;AAED,wFAAwF;AACxF,wBAAgB,iBAAiB,CAC/B,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,EAC3C,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,aAAa,CAAC,MAAM,CAAC,CAAA;CAAE,GAC1F,KAAK,CAAC,iBAAiB,CAAC,CAuB1B"}
|