wuchale 0.15.2 → 0.15.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.
- package/dist/adapter-utils/mixed-visitor.js +2 -2
- package/dist/adapter-vanilla/index.js +1 -1
- package/dist/adapter-vanilla/transformer.d.ts +2 -2
- package/dist/adapter-vanilla/transformer.js +5 -14
- package/dist/adapters.d.ts +3 -4
- package/dist/handler.d.ts +5 -4
- package/dist/handler.js +44 -42
- package/package.json +1 -1
|
@@ -141,10 +141,10 @@ export class MixedVisitor {
|
|
|
141
141
|
else {
|
|
142
142
|
return msgs;
|
|
143
143
|
}
|
|
144
|
-
if (childrenNestedRanges.length) {
|
|
144
|
+
if (props.scope === 'markup' && iArg > 0 || childrenNestedRanges.length > 0) {
|
|
145
145
|
this.wrapNested(msgInfo, iArg > 0, childrenNestedRanges, lastChildEnd);
|
|
146
146
|
}
|
|
147
|
-
else
|
|
147
|
+
else {
|
|
148
148
|
// no need for component use
|
|
149
149
|
let begin = '{';
|
|
150
150
|
let end = ')}';
|
|
@@ -30,7 +30,7 @@ const resolveLoaderPath = (name) => new URL(`../../src/adapter-vanilla/loaders/$
|
|
|
30
30
|
export const adapter = (args = defaultArgs) => {
|
|
31
31
|
const { heuristic, pluralsFunc, runtime, ...rest } = deepMergeObjects(args, defaultArgs);
|
|
32
32
|
return {
|
|
33
|
-
transform: ({ content, filename, index,
|
|
33
|
+
transform: ({ content, filename, index, expr }) => new Transformer(content, filename, index, heuristic, pluralsFunc, expr, runtime).transform(),
|
|
34
34
|
loaderExts: ['.js', '.ts'],
|
|
35
35
|
defaultLoaders: async () => {
|
|
36
36
|
if (rest.bundleLoad) {
|
|
@@ -71,7 +71,7 @@ export declare class Transformer {
|
|
|
71
71
|
visitProgram: (node: Estree.Program) => Message[];
|
|
72
72
|
processCommentDirectives: (data: string) => CommentDirectives;
|
|
73
73
|
visit: (node: Estree.AnyNode) => Message[];
|
|
74
|
-
finalize: (msgs: Message[], hmrHeaderIndex: number) => TransformOutput;
|
|
75
|
-
transform: (
|
|
74
|
+
finalize: (msgs: Message[], hmrHeaderIndex: number, additionalHeader?: string) => TransformOutput;
|
|
75
|
+
transform: () => TransformOutput;
|
|
76
76
|
}
|
|
77
77
|
export {};
|
|
@@ -427,29 +427,20 @@ export class Transformer {
|
|
|
427
427
|
this.commentDirectives = commentDirectives; // restore
|
|
428
428
|
return msgs;
|
|
429
429
|
};
|
|
430
|
-
finalize = (msgs, hmrHeaderIndex) => ({
|
|
430
|
+
finalize = (msgs, hmrHeaderIndex, additionalHeader = '') => ({
|
|
431
431
|
msgs,
|
|
432
|
-
output:
|
|
433
|
-
|
|
434
|
-
return {};
|
|
435
|
-
}
|
|
436
|
-
if (hmrData) {
|
|
437
|
-
this.mstr.prependRight(hmrHeaderIndex, `\nconst ${varNames.hmrUpdate} = ${JSON.stringify(hmrData)}\n`);
|
|
438
|
-
}
|
|
432
|
+
output: header => {
|
|
433
|
+
this.mstr.prependRight(hmrHeaderIndex, `\n${header}\n${additionalHeader}\n`);
|
|
439
434
|
return {
|
|
440
435
|
code: this.mstr.toString(),
|
|
441
436
|
map: this.mstr.generateMap(),
|
|
442
437
|
};
|
|
443
438
|
}
|
|
444
439
|
});
|
|
445
|
-
transform = (
|
|
440
|
+
transform = () => {
|
|
446
441
|
const [ast, comments] = parseScript(this.content);
|
|
447
442
|
this.comments = comments;
|
|
448
443
|
this.mstr = new MagicString(this.content);
|
|
449
|
-
|
|
450
|
-
if (msgs.length) {
|
|
451
|
-
this.mstr.appendRight(this.getRealBodyStart(ast.body), headerHead + '\n');
|
|
452
|
-
}
|
|
453
|
-
return this.finalize(msgs, 0);
|
|
444
|
+
return this.finalize(this.visit(ast), this.getRealBodyStart(ast.body));
|
|
454
445
|
};
|
|
455
446
|
}
|
package/dist/adapters.d.ts
CHANGED
|
@@ -44,19 +44,18 @@ export type CatalogExpr = {
|
|
|
44
44
|
};
|
|
45
45
|
export type TransformHeader = {
|
|
46
46
|
head: string;
|
|
47
|
-
expr: CatalogExpr;
|
|
48
47
|
};
|
|
49
48
|
type TransformCtx = {
|
|
50
49
|
content: string;
|
|
51
50
|
filename: string;
|
|
52
51
|
index: IndexTracker;
|
|
53
|
-
|
|
52
|
+
expr: CatalogExpr;
|
|
54
53
|
};
|
|
55
54
|
export type HMRData = {
|
|
56
55
|
version: number;
|
|
57
56
|
data: Record<string, [number, CompiledElement][]>;
|
|
58
57
|
};
|
|
59
|
-
export type TransformOutputFunc = (
|
|
58
|
+
export type TransformOutputFunc = (header: string) => {
|
|
60
59
|
code?: string;
|
|
61
60
|
map?: any;
|
|
62
61
|
};
|
|
@@ -64,7 +63,7 @@ export type TransformOutput = {
|
|
|
64
63
|
output: TransformOutputFunc;
|
|
65
64
|
msgs: Message[];
|
|
66
65
|
};
|
|
67
|
-
export type TransformFunc = (
|
|
66
|
+
export type TransformFunc = (expr: TransformCtx) => TransformOutput;
|
|
68
67
|
export type WrapFunc = (expr: string) => string;
|
|
69
68
|
export type UseReactiveFunc = (details: {
|
|
70
69
|
funcName?: string;
|
package/dist/handler.d.ts
CHANGED
|
@@ -38,6 +38,10 @@ type GranularState = {
|
|
|
38
38
|
type LoaderPathEmpty = {
|
|
39
39
|
[K in keyof LoaderPath]: boolean;
|
|
40
40
|
};
|
|
41
|
+
type TransformOutputCode = {
|
|
42
|
+
code?: string;
|
|
43
|
+
map?: any;
|
|
44
|
+
};
|
|
41
45
|
export declare class AdapterHandler {
|
|
42
46
|
#private;
|
|
43
47
|
key: string;
|
|
@@ -73,9 +77,6 @@ export declare class AdapterHandler {
|
|
|
73
77
|
ignore: string[];
|
|
74
78
|
}];
|
|
75
79
|
savePoAndCompile: (loc: string) => Promise<void>;
|
|
76
|
-
transform: (content: string, filename: string, hmrVersion?: number, ssr?: boolean) => Promise<
|
|
77
|
-
code?: string;
|
|
78
|
-
map?: any;
|
|
79
|
-
}>;
|
|
80
|
+
transform: (content: string, filename: string, hmrVersion?: number, ssr?: boolean) => Promise<TransformOutputCode>;
|
|
80
81
|
}
|
|
81
82
|
export {};
|
package/dist/handler.js
CHANGED
|
@@ -15,6 +15,13 @@ const defaultPluralRule = {
|
|
|
15
15
|
nplurals: 2,
|
|
16
16
|
plural: 'n == 1 ? 0 : 1',
|
|
17
17
|
};
|
|
18
|
+
const getFuncPlain = '_w_load_';
|
|
19
|
+
const getFuncReactive = getFuncPlain + 'rx_';
|
|
20
|
+
const catalogsVarName = '_w_catalogs_';
|
|
21
|
+
const bundledCatalogExpr = {
|
|
22
|
+
plain: `${getFuncPlain}(${catalogsVarName})`,
|
|
23
|
+
reactive: `${getFuncReactive}(${catalogsVarName})`,
|
|
24
|
+
};
|
|
18
25
|
const objKeyLocale = (locale) => locale.includes('-') ? `'${locale}'` : locale;
|
|
19
26
|
export async function loadPOFile(filename) {
|
|
20
27
|
return new Promise((res, rej) => {
|
|
@@ -467,7 +474,7 @@ export class AdapterHandler {
|
|
|
467
474
|
}
|
|
468
475
|
`;
|
|
469
476
|
};
|
|
470
|
-
#prepareHeader = (filename, loadID,
|
|
477
|
+
#prepareHeader = (filename, loadID, hmrData, ssr) => {
|
|
471
478
|
let loaderRelTo = filename;
|
|
472
479
|
if (this.#adapter.writeFiles.transformed) {
|
|
473
480
|
loaderRelTo = resolve(this.outDir + '/' + filename);
|
|
@@ -478,36 +485,29 @@ export class AdapterHandler {
|
|
|
478
485
|
}
|
|
479
486
|
const importsFuncs = [];
|
|
480
487
|
const runtimeConf = this.#adapter.runtime;
|
|
481
|
-
let getFuncPlain = '_w_load_';
|
|
482
|
-
let getFuncReactive = getFuncPlain + 'rx_';
|
|
483
488
|
let head = [];
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
+
let getFuncImportPlain = getFuncPlain;
|
|
490
|
+
let getFuncImportReactive = getFuncReactive;
|
|
491
|
+
if (hmrData != null) {
|
|
492
|
+
head.push(`const ${varNames.hmrUpdate} = ${JSON.stringify(hmrData)}`);
|
|
493
|
+
getFuncImportPlain += 'hmr_';
|
|
494
|
+
getFuncImportReactive += 'hmr_';
|
|
489
495
|
if (runtimeConf.plain?.importName) {
|
|
490
|
-
head.push(this.#hmrUpdateFunc(
|
|
496
|
+
head.push(this.#hmrUpdateFunc(getFuncPlain, getFuncImportPlain));
|
|
491
497
|
}
|
|
492
498
|
if (runtimeConf.reactive?.importName) {
|
|
493
|
-
head.push(this.#hmrUpdateFunc(
|
|
499
|
+
head.push(this.#hmrUpdateFunc(getFuncReactive, getFuncImportReactive));
|
|
494
500
|
}
|
|
495
501
|
}
|
|
496
|
-
this.#putImportSpec(runtimeConf.plain?.importName,
|
|
497
|
-
this.#putImportSpec(runtimeConf.reactive?.importName,
|
|
502
|
+
this.#putImportSpec(runtimeConf.plain?.importName, getFuncImportPlain, importsFuncs);
|
|
503
|
+
this.#putImportSpec(runtimeConf.reactive?.importName, getFuncImportReactive, importsFuncs);
|
|
498
504
|
head = [
|
|
499
505
|
`import ${varNames.rtWrap} from 'wuchale/runtime'`,
|
|
500
506
|
`import ${importsFuncs.join(',')} from "${loaderPath}"`,
|
|
501
507
|
...head,
|
|
502
508
|
];
|
|
503
509
|
if (!this.#adapter.bundleLoad) {
|
|
504
|
-
return
|
|
505
|
-
head: head.join('\n'),
|
|
506
|
-
expr: {
|
|
507
|
-
plain: `${getFuncPlain}('${loadID}')`,
|
|
508
|
-
reactive: `${getFuncReactive}('${loadID}')`,
|
|
509
|
-
}
|
|
510
|
-
};
|
|
510
|
+
return head.join('\n');
|
|
511
511
|
}
|
|
512
512
|
const imports = [];
|
|
513
513
|
const objElms = [];
|
|
@@ -516,17 +516,19 @@ export class AdapterHandler {
|
|
|
516
516
|
imports.push(`import * as ${locKW} from '${this.virtModEvent(loc, loadID)}'`);
|
|
517
517
|
objElms.push(`${objKeyLocale(loc)}: ${locKW}`);
|
|
518
518
|
}
|
|
519
|
-
|
|
519
|
+
return [
|
|
520
|
+
...imports,
|
|
521
|
+
...head,
|
|
522
|
+
`const ${catalogsVarName} = {${objElms.join(',')}}`
|
|
523
|
+
].join('\n');
|
|
524
|
+
};
|
|
525
|
+
#prepareRuntimeExpr = (loadID) => {
|
|
526
|
+
if (this.#adapter.bundleLoad) {
|
|
527
|
+
return bundledCatalogExpr;
|
|
528
|
+
}
|
|
520
529
|
return {
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
...head,
|
|
524
|
-
`const ${catalogsVarName} = {${objElms.join(',')}}`
|
|
525
|
-
].join('\n'),
|
|
526
|
-
expr: {
|
|
527
|
-
plain: `${getFuncPlain}(${catalogsVarName})`,
|
|
528
|
-
reactive: `${getFuncReactive}(${catalogsVarName})`,
|
|
529
|
-
}
|
|
530
|
+
plain: `${getFuncPlain}('${loadID}')`,
|
|
531
|
+
reactive: `${getFuncReactive}('${loadID}')`,
|
|
530
532
|
};
|
|
531
533
|
};
|
|
532
534
|
transform = async (content, filename, hmrVersion = -1, ssr = false) => {
|
|
@@ -543,7 +545,7 @@ export class AdapterHandler {
|
|
|
543
545
|
content,
|
|
544
546
|
filename,
|
|
545
547
|
index: indexTracker,
|
|
546
|
-
|
|
548
|
+
expr: this.#prepareRuntimeExpr(loadID),
|
|
547
549
|
});
|
|
548
550
|
const hmrKeys = {};
|
|
549
551
|
for (const loc of this.#locales) {
|
|
@@ -632,21 +634,21 @@ export class AdapterHandler {
|
|
|
632
634
|
this.#log.log(`Gemini translate ${color.cyan(untranslated.length)} items to ${color.cyan(getLanguageName(loc))} ${opType}`);
|
|
633
635
|
await this.#geminiQueue[loc].running;
|
|
634
636
|
}
|
|
635
|
-
let
|
|
636
|
-
if (
|
|
637
|
-
hmrData =
|
|
638
|
-
|
|
639
|
-
hmrData
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
637
|
+
let output = {};
|
|
638
|
+
if (msgs.length) {
|
|
639
|
+
let hmrData = null;
|
|
640
|
+
if (hmrVersion >= 0) {
|
|
641
|
+
hmrData = { version: hmrVersion, data: {} };
|
|
642
|
+
for (const loc of this.#locales) {
|
|
643
|
+
hmrData.data[loc] = hmrKeys[loc]?.map(key => {
|
|
644
|
+
const index = indexTracker.get(key);
|
|
645
|
+
return [index, compiled[loc].items[index]];
|
|
646
|
+
});
|
|
647
|
+
}
|
|
643
648
|
}
|
|
649
|
+
output = result.output(this.#prepareHeader(filename, loadID, hmrData, ssr));
|
|
644
650
|
}
|
|
645
|
-
const output = result.output(hmrData);
|
|
646
651
|
await this.writeTransformed(filename, output.code ?? content);
|
|
647
|
-
if (!msgs.length) {
|
|
648
|
-
return {};
|
|
649
|
-
}
|
|
650
652
|
return output;
|
|
651
653
|
};
|
|
652
654
|
}
|