@intlify/bundle-utils 12.0.0-alpha.2 → 12.0.0-alpha.3

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
@@ -2,13 +2,13 @@
2
2
 
3
3
  const module$1 = require('node:module');
4
4
  const shared = require('@intlify/shared');
5
- const acorn = require('acorn');
6
5
  const escodegen = require('escodegen');
7
- const estreeWalker = require('estree-walker');
6
+ const oxcParser = require('oxc-parser');
7
+ const oxcWalker = require('oxc-walker');
8
8
  const messageCompiler = require('@intlify/message-compiler');
9
9
  const sourceMapJs = require('source-map-js');
10
10
  const jsoncEslintParser = require('jsonc-eslint-parser');
11
- const esbuild = require('esbuild');
11
+ const oxcTransform = require('oxc-transform');
12
12
  const yamlEslintParser = require('yaml-eslint-parser');
13
13
 
14
14
  var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
@@ -210,39 +210,46 @@ function mapLinesColumns(resMap, codeMaps, inSourceMap) {
210
210
  if (inMapFirstItem) {
211
211
  return;
212
212
  }
213
+ if (m.originalLine == null || m.originalColumn == null) {
214
+ return;
215
+ }
213
216
  inMapFirstItem = m;
214
217
  });
215
218
  }
216
219
  resMapConsumer.eachMapping((res) => {
217
- if (res.originalLine == null) {
220
+ const resOriginalLine = res.originalLine;
221
+ const resOriginalColumn = res.originalColumn;
222
+ const resName = res.name;
223
+ if (resOriginalLine == null || resOriginalColumn == null || resName == null) {
218
224
  return;
219
225
  }
220
- const map = codeMaps.get(res.name);
226
+ const map = codeMaps.get(resName);
221
227
  if (!map) {
222
228
  return;
223
229
  }
224
230
  let inMapOrigin = null;
225
231
  if (inMapConsumer) {
226
232
  inMapOrigin = inMapConsumer.originalPositionFor({
227
- line: res.originalLine,
228
- column: res.originalColumn - 1
233
+ line: resOriginalLine,
234
+ column: resOriginalColumn - 1
229
235
  });
230
236
  if (inMapOrigin.source == null) {
231
237
  inMapOrigin = null;
232
238
  return;
233
239
  }
234
240
  }
241
+ const inMapFirst = inMapFirstItem;
235
242
  const mapConsumer = new sourceMapJs.SourceMapConsumer(map);
236
243
  mapConsumer.eachMapping((m) => {
237
244
  mergedMapGenerator.addMapping({
238
245
  original: {
239
- line: inMapFirstItem ? inMapFirstItem.originalLine + res.originalLine - 2 : res.originalLine,
240
- column: inMapFirstItem ? inMapFirstItem.originalColumn + res.originalColumn : res.originalColumn
246
+ line: inMapFirst ? inMapFirst.originalLine + resOriginalLine - 2 : resOriginalLine,
247
+ column: inMapFirst ? inMapFirst.originalColumn + resOriginalColumn : resOriginalColumn
241
248
  },
242
249
  generated: {
243
- line: inMapFirstItem ? inMapFirstItem.generatedLine + res.originalLine - 2 : res.originalLine,
250
+ line: inMapFirst ? inMapFirst.generatedLine + resOriginalLine - 2 : resOriginalLine,
244
251
  // map column with message format compilation code map
245
- column: inMapFirstItem ? inMapFirstItem.generatedColumn + res.originalColumn + m.generatedColumn : res.originalColumn + m.generatedColumn
252
+ column: inMapFirst ? inMapFirst.generatedColumn + resOriginalColumn + m.generatedColumn : resOriginalColumn + m.generatedColumn
246
253
  },
247
254
  source: inMapOrigin ? inMapOrigin.source : res.source,
248
255
  name: m.name
@@ -324,48 +331,32 @@ function excludeLocales({
324
331
 
325
332
  class DynamicResourceError extends Error {
326
333
  }
327
- function generate$3(targetSource, {
328
- type = "plain",
329
- filename = "vue-i18n-loader.js",
330
- inSourceMap = void 0,
331
- locale = "",
332
- isGlobal = false,
333
- sourceMap = false,
334
- env = "development",
335
- forceStringify = false,
336
- onError = void 0,
337
- onWarn = void 0,
338
- strictMessage = true,
339
- escapeHtml = false,
340
- allowDynamic = false,
341
- jit = false
342
- }) {
334
+ const DEFAULT_OPTIONS = {
335
+ type: "plain",
336
+ filename: "vue-i18n-loader.js",
337
+ inSourceMap: void 0,
338
+ locale: "",
339
+ isGlobal: false,
340
+ sourceMap: false,
341
+ env: "development",
342
+ forceStringify: false,
343
+ onError: void 0,
344
+ onWarn: void 0,
345
+ strictMessage: true,
346
+ escapeHtml: false,
347
+ allowDynamic: false,
348
+ jit: false
349
+ };
350
+ function generate$3(targetSource, options) {
343
351
  const value = Buffer.isBuffer(targetSource) ? targetSource.toString() : targetSource;
344
- const options = {
345
- type,
346
- source: value,
347
- sourceMap,
348
- locale,
349
- isGlobal,
350
- inSourceMap,
351
- env,
352
- filename,
353
- forceStringify,
354
- onError,
355
- onWarn,
356
- strictMessage,
357
- escapeHtml,
358
- jit
359
- };
360
- const generator = createCodeGenerator(options);
361
- const ast = acorn.parse(value, {
362
- ecmaVersion: "latest",
352
+ const _options = Object.assign({}, DEFAULT_OPTIONS, options, { source: value });
353
+ const generator = createCodeGenerator(_options);
354
+ const { program: ast } = oxcParser.parseSync(_options.filename ?? "", value, {
363
355
  sourceType: "module",
364
- sourceFile: filename,
365
- allowImportExportEverywhere: true
356
+ lang: "js"
366
357
  });
367
358
  const exportResult = scanAst(ast);
368
- if (!allowDynamic) {
359
+ if (!_options.allowDynamic) {
369
360
  if (!exportResult) {
370
361
  throw new Error(`You need to define an object as the locale message with 'export default'.`);
371
362
  }
@@ -382,13 +373,13 @@ function generate$3(targetSource, {
382
373
  return {
383
374
  ast,
384
375
  code: value,
385
- map: inSourceMap
376
+ map: _options.inSourceMap
386
377
  };
387
378
  }
388
379
  }
389
- const codeMaps = _generate$2(generator, ast, options);
380
+ const codeMaps = _generate$2(generator, ast, _options);
390
381
  const { code, map } = generator.context();
391
- const newMap = map ? mapLinesColumns(map.toJSON(), codeMaps, inSourceMap) || null : null;
382
+ const newMap = map ? mapLinesColumns(map.toJSON(), codeMaps, _options.inSourceMap) || null : null;
392
383
  return {
393
384
  ast,
394
385
  code,
@@ -428,16 +419,10 @@ function _generate$2(generator, node, options = {}) {
428
419
  }
429
420
  const componentNamespace = "_Component";
430
421
  const variableDeclarations = [];
431
- estreeWalker.walk(node, {
432
- /**
433
- * NOTE:
434
- * force cast to Node of `estree-walker@3.x`,
435
- * because `estree-walker@3.x` is not dual packages,
436
- * so it's support only esm only ...
437
- */
422
+ oxcWalker.walk(node, {
438
423
  // @ts-ignore
439
- enter(node2, _parent) {
440
- if (_parent?.type != null) this.skip();
424
+ enter(node2, parent) {
425
+ if (parent?.type != null) this.skip();
441
426
  switch (node2.type) {
442
427
  case "ExportDefaultDeclaration":
443
428
  this.skip();
@@ -462,7 +447,7 @@ function _generate$2(generator, node, options = {}) {
462
447
  Variable declarations are not optimized - found ${variableDeclarations.join(", ")}`
463
448
  );
464
449
  }
465
- estreeWalker.walk(node, {
450
+ oxcWalker.walk(node, {
466
451
  /**
467
452
  * NOTE:
468
453
  * force cast to Node of `estree-walker@3.x`,
@@ -581,12 +566,6 @@ Variable declarations are not optimized - found ${variableDeclarations.join(", "
581
566
  break;
582
567
  }
583
568
  },
584
- /**
585
- * NOTE:
586
- * force cast to Node of `estree-walker@3.x`,
587
- * because `estree-walker@3.x` is not dual packages,
588
- * so it's support only esm only ...
589
- */
590
569
  // @ts-ignore
591
570
  leave(node2, parent) {
592
571
  switch (node2.type) {
@@ -823,48 +802,15 @@ function _generate$1(generator, node, options = {}) {
823
802
  return codeMaps;
824
803
  }
825
804
 
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
- }) {
805
+ function generate$1(targetSource, options) {
842
806
  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
- }
807
+ const _options = Object.assign({}, DEFAULT_OPTIONS, options, { source: value });
808
+ const transformed = oxcTransform.transform(_options.filename ?? "", value, { lang: "ts" });
809
+ if (transformed && transformed.code) {
810
+ value = transformed.code;
811
+ _options.source = transformed.code;
866
812
  }
867
- return generate$3(value, options);
813
+ return generate$3(value, _options);
868
814
  }
869
815
 
870
816
  function generate(targetSource, {
package/lib/index.d.cts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { RawSourceMap } from 'source-map-js';
2
2
  import { CompileError } from '@intlify/message-compiler';
3
- import { Node } from 'estree';
3
+ import { Node } from 'oxc-parser';
4
4
  import { JSONProgram } from 'jsonc-eslint-parser/lib/parser/ast';
5
5
  import { YAMLProgram } from 'yaml-eslint-parser/lib/ast';
6
6
 
@@ -61,7 +61,7 @@ declare class DynamicResourceError extends Error {
61
61
  /**
62
62
  * @internal
63
63
  */
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>;
64
+ declare function generate$3(targetSource: string | Buffer, options: CodeGenOptions): CodeGenResult<Node>;
65
65
 
66
66
  /**
67
67
  * Code / AST generator for i18n json/json5 resource
@@ -72,13 +72,13 @@ declare function generate$2(targetSource: string | Buffer, { type, onlyLocales,
72
72
  /**
73
73
  * Code generator for i18n ts resource
74
74
  *
75
- * An async wrapper for the js generator which transforms ts to js before generating
75
+ * A wrapper for the js generator which transforms ts to js before generating
76
76
  */
77
77
 
78
78
  /**
79
79
  * @internal
80
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>>;
81
+ declare function generate$1(targetSource: string | Buffer, options: CodeGenOptions): CodeGenResult<Node>;
82
82
 
83
83
  /**
84
84
  * Code generator for i18n yaml resource
@@ -89,4 +89,5 @@ declare function generate$1(targetSource: string | Buffer, { type, filename, inS
89
89
  */
90
90
  declare function generate(targetSource: string | Buffer, { type, onlyLocales, filename, inSourceMap, locale, isGlobal, sourceMap, env, forceStringify, onError, strictMessage, escapeHtml, jit }: CodeGenOptions): CodeGenResult<YAMLProgram>;
91
91
 
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 };
92
+ export { DynamicResourceError, checkInstallPackage, generate$2 as generateJSON, generate$3 as generateJavaScript, generate$1 as generateTypescript, generate as generateYAML, getVueI18nVersion };
93
+ export type { CodeGenOptions, CodeGenResult, DevEnv, InstalledPackage };
package/lib/index.d.mts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { RawSourceMap } from 'source-map-js';
2
2
  import { CompileError } from '@intlify/message-compiler';
3
- import { Node } from 'estree';
3
+ import { Node } from 'oxc-parser';
4
4
  import { JSONProgram } from 'jsonc-eslint-parser/lib/parser/ast';
5
5
  import { YAMLProgram } from 'yaml-eslint-parser/lib/ast';
6
6
 
@@ -61,7 +61,7 @@ declare class DynamicResourceError extends Error {
61
61
  /**
62
62
  * @internal
63
63
  */
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>;
64
+ declare function generate$3(targetSource: string | Buffer, options: CodeGenOptions): CodeGenResult<Node>;
65
65
 
66
66
  /**
67
67
  * Code / AST generator for i18n json/json5 resource
@@ -72,13 +72,13 @@ declare function generate$2(targetSource: string | Buffer, { type, onlyLocales,
72
72
  /**
73
73
  * Code generator for i18n ts resource
74
74
  *
75
- * An async wrapper for the js generator which transforms ts to js before generating
75
+ * A wrapper for the js generator which transforms ts to js before generating
76
76
  */
77
77
 
78
78
  /**
79
79
  * @internal
80
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>>;
81
+ declare function generate$1(targetSource: string | Buffer, options: CodeGenOptions): CodeGenResult<Node>;
82
82
 
83
83
  /**
84
84
  * Code generator for i18n yaml resource
@@ -89,4 +89,5 @@ declare function generate$1(targetSource: string | Buffer, { type, filename, inS
89
89
  */
90
90
  declare function generate(targetSource: string | Buffer, { type, onlyLocales, filename, inSourceMap, locale, isGlobal, sourceMap, env, forceStringify, onError, strictMessage, escapeHtml, jit }: CodeGenOptions): CodeGenResult<YAMLProgram>;
91
91
 
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 };
92
+ export { DynamicResourceError, checkInstallPackage, generate$2 as generateJSON, generate$3 as generateJavaScript, generate$1 as generateTypescript, generate as generateYAML, getVueI18nVersion };
93
+ export type { CodeGenOptions, CodeGenResult, DevEnv, InstalledPackage };
package/lib/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { RawSourceMap } from 'source-map-js';
2
2
  import { CompileError } from '@intlify/message-compiler';
3
- import { Node } from 'estree';
3
+ import { Node } from 'oxc-parser';
4
4
  import { JSONProgram } from 'jsonc-eslint-parser/lib/parser/ast';
5
5
  import { YAMLProgram } from 'yaml-eslint-parser/lib/ast';
6
6
 
@@ -61,7 +61,7 @@ declare class DynamicResourceError extends Error {
61
61
  /**
62
62
  * @internal
63
63
  */
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>;
64
+ declare function generate$3(targetSource: string | Buffer, options: CodeGenOptions): CodeGenResult<Node>;
65
65
 
66
66
  /**
67
67
  * Code / AST generator for i18n json/json5 resource
@@ -72,13 +72,13 @@ declare function generate$2(targetSource: string | Buffer, { type, onlyLocales,
72
72
  /**
73
73
  * Code generator for i18n ts resource
74
74
  *
75
- * An async wrapper for the js generator which transforms ts to js before generating
75
+ * A wrapper for the js generator which transforms ts to js before generating
76
76
  */
77
77
 
78
78
  /**
79
79
  * @internal
80
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>>;
81
+ declare function generate$1(targetSource: string | Buffer, options: CodeGenOptions): CodeGenResult<Node>;
82
82
 
83
83
  /**
84
84
  * Code generator for i18n yaml resource
@@ -89,4 +89,5 @@ declare function generate$1(targetSource: string | Buffer, { type, filename, inS
89
89
  */
90
90
  declare function generate(targetSource: string | Buffer, { type, onlyLocales, filename, inSourceMap, locale, isGlobal, sourceMap, env, forceStringify, onError, strictMessage, escapeHtml, jit }: CodeGenOptions): CodeGenResult<YAMLProgram>;
91
91
 
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 };
92
+ export { DynamicResourceError, checkInstallPackage, generate$2 as generateJSON, generate$3 as generateJavaScript, generate$1 as generateTypescript, generate as generateYAML, getVueI18nVersion };
93
+ export type { CodeGenOptions, CodeGenResult, DevEnv, InstalledPackage };
package/lib/index.mjs CHANGED
@@ -1,15 +1,15 @@
1
- import module from 'node:module';
1
+ import module$1 from 'node:module';
2
2
  import { isBoolean, format, escapeHtml, friendlyJSONstringify, isString, isNumber } from '@intlify/shared';
3
- import { parse } from 'acorn';
4
3
  import { generate as generate$4 } from 'escodegen';
5
- import { walk } from 'estree-walker';
4
+ import { parseSync } from 'oxc-parser';
5
+ import { walk } from 'oxc-walker';
6
6
  import { LOCATION_STUB, detectHtmlTag, baseCompile } from '@intlify/message-compiler';
7
7
  import { SourceMapGenerator, SourceMapConsumer } from 'source-map-js';
8
8
  import { parseJSON, getStaticJSONValue, traverseNodes } from 'jsonc-eslint-parser';
9
- import { transform } from 'esbuild';
9
+ import { transform } from 'oxc-transform';
10
10
  import { parseYAML, getStaticYAMLValue, traverseNodes as traverseNodes$1 } from 'yaml-eslint-parser';
11
11
 
12
- const _require = module.createRequire(import.meta.url);
12
+ const _require = module$1.createRequire(import.meta.url);
13
13
  function checkInstallPackage(pkg, debug) {
14
14
  let installedVueI18n = false;
15
15
  try {
@@ -203,39 +203,46 @@ function mapLinesColumns(resMap, codeMaps, inSourceMap) {
203
203
  if (inMapFirstItem) {
204
204
  return;
205
205
  }
206
+ if (m.originalLine == null || m.originalColumn == null) {
207
+ return;
208
+ }
206
209
  inMapFirstItem = m;
207
210
  });
208
211
  }
209
212
  resMapConsumer.eachMapping((res) => {
210
- if (res.originalLine == null) {
213
+ const resOriginalLine = res.originalLine;
214
+ const resOriginalColumn = res.originalColumn;
215
+ const resName = res.name;
216
+ if (resOriginalLine == null || resOriginalColumn == null || resName == null) {
211
217
  return;
212
218
  }
213
- const map = codeMaps.get(res.name);
219
+ const map = codeMaps.get(resName);
214
220
  if (!map) {
215
221
  return;
216
222
  }
217
223
  let inMapOrigin = null;
218
224
  if (inMapConsumer) {
219
225
  inMapOrigin = inMapConsumer.originalPositionFor({
220
- line: res.originalLine,
221
- column: res.originalColumn - 1
226
+ line: resOriginalLine,
227
+ column: resOriginalColumn - 1
222
228
  });
223
229
  if (inMapOrigin.source == null) {
224
230
  inMapOrigin = null;
225
231
  return;
226
232
  }
227
233
  }
234
+ const inMapFirst = inMapFirstItem;
228
235
  const mapConsumer = new SourceMapConsumer(map);
229
236
  mapConsumer.eachMapping((m) => {
230
237
  mergedMapGenerator.addMapping({
231
238
  original: {
232
- line: inMapFirstItem ? inMapFirstItem.originalLine + res.originalLine - 2 : res.originalLine,
233
- column: inMapFirstItem ? inMapFirstItem.originalColumn + res.originalColumn : res.originalColumn
239
+ line: inMapFirst ? inMapFirst.originalLine + resOriginalLine - 2 : resOriginalLine,
240
+ column: inMapFirst ? inMapFirst.originalColumn + resOriginalColumn : resOriginalColumn
234
241
  },
235
242
  generated: {
236
- line: inMapFirstItem ? inMapFirstItem.generatedLine + res.originalLine - 2 : res.originalLine,
243
+ line: inMapFirst ? inMapFirst.generatedLine + resOriginalLine - 2 : resOriginalLine,
237
244
  // map column with message format compilation code map
238
- column: inMapFirstItem ? inMapFirstItem.generatedColumn + res.originalColumn + m.generatedColumn : res.originalColumn + m.generatedColumn
245
+ column: inMapFirst ? inMapFirst.generatedColumn + resOriginalColumn + m.generatedColumn : resOriginalColumn + m.generatedColumn
239
246
  },
240
247
  source: inMapOrigin ? inMapOrigin.source : res.source,
241
248
  name: m.name
@@ -317,48 +324,32 @@ function excludeLocales({
317
324
 
318
325
  class DynamicResourceError extends Error {
319
326
  }
320
- function generate$3(targetSource, {
321
- type = "plain",
322
- filename = "vue-i18n-loader.js",
323
- inSourceMap = void 0,
324
- locale = "",
325
- isGlobal = false,
326
- sourceMap = false,
327
- env = "development",
328
- forceStringify = false,
329
- onError = void 0,
330
- onWarn = void 0,
331
- strictMessage = true,
332
- escapeHtml = false,
333
- allowDynamic = false,
334
- jit = false
335
- }) {
327
+ const DEFAULT_OPTIONS = {
328
+ type: "plain",
329
+ filename: "vue-i18n-loader.js",
330
+ inSourceMap: void 0,
331
+ locale: "",
332
+ isGlobal: false,
333
+ sourceMap: false,
334
+ env: "development",
335
+ forceStringify: false,
336
+ onError: void 0,
337
+ onWarn: void 0,
338
+ strictMessage: true,
339
+ escapeHtml: false,
340
+ allowDynamic: false,
341
+ jit: false
342
+ };
343
+ function generate$3(targetSource, options) {
336
344
  const value = Buffer.isBuffer(targetSource) ? targetSource.toString() : targetSource;
337
- const options = {
338
- type,
339
- source: value,
340
- sourceMap,
341
- locale,
342
- isGlobal,
343
- inSourceMap,
344
- env,
345
- filename,
346
- forceStringify,
347
- onError,
348
- onWarn,
349
- strictMessage,
350
- escapeHtml,
351
- jit
352
- };
353
- const generator = createCodeGenerator(options);
354
- const ast = parse(value, {
355
- ecmaVersion: "latest",
345
+ const _options = Object.assign({}, DEFAULT_OPTIONS, options, { source: value });
346
+ const generator = createCodeGenerator(_options);
347
+ const { program: ast } = parseSync(_options.filename ?? "", value, {
356
348
  sourceType: "module",
357
- sourceFile: filename,
358
- allowImportExportEverywhere: true
349
+ lang: "js"
359
350
  });
360
351
  const exportResult = scanAst(ast);
361
- if (!allowDynamic) {
352
+ if (!_options.allowDynamic) {
362
353
  if (!exportResult) {
363
354
  throw new Error(`You need to define an object as the locale message with 'export default'.`);
364
355
  }
@@ -375,13 +366,13 @@ function generate$3(targetSource, {
375
366
  return {
376
367
  ast,
377
368
  code: value,
378
- map: inSourceMap
369
+ map: _options.inSourceMap
379
370
  };
380
371
  }
381
372
  }
382
- const codeMaps = _generate$2(generator, ast, options);
373
+ const codeMaps = _generate$2(generator, ast, _options);
383
374
  const { code, map } = generator.context();
384
- const newMap = map ? mapLinesColumns(map.toJSON(), codeMaps, inSourceMap) || null : null;
375
+ const newMap = map ? mapLinesColumns(map.toJSON(), codeMaps, _options.inSourceMap) || null : null;
385
376
  return {
386
377
  ast,
387
378
  code,
@@ -422,15 +413,9 @@ function _generate$2(generator, node, options = {}) {
422
413
  const componentNamespace = "_Component";
423
414
  const variableDeclarations = [];
424
415
  walk(node, {
425
- /**
426
- * NOTE:
427
- * force cast to Node of `estree-walker@3.x`,
428
- * because `estree-walker@3.x` is not dual packages,
429
- * so it's support only esm only ...
430
- */
431
416
  // @ts-ignore
432
- enter(node2, _parent) {
433
- if (_parent?.type != null) this.skip();
417
+ enter(node2, parent) {
418
+ if (parent?.type != null) this.skip();
434
419
  switch (node2.type) {
435
420
  case "ExportDefaultDeclaration":
436
421
  this.skip();
@@ -574,12 +559,6 @@ Variable declarations are not optimized - found ${variableDeclarations.join(", "
574
559
  break;
575
560
  }
576
561
  },
577
- /**
578
- * NOTE:
579
- * force cast to Node of `estree-walker@3.x`,
580
- * because `estree-walker@3.x` is not dual packages,
581
- * so it's support only esm only ...
582
- */
583
562
  // @ts-ignore
584
563
  leave(node2, parent) {
585
564
  switch (node2.type) {
@@ -816,48 +795,15 @@ function _generate$1(generator, node, options = {}) {
816
795
  return codeMaps;
817
796
  }
818
797
 
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
- }) {
798
+ function generate$1(targetSource, options) {
835
799
  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
- }
800
+ const _options = Object.assign({}, DEFAULT_OPTIONS, options, { source: value });
801
+ const transformed = transform(_options.filename ?? "", value, { lang: "ts" });
802
+ if (transformed && transformed.code) {
803
+ value = transformed.code;
804
+ _options.source = transformed.code;
859
805
  }
860
- return generate$3(value, options);
806
+ return generate$3(value, _options);
861
807
  }
862
808
 
863
809
  function generate(targetSource, {
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.2",
4
+ "version": "12.0.0-alpha.3",
5
5
  "author": {
6
6
  "name": "kazuya kawaguchi",
7
7
  "email": "kawakazu80@gmail.com"
@@ -20,21 +20,20 @@
20
20
  "dependencies": {
21
21
  "@intlify/message-compiler": "next",
22
22
  "@intlify/shared": "next",
23
- "acorn": "^8.8.2",
24
- "esbuild": "^0.25.1",
25
23
  "escodegen": "^2.1.0",
26
- "estree-walker": "^2.0.2",
27
24
  "jsonc-eslint-parser": "^2.3.0",
25
+ "oxc-parser": "^0.130.0",
26
+ "oxc-transform": "^0.96.0",
27
+ "oxc-walker": "^0.7.0",
28
28
  "source-map-js": "^1.0.1",
29
29
  "yaml-eslint-parser": "^1.2.2"
30
30
  },
31
31
  "devDependencies": {
32
32
  "@types/escodegen": "^0.0.10",
33
- "@types/estree": "^1.0.0",
34
- "unbuild": "^3.5.0"
33
+ "unbuild": "^3.6.1"
35
34
  },
36
35
  "engines": {
37
- "node": ">= 20"
36
+ "node": ">= 22.13"
38
37
  },
39
38
  "files": [
40
39
  "lib"