wuchale 0.15.5 → 0.15.7

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.
@@ -4,7 +4,7 @@ export declare const varNames: {
4
4
  hmrUpdate: string;
5
5
  rtWrap: string;
6
6
  };
7
- export declare function runtimeVars(wrapFunc: (expr: string) => string): {
7
+ export declare function runtimeVars(wrapFunc: (expr: string) => string, base?: string): {
8
8
  rtTrans: string;
9
9
  rtTPlural: string;
10
10
  rtPlural: string;
@@ -5,13 +5,13 @@ export const varNames = {
5
5
  hmrUpdate: '_w_hmrUpdate_',
6
6
  rtWrap: '_w_to_rt_',
7
7
  };
8
- export function runtimeVars(wrapFunc) {
8
+ export function runtimeVars(wrapFunc, base = varNames.rt) {
9
9
  return {
10
- rtTrans: `${wrapFunc(varNames.rt)}.t`,
11
- rtTPlural: `${wrapFunc(varNames.rt)}.tp`,
12
- rtPlural: `${wrapFunc(varNames.rt)}._.p`,
13
- rtCtx: `${wrapFunc(varNames.rt)}.cx`,
14
- rtTransCtx: `${wrapFunc(varNames.rt)}.tx`,
10
+ rtTrans: `${wrapFunc(base)}.t`,
11
+ rtTPlural: `${wrapFunc(base)}.tp`,
12
+ rtPlural: `${wrapFunc(base)}._.p`,
13
+ rtCtx: `${wrapFunc(base)}.cx`,
14
+ rtTransCtx: `${wrapFunc(base)}.tx`,
15
15
  /** for when nesting, used in adapters with elements */
16
16
  nestCtx: '_w_ctx_',
17
17
  };
@@ -6,7 +6,7 @@ import { type RuntimeVars } from "../adapter-utils/index.js";
6
6
  export declare const scriptParseOptions: Estree.Options;
7
7
  export declare function scriptParseOptionsWithComments(): [Estree.Options, Estree.Comment[][]];
8
8
  export declare function parseScript(content: string): [Estree.Program, Estree.Comment[][]];
9
- declare function initRuntimeStmt(rtConf: RuntimeConf, expr: CatalogExpr): (file: string, funcName: string, parentFunc: string, additional: object) => string;
9
+ type InitRuntimeFunc = (file: string, funcName: string, parentFunc: string, additional: object) => string;
10
10
  export declare class Transformer {
11
11
  index: IndexTracker;
12
12
  heuristic: HeuristicFunc;
@@ -15,7 +15,8 @@ export declare class Transformer {
15
15
  filename: string;
16
16
  mstr: MagicString;
17
17
  pluralFunc: string;
18
- initRuntime: ReturnType<typeof initRuntimeStmt>;
18
+ initRuntime: InitRuntimeFunc;
19
+ currentRtVar: string;
19
20
  vars: () => RuntimeVars;
20
21
  commentDirectives: CommentDirectives;
21
22
  insideProgram: boolean;
@@ -26,7 +27,7 @@ export declare class Transformer {
26
27
  currentTopLevelCall: string;
27
28
  /** for subclasses. right now for svelte, if in <script module> */
28
29
  additionalState: object;
29
- constructor(content: string, filename: string, index: IndexTracker, heuristic: HeuristicFunc, pluralsFunc: string, catalogExpr: CatalogExpr, rtConf: RuntimeConf);
30
+ constructor(content: string, filename: string, index: IndexTracker, heuristic: HeuristicFunc, pluralsFunc: string, catalogExpr: CatalogExpr, rtConf: RuntimeConf, rtBaseVars?: string[]);
30
31
  checkHeuristicBool: HeuristicFunc<HeuristicDetailsBase>;
31
32
  checkHeuristic: (msgStr: string, detailsBase: HeuristicDetailsBase) => [boolean, Message];
32
33
  visitLiteral: (node: Estree.Literal & {
@@ -34,6 +35,7 @@ export declare class Transformer {
34
35
  end: number;
35
36
  }) => Message[];
36
37
  visitArrayExpression: (node: Estree.ArrayExpression) => Message[];
38
+ visitSequenceExpression: (node: Estree.SequenceExpression) => Message[];
37
39
  visitObjectExpression: (node: Estree.ObjectExpression) => Message[];
38
40
  visitObjectPattern: (node: Estree.ObjectPattern) => Message[];
39
41
  visitRestElement: (node: Estree.RestElement) => Message[];
@@ -39,18 +39,6 @@ export function parseScript(content) {
39
39
  const [opts, comments] = scriptParseOptionsWithComments();
40
40
  return [ScriptParser.parse(content, opts), comments];
41
41
  }
42
- function initRuntimeStmt(rtConf, expr) {
43
- return (file, funcName, parentFunc, additional) => {
44
- const useReactive = rtConf.useReactive({ funcName, nested: parentFunc != null, file, additional });
45
- if (useReactive.init == null) {
46
- return;
47
- }
48
- const wrapInit = useReactive.init ? rtConf.reactive.wrapInit : rtConf.plain.wrapInit;
49
- const catalogExpr = useReactive.init ? expr.reactive : expr.plain;
50
- const runtimeExpr = `${varNames.rtWrap}(${catalogExpr})`;
51
- return `\nconst ${varNames.rt} = ${wrapInit(runtimeExpr)}\n`;
52
- };
53
- }
54
42
  export class Transformer {
55
43
  index;
56
44
  heuristic;
@@ -61,6 +49,7 @@ export class Transformer {
61
49
  mstr;
62
50
  pluralFunc;
63
51
  initRuntime;
52
+ currentRtVar;
64
53
  vars;
65
54
  // state
66
55
  commentDirectives = {};
@@ -72,21 +61,27 @@ export class Transformer {
72
61
  currentTopLevelCall;
73
62
  /** for subclasses. right now for svelte, if in <script module> */
74
63
  additionalState = {};
75
- constructor(content, filename, index, heuristic, pluralsFunc, catalogExpr, rtConf) {
64
+ constructor(content, filename, index, heuristic, pluralsFunc, catalogExpr, rtConf, rtBaseVars = [varNames.rt]) {
76
65
  this.index = index;
77
66
  this.heuristic = heuristic;
78
67
  this.pluralFunc = pluralsFunc;
79
68
  this.content = content;
80
69
  this.filename = filename;
81
- this.initRuntime = initRuntimeStmt(rtConf, catalogExpr);
82
70
  const topLevelUseReactive = rtConf.useReactive({
83
71
  funcName: null,
84
72
  nested: false,
85
73
  file: filename,
86
74
  additional: this.additionalState,
87
75
  });
88
- const reactiveVars = rtConf.reactive?.wrapUse && runtimeVars(rtConf.reactive.wrapUse);
89
- const plainVars = rtConf.plain?.wrapUse && runtimeVars(rtConf.plain.wrapUse);
76
+ const vars = {};
77
+ // to enable the use of different runtime vars for different places, right now for svelte <script module>s
78
+ for (const baseVar of rtBaseVars) {
79
+ vars[baseVar] = {
80
+ reactive: rtConf.reactive?.wrapUse && runtimeVars(rtConf.reactive.wrapUse, baseVar),
81
+ plain: rtConf.plain?.wrapUse && runtimeVars(rtConf.plain.wrapUse, baseVar),
82
+ };
83
+ }
84
+ this.currentRtVar = rtBaseVars[0];
90
85
  this.vars = () => {
91
86
  const useReactive = rtConf.useReactive({
92
87
  funcName: this.currentFuncDef,
@@ -94,7 +89,18 @@ export class Transformer {
94
89
  file: filename,
95
90
  additional: this.additionalState,
96
91
  }) ?? topLevelUseReactive;
97
- return useReactive.use ? reactiveVars : plainVars;
92
+ const currentVars = vars[this.currentRtVar];
93
+ return useReactive.use ? currentVars.reactive : currentVars.plain;
94
+ };
95
+ this.initRuntime = (file, funcName, parentFunc, additional) => {
96
+ const useReactive = rtConf.useReactive({ funcName, nested: parentFunc != null, file, additional });
97
+ if (useReactive.init == null) {
98
+ return;
99
+ }
100
+ const wrapInit = useReactive.init ? rtConf.reactive.wrapInit : rtConf.plain.wrapInit;
101
+ const expr = useReactive.init ? catalogExpr.reactive : catalogExpr.plain;
102
+ const runtimeExpr = `${varNames.rtWrap}(${expr})`;
103
+ return `\nconst ${this.currentRtVar} = ${wrapInit(runtimeExpr)}\n`;
98
104
  };
99
105
  }
100
106
  checkHeuristicBool = (msgStr, detailsBase) => {
@@ -140,6 +146,7 @@ export class Transformer {
140
146
  return [msgInfo];
141
147
  };
142
148
  visitArrayExpression = (node) => node.elements.map(this.visit).flat();
149
+ visitSequenceExpression = (node) => node.expressions.map(this.visit).flat();
143
150
  visitObjectExpression = (node) => node.properties.map(this.visit).flat();
144
151
  visitObjectPattern = (node) => node.properties.map(this.visit).flat();
145
152
  visitRestElement = (node) => this.visit(node.argument);
@@ -16,7 +16,9 @@ export async function extractAdap(handler, sharedState, files, locales, clean, l
16
16
  if (clean) {
17
17
  for (const loc of locales) {
18
18
  for (const item of Object.values(handler.sharedState.poFilesByLoc[loc].catalog)) {
19
- item.references = [];
19
+ // unreference all files that belong to this adapter
20
+ // don't touch other adapters' files
21
+ item.references = item.references.filter(ref => !handler.fileMatches(ref));
20
22
  }
21
23
  }
22
24
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wuchale",
3
- "version": "0.15.5",
3
+ "version": "0.15.7",
4
4
  "description": "Protobuf-like i18n from plain code",
5
5
  "scripts": {
6
6
  "dev": "tsc --watch",