@discord/intl-loader-core 0.19.1-canary.f6592a8 → 0.19.1

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@discord/intl-loader-core",
3
- "version": "0.19.1-canary.f6592a8",
3
+ "version": "0.19.1",
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.19.1-canary.f6592a8"
31
+ "@discord/intl-message-database": "0.19.1"
32
32
  },
33
33
  "devDependencies": {
34
34
  "@types/debug": "^4.1.12",
@@ -124,13 +124,36 @@ class MessageDefinitionsTransformer {
124
124
  * more of a debugging utility than anything else, but can be useful for diagnosing when messages
125
125
  * are used in critical paths or otherwise.
126
126
  *
127
- * @returns {string[]}
127
+ * @param {string} bindFunc Code expression that creates a getter bind
128
+ * @returns {string}
128
129
  */
129
- createBindsProxy() {
130
- return [
131
- `const {makeMessagesProxy} = require('@discord/intl');`,
132
- `const binds = makeMessagesProxy(${this.loaderName});`,
133
- ];
130
+ createBindsProxy(bindFunc) {
131
+ return `new Proxy({},
132
+ {
133
+ ownKeys(self) {
134
+ return Reflect.ownKeys(self);
135
+ },
136
+ getOwnPropertyDescriptor(self, prop) {
137
+ return {
138
+ value: self[prop] ||= ${bindFunc},
139
+ configurable: true,
140
+ enumerable: true,
141
+ writable: false,
142
+ };
143
+ },
144
+ get(self, prop) {
145
+ if (prop === '$$typeof') {
146
+ return 'object';
147
+ }
148
+ if (prop === Symbol.toStringTag) {
149
+ return 'IntlMessagesProxy';
150
+ }
151
+
152
+ self[prop] ||= ${bindFunc};
153
+ return self[prop];
154
+ },
155
+ },
156
+ )`;
134
157
  }
135
158
 
136
159
  /**
@@ -145,7 +168,7 @@ class MessageDefinitionsTransformer {
145
168
  case 'proxy':
146
169
  return [
147
170
  `const ${this.loaderName} = createLoader(_localeMap, _defaultLocale);`,
148
- ...this.createBindsProxy(),
171
+ `const binds = ${this.createBindsProxy(`(locale) => ${this.loaderName}.get(prop, locale)`)};`,
149
172
  ];
150
173
  case 'literal': {
151
174
  const bindLines = Object.keys(this.options.messageKeys).map(
@@ -105,9 +105,10 @@ export class MessageDefinitionsTransformer {
105
105
  * more of a debugging utility than anything else, but can be useful for diagnosing when messages
106
106
  * are used in critical paths or otherwise.
107
107
  *
108
- * @returns {string[]}
108
+ * @param {string} bindFunc Code expression that creates a getter bind
109
+ * @returns {string}
109
110
  */
110
- createBindsProxy(): string[];
111
+ createBindsProxy(bindFunc: string): string;
111
112
  /**
112
113
  * Return a map of key names to bound message getter functions. If `proxyBinds` is
113
114
  * configured to be `true`, the binds will be created as a constant object in the output.