@wuchale/jsx 0.7.1 → 0.7.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.
@@ -12,7 +12,7 @@ export declare class JSXTransformer extends Transformer {
12
12
  inCompoundText: boolean;
13
13
  commentDirectivesStack: CommentDirectives[];
14
14
  lastVisitIsComment: boolean;
15
- currentJsxKey: number;
15
+ currentJsxKey?: number;
16
16
  mixedVisitor: MixedVisitor<MixedNodesTypes>;
17
17
  constructor(content: string, filename: string, index: IndexTracker, heuristic: HeuristicFunc, pluralsFunc: string, catalogExpr: CatalogExpr, rtConf: RuntimeConf);
18
18
  initMixedVisitor: () => MixedVisitor<MixedNodesTypes>;
@@ -2,10 +2,9 @@ import MagicString from 'magic-string';
2
2
  import { Parser } from 'acorn';
3
3
  import { Message } from 'wuchale';
4
4
  import { tsPlugin } from '@sveltejs/acorn-typescript';
5
- import jsx from 'acorn-jsx';
6
5
  import { Transformer, scriptParseOptionsWithComments } from 'wuchale/adapter-vanilla';
7
6
  import { nonWhitespaceText, MixedVisitor, processCommentDirectives } from "wuchale/adapter-utils";
8
- const JsxParser = Parser.extend(tsPlugin(), jsx());
7
+ const JsxParser = Parser.extend(tsPlugin({ jsx: true }));
9
8
  export function parseScript(content) {
10
9
  const [opts, comments] = scriptParseOptionsWithComments();
11
10
  return [JsxParser.parse(content, opts), comments];
@@ -18,7 +17,7 @@ export class JSXTransformer extends Transformer {
18
17
  inCompoundText = false;
19
18
  commentDirectivesStack = [];
20
19
  lastVisitIsComment = false;
21
- currentJsxKey = 0;
20
+ currentJsxKey;
22
21
  mixedVisitor;
23
22
  constructor(content, filename, index, heuristic, pluralsFunc, catalogExpr, rtConf) {
24
23
  super(content, filename, index, heuristic, pluralsFunc, catalogExpr, rtConf);
@@ -107,11 +106,14 @@ export class JSXTransformer extends Transformer {
107
106
  for (const attr of node.openingElement.attributes) {
108
107
  msgs.push(...this.visitJx(attr));
109
108
  }
110
- if (this.inCompoundText) {
111
- this.mstr.appendLeft(
112
- // @ts-expect-error
113
- node.openingElement.name.end, ` key="_${this.currentJsxKey}"`);
114
- this.currentJsxKey++;
109
+ if (this.inCompoundText && this.currentJsxKey != null) {
110
+ const key = node.openingElement.attributes.find(attr => attr.type === 'JSXAttribute' && attr.name.name === 'key');
111
+ if (!key) {
112
+ this.mstr.appendLeft(
113
+ // @ts-expect-error
114
+ node.openingElement.name.end, ` key="_${this.currentJsxKey}"`);
115
+ this.currentJsxKey++;
116
+ }
115
117
  }
116
118
  this.currentElement = currentElement;
117
119
  return msgs;
@@ -220,6 +222,9 @@ export class JSXTransformer extends Transformer {
220
222
  this.comments = comments;
221
223
  this.mstr = new MagicString(this.content);
222
224
  this.mixedVisitor = this.initMixedVisitor();
225
+ if (lib === 'default') {
226
+ this.currentJsxKey = 0;
227
+ }
223
228
  const msgs = this.visitJx(ast);
224
229
  const header = [
225
230
  `import ${rtComponent} from "@wuchale/jsx/runtime${lib === 'solidjs' ? '.solid' : ''}.jsx"`,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wuchale/jsx",
3
- "version": "0.7.1",
3
+ "version": "0.7.3",
4
4
  "description": "Protobuf-like i18n from plain code: JSX adapter",
5
5
  "scripts": {
6
6
  "dev": "tsc --watch",
@@ -71,8 +71,7 @@
71
71
  "dependencies": {
72
72
  "@sveltejs/acorn-typescript": "^1.0.5",
73
73
  "acorn": "^8.15.0",
74
- "acorn-jsx": "^5.3.2",
75
- "wuchale": "^0.16.4"
74
+ "wuchale": "^0.16.5"
76
75
  },
77
76
  "devDependencies": {
78
77
  "@types/estree-jsx": "^1.0.5",