@wuchale/jsx 0.7.0 → 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.
- package/dist/index.js +0 -4
- package/dist/transformer.d.ts +1 -1
- package/dist/transformer.js +12 -6
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -2,14 +2,10 @@ import { defaultGenerateLoadID, defaultHeuristic, deepMergeObjects } from 'wucha
|
|
|
2
2
|
import { 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 ignoreElements = ['style', 'path', 'code', 'pre'];
|
|
6
5
|
const jsxHeuristic = (msgStr, details) => {
|
|
7
6
|
if (!defaultHeuristic(msgStr, details)) {
|
|
8
7
|
return false;
|
|
9
8
|
}
|
|
10
|
-
if (ignoreElements.includes(details.element)) {
|
|
11
|
-
return false;
|
|
12
|
-
}
|
|
13
9
|
if (details.scope !== 'script') {
|
|
14
10
|
return true;
|
|
15
11
|
}
|
package/dist/transformer.d.ts
CHANGED
|
@@ -12,7 +12,7 @@ export declare class JSXTransformer extends Transformer {
|
|
|
12
12
|
inCompoundText: boolean;
|
|
13
13
|
commentDirectivesStack: CommentDirectives[];
|
|
14
14
|
lastVisitIsComment: boolean;
|
|
15
|
-
currentJsxKey
|
|
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>;
|
package/dist/transformer.js
CHANGED
|
@@ -18,7 +18,7 @@ export class JSXTransformer extends Transformer {
|
|
|
18
18
|
inCompoundText = false;
|
|
19
19
|
commentDirectivesStack = [];
|
|
20
20
|
lastVisitIsComment = false;
|
|
21
|
-
currentJsxKey
|
|
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
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
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.
|
|
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.
|
|
75
|
+
"wuchale": "^0.16.5"
|
|
76
76
|
},
|
|
77
77
|
"devDependencies": {
|
|
78
78
|
"@types/estree-jsx": "^1.0.5",
|