wuchale 0.16.2 → 0.16.4
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.
|
@@ -15,9 +15,9 @@ const defaultArgs = {
|
|
|
15
15
|
generateLoadID: defaultGenerateLoadID,
|
|
16
16
|
writeFiles: {},
|
|
17
17
|
runtime: {
|
|
18
|
-
useReactive: () => ({
|
|
19
|
-
init: false,
|
|
20
|
-
use: false
|
|
18
|
+
useReactive: ({ nested }) => ({
|
|
19
|
+
init: nested ? null : false,
|
|
20
|
+
use: nested ? null : false,
|
|
21
21
|
}),
|
|
22
22
|
plain: {
|
|
23
23
|
importName: 'default',
|
|
@@ -61,8 +61,8 @@ export declare class Transformer {
|
|
|
61
61
|
visitVariableDeclaration: (node: Estree.VariableDeclaration) => Message[];
|
|
62
62
|
visitExportNamedDeclaration: (node: Estree.ExportNamedDeclaration) => Message[];
|
|
63
63
|
visitExportDefaultDeclaration: (node: Estree.ExportNamedDeclaration) => Message[];
|
|
64
|
-
getRealBodyStart: (nodes: (Estree.Statement | Estree.ModuleDeclaration)[]) => number;
|
|
65
|
-
visitFunctionBody: (node: Estree.BlockStatement | Estree.Expression, name: string | null) => Message[];
|
|
64
|
+
getRealBodyStart: (nodes: (Estree.Statement | Estree.ModuleDeclaration)[]) => number | undefined;
|
|
65
|
+
visitFunctionBody: (node: Estree.BlockStatement | Estree.Expression, name: string | null, end?: number) => Message[];
|
|
66
66
|
visitFunctionDeclaration: (node: Estree.FunctionDeclaration) => Message[];
|
|
67
67
|
visitArrowFunctionExpression: (node: Estree.ArrowFunctionExpression) => Message[];
|
|
68
68
|
visitFunctionExpression: (node: Estree.FunctionExpression) => Message[];
|
|
@@ -276,9 +276,8 @@ export class Transformer {
|
|
|
276
276
|
continue;
|
|
277
277
|
}
|
|
278
278
|
msgs.push(...this.visit(dec.id));
|
|
279
|
-
// store the name of the function after =
|
|
280
279
|
if (atTopLevelDefn) {
|
|
281
|
-
if (dec.init.type === 'ArrowFunctionExpression') {
|
|
280
|
+
if (dec.init.type === 'ArrowFunctionExpression' || dec.init.type === 'FunctionExpression') {
|
|
282
281
|
this.declaring = 'function';
|
|
283
282
|
}
|
|
284
283
|
else {
|
|
@@ -309,18 +308,37 @@ export class Transformer {
|
|
|
309
308
|
}
|
|
310
309
|
return node.start;
|
|
311
310
|
}
|
|
312
|
-
return nodes[0]
|
|
311
|
+
return nodes[0]?.start;
|
|
313
312
|
};
|
|
314
|
-
visitFunctionBody = (node, name) => {
|
|
313
|
+
visitFunctionBody = (node, name, end) => {
|
|
315
314
|
const prevFuncDef = this.currentFuncDef;
|
|
316
315
|
const prevFuncNested = this.currentFuncNested;
|
|
317
|
-
|
|
318
|
-
this.
|
|
319
|
-
this.currentFuncNested = isBlock && name != null && prevFuncDef != null;
|
|
316
|
+
this.currentFuncDef = name;
|
|
317
|
+
this.currentFuncNested = name != null && prevFuncDef != null;
|
|
320
318
|
const msgs = this.visit(node);
|
|
321
|
-
if (msgs.length > 0
|
|
319
|
+
if (msgs.length > 0) {
|
|
322
320
|
const initRuntime = this.initRuntime(this.filename, this.currentFuncDef, prevFuncDef, this.additionalState);
|
|
323
|
-
|
|
321
|
+
if (initRuntime) {
|
|
322
|
+
if (node.type === 'BlockStatement') {
|
|
323
|
+
this.mstr.prependLeft(this.getRealBodyStart(node.body) ?? node.start, initRuntime);
|
|
324
|
+
}
|
|
325
|
+
else {
|
|
326
|
+
// get real start if surrounded by parens
|
|
327
|
+
let start = node.start - 1;
|
|
328
|
+
for (; start > 0; start--) {
|
|
329
|
+
const char = this.content[start];
|
|
330
|
+
if (char === '(') {
|
|
331
|
+
break;
|
|
332
|
+
}
|
|
333
|
+
if (!/\s/.test(char)) {
|
|
334
|
+
start = node.start;
|
|
335
|
+
break;
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
this.mstr.prependLeft(start, `{${initRuntime}return `);
|
|
339
|
+
this.mstr.appendRight(end ?? node.end, '\n}');
|
|
340
|
+
}
|
|
341
|
+
}
|
|
324
342
|
}
|
|
325
343
|
this.currentFuncNested = prevFuncNested;
|
|
326
344
|
this.currentFuncDef = prevFuncDef;
|
|
@@ -333,7 +351,7 @@ export class Transformer {
|
|
|
333
351
|
this.declaring = declaring;
|
|
334
352
|
return msgs;
|
|
335
353
|
};
|
|
336
|
-
visitArrowFunctionExpression = (node) => this.visitFunctionBody(node.body, '');
|
|
354
|
+
visitArrowFunctionExpression = (node) => this.visitFunctionBody(node.body, '', node.end);
|
|
337
355
|
visitFunctionExpression = (node) => this.visitFunctionBody(node.body, '');
|
|
338
356
|
visitBlockStatement = (node) => node.body.map(this.visit).flat();
|
|
339
357
|
visitReturnStatement = (node) => node.argument ? this.visit(node.argument) : [];
|
|
@@ -353,7 +371,7 @@ export class Transformer {
|
|
|
353
371
|
if (body.type === 'MethodDefinition') {
|
|
354
372
|
msgs.push(...this.visit(body.key));
|
|
355
373
|
const methodName = this.content.slice(body.key.start, body.key.end);
|
|
356
|
-
msgs.push(...this.visitFunctionBody(body.value, `${node.id.name}.${methodName}`));
|
|
374
|
+
msgs.push(...this.visitFunctionBody(body.value.body, `${node.id.name}.${methodName}`));
|
|
357
375
|
}
|
|
358
376
|
else if (body.type === 'StaticBlock') {
|
|
359
377
|
const currentFuncDef = this.currentFuncDef;
|
|
@@ -461,6 +479,6 @@ export class Transformer {
|
|
|
461
479
|
const [ast, comments] = parseScript(this.content);
|
|
462
480
|
this.comments = comments;
|
|
463
481
|
this.mstr = new MagicString(this.content);
|
|
464
|
-
return this.finalize(this.visit(ast), this.getRealBodyStart(ast.body));
|
|
482
|
+
return this.finalize(this.visit(ast), this.getRealBodyStart(ast.body) ?? 0);
|
|
465
483
|
};
|
|
466
484
|
}
|
package/dist/adapters.js
CHANGED
|
@@ -1,7 +1,19 @@
|
|
|
1
|
+
const ignoreElements = ['style', 'path', 'code', 'pre'];
|
|
2
|
+
const ignoreAttribs = [['form', 'method']];
|
|
1
3
|
export function defaultHeuristic(msgStr, details) {
|
|
2
4
|
if (msgStr.search(/\p{L}/u) === -1) {
|
|
3
5
|
return false;
|
|
4
6
|
}
|
|
7
|
+
if (details.element && ignoreElements.includes(details.element)) {
|
|
8
|
+
return false;
|
|
9
|
+
}
|
|
10
|
+
if (details.scope === 'attribute') {
|
|
11
|
+
for (const [element, attrib] of ignoreAttribs) {
|
|
12
|
+
if (details.element === element && details.attribute === attrib) {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
5
17
|
if (details.scope === 'markup') {
|
|
6
18
|
return true;
|
|
7
19
|
}
|
|
@@ -16,7 +28,7 @@ export function defaultHeuristic(msgStr, details) {
|
|
|
16
28
|
if (details.declaring === 'expression' && !details.funcName) {
|
|
17
29
|
return false;
|
|
18
30
|
}
|
|
19
|
-
return !details.call?.startsWith('console.');
|
|
31
|
+
return !details.call?.startsWith('console.') && details.call !== 'fetch';
|
|
20
32
|
}
|
|
21
33
|
// only allow inside function definitions for script scope
|
|
22
34
|
export const defaultHeuristicFuncOnly = (msgStr, details) => {
|