@intlify/bundle-utils 10.0.1 → 12.0.0-alpha.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/lib/index.cjs CHANGED
@@ -1,20 +1,69 @@
1
1
  'use strict';
2
2
 
3
- const jsoncEslintParser = require('jsonc-eslint-parser');
3
+ const module$1 = require('node:module');
4
+ const core = require('@babel/core');
4
5
  const shared = require('@intlify/shared');
5
- const sourceMapJs = require('source-map-js');
6
- const messageCompiler = require('@intlify/message-compiler');
7
- const yamlEslintParser = require('yaml-eslint-parser');
8
6
  const acorn = require('acorn');
9
7
  const escodegen = require('escodegen');
10
8
  const estreeWalker = require('estree-walker');
11
- const module$1 = require('node:module');
9
+ const messageCompiler = require('@intlify/message-compiler');
10
+ const sourceMapJs = require('source-map-js');
11
+ const jsoncEslintParser = require('jsonc-eslint-parser');
12
+ const yamlEslintParser = require('yaml-eslint-parser');
12
13
 
13
14
  var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
14
15
  function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
15
16
 
16
17
  const module__default = /*#__PURE__*/_interopDefaultCompat(module$1);
17
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)));
20
+ function checkInstallPackage(pkg, debug) {
21
+ let installedVueI18n = false;
22
+ try {
23
+ debug(`vue-i18n load path: ${_require.resolve("vue-i18n")}`);
24
+ installedVueI18n = true;
25
+ } catch (e) {
26
+ debug(`cannot find 'vue-i18n'`, e);
27
+ }
28
+ let installedPetiteVueI18n = false;
29
+ try {
30
+ debug(`petite-vue-i18n load path: ${_require.resolve("petite-vue-i18n")}`);
31
+ installedPetiteVueI18n = true;
32
+ } catch (e) {
33
+ debug(`cannot find 'petite-vue-i18n'`, e);
34
+ }
35
+ if (installedVueI18n) {
36
+ return "vue-i18n";
37
+ }
38
+ if (installedPetiteVueI18n) {
39
+ return "petite-vue-i18n";
40
+ }
41
+ throw new Error(
42
+ `${pkg} requires 'vue-i18n' or 'petite-vue-i18n' to be present in the dependency tree.`
43
+ );
44
+ }
45
+ function getVueI18nVersion(debug, pkg = "vue-i18n") {
46
+ const VueI18n = loadModule(pkg, debug);
47
+ if (VueI18n == null) {
48
+ return "";
49
+ }
50
+ if (VueI18n.VERSION && VueI18n.VERSION.startsWith("9.")) {
51
+ return "9";
52
+ }
53
+ if (VueI18n.VERSION && VueI18n.VERSION.startsWith("10.")) {
54
+ return "10";
55
+ }
56
+ return "unknown";
57
+ }
58
+ function loadModule(moduleName, debug) {
59
+ try {
60
+ return _require(moduleName);
61
+ } catch (e) {
62
+ debug(`cannot load '${moduleName}'`, e);
63
+ return null;
64
+ }
65
+ }
66
+
18
67
  function createCodeGenerator(options = {
19
68
  filename: "bundle.json",
20
69
  sourceMap: false,
@@ -273,10 +322,11 @@ function excludeLocales({
273
322
  return _messages;
274
323
  }
275
324
 
325
+ class DynamicResourceError extends Error {
326
+ }
276
327
  function generate$2(targetSource, {
277
328
  type = "plain",
278
- onlyLocales = [],
279
- filename = "vue-i18n-loader.json",
329
+ filename = "vue-i18n-loader.js",
280
330
  inSourceMap = void 0,
281
331
  locale = "",
282
332
  isGlobal = false,
@@ -284,11 +334,14 @@ function generate$2(targetSource, {
284
334
  env = "development",
285
335
  forceStringify = false,
286
336
  onError = void 0,
337
+ onWarn = void 0,
287
338
  strictMessage = true,
288
339
  escapeHtml = false,
340
+ allowDynamic = false,
289
341
  jit = false
290
342
  }) {
291
- let value = Buffer.isBuffer(targetSource) ? targetSource.toString() : targetSource;
343
+ const target = Buffer.isBuffer(targetSource) ? targetSource.toString() : targetSource;
344
+ let value = target;
292
345
  const options = {
293
346
  type,
294
347
  source: value,
@@ -300,221 +353,314 @@ function generate$2(targetSource, {
300
353
  filename,
301
354
  forceStringify,
302
355
  onError,
356
+ onWarn,
303
357
  strictMessage,
304
358
  escapeHtml,
305
359
  jit
306
360
  };
307
- let ast = jsoncEslintParser.parseJSON(value, { filePath: filename });
308
- if (!locale && type === "sfc" && onlyLocales?.length) {
309
- const messages = jsoncEslintParser.getStaticJSONValue(ast);
310
- value = JSON.stringify(
311
- excludeLocales({
312
- messages,
313
- onlyLocales
314
- })
315
- );
316
- ast = jsoncEslintParser.parseJSON(value, { filePath: filename });
361
+ 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
+ }
317
377
  }
318
- if (locale && onlyLocales?.length && !onlyLocales.includes(locale)) {
319
- value = JSON.stringify({});
320
- ast = jsoncEslintParser.parseJSON(value, { filePath: filename });
321
- options.locale = "";
322
- options.source = void 0;
378
+ const ast = acorn.parse(value, {
379
+ ecmaVersion: "latest",
380
+ sourceType: "module",
381
+ sourceFile: filename,
382
+ allowImportExportEverywhere: true
383
+ });
384
+ const exportResult = scanAst(ast);
385
+ if (!allowDynamic) {
386
+ if (!exportResult) {
387
+ throw new Error(`You need to define an object as the locale message with 'export default'.`);
388
+ }
389
+ if (exportResult !== "object") {
390
+ throw new DynamicResourceError(
391
+ `You need to define an object as the locale message with 'export default'.`
392
+ );
393
+ }
394
+ } else {
395
+ if (!exportResult) {
396
+ throw new Error(`You need to define 'export default' that will return the locale messages.`);
397
+ }
398
+ if (exportResult !== "object") {
399
+ return {
400
+ ast,
401
+ code: value,
402
+ map: inSourceMap
403
+ };
404
+ }
323
405
  }
324
- const generator = createCodeGenerator(options);
325
406
  const codeMaps = _generate$2(generator, ast, options);
326
407
  const { code, map } = generator.context();
327
- const newMap = map && !jit ? mapLinesColumns(map.toJSON(), codeMaps, inSourceMap) || null : null;
408
+ const newMap = map ? mapLinesColumns(map.toJSON(), codeMaps, inSourceMap) || null : null;
328
409
  return {
329
410
  ast,
330
411
  code,
331
412
  map: newMap != null ? newMap : void 0
332
413
  };
333
414
  }
415
+ function scanAst(ast) {
416
+ if (ast.type !== "Program") {
417
+ throw new Error("Invalid AST: does not have Program node");
418
+ }
419
+ for (const node of ast.body) {
420
+ if (node.type !== "ExportDefaultDeclaration")
421
+ continue;
422
+ switch (node.declaration.type) {
423
+ case "ObjectExpression":
424
+ return "object";
425
+ case "FunctionDeclaration":
426
+ return "function";
427
+ case "ArrowFunctionExpression":
428
+ return "arrow-function";
429
+ }
430
+ }
431
+ return false;
432
+ }
334
433
  function _generate$2(generator, node, options = {}) {
335
434
  const propsCountStack = [];
336
435
  const pathStack = [];
337
436
  const itemsCountStack = [];
437
+ const skipStack = [];
338
438
  const { forceStringify } = generator.context();
339
439
  const codeMaps = /* @__PURE__ */ new Map();
340
440
  const { type, sourceMap, isGlobal, locale, jit } = options;
341
- const codegenFn = jit ? generateResourceAst : generateMessageFunction;
441
+ const _codegenFn = jit ? generateResourceAst : generateMessageFunction;
442
+ function codegenFn(value) {
443
+ const { code, map } = _codegenFn(value, options, pathStack);
444
+ sourceMap && map != null && codeMaps.set(value, map);
445
+ return code;
446
+ }
342
447
  const componentNamespace = "_Component";
343
- jsoncEslintParser.traverseNodes(node, {
344
- enterNode(node2, parent) {
448
+ const variableDeclarations = [];
449
+ estreeWalker.walk(node, {
450
+ /**
451
+ * NOTE:
452
+ * force cast to Node of `estree-walker@3.x`,
453
+ * because `estree-walker@3.x` is not dual packages,
454
+ * so it's support only esm only ...
455
+ */
456
+ // @ts-ignore
457
+ enter(node2, _parent) {
458
+ if (_parent?.type != null)
459
+ this.skip();
460
+ switch (node2.type) {
461
+ case "ExportDefaultDeclaration":
462
+ this.skip();
463
+ break;
464
+ case "ImportDeclaration":
465
+ generator.push(options.source?.slice(node2.start, node2.end));
466
+ generator.newline();
467
+ break;
468
+ case "VariableDeclaration":
469
+ generator.push(options.source?.slice(node2.start, node2.end));
470
+ generator.newline();
471
+ variableDeclarations.push(
472
+ ...node2.declarations.map((x) => `\`${x.id.name}\``)
473
+ );
474
+ break;
475
+ }
476
+ }
477
+ });
478
+ if (variableDeclarations.length > 0) {
479
+ options?.onWarn?.(
480
+ `
481
+ Variable declarations are not optimized - found ${variableDeclarations.join(", ")}`
482
+ );
483
+ }
484
+ estreeWalker.walk(node, {
485
+ /**
486
+ * NOTE:
487
+ * force cast to Node of `estree-walker@3.x`,
488
+ * because `estree-walker@3.x` is not dual packages,
489
+ * so it's support only esm only ...
490
+ */
491
+ // @ts-ignore
492
+ enter(node2, parent) {
493
+ if (parent?.type === "Program") {
494
+ switch (node2.type) {
495
+ case "ImportDeclaration":
496
+ case "VariableDeclaration":
497
+ case "VariableDeclarator":
498
+ this.skip();
499
+ }
500
+ } else if (parent?.type === "ArrayExpression") {
501
+ const lastIndex = itemsCountStack.length - 1;
502
+ const currentCount = parent.elements.length - itemsCountStack[lastIndex];
503
+ pathStack.push(currentCount.toString());
504
+ itemsCountStack[lastIndex] = --itemsCountStack[lastIndex];
505
+ } else if (parent?.type === "ObjectExpression") {
506
+ const lastIndex = propsCountStack.length - 1;
507
+ propsCountStack[lastIndex] = --propsCountStack[lastIndex];
508
+ }
345
509
  switch (node2.type) {
346
510
  case "Program":
347
511
  if (type === "plain") {
348
512
  generator.push(`const resource = `);
349
513
  } else if (type === "sfc") {
350
- const variableName = type === "sfc" ? !isGlobal ? "__i18n" : "__i18nGlobal" : "";
351
- const localeName = type === "sfc" ? locale != null ? locale : `""` : "";
352
- const exportSyntax = "export default";
353
- generator.push(`${exportSyntax} function (Component) {`);
514
+ const localeName = JSON.stringify(locale ?? '""');
515
+ const variableName = !isGlobal ? "__i18n" : "__i18nGlobal";
516
+ generator.push(`export default function (Component) {`);
354
517
  generator.indent();
355
- const componentVariable = `Component`;
356
- generator.pushline(
357
- `const ${componentNamespace} = ${componentVariable}`
358
- );
518
+ generator.pushline(`const ${componentNamespace} = Component`);
359
519
  generator.pushline(
360
520
  `${componentNamespace}.${variableName} = ${componentNamespace}.${variableName} || []`
361
521
  );
362
522
  generator.push(`${componentNamespace}.${variableName}.push({`);
363
523
  generator.indent();
364
- generator.pushline(`"locale": ${JSON.stringify(localeName)},`);
524
+ generator.pushline(`"locale": ${localeName},`);
365
525
  generator.push(`"resource": `);
366
526
  }
367
527
  break;
368
- case "JSONObjectExpression":
369
- generator.push(`{`);
528
+ case "ObjectExpression":
529
+ generator.push("{");
370
530
  generator.indent();
371
531
  propsCountStack.push(node2.properties.length);
372
- if (parent.type === "JSONArrayExpression") {
373
- const lastIndex2 = itemsCountStack.length - 1;
374
- const currentCount = parent.elements.length - itemsCountStack[lastIndex2];
375
- pathStack.push(currentCount.toString());
376
- itemsCountStack[lastIndex2] = --itemsCountStack[lastIndex2];
377
- }
378
532
  break;
379
- case "JSONProperty":
380
- if (node2.value.type === "JSONLiteral" && (node2.key.type === "JSONLiteral" || node2.key.type === "JSONIdentifier")) {
381
- const name = node2.key.type === "JSONLiteral" ? node2.key.value : node2.key.name;
382
- const value = node2.value.value;
383
- if (shared.isString(value)) {
384
- generator.push(`${JSON.stringify(name)}: `);
385
- pathStack.push(name.toString());
386
- const { code, map } = codegenFn(value, options, pathStack);
387
- sourceMap && map != null && codeMaps.set(value, map);
388
- generator.push(`${code}`, node2.value, value);
533
+ case "ArrayExpression":
534
+ generator.push("[");
535
+ generator.indent();
536
+ itemsCountStack.push(node2.elements.length);
537
+ break;
538
+ case "Property":
539
+ if (parent?.type !== "ObjectExpression")
540
+ break;
541
+ if (node2.key.type !== "Literal" && node2.key.type !== "Identifier")
542
+ break;
543
+ const name = node2.key.type === "Literal" ? String(node2.key.value) : node2.key.name;
544
+ const strName = JSON.stringify(name);
545
+ if (isJSONablePrimitiveLiteral(node2.value)) {
546
+ generator.push(`${strName}: `);
547
+ pathStack.push(name);
548
+ const value = getValue(node2.value);
549
+ const strValue = JSON.stringify(value);
550
+ if (node2.value.type === "Literal" && shared.isString(node2.value.value) || node2.value.type === "TemplateLiteral") {
551
+ generator.push(codegenFn(value), node2.value, value);
552
+ } else if (forceStringify) {
553
+ generator.push(codegenFn(strValue), node2.value, strValue);
389
554
  } else {
390
- if (forceStringify) {
391
- const strValue = JSON.stringify(value);
392
- generator.push(`${JSON.stringify(name)}: `);
393
- pathStack.push(name.toString());
394
- const { code, map } = codegenFn(strValue, options, pathStack);
395
- sourceMap && map != null && codeMaps.set(strValue, map);
396
- generator.push(`${code}`, node2.value, strValue);
397
- } else {
398
- generator.push(
399
- `${JSON.stringify(name)}: ${JSON.stringify(value)}`
400
- );
401
- pathStack.push(name.toString());
402
- }
555
+ generator.push(strValue);
556
+ }
557
+ skipStack.push(false);
558
+ } else if (node2.value.type === "ArrayExpression" || node2.value.type === "ObjectExpression") {
559
+ generator.push(`${strName}: `);
560
+ pathStack.push(name);
561
+ skipStack.push(false);
562
+ } else if (node2.value.type === "FunctionExpression" || node2.value.type === "ArrowFunctionExpression") {
563
+ generator.push(`${strName}: `);
564
+ pathStack.push(name);
565
+ const code = escodegen.generate(node2.value, {
566
+ format: { compact: true }
567
+ });
568
+ generator.push(code, node2.value, code);
569
+ skipStack.push(false);
570
+ } else {
571
+ const skipProperty = "regex" in node2.value;
572
+ if (!skipProperty && node2.type === "Property") {
573
+ const identifierName = node2.value.type === "Identifier" && String(node2.value.name) || node2.value.type === "Literal" && String(node2.value.value);
574
+ generator.push(`${strName}: ${identifierName || name}`);
575
+ skipStack.push(false);
576
+ } else {
577
+ skipStack.push(true);
403
578
  }
404
- } else if ((node2.value.type === "JSONObjectExpression" || node2.value.type === "JSONArrayExpression") && (node2.key.type === "JSONLiteral" || node2.key.type === "JSONIdentifier")) {
405
- const name = node2.key.type === "JSONLiteral" ? node2.key.value : node2.key.name;
406
- generator.push(`${JSON.stringify(name)}: `);
407
- pathStack.push(name.toString());
408
579
  }
409
- const lastIndex = propsCountStack.length - 1;
410
- propsCountStack[lastIndex] = --propsCountStack[lastIndex];
411
580
  break;
412
- case "JSONArrayExpression":
413
- generator.push(`[`);
414
- generator.indent();
415
- if (parent.type === "JSONArrayExpression") {
416
- const lastIndex2 = itemsCountStack.length - 1;
417
- const currentCount = parent.elements.length - itemsCountStack[lastIndex2];
418
- pathStack.push(currentCount.toString());
419
- itemsCountStack[lastIndex2] = --itemsCountStack[lastIndex2];
420
- }
421
- itemsCountStack.push(node2.elements.length);
581
+ case "SpreadElement":
582
+ const spreadIdentifier = node2.argument.type === "Identifier" && String(node2.argument.name) || node2.argument.type === "Literal" && String(node2.argument.value);
583
+ generator.push(`...${spreadIdentifier}`);
422
584
  break;
423
- case "JSONLiteral":
424
- if (parent.type === "JSONArrayExpression") {
425
- const lastIndex2 = itemsCountStack.length - 1;
426
- const currentCount = parent.elements.length - itemsCountStack[lastIndex2];
427
- pathStack.push(currentCount.toString());
428
- if (node2.type === "JSONLiteral") {
429
- const value = node2.value;
430
- if (shared.isString(value)) {
431
- const { code, map } = codegenFn(value, options, pathStack);
432
- sourceMap && map != null && codeMaps.set(value, map);
433
- generator.push(`${code}`, node2, value);
585
+ default:
586
+ if (parent?.type === "ArrayExpression") {
587
+ if (isJSONablePrimitiveLiteral(node2)) {
588
+ const value = getValue(node2);
589
+ const strValue = JSON.stringify(value);
590
+ if (node2.type === "Literal" && shared.isString(node2.value) || node2.type === "TemplateLiteral") {
591
+ generator.push(codegenFn(value), node2, value);
592
+ } else if (forceStringify) {
593
+ generator.push(codegenFn(strValue), node2, strValue);
434
594
  } else {
435
- if (forceStringify) {
436
- const strValue = JSON.stringify(value);
437
- const { code, map } = codegenFn(strValue, options, pathStack);
438
- sourceMap && map != null && codeMaps.set(strValue, map);
439
- generator.push(`${code}`, node2, strValue);
440
- } else {
441
- generator.push(`${JSON.stringify(value)}`);
442
- }
595
+ generator.push(strValue);
443
596
  }
597
+ skipStack.push(false);
598
+ } else {
599
+ skipStack.push(true);
444
600
  }
445
- itemsCountStack[lastIndex2] = --itemsCountStack[lastIndex2];
446
601
  }
447
602
  break;
448
603
  }
449
604
  },
450
- leaveNode(node2, parent) {
605
+ /**
606
+ * NOTE:
607
+ * force cast to Node of `estree-walker@3.x`,
608
+ * because `estree-walker@3.x` is not dual packages,
609
+ * so it's support only esm only ...
610
+ */
611
+ // @ts-ignore
612
+ leave(node2, parent) {
451
613
  switch (node2.type) {
452
614
  case "Program":
453
- if (type === "sfc") {
615
+ if (type === "plain") {
616
+ generator.push("\n");
617
+ generator.push("export default resource");
618
+ } else if (type === "sfc") {
454
619
  generator.deindent();
455
- generator.push(`})`);
620
+ generator.push("})");
456
621
  generator.deindent();
457
- generator.pushline(`}`);
458
- } else if (type === "plain") {
459
- generator.push(`
460
- `);
461
- generator.push("export default resource");
622
+ generator.pushline("}");
462
623
  }
463
624
  break;
464
- case "JSONObjectExpression":
625
+ case "ObjectExpression":
465
626
  if (propsCountStack[propsCountStack.length - 1] === 0) {
466
627
  pathStack.pop();
467
628
  propsCountStack.pop();
468
629
  }
469
630
  generator.deindent();
470
- generator.push(`}`);
471
- if (parent.type === "JSONArrayExpression") {
472
- if (itemsCountStack[itemsCountStack.length - 1] !== 0) {
473
- pathStack.pop();
474
- generator.pushline(`,`);
475
- }
476
- }
477
- break;
478
- case "JSONProperty":
479
- if (propsCountStack[propsCountStack.length - 1] !== 0) {
480
- pathStack.pop();
481
- generator.pushline(`,`);
482
- }
631
+ generator.push("}");
483
632
  break;
484
- case "JSONArrayExpression":
633
+ case "ArrayExpression":
485
634
  if (itemsCountStack[itemsCountStack.length - 1] === 0) {
486
635
  pathStack.pop();
487
636
  itemsCountStack.pop();
488
637
  }
489
638
  generator.deindent();
490
- generator.push(`]`);
491
- if (parent.type === "JSONArrayExpression") {
492
- if (itemsCountStack[itemsCountStack.length - 1] !== 0) {
493
- pathStack.pop();
494
- generator.pushline(`,`);
495
- }
496
- }
497
- break;
498
- case "JSONLiteral":
499
- if (parent.type === "JSONArrayExpression") {
500
- if (itemsCountStack[itemsCountStack.length - 1] !== 0) {
501
- pathStack.pop();
502
- generator.pushline(`,`);
503
- } else {
504
- generator.pushline(`,`);
505
- }
506
- }
639
+ generator.push("]");
507
640
  break;
508
641
  }
642
+ if (parent?.type === "ArrayExpression" || parent?.type === "ObjectExpression") {
643
+ const stackArr = node2.type === "Property" ? propsCountStack : itemsCountStack;
644
+ if (stackArr[stackArr.length - 1] !== 0) {
645
+ pathStack.pop();
646
+ !skipStack.pop() && generator.pushline(",");
647
+ }
648
+ }
509
649
  }
510
650
  });
511
651
  return codeMaps;
512
652
  }
653
+ function isJSONablePrimitiveLiteral(node) {
654
+ return node.type === "Literal" && (shared.isString(node.value) || shared.isNumber(node.value) || shared.isBoolean(node.value) || node.value === null) || node.type === "TemplateLiteral";
655
+ }
656
+ function getValue(node) {
657
+ return node.type === "Literal" ? node.value : node.type === "TemplateLiteral" ? node.quasis.map((quasi) => quasi.value.cooked).join("") : void 0;
658
+ }
513
659
 
514
660
  function generate$1(targetSource, {
515
661
  type = "plain",
516
662
  onlyLocales = [],
517
- filename = "vue-i18n-loader.yaml",
663
+ filename = "vue-i18n-loader.json",
518
664
  inSourceMap = void 0,
519
665
  locale = "",
520
666
  isGlobal = false,
@@ -542,27 +688,27 @@ function generate$1(targetSource, {
542
688
  escapeHtml,
543
689
  jit
544
690
  };
545
- let ast = yamlEslintParser.parseYAML(value, { filePath: filename });
691
+ let ast = jsoncEslintParser.parseJSON(value, { filePath: filename });
546
692
  if (!locale && type === "sfc" && onlyLocales?.length) {
547
- const messages = yamlEslintParser.getStaticYAMLValue(ast);
693
+ const messages = jsoncEslintParser.getStaticJSONValue(ast);
548
694
  value = JSON.stringify(
549
695
  excludeLocales({
550
696
  messages,
551
697
  onlyLocales
552
698
  })
553
699
  );
554
- ast = yamlEslintParser.parseYAML(value, { filePath: filename });
700
+ ast = jsoncEslintParser.parseJSON(value, { filePath: filename });
555
701
  }
556
702
  if (locale && onlyLocales?.length && !onlyLocales.includes(locale)) {
557
703
  value = JSON.stringify({});
558
- ast = yamlEslintParser.parseYAML(value, { filePath: filename });
704
+ ast = jsoncEslintParser.parseJSON(value, { filePath: filename });
559
705
  options.locale = "";
560
706
  options.source = void 0;
561
707
  }
562
708
  const generator = createCodeGenerator(options);
563
709
  const codeMaps = _generate$1(generator, ast, options);
564
710
  const { code, map } = generator.context();
565
- const newMap = map ? mapLinesColumns(map.toJSON(), codeMaps, inSourceMap) || null : null;
711
+ const newMap = map && !jit ? mapLinesColumns(map.toJSON(), codeMaps, inSourceMap) || null : null;
566
712
  return {
567
713
  ast,
568
714
  code,
@@ -576,111 +722,82 @@ function _generate$1(generator, node, options = {}) {
576
722
  const { forceStringify } = generator.context();
577
723
  const codeMaps = /* @__PURE__ */ new Map();
578
724
  const { type, sourceMap, isGlobal, locale, jit } = options;
579
- const codegenFn = jit ? generateResourceAst : generateMessageFunction;
725
+ const _codegenFn = jit ? generateResourceAst : generateMessageFunction;
726
+ function codegenFn(value) {
727
+ const { code, map } = _codegenFn(value, options, pathStack);
728
+ sourceMap && map != null && codeMaps.set(value, map);
729
+ return code;
730
+ }
580
731
  const componentNamespace = "_Component";
581
- yamlEslintParser.traverseNodes(node, {
732
+ jsoncEslintParser.traverseNodes(node, {
582
733
  enterNode(node2, parent) {
734
+ if (parent?.type === "JSONArrayExpression") {
735
+ const lastIndex = itemsCountStack.length - 1;
736
+ const currentCount = parent.elements.length - itemsCountStack[lastIndex];
737
+ pathStack.push(currentCount.toString());
738
+ itemsCountStack[lastIndex] = --itemsCountStack[lastIndex];
739
+ } else if (parent?.type === "JSONObjectExpression") {
740
+ const lastIndex = propsCountStack.length - 1;
741
+ propsCountStack[lastIndex] = --propsCountStack[lastIndex];
742
+ }
583
743
  switch (node2.type) {
584
744
  case "Program":
585
745
  if (type === "plain") {
586
746
  generator.push(`const resource = `);
587
747
  } else if (type === "sfc") {
588
- const variableName = type === "sfc" ? !isGlobal ? "__i18n" : "__i18nGlobal" : "";
589
- const localeName = type === "sfc" ? locale != null ? locale : `""` : "";
590
- const exportSyntax = "export default";
591
- generator.push(`${exportSyntax} function (Component) {`);
748
+ const variableName = !isGlobal ? "__i18n" : "__i18nGlobal";
749
+ const localeName = JSON.stringify(locale ?? `""`);
750
+ generator.push(`export default function (Component) {`);
592
751
  generator.indent();
593
- const componentVariable = `Component`;
594
- generator.pushline(
595
- `const ${componentNamespace} = ${componentVariable}`
596
- );
752
+ generator.pushline(`const ${componentNamespace} = Component`);
597
753
  generator.pushline(
598
754
  `${componentNamespace}.${variableName} = ${componentNamespace}.${variableName} || []`
599
755
  );
600
756
  generator.push(`${componentNamespace}.${variableName}.push({`);
601
757
  generator.indent();
602
- generator.pushline(`"locale": ${JSON.stringify(localeName)},`);
758
+ generator.pushline(`"locale": ${localeName},`);
603
759
  generator.push(`"resource": `);
604
760
  }
605
761
  break;
606
- case "YAMLMapping":
762
+ case "JSONObjectExpression":
607
763
  generator.push(`{`);
608
764
  generator.indent();
609
- propsCountStack.push(node2.pairs.length);
610
- if (parent.type === "YAMLSequence") {
611
- const lastIndex2 = itemsCountStack.length - 1;
612
- const currentCount = parent.entries.length - itemsCountStack[lastIndex2];
613
- pathStack.push(currentCount.toString());
614
- itemsCountStack[lastIndex2] = --itemsCountStack[lastIndex2];
615
- }
616
- break;
617
- case "YAMLPair":
618
- if (node2.value && node2.value.type === "YAMLScalar" && node2.key && node2.key.type === "YAMLScalar") {
619
- const name = node2.key.value;
620
- const value = node2.value.value;
621
- if (shared.isString(value)) {
622
- generator.push(`${JSON.stringify(name)}: `);
623
- name && pathStack.push(name.toString());
624
- const { code, map } = codegenFn(value, options, pathStack);
625
- sourceMap && map != null && codeMaps.set(value, map);
626
- generator.push(`${code}`, node2.value, value);
627
- } else {
628
- if (forceStringify) {
629
- const strValue = JSON.stringify(value);
630
- generator.push(`${JSON.stringify(name)}: `);
631
- name && pathStack.push(name.toString());
632
- const { code, map } = codegenFn(strValue, options, pathStack);
633
- sourceMap && map != null && codeMaps.set(strValue, map);
634
- generator.push(`${code}`, node2.value, strValue);
635
- } else {
636
- generator.push(
637
- `${JSON.stringify(name)}: ${JSON.stringify(value)}`
638
- );
639
- name && pathStack.push(name.toString());
640
- }
641
- }
642
- } else if (node2.value && (node2.value.type === "YAMLMapping" || node2.value.type === "YAMLSequence") && node2.key && node2.key.type === "YAMLScalar") {
643
- const name = node2.key.value;
644
- generator.push(`${JSON.stringify(name)}: `);
645
- name && pathStack.push(name.toString());
646
- }
647
- const lastIndex = propsCountStack.length - 1;
648
- propsCountStack[lastIndex] = --propsCountStack[lastIndex];
765
+ propsCountStack.push(node2.properties.length);
649
766
  break;
650
- case "YAMLSequence":
767
+ case "JSONArrayExpression":
651
768
  generator.push(`[`);
652
769
  generator.indent();
653
- if (parent.type === "YAMLSequence") {
654
- const lastIndex2 = itemsCountStack.length - 1;
655
- const currentCount = parent.entries.length - itemsCountStack[lastIndex2];
656
- pathStack.push(currentCount.toString());
657
- itemsCountStack[lastIndex2] = --itemsCountStack[lastIndex2];
658
- }
659
- itemsCountStack.push(node2.entries.length);
770
+ itemsCountStack.push(node2.elements.length);
660
771
  break;
661
- case "YAMLScalar":
662
- if (parent.type === "YAMLSequence") {
663
- const lastIndex2 = itemsCountStack.length - 1;
664
- const currentCount = parent.entries.length - itemsCountStack[lastIndex2];
665
- pathStack.push(currentCount.toString());
666
- if (node2.type === "YAMLScalar") {
667
- const value = node2.value;
668
- if (shared.isString(value)) {
669
- const { code, map } = codegenFn(value, options, pathStack);
670
- sourceMap && map != null && codeMaps.set(value, map);
671
- generator.push(`${code}`, node2, value);
672
- } else {
673
- if (forceStringify) {
674
- const strValue = JSON.stringify(value);
675
- const { code, map } = codegenFn(strValue, options, pathStack);
676
- sourceMap && map != null && codeMaps.set(strValue, map);
677
- generator.push(`${code}`, node2, strValue);
678
- } else {
679
- generator.push(`${JSON.stringify(value)}`);
680
- }
681
- }
772
+ case "JSONProperty": {
773
+ const name = node2.key.type === "JSONLiteral" ? node2.key.value : node2.key.name;
774
+ const strName = JSON.stringify(name);
775
+ generator.push(`${strName}: `);
776
+ pathStack.push(name.toString());
777
+ if (node2.value.type === "JSONLiteral") {
778
+ const value2 = node2.value.value;
779
+ const strValue2 = JSON.stringify(value2);
780
+ if (shared.isString(value2)) {
781
+ generator.push(codegenFn(value2), node2.value, value2);
782
+ } else if (forceStringify) {
783
+ generator.push(codegenFn(strValue2), node2.value, strValue2);
784
+ } else {
785
+ generator.push(strValue2);
682
786
  }
683
- itemsCountStack[lastIndex2] = --itemsCountStack[lastIndex2];
787
+ }
788
+ break;
789
+ }
790
+ case "JSONLiteral":
791
+ if (parent.type !== "JSONArrayExpression")
792
+ break;
793
+ const value = node2.value;
794
+ const strValue = JSON.stringify(value);
795
+ if (shared.isString(value)) {
796
+ generator.push(codegenFn(value), node2, value);
797
+ } else if (forceStringify) {
798
+ generator.push(codegenFn(strValue), node2, strValue);
799
+ } else {
800
+ generator.push(strValue);
684
801
  }
685
802
  break;
686
803
  }
@@ -692,58 +809,37 @@ function _generate$1(generator, node, options = {}) {
692
809
  generator.deindent();
693
810
  generator.push(`})`);
694
811
  generator.deindent();
695
- generator.push(`}`);
812
+ generator.pushline(`}`);
696
813
  } else if (type === "plain") {
697
814
  generator.push(`
698
815
  `);
699
816
  generator.push("export default resource");
700
817
  }
701
818
  break;
702
- case "YAMLMapping":
819
+ case "JSONObjectExpression":
703
820
  if (propsCountStack[propsCountStack.length - 1] === 0) {
704
821
  pathStack.pop();
705
822
  propsCountStack.pop();
706
823
  }
707
824
  generator.deindent();
708
825
  generator.push(`}`);
709
- if (parent.type === "YAMLSequence") {
710
- if (itemsCountStack[itemsCountStack.length - 1] !== 0) {
711
- pathStack.pop();
712
- generator.pushline(`,`);
713
- }
714
- }
715
- break;
716
- case "YAMLPair":
717
- if (propsCountStack[propsCountStack.length - 1] !== 0) {
718
- pathStack.pop();
719
- generator.pushline(`,`);
720
- }
721
826
  break;
722
- case "YAMLSequence":
827
+ case "JSONArrayExpression":
723
828
  if (itemsCountStack[itemsCountStack.length - 1] === 0) {
724
829
  pathStack.pop();
725
830
  itemsCountStack.pop();
726
831
  }
727
832
  generator.deindent();
728
833
  generator.push(`]`);
729
- if (parent.type === "YAMLSequence") {
730
- if (itemsCountStack[itemsCountStack.length - 1] !== 0) {
731
- pathStack.pop();
732
- generator.pushline(`,`);
733
- }
734
- }
735
- break;
736
- case "YAMLScalar":
737
- if (parent.type === "YAMLSequence") {
738
- if (itemsCountStack[itemsCountStack.length - 1] !== 0) {
739
- pathStack.pop();
740
- generator.pushline(`,`);
741
- } else {
742
- generator.pushline(`,`);
743
- }
744
- }
745
834
  break;
746
835
  }
836
+ if (parent?.type === "JSONArrayExpression" || parent?.type === "JSONObjectExpression") {
837
+ const stackArr = node2.type === "JSONProperty" ? propsCountStack : itemsCountStack;
838
+ if (stackArr[stackArr.length - 1] !== 0) {
839
+ pathStack.pop();
840
+ generator.pushline(`,`);
841
+ }
842
+ }
747
843
  }
748
844
  });
749
845
  return codeMaps;
@@ -751,7 +847,8 @@ function _generate$1(generator, node, options = {}) {
751
847
 
752
848
  function generate(targetSource, {
753
849
  type = "plain",
754
- filename = "vue-i18n-loader.js",
850
+ onlyLocales = [],
851
+ filename = "vue-i18n-loader.yaml",
755
852
  inSourceMap = void 0,
756
853
  locale = "",
757
854
  isGlobal = false,
@@ -761,11 +858,9 @@ function generate(targetSource, {
761
858
  onError = void 0,
762
859
  strictMessage = true,
763
860
  escapeHtml = false,
764
- allowDynamic = false,
765
861
  jit = false
766
862
  }) {
767
- const target = Buffer.isBuffer(targetSource) ? targetSource.toString() : targetSource;
768
- const value = target;
863
+ let value = Buffer.isBuffer(targetSource) ? targetSource.toString() : targetSource;
769
864
  const options = {
770
865
  type,
771
866
  source: value,
@@ -781,34 +876,24 @@ function generate(targetSource, {
781
876
  escapeHtml,
782
877
  jit
783
878
  };
784
- const generator = createCodeGenerator(options);
785
- const ast = acorn.parse(value, {
786
- ecmaVersion: "latest",
787
- sourceType: "module",
788
- sourceFile: filename,
789
- allowImportExportEverywhere: true
790
- });
791
- const exportResult = scanAst(ast);
792
- if (!allowDynamic) {
793
- if (!exportResult || exportResult !== "object") {
794
- throw new Error(
795
- `You need to define an object as the locale message with 'export default'.`
796
- );
797
- }
798
- } else {
799
- if (!exportResult) {
800
- throw new Error(
801
- `You need to define 'export default' that will return the locale messages.`
802
- );
803
- }
804
- if (exportResult !== "object") {
805
- return {
806
- ast,
807
- code: value,
808
- map: inSourceMap
809
- };
810
- }
879
+ let ast = yamlEslintParser.parseYAML(value, { filePath: filename });
880
+ if (!locale && type === "sfc" && onlyLocales?.length) {
881
+ const messages = yamlEslintParser.getStaticYAMLValue(ast);
882
+ value = JSON.stringify(
883
+ excludeLocales({
884
+ messages,
885
+ onlyLocales
886
+ })
887
+ );
888
+ ast = yamlEslintParser.parseYAML(value, { filePath: filename });
889
+ }
890
+ if (locale && onlyLocales?.length && !onlyLocales.includes(locale)) {
891
+ value = JSON.stringify({});
892
+ ast = yamlEslintParser.parseYAML(value, { filePath: filename });
893
+ options.locale = "";
894
+ options.source = void 0;
811
895
  }
896
+ const generator = createCodeGenerator(options);
812
897
  const codeMaps = _generate(generator, ast, options);
813
898
  const { code, map } = generator.context();
814
899
  const newMap = map ? mapLinesColumns(map.toJSON(), codeMaps, inSourceMap) || null : null;
@@ -818,318 +903,146 @@ function generate(targetSource, {
818
903
  map: newMap != null ? newMap : void 0
819
904
  };
820
905
  }
821
- function scanAst(ast) {
822
- if (ast.type !== "Program") {
823
- throw new Error("Invalid AST: does not have Program node");
824
- }
825
- let ret = false;
826
- for (const node of ast.body) {
827
- if (node.type === "ExportDefaultDeclaration") {
828
- if (node.declaration.type === "ObjectExpression") {
829
- ret = "object";
830
- break;
831
- } else if (node.declaration.type === "FunctionDeclaration") {
832
- ret = "function";
833
- break;
834
- } else if (node.declaration.type === "ArrowFunctionExpression") {
835
- ret = "arrow-function";
836
- break;
837
- }
838
- }
839
- }
840
- return ret;
841
- }
842
906
  function _generate(generator, node, options = {}) {
843
907
  const propsCountStack = [];
844
908
  const pathStack = [];
845
909
  const itemsCountStack = [];
846
- const skipStack = [];
847
910
  const { forceStringify } = generator.context();
848
911
  const codeMaps = /* @__PURE__ */ new Map();
849
912
  const { type, sourceMap, isGlobal, locale, jit } = options;
850
- const codegenFn = jit ? generateResourceAst : generateMessageFunction;
913
+ const _codegenFn = jit ? generateResourceAst : generateMessageFunction;
914
+ function codegenFn(value) {
915
+ const { code, map } = _codegenFn(value, options, pathStack);
916
+ sourceMap && map != null && codeMaps.set(value, map);
917
+ return code;
918
+ }
851
919
  const componentNamespace = "_Component";
852
- estreeWalker.walk(node, {
853
- /**
854
- * NOTE:
855
- * force cast to Node of `estree-walker@3.x`,
856
- * because `estree-walker@3.x` is not dual packages,
857
- * so it's support only esm only ...
858
- */
859
- // @ts-ignore
860
- enter(node2, parent) {
920
+ yamlEslintParser.traverseNodes(node, {
921
+ enterNode(node2, parent) {
922
+ if (parent?.type === "YAMLSequence") {
923
+ const lastIndex = itemsCountStack.length - 1;
924
+ const currentCount = parent.entries.length - itemsCountStack[lastIndex];
925
+ pathStack.push(currentCount.toString());
926
+ itemsCountStack[lastIndex] = --itemsCountStack[lastIndex];
927
+ } else if (parent?.type === "YAMLMapping") {
928
+ const lastIndex = propsCountStack.length - 1;
929
+ propsCountStack[lastIndex] = --propsCountStack[lastIndex];
930
+ }
861
931
  switch (node2.type) {
862
932
  case "Program":
863
933
  if (type === "plain") {
864
934
  generator.push(`const resource = `);
865
935
  } else if (type === "sfc") {
866
- const variableName = type === "sfc" ? !isGlobal ? "__i18n" : "__i18nGlobal" : "";
867
- const localeName = type === "sfc" ? locale != null ? locale : `""` : "";
868
- const exportSyntax = "export default";
869
- generator.push(`${exportSyntax} function (Component) {`);
936
+ const variableName = !isGlobal ? "__i18n" : "__i18nGlobal";
937
+ const localeName = JSON.stringify(locale ?? `""`);
938
+ generator.push(`export default function (Component) {`);
870
939
  generator.indent();
871
- const componentVariable = `Component`;
872
- generator.pushline(
873
- `const ${componentNamespace} = ${componentVariable}`
874
- );
940
+ generator.pushline(`const ${componentNamespace} = Component`);
875
941
  generator.pushline(
876
942
  `${componentNamespace}.${variableName} = ${componentNamespace}.${variableName} || []`
877
943
  );
878
944
  generator.push(`${componentNamespace}.${variableName}.push({`);
879
945
  generator.indent();
880
- generator.pushline(`"locale": ${JSON.stringify(localeName)},`);
946
+ generator.pushline(`"locale": ${localeName},`);
881
947
  generator.push(`"resource": `);
882
948
  }
883
949
  break;
884
- case "ObjectExpression":
950
+ case "YAMLMapping":
885
951
  generator.push(`{`);
886
952
  generator.indent();
887
- propsCountStack.push(node2.properties.length);
888
- if (parent != null && parent.type === "ArrayExpression") {
889
- const lastIndex = itemsCountStack.length - 1;
890
- const currentCount = parent.elements.length - itemsCountStack[lastIndex];
891
- pathStack.push(currentCount.toString());
892
- itemsCountStack[lastIndex] = --itemsCountStack[lastIndex];
893
- }
894
- break;
895
- case "Property":
896
- if (parent != null && parent.type === "ObjectExpression") {
897
- if (node2 != null) {
898
- if (isJSONablePrimitiveLiteral(node2.value) && (node2.key.type === "Literal" || node2.key.type === "Identifier")) {
899
- const name = node2.key.type === "Literal" ? String(node2.key.value) : node2.key.name;
900
- if (node2.value.type === "Literal" && shared.isString(node2.value.value) || node2.value.type === "TemplateLiteral") {
901
- const value = getValue(node2.value);
902
- generator.push(`${JSON.stringify(name)}: `);
903
- pathStack.push(name);
904
- const { code, map } = codegenFn(value, options, pathStack);
905
- sourceMap && map != null && codeMaps.set(value, map);
906
- generator.push(`${code}`, node2.value, value);
907
- skipStack.push(false);
908
- } else {
909
- const value = getValue(node2.value);
910
- if (forceStringify) {
911
- const strValue = JSON.stringify(value);
912
- generator.push(`${JSON.stringify(name)}: `);
913
- pathStack.push(name);
914
- const { code, map } = codegenFn(
915
- strValue,
916
- options,
917
- pathStack
918
- );
919
- sourceMap && map != null && codeMaps.set(strValue, map);
920
- generator.push(`${code}`, node2.value, strValue);
921
- } else {
922
- generator.push(
923
- `${JSON.stringify(name)}: ${JSON.stringify(value)}`
924
- );
925
- pathStack.push(name);
926
- }
927
- skipStack.push(false);
928
- }
929
- } else if ((node2.value.type === "FunctionExpression" || node2.value.type === "ArrowFunctionExpression") && (node2.key.type === "Literal" || node2.key.type === "Identifier")) {
930
- const name = node2.key.type === "Literal" ? String(node2.key.value) : node2.key.name;
931
- generator.push(`${JSON.stringify(name)}: `);
932
- pathStack.push(name);
933
- const code = escodegen.generate(node2.value);
934
- generator.push(`${code}`, node2.value, code);
935
- skipStack.push(false);
936
- } else if ((node2.value.type === "ObjectExpression" || node2.value.type === "ArrayExpression") && (node2.key.type === "Literal" || node2.key.type === "Identifier")) {
937
- const name = node2.key.type === "Literal" ? String(node2.key.value) : node2.key.name;
938
- generator.push(`${JSON.stringify(name)}: `);
939
- pathStack.push(name);
940
- } else {
941
- skipStack.push(true);
942
- }
943
- }
944
- const lastIndex = propsCountStack.length - 1;
945
- propsCountStack[lastIndex] = --propsCountStack[lastIndex];
946
- }
953
+ propsCountStack.push(node2.pairs.length);
947
954
  break;
948
- case "ArrayExpression":
955
+ case "YAMLSequence":
949
956
  generator.push(`[`);
950
957
  generator.indent();
951
- if (parent != null && parent.type === "ArrayExpression") {
952
- const lastIndex = itemsCountStack.length - 1;
953
- const currentCount = parent.elements.length - itemsCountStack[lastIndex];
954
- pathStack.push(currentCount.toString());
955
- itemsCountStack[lastIndex] = --itemsCountStack[lastIndex];
958
+ itemsCountStack.push(node2.entries.length);
959
+ break;
960
+ case "YAMLPair":
961
+ if (node2.key?.type !== "YAMLScalar")
962
+ break;
963
+ if (node2.value?.type === "YAMLScalar") {
964
+ const name = node2.key.value;
965
+ const value = node2.value.value;
966
+ const strName = JSON.stringify(name);
967
+ const strValue = JSON.stringify(value);
968
+ name && pathStack.push(name.toString());
969
+ generator.push(`${strName}: `);
970
+ if (shared.isString(value)) {
971
+ generator.push(codegenFn(value), node2.value, value);
972
+ } else if (forceStringify) {
973
+ generator.push(codegenFn(strValue), node2.value, strValue);
974
+ } else {
975
+ generator.push(strValue);
976
+ }
977
+ } else if (node2.value?.type === "YAMLMapping" || node2.value?.type === "YAMLSequence") {
978
+ const name = node2.key.value;
979
+ name && pathStack.push(name.toString());
980
+ generator.push(`${JSON.stringify(name)}: `);
956
981
  }
957
- itemsCountStack.push(node2.elements.length);
958
982
  break;
959
- default:
960
- if (node2 != null && parent != null) {
961
- if (parent.type === "ArrayExpression") {
962
- const lastIndex = itemsCountStack.length - 1;
963
- const currentCount = parent.elements.length - itemsCountStack[lastIndex];
964
- pathStack.push(currentCount.toString());
965
- if (isJSONablePrimitiveLiteral(node2)) {
966
- if (node2.type === "Literal" && shared.isString(node2.value) || node2.type === "TemplateLiteral") {
967
- const value = getValue(node2);
968
- const { code, map } = codegenFn(value, options, pathStack);
969
- sourceMap && map != null && codeMaps.set(value, map);
970
- generator.push(`${code}`, node2, value);
971
- } else {
972
- const value = getValue(node2);
973
- if (forceStringify) {
974
- const strValue = JSON.stringify(value);
975
- const { code, map } = codegenFn(
976
- strValue,
977
- options,
978
- pathStack
979
- );
980
- sourceMap && map != null && codeMaps.set(strValue, map);
981
- generator.push(`${code}`, node2, strValue);
982
- } else {
983
- generator.push(`${JSON.stringify(value)}`);
984
- }
985
- }
986
- skipStack.push(false);
987
- } else {
988
- skipStack.push(true);
989
- }
990
- itemsCountStack[lastIndex] = --itemsCountStack[lastIndex];
983
+ case "YAMLScalar":
984
+ if (parent.type === "YAMLSequence") {
985
+ const value = node2.value;
986
+ const strValue = JSON.stringify(value);
987
+ if (shared.isString(value)) {
988
+ generator.push(codegenFn(value), node2, value);
989
+ } else if (forceStringify) {
990
+ generator.push(codegenFn(strValue), node2, strValue);
991
+ } else {
992
+ generator.push(strValue);
991
993
  }
992
994
  }
993
995
  break;
994
996
  }
995
997
  },
996
- /**
997
- * NOTE:
998
- * force cast to Node of `estree-walker@3.x`,
999
- * because `estree-walker@3.x` is not dual packages,
1000
- * so it's support only esm only ...
1001
- */
1002
- // @ts-ignore
1003
- leave(node2, parent) {
998
+ leaveNode(node2, parent) {
1004
999
  switch (node2.type) {
1005
1000
  case "Program":
1006
1001
  if (type === "sfc") {
1007
1002
  generator.deindent();
1008
1003
  generator.push(`})`);
1009
1004
  generator.deindent();
1010
- generator.pushline(`}`);
1005
+ generator.push(`}`);
1011
1006
  } else if (type === "plain") {
1012
1007
  generator.push(`
1013
1008
  `);
1014
1009
  generator.push("export default resource");
1015
1010
  }
1016
1011
  break;
1017
- case "ObjectExpression":
1012
+ case "YAMLMapping":
1018
1013
  if (propsCountStack[propsCountStack.length - 1] === 0) {
1019
1014
  pathStack.pop();
1020
1015
  propsCountStack.pop();
1021
1016
  }
1022
1017
  generator.deindent();
1023
1018
  generator.push(`}`);
1024
- if (parent != null && parent.type === "ArrayExpression") {
1025
- if (itemsCountStack[itemsCountStack.length - 1] !== 0) {
1026
- pathStack.pop();
1027
- generator.pushline(`,`);
1028
- }
1029
- }
1030
1019
  break;
1031
- case "Property":
1032
- if (parent != null && parent.type === "ObjectExpression") {
1033
- if (propsCountStack[propsCountStack.length - 1] !== 0) {
1034
- pathStack.pop();
1035
- if (!skipStack.pop()) {
1036
- generator.pushline(`,`);
1037
- }
1038
- }
1039
- }
1040
- break;
1041
- case "ArrayExpression":
1020
+ case "YAMLSequence":
1042
1021
  if (itemsCountStack[itemsCountStack.length - 1] === 0) {
1043
1022
  pathStack.pop();
1044
1023
  itemsCountStack.pop();
1045
1024
  }
1046
1025
  generator.deindent();
1047
1026
  generator.push(`]`);
1048
- if (parent != null && parent.type === "ArrayExpression") {
1049
- if (itemsCountStack[itemsCountStack.length - 1] !== 0) {
1050
- pathStack.pop();
1051
- if (!skipStack.pop()) {
1052
- generator.pushline(`,`);
1053
- }
1054
- }
1055
- }
1056
- break;
1057
- case "Literal":
1058
- if (parent != null && parent.type === "ArrayExpression") {
1059
- if (itemsCountStack[itemsCountStack.length - 1] !== 0) {
1060
- pathStack.pop();
1061
- if (!skipStack.pop()) {
1062
- generator.pushline(`,`);
1063
- }
1064
- } else {
1065
- if (!skipStack.pop()) {
1066
- generator.pushline(`,`);
1067
- }
1068
- }
1069
- }
1070
1027
  break;
1071
1028
  }
1029
+ const stackArr = node2.type === "YAMLPair" ? propsCountStack : itemsCountStack;
1030
+ if (parent?.type === "YAMLSequence" || parent?.type === "YAMLMapping") {
1031
+ if (stackArr[stackArr.length - 1] !== 0) {
1032
+ pathStack.pop();
1033
+ generator.pushline(`,`);
1034
+ } else if (node2.type === "YAMLScalar") {
1035
+ generator.pushline(`,`);
1036
+ }
1037
+ }
1072
1038
  }
1073
1039
  });
1074
1040
  return codeMaps;
1075
1041
  }
1076
- function isJSONablePrimitiveLiteral(node) {
1077
- return node.type === "Literal" && (shared.isString(node.value) || shared.isNumber(node.value) || shared.isBoolean(node.value) || node.value === null) || node.type === "TemplateLiteral";
1078
- }
1079
- function getValue(node) {
1080
- return node.type === "Literal" ? node.value : node.type === "TemplateLiteral" ? node.quasis.map((quasi) => quasi.value.cooked).join("") : void 0;
1081
- }
1082
-
1083
- const _require = module__default.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href)));
1084
- function checkInstallPackage(pkg, debug) {
1085
- let installedVueI18n = false;
1086
- try {
1087
- debug(`vue-i18n load path: ${_require.resolve("vue-i18n")}`);
1088
- installedVueI18n = true;
1089
- } catch (e) {
1090
- debug(`cannot find 'vue-i18n'`, e);
1091
- }
1092
- let installedPetiteVueI18n = false;
1093
- try {
1094
- debug(`petite-vue-i18n load path: ${_require.resolve("petite-vue-i18n")}`);
1095
- installedPetiteVueI18n = true;
1096
- } catch (e) {
1097
- debug(`cannot find 'petite-vue-i18n'`, e);
1098
- }
1099
- if (installedVueI18n) {
1100
- return "vue-i18n";
1101
- }
1102
- if (installedPetiteVueI18n) {
1103
- return "petite-vue-i18n";
1104
- }
1105
- throw new Error(
1106
- `${pkg} requires 'vue-i18n' or 'petite-vue-i18n' to be present in the dependency tree.`
1107
- );
1108
- }
1109
- function getVueI18nVersion(debug, pkg = "vue-i18n") {
1110
- const VueI18n = loadModule(pkg, debug);
1111
- if (VueI18n == null) {
1112
- return "";
1113
- }
1114
- if (VueI18n.VERSION && VueI18n.VERSION.startsWith("9.")) {
1115
- return "9";
1116
- }
1117
- if (VueI18n.VERSION && VueI18n.VERSION.startsWith("10.")) {
1118
- return "10";
1119
- }
1120
- return "unknown";
1121
- }
1122
- function loadModule(moduleName, debug) {
1123
- try {
1124
- return _require(moduleName);
1125
- } catch (e) {
1126
- debug(`cannot load '${moduleName}'`, e);
1127
- return null;
1128
- }
1129
- }
1130
1042
 
1043
+ exports.DynamicResourceError = DynamicResourceError;
1131
1044
  exports.checkInstallPackage = checkInstallPackage;
1132
- exports.generateJSON = generate$2;
1133
- exports.generateJavaScript = generate;
1134
- exports.generateYAML = generate$1;
1045
+ exports.generateJSON = generate$1;
1046
+ exports.generateJavaScript = generate$2;
1047
+ exports.generateYAML = generate;
1135
1048
  exports.getVueI18nVersion = getVueI18nVersion;