Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow worklet referencing in plugin #5911

Merged
merged 11 commits into from
Jun 10, 2024
Prev Previous commit
Next Next commit
forgot to commit tests
  • Loading branch information
tjzel committed Apr 22, 2024
commit 06d53835017c0f1466f0aa12a7ebcdde8a01a5a7
46 changes: 46 additions & 0 deletions __tests__/__snapshots__/plugin.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -76,19 +76,19 @@
`;

exports[`babel plugin for Layout Animations doesn't workletize callback functions on unknown chained methods before 1`] = `
"FadeIn.AmogusIn().withCallback(function () {

Check warning on line 79 in __tests__/__snapshots__/plugin.test.ts.snap

View workflow job for this annotation

GitHub Actions / spellcheck

Unknown word (Amogus)
console.log('FadeIn with AmogusIn before');

Check warning on line 80 in __tests__/__snapshots__/plugin.test.ts.snap

View workflow job for this annotation

GitHub Actions / spellcheck

Unknown word (Amogus)
});"
`;

exports[`babel plugin for Layout Animations doesn't workletize callback functions on unknown chained methods before with new keyword 1`] = `
"new FadeIn().AmogusIn().withCallback(function () {

Check warning on line 85 in __tests__/__snapshots__/plugin.test.ts.snap

View workflow job for this annotation

GitHub Actions / spellcheck

Unknown word (Amogus)
console.log('FadeIn with AmogusIn before');

Check warning on line 86 in __tests__/__snapshots__/plugin.test.ts.snap

View workflow job for this annotation

GitHub Actions / spellcheck

Unknown word (Amogus)
});"
`;

exports[`babel plugin for Layout Animations doesn't workletize callback functions on unknown objects 1`] = `
"AmogusIn.withCallback(function () {

Check warning on line 91 in __tests__/__snapshots__/plugin.test.ts.snap

View workflow job for this annotation

GitHub Actions / spellcheck

Unknown word (Amogus)
console.log('AmogusIn');
});"
`;
Expand Down Expand Up @@ -1460,7 +1460,7 @@
var _e = [new global.Error(), 1, -27];
var foo = function foo() {
var bar = [4, 5];
var baz = [1].concat([2, 3], bar);

Check warning on line 1463 in __tests__/__snapshots__/plugin.test.ts.snap

View workflow job for this annotation

GitHub Actions / spellcheck

Unknown word (concat)
};
foo.__closure = {};
foo.__workletHash = 3161057533258;
Expand Down Expand Up @@ -1876,6 +1876,52 @@
var scrollHandler = useAnimatedScrollHandler(handler);"
`;

exports[`babel plugin for referenced worklets workletizes in immediate scope 1`] = `
"var _worklet_11844349717570_init_data = {
code: "function style(){return{};}",
location: "/dev/null",
sourceMap: "\\"mock source map\\"",
version: "x.y.z"
};
var style = function () {
const _e = [new global.Error(), 1, -27];
const style = function () {
return {};
};
style.__closure = {};
style.__workletHash = 11844349717570;
style.__initData = _worklet_11844349717570_init_data;
style.__stackDetails = _e;
return style;
}();
animatedStyle = useAnimatedStyle(style);"
`;

exports[`babel plugin for referenced worklets workletizes in nested scope 1`] = `
"var _worklet_11844349717570_init_data = {
code: "function style(){return{};}",
location: "/dev/null",
sourceMap: "\\"mock source map\\"",
version: "x.y.z"
};
function outerScope() {
var style = function () {
const _e = [new global.Error(), 1, -27];
const style = function () {
return {};
};
style.__closure = {};
style.__workletHash = 11844349717570;
style.__initData = _worklet_11844349717570_init_data;
style.__stackDetails = _e;
return style;
}();
function innerScope() {
animatedStyle = useAnimatedStyle(style);
}
}"
`;

exports[`babel plugin for sequence expressions supports SequenceExpression 1`] = `
"function App() {
(0, fun)({
Expand Down Expand Up @@ -2089,7 +2135,7 @@
}();"
`;

exports[`babel plugin for worklet nesting transpiles nested worklets embedded in runOnJS in runOnUI 1`] = `

Check warning on line 2138 in __tests__/__snapshots__/plugin.test.ts.snap

View workflow job for this annotation

GitHub Actions / spellcheck

Unknown word (transpiles)
"var _worklet_13427774179957_init_data = {
code: "function anonymous(){console.log('Hello from JS thread');}",
location: "/dev/null",
Expand Down Expand Up @@ -2129,7 +2175,7 @@
}())();"
`;

exports[`babel plugin for worklet nesting transpiles nested worklets embedded in runOnUI in runOnJS in runOnUI 1`] = `

Check warning on line 2178 in __tests__/__snapshots__/plugin.test.ts.snap

View workflow job for this annotation

GitHub Actions / spellcheck

Unknown word (transpiles)
"var _worklet_15780567630262_init_data = {
code: "function anonymous(){const{runOnUI}=this.__closure;console.log('Hello from JS thread');runOnUI(function(){console.log('Hello from UI thread again');})();}",
location: "/dev/null",
Expand Down Expand Up @@ -2189,7 +2235,7 @@
}())();"
`;

exports[`babel plugin for worklet nesting transpiles nested worklets when enabled 1`] = `

Check warning on line 2238 in __tests__/__snapshots__/plugin.test.ts.snap

View workflow job for this annotation

GitHub Actions / spellcheck

Unknown word (transpiles)
"var _worklet_14052814262791_init_data = {
code: "function anonymous(){console.log('bar');}",
location: "/dev/null",
Expand Down Expand Up @@ -2228,7 +2274,7 @@
}();"
`;

exports[`babel plugin for worklet nesting transpiles nested worklets when enabled with depth 3 1`] = `

Check warning on line 2277 in __tests__/__snapshots__/plugin.test.ts.snap

View workflow job for this annotation

GitHub Actions / spellcheck

Unknown word (transpiles)
"var _worklet_744555119489_init_data = {
code: "function anonymous(){console.log('foobar');}",
location: "/dev/null",
Expand Down
26 changes: 26 additions & 0 deletions __tests__/plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1917,5 +1917,31 @@ describe('babel plugin', () => {
expect(code).toIncludeInWorkletString('AssignmentExpression');
expect(code).toMatchSnapshot();
});

it('workletizes in immediate scope', () => {
const input = html`<script>
let style = () => ({});
animatedStyle = useAnimatedStyle(style);
</script>`;

const { code } = runPlugin(input);
expect(code).toHaveWorkletData(1);
expect(code).toMatchSnapshot();
});

it('workletizes in nested scope', () => {
const input = html`<script>
function outerScope() {
let style = () => ({});
function innerScope() {
animatedStyle = useAnimatedStyle(style);
}
}
</script>`;

const { code } = runPlugin(input);
expect(code).toHaveWorkletData(1);
expect(code).toMatchSnapshot();
});
});
});
Loading