@vxrn/compiler 1.14.4 → 1.15.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/cjs/cache.cjs +65 -44
- package/dist/cjs/configure.cjs +16 -14
- package/dist/cjs/constants.cjs +55 -53
- package/dist/cjs/index.cjs +217 -136
- package/dist/cjs/refresh-runtime.cjs +284 -125
- package/dist/cjs/transformBabel.cjs +180 -95
- package/dist/cjs/transformSWC.cjs +188 -131
- package/dist/cjs/types.cjs +7 -5
- package/dist/esm/cache.mjs +49 -30
- package/dist/esm/cache.mjs.map +1 -1
- package/dist/esm/configure.mjs +4 -4
- package/dist/esm/constants.mjs +43 -43
- package/dist/esm/constants.mjs.map +1 -1
- package/dist/esm/index.js +182 -103
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/index.mjs +182 -103
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/refresh-runtime.mjs +272 -115
- package/dist/esm/refresh-runtime.mjs.map +1 -1
- package/dist/esm/transformBabel.mjs +151 -68
- package/dist/esm/transformBabel.mjs.map +1 -1
- package/dist/esm/transformSWC.mjs +171 -116
- package/dist/esm/transformSWC.mjs.map +1 -1
- package/package.json +4 -4
|
@@ -2,145 +2,230 @@ var __create = Object.create;
|
|
|
2
2
|
var __defProp = Object.defineProperty;
|
|
3
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getProtoOf = Object.getPrototypeOf
|
|
6
|
-
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
7
|
var __export = (target, all) => {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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, {
|
|
15
16
|
get: () => from[key],
|
|
16
17
|
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
17
18
|
});
|
|
18
|
-
|
|
19
|
-
|
|
19
|
+
}
|
|
20
|
+
return to;
|
|
21
|
+
};
|
|
20
22
|
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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);
|
|
32
34
|
var transformBabel_exports = {};
|
|
33
35
|
__export(transformBabel_exports, {
|
|
34
36
|
getBabelOptions: () => getBabelOptions,
|
|
35
37
|
transformBabel: () => transformBabel
|
|
36
38
|
});
|
|
37
39
|
module.exports = __toCommonJS(transformBabel_exports);
|
|
38
|
-
var import_node_path = require("node:path")
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
40
|
+
var import_node_path = require("node:path");
|
|
41
|
+
var import_core = __toESM(require("@babel/core"), 1);
|
|
42
|
+
var import_utils = require("@vxrn/utils");
|
|
43
|
+
var import_configure = require("./configure.cjs");
|
|
44
|
+
var import_constants = require("./constants.cjs");
|
|
43
45
|
function getBabelOptions(props) {
|
|
44
|
-
|
|
46
|
+
if (props.userSetting === "babel") {
|
|
47
|
+
return getOptions(props, true);
|
|
48
|
+
}
|
|
49
|
+
if (typeof props.userSetting === "undefined" || typeof props.userSetting === "object" && props.userSetting.transform === "babel") {
|
|
50
|
+
if (props.userSetting?.excludeDefaultPlugins) {
|
|
51
|
+
return props.userSetting;
|
|
52
|
+
}
|
|
53
|
+
return getOptions(props);
|
|
54
|
+
}
|
|
55
|
+
return null;
|
|
45
56
|
}
|
|
46
|
-
const getOptions = (props, force =
|
|
57
|
+
const getOptions = (props, force = false) => {
|
|
47
58
|
let plugins = [];
|
|
48
|
-
(force || shouldBabelGenerators(props))
|
|
59
|
+
if (force || shouldBabelGenerators(props)) {
|
|
60
|
+
plugins = getBasePlugins(props);
|
|
61
|
+
}
|
|
49
62
|
const enableNativewind = import_configure.configuration.enableNativewind && (props.environment === "ios" || props.environment === "android") &&
|
|
50
63
|
// if reanimated gets wrapped in transform it causes circular dep issues
|
|
51
64
|
!/node_modules/.test(props.id) &&
|
|
52
65
|
// only needed for createElement calls, so be a bit conservative
|
|
53
66
|
props.code.includes("createElement");
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
}
|
|
67
|
+
if (enableNativewind) {
|
|
68
|
+
if (!props.id.includes("node_modules")) {
|
|
69
|
+
plugins.push((0, import_utils.resolvePath)("react-native-css-interop/dist/babel-plugin.js"));
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
if (enableNativewind || shouldBabelReanimated(props)) {
|
|
73
|
+
(0, import_constants.debug)?.(`Using babel reanimated on file ${props.id}`);
|
|
74
|
+
plugins.push(
|
|
75
|
+
// TODO make this configurable
|
|
76
|
+
process.env.VXRN_WORKLET_PLUGIN ? "react-native-worklets/plugin" : "react-native-reanimated/plugin");
|
|
77
|
+
}
|
|
78
|
+
if (shouldBabelReactCompiler(props)) {
|
|
79
|
+
(0, import_constants.debug)?.(`Using babel react compiler on file`);
|
|
80
|
+
plugins.push(getBabelReactCompilerPlugin(props));
|
|
81
|
+
}
|
|
82
|
+
if (shouldBabelReactNativeCodegen(props)) {
|
|
83
|
+
(0, import_constants.debug)?.(`Using babel @react-native/babel-plugin-codegen on file`);
|
|
84
|
+
plugins.push("@react-native/babel-plugin-codegen");
|
|
85
|
+
}
|
|
86
|
+
if (plugins.length) {
|
|
87
|
+
return {
|
|
88
|
+
plugins
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
return null;
|
|
59
92
|
};
|
|
60
93
|
async function transformBabel(id, code, options) {
|
|
61
|
-
const extension = (0, import_node_path.extname)(id)
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
}
|
|
94
|
+
const extension = (0, import_node_path.extname)(id);
|
|
95
|
+
const isTSX = extension === ".tsx";
|
|
96
|
+
const isTS = isTSX || extension === ".ts";
|
|
97
|
+
const babelOptions = {
|
|
98
|
+
filename: id,
|
|
99
|
+
compact: false,
|
|
100
|
+
babelrc: false,
|
|
101
|
+
configFile: false,
|
|
102
|
+
sourceMaps: false,
|
|
103
|
+
minified: false,
|
|
104
|
+
...options,
|
|
105
|
+
presets: [isTS ? ["@babel/preset-typescript", {
|
|
106
|
+
isTSX,
|
|
107
|
+
allExtensions: isTSX
|
|
108
|
+
}] : "", ...(options.presets || [])].filter(Boolean)
|
|
109
|
+
};
|
|
76
110
|
try {
|
|
77
|
-
|
|
111
|
+
const out = await new Promise((res, rej) => {
|
|
78
112
|
import_core.default.transform(code, babelOptions, (err, result) => {
|
|
79
|
-
if (!result || err)
|
|
113
|
+
if (!result || err) {
|
|
114
|
+
return rej(err || "no res");
|
|
115
|
+
}
|
|
80
116
|
res(result);
|
|
81
117
|
});
|
|
82
118
|
});
|
|
119
|
+
return out;
|
|
83
120
|
} catch (err) {
|
|
84
|
-
if (err?.message?.includes("Could not find component config"))
|
|
85
|
-
|
|
121
|
+
if (err?.message?.includes("Could not find component config")) {
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
console.error(`[vxrn:compiler] babel transform error`, err, `with options`, babelOptions);
|
|
125
|
+
console.error("code", code);
|
|
126
|
+
console.error("id", id);
|
|
86
127
|
}
|
|
87
128
|
}
|
|
88
129
|
const getBasePlugins = ({
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
130
|
+
development
|
|
131
|
+
}) => [["@babel/plugin-transform-destructuring"], ["@babel/plugin-transform-react-jsx", {
|
|
132
|
+
development
|
|
133
|
+
}], ["@babel/plugin-transform-async-generator-functions"], ["@babel/plugin-transform-async-to-generator"], ["@babel/plugin-transform-runtime", {
|
|
134
|
+
helpers: true,
|
|
135
|
+
// NOTE THIS WAS SPELLED WRONG BEFOER THIS COMMIT MAYBE IT WAS UNINTENTIONALLY WORKING
|
|
136
|
+
regenerator: false
|
|
137
|
+
}]];
|
|
138
|
+
const NATIVE_COMPONENT_RE = /NativeComponent\.[jt]sx?$/;
|
|
139
|
+
const SPEC_FILE_RE = /[/\\]specs?[/\\]/;
|
|
140
|
+
const shouldBabelReactNativeCodegen = ({
|
|
141
|
+
id,
|
|
142
|
+
environment
|
|
143
|
+
}) => {
|
|
144
|
+
return (environment === "ios" || environment === "android") && (NATIVE_COMPONENT_RE.test(id) || SPEC_FILE_RE.test(id));
|
|
145
|
+
};
|
|
146
|
+
const shouldBabelReactCompiler = props => {
|
|
147
|
+
if (props.environment === "ssr") {
|
|
148
|
+
return false;
|
|
149
|
+
}
|
|
150
|
+
if (!import_configure.configuration.enableCompiler) {
|
|
151
|
+
return false;
|
|
152
|
+
}
|
|
153
|
+
const {
|
|
154
|
+
enableCompiler
|
|
155
|
+
} = import_configure.configuration;
|
|
156
|
+
if (typeof enableCompiler === "object" && !Array.isArray(enableCompiler) && !(enableCompiler instanceof RegExp)) {
|
|
157
|
+
const isNative = props.environment === "ios" || props.environment === "android";
|
|
158
|
+
const filter = isNative ? enableCompiler.native : enableCompiler.web;
|
|
159
|
+
if (!filter) return false;
|
|
160
|
+
return applyCompilerFilter(filter, props);
|
|
161
|
+
}
|
|
162
|
+
if (typeof enableCompiler === "function") {
|
|
163
|
+
return enableCompiler(props.id, props.environment);
|
|
164
|
+
}
|
|
165
|
+
if (enableCompiler instanceof RegExp) {
|
|
166
|
+
return enableCompiler.test(props.id);
|
|
167
|
+
}
|
|
168
|
+
if (Array.isArray(enableCompiler)) {
|
|
169
|
+
if (!enableCompiler.includes(props.environment)) {
|
|
170
|
+
return false;
|
|
111
171
|
}
|
|
112
|
-
|
|
113
|
-
|
|
172
|
+
}
|
|
173
|
+
return applyDefaultFilters(props);
|
|
174
|
+
};
|
|
114
175
|
function applyCompilerFilter(filter, props) {
|
|
115
|
-
|
|
176
|
+
if (typeof filter === "function") {
|
|
177
|
+
return filter(props.id, props.environment);
|
|
178
|
+
}
|
|
179
|
+
if (filter instanceof RegExp) {
|
|
180
|
+
return filter.test(props.id);
|
|
181
|
+
}
|
|
182
|
+
if (filter === true) {
|
|
183
|
+
return applyDefaultFilters(props);
|
|
184
|
+
}
|
|
185
|
+
return false;
|
|
116
186
|
}
|
|
117
187
|
function applyDefaultFilters(props) {
|
|
118
|
-
|
|
188
|
+
if (!/(\.tsx?)$/.test(props.id)) return false;
|
|
189
|
+
if (props.id.includes("node_modules")) return false;
|
|
190
|
+
if (props.id.includes("+api.")) return false;
|
|
191
|
+
if (props.code.startsWith("// disable-compiler")) return false;
|
|
192
|
+
return true;
|
|
119
193
|
}
|
|
120
|
-
const getBabelReactCompilerPlugin = props =>
|
|
121
|
-
target
|
|
122
|
-
|
|
194
|
+
const getBabelReactCompilerPlugin = props => {
|
|
195
|
+
const target = props.reactForRNVersion === "18" && (props.environment === "ios" || props.environment === "android") ? "18" : "19";
|
|
196
|
+
return ["babel-plugin-react-compiler", {
|
|
197
|
+
target
|
|
198
|
+
}];
|
|
199
|
+
};
|
|
123
200
|
function shouldBabelGenerators({
|
|
124
201
|
code
|
|
125
202
|
}) {
|
|
126
|
-
if (process.env.VXRN_USE_BABEL_FOR_GENERATORS)
|
|
203
|
+
if (process.env.VXRN_USE_BABEL_FOR_GENERATORS) {
|
|
204
|
+
return import_constants.asyncGeneratorRegex.test(code);
|
|
205
|
+
}
|
|
127
206
|
}
|
|
128
|
-
const REANIMATED_AUTOWORKLETIZATION_KEYWORDS = ["worklet", "useAnimatedGestureHandler", "useAnimatedScrollHandler", "useFrameCallback", "useAnimatedStyle", "useAnimatedProps", "createAnimatedPropAdapter", "useDerivedValue", "useAnimatedReaction", "useWorkletCallback", "withTiming", "withSpring", "withDecay", "withRepeat", "runOnUI", "executeOnUIRuntimeSync"]
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
207
|
+
const REANIMATED_AUTOWORKLETIZATION_KEYWORDS = ["worklet", "useAnimatedGestureHandler", "useAnimatedScrollHandler", "useFrameCallback", "useAnimatedStyle", "useAnimatedProps", "createAnimatedPropAdapter", "useDerivedValue", "useAnimatedReaction", "useWorkletCallback", "withTiming", "withSpring", "withDecay", "withRepeat", "runOnUI", "executeOnUIRuntimeSync"];
|
|
208
|
+
const REANIMATED_REGEX = new RegExp(REANIMATED_AUTOWORKLETIZATION_KEYWORDS.join("|"));
|
|
209
|
+
const REANIMATED_IGNORED_PATHS = [
|
|
210
|
+
// Prebuilt/vendored react-native that shouldn't be transformed
|
|
211
|
+
"react-native-prebuilt", "node_modules/.vxrn/react-native",
|
|
212
|
+
// Known false positives - they mention worklet keywords in comments/strings but don't use them
|
|
213
|
+
"node_modules/react/", "node_modules/react-dom/", "node_modules/react-native/", "node_modules/react-native-web/"];
|
|
214
|
+
const REANIMATED_IGNORED_PATHS_REGEX = new RegExp(REANIMATED_IGNORED_PATHS.map(s => s.replace(/\//g, "/")).join("|"));
|
|
136
215
|
function shouldBabelReanimated({
|
|
137
216
|
code,
|
|
138
217
|
id
|
|
139
218
|
}) {
|
|
140
|
-
if (!import_configure.configuration.enableReanimated
|
|
219
|
+
if (!import_configure.configuration.enableReanimated) {
|
|
220
|
+
return false;
|
|
221
|
+
}
|
|
222
|
+
if (REANIMATED_IGNORED_PATHS_REGEX.test(id)) {
|
|
223
|
+
return false;
|
|
224
|
+
}
|
|
141
225
|
if (REANIMATED_REGEX.test(code)) {
|
|
142
226
|
const location = id.includes("node_modules") ? "node_modules" : "user-code";
|
|
143
|
-
|
|
227
|
+
(0, import_constants.debug)?.(` \u{1FA84} [reanimated/${location}] ${(0, import_node_path.relative)(process.cwd(), id)}`);
|
|
228
|
+
return true;
|
|
144
229
|
}
|
|
145
|
-
return
|
|
230
|
+
return false;
|
|
146
231
|
}
|