dillon1000/react
Commit
Browse files Initial (flagged) support for reactive scopes with early return
Adds support for early returns within reactive scopes, behind a new feature flag. The flag is off by default, where this case continues to throw a Todo bailout. Since implementing a sketch of the codegen in the previous PR I realized that it's easy enough to implement the more optimal output, so i've updated that here. Rather than both the if and else branch of the reactive scope having an "if the return value was not a sentinel return it" check, we instead make the return temporary a proper declaration of the reactive scope. Then, since it's actually an output it's available in the outer block scope, and we could do a single if-return after the reactive scope. Edit: see comment below for thoughts on test cases.
Changed paths24 files
First-parent comparisoncompiler/packages/babel-plugin-react-forget/src/HIR/Environment.ts ModifiedM compiler/packages/babel-plugin-react-forget/src/HIR/HIR.ts ModifiedM compiler/packages/babel-plugin-react-forget/src/ReactiveScopes/CodegenReactiveFunction.ts ModifiedM compiler/packages/babel-plugin-react-forget/src/ReactiveScopes/PropagateEarlyReturns.ts ModifiedM compiler/packages/babel-plugin-react-forget/src/ReactiveScopes/PruneUnusedScopes.ts ModifiedA compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/conditional-early-return.expect.md AddedR compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.todo-early-return--conditional-break.js →compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/conditional-early-return.js RenamedA compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/early-return-nested-early-return-within-reactive-scope.expect.md AddedR compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.todo-early-return--early-return-nested-early-return-within-reactive-scope.js →compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/early-return-nested-early-return-within-reactive-scope.js RenamedA compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/early-return-within-reactive-scope.expect.md AddedR compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.todo-early-return--partial-early-return-within-reactive-scope.expect.md →compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/early-return-within-reactive-scope.js RenamedD compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.todo-early-return--conditional-break.expect.md DeletedD compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.todo-early-return--early-return-nested-early-return-within-reactive-scope.expect.md DeletedD compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.todo-early-return--try-catch-try-value-modified-in-catch.expect.md DeletedD compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.todo-early-return--try-catch-with-catch-param.expect.md DeletedD compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.todo-early-return--try-catch-with-return.expect.md DeletedA compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/partial-early-return-within-reactive-scope.expect.md AddedR compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.todo-early-return--partial-early-return-within-reactive-scope.js →compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/partial-early-return-within-reactive-scope.js RenamedA compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/try-catch-try-value-modified-in-catch.expect.md AddedR compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.todo-early-return--try-catch-try-value-modified-in-catch.js →compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/try-catch-try-value-modified-in-catch.js RenamedA compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/try-catch-with-catch-param.expect.md AddedR compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.todo-early-return--try-catch-with-catch-param.js →compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/try-catch-with-catch-param.js RenamedA compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/try-catch-with-return.expect.md AddedR compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.todo-early-return--try-catch-with-return.js →compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/try-catch-with-return.js RenamedPatch
Files changed
Rendering syntax-highlighted changes…