@vxrn/compiler 2.0.0-beta.33.1 → 2.0.0-beta.45.1

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 (94) hide show
  1. package/dist/cjs/cache.cjs +112 -109
  2. package/dist/cjs/configure.cjs +26 -28
  3. package/dist/cjs/constants.cjs +56 -60
  4. package/dist/cjs/index.cjs +420 -438
  5. package/dist/cjs/reactNativeCodegen.cjs +105 -114
  6. package/dist/cjs/reactNativeViewConfig.cjs +362 -381
  7. package/dist/cjs/refresh-runtime.cjs +390 -397
  8. package/dist/cjs/transformBabel.cjs +278 -218
  9. package/dist/cjs/transformHermesAsync.cjs +36 -47
  10. package/dist/cjs/transformHermesLoops.cjs +279 -281
  11. package/dist/cjs/transformSWC.cjs +183 -200
  12. package/dist/cjs/transformWorklets.cjs +107 -95
  13. package/dist/cjs/types.cjs +9 -11
  14. package/dist/cjs/worklets/autoworklet.cjs +277 -222
  15. package/dist/cjs/worklets/globals.cjs +124 -60
  16. package/dist/cjs/worklets/hash.cjs +23 -27
  17. package/dist/cjs/worklets/scope.cjs +338 -359
  18. package/dist/cjs/worklets/serialize.cjs +73 -75
  19. package/dist/cjs/worklets/transform.cjs +217 -222
  20. package/dist/cjs/worklets/types.cjs +9 -11
  21. package/dist/esm/cache.mjs +96 -89
  22. package/dist/esm/cache.mjs.map +1 -1
  23. package/dist/esm/configure.mjs +11 -10
  24. package/dist/esm/configure.mjs.map +1 -1
  25. package/dist/esm/constants.mjs +41 -41
  26. package/dist/esm/constants.mjs.map +1 -1
  27. package/dist/esm/index.js +417 -420
  28. package/dist/esm/index.js.map +1 -1
  29. package/dist/esm/index.mjs +417 -420
  30. package/dist/esm/index.mjs.map +1 -1
  31. package/dist/esm/reactNativeCodegen.mjs +90 -88
  32. package/dist/esm/reactNativeCodegen.mjs.map +1 -1
  33. package/dist/esm/reactNativeViewConfig.mjs +347 -362
  34. package/dist/esm/reactNativeViewConfig.mjs.map +1 -1
  35. package/dist/esm/refresh-runtime.mjs +372 -376
  36. package/dist/esm/refresh-runtime.mjs.map +1 -1
  37. package/dist/esm/transformBabel.mjs +261 -194
  38. package/dist/esm/transformBabel.mjs.map +1 -1
  39. package/dist/esm/transformHermesAsync.mjs +20 -21
  40. package/dist/esm/transformHermesAsync.mjs.map +1 -1
  41. package/dist/esm/transformHermesLoops.mjs +264 -255
  42. package/dist/esm/transformHermesLoops.mjs.map +1 -1
  43. package/dist/esm/transformSWC.mjs +163 -171
  44. package/dist/esm/transformSWC.mjs.map +1 -1
  45. package/dist/esm/transformWorklets.mjs +89 -69
  46. package/dist/esm/transformWorklets.mjs.map +1 -1
  47. package/dist/esm/types.mjs +0 -2
  48. package/dist/esm/worklets/autoworklet.mjs +258 -200
  49. package/dist/esm/worklets/autoworklet.mjs.map +1 -1
  50. package/dist/esm/worklets/globals.mjs +109 -42
  51. package/dist/esm/worklets/globals.mjs.map +1 -1
  52. package/dist/esm/worklets/hash.mjs +10 -9
  53. package/dist/esm/worklets/hash.mjs.map +1 -1
  54. package/dist/esm/worklets/scope.mjs +325 -341
  55. package/dist/esm/worklets/scope.mjs.map +1 -1
  56. package/dist/esm/worklets/serialize.mjs +60 -58
  57. package/dist/esm/worklets/serialize.mjs.map +1 -1
  58. package/dist/esm/worklets/transform.mjs +201 -197
  59. package/dist/esm/worklets/transform.mjs.map +1 -1
  60. package/dist/esm/worklets/types.mjs +0 -2
  61. package/package.json +7 -6
  62. package/src/cache.ts +37 -7
  63. package/src/index.ts +33 -18
  64. package/src/transformBabel.test.ts +311 -1
  65. package/src/transformBabel.ts +110 -13
  66. package/types/cache.d.ts +2 -2
  67. package/types/cache.d.ts.map +1 -1
  68. package/types/index.d.ts.map +1 -1
  69. package/types/transformBabel.d.ts +16 -1
  70. package/types/transformBabel.d.ts.map +1 -1
  71. package/types/transformSWC.d.ts +1 -4
  72. package/types/transformSWC.d.ts.map +1 -1
  73. package/dist/cjs/transformBabel.test.cjs +0 -360
  74. package/dist/cjs/transformHermesLoops.test.cjs +0 -257
  75. package/dist/cjs/transformSWC.test.cjs +0 -117
  76. package/dist/cjs/transformWorklets.test.cjs +0 -604
  77. package/dist/esm/transformBabel.test.mjs +0 -337
  78. package/dist/esm/transformBabel.test.mjs.map +0 -1
  79. package/dist/esm/transformHermesLoops.test.mjs +0 -234
  80. package/dist/esm/transformHermesLoops.test.mjs.map +0 -1
  81. package/dist/esm/transformSWC.test.mjs +0 -118
  82. package/dist/esm/transformSWC.test.mjs.map +0 -1
  83. package/dist/esm/transformWorklets.test.mjs +0 -581
  84. package/dist/esm/transformWorklets.test.mjs.map +0 -1
  85. package/dist/esm/types.mjs.map +0 -1
  86. package/dist/esm/worklets/types.mjs.map +0 -1
  87. package/types/transformBabel.test.d.ts +0 -2
  88. package/types/transformBabel.test.d.ts.map +0 -1
  89. package/types/transformHermesLoops.test.d.ts +0 -2
  90. package/types/transformHermesLoops.test.d.ts.map +0 -1
  91. package/types/transformSWC.test.d.ts +0 -2
  92. package/types/transformSWC.test.d.ts.map +0 -1
  93. package/types/transformWorklets.test.d.ts +0 -2
  94. package/types/transformWorklets.test.d.ts.map +0 -1
@@ -5,136 +5,127 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
5
5
  var __getProtoOf = Object.getPrototypeOf;
6
6
  var __hasOwnProp = Object.prototype.hasOwnProperty;
7
7
  var __export = (target, all) => {
8
- for (var name in all) __defProp(target, name, {
9
- get: all[name],
10
- enumerable: true
11
- });
8
+ for (var name in all) __defProp(target, name, {
9
+ get: all[name],
10
+ enumerable: true
11
+ });
12
12
  };
13
13
  var __copyProps = (to, from, except, desc) => {
14
- if (from && typeof from === "object" || typeof from === "function") {
15
- for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
16
- get: () => from[key],
17
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
18
- });
19
- }
20
- return to;
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
16
+ get: () => from[key],
17
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
18
+ });
19
+ }
20
+ return to;
21
21
  };
22
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
23
- // If the importer is in node compatibility mode or this is not an ESM
24
- // file that has been converted to a CommonJS file using a Babel-
25
- // compatible transform (i.e. "__esModule" has not been set), then set
26
- // "default" to the CommonJS "module.exports" for node compatibility.
27
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
28
- value: mod,
29
- enumerable: true
22
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
23
+ value: mod,
24
+ enumerable: true
30
25
  }) : target, mod));
31
- var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
32
- value: true
33
- }), mod);
26
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
34
27
  var reactNativeCodegen_exports = {};
35
- __export(reactNativeCodegen_exports, {
36
- transformReactNativeCodegen: () => transformReactNativeCodegen
37
- });
28
+ __export(reactNativeCodegen_exports, { transformReactNativeCodegen: () => transformReactNativeCodegen });
38
29
  module.exports = __toCommonJS(reactNativeCodegen_exports);
39
30
  var import_magic_string = __toESM(require("magic-string"), 1);
40
31
  var import_reactNativeViewConfig = require("./reactNativeViewConfig.cjs");
41
32
  function normalizePath(id) {
42
- return id.replace(/\\/g, "/");
33
+ return id.replace(/\\/g, "/");
43
34
  }
44
35
  const CODEGEN_FILE_RE = /(?:NativeComponent\.[cm]?[jt]sx?$|[/\\]specs?[/\\])/;
45
36
  const CODEGEN_CALL_RE = /codegenNativeComponent\s*[<(]/;
46
- const startOf = node => node.start ?? node.range[0];
47
- const endOf = node => node.end ?? node.range[1];
37
+ const startOf = (node) => node.start ?? node.range[0];
38
+ const endOf = (node) => node.end ?? node.range[1];
48
39
  function unwrapExpression(node) {
49
- while (node) {
50
- if (node.type === "TSAsExpression" || node.type === "TSSatisfiesExpression" || node.type === "TSTypeAssertion" || node.type === "TypeCastExpression" || node.type === "AsExpression" || node.type === "ParenthesizedExpression") {
51
- node = node.expression;
52
- } else if (node.type === "SequenceExpression" && Array.isArray(node.expressions) && node.expressions.length > 0) {
53
- node = node.expressions[node.expressions.length - 1];
54
- } else {
55
- break;
56
- }
57
- }
58
- return node;
40
+ while (node) {
41
+ if (node.type === "TSAsExpression" || node.type === "TSSatisfiesExpression" || node.type === "TSTypeAssertion" || node.type === "TypeCastExpression" || node.type === "AsExpression" || node.type === "ParenthesizedExpression") {
42
+ node = node.expression;
43
+ } else if (node.type === "SequenceExpression" && Array.isArray(node.expressions) && node.expressions.length > 0) {
44
+ node = node.expressions[node.expressions.length - 1];
45
+ } else {
46
+ break;
47
+ }
48
+ }
49
+ return node;
59
50
  }
60
51
  function isCodegenDeclaration(declaration) {
61
- if (!declaration) return false;
62
- if (declaration.left && declaration.left.left && declaration.left.left.name === "codegenNativeComponent") {
63
- return true;
64
- }
65
- const unwrapped = unwrapExpression(declaration);
66
- return unwrapped?.type === "CallExpression" && unwrapped.callee?.type === "Identifier" && unwrapped.callee.name === "codegenNativeComponent";
52
+ if (!declaration) return false;
53
+ if (declaration.left && declaration.left.left && declaration.left.left.name === "codegenNativeComponent") {
54
+ return true;
55
+ }
56
+ const unwrapped = unwrapExpression(declaration);
57
+ return unwrapped?.type === "CallExpression" && unwrapped.callee?.type === "Identifier" && unwrapped.callee.name === "codegenNativeComponent";
67
58
  }
68
59
  function isCodegenNativeCommandsDeclaration(declaration) {
69
- if (!declaration) return false;
70
- const unwrapped = unwrapExpression(declaration);
71
- return unwrapped?.type === "CallExpression" && unwrapped.callee?.type === "Identifier" && unwrapped.callee.name === "codegenNativeCommands";
60
+ if (!declaration) return false;
61
+ const unwrapped = unwrapExpression(declaration);
62
+ return unwrapped?.type === "CallExpression" && unwrapped.callee?.type === "Identifier" && unwrapped.callee.name === "codegenNativeCommands";
72
63
  }
73
64
  function transformReactNativeCodegen(code, id, projectRoot) {
74
- const cleanId = normalizePath(id.split("?")[0]);
75
- if (!CODEGEN_FILE_RE.test(cleanId)) {
76
- return;
77
- }
78
- if (!CODEGEN_CALL_RE.test(code)) {
79
- return;
80
- }
81
- const program = (0, import_reactNativeViewConfig.parseSpec)(code, cleanId, projectRoot);
82
- const body = program?.body;
83
- if (!body) {
84
- return;
85
- }
86
- let defaultExport = null;
87
- let commandsExport = null;
88
- for (const node of body) {
89
- if (node.type === "ExportDefaultDeclaration") {
90
- if (isCodegenDeclaration(node.declaration)) {
91
- defaultExport = node;
92
- }
93
- } else if (node.type === "ExportNamedDeclaration") {
94
- if (node.declaration && node.declaration.declarations) {
95
- const firstDeclaration = node.declaration.declarations[0];
96
- if (firstDeclaration?.type === "VariableDeclarator") {
97
- const isValidCommandsExport = isCodegenNativeCommandsDeclaration(firstDeclaration.init);
98
- if (isValidCommandsExport) {
99
- if (firstDeclaration.id?.type === "Identifier" && firstDeclaration.id.name !== "Commands") {
100
- throw new Error("Native commands must be exported with the name 'Commands'");
101
- }
102
- commandsExport = node;
103
- } else {
104
- if (firstDeclaration.id?.type === "Identifier" && firstDeclaration.id.name === "Commands") {
105
- throw new Error("'Commands' is a reserved export and may only be used to export the result of codegenNativeCommands.");
106
- }
107
- }
108
- }
109
- } else if (node.specifiers && node.specifiers.length > 0) {
110
- for (const specifier of node.specifiers) {
111
- if (specifier.type === "ExportSpecifier" && (specifier.local?.type === "Identifier" && specifier.local.name === "Commands" || specifier.exported?.type === "Identifier" && specifier.exported.name === "Commands")) {
112
- throw new Error("'Commands' is a reserved export and may only be used to export the result of codegenNativeCommands.");
113
- }
114
- }
115
- }
116
- }
117
- }
118
- if (!defaultExport) {
119
- return;
120
- }
121
- const generated = (0, import_reactNativeViewConfig.generateViewConfig)(program);
122
- if (!generated) {
123
- return;
124
- }
125
- const s = new import_magic_string.default(code);
126
- if (commandsExport) {
127
- let removeEnd = endOf(commandsExport);
128
- if (code[removeEnd] === "\r") removeEnd++;
129
- if (code[removeEnd] === "\n") removeEnd++;
130
- s.remove(startOf(commandsExport), removeEnd);
131
- }
132
- s.overwrite(startOf(defaultExport), endOf(defaultExport), (0, import_reactNativeViewConfig.renderViewConfigModule)(generated));
133
- return {
134
- code: s.toString(),
135
- map: s.generateMap({
136
- hires: true,
137
- source: cleanId
138
- })
139
- };
140
- }
65
+ const cleanId = normalizePath(id.split("?")[0]);
66
+ if (!CODEGEN_FILE_RE.test(cleanId)) {
67
+ return;
68
+ }
69
+ if (!CODEGEN_CALL_RE.test(code)) {
70
+ return;
71
+ }
72
+ const program = (0, import_reactNativeViewConfig.parseSpec)(code, cleanId, projectRoot);
73
+ const body = program?.body;
74
+ if (!body) {
75
+ return;
76
+ }
77
+ let defaultExport = null;
78
+ let commandsExport = null;
79
+ for (const node of body) {
80
+ if (node.type === "ExportDefaultDeclaration") {
81
+ if (isCodegenDeclaration(node.declaration)) {
82
+ defaultExport = node;
83
+ }
84
+ } else if (node.type === "ExportNamedDeclaration") {
85
+ if (node.declaration && node.declaration.declarations) {
86
+ const firstDeclaration = node.declaration.declarations[0];
87
+ if (firstDeclaration?.type === "VariableDeclarator") {
88
+ const isValidCommandsExport = isCodegenNativeCommandsDeclaration(firstDeclaration.init);
89
+ if (isValidCommandsExport) {
90
+ if (firstDeclaration.id?.type === "Identifier" && firstDeclaration.id.name !== "Commands") {
91
+ throw new Error("Native commands must be exported with the name 'Commands'");
92
+ }
93
+ commandsExport = node;
94
+ } else {
95
+ if (firstDeclaration.id?.type === "Identifier" && firstDeclaration.id.name === "Commands") {
96
+ throw new Error("'Commands' is a reserved export and may only be used to export the result of codegenNativeCommands.");
97
+ }
98
+ }
99
+ }
100
+ } else if (node.specifiers && node.specifiers.length > 0) {
101
+ for (const specifier of node.specifiers) {
102
+ if (specifier.type === "ExportSpecifier" && (specifier.local?.type === "Identifier" && specifier.local.name === "Commands" || specifier.exported?.type === "Identifier" && specifier.exported.name === "Commands")) {
103
+ throw new Error("'Commands' is a reserved export and may only be used to export the result of codegenNativeCommands.");
104
+ }
105
+ }
106
+ }
107
+ }
108
+ }
109
+ if (!defaultExport) {
110
+ return;
111
+ }
112
+ const generated = (0, import_reactNativeViewConfig.generateViewConfig)(program);
113
+ if (!generated) {
114
+ return;
115
+ }
116
+ const s = new import_magic_string.default(code);
117
+ if (commandsExport) {
118
+ let removeEnd = endOf(commandsExport);
119
+ if (code[removeEnd] === "\r") removeEnd++;
120
+ if (code[removeEnd] === "\n") removeEnd++;
121
+ s.remove(startOf(commandsExport), removeEnd);
122
+ }
123
+ s.overwrite(startOf(defaultExport), endOf(defaultExport), (0, import_reactNativeViewConfig.renderViewConfigModule)(generated));
124
+ return {
125
+ code: s.toString(),
126
+ map: s.generateMap({
127
+ hires: true,
128
+ source: cleanId
129
+ })
130
+ };
131
+ }