@vxrn/compiler 1.25.13 → 1.25.16-1788753284749
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 +3 -1
- package/dist/cjs/configure.cjs +9 -1
- package/dist/cjs/index.cjs +82 -4
- 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/transformHermesLoops.cjs +317 -0
- package/dist/cjs/transformHermesLoops.test.cjs +220 -0
- package/dist/cjs/transformSWC.cjs +102 -137
- package/dist/cjs/transformSWC.test.cjs +74 -0
- package/dist/cjs/transformWorklets.cjs +121 -0
- package/dist/cjs/transformWorklets.test.cjs +604 -0
- package/dist/cjs/worklets/autoworklet.cjs +265 -0
- package/dist/cjs/worklets/globals.cjs +71 -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 +232 -0
- package/dist/cjs/worklets/types.cjs +18 -0
- package/dist/esm/cache.mjs +4 -2
- 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 +72 -5
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/index.mjs +72 -5
- 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/transformHermesLoops.mjs +281 -0
- package/dist/esm/transformHermesLoops.mjs.map +1 -0
- package/dist/esm/transformHermesLoops.test.mjs +197 -0
- package/dist/esm/transformHermesLoops.test.mjs.map +1 -0
- package/dist/esm/transformSWC.mjs +89 -138
- package/dist/esm/transformSWC.mjs.map +1 -1
- package/dist/esm/transformSWC.test.mjs +75 -0
- package/dist/esm/transformSWC.test.mjs.map +1 -0
- package/dist/esm/transformWorklets.mjs +81 -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 +45 -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 +196 -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 +10 -6
- package/src/cache.ts +9 -2
- package/src/configure.ts +12 -0
- package/src/index.ts +93 -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/transformHermesLoops.test.ts +282 -0
- package/src/transformHermesLoops.ts +433 -0
- package/src/transformSWC.test.ts +88 -0
- package/src/transformSWC.ts +109 -160
- 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 +125 -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 +282 -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 +3 -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/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 +12 -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 +22 -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 +3 -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 +6 -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,6 +51,7 @@ 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
|
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,6 +20,15 @@ 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);
|
|
@@ -35,10 +46,15 @@ var import_css_to_rn = require("react-native-css-interop/css-to-rn/index.js");
|
|
|
35
46
|
var import_configure = require("./configure.cjs");
|
|
36
47
|
var import_constants = require("./constants.cjs");
|
|
37
48
|
var import_transformBabel = require("./transformBabel.cjs");
|
|
49
|
+
var import_transformSWC = require("./transformSWC.cjs");
|
|
50
|
+
var import_transformWorklets = require("./transformWorklets.cjs");
|
|
38
51
|
var import_cache = require("./cache.cjs");
|
|
39
52
|
__reExport(index_exports, require("./configure.cjs"), module.exports);
|
|
40
53
|
__reExport(index_exports, require("./transformBabel.cjs"), module.exports);
|
|
41
54
|
__reExport(index_exports, require("./transformSWC.cjs"), module.exports);
|
|
55
|
+
__reExport(index_exports, require("./transformWorklets.cjs"), module.exports);
|
|
56
|
+
__reExport(index_exports, require("./reactNativeCodegen.cjs"), module.exports);
|
|
57
|
+
__reExport(index_exports, require("./transformHermesLoops.cjs"), module.exports);
|
|
42
58
|
const import_meta = {};
|
|
43
59
|
const perfStats = {
|
|
44
60
|
babel: {
|
|
@@ -125,7 +141,7 @@ async function performBabelTransform({
|
|
|
125
141
|
if (userTransform === false) {
|
|
126
142
|
return null;
|
|
127
143
|
}
|
|
128
|
-
if (userTransform !== "swc") {
|
|
144
|
+
if (userTransform !== "swc" && userTransform !== "oxc") {
|
|
129
145
|
const babelOptions = (0, import_transformBabel.getBabelOptions)({
|
|
130
146
|
...transformProps,
|
|
131
147
|
userSetting: userTransform
|
|
@@ -142,10 +158,72 @@ async function performBabelTransform({
|
|
|
142
158
|
(0, import_constants.debug)?.(`[babel/cached] ${id}`);
|
|
143
159
|
return cached;
|
|
144
160
|
}
|
|
145
|
-
|
|
146
|
-
const
|
|
161
|
+
let compilerOut = null;
|
|
162
|
+
const compilerPluginIndex = babelOptions.plugins?.findIndex(x => Array.isArray(x) && x[0] === "babel-plugin-react-compiler") ?? -1;
|
|
163
|
+
if (compilerPluginIndex !== -1) {
|
|
164
|
+
const compilerTarget = babelOptions.plugins[compilerPluginIndex][1]?.target ?? "19";
|
|
165
|
+
compilerOut = await (0, import_transformBabel.transformOxcReactCompiler)(id, code, compilerTarget, (0, import_transformSWC.shouldSourceMap)());
|
|
166
|
+
babelOptions.plugins.splice(compilerPluginIndex, 1);
|
|
167
|
+
}
|
|
168
|
+
let curCode = compilerOut ? compilerOut.code : code;
|
|
169
|
+
let workletsOut = null;
|
|
170
|
+
const isWorkletPlugin = entry => {
|
|
171
|
+
if (!entry) return false;
|
|
172
|
+
const name = typeof entry === "string" ? entry : Array.isArray(entry) ? entry[0] : null;
|
|
173
|
+
return typeof name === "string" && (name.includes("react-native-worklets") || name.includes("react-native-reanimated"));
|
|
174
|
+
};
|
|
175
|
+
const workletPluginIndex = babelOptions.plugins?.findIndex(isWorkletPlugin) ?? -1;
|
|
176
|
+
let workletPluginOptions = void 0;
|
|
177
|
+
if (workletPluginIndex !== -1) {
|
|
178
|
+
const entry = babelOptions.plugins[workletPluginIndex];
|
|
179
|
+
if (Array.isArray(entry) && entry[1] && typeof entry[1] === "object") {
|
|
180
|
+
workletPluginOptions = entry[1];
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
if ((0, import_configure.isNativeWorkletsEnabled)() && (workletPluginIndex !== -1 || (0, import_transformWorklets.shouldTransformWorklets)({
|
|
184
|
+
id,
|
|
185
|
+
code: curCode
|
|
186
|
+
}))) {
|
|
187
|
+
workletsOut = await (0, import_transformWorklets.transformWorklets)(id, curCode, (0, import_transformSWC.shouldSourceMap)(), {
|
|
188
|
+
projectRoot,
|
|
189
|
+
...workletPluginOptions
|
|
190
|
+
});
|
|
191
|
+
if (workletPluginIndex !== -1) {
|
|
192
|
+
babelOptions.plugins.splice(workletPluginIndex, 1);
|
|
193
|
+
}
|
|
194
|
+
curCode = workletsOut.code;
|
|
195
|
+
}
|
|
147
196
|
const startTime = Date.now();
|
|
148
|
-
|
|
197
|
+
let babelOut = null;
|
|
198
|
+
if (babelOptions.plugins?.length === 0) {
|
|
199
|
+
let finalMap = void 0;
|
|
200
|
+
if ((0, import_transformSWC.shouldSourceMap)()) {
|
|
201
|
+
const intermediateMaps = [compilerOut?.map, workletsOut?.map].filter(Boolean);
|
|
202
|
+
if (intermediateMaps.length === 1) {
|
|
203
|
+
finalMap = intermediateMaps[0];
|
|
204
|
+
} else if (intermediateMaps.length > 1) {
|
|
205
|
+
const remapping = (await import("@jridgewell/remapping")).default;
|
|
206
|
+
finalMap = remapping(intermediateMaps.slice().reverse(), () => null);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
babelOut = {
|
|
210
|
+
code: curCode,
|
|
211
|
+
map: finalMap
|
|
212
|
+
};
|
|
213
|
+
} else {
|
|
214
|
+
const babelOptsWithMap = (0, import_transformSWC.shouldSourceMap)() && (workletsOut?.map || compilerOut?.map) ? {
|
|
215
|
+
...babelOptions,
|
|
216
|
+
sourceMaps: true
|
|
217
|
+
} : babelOptions;
|
|
218
|
+
babelOut = await (0, import_transformBabel.transformBabel)(id, curCode, babelOptsWithMap);
|
|
219
|
+
if ((0, import_transformSWC.shouldSourceMap)() && babelOut?.map) {
|
|
220
|
+
const priorMaps = [compilerOut?.map, workletsOut?.map].filter(Boolean);
|
|
221
|
+
if (priorMaps.length > 0) {
|
|
222
|
+
const remapping = (await import("@jridgewell/remapping")).default;
|
|
223
|
+
babelOut.map = remapping([babelOut.map, ...priorMaps.slice().reverse()], () => null);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
}
|
|
149
227
|
const babelTime = Date.now() - startTime;
|
|
150
228
|
if (babelOut?.code) {
|
|
151
229
|
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
|
+
}
|