@intlify/bundle-utils 12.0.0-alpha.1 → 12.0.0-alpha.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/lib/index.cjs +58 -36
- package/lib/index.d.cts +14 -3
- package/lib/index.d.mts +14 -3
- package/lib/index.d.ts +14 -3
- package/lib/index.mjs +57 -36
- package/package.json +3 -5
package/lib/index.cjs
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const module$1 = require('node:module');
|
|
4
|
-
const core = require('@babel/core');
|
|
5
4
|
const shared = require('@intlify/shared');
|
|
6
5
|
const acorn = require('acorn');
|
|
7
6
|
const escodegen = require('escodegen');
|
|
@@ -9,6 +8,7 @@ const estreeWalker = require('estree-walker');
|
|
|
9
8
|
const messageCompiler = require('@intlify/message-compiler');
|
|
10
9
|
const sourceMapJs = require('source-map-js');
|
|
11
10
|
const jsoncEslintParser = require('jsonc-eslint-parser');
|
|
11
|
+
const esbuild = require('esbuild');
|
|
12
12
|
const yamlEslintParser = require('yaml-eslint-parser');
|
|
13
13
|
|
|
14
14
|
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
|
@@ -16,7 +16,7 @@ function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'defau
|
|
|
16
16
|
|
|
17
17
|
const module__default = /*#__PURE__*/_interopDefaultCompat(module$1);
|
|
18
18
|
|
|
19
|
-
const _require = module__default.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href)));
|
|
19
|
+
const _require = module__default.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href)));
|
|
20
20
|
function checkInstallPackage(pkg, debug) {
|
|
21
21
|
let installedVueI18n = false;
|
|
22
22
|
try {
|
|
@@ -324,7 +324,7 @@ function excludeLocales({
|
|
|
324
324
|
|
|
325
325
|
class DynamicResourceError extends Error {
|
|
326
326
|
}
|
|
327
|
-
function generate$
|
|
327
|
+
function generate$3(targetSource, {
|
|
328
328
|
type = "plain",
|
|
329
329
|
filename = "vue-i18n-loader.js",
|
|
330
330
|
inSourceMap = void 0,
|
|
@@ -340,8 +340,7 @@ function generate$2(targetSource, {
|
|
|
340
340
|
allowDynamic = false,
|
|
341
341
|
jit = false
|
|
342
342
|
}) {
|
|
343
|
-
const
|
|
344
|
-
let value = target;
|
|
343
|
+
const value = Buffer.isBuffer(targetSource) ? targetSource.toString() : targetSource;
|
|
345
344
|
const options = {
|
|
346
345
|
type,
|
|
347
346
|
source: value,
|
|
@@ -359,22 +358,6 @@ function generate$2(targetSource, {
|
|
|
359
358
|
jit
|
|
360
359
|
};
|
|
361
360
|
const generator = createCodeGenerator(options);
|
|
362
|
-
if (options.filename && /.[c|m]?ts$/.test(options.filename)) {
|
|
363
|
-
const transformed = core.transform(value, {
|
|
364
|
-
filename: options.filename,
|
|
365
|
-
sourceMaps: options.sourceMap,
|
|
366
|
-
babelrc: false,
|
|
367
|
-
configFile: false,
|
|
368
|
-
browserslistConfigFile: false,
|
|
369
|
-
comments: false,
|
|
370
|
-
envName: "development",
|
|
371
|
-
presets: ["@babel/preset-typescript"]
|
|
372
|
-
});
|
|
373
|
-
if (transformed && transformed.code) {
|
|
374
|
-
value = transformed.code;
|
|
375
|
-
options.source = transformed.code;
|
|
376
|
-
}
|
|
377
|
-
}
|
|
378
361
|
const ast = acorn.parse(value, {
|
|
379
362
|
ecmaVersion: "latest",
|
|
380
363
|
sourceType: "module",
|
|
@@ -417,8 +400,7 @@ function scanAst(ast) {
|
|
|
417
400
|
throw new Error("Invalid AST: does not have Program node");
|
|
418
401
|
}
|
|
419
402
|
for (const node of ast.body) {
|
|
420
|
-
if (node.type !== "ExportDefaultDeclaration")
|
|
421
|
-
continue;
|
|
403
|
+
if (node.type !== "ExportDefaultDeclaration") continue;
|
|
422
404
|
switch (node.declaration.type) {
|
|
423
405
|
case "ObjectExpression":
|
|
424
406
|
return "object";
|
|
@@ -455,8 +437,7 @@ function _generate$2(generator, node, options = {}) {
|
|
|
455
437
|
*/
|
|
456
438
|
// @ts-ignore
|
|
457
439
|
enter(node2, _parent) {
|
|
458
|
-
if (_parent?.type != null)
|
|
459
|
-
this.skip();
|
|
440
|
+
if (_parent?.type != null) this.skip();
|
|
460
441
|
switch (node2.type) {
|
|
461
442
|
case "ExportDefaultDeclaration":
|
|
462
443
|
this.skip();
|
|
@@ -536,10 +517,8 @@ Variable declarations are not optimized - found ${variableDeclarations.join(", "
|
|
|
536
517
|
itemsCountStack.push(node2.elements.length);
|
|
537
518
|
break;
|
|
538
519
|
case "Property":
|
|
539
|
-
if (parent?.type !== "ObjectExpression")
|
|
540
|
-
|
|
541
|
-
if (node2.key.type !== "Literal" && node2.key.type !== "Identifier")
|
|
542
|
-
break;
|
|
520
|
+
if (parent?.type !== "ObjectExpression") break;
|
|
521
|
+
if (node2.key.type !== "Literal" && node2.key.type !== "Identifier") break;
|
|
543
522
|
const name = node2.key.type === "Literal" ? String(node2.key.value) : node2.key.name;
|
|
544
523
|
const strName = JSON.stringify(name);
|
|
545
524
|
if (isJSONablePrimitiveLiteral(node2.value)) {
|
|
@@ -657,7 +636,7 @@ function getValue(node) {
|
|
|
657
636
|
return node.type === "Literal" ? node.value : node.type === "TemplateLiteral" ? node.quasis.map((quasi) => quasi.value.cooked).join("") : void 0;
|
|
658
637
|
}
|
|
659
638
|
|
|
660
|
-
function generate$
|
|
639
|
+
function generate$2(targetSource, {
|
|
661
640
|
type = "plain",
|
|
662
641
|
onlyLocales = [],
|
|
663
642
|
filename = "vue-i18n-loader.json",
|
|
@@ -788,8 +767,7 @@ function _generate$1(generator, node, options = {}) {
|
|
|
788
767
|
break;
|
|
789
768
|
}
|
|
790
769
|
case "JSONLiteral":
|
|
791
|
-
if (parent.type !== "JSONArrayExpression")
|
|
792
|
-
break;
|
|
770
|
+
if (parent.type !== "JSONArrayExpression") break;
|
|
793
771
|
const value = node2.value;
|
|
794
772
|
const strValue = JSON.stringify(value);
|
|
795
773
|
if (shared.isString(value)) {
|
|
@@ -845,6 +823,50 @@ function _generate$1(generator, node, options = {}) {
|
|
|
845
823
|
return codeMaps;
|
|
846
824
|
}
|
|
847
825
|
|
|
826
|
+
async function generate$1(targetSource, {
|
|
827
|
+
type = "plain",
|
|
828
|
+
filename = "vue-i18n-loader.js",
|
|
829
|
+
inSourceMap = void 0,
|
|
830
|
+
locale = "",
|
|
831
|
+
isGlobal = false,
|
|
832
|
+
sourceMap = false,
|
|
833
|
+
env = "development",
|
|
834
|
+
forceStringify = false,
|
|
835
|
+
onError = void 0,
|
|
836
|
+
onWarn = void 0,
|
|
837
|
+
strictMessage = true,
|
|
838
|
+
escapeHtml = false,
|
|
839
|
+
allowDynamic = false,
|
|
840
|
+
jit = false
|
|
841
|
+
}) {
|
|
842
|
+
let value = Buffer.isBuffer(targetSource) ? targetSource.toString() : targetSource;
|
|
843
|
+
const options = {
|
|
844
|
+
type,
|
|
845
|
+
source: value,
|
|
846
|
+
sourceMap,
|
|
847
|
+
locale,
|
|
848
|
+
isGlobal,
|
|
849
|
+
inSourceMap,
|
|
850
|
+
env,
|
|
851
|
+
filename,
|
|
852
|
+
forceStringify,
|
|
853
|
+
onError,
|
|
854
|
+
onWarn,
|
|
855
|
+
strictMessage,
|
|
856
|
+
escapeHtml,
|
|
857
|
+
allowDynamic,
|
|
858
|
+
jit
|
|
859
|
+
};
|
|
860
|
+
if (options.filename && /.[c|m]?ts$/.test(options.filename)) {
|
|
861
|
+
const transformed = await esbuild.transform(value, { loader: "ts" });
|
|
862
|
+
if (transformed && transformed.code) {
|
|
863
|
+
value = transformed.code;
|
|
864
|
+
options.source = transformed.code;
|
|
865
|
+
}
|
|
866
|
+
}
|
|
867
|
+
return generate$3(value, options);
|
|
868
|
+
}
|
|
869
|
+
|
|
848
870
|
function generate(targetSource, {
|
|
849
871
|
type = "plain",
|
|
850
872
|
onlyLocales = [],
|
|
@@ -958,8 +980,7 @@ function _generate(generator, node, options = {}) {
|
|
|
958
980
|
itemsCountStack.push(node2.entries.length);
|
|
959
981
|
break;
|
|
960
982
|
case "YAMLPair":
|
|
961
|
-
if (node2.key?.type !== "YAMLScalar")
|
|
962
|
-
break;
|
|
983
|
+
if (node2.key?.type !== "YAMLScalar") break;
|
|
963
984
|
if (node2.value?.type === "YAMLScalar") {
|
|
964
985
|
const name = node2.key.value;
|
|
965
986
|
const value = node2.value.value;
|
|
@@ -1042,7 +1063,8 @@ function _generate(generator, node, options = {}) {
|
|
|
1042
1063
|
|
|
1043
1064
|
exports.DynamicResourceError = DynamicResourceError;
|
|
1044
1065
|
exports.checkInstallPackage = checkInstallPackage;
|
|
1045
|
-
exports.generateJSON = generate$
|
|
1046
|
-
exports.generateJavaScript = generate$
|
|
1066
|
+
exports.generateJSON = generate$2;
|
|
1067
|
+
exports.generateJavaScript = generate$3;
|
|
1068
|
+
exports.generateTypescript = generate$1;
|
|
1047
1069
|
exports.generateYAML = generate;
|
|
1048
1070
|
exports.getVueI18nVersion = getVueI18nVersion;
|
package/lib/index.d.cts
CHANGED
|
@@ -61,13 +61,24 @@ declare class DynamicResourceError extends Error {
|
|
|
61
61
|
/**
|
|
62
62
|
* @internal
|
|
63
63
|
*/
|
|
64
|
-
declare function generate$
|
|
64
|
+
declare function generate$3(targetSource: string | Buffer, { type, filename, inSourceMap, locale, isGlobal, sourceMap, env, forceStringify, onError, onWarn, strictMessage, escapeHtml, allowDynamic, jit }: CodeGenOptions): CodeGenResult<Node>;
|
|
65
65
|
|
|
66
66
|
/**
|
|
67
67
|
* Code / AST generator for i18n json/json5 resource
|
|
68
68
|
*/
|
|
69
69
|
|
|
70
|
-
declare function generate$
|
|
70
|
+
declare function generate$2(targetSource: string | Buffer, { type, onlyLocales, filename, inSourceMap, locale, isGlobal, sourceMap, env, forceStringify, onError, strictMessage, escapeHtml, jit }: CodeGenOptions): CodeGenResult<JSONProgram>;
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Code generator for i18n ts resource
|
|
74
|
+
*
|
|
75
|
+
* An async wrapper for the js generator which transforms ts to js before generating
|
|
76
|
+
*/
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* @internal
|
|
80
|
+
*/
|
|
81
|
+
declare function generate$1(targetSource: string | Buffer, { type, filename, inSourceMap, locale, isGlobal, sourceMap, env, forceStringify, onError, onWarn, strictMessage, escapeHtml, allowDynamic, jit }: CodeGenOptions): Promise<CodeGenResult<Node>>;
|
|
71
82
|
|
|
72
83
|
/**
|
|
73
84
|
* Code generator for i18n yaml resource
|
|
@@ -78,4 +89,4 @@ declare function generate$1(targetSource: string | Buffer, { type, onlyLocales,
|
|
|
78
89
|
*/
|
|
79
90
|
declare function generate(targetSource: string | Buffer, { type, onlyLocales, filename, inSourceMap, locale, isGlobal, sourceMap, env, forceStringify, onError, strictMessage, escapeHtml, jit }: CodeGenOptions): CodeGenResult<YAMLProgram>;
|
|
80
91
|
|
|
81
|
-
export { type CodeGenOptions, type CodeGenResult, type DevEnv, DynamicResourceError, type InstalledPackage, checkInstallPackage, generate$
|
|
92
|
+
export { type CodeGenOptions, type CodeGenResult, type DevEnv, DynamicResourceError, type InstalledPackage, checkInstallPackage, generate$2 as generateJSON, generate$3 as generateJavaScript, generate$1 as generateTypescript, generate as generateYAML, getVueI18nVersion };
|
package/lib/index.d.mts
CHANGED
|
@@ -61,13 +61,24 @@ declare class DynamicResourceError extends Error {
|
|
|
61
61
|
/**
|
|
62
62
|
* @internal
|
|
63
63
|
*/
|
|
64
|
-
declare function generate$
|
|
64
|
+
declare function generate$3(targetSource: string | Buffer, { type, filename, inSourceMap, locale, isGlobal, sourceMap, env, forceStringify, onError, onWarn, strictMessage, escapeHtml, allowDynamic, jit }: CodeGenOptions): CodeGenResult<Node>;
|
|
65
65
|
|
|
66
66
|
/**
|
|
67
67
|
* Code / AST generator for i18n json/json5 resource
|
|
68
68
|
*/
|
|
69
69
|
|
|
70
|
-
declare function generate$
|
|
70
|
+
declare function generate$2(targetSource: string | Buffer, { type, onlyLocales, filename, inSourceMap, locale, isGlobal, sourceMap, env, forceStringify, onError, strictMessage, escapeHtml, jit }: CodeGenOptions): CodeGenResult<JSONProgram>;
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Code generator for i18n ts resource
|
|
74
|
+
*
|
|
75
|
+
* An async wrapper for the js generator which transforms ts to js before generating
|
|
76
|
+
*/
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* @internal
|
|
80
|
+
*/
|
|
81
|
+
declare function generate$1(targetSource: string | Buffer, { type, filename, inSourceMap, locale, isGlobal, sourceMap, env, forceStringify, onError, onWarn, strictMessage, escapeHtml, allowDynamic, jit }: CodeGenOptions): Promise<CodeGenResult<Node>>;
|
|
71
82
|
|
|
72
83
|
/**
|
|
73
84
|
* Code generator for i18n yaml resource
|
|
@@ -78,4 +89,4 @@ declare function generate$1(targetSource: string | Buffer, { type, onlyLocales,
|
|
|
78
89
|
*/
|
|
79
90
|
declare function generate(targetSource: string | Buffer, { type, onlyLocales, filename, inSourceMap, locale, isGlobal, sourceMap, env, forceStringify, onError, strictMessage, escapeHtml, jit }: CodeGenOptions): CodeGenResult<YAMLProgram>;
|
|
80
91
|
|
|
81
|
-
export { type CodeGenOptions, type CodeGenResult, type DevEnv, DynamicResourceError, type InstalledPackage, checkInstallPackage, generate$
|
|
92
|
+
export { type CodeGenOptions, type CodeGenResult, type DevEnv, DynamicResourceError, type InstalledPackage, checkInstallPackage, generate$2 as generateJSON, generate$3 as generateJavaScript, generate$1 as generateTypescript, generate as generateYAML, getVueI18nVersion };
|
package/lib/index.d.ts
CHANGED
|
@@ -61,13 +61,24 @@ declare class DynamicResourceError extends Error {
|
|
|
61
61
|
/**
|
|
62
62
|
* @internal
|
|
63
63
|
*/
|
|
64
|
-
declare function generate$
|
|
64
|
+
declare function generate$3(targetSource: string | Buffer, { type, filename, inSourceMap, locale, isGlobal, sourceMap, env, forceStringify, onError, onWarn, strictMessage, escapeHtml, allowDynamic, jit }: CodeGenOptions): CodeGenResult<Node>;
|
|
65
65
|
|
|
66
66
|
/**
|
|
67
67
|
* Code / AST generator for i18n json/json5 resource
|
|
68
68
|
*/
|
|
69
69
|
|
|
70
|
-
declare function generate$
|
|
70
|
+
declare function generate$2(targetSource: string | Buffer, { type, onlyLocales, filename, inSourceMap, locale, isGlobal, sourceMap, env, forceStringify, onError, strictMessage, escapeHtml, jit }: CodeGenOptions): CodeGenResult<JSONProgram>;
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Code generator for i18n ts resource
|
|
74
|
+
*
|
|
75
|
+
* An async wrapper for the js generator which transforms ts to js before generating
|
|
76
|
+
*/
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* @internal
|
|
80
|
+
*/
|
|
81
|
+
declare function generate$1(targetSource: string | Buffer, { type, filename, inSourceMap, locale, isGlobal, sourceMap, env, forceStringify, onError, onWarn, strictMessage, escapeHtml, allowDynamic, jit }: CodeGenOptions): Promise<CodeGenResult<Node>>;
|
|
71
82
|
|
|
72
83
|
/**
|
|
73
84
|
* Code generator for i18n yaml resource
|
|
@@ -78,4 +89,4 @@ declare function generate$1(targetSource: string | Buffer, { type, onlyLocales,
|
|
|
78
89
|
*/
|
|
79
90
|
declare function generate(targetSource: string | Buffer, { type, onlyLocales, filename, inSourceMap, locale, isGlobal, sourceMap, env, forceStringify, onError, strictMessage, escapeHtml, jit }: CodeGenOptions): CodeGenResult<YAMLProgram>;
|
|
80
91
|
|
|
81
|
-
export { type CodeGenOptions, type CodeGenResult, type DevEnv, DynamicResourceError, type InstalledPackage, checkInstallPackage, generate$
|
|
92
|
+
export { type CodeGenOptions, type CodeGenResult, type DevEnv, DynamicResourceError, type InstalledPackage, checkInstallPackage, generate$2 as generateJSON, generate$3 as generateJavaScript, generate$1 as generateTypescript, generate as generateYAML, getVueI18nVersion };
|
package/lib/index.mjs
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import module from 'node:module';
|
|
2
|
-
import { transform } from '@babel/core';
|
|
3
2
|
import { isBoolean, format, escapeHtml, friendlyJSONstringify, isString, isNumber } from '@intlify/shared';
|
|
4
3
|
import { parse } from 'acorn';
|
|
5
|
-
import { generate as generate$
|
|
4
|
+
import { generate as generate$4 } from 'escodegen';
|
|
6
5
|
import { walk } from 'estree-walker';
|
|
7
6
|
import { LOCATION_STUB, detectHtmlTag, baseCompile } from '@intlify/message-compiler';
|
|
8
7
|
import { SourceMapGenerator, SourceMapConsumer } from 'source-map-js';
|
|
9
8
|
import { parseJSON, getStaticJSONValue, traverseNodes } from 'jsonc-eslint-parser';
|
|
9
|
+
import { transform } from 'esbuild';
|
|
10
10
|
import { parseYAML, getStaticYAMLValue, traverseNodes as traverseNodes$1 } from 'yaml-eslint-parser';
|
|
11
11
|
|
|
12
12
|
const _require = module.createRequire(import.meta.url);
|
|
@@ -317,7 +317,7 @@ function excludeLocales({
|
|
|
317
317
|
|
|
318
318
|
class DynamicResourceError extends Error {
|
|
319
319
|
}
|
|
320
|
-
function generate$
|
|
320
|
+
function generate$3(targetSource, {
|
|
321
321
|
type = "plain",
|
|
322
322
|
filename = "vue-i18n-loader.js",
|
|
323
323
|
inSourceMap = void 0,
|
|
@@ -333,8 +333,7 @@ function generate$2(targetSource, {
|
|
|
333
333
|
allowDynamic = false,
|
|
334
334
|
jit = false
|
|
335
335
|
}) {
|
|
336
|
-
const
|
|
337
|
-
let value = target;
|
|
336
|
+
const value = Buffer.isBuffer(targetSource) ? targetSource.toString() : targetSource;
|
|
338
337
|
const options = {
|
|
339
338
|
type,
|
|
340
339
|
source: value,
|
|
@@ -352,22 +351,6 @@ function generate$2(targetSource, {
|
|
|
352
351
|
jit
|
|
353
352
|
};
|
|
354
353
|
const generator = createCodeGenerator(options);
|
|
355
|
-
if (options.filename && /.[c|m]?ts$/.test(options.filename)) {
|
|
356
|
-
const transformed = transform(value, {
|
|
357
|
-
filename: options.filename,
|
|
358
|
-
sourceMaps: options.sourceMap,
|
|
359
|
-
babelrc: false,
|
|
360
|
-
configFile: false,
|
|
361
|
-
browserslistConfigFile: false,
|
|
362
|
-
comments: false,
|
|
363
|
-
envName: "development",
|
|
364
|
-
presets: ["@babel/preset-typescript"]
|
|
365
|
-
});
|
|
366
|
-
if (transformed && transformed.code) {
|
|
367
|
-
value = transformed.code;
|
|
368
|
-
options.source = transformed.code;
|
|
369
|
-
}
|
|
370
|
-
}
|
|
371
354
|
const ast = parse(value, {
|
|
372
355
|
ecmaVersion: "latest",
|
|
373
356
|
sourceType: "module",
|
|
@@ -410,8 +393,7 @@ function scanAst(ast) {
|
|
|
410
393
|
throw new Error("Invalid AST: does not have Program node");
|
|
411
394
|
}
|
|
412
395
|
for (const node of ast.body) {
|
|
413
|
-
if (node.type !== "ExportDefaultDeclaration")
|
|
414
|
-
continue;
|
|
396
|
+
if (node.type !== "ExportDefaultDeclaration") continue;
|
|
415
397
|
switch (node.declaration.type) {
|
|
416
398
|
case "ObjectExpression":
|
|
417
399
|
return "object";
|
|
@@ -448,8 +430,7 @@ function _generate$2(generator, node, options = {}) {
|
|
|
448
430
|
*/
|
|
449
431
|
// @ts-ignore
|
|
450
432
|
enter(node2, _parent) {
|
|
451
|
-
if (_parent?.type != null)
|
|
452
|
-
this.skip();
|
|
433
|
+
if (_parent?.type != null) this.skip();
|
|
453
434
|
switch (node2.type) {
|
|
454
435
|
case "ExportDefaultDeclaration":
|
|
455
436
|
this.skip();
|
|
@@ -529,10 +510,8 @@ Variable declarations are not optimized - found ${variableDeclarations.join(", "
|
|
|
529
510
|
itemsCountStack.push(node2.elements.length);
|
|
530
511
|
break;
|
|
531
512
|
case "Property":
|
|
532
|
-
if (parent?.type !== "ObjectExpression")
|
|
533
|
-
|
|
534
|
-
if (node2.key.type !== "Literal" && node2.key.type !== "Identifier")
|
|
535
|
-
break;
|
|
513
|
+
if (parent?.type !== "ObjectExpression") break;
|
|
514
|
+
if (node2.key.type !== "Literal" && node2.key.type !== "Identifier") break;
|
|
536
515
|
const name = node2.key.type === "Literal" ? String(node2.key.value) : node2.key.name;
|
|
537
516
|
const strName = JSON.stringify(name);
|
|
538
517
|
if (isJSONablePrimitiveLiteral(node2.value)) {
|
|
@@ -555,7 +534,7 @@ Variable declarations are not optimized - found ${variableDeclarations.join(", "
|
|
|
555
534
|
} else if (node2.value.type === "FunctionExpression" || node2.value.type === "ArrowFunctionExpression") {
|
|
556
535
|
generator.push(`${strName}: `);
|
|
557
536
|
pathStack.push(name);
|
|
558
|
-
const code = generate$
|
|
537
|
+
const code = generate$4(node2.value, {
|
|
559
538
|
format: { compact: true }
|
|
560
539
|
});
|
|
561
540
|
generator.push(code, node2.value, code);
|
|
@@ -650,7 +629,7 @@ function getValue(node) {
|
|
|
650
629
|
return node.type === "Literal" ? node.value : node.type === "TemplateLiteral" ? node.quasis.map((quasi) => quasi.value.cooked).join("") : void 0;
|
|
651
630
|
}
|
|
652
631
|
|
|
653
|
-
function generate$
|
|
632
|
+
function generate$2(targetSource, {
|
|
654
633
|
type = "plain",
|
|
655
634
|
onlyLocales = [],
|
|
656
635
|
filename = "vue-i18n-loader.json",
|
|
@@ -781,8 +760,7 @@ function _generate$1(generator, node, options = {}) {
|
|
|
781
760
|
break;
|
|
782
761
|
}
|
|
783
762
|
case "JSONLiteral":
|
|
784
|
-
if (parent.type !== "JSONArrayExpression")
|
|
785
|
-
break;
|
|
763
|
+
if (parent.type !== "JSONArrayExpression") break;
|
|
786
764
|
const value = node2.value;
|
|
787
765
|
const strValue = JSON.stringify(value);
|
|
788
766
|
if (isString(value)) {
|
|
@@ -838,6 +816,50 @@ function _generate$1(generator, node, options = {}) {
|
|
|
838
816
|
return codeMaps;
|
|
839
817
|
}
|
|
840
818
|
|
|
819
|
+
async function generate$1(targetSource, {
|
|
820
|
+
type = "plain",
|
|
821
|
+
filename = "vue-i18n-loader.js",
|
|
822
|
+
inSourceMap = void 0,
|
|
823
|
+
locale = "",
|
|
824
|
+
isGlobal = false,
|
|
825
|
+
sourceMap = false,
|
|
826
|
+
env = "development",
|
|
827
|
+
forceStringify = false,
|
|
828
|
+
onError = void 0,
|
|
829
|
+
onWarn = void 0,
|
|
830
|
+
strictMessage = true,
|
|
831
|
+
escapeHtml = false,
|
|
832
|
+
allowDynamic = false,
|
|
833
|
+
jit = false
|
|
834
|
+
}) {
|
|
835
|
+
let value = Buffer.isBuffer(targetSource) ? targetSource.toString() : targetSource;
|
|
836
|
+
const options = {
|
|
837
|
+
type,
|
|
838
|
+
source: value,
|
|
839
|
+
sourceMap,
|
|
840
|
+
locale,
|
|
841
|
+
isGlobal,
|
|
842
|
+
inSourceMap,
|
|
843
|
+
env,
|
|
844
|
+
filename,
|
|
845
|
+
forceStringify,
|
|
846
|
+
onError,
|
|
847
|
+
onWarn,
|
|
848
|
+
strictMessage,
|
|
849
|
+
escapeHtml,
|
|
850
|
+
allowDynamic,
|
|
851
|
+
jit
|
|
852
|
+
};
|
|
853
|
+
if (options.filename && /.[c|m]?ts$/.test(options.filename)) {
|
|
854
|
+
const transformed = await transform(value, { loader: "ts" });
|
|
855
|
+
if (transformed && transformed.code) {
|
|
856
|
+
value = transformed.code;
|
|
857
|
+
options.source = transformed.code;
|
|
858
|
+
}
|
|
859
|
+
}
|
|
860
|
+
return generate$3(value, options);
|
|
861
|
+
}
|
|
862
|
+
|
|
841
863
|
function generate(targetSource, {
|
|
842
864
|
type = "plain",
|
|
843
865
|
onlyLocales = [],
|
|
@@ -951,8 +973,7 @@ function _generate(generator, node, options = {}) {
|
|
|
951
973
|
itemsCountStack.push(node2.entries.length);
|
|
952
974
|
break;
|
|
953
975
|
case "YAMLPair":
|
|
954
|
-
if (node2.key?.type !== "YAMLScalar")
|
|
955
|
-
break;
|
|
976
|
+
if (node2.key?.type !== "YAMLScalar") break;
|
|
956
977
|
if (node2.value?.type === "YAMLScalar") {
|
|
957
978
|
const name = node2.key.value;
|
|
958
979
|
const value = node2.value.value;
|
|
@@ -1033,4 +1054,4 @@ function _generate(generator, node, options = {}) {
|
|
|
1033
1054
|
return codeMaps;
|
|
1034
1055
|
}
|
|
1035
1056
|
|
|
1036
|
-
export { DynamicResourceError, checkInstallPackage, generate$
|
|
1057
|
+
export { DynamicResourceError, checkInstallPackage, generate$2 as generateJSON, generate$3 as generateJavaScript, generate$1 as generateTypescript, generate as generateYAML, getVueI18nVersion };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@intlify/bundle-utils",
|
|
3
3
|
"description": "Bundle utilities for Intlify project",
|
|
4
|
-
"version": "12.0.0-alpha.
|
|
4
|
+
"version": "12.0.0-alpha.2",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "kazuya kawaguchi",
|
|
7
7
|
"email": "kawakazu80@gmail.com"
|
|
@@ -18,11 +18,10 @@
|
|
|
18
18
|
}
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@babel/core": "^7.26.10",
|
|
22
|
-
"@babel/preset-typescript": "^7.26.0",
|
|
23
21
|
"@intlify/message-compiler": "next",
|
|
24
22
|
"@intlify/shared": "next",
|
|
25
23
|
"acorn": "^8.8.2",
|
|
24
|
+
"esbuild": "^0.25.1",
|
|
26
25
|
"escodegen": "^2.1.0",
|
|
27
26
|
"estree-walker": "^2.0.2",
|
|
28
27
|
"jsonc-eslint-parser": "^2.3.0",
|
|
@@ -30,10 +29,9 @@
|
|
|
30
29
|
"yaml-eslint-parser": "^1.2.2"
|
|
31
30
|
},
|
|
32
31
|
"devDependencies": {
|
|
33
|
-
"@types/babel__core": "^7.20.5",
|
|
34
32
|
"@types/escodegen": "^0.0.10",
|
|
35
33
|
"@types/estree": "^1.0.0",
|
|
36
|
-
"unbuild": "^
|
|
34
|
+
"unbuild": "^3.5.0"
|
|
37
35
|
},
|
|
38
36
|
"engines": {
|
|
39
37
|
"node": ">= 20"
|