Skip to content

Commit

Permalink
fix Error Variable scope conflicts, and remove duplicate Date
Browse files Browse the repository at this point in the history
  • Loading branch information
jinliming2 committed Feb 21, 2023
1 parent 4f8b552 commit cada1ec
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 32 deletions.
60 changes: 30 additions & 30 deletions __tests__/__snapshots__/plugin.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ var _worklet_5359970077727_init_data = {
location: \\"${ process.cwd() }/jest tests fixture\\"
};
var f = function () {
var _e = [new Error(), -3, -20];
var _e = [new global.Error(), -3, -20];
var _f = function _f() {
return {
res: x + objX.x
Expand All @@ -33,7 +33,7 @@ exports[`babel plugin doesn't capture globals 1`] = `
location: \\"${ process.cwd() }/jest tests fixture\\"
};
var f = function () {
var _e = [new Error(), 1, -20];
var _e = [new global.Error(), 1, -20];
var _f = function _f() {
console.log('test');
};
Expand All @@ -57,7 +57,7 @@ exports[`babel plugin doesn't transform string literals 1`] = `
location: \\"${ process.cwd() }/jest tests fixture\\"
};
var foo = function () {
var _e = [new Error(), 1, -20];
var _e = [new global.Error(), 1, -20];
var _f = function _f(x) {
var bar = 'worklet';
var baz = \\"worklet\\";
Expand Down Expand Up @@ -86,7 +86,7 @@ exports[`babel plugin supports SequenceExpression, many arguments 1`] = `
function App() {
(0, 3, fun)({
onStart: function () {
var _e = [new Error(), 1, -20];
var _e = [new global.Error(), 1, -20];
var _f = function _f() {};
_f._closure = {};
_f.__initData = _worklet_4434179069699_init_data;
Expand All @@ -106,7 +106,7 @@ exports[`babel plugin supports SequenceExpression, with objectHook 1`] = `
function App() {
(0, useAnimatedGestureHandler)({
onStart: function () {
var _e = [new Error(), 1, -20];
var _e = [new global.Error(), 1, -20];
var _f = function _f() {};
_f._closure = {};
_f.__initData = _worklet_4434179069699_init_data;
Expand All @@ -126,7 +126,7 @@ exports[`babel plugin supports SequenceExpression, with worklet 1`] = `
function App() {
(0, fun)({
onStart: function () {
var _e = [new Error(), 1, -20];
var _e = [new global.Error(), 1, -20];
var _f = function _f() {};
_f._closure = {};
_f.__initData = _worklet_4434179069699_init_data;
Expand All @@ -150,7 +150,7 @@ function App() {
};
(0, fun)({
onStart: function () {
var _e = [new Error(), -2, -20];
var _e = [new global.Error(), -2, -20];
var _f = function _f() {
var a = obj.a;
};
Expand All @@ -173,7 +173,7 @@ var _worklet_2022702330805_init_data = {
location: \\"${ process.cwd() }/jest tests fixture\\"
};
var foo = function () {
var _e = [new Error(), -2, -20];
var _e = [new global.Error(), -2, -20];
var _f = function _f(t) {
if (t > 0) {
return a + foo(t - 1);
Expand All @@ -200,7 +200,7 @@ var _worklet_16669311443114_init_data = {
function Box() {
var offset = (0, _reactNativeReanimated.useSharedValue)(0);
var animatedStyles = (0, _reactNativeReanimated.useAnimatedStyle)(function () {
var _e = [new Error(), -2, -20];
var _e = [new global.Error(), -2, -20];
var _f = function _f() {
return {
transform: [{
Expand Down Expand Up @@ -233,7 +233,7 @@ exports[`babel plugin transforms spread operator in worklets for arrays 1`] = `
location: \\"${ process.cwd() }/jest tests fixture\\"
};
var foo = function () {
var _e = [new Error(), 1, -20];
var _e = [new global.Error(), 1, -20];
var _f = function _f() {
var bar = [4, 5];
var baz = [1].concat([2, 3], bar);
Expand All @@ -252,7 +252,7 @@ exports[`babel plugin transforms spread operator in worklets for function argume
location: \\"${ process.cwd() }/jest tests fixture\\"
};
var foo = function () {
var _e = [new Error(), 1, -20];
var _e = [new global.Error(), 1, -20];
var _f = function _f() {
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
Expand All @@ -275,7 +275,7 @@ var _worklet_2015887751437_init_data = {
location: \\"${ process.cwd() }/jest tests fixture\\"
};
var foo = function () {
var _e = [new Error(), 1, -20];
var _e = [new global.Error(), 1, -20];
var _f = function _f(arg) {
var _console;
(_console = console).log.apply(_console, (0, _toConsumableArray2.default)(arg));
Expand All @@ -294,7 +294,7 @@ exports[`babel plugin transforms spread operator in worklets for objects 1`] = `
location: \\"${ process.cwd() }/jest tests fixture\\"
};
var foo = function () {
var _e = [new Error(), 1, -20];
var _e = [new global.Error(), 1, -20];
var _f = function _f() {
var bar = {
d: 4,
Expand All @@ -321,7 +321,7 @@ exports[`babel plugin workletizes ArrowFunctionExpression 1`] = `
location: \\"${ process.cwd() }/jest tests fixture\\"
};
var foo = function () {
var _e = [new Error(), 1, -20];
var _e = [new global.Error(), 1, -20];
var _f = function _f(x) {
return x + 2;
};
Expand All @@ -339,7 +339,7 @@ exports[`babel plugin workletizes FunctionDeclaration 1`] = `
location: \\"${ process.cwd() }/jest tests fixture\\"
};
var foo = function () {
var _e = [new Error(), 1, -20];
var _e = [new global.Error(), 1, -20];
var _f = function _f(x) {
return x + 2;
};
Expand All @@ -366,7 +366,7 @@ var Foo = function () {
(0, _createClass2.default)(Foo, [{
key: \\"bar\\",
get: function () {
var _e = [new Error(), -2, -20];
var _e = [new global.Error(), -2, -20];
var _f = function _f() {
return x + 2;
};
Expand All @@ -389,7 +389,7 @@ exports[`babel plugin workletizes hook wrapped ArrowFunctionExpression automatic
location: \\"${ process.cwd() }/jest tests fixture\\"
};
var animatedStyle = useAnimatedStyle(function () {
var _e = [new Error(), 1, -20];
var _e = [new global.Error(), 1, -20];
var _f = function _f() {
return {
width: 50
Expand All @@ -409,7 +409,7 @@ exports[`babel plugin workletizes hook wrapped named FunctionExpression automati
location: \\"${ process.cwd() }/jest tests fixture\\"
};
var animatedStyle = useAnimatedStyle(function () {
var _e = [new Error(), 1, -20];
var _e = [new global.Error(), 1, -20];
var _f = function _f() {
return {
width: 50
Expand All @@ -429,7 +429,7 @@ exports[`babel plugin workletizes hook wrapped unnamed FunctionExpression automa
location: \\"${ process.cwd() }/jest tests fixture\\"
};
var animatedStyle = useAnimatedStyle(function () {
var _e = [new Error(), 1, -20];
var _e = [new global.Error(), 1, -20];
var _f = function _f() {
return {
width: 50
Expand Down Expand Up @@ -458,7 +458,7 @@ var Foo = function () {
(0, _createClass2.default)(Foo, [{
key: \\"bar\\",
value: function () {
var _e = [new Error(), 1, -20];
var _e = [new global.Error(), 1, -20];
var _f = function _f(x) {
return x + 2;
};
Expand All @@ -479,7 +479,7 @@ exports[`babel plugin workletizes named FunctionExpression 1`] = `
location: \\"${ process.cwd() }/jest tests fixture\\"
};
var foo = function () {
var _e = [new Error(), 1, -20];
var _e = [new global.Error(), 1, -20];
var _f = function _f(x) {
return x + 2;
};
Expand All @@ -498,7 +498,7 @@ exports[`babel plugin workletizes object hook wrapped ArrowFunctionExpression au
};
useAnimatedGestureHandler({
onStart: function () {
var _e = [new Error(), 1, -20];
var _e = [new global.Error(), 1, -20];
var _f = function _f(event) {
console.log(event);
};
Expand All @@ -518,7 +518,7 @@ exports[`babel plugin workletizes object hook wrapped ObjectMethod automatically
};
useAnimatedGestureHandler({
onStart: function () {
var _e = [new Error(), 1, -20];
var _e = [new global.Error(), 1, -20];
var _f = function _f(event) {
console.log(event);
};
Expand All @@ -538,7 +538,7 @@ exports[`babel plugin workletizes object hook wrapped named FunctionExpression a
};
useAnimatedGestureHandler({
onStart: function () {
var _e = [new Error(), 1, -20];
var _e = [new global.Error(), 1, -20];
var _f = function _f(event) {
console.log(event);
};
Expand All @@ -558,7 +558,7 @@ exports[`babel plugin workletizes object hook wrapped unnamed FunctionExpression
};
useAnimatedGestureHandler({
onStart: function () {
var _e = [new Error(), 1, -20];
var _e = [new global.Error(), 1, -20];
var _f = function _f(event) {
console.log(event);
};
Expand Down Expand Up @@ -586,7 +586,7 @@ var _worklet_232586479291_init_data = {
location: \\"${ process.cwd() }/jest tests fixture\\"
};
var foo = _reactNativeGestureHandler.Gesture.Tap().numberOfTaps(2).onBegin(function () {
var _e = [new Error(), 1, -20];
var _e = [new global.Error(), 1, -20];
var _f = function _f() {
console.log('onBegin');
};
Expand All @@ -596,7 +596,7 @@ var foo = _reactNativeGestureHandler.Gesture.Tap().numberOfTaps(2).onBegin(funct
_f.__stackDetails = _e;
return _f;
}()).onStart(function () {
var _e = [new Error(), 1, -20];
var _e = [new global.Error(), 1, -20];
var _f = function _f(_event) {
console.log('onStart');
};
Expand All @@ -606,7 +606,7 @@ var foo = _reactNativeGestureHandler.Gesture.Tap().numberOfTaps(2).onBegin(funct
_f.__stackDetails = _e;
return _f;
}()).onEnd(function () {
var _e = [new Error(), 1, -20];
var _e = [new global.Error(), 1, -20];
var _f = function _f(_event, _success) {
console.log('onEnd');
};
Expand All @@ -633,7 +633,7 @@ var Foo = function () {
(0, _createClass2.default)(Foo, null, [{
key: \\"bar\\",
value: function () {
var _e = [new Error(), 1, -20];
var _e = [new global.Error(), 1, -20];
var _f = function _f(x) {
return x + 2;
};
Expand All @@ -654,7 +654,7 @@ exports[`babel plugin workletizes unnamed FunctionExpression 1`] = `
location: \\"${ process.cwd() }/jest tests fixture\\"
};
var foo = function () {
var _e = [new Error(), 1, -20];
var _e = [new global.Error(), 1, -20];
var _f = function _f(x) {
return x + 2;
};
Expand Down
6 changes: 4 additions & 2 deletions plugin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ const globals = new Set([
'Uint32Array',
'Float32Array',
'Float64Array',
'Date',
'HermesInternal',
'JSON',
'Math',
Expand Down Expand Up @@ -452,7 +451,10 @@ function makeWorklet(t, fun, state) {
t.variableDeclarator(
t.identifier('_e'),
t.arrayExpression([
t.newExpression(t.identifier('Error'), []),
t.newExpression(t.memberExpression(
t.identifier('global'),
t.identifier('Error'),
), []),
t.numericLiteral(lineOffset),
t.numericLiteral(-20), // the placement of opening bracket after Exception in line that defined '_e' variable
])
Expand Down

0 comments on commit cada1ec

Please sign in to comment.