MCPcopy
hub / github.com/messageformat/messageformat / compile

Method compile

packages/messageformat/src/compiler.js:45–69  ·  view source on GitHub ↗

Recursively compile a string or a tree of strings to JavaScript function sources * * If `src` is an object with a key that is also present in `plurals`, the key * in question will be used as the locale identifier for its value. To disable * the compile-time checks for plural & selecto

(src, plural, plurals)

Source from the content-addressed store, hash-verified

43 * @param {object} plurals - a map of pluralization keys for all available locales
44 */
45 compile(src, plural, plurals) {
46 if (typeof src === 'object') {
47 const result = {};
48 for (const key of Object.keys(src)) {
49 const pl = plurals[key] || plural;
50 result[key] = this.compile(src[key], pl, plurals);
51 }
52 return result;
53 }
54
55 this.plural = plural;
56 const parserOptions = {
57 cardinal: plural.cardinals,
58 ordinal: plural.ordinals,
59 strict: this.options.strictNumberSign
60 };
61 this.arguments = [];
62 const r = parse(src, parserOptions).map(token => this.token(token));
63 let reqArgs = '';
64 if (this.options.requireAllArguments && this.arguments.length > 0) {
65 this.setRuntimeFn('reqArgs');
66 reqArgs = `reqArgs(${JSON.stringify(this.arguments)}, d); `;
67 }
68 return `function(d) { ${reqArgs}return ${this.concatenate(r, true)}; }`;
69 }
70
71 cases(token, pluralToken) {
72 let needOther = true;

Callers 4

compileMethod · 0.95
compileModuleFunction · 0.95
formatters.jsFile · 0.45
messageformat.jsFile · 0.45

Calls 3

tokenMethod · 0.95
setRuntimeFnMethod · 0.95
concatenateMethod · 0.95

Tested by

no test coverage detected