wuchale 0.18.3 → 0.18.5

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.
@@ -3,7 +3,7 @@ import { Transformer } from "./transformer.js";
3
3
  export { Transformer };
4
4
  export { parseScript, scriptParseOptions, scriptParseOptionsWithComments } from './transformer.js';
5
5
  export declare const pluralPattern: CodePattern;
6
- type LoadersAvailable = 'bundle' | 'server' | 'vite';
6
+ type LoadersAvailable = 'server' | 'vite';
7
7
  export declare function getDefaultLoaderPath(loader: LoaderChoice<LoadersAvailable>, bundle: boolean): string | {
8
8
  client: string;
9
9
  server: string;
@@ -79,6 +79,12 @@ export declare class Transformer {
79
79
  visitTemplateLiteralQuasis: (node: Estree.TemplateLiteral, msgTyp: MessageType) => [number, Message[]];
80
80
  visitTemplateLiteral: (node: Estree.TemplateLiteral, heurDetails?: HeuristicDetailsBase | boolean) => Message[];
81
81
  visitTaggedTemplateExpression: (node: Estree.TaggedTemplateExpression) => Message[];
82
+ visitTSAsExpression: (node: {
83
+ expression: Estree.AnyNode;
84
+ }) => Message[];
85
+ visitTSTypeAssertion: (node: {
86
+ expression: Estree.AnyNode;
87
+ }) => Message[];
82
88
  visitProgram: (node: Estree.Program) => Message[];
83
89
  visitWithCommentDirectives: (node: Estree.AnyNode, func: Function) => any;
84
90
  visit: (node: Estree.AnyNode) => Message[];
@@ -580,6 +580,8 @@ export class Transformer {
580
580
  this.currentCall = prevCall;
581
581
  return msgs;
582
582
  };
583
+ visitTSAsExpression = (node) => this.visit(node.expression);
584
+ visitTSTypeAssertion = (node) => this.visit(node.expression);
583
585
  visitProgram = (node) => {
584
586
  this.insideProgram = true;
585
587
  const msgs = this.visitStatementsNSaveRealBodyStart(node.body);
@@ -123,6 +123,8 @@ export type Adapter = AdapterPassThruOpts & {
123
123
  loaderExts: string[];
124
124
  /** default loaders to copy, `null` means custom */
125
125
  defaultLoaderPath: LoaderPath | string | null;
126
+ /** names to import from loaders, should avoid collision with code variables */
127
+ getRuntimeVars?: Partial<CatalogExpr>;
126
128
  };
127
129
  export type CodePattern = {
128
130
  name: string;
package/dist/handler.js CHANGED
@@ -23,13 +23,9 @@ export const urlPatternFlag = 'url-pattern';
23
23
  const urlExtractedFlag = 'url-extracted';
24
24
  const loaderImportGetRuntime = 'getRuntime';
25
25
  const loaderImportGetRuntimeRx = 'getRuntimeRx';
26
- const getFuncPlain = '_w_load_';
27
- const getFuncReactive = getFuncPlain + 'rx_';
26
+ const getFuncPlainDefault = '_w_load_';
27
+ const getFuncReactiveDefault = getFuncPlainDefault + 'rx_';
28
28
  const bundleCatalogsVarName = '_w_catalogs_';
29
- const bundledCatalogExpr = {
30
- plain: `${getFuncPlain}(${bundleCatalogsVarName})`,
31
- reactive: `${getFuncReactive}(${bundleCatalogsVarName})`,
32
- };
33
29
  const objKeyLocale = (locale) => locale.includes('-') ? `'${locale}'` : locale;
34
30
  export async function loadPOFile(filename) {
35
31
  return new Promise((res, rej) => {
@@ -664,13 +660,14 @@ export class AdapterHandler {
664
660
  ['MIME-Version', '1.0'],
665
661
  ['Content-Type', 'text/plain; charset=utf-8'],
666
662
  ['Content-Transfer-Encoding', '8bit'],
667
- ['PO-Revision-Date', new Date().toISOString()],
668
663
  ];
669
664
  for (const [key, val] of updateHeaders) {
670
665
  fullHead[key] = val;
671
666
  }
667
+ const now = new Date().toISOString();
672
668
  const defaultHeaders = [
673
- ['POT-Creation-Date', new Date().toISOString()],
669
+ ['POT-Creation-Date', now],
670
+ ['PO-Revision-Date', now],
674
671
  ];
675
672
  for (const [key, val] of defaultHeaders) {
676
673
  if (!fullHead[key]) {
@@ -697,15 +694,20 @@ export class AdapterHandler {
697
694
  }
698
695
  `;
699
696
  };
697
+ #getRuntimeVars = () => ({
698
+ plain: this.#adapter.getRuntimeVars?.plain ?? getFuncPlainDefault,
699
+ reactive: this.#adapter.getRuntimeVars?.reactive ?? getFuncReactiveDefault,
700
+ });
700
701
  #prepareHeader = (filename, loadID, hmrData, forServer) => {
701
702
  let head = [];
702
- let getFuncImportPlain = getFuncPlain;
703
- let getFuncImportReactive = getFuncReactive;
703
+ const getRuntimeVars = this.#getRuntimeVars();
704
+ let getRuntimePlain = getRuntimeVars.plain;
705
+ let getRuntimeReactive = getRuntimeVars.reactive;
704
706
  if (hmrData != null) {
705
707
  head.push(`const ${varNames.hmrUpdate} = ${JSON.stringify(hmrData)}`);
706
- getFuncImportPlain += 'hmr_';
707
- getFuncImportReactive += 'hmr_';
708
- head.push(this.#hmrUpdateFunc(getFuncPlain, getFuncImportPlain), this.#hmrUpdateFunc(getFuncReactive, getFuncImportReactive));
708
+ getRuntimePlain += 'hmr_';
709
+ getRuntimeReactive += 'hmr_';
710
+ head.push(this.#hmrUpdateFunc(getRuntimeVars.plain, getRuntimePlain), this.#hmrUpdateFunc(getRuntimeVars.reactive, getRuntimeReactive));
709
711
  }
710
712
  let loaderRelTo = filename;
711
713
  if (this.#adapter.outDir) {
@@ -713,8 +715,8 @@ export class AdapterHandler {
713
715
  }
714
716
  const loaderPath = this.#getImportPath(forServer ? this.loaderPath.server : this.loaderPath.client, loaderRelTo);
715
717
  const importsFuncs = [
716
- `${loaderImportGetRuntime} as ${getFuncImportPlain}`,
717
- `${loaderImportGetRuntimeRx} as ${getFuncImportReactive}`,
718
+ `${loaderImportGetRuntime} as ${getRuntimePlain}`,
719
+ `${loaderImportGetRuntimeRx} as ${getRuntimeReactive}`,
718
720
  ];
719
721
  head = [
720
722
  `import {${importsFuncs.join(', ')}} from "${loaderPath}"`,
@@ -738,12 +740,16 @@ export class AdapterHandler {
738
740
  ].join('\n');
739
741
  };
740
742
  #prepareRuntimeExpr = (loadID) => {
743
+ const importLoaderVars = this.#getRuntimeVars();
741
744
  if (this.#adapter.bundleLoad) {
742
- return bundledCatalogExpr;
745
+ return {
746
+ plain: `${importLoaderVars.plain}(${bundleCatalogsVarName})`,
747
+ reactive: `${importLoaderVars.reactive}(${bundleCatalogsVarName})`,
748
+ };
743
749
  }
744
750
  return {
745
- plain: `${getFuncPlain}('${loadID}')`,
746
- reactive: `${getFuncReactive}('${loadID}')`,
751
+ plain: `${importLoaderVars.plain}('${loadID}')`,
752
+ reactive: `${importLoaderVars.reactive}('${loadID}')`,
747
753
  };
748
754
  };
749
755
  handleMessages = async (loc, msgs, filename) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wuchale",
3
- "version": "0.18.3",
3
+ "version": "0.18.5",
4
4
  "description": "Protobuf-like i18n from plain code",
5
5
  "scripts": {
6
6
  "dev": "tsc --watch",