@wuchale/jsx 0.7.3 → 0.8.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 +8 -8
- package/dist/transformer.d.ts +3 -3
- package/dist/transformer.js +7 -5
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { defaultGenerateLoadID, defaultHeuristic, deepMergeObjects } from 'wuchale';
|
|
2
|
-
import { adapter as vanillaAdapter } from 'wuchale/adapter-vanilla';
|
|
2
|
+
import { pluralPattern, 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 jsxHeuristic =
|
|
6
|
-
if (!defaultHeuristic(
|
|
5
|
+
const jsxHeuristic = msg => {
|
|
6
|
+
if (!defaultHeuristic(msg)) {
|
|
7
7
|
return false;
|
|
8
8
|
}
|
|
9
|
-
if (details.scope !== 'script') {
|
|
9
|
+
if (msg.details.scope !== 'script') {
|
|
10
10
|
return true;
|
|
11
11
|
}
|
|
12
|
-
if (details.declaring === 'variable') {
|
|
12
|
+
if (msg.details.declaring === 'variable') {
|
|
13
13
|
return false;
|
|
14
14
|
}
|
|
15
15
|
return true;
|
|
@@ -52,7 +52,7 @@ const defaultRuntimeSolid = {
|
|
|
52
52
|
const defaultArgs = {
|
|
53
53
|
files: { include: 'src/**/*.{js,ts,jsx,tsx}', ignore: '**/*.d.ts' },
|
|
54
54
|
catalog: './src/locales/{locale}',
|
|
55
|
-
|
|
55
|
+
patterns: [pluralPattern],
|
|
56
56
|
heuristic: jsxHeuristic,
|
|
57
57
|
granularLoad: false,
|
|
58
58
|
bundleLoad: false,
|
|
@@ -63,13 +63,13 @@ const defaultArgs = {
|
|
|
63
63
|
};
|
|
64
64
|
const resolveLoaderPath = loaderPathResolver(import.meta.url, '../src/loaders', 'js');
|
|
65
65
|
export const adapter = (args = defaultArgs) => {
|
|
66
|
-
let { heuristic,
|
|
66
|
+
let { heuristic, patterns, variant, runtime, ...rest } = deepMergeObjects(args, defaultArgs);
|
|
67
67
|
if (variant === 'solidjs' && args.runtime == null) {
|
|
68
68
|
runtime = defaultRuntimeSolid;
|
|
69
69
|
}
|
|
70
70
|
return {
|
|
71
71
|
transform: ({ content, filename, index, expr }) => {
|
|
72
|
-
return new JSXTransformer(content, filename, index, heuristic,
|
|
72
|
+
return new JSXTransformer(content, filename, index, heuristic, patterns, expr, runtime).transformJx(variant);
|
|
73
73
|
},
|
|
74
74
|
loaderExts: ['.js', '.ts'],
|
|
75
75
|
defaultLoaders: async () => {
|
package/dist/transformer.d.ts
CHANGED
|
@@ -2,9 +2,9 @@ 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, RuntimeConf, CatalogExpr } from 'wuchale';
|
|
5
|
+
import type { IndexTracker, HeuristicFunc, TransformOutput, RuntimeConf, CatalogExpr, CodePattern } from 'wuchale';
|
|
6
6
|
import { MixedVisitor, type CommentDirectives } from "wuchale/adapter-utils";
|
|
7
|
-
export declare function
|
|
7
|
+
export declare function parseScriptJSX(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';
|
|
10
10
|
export declare class JSXTransformer extends Transformer {
|
|
@@ -14,7 +14,7 @@ export declare class JSXTransformer extends Transformer {
|
|
|
14
14
|
lastVisitIsComment: boolean;
|
|
15
15
|
currentJsxKey?: number;
|
|
16
16
|
mixedVisitor: MixedVisitor<MixedNodesTypes>;
|
|
17
|
-
constructor(content: string, filename: string, index: IndexTracker, heuristic: HeuristicFunc,
|
|
17
|
+
constructor(content: string, filename: string, index: IndexTracker, heuristic: HeuristicFunc, patterns: CodePattern[], catalogExpr: CatalogExpr, rtConf: RuntimeConf);
|
|
18
18
|
initMixedVisitor: () => MixedVisitor<MixedNodesTypes>;
|
|
19
19
|
visitChildrenJ: (node: JX.JSXElement | JX.JSXFragment) => Message[];
|
|
20
20
|
visitNameJSXNamespacedName: (node: JX.JSXNamespacedName) => string;
|
package/dist/transformer.js
CHANGED
|
@@ -2,10 +2,10 @@ 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 { Transformer, scriptParseOptionsWithComments } from 'wuchale/adapter-vanilla';
|
|
5
|
+
import { Transformer, scriptParseOptionsWithComments, parseScript } from 'wuchale/adapter-vanilla';
|
|
6
6
|
import { nonWhitespaceText, MixedVisitor, processCommentDirectives } from "wuchale/adapter-utils";
|
|
7
7
|
const JsxParser = Parser.extend(tsPlugin({ jsx: true }));
|
|
8
|
-
export function
|
|
8
|
+
export function parseScriptJSX(content) {
|
|
9
9
|
const [opts, comments] = scriptParseOptionsWithComments();
|
|
10
10
|
return [JsxParser.parse(content, opts), comments];
|
|
11
11
|
}
|
|
@@ -19,8 +19,8 @@ export class JSXTransformer extends Transformer {
|
|
|
19
19
|
lastVisitIsComment = false;
|
|
20
20
|
currentJsxKey;
|
|
21
21
|
mixedVisitor;
|
|
22
|
-
constructor(content, filename, index, heuristic,
|
|
23
|
-
super(content, filename, index, heuristic,
|
|
22
|
+
constructor(content, filename, index, heuristic, patterns, catalogExpr, rtConf) {
|
|
23
|
+
super(content, filename, index, heuristic, patterns, catalogExpr, rtConf);
|
|
24
24
|
}
|
|
25
25
|
initMixedVisitor = () => new MixedVisitor({
|
|
26
26
|
mstr: this.mstr,
|
|
@@ -48,6 +48,7 @@ export class JSXTransformer extends Transformer {
|
|
|
48
48
|
return childTxts;
|
|
49
49
|
},
|
|
50
50
|
visitExpressionTag: this.visitJSXExpressionContainer,
|
|
51
|
+
fullHeuristicDetails: this.fullHeuristicDetails,
|
|
51
52
|
checkHeuristic: this.checkHeuristicBool,
|
|
52
53
|
index: this.index,
|
|
53
54
|
wrapNested: (msgInfo, hasExprs, nestedRanges, lastChildEnd) => {
|
|
@@ -218,7 +219,8 @@ export class JSXTransformer extends Transformer {
|
|
|
218
219
|
return msgs;
|
|
219
220
|
};
|
|
220
221
|
transformJx = (lib) => {
|
|
221
|
-
|
|
222
|
+
// jsx vs type casting is not ambiguous in all files except .ts files
|
|
223
|
+
const [ast, comments] = (this.filename.endsWith('.ts') ? parseScript : parseScriptJSX)(this.content);
|
|
222
224
|
this.comments = comments;
|
|
223
225
|
this.mstr = new MagicString(this.content);
|
|
224
226
|
this.mixedVisitor = this.initMixedVisitor();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wuchale/jsx",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"description": "Protobuf-like i18n from plain code: JSX adapter",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"dev": "tsc --watch",
|
|
@@ -69,9 +69,9 @@
|
|
|
69
69
|
}
|
|
70
70
|
},
|
|
71
71
|
"dependencies": {
|
|
72
|
-
"@sveltejs/acorn-typescript": "^1.0.
|
|
72
|
+
"@sveltejs/acorn-typescript": "^1.0.6",
|
|
73
73
|
"acorn": "^8.15.0",
|
|
74
|
-
"wuchale": "^0.
|
|
74
|
+
"wuchale": "^0.17.0"
|
|
75
75
|
},
|
|
76
76
|
"devDependencies": {
|
|
77
77
|
"@types/estree-jsx": "^1.0.5",
|