@wuchale/jsx 0.6.2 → 0.7.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 +4 -3
- package/dist/transformer.d.ts +3 -3
- package/dist/transformer.js +10 -6
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { defaultGenerateLoadID, defaultHeuristic, deepMergeObjects } from 'wuchale';
|
|
2
2
|
import { adapter as vanillaAdapter } from 'wuchale/adapter-vanilla';
|
|
3
3
|
import { JSXTransformer } from "./transformer.js";
|
|
4
|
-
import { getDependencies } from 'wuchale/adapter-utils';
|
|
5
|
-
const ignoreElements = ['style', 'path'];
|
|
4
|
+
import { getDependencies, loaderPathResolver } from 'wuchale/adapter-utils';
|
|
5
|
+
const ignoreElements = ['style', 'path', 'code', 'pre'];
|
|
6
6
|
const jsxHeuristic = (msgStr, details) => {
|
|
7
7
|
if (!defaultHeuristic(msgStr, details)) {
|
|
8
8
|
return false;
|
|
@@ -65,6 +65,7 @@ const defaultArgs = {
|
|
|
65
65
|
runtime: defaultRuntime,
|
|
66
66
|
variant: 'default',
|
|
67
67
|
};
|
|
68
|
+
const resolveLoaderPath = loaderPathResolver(import.meta.url, '../src/loaders', 'js');
|
|
68
69
|
export const adapter = (args = defaultArgs) => {
|
|
69
70
|
let { heuristic, pluralsFunc, variant, runtime, ...rest } = deepMergeObjects(args, defaultArgs);
|
|
70
71
|
if (variant === 'solidjs' && args.runtime == null) {
|
|
@@ -93,7 +94,7 @@ export const adapter = (args = defaultArgs) => {
|
|
|
93
94
|
if (rest.bundleLoad) {
|
|
94
95
|
loader += '.bundle';
|
|
95
96
|
}
|
|
96
|
-
return
|
|
97
|
+
return resolveLoaderPath(loader);
|
|
97
98
|
},
|
|
98
99
|
runtime,
|
|
99
100
|
...rest,
|
package/dist/transformer.d.ts
CHANGED
|
@@ -2,8 +2,8 @@ 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,
|
|
6
|
-
import { MixedVisitor } from "wuchale/adapter-utils";
|
|
5
|
+
import type { IndexTracker, HeuristicFunc, TransformOutput, RuntimeConf, CatalogExpr } from 'wuchale';
|
|
6
|
+
import { MixedVisitor, type CommentDirectives } from "wuchale/adapter-utils";
|
|
7
7
|
export declare function parseScript(content: string): [Estree.Program, Estree.Comment[][]];
|
|
8
8
|
type MixedNodesTypes = JX.JSXElement | JX.JSXFragment | JX.JSXText | JX.JSXExpressionContainer | JX.JSXSpreadChild;
|
|
9
9
|
export type JSXLib = 'default' | 'solidjs';
|
|
@@ -12,7 +12,7 @@ export declare class JSXTransformer extends Transformer {
|
|
|
12
12
|
inCompoundText: boolean;
|
|
13
13
|
commentDirectivesStack: CommentDirectives[];
|
|
14
14
|
lastVisitIsComment: boolean;
|
|
15
|
-
|
|
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
|
@@ -4,7 +4,7 @@ import { Message } from 'wuchale';
|
|
|
4
4
|
import { tsPlugin } from '@sveltejs/acorn-typescript';
|
|
5
5
|
import jsx from 'acorn-jsx';
|
|
6
6
|
import { Transformer, scriptParseOptionsWithComments } from 'wuchale/adapter-vanilla';
|
|
7
|
-
import { nonWhitespaceText, MixedVisitor } from "wuchale/adapter-utils";
|
|
7
|
+
import { nonWhitespaceText, MixedVisitor, processCommentDirectives } from "wuchale/adapter-utils";
|
|
8
8
|
const JsxParser = Parser.extend(tsPlugin(), jsx());
|
|
9
9
|
export function parseScript(content) {
|
|
10
10
|
const [opts, comments] = scriptParseOptionsWithComments();
|
|
@@ -18,7 +18,7 @@ export class JSXTransformer extends Transformer {
|
|
|
18
18
|
inCompoundText = false;
|
|
19
19
|
commentDirectivesStack = [];
|
|
20
20
|
lastVisitIsComment = false;
|
|
21
|
-
|
|
21
|
+
currentJsxKey = 0;
|
|
22
22
|
mixedVisitor;
|
|
23
23
|
constructor(content, filename, index, heuristic, pluralsFunc, catalogExpr, rtConf) {
|
|
24
24
|
super(content, filename, index, heuristic, pluralsFunc, catalogExpr, rtConf);
|
|
@@ -110,7 +110,8 @@ export class JSXTransformer extends Transformer {
|
|
|
110
110
|
if (this.inCompoundText) {
|
|
111
111
|
this.mstr.appendLeft(
|
|
112
112
|
// @ts-expect-error
|
|
113
|
-
node.openingElement.name.end, ` key="_${this.
|
|
113
|
+
node.openingElement.name.end, ` key="_${this.currentJsxKey}"`);
|
|
114
|
+
this.currentJsxKey++;
|
|
114
115
|
}
|
|
115
116
|
this.currentElement = currentElement;
|
|
116
117
|
return msgs;
|
|
@@ -182,12 +183,12 @@ export class JSXTransformer extends Transformer {
|
|
|
182
183
|
if (!commentContents) {
|
|
183
184
|
return [];
|
|
184
185
|
}
|
|
185
|
-
|
|
186
|
+
this.commentDirectives = processCommentDirectives(commentContents, this.commentDirectives);
|
|
186
187
|
if (this.lastVisitIsComment) {
|
|
187
|
-
this.commentDirectivesStack[this.commentDirectivesStack.length - 1] =
|
|
188
|
+
this.commentDirectivesStack[this.commentDirectivesStack.length - 1] = this.commentDirectives;
|
|
188
189
|
}
|
|
189
190
|
else {
|
|
190
|
-
this.commentDirectivesStack.push(
|
|
191
|
+
this.commentDirectivesStack.push(this.commentDirectives);
|
|
191
192
|
}
|
|
192
193
|
this.lastVisitIsComment = true;
|
|
193
194
|
return [];
|
|
@@ -205,6 +206,9 @@ export class JSXTransformer extends Transformer {
|
|
|
205
206
|
this.commentDirectives = this.commentDirectivesStack.pop();
|
|
206
207
|
this.lastVisitIsComment = false;
|
|
207
208
|
}
|
|
209
|
+
if (this.commentDirectives.ignoreFile) {
|
|
210
|
+
return [];
|
|
211
|
+
}
|
|
208
212
|
if (this.commentDirectives.forceInclude !== false) {
|
|
209
213
|
msgs = this.visit(node);
|
|
210
214
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wuchale/jsx",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
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.
|
|
75
|
+
"wuchale": "^0.16.0"
|
|
76
76
|
},
|
|
77
77
|
"devDependencies": {
|
|
78
78
|
"@types/estree-jsx": "^1.0.5",
|