@vxrn/compiler 1.25.16 → 1.26.0-1788990885077
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/cjs/cache.cjs +4 -2
- package/dist/cjs/configure.cjs +9 -1
- package/dist/cjs/index.cjs +87 -5
- package/dist/cjs/reactNativeCodegen.cjs +140 -0
- package/dist/cjs/reactNativeViewConfig.cjs +489 -0
- package/dist/cjs/transformBabel.cjs +15 -20
- package/dist/cjs/transformBabel.test.cjs +260 -0
- package/dist/cjs/transformHermesAsync.cjs +61 -0
- package/dist/cjs/transformHermesLoops.cjs +319 -0
- package/dist/cjs/transformHermesLoops.test.cjs +257 -0
- package/dist/cjs/transformSWC.cjs +110 -138
- package/dist/cjs/transformSWC.test.cjs +117 -0
- package/dist/cjs/transformWorklets.cjs +123 -0
- package/dist/cjs/transformWorklets.test.cjs +604 -0
- package/dist/cjs/worklets/autoworklet.cjs +265 -0
- package/dist/cjs/worklets/globals.cjs +73 -0
- package/dist/cjs/worklets/hash.cjs +38 -0
- package/dist/cjs/worklets/scope.cjs +370 -0
- package/dist/cjs/worklets/serialize.cjs +101 -0
- package/dist/cjs/worklets/transform.cjs +266 -0
- package/dist/cjs/worklets/types.cjs +18 -0
- package/dist/esm/cache.mjs +5 -3
- package/dist/esm/cache.mjs.map +1 -1
- package/dist/esm/configure.mjs +8 -1
- package/dist/esm/configure.mjs.map +1 -1
- package/dist/esm/index.js +75 -6
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/index.mjs +75 -6
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/reactNativeCodegen.mjs +104 -0
- package/dist/esm/reactNativeCodegen.mjs.map +1 -0
- package/dist/esm/reactNativeViewConfig.mjs +460 -0
- package/dist/esm/reactNativeViewConfig.mjs.map +1 -0
- package/dist/esm/transformBabel.mjs +14 -19
- package/dist/esm/transformBabel.mjs.map +1 -1
- package/dist/esm/transformBabel.test.mjs +261 -1
- package/dist/esm/transformBabel.test.mjs.map +1 -1
- package/dist/esm/transformHermesAsync.mjs +25 -0
- package/dist/esm/transformHermesAsync.mjs.map +1 -0
- package/dist/esm/transformHermesLoops.mjs +283 -0
- package/dist/esm/transformHermesLoops.mjs.map +1 -0
- package/dist/esm/transformHermesLoops.test.mjs +234 -0
- package/dist/esm/transformHermesLoops.test.mjs.map +1 -0
- package/dist/esm/transformSWC.mjs +96 -139
- package/dist/esm/transformSWC.mjs.map +1 -1
- package/dist/esm/transformSWC.test.mjs +118 -0
- package/dist/esm/transformSWC.test.mjs.map +1 -0
- package/dist/esm/transformWorklets.mjs +82 -0
- package/dist/esm/transformWorklets.mjs.map +1 -0
- package/dist/esm/transformWorklets.test.mjs +581 -0
- package/dist/esm/transformWorklets.test.mjs.map +1 -0
- package/dist/esm/worklets/autoworklet.mjs +234 -0
- package/dist/esm/worklets/autoworklet.mjs.map +1 -0
- package/dist/esm/worklets/globals.mjs +46 -0
- package/dist/esm/worklets/globals.mjs.map +1 -0
- package/dist/esm/worklets/hash.mjs +13 -0
- package/dist/esm/worklets/hash.mjs.map +1 -0
- package/dist/esm/worklets/scope.mjs +345 -0
- package/dist/esm/worklets/scope.mjs.map +1 -0
- package/dist/esm/worklets/serialize.mjs +75 -0
- package/dist/esm/worklets/serialize.mjs.map +1 -0
- package/dist/esm/worklets/transform.mjs +229 -0
- package/dist/esm/worklets/transform.mjs.map +1 -0
- package/dist/esm/worklets/types.mjs +2 -0
- package/dist/esm/worklets/types.mjs.map +1 -0
- package/package.json +11 -6
- package/src/cache.ts +10 -3
- package/src/configure.ts +12 -0
- package/src/index.ts +96 -13
- package/src/reactNativeCodegen.ts +181 -0
- package/src/reactNativeViewConfig.ts +593 -0
- package/src/transformBabel.test.ts +268 -1
- package/src/transformBabel.ts +21 -31
- package/src/transformHermesAsync.ts +30 -0
- package/src/transformHermesLoops.test.ts +341 -0
- package/src/transformHermesLoops.ts +435 -0
- package/src/transformSWC.test.ts +132 -0
- package/src/transformSWC.ts +121 -161
- package/src/transformWorklets.test.ts +708 -0
- package/src/transformWorklets.ts +160 -0
- package/src/types.ts +4 -4
- package/src/worklets/autoworklet.ts +391 -0
- package/src/worklets/globals.ts +129 -0
- package/src/worklets/hash.ts +14 -0
- package/src/worklets/scope.ts +401 -0
- package/src/worklets/serialize.ts +114 -0
- package/src/worklets/transform.ts +319 -0
- package/src/worklets/types.ts +26 -0
- package/types/cache.d.ts +1 -0
- package/types/cache.d.ts.map +1 -1
- package/types/configure.d.ts +2 -0
- package/types/configure.d.ts.map +1 -1
- package/types/index.d.ts +6 -0
- package/types/index.d.ts.map +1 -1
- package/types/reactNativeCodegen.d.ts +5 -0
- package/types/reactNativeCodegen.d.ts.map +1 -0
- package/types/reactNativeViewConfig.d.ts +35 -0
- package/types/reactNativeViewConfig.d.ts.map +1 -0
- package/types/transformBabel.d.ts +3 -3
- package/types/transformBabel.d.ts.map +1 -1
- package/types/transformHermesAsync.d.ts +5 -0
- package/types/transformHermesAsync.d.ts.map +1 -0
- package/types/transformHermesLoops.d.ts +5 -0
- package/types/transformHermesLoops.d.ts.map +1 -0
- package/types/transformHermesLoops.test.d.ts +2 -0
- package/types/transformHermesLoops.test.d.ts.map +1 -0
- package/types/transformSWC.d.ts +13 -3
- package/types/transformSWC.d.ts.map +1 -1
- package/types/transformSWC.test.d.ts +2 -0
- package/types/transformSWC.test.d.ts.map +1 -0
- package/types/transformWorklets.d.ts +23 -0
- package/types/transformWorklets.d.ts.map +1 -0
- package/types/transformWorklets.test.d.ts +2 -0
- package/types/transformWorklets.test.d.ts.map +1 -0
- package/types/types.d.ts +4 -4
- package/types/types.d.ts.map +1 -1
- package/types/worklets/autoworklet.d.ts +14 -0
- package/types/worklets/autoworklet.d.ts.map +1 -0
- package/types/worklets/globals.d.ts +4 -0
- package/types/worklets/globals.d.ts.map +1 -0
- package/types/worklets/hash.d.ts +5 -0
- package/types/worklets/hash.d.ts.map +1 -0
- package/types/worklets/scope.d.ts +7 -0
- package/types/worklets/scope.d.ts.map +1 -0
- package/types/worklets/serialize.d.ts +12 -0
- package/types/worklets/serialize.d.ts.map +1 -0
- package/types/worklets/transform.d.ts +10 -0
- package/types/worklets/transform.d.ts.map +1 -0
- package/types/worklets/types.d.ts +21 -0
- package/types/worklets/types.d.ts.map +1 -0
package/dist/cjs/cache.cjs
CHANGED
|
@@ -35,7 +35,8 @@ var import_configure = require("./configure.cjs");
|
|
|
35
35
|
const stats = {
|
|
36
36
|
hits: 0,
|
|
37
37
|
misses: 0,
|
|
38
|
-
writes: 0
|
|
38
|
+
writes: 0,
|
|
39
|
+
errors: 0
|
|
39
40
|
};
|
|
40
41
|
function getCacheDir() {
|
|
41
42
|
const cacheDir = (0, import_node_path.join)(process.cwd(), "node_modules", ".vxrn", "compiler-cache");
|
|
@@ -50,11 +51,12 @@ function getConfigFingerprint() {
|
|
|
50
51
|
return (0, import_node_crypto.createHash)("sha1").update(JSON.stringify({
|
|
51
52
|
compiler: import_configure.configuration.enableCompiler,
|
|
52
53
|
reanimated: import_configure.configuration.enableReanimated,
|
|
54
|
+
nativeWorklets: (0, import_configure.isNativeWorkletsEnabled)(),
|
|
53
55
|
nativewind: import_configure.configuration.enableNativewind,
|
|
54
56
|
nativeCSS: import_configure.configuration.enableNativeCSS,
|
|
55
57
|
// bump when the transform engine changes, so entries written by a
|
|
56
58
|
// previous engine aren't served for the same source
|
|
57
|
-
engine: "oxc-
|
|
59
|
+
engine: "oxc-worklets-hermes-async"
|
|
58
60
|
})).digest("hex").slice(0, 8);
|
|
59
61
|
}
|
|
60
62
|
function getCacheKey(filePath, environment) {
|
package/dist/cjs/configure.cjs
CHANGED
|
@@ -23,15 +23,23 @@ var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
|
23
23
|
var configure_exports = {};
|
|
24
24
|
__export(configure_exports, {
|
|
25
25
|
configuration: () => configuration,
|
|
26
|
-
configureVXRNCompilerPlugin: () => configureVXRNCompilerPlugin
|
|
26
|
+
configureVXRNCompilerPlugin: () => configureVXRNCompilerPlugin,
|
|
27
|
+
isNativeWorkletsEnabled: () => isNativeWorkletsEnabled
|
|
27
28
|
});
|
|
28
29
|
module.exports = __toCommonJS(configure_exports);
|
|
29
30
|
const configuration = {
|
|
30
31
|
enableNativewind: false,
|
|
31
32
|
enableReanimated: false,
|
|
33
|
+
enableNativeWorklets: true,
|
|
32
34
|
enableCompiler: false,
|
|
33
35
|
enableNativeCSS: false
|
|
34
36
|
};
|
|
37
|
+
function isNativeWorkletsEnabled() {
|
|
38
|
+
if (process.env.VXRN_NATIVE_WORKLETS === "false" || process.env.VXRN_NATIVE_WORKLETS === "0") {
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
return configuration.enableNativeWorklets !== false;
|
|
42
|
+
}
|
|
35
43
|
function configureVXRNCompilerPlugin(_) {
|
|
36
44
|
Object.assign(configuration, _);
|
|
37
45
|
}
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
1
2
|
var __defProp = Object.defineProperty;
|
|
2
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
4
6
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
7
|
var __export = (target, all) => {
|
|
6
8
|
for (var name in all) __defProp(target, name, {
|
|
@@ -18,12 +20,23 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
20
|
return to;
|
|
19
21
|
};
|
|
20
22
|
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
23
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
24
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
25
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
26
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
27
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
28
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
29
|
+
value: mod,
|
|
30
|
+
enumerable: true
|
|
31
|
+
}) : target, mod));
|
|
21
32
|
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
22
33
|
value: true
|
|
23
34
|
}), mod);
|
|
24
35
|
var index_exports = {};
|
|
25
36
|
__export(index_exports, {
|
|
26
|
-
|
|
37
|
+
JS_GLOBALS: () => import_globals.JS_GLOBALS,
|
|
38
|
+
createVXRNCompilerPlugin: () => createVXRNCompilerPlugin,
|
|
39
|
+
getClosureVariables: () => import_scope.getClosureVariables
|
|
27
40
|
});
|
|
28
41
|
module.exports = __toCommonJS(index_exports);
|
|
29
42
|
var import_node_fs = require("node:fs");
|
|
@@ -35,10 +48,18 @@ var import_css_to_rn = require("react-native-css-interop/css-to-rn/index.js");
|
|
|
35
48
|
var import_configure = require("./configure.cjs");
|
|
36
49
|
var import_constants = require("./constants.cjs");
|
|
37
50
|
var import_transformBabel = require("./transformBabel.cjs");
|
|
51
|
+
var import_transformSWC = require("./transformSWC.cjs");
|
|
52
|
+
var import_transformWorklets = require("./transformWorklets.cjs");
|
|
38
53
|
var import_cache = require("./cache.cjs");
|
|
39
54
|
__reExport(index_exports, require("./configure.cjs"), module.exports);
|
|
40
55
|
__reExport(index_exports, require("./transformBabel.cjs"), module.exports);
|
|
41
56
|
__reExport(index_exports, require("./transformSWC.cjs"), module.exports);
|
|
57
|
+
__reExport(index_exports, require("./transformWorklets.cjs"), module.exports);
|
|
58
|
+
__reExport(index_exports, require("./reactNativeCodegen.cjs"), module.exports);
|
|
59
|
+
__reExport(index_exports, require("./transformHermesLoops.cjs"), module.exports);
|
|
60
|
+
__reExport(index_exports, require("./transformHermesAsync.cjs"), module.exports);
|
|
61
|
+
var import_globals = require("./worklets/globals.cjs");
|
|
62
|
+
var import_scope = require("./worklets/scope.cjs");
|
|
42
63
|
const import_meta = {};
|
|
43
64
|
const perfStats = {
|
|
44
65
|
babel: {
|
|
@@ -125,7 +146,7 @@ async function performBabelTransform({
|
|
|
125
146
|
if (userTransform === false) {
|
|
126
147
|
return null;
|
|
127
148
|
}
|
|
128
|
-
if (userTransform !== "swc") {
|
|
149
|
+
if (userTransform !== "swc" && userTransform !== "oxc") {
|
|
129
150
|
const babelOptions = (0, import_transformBabel.getBabelOptions)({
|
|
130
151
|
...transformProps,
|
|
131
152
|
userSetting: userTransform
|
|
@@ -142,10 +163,71 @@ async function performBabelTransform({
|
|
|
142
163
|
(0, import_constants.debug)?.(`[babel/cached] ${id}`);
|
|
143
164
|
return cached;
|
|
144
165
|
}
|
|
145
|
-
const
|
|
146
|
-
|
|
166
|
+
const isWorkletPlugin = entry => {
|
|
167
|
+
if (!entry) return false;
|
|
168
|
+
const name = typeof entry === "string" ? entry : Array.isArray(entry) ? entry[0] : null;
|
|
169
|
+
return typeof name === "string" && (name.includes("react-native-worklets") || name.includes("react-native-reanimated"));
|
|
170
|
+
};
|
|
171
|
+
const workletEntry = babelOptions.plugins?.find(isWorkletPlugin);
|
|
172
|
+
const workletPluginOptions = Array.isArray(workletEntry) ? workletEntry[1] : void 0;
|
|
173
|
+
const useWorklets = (0, import_configure.isNativeWorkletsEnabled)() && (Boolean(workletEntry) || (0, import_transformWorklets.shouldTransformWorklets)({
|
|
174
|
+
id,
|
|
175
|
+
code
|
|
176
|
+
}));
|
|
177
|
+
let curCode = code;
|
|
178
|
+
let workletPreparation = null;
|
|
179
|
+
let compilerOut = null;
|
|
180
|
+
const compilerPluginIndex = babelOptions.plugins?.findIndex(x => Array.isArray(x) && x[0] === "babel-plugin-react-compiler") ?? -1;
|
|
181
|
+
if (compilerPluginIndex !== -1) {
|
|
182
|
+
if (useWorklets) {
|
|
183
|
+
workletPreparation = (0, import_transformWorklets.prepareWorkletsForReactCompiler)(id, curCode, (0, import_transformSWC.shouldSourceMap)());
|
|
184
|
+
if (workletPreparation) curCode = workletPreparation.code;
|
|
185
|
+
}
|
|
186
|
+
const compilerTarget = babelOptions.plugins[compilerPluginIndex][1]?.target ?? "19";
|
|
187
|
+
compilerOut = await (0, import_transformBabel.transformOxcReactCompiler)(id, curCode, compilerTarget, (0, import_transformSWC.shouldSourceMap)());
|
|
188
|
+
if (compilerOut) curCode = compilerOut.code;
|
|
189
|
+
babelOptions.plugins.splice(compilerPluginIndex, 1);
|
|
190
|
+
}
|
|
191
|
+
let workletsOut = null;
|
|
192
|
+
if (useWorklets) {
|
|
193
|
+
workletsOut = await (0, import_transformWorklets.transformWorklets)(id, curCode, (0, import_transformSWC.shouldSourceMap)(), {
|
|
194
|
+
projectRoot,
|
|
195
|
+
...workletPluginOptions
|
|
196
|
+
});
|
|
197
|
+
babelOptions.plugins = babelOptions.plugins?.filter(entry => !isWorkletPlugin(entry));
|
|
198
|
+
curCode = workletsOut.code;
|
|
199
|
+
}
|
|
147
200
|
const startTime = Date.now();
|
|
148
|
-
|
|
201
|
+
let babelOut = null;
|
|
202
|
+
if (babelOptions.plugins?.length === 0) {
|
|
203
|
+
let finalMap = void 0;
|
|
204
|
+
if ((0, import_transformSWC.shouldSourceMap)()) {
|
|
205
|
+
const intermediateMaps = [workletPreparation?.map, compilerOut?.map, workletsOut?.map].filter(Boolean);
|
|
206
|
+
if (intermediateMaps.length === 1) {
|
|
207
|
+
finalMap = intermediateMaps[0];
|
|
208
|
+
} else if (intermediateMaps.length > 1) {
|
|
209
|
+
const remapping = (await import("@jridgewell/remapping")).default;
|
|
210
|
+
finalMap = remapping(intermediateMaps.slice().reverse(), () => null);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
babelOut = {
|
|
214
|
+
code: curCode,
|
|
215
|
+
map: finalMap
|
|
216
|
+
};
|
|
217
|
+
} else {
|
|
218
|
+
const babelOptsWithMap = (0, import_transformSWC.shouldSourceMap)() && (workletsOut?.map || compilerOut?.map || workletPreparation?.map) ? {
|
|
219
|
+
...babelOptions,
|
|
220
|
+
sourceMaps: true
|
|
221
|
+
} : babelOptions;
|
|
222
|
+
babelOut = await (0, import_transformBabel.transformBabel)(id, curCode, babelOptsWithMap);
|
|
223
|
+
if ((0, import_transformSWC.shouldSourceMap)() && babelOut?.map) {
|
|
224
|
+
const priorMaps = [workletPreparation?.map, compilerOut?.map, workletsOut?.map].filter(Boolean);
|
|
225
|
+
if (priorMaps.length > 0) {
|
|
226
|
+
const remapping = (await import("@jridgewell/remapping")).default;
|
|
227
|
+
babelOut.map = remapping([babelOut.map, ...priorMaps.slice().reverse()], () => null);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
}
|
|
149
231
|
const babelTime = Date.now() - startTime;
|
|
150
232
|
if (babelOut?.code) {
|
|
151
233
|
perfStats.babel.totalTransforms++;
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all) __defProp(target, name, {
|
|
9
|
+
get: all[name],
|
|
10
|
+
enumerable: true
|
|
11
|
+
});
|
|
12
|
+
};
|
|
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;
|
|
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
|
|
30
|
+
}) : target, mod));
|
|
31
|
+
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
32
|
+
value: true
|
|
33
|
+
}), mod);
|
|
34
|
+
var reactNativeCodegen_exports = {};
|
|
35
|
+
__export(reactNativeCodegen_exports, {
|
|
36
|
+
transformReactNativeCodegen: () => transformReactNativeCodegen
|
|
37
|
+
});
|
|
38
|
+
module.exports = __toCommonJS(reactNativeCodegen_exports);
|
|
39
|
+
var import_magic_string = __toESM(require("magic-string"), 1);
|
|
40
|
+
var import_reactNativeViewConfig = require("./reactNativeViewConfig.cjs");
|
|
41
|
+
function normalizePath(id) {
|
|
42
|
+
return id.replace(/\\/g, "/");
|
|
43
|
+
}
|
|
44
|
+
const CODEGEN_FILE_RE = /(?:NativeComponent\.[cm]?[jt]sx?$|[/\\]specs?[/\\])/;
|
|
45
|
+
const CODEGEN_CALL_RE = /codegenNativeComponent\s*[<(]/;
|
|
46
|
+
const startOf = node => node.start ?? node.range[0];
|
|
47
|
+
const endOf = node => node.end ?? node.range[1];
|
|
48
|
+
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;
|
|
59
|
+
}
|
|
60
|
+
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";
|
|
67
|
+
}
|
|
68
|
+
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";
|
|
72
|
+
}
|
|
73
|
+
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
|
+
}
|