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

Pass down generator boolean in babel plugin #5565

Merged
merged 6 commits into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions __tests__/plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,18 @@ describe('babel plugin', () => {
expect(code).toMatchSnapshot();
});

it('supports generators', () => {
const input = html`<script>
function* foo() {
'worklet';
yield 'hello';
yield 'world';
}
</script>`;
const { code } = runPlugin(input);
expect(code).toContain('var foo = function* foo() {');
});

it('supports recursive calls', () => {
const input = html`<script>
const a = 1;
Expand Down
4 changes: 2 additions & 2 deletions plugin/build/plugin.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion plugin/src/buildWorkletString.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ export function buildWorkletString(
const workletFunction = functionExpression(
identifier(name),
expression.params,
expression.body
expression.body,
expression.generator
);

const code = generate(workletFunction).code;
Expand Down
2 changes: 1 addition & 1 deletion plugin/src/makeWorklet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export function makeWorklet(

const clone = cloneNode(fun.node);
const funExpression = isBlockStatement(clone.body)
? functionExpression(null, clone.params, clone.body)
? functionExpression(null, clone.params, clone.body, clone.generator)
: clone;

let [funString, sourceMapString] = buildWorkletString(
Expand Down