@wuchale/jsx 0.10.2 → 0.11.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,4 +1,4 @@
1
- import { createHeuristic, deepMergeObjects, defaultGenerateLoadID, defaultHeuristicOpts } from 'wuchale';
1
+ import { createHeuristic, deepMergeObjects, defaultGenerateLoadID, defaultHeuristicOpts, pofile } from 'wuchale';
2
2
  import { loaderPathResolver } from 'wuchale/adapter-utils';
3
3
  import { getDefaultLoaderPath as getDefaultLoaderPathVanilla, pluralPattern } from 'wuchale/adapter-vanilla';
4
4
  import { JSXTransformer } from './transformer.js';
@@ -48,7 +48,7 @@ const defaultRuntimeSolid = {
48
48
  };
49
49
  export const defaultArgs = {
50
50
  files: { include: 'src/**/*.{js,ts,jsx,tsx}', ignore: '**/*.d.ts' },
51
- localesDir: './src/locales',
51
+ storage: pofile(),
52
52
  patterns: [pluralPattern],
53
53
  heuristic: jsxDefaultHeuristic,
54
54
  granularLoad: false,
@@ -1,6 +1,7 @@
1
1
  import { tsPlugin } from '@sveltejs/acorn-typescript';
2
2
  import { Parser } from 'acorn';
3
3
  import MagicString from 'magic-string';
4
+ import { getKey } from 'wuchale';
4
5
  import { MixedVisitor, nonWhitespaceText } from 'wuchale/adapter-utils';
5
6
  import { parseScript, scriptParseOptionsWithComments, Transformer } from 'wuchale/adapter-vanilla';
6
7
  const JsxParser = Parser.extend(tsPlugin({ jsx: true }));
@@ -67,7 +68,7 @@ export class JSXTransformer extends Transformer {
67
68
  begin += `{${this.vars().nestCtx}} n`;
68
69
  }
69
70
  else {
70
- const index = this.index.get(msgInfo.toKey());
71
+ const index = this.index.get(getKey(msgInfo.msgStr, msgInfo.context));
71
72
  begin += `{${this.vars().rtCtx}(${index})}`;
72
73
  }
73
74
  let end = ' />';
@@ -128,7 +129,7 @@ export class JSXTransformer extends Transformer {
128
129
  if (!pass) {
129
130
  return [];
130
131
  }
131
- this.mstr.update(node.start + startWh, node.end - endWh, `{${this.vars().rtTrans}(${this.index.get(msgInfo.toKey())})}`);
132
+ this.mstr.update(node.start + startWh, node.end - endWh, `{${this.vars().rtTrans}(${this.index.get(getKey(msgInfo.msgStr, msgInfo.context))})}`);
132
133
  return [msgInfo];
133
134
  };
134
135
  visitJSXFragment = (node) => this.visitChildrenJ(node);
@@ -177,7 +178,7 @@ export class JSXTransformer extends Transformer {
177
178
  if (!pass) {
178
179
  return [];
179
180
  }
180
- this.mstr.update(value.start, value.end, `{${this.vars().rtTrans}(${this.index.get(msgInfo.toKey())})}`);
181
+ this.mstr.update(value.start, value.end, `{${this.literalRepl(msgInfo)}}`);
181
182
  return [msgInfo];
182
183
  };
183
184
  visitJSXSpreadAttribute = (node) => this.visit(node.argument);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wuchale/jsx",
3
- "version": "0.10.2",
3
+ "version": "0.11.0",
4
4
  "description": "Protobuf-like i18n from plain code: JSX adapter",
5
5
  "scripts": {
6
6
  "dev": "tsc --watch",
@@ -59,9 +59,9 @@
59
59
  "license": "MIT",
60
60
  "dependencies": {
61
61
  "@sveltejs/acorn-typescript": "^1.0.9",
62
- "acorn": "^8.15.0",
62
+ "acorn": "^8.16.0",
63
63
  "magic-string": "^0.30.21",
64
- "wuchale": "^0.20.0"
64
+ "wuchale": "^0.21.0"
65
65
  },
66
66
  "devDependencies": {
67
67
  "@types/estree-jsx": "^1.0.5",
@@ -5,13 +5,13 @@ import { locales } from '${DATA}'
5
5
  let locale = locales[0]
6
6
 
7
7
  const callbacks = new Set([
8
- (/** @type {string} */ loc) => {
8
+ (/** @type {import('${DATA}').Locale} */ loc) => {
9
9
  locale = loc
10
10
  },
11
11
  ])
12
12
 
13
13
  /**
14
- * @param {string} locale
14
+ * @param {import('${DATA}').Locale} locale
15
15
  */
16
16
  export function setLocale(locale) {
17
17
  for (const callback of callbacks) {