@fluentic/i18n 0.1.0-beta.1 → 0.1.0-beta.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/CHANGELOG.md +13 -0
- package/README.md +9 -1
- package/dist/adapter.d.ts +6 -4
- package/dist/adapter.js +4 -3
- package/dist/compiled.d.ts +26 -24
- package/dist/compiled.js +4 -2
- package/dist/compiled.js.map +1 -1
- package/dist/compiler-support.d.ts +4 -0
- package/dist/compiler-support.js +4 -0
- package/dist/core/format.d.ts +11 -0
- package/dist/core/i18n.d.ts +26 -0
- package/dist/core/index.d.ts +1 -5
- package/dist/core/index.js +3 -2
- package/dist/core/types.d.ts +79 -0
- package/dist/hash-VJlyT31Z.js +90 -0
- package/dist/hash-VJlyT31Z.js.map +1 -0
- package/dist/hydration-store-BK6UxrtJ.js +13 -0
- package/dist/hydration-store-BK6UxrtJ.js.map +1 -0
- package/dist/hydration-store.d.ts +29 -0
- package/dist/hydration.d.ts +7 -0
- package/dist/hydration.js +35 -0
- package/dist/hydration.js.map +1 -0
- package/dist/index.d.ts +6 -6
- package/dist/index.js +3 -2
- package/dist/{interpreter-Dld8QyOI.js → interpreter-BfzvLLrD.js} +4 -3
- package/dist/interpreter-BfzvLLrD.js.map +1 -0
- package/dist/{manager-BW778X1Y.js → manager-BgMJWXWY.js} +21 -31
- package/dist/manager-BgMJWXWY.js.map +1 -0
- package/dist/manager.d.ts +62 -0
- package/dist/message-D4jK2Lzc.js +9 -0
- package/dist/message-D4jK2Lzc.js.map +1 -0
- package/dist/react.d.ts +41 -46
- package/dist/react.js +12 -8
- package/dist/react.js.map +1 -1
- package/dist/registry-manager.d.ts +7 -0
- package/dist/runtime-DXnGeCBw.js +110 -0
- package/dist/runtime-DXnGeCBw.js.map +1 -0
- package/dist/shared/compact.d.ts +5 -0
- package/dist/shared/formatting.d.ts +11 -0
- package/dist/shared/hash.d.ts +7 -0
- package/dist/shared/interpreter.d.ts +2 -0
- package/dist/shared/message.d.ts +2 -0
- package/dist/shared/runtime.d.ts +49 -0
- package/dist/{src-BovRx-mX.js → src-ON68XIog.js} +9 -7
- package/dist/src-ON68XIog.js.map +1 -0
- package/dist/state-manager.d.ts +6 -0
- package/dist/state.d.ts +8 -0
- package/dist/storage-manager.d.ts +14 -0
- package/dist/{translation-manager-C79eKu2K.js → translation-manager-BkmFnlb_.js} +5 -104
- package/dist/translation-manager-BkmFnlb_.js.map +1 -0
- package/dist/translation-manager.d.ts +34 -0
- package/dist/translation.d.ts +20 -0
- package/dist/types-BkDsJfVD.js.map +1 -1
- package/dist/types.d.ts +3 -2
- package/package.json +20 -54
- package/dist/adapter-CWC8rng-.d.ts +0 -178
- package/dist/analyze-CdXCxQDg.d.ts +0 -14
- package/dist/compact-CJ0OWoIv.d.ts +0 -7
- package/dist/compiler-BZtB9WLi.js +0 -365
- package/dist/compiler-BZtB9WLi.js.map +0 -1
- package/dist/compiler.d.ts +0 -35
- package/dist/compiler.js +0 -3
- package/dist/i18n-CfYNwubL.d.ts +0 -25
- package/dist/interpreter-Dld8QyOI.js.map +0 -1
- package/dist/manager-BW778X1Y.js.map +0 -1
- package/dist/options-DE7vYj0e.d.ts +0 -7
- package/dist/options-Dxxx0aOz.js +0 -23
- package/dist/options-Dxxx0aOz.js.map +0 -1
- package/dist/plugin/babel.d.ts +0 -11
- package/dist/plugin/babel.js +0 -31
- package/dist/plugin/babel.js.map +0 -1
- package/dist/plugin/esbuild.d.ts +0 -7
- package/dist/plugin/esbuild.js +0 -37
- package/dist/plugin/esbuild.js.map +0 -1
- package/dist/plugin/rollup.d.ts +0 -30
- package/dist/plugin/rollup.js +0 -34
- package/dist/plugin/rollup.js.map +0 -1
- package/dist/plugin/vite.d.ts +0 -31
- package/dist/plugin/vite.js +0 -11
- package/dist/plugin/vite.js.map +0 -1
- package/dist/plugin/webpack-loader.d.ts +0 -3
- package/dist/plugin/webpack-loader.js +0 -21
- package/dist/plugin/webpack-loader.js.map +0 -1
- package/dist/plugin/webpack.d.ts +0 -8
- package/dist/plugin/webpack.js +0 -22
- package/dist/plugin/webpack.js.map +0 -1
- package/dist/src-BovRx-mX.js.map +0 -1
- package/dist/translation-manager-C79eKu2K.js.map +0 -1
- package/dist/types-BuGoCU3P.d.ts +0 -75
- package/dist-cjs/babel.cjs +0 -379
- package/dist-cjs/babel.cjs.map +0 -1
- package/src/adapter.ts +0 -6
- package/src/compiled.ts +0 -116
- package/src/compiler/analyze.ts +0 -182
- package/src/compiler/index.ts +0 -208
- package/src/compiler/message.ts +0 -74
- package/src/core/format.ts +0 -40
- package/src/core/i18n.ts +0 -124
- package/src/core/index.ts +0 -1
- package/src/core/types.ts +0 -121
- package/src/index.ts +0 -9
- package/src/manager.ts +0 -175
- package/src/plugin/babel.ts +0 -34
- package/src/plugin/esbuild.ts +0 -45
- package/src/plugin/options.ts +0 -24
- package/src/plugin/rollup.ts +0 -29
- package/src/plugin/vite.ts +0 -6
- package/src/plugin/webpack-loader.ts +0 -22
- package/src/plugin/webpack.ts +0 -15
- package/src/react.ts +0 -97
- package/src/registry-manager.ts +0 -3
- package/src/shared/compact.ts +0 -51
- package/src/shared/formatting.ts +0 -121
- package/src/shared/interpreter.ts +0 -128
- package/src/shared/runtime.ts +0 -131
- package/src/state-manager.ts +0 -29
- package/src/state.ts +0 -20
- package/src/storage-manager.ts +0 -47
- package/src/translation-manager.ts +0 -82
- package/src/translation.ts +0 -106
- package/src/types.ts +0 -2
|
@@ -1,178 +0,0 @@
|
|
|
1
|
-
import { n as CompactMessage } from "./compact-CJ0OWoIv.js";
|
|
2
|
-
import { C as MessageTagHandler, O as TranslationGetter, f as LanguageId, h as MessageFormatOptions, p as MessageContext } from "./types-BuGoCU3P.js";
|
|
3
|
-
type StateManager<StateData> = {
|
|
4
|
-
get(): StateData;
|
|
5
|
-
subscribe(listener: () => void): () => void;
|
|
6
|
-
set(partial: Partial<StateData>): void;
|
|
7
|
-
};
|
|
8
|
-
declare function createStateManager<StateData extends object>(initial: StateData): StateManager<StateData>;
|
|
9
|
-
type Formats = {
|
|
10
|
-
number: Record<string, Intl.NumberFormatOptions>;
|
|
11
|
-
date: Record<string, Intl.DateTimeFormatOptions>;
|
|
12
|
-
time: Record<string, Intl.DateTimeFormatOptions>;
|
|
13
|
-
};
|
|
14
|
-
type FormatContext = {
|
|
15
|
-
languageId: string;
|
|
16
|
-
};
|
|
17
|
-
type FormatFactory<T> = T | ((context: FormatContext) => T);
|
|
18
|
-
type RegistryConfig = { [K in keyof Formats]: Record<string, FormatFactory<Formats[K][string]>>; };
|
|
19
|
-
type PartsRenderer = (runtime?: Runtime) => unknown[];
|
|
20
|
-
type Runtime = {
|
|
21
|
-
languageId: string;
|
|
22
|
-
ready: boolean;
|
|
23
|
-
translationsEnabled: boolean;
|
|
24
|
-
translationGetter: TranslationGetter | null;
|
|
25
|
-
formats: Partial<Formats>;
|
|
26
|
-
registry: RegistryConfig;
|
|
27
|
-
jsxLineBreak: unknown;
|
|
28
|
-
jsxHandler: ((options: MessageFormatOptions, render: PartsRenderer) => unknown) | null;
|
|
29
|
-
tagElement: ((element: unknown) => (chunks: unknown[]) => unknown) | null;
|
|
30
|
-
subscribe: (listener: () => void) => () => void;
|
|
31
|
-
getSnapshot: () => unknown;
|
|
32
|
-
};
|
|
33
|
-
declare function createRuntime(): Runtime;
|
|
34
|
-
declare const defaultRuntime: Runtime;
|
|
35
|
-
declare function setRuntimeResolver(next: () => Runtime): void;
|
|
36
|
-
declare function getRuntime(): Runtime;
|
|
37
|
-
declare function setTranslationGetter(getter: TranslationGetter | null): void;
|
|
38
|
-
declare function setLanguageId(languageId: string): void;
|
|
39
|
-
declare function setFormats(formats: Partial<Formats>): void;
|
|
40
|
-
declare function setGetJsxHandler(handler: Runtime['jsxHandler']): void;
|
|
41
|
-
declare const I18nRegistry: {
|
|
42
|
-
addNumberFormat(name: string, format: FormatFactory<Intl.NumberFormatOptions>): void;
|
|
43
|
-
addDateFormat(name: string, format: FormatFactory<Intl.DateTimeFormatOptions>): void;
|
|
44
|
-
addTimeFormat(name: string, format: FormatFactory<Intl.DateTimeFormatOptions>): void;
|
|
45
|
-
setLanguageId: typeof setLanguageId;
|
|
46
|
-
getConfig(): RegistryConfig;
|
|
47
|
-
};
|
|
48
|
-
declare function getFormats(runtime: Runtime, languageId: string): Partial<Formats>;
|
|
49
|
-
declare function noTranslate<T>(fn: () => T): T;
|
|
50
|
-
declare function createTagHandler<T, R>(handler: (chunks: Array<string | T>) => R): MessageTagHandler<T, R>;
|
|
51
|
-
/** Synchronous binding only: async callers must keep and use their own instance. */
|
|
52
|
-
declare function withRuntime<T>(runtime: Runtime, fn: () => T): T;
|
|
53
|
-
type StoredState = {
|
|
54
|
-
languageId: LanguageId;
|
|
55
|
-
};
|
|
56
|
-
type I18nStorage = {
|
|
57
|
-
read(): StoredState | null | Promise<StoredState | null>;
|
|
58
|
-
write(state: StoredState): void | Promise<void>;
|
|
59
|
-
};
|
|
60
|
-
declare function createStorageManager(initial?: I18nStorage | null): {
|
|
61
|
-
setStorage(next: I18nStorage | null): void;
|
|
62
|
-
getStorage(): I18nStorage;
|
|
63
|
-
hasStorage(): boolean;
|
|
64
|
-
};
|
|
65
|
-
declare function createLocalStorage(): I18nStorage | null;
|
|
66
|
-
type TranslationItem = {
|
|
67
|
-
id: string;
|
|
68
|
-
translation: string;
|
|
69
|
-
};
|
|
70
|
-
type TranslationRow = [id: string, translation: string] | [context: string, id: string, translation: string];
|
|
71
|
-
type CompiledTranslationItem = [id: string, message: CompactMessage];
|
|
72
|
-
type CompiledCatalogHeader = {
|
|
73
|
-
compiled: true;
|
|
74
|
-
};
|
|
75
|
-
type TranslationJsonl = string;
|
|
76
|
-
type TranslationData = unknown[] | TranslationJsonl | {
|
|
77
|
-
jsonl: TranslationJsonl;
|
|
78
|
-
};
|
|
79
|
-
type Catalog = Record<string, CompactMessage>;
|
|
80
|
-
declare function normalizeCatalog(data: TranslationData): Catalog;
|
|
81
|
-
declare function parseCatalog(data: TranslationData): {
|
|
82
|
-
catalog: Catalog;
|
|
83
|
-
compiled: boolean;
|
|
84
|
-
};
|
|
85
|
-
type TranslationLoaderArgs = {
|
|
86
|
-
languageId: LanguageId;
|
|
87
|
-
};
|
|
88
|
-
type TranslationLookupArgs = {
|
|
89
|
-
languageId: LanguageId;
|
|
90
|
-
context: MessageContext | null;
|
|
91
|
-
message: string;
|
|
92
|
-
};
|
|
93
|
-
type TranslationLoader = (args: TranslationLoaderArgs) => TranslationData | Promise<TranslationData>;
|
|
94
|
-
type TranslationModule = {
|
|
95
|
-
default: TranslationData;
|
|
96
|
-
};
|
|
97
|
-
type TranslationSource = TranslationData | TranslationModule;
|
|
98
|
-
type TranslationLoaderEntry = TranslationSource | Promise<TranslationSource> | (() => TranslationSource | Promise<TranslationSource>);
|
|
99
|
-
type TranslationLoaderMap = Record<string, TranslationLoaderEntry>;
|
|
100
|
-
declare function defineTranslationLoader(loader: TranslationLoader | TranslationLoaderMap): TranslationLoader;
|
|
101
|
-
declare function createTranslationManager(): {
|
|
102
|
-
catalogs: Record<string, Catalog>;
|
|
103
|
-
compiledCatalogs: Record<string, boolean>;
|
|
104
|
-
setTranslationLoader: (next: TranslationLoader | null) => void;
|
|
105
|
-
loadTranslations: (languageId: string) => Promise<void>;
|
|
106
|
-
getTranslation: (args: TranslationLookupArgs) => CompactMessage;
|
|
107
|
-
};
|
|
108
|
-
type StateData = {
|
|
109
|
-
languageId: string;
|
|
110
|
-
isLoading: boolean;
|
|
111
|
-
ready: boolean;
|
|
112
|
-
};
|
|
113
|
-
type I18nManagerOptions = {
|
|
114
|
-
languageId: string;
|
|
115
|
-
fallbackLanguageId?: string;
|
|
116
|
-
};
|
|
117
|
-
type CreateI18nManagerOptions = {
|
|
118
|
-
storage?: I18nStorage | null;
|
|
119
|
-
runtime?: Runtime;
|
|
120
|
-
};
|
|
121
|
-
type GetTranslationArgs = {
|
|
122
|
-
languageId?: string;
|
|
123
|
-
context?: string | null;
|
|
124
|
-
message: string;
|
|
125
|
-
};
|
|
126
|
-
type I18nSnapshot = {
|
|
127
|
-
languageId: string;
|
|
128
|
-
fallbackLanguageId?: string;
|
|
129
|
-
translations: Record<string, Catalog>;
|
|
130
|
-
formats?: Partial<Formats>;
|
|
131
|
-
compiledLanguages?: string[];
|
|
132
|
-
};
|
|
133
|
-
declare function createI18nManager(options?: CreateI18nManagerOptions): {
|
|
134
|
-
manager: {
|
|
135
|
-
configure: (config: I18nManagerOptions) => void;
|
|
136
|
-
setStorage: (next: I18nStorage | null) => void;
|
|
137
|
-
setTranslationLoader: (loader: TranslationLoader | null) => void;
|
|
138
|
-
init: () => Promise<void>;
|
|
139
|
-
setLanguageId: (languageId: string) => Promise<void>;
|
|
140
|
-
getLanguageId: () => string;
|
|
141
|
-
getTranslation: (args: GetTranslationArgs) => CompactMessage | null;
|
|
142
|
-
getSnapshot: () => I18nSnapshot;
|
|
143
|
-
hydrate: (snapshot: I18nSnapshot) => void;
|
|
144
|
-
};
|
|
145
|
-
state: StateManager<StateData>;
|
|
146
|
-
runtime: Runtime;
|
|
147
|
-
};
|
|
148
|
-
type ManagedI18n = ReturnType<typeof createI18nManager>;
|
|
149
|
-
type I18nManager = ManagedI18n['manager'];
|
|
150
|
-
declare const defaultManaged: {
|
|
151
|
-
manager: {
|
|
152
|
-
configure: (config: I18nManagerOptions) => void;
|
|
153
|
-
setStorage: (next: I18nStorage | null) => void;
|
|
154
|
-
setTranslationLoader: (loader: TranslationLoader | null) => void;
|
|
155
|
-
init: () => Promise<void>;
|
|
156
|
-
setLanguageId: (languageId: string) => Promise<void>;
|
|
157
|
-
getLanguageId: () => string;
|
|
158
|
-
getTranslation: (args: GetTranslationArgs) => CompactMessage | null;
|
|
159
|
-
getSnapshot: () => I18nSnapshot;
|
|
160
|
-
hydrate: (snapshot: I18nSnapshot) => void;
|
|
161
|
-
};
|
|
162
|
-
state: StateManager<StateData>;
|
|
163
|
-
runtime: Runtime;
|
|
164
|
-
};
|
|
165
|
-
declare const I18nManager: {
|
|
166
|
-
configure: (config: I18nManagerOptions) => void;
|
|
167
|
-
setStorage: (next: I18nStorage | null) => void;
|
|
168
|
-
setTranslationLoader: (loader: TranslationLoader | null) => void;
|
|
169
|
-
init: () => Promise<void>;
|
|
170
|
-
setLanguageId: (languageId: string) => Promise<void>;
|
|
171
|
-
getLanguageId: () => string;
|
|
172
|
-
getTranslation: (args: GetTranslationArgs) => CompactMessage | null;
|
|
173
|
-
getSnapshot: () => I18nSnapshot;
|
|
174
|
-
hydrate: (snapshot: I18nSnapshot) => void;
|
|
175
|
-
};
|
|
176
|
-
declare const defaultI18nState: StateManager<StateData>;
|
|
177
|
-
export { createStateManager as $, StoredState as A, createRuntime as B, TranslationData as C, normalizeCatalog as D, TranslationRow as E, Formats as F, noTranslate as G, defaultRuntime as H, I18nRegistry as I, setLanguageId as J, setFormats as K, PartsRenderer as L, createStorageManager as M, FormatContext as N, parseCatalog as O, FormatFactory as P, StateManager as Q, RegistryConfig as R, CompiledTranslationItem as S, TranslationJsonl as T, getFormats as U, createTagHandler as V, getRuntime as W, setTranslationGetter as X, setRuntimeResolver as Y, withRuntime as Z, TranslationSource as _, I18nSnapshot as a, Catalog as b, createI18nManager as c, TranslationLoader as d, TranslationLoaderArgs as f, TranslationModule as g, TranslationLookupArgs as h, I18nManagerOptions as i, createLocalStorage as j, I18nStorage as k, defaultI18nState as l, TranslationLoaderMap as m, GetTranslationArgs as n, ManagedI18n as o, TranslationLoaderEntry as p, setGetJsxHandler as q, I18nManager as r, StateData as s, CreateI18nManagerOptions as t, defaultManaged as u, createTranslationManager as v, TranslationItem as w, CompiledCatalogHeader as x, defineTranslationLoader as y, Runtime as z };
|
|
178
|
-
//# sourceMappingURL=adapter-CWC8rng-.d.ts.map
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import "@babel/types";
|
|
2
|
-
import "@babel/traverse";
|
|
3
|
-
type Scope = {
|
|
4
|
-
context: string | null;
|
|
5
|
-
notes: string[];
|
|
6
|
-
meta?: unknown;
|
|
7
|
-
};
|
|
8
|
-
type ExtractedMessage = Scope & {
|
|
9
|
-
id: string;
|
|
10
|
-
source: string;
|
|
11
|
-
};
|
|
12
|
-
declare function collectMessages(code: string, filename: string, imports?: string[]): ExtractedMessage[];
|
|
13
|
-
export { collectMessages as n, ExtractedMessage as t };
|
|
14
|
-
//# sourceMappingURL=analyze-CdXCxQDg.d.ts.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
/** Compact message format v1. Strings are literal messages or literal parts. */
|
|
2
|
-
type CompactMessage = string | CompactPart[];
|
|
3
|
-
type CompactPart = string | [0, string] | [1, string, string | Record<string, unknown> | null] | [2 | 3, string, string | Record<string, unknown> | null] | [4, string, Record<string, CompactMessage>] | [5, string, number, 0 | 1, Record<string, CompactMessage>] | [6] | [7, string, CompactMessage];
|
|
4
|
-
declare const COMPACT_VERSION = 1;
|
|
5
|
-
declare function validateCompact(value: unknown, depth?: number): asserts value is CompactMessage;
|
|
6
|
-
export { validateCompact as i, CompactMessage as n, CompactPart as r, COMPACT_VERSION as t };
|
|
7
|
-
//# sourceMappingURL=compact-CJ0OWoIv.d.ts.map
|
|
@@ -1,365 +0,0 @@
|
|
|
1
|
-
import * as generatorModule from "@babel/generator";
|
|
2
|
-
import * as b from "@babel/types";
|
|
3
|
-
import { parse } from "@babel/parser";
|
|
4
|
-
import * as traverseModule from "@babel/traverse";
|
|
5
|
-
import { TYPE, parse as parse$1 } from "@formatjs/icu-messageformat-parser";
|
|
6
|
-
import { createHash } from "node:crypto";
|
|
7
|
-
// src/compiler/analyze.ts
|
|
8
|
-
const traverse = traverseModule.default.default ?? traverseModule.default;
|
|
9
|
-
const importMap = {
|
|
10
|
-
"@fluentic/i18n": "@fluentic/i18n/compiled",
|
|
11
|
-
"@fluentic/i18n/core": "@fluentic/i18n/compiled"
|
|
12
|
-
};
|
|
13
|
-
function parseSource(code, filename) {
|
|
14
|
-
return parse(code, {
|
|
15
|
-
sourceFilename: filename,
|
|
16
|
-
sourceType: "unambiguous",
|
|
17
|
-
plugins: [
|
|
18
|
-
.../\.[cm]?tsx?$/.test(filename) ? ["typescript"] : [],
|
|
19
|
-
...!/\.[cm]?ts$/.test(filename) ? ["jsx"] : [],
|
|
20
|
-
"decorators-legacy",
|
|
21
|
-
"importAttributes"
|
|
22
|
-
]
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
function unwrap(path) {
|
|
26
|
-
while (path.isTSAsExpression() || path.isTSSatisfiesExpression() || path.isTSNonNullExpression() || path.isTypeCastExpression() || path.isParenthesizedExpression()) path = path.get("expression");
|
|
27
|
-
return path;
|
|
28
|
-
}
|
|
29
|
-
function literal(path, seen = /* @__PURE__ */ new Set()) {
|
|
30
|
-
path = unwrap(path);
|
|
31
|
-
if (path.isStringLiteral()) return path.node.value;
|
|
32
|
-
if (path.isTemplateLiteral() && !path.node.expressions.length) return path.node.quasis[0].value.cooked ?? "";
|
|
33
|
-
if (path.isIdentifier()) {
|
|
34
|
-
const binding = path.scope.getBinding(path.node.name);
|
|
35
|
-
if (binding?.constant && binding.path.isVariableDeclarator() && !seen.has(binding)) {
|
|
36
|
-
seen.add(binding);
|
|
37
|
-
return literal(binding.path.get("init"), seen);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
return null;
|
|
41
|
-
}
|
|
42
|
-
function memberName(path) {
|
|
43
|
-
if (!path.isMemberExpression()) return null;
|
|
44
|
-
const property = path.get("property");
|
|
45
|
-
return !path.node.computed && property.isIdentifier() ? property.node.name : property.isStringLiteral() ? property.node.value : null;
|
|
46
|
-
}
|
|
47
|
-
function analyzer(imports = Object.keys(importMap)) {
|
|
48
|
-
const memo = /* @__PURE__ */ new Map();
|
|
49
|
-
const scopedBindings = /* @__PURE__ */ new Set();
|
|
50
|
-
const scopeCalls = /* @__PURE__ */ new Set();
|
|
51
|
-
const resolve = (path, visiting = /* @__PURE__ */ new Set()) => {
|
|
52
|
-
path = unwrap(path);
|
|
53
|
-
if (path.isIdentifier()) {
|
|
54
|
-
const binding = path.scope.getBinding(path.node.name);
|
|
55
|
-
if (!binding) return null;
|
|
56
|
-
if (memo.has(binding)) return memo.get(binding);
|
|
57
|
-
if (visiting.has(binding)) throw new Error("[i18n] circular translator alias");
|
|
58
|
-
if (binding.path.isImportSpecifier()) {
|
|
59
|
-
const declaration = binding.path.parentPath;
|
|
60
|
-
const imported = binding.path.node.imported;
|
|
61
|
-
return declaration.isImportDeclaration() && imports.includes(declaration.node.source.value) && (b.isIdentifier(imported) ? imported.name : imported.value) === "t" && declaration.node.importKind !== "type" ? {
|
|
62
|
-
context: null,
|
|
63
|
-
notes: []
|
|
64
|
-
} : null;
|
|
65
|
-
}
|
|
66
|
-
if (binding.path.isVariableDeclarator()) {
|
|
67
|
-
visiting.add(binding);
|
|
68
|
-
const scope = resolve(binding.path.get("init"), visiting);
|
|
69
|
-
visiting.delete(binding);
|
|
70
|
-
if (scope && !binding.constant) throw new Error("[i18n] translator aliases must not be reassigned: " + path.node.name);
|
|
71
|
-
memo.set(binding, scope);
|
|
72
|
-
if (scope) scopedBindings.add(binding);
|
|
73
|
-
return scope;
|
|
74
|
-
}
|
|
75
|
-
return null;
|
|
76
|
-
}
|
|
77
|
-
if (path.isMemberExpression() && memberName(path) === "t") {
|
|
78
|
-
const object = path.get("object");
|
|
79
|
-
if (!object.isIdentifier()) return null;
|
|
80
|
-
const binding = object.scope.getBinding(object.node.name);
|
|
81
|
-
const declaration = binding?.path.parentPath;
|
|
82
|
-
if (binding?.path.isImportNamespaceSpecifier() && declaration?.isImportDeclaration() && imports.includes(declaration.node.source.value)) return {
|
|
83
|
-
context: null,
|
|
84
|
-
notes: []
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
|
-
if (!path.isCallExpression()) return null;
|
|
88
|
-
const callee = path.get("callee");
|
|
89
|
-
const method = memberName(callee);
|
|
90
|
-
if (!method || ![
|
|
91
|
-
"context",
|
|
92
|
-
"note",
|
|
93
|
-
"meta"
|
|
94
|
-
].includes(method)) return null;
|
|
95
|
-
const parent = resolve(callee.get("object"), visiting);
|
|
96
|
-
if (!parent) return null;
|
|
97
|
-
if (path.node.arguments.length !== 1) throw new Error("[i18n] scope methods require one static argument");
|
|
98
|
-
const argument = path.get("arguments.0");
|
|
99
|
-
scopeCalls.add(path);
|
|
100
|
-
if (method === "meta") {
|
|
101
|
-
const evaluated = argument.evaluate();
|
|
102
|
-
if (!evaluated.confident) throw new Error("[i18n] metadata must be statically known");
|
|
103
|
-
return {
|
|
104
|
-
...parent,
|
|
105
|
-
meta: evaluated.value
|
|
106
|
-
};
|
|
107
|
-
}
|
|
108
|
-
const value = literal(argument);
|
|
109
|
-
if (value === null) throw new Error("[i18n] " + method + " must be a static string");
|
|
110
|
-
return method === "note" ? {
|
|
111
|
-
...parent,
|
|
112
|
-
notes: [...parent.notes, value]
|
|
113
|
-
} : {
|
|
114
|
-
...parent,
|
|
115
|
-
context: parent.context ? `${parent.context}.${value}` : value
|
|
116
|
-
};
|
|
117
|
-
};
|
|
118
|
-
return {
|
|
119
|
-
resolve,
|
|
120
|
-
scopedBindings,
|
|
121
|
-
scopeCalls
|
|
122
|
-
};
|
|
123
|
-
}
|
|
124
|
-
function collectMessages(code, filename, imports) {
|
|
125
|
-
const ast = parseSource(code, filename);
|
|
126
|
-
const { resolve } = analyzer(imports);
|
|
127
|
-
const messages = [];
|
|
128
|
-
traverse(ast, { CallExpression(path) {
|
|
129
|
-
const callee = path.get("callee");
|
|
130
|
-
const method = memberName(callee);
|
|
131
|
-
if (!method || ![
|
|
132
|
-
"msg",
|
|
133
|
-
"text",
|
|
134
|
-
"jsx"
|
|
135
|
-
].includes(method)) return;
|
|
136
|
-
const scope = resolve(callee.get("object"));
|
|
137
|
-
if (!scope) return;
|
|
138
|
-
const source = literal(path.get("arguments.0"));
|
|
139
|
-
if (source === null) {
|
|
140
|
-
if (method === "msg") throw new Error(`[i18n] ${filename}:${path.node.loc?.start.line}: t.msg requires a static message`);
|
|
141
|
-
return;
|
|
142
|
-
}
|
|
143
|
-
messages.push({
|
|
144
|
-
...scope,
|
|
145
|
-
id: scope.context ? `${scope.context}\0${source}` : source,
|
|
146
|
-
source
|
|
147
|
-
});
|
|
148
|
-
} });
|
|
149
|
-
return [...new Map(messages.map((message) => [message.id, message])).values()];
|
|
150
|
-
}
|
|
151
|
-
// src/compiler/message.ts
|
|
152
|
-
function messageIdentity(context, source) {
|
|
153
|
-
return context ? `${context}\0${source}` : source;
|
|
154
|
-
}
|
|
155
|
-
function messageId(context, source) {
|
|
156
|
-
return createHash("sha256").update(messageIdentity(context, source)).digest("hex").slice(0, 24);
|
|
157
|
-
}
|
|
158
|
-
function compileMessage(source) {
|
|
159
|
-
const compact = (elements) => {
|
|
160
|
-
const result = elements.map((element) => {
|
|
161
|
-
switch (element.type) {
|
|
162
|
-
case TYPE.literal: return element.value;
|
|
163
|
-
case TYPE.argument: return [0, element.value];
|
|
164
|
-
case TYPE.number:
|
|
165
|
-
case TYPE.date:
|
|
166
|
-
case TYPE.time: return [
|
|
167
|
-
element.type === TYPE.number ? 1 : element.type === TYPE.date ? 2 : 3,
|
|
168
|
-
element.value,
|
|
169
|
-
typeof element.style === "object" && element.style ? element.style.parsedOptions : element.style ?? null
|
|
170
|
-
];
|
|
171
|
-
case TYPE.select: return [
|
|
172
|
-
4,
|
|
173
|
-
element.value,
|
|
174
|
-
Object.fromEntries(Object.entries(element.options).map(([key, option]) => [key, compact(option.value)]))
|
|
175
|
-
];
|
|
176
|
-
case TYPE.plural: return [
|
|
177
|
-
5,
|
|
178
|
-
element.value,
|
|
179
|
-
element.offset,
|
|
180
|
-
element.pluralType === "ordinal" ? 1 : 0,
|
|
181
|
-
Object.fromEntries(Object.entries(element.options).map(([key, option]) => [key, compact(option.value)]))
|
|
182
|
-
];
|
|
183
|
-
case TYPE.pound: return [6];
|
|
184
|
-
case TYPE.tag: return [
|
|
185
|
-
7,
|
|
186
|
-
element.value,
|
|
187
|
-
compact(element.children)
|
|
188
|
-
];
|
|
189
|
-
}
|
|
190
|
-
});
|
|
191
|
-
return result.every((part) => typeof part === "string") ? result.join("") : result;
|
|
192
|
-
};
|
|
193
|
-
return compact(parse$1(source, { captureLocation: false }));
|
|
194
|
-
}
|
|
195
|
-
function compileCatalog(records) {
|
|
196
|
-
const seen = /* @__PURE__ */ new Map();
|
|
197
|
-
return records.flatMap((record) => {
|
|
198
|
-
const id = messageId(record.context, record.source);
|
|
199
|
-
const identity = messageIdentity(record.context, record.source);
|
|
200
|
-
if (seen.has(id) && seen.get(id) !== identity) throw new Error("[i18n] message hash collision: " + id);
|
|
201
|
-
seen.set(id, identity);
|
|
202
|
-
return record.translation === "" ? [] : [[id, compileMessage(record.translation)]];
|
|
203
|
-
});
|
|
204
|
-
}
|
|
205
|
-
// src/compiler/index.ts
|
|
206
|
-
const generate = generatorModule.default.default ?? generatorModule.default;
|
|
207
|
-
function compileProgram(code, filename, options = {}) {
|
|
208
|
-
const ast = parseSource(code, filename);
|
|
209
|
-
const messages = [];
|
|
210
|
-
if (options.compiled === false) return {
|
|
211
|
-
ast,
|
|
212
|
-
messages,
|
|
213
|
-
changed: false
|
|
214
|
-
};
|
|
215
|
-
const analysis = analyzer();
|
|
216
|
-
const plans = [];
|
|
217
|
-
const declarations = [];
|
|
218
|
-
let program;
|
|
219
|
-
traverse(ast, {
|
|
220
|
-
Program(path) {
|
|
221
|
-
program = path;
|
|
222
|
-
},
|
|
223
|
-
ExportAllDeclaration(path) {
|
|
224
|
-
if (importMap[path.node.source.value]) throw new Error("[i18n] do not re-export the translator in compiled mode; import t directly at each use");
|
|
225
|
-
},
|
|
226
|
-
ExportNamedDeclaration(path) {
|
|
227
|
-
if (path.node.source && importMap[path.node.source.value] && path.node.specifiers.some((specifier) => b.isExportSpecifier(specifier) && (b.isIdentifier(specifier.local) ? specifier.local.name : "") === "t")) throw new Error("[i18n] do not re-export the translator in compiled mode; export message descriptors instead");
|
|
228
|
-
},
|
|
229
|
-
ImportDeclaration(path) {
|
|
230
|
-
if (importMap[path.node.source.value] && path.node.importKind !== "type") declarations.push(path);
|
|
231
|
-
},
|
|
232
|
-
CallExpression(path) {
|
|
233
|
-
const callee = path.get("callee");
|
|
234
|
-
const method = memberName(callee);
|
|
235
|
-
if (!method || ![
|
|
236
|
-
"msg",
|
|
237
|
-
"jsx",
|
|
238
|
-
"text"
|
|
239
|
-
].includes(method)) return;
|
|
240
|
-
const scope = analysis.resolve(callee.get("object"));
|
|
241
|
-
if (!scope) return;
|
|
242
|
-
const source = literal(path.get("arguments.0"));
|
|
243
|
-
if (source === null && method === "msg") throw new Error(`[i18n] ${filename}:${path.node.loc?.start.line}: t.msg requires a static message`);
|
|
244
|
-
plans.push({
|
|
245
|
-
path,
|
|
246
|
-
source,
|
|
247
|
-
scope
|
|
248
|
-
});
|
|
249
|
-
if (source !== null) messages.push({
|
|
250
|
-
...scope,
|
|
251
|
-
source,
|
|
252
|
-
id: scope.context ? `${scope.context}\0${source}` : source
|
|
253
|
-
});
|
|
254
|
-
}
|
|
255
|
-
});
|
|
256
|
-
traverse(ast, {
|
|
257
|
-
VariableDeclarator(path) {
|
|
258
|
-
analysis.resolve(path.get("id"));
|
|
259
|
-
},
|
|
260
|
-
CallExpression(path) {
|
|
261
|
-
const name = memberName(path.get("callee"));
|
|
262
|
-
if (name && [
|
|
263
|
-
"context",
|
|
264
|
-
"note",
|
|
265
|
-
"meta"
|
|
266
|
-
].includes(name)) analysis.resolve(path);
|
|
267
|
-
}
|
|
268
|
-
});
|
|
269
|
-
const expressionUse = (path) => {
|
|
270
|
-
while (path.parentPath && (path.parentPath.isTSAsExpression() || path.parentPath.isTSSatisfiesExpression() || path.parentPath.isTSNonNullExpression() || path.parentPath.isTypeCastExpression() || path.parentPath.isParenthesizedExpression())) path = path.parentPath;
|
|
271
|
-
return path;
|
|
272
|
-
};
|
|
273
|
-
for (const path of analysis.scopeCalls) {
|
|
274
|
-
const use = expressionUse(path);
|
|
275
|
-
const parent = use.parentPath;
|
|
276
|
-
if (parent?.isVariableDeclarator() || parent?.isExpressionStatement()) continue;
|
|
277
|
-
if (parent?.isMemberExpression() && parent.get("object") === use && parent.parentPath?.isCallExpression()) continue;
|
|
278
|
-
throw new Error("[i18n] scoped translator escapes same-file message calls");
|
|
279
|
-
}
|
|
280
|
-
for (const binding of analysis.scopedBindings) {
|
|
281
|
-
if (binding.path.parentPath?.parentPath?.isExportNamedDeclaration()) throw new Error("[i18n] scoped translators cannot be exported; repeat the context in the consuming file");
|
|
282
|
-
for (const reference of binding.referencePaths) {
|
|
283
|
-
if (reference.findParent((parent) => parent.isTSType())) continue;
|
|
284
|
-
const use = expressionUse(reference);
|
|
285
|
-
const parent = use.parentPath;
|
|
286
|
-
if (parent?.isVariableDeclarator() && parent.get("init") === use) continue;
|
|
287
|
-
if (parent?.isMemberExpression() && parent.get("object") === use) {
|
|
288
|
-
const method = memberName(parent);
|
|
289
|
-
if (method && [
|
|
290
|
-
"msg",
|
|
291
|
-
"text",
|
|
292
|
-
"jsx",
|
|
293
|
-
"context",
|
|
294
|
-
"note",
|
|
295
|
-
"meta"
|
|
296
|
-
].includes(method) && parent.parentPath?.isCallExpression()) continue;
|
|
297
|
-
}
|
|
298
|
-
throw new Error("[i18n] scoped translator escapes same-file message calls: " + binding.identifier.name);
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
if (!declarations.length) return {
|
|
302
|
-
ast,
|
|
303
|
-
messages,
|
|
304
|
-
changed: false
|
|
305
|
-
};
|
|
306
|
-
const helper = program.scope.generateUidIdentifier("tc");
|
|
307
|
-
if (plans.length) program.unshiftContainer("body", b.importDeclaration([b.importSpecifier(helper, b.identifier("t"))], b.stringLiteral("@fluentic/i18n/compiled")));
|
|
308
|
-
for (const { path, source, scope } of plans) {
|
|
309
|
-
path.get("callee").get("object").replaceWith(b.cloneNode(helper));
|
|
310
|
-
if (source !== null) {
|
|
311
|
-
const replacement = b.valueToNode([messageId(scope.context, source), compileMessage(source)]);
|
|
312
|
-
b.inherits(replacement, path.node.arguments[0]);
|
|
313
|
-
path.node.arguments[0] = replacement;
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
let removed = true;
|
|
317
|
-
while (removed) {
|
|
318
|
-
removed = false;
|
|
319
|
-
program.scope.crawl();
|
|
320
|
-
for (const binding of analysis.scopedBindings) {
|
|
321
|
-
if (binding.path.removed) continue;
|
|
322
|
-
const current = binding.path.scope.getBinding(binding.identifier.name);
|
|
323
|
-
if (current && !current.referenced) {
|
|
324
|
-
binding.path.remove();
|
|
325
|
-
removed = true;
|
|
326
|
-
}
|
|
327
|
-
}
|
|
328
|
-
}
|
|
329
|
-
for (const path of analysis.scopeCalls) if (!path.removed) {
|
|
330
|
-
const use = expressionUse(path);
|
|
331
|
-
if (use.parentPath?.isExpressionStatement()) use.parentPath.remove();
|
|
332
|
-
}
|
|
333
|
-
for (const declaration of declarations) declaration.node.source.value = importMap[declaration.node.source.value];
|
|
334
|
-
program.scope.crawl();
|
|
335
|
-
for (const declaration of declarations) {
|
|
336
|
-
declaration.node.specifiers = declaration.node.specifiers.filter((specifier) => {
|
|
337
|
-
if (!b.isImportSpecifier(specifier) || (b.isIdentifier(specifier.imported) ? specifier.imported.name : specifier.imported.value) !== "t") return true;
|
|
338
|
-
return Boolean(program.scope.getBinding(specifier.local.name)?.referenced);
|
|
339
|
-
});
|
|
340
|
-
if (!declaration.node.specifiers.length) declaration.remove();
|
|
341
|
-
}
|
|
342
|
-
return {
|
|
343
|
-
ast,
|
|
344
|
-
messages,
|
|
345
|
-
changed: true
|
|
346
|
-
};
|
|
347
|
-
}
|
|
348
|
-
function transform(code, options = {}) {
|
|
349
|
-
const filename = options.filename ?? "source.tsx";
|
|
350
|
-
const result = compileProgram(code, filename, options);
|
|
351
|
-
if (!result.changed) return null;
|
|
352
|
-
const output = generate(result.ast, {
|
|
353
|
-
sourceMaps: true,
|
|
354
|
-
sourceFileName: filename,
|
|
355
|
-
comments: true
|
|
356
|
-
}, code);
|
|
357
|
-
return {
|
|
358
|
-
code: output.code,
|
|
359
|
-
map: output.map,
|
|
360
|
-
messages: result.messages
|
|
361
|
-
};
|
|
362
|
-
}
|
|
363
|
-
export { messageId as a, traverse as c, compileMessage as i, transform as n, messageIdentity as o, compileCatalog as r, collectMessages as s, compileProgram as t };
|
|
364
|
-
|
|
365
|
-
//# sourceMappingURL=compiler-BZtB9WLi.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"compiler-BZtB9WLi.js","names":["parse"],"sources":["../src/compiler/analyze.ts","../src/compiler/message.ts","../src/compiler/index.ts"],"sourcesContent":["import { parse } from '@babel/parser';\nimport * as traverseModule from '@babel/traverse';\nimport type { Binding, NodePath } from '@babel/traverse';\nimport * as b from '@babel/types';\n\nconst traverse = ((traverseModule.default as unknown as { default?: typeof traverseModule.default; }).default ??\n traverseModule.default) as typeof traverseModule.default;\nexport { traverse };\n\nexport const importMap: Record<string, string> = {\n '@fluentic/i18n': '@fluentic/i18n/compiled',\n '@fluentic/i18n/core': '@fluentic/i18n/compiled',\n};\nexport type Scope = { context: string | null; notes: string[]; meta?: unknown; };\nexport type ExtractedMessage = Scope & { id: string; source: string; };\n\nexport function parseSource(code: string, filename: string) {\n return parse(code, {\n sourceFilename: filename,\n sourceType: 'unambiguous',\n plugins: [\n ...(/\\.[cm]?tsx?$/.test(filename) ? ['typescript' as const] : []),\n ...(!/\\.[cm]?ts$/.test(filename) ? ['jsx' as const] : []),\n 'decorators-legacy',\n 'importAttributes',\n ],\n });\n}\n\nexport function unwrap(path: NodePath): NodePath {\n while (\n path.isTSAsExpression() || path.isTSSatisfiesExpression() || path.isTSNonNullExpression() ||\n path.isTypeCastExpression() || path.isParenthesizedExpression()\n ) path = path.get('expression') as NodePath;\n\n return path;\n}\n\nexport function literal(path: NodePath, seen = new Set<Binding>()): string | null {\n path = unwrap(path);\n if (path.isStringLiteral()) return path.node.value;\n if (path.isTemplateLiteral() && !path.node.expressions.length) return path.node.quasis[0].value.cooked ?? '';\n if (path.isIdentifier()) {\n const binding = path.scope.getBinding(path.node.name);\n\n if (binding?.constant && binding.path.isVariableDeclarator() && !seen.has(binding)) {\n seen.add(binding);\n\n return literal(binding.path.get('init') as NodePath, seen);\n }\n }\n\n return null;\n}\n\nexport function memberName(path: NodePath): string | null {\n if (!path.isMemberExpression()) return null;\n\n const property = path.get('property');\n\n return !path.node.computed && property.isIdentifier()\n ? property.node.name\n : property.isStringLiteral()\n ? property.node.value\n : null;\n}\n\nexport function analyzer(imports = Object.keys(importMap)) {\n const memo = new Map<Binding, Scope | null>();\n const scopedBindings = new Set<Binding>();\n const scopeCalls = new Set<NodePath>();\n\n const resolve = (path: NodePath, visiting = new Set<Binding>()): Scope | null => {\n path = unwrap(path);\n if (path.isIdentifier()) {\n const binding = path.scope.getBinding(path.node.name);\n\n if (!binding) return null;\n if (memo.has(binding)) return memo.get(binding)!;\n if (visiting.has(binding)) throw new Error('[i18n] circular translator alias');\n if (binding.path.isImportSpecifier()) {\n const declaration = binding.path.parentPath;\n const imported = binding.path.node.imported;\n\n return declaration.isImportDeclaration() && imports.includes(declaration.node.source.value) &&\n (b.isIdentifier(imported) ? imported.name : imported.value) === 't' &&\n declaration.node.importKind !== 'type'\n ? { context: null, notes: [] }\n : null;\n }\n if (binding.path.isVariableDeclarator()) {\n visiting.add(binding);\n const scope = resolve(binding.path.get('init') as NodePath, visiting);\n visiting.delete(binding);\n if (scope && !binding.constant) {\n throw new Error('[i18n] translator aliases must not be reassigned: ' + path.node.name);\n }\n memo.set(binding, scope);\n if (scope) scopedBindings.add(binding);\n\n return scope;\n }\n\n return null;\n }\n if (path.isMemberExpression() && memberName(path) === 't') {\n const object = path.get('object');\n\n if (!object.isIdentifier()) return null;\n\n const binding = object.scope.getBinding(object.node.name);\n const declaration = binding?.path.parentPath;\n\n if (\n binding?.path.isImportNamespaceSpecifier() && declaration?.isImportDeclaration() &&\n imports.includes(declaration.node.source.value)\n ) return { context: null, notes: [] };\n }\n if (!path.isCallExpression()) return null;\n\n const callee = path.get('callee');\n const method = memberName(callee);\n\n if (!method || !['context', 'note', 'meta'].includes(method)) return null;\n\n const parent = resolve((callee as NodePath<b.MemberExpression>).get('object'), visiting);\n\n if (!parent) return null;\n if (path.node.arguments.length !== 1) throw new Error('[i18n] scope methods require one static argument');\n\n const argument = path.get('arguments.0') as NodePath;\n scopeCalls.add(path);\n if (method === 'meta') {\n const evaluated = argument.evaluate();\n\n if (!evaluated.confident) throw new Error('[i18n] metadata must be statically known');\n\n return { ...parent, meta: evaluated.value };\n }\n\n const value = literal(argument);\n\n if (value === null) throw new Error('[i18n] ' + method + ' must be a static string');\n\n return method === 'note'\n ? { ...parent, notes: [...parent.notes, value] }\n : { ...parent, context: parent.context ? `${parent.context}.${value}` : value };\n };\n\n return { resolve, scopedBindings, scopeCalls };\n}\n\nexport function collectMessages(code: string, filename: string, imports?: string[]): ExtractedMessage[] {\n const ast = parseSource(code, filename);\n const { resolve } = analyzer(imports);\n const messages: ExtractedMessage[] = [];\n traverse(ast, {\n CallExpression(path) {\n const callee = path.get('callee');\n const method = memberName(callee);\n\n if (!method || !['msg', 'text', 'jsx'].includes(method)) return;\n\n const scope = resolve((callee as NodePath<b.MemberExpression>).get('object'));\n\n if (!scope) return;\n\n const source = literal(path.get('arguments.0') as NodePath);\n\n if (source === null) {\n if (method === 'msg') {\n throw new Error(`[i18n] ${filename}:${path.node.loc?.start.line}: t.msg requires a static message`);\n }\n\n return;\n }\n messages.push({ ...scope, id: scope.context ? `${scope.context}\\0${source}` : source, source });\n },\n });\n\n return [...new Map(messages.map((message) => [message.id, message])).values()];\n}\n","import { type MessageFormatElement, parse, TYPE } from '@formatjs/icu-messageformat-parser';\nimport { createHash } from 'node:crypto';\nimport type { CompactMessage, CompactPart } from '../shared/compact';\n\nexport { COMPACT_VERSION } from '../shared/compact';\n\nexport function messageIdentity(context: string | null, source: string): string {\n return context ? `${context}\\0${source}` : source;\n}\n\nexport function messageId(context: string | null, source: string): string {\n return createHash('sha256').update(messageIdentity(context, source)).digest('hex').slice(0, 24);\n}\n\nexport function compileMessage(source: string): CompactMessage {\n const compact = (elements: MessageFormatElement[]): CompactMessage => {\n const result: CompactPart[] = elements.map((element): CompactPart => {\n switch (element.type) {\n case TYPE.literal:\n return element.value;\n case TYPE.argument:\n return [0, element.value];\n case TYPE.number:\n case TYPE.date:\n case TYPE.time:\n return [\n element.type === TYPE.number ? 1 : element.type === TYPE.date ? 2 : 3,\n element.value,\n typeof element.style === 'object' && element.style\n ? element.style.parsedOptions as Record<string, unknown>\n : element.style ?? null,\n ];\n case TYPE.select:\n return [\n 4,\n element.value,\n Object.fromEntries(Object.entries(element.options).map(([key, option]) => [key, compact(option.value)])),\n ];\n case TYPE.plural:\n return [\n 5,\n element.value,\n element.offset,\n element.pluralType === 'ordinal' ? 1 : 0,\n Object.fromEntries(Object.entries(element.options).map(([key, option]) => [key, compact(option.value)])),\n ];\n case TYPE.pound:\n return [6];\n case TYPE.tag:\n return [7, element.value, compact(element.children)];\n }\n });\n\n return result.every((part) => typeof part === 'string') ? result.join('') : result;\n };\n\n return compact(parse(source, { captureLocation: false }));\n}\n\nexport function compileCatalog(\n records: Array<{ source: string; context: string | null; translation: string; }>,\n): Array<[string, CompactMessage]> {\n const seen = new Map<string, string>();\n\n return records.flatMap((record) => {\n const id = messageId(record.context, record.source);\n const identity = messageIdentity(record.context, record.source);\n\n if (seen.has(id) && seen.get(id) !== identity) throw new Error('[i18n] message hash collision: ' + id);\n seen.set(id, identity);\n\n return record.translation === '' ? [] : [[id, compileMessage(record.translation)] as [string, CompactMessage]];\n });\n}\n","import * as generatorModule from '@babel/generator';\nimport type { NodePath } from '@babel/traverse';\nimport * as b from '@babel/types';\nimport {\n analyzer,\n collectMessages,\n type ExtractedMessage,\n importMap,\n literal,\n memberName,\n parseSource,\n traverse,\n} from './analyze';\nimport { compileMessage, messageId } from './message';\n\nexport { collectMessages } from './analyze';\nexport * from './message';\n\nconst generate = ((generatorModule.default as unknown as { default?: typeof generatorModule.default; }).default ??\n generatorModule.default) as typeof generatorModule.default;\nexport type CompilerOptions = { compiled?: boolean; filename?: string; };\n\nexport function compileProgram(code: string, filename: string, options: CompilerOptions = {}) {\n const ast = parseSource(code, filename);\n const messages: ExtractedMessage[] = [];\n\n if (options.compiled === false) return { ast, messages, changed: false };\n\n const analysis = analyzer();\n\n const plans: Array<\n {\n path: NodePath<b.CallExpression>;\n source: string | null;\n scope: NonNullable<ReturnType<typeof analysis.resolve>>;\n }\n > = [];\n const declarations: NodePath<b.ImportDeclaration>[] = [];\n\n let program: NodePath<b.Program> | undefined;\n traverse(ast, {\n Program(path) {\n program = path;\n },\n ExportAllDeclaration(path) {\n if (importMap[path.node.source.value]) {\n throw new Error('[i18n] do not re-export the translator in compiled mode; import t directly at each use');\n }\n },\n ExportNamedDeclaration(path) {\n if (\n path.node.source && importMap[path.node.source.value] &&\n path.node.specifiers.some((specifier) =>\n b.isExportSpecifier(specifier) && (b.isIdentifier(specifier.local) ? specifier.local.name : '') === 't'\n )\n ) throw new Error('[i18n] do not re-export the translator in compiled mode; export message descriptors instead');\n },\n ImportDeclaration(path) {\n if (importMap[path.node.source.value] && path.node.importKind !== 'type') declarations.push(path);\n },\n CallExpression(path) {\n const callee = path.get('callee');\n const method = memberName(callee);\n\n if (!method || !['msg', 'jsx', 'text'].includes(method)) return;\n\n const scope = analysis.resolve((callee as NodePath<b.MemberExpression>).get('object'));\n\n if (!scope) return;\n\n const source = literal(path.get('arguments.0') as NodePath);\n\n if (source === null && method === 'msg') {\n throw new Error(`[i18n] ${filename}:${path.node.loc?.start.line}: t.msg requires a static message`);\n }\n plans.push({ path, source, scope });\n if (source !== null) {\n messages.push({ ...scope, source, id: scope.context ? `${scope.context}\\0${source}` : source });\n }\n },\n });\n // Discover unused/escaping scopes as well as scopes reached by message calls.\n traverse(ast, {\n VariableDeclarator(path) {\n analysis.resolve(path.get('id') as NodePath);\n },\n CallExpression(path) {\n const name = memberName(path.get('callee'));\n\n if (name && ['context', 'note', 'meta'].includes(name)) analysis.resolve(path);\n },\n });\n const expressionUse = (path: NodePath): NodePath => {\n while (\n path.parentPath &&\n (path.parentPath.isTSAsExpression() || path.parentPath.isTSSatisfiesExpression() ||\n path.parentPath.isTSNonNullExpression() || path.parentPath.isTypeCastExpression() ||\n path.parentPath.isParenthesizedExpression())\n ) path = path.parentPath;\n\n return path;\n };\n\n for (const path of analysis.scopeCalls) {\n const use = expressionUse(path);\n const parent = use.parentPath;\n\n if (parent?.isVariableDeclarator() || parent?.isExpressionStatement()) continue;\n if (parent?.isMemberExpression() && parent.get('object') === use && parent.parentPath?.isCallExpression()) continue;\n throw new Error('[i18n] scoped translator escapes same-file message calls');\n }\n for (const binding of analysis.scopedBindings) {\n if (binding.path.parentPath?.parentPath?.isExportNamedDeclaration()) {\n throw new Error('[i18n] scoped translators cannot be exported; repeat the context in the consuming file');\n }\n\n for (const reference of binding.referencePaths) {\n if (reference.findParent((parent) => parent.isTSType())) continue;\n\n const use = expressionUse(reference);\n const parent = use.parentPath;\n\n if (parent?.isVariableDeclarator() && parent.get('init') === use) continue;\n if (parent?.isMemberExpression() && parent.get('object') === use) {\n const method = memberName(parent);\n\n if (\n method && ['msg', 'text', 'jsx', 'context', 'note', 'meta'].includes(method) &&\n parent.parentPath?.isCallExpression()\n ) continue;\n }\n throw new Error('[i18n] scoped translator escapes same-file message calls: ' + binding.identifier.name);\n }\n }\n if (!declarations.length) return { ast, messages, changed: false };\n\n const helper = program!.scope.generateUidIdentifier('tc');\n\n if (plans.length) {\n program!.unshiftContainer(\n 'body',\n b.importDeclaration([b.importSpecifier(helper, b.identifier('t'))], b.stringLiteral('@fluentic/i18n/compiled')),\n );\n }\n\n for (const { path, source, scope } of plans) {\n const callee = path.get('callee') as NodePath<b.MemberExpression>;\n callee.get('object').replaceWith(b.cloneNode(helper));\n if (source !== null) {\n const replacement = b.valueToNode([messageId(scope.context, source), compileMessage(source)]);\n b.inherits(replacement, path.node.arguments[0]);\n path.node.arguments[0] = replacement;\n }\n }\n // All scope uses were checked before mutation. Remove aliases from leaves to roots.\n let removed = true;\n\n while (removed) {\n removed = false;\n program!.scope.crawl();\n\n for (const binding of analysis.scopedBindings) {\n if (binding.path.removed) continue;\n\n const current = binding.path.scope.getBinding(binding.identifier.name);\n\n if (current && !current.referenced) {\n binding.path.remove();\n removed = true;\n }\n }\n }\n\n for (const path of analysis.scopeCalls) {\n if (!path.removed) {\n const use = expressionUse(path);\n\n if (use.parentPath?.isExpressionStatement()) use.parentPath.remove();\n }\n }\n for (const declaration of declarations) declaration.node.source.value = importMap[declaration.node.source.value];\n program!.scope.crawl();\n\n for (const declaration of declarations) {\n declaration.node.specifiers = declaration.node.specifiers.filter((specifier) => {\n if (\n !b.isImportSpecifier(specifier) ||\n (b.isIdentifier(specifier.imported) ? specifier.imported.name : specifier.imported.value) !== 't'\n ) return true;\n\n return Boolean(program!.scope.getBinding(specifier.local.name)?.referenced);\n });\n if (!declaration.node.specifiers.length) declaration.remove();\n }\n\n return { ast, messages, changed: true };\n}\n\nexport function transform(code: string, options: CompilerOptions = {}) {\n const filename = options.filename ?? 'source.tsx';\n const result = compileProgram(code, filename, options);\n\n if (!result.changed) return null;\n\n const output = generate(result.ast, { sourceMaps: true, sourceFileName: filename, comments: true }, code);\n\n return { code: output.code, map: output.map, messages: result.messages };\n}\n"],"mappings":";;;;;;;AAKA,MAAM,WAAa,eAAe,QAAoE,WACpG,eAAe;AAGjB,MAAa,YAAoC;CAC/C,kBAAkB;CAClB,uBAAuB;AACzB;AAIA,SAAgB,YAAY,MAAc,UAAkB;CAC1D,OAAO,MAAM,MAAM;EACjB,gBAAgB;EAChB,YAAY;EACZ,SAAS;GACP,GAAI,eAAe,KAAK,QAAQ,IAAI,CAAC,YAAqB,IAAI,CAAC;GAC/D,GAAI,CAAC,aAAa,KAAK,QAAQ,IAAI,CAAC,KAAc,IAAI,CAAC;GACvD;GACA;EACF;CACF,CAAC;AACH;AAEA,SAAgB,OAAO,MAA0B;CAC/C,OACE,KAAK,iBAAiB,KAAK,KAAK,wBAAwB,K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MAAM,MAAM;CAErB,KAAK,MAAM,eAAe,cAAc;EACtC,YAAY,KAAK,aAAa,YAAY,KAAK,WAAW,QAAQ,cAAc;GAC9E,IACE,CAAC,EAAE,kBAAkB,SAAS,MAC7B,EAAE,aAAa,UAAU,QAAQ,IAAI,UAAU,SAAS,OAAO,UAAU,SAAS,WAAW,KAC9F,OAAO;GAET,OAAO,QAAQ,QAAS,MAAM,WAAW,UAAU,MAAM,IAAI,CAAC,EAAE,UAAU;EAC5E,CAAC;EACD,IAAI,CAAC,YAAY,KAAK,WAAW,QAAQ,YAAY,OAAO;CAC9D;CAEA,OAAO;EAAE;EAAK;EAAU,SAAS;CAAK;AACxC;AAEA,SAAgB,UAAU,MAAc,UAA2B,CAAC,GAAG;CACrE,MAAM,WAAW,QAAQ,YAAY;CACrC,MAAM,SAAS,eAAe,MAAM,UAAU,OAAO;CAErD,IAAI,CAAC,OAAO,SAAS,OAAO;CAE5B,MAAM,SAAS,SAAS,OAAO,KAAK;EAAE,YAAY;EAAM,gBAAgB;EAAU,UAAU;CAAK,GAAG,IAAI;CAExG,OAAO;EAAE,MAAM,OAAO;EAAM,KAAK,OAAO;EAAK,UAAU,OAAO;CAAS;AACzE"}
|
package/dist/compiler.d.ts
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { n as CompactMessage, t as COMPACT_VERSION } from "./compact-CJ0OWoIv.js";
|
|
2
|
-
import { n as collectMessages, t as ExtractedMessage } from "./analyze-CdXCxQDg.js";
|
|
3
|
-
import * as b from "@babel/types";
|
|
4
|
-
declare function messageIdentity(context: string | null, source: string): string;
|
|
5
|
-
declare function messageId(context: string | null, source: string): string;
|
|
6
|
-
declare function compileMessage(source: string): CompactMessage;
|
|
7
|
-
declare function compileCatalog(records: Array<{
|
|
8
|
-
source: string;
|
|
9
|
-
context: string | null;
|
|
10
|
-
translation: string;
|
|
11
|
-
}>): Array<[string, CompactMessage]>;
|
|
12
|
-
type CompilerOptions = {
|
|
13
|
-
compiled?: boolean;
|
|
14
|
-
filename?: string;
|
|
15
|
-
};
|
|
16
|
-
declare function compileProgram(code: string, filename: string, options?: CompilerOptions): {
|
|
17
|
-
ast: import("@babel/parser").ParseResult<b.File>;
|
|
18
|
-
messages: ExtractedMessage[];
|
|
19
|
-
changed: boolean;
|
|
20
|
-
};
|
|
21
|
-
declare function transform(code: string, options?: CompilerOptions): {
|
|
22
|
-
code: string;
|
|
23
|
-
map: {
|
|
24
|
-
version: number;
|
|
25
|
-
sources: string[];
|
|
26
|
-
names: string[];
|
|
27
|
-
sourceRoot?: string | undefined;
|
|
28
|
-
sourcesContent?: string[] | undefined;
|
|
29
|
-
mappings: string;
|
|
30
|
-
file: string;
|
|
31
|
-
} | null;
|
|
32
|
-
messages: ExtractedMessage[];
|
|
33
|
-
} | null;
|
|
34
|
-
export { COMPACT_VERSION, CompilerOptions, collectMessages, compileCatalog, compileMessage, compileProgram, messageId, messageIdentity, transform };
|
|
35
|
-
//# sourceMappingURL=compiler.d.ts.map
|
package/dist/compiler.js
DELETED
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import { t as COMPACT_VERSION } from "./compact-E3zj3Z8d.js";
|
|
2
|
-
import { a as messageId, i as compileMessage, n as transform, o as messageIdentity, r as compileCatalog, s as collectMessages, t as compileProgram } from "./compiler-BZtB9WLi.js";
|
|
3
|
-
export { COMPACT_VERSION, collectMessages, compileCatalog, compileMessage, compileProgram, messageId, messageIdentity, transform };
|