@intlayer/babel 6.1.6 → 7.0.0-canary.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/dist/cjs/_virtual/rolldown_runtime.cjs +25 -0
- package/dist/cjs/babel-plugin-intlayer.cjs +267 -270
- package/dist/cjs/babel-plugin-intlayer.cjs.map +1 -1
- package/dist/cjs/index.cjs +3 -23
- package/dist/esm/babel-plugin-intlayer.mjs +261 -234
- package/dist/esm/babel-plugin-intlayer.mjs.map +1 -1
- package/dist/esm/index.mjs +3 -2
- package/dist/types/babel-plugin-intlayer.d.ts +65 -58
- package/dist/types/babel-plugin-intlayer.d.ts.map +1 -1
- package/dist/types/index.d.ts +2 -2
- package/package.json +38 -46
- package/LICENSE +0 -202
- package/dist/cjs/index.cjs.map +0 -1
- package/dist/esm/index.mjs.map +0 -1
- package/dist/types/index.d.ts.map +0 -1
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
//#region rolldown:runtime
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
10
|
+
key = keys[i];
|
|
11
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
12
|
+
get: ((k) => from[k]).bind(null, key),
|
|
13
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
19
|
+
value: mod,
|
|
20
|
+
enumerable: true
|
|
21
|
+
}) : target, mod));
|
|
22
|
+
|
|
23
|
+
//#endregion
|
|
24
|
+
|
|
25
|
+
exports.__toESM = __toESM;
|
|
@@ -1,282 +1,279 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
var babel_plugin_intlayer_exports = {};
|
|
30
|
-
__export(babel_plugin_intlayer_exports, {
|
|
31
|
-
intlayerBabelPlugin: () => intlayerBabelPlugin
|
|
32
|
-
});
|
|
33
|
-
module.exports = __toCommonJS(babel_plugin_intlayer_exports);
|
|
34
|
-
var t = __toESM(require("@babel/types"));
|
|
35
|
-
var import_chokidar = require("@intlayer/chokidar");
|
|
36
|
-
var import_config = require("@intlayer/config");
|
|
37
|
-
var import_node_path = require("node:path");
|
|
1
|
+
const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
|
|
2
|
+
let node_path = require("node:path");
|
|
3
|
+
node_path = require_rolldown_runtime.__toESM(node_path);
|
|
4
|
+
let __intlayer_chokidar = require("@intlayer/chokidar");
|
|
5
|
+
__intlayer_chokidar = require_rolldown_runtime.__toESM(__intlayer_chokidar);
|
|
6
|
+
let __intlayer_config = require("@intlayer/config");
|
|
7
|
+
__intlayer_config = require_rolldown_runtime.__toESM(__intlayer_config);
|
|
8
|
+
|
|
9
|
+
//#region src/babel-plugin-intlayer.ts
|
|
38
10
|
const PACKAGE_LIST = [
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
11
|
+
"intlayer",
|
|
12
|
+
"@intlayer/core",
|
|
13
|
+
"react-intlayer",
|
|
14
|
+
"react-intlayer/client",
|
|
15
|
+
"react-intlayer/server",
|
|
16
|
+
"next-intlayer",
|
|
17
|
+
"next-intlayer/client",
|
|
18
|
+
"next-intlayer/server",
|
|
19
|
+
"svelte-intlayer",
|
|
20
|
+
"vue-intlayer",
|
|
21
|
+
"angular-intlayer",
|
|
22
|
+
"preact-intlayer",
|
|
23
|
+
"solid-intlayer"
|
|
52
24
|
];
|
|
53
25
|
const CALLER_LIST = ["useIntlayer", "getIntlayer"];
|
|
26
|
+
/**
|
|
27
|
+
* Packages that support dynamic import
|
|
28
|
+
*/
|
|
54
29
|
const PACKAGE_LIST_DYNAMIC = [
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
30
|
+
"react-intlayer",
|
|
31
|
+
"react-intlayer/client",
|
|
32
|
+
"react-intlayer/server",
|
|
33
|
+
"next-intlayer",
|
|
34
|
+
"next-intlayer/client",
|
|
35
|
+
"next-intlayer/server",
|
|
36
|
+
"preact-intlayer",
|
|
37
|
+
"vue-intlayer",
|
|
38
|
+
"solid-intlayer",
|
|
39
|
+
"svelte-intlayer",
|
|
40
|
+
"angular-intlayer"
|
|
66
41
|
];
|
|
67
42
|
const STATIC_IMPORT_FUNCTION = {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
};
|
|
71
|
-
const FETCH_IMPORT_FUNCTION = {
|
|
72
|
-
useIntlayer: "useDictionaryDynamic"
|
|
73
|
-
};
|
|
74
|
-
const DYNAMIC_IMPORT_FUNCTION = {
|
|
75
|
-
useIntlayer: "useDictionaryDynamic"
|
|
43
|
+
getIntlayer: "getDictionary",
|
|
44
|
+
useIntlayer: "useDictionary"
|
|
76
45
|
};
|
|
77
|
-
const
|
|
78
|
-
|
|
79
|
-
|
|
46
|
+
const DYNAMIC_IMPORT_FUNCTION = { useIntlayer: "useDictionaryDynamic" };
|
|
47
|
+
/**
|
|
48
|
+
* Replicates the xxHash64 → Base-62 algorithm used by the SWC version
|
|
49
|
+
* and prefixes an underscore so the generated identifiers never collide
|
|
50
|
+
* with user-defined ones.
|
|
51
|
+
*/
|
|
52
|
+
const makeIdent = (key, t) => {
|
|
53
|
+
const hash = (0, __intlayer_chokidar.getFileHash)(key);
|
|
54
|
+
return t.identifier(`_${hash}`);
|
|
80
55
|
};
|
|
81
56
|
const computeImport = (fromFile, dictionariesDir, dynamicDictionariesDir, fetchDictionariesDir, key, importMode) => {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
let rel = (0, import_node_path.relative)((0, import_node_path.dirname)(fromFile), relativePath);
|
|
90
|
-
rel = (0, import_config.normalizePath)(rel);
|
|
91
|
-
if (!rel.startsWith("./") && !rel.startsWith("../")) {
|
|
92
|
-
rel = `./${rel}`;
|
|
93
|
-
}
|
|
94
|
-
return rel;
|
|
57
|
+
let relativePath = (0, node_path.join)(dictionariesDir, `${key}.json`);
|
|
58
|
+
if (importMode === "live") relativePath = (0, node_path.join)(fetchDictionariesDir, `${key}.mjs`);
|
|
59
|
+
if (importMode === "dynamic") relativePath = (0, node_path.join)(dynamicDictionariesDir, `${key}.mjs`);
|
|
60
|
+
let rel = (0, node_path.relative)((0, node_path.dirname)(fromFile), relativePath);
|
|
61
|
+
rel = (0, __intlayer_config.normalizePath)(rel);
|
|
62
|
+
if (!rel.startsWith("./") && !rel.startsWith("../")) rel = `./${rel}`;
|
|
63
|
+
return rel;
|
|
95
64
|
};
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
65
|
+
/**
|
|
66
|
+
* Babel plugin that transforms Intlayer function calls and auto-imports dictionaries.
|
|
67
|
+
*
|
|
68
|
+
* This plugin transforms calls to `useIntlayer()` and `getIntlayer()` from various Intlayer
|
|
69
|
+
* packages into optimized dictionary access patterns, automatically importing the required
|
|
70
|
+
* dictionary files based on the configured import mode.
|
|
71
|
+
*
|
|
72
|
+
* ## Supported Input Patterns
|
|
73
|
+
*
|
|
74
|
+
* The plugin recognizes these function calls:
|
|
75
|
+
*
|
|
76
|
+
* ```ts
|
|
77
|
+
* // useIntlayer
|
|
78
|
+
* import { useIntlayer } from 'react-intlayer';
|
|
79
|
+
* import { useIntlayer } from 'next-intlayer';
|
|
80
|
+
*
|
|
81
|
+
* // getIntlayer
|
|
82
|
+
* import { getIntlayer } from 'intlayer';
|
|
83
|
+
*
|
|
84
|
+
* // Usage
|
|
85
|
+
* const content = useIntlayer('app');
|
|
86
|
+
* const content = getIntlayer('app');
|
|
87
|
+
* ```
|
|
88
|
+
*
|
|
89
|
+
* ## Transformation Modes
|
|
90
|
+
*
|
|
91
|
+
* ### Static Mode (default: `importMode = "static"`)
|
|
92
|
+
*
|
|
93
|
+
* Imports JSON dictionaries directly and replaces function calls with dictionary access:
|
|
94
|
+
*
|
|
95
|
+
* **Output:**
|
|
96
|
+
* ```ts
|
|
97
|
+
* import _dicHash from '../../.intlayer/dictionaries/app.json' with { type: 'json' };
|
|
98
|
+
* import { useDictionary as useIntlayer } from 'react-intlayer';
|
|
99
|
+
* import { getDictionary as getIntlayer } from 'intlayer';
|
|
100
|
+
*
|
|
101
|
+
* const content1 = useIntlayer(_dicHash);
|
|
102
|
+
* const content2 = getIntlayer(_dicHash);
|
|
103
|
+
* ```
|
|
104
|
+
*
|
|
105
|
+
* ### Dynamic Mode (`importMode = "dynamic"`)
|
|
106
|
+
*
|
|
107
|
+
* Uses dynamic dictionary loading with Suspense support:
|
|
108
|
+
*
|
|
109
|
+
* **Output:**
|
|
110
|
+
* ```ts
|
|
111
|
+
* import _dicHash from '../../.intlayer/dictionaries/app.json' with { type: 'json' };
|
|
112
|
+
* import _dicHash_dyn from '../../.intlayer/dynamic_dictionaries/app.mjs';
|
|
113
|
+
* import { useDictionaryDynamic as useIntlayer } from 'react-intlayer';
|
|
114
|
+
* import { getDictionary as getIntlayer } from 'intlayer';
|
|
115
|
+
*
|
|
116
|
+
* const content1 = useIntlayer(_dicHash_dyn, 'app');
|
|
117
|
+
* const content2 = getIntlayer(_dicHash);
|
|
118
|
+
* ```
|
|
119
|
+
*
|
|
120
|
+
* ### Live Mode (`importMode = "live"`)
|
|
121
|
+
*
|
|
122
|
+
* Uses live-based dictionary loading for remote dictionaries:
|
|
123
|
+
*
|
|
124
|
+
* **Output if `liveSyncKeys` includes the key:**
|
|
125
|
+
* ```ts
|
|
126
|
+
* import _dicHash from '../../.intlayer/dictionaries/app.json' with { type: 'json' };
|
|
127
|
+
* import _dicHash_fetch from '../../.intlayer/fetch_dictionaries/app.mjs';
|
|
128
|
+
* import { useDictionaryDynamic as useIntlayer } from 'react-intlayer';
|
|
129
|
+
* import { getDictionary as getIntlayer } from 'intlayer';
|
|
130
|
+
*
|
|
131
|
+
* const content1 = useIntlayer(_dicHash_fetch, "app");
|
|
132
|
+
* const content2 = getIntlayer(_dicHash);
|
|
133
|
+
* ```
|
|
134
|
+
*
|
|
135
|
+
* > If `liveSyncKeys` does not include the key, the plugin will fallback to the dynamic impor
|
|
136
|
+
*
|
|
137
|
+
* ```ts
|
|
138
|
+
* import _dicHash from '../../.intlayer/dictionaries/app.json' with { type: 'json' };
|
|
139
|
+
* import _dicHash_dyn from '../../.intlayer/dynamic_dictionaries/app.mjs';
|
|
140
|
+
* import { useDictionaryDynamic as useIntlayer } from 'react-intlayer';
|
|
141
|
+
* import { getDictionary as getIntlayer } from 'intlayer';
|
|
142
|
+
*
|
|
143
|
+
* const content1 = useIntlayer(_dicHash_dyn, 'app');
|
|
144
|
+
* const content2 = getIntlayer(_dicHash);
|
|
145
|
+
* ```
|
|
146
|
+
*/
|
|
147
|
+
const intlayerBabelPlugin = (babel) => {
|
|
148
|
+
const { types: t } = babel;
|
|
149
|
+
return {
|
|
150
|
+
name: "babel-plugin-intlayer-transform",
|
|
151
|
+
pre() {
|
|
152
|
+
this._newStaticImports = /* @__PURE__ */ new Map();
|
|
153
|
+
this._newDynamicImports = /* @__PURE__ */ new Map();
|
|
154
|
+
this._isIncluded = true;
|
|
155
|
+
this._hasValidImport = false;
|
|
156
|
+
this._isDictEntry = false;
|
|
157
|
+
this._useDynamicHelpers = false;
|
|
158
|
+
const filename = this.file.opts.filename;
|
|
159
|
+
if (this.opts.filesList && filename) {
|
|
160
|
+
if (!this.opts.filesList.includes(filename)) {
|
|
161
|
+
this._isIncluded = false;
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
},
|
|
166
|
+
visitor: {
|
|
167
|
+
Program: {
|
|
168
|
+
enter(programPath, state) {
|
|
169
|
+
const filename = state.file.opts.filename;
|
|
170
|
+
if (state.opts.replaceDictionaryEntry && filename === state.opts.dictionariesEntryPath) {
|
|
171
|
+
state._isDictEntry = true;
|
|
172
|
+
programPath.node.body = [t.exportDefaultDeclaration(t.objectExpression([]))];
|
|
173
|
+
programPath.stop();
|
|
174
|
+
}
|
|
175
|
+
},
|
|
176
|
+
exit(programPath, state) {
|
|
177
|
+
if (state._isDictEntry) return;
|
|
178
|
+
if (!state._hasValidImport) return;
|
|
179
|
+
if (!state._isIncluded) return;
|
|
180
|
+
const file = state.file.opts.filename;
|
|
181
|
+
const dictionariesDir = state.opts.dictionariesDir;
|
|
182
|
+
const dynamicDictionariesDir = state.opts.dynamicDictionariesDir;
|
|
183
|
+
const fetchDictionariesDir = state.opts.fetchDictionariesDir;
|
|
184
|
+
const imports = [];
|
|
185
|
+
for (const [key, ident] of state._newStaticImports) {
|
|
186
|
+
const rel = computeImport(file, dictionariesDir, dynamicDictionariesDir, fetchDictionariesDir, key, "static");
|
|
187
|
+
const importDeclarationNode = t.importDeclaration([t.importDefaultSpecifier(t.identifier(ident.name))], t.stringLiteral(rel));
|
|
188
|
+
importDeclarationNode.attributes = [t.importAttribute(t.identifier("type"), t.stringLiteral("json"))];
|
|
189
|
+
imports.push(importDeclarationNode);
|
|
190
|
+
}
|
|
191
|
+
for (const [key, ident] of state._newDynamicImports) {
|
|
192
|
+
const rel = computeImport(file, dictionariesDir, dynamicDictionariesDir, fetchDictionariesDir, key, ident.name.endsWith("_fetch") ? "live" : "dynamic");
|
|
193
|
+
imports.push(t.importDeclaration([t.importDefaultSpecifier(t.identifier(ident.name))], t.stringLiteral(rel)));
|
|
194
|
+
}
|
|
195
|
+
if (!imports.length) return;
|
|
196
|
+
const bodyPaths = programPath.get("body");
|
|
197
|
+
let insertPos = 0;
|
|
198
|
+
for (const stmtPath of bodyPaths) {
|
|
199
|
+
const stmt = stmtPath.node;
|
|
200
|
+
if (t.isExpressionStatement(stmt) && t.isStringLiteral(stmt.expression) && !stmt.expression.value.startsWith("import") && !stmt.expression.value.startsWith("require")) insertPos += 1;
|
|
201
|
+
else break;
|
|
202
|
+
}
|
|
203
|
+
programPath.node.body.splice(insertPos, 0, ...imports);
|
|
204
|
+
}
|
|
205
|
+
},
|
|
206
|
+
ImportDeclaration(path, state) {
|
|
207
|
+
if (state._isDictEntry) return;
|
|
208
|
+
const src = path.node.source.value;
|
|
209
|
+
if (!PACKAGE_LIST.includes(src)) return;
|
|
210
|
+
state._hasValidImport = true;
|
|
211
|
+
for (const spec of path.node.specifiers) {
|
|
212
|
+
if (!t.isImportSpecifier(spec)) continue;
|
|
213
|
+
const importedName = t.isIdentifier(spec.imported) ? spec.imported.name : spec.imported.value;
|
|
214
|
+
const importMode = state.opts.importMode;
|
|
215
|
+
const shouldUseDynamicHelpers = (importMode === "dynamic" || importMode === "live") && PACKAGE_LIST_DYNAMIC.includes(src);
|
|
216
|
+
if (shouldUseDynamicHelpers) state._useDynamicHelpers = true;
|
|
217
|
+
let helperMap;
|
|
218
|
+
if (shouldUseDynamicHelpers) helperMap = {
|
|
219
|
+
...STATIC_IMPORT_FUNCTION,
|
|
220
|
+
...DYNAMIC_IMPORT_FUNCTION
|
|
221
|
+
};
|
|
222
|
+
else helperMap = STATIC_IMPORT_FUNCTION;
|
|
223
|
+
const newIdentifier = helperMap[importedName];
|
|
224
|
+
if (newIdentifier) spec.imported = t.identifier(newIdentifier);
|
|
225
|
+
}
|
|
226
|
+
},
|
|
227
|
+
CallExpression(path, state) {
|
|
228
|
+
if (state._isDictEntry) return;
|
|
229
|
+
const callee = path.node.callee;
|
|
230
|
+
if (!t.isIdentifier(callee)) return;
|
|
231
|
+
if (!CALLER_LIST.includes(callee.name)) return;
|
|
232
|
+
state._hasValidImport = true;
|
|
233
|
+
const arg = path.node.arguments[0];
|
|
234
|
+
if (!arg || !t.isStringLiteral(arg)) return;
|
|
235
|
+
const key = arg.value;
|
|
236
|
+
const importMode = state.opts.importMode;
|
|
237
|
+
const isUseIntlayer = callee.name === "useIntlayer";
|
|
238
|
+
const useDynamicHelpers = Boolean(state._useDynamicHelpers);
|
|
239
|
+
let perCallMode = "static";
|
|
240
|
+
if (isUseIntlayer && useDynamicHelpers) {
|
|
241
|
+
if (importMode === "dynamic") perCallMode = "dynamic";
|
|
242
|
+
else if (importMode === "live") perCallMode = (state.opts.liveSyncKeys ?? []).includes(key) ? "live" : "dynamic";
|
|
243
|
+
}
|
|
244
|
+
let ident;
|
|
245
|
+
if (perCallMode === "live") {
|
|
246
|
+
let dynamicIdent = state._newDynamicImports?.get(key);
|
|
247
|
+
if (!dynamicIdent) {
|
|
248
|
+
const hash = (0, __intlayer_chokidar.getFileHash)(key);
|
|
249
|
+
dynamicIdent = t.identifier(`_${hash}_fetch`);
|
|
250
|
+
state._newDynamicImports?.set(key, dynamicIdent);
|
|
251
|
+
}
|
|
252
|
+
ident = dynamicIdent;
|
|
253
|
+
path.node.arguments = [t.identifier(ident.name), ...path.node.arguments];
|
|
254
|
+
} else if (perCallMode === "dynamic") {
|
|
255
|
+
let dynamicIdent = state._newDynamicImports?.get(key);
|
|
256
|
+
if (!dynamicIdent) {
|
|
257
|
+
const hash = (0, __intlayer_chokidar.getFileHash)(key);
|
|
258
|
+
dynamicIdent = t.identifier(`_${hash}_dyn`);
|
|
259
|
+
state._newDynamicImports?.set(key, dynamicIdent);
|
|
260
|
+
}
|
|
261
|
+
ident = dynamicIdent;
|
|
262
|
+
path.node.arguments = [t.identifier(ident.name), ...path.node.arguments];
|
|
263
|
+
} else {
|
|
264
|
+
let staticIdent = state._newStaticImports?.get(key);
|
|
265
|
+
if (!staticIdent) {
|
|
266
|
+
staticIdent = makeIdent(key, t);
|
|
267
|
+
state._newStaticImports?.set(key, staticIdent);
|
|
268
|
+
}
|
|
269
|
+
ident = staticIdent;
|
|
270
|
+
path.node.arguments[0] = t.identifier(ident.name);
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
};
|
|
277
275
|
};
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
});
|
|
276
|
+
|
|
277
|
+
//#endregion
|
|
278
|
+
exports.intlayerBabelPlugin = intlayerBabelPlugin;
|
|
282
279
|
//# sourceMappingURL=babel-plugin-intlayer.cjs.map
|