@vxrn/compiler 1.14.4 → 1.14.5

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.
@@ -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
- __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __getProtoOf = Object.getPrototypeOf;
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: !0
11
- });
12
- },
13
- __copyProps = (to, from, except, desc) => {
14
- if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
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
- return to;
19
- };
19
+ }
20
+ return to;
21
+ };
20
22
  var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
26
- value: mod,
27
- enumerable: !0
28
- }) : target, mod)),
29
- __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
30
- value: !0
31
- }), mod);
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
- import_core = __toESM(require("@babel/core"), 1),
40
- import_utils = require("@vxrn/utils"),
41
- import_configure = require("./configure.cjs"),
42
- import_constants = require("./constants.cjs");
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
- return props.userSetting === "babel" ? getOptions(props, !0) : typeof props.userSetting > "u" || typeof props.userSetting == "object" && props.userSetting.transform === "babel" ? props.userSetting?.excludeDefaultPlugins ? props.userSetting : getOptions(props) : null;
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 = !1) => {
57
+ const getOptions = (props, force = false) => {
47
58
  let plugins = [];
48
- (force || shouldBabelGenerators(props)) && (plugins = getBasePlugins(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
- return enableNativewind && (props.id.includes("node_modules") || plugins.push((0, import_utils.resolvePath)("react-native-css-interop/dist/babel-plugin.js"))), (enableNativewind || shouldBabelReanimated(props)) && ((0, import_constants.debug)?.(`Using babel reanimated on file ${props.id}`), plugins.push(
55
- // TODO make this configurable
56
- process.env.VXRN_WORKLET_PLUGIN ? "react-native-worklets/plugin" : "react-native-reanimated/plugin")), shouldBabelReactCompiler(props) && ((0, import_constants.debug)?.("Using babel react compiler on file"), plugins.push(getBabelReactCompilerPlugin(props))), shouldBabelReactNativeCodegen(props) && ((0, import_constants.debug)?.("Using babel @react-native/babel-plugin-codegen on file"), plugins.push("@react-native/babel-plugin-codegen")), plugins.length ? {
57
- plugins
58
- } : null;
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
- isTSX = extension === ".tsx",
63
- babelOptions = {
64
- filename: id,
65
- compact: !1,
66
- babelrc: !1,
67
- configFile: !1,
68
- sourceMaps: !1,
69
- minified: !1,
70
- ...options,
71
- presets: [isTSX || extension === ".ts" ? ["@babel/preset-typescript", {
72
- isTSX,
73
- allExtensions: isTSX
74
- }] : "", ...(options.presets || [])].filter(Boolean)
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
- return await new Promise((res, rej) => {
111
+ const out = await new Promise((res, rej) => {
78
112
  import_core.default.transform(code, babelOptions, (err, result) => {
79
- if (!result || err) return rej(err || "no res");
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")) return;
85
- console.error("[vxrn:compiler] babel transform error", err, "with options", babelOptions), console.error("code", code), console.error("id", id);
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
- development
90
- }) => [["@babel/plugin-transform-destructuring"], ["@babel/plugin-transform-react-jsx", {
91
- development
92
- }], ["@babel/plugin-transform-async-generator-functions"], ["@babel/plugin-transform-async-to-generator"], ["@babel/plugin-transform-runtime", {
93
- helpers: !0,
94
- // NOTE THIS WAS SPELLED WRONG BEFOER THIS COMMIT MAYBE IT WAS UNINTENTIONALLY WORKING
95
- regenerator: !1
96
- }]],
97
- NATIVE_COMPONENT_RE = /NativeComponent\.[jt]sx?$/,
98
- SPEC_FILE_RE = /[/\\]specs?[/\\]/,
99
- shouldBabelReactNativeCodegen = ({
100
- id,
101
- environment
102
- }) => (environment === "ios" || environment === "android") && (NATIVE_COMPONENT_RE.test(id) || SPEC_FILE_RE.test(id)),
103
- shouldBabelReactCompiler = props => {
104
- if (props.environment === "ssr" || !import_configure.configuration.enableCompiler) return !1;
105
- const {
106
- enableCompiler
107
- } = import_configure.configuration;
108
- if (typeof enableCompiler == "object" && !Array.isArray(enableCompiler) && !(enableCompiler instanceof RegExp)) {
109
- const filter = props.environment === "ios" || props.environment === "android" ? enableCompiler.native : enableCompiler.web;
110
- return filter ? applyCompilerFilter(filter, props) : !1;
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
- return typeof enableCompiler == "function" ? enableCompiler(props.id, props.environment) : enableCompiler instanceof RegExp ? enableCompiler.test(props.id) : Array.isArray(enableCompiler) && !enableCompiler.includes(props.environment) ? !1 : applyDefaultFilters(props);
113
- };
172
+ }
173
+ return applyDefaultFilters(props);
174
+ };
114
175
  function applyCompilerFilter(filter, props) {
115
- return typeof filter == "function" ? filter(props.id, props.environment) : filter instanceof RegExp ? filter.test(props.id) : filter === !0 ? applyDefaultFilters(props) : !1;
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
- return !(!/(\.tsx?)$/.test(props.id) || props.id.includes("node_modules") || props.id.includes("+api.") || props.code.startsWith("// disable-compiler"));
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 => ["babel-plugin-react-compiler", {
121
- target: props.reactForRNVersion === "18" && (props.environment === "ios" || props.environment === "android") ? "18" : "19"
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) return import_constants.asyncGeneratorRegex.test(code);
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
- REANIMATED_REGEX = new RegExp(REANIMATED_AUTOWORKLETIZATION_KEYWORDS.join("|")),
130
- REANIMATED_IGNORED_PATHS = [
131
- // Prebuilt/vendored react-native that shouldn't be transformed
132
- "react-native-prebuilt", "node_modules/.vxrn/react-native",
133
- // Known false positives - they mention worklet keywords in comments/strings but don't use them
134
- "node_modules/react/", "node_modules/react-dom/", "node_modules/react-native/", "node_modules/react-native-web/"],
135
- REANIMATED_IGNORED_PATHS_REGEX = new RegExp(REANIMATED_IGNORED_PATHS.map(s => s.replace(/\//g, "/")).join("|"));
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 || REANIMATED_IGNORED_PATHS_REGEX.test(id)) return !1;
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
- return (0, import_constants.debug)?.(` \u{1FA84} [reanimated/${location}] ${(0, import_node_path.relative)(process.cwd(), id)}`), !0;
227
+ (0, import_constants.debug)?.(` \u{1FA84} [reanimated/${location}] ${(0, import_node_path.relative)(process.cwd(), id)}`);
228
+ return true;
144
229
  }
145
- return !1;
230
+ return false;
146
231
  }