@vobs/compiler 1.2.1 → 1.3.0
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/compile.cjs +349 -254
- package/dist/compile.cjs.map +1 -1
- package/dist/compile.js +90 -23
- package/dist/compile.js.map +1 -1
- package/dist/i18n-extractor.cjs +45 -16
- package/dist/i18n-extractor.cjs.map +1 -1
- package/dist/i18n-extractor.js +6 -5
- package/dist/i18n-extractor.js.map +1 -1
- package/dist/index.cjs +361 -260
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +99 -28
- package/dist/index.js.map +1 -1
- package/dist/plugin.cjs +18 -2
- package/dist/plugin.cjs.map +1 -1
- package/dist/plugin.d.cts +6 -0
- package/dist/plugin.d.ts +6 -0
- package/dist/plugin.js +0 -2
- package/dist/plugin.js.map +1 -1
- package/package.json +2 -2
- package/src/compile.test.ts +74 -0
- package/src/compile.ts +113 -17
- package/src/plugin.ts +6 -0
package/dist/i18n-extractor.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import ts from 'typescript';
|
|
2
|
-
|
|
3
1
|
var __defProp = Object.defineProperty;
|
|
4
2
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
|
|
4
|
+
// packages/compiler/src/i18n-extractor.ts
|
|
5
|
+
import ts from "typescript";
|
|
5
6
|
function createI18nExtractor(options = {}) {
|
|
6
7
|
const names = new Set(options.functions ?? ["t"]);
|
|
7
8
|
const keys = /* @__PURE__ */ new Set();
|
|
@@ -39,7 +40,7 @@ function readStaticKey(argument) {
|
|
|
39
40
|
return void 0;
|
|
40
41
|
}
|
|
41
42
|
__name(readStaticKey, "readStaticKey");
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
43
|
+
export {
|
|
44
|
+
createI18nExtractor
|
|
45
|
+
};
|
|
45
46
|
//# sourceMappingURL=i18n-extractor.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/i18n-extractor.ts"],"
|
|
1
|
+
{"version":3,"sources":["../src/i18n-extractor.ts"],"sourcesContent":["import ts from 'typescript'\nimport type { CompilerPlugin } from './plugin'\n\nexport interface I18nExtractorOptions {\n readonly functions?: readonly string[]\n readonly onKey?: (key: string, filename: string) => void\n}\n\nexport interface I18nExtractor {\n readonly plugin: CompilerPlugin\n getKeys(): readonly string[]\n reset(): void\n}\n\n/** Collects statically addressable translation keys without changing emitted code. */\nexport function createI18nExtractor(options: I18nExtractorOptions = {}): I18nExtractor {\n const names = new Set(options.functions ?? ['t'])\n const keys = new Set<string>()\n const plugin: CompilerPlugin = {\n name: 'i18n-extractor',\n analyze(program, context) {\n const visit = (node: ts.Node): void => {\n if (ts.isCallExpression(node) && isTranslationCall(node.expression, names)) {\n const key = readStaticKey(node.arguments[0])\n if (key) {\n keys.add(key)\n options.onKey?.(key, context.filename)\n }\n }\n ts.forEachChild(node, visit)\n }\n visit(program)\n }\n }\n return {\n plugin,\n getKeys: () => [...keys].sort(),\n reset: () => keys.clear()\n }\n}\n\nfunction isTranslationCall(expression: ts.LeftHandSideExpression, names: Set<string>): boolean {\n if (ts.isIdentifier(expression)) return names.has(expression.text)\n return ts.isPropertyAccessExpression(expression) && names.has(expression.name.text)\n}\n\nfunction readStaticKey(argument: ts.Expression | undefined): string | undefined {\n if (!argument) return undefined\n if (ts.isStringLiteral(argument) || ts.isNoSubstitutionTemplateLiteral(argument)) return argument.text\n return undefined\n}\n"],"mappings":";;;;AAAA,OAAO,QAAQ;AAeR,SAAS,oBAAoB,UAAgC,CAAC,GAAkB;AACrF,QAAM,QAAQ,IAAI,IAAI,QAAQ,aAAa,CAAC,GAAG,CAAC;AAChD,QAAM,OAAO,oBAAI,IAAY;AAC7B,QAAM,SAAyB;AAAA,IAC7B,MAAM;AAAA,IACN,QAAQ,SAAS,SAAS;AACxB,YAAM,QAAQ,wBAAC,SAAwB;AACrC,YAAI,GAAG,iBAAiB,IAAI,KAAK,kBAAkB,KAAK,YAAY,KAAK,GAAG;AAC1E,gBAAM,MAAM,cAAc,KAAK,UAAU,CAAC,CAAC;AAC3C,cAAI,KAAK;AACP,iBAAK,IAAI,GAAG;AACZ,oBAAQ,QAAQ,KAAK,QAAQ,QAAQ;AAAA,UACvC;AAAA,QACF;AACA,WAAG,aAAa,MAAM,KAAK;AAAA,MAC7B,GATc;AAUd,YAAM,OAAO;AAAA,IACf;AAAA,EACF;AACA,SAAO;AAAA,IACL;AAAA,IACA,SAAS,6BAAM,CAAC,GAAG,IAAI,EAAE,KAAK,GAArB;AAAA,IACT,OAAO,6BAAM,KAAK,MAAM,GAAjB;AAAA,EACT;AACF;AAxBgB;AA0BhB,SAAS,kBAAkB,YAAuC,OAA6B;AAC7F,MAAI,GAAG,aAAa,UAAU,EAAG,QAAO,MAAM,IAAI,WAAW,IAAI;AACjE,SAAO,GAAG,2BAA2B,UAAU,KAAK,MAAM,IAAI,WAAW,KAAK,IAAI;AACpF;AAHS;AAKT,SAAS,cAAc,UAAyD;AAC9E,MAAI,CAAC,SAAU,QAAO;AACtB,MAAI,GAAG,gBAAgB,QAAQ,KAAK,GAAG,gCAAgC,QAAQ,EAAG,QAAO,SAAS;AAClG,SAAO;AACT;AAJS;","names":[]}
|