diff --git a/__tests__/__snapshots__/plugin.test.ts.snap b/__tests__/__snapshots__/plugin.test.ts.snap
index 44e740a54ac9..722be4b8aceb 100644
--- a/__tests__/__snapshots__/plugin.test.ts.snap
+++ b/__tests__/__snapshots__/plugin.test.ts.snap
@@ -1,33 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
-exports[`babel plugin captures worklets environment 1`] = `
-"var x = 5;
-var objX = {
- x: x
-};
-var _worklet_5359970077727_init_data = {
- code: "function f(){const{x,objX}=this._closure;return{res:x+objX.x};}",
- location: "/dev/null"
-};
-var f = function () {
- var _e = [new global.Error(), -3, -27];
- var _f = function _f() {
- return {
- res: x + objX.x
- };
- };
- _f._closure = {
- x: x,
- objX: objX
- };
- _f.__initData = _worklet_5359970077727_init_data;
- _f.__workletHash = 5359970077727;
- _f.__stackDetails = _e;
- return _f;
-}();"
-`;
-
-exports[`babel plugin doesn't bother other Directive Literals 1`] = `
+exports[`babel plugin for DirectiveLiterals doesn't bother other Directive Literals 1`] = `
"function foo() {
'foobar';
@@ -35,88 +8,13 @@ exports[`babel plugin doesn't bother other Directive Literals 1`] = `
}"
`;
-exports[`babel plugin doesn't capture globals 1`] = `
-"var _worklet_13298016111221_init_data = {
- code: "function f(){console.log('test');}",
- location: "/dev/null"
-};
-var f = function () {
- var _e = [new global.Error(), 1, -27];
- var _f = function _f() {
- console.log('test');
- };
- _f._closure = {};
- _f.__initData = _worklet_13298016111221_init_data;
- _f.__workletHash = 13298016111221;
- _f.__stackDetails = _e;
- return _f;
-}();"
-`;
-
-exports[`babel plugin doesn't nest worklets for other threads 1`] = `
-"var _worklet_1678749606628_init_data = {
- code: "function foo(x){function bar(x){'worklet';return x+2;}return bar(x)+1;}",
- location: "/dev/null"
-};
-var _worklet_16974800582491_init_data = {
- code: "function bar(x){return x+2;}",
- location: "/dev/null"
-};
-var foo = function () {
- var _e = [new global.Error(), 1, -27];
- var _f = function _f(x) {
- var bar = function () {
- var _e = [new global.Error(), 1, -27];
- var _f = function _f(x) {
- return x + 2;
- };
- _f._closure = {};
- _f.__initData = _worklet_16974800582491_init_data;
- _f.__workletHash = 16974800582491;
- _f.__stackDetails = _e;
- return _f;
- }();
- return bar(x) + 1;
- };
- _f._closure = {};
- _f.__initData = _worklet_1678749606628_init_data;
- _f.__workletHash = 1678749606628;
- _f.__stackDetails = _e;
- return _f;
-}();"
-`;
-
-exports[`babel plugin doesn't show a warning if user writes something like style={styles.value} 1`] = `
-"function App() {
- return React.createElement(Animated.View, {
- style: styles.value
- });
-}"
-`;
-
-exports[`babel plugin doesn't transform ArrowFunctionExpression as argument of useAnimatedGestureHandler 1`] = `"useAnimatedGestureHandler(function () {});"`;
-
-exports[`babel plugin doesn't transform chained methods of objects containing Gesture property 1`] = `
-"var foo = Something.Gesture.Tap().onEnd(function () {
- console.log('onEnd');
-});"
-`;
-
-exports[`babel plugin doesn't transform functions without 'worklet' directive 1`] = `
+exports[`babel plugin for DirectiveLiterals doesn't transform functions without 'worklet' directive 1`] = `
"function f(x) {
return x + 2;
}"
`;
-exports[`babel plugin doesn't transform named FunctionExpression as argument of useAnimatedGestureHandler 1`] = `"useAnimatedGestureHandler(function foo() {});"`;
-
-exports[`babel plugin doesn't transform standard callback functions 1`] = `
-"var foo = Something.Tap().onEnd(function (_event, _success) {
- console.log('onEnd');
-});"
-`;
-
-exports[`babel plugin doesn't transform string literals 1`] = `
+exports[`babel plugin for DirectiveLiterals doesn't transform string literals 1`] = `
"var _worklet_9810417751380_init_data = {
code: "function foo(x){const bar='worklet';const baz=\\"worklet\\";}",
location: "/dev/null"
@@ -135,11 +33,7 @@ var foo = function () {
}();"
`;
-exports[`babel plugin doesn't transform unnamed FunctionExpression as argument of useAnimatedGestureHandler 1`] = `"useAnimatedGestureHandler(function () {});"`;
-
-exports[`babel plugin doesn't workletize irrelevant chained gesture object callback functions 1`] = `"var foo = Gesture.Tap().toString();"`;
-
-exports[`babel plugin removes "worklet"; directive from worklets 1`] = `
+exports[`babel plugin for DirectiveLiterals removes "worklet"; directive from worklets 1`] = `
"var _worklet_4679479961836_init_data = {
code: "function foo(x){return x+2;}",
location: "/dev/null"
@@ -157,7 +51,7 @@ var foo = function () {
}();"
`;
-exports[`babel plugin removes 'worklet'; directive from worklets 1`] = `
+exports[`babel plugin for DirectiveLiterals removes 'worklet'; directive from worklets 1`] = `
"var _worklet_4679479961836_init_data = {
code: "function foo(x){return x+2;}",
location: "/dev/null"
@@ -175,227 +69,515 @@ var foo = function () {
}();"
`;
-exports[`babel plugin removes comments from worklets 1`] = `
-"var _worklet_235615426006_init_data = {
- code: "function anonymous(){return true;}",
+exports[`babel plugin for UIRuntimeChecks changes _WORKLET and global._WORKLET in worklets 1`] = `
+"var _worklet_138651347916_init_data = {
+ code: "function foo(){if(true&&true){return 1;}}",
location: "/dev/null"
};
-var f = function () {
+var foo = function () {
var _e = [new global.Error(), 1, -27];
var _f = function _f() {
- return true;
+ if (_WORKLET && global._WORKLET) {
+ return 1;
+ }
};
_f._closure = {};
- _f.__initData = _worklet_235615426006_init_data;
- _f.__workletHash = 235615426006;
+ _f.__initData = _worklet_138651347916_init_data;
+ _f.__workletHash = 138651347916;
_f.__stackDetails = _e;
return _f;
}();"
`;
-exports[`babel plugin shows a warning if user uses .value inside inline style 1`] = `
-"function App() {
- return React.createElement(Animated.View, {
- style: {
- width: function () {
- console.warn(require("react-native-reanimated").getUseOfValueInStyleWarning());
- return sharedValue.value;
- }()
+exports[`babel plugin for UIRuntimeChecks changes _WORKLET in worklets 1`] = `
+"var _worklet_13060407119290_init_data = {
+ code: "function foo(){if(true){return 1;}}",
+ location: "/dev/null"
+};
+var foo = function () {
+ var _e = [new global.Error(), 1, -27];
+ var _f = function _f() {
+ if (_WORKLET) {
+ return 1;
}
- });
-}"
-`;
-
-exports[`babel plugin shows a warning if user uses .value inside inline style, style array 1`] = `
-"function App() {
- return React.createElement(Animated.View, {
- style: [style, {
- width: function () {
- console.warn(require("react-native-reanimated").getUseOfValueInStyleWarning());
- return sharedValue.value;
- }()
- }]
- });
-}"
+ };
+ _f._closure = {};
+ _f.__initData = _worklet_13060407119290_init_data;
+ _f.__workletHash = 13060407119290;
+ _f.__stackDetails = _e;
+ return _f;
+}();"
`;
-exports[`babel plugin shows a warning if user uses .value inside inline style, transforms 1`] = `
-"function App() {
- return React.createElement(Animated.View, {
- style: {
- transform: [{
- translateX: function () {
- console.warn(require("react-native-reanimated").getUseOfValueInStyleWarning());
- return sharedValue.value;
- }()
- }]
+exports[`babel plugin for UIRuntimeChecks changes global._WORKLET in worklets 1`] = `
+"var _worklet_13060407119290_init_data = {
+ code: "function foo(){if(true){return 1;}}",
+ location: "/dev/null"
+};
+var foo = function () {
+ var _e = [new global.Error(), 1, -27];
+ var _f = function _f() {
+ if (global._WORKLET) {
+ return 1;
}
- });
-}"
+ };
+ _f._closure = {};
+ _f.__initData = _worklet_13060407119290_init_data;
+ _f.__workletHash = 13060407119290;
+ _f.__stackDetails = _e;
+ return _f;
+}();"
`;
-exports[`babel plugin supports SequenceExpression 1`] = `
-"function App() {
- (0, fun)({
- onStart: function onStart() {}
- }, []);
+exports[`babel plugin for UIRuntimeChecks doesn't change _WORKLET in non-worklets 1`] = `
+"function foo() {
+ if (_WORKLET) {
+ return 1;
+ }
}"
`;
-exports[`babel plugin supports SequenceExpression, many arguments 1`] = `
-"var _worklet_4434179069699_init_data = {
- code: "function onStart(){}",
- location: "/dev/null"
-};
-function App() {
- (0, 3, fun)({
- onStart: function () {
- var _e = [new global.Error(), 1, -27];
- var _f = function _f() {};
- _f._closure = {};
- _f.__initData = _worklet_4434179069699_init_data;
- _f.__workletHash = 4434179069699;
- _f.__stackDetails = _e;
- return _f;
- }()
- }, []);
+exports[`babel plugin for UIRuntimeChecks doesn't change global._WORKLET in non-worklets 1`] = `
+"function foo() {
+ if (global._WORKLET) {
+ return 1;
+ }
}"
`;
-exports[`babel plugin supports SequenceExpression, with objectHook 1`] = `
-"var _worklet_4434179069699_init_data = {
- code: "function onStart(){}",
+exports[`babel plugin for class worklets workletizes class field 1`] = `
+"var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
+var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
+var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
+var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
+var _worklet_16347365292089_init_data = {
+ code: "function anonymous(x){return x+2;}",
location: "/dev/null"
};
-function App() {
- (0, useAnimatedGestureHandler)({
- onStart: function () {
- var _e = [new global.Error(), 1, -27];
- var _f = function _f() {};
- _f._closure = {};
- _f.__initData = _worklet_4434179069699_init_data;
- _f.__workletHash = 4434179069699;
- _f.__stackDetails = _e;
- return _f;
- }()
- }, []);
-}"
+var Foo = (0, _createClass2.default)(function Foo() {
+ (0, _classCallCheck2.default)(this, Foo);
+ (0, _defineProperty2.default)(this, "bar", function () {
+ var _e = [new global.Error(), 1, -27];
+ var _f = function _f(x) {
+ return x + 2;
+ };
+ _f._closure = {};
+ _f.__initData = _worklet_16347365292089_init_data;
+ _f.__workletHash = 16347365292089;
+ _f.__stackDetails = _e;
+ return _f;
+ }());
+});"
`;
-exports[`babel plugin supports SequenceExpression, with worklet 1`] = `
-"var _worklet_4434179069699_init_data = {
- code: "function onStart(){}",
+exports[`babel plugin for class worklets workletizes constructor 1`] = `
+"var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
+var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
+var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
+var _worklet_14658848071366_init_data = {
+ code: "function Foo(x){const Foo=this._recur;const{_classCallCheck}=this._closure;_classCallCheck(this,Foo);this.x=x;}",
location: "/dev/null"
};
-function App() {
- (0, fun)({
- onStart: function () {
- var _e = [new global.Error(), 1, -27];
- var _f = function _f() {};
- _f._closure = {};
- _f.__initData = _worklet_4434179069699_init_data;
- _f.__workletHash = 4434179069699;
- _f.__stackDetails = _e;
- return _f;
- }()
- }, []);
-}"
+var Foo = (0, _createClass2.default)(function () {
+ var _e = [new global.Error(), -2, -27];
+ var _f = function _f(x) {
+ (0, _classCallCheck2.default)(this, Foo);
+ this.x = x;
+ };
+ _f._closure = {
+ _classCallCheck: _classCallCheck2.default
+ };
+ _f.__initData = _worklet_14658848071366_init_data;
+ _f.__workletHash = 14658848071366;
+ _f.__stackDetails = _e;
+ return _f;
+}());"
`;
-exports[`babel plugin supports SequenceExpression, with worklet closure 1`] = `
-"var _worklet_16676723780973_init_data = {
- code: "function onStart(){const{obj}=this._closure;const a=obj.a;}",
+exports[`babel plugin for class worklets workletizes getter 1`] = `
+"var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
+var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
+var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
+var _worklet_10436985806815_init_data = {
+ code: "function get(){const{x}=this._closure;return x+2;}",
location: "/dev/null"
};
-function App() {
- var obj = {
- a: 1,
- b: 2
- };
- (0, fun)({
- onStart: function () {
+var Foo = function () {
+ function Foo() {
+ (0, _classCallCheck2.default)(this, Foo);
+ }
+ (0, _createClass2.default)(Foo, [{
+ key: "bar",
+ get: function () {
var _e = [new global.Error(), -2, -27];
var _f = function _f() {
- var a = obj.a;
+ return x + 2;
};
_f._closure = {
- obj: obj
+ x: x
};
- _f.__initData = _worklet_16676723780973_init_data;
- _f.__workletHash = 16676723780973;
+ _f.__initData = _worklet_10436985806815_init_data;
+ _f.__workletHash = 10436985806815;
_f.__stackDetails = _e;
return _f;
}()
- }, []);
-}"
+ }]);
+ return Foo;
+}();"
`;
-exports[`babel plugin supports empty object in useAnimatedGestureHandler 1`] = `"useAnimatedGestureHandler({});"`;
+exports[`babel plugin for class worklets workletizes instance method 1`] = `
+"var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
+var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
+var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
+var _worklet_16974800582491_init_data = {
+ code: "function bar(x){return x+2;}",
+ location: "/dev/null"
+};
+var Foo = function () {
+ function Foo() {
+ (0, _classCallCheck2.default)(this, Foo);
+ }
+ (0, _createClass2.default)(Foo, [{
+ key: "bar",
+ value: function () {
+ var _e = [new global.Error(), 1, -27];
+ var _f = function _f(x) {
+ return x + 2;
+ };
+ _f._closure = {};
+ _f.__initData = _worklet_16974800582491_init_data;
+ _f.__workletHash = 16974800582491;
+ _f.__stackDetails = _e;
+ return _f;
+ }()
+ }]);
+ return Foo;
+}();"
+`;
+
+exports[`babel plugin for class worklets workletizes setter 1`] = `
+"var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
+var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
+var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
+var _worklet_6451428689423_init_data = {
+ code: "function set(x){this.x=x+2;}",
+ location: "/dev/null"
+};
+var Foo = function () {
+ function Foo() {
+ (0, _classCallCheck2.default)(this, Foo);
+ }
+ (0, _createClass2.default)(Foo, [{
+ key: "bar",
+ set: function () {
+ var _e = [new global.Error(), 1, -27];
+ var _f = function _f(x) {
+ this.x = x + 2;
+ };
+ _f._closure = {};
+ _f.__initData = _worklet_6451428689423_init_data;
+ _f.__workletHash = 6451428689423;
+ _f.__stackDetails = _e;
+ return _f;
+ }()
+ }]);
+ return Foo;
+}();"
+`;
-exports[`babel plugin supports empty object in useAnimatedScrollHandler 1`] = `"useAnimatedScrollHandler({});"`;
+exports[`babel plugin for class worklets workletizes static class field 1`] = `
+"var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
+var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
+var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
+var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
+var Foo = (0, _createClass2.default)(function Foo() {
+ (0, _classCallCheck2.default)(this, Foo);
+});
+var _worklet_16347365292089_init_data = {
+ code: "function anonymous(x){return x+2;}",
+ location: "/dev/null"
+};
+(0, _defineProperty2.default)(Foo, "bar", function () {
+ var _e = [new global.Error(), 1, -27];
+ var _f = function _f(x) {
+ return x + 2;
+ };
+ _f._closure = {};
+ _f.__initData = _worklet_16347365292089_init_data;
+ _f.__workletHash = 16347365292089;
+ _f.__stackDetails = _e;
+ return _f;
+}());"
+`;
-exports[`babel plugin supports recursive calls 1`] = `
-"var a = 1;
-var _worklet_2022702330805_init_data = {
- code: "function foo(t){const foo=this._recur;const{a}=this._closure;if(t>0){return a+foo(t-1);}}",
+exports[`babel plugin for class worklets workletizes static method 1`] = `
+"var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
+var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
+var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
+var _worklet_16974800582491_init_data = {
+ code: "function bar(x){return x+2;}",
+ location: "/dev/null"
+};
+var Foo = function () {
+ function Foo() {
+ (0, _classCallCheck2.default)(this, Foo);
+ }
+ (0, _createClass2.default)(Foo, null, [{
+ key: "bar",
+ value: function () {
+ var _e = [new global.Error(), 1, -27];
+ var _f = function _f(x) {
+ return x + 2;
+ };
+ _f._closure = {};
+ _f.__initData = _worklet_16974800582491_init_data;
+ _f.__workletHash = 16974800582491;
+ _f.__stackDetails = _e;
+ return _f;
+ }()
+ }]);
+ return Foo;
+}();"
+`;
+
+exports[`babel plugin for closure capturing captures worklets environment 1`] = `
+"var x = 5;
+var objX = {
+ x: x
+};
+var _worklet_5359970077727_init_data = {
+ code: "function f(){const{x,objX}=this._closure;return{res:x+objX.x};}",
+ location: "/dev/null"
+};
+var f = function () {
+ var _e = [new global.Error(), -3, -27];
+ var _f = function _f() {
+ return {
+ res: x + objX.x
+ };
+ };
+ _f._closure = {
+ x: x,
+ objX: objX
+ };
+ _f.__initData = _worklet_5359970077727_init_data;
+ _f.__workletHash = 5359970077727;
+ _f.__stackDetails = _e;
+ return _f;
+}();"
+`;
+
+exports[`babel plugin for closure capturing doesn't capture globals 1`] = `
+"var _worklet_13298016111221_init_data = {
+ code: "function f(){console.log('test');}",
+ location: "/dev/null"
+};
+var f = function () {
+ var _e = [new global.Error(), 1, -27];
+ var _f = function _f() {
+ console.log('test');
+ };
+ _f._closure = {};
+ _f.__initData = _worklet_13298016111221_init_data;
+ _f.__workletHash = 13298016111221;
+ _f.__stackDetails = _e;
+ return _f;
+}();"
+`;
+
+exports[`babel plugin for explicit worklets workletizes ArrowFunctionExpression 1`] = `
+"var _worklet_16347365292089_init_data = {
+ code: "function anonymous(x){return x+2;}",
+ location: "/dev/null"
+};
+var foo = function () {
+ var _e = [new global.Error(), 1, -27];
+ var _f = function _f(x) {
+ return x + 2;
+ };
+ _f._closure = {};
+ _f.__initData = _worklet_16347365292089_init_data;
+ _f.__workletHash = 16347365292089;
+ _f.__stackDetails = _e;
+ return _f;
+}();"
+`;
+
+exports[`babel plugin for explicit worklets workletizes FunctionDeclaration 1`] = `
+"var _worklet_4679479961836_init_data = {
+ code: "function foo(x){return x+2;}",
+ location: "/dev/null"
+};
+var foo = function () {
+ var _e = [new global.Error(), 1, -27];
+ var _f = function _f(x) {
+ return x + 2;
+ };
+ _f._closure = {};
+ _f.__initData = _worklet_4679479961836_init_data;
+ _f.__workletHash = 4679479961836;
+ _f.__stackDetails = _e;
+ return _f;
+}();"
+`;
+
+exports[`babel plugin for explicit worklets workletizes named FunctionExpression 1`] = `
+"var _worklet_4679479961836_init_data = {
+ code: "function foo(x){return x+2;}",
+ location: "/dev/null"
+};
+var foo = function () {
+ var _e = [new global.Error(), 1, -27];
+ var _f = function _f(x) {
+ return x + 2;
+ };
+ _f._closure = {};
+ _f.__initData = _worklet_4679479961836_init_data;
+ _f.__workletHash = 4679479961836;
+ _f.__stackDetails = _e;
+ return _f;
+}();"
+`;
+
+exports[`babel plugin for explicit worklets workletizes unnamed FunctionExpression 1`] = `
+"var _worklet_16347365292089_init_data = {
+ code: "function anonymous(x){return x+2;}",
+ location: "/dev/null"
+};
+var foo = function () {
+ var _e = [new global.Error(), 1, -27];
+ var _f = function _f(x) {
+ return x + 2;
+ };
+ _f._closure = {};
+ _f.__initData = _worklet_16347365292089_init_data;
+ _f.__workletHash = 16347365292089;
+ _f.__stackDetails = _e;
+ return _f;
+}();"
+`;
+
+exports[`babel plugin for function hooks workletizes hook wrapped ArrowFunctionExpression automatically 1`] = `
+"var _worklet_9645206935615_init_data = {
+ code: "function anonymous(){return{width:50};}",
+ location: "/dev/null"
+};
+var animatedStyle = useAnimatedStyle(function () {
+ var _e = [new global.Error(), 1, -27];
+ var _f = function _f() {
+ return {
+ width: 50
+ };
+ };
+ _f._closure = {};
+ _f.__initData = _worklet_9645206935615_init_data;
+ _f.__workletHash = 9645206935615;
+ _f.__stackDetails = _e;
+ return _f;
+}());"
+`;
+
+exports[`babel plugin for function hooks workletizes hook wrapped named FunctionExpression automatically 1`] = `
+"var _worklet_6275510763626_init_data = {
+ code: "function foo(){return{width:50};}",
location: "/dev/null"
};
-var foo = function () {
- var _e = [new global.Error(), -2, -27];
- var _f = function _f(t) {
- if (t > 0) {
- return a + foo(t - 1);
- }
- };
- _f._closure = {
- a: a
+var animatedStyle = useAnimatedStyle(function () {
+ var _e = [new global.Error(), 1, -27];
+ var _f = function _f() {
+ return {
+ width: 50
+ };
};
- _f.__initData = _worklet_2022702330805_init_data;
- _f.__workletHash = 2022702330805;
+ _f._closure = {};
+ _f.__initData = _worklet_6275510763626_init_data;
+ _f.__workletHash = 6275510763626;
_f.__stackDetails = _e;
return _f;
-}();"
+}());"
`;
-exports[`babel plugin transforms 1`] = `
-"var _reactNativeReanimated = _interopRequireWildcard(require("react-native-reanimated"));
-function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
-function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
-var _worklet_16669311443114_init_data = {
- code: "function anonymous(){const{offset}=this._closure;return{transform:[{translateX:offset.value*255}]};}",
+exports[`babel plugin for function hooks workletizes hook wrapped unnamed FunctionExpression automatically 1`] = `
+"var _worklet_9645206935615_init_data = {
+ code: "function anonymous(){return{width:50};}",
location: "/dev/null"
};
-function Box() {
- var offset = (0, _reactNativeReanimated.useSharedValue)(0);
- var animatedStyles = (0, _reactNativeReanimated.useAnimatedStyle)(function () {
- var _e = [new global.Error(), -2, -27];
- var _f = function _f() {
- return {
- transform: [{
- translateX: offset.value * 255
- }]
- };
- };
- _f._closure = {
- offset: offset
+var animatedStyle = useAnimatedStyle(function () {
+ var _e = [new global.Error(), 1, -27];
+ var _f = function _f() {
+ return {
+ width: 50
};
- _f.__initData = _worklet_16669311443114_init_data;
- _f.__workletHash = 16669311443114;
- _f.__stackDetails = _e;
- return _f;
- }());
- return React.createElement(React.Fragment, null, React.createElement(_reactNativeReanimated.default.View, {
- style: [styles.box, animatedStyles]
- }), React.createElement(Button, {
- onPress: function onPress() {
- return offset.value = Math.random();
- },
- title: "Move"
- }));
+ };
+ _f._closure = {};
+ _f.__initData = _worklet_9645206935615_init_data;
+ _f.__workletHash = 9645206935615;
+ _f.__stackDetails = _e;
+ return _f;
+}());"
+`;
+
+exports[`babel plugin for inline styles doesn't show a warning if user writes something like style={styles.value} 1`] = `
+"function App() {
+ return React.createElement(Animated.View, {
+ style: styles.value
+ });
+}"
+`;
+
+exports[`babel plugin for inline styles shows a warning if user uses .value inside inline style 1`] = `
+"function App() {
+ return React.createElement(Animated.View, {
+ style: {
+ width: function () {
+ console.warn(require("react-native-reanimated").getUseOfValueInStyleWarning());
+ return sharedValue.value;
+ }()
+ }
+ });
+}"
+`;
+
+exports[`babel plugin for inline styles shows a warning if user uses .value inside inline style, style array 1`] = `
+"function App() {
+ return React.createElement(Animated.View, {
+ style: [style, {
+ width: function () {
+ console.warn(require("react-native-reanimated").getUseOfValueInStyleWarning());
+ return sharedValue.value;
+ }()
+ }]
+ });
+}"
+`;
+
+exports[`babel plugin for inline styles shows a warning if user uses .value inside inline style, transforms 1`] = `
+"function App() {
+ return React.createElement(Animated.View, {
+ style: {
+ transform: [{
+ translateX: function () {
+ console.warn(require("react-native-reanimated").getUseOfValueInStyleWarning());
+ return sharedValue.value;
+ }()
+ }]
+ }
+ });
}"
`;
-exports[`babel plugin transforms ArrowFunctionExpression as argument of useAnimatedScrollHandler 1`] = `
+exports[`babel plugin for object hooks doesn't transform ArrowFunctionExpression as argument of useAnimatedGestureHandler 1`] = `"useAnimatedGestureHandler(function () {});"`;
+
+exports[`babel plugin for object hooks doesn't transform named FunctionExpression as argument of useAnimatedGestureHandler 1`] = `"useAnimatedGestureHandler(function foo() {});"`;
+
+exports[`babel plugin for object hooks doesn't transform unnamed FunctionExpression as argument of useAnimatedGestureHandler 1`] = `"useAnimatedGestureHandler(function () {});"`;
+
+exports[`babel plugin for object hooks supports empty object in useAnimatedGestureHandler 1`] = `"useAnimatedGestureHandler({});"`;
+
+exports[`babel plugin for object hooks supports empty object in useAnimatedScrollHandler 1`] = `"useAnimatedScrollHandler({});"`;
+
+exports[`babel plugin for object hooks transforms ArrowFunctionExpression as argument of useAnimatedScrollHandler 1`] = `
"var _worklet_1022605193782_init_data = {
code: "function anonymous(event){console.log(event);}",
location: "/dev/null"
@@ -413,7 +595,7 @@ useAnimatedScrollHandler(function () {
}());"
`;
-exports[`babel plugin transforms each object property in useAnimatedGestureHandler 1`] = `
+exports[`babel plugin for object hooks transforms each object property in useAnimatedGestureHandler 1`] = `
"var _worklet_14892326408241_init_data = {
code: "function anonymous(){}",
location: "/dev/null"
@@ -457,7 +639,7 @@ useAnimatedGestureHandler({
});"
`;
-exports[`babel plugin transforms each object property in useAnimatedScrollHandler 1`] = `
+exports[`babel plugin for object hooks transforms each object property in useAnimatedScrollHandler 1`] = `
"var _worklet_14892326408241_init_data = {
code: "function anonymous(){}",
location: "/dev/null"
@@ -527,7 +709,7 @@ useAnimatedScrollHandler({
});"
`;
-exports[`babel plugin transforms named FunctionExpression as argument of useAnimatedScrollHandler 1`] = `
+exports[`babel plugin for object hooks transforms named FunctionExpression as argument of useAnimatedScrollHandler 1`] = `
"var _worklet_14540236792163_init_data = {
code: "function foo(event){console.log(event);}",
location: "/dev/null"
@@ -545,141 +727,7 @@ useAnimatedScrollHandler(function () {
}());"
`;
-exports[`babel plugin transforms nested worklets for JS thread 1`] = `
-"var _worklet_1678749606628_init_data = {
- code: "function foo(x){function bar(x){'worklet';return x+2;}return bar(x)+1;}",
- location: "/dev/null"
-};
-var _worklet_16974800582491_init_data = {
- code: "function bar(x){return x+2;}",
- location: "/dev/null"
-};
-var foo = function () {
- var _e = [new global.Error(), 1, -27];
- var _f = function _f(x) {
- var bar = function () {
- var _e = [new global.Error(), 1, -27];
- var _f = function _f(x) {
- return x + 2;
- };
- _f._closure = {};
- _f.__initData = _worklet_16974800582491_init_data;
- _f.__workletHash = 16974800582491;
- _f.__stackDetails = _e;
- return _f;
- }();
- return bar(x) + 1;
- };
- _f._closure = {};
- _f.__initData = _worklet_1678749606628_init_data;
- _f.__workletHash = 1678749606628;
- _f.__stackDetails = _e;
- return _f;
-}();"
-`;
-
-exports[`babel plugin transforms spread operator in Animated component 1`] = `
-"function App() {
- return React.createElement(Animated.View, {
- style: [style, Object.assign({}, styles.container, {
- width: function () {
- console.warn(require("react-native-reanimated").getUseOfValueInStyleWarning());
- return sharedValue.value;
- }()
- })]
- });
-}"
-`;
-
-exports[`babel plugin transforms spread operator in worklets for arrays 1`] = `
-"var _worklet_3161057533258_init_data = {
- code: "function foo(){const bar=[4,5];const baz=[1,...[2,3],...bar];}",
- location: "/dev/null"
-};
-var foo = function () {
- var _e = [new global.Error(), 1, -27];
- var _f = function _f() {
- var bar = [4, 5];
- var baz = [1].concat([2, 3], bar);
- };
- _f._closure = {};
- _f.__initData = _worklet_3161057533258_init_data;
- _f.__workletHash = 3161057533258;
- _f.__stackDetails = _e;
- return _f;
-}();"
-`;
-
-exports[`babel plugin transforms spread operator in worklets for function arguments 1`] = `
-"var _worklet_9866931756941_init_data = {
- code: "function foo(...args){console.log(args);}",
- location: "/dev/null"
-};
-var foo = function () {
- var _e = [new global.Error(), 1, -27];
- var _f = function _f() {
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
- args[_key] = arguments[_key];
- }
- console.log(args);
- };
- _f._closure = {};
- _f.__initData = _worklet_9866931756941_init_data;
- _f.__workletHash = 9866931756941;
- _f.__stackDetails = _e;
- return _f;
-}();"
-`;
-
-exports[`babel plugin transforms spread operator in worklets for function calls 1`] = `
-"var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
-var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
-var _worklet_2015887751437_init_data = {
- code: "function foo(arg){console.log(...arg);}",
- location: "/dev/null"
-};
-var foo = function () {
- var _e = [new global.Error(), 1, -27];
- var _f = function _f(arg) {
- var _console;
- (_console = console).log.apply(_console, (0, _toConsumableArray2.default)(arg));
- };
- _f._closure = {};
- _f.__initData = _worklet_2015887751437_init_data;
- _f.__workletHash = 2015887751437;
- _f.__stackDetails = _e;
- return _f;
-}();"
-`;
-
-exports[`babel plugin transforms spread operator in worklets for objects 1`] = `
-"var _worklet_792186851025_init_data = {
- code: "function foo(){const bar={d:4,e:5};const baz={a:1,...{b:2,c:3},...bar};}",
- location: "/dev/null"
-};
-var foo = function () {
- var _e = [new global.Error(), 1, -27];
- var _f = function _f() {
- var bar = {
- d: 4,
- e: 5
- };
- var baz = Object.assign({
- a: 1
- }, {
- b: 2,
- c: 3
- }, bar);
- };
- _f._closure = {};
- _f.__initData = _worklet_792186851025_init_data;
- _f.__workletHash = 792186851025;
- _f.__stackDetails = _e;
- return _f;
-}();"
-`;
-
-exports[`babel plugin transforms unnamed FunctionExpression as argument of useAnimatedScrollHandler 1`] = `
+exports[`babel plugin for object hooks transforms unnamed FunctionExpression as argument of useAnimatedScrollHandler 1`] = `
"var _worklet_1022605193782_init_data = {
code: "function anonymous(event){console.log(event);}",
location: "/dev/null"
@@ -697,268 +745,282 @@ useAnimatedScrollHandler(function () {
}());"
`;
-exports[`babel plugin workletizes ArrowFunctionExpression 1`] = `
-"var _worklet_16347365292089_init_data = {
- code: "function anonymous(x){return x+2;}",
+exports[`babel plugin for object hooks workletizes useAnimatedGestureHandler wrapped ArrowFunctionExpression automatically 1`] = `
+"var _worklet_1022605193782_init_data = {
+ code: "function anonymous(event){console.log(event);}",
+ location: "/dev/null"
+};
+useAnimatedGestureHandler({
+ onStart: function () {
+ var _e = [new global.Error(), 1, -27];
+ var _f = function _f(event) {
+ console.log(event);
+ };
+ _f._closure = {};
+ _f.__initData = _worklet_1022605193782_init_data;
+ _f.__workletHash = 1022605193782;
+ _f.__stackDetails = _e;
+ return _f;
+ }()
+});"
+`;
+
+exports[`babel plugin for object hooks workletizes useAnimatedGestureHandler wrapped ObjectMethod automatically 1`] = `
+"var _worklet_338158776260_init_data = {
+ code: "function onStart(event){console.log(event);}",
location: "/dev/null"
};
-var foo = function () {
- var _e = [new global.Error(), 1, -27];
- var _f = function _f(x) {
- return x + 2;
- };
- _f._closure = {};
- _f.__initData = _worklet_16347365292089_init_data;
- _f.__workletHash = 16347365292089;
- _f.__stackDetails = _e;
- return _f;
-}();"
+useAnimatedGestureHandler({
+ onStart: function () {
+ var _e = [new global.Error(), 1, -27];
+ var _f = function _f(event) {
+ console.log(event);
+ };
+ _f._closure = {};
+ _f.__initData = _worklet_338158776260_init_data;
+ _f.__workletHash = 338158776260;
+ _f.__stackDetails = _e;
+ return _f;
+ }()
+});"
`;
-exports[`babel plugin workletizes ArrowFunctionExpression inside runOnUI automatically 1`] = `
-"var _worklet_15854903236968_init_data = {
- code: "function anonymous(){console.log('Hello from the UI thread!');}",
+exports[`babel plugin for object hooks workletizes useAnimatedGestureHandler wrapped named FunctionExpression automatically 1`] = `
+"var _worklet_338158776260_init_data = {
+ code: "function onStart(event){console.log(event);}",
location: "/dev/null"
};
-runOnUI(function () {
- var _e = [new global.Error(), 1, -27];
- var _f = function _f() {
- console.log('Hello from the UI thread!');
- };
- _f._closure = {};
- _f.__initData = _worklet_15854903236968_init_data;
- _f.__workletHash = 15854903236968;
- _f.__stackDetails = _e;
- return _f;
-}())();"
+useAnimatedGestureHandler({
+ onStart: function () {
+ var _e = [new global.Error(), 1, -27];
+ var _f = function _f(event) {
+ console.log(event);
+ };
+ _f._closure = {};
+ _f.__initData = _worklet_338158776260_init_data;
+ _f.__workletHash = 338158776260;
+ _f.__stackDetails = _e;
+ return _f;
+ }()
+});"
`;
-exports[`babel plugin workletizes FunctionDeclaration 1`] = `
-"var _worklet_4679479961836_init_data = {
- code: "function foo(x){return x+2;}",
+exports[`babel plugin for object hooks workletizes useAnimatedGestureHandler wrapped unnamed FunctionExpression automatically 1`] = `
+"var _worklet_1022605193782_init_data = {
+ code: "function anonymous(event){console.log(event);}",
location: "/dev/null"
};
-var foo = function () {
- var _e = [new global.Error(), 1, -27];
- var _f = function _f(x) {
- return x + 2;
- };
- _f._closure = {};
- _f.__initData = _worklet_4679479961836_init_data;
- _f.__workletHash = 4679479961836;
- _f.__stackDetails = _e;
- return _f;
-}();"
+useAnimatedGestureHandler({
+ onStart: function () {
+ var _e = [new global.Error(), 1, -27];
+ var _f = function _f(event) {
+ console.log(event);
+ };
+ _f._closure = {};
+ _f.__initData = _worklet_1022605193782_init_data;
+ _f.__workletHash = 1022605193782;
+ _f.__stackDetails = _e;
+ return _f;
+ }()
+});"
`;
-exports[`babel plugin workletizes class field 1`] = `
-"var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
-var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
-var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
-var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
-var _worklet_16347365292089_init_data = {
- code: "function anonymous(x){return x+2;}",
+exports[`babel plugin for object hooks workletizes useAnimatedScrollHandler wrapped ArrowFunctionExpression automatically 1`] = `
+"var _worklet_1022605193782_init_data = {
+ code: "function anonymous(event){console.log(event);}",
location: "/dev/null"
};
-var Foo = (0, _createClass2.default)(function Foo() {
- (0, _classCallCheck2.default)(this, Foo);
- (0, _defineProperty2.default)(this, "bar", function () {
+useAnimatedScrollHandler({
+ onScroll: function () {
var _e = [new global.Error(), 1, -27];
- var _f = function _f(x) {
- return x + 2;
+ var _f = function _f(event) {
+ console.log(event);
};
_f._closure = {};
- _f.__initData = _worklet_16347365292089_init_data;
- _f.__workletHash = 16347365292089;
+ _f.__initData = _worklet_1022605193782_init_data;
+ _f.__workletHash = 1022605193782;
_f.__stackDetails = _e;
return _f;
- }());
+ }()
});"
`;
-exports[`babel plugin workletizes constructor 1`] = `
-"var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
-var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
-var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
-var _worklet_14658848071366_init_data = {
- code: "function Foo(x){const Foo=this._recur;const{_classCallCheck}=this._closure;_classCallCheck(this,Foo);this.x=x;}",
+exports[`babel plugin for object hooks workletizes useAnimatedScrollHandler wrapped ObjectMethod automatically 1`] = `
+"var _worklet_947458829673_init_data = {
+ code: "function onScroll(event){console.log(event);}",
location: "/dev/null"
};
-var Foo = (0, _createClass2.default)(function () {
- var _e = [new global.Error(), -2, -27];
- var _f = function _f(x) {
- (0, _classCallCheck2.default)(this, Foo);
- this.x = x;
- };
- _f._closure = {
- _classCallCheck: _classCallCheck2.default
- };
- _f.__initData = _worklet_14658848071366_init_data;
- _f.__workletHash = 14658848071366;
- _f.__stackDetails = _e;
- return _f;
-}());"
+useAnimatedGestureHandler({
+ onScroll: function () {
+ var _e = [new global.Error(), 1, -27];
+ var _f = function _f(event) {
+ console.log(event);
+ };
+ _f._closure = {};
+ _f.__initData = _worklet_947458829673_init_data;
+ _f.__workletHash = 947458829673;
+ _f.__stackDetails = _e;
+ return _f;
+ }()
+});"
`;
-exports[`babel plugin workletizes getter 1`] = `
-"var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
-var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
-var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
-var _worklet_10436985806815_init_data = {
- code: "function get(){const{x}=this._closure;return x+2;}",
+exports[`babel plugin for object hooks workletizes useAnimatedScrollHandler wrapped named FunctionExpression automatically 1`] = `
+"var _worklet_947458829673_init_data = {
+ code: "function onScroll(event){console.log(event);}",
location: "/dev/null"
};
-var Foo = function () {
- function Foo() {
- (0, _classCallCheck2.default)(this, Foo);
- }
- (0, _createClass2.default)(Foo, [{
- key: "bar",
- get: function () {
- var _e = [new global.Error(), -2, -27];
- var _f = function _f() {
- return x + 2;
- };
- _f._closure = {
- x: x
- };
- _f.__initData = _worklet_10436985806815_init_data;
- _f.__workletHash = 10436985806815;
- _f.__stackDetails = _e;
- return _f;
- }()
- }]);
- return Foo;
-}();"
+useAnimatedScrollHandler({
+ onScroll: function () {
+ var _e = [new global.Error(), 1, -27];
+ var _f = function _f(event) {
+ console.log(event);
+ };
+ _f._closure = {};
+ _f.__initData = _worklet_947458829673_init_data;
+ _f.__workletHash = 947458829673;
+ _f.__stackDetails = _e;
+ return _f;
+ }()
+});"
`;
-exports[`babel plugin workletizes hook wrapped ArrowFunctionExpression automatically 1`] = `
-"var _worklet_9645206935615_init_data = {
- code: "function anonymous(){return{width:50};}",
+exports[`babel plugin for object hooks workletizes useAnimatedScrollHandler wrapped unnamed FunctionExpression automatically 1`] = `
+"var _worklet_1022605193782_init_data = {
+ code: "function anonymous(event){console.log(event);}",
location: "/dev/null"
};
-var animatedStyle = useAnimatedStyle(function () {
- var _e = [new global.Error(), 1, -27];
- var _f = function _f() {
- return {
- width: 50
+useAnimatedScrollHandler({
+ onScroll: function () {
+ var _e = [new global.Error(), 1, -27];
+ var _f = function _f(event) {
+ console.log(event);
};
- };
- _f._closure = {};
- _f.__initData = _worklet_9645206935615_init_data;
- _f.__workletHash = 9645206935615;
- _f.__stackDetails = _e;
- return _f;
-}());"
+ _f._closure = {};
+ _f.__initData = _worklet_1022605193782_init_data;
+ _f.__workletHash = 1022605193782;
+ _f.__stackDetails = _e;
+ return _f;
+ }()
+});"
`;
-exports[`babel plugin workletizes hook wrapped named FunctionExpression automatically 1`] = `
-"var _worklet_6275510763626_init_data = {
- code: "function foo(){return{width:50};}",
+exports[`babel plugin for react-native-gesture-handler doesn't transform chained methods of objects containing Gesture property 1`] = `
+"var foo = Something.Gesture.Tap().onEnd(function () {
+ console.log('onEnd');
+});"
+`;
+
+exports[`babel plugin for react-native-gesture-handler doesn't transform standard callback functions 1`] = `
+"var foo = Something.Tap().onEnd(function (_event, _success) {
+ console.log('onEnd');
+});"
+`;
+
+exports[`babel plugin for react-native-gesture-handler doesn't workletize irrelevant chained gesture object callback functions 1`] = `"var foo = Gesture.Tap().toString();"`;
+
+exports[`babel plugin for react-native-gesture-handler transforms spread operator in Animated component 1`] = `
+"function App() {
+ return React.createElement(Animated.View, {
+ style: [style, Object.assign({}, styles.container, {
+ width: function () {
+ console.warn(require("react-native-reanimated").getUseOfValueInStyleWarning());
+ return sharedValue.value;
+ }()
+ })]
+ });
+}"
+`;
+
+exports[`babel plugin for react-native-gesture-handler transforms spread operator in worklets for arrays 1`] = `
+"var _worklet_3161057533258_init_data = {
+ code: "function foo(){const bar=[4,5];const baz=[1,...[2,3],...bar];}",
location: "/dev/null"
};
-var animatedStyle = useAnimatedStyle(function () {
+var foo = function () {
var _e = [new global.Error(), 1, -27];
var _f = function _f() {
- return {
- width: 50
- };
+ var bar = [4, 5];
+ var baz = [1].concat([2, 3], bar);
};
_f._closure = {};
- _f.__initData = _worklet_6275510763626_init_data;
- _f.__workletHash = 6275510763626;
+ _f.__initData = _worklet_3161057533258_init_data;
+ _f.__workletHash = 3161057533258;
_f.__stackDetails = _e;
return _f;
-}());"
+}();"
`;
-exports[`babel plugin workletizes hook wrapped unnamed FunctionExpression automatically 1`] = `
-"var _worklet_9645206935615_init_data = {
- code: "function anonymous(){return{width:50};}",
+exports[`babel plugin for react-native-gesture-handler transforms spread operator in worklets for function arguments 1`] = `
+"var _worklet_9866931756941_init_data = {
+ code: "function foo(...args){console.log(args);}",
location: "/dev/null"
};
-var animatedStyle = useAnimatedStyle(function () {
+var foo = function () {
var _e = [new global.Error(), 1, -27];
var _f = function _f() {
- return {
- width: 50
- };
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
+ args[_key] = arguments[_key];
+ }
+ console.log(args);
};
_f._closure = {};
- _f.__initData = _worklet_9645206935615_init_data;
- _f.__workletHash = 9645206935615;
+ _f.__initData = _worklet_9866931756941_init_data;
+ _f.__workletHash = 9866931756941;
_f.__stackDetails = _e;
return _f;
-}());"
-`;
-
-exports[`babel plugin workletizes instance method 1`] = `
-"var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
-var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
-var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
-var _worklet_16974800582491_init_data = {
- code: "function bar(x){return x+2;}",
- location: "/dev/null"
-};
-var Foo = function () {
- function Foo() {
- (0, _classCallCheck2.default)(this, Foo);
- }
- (0, _createClass2.default)(Foo, [{
- key: "bar",
- value: function () {
- var _e = [new global.Error(), 1, -27];
- var _f = function _f(x) {
- return x + 2;
- };
- _f._closure = {};
- _f.__initData = _worklet_16974800582491_init_data;
- _f.__workletHash = 16974800582491;
- _f.__stackDetails = _e;
- return _f;
- }()
- }]);
- return Foo;
}();"
`;
-exports[`babel plugin workletizes named FunctionExpression 1`] = `
-"var _worklet_4679479961836_init_data = {
- code: "function foo(x){return x+2;}",
+exports[`babel plugin for react-native-gesture-handler transforms spread operator in worklets for function calls 1`] = `
+"var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
+var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
+var _worklet_2015887751437_init_data = {
+ code: "function foo(arg){console.log(...arg);}",
location: "/dev/null"
};
var foo = function () {
var _e = [new global.Error(), 1, -27];
- var _f = function _f(x) {
- return x + 2;
+ var _f = function _f(arg) {
+ var _console;
+ (_console = console).log.apply(_console, (0, _toConsumableArray2.default)(arg));
};
_f._closure = {};
- _f.__initData = _worklet_4679479961836_init_data;
- _f.__workletHash = 4679479961836;
+ _f.__initData = _worklet_2015887751437_init_data;
+ _f.__workletHash = 2015887751437;
_f.__stackDetails = _e;
return _f;
}();"
`;
-exports[`babel plugin workletizes named FunctionExpression inside runOnUI automatically 1`] = `
-"var _worklet_5662051517689_init_data = {
- code: "function hello(){console.log('Hello from the UI thread!');}",
+exports[`babel plugin for react-native-gesture-handler transforms spread operator in worklets for objects 1`] = `
+"var _worklet_792186851025_init_data = {
+ code: "function foo(){const bar={d:4,e:5};const baz={a:1,...{b:2,c:3},...bar};}",
location: "/dev/null"
};
-runOnUI(function () {
+var foo = function () {
var _e = [new global.Error(), 1, -27];
var _f = function _f() {
- console.log('Hello from the UI thread!');
+ var bar = {
+ d: 4,
+ e: 5
+ };
+ var baz = Object.assign({
+ a: 1
+ }, {
+ b: 2,
+ c: 3
+ }, bar);
};
_f._closure = {};
- _f.__initData = _worklet_5662051517689_init_data;
- _f.__workletHash = 5662051517689;
+ _f.__initData = _worklet_792186851025_init_data;
+ _f.__workletHash = 792186851025;
_f.__stackDetails = _e;
return _f;
-}())();"
+}();"
`;
-exports[`babel plugin workletizes possibly chained gesture object callback functions automatically 1`] = `
+exports[`babel plugin for react-native-gesture-handler workletizes possibly chained gesture object callback functions automatically 1`] = `
"var _worklet_15393478329680_init_data = {
code: "function anonymous(){console.log('onBegin');}",
location: "/dev/null"
@@ -1004,76 +1066,169 @@ var foo = Gesture.Tap().numberOfTaps(2).onBegin(function () {
}());"
`;
-exports[`babel plugin workletizes setter 1`] = `
-"var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
-var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
-var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
-var _worklet_6451428689423_init_data = {
- code: "function set(x){this.x=x+2;}",
+exports[`babel plugin for runOnUI workletizes ArrowFunctionExpression inside runOnUI automatically 1`] = `
+"var _worklet_15854903236968_init_data = {
+ code: "function anonymous(){console.log('Hello from the UI thread!');}",
location: "/dev/null"
};
-var Foo = function () {
- function Foo() {
- (0, _classCallCheck2.default)(this, Foo);
- }
- (0, _createClass2.default)(Foo, [{
- key: "bar",
- set: function () {
+runOnUI(function () {
+ var _e = [new global.Error(), 1, -27];
+ var _f = function _f() {
+ console.log('Hello from the UI thread!');
+ };
+ _f._closure = {};
+ _f.__initData = _worklet_15854903236968_init_data;
+ _f.__workletHash = 15854903236968;
+ _f.__stackDetails = _e;
+ return _f;
+}())();"
+`;
+
+exports[`babel plugin for runOnUI workletizes named FunctionExpression inside runOnUI automatically 1`] = `
+"var _worklet_5662051517689_init_data = {
+ code: "function hello(){console.log('Hello from the UI thread!');}",
+ location: "/dev/null"
+};
+runOnUI(function () {
+ var _e = [new global.Error(), 1, -27];
+ var _f = function _f() {
+ console.log('Hello from the UI thread!');
+ };
+ _f._closure = {};
+ _f.__initData = _worklet_5662051517689_init_data;
+ _f.__workletHash = 5662051517689;
+ _f.__stackDetails = _e;
+ return _f;
+}())();"
+`;
+
+exports[`babel plugin for runOnUI workletizes unnamed FunctionExpression inside runOnUI automatically 1`] = `
+"var _worklet_15854903236968_init_data = {
+ code: "function anonymous(){console.log('Hello from the UI thread!');}",
+ location: "/dev/null"
+};
+runOnUI(function () {
+ var _e = [new global.Error(), 1, -27];
+ var _f = function _f() {
+ console.log('Hello from the UI thread!');
+ };
+ _f._closure = {};
+ _f.__initData = _worklet_15854903236968_init_data;
+ _f.__workletHash = 15854903236968;
+ _f.__stackDetails = _e;
+ return _f;
+}())();"
+`;
+
+exports[`babel plugin for sequence expressions supports SequenceExpression 1`] = `
+"function App() {
+ (0, fun)({
+ onStart: function onStart() {}
+ }, []);
+}"
+`;
+
+exports[`babel plugin for sequence expressions supports SequenceExpression, many arguments 1`] = `
+"var _worklet_4434179069699_init_data = {
+ code: "function onStart(){}",
+ location: "/dev/null"
+};
+function App() {
+ (0, 3, fun)({
+ onStart: function () {
var _e = [new global.Error(), 1, -27];
- var _f = function _f(x) {
- this.x = x + 2;
- };
+ var _f = function _f() {};
_f._closure = {};
- _f.__initData = _worklet_6451428689423_init_data;
- _f.__workletHash = 6451428689423;
+ _f.__initData = _worklet_4434179069699_init_data;
+ _f.__workletHash = 4434179069699;
_f.__stackDetails = _e;
return _f;
}()
- }]);
- return Foo;
-}();"
+ }, []);
+}"
`;
-exports[`babel plugin workletizes static class field 1`] = `
-"var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
-var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
-var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
-var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
-var Foo = (0, _createClass2.default)(function Foo() {
- (0, _classCallCheck2.default)(this, Foo);
-});
-var _worklet_16347365292089_init_data = {
- code: "function anonymous(x){return x+2;}",
+exports[`babel plugin for sequence expressions supports SequenceExpression, with objectHook 1`] = `
+"var _worklet_4434179069699_init_data = {
+ code: "function onStart(){}",
location: "/dev/null"
};
-(0, _defineProperty2.default)(Foo, "bar", function () {
- var _e = [new global.Error(), 1, -27];
- var _f = function _f(x) {
- return x + 2;
+function App() {
+ (0, useAnimatedGestureHandler)({
+ onStart: function () {
+ var _e = [new global.Error(), 1, -27];
+ var _f = function _f() {};
+ _f._closure = {};
+ _f.__initData = _worklet_4434179069699_init_data;
+ _f.__workletHash = 4434179069699;
+ _f.__stackDetails = _e;
+ return _f;
+ }()
+ }, []);
+}"
+`;
+
+exports[`babel plugin for sequence expressions supports SequenceExpression, with worklet 1`] = `
+"var _worklet_4434179069699_init_data = {
+ code: "function onStart(){}",
+ location: "/dev/null"
+};
+function App() {
+ (0, fun)({
+ onStart: function () {
+ var _e = [new global.Error(), 1, -27];
+ var _f = function _f() {};
+ _f._closure = {};
+ _f.__initData = _worklet_4434179069699_init_data;
+ _f.__workletHash = 4434179069699;
+ _f.__stackDetails = _e;
+ return _f;
+ }()
+ }, []);
+}"
+`;
+
+exports[`babel plugin for sequence expressions supports SequenceExpression, with worklet closure 1`] = `
+"var _worklet_16676723780973_init_data = {
+ code: "function onStart(){const{obj}=this._closure;const a=obj.a;}",
+ location: "/dev/null"
+};
+function App() {
+ var obj = {
+ a: 1,
+ b: 2
};
- _f._closure = {};
- _f.__initData = _worklet_16347365292089_init_data;
- _f.__workletHash = 16347365292089;
- _f.__stackDetails = _e;
- return _f;
-}());"
+ (0, fun)({
+ onStart: function () {
+ var _e = [new global.Error(), -2, -27];
+ var _f = function _f() {
+ var a = obj.a;
+ };
+ _f._closure = {
+ obj: obj
+ };
+ _f.__initData = _worklet_16676723780973_init_data;
+ _f.__workletHash = 16676723780973;
+ _f.__stackDetails = _e;
+ return _f;
+ }()
+ }, []);
+}"
`;
-exports[`babel plugin workletizes static method 1`] = `
-"var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
-var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
-var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
+exports[`babel plugin for worklet nesting doesn't nest worklets for other threads 1`] = `
+"var _worklet_1678749606628_init_data = {
+ code: "function foo(x){function bar(x){'worklet';return x+2;}return bar(x)+1;}",
+ location: "/dev/null"
+};
var _worklet_16974800582491_init_data = {
code: "function bar(x){return x+2;}",
location: "/dev/null"
};
-var Foo = function () {
- function Foo() {
- (0, _classCallCheck2.default)(this, Foo);
- }
- (0, _createClass2.default)(Foo, null, [{
- key: "bar",
- value: function () {
+var foo = function () {
+ var _e = [new global.Error(), 1, -27];
+ var _f = function _f(x) {
+ var bar = function () {
var _e = [new global.Error(), 1, -27];
var _f = function _f(x) {
return x + 2;
@@ -1083,204 +1238,125 @@ var Foo = function () {
_f.__workletHash = 16974800582491;
_f.__stackDetails = _e;
return _f;
- }()
- }]);
- return Foo;
+ }();
+ return bar(x) + 1;
+ };
+ _f._closure = {};
+ _f.__initData = _worklet_1678749606628_init_data;
+ _f.__workletHash = 1678749606628;
+ _f.__stackDetails = _e;
+ return _f;
}();"
`;
-exports[`babel plugin workletizes unnamed FunctionExpression 1`] = `
-"var _worklet_16347365292089_init_data = {
- code: "function anonymous(x){return x+2;}",
+exports[`babel plugin for worklet nesting transforms nested worklets for JS thread 1`] = `
+"var _worklet_1678749606628_init_data = {
+ code: "function foo(x){function bar(x){'worklet';return x+2;}return bar(x)+1;}",
+ location: "/dev/null"
+};
+var _worklet_16974800582491_init_data = {
+ code: "function bar(x){return x+2;}",
location: "/dev/null"
};
var foo = function () {
var _e = [new global.Error(), 1, -27];
var _f = function _f(x) {
- return x + 2;
+ var bar = function () {
+ var _e = [new global.Error(), 1, -27];
+ var _f = function _f(x) {
+ return x + 2;
+ };
+ _f._closure = {};
+ _f.__initData = _worklet_16974800582491_init_data;
+ _f.__workletHash = 16974800582491;
+ _f.__stackDetails = _e;
+ return _f;
+ }();
+ return bar(x) + 1;
};
_f._closure = {};
- _f.__initData = _worklet_16347365292089_init_data;
- _f.__workletHash = 16347365292089;
+ _f.__initData = _worklet_1678749606628_init_data;
+ _f.__workletHash = 1678749606628;
_f.__stackDetails = _e;
return _f;
}();"
`;
-exports[`babel plugin workletizes unnamed FunctionExpression inside runOnUI automatically 1`] = `
-"var _worklet_15854903236968_init_data = {
- code: "function anonymous(){console.log('Hello from the UI thread!');}",
+exports[`babel plugin generally removes comments from worklets 1`] = `
+"var _worklet_235615426006_init_data = {
+ code: "function anonymous(){return true;}",
location: "/dev/null"
};
-runOnUI(function () {
+var f = function () {
var _e = [new global.Error(), 1, -27];
var _f = function _f() {
- console.log('Hello from the UI thread!');
+ return true;
};
_f._closure = {};
- _f.__initData = _worklet_15854903236968_init_data;
- _f.__workletHash = 15854903236968;
+ _f.__initData = _worklet_235615426006_init_data;
+ _f.__workletHash = 235615426006;
_f.__stackDetails = _e;
return _f;
-}())();"
-`;
-
-exports[`babel plugin workletizes useAnimatedGestureHandler wrapped ArrowFunctionExpression automatically 1`] = `
-"var _worklet_1022605193782_init_data = {
- code: "function anonymous(event){console.log(event);}",
- location: "/dev/null"
-};
-useAnimatedGestureHandler({
- onStart: function () {
- var _e = [new global.Error(), 1, -27];
- var _f = function _f(event) {
- console.log(event);
- };
- _f._closure = {};
- _f.__initData = _worklet_1022605193782_init_data;
- _f.__workletHash = 1022605193782;
- _f.__stackDetails = _e;
- return _f;
- }()
-});"
-`;
-
-exports[`babel plugin workletizes useAnimatedGestureHandler wrapped ObjectMethod automatically 1`] = `
-"var _worklet_338158776260_init_data = {
- code: "function onStart(event){console.log(event);}",
- location: "/dev/null"
-};
-useAnimatedGestureHandler({
- onStart: function () {
- var _e = [new global.Error(), 1, -27];
- var _f = function _f(event) {
- console.log(event);
- };
- _f._closure = {};
- _f.__initData = _worklet_338158776260_init_data;
- _f.__workletHash = 338158776260;
- _f.__stackDetails = _e;
- return _f;
- }()
-});"
-`;
-
-exports[`babel plugin workletizes useAnimatedGestureHandler wrapped named FunctionExpression automatically 1`] = `
-"var _worklet_338158776260_init_data = {
- code: "function onStart(event){console.log(event);}",
- location: "/dev/null"
-};
-useAnimatedGestureHandler({
- onStart: function () {
- var _e = [new global.Error(), 1, -27];
- var _f = function _f(event) {
- console.log(event);
- };
- _f._closure = {};
- _f.__initData = _worklet_338158776260_init_data;
- _f.__workletHash = 338158776260;
- _f.__stackDetails = _e;
- return _f;
- }()
-});"
-`;
-
-exports[`babel plugin workletizes useAnimatedGestureHandler wrapped unnamed FunctionExpression automatically 1`] = `
-"var _worklet_1022605193782_init_data = {
- code: "function anonymous(event){console.log(event);}",
- location: "/dev/null"
-};
-useAnimatedGestureHandler({
- onStart: function () {
- var _e = [new global.Error(), 1, -27];
- var _f = function _f(event) {
- console.log(event);
- };
- _f._closure = {};
- _f.__initData = _worklet_1022605193782_init_data;
- _f.__workletHash = 1022605193782;
- _f.__stackDetails = _e;
- return _f;
- }()
-});"
-`;
-
-exports[`babel plugin workletizes useAnimatedScrollHandler wrapped ArrowFunctionExpression automatically 1`] = `
-"var _worklet_1022605193782_init_data = {
- code: "function anonymous(event){console.log(event);}",
- location: "/dev/null"
-};
-useAnimatedScrollHandler({
- onScroll: function () {
- var _e = [new global.Error(), 1, -27];
- var _f = function _f(event) {
- console.log(event);
- };
- _f._closure = {};
- _f.__initData = _worklet_1022605193782_init_data;
- _f.__workletHash = 1022605193782;
- _f.__stackDetails = _e;
- return _f;
- }()
-});"
+}();"
`;
-exports[`babel plugin workletizes useAnimatedScrollHandler wrapped ObjectMethod automatically 1`] = `
-"var _worklet_947458829673_init_data = {
- code: "function onScroll(event){console.log(event);}",
+exports[`babel plugin generally supports recursive calls 1`] = `
+"var a = 1;
+var _worklet_2022702330805_init_data = {
+ code: "function foo(t){const foo=this._recur;const{a}=this._closure;if(t>0){return a+foo(t-1);}}",
location: "/dev/null"
};
-useAnimatedGestureHandler({
- onScroll: function () {
- var _e = [new global.Error(), 1, -27];
- var _f = function _f(event) {
- console.log(event);
- };
- _f._closure = {};
- _f.__initData = _worklet_947458829673_init_data;
- _f.__workletHash = 947458829673;
- _f.__stackDetails = _e;
- return _f;
- }()
-});"
+var foo = function () {
+ var _e = [new global.Error(), -2, -27];
+ var _f = function _f(t) {
+ if (t > 0) {
+ return a + foo(t - 1);
+ }
+ };
+ _f._closure = {
+ a: a
+ };
+ _f.__initData = _worklet_2022702330805_init_data;
+ _f.__workletHash = 2022702330805;
+ _f.__stackDetails = _e;
+ return _f;
+}();"
`;
-exports[`babel plugin workletizes useAnimatedScrollHandler wrapped named FunctionExpression automatically 1`] = `
-"var _worklet_947458829673_init_data = {
- code: "function onScroll(event){console.log(event);}",
+exports[`babel plugin generally transforms 1`] = `
+"var _reactNativeReanimated = _interopRequireWildcard(require("react-native-reanimated"));
+function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
+function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
+var _worklet_16669311443114_init_data = {
+ code: "function anonymous(){const{offset}=this._closure;return{transform:[{translateX:offset.value*255}]};}",
location: "/dev/null"
};
-useAnimatedScrollHandler({
- onScroll: function () {
- var _e = [new global.Error(), 1, -27];
- var _f = function _f(event) {
- console.log(event);
+function Box() {
+ var offset = (0, _reactNativeReanimated.useSharedValue)(0);
+ var animatedStyles = (0, _reactNativeReanimated.useAnimatedStyle)(function () {
+ var _e = [new global.Error(), -2, -27];
+ var _f = function _f() {
+ return {
+ transform: [{
+ translateX: offset.value * 255
+ }]
+ };
};
- _f._closure = {};
- _f.__initData = _worklet_947458829673_init_data;
- _f.__workletHash = 947458829673;
- _f.__stackDetails = _e;
- return _f;
- }()
-});"
-`;
-
-exports[`babel plugin workletizes useAnimatedScrollHandler wrapped unnamed FunctionExpression automatically 1`] = `
-"var _worklet_1022605193782_init_data = {
- code: "function anonymous(event){console.log(event);}",
- location: "/dev/null"
-};
-useAnimatedScrollHandler({
- onScroll: function () {
- var _e = [new global.Error(), 1, -27];
- var _f = function _f(event) {
- console.log(event);
+ _f._closure = {
+ offset: offset
};
- _f._closure = {};
- _f.__initData = _worklet_1022605193782_init_data;
- _f.__workletHash = 1022605193782;
+ _f.__initData = _worklet_16669311443114_init_data;
+ _f.__workletHash = 16669311443114;
_f.__stackDetails = _e;
return _f;
- }()
-});"
+ }());
+ return React.createElement(React.Fragment, null, React.createElement(_reactNativeReanimated.default.View, {
+ style: [styles.box, animatedStyles]
+ }), React.createElement(Button, {
+ onPress: function onPress() {
+ return offset.value = Math.random();
+ },
+ title: "Move"
+ }));
+}"
`;
diff --git a/__tests__/plugin.test.ts b/__tests__/plugin.test.ts
index cb5789a4b38d..abff4bb6ac17 100644
--- a/__tests__/plugin.test.ts
+++ b/__tests__/plugin.test.ts
@@ -25,1002 +25,1006 @@ describe('babel plugin', () => {
process.env.REANIMATED_JEST_DISABLE_VERSION = 'jest';
});
- // Utils
- it('transforms', () => {
- const input = html``;
-
- const { code } = runPlugin(input);
- expect(code).toHaveWorkletData();
- expect(code).toMatchSnapshot();
- });
-
- it('injects its version', () => {
- delete process.env.REANIMATED_JEST_DISABLE_VERSION;
-
- const input = html``;
-
- const { code } = runPlugin(input, {});
- const { version: packageVersion } = require('../package.json');
- expect(code).toContain(`f.__version = "${packageVersion}";`);
- });
-
- it('removes comments from worklets', () => {
- const input = html``;
-
- const { code } = runPlugin(input);
- expect(code).not.toContain('some comment');
- expect(code).not.toContain('other comment');
- expect(code).toMatchSnapshot();
- });
+ describe('generally', () => {
+ it('transforms', () => {
+ const input = html``;
+ `;
- const { code } = runPlugin(input);
- expect(code).toContain('const foo=this._recur');
- expect(code).toMatchSnapshot();
- });
-
- // DirectiveLiterals and 'worklet'
- it("doesn't bother other Directive Literals", () => {
- const input = html``;
+ const { code } = runPlugin(input);
+ expect(code).toHaveWorkletData();
+ expect(code).toMatchSnapshot();
+ });
- const { code } = runPlugin(input, {});
- expect(code).toContain('foobar');
- expect(code).toMatchSnapshot();
- });
+ it('injects its version', () => {
+ delete process.env.REANIMATED_JEST_DISABLE_VERSION;
- it("doesn't transform functions without 'worklet' directive", () => {
- const input = html``;
+ const input = html``;
- const { code } = runPlugin(input);
- expect(code).not.toHaveWorkletData();
- expect(code).toMatchSnapshot();
- });
+ const { code } = runPlugin(input, {});
+ const { version: packageVersion } = require('../package.json');
+ expect(code).toContain(`f.__version = "${packageVersion}";`);
+ });
- it('removes "worklet"; directive from worklets', () => {
- const input = html``;
+ it('removes comments from worklets', () => {
+ const input = html``;
- const { code } = runPlugin(input);
- expect(code).not.toContain('"worklet";');
- expect(code).toMatchSnapshot();
- });
+ const { code } = runPlugin(input);
+ expect(code).not.toContain('some comment');
+ expect(code).not.toContain('other comment');
+ expect(code).toMatchSnapshot();
+ });
- it("removes 'worklet'; directive from worklets", () => {
- const input = html``;
+ it('supports recursive calls', () => {
+ const input = html``;
- const { code } = runPlugin(input);
- expect(code).not.toContain("'worklet';");
- expect(code).toMatchSnapshot();
+ const { code } = runPlugin(input);
+ expect(code).toContain('const foo=this._recur');
+ expect(code).toMatchSnapshot();
+ });
});
- it("doesn't transform string literals", () => {
- const input = html``;
-
- const { code } = runPlugin(input);
- expect(code).toContain("bar = 'worklet';");
- expect(code).toContain('baz = "worklet";');
- expect(code).toMatchSnapshot();
- });
+ describe('for DirectiveLiterals', () => {
+ it("doesn't bother other Directive Literals", () => {
+ const input = html``;
- // Worklet nesting
+ const { code } = runPlugin(input, {});
+ expect(code).toContain('foobar');
+ expect(code).toMatchSnapshot();
+ });
- it("doesn't nest worklets for other threads", () => {
- const input = html``;
- const { code } = runPlugin(input);
- expect(code).toContain("'worklet';");
- expect(code).toMatchSnapshot();
- });
+ `;
- it('transforms nested worklets for JS thread', () => {
- const input = html``;
+ `;
- const { code } = runPlugin(input);
- expect(code).toHaveWorkletData(2);
- expect(code).toMatchSnapshot();
- });
+ const { code } = runPlugin(input);
+ expect(code).not.toContain('"worklet";');
+ expect(code).toMatchSnapshot();
+ });
- // Closure capturing
- it('captures worklets environment', () => {
- const input = html``;
- const objX = { x };
+ const { code } = runPlugin(input);
+ expect(code).not.toContain("'worklet';");
+ expect(code).toMatchSnapshot();
+ });
- function f() {
- 'worklet';
- return { res: x + objX.x };
- }
- `;
+ it("doesn't transform string literals", () => {
+ const input = html``;
- const { code } = runPlugin(input);
- expect(code).not.toContain('_f._closure = {};');
- expect(code).toMatchSnapshot();
+ const { code } = runPlugin(input);
+ expect(code).toContain("bar = 'worklet';");
+ expect(code).toContain('baz = "worklet";');
+ expect(code).toMatchSnapshot();
+ });
});
- it("doesn't capture globals", () => {
- const input = html``;
-
- const { code, ast } = runPlugin(input, { ast: true });
- let closureBindings;
- traverse(ast, {
- enter(path) {
- if (
- path.isAssignmentExpression() &&
- 'property' in path.node.left &&
- 'name' in path.node.left.property &&
- 'properties' in path.node.right &&
- path.node.left.property.name === '_closure'
- ) {
- closureBindings = path.node.right.properties;
+ describe('for worklet nesting', () => {
+ it("doesn't nest worklets for other threads", () => {
+ const input = html``;
+ const { code } = runPlugin(input);
+ expect(code).toContain("'worklet';");
+ expect(code).toMatchSnapshot();
});
- expect(closureBindings).toEqual([]);
- expect(code).toMatchSnapshot();
- });
-
- // Explicit worklets
-
- it('workletizes FunctionDeclaration', () => {
- const input = html``;
-
- const { code } = runPlugin(input);
- expect(code).toHaveWorkletData();
- expect(code).not.toContain("'worklet';");
- expect(code).toMatchSnapshot();
- });
- it('workletizes ArrowFunctionExpression', () => {
- const input = html``;
-
- const { code } = runPlugin(input);
- expect(code).toHaveWorkletData();
- expect(code).not.toContain("'worklet';");
- expect(code).toMatchSnapshot();
- });
-
- it('workletizes unnamed FunctionExpression', () => {
- const input = html``;
+ it('transforms nested worklets for JS thread', () => {
+ const input = html``;
- const { code } = runPlugin(input);
- expect(code).toHaveWorkletData();
- expect(code).not.toContain("'worklet';");
- expect(code).toMatchSnapshot();
+ const { code } = runPlugin(input);
+ expect(code).toHaveWorkletData(2);
+ expect(code).toMatchSnapshot();
+ });
});
- it('workletizes named FunctionExpression', () => {
- const input = html``;
-
- const { code } = runPlugin(input);
- expect(code).toHaveWorkletData();
- expect(code).not.toContain("'worklet';");
- expect(code).toMatchSnapshot();
- });
+ describe('for closure capturing', () => {
+ it('captures worklets environment', () => {
+ const input = html``;
+ `;
- const { code } = runPlugin(input);
- expect(code).toHaveWorkletData();
- expect(code).not.toContain("'worklet';");
- expect(code).toMatchSnapshot();
- });
+ const { code } = runPlugin(input);
+ expect(code).not.toContain('_f._closure = {};');
+ expect(code).toMatchSnapshot();
+ });
- it('workletizes static method', () => {
- const input = html``;
-
- const { code } = runPlugin(input);
- expect(code).toHaveWorkletData();
- expect(code).not.toContain("'worklet';");
- expect(code).toMatchSnapshot();
+ `;
+
+ const { code, ast } = runPlugin(input, { ast: true });
+ let closureBindings;
+ traverse(ast, {
+ enter(path) {
+ if (
+ path.isAssignmentExpression() &&
+ 'property' in path.node.left &&
+ 'name' in path.node.left.property &&
+ 'properties' in path.node.right &&
+ path.node.left.property.name === '_closure'
+ ) {
+ closureBindings = path.node.right.properties;
+ }
+ },
+ });
+ expect(closureBindings).toEqual([]);
+ expect(code).toMatchSnapshot();
+ });
});
- it('workletizes getter', () => {
- const input = html``;
+ `;
- const { code } = runPlugin(input);
- expect(code).toHaveWorkletData();
- expect(code).not.toContain("'worklet';");
- expect(code).toMatchSnapshot();
- });
+ const { code } = runPlugin(input);
+ expect(code).toHaveWorkletData();
+ expect(code).not.toContain("'worklet';");
+ expect(code).toMatchSnapshot();
+ });
- it('workletizes setter', () => {
- const input = html``;
+ return x + 2;
+ };
+ `;
- const { code } = runPlugin(input);
- expect(code).toHaveWorkletData();
- expect(code).not.toContain("'worklet';");
- expect(code).toMatchSnapshot();
- });
+ const { code } = runPlugin(input);
+ expect(code).toHaveWorkletData();
+ expect(code).not.toContain("'worklet';");
+ expect(code).toMatchSnapshot();
+ });
- it('workletizes class field', () => {
- const input = html``;
+ `;
- const { code } = runPlugin(input);
- expect(code).toHaveWorkletData();
- expect(code).not.toContain("'worklet';");
- expect(code).toMatchSnapshot();
- });
+ const { code } = runPlugin(input);
+ expect(code).toHaveWorkletData();
+ expect(code).not.toContain("'worklet';");
+ expect(code).toMatchSnapshot();
+ });
- it('workletizes static class field', () => {
- const input = html``;
+ `;
- const { code } = runPlugin(input);
- expect(code).toHaveWorkletData();
- expect(code).not.toContain("'worklet';");
- expect(code).toMatchSnapshot();
+ const { code } = runPlugin(input);
+ expect(code).toHaveWorkletData();
+ expect(code).not.toContain("'worklet';");
+ expect(code).toMatchSnapshot();
+ });
});
- it('workletizes constructor', () => {
- const input = html``;
+ `;
- const { code } = runPlugin(input);
- expect(code).toHaveWorkletData();
- expect(code).not.toContain("'worklet';");
- expect(code).toMatchSnapshot();
- });
+ const { code } = runPlugin(input);
+ expect(code).toHaveWorkletData();
+ expect(code).not.toContain("'worklet';");
+ expect(code).toMatchSnapshot();
+ });
- // Function hooks
+ it('workletizes static method', () => {
+ const input = html``;
- it('workletizes hook wrapped ArrowFunctionExpression automatically', () => {
- const input = html``;
+ const { code } = runPlugin(input);
+ expect(code).toHaveWorkletData();
+ expect(code).not.toContain("'worklet';");
+ expect(code).toMatchSnapshot();
+ });
- const { code } = runPlugin(input);
- expect(code).toHaveWorkletData();
- expect(code).toMatchSnapshot();
- });
+ it('workletizes getter', () => {
+ const input = html``;
- it('workletizes hook wrapped unnamed FunctionExpression automatically', () => {
- const input = html``;
+ const { code } = runPlugin(input);
+ expect(code).toHaveWorkletData();
+ expect(code).not.toContain("'worklet';");
+ expect(code).toMatchSnapshot();
+ });
- const { code } = runPlugin(input);
- expect(code).toHaveWorkletData();
- expect(code).toMatchSnapshot();
- });
+ it('workletizes setter', () => {
+ const input = html``;
- it('workletizes hook wrapped named FunctionExpression automatically', () => {
- const input = html``;
+ const { code } = runPlugin(input);
+ expect(code).toHaveWorkletData();
+ expect(code).not.toContain("'worklet';");
+ expect(code).toMatchSnapshot();
+ });
- const { code } = runPlugin(input);
- expect(code).toHaveWorkletData();
- expect(code).toMatchSnapshot();
- });
+ it('workletizes class field', () => {
+ const input = html``;
- // runOnUI
+ const { code } = runPlugin(input);
+ expect(code).toHaveWorkletData();
+ expect(code).not.toContain("'worklet';");
+ expect(code).toMatchSnapshot();
+ });
- it('workletizes ArrowFunctionExpression inside runOnUI automatically', () => {
- const input = html``;
+ it('workletizes static class field', () => {
+ const input = html``;
- const { code } = runPlugin(input);
- expect(code).toHaveWorkletData();
- expect(code).toMatchSnapshot();
- });
+ const { code } = runPlugin(input);
+ expect(code).toHaveWorkletData();
+ expect(code).not.toContain("'worklet';");
+ expect(code).toMatchSnapshot();
+ });
- it('workletizes unnamed FunctionExpression inside runOnUI automatically', () => {
- const input = html``;
+ it('workletizes constructor', () => {
+ const input = html``;
- const { code } = runPlugin(input);
- expect(code).toHaveWorkletData();
- expect(code).toMatchSnapshot();
+ const { code } = runPlugin(input);
+ expect(code).toHaveWorkletData();
+ expect(code).not.toContain("'worklet';");
+ expect(code).toMatchSnapshot();
+ });
});
- it('workletizes named FunctionExpression inside runOnUI automatically', () => {
- const input = html``;
+ describe('for function hooks', () => {
+ it('workletizes hook wrapped ArrowFunctionExpression automatically', () => {
+ const input = html``;
- const { code } = runPlugin(input);
- expect(code).toHaveWorkletData();
- expect(code).toMatchSnapshot();
- });
+ const { code } = runPlugin(input);
+ expect(code).toHaveWorkletData();
+ expect(code).toMatchSnapshot();
+ });
+
+ it('workletizes hook wrapped unnamed FunctionExpression automatically', () => {
+ const input = html``;
- // Object hooks
+ const { code } = runPlugin(input);
+ expect(code).toHaveWorkletData();
+ expect(code).toMatchSnapshot();
+ });
- it('workletizes useAnimatedGestureHandler wrapped ArrowFunctionExpression automatically', () => {
- const input = html``;
+ it('workletizes hook wrapped named FunctionExpression automatically', () => {
+ const input = html``;
- const { code } = runPlugin(input);
- expect(code).toHaveWorkletData();
- expect(code).toMatchSnapshot();
+ const { code } = runPlugin(input);
+ expect(code).toHaveWorkletData();
+ expect(code).toMatchSnapshot();
+ });
});
- it('workletizes useAnimatedScrollHandler wrapped ArrowFunctionExpression automatically', () => {
- const input = html``;
+ describe('for runOnUI', () => {
+ it('workletizes ArrowFunctionExpression inside runOnUI automatically', () => {
+ const input = html``;
- const { code } = runPlugin(input);
- expect(code).toHaveWorkletData();
- expect(code).toMatchSnapshot();
- });
+ const { code } = runPlugin(input);
+ expect(code).toHaveWorkletData();
+ expect(code).toMatchSnapshot();
+ });
- it('workletizes useAnimatedGestureHandler wrapped unnamed FunctionExpression automatically', () => {
- const input = html``;
+ it('workletizes unnamed FunctionExpression inside runOnUI automatically', () => {
+ const input = html``;
- const { code } = runPlugin(input);
- expect(code).toHaveWorkletData();
- expect(code).toMatchSnapshot();
- });
+ const { code } = runPlugin(input);
+ expect(code).toHaveWorkletData();
+ expect(code).toMatchSnapshot();
+ });
- it('workletizes useAnimatedScrollHandler wrapped unnamed FunctionExpression automatically', () => {
- const input = html``;
+ it('workletizes named FunctionExpression inside runOnUI automatically', () => {
+ const input = html``;
- const { code } = runPlugin(input);
- expect(code).toHaveWorkletData();
- expect(code).toMatchSnapshot();
+ const { code } = runPlugin(input);
+ expect(code).toHaveWorkletData();
+ expect(code).toMatchSnapshot();
+ });
});
- it('workletizes useAnimatedGestureHandler wrapped named FunctionExpression automatically', () => {
- const input = html``;
+ describe('for object hooks', () => {
+ it('workletizes useAnimatedGestureHandler wrapped ArrowFunctionExpression automatically', () => {
+ const input = html``;
- const { code } = runPlugin(input);
- expect(code).toHaveWorkletData();
- expect(code).toMatchSnapshot();
- });
+ const { code } = runPlugin(input);
+ expect(code).toHaveWorkletData();
+ expect(code).toMatchSnapshot();
+ });
- it('workletizes useAnimatedScrollHandler wrapped named FunctionExpression automatically', () => {
- const input = html``;
+ it('workletizes useAnimatedScrollHandler wrapped ArrowFunctionExpression automatically', () => {
+ const input = html``;
- const { code } = runPlugin(input);
- expect(code).toHaveWorkletData();
- expect(code).toMatchSnapshot();
- });
+ const { code } = runPlugin(input);
+ expect(code).toHaveWorkletData();
+ expect(code).toMatchSnapshot();
+ });
- it('workletizes useAnimatedGestureHandler wrapped ObjectMethod automatically', () => {
- const input = html``;
+ it('workletizes useAnimatedGestureHandler wrapped unnamed FunctionExpression automatically', () => {
+ const input = html``;
- const { code } = runPlugin(input);
- expect(code).toHaveWorkletData();
- expect(code).toMatchSnapshot();
- });
+ const { code } = runPlugin(input);
+ expect(code).toHaveWorkletData();
+ expect(code).toMatchSnapshot();
+ });
- it('workletizes useAnimatedScrollHandler wrapped ObjectMethod automatically', () => {
- const input = html``;
+ it('workletizes useAnimatedScrollHandler wrapped unnamed FunctionExpression automatically', () => {
+ const input = html``;
- const { code } = runPlugin(input);
- expect(code).toHaveWorkletData();
- expect(code).toMatchSnapshot();
- });
+ const { code } = runPlugin(input);
+ expect(code).toHaveWorkletData();
+ expect(code).toMatchSnapshot();
+ });
- it('supports empty object in useAnimatedGestureHandler', () => {
- const input = html``;
+ it('workletizes useAnimatedGestureHandler wrapped named FunctionExpression automatically', () => {
+ const input = html``;
- const { code } = runPlugin(input);
- expect(code).not.toHaveWorkletData();
- expect(code).toMatchSnapshot();
- });
+ const { code } = runPlugin(input);
+ expect(code).toHaveWorkletData();
+ expect(code).toMatchSnapshot();
+ });
- it('supports empty object in useAnimatedScrollHandler', () => {
- const input = html``;
+ it('workletizes useAnimatedScrollHandler wrapped named FunctionExpression automatically', () => {
+ const input = html``;
- const { code } = runPlugin(input);
- expect(code).not.toHaveWorkletData();
- expect(code).toMatchSnapshot();
- });
+ const { code } = runPlugin(input);
+ expect(code).toHaveWorkletData();
+ expect(code).toMatchSnapshot();
+ });
- it('transforms each object property in useAnimatedGestureHandler', () => {
- const input = html``;
+ it('workletizes useAnimatedGestureHandler wrapped ObjectMethod automatically', () => {
+ const input = html``;
- const { code } = runPlugin(input);
- expect(code).toHaveWorkletData(3);
- expect(code).toMatchSnapshot();
- });
+ const { code } = runPlugin(input);
+ expect(code).toHaveWorkletData();
+ expect(code).toMatchSnapshot();
+ });
- it('transforms each object property in useAnimatedScrollHandler', () => {
- const input = html``;
+ it('workletizes useAnimatedScrollHandler wrapped ObjectMethod automatically', () => {
+ const input = html``;
- const { code } = runPlugin(input);
- expect(code).toHaveWorkletData(5);
- expect(code).toMatchSnapshot();
- });
+ const { code } = runPlugin(input);
+ expect(code).toHaveWorkletData();
+ expect(code).toMatchSnapshot();
+ });
- it("doesn't transform ArrowFunctionExpression as argument of useAnimatedGestureHandler", () => {
- const input = html``;
+ it('supports empty object in useAnimatedGestureHandler', () => {
+ const input = html``;
- const { code } = runPlugin(input);
- expect(code).not.toHaveWorkletData();
- expect(code).toMatchSnapshot();
- });
+ const { code } = runPlugin(input);
+ expect(code).not.toHaveWorkletData();
+ expect(code).toMatchSnapshot();
+ });
- it("doesn't transform unnamed FunctionExpression as argument of useAnimatedGestureHandler", () => {
- const input = html``;
+ it('supports empty object in useAnimatedScrollHandler', () => {
+ const input = html``;
- const { code } = runPlugin(input);
- expect(code).not.toHaveWorkletData();
- expect(code).toMatchSnapshot();
- });
+ const { code } = runPlugin(input);
+ expect(code).not.toHaveWorkletData();
+ expect(code).toMatchSnapshot();
+ });
- it("doesn't transform named FunctionExpression as argument of useAnimatedGestureHandler", () => {
- const input = html``;
+ it('transforms each object property in useAnimatedGestureHandler', () => {
+ const input = html``;
- const { code } = runPlugin(input);
- expect(code).not.toHaveWorkletData();
- expect(code).toMatchSnapshot();
- });
+ const { code } = runPlugin(input);
+ expect(code).toHaveWorkletData(3);
+ expect(code).toMatchSnapshot();
+ });
- it('transforms ArrowFunctionExpression as argument of useAnimatedScrollHandler', () => {
- const input = html``;
+ it('transforms each object property in useAnimatedScrollHandler', () => {
+ const input = html``;
- const { code } = runPlugin(input);
- expect(code).toHaveWorkletData();
- expect(code).toMatchSnapshot();
- });
+ const { code } = runPlugin(input);
+ expect(code).toHaveWorkletData(5);
+ expect(code).toMatchSnapshot();
+ });
- it('transforms unnamed FunctionExpression as argument of useAnimatedScrollHandler', () => {
- const input = html``;
+ it("doesn't transform ArrowFunctionExpression as argument of useAnimatedGestureHandler", () => {
+ const input = html``;
- const { code } = runPlugin(input);
- expect(code).toHaveWorkletData();
- expect(code).toMatchSnapshot();
- });
+ const { code } = runPlugin(input);
+ expect(code).not.toHaveWorkletData();
+ expect(code).toMatchSnapshot();
+ });
- it('transforms named FunctionExpression as argument of useAnimatedScrollHandler', () => {
- const input = html``;
+ it("doesn't transform unnamed FunctionExpression as argument of useAnimatedGestureHandler", () => {
+ const input = html``;
- const { code } = runPlugin(input);
- expect(code).toHaveWorkletData();
- expect(code).toMatchSnapshot();
- });
+ const { code } = runPlugin(input);
+ expect(code).not.toHaveWorkletData();
+ expect(code).toMatchSnapshot();
+ });
- // React Native Gesture Handler
+ it("doesn't transform named FunctionExpression as argument of useAnimatedGestureHandler", () => {
+ const input = html``;
- it('workletizes possibly chained gesture object callback functions automatically', () => {
- const input = html``;
+ `;
- const { code } = runPlugin(input);
- expect(code).toHaveWorkletData(3);
- expect(code).toMatchSnapshot();
- });
+ const { code } = runPlugin(input);
+ expect(code).toHaveWorkletData();
+ expect(code).toMatchSnapshot();
+ });
- it("doesn't workletize irrelevant chained gesture object callback functions", () => {
- const input = html``;
+ it('transforms unnamed FunctionExpression as argument of useAnimatedScrollHandler', () => {
+ const input = html``;
- const { code } = runPlugin(input);
- expect(code).not.toHaveWorkletData();
- expect(code).toMatchSnapshot();
- });
+ const { code } = runPlugin(input);
+ expect(code).toHaveWorkletData();
+ expect(code).toMatchSnapshot();
+ });
- it("doesn't transform standard callback functions", () => {
- const input = html``;
+ it('transforms named FunctionExpression as argument of useAnimatedScrollHandler', () => {
+ const input = html``;
- const { code } = runPlugin(input);
- expect(code).not.toHaveWorkletData();
- expect(code).toMatchSnapshot();
+ const { code } = runPlugin(input);
+ expect(code).toHaveWorkletData();
+ expect(code).toMatchSnapshot();
+ });
});
- it("doesn't transform chained methods of objects containing Gesture property", () => {
- const input = html``;
+ describe('for react-native-gesture-handler', () => {
+ it('workletizes possibly chained gesture object callback functions automatically', () => {
+ const input = html``;
- const { code } = runPlugin(input);
- expect(code).not.toHaveWorkletData();
- expect(code).toMatchSnapshot();
- });
+ const { code } = runPlugin(input);
+ expect(code).toHaveWorkletData(3);
+ expect(code).toMatchSnapshot();
+ });
- it('transforms spread operator in worklets for arrays', () => {
- const input = html``;
+ it("doesn't workletize irrelevant chained gesture object callback functions", () => {
+ const input = html``;
- const { code } = runPlugin(input);
- expect(code).toContain('...[2,3]');
- expect(code).toContain('...bar');
- expect(code).toMatchSnapshot();
- });
+ const { code } = runPlugin(input);
+ expect(code).not.toHaveWorkletData();
+ expect(code).toMatchSnapshot();
+ });
- it('transforms spread operator in worklets for objects', () => {
- const input = html``;
+ it("doesn't transform standard callback functions", () => {
+ const input = html``;
- const { code } = runPlugin(input);
- expect(code).toContain('...{b:2,c:3}');
- expect(code).toContain('...bar');
- expect(code).toMatchSnapshot();
- });
+ const { code } = runPlugin(input);
+ expect(code).not.toHaveWorkletData();
+ expect(code).toMatchSnapshot();
+ });
- it('transforms spread operator in worklets for function arguments', () => {
- const input = html``;
+ it("doesn't transform chained methods of objects containing Gesture property", () => {
+ const input = html``;
- const { code } = runPlugin(input);
- expect(code).toContain('...args');
- expect(code).toMatchSnapshot();
- });
+ const { code } = runPlugin(input);
+ expect(code).not.toHaveWorkletData();
+ expect(code).toMatchSnapshot();
+ });
- it('transforms spread operator in worklets for function calls', () => {
- const input = html``;
+ it('transforms spread operator in worklets for arrays', () => {
+ const input = html``;
- const { code } = runPlugin(input);
- expect(code).toContain('...arg');
- expect(code).toMatchSnapshot();
- });
+ const { code } = runPlugin(input);
+ expect(code).toContain('...[2,3]');
+ expect(code).toContain('...bar');
+ expect(code).toMatchSnapshot();
+ });
- it('transforms spread operator in Animated component', () => {
- const input = html``;
+ it('transforms spread operator in worklets for objects', () => {
+ const input = html``;
- const { code } = runPlugin(input);
- expect(code).toMatchSnapshot();
- });
+ const { code } = runPlugin(input);
+ expect(code).toContain('...{b:2,c:3}');
+ expect(code).toContain('...bar');
+ expect(code).toMatchSnapshot();
+ });
- // SequenceExpressions
- it('supports SequenceExpression', () => {
- const input = html``;
+ it('transforms spread operator in worklets for function arguments', () => {
+ const input = html``;
- const { code } = runPlugin(input);
- expect(code).toMatchSnapshot();
- });
+ const { code } = runPlugin(input);
+ expect(code).toContain('...args');
+ expect(code).toMatchSnapshot();
+ });
- it('supports SequenceExpression, with objectHook', () => {
- const input = html``;
+ it('transforms spread operator in worklets for function calls', () => {
+ const input = html``;
- const { code } = runPlugin(input);
- expect(code).toHaveWorkletData();
- expect(code).toMatchSnapshot();
- });
+ const { code } = runPlugin(input);
+ expect(code).toContain('...arg');
+ expect(code).toMatchSnapshot();
+ });
- it('supports SequenceExpression, with worklet', () => {
- const input = html``;
+ it('transforms spread operator in Animated component', () => {
+ const input = html``;
- const { code } = runPlugin(input);
- expect(code).toHaveWorkletData();
- expect(code).not.toContain("'worklet';");
- expect(code).toMatchSnapshot();
+ const { code } = runPlugin(input);
+ expect(code).toMatchSnapshot();
+ });
});
- it('supports SequenceExpression, many arguments', () => {
- const input = html``;
+
+ const { code } = runPlugin(input);
+ expect(code).toMatchSnapshot();
+ });
+
+ it('supports SequenceExpression, with objectHook', () => {
+ const input = html``;
+
+ const { code } = runPlugin(input);
+ expect(code).toHaveWorkletData();
+ expect(code).toMatchSnapshot();
+ });
+
+ it('supports SequenceExpression, with worklet', () => {
+ const input = html``;
+ []
+ );
+ }
+ `;
- const { code } = runPlugin(input);
- expect(code).toHaveWorkletData();
- expect(code).not.toContain("'worklet';");
- expect(code).toMatchSnapshot();
- });
+ const { code } = runPlugin(input);
+ expect(code).toHaveWorkletData();
+ expect(code).not.toContain("'worklet';");
+ expect(code).toMatchSnapshot();
+ });
- it('supports SequenceExpression, with worklet closure', () => {
- const input = html``;
+ []
+ );
+ }
+ `;
+
+ const { code } = runPlugin(input);
+ expect(code).toHaveWorkletData();
+ expect(code).not.toContain("'worklet';");
+ expect(code).toMatchSnapshot();
+ });
- const { code, ast } = runPlugin(input, { ast: true });
- let closureBindings;
- traverse(ast, {
- enter(path) {
- if (
- path.isAssignmentExpression() &&
- 'property' in path.node.left &&
- 'name' in path.node.left.property &&
- 'properties' in path.node.right &&
- path.node.left.property.name === '_closure'
- ) {
- closureBindings = path.node.right.properties;
+ it('supports SequenceExpression, with worklet closure', () => {
+ const input = html``;
+
+ const { code, ast } = runPlugin(input, { ast: true });
+ let closureBindings;
+ traverse(ast, {
+ enter(path) {
+ if (
+ path.isAssignmentExpression() &&
+ 'property' in path.node.left &&
+ 'name' in path.node.left.property &&
+ 'properties' in path.node.right &&
+ path.node.left.property.name === '_closure'
+ ) {
+ closureBindings = path.node.right.properties;
+ }
+ },
+ });
+ expect(closureBindings).toHaveLength(1);
+ expect(code).toMatchSnapshot();
});
- expect(closureBindings).toHaveLength(1);
- expect(code).toMatchSnapshot();
});
- // TODO add a test that will workletize only last function in sequence expression
-
- // Inline styles
-
- it('shows a warning if user uses .value inside inline style', () => {
- const input = html``;
+ describe('for inline styles', () => {
+ it('shows a warning if user uses .value inside inline style', () => {
+ const input = html``;
- const { code } = runPlugin(input);
- expect(code).toHaveInlineStyleWarning();
- expect(code).toMatchSnapshot();
- });
+ const { code } = runPlugin(input);
+ expect(code).toHaveInlineStyleWarning();
+ expect(code).toMatchSnapshot();
+ });
- it('shows a warning if user uses .value inside inline style, style array', () => {
- const input = html``;
+ it('shows a warning if user uses .value inside inline style, style array', () => {
+ const input = html``;
- const { code } = runPlugin(input);
- expect(code).toHaveInlineStyleWarning();
- expect(code).toMatchSnapshot();
- });
+ const { code } = runPlugin(input);
+ expect(code).toHaveInlineStyleWarning();
+ expect(code).toMatchSnapshot();
+ });
- it('shows a warning if user uses .value inside inline style, transforms', () => {
- const input = html``;
+ it('shows a warning if user uses .value inside inline style, transforms', () => {
+ const input = html``;
- const { code } = runPlugin(input);
- expect(code).toHaveInlineStyleWarning();
- expect(code).toMatchSnapshot();
- });
+ const { code } = runPlugin(input);
+ expect(code).toHaveInlineStyleWarning();
+ expect(code).toMatchSnapshot();
+ });
- it("doesn't show a warning if user writes something like style={styles.value}", () => {
- const input = html``;
+ it("doesn't show a warning if user writes something like style={styles.value}", () => {
+ const input = html``;
- const { code } = runPlugin(input);
- expect(code).not.toHaveInlineStyleWarning();
- expect(code).toMatchSnapshot();
+ const { code } = runPlugin(input);
+ expect(code).not.toHaveInlineStyleWarning();
+ expect(code).toMatchSnapshot();
+ // });
+ });
});
- // Idempotency
- it('is indempotent for common cases', () => {
+ describe('is indempotent for common cases', () => {
function resultIsIdempotent(input: string) {
const firstResult = runPlugin(input).code;
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
@@ -1125,4 +1129,84 @@ describe('babel plugin', () => {
`;
expect(resultIsIdempotent(input9)).toBe(true);
});
+
+ describe('for UIRuntimeChecks', () => {
+ it("doesn't change _WORKLET in non-worklets", () => {
+ const input = html``;
+
+ const { code } = runPlugin(input);
+
+ expect(code).toHaveUIRuntimeCheck();
+ expect(code).toMatchSnapshot();
+ });
+
+ it("doesn't change global._WORKLET in non-worklets", () => {
+ const input = html``;
+
+ const { code } = runPlugin(input);
+
+ expect(code).toHaveUIRuntimeCheck();
+ expect(code).toMatchSnapshot();
+ });
+
+ it('changes _WORKLET in worklets', () => {
+ const input = html``;
+
+ const { code } = runPlugin(input);
+
+ expect(code).toHaveUIRuntimeCheck(1);
+ expect(code).toMatchSnapshot();
+ });
+
+ it('changes global._WORKLET in worklets', () => {
+ const input = html``;
+
+ const { code } = runPlugin(input);
+
+ expect(code).toHaveUIRuntimeCheck(1);
+ expect(code).toMatchSnapshot();
+ });
+
+ it('changes _WORKLET and global._WORKLET in worklets', () => {
+ const input = html``;
+
+ const { code } = runPlugin(input);
+
+ expect(code).toHaveUIRuntimeCheck(2);
+ expect(code).toMatchSnapshot();
+ });
+ });
});
diff --git a/plugin/build/plugin.js b/plugin/build/plugin.js
index 89bf7caf550a..f297d74cfc9a 100644
--- a/plugin/build/plugin.js
+++ b/plugin/build/plugin.js
@@ -244,7 +244,7 @@ var require_makeWorklet = __commonJS({
return mod && mod.__esModule ? mod : { "default": mod };
};
Object.defineProperty(exports2, "__esModule", { value: true });
- exports2.makeWorklet = void 0;
+ exports2.makeWorklet = exports2.UI_RUNTIME_CHECK_REGEX = void 0;
var core_1 = require("@babel/core");
var generator_1 = __importDefault(require("@babel/generator"));
var types_1 = require("@babel/types");
@@ -254,20 +254,16 @@ var require_makeWorklet = __commonJS({
var path_1 = require("path");
var buildWorkletString_1 = require_buildWorkletString();
var version = require("../../package.json").version;
+ exports2.UI_RUNTIME_CHECK_REGEX = /(global.)?_WORKLET/g;
function makeWorklet(fun, state) {
const functionName = makeWorkletName(fun);
- fun.traverse({
- DirectiveLiteral(path) {
- if (path.node.value === "worklet" && path.getFunctionParent() === fun) {
- path.parentPath.remove();
- }
- }
- });
+ removeWorkletDirective(fun);
(0, assert_1.strict)(state.file.opts.filename, "'state.file.opts.filename' is undefined");
const codeObject = (0, generator_1.default)(fun.node, {
sourceMaps: true,
sourceFileName: state.file.opts.filename
});
+ codeObject.code = codeObject.code.replace(exports2.UI_RUNTIME_CHECK_REGEX, "true");
codeObject.code = "(" + ((0, types_1.isObjectMethod)(fun) ? "function " : "") + codeObject.code + "\n)";
const transformed = (0, core_1.transformSync)(codeObject.code, {
filename: state.file.opts.filename,
@@ -346,6 +342,15 @@ var require_makeWorklet = __commonJS({
return newFun;
}
exports2.makeWorklet = makeWorklet;
+ function removeWorkletDirective(fun) {
+ fun.traverse({
+ DirectiveLiteral(path) {
+ if (path.node.value === "worklet" && path.getFunctionParent() === fun) {
+ path.parentPath.remove();
+ }
+ }
+ });
+ }
function shouldInjectVersion() {
if ((0, utils_1.isRelease)()) {
return false;
diff --git a/plugin/build/plugin.js.map b/plugin/build/plugin.js.map
index 87048a8f9ae9..c32507fe661c 100644
--- a/plugin/build/plugin.js.map
+++ b/plugin/build/plugin.js.map
@@ -1,7 +1,7 @@
{
"version": 3,
"sources": ["../src/commonObjects.ts", "../src/utils.ts", "../src/buildWorkletString.ts", "../src/makeWorklet.ts", "../src/processWorkletObjectMethod.ts", "../src/processIfWorkletFunction.ts", "../src/processForCalleesWorklets.ts", "../src/processIfWorkletNode.ts", "../src/processIfGestureHandlerEventCallbackFunctionNode.ts", "../src/processInlineStylesWarning.ts", "../src/plugin.ts"],
- "sourcesContent": ["export const globals = new Set([\n 'this',\n 'console',\n 'performance',\n 'Date',\n 'Array',\n 'ArrayBuffer',\n 'Int8Array',\n 'Int16Array',\n 'Int32Array',\n 'Uint8Array',\n 'Uint8ClampedArray',\n 'Uint16Array',\n 'Uint32Array',\n 'Float32Array',\n 'Float64Array',\n 'HermesInternal',\n 'JSON',\n 'Math',\n 'Number',\n 'Object',\n 'String',\n 'Symbol',\n 'undefined',\n 'null',\n 'UIManager',\n 'requestAnimationFrame',\n 'setImmediate',\n 'queueMicrotask',\n '_WORKLET',\n 'arguments',\n 'Boolean',\n 'parseInt',\n 'parseFloat',\n 'Map',\n 'WeakMap',\n 'Proxy',\n 'WeakRef',\n 'Set',\n '_log',\n '_scheduleOnJS',\n '_makeShareableClone',\n '_updateDataSynchronously',\n 'eval',\n '_updatePropsPaper',\n '_updatePropsFabric',\n '_removeFromPropsRegistry',\n 'RegExp',\n 'Error',\n '__ErrorUtils',\n 'global',\n '_measurePaper',\n '_measureFabric',\n '_scrollToPaper',\n '_dispatchCommandFabric',\n '_setGestureState',\n 'isNaN',\n 'LayoutAnimationRepository',\n '_notifyAboutProgress',\n '_notifyAboutEnd',\n '_runOnUIQueue',\n]);\n", "export function isRelease() {\n return (\n process.env.BABEL_ENV &&\n ['production', 'release'].includes(process.env.BABEL_ENV)\n );\n}\n", "import {\n BabelFileResult,\n NodePath,\n transformSync,\n PluginItem,\n} from '@babel/core';\nimport generate from '@babel/generator';\nimport {\n ObjectMethod,\n isObjectMethod,\n FunctionDeclaration,\n FunctionExpression,\n ArrowFunctionExpression,\n identifier,\n Identifier,\n objectProperty,\n isArrowFunctionExpression,\n variableDeclaration,\n variableDeclarator,\n isBlockStatement,\n functionExpression,\n isFunctionDeclaration,\n VariableDeclaration,\n ExpressionStatement,\n isProgram,\n memberExpression,\n File as BabelFile,\n objectPattern,\n thisExpression,\n isExpression,\n isExpressionStatement,\n} from '@babel/types';\nimport * as fs from 'fs';\nimport * as convertSourceMap from 'convert-source-map';\nimport { strict as assert } from 'assert';\nimport { isRelease } from './utils';\n\nexport function buildWorkletString(\n fun: BabelFile,\n closureVariables: Array,\n name: string,\n inputMap: BabelFileResult['map']\n): Array {\n const draftExpression = (fun.program.body.find((obj) =>\n isFunctionDeclaration(obj)\n ) ||\n fun.program.body.find((obj) => isExpressionStatement(obj)) ||\n undefined) as FunctionDeclaration | ExpressionStatement | undefined;\n\n assert(draftExpression, \"'draftExpression' is undefined\");\n\n const expression = isFunctionDeclaration(draftExpression)\n ? draftExpression\n : draftExpression.expression;\n\n assert(\n 'params' in expression,\n \"'params' property is undefined in 'expression'\"\n );\n assert(\n isBlockStatement(expression.body),\n \"'expression.body' is not a 'BlockStatement'\"\n );\n\n const workletFunction = functionExpression(\n identifier(name),\n expression.params,\n expression.body\n );\n\n const code = generate(workletFunction).code;\n\n assert(inputMap, \"'inputMap' is undefined\");\n\n const includeSourceMap = shouldGenerateSourceMap();\n\n if (includeSourceMap) {\n // Clear contents array (should be empty anyways)\n inputMap.sourcesContent = [];\n // Include source contents in source map, because Flipper/iframe is not\n // allowed to read files from disk.\n for (const sourceFile of inputMap.sources) {\n inputMap.sourcesContent.push(\n fs.readFileSync(sourceFile).toString('utf-8')\n );\n }\n }\n\n const transformed = transformSync(code, {\n plugins: [prependClosureVariablesIfNecessary(closureVariables)],\n compact: !includeSourceMap,\n sourceMaps: includeSourceMap,\n inputSourceMap: inputMap,\n ast: false,\n babelrc: false,\n configFile: false,\n comments: false,\n });\n\n assert(transformed, \"'transformed' is null\");\n\n let sourceMap;\n if (includeSourceMap) {\n sourceMap = convertSourceMap.fromObject(transformed.map).toObject();\n // sourcesContent field contains a full source code of the file which contains the worklet\n // and is not needed by the source map interpreter in order to symbolicate a stack trace.\n // Therefore, we remove it to reduce the bandwith and avoid sending it potentially multiple times\n // in files that contain multiple worklets. Along with sourcesContent.\n delete sourceMap.sourcesContent;\n }\n\n return [transformed.code, JSON.stringify(sourceMap)];\n}\n\nfunction shouldGenerateSourceMap() {\n if (isRelease()) {\n return false;\n }\n\n // We want to detect this, so we can disable source maps (because they break\n // snapshot tests with jest).\n if (process.env.REANIMATED_JEST_DISABLE_SOURCEMAP === 'jest') {\n return false;\n }\n\n return true;\n}\n\nfunction prependClosure(\n path: NodePath<\n | FunctionDeclaration\n | FunctionExpression\n | ArrowFunctionExpression\n | ObjectMethod\n >,\n closureVariables: Array,\n closureDeclaration: VariableDeclaration\n) {\n if (closureVariables.length === 0 || !isProgram(path.parent)) {\n return;\n }\n\n if (!isExpression(path.node.body)) {\n path.node.body.body.unshift(closureDeclaration);\n }\n}\n\nfunction prependRecursiveDeclaration(\n path: NodePath<\n | FunctionDeclaration\n | FunctionExpression\n | ArrowFunctionExpression\n | ObjectMethod\n >\n) {\n if (\n isProgram(path.parent) &&\n !isArrowFunctionExpression(path.node) &&\n !isObjectMethod(path.node) &&\n path.node.id &&\n path.scope.parent\n ) {\n const hasRecursiveCalls =\n path.scope.parent.bindings[path.node.id.name]?.references > 0;\n if (hasRecursiveCalls) {\n path.node.body.body.unshift(\n variableDeclaration('const', [\n variableDeclarator(\n identifier(path.node.id.name),\n memberExpression(thisExpression(), identifier('_recur'))\n ),\n ])\n );\n }\n }\n}\n\nfunction prependClosureVariablesIfNecessary(\n closureVariables: Array\n): PluginItem {\n const closureDeclaration = variableDeclaration('const', [\n variableDeclarator(\n objectPattern(\n closureVariables.map((variable) =>\n objectProperty(\n identifier(variable.name),\n identifier(variable.name),\n false,\n true\n )\n )\n ),\n memberExpression(thisExpression(), identifier('_closure'))\n ),\n ]);\n\n return {\n visitor: {\n 'FunctionDeclaration|FunctionExpression|ArrowFunctionExpression|ObjectMethod':\n (\n path: NodePath<\n | FunctionDeclaration\n | FunctionExpression\n | ArrowFunctionExpression\n | ObjectMethod\n >\n ) => {\n prependClosure(path, closureVariables, closureDeclaration);\n prependRecursiveDeclaration(path);\n },\n },\n };\n}\n", "import { NodePath, transformSync, traverse } from '@babel/core';\nimport generate from '@babel/generator';\nimport {\n ObjectMethod,\n isObjectMethod,\n FunctionDeclaration,\n FunctionExpression,\n ArrowFunctionExpression,\n identifier,\n Identifier,\n objectProperty,\n variableDeclaration,\n variableDeclarator,\n cloneNode,\n isBlockStatement,\n functionExpression,\n objectExpression,\n stringLiteral,\n isFunctionDeclaration,\n VariableDeclaration,\n ExpressionStatement,\n ReturnStatement,\n isProgram,\n isObjectProperty,\n isMemberExpression,\n isObjectExpression,\n expressionStatement,\n assignmentExpression,\n memberExpression,\n numericLiteral,\n arrayExpression,\n newExpression,\n returnStatement,\n blockStatement,\n isFunctionExpression,\n isIdentifier,\n File as BabelFile,\n} from '@babel/types';\nimport { ReanimatedPluginPass } from './types';\nimport { isRelease } from './utils';\nimport { strict as assert } from 'assert';\nimport { globals } from './commonObjects';\nimport { relative } from 'path';\nimport { buildWorkletString } from './buildWorkletString';\n\nconst version = require('../../package.json').version;\n\nexport function makeWorklet(\n fun: NodePath<\n | FunctionDeclaration\n | FunctionExpression\n | ObjectMethod\n | ArrowFunctionExpression\n >,\n state: ReanimatedPluginPass\n): FunctionExpression {\n // Returns a new FunctionExpression which is a workletized version of provided\n // FunctionDeclaration, FunctionExpression, ArrowFunctionExpression or ObjectMethod.\n\n const functionName = makeWorkletName(fun);\n\n // remove 'worklet'; directive before generating string\n fun.traverse({\n DirectiveLiteral(path) {\n if (path.node.value === 'worklet' && path.getFunctionParent() === fun) {\n path.parentPath.remove();\n }\n },\n });\n\n // We use copy because some of the plugins don't update bindings and\n // some even break them\n assert(state.file.opts.filename, \"'state.file.opts.filename' is undefined\");\n\n const codeObject = generate(fun.node, {\n sourceMaps: true,\n sourceFileName: state.file.opts.filename,\n });\n\n // We need to add a newline at the end, because there could potentially be a\n // comment after the function that gets included here, and then the closing\n // bracket would become part of the comment thus resulting in an error, since\n // there is a missing closing bracket.\n codeObject.code =\n '(' + (isObjectMethod(fun) ? 'function ' : '') + codeObject.code + '\\n)';\n\n const transformed = transformSync(codeObject.code, {\n filename: state.file.opts.filename,\n presets: [require.resolve('@babel/preset-typescript')],\n plugins: [\n require.resolve('@babel/plugin-transform-shorthand-properties'),\n require.resolve('@babel/plugin-transform-arrow-functions'),\n require.resolve('@babel/plugin-proposal-optional-chaining'),\n require.resolve('@babel/plugin-proposal-nullish-coalescing-operator'),\n [\n require.resolve('@babel/plugin-transform-template-literals'),\n { loose: true },\n ],\n ],\n ast: true,\n babelrc: false,\n configFile: false,\n inputSourceMap: codeObject.map,\n });\n\n assert(transformed, \"'transformed' is undefined\");\n assert(transformed.ast, \"'transformed.ast' is undefined\");\n\n const variables = makeArrayFromCapturedBindings(transformed.ast, fun);\n\n const privateFunctionId = identifier('_f');\n const clone = cloneNode(fun.node);\n const funExpression = isBlockStatement(clone.body)\n ? functionExpression(null, clone.params, clone.body)\n : clone;\n\n const [funString, sourceMapString] = buildWorkletString(\n transformed.ast,\n variables,\n functionName,\n transformed.map\n );\n assert(funString, \"'funString' is undefined\");\n const workletHash = hash(funString);\n\n let location = state.file.opts.filename;\n if (state.opts.relativeSourceLocation) {\n location = relative(state.cwd, location);\n }\n\n let lineOffset = 1;\n if (variables.length > 0) {\n // When worklet captures some variables, we append closure destructing at\n // the beginning of the function body. This effectively results in line\n // numbers shifting by the number of captured variables (size of the\n // closure) + 2 (for the opening and closing brackets of the destruct\n // statement)\n lineOffset -= variables.length + 2;\n }\n\n const pathForStringDefinitions = fun.parentPath.isProgram()\n ? fun\n : fun.findParent((path) => isProgram(path.parentPath));\n assert(pathForStringDefinitions, \"'pathForStringDefinitions' is null\");\n assert(\n pathForStringDefinitions.parentPath,\n \"'pathForStringDefinitions.parentPath' is null\"\n );\n\n const initDataId =\n pathForStringDefinitions.parentPath.scope.generateUidIdentifier(\n `worklet_${workletHash}_init_data`\n );\n\n const initDataObjectExpression = objectExpression([\n objectProperty(identifier('code'), stringLiteral(funString)),\n objectProperty(identifier('location'), stringLiteral(location)),\n ]);\n\n if (sourceMapString) {\n initDataObjectExpression.properties.push(\n objectProperty(identifier('sourceMap'), stringLiteral(sourceMapString))\n );\n }\n\n pathForStringDefinitions.insertBefore(\n variableDeclaration('const', [\n variableDeclarator(initDataId, initDataObjectExpression),\n ])\n );\n\n assert(\n !isFunctionDeclaration(funExpression),\n \"'funExpression' is a 'FunctionDeclaration'\"\n );\n assert(\n !isObjectMethod(funExpression),\n \"'funExpression' is an 'ObjectMethod'\"\n );\n\n const statements: Array<\n VariableDeclaration | ExpressionStatement | ReturnStatement\n > = [\n variableDeclaration('const', [\n variableDeclarator(privateFunctionId, funExpression),\n ]),\n expressionStatement(\n assignmentExpression(\n '=',\n memberExpression(privateFunctionId, identifier('_closure'), false),\n objectExpression(\n variables.map((variable) =>\n objectProperty(identifier(variable.name), variable, false, true)\n )\n )\n )\n ),\n expressionStatement(\n assignmentExpression(\n '=',\n memberExpression(privateFunctionId, identifier('__initData'), false),\n initDataId\n )\n ),\n expressionStatement(\n assignmentExpression(\n '=',\n memberExpression(privateFunctionId, identifier('__workletHash'), false),\n numericLiteral(workletHash)\n )\n ),\n ];\n\n if (!isRelease()) {\n statements.unshift(\n variableDeclaration('const', [\n variableDeclarator(\n identifier('_e'),\n arrayExpression([\n newExpression(\n memberExpression(identifier('global'), identifier('Error')),\n []\n ),\n numericLiteral(lineOffset),\n numericLiteral(-27), // the placement of opening bracket after Exception in line that defined '_e' variable\n ])\n ),\n ])\n );\n statements.push(\n expressionStatement(\n assignmentExpression(\n '=',\n memberExpression(\n privateFunctionId,\n identifier('__stackDetails'),\n false\n ),\n identifier('_e')\n )\n )\n );\n if (shouldInjectVersion()) {\n statements.push(\n expressionStatement(\n assignmentExpression(\n '=',\n memberExpression(privateFunctionId, identifier('__version'), false),\n stringLiteral(version)\n )\n )\n );\n }\n }\n\n statements.push(returnStatement(privateFunctionId));\n\n const newFun = functionExpression(undefined, [], blockStatement(statements));\n\n return newFun;\n}\n\nfunction shouldInjectVersion() {\n // We don't inject version in release since cache is reset there anyway\n if (isRelease()) {\n return false;\n }\n\n // We don't want to pollute tests with current version number so we disable it\n // for all tests (except one)\n if (process.env.REANIMATED_JEST_DISABLE_VERSION === 'jest') {\n return false;\n }\n\n return true;\n}\n\nfunction hash(str: string) {\n let i = str.length;\n let hash1 = 5381;\n let hash2 = 52711;\n\n while (i--) {\n const char = str.charCodeAt(i);\n // eslint-disable-next-line no-bitwise\n hash1 = (hash1 * 33) ^ char;\n // eslint-disable-next-line no-bitwise\n hash2 = (hash2 * 33) ^ char;\n }\n\n // eslint-disable-next-line no-bitwise\n return (hash1 >>> 0) * 4096 + (hash2 >>> 0);\n}\n\nfunction makeWorkletName(\n fun: NodePath<\n | FunctionDeclaration\n | FunctionExpression\n | ObjectMethod\n | ArrowFunctionExpression\n >\n) {\n if (isObjectMethod(fun.node) && 'name' in fun.node.key) {\n return fun.node.key.name;\n }\n if (isFunctionDeclaration(fun.node) && fun.node.id) {\n return fun.node.id.name;\n }\n if (isFunctionExpression(fun.node) && isIdentifier(fun.node.id)) {\n return fun.node.id.name;\n }\n return 'anonymous'; // fallback for ArrowFunctionExpression and unnamed FunctionExpression\n}\n\nfunction makeArrayFromCapturedBindings(\n ast: BabelFile,\n fun: NodePath<\n | FunctionDeclaration\n | FunctionExpression\n | ObjectMethod\n | ArrowFunctionExpression\n >\n) {\n const closure = new Map();\n\n // this traversal looks for variables to capture\n traverse(ast, {\n Identifier(path) {\n // we only capture variables that were declared outside of the scope\n if (!path.isReferencedIdentifier()) {\n return;\n }\n const name = path.node.name;\n // if the function is named and was added to globals we don't want to add it to closure\n // hence we check if identifier has that name\n if (globals.has(name)) {\n return;\n }\n if (\n 'id' in fun.node &&\n fun.node.id &&\n fun.node.id.name === name // we don't want to capture function's own name\n ) {\n return;\n }\n\n const parentNode = path.parent;\n\n if (\n isMemberExpression(parentNode) &&\n parentNode.property === path.node &&\n !parentNode.computed\n ) {\n return;\n }\n\n if (\n isObjectProperty(parentNode) &&\n isObjectExpression(path.parentPath.parent) &&\n path.node !== parentNode.value\n ) {\n return;\n }\n\n let currentScope = path.scope;\n\n while (currentScope != null) {\n if (currentScope.bindings[name] != null) {\n return;\n }\n currentScope = currentScope.parent;\n }\n closure.set(name, path.node);\n },\n });\n\n return Array.from(closure.values());\n}\n", "import { NodePath } from '@babel/core';\nimport {\n ObjectMethod,\n identifier,\n isIdentifier,\n isFunctionParent,\n objectProperty,\n callExpression,\n} from '@babel/types';\nimport { ReanimatedPluginPass } from './types';\nimport { makeWorklet } from './makeWorklet';\n\nexport function processWorkletObjectMethod(\n path: NodePath,\n state: ReanimatedPluginPass\n) {\n // Replaces ObjectMethod with a workletized version of itself.\n\n if (!isFunctionParent(path)) {\n return;\n }\n\n const newFun = makeWorklet(path, state);\n\n const replacement = objectProperty(\n identifier(isIdentifier(path.node.key) ? path.node.key.name : ''),\n callExpression(newFun, [])\n );\n\n path.replaceWith(replacement);\n}\n", "import { NodePath, Node } from '@babel/core';\nimport {\n FunctionDeclaration,\n FunctionExpression,\n ArrowFunctionExpression,\n callExpression,\n isScopable,\n isExportNamedDeclaration,\n variableDeclaration,\n variableDeclarator,\n} from '@babel/types';\nimport { ReanimatedPluginPass } from './types';\nimport { makeWorklet } from './makeWorklet';\n\n// Replaces FunctionDeclaration, FunctionExpression or ArrowFunctionExpression\n// with a workletized version of itself.\n\nexport function processIfWorkletFunction(\n path: NodePath,\n state: ReanimatedPluginPass\n) {\n if (\n path.isFunctionDeclaration() ||\n path.isFunctionExpression() ||\n path.isArrowFunctionExpression()\n ) {\n processWorkletFunction(path, state);\n }\n}\n\nfunction processWorkletFunction(\n path: NodePath<\n FunctionDeclaration | FunctionExpression | ArrowFunctionExpression\n >,\n state: ReanimatedPluginPass\n) {\n const newFun = makeWorklet(path, state);\n\n const replacement = callExpression(newFun, []);\n\n // we check if function needs to be assigned to variable declaration.\n // This is needed if function definition directly in a scope. Some other ways\n // where function definition can be used is for example with variable declaration:\n // const ggg = function foo() { }\n // ^ in such a case we don't need to define variable for the function\n const needDeclaration =\n isScopable(path.parent) || isExportNamedDeclaration(path.parent);\n path.replaceWith(\n 'id' in path.node && path.node.id && needDeclaration\n ? variableDeclaration('const', [\n variableDeclarator(path.node.id, replacement),\n ])\n : replacement\n );\n}\n", "import { NodePath } from '@babel/core';\nimport {\n CallExpression,\n isSequenceExpression,\n ObjectExpression,\n} from '@babel/types';\nimport { ReanimatedPluginPass } from './types';\nimport { processWorkletObjectMethod } from './processWorkletObjectMethod';\nimport { processIfWorkletFunction } from './processIfWorkletFunction';\nimport { strict as assert } from 'assert';\n\nconst functionArgsToWorkletize = new Map([\n ['useFrameCallback', [0]],\n ['useAnimatedStyle', [0]],\n ['useAnimatedProps', [0]],\n ['createAnimatedPropAdapter', [0]],\n ['useDerivedValue', [0]],\n ['useAnimatedScrollHandler', [0]],\n ['useAnimatedReaction', [0, 1]],\n ['useWorkletCallback', [0]],\n // animations' callbacks\n ['withTiming', [2]],\n ['withSpring', [2]],\n ['withDecay', [1]],\n ['withRepeat', [3]],\n // scheduling functions\n ['runOnUI', [0]],\n]);\n\nconst objectHooks = new Set([\n 'useAnimatedGestureHandler',\n 'useAnimatedScrollHandler',\n]);\n\nexport function processForCalleesWorklets(\n path: NodePath,\n state: ReanimatedPluginPass\n) {\n const callee = isSequenceExpression(path.node.callee)\n ? path.node.callee.expressions[path.node.callee.expressions.length - 1]\n : path.node.callee;\n\n // We are looking for objects we know we should workletize\n // hence if object is not named, we return.\n const name =\n 'name' in callee\n ? callee.name\n : 'property' in callee && 'name' in callee.property\n ? callee.property.name\n : undefined;\n if (name === undefined) {\n return;\n }\n\n if (objectHooks.has(name)) {\n const workletToProcess = path.get('arguments.0');\n assert(!Array.isArray(workletToProcess), \"'workletToProcess' is an array'\");\n if (workletToProcess.isObjectExpression()) {\n processObjectHook(workletToProcess, state);\n // useAnimatedScrollHandler can take a function as an argument instead of an ObjectExpression\n // but useAnimatedGestureHandler can't\n } else if (name === 'useAnimatedScrollHandler') {\n processIfWorkletFunction(workletToProcess, state);\n }\n } else {\n const indices = functionArgsToWorkletize.get(name);\n if (indices === undefined) {\n return;\n }\n processArguments(path, indices, state);\n }\n}\n\nfunction processObjectHook(\n path: NodePath,\n state: ReanimatedPluginPass\n) {\n const properties = path.get('properties');\n for (const property of properties) {\n if (property.isObjectMethod()) {\n processWorkletObjectMethod(property, state);\n } else if (property.isObjectProperty()) {\n const value = property.get('value');\n processIfWorkletFunction(value, state);\n } else {\n throw new Error(\n `'${property.type}' as to-be workletized arguments is not supported for object hooks`\n );\n }\n }\n}\n\nfunction processArguments(\n path: NodePath,\n indices: number[],\n state: ReanimatedPluginPass\n) {\n const argumentsArray = path.get('arguments');\n indices.forEach((index) => {\n const argumentToWorkletize = argumentsArray[index];\n if (!argumentToWorkletize) {\n // workletizable argument doesn't always have to be specified\n return;\n }\n processIfWorkletFunction(argumentToWorkletize, state);\n });\n}\n", "import { NodePath } from '@babel/core';\nimport {\n FunctionDeclaration,\n FunctionExpression,\n ArrowFunctionExpression,\n isBlockStatement,\n isDirectiveLiteral,\n} from '@babel/types';\nimport { processIfWorkletFunction } from './processIfWorkletFunction';\nimport { ReanimatedPluginPass } from './types';\n\nexport function processIfWorkletNode(\n fun: NodePath<\n FunctionDeclaration | FunctionExpression | ArrowFunctionExpression\n >,\n state: ReanimatedPluginPass\n) {\n fun.traverse({\n DirectiveLiteral(path) {\n const value = path.node.value;\n if (\n value === 'worklet' &&\n path.getFunctionParent() === fun &&\n isBlockStatement(fun.node.body)\n ) {\n // make sure \"worklet\" is listed among directives for the fun\n // this is necessary as because of some bug, babel will attempt to\n // process replaced function if it is nested inside another function\n const directives = fun.node.body.directives;\n if (\n directives &&\n directives.length > 0 &&\n directives.some(\n (directive) =>\n isDirectiveLiteral(directive.value) &&\n directive.value.value === 'worklet'\n )\n ) {\n processIfWorkletFunction(fun, state);\n }\n }\n },\n });\n}\n", "import { NodePath } from '@babel/core';\nimport {\n FunctionDeclaration,\n FunctionExpression,\n ArrowFunctionExpression,\n isIdentifier,\n isCallExpression,\n Expression,\n isMemberExpression,\n isExpression,\n} from '@babel/types';\nimport { processIfWorkletFunction } from './processIfWorkletFunction';\nimport { ReanimatedPluginPass } from './types';\n\nconst gestureHandlerGestureObjects = new Set([\n // from https://github.com/software-mansion/react-native-gesture-handler/blob/new-api/src/handlers/gestures/gestureObjects.ts\n 'Tap',\n 'Pan',\n 'Pinch',\n 'Rotation',\n 'Fling',\n 'LongPress',\n 'ForceTouch',\n 'Native',\n 'Manual',\n 'Race',\n 'Simultaneous',\n 'Exclusive',\n]);\n\nconst gestureHandlerBuilderMethods = new Set([\n 'onBegin',\n 'onStart',\n 'onEnd',\n 'onFinalize',\n 'onUpdate',\n 'onChange',\n 'onTouchesDown',\n 'onTouchesMove',\n 'onTouchesUp',\n 'onTouchesCancelled',\n]);\n\n// Auto-workletizes React Native Gesture Handler callback functions.\n// Detects `Gesture.Tap().onEnd()` or similar, but skips `something.onEnd()`.\n// Supports method chaining as well, e.g. `Gesture.Tap().onStart().onUpdate().onEnd()`.\n\n// Example #1: `Gesture.Tap().onEnd()`\n/*\n CallExpression(\n callee: MemberExpression(\n object: CallExpression(\n callee: MemberExpression(\n object: Identifier('Gesture')\n property: Identifier('Tap')\n )\n )\n property: Identifier('onEnd')\n )\n arguments: [fun]\n )\n */\n\n// Example #2: `Gesture.Tap().onStart().onUpdate().onEnd()`\n/*\n CallExpression(\n callee: MemberExpression(\n object: CallExpression(\n callee: MemberExpression(\n object: CallExpression(\n callee: MemberExpression(\n object: CallExpression(\n callee: MemberExpression(\n object: Identifier('Gesture')\n property: Identifier('Tap')\n )\n )\n property: Identifier('onStart')\n )\n arguments: [fun1]\n )\n property: Identifier('onUpdate')\n )\n arguments: [fun2]\n )\n property: Identifier('onEnd')\n )\n arguments: [fun3]\n )\n */\nexport function processIfGestureHandlerEventCallbackFunctionNode(\n path: NodePath<\n FunctionDeclaration | FunctionExpression | ArrowFunctionExpression\n >,\n state: ReanimatedPluginPass\n) {\n if (\n isCallExpression(path.parent) &&\n isExpression(path.parent.callee) &&\n isGestureObjectEventCallbackMethod(path.parent.callee)\n ) {\n processIfWorkletFunction(path, state);\n }\n}\n\nfunction isGestureObjectEventCallbackMethod(exp: Expression) {\n // Checks if node matches the pattern `Gesture.Foo()[*].onBar`\n // where `[*]` represents any number of method calls.\n return (\n isMemberExpression(exp) &&\n isIdentifier(exp.property) &&\n gestureHandlerBuilderMethods.has(exp.property.name) &&\n containsGestureObject(exp.object)\n );\n}\n\nfunction containsGestureObject(exp: Expression) {\n // Checks if node matches the pattern `Gesture.Foo()[*]`\n // where `[*]` represents any number of chained method calls, like `.something(42)`.\n\n // direct call\n if (isGestureObject(exp)) {\n return true;\n }\n\n // method chaining\n if (\n isCallExpression(exp) &&\n isMemberExpression(exp.callee) &&\n containsGestureObject(exp.callee.object)\n ) {\n return true;\n }\n\n return false;\n}\n\nfunction isGestureObject(exp: Expression) {\n // Checks if node matches `Gesture.Tap()` or similar.\n /*\n node: CallExpression(\n callee: MemberExpression(\n object: Identifier('Gesture')\n property: Identifier('Tap')\n )\n )\n */\n return (\n isCallExpression(exp) &&\n isMemberExpression(exp.callee) &&\n isIdentifier(exp.callee.object) &&\n exp.callee.object.name === 'Gesture' &&\n isIdentifier(exp.callee.property) &&\n gestureHandlerGestureObjects.has(exp.callee.property.name)\n );\n}\n", "import { NodePath } from '@babel/core';\nimport {\n MemberExpression,\n callExpression,\n arrowFunctionExpression,\n isArrayExpression,\n ObjectExpression,\n JSXAttribute,\n isJSXExpressionContainer,\n identifier,\n stringLiteral,\n expressionStatement,\n memberExpression,\n returnStatement,\n blockStatement,\n ObjectProperty,\n isIdentifier,\n} from '@babel/types';\nimport { isRelease } from './utils';\nimport { ReanimatedPluginPass } from './types';\nimport { strict as assert } from 'assert';\n\nfunction generateInlineStylesWarning(path: NodePath) {\n // replaces `sharedvalue.value` with `(()=>{console.warn(require('react-native-reanimated').getUseOfValueInStyleWarning());return sharedvalue.value;})()`\n return callExpression(\n arrowFunctionExpression(\n [],\n blockStatement([\n expressionStatement(\n callExpression(\n memberExpression(identifier('console'), identifier('warn')),\n [\n callExpression(\n memberExpression(\n callExpression(identifier('require'), [\n stringLiteral('react-native-reanimated'),\n ]),\n identifier('getUseOfValueInStyleWarning')\n ),\n []\n ),\n ]\n )\n ),\n returnStatement(path.node),\n ])\n ),\n []\n );\n}\n\nfunction processPropertyValueForInlineStylesWarning(\n path: NodePath\n) {\n // if it's something like object.value then raise a warning\n if (path.isMemberExpression() && isIdentifier(path.node.property)) {\n if (path.node.property.name === 'value') {\n path.replaceWith(generateInlineStylesWarning(path));\n }\n }\n}\n\nfunction processTransformPropertyForInlineStylesWarning(\n path: NodePath\n) {\n if (isArrayExpression(path.node)) {\n const elements = path.get('elements');\n assert(Array.isArray(elements), \"'elements' should be an array\");\n for (const element of elements) {\n if (element.isObjectExpression()) {\n processStyleObjectForInlineStylesWarning(element);\n }\n }\n }\n}\n\nfunction processStyleObjectForInlineStylesWarning(\n path: NodePath\n) {\n const properties = path.get('properties');\n for (const property of properties) {\n if (property.isObjectProperty()) {\n const value = property.get('value');\n if (\n isIdentifier(property.node.key) &&\n property.node.key.name === 'transform'\n ) {\n processTransformPropertyForInlineStylesWarning(value);\n } else {\n processPropertyValueForInlineStylesWarning(value);\n }\n }\n }\n}\n\nexport function processInlineStylesWarning(\n path: NodePath,\n state: ReanimatedPluginPass\n) {\n if (isRelease()) {\n return;\n }\n if (state.opts.disableInlineStylesWarning) {\n return;\n }\n if (path.node.name.name !== 'style') {\n return;\n }\n if (!isJSXExpressionContainer(path.node.value)) {\n return;\n }\n\n const expression = path.get('value').get('expression');\n // style={[{...}, {...}]}\n assert(!Array.isArray(expression), \"'expression' should not be an array\");\n if (expression.isArrayExpression()) {\n const elements = expression.get('elements');\n assert(Array.isArray(elements), \"'elements' should be an array\");\n for (const element of elements) {\n if (element.isObjectExpression()) {\n processStyleObjectForInlineStylesWarning(element);\n }\n }\n }\n // style={{...}}\n else if (expression.isObjectExpression()) {\n processStyleObjectForInlineStylesWarning(expression);\n }\n}\n", "import { PluginItem, NodePath } from '@babel/core';\nimport { globals } from './commonObjects';\nimport {\n CallExpression,\n FunctionDeclaration,\n FunctionExpression,\n ArrowFunctionExpression,\n} from '@babel/types';\nimport { processForCalleesWorklets } from './processForCalleesWorklets';\nimport { ReanimatedPluginPass } from './types';\nimport { processIfWorkletNode } from './processIfWorkletNode';\nimport { processIfGestureHandlerEventCallbackFunctionNode } from './processIfGestureHandlerEventCallbackFunctionNode';\nimport { processInlineStylesWarning } from './processInlineStylesWarning';\n\nmodule.exports = function (): PluginItem {\n return {\n pre() {\n // allows adding custom globals such as host-functions\n if (this.opts != null && Array.isArray(this.opts.globals)) {\n this.opts.globals.forEach((name: string) => {\n globals.add(name);\n });\n }\n },\n visitor: {\n CallExpression: {\n enter(path: NodePath, state: ReanimatedPluginPass) {\n processForCalleesWorklets(path, state);\n },\n },\n 'FunctionDeclaration|FunctionExpression|ArrowFunctionExpression': {\n enter(\n path: NodePath<\n FunctionDeclaration | FunctionExpression | ArrowFunctionExpression\n >,\n state: ReanimatedPluginPass\n ) {\n processIfWorkletNode(path, state);\n processIfGestureHandlerEventCallbackFunctionNode(path, state);\n },\n },\n JSXAttribute: {\n enter(path, state) {\n processInlineStylesWarning(path, state);\n },\n },\n },\n };\n};\n"],
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAa,IAAAA,SAAA,UAAU,oBAAI,IAAI;MAC7B;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;KACD;;;;;;;;;;AC7DD,aAAgB,YAAS;AACvB,aACE,QAAQ,IAAI,aACZ,CAAC,cAAc,SAAS,EAAE,SAAS,QAAQ,IAAI,SAAS;IAE5D;AALA,IAAAC,SAAA,YAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACAA,QAAA,SAAA,QAAA,aAAA;AAMA,QAAA,cAAA,gBAAA,QAAA,kBAAA,CAAA;AACA,QAAA,UAAA,QAAA,cAAA;AAyBA,QAAA,KAAA,aAAA,QAAA,IAAA,CAAA;AACA,QAAA,mBAAA,aAAA,QAAA,oBAAA,CAAA;AACA,QAAA,WAAA,QAAA,QAAA;AACA,QAAA,UAAA;AAEA,aAAgB,mBACd,KACA,kBACA,MACA,UAAgC;AAEhC,YAAM,kBAAmB,IAAI,QAAQ,KAAK,KAAK,CAAC,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,UAAI,WAAW,kBAAiB,GAAI;AAClC,cAAM,WAAW,WAAW,IAAI,UAAU;AAC1C,SAAA,GAAA,SAAA,QAAO,MAAM,QAAQ,QAAQ,GAAG,+BAA+B;AAC/D,mBAAW,WAAW,UAAU;AAC9B,cAAI,QAAQ,mBAAkB,GAAI;AAChC,qDAAyC,OAAO;;;iBAK7C,WAAW,mBAAkB,GAAI;AACxC,iDAAyC,UAAU;;IAEvD;AAjCA,IAAAC,SAAA,6BAAA;;;;;;AC9FA,IAAA,kBAAA;AAOA,IAAA,8BAAA;AAEA,IAAA,yBAAA;AACA,IAAA,qDAAA;AACA,IAAA,+BAAA;AAEA,OAAO,UAAU,WAAA;AACf,SAAO;IACL,MAAG;AAED,UAAI,KAAK,QAAQ,QAAQ,MAAM,QAAQ,KAAK,KAAK,OAAO,GAAG;AACzD,aAAK,KAAK,QAAQ,QAAQ,CAAC,SAAgB;AACzC,0BAAA,QAAQ,IAAI,IAAI;QAClB,CAAC;;IAEL;IACA,SAAS;MACP,gBAAgB;QACd,MAAM,MAAgC,OAA2B;AAC/D,WAAA,GAAA,4BAAA,2BAA0B,MAAM,KAAK;QACvC;;MAEF,kEAAkE;QAChE,MACE,MAGA,OAA2B;AAE3B,WAAA,GAAA,uBAAA,sBAAqB,MAAM,KAAK;AAChC,WAAA,GAAA,mDAAA,kDAAiD,MAAM,KAAK;QAC9D;;MAEF,cAAc;QACZ,MAAM,MAAM,OAAK;AACf,WAAA,GAAA,6BAAA,4BAA2B,MAAM,KAAK;QACxC;;;;AAIR;",
+ "sourcesContent": ["export const globals = new Set([\n 'this',\n 'console',\n 'performance',\n 'Date',\n 'Array',\n 'ArrayBuffer',\n 'Int8Array',\n 'Int16Array',\n 'Int32Array',\n 'Uint8Array',\n 'Uint8ClampedArray',\n 'Uint16Array',\n 'Uint32Array',\n 'Float32Array',\n 'Float64Array',\n 'HermesInternal',\n 'JSON',\n 'Math',\n 'Number',\n 'Object',\n 'String',\n 'Symbol',\n 'undefined',\n 'null',\n 'UIManager',\n 'requestAnimationFrame',\n 'setImmediate',\n 'queueMicrotask',\n '_WORKLET',\n 'arguments',\n 'Boolean',\n 'parseInt',\n 'parseFloat',\n 'Map',\n 'WeakMap',\n 'Proxy',\n 'WeakRef',\n 'Set',\n '_log',\n '_scheduleOnJS',\n '_makeShareableClone',\n '_updateDataSynchronously',\n 'eval',\n '_updatePropsPaper',\n '_updatePropsFabric',\n '_removeFromPropsRegistry',\n 'RegExp',\n 'Error',\n '__ErrorUtils',\n 'global',\n '_measurePaper',\n '_measureFabric',\n '_scrollToPaper',\n '_dispatchCommandFabric',\n '_setGestureState',\n 'isNaN',\n 'LayoutAnimationRepository',\n '_notifyAboutProgress',\n '_notifyAboutEnd',\n '_runOnUIQueue',\n]);\n", "export function isRelease() {\n return (\n process.env.BABEL_ENV &&\n ['production', 'release'].includes(process.env.BABEL_ENV)\n );\n}\n", "import {\n BabelFileResult,\n NodePath,\n transformSync,\n PluginItem,\n} from '@babel/core';\nimport generate from '@babel/generator';\nimport {\n isObjectMethod,\n FunctionDeclaration,\n identifier,\n Identifier,\n objectProperty,\n isArrowFunctionExpression,\n variableDeclaration,\n variableDeclarator,\n isBlockStatement,\n functionExpression,\n isFunctionDeclaration,\n VariableDeclaration,\n ExpressionStatement,\n isProgram,\n memberExpression,\n File as BabelFile,\n objectPattern,\n thisExpression,\n isExpression,\n isExpressionStatement,\n} from '@babel/types';\nimport * as fs from 'fs';\nimport * as convertSourceMap from 'convert-source-map';\nimport { strict as assert } from 'assert';\nimport { isRelease } from './utils';\nimport { WorkletizableFunction } from './types';\n\nexport function buildWorkletString(\n fun: BabelFile,\n closureVariables: Array,\n name: string,\n inputMap: BabelFileResult['map']\n): Array {\n const draftExpression = (fun.program.body.find((obj) =>\n isFunctionDeclaration(obj)\n ) ||\n fun.program.body.find((obj) => isExpressionStatement(obj)) ||\n undefined) as FunctionDeclaration | ExpressionStatement | undefined;\n\n assert(draftExpression, \"'draftExpression' is undefined\");\n\n const expression = isFunctionDeclaration(draftExpression)\n ? draftExpression\n : draftExpression.expression;\n\n assert(\n 'params' in expression,\n \"'params' property is undefined in 'expression'\"\n );\n assert(\n isBlockStatement(expression.body),\n \"'expression.body' is not a 'BlockStatement'\"\n );\n\n const workletFunction = functionExpression(\n identifier(name),\n expression.params,\n expression.body\n );\n\n const code = generate(workletFunction).code;\n\n assert(inputMap, \"'inputMap' is undefined\");\n\n const includeSourceMap = shouldGenerateSourceMap();\n\n if (includeSourceMap) {\n // Clear contents array (should be empty anyways)\n inputMap.sourcesContent = [];\n // Include source contents in source map, because Flipper/iframe is not\n // allowed to read files from disk.\n for (const sourceFile of inputMap.sources) {\n inputMap.sourcesContent.push(\n fs.readFileSync(sourceFile).toString('utf-8')\n );\n }\n }\n\n const transformed = transformSync(code, {\n plugins: [prependClosureVariablesIfNecessary(closureVariables)],\n compact: !includeSourceMap,\n sourceMaps: includeSourceMap,\n inputSourceMap: inputMap,\n ast: false,\n babelrc: false,\n configFile: false,\n comments: false,\n });\n\n assert(transformed, \"'transformed' is null\");\n\n let sourceMap;\n if (includeSourceMap) {\n sourceMap = convertSourceMap.fromObject(transformed.map).toObject();\n // sourcesContent field contains a full source code of the file which contains the worklet\n // and is not needed by the source map interpreter in order to symbolicate a stack trace.\n // Therefore, we remove it to reduce the bandwith and avoid sending it potentially multiple times\n // in files that contain multiple worklets. Along with sourcesContent.\n delete sourceMap.sourcesContent;\n }\n\n return [transformed.code, JSON.stringify(sourceMap)];\n}\n\nfunction shouldGenerateSourceMap() {\n if (isRelease()) {\n return false;\n }\n\n // We want to detect this, so we can disable source maps (because they break\n // snapshot tests with jest).\n if (process.env.REANIMATED_JEST_DISABLE_SOURCEMAP === 'jest') {\n return false;\n }\n\n return true;\n}\n\nfunction prependClosure(\n path: NodePath,\n closureVariables: Array,\n closureDeclaration: VariableDeclaration\n) {\n if (closureVariables.length === 0 || !isProgram(path.parent)) {\n return;\n }\n\n if (!isExpression(path.node.body)) {\n path.node.body.body.unshift(closureDeclaration);\n }\n}\n\nfunction prependRecursiveDeclaration(path: NodePath) {\n if (\n isProgram(path.parent) &&\n !isArrowFunctionExpression(path.node) &&\n !isObjectMethod(path.node) &&\n path.node.id &&\n path.scope.parent\n ) {\n const hasRecursiveCalls =\n path.scope.parent.bindings[path.node.id.name]?.references > 0;\n if (hasRecursiveCalls) {\n path.node.body.body.unshift(\n variableDeclaration('const', [\n variableDeclarator(\n identifier(path.node.id.name),\n memberExpression(thisExpression(), identifier('_recur'))\n ),\n ])\n );\n }\n }\n}\n\nfunction prependClosureVariablesIfNecessary(\n closureVariables: Array\n): PluginItem {\n const closureDeclaration = variableDeclaration('const', [\n variableDeclarator(\n objectPattern(\n closureVariables.map((variable) =>\n objectProperty(\n identifier(variable.name),\n identifier(variable.name),\n false,\n true\n )\n )\n ),\n memberExpression(thisExpression(), identifier('_closure'))\n ),\n ]);\n\n return {\n visitor: {\n 'FunctionDeclaration|FunctionExpression|ArrowFunctionExpression|ObjectMethod':\n (path: NodePath) => {\n prependClosure(path, closureVariables, closureDeclaration);\n prependRecursiveDeclaration(path);\n },\n },\n };\n}\n", "import { NodePath, transformSync, traverse } from '@babel/core';\nimport generate from '@babel/generator';\nimport {\n isObjectMethod,\n FunctionExpression,\n identifier,\n Identifier,\n objectProperty,\n variableDeclaration,\n variableDeclarator,\n cloneNode,\n isBlockStatement,\n functionExpression,\n objectExpression,\n stringLiteral,\n isFunctionDeclaration,\n VariableDeclaration,\n ExpressionStatement,\n ReturnStatement,\n isProgram,\n isObjectProperty,\n isMemberExpression,\n isObjectExpression,\n expressionStatement,\n assignmentExpression,\n memberExpression,\n numericLiteral,\n arrayExpression,\n newExpression,\n returnStatement,\n blockStatement,\n isFunctionExpression,\n isIdentifier,\n File as BabelFile,\n} from '@babel/types';\nimport { ReanimatedPluginPass, WorkletizableFunction } from './types';\nimport { isRelease } from './utils';\nimport { strict as assert } from 'assert';\nimport { globals } from './commonObjects';\nimport { relative } from 'path';\nimport { buildWorkletString } from './buildWorkletString';\n\nconst version = require('../../package.json').version;\n\nexport const UI_RUNTIME_CHECK_REGEX = /(global.)?_WORKLET/g;\n\nexport function makeWorklet(\n fun: NodePath,\n state: ReanimatedPluginPass\n): FunctionExpression {\n // Returns a new FunctionExpression which is a workletized version of provided\n // FunctionDeclaration, FunctionExpression, ArrowFunctionExpression or ObjectMethod.\n\n const functionName = makeWorkletName(fun);\n\n removeWorkletDirective(fun);\n\n // We use copy because some of the plugins don't update bindings and\n // some even break them\n assert(state.file.opts.filename, \"'state.file.opts.filename' is undefined\");\n\n const codeObject = generate(fun.node, {\n sourceMaps: true,\n sourceFileName: state.file.opts.filename,\n });\n\n // We change _WORKLET to true to simplify conditionals and avoid\n // situations when _WORKLET is not yet defined but referenced.\n codeObject.code = codeObject.code.replace(UI_RUNTIME_CHECK_REGEX, 'true');\n\n // We need to add a newline at the end, because there could potentially be a\n // comment after the function that gets included here, and then the closing\n // bracket would become part of the comment thus resulting in an error, since\n // there is a missing closing bracket.\n codeObject.code =\n '(' + (isObjectMethod(fun) ? 'function ' : '') + codeObject.code + '\\n)';\n\n const transformed = transformSync(codeObject.code, {\n filename: state.file.opts.filename,\n presets: [require.resolve('@babel/preset-typescript')],\n plugins: [\n require.resolve('@babel/plugin-transform-shorthand-properties'),\n require.resolve('@babel/plugin-transform-arrow-functions'),\n require.resolve('@babel/plugin-proposal-optional-chaining'),\n require.resolve('@babel/plugin-proposal-nullish-coalescing-operator'),\n [\n require.resolve('@babel/plugin-transform-template-literals'),\n { loose: true },\n ],\n ],\n ast: true,\n babelrc: false,\n configFile: false,\n inputSourceMap: codeObject.map,\n });\n\n assert(transformed, \"'transformed' is undefined\");\n assert(transformed.ast, \"'transformed.ast' is undefined\");\n\n const variables = makeArrayFromCapturedBindings(transformed.ast, fun);\n\n const privateFunctionId = identifier('_f');\n const clone = cloneNode(fun.node);\n const funExpression = isBlockStatement(clone.body)\n ? functionExpression(null, clone.params, clone.body)\n : clone;\n\n const [funString, sourceMapString] = buildWorkletString(\n transformed.ast,\n variables,\n functionName,\n transformed.map\n );\n assert(funString, \"'funString' is undefined\");\n const workletHash = hash(funString);\n\n let location = state.file.opts.filename;\n if (state.opts.relativeSourceLocation) {\n location = relative(state.cwd, location);\n }\n\n let lineOffset = 1;\n if (variables.length > 0) {\n // When worklet captures some variables, we append closure destructing at\n // the beginning of the function body. This effectively results in line\n // numbers shifting by the number of captured variables (size of the\n // closure) + 2 (for the opening and closing brackets of the destruct\n // statement)\n lineOffset -= variables.length + 2;\n }\n\n const pathForStringDefinitions = fun.parentPath.isProgram()\n ? fun\n : fun.findParent((path) => isProgram(path.parentPath));\n assert(pathForStringDefinitions, \"'pathForStringDefinitions' is null\");\n assert(\n pathForStringDefinitions.parentPath,\n \"'pathForStringDefinitions.parentPath' is null\"\n );\n\n const initDataId =\n pathForStringDefinitions.parentPath.scope.generateUidIdentifier(\n `worklet_${workletHash}_init_data`\n );\n\n const initDataObjectExpression = objectExpression([\n objectProperty(identifier('code'), stringLiteral(funString)),\n objectProperty(identifier('location'), stringLiteral(location)),\n ]);\n\n if (sourceMapString) {\n initDataObjectExpression.properties.push(\n objectProperty(identifier('sourceMap'), stringLiteral(sourceMapString))\n );\n }\n\n pathForStringDefinitions.insertBefore(\n variableDeclaration('const', [\n variableDeclarator(initDataId, initDataObjectExpression),\n ])\n );\n\n assert(\n !isFunctionDeclaration(funExpression),\n \"'funExpression' is a 'FunctionDeclaration'\"\n );\n assert(\n !isObjectMethod(funExpression),\n \"'funExpression' is an 'ObjectMethod'\"\n );\n\n const statements: Array<\n VariableDeclaration | ExpressionStatement | ReturnStatement\n > = [\n variableDeclaration('const', [\n variableDeclarator(privateFunctionId, funExpression),\n ]),\n expressionStatement(\n assignmentExpression(\n '=',\n memberExpression(privateFunctionId, identifier('_closure'), false),\n objectExpression(\n variables.map((variable) =>\n objectProperty(identifier(variable.name), variable, false, true)\n )\n )\n )\n ),\n expressionStatement(\n assignmentExpression(\n '=',\n memberExpression(privateFunctionId, identifier('__initData'), false),\n initDataId\n )\n ),\n expressionStatement(\n assignmentExpression(\n '=',\n memberExpression(privateFunctionId, identifier('__workletHash'), false),\n numericLiteral(workletHash)\n )\n ),\n ];\n\n if (!isRelease()) {\n statements.unshift(\n variableDeclaration('const', [\n variableDeclarator(\n identifier('_e'),\n arrayExpression([\n newExpression(\n memberExpression(identifier('global'), identifier('Error')),\n []\n ),\n numericLiteral(lineOffset),\n numericLiteral(-27), // the placement of opening bracket after Exception in line that defined '_e' variable\n ])\n ),\n ])\n );\n statements.push(\n expressionStatement(\n assignmentExpression(\n '=',\n memberExpression(\n privateFunctionId,\n identifier('__stackDetails'),\n false\n ),\n identifier('_e')\n )\n )\n );\n if (shouldInjectVersion()) {\n statements.push(\n expressionStatement(\n assignmentExpression(\n '=',\n memberExpression(privateFunctionId, identifier('__version'), false),\n stringLiteral(version)\n )\n )\n );\n }\n }\n\n statements.push(returnStatement(privateFunctionId));\n\n const newFun = functionExpression(undefined, [], blockStatement(statements));\n\n return newFun;\n}\n\nfunction removeWorkletDirective(fun: NodePath) {\n fun.traverse({\n // Remove 'worklet'; directive before generating string.\n DirectiveLiteral(path) {\n if (path.node.value === 'worklet' && path.getFunctionParent() === fun) {\n path.parentPath.remove();\n }\n },\n });\n}\n\nfunction shouldInjectVersion() {\n // We don't inject version in release since cache is reset there anyway\n if (isRelease()) {\n return false;\n }\n\n // We don't want to pollute tests with current version number so we disable it\n // for all tests (except one)\n if (process.env.REANIMATED_JEST_DISABLE_VERSION === 'jest') {\n return false;\n }\n\n return true;\n}\n\nfunction hash(str: string) {\n let i = str.length;\n let hash1 = 5381;\n let hash2 = 52711;\n\n while (i--) {\n const char = str.charCodeAt(i);\n // eslint-disable-next-line no-bitwise\n hash1 = (hash1 * 33) ^ char;\n // eslint-disable-next-line no-bitwise\n hash2 = (hash2 * 33) ^ char;\n }\n\n // eslint-disable-next-line no-bitwise\n return (hash1 >>> 0) * 4096 + (hash2 >>> 0);\n}\n\nfunction makeWorkletName(fun: NodePath) {\n if (isObjectMethod(fun.node) && 'name' in fun.node.key) {\n return fun.node.key.name;\n }\n if (isFunctionDeclaration(fun.node) && fun.node.id) {\n return fun.node.id.name;\n }\n if (isFunctionExpression(fun.node) && isIdentifier(fun.node.id)) {\n return fun.node.id.name;\n }\n return 'anonymous'; // fallback for ArrowFunctionExpression and unnamed FunctionExpression\n}\n\nfunction makeArrayFromCapturedBindings(\n ast: BabelFile,\n fun: NodePath\n) {\n const closure = new Map();\n\n // this traversal looks for variables to capture\n traverse(ast, {\n Identifier(path) {\n // we only capture variables that were declared outside of the scope\n if (!path.isReferencedIdentifier()) {\n return;\n }\n const name = path.node.name;\n // if the function is named and was added to globals we don't want to add it to closure\n // hence we check if identifier has that name\n if (globals.has(name)) {\n return;\n }\n if (\n 'id' in fun.node &&\n fun.node.id &&\n fun.node.id.name === name // we don't want to capture function's own name\n ) {\n return;\n }\n\n const parentNode = path.parent;\n\n if (\n isMemberExpression(parentNode) &&\n parentNode.property === path.node &&\n !parentNode.computed\n ) {\n return;\n }\n\n if (\n isObjectProperty(parentNode) &&\n isObjectExpression(path.parentPath.parent) &&\n path.node !== parentNode.value\n ) {\n return;\n }\n\n let currentScope = path.scope;\n\n while (currentScope != null) {\n if (currentScope.bindings[name] != null) {\n return;\n }\n currentScope = currentScope.parent;\n }\n closure.set(name, path.node);\n },\n });\n\n return Array.from(closure.values());\n}\n", "import { NodePath } from '@babel/core';\nimport {\n ObjectMethod,\n identifier,\n isIdentifier,\n isFunctionParent,\n objectProperty,\n callExpression,\n} from '@babel/types';\nimport { ReanimatedPluginPass } from './types';\nimport { makeWorklet } from './makeWorklet';\n\nexport function processWorkletObjectMethod(\n path: NodePath,\n state: ReanimatedPluginPass\n) {\n // Replaces ObjectMethod with a workletized version of itself.\n\n if (!isFunctionParent(path)) {\n return;\n }\n\n const newFun = makeWorklet(path, state);\n\n const replacement = objectProperty(\n identifier(isIdentifier(path.node.key) ? path.node.key.name : ''),\n callExpression(newFun, [])\n );\n\n path.replaceWith(replacement);\n}\n", "import { NodePath, Node } from '@babel/core';\nimport {\n callExpression,\n isScopable,\n isExportNamedDeclaration,\n variableDeclaration,\n variableDeclarator,\n} from '@babel/types';\nimport { ExplicitWorklet, ReanimatedPluginPass } from './types';\nimport { makeWorklet } from './makeWorklet';\n\n// Replaces FunctionDeclaration, FunctionExpression or ArrowFunctionExpression\n// with a workletized version of itself.\n\nexport function processIfWorkletFunction(\n path: NodePath,\n state: ReanimatedPluginPass\n) {\n if (\n path.isFunctionDeclaration() ||\n path.isFunctionExpression() ||\n path.isArrowFunctionExpression()\n ) {\n processWorkletFunction(path, state);\n }\n}\n\nfunction processWorkletFunction(\n path: NodePath,\n state: ReanimatedPluginPass\n) {\n const newFun = makeWorklet(path, state);\n\n const replacement = callExpression(newFun, []);\n\n // we check if function needs to be assigned to variable declaration.\n // This is needed if function definition directly in a scope. Some other ways\n // where function definition can be used is for example with variable declaration:\n // const ggg = function foo() { }\n // ^ in such a case we don't need to define variable for the function\n const needDeclaration =\n isScopable(path.parent) || isExportNamedDeclaration(path.parent);\n path.replaceWith(\n 'id' in path.node && path.node.id && needDeclaration\n ? variableDeclaration('const', [\n variableDeclarator(path.node.id, replacement),\n ])\n : replacement\n );\n}\n", "import { NodePath } from '@babel/core';\nimport {\n CallExpression,\n isSequenceExpression,\n ObjectExpression,\n} from '@babel/types';\nimport { ReanimatedPluginPass } from './types';\nimport { processWorkletObjectMethod } from './processWorkletObjectMethod';\nimport { processIfWorkletFunction } from './processIfWorkletFunction';\nimport { strict as assert } from 'assert';\n\nconst functionArgsToWorkletize = new Map([\n ['useFrameCallback', [0]],\n ['useAnimatedStyle', [0]],\n ['useAnimatedProps', [0]],\n ['createAnimatedPropAdapter', [0]],\n ['useDerivedValue', [0]],\n ['useAnimatedScrollHandler', [0]],\n ['useAnimatedReaction', [0, 1]],\n ['useWorkletCallback', [0]],\n // animations' callbacks\n ['withTiming', [2]],\n ['withSpring', [2]],\n ['withDecay', [1]],\n ['withRepeat', [3]],\n // scheduling functions\n ['runOnUI', [0]],\n]);\n\nconst objectHooks = new Set([\n 'useAnimatedGestureHandler',\n 'useAnimatedScrollHandler',\n]);\n\nexport function processForCalleesWorklets(\n path: NodePath,\n state: ReanimatedPluginPass\n) {\n const callee = isSequenceExpression(path.node.callee)\n ? path.node.callee.expressions[path.node.callee.expressions.length - 1]\n : path.node.callee;\n\n // We are looking for objects we know we should workletize\n // hence if object is not named, we return.\n const name =\n 'name' in callee\n ? callee.name\n : 'property' in callee && 'name' in callee.property\n ? callee.property.name\n : undefined;\n if (name === undefined) {\n return;\n }\n\n if (objectHooks.has(name)) {\n const workletToProcess = path.get('arguments.0');\n assert(!Array.isArray(workletToProcess), \"'workletToProcess' is an array'\");\n if (workletToProcess.isObjectExpression()) {\n processObjectHook(workletToProcess, state);\n // useAnimatedScrollHandler can take a function as an argument instead of an ObjectExpression\n // but useAnimatedGestureHandler can't\n } else if (name === 'useAnimatedScrollHandler') {\n processIfWorkletFunction(workletToProcess, state);\n }\n } else {\n const indices = functionArgsToWorkletize.get(name);\n if (indices === undefined) {\n return;\n }\n processArguments(path, indices, state);\n }\n}\n\nfunction processObjectHook(\n path: NodePath,\n state: ReanimatedPluginPass\n) {\n const properties = path.get('properties');\n for (const property of properties) {\n if (property.isObjectMethod()) {\n processWorkletObjectMethod(property, state);\n } else if (property.isObjectProperty()) {\n const value = property.get('value');\n processIfWorkletFunction(value, state);\n } else {\n throw new Error(\n `'${property.type}' as to-be workletized arguments is not supported for object hooks`\n );\n }\n }\n}\n\nfunction processArguments(\n path: NodePath,\n indices: number[],\n state: ReanimatedPluginPass\n) {\n const argumentsArray = path.get('arguments');\n indices.forEach((index) => {\n const argumentToWorkletize = argumentsArray[index];\n if (!argumentToWorkletize) {\n // workletizable argument doesn't always have to be specified\n return;\n }\n processIfWorkletFunction(argumentToWorkletize, state);\n });\n}\n", "import { NodePath } from '@babel/core';\nimport { isBlockStatement, isDirectiveLiteral } from '@babel/types';\nimport { processIfWorkletFunction } from './processIfWorkletFunction';\nimport { ExplicitWorklet, ReanimatedPluginPass } from './types';\n\nexport function processIfWorkletNode(\n fun: NodePath,\n state: ReanimatedPluginPass\n) {\n fun.traverse({\n DirectiveLiteral(path) {\n const value = path.node.value;\n if (\n value === 'worklet' &&\n path.getFunctionParent() === fun &&\n isBlockStatement(fun.node.body)\n ) {\n // make sure \"worklet\" is listed among directives for the fun\n // this is necessary as because of some bug, babel will attempt to\n // process replaced function if it is nested inside another function\n const directives = fun.node.body.directives;\n if (\n directives &&\n directives.length > 0 &&\n directives.some(\n (directive) =>\n isDirectiveLiteral(directive.value) &&\n directive.value.value === 'worklet'\n )\n ) {\n processIfWorkletFunction(fun, state);\n }\n }\n },\n });\n}\n", "import { NodePath } from '@babel/core';\nimport {\n isIdentifier,\n isCallExpression,\n Expression,\n isMemberExpression,\n isExpression,\n} from '@babel/types';\nimport { processIfWorkletFunction } from './processIfWorkletFunction';\nimport { ExplicitWorklet, ReanimatedPluginPass } from './types';\n\nconst gestureHandlerGestureObjects = new Set([\n // from https://github.com/software-mansion/react-native-gesture-handler/blob/new-api/src/handlers/gestures/gestureObjects.ts\n 'Tap',\n 'Pan',\n 'Pinch',\n 'Rotation',\n 'Fling',\n 'LongPress',\n 'ForceTouch',\n 'Native',\n 'Manual',\n 'Race',\n 'Simultaneous',\n 'Exclusive',\n]);\n\nconst gestureHandlerBuilderMethods = new Set([\n 'onBegin',\n 'onStart',\n 'onEnd',\n 'onFinalize',\n 'onUpdate',\n 'onChange',\n 'onTouchesDown',\n 'onTouchesMove',\n 'onTouchesUp',\n 'onTouchesCancelled',\n]);\n\n// Auto-workletizes React Native Gesture Handler callback functions.\n// Detects `Gesture.Tap().onEnd()` or similar, but skips `something.onEnd()`.\n// Supports method chaining as well, e.g. `Gesture.Tap().onStart().onUpdate().onEnd()`.\n\n// Example #1: `Gesture.Tap().onEnd()`\n/*\n CallExpression(\n callee: MemberExpression(\n object: CallExpression(\n callee: MemberExpression(\n object: Identifier('Gesture')\n property: Identifier('Tap')\n )\n )\n property: Identifier('onEnd')\n )\n arguments: [fun]\n )\n */\n\n// Example #2: `Gesture.Tap().onStart().onUpdate().onEnd()`\n/*\n CallExpression(\n callee: MemberExpression(\n object: CallExpression(\n callee: MemberExpression(\n object: CallExpression(\n callee: MemberExpression(\n object: CallExpression(\n callee: MemberExpression(\n object: Identifier('Gesture')\n property: Identifier('Tap')\n )\n )\n property: Identifier('onStart')\n )\n arguments: [fun1]\n )\n property: Identifier('onUpdate')\n )\n arguments: [fun2]\n )\n property: Identifier('onEnd')\n )\n arguments: [fun3]\n )\n */\nexport function processIfGestureHandlerEventCallbackFunctionNode(\n path: NodePath,\n state: ReanimatedPluginPass\n) {\n if (\n isCallExpression(path.parent) &&\n isExpression(path.parent.callee) &&\n isGestureObjectEventCallbackMethod(path.parent.callee)\n ) {\n processIfWorkletFunction(path, state);\n }\n}\n\nfunction isGestureObjectEventCallbackMethod(exp: Expression) {\n // Checks if node matches the pattern `Gesture.Foo()[*].onBar`\n // where `[*]` represents any number of method calls.\n return (\n isMemberExpression(exp) &&\n isIdentifier(exp.property) &&\n gestureHandlerBuilderMethods.has(exp.property.name) &&\n containsGestureObject(exp.object)\n );\n}\n\nfunction containsGestureObject(exp: Expression) {\n // Checks if node matches the pattern `Gesture.Foo()[*]`\n // where `[*]` represents any number of chained method calls, like `.something(42)`.\n\n // direct call\n if (isGestureObject(exp)) {\n return true;\n }\n\n // method chaining\n if (\n isCallExpression(exp) &&\n isMemberExpression(exp.callee) &&\n containsGestureObject(exp.callee.object)\n ) {\n return true;\n }\n\n return false;\n}\n\nfunction isGestureObject(exp: Expression) {\n // Checks if node matches `Gesture.Tap()` or similar.\n /*\n node: CallExpression(\n callee: MemberExpression(\n object: Identifier('Gesture')\n property: Identifier('Tap')\n )\n )\n */\n return (\n isCallExpression(exp) &&\n isMemberExpression(exp.callee) &&\n isIdentifier(exp.callee.object) &&\n exp.callee.object.name === 'Gesture' &&\n isIdentifier(exp.callee.property) &&\n gestureHandlerGestureObjects.has(exp.callee.property.name)\n );\n}\n", "import { NodePath } from '@babel/core';\nimport {\n MemberExpression,\n callExpression,\n arrowFunctionExpression,\n isArrayExpression,\n ObjectExpression,\n JSXAttribute,\n isJSXExpressionContainer,\n identifier,\n stringLiteral,\n expressionStatement,\n memberExpression,\n returnStatement,\n blockStatement,\n ObjectProperty,\n isIdentifier,\n} from '@babel/types';\nimport { isRelease } from './utils';\nimport { ReanimatedPluginPass } from './types';\nimport { strict as assert } from 'assert';\n\nfunction generateInlineStylesWarning(path: NodePath) {\n // replaces `sharedvalue.value` with `(()=>{console.warn(require('react-native-reanimated').getUseOfValueInStyleWarning());return sharedvalue.value;})()`\n return callExpression(\n arrowFunctionExpression(\n [],\n blockStatement([\n expressionStatement(\n callExpression(\n memberExpression(identifier('console'), identifier('warn')),\n [\n callExpression(\n memberExpression(\n callExpression(identifier('require'), [\n stringLiteral('react-native-reanimated'),\n ]),\n identifier('getUseOfValueInStyleWarning')\n ),\n []\n ),\n ]\n )\n ),\n returnStatement(path.node),\n ])\n ),\n []\n );\n}\n\nfunction processPropertyValueForInlineStylesWarning(\n path: NodePath\n) {\n // if it's something like object.value then raise a warning\n if (path.isMemberExpression() && isIdentifier(path.node.property)) {\n if (path.node.property.name === 'value') {\n path.replaceWith(generateInlineStylesWarning(path));\n }\n }\n}\n\nfunction processTransformPropertyForInlineStylesWarning(\n path: NodePath\n) {\n if (isArrayExpression(path.node)) {\n const elements = path.get('elements');\n assert(Array.isArray(elements), \"'elements' should be an array\");\n for (const element of elements) {\n if (element.isObjectExpression()) {\n processStyleObjectForInlineStylesWarning(element);\n }\n }\n }\n}\n\nfunction processStyleObjectForInlineStylesWarning(\n path: NodePath\n) {\n const properties = path.get('properties');\n for (const property of properties) {\n if (property.isObjectProperty()) {\n const value = property.get('value');\n if (\n isIdentifier(property.node.key) &&\n property.node.key.name === 'transform'\n ) {\n processTransformPropertyForInlineStylesWarning(value);\n } else {\n processPropertyValueForInlineStylesWarning(value);\n }\n }\n }\n}\n\nexport function processInlineStylesWarning(\n path: NodePath,\n state: ReanimatedPluginPass\n) {\n if (isRelease()) {\n return;\n }\n if (state.opts.disableInlineStylesWarning) {\n return;\n }\n if (path.node.name.name !== 'style') {\n return;\n }\n if (!isJSXExpressionContainer(path.node.value)) {\n return;\n }\n\n const expression = path.get('value').get('expression');\n // style={[{...}, {...}]}\n assert(!Array.isArray(expression), \"'expression' should not be an array\");\n if (expression.isArrayExpression()) {\n const elements = expression.get('elements');\n assert(Array.isArray(elements), \"'elements' should be an array\");\n for (const element of elements) {\n if (element.isObjectExpression()) {\n processStyleObjectForInlineStylesWarning(element);\n }\n }\n }\n // style={{...}}\n else if (expression.isObjectExpression()) {\n processStyleObjectForInlineStylesWarning(expression);\n }\n}\n", "import { PluginItem, NodePath } from '@babel/core';\nimport { globals } from './commonObjects';\nimport { CallExpression } from '@babel/types';\nimport { processForCalleesWorklets } from './processForCalleesWorklets';\nimport { ExplicitWorklet, ReanimatedPluginPass } from './types';\nimport { processIfWorkletNode } from './processIfWorkletNode';\nimport { processIfGestureHandlerEventCallbackFunctionNode } from './processIfGestureHandlerEventCallbackFunctionNode';\nimport { processInlineStylesWarning } from './processInlineStylesWarning';\n\nmodule.exports = function (): PluginItem {\n return {\n pre() {\n // allows adding custom globals such as host-functions\n if (this.opts != null && Array.isArray(this.opts.globals)) {\n this.opts.globals.forEach((name: string) => {\n globals.add(name);\n });\n }\n },\n visitor: {\n CallExpression: {\n enter(path: NodePath, state: ReanimatedPluginPass) {\n processForCalleesWorklets(path, state);\n },\n },\n 'FunctionDeclaration|FunctionExpression|ArrowFunctionExpression': {\n enter(path: NodePath, state: ReanimatedPluginPass) {\n processIfWorkletNode(path, state);\n processIfGestureHandlerEventCallbackFunctionNode(path, state);\n },\n },\n JSXAttribute: {\n enter(path, state) {\n processInlineStylesWarning(path, state);\n },\n },\n },\n };\n};\n"],
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAa,IAAAA,SAA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kB,GAAI;AACxC,iDAAyC,UAAU;;IAEvD;AAjCA,IAAAC,SAAA,6BAAA;;;;;;AC9FA,IAAA,kBAAA;AAEA,IAAA,8BAAA;AAEA,IAAA,yBAAA;AACA,IAAA,qDAAA;AACA,IAAA,+BAAA;AAEA,OAAO,UAAU,WAAA;AACf,SAAO;IACL,MAAG;AAED,UAAI,KAAK,QAAQ,QAAQ,MAAM,QAAQ,KAAK,KAAK,OAAO,GAAG;AACzD,aAAK,KAAK,QAAQ,QAAQ,CAAC,SAAgB;AACzC,0BAAA,QAAQ,IAAI,IAAI;QAClB,CAAC;;IAEL;IACA,SAAS;MACP,gBAAgB;QACd,MAAM,MAAgC,OAA2B;AAC/D,WAAA,GAAA,4BAAA,2BAA0B,MAAM,KAAK;QACvC;;MAEF,kEAAkE;QAChE,MAAM,MAAiC,OAA2B;AAChE,WAAA,GAAA,uBAAA,sBAAqB,MAAM,KAAK;AAChC,WAAA,GAAA,mDAAA,kDAAiD,MAAM,KAAK;QAC9D;;MAEF,cAAc;QACZ,MAAM,MAAM,OAAK;AACf,WAAA,GAAA,6BAAA,4BAA2B,MAAM,KAAK;QACxC;;;;AAIR;",
"names": ["exports", "exports", "exports", "commonObjects_1", "exports", "exports", "exports", "exports", "exports", "exports", "exports"]
}
diff --git a/plugin/jestUtils.ts b/plugin/jestUtils.ts
index d37a3701d723..3f2c5984c772 100644
--- a/plugin/jestUtils.ts
+++ b/plugin/jestUtils.ts
@@ -1,10 +1,11 @@
-export {};
+import { UI_RUNTIME_CHECK_REGEX } from './src/makeWorklet';
declare global {
namespace jest {
interface Matchers {
toHaveWorkletData(times?: number): R;
toHaveInlineStyleWarning(times?: number): R;
+ toHaveUIRuntimeCheck(times?: number): R;
}
}
}
@@ -52,3 +53,22 @@ expect.extend({
};
},
});
+
+expect.extend({
+ toHaveUIRuntimeCheck(received: string, expectedMatchCount: number = 1) {
+ const receivedMatchCount = received.match(UI_RUNTIME_CHECK_REGEX)?.length;
+
+ if (receivedMatchCount === expectedMatchCount) {
+ return {
+ message: () =>
+ `Reanimated: expected to have UI runtime check ${expectedMatchCount} times`,
+ pass: true,
+ };
+ }
+ return {
+ message: () =>
+ `Reanimated: expected to have UI runtime check ${expectedMatchCount} times, but found ${receivedMatchCount}`,
+ pass: false,
+ };
+ },
+});
diff --git a/plugin/src/buildWorkletString.ts b/plugin/src/buildWorkletString.ts
index 6fc1899d519e..706f8399b967 100644
--- a/plugin/src/buildWorkletString.ts
+++ b/plugin/src/buildWorkletString.ts
@@ -6,11 +6,8 @@ import {
} from '@babel/core';
import generate from '@babel/generator';
import {
- ObjectMethod,
isObjectMethod,
FunctionDeclaration,
- FunctionExpression,
- ArrowFunctionExpression,
identifier,
Identifier,
objectProperty,
@@ -34,6 +31,7 @@ import * as fs from 'fs';
import * as convertSourceMap from 'convert-source-map';
import { strict as assert } from 'assert';
import { isRelease } from './utils';
+import { WorkletizableFunction } from './types';
export function buildWorkletString(
fun: BabelFile,
@@ -127,12 +125,7 @@ function shouldGenerateSourceMap() {
}
function prependClosure(
- path: NodePath<
- | FunctionDeclaration
- | FunctionExpression
- | ArrowFunctionExpression
- | ObjectMethod
- >,
+ path: NodePath,
closureVariables: Array,
closureDeclaration: VariableDeclaration
) {
@@ -145,14 +138,7 @@ function prependClosure(
}
}
-function prependRecursiveDeclaration(
- path: NodePath<
- | FunctionDeclaration
- | FunctionExpression
- | ArrowFunctionExpression
- | ObjectMethod
- >
-) {
+function prependRecursiveDeclaration(path: NodePath) {
if (
isProgram(path.parent) &&
!isArrowFunctionExpression(path.node) &&
@@ -197,14 +183,7 @@ function prependClosureVariablesIfNecessary(
return {
visitor: {
'FunctionDeclaration|FunctionExpression|ArrowFunctionExpression|ObjectMethod':
- (
- path: NodePath<
- | FunctionDeclaration
- | FunctionExpression
- | ArrowFunctionExpression
- | ObjectMethod
- >
- ) => {
+ (path: NodePath) => {
prependClosure(path, closureVariables, closureDeclaration);
prependRecursiveDeclaration(path);
},
diff --git a/plugin/src/makeWorklet.ts b/plugin/src/makeWorklet.ts
index c3a1a37d6ecd..da85b196436e 100644
--- a/plugin/src/makeWorklet.ts
+++ b/plugin/src/makeWorklet.ts
@@ -1,11 +1,8 @@
import { NodePath, transformSync, traverse } from '@babel/core';
import generate from '@babel/generator';
import {
- ObjectMethod,
isObjectMethod,
- FunctionDeclaration,
FunctionExpression,
- ArrowFunctionExpression,
identifier,
Identifier,
objectProperty,
@@ -36,7 +33,7 @@ import {
isIdentifier,
File as BabelFile,
} from '@babel/types';
-import { ReanimatedPluginPass } from './types';
+import { ReanimatedPluginPass, WorkletizableFunction } from './types';
import { isRelease } from './utils';
import { strict as assert } from 'assert';
import { globals } from './commonObjects';
@@ -45,13 +42,10 @@ import { buildWorkletString } from './buildWorkletString';
const version = require('../../package.json').version;
+export const UI_RUNTIME_CHECK_REGEX = /(global.)?_WORKLET/g;
+
export function makeWorklet(
- fun: NodePath<
- | FunctionDeclaration
- | FunctionExpression
- | ObjectMethod
- | ArrowFunctionExpression
- >,
+ fun: NodePath,
state: ReanimatedPluginPass
): FunctionExpression {
// Returns a new FunctionExpression which is a workletized version of provided
@@ -59,14 +53,7 @@ export function makeWorklet(
const functionName = makeWorkletName(fun);
- // remove 'worklet'; directive before generating string
- fun.traverse({
- DirectiveLiteral(path) {
- if (path.node.value === 'worklet' && path.getFunctionParent() === fun) {
- path.parentPath.remove();
- }
- },
- });
+ removeWorkletDirective(fun);
// We use copy because some of the plugins don't update bindings and
// some even break them
@@ -77,6 +64,10 @@ export function makeWorklet(
sourceFileName: state.file.opts.filename,
});
+ // We change _WORKLET to true to simplify conditionals and avoid
+ // situations when _WORKLET is not yet defined but referenced.
+ codeObject.code = codeObject.code.replace(UI_RUNTIME_CHECK_REGEX, 'true');
+
// We need to add a newline at the end, because there could potentially be a
// comment after the function that gets included here, and then the closing
// bracket would become part of the comment thus resulting in an error, since
@@ -260,6 +251,17 @@ export function makeWorklet(
return newFun;
}
+function removeWorkletDirective(fun: NodePath) {
+ fun.traverse({
+ // Remove 'worklet'; directive before generating string.
+ DirectiveLiteral(path) {
+ if (path.node.value === 'worklet' && path.getFunctionParent() === fun) {
+ path.parentPath.remove();
+ }
+ },
+ });
+}
+
function shouldInjectVersion() {
// We don't inject version in release since cache is reset there anyway
if (isRelease()) {
@@ -292,14 +294,7 @@ function hash(str: string) {
return (hash1 >>> 0) * 4096 + (hash2 >>> 0);
}
-function makeWorkletName(
- fun: NodePath<
- | FunctionDeclaration
- | FunctionExpression
- | ObjectMethod
- | ArrowFunctionExpression
- >
-) {
+function makeWorkletName(fun: NodePath) {
if (isObjectMethod(fun.node) && 'name' in fun.node.key) {
return fun.node.key.name;
}
@@ -314,12 +309,7 @@ function makeWorkletName(
function makeArrayFromCapturedBindings(
ast: BabelFile,
- fun: NodePath<
- | FunctionDeclaration
- | FunctionExpression
- | ObjectMethod
- | ArrowFunctionExpression
- >
+ fun: NodePath
) {
const closure = new Map();
diff --git a/plugin/src/plugin.ts b/plugin/src/plugin.ts
index 5e68ea69342a..5d1b85b1fbe1 100644
--- a/plugin/src/plugin.ts
+++ b/plugin/src/plugin.ts
@@ -1,13 +1,8 @@
import { PluginItem, NodePath } from '@babel/core';
import { globals } from './commonObjects';
-import {
- CallExpression,
- FunctionDeclaration,
- FunctionExpression,
- ArrowFunctionExpression,
-} from '@babel/types';
+import { CallExpression } from '@babel/types';
import { processForCalleesWorklets } from './processForCalleesWorklets';
-import { ReanimatedPluginPass } from './types';
+import { ExplicitWorklet, ReanimatedPluginPass } from './types';
import { processIfWorkletNode } from './processIfWorkletNode';
import { processIfGestureHandlerEventCallbackFunctionNode } from './processIfGestureHandlerEventCallbackFunctionNode';
import { processInlineStylesWarning } from './processInlineStylesWarning';
@@ -29,12 +24,7 @@ module.exports = function (): PluginItem {
},
},
'FunctionDeclaration|FunctionExpression|ArrowFunctionExpression': {
- enter(
- path: NodePath<
- FunctionDeclaration | FunctionExpression | ArrowFunctionExpression
- >,
- state: ReanimatedPluginPass
- ) {
+ enter(path: NodePath, state: ReanimatedPluginPass) {
processIfWorkletNode(path, state);
processIfGestureHandlerEventCallbackFunctionNode(path, state);
},
diff --git a/plugin/src/processIfGestureHandlerEventCallbackFunctionNode.ts b/plugin/src/processIfGestureHandlerEventCallbackFunctionNode.ts
index aed310489fb8..ce429337e6fd 100644
--- a/plugin/src/processIfGestureHandlerEventCallbackFunctionNode.ts
+++ b/plugin/src/processIfGestureHandlerEventCallbackFunctionNode.ts
@@ -1,8 +1,5 @@
import { NodePath } from '@babel/core';
import {
- FunctionDeclaration,
- FunctionExpression,
- ArrowFunctionExpression,
isIdentifier,
isCallExpression,
Expression,
@@ -10,7 +7,7 @@ import {
isExpression,
} from '@babel/types';
import { processIfWorkletFunction } from './processIfWorkletFunction';
-import { ReanimatedPluginPass } from './types';
+import { ExplicitWorklet, ReanimatedPluginPass } from './types';
const gestureHandlerGestureObjects = new Set([
// from https://github.com/software-mansion/react-native-gesture-handler/blob/new-api/src/handlers/gestures/gestureObjects.ts
@@ -89,9 +86,7 @@ const gestureHandlerBuilderMethods = new Set([
)
*/
export function processIfGestureHandlerEventCallbackFunctionNode(
- path: NodePath<
- FunctionDeclaration | FunctionExpression | ArrowFunctionExpression
- >,
+ path: NodePath,
state: ReanimatedPluginPass
) {
if (
diff --git a/plugin/src/processIfWorkletFunction.ts b/plugin/src/processIfWorkletFunction.ts
index 72ad593b48d2..4d3a426969ca 100644
--- a/plugin/src/processIfWorkletFunction.ts
+++ b/plugin/src/processIfWorkletFunction.ts
@@ -1,15 +1,12 @@
import { NodePath, Node } from '@babel/core';
import {
- FunctionDeclaration,
- FunctionExpression,
- ArrowFunctionExpression,
callExpression,
isScopable,
isExportNamedDeclaration,
variableDeclaration,
variableDeclarator,
} from '@babel/types';
-import { ReanimatedPluginPass } from './types';
+import { ExplicitWorklet, ReanimatedPluginPass } from './types';
import { makeWorklet } from './makeWorklet';
// Replaces FunctionDeclaration, FunctionExpression or ArrowFunctionExpression
@@ -29,9 +26,7 @@ export function processIfWorkletFunction(
}
function processWorkletFunction(
- path: NodePath<
- FunctionDeclaration | FunctionExpression | ArrowFunctionExpression
- >,
+ path: NodePath,
state: ReanimatedPluginPass
) {
const newFun = makeWorklet(path, state);
diff --git a/plugin/src/processIfWorkletNode.ts b/plugin/src/processIfWorkletNode.ts
index 66fd56c38ee2..f61f21bae250 100644
--- a/plugin/src/processIfWorkletNode.ts
+++ b/plugin/src/processIfWorkletNode.ts
@@ -1,18 +1,10 @@
import { NodePath } from '@babel/core';
-import {
- FunctionDeclaration,
- FunctionExpression,
- ArrowFunctionExpression,
- isBlockStatement,
- isDirectiveLiteral,
-} from '@babel/types';
+import { isBlockStatement, isDirectiveLiteral } from '@babel/types';
import { processIfWorkletFunction } from './processIfWorkletFunction';
-import { ReanimatedPluginPass } from './types';
+import { ExplicitWorklet, ReanimatedPluginPass } from './types';
export function processIfWorkletNode(
- fun: NodePath<
- FunctionDeclaration | FunctionExpression | ArrowFunctionExpression
- >,
+ fun: NodePath,
state: ReanimatedPluginPass
) {
fun.traverse({
diff --git a/plugin/src/types.ts b/plugin/src/types.ts
index ba7c70182215..4268d246dc66 100644
--- a/plugin/src/types.ts
+++ b/plugin/src/types.ts
@@ -1,4 +1,10 @@
import { BabelFile } from '@babel/core';
+import {
+ FunctionDeclaration,
+ FunctionExpression,
+ ObjectMethod,
+ ArrowFunctionExpression,
+} from '@babel/types';
export interface ReanimatedPluginPass {
file: BabelFile;
@@ -13,3 +19,10 @@ export interface ReanimatedPluginPass {
set(key: unknown, value: unknown): void;
[key: string]: unknown;
}
+
+export type ExplicitWorklet =
+ | FunctionDeclaration
+ | FunctionExpression
+ | ArrowFunctionExpression;
+
+export type WorkletizableFunction = ExplicitWorklet | ObjectMethod;