@wuchale/jsx 0.7.4 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,15 +1,15 @@
1
1
  import { defaultGenerateLoadID, defaultHeuristic, deepMergeObjects } from 'wuchale';
2
- import { adapter as vanillaAdapter } from 'wuchale/adapter-vanilla';
2
+ import { pluralPattern, adapter as vanillaAdapter } from 'wuchale/adapter-vanilla';
3
3
  import { JSXTransformer } from "./transformer.js";
4
4
  import { getDependencies, loaderPathResolver } from 'wuchale/adapter-utils';
5
- const jsxHeuristic = (msgStr, details) => {
6
- if (!defaultHeuristic(msgStr, details)) {
5
+ const jsxHeuristic = msg => {
6
+ if (!defaultHeuristic(msg)) {
7
7
  return false;
8
8
  }
9
- if (details.scope !== 'script') {
9
+ if (msg.details.scope !== 'script') {
10
10
  return true;
11
11
  }
12
- if (details.declaring === 'variable') {
12
+ if (msg.details.declaring === 'variable') {
13
13
  return false;
14
14
  }
15
15
  return true;
@@ -52,7 +52,7 @@ const defaultRuntimeSolid = {
52
52
  const defaultArgs = {
53
53
  files: { include: 'src/**/*.{js,ts,jsx,tsx}', ignore: '**/*.d.ts' },
54
54
  catalog: './src/locales/{locale}',
55
- pluralsFunc: 'plural',
55
+ patterns: [pluralPattern],
56
56
  heuristic: jsxHeuristic,
57
57
  granularLoad: false,
58
58
  bundleLoad: false,
@@ -63,13 +63,13 @@ const defaultArgs = {
63
63
  };
64
64
  const resolveLoaderPath = loaderPathResolver(import.meta.url, '../src/loaders', 'js');
65
65
  export const adapter = (args = defaultArgs) => {
66
- let { heuristic, pluralsFunc, variant, runtime, ...rest } = deepMergeObjects(args, defaultArgs);
66
+ let { heuristic, patterns, variant, runtime, ...rest } = deepMergeObjects(args, defaultArgs);
67
67
  if (variant === 'solidjs' && args.runtime == null) {
68
68
  runtime = defaultRuntimeSolid;
69
69
  }
70
70
  return {
71
71
  transform: ({ content, filename, index, expr }) => {
72
- return new JSXTransformer(content, filename, index, heuristic, pluralsFunc, expr, runtime).transformJx(variant);
72
+ return new JSXTransformer(content, filename, index, heuristic, patterns, expr, runtime).transformJx(variant);
73
73
  },
74
74
  loaderExts: ['.js', '.ts'],
75
75
  defaultLoaders: async () => {
@@ -2,7 +2,7 @@ import { Message } from 'wuchale';
2
2
  import type * as JX from 'estree-jsx';
3
3
  import type * as Estree from 'acorn';
4
4
  import { Transformer } from 'wuchale/adapter-vanilla';
5
- import type { IndexTracker, HeuristicFunc, TransformOutput, RuntimeConf, CatalogExpr } from 'wuchale';
5
+ import type { IndexTracker, HeuristicFunc, TransformOutput, RuntimeConf, CatalogExpr, CodePattern } from 'wuchale';
6
6
  import { MixedVisitor, type CommentDirectives } from "wuchale/adapter-utils";
7
7
  export declare function parseScriptJSX(content: string): [Estree.Program, Estree.Comment[][]];
8
8
  type MixedNodesTypes = JX.JSXElement | JX.JSXFragment | JX.JSXText | JX.JSXExpressionContainer | JX.JSXSpreadChild;
@@ -14,7 +14,7 @@ export declare class JSXTransformer extends Transformer {
14
14
  lastVisitIsComment: boolean;
15
15
  currentJsxKey?: number;
16
16
  mixedVisitor: MixedVisitor<MixedNodesTypes>;
17
- constructor(content: string, filename: string, index: IndexTracker, heuristic: HeuristicFunc, pluralsFunc: string, catalogExpr: CatalogExpr, rtConf: RuntimeConf);
17
+ constructor(content: string, filename: string, index: IndexTracker, heuristic: HeuristicFunc, patterns: CodePattern[], catalogExpr: CatalogExpr, rtConf: RuntimeConf);
18
18
  initMixedVisitor: () => MixedVisitor<MixedNodesTypes>;
19
19
  visitChildrenJ: (node: JX.JSXElement | JX.JSXFragment) => Message[];
20
20
  visitNameJSXNamespacedName: (node: JX.JSXNamespacedName) => string;
@@ -19,8 +19,8 @@ export class JSXTransformer extends Transformer {
19
19
  lastVisitIsComment = false;
20
20
  currentJsxKey;
21
21
  mixedVisitor;
22
- constructor(content, filename, index, heuristic, pluralsFunc, catalogExpr, rtConf) {
23
- super(content, filename, index, heuristic, pluralsFunc, catalogExpr, rtConf);
22
+ constructor(content, filename, index, heuristic, patterns, catalogExpr, rtConf) {
23
+ super(content, filename, index, heuristic, patterns, catalogExpr, rtConf);
24
24
  }
25
25
  initMixedVisitor = () => new MixedVisitor({
26
26
  mstr: this.mstr,
@@ -48,6 +48,7 @@ export class JSXTransformer extends Transformer {
48
48
  return childTxts;
49
49
  },
50
50
  visitExpressionTag: this.visitJSXExpressionContainer,
51
+ fullHeuristicDetails: this.fullHeuristicDetails,
51
52
  checkHeuristic: this.checkHeuristicBool,
52
53
  index: this.index,
53
54
  wrapNested: (msgInfo, hasExprs, nestedRanges, lastChildEnd) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wuchale/jsx",
3
- "version": "0.7.4",
3
+ "version": "0.8.0",
4
4
  "description": "Protobuf-like i18n from plain code: JSX adapter",
5
5
  "scripts": {
6
6
  "dev": "tsc --watch",
@@ -69,9 +69,9 @@
69
69
  }
70
70
  },
71
71
  "dependencies": {
72
- "@sveltejs/acorn-typescript": "^1.0.5",
72
+ "@sveltejs/acorn-typescript": "^1.0.6",
73
73
  "acorn": "^8.15.0",
74
- "wuchale": "^0.16.5"
74
+ "wuchale": "^0.17.0"
75
75
  },
76
76
  "devDependencies": {
77
77
  "@types/estree-jsx": "^1.0.5",