@wuchale/jsx 0.7.1 → 0.7.2

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>;
@@ -18,7 +18,7 @@ export class JSXTransformer extends Transformer {
18
18
  inCompoundText = false;
19
19
  commentDirectivesStack = [];
20
20
  lastVisitIsComment = false;
21
- currentJsxKey = 0;
21
+ currentJsxKey;
22
22
  mixedVisitor;
23
23
  constructor(content, filename, index, heuristic, pluralsFunc, catalogExpr, rtConf) {
24
24
  super(content, filename, index, heuristic, pluralsFunc, catalogExpr, rtConf);
@@ -107,11 +107,14 @@ export class JSXTransformer extends Transformer {
107
107
  for (const attr of node.openingElement.attributes) {
108
108
  msgs.push(...this.visitJx(attr));
109
109
  }
110
- if (this.inCompoundText) {
111
- this.mstr.appendLeft(
112
- // @ts-expect-error
113
- node.openingElement.name.end, ` key="_${this.currentJsxKey}"`);
114
- this.currentJsxKey++;
110
+ if (this.inCompoundText && this.currentJsxKey != null) {
111
+ const key = node.openingElement.attributes.find(attr => attr.type === 'JSXAttribute' && attr.name.name === 'key');
112
+ if (!key) {
113
+ this.mstr.appendLeft(
114
+ // @ts-expect-error
115
+ node.openingElement.name.end, ` key="_${this.currentJsxKey}"`);
116
+ this.currentJsxKey++;
117
+ }
115
118
  }
116
119
  this.currentElement = currentElement;
117
120
  return msgs;
@@ -220,6 +223,9 @@ export class JSXTransformer extends Transformer {
220
223
  this.comments = comments;
221
224
  this.mstr = new MagicString(this.content);
222
225
  this.mixedVisitor = this.initMixedVisitor();
226
+ if (lib === 'default') {
227
+ this.currentJsxKey = 0;
228
+ }
223
229
  const msgs = this.visitJx(ast);
224
230
  const header = [
225
231
  `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.2",
4
4
  "description": "Protobuf-like i18n from plain code: JSX adapter",
5
5
  "scripts": {
6
6
  "dev": "tsc --watch",
@@ -72,7 +72,7 @@
72
72
  "@sveltejs/acorn-typescript": "^1.0.5",
73
73
  "acorn": "^8.15.0",
74
74
  "acorn-jsx": "^5.3.2",
75
- "wuchale": "^0.16.4"
75
+ "wuchale": "^0.16.5"
76
76
  },
77
77
  "devDependencies": {
78
78
  "@types/estree-jsx": "^1.0.5",