@wuchale/jsx 0.6.1 → 0.6.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 CHANGED
@@ -71,8 +71,8 @@ export const adapter = (args = defaultArgs) => {
71
71
  runtime = defaultRuntimeSolid;
72
72
  }
73
73
  return {
74
- transform: ({ content, filename, index, header }) => {
75
- return new JSXTransformer(content, filename, index, heuristic, pluralsFunc, header.expr, runtime).transformJx(header.head, variant);
74
+ transform: ({ content, filename, index, expr }) => {
75
+ return new JSXTransformer(content, filename, index, heuristic, pluralsFunc, expr, runtime).transformJx(variant);
76
76
  },
77
77
  loaderExts: ['.js', '.ts'],
78
78
  defaultLoaders: async () => {
package/dist/runtime.d.ts CHANGED
@@ -1,10 +1,10 @@
1
1
  import type { Composite, Mixed } from 'wuchale';
2
2
  export type WuchaleComponentProps = {
3
- nest?: boolean;
4
- ctx: Composite;
5
- tags: Function;
6
- args: any[];
3
+ n?: boolean;
4
+ x: Composite;
5
+ t: Function;
6
+ a: any[];
7
7
  };
8
- export declare function selectFragment({ nest, ctx, tags, args }: WuchaleComponentProps, i: number): string | Mixed | Composite;
8
+ export declare function selectFragment({ n, x, t, a }: WuchaleComponentProps, i: number): string | Mixed | Composite;
9
9
  declare const _default: (props: WuchaleComponentProps) => (string | Composite | Mixed)[];
10
10
  export default _default;
package/dist/runtime.jsx CHANGED
@@ -1,22 +1,22 @@
1
- export function selectFragment({ nest, ctx, tags, args }, i) {
2
- if (typeof ctx === 'string') {
3
- return ctx;
1
+ export function selectFragment({ n, x, t, a }, i) {
2
+ if (typeof x === 'string') {
3
+ return x;
4
4
  }
5
- if (typeof ctx === 'number') {
6
- if (!nest || i > 0) {
7
- return args[ctx];
5
+ if (typeof x === 'number') {
6
+ if (!n || i > 0) {
7
+ return a[x];
8
8
  }
9
9
  }
10
10
  else {
11
- const tag = tags[ctx[0]];
11
+ const tag = t[x[0]];
12
12
  if (tag == null) {
13
13
  return 'i18n-404:tag';
14
14
  }
15
15
  else {
16
- return tag(ctx);
16
+ return tag(x);
17
17
  }
18
18
  }
19
19
  }
20
20
  export default (props) => {
21
- return props.ctx.map((fragment, i) => selectFragment({ ...props, ctx: fragment }, i));
21
+ return props.x.map((fragment, i) => selectFragment({ ...props, x: fragment }, i));
22
22
  };
@@ -1,7 +1,7 @@
1
1
  import { selectFragment } from './runtime.jsx';
2
2
  import { For } from 'solid-js';
3
3
  export default (props) => {
4
- return <For each={props.ctx}>
5
- {(fragment, i) => <>{selectFragment({ ...props, ctx: fragment }, i())}</>}
4
+ return <For each={props.x}>
5
+ {(fragment, i) => <>{selectFragment({ ...props, x: fragment }, i())}</>}
6
6
  </For>;
7
7
  };
@@ -30,6 +30,6 @@ export declare class JSXTransformer extends Transformer {
30
30
  visitJSXSpreadAttribute: (node: JX.JSXSpreadAttribute) => Message[];
31
31
  visitJSXEmptyExpression: (node: JX.JSXEmptyExpression) => Message[];
32
32
  visitJx: (node: JX.Node | JX.JSXSpreadChild | Estree.Program) => Message[];
33
- transformJx: (headerHead: string, lib: JSXLib) => TransformOutput;
33
+ transformJx: (lib: JSXLib) => TransformOutput;
34
34
  }
35
35
  export {};
@@ -11,7 +11,7 @@ export function parseScript(content) {
11
11
  return [JsxParser.parse(content, opts), comments];
12
12
  }
13
13
  const nodesWithChildren = ['JSXElement'];
14
- const rtComponent = 'WuchaleTrans';
14
+ const rtComponent = 'W_tx_';
15
15
  export class JSXTransformer extends Transformer {
16
16
  // state
17
17
  currentElement;
@@ -52,19 +52,23 @@ export class JSXTransformer extends Transformer {
52
52
  checkHeuristic: this.checkHeuristicBool,
53
53
  index: this.index,
54
54
  wrapNested: (msgInfo, hasExprs, nestedRanges, lastChildEnd) => {
55
- for (const [i, [childStart, _, haveCtx]] of nestedRanges.entries()) {
56
- let toAppend;
57
- if (i === 0) {
58
- toAppend = `<${rtComponent} tags={[`;
55
+ let begin = `<${rtComponent}`;
56
+ if (nestedRanges.length > 0) {
57
+ for (const [i, [childStart, _, haveCtx]] of nestedRanges.entries()) {
58
+ let toAppend;
59
+ if (i === 0) {
60
+ toAppend = `${begin} t={[`;
61
+ }
62
+ else {
63
+ toAppend = ', ';
64
+ }
65
+ this.mstr.appendRight(childStart, `${toAppend}${haveCtx ? this.vars().nestCtx : '()'} => `);
59
66
  }
60
- else {
61
- toAppend = ', ';
62
- }
63
- this.mstr.appendRight(childStart, `${toAppend}${haveCtx ? this.vars().nestCtx : '()'} => `);
67
+ begin = `]}`;
64
68
  }
65
- let begin = `]} ctx=`;
69
+ begin += ' x=';
66
70
  if (this.inCompoundText) {
67
- begin += `{${this.vars().nestCtx}} nest`;
71
+ begin += `{${this.vars().nestCtx}} n`;
68
72
  }
69
73
  else {
70
74
  const index = this.index.get(msgInfo.toKey());
@@ -72,7 +76,7 @@ export class JSXTransformer extends Transformer {
72
76
  }
73
77
  let end = ' />';
74
78
  if (hasExprs) {
75
- begin += ' args={[';
79
+ begin += ' a={[';
76
80
  end = ']}' + end;
77
81
  }
78
82
  this.mstr.appendLeft(lastChildEnd, begin);
@@ -207,22 +211,17 @@ export class JSXTransformer extends Transformer {
207
211
  this.commentDirectives = commentDirectivesPrev;
208
212
  return msgs;
209
213
  };
210
- transformJx = (headerHead, lib) => {
214
+ transformJx = (lib) => {
211
215
  const [ast, comments] = parseScript(this.content);
212
216
  this.comments = comments;
213
217
  this.mstr = new MagicString(this.content);
214
218
  this.mixedVisitor = this.initMixedVisitor();
215
219
  const msgs = this.visitJx(ast);
216
- if (!msgs.length) {
217
- return this.finalize(msgs, 0);
218
- }
219
- const headerFin = [
220
+ const header = [
220
221
  `import ${rtComponent} from "@wuchale/jsx/runtime${lib === 'solidjs' ? '.solid' : ''}.jsx"`,
221
- headerHead,
222
222
  this.initRuntime(this.filename, null, null, {}),
223
223
  ].join('\n');
224
224
  const bodyStart = this.getRealBodyStart(ast.body);
225
- this.mstr.appendRight(bodyStart, headerFin + '\n');
226
- return this.finalize(msgs, bodyStart);
225
+ return this.finalize(msgs, bodyStart, header);
227
226
  };
228
227
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wuchale/jsx",
3
- "version": "0.6.1",
3
+ "version": "0.6.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.15.1"
75
+ "wuchale": "^0.15.4"
76
76
  },
77
77
  "devDependencies": {
78
78
  "@types/estree-jsx": "^1.0.5",