@discord/intl-loader-core 0.18.0-canary.8b215fd → 0.18.0-rc.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/package.json +2 -2
- package/src/transformer.js +15 -5
- package/types/src/transformer.d.ts +3 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@discord/intl-loader-core",
|
|
3
|
-
"version": "0.18.0-
|
|
3
|
+
"version": "0.18.0-rc.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "Core utilities for writing loaders and transformers using @discord/intl",
|
|
6
6
|
"author": "Jon Egeland",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"chokidar": "^3.6.0",
|
|
30
30
|
"debug": "^4.3.6",
|
|
31
|
-
"@discord/intl-message-database": "0.18.0"
|
|
31
|
+
"@discord/intl-message-database": "0.18.0-rc.0"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"@types/debug": "^4.1.12",
|
package/src/transformer.js
CHANGED
|
@@ -118,12 +118,20 @@ class MessageDefinitionsTransformer {
|
|
|
118
118
|
* binds during initialization. The Proxy supports `key in proxy` queries, getter access,
|
|
119
119
|
* spreads, and more.
|
|
120
120
|
*
|
|
121
|
+
* @param {string} keyArrayName Name of an Array to use for `keys` queries.
|
|
122
|
+
* @param {string} keySetName Name of a Set to use for `has` queries.
|
|
121
123
|
* @param {string} bindFunc Code expression that creates a getter bind
|
|
122
124
|
* @returns {string}
|
|
123
125
|
*/
|
|
124
|
-
createBindsProxy(bindFunc) {
|
|
126
|
+
createBindsProxy(keyArrayName, keySetName, bindFunc) {
|
|
125
127
|
return `new Proxy({},
|
|
126
128
|
{
|
|
129
|
+
has(self, prop) {
|
|
130
|
+
return ${keySetName}.has(prop);
|
|
131
|
+
},
|
|
132
|
+
ownKeys(self) {
|
|
133
|
+
return ${keyArrayName};
|
|
134
|
+
},
|
|
127
135
|
getOwnPropertyDescriptor(self, prop) {
|
|
128
136
|
return {
|
|
129
137
|
value: self[prop] ||= ${bindFunc},
|
|
@@ -140,6 +148,8 @@ class MessageDefinitionsTransformer {
|
|
|
140
148
|
return 'proxyAssign';
|
|
141
149
|
}
|
|
142
150
|
|
|
151
|
+
if(!${keySetName}.has(prop)) return undefined;
|
|
152
|
+
|
|
143
153
|
self[prop] ||= ${bindFunc};
|
|
144
154
|
return self[prop];
|
|
145
155
|
},
|
|
@@ -157,10 +167,10 @@ class MessageDefinitionsTransformer {
|
|
|
157
167
|
createLoaderAndBinds() {
|
|
158
168
|
if (this.options.preGenerateBinds === 'proxy') {
|
|
159
169
|
return [
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
`const ${this.loaderName} = createLoader(
|
|
163
|
-
`const binds = ${this.createBindsProxy(`(locale) => ${this.loaderName}.get(prop, locale)`)};`,
|
|
170
|
+
`const _keys = ${JSON.stringify(Object.keys(this.options.messageKeys))};`,
|
|
171
|
+
'const _keySet = new Set(_keys);',
|
|
172
|
+
`const ${this.loaderName} = createLoader(_keys, _locales, _defaultLocale);`,
|
|
173
|
+
`const binds = ${this.createBindsProxy('_keys', '_keySet', `(locale) => ${this.loaderName}.get(prop, locale)`)};`,
|
|
164
174
|
];
|
|
165
175
|
} else if (this.options.preGenerateBinds === true) {
|
|
166
176
|
const bindLines = Object.keys(this.options.messageKeys).map(
|
|
@@ -98,10 +98,12 @@ export class MessageDefinitionsTransformer {
|
|
|
98
98
|
* binds during initialization. The Proxy supports `key in proxy` queries, getter access,
|
|
99
99
|
* spreads, and more.
|
|
100
100
|
*
|
|
101
|
+
* @param {string} keyArrayName Name of an Array to use for `keys` queries.
|
|
102
|
+
* @param {string} keySetName Name of a Set to use for `has` queries.
|
|
101
103
|
* @param {string} bindFunc Code expression that creates a getter bind
|
|
102
104
|
* @returns {string}
|
|
103
105
|
*/
|
|
104
|
-
createBindsProxy(bindFunc: string): string;
|
|
106
|
+
createBindsProxy(keyArrayName: string, keySetName: string, bindFunc: string): string;
|
|
105
107
|
/**
|
|
106
108
|
* Return a map of key names to bound message getter functions. If `preGenerateBinds` is
|
|
107
109
|
* configured to be `true`, the binds will be created as a constant object in the output.
|