Skip to content

Commit

Permalink
Run plugin inside a try-catch block (software-mansion#4957)
Browse files Browse the repository at this point in the history
<!-- Thanks for submitting a pull request! We appreciate you spending
the time to work on these changes. Please follow the template so that
the reviewers can easily understand what the code changes affect. -->

## Summary

Currently when Reanimated Babel plugin fails to transpile a file,
regardless of the reason, we don't have any indication that it failed -
we just get some generic error from e.g. metro bundler transpilation
process. With this PR now we will get additional `[Reanimated] Babel
plugin exception` substring in the error, allowing us to narrow down the
issue.

Inspired by software-mansion#4943 

## Test plan

Added two simple tests for it.
  • Loading branch information
tjzel authored Aug 24, 2023
1 parent 002717e commit 9af2c5f
Show file tree
Hide file tree
Showing 9 changed files with 406 additions and 302 deletions.
113 changes: 67 additions & 46 deletions __tests__/__snapshots__/plugin.test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,50 +1,5 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`babel plugin doesn't capture arguments 1`] = `
"var _worklet_17093819837059_init_data = {
code: "function f(a,b,c){console.log(arguments);}",
location: "/dev/null",
sourceMap: "\\"mock source map\\"",
version: "x.y.z"
};
var f = function () {
var _e = [new global.Error(), 1, -27];
var f = function f(a, b, c) {
console.log(arguments);
};
f.__closure = {};
f.__initData = _worklet_17093819837059_init_data;
f.__workletHash = 17093819837059;
f.__stackDetails = _e;
return f;
}();"
`;

exports[`babel plugin doesn't capture objects' properties 1`] = `
"var foo = {
bar: 42
};
var _worklet_3750134465664_init_data = {
code: "function f(){const{foo}=this.__closure;console.log(foo.bar);}",
location: "/dev/null",
sourceMap: "\\"mock source map\\"",
version: "x.y.z"
};
var f = function () {
var _e = [new global.Error(), -2, -27];
var f = function f() {
console.log(foo.bar);
};
f.__closure = {
foo: foo
};
f.__initData = _worklet_3750134465664_init_data;
f.__workletHash = 3750134465664;
f.__stackDetails = _e;
return f;
}();"
`;

exports[`babel plugin for DirectiveLiterals doesn't bother other Directive Literals 1`] = `
"function foo() {
'foobar';
Expand Down Expand Up @@ -619,7 +574,48 @@ var f = function () {
}();"
`;

exports[`babel plugin for closure capturing doesn't capture globals 1`] = `
exports[`babel plugin for closure capturing doesn't capture arguments 1`] = `
"var _worklet_17093819837059_init_data = {
code: "function f(a,b,c){console.log(arguments);}",
location: "/dev/null",
sourceMap: "\\"mock source map\\"",
version: "x.y.z"
};
var f = function () {
var _e = [new global.Error(), 1, -27];
var f = function f(a, b, c) {
console.log(arguments);
};
f.__closure = {};
f.__initData = _worklet_17093819837059_init_data;
f.__workletHash = 17093819837059;
f.__stackDetails = _e;
return f;
}();"
`;

exports[`babel plugin for closure capturing doesn't capture custom globals 1`] = `
"var foo = 42;
var _worklet_7141086932261_init_data = {
code: "function f(){console.log(foo);}",
location: "/dev/null",
sourceMap: "\\"mock source map\\"",
version: "x.y.z"
};
var f = function () {
var _e = [new global.Error(), 1, -27];
var f = function f() {
console.log(foo);
};
f.__closure = {};
f.__initData = _worklet_7141086932261_init_data;
f.__workletHash = 7141086932261;
f.__stackDetails = _e;
return f;
}();"
`;

exports[`babel plugin for closure capturing doesn't capture default globals 1`] = `
"var _worklet_13298016111221_init_data = {
code: "function f(){console.log('test');}",
location: "/dev/null",
Expand All @@ -639,6 +635,31 @@ var f = function () {
}();"
`;

exports[`babel plugin for closure capturing doesn't capture objects' properties 1`] = `
"var foo = {
bar: 42
};
var _worklet_3750134465664_init_data = {
code: "function f(){const{foo}=this.__closure;console.log(foo.bar);}",
location: "/dev/null",
sourceMap: "\\"mock source map\\"",
version: "x.y.z"
};
var f = function () {
var _e = [new global.Error(), -2, -27];
var f = function f() {
console.log(foo.bar);
};
f.__closure = {
foo: foo
};
f.__initData = _worklet_3750134465664_init_data;
f.__workletHash = 3750134465664;
f.__stackDetails = _e;
return f;
}();"
`;

exports[`babel plugin for debugging does inject location for worklets in dev builds 1`] = `
"var _worklet_1852213185147_init_data = {
code: "function anonymous(){const x=1;}",
Expand Down
Loading

0 comments on commit 9af2c5f

Please sign in to comment.