@x18n/builtins 0.0.7 → 0.0.8

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.
@@ -1,4 +1,4 @@
1
- import { X18nError, createLineIndex, pathMatcher } from "@x18n/core";
1
+ import { createLineIndex, errors, pathMatcher } from "@x18n/core";
2
2
  //#region src/extractors/index.ts
3
3
  const textKinds = /* @__PURE__ */ new Set([
4
4
  "jsx-text",
@@ -301,7 +301,7 @@ function toPlanFile(project, candidates) {
301
301
  function extractItems(project, items) {
302
302
  return items.map((item) => {
303
303
  const text = project.text(item.path);
304
- if (text === void 0 || text.slice(item.range.start, item.range.end) !== item.original) throw new X18nError("X18N4004", `${item.path} changed since the plan was made`);
304
+ if (text === void 0 || text.slice(item.range.start, item.range.end) !== item.original) throw errors.X18N4004({ path: item.path });
305
305
  return {
306
306
  path: item.path,
307
307
  range: item.range,
package/dist/finders.mjs CHANGED
@@ -1,3 +1,3 @@
1
1
  import { a as patternFinder, i as pattern, n as guessResources, r as namespaceFromPath, t as compilePattern } from "./finders-CqTGh4OJ.mjs";
2
- import { n as sfcFluentBlocks, t as sfcBlocks } from "./sfc-blocks-BwJwCUka.mjs";
2
+ import { n as sfcFluentBlocks, t as sfcBlocks } from "./sfc-blocks-BIPqKcvd.mjs";
3
3
  export { compilePattern, guessResources, namespaceFromPath, pattern, patternFinder, sfcBlocks, sfcFluentBlocks };
@@ -1,4 +1,4 @@
1
- import { X18nError, applyMessageOps, applyTextEdits, buildTree, diffText, isMessageLeaf, isMessageTree, pathId, walkLeaves } from "@x18n/core";
1
+ import { applyMessageOps, applyTextEdits, buildTree, diffText, errors, isMessageLeaf, isMessageTree, pathId, walkLeaves } from "@x18n/core";
2
2
  import { parseSync } from "oxc-parser";
3
3
  import { applyEdits, modify, parseTree, printParseErrorCode } from "jsonc-parser";
4
4
  import JSON5 from "json5";
@@ -179,14 +179,21 @@ function readObject(node, path, module, text, fail) {
179
179
  return out;
180
180
  }
181
181
  function readModule(text, path) {
182
- const fail = (code, node, message) => {
183
- throw new X18nError(code, `${path}:${text.slice(0, node.start).split("\n").length}: ${message}`);
182
+ const fail = (code, node, reason) => {
183
+ throw errors[code]({
184
+ path,
185
+ line: text.slice(0, node.start).split("\n").length,
186
+ reason
187
+ });
184
188
  };
185
189
  const result = parseSync(path, text, {
186
190
  lang: /\.[mc]?ts$/.test(path) ? "ts" : "js",
187
191
  sourceType: "module"
188
192
  });
189
- if (result.errors.length > 0) throw new X18nError("X18N2002", `${path}: ${result.errors[0].message}`);
193
+ if (result.errors.length > 0) throw errors.X18N2002({
194
+ path,
195
+ reason: result.errors[0].message
196
+ });
190
197
  const root = findRoot(result.program, fail);
191
198
  const found = {
192
199
  ranges: /* @__PURE__ */ new Map(),
@@ -317,7 +324,11 @@ function read$3(text, path) {
317
324
  continue;
318
325
  }
319
326
  if (/^[ \t]/.test(content)) {
320
- if (!current) throw new X18nError("X18N2002", `${path}:${lineNumber}: indented line outside a message`);
327
+ if (!current) throw errors.X18N2002({
328
+ path,
329
+ line: lineNumber,
330
+ reason: "indented line outside a message"
331
+ });
321
332
  const attribute = /^[ \t]+\.([a-z][\w-]*)[ \t]*=[ \t]*/i.exec(content);
322
333
  if (attribute) {
323
334
  const nameStart = line.start + attribute[0].indexOf(".") + 1;
@@ -357,7 +368,11 @@ function read$3(text, path) {
357
368
  continue;
358
369
  }
359
370
  const message = /^(-?[a-z][\w-]*)[ \t]*=[ \t]*/i.exec(content);
360
- if (!message) throw new X18nError("X18N2002", `${path}:${lineNumber}: expected a message, a term or a comment`);
371
+ if (!message) throw errors.X18N2002({
372
+ path,
373
+ line: lineNumber,
374
+ reason: "expected a message, a term or a comment"
375
+ });
361
376
  current = {
362
377
  id: message[1],
363
378
  idRange: {
@@ -534,7 +549,11 @@ function read$2(text, path) {
534
549
  let section = "";
535
550
  let lineNumber = 0;
536
551
  const fail = (message) => {
537
- throw new X18nError("X18N2002", `${path}:${lineNumber}: ${message}`);
552
+ throw errors.X18N2002({
553
+ path,
554
+ line: lineNumber,
555
+ reason: message
556
+ });
538
557
  };
539
558
  for (const line of splitLines(text)) {
540
559
  lineNumber++;
@@ -669,21 +688,24 @@ function createJsonFormat(id, extensions, allowComments, defaultIndent) {
669
688
  id,
670
689
  extensions,
671
690
  parse(text, ctx) {
672
- const errors = [];
673
- const root = parseTree(text, errors, {
691
+ const problems = [];
692
+ const root = parseTree(text, problems, {
674
693
  allowTrailingComma: true,
675
694
  disallowComments: !allowComments
676
695
  });
677
- if (errors.length > 0) {
678
- const first = errors[0];
679
- throw new X18nError("X18N2002", `${ctx.path}: ${printParseErrorCode(first.error)} at offset ${first.offset}`);
696
+ if (problems.length > 0) {
697
+ const first = problems[0];
698
+ throw errors.X18N2002({
699
+ path: ctx.path,
700
+ reason: `${printParseErrorCode(first.error)} at offset ${first.offset}`
701
+ });
680
702
  }
681
703
  if (!root || root.type !== "object") {
682
704
  if (text.trim() === "") return {
683
705
  tree: {},
684
706
  ranges: /* @__PURE__ */ new Map()
685
707
  };
686
- throw new X18nError("X18N2003", ctx.path);
708
+ throw errors.X18N2003({ path: ctx.path });
687
709
  }
688
710
  const ranges = /* @__PURE__ */ new Map();
689
711
  return {
@@ -732,9 +754,13 @@ function json5() {
732
754
  try {
733
755
  data = JSON5.parse(text);
734
756
  } catch (error) {
735
- throw new X18nError("X18N2002", `${ctx.path}: ${error instanceof Error ? error.message : String(error)}`);
757
+ throw errors.X18N2002({
758
+ path: ctx.path,
759
+ reason: error instanceof Error ? error.message : String(error),
760
+ cause: error
761
+ });
736
762
  }
737
- if (!isMessageTree(data)) throw new X18nError("X18N2003", ctx.path);
763
+ if (!isMessageTree(data)) throw errors.X18N2003({ path: ctx.path });
738
764
  return { tree: data };
739
765
  },
740
766
  serialize: (tree, ctx) => `${JSON5.stringify(tree, null, ctx.indent === "tab" ? " " : ctx.indent ?? 2)}\n`
@@ -765,9 +791,12 @@ function decodeDouble(raw, fail) {
765
791
  }
766
792
  function parseFile(text, path) {
767
793
  let pos = 0;
768
- const fail = (code, message) => {
769
- const line = text.slice(0, pos).split("\n").length;
770
- throw new X18nError(code, `${path}:${line}: ${message}`);
794
+ const fail = (code, reason) => {
795
+ throw errors[code]({
796
+ path,
797
+ line: text.slice(0, pos).split("\n").length,
798
+ reason
799
+ });
771
800
  };
772
801
  const skip = () => {
773
802
  for (;;) {
@@ -1008,7 +1037,11 @@ function read$1(text, path) {
1008
1037
  const entries = [];
1009
1038
  let lineNumber = 0;
1010
1039
  const fail = (message) => {
1011
- throw new X18nError("X18N2002", `${path}:${lineNumber}: ${message}`);
1040
+ throw errors.X18N2002({
1041
+ path,
1042
+ line: lineNumber,
1043
+ reason: message
1044
+ });
1012
1045
  };
1013
1046
  let draft;
1014
1047
  let field;
@@ -1128,7 +1161,10 @@ function unescape(raw, path) {
1128
1161
  while (isSpace(raw[i + 1])) i++;
1129
1162
  } else if (next === "u") {
1130
1163
  const hex = raw.slice(i + 1, i + 5);
1131
- if (!/^[0-9a-f]{4}$/i.test(hex)) throw new X18nError("X18N2002", `${path}: malformed \\u escape "\\u${hex}"`);
1164
+ if (!/^[0-9a-f]{4}$/i.test(hex)) throw errors.X18N2002({
1165
+ path,
1166
+ reason: `malformed \\u escape "\\u${hex}"`
1167
+ });
1132
1168
  out += String.fromCharCode(Number.parseInt(hex, 16));
1133
1169
  i += 4;
1134
1170
  } else out += escapes[next] ?? next;
@@ -1267,7 +1303,10 @@ function parse$1(text, path) {
1267
1303
  keepSourceTokens: true,
1268
1304
  uniqueKeys: false
1269
1305
  });
1270
- if (doc.errors.length > 0) throw new X18nError("X18N2002", `${path}: ${doc.errors[0].message}`);
1306
+ if (doc.errors.length > 0) throw errors.X18N2002({
1307
+ path,
1308
+ reason: doc.errors[0].message
1309
+ });
1271
1310
  return doc;
1272
1311
  }
1273
1312
  function scalarText(value, type) {
@@ -1292,7 +1331,7 @@ function yaml() {
1292
1331
  tree: {},
1293
1332
  ranges
1294
1333
  };
1295
- if (!isMap(doc.contents)) throw new X18nError("X18N2003", ctx.path);
1334
+ if (!isMap(doc.contents)) throw errors.X18N2003({ path: ctx.path });
1296
1335
  return {
1297
1336
  tree: readMap(doc.contents, [], ranges),
1298
1337
  ranges
package/dist/formats.mjs CHANGED
@@ -1 +1 @@
1
- export { u as ecmascript, l as ftl, c as ini, o as json, a as json5, s as jsonc, i as php, r as po, n as properties, t as yaml } from "./formats-BAogSrvw.mjs";
1
+ export { u as ecmascript, l as ftl, c as ini, o as json, a as json5, s as jsonc, i as php, r as po, n as properties, t as yaml } from "./formats-CFkM5co0.mjs";
package/dist/index.mjs CHANGED
@@ -1,10 +1,10 @@
1
1
  import { recommended } from "./checks.mjs";
2
2
  import { i as pattern } from "./finders-CqTGh4OJ.mjs";
3
- import { a as json5, c as ini, i as php, l as ftl, n as properties, o as json, r as po, s as jsonc, t as yaml, u as ecmascript } from "./formats-BAogSrvw.mjs";
3
+ import { a as json5, c as ini, i as php, l as ftl, n as properties, o as json, r as po, s as jsonc, t as yaml, u as ecmascript } from "./formats-CFkM5co0.mjs";
4
4
  import { i as js, n as vue } from "./vue-5GFR5hft.mjs";
5
5
  import { manifests } from "./manifests.mjs";
6
6
  import { n as regex } from "./regex-B9TBGgXC.mjs";
7
- import { t as presets } from "./presets-DNnE_2MQ.mjs";
7
+ import { t as presets } from "./presets-C-DdV8pj.mjs";
8
8
  import { reporters } from "./reporters.mjs";
9
9
  import { t as svelte } from "./scanners-B27IEH4_.mjs";
10
10
  //#region src/index.ts
@@ -1,5 +1,5 @@
1
1
  import { defaultTemplates } from "./extractors.mjs";
2
- import { n as sfcFluentBlocks, t as sfcBlocks } from "./sfc-blocks-BwJwCUka.mjs";
2
+ import { n as sfcFluentBlocks, t as sfcBlocks } from "./sfc-blocks-BIPqKcvd.mjs";
3
3
  import { braces, colon, dollars, doubleBraces, fluent, icu, linked, nesting, percentBraces, placeholders, printf } from "./placeholders.mjs";
4
4
  import { r as regexScopes } from "./regex-B9TBGgXC.mjs";
5
5
  import { isMessageLeaf } from "@x18n/core";
package/dist/presets.mjs CHANGED
@@ -1 +1 @@
1
- export { n as chromeExtension, r as emberIntl, i as fluentVue, b as flutter, x as general, a as globalize, o as i18nJs, s as i18nTag, S as i18next, c as i18nextShopify, m as jekyll, h as laravel, l as lingui, u as nextInternational, C as nextIntl, d as nextTranslate, A as ngxTranslate, w as nuxtI18n, g as phpGettext, _ as phpJoomla, f as polyglot, t as presets, v as railsLazyKey, T as reactI18next, E as reactIntl, y as rubyRails, D as svelteI18n, j as transloco, p as ui5, O as vscodeExtension, k as vueI18n } from "./presets-DNnE_2MQ.mjs";
1
+ export { n as chromeExtension, r as emberIntl, i as fluentVue, b as flutter, x as general, a as globalize, o as i18nJs, s as i18nTag, S as i18next, c as i18nextShopify, m as jekyll, h as laravel, l as lingui, u as nextInternational, C as nextIntl, d as nextTranslate, A as ngxTranslate, w as nuxtI18n, g as phpGettext, _ as phpJoomla, f as polyglot, t as presets, v as railsLazyKey, T as reactI18next, E as reactIntl, y as rubyRails, D as svelteI18n, j as transloco, p as ui5, O as vscodeExtension, k as vueI18n } from "./presets-C-DdV8pj.mjs";
@@ -1,4 +1,4 @@
1
- import { a as json5, o as json, t as yaml } from "./formats-BAogSrvw.mjs";
1
+ import { a as json5, o as json, t as yaml } from "./formats-CFkM5co0.mjs";
2
2
  import { t as loadVueCompiler } from "./vue-5GFR5hft.mjs";
3
3
  import { isMessageLeaf, pathId } from "@x18n/core";
4
4
  //#region src/finders/sfc-blocks.ts
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@x18n/builtins",
3
3
  "type": "module",
4
- "version": "0.0.7",
4
+ "version": "0.0.8",
5
5
  "description": "Built-in x18n plugins and presets: formats, locale finders, scanners, checks and reporters",
6
6
  "author": "Anthony Fu <anthonyfu117@hotmail.com>",
7
7
  "license": "MIT",
@@ -33,7 +33,7 @@
33
33
  ],
34
34
  "dependencies": {
35
35
  "@vue/compiler-sfc": "^3.5.44",
36
- "@x18n/core": "0.0.7",
36
+ "@x18n/core": "0.0.8",
37
37
  "json5": "^2.2.3",
38
38
  "jsonc-parser": "^3.3.1",
39
39
  "oxc-parser": "^0.155.0",