wuchale 0.22.11 → 0.23.1

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.
Files changed (44) hide show
  1. package/dist/adapter-utils/index.d.ts +1 -0
  2. package/dist/adapter-utils/index.js +9 -0
  3. package/dist/adapter-utils/mixed-visitor.d.ts +16 -17
  4. package/dist/adapter-utils/mixed-visitor.js +45 -47
  5. package/dist/adapter-vanilla/index.d.ts +3 -2
  6. package/dist/adapter-vanilla/index.js +7 -3
  7. package/dist/adapter-vanilla/transformer.d.ts +39 -5
  8. package/dist/adapter-vanilla/transformer.js +61 -16
  9. package/dist/adapters.d.ts +20 -24
  10. package/dist/ai/gemini.js +2 -2
  11. package/dist/ai/index.d.ts +0 -1
  12. package/dist/ai/index.js +0 -1
  13. package/dist/bundlers/vite.d.ts +10 -5
  14. package/dist/bundlers/vite.js +30 -12
  15. package/dist/cli/check.d.ts +1 -1
  16. package/dist/cli/check.js +1 -3
  17. package/dist/cli/index.js +1 -2
  18. package/dist/cli/status.js +1 -2
  19. package/dist/compile.js +2 -2
  20. package/dist/config.d.ts +8 -4
  21. package/dist/config.js +17 -18
  22. package/dist/fs.d.ts +2 -2
  23. package/dist/fs.js +19 -11
  24. package/dist/handler/files.d.ts +17 -12
  25. package/dist/handler/files.js +106 -118
  26. package/dist/handler/index.d.ts +27 -18
  27. package/dist/handler/index.js +118 -97
  28. package/dist/handler/state.d.ts +5 -5
  29. package/dist/handler/state.js +3 -3
  30. package/dist/handler/url.d.ts +2 -2
  31. package/dist/handler/url.js +11 -11
  32. package/dist/hub.d.ts +2 -2
  33. package/dist/hub.js +105 -99
  34. package/dist/index.d.ts +4 -3
  35. package/dist/index.js +2 -2
  36. package/dist/pofile.d.ts +1 -0
  37. package/dist/pofile.js +49 -41
  38. package/dist/runtime.d.ts +10 -5
  39. package/dist/runtime.js +6 -12
  40. package/dist/storage.d.ts +8 -7
  41. package/dist/storage.js +16 -1
  42. package/dist/url.js +1 -1
  43. package/package.json +6 -6
  44. package/src/adapter-vanilla/loaders/server.js +1 -1
@@ -27,3 +27,4 @@ export type CommentDirectives = {
27
27
  context?: string;
28
28
  };
29
29
  export declare function updateCommentDirectives(data: string, directives: CommentDirectives): void;
30
+ export declare function restoreCommentDirectives(target: CommentDirectives, original: CommentDirectives): void;
@@ -59,3 +59,12 @@ export function updateCommentDirectives(data, directives) {
59
59
  directives.context = data.slice(commentDirectives.context.length).trim();
60
60
  }
61
61
  }
62
+ /** for restore. like Object.assign but in reverse, pull the keys on the target from the source */
63
+ function pullDirective(target, source, key) {
64
+ target[key] = source[key];
65
+ }
66
+ export function restoreCommentDirectives(target, original) {
67
+ for (const key in target) {
68
+ pullDirective(target, original, key); // restore
69
+ }
70
+ }
@@ -2,22 +2,22 @@ import type MagicString from 'magic-string';
2
2
  import { type HeuristicDetails, type HeuristicDetailsBase, type HeuristicFunc, type IndexTracker, type Message, type MessageType } from '../adapters.js';
3
3
  import { type CommentDirectives, type RuntimeVars } from './index.js';
4
4
  type NestedRanges = [number, number, boolean][];
5
- type InitProps<NodeT> = {
5
+ type InitProps<MixNodeT, TxtT extends MixNodeT, ComT extends MixNodeT, ExprT extends MixNodeT> = {
6
6
  vars: () => RuntimeVars;
7
7
  mstr: MagicString;
8
- getRange: (node: NodeT) => {
8
+ getRange: (node: MixNodeT) => {
9
9
  start: number;
10
10
  end: number;
11
11
  };
12
- isText: (node: NodeT) => boolean;
13
- isExpression: (node: NodeT) => boolean;
14
- isComment: (node: NodeT) => boolean;
15
- leaveInPlace: (node: NodeT) => boolean;
16
- canHaveChildren: (node: NodeT) => boolean;
17
- getTextContent: (node: NodeT) => string;
18
- getCommentData: (node: NodeT) => string;
19
- visitFunc: (node: NodeT, inCompoundText: boolean) => Message[];
20
- visitExpressionTag: (node: NodeT) => Message[];
12
+ isText: (node: MixNodeT) => node is TxtT;
13
+ isExpression: (node: MixNodeT) => node is ExprT;
14
+ isComment: (node: MixNodeT) => node is ComT;
15
+ leaveInPlace: (node: MixNodeT) => boolean;
16
+ canHaveChildren: (node: MixNodeT) => boolean;
17
+ getTextContent: (node: TxtT) => string;
18
+ getCommentData: (node: ComT) => string;
19
+ visitFunc: (node: MixNodeT, inCompoundText: boolean) => Message[];
20
+ visitExpressionTag: (node: ExprT) => Message[];
21
21
  fullHeuristicDetails: (details: HeuristicDetailsBase) => HeuristicDetails;
22
22
  checkHeuristic: HeuristicFunc;
23
23
  wrapNested: (msgInfo: Message, hasExprs: boolean, nestedRanges: NestedRanges, lastChildEnd: number) => void;
@@ -36,12 +36,11 @@ type VisitProps<NodeT> = {
36
36
  * e.g. components in jsx to prevent `[object Object]` being rendered. */
37
37
  useComponent?: boolean;
38
38
  };
39
- export interface MixedVisitor<NodeT> extends InitProps<NodeT> {
40
- }
41
39
  type SeparateVisitRes = [boolean, boolean, boolean, MessageType, Message[]];
42
- export declare class MixedVisitor<NodeT> {
43
- constructor(props: InitProps<NodeT>);
44
- separatelyVisitChildren: (props: VisitProps<NodeT>) => SeparateVisitRes;
45
- visit: (props: VisitProps<NodeT>) => Message[];
40
+ export declare class MixedVisitor<MixNodeT, TxtT extends MixNodeT, ComT extends MixNodeT, ExprT extends MixNodeT> {
41
+ #private;
42
+ constructor(props: InitProps<MixNodeT, TxtT, ComT, ExprT>);
43
+ separatelyVisitChildren: (props: VisitProps<MixNodeT>) => SeparateVisitRes;
44
+ visit: (props: VisitProps<MixNodeT>) => Message[];
46
45
  }
47
46
  export {};
@@ -1,9 +1,10 @@
1
1
  // Shared logic between adapters for handling nested / mixed elements within elements / fragments
2
2
  import { getKey, newMessage, } from '../adapters.js';
3
- import { commentPrefix, nonWhitespaceText, updateCommentDirectives, varNames, } from './index.js';
3
+ import { commentPrefix, nonWhitespaceText, restoreCommentDirectives, updateCommentDirectives, varNames, } from './index.js';
4
4
  export class MixedVisitor {
5
+ #props;
5
6
  constructor(props) {
6
- Object.assign(this, props);
7
+ this.#props = props;
7
8
  }
8
9
  separatelyVisitChildren = (props) => {
9
10
  let hasTextChild = false;
@@ -11,20 +12,20 @@ export class MixedVisitor {
11
12
  let heurStr = '';
12
13
  let hasCommentDirectives = false;
13
14
  for (const child of props.children) {
14
- if (this.isText(child)) {
15
- const strContent = this.getTextContent(child);
15
+ if (this.#props.isText(child)) {
16
+ const strContent = this.#props.getTextContent(child);
16
17
  if (!strContent.trim()) {
17
18
  continue;
18
19
  }
19
20
  hasTextChild = true;
20
21
  heurStr += strContent;
21
22
  }
22
- else if (this.isComment(child)) {
23
- if (this.getCommentData(child).trim().startsWith(commentPrefix)) {
23
+ else if (this.#props.isComment(child)) {
24
+ if (this.#props.getCommentData(child).trim().startsWith(commentPrefix)) {
24
25
  hasCommentDirectives = true;
25
26
  }
26
27
  }
27
- else if (!this.leaveInPlace(child)) {
28
+ else if (!this.#props.leaveInPlace(child)) {
28
29
  hasNonTextChild = true;
29
30
  heurStr += `#`;
30
31
  }
@@ -32,13 +33,13 @@ export class MixedVisitor {
32
33
  heurStr = heurStr.trimEnd();
33
34
  const msg = newMessage({
34
35
  msgStr: [heurStr],
35
- details: this.fullHeuristicDetails({
36
+ details: this.#props.fullHeuristicDetails({
36
37
  scope: props.scope,
37
38
  element: props.element,
38
39
  attribute: props.attribute,
39
40
  }),
40
41
  });
41
- const heurMsgType = this.checkHeuristic(msg);
42
+ const heurMsgType = this.#props.checkHeuristic(msg);
42
43
  if (heurMsgType || props.commentDirectives.unit) {
43
44
  const hasCompoundText = hasTextChild && hasNonTextChild;
44
45
  if (props.inCompoundText || props.commentDirectives.unit || (hasCompoundText && !hasCommentDirectives)) {
@@ -54,27 +55,24 @@ export class MixedVisitor {
54
55
  const commentDirectivesOrig = { ...props.commentDirectives };
55
56
  let lastVisitIsComment = false;
56
57
  for (const child of props.children) {
57
- if (this.isComment(child)) {
58
- updateCommentDirectives(this.getCommentData(child), props.commentDirectives);
58
+ if (this.#props.isComment(child)) {
59
+ updateCommentDirectives(this.#props.getCommentData(child), props.commentDirectives);
59
60
  lastVisitIsComment = true;
60
61
  continue;
61
62
  }
62
- if (this.isText(child) && !this.getTextContent(child).trim()) {
63
+ if (this.#props.isText(child) && !this.#props.getTextContent(child).trim()) {
63
64
  continue;
64
65
  }
65
66
  if (props.commentDirectives.ignoreFile) {
66
67
  break;
67
68
  }
68
69
  if (props.commentDirectives.forceType !== false) {
69
- msgs.push(...this.visitFunc(child, props.inCompoundText));
70
+ msgs.push(...this.#props.visitFunc(child, props.inCompoundText));
70
71
  }
71
72
  if (!lastVisitIsComment) {
72
73
  continue;
73
74
  }
74
- // restore. like Object.assign but in reverse for keys
75
- for (const key in props.commentDirectives) {
76
- props.commentDirectives[key] = commentDirectivesOrig[key];
77
- }
75
+ restoreCommentDirectives(props.commentDirectives, commentDirectivesOrig);
78
76
  lastVisitIsComment = false;
79
77
  }
80
78
  return res;
@@ -90,21 +88,21 @@ export class MixedVisitor {
90
88
  let msgStr = '';
91
89
  let iArg = 0;
92
90
  let iTag = 0;
93
- const lastChildEnd = this.getRange(props.children.slice(-1)[0]).end;
91
+ const lastChildEnd = this.#props.getRange(props.children.slice(-1)[0]).end;
94
92
  const childrenNestedRanges = [];
95
93
  let hasTextDescendants = false;
96
94
  const msgs = [];
97
95
  const placeholders = [];
98
96
  for (const child of props.children) {
99
- if (this.isComment(child)) {
97
+ if (this.#props.isComment(child)) {
100
98
  continue;
101
99
  }
102
- const chRange = this.getRange(child);
103
- if (this.isText(child)) {
104
- const [startWh, trimmed, endWh] = nonWhitespaceText(this.getTextContent(child));
100
+ const chRange = this.#props.getRange(child);
101
+ if (this.#props.isText(child)) {
102
+ const [startWh, trimmed, endWh] = nonWhitespaceText(this.#props.getTextContent(child));
105
103
  const msgInfo = newMessage({
106
104
  msgStr: [trimmed],
107
- details: this.fullHeuristicDetails({ scope: props.scope }),
105
+ details: this.#props.fullHeuristicDetails({ scope: props.scope }),
108
106
  context: props.commentDirectives.context,
109
107
  });
110
108
  if (startWh && !msgStr.endsWith(' ')) {
@@ -118,36 +116,36 @@ export class MixedVisitor {
118
116
  if (endWh) {
119
117
  msgStr += ' ';
120
118
  }
121
- this.mstr.remove(chRange.start, chRange.end);
119
+ this.#props.mstr.remove(chRange.start, chRange.end);
122
120
  continue;
123
121
  }
124
- if (this.isExpression(child)) {
125
- msgs.push(...this.visitExpressionTag(child));
122
+ if (this.#props.isExpression(child)) {
123
+ msgs.push(...this.#props.visitExpressionTag(child));
126
124
  if (!hasCompoundText) {
127
125
  continue;
128
126
  }
129
127
  msgStr += `{${iArg}}`;
130
- placeholders.push([iArg, this.mstr.original.slice(chRange.start + 1, chRange.end - 1)]);
128
+ placeholders.push([iArg, this.#props.mstr.original.slice(chRange.start + 1, chRange.end - 1)]);
131
129
  let moveStart = chRange.start;
132
130
  if (iArg > 0) {
133
- this.mstr.update(chRange.start, chRange.start + 1, ', ');
131
+ this.#props.mstr.update(chRange.start, chRange.start + 1, ', ');
134
132
  }
135
133
  else {
136
134
  moveStart++;
137
- this.mstr.remove(chRange.start, chRange.start + 1);
135
+ this.#props.mstr.remove(chRange.start, chRange.start + 1);
138
136
  }
139
- this.mstr.move(moveStart, chRange.end - 1, lastChildEnd);
140
- this.mstr.remove(chRange.end - 1, chRange.end);
137
+ this.#props.mstr.move(moveStart, chRange.end - 1, lastChildEnd);
138
+ this.#props.mstr.remove(chRange.end - 1, chRange.end);
141
139
  iArg++;
142
140
  continue;
143
141
  }
144
- if (this.leaveInPlace(child)) {
145
- msgs.push(...this.visitFunc(child, this.canHaveChildren(child)));
142
+ if (this.#props.leaveInPlace(child)) {
143
+ msgs.push(...this.#props.visitFunc(child, this.#props.canHaveChildren(child)));
146
144
  continue;
147
145
  }
148
146
  // elements, components and other things as well
149
- const canHaveChildren = this.canHaveChildren(child);
150
- const childMsgs = this.visitFunc(child, canHaveChildren);
147
+ const canHaveChildren = this.#props.canHaveChildren(child);
148
+ const childMsgs = this.#props.visitFunc(child, canHaveChildren);
151
149
  let nestedNeedsCtx = false;
152
150
  let chTxt = '';
153
151
  for (const msgInfo of childMsgs) {
@@ -178,7 +176,7 @@ export class MixedVisitor {
178
176
  }
179
177
  const msgInfo = newMessage({
180
178
  msgStr: [msgStr],
181
- details: this.fullHeuristicDetails({ scope: props.scope }),
179
+ details: this.#props.fullHeuristicDetails({ scope: props.scope }),
182
180
  context: props.commentDirectives.context,
183
181
  });
184
182
  msgInfo.type = heurMsgType;
@@ -190,34 +188,34 @@ export class MixedVisitor {
190
188
  return msgs;
191
189
  }
192
190
  if (((props.useComponent ?? true) && props.scope === 'markup' && iArg > 0) || childrenNestedRanges.length > 0) {
193
- this.wrapNested(msgInfo, iArg > 0, childrenNestedRanges, lastChildEnd);
191
+ this.#props.wrapNested(msgInfo, iArg > 0, childrenNestedRanges, lastChildEnd);
194
192
  }
195
193
  else {
196
194
  // no need for component use
197
195
  let begin = '{';
198
196
  let end = ')}';
199
197
  if (props.inCompoundText) {
200
- begin += `${this.vars().rtTransCtx}(${this.vars().nestCtx}`;
198
+ begin += `${this.#props.vars().rtTransCtx}(${this.#props.vars().nestCtx}`;
201
199
  }
202
200
  else {
203
201
  if (msgInfo.type === 'url') {
204
202
  begin += `${varNames.urlLocalize}(`;
205
- end = `), ${this.vars().rtLocale}${end}`;
203
+ end = `), ${this.#props.vars().rtLocale}${end}`;
206
204
  }
207
- begin += `${this.vars().rtTrans}(${this.index.get(getKey(msgInfo.msgStr, msgInfo.context))}`;
205
+ begin += `${this.#props.vars().rtTrans}(${this.#props.index.get(getKey(msgInfo.msgStr, msgInfo.context))}`;
208
206
  }
209
207
  if (iArg > 0) {
210
208
  begin += ', [';
211
- end = ']' + end;
209
+ end = `]${end}`;
212
210
  }
213
- if (props.scope === 'attribute' && `'"`.includes(this.mstr.original[lastChildEnd])) {
211
+ if (props.scope === 'attribute' && `'"`.includes(this.#props.mstr.original[lastChildEnd])) {
214
212
  const firstChild = props.children[0];
215
- const { start } = this.getRange(firstChild);
216
- this.mstr.remove(start - 1, start);
217
- this.mstr.remove(lastChildEnd, lastChildEnd + 1);
213
+ const { start } = this.#props.getRange(firstChild);
214
+ this.#props.mstr.remove(start - 1, start);
215
+ this.#props.mstr.remove(lastChildEnd, lastChildEnd + 1);
218
216
  }
219
- this.mstr.appendLeft(lastChildEnd, begin);
220
- this.mstr.appendRight(lastChildEnd, end);
217
+ this.#props.mstr.appendLeft(lastChildEnd, begin);
218
+ this.#props.mstr.appendRight(lastChildEnd, end);
221
219
  }
222
220
  return msgs;
223
221
  };
@@ -1,7 +1,8 @@
1
1
  import type { Adapter, AdapterArgs, CodePattern, LoaderChoice } from '../adapters.js';
2
+ import { type DeepPartial } from '../config.js';
2
3
  import { Transformer } from './transformer.js';
3
- export { Transformer };
4
4
  export { parseScript, scriptParseOptions, scriptParseOptionsWithComments } from './transformer.js';
5
+ export { Transformer };
5
6
  export declare const pluralPattern: CodePattern;
6
7
  type LoadersAvailable = 'server' | 'vite';
7
8
  export type VanillaArgs = AdapterArgs<LoadersAvailable>;
@@ -10,4 +11,4 @@ export declare function getDefaultLoaderPath(loader: LoaderChoice<LoadersAvailab
10
11
  client: string;
11
12
  server: string;
12
13
  } | null;
13
- export declare const adapter: (args?: Partial<VanillaArgs>) => Adapter;
14
+ export declare const adapter: (args?: DeepPartial<VanillaArgs>) => Adapter;
@@ -1,11 +1,11 @@
1
1
  // $$ cd .. && npm run test
2
2
  import { loaderPathResolver } from '../adapter-utils/index.js';
3
3
  import { defaultGenerateLoadID, defaultHeuristicFuncOnly } from '../adapters.js';
4
- import { deepMergeObjects } from '../config.js';
4
+ import { fillDefaults } from '../config.js';
5
5
  import { pofile } from '../pofile.js';
6
6
  import { Transformer } from './transformer.js';
7
- export { Transformer };
8
7
  export { parseScript, scriptParseOptions, scriptParseOptionsWithComments } from './transformer.js';
8
+ export { Transformer };
9
9
  export const pluralPattern = {
10
10
  name: 'plural',
11
11
  args: ['other', 'message', 'pluralFunc'],
@@ -26,6 +26,10 @@ export const defaultArgs = {
26
26
  wrapInit: expr => expr,
27
27
  wrapUse: expr => expr,
28
28
  },
29
+ reactive: {
30
+ wrapInit: expr => expr,
31
+ wrapUse: expr => expr,
32
+ },
29
33
  },
30
34
  };
31
35
  const resolveLoaderPath = loaderPathResolver(import.meta.url, '../../src/adapter-vanilla/loaders', 'js');
@@ -45,7 +49,7 @@ export function getDefaultLoaderPath(loader, bundle) {
45
49
  return resolveLoaderPath(loader);
46
50
  }
47
51
  export const adapter = (args = defaultArgs) => {
48
- const { heuristic, patterns, runtime, loader, ...rest } = deepMergeObjects(args, defaultArgs);
52
+ const { heuristic, patterns, runtime, loader, ...rest } = fillDefaults(args, defaultArgs);
49
53
  return {
50
54
  transform: ({ content, filename, index, expr, matchUrl }) => new Transformer(content, filename, index, heuristic, patterns, expr, runtime, matchUrl).transform(),
51
55
  loaderExts: ['.js', '.ts'],
@@ -7,7 +7,7 @@ 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
9
  type InitRuntimeFunc = (funcName?: string, parentFunc?: string) => string | undefined;
10
- export declare class Transformer<RTCtxT = {}> {
10
+ export declare class Transformer {
11
11
  index: IndexTracker;
12
12
  heuristic: HeuristicFunc;
13
13
  content: string;
@@ -23,8 +23,8 @@ export declare class Transformer<RTCtxT = {}> {
23
23
  /** .start of the first statements in their respective parents, to put the runtime init before */
24
24
  realBodyStarts: Set<number>;
25
25
  /** will be passed to decide which runtime variable to use */
26
- runtimeCtx: RTCtxT;
27
- constructor(content: string, filename: string, index: IndexTracker, heuristic: HeuristicFunc, patterns: CodePattern[], catalogExpr: RuntimeExpr, rtConf: RuntimeConf<RTCtxT>, matchUrl: UrlMatcher, rtBaseVars?: string[]);
26
+ runtimeCtx: {};
27
+ constructor(content: string, filename: string, index: IndexTracker, heuristic: HeuristicFunc, patterns: CodePattern[], catalogExpr: RuntimeExpr, rtConf: RuntimeConf, matchUrl: UrlMatcher, rtBaseVars?: string[]);
28
28
  fullHeuristicDetails: (detailsBase: HeuristicDetailsBase) => HeuristicDetails;
29
29
  getHeuristicMessageType: (msg: Message) => HeuristicResultChecked;
30
30
  checkHeuristic: (msgStr: string, detailsBase: HeuristicDetailsBase) => [MessageType, Message] | [false, null];
@@ -71,17 +71,51 @@ export declare class Transformer<RTCtxT = {}> {
71
71
  visitBlockStatement: (node: Estree.BlockStatement) => Message[];
72
72
  visitReturnStatement: (node: Estree.ReturnStatement) => Message[];
73
73
  visitIfStatement: (node: Estree.IfStatement) => Message[];
74
+ visitWhileStatement: (node: Estree.WhileStatement) => Message[];
75
+ visitDoWhileStatement: (node: Estree.DoWhileStatement) => Message[];
76
+ visitLabeledStatement: (node: Estree.LabeledStatement) => Message[];
77
+ visitParenthesizedExpression: (node: Estree.ParenthesizedExpression) => Message[];
78
+ visitSwitchStatement: (node: Estree.SwitchStatement) => Message[];
79
+ visitSwitchCase: (node: Estree.SwitchCase) => Message[];
80
+ visitYieldExpression: (node: Estree.YieldExpression) => Message[];
74
81
  visitClassDeclaration: (node: Estree.ClassDeclaration) => Message[];
75
82
  checkHeuristicTemplateLiteral: (node: Estree.TemplateLiteral, heurDetails?: HeuristicDetailsBase) => HeuristicResultChecked;
76
83
  visitTemplateLiteralQuasis: (node: Estree.TemplateLiteral, msgTyp: MessageType) => [number, Message[]];
77
84
  visitTemplateLiteral: (node: Estree.TemplateLiteral, heurDetails?: HeuristicDetailsBase | boolean) => Message[];
78
85
  visitTaggedTemplateExpression: (node: Estree.TaggedTemplateExpression) => Message[];
79
- visitSwitchStatement: (node: Estree.SwitchStatement) => Message[];
80
86
  visitTryStatement: (node: Estree.TryStatement) => Message[];
81
87
  visitTSAsExpression: (node: Estree.TSAsExpression) => Message[];
82
88
  visitTSTypeAssertion: (node: Estree.TSTypeAssertion) => Message[];
83
89
  visitProgram: (node: Estree.Program) => Message[];
84
- visitWithCommentDirectives: (node: Estree.AnyNode, func: Function) => any;
90
+ visitWithCommentDirectives: (node: Estree.AnyNode, func: () => Message[]) => Message[];
91
+ visitEmptyStatement: () => Message[];
92
+ visitArrayPattern: () => Message[];
93
+ visitBreakStatement: () => Message[];
94
+ visitCatchClause: () => Message[];
95
+ visitClassBody: () => Message[];
96
+ visitClassExpression: () => Message[];
97
+ visitContinueStatement: () => Message[];
98
+ visitDebuggerStatement: () => Message[];
99
+ visitExportAllDeclaration: () => Message[];
100
+ visitExportSpecifier: () => Message[];
101
+ visitIdentifier: () => Message[];
102
+ visitImportAttribute: () => Message[];
103
+ visitImportDeclaration: () => Message[];
104
+ visitImportDefaultSpecifier: () => Message[];
105
+ visitImportExpression: () => Message[];
106
+ visitImportNamespaceSpecifier: () => Message[];
107
+ visitImportSpecifier: () => Message[];
108
+ visitMetaProperty: () => Message[];
109
+ visitMethodDefinition: () => Message[];
110
+ visitPrivateIdentifier: () => Message[];
111
+ visitPropertyDefinition: () => Message[];
112
+ visitStaticBlock: () => Message[];
113
+ visitSuper: () => Message[];
114
+ visitTemplateElement: () => Message[];
115
+ visitThisExpression: () => Message[];
116
+ visitThrowStatement: () => Message[];
117
+ visitUpdateExpression: () => Message[];
118
+ visitWithStatement: () => Message[];
85
119
  visit: (node: Estree.AnyNode) => Message[];
86
120
  finalize: (msgs: Message[], hmrHeaderIndex: number, additionalHeader?: string) => TransformOutput;
87
121
  transform: () => TransformOutput;
@@ -2,7 +2,7 @@
2
2
  import { tsPlugin } from '@sveltejs/acorn-typescript';
3
3
  import { Parser } from 'acorn';
4
4
  import MagicString from 'magic-string';
5
- import { runtimeVars, updateCommentDirectives, varNames, } from '../adapter-utils/index.js';
5
+ import { restoreCommentDirectives, runtimeVars, updateCommentDirectives, varNames, } from '../adapter-utils/index.js';
6
6
  import { defaultHeuristicFuncOnly, getKey, newMessage } from '../adapters.js';
7
7
  export const scriptParseOptions = {
8
8
  sourceType: 'module',
@@ -68,21 +68,23 @@ export class Transformer {
68
68
  this.heuristic = heuristic;
69
69
  this.patterns = patterns;
70
70
  this.content = content;
71
+ this.mstr = new MagicString(this.content);
71
72
  this.heuristciDetails.file = filename;
72
73
  this.matchUrl = matchUrl;
73
74
  const topLevelUseReactive = typeof rtConf.useReactive === 'boolean'
74
- ? () => rtConf.useReactive
75
- : {
75
+ ? rtConf.useReactive
76
+ : (rtConf.useReactive({
77
+ funcName: undefined,
76
78
  nested: false,
77
79
  file: filename,
78
80
  ctx: this.runtimeCtx,
79
- };
81
+ }) ?? false);
80
82
  const vars = {};
81
83
  // to enable the use of different runtime vars for different places, right now for svelte <script module>s
82
84
  for (const baseVar of rtBaseVars) {
83
85
  vars[baseVar] = {
84
- reactive: rtConf.reactive?.wrapUse && runtimeVars(rtConf.reactive.wrapUse, baseVar),
85
- plain: rtConf.plain?.wrapUse && runtimeVars(rtConf.plain.wrapUse, baseVar),
86
+ reactive: runtimeVars(rtConf.reactive.wrapUse, baseVar),
87
+ plain: runtimeVars(rtConf.plain.wrapUse, baseVar),
86
88
  };
87
89
  }
88
90
  this.currentRtVar = rtBaseVars[0];
@@ -93,7 +95,7 @@ export class Transformer {
93
95
  funcName: this.heuristciDetails.funcName ?? undefined,
94
96
  nested: this.heuristciDetails.funcIsNested ?? false,
95
97
  file: filename,
96
- ...this.runtimeCtx,
98
+ ctx: this.runtimeCtx,
97
99
  }) ?? topLevelUseReactive);
98
100
  const currentVars = vars[this.currentRtVar];
99
101
  return useReactive ? currentVars.reactive : currentVars.plain;
@@ -103,7 +105,7 @@ export class Transformer {
103
105
  funcName,
104
106
  nested: parentFunc != null,
105
107
  file: filename,
106
- ...this.runtimeCtx,
108
+ ctx: this.runtimeCtx,
107
109
  });
108
110
  if (initReactive == null) {
109
111
  return;
@@ -153,7 +155,7 @@ export class Transformer {
153
155
  return [heuRes, msg];
154
156
  };
155
157
  literalRepl(msgInfo) {
156
- let repl = `${this.vars().rtTrans}(${this.index.get(getKey(msgInfo.msgStr, msgInfo.context))})`;
158
+ const repl = `${this.vars().rtTrans}(${this.index.get(getKey(msgInfo.msgStr, msgInfo.context))})`;
157
159
  if (msgInfo.type !== 'url') {
158
160
  return repl;
159
161
  }
@@ -262,7 +264,7 @@ export class Transformer {
262
264
  continue;
263
265
  }
264
266
  // message, always required
265
- if (argVal === null) {
267
+ if (argVal == null) {
266
268
  return this.defaultVisitCallExpression(node);
267
269
  }
268
270
  if (argVal.type === 'Literal') {
@@ -533,6 +535,25 @@ export class Transformer {
533
535
  }
534
536
  return msgs;
535
537
  };
538
+ visitWhileStatement = (node) => [
539
+ ...this.visit(node.test),
540
+ ...this.visit(node.body),
541
+ ];
542
+ visitDoWhileStatement = (node) => [
543
+ ...this.visit(node.body),
544
+ ...this.visit(node.test),
545
+ ];
546
+ visitLabeledStatement = (node) => this.visit(node.body);
547
+ visitParenthesizedExpression = (node) => this.visit(node.expression);
548
+ visitSwitchStatement = (node) => node.cases.flatMap(this.visit);
549
+ visitSwitchCase = (node) => {
550
+ const msgs = node.consequent.flatMap(this.visit);
551
+ if (node.test) {
552
+ return [...this.visit(node.test), ...msgs];
553
+ }
554
+ return msgs;
555
+ };
556
+ visitYieldExpression = (node) => (node.argument ? this.visit(node.argument) : []);
536
557
  visitClassDeclaration = (node) => {
537
558
  const msgs = [];
538
559
  const prevDecl = this.heuristciDetails.declaring;
@@ -614,7 +635,7 @@ export class Transformer {
614
635
  }
615
636
  if (node.expressions.length) {
616
637
  begin += ', [';
617
- end = ']' + end;
638
+ end = `]${end}`;
618
639
  this.mstr.update(start0 - 1, end0 + 2, begin);
619
640
  this.mstr.update(node.end - 1, node.end, end);
620
641
  }
@@ -645,7 +666,6 @@ export class Transformer {
645
666
  this.heuristciDetails.call = prevCall;
646
667
  return msgs;
647
668
  };
648
- visitSwitchStatement = (node) => node.cases.flatMap(c => c.consequent.map(this.visit)).flat();
649
669
  visitTryStatement = (node) => {
650
670
  const msgs = this.visit(node.block);
651
671
  if (node.handler) {
@@ -676,11 +696,37 @@ export class Transformer {
676
696
  return [];
677
697
  }
678
698
  const res = func();
679
- for (const key in this.commentDirectives) {
680
- this.commentDirectives[key] = commentDirectives[key]; // restore
681
- }
699
+ restoreCommentDirectives(this.commentDirectives, commentDirectives);
682
700
  return res;
683
701
  };
702
+ visitEmptyStatement = () => [];
703
+ visitArrayPattern = () => [];
704
+ visitBreakStatement = () => [];
705
+ visitCatchClause = () => [];
706
+ visitClassBody = () => [];
707
+ visitClassExpression = () => [];
708
+ visitContinueStatement = () => [];
709
+ visitDebuggerStatement = () => [];
710
+ visitExportAllDeclaration = () => [];
711
+ visitExportSpecifier = () => [];
712
+ visitIdentifier = () => [];
713
+ visitImportAttribute = () => [];
714
+ visitImportDeclaration = () => [];
715
+ visitImportDefaultSpecifier = () => [];
716
+ visitImportExpression = () => [];
717
+ visitImportNamespaceSpecifier = () => [];
718
+ visitImportSpecifier = () => [];
719
+ visitMetaProperty = () => [];
720
+ visitMethodDefinition = () => []; // handled inside visitClassDeclaration
721
+ visitPrivateIdentifier = () => [];
722
+ visitPropertyDefinition = () => [];
723
+ visitStaticBlock = () => []; // handled inside visitClassDeclaration
724
+ visitSuper = () => [];
725
+ visitTemplateElement = () => [];
726
+ visitThisExpression = () => [];
727
+ visitThrowStatement = () => [];
728
+ visitUpdateExpression = () => [];
729
+ visitWithStatement = () => [];
684
730
  visit = (node) => this.visitWithCommentDirectives(node, () => {
685
731
  if (this.commentDirectives.forceType === false) {
686
732
  return [];
@@ -707,7 +753,6 @@ export class Transformer {
707
753
  transform = () => {
708
754
  const [ast, comments] = parseScript(this.content);
709
755
  this.comments = comments;
710
- this.mstr = new MagicString(this.content);
711
756
  return this.finalize(this.visit(ast), this.getRealBodyStart(ast.body) ?? 0);
712
757
  };
713
758
  }