@generaltranslation/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.
Files changed (55) hide show
  1. package/dist/config.d.ts +23 -0
  2. package/dist/config.d.ts.map +1 -1
  3. package/dist/index.d.ts.map +1 -1
  4. package/dist/index.js +26 -4
  5. package/dist/index.js.map +1 -1
  6. package/dist/passes/jsxInsertionPass.d.ts +11 -0
  7. package/dist/passes/jsxInsertionPass.d.ts.map +1 -0
  8. package/dist/passes/jsxInsertionPass.js +35 -0
  9. package/dist/passes/jsxInsertionPass.js.map +1 -0
  10. package/dist/processing/collection/processCallExpression.js +4 -0
  11. package/dist/processing/collection/processCallExpression.js.map +1 -1
  12. package/dist/processing/jsx-insertion/processCallExpression.d.ts +13 -0
  13. package/dist/processing/jsx-insertion/processCallExpression.d.ts.map +1 -0
  14. package/dist/processing/jsx-insertion/processCallExpression.js +424 -0
  15. package/dist/processing/jsx-insertion/processCallExpression.js.map +1 -0
  16. package/dist/processing/jsx-insertion/processImportDeclaration.d.ts +20 -0
  17. package/dist/processing/jsx-insertion/processImportDeclaration.d.ts.map +1 -0
  18. package/dist/processing/jsx-insertion/processImportDeclaration.js +87 -0
  19. package/dist/processing/jsx-insertion/processImportDeclaration.js.map +1 -0
  20. package/dist/processing/jsx-insertion/processProgram.d.ts +18 -0
  21. package/dist/processing/jsx-insertion/processProgram.d.ts.map +1 -0
  22. package/dist/processing/jsx-insertion/processProgram.js +69 -0
  23. package/dist/processing/jsx-insertion/processProgram.js.map +1 -0
  24. package/dist/state/types.d.ts +3 -0
  25. package/dist/state/types.d.ts.map +1 -1
  26. package/dist/state/utils/initializeState.d.ts.map +1 -1
  27. package/dist/state/utils/initializeState.js +19 -13
  28. package/dist/state/utils/initializeState.js.map +1 -1
  29. package/dist/transform/jsx-children/constructJsxChildren.d.ts.map +1 -1
  30. package/dist/transform/jsx-children/constructJsxChildren.js +11 -1
  31. package/dist/transform/jsx-children/constructJsxChildren.js.map +1 -1
  32. package/dist/transform/jsx-insertion/injectJsxInsertionImport.d.ts +8 -0
  33. package/dist/transform/jsx-insertion/injectJsxInsertionImport.d.ts.map +1 -0
  34. package/dist/transform/jsx-insertion/injectJsxInsertionImport.js +52 -0
  35. package/dist/transform/jsx-insertion/injectJsxInsertionImport.js.map +1 -0
  36. package/dist/transform/validation/validateTranslationComponentArgs.d.ts.map +1 -1
  37. package/dist/transform/validation/validateTranslationComponentArgs.js +1 -0
  38. package/dist/transform/validation/validateTranslationComponentArgs.js.map +1 -1
  39. package/dist/utils/constants/gt/constants.d.ts +21 -1
  40. package/dist/utils/constants/gt/constants.d.ts.map +1 -1
  41. package/dist/utils/constants/gt/constants.js +21 -1
  42. package/dist/utils/constants/gt/constants.js.map +1 -1
  43. package/dist/utils/constants/gt/helpers.d.ts +4 -0
  44. package/dist/utils/constants/gt/helpers.d.ts.map +1 -1
  45. package/dist/utils/constants/gt/helpers.js +17 -3
  46. package/dist/utils/constants/gt/helpers.js.map +1 -1
  47. package/dist/utils/constants/resolveIdentifier/isGTComponent.d.ts +17 -0
  48. package/dist/utils/constants/resolveIdentifier/isGTComponent.d.ts.map +1 -0
  49. package/dist/utils/constants/resolveIdentifier/isGTComponent.js +92 -0
  50. package/dist/utils/constants/resolveIdentifier/isGTComponent.js.map +1 -0
  51. package/dist/utils/constants/resolveIdentifier/isReactJsxFunction.d.ts +10 -0
  52. package/dist/utils/constants/resolveIdentifier/isReactJsxFunction.d.ts.map +1 -0
  53. package/dist/utils/constants/resolveIdentifier/isReactJsxFunction.js +93 -0
  54. package/dist/utils/constants/resolveIdentifier/isReactJsxFunction.js.map +1 -0
  55. package/package.json +2 -2
@@ -0,0 +1,92 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.resolveFirstArgGTName = resolveFirstArgGTName;
37
+ exports.isUserTranslationComponent = isUserTranslationComponent;
38
+ exports.isUserVariableComponent = isUserVariableComponent;
39
+ exports.isGTBranchComponent = isGTBranchComponent;
40
+ exports.isGTDeriveComponent = isGTDeriveComponent;
41
+ const t = __importStar(require("@babel/types"));
42
+ const helpers_1 = require("../gt/helpers");
43
+ const constants_1 = require("../gt/constants");
44
+ /**
45
+ * Given a NodePath to the first argument of a jsx() call (the component identifier),
46
+ * resolve it to its original imported name from a GT source.
47
+ * Returns null if the identifier is not imported from a GT library.
48
+ */
49
+ function resolveFirstArgGTName(firstArgPath) {
50
+ if (!firstArgPath.isIdentifier())
51
+ return null;
52
+ const binding = firstArgPath.scope.getBinding(firstArgPath.node.name);
53
+ if (!binding || !binding.path.isImportSpecifier())
54
+ return null;
55
+ const imported = binding.path.node.imported;
56
+ const originalName = t.isIdentifier(imported)
57
+ ? imported.name
58
+ : imported.value;
59
+ const parentPath = binding.path.parentPath;
60
+ if (!(parentPath === null || parentPath === void 0 ? void 0 : parentPath.isImportDeclaration()))
61
+ return null;
62
+ const importSource = parentPath.node.source.value;
63
+ if (!(0, helpers_1.isGTImportSource)(importSource))
64
+ return null;
65
+ return originalName;
66
+ }
67
+ /** Check if first arg of jsx call is user-written T (not GtInternalTranslateJsx) */
68
+ function isUserTranslationComponent(firstArgPath) {
69
+ return resolveFirstArgGTName(firstArgPath) === constants_1.GT_COMPONENT_TYPES.T;
70
+ }
71
+ /** Check if first arg is user-written Var, Num, Currency, DateTime, or RelativeTime */
72
+ function isUserVariableComponent(firstArgPath) {
73
+ const name = resolveFirstArgGTName(firstArgPath);
74
+ return [
75
+ constants_1.GT_COMPONENT_TYPES.Var,
76
+ constants_1.GT_COMPONENT_TYPES.Num,
77
+ constants_1.GT_COMPONENT_TYPES.Currency,
78
+ constants_1.GT_COMPONENT_TYPES.DateTime,
79
+ constants_1.GT_COMPONENT_TYPES.RelativeTime,
80
+ ].includes((name !== null && name !== void 0 ? name : ''));
81
+ }
82
+ /** Check if first arg is Branch or Plural */
83
+ function isGTBranchComponent(firstArgPath) {
84
+ const name = resolveFirstArgGTName(firstArgPath);
85
+ return (name === constants_1.GT_COMPONENT_TYPES.Branch || name === constants_1.GT_COMPONENT_TYPES.Plural);
86
+ }
87
+ /** Check if first arg is Derive or Static */
88
+ function isGTDeriveComponent(firstArgPath) {
89
+ const name = resolveFirstArgGTName(firstArgPath);
90
+ return (name === constants_1.GT_COMPONENT_TYPES.Derive || name === constants_1.GT_COMPONENT_TYPES.Static);
91
+ }
92
+ //# sourceMappingURL=isGTComponent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"isGTComponent.js","sourceRoot":"","sources":["../../../../src/utils/constants/resolveIdentifier/isGTComponent.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;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B,CAAC,YAAY,CAAC,CAAC;IACjD,OAAO;QACL,8BAAkB,CAAC,GAAG;QACtB,8BAAkB,CAAC,GAAG;QACtB,8BAAkB,CAAC,QAAQ;QAC3B,8BAAkB,CAAC,QAAQ;QAC3B,8BAAkB,CAAC,YAAY;KAChC,CAAC,QAAQ,CAAC,CAAC,IAAI,aAAJ,IAAI,cAAJ,IAAI,GAAI,EAAE,CAAuB,CAAC,CAAC;AACjD,CAAC;AAED,6CAA6C;AAC7C,SAAgB,mBAAmB,CACjC,YAAoC;IAEpC,MAAM,IAAI,GAAG,qBAAqB,CAAC,YAAY,CAAC,CAAC;IACjD,OAAO,CACL,IAAI,KAAK,8BAAkB,CAAC,MAAM,IAAI,IAAI,KAAK,8BAAkB,CAAC,MAAM,CACzE,CAAC;AACJ,CAAC;AAED,6CAA6C;AAC7C,SAAgB,mBAAmB,CACjC,YAAoC;IAEpC,MAAM,IAAI,GAAG,qBAAqB,CAAC,YAAY,CAAC,CAAC;IACjD,OAAO,CACL,IAAI,KAAK,8BAAkB,CAAC,MAAM,IAAI,IAAI,KAAK,8BAAkB,CAAC,MAAM,CACzE,CAAC;AACJ,CAAC"}
@@ -0,0 +1,10 @@
1
+ import { NodePath } from '@babel/traverse';
2
+ import * as t from '@babel/types';
3
+ /**
4
+ * Given an identifier node, determine if it is a React Jsx function
5
+ * jsxDEV, jsx, jsxs, ...
6
+ *
7
+ * TODO: handle default imports and namespace imports
8
+ */
9
+ export declare function isReactJsxFunction(path: NodePath<t.Identifier | t.MemberExpression>): boolean;
10
+ //# sourceMappingURL=isReactJsxFunction.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"isReactJsxFunction.d.ts","sourceRoot":"","sources":["../../../../src/utils/constants/resolveIdentifier/isReactJsxFunction.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,KAAK,CAAC,MAAM,cAAc,CAAC;AAGlC;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAChC,IAAI,EAAE,QAAQ,CAAC,CAAC,CAAC,UAAU,GAAG,CAAC,CAAC,gBAAgB,CAAC,GAChD,OAAO,CAOT"}
@@ -0,0 +1,93 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.isReactJsxFunction = isReactJsxFunction;
37
+ const t = __importStar(require("@babel/types"));
38
+ const helpers_1 = require("../react/helpers");
39
+ /**
40
+ * Given an identifier node, determine if it is a React Jsx function
41
+ * jsxDEV, jsx, jsxs, ...
42
+ *
43
+ * TODO: handle default imports and namespace imports
44
+ */
45
+ function isReactJsxFunction(path) {
46
+ if (path.isIdentifier()) {
47
+ return isReactJsxFunctionImportSpecifier(path);
48
+ }
49
+ else if (path.isMemberExpression()) {
50
+ return isReactJsxFunctionMemberExpression(path);
51
+ }
52
+ return false;
53
+ }
54
+ // --- Helpers --- //
55
+ /**
56
+ * Check if the identifier is a React Jsx function import specifier
57
+ * import { jsxDEV, jsx, jsxs } from 'react'
58
+ */
59
+ function isReactJsxFunctionImportSpecifier(identifierPath) {
60
+ // Check that binding is being imported
61
+ // import { jsxDEV, jsx, jsxs } from '...'
62
+ const binding = identifierPath.scope.getBinding(identifierPath.node.name);
63
+ if (!binding || !binding.path.isImportSpecifier()) {
64
+ return false;
65
+ }
66
+ // Check the original name is a React Jsx function
67
+ const imported = binding.path.node.imported;
68
+ const originalName = t.isIdentifier(imported)
69
+ ? imported.name
70
+ : imported.value;
71
+ if (!(0, helpers_1.isReactFunction)(originalName)) {
72
+ return false;
73
+ }
74
+ // Check the import source is from React
75
+ const parentPath = binding.path.parentPath;
76
+ if (!parentPath || !parentPath.isImportDeclaration()) {
77
+ return false;
78
+ }
79
+ const importSource = parentPath.node.source.value;
80
+ if (!(0, helpers_1.isReactImportSource)(importSource)) {
81
+ return false;
82
+ }
83
+ return true;
84
+ }
85
+ /**
86
+ * Check if the member expression is a React Jsx function
87
+ * React.jsxDEV, React.jsx, React.jsxs, ...
88
+ */
89
+ function isReactJsxFunctionMemberExpression(memberExpressionPath) {
90
+ // TODO: implement
91
+ return false;
92
+ }
93
+ //# sourceMappingURL=isReactJsxFunction.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"isReactJsxFunction.js","sourceRoot":"","sources":["../../../../src/utils/constants/resolveIdentifier/isReactJsxFunction.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAUA,gDASC;AAlBD,gDAAkC;AAClC,8CAAwE;AAExE;;;;;GAKG;AACH,SAAgB,kBAAkB,CAChC,IAAiD;IAEjD,IAAI,IAAI,CAAC,YAAY,EAAE,E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CAAC;AAED;;;GAGG;AACH,SAAS,kCAAkC,CACzC,oBAAkD;IAElD,kBAAkB;IAClB,OAAO,KAAK,CAAC;AACf,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@generaltranslation/compiler",
3
- "version": "1.2.1",
3
+ "version": "1.3.0",
4
4
  "description": "Universal plugin for compile-time optimization of GT translation components",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -24,7 +24,7 @@
24
24
  "@babel/traverse": "^7.23.0",
25
25
  "@babel/types": "^7.23.0",
26
26
  "unplugin": "^2.3.10",
27
- "generaltranslation": "8.2.1"
27
+ "generaltranslation": "8.2.2"
28
28
  },
29
29
  "devDependencies": {
30
30
  "@types/babel__core": "^7.20.0",