Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -1160,9 +1160,9 @@ function codegenTerminal(
const value = codegenPlaceToExpression(cx, terminal.value);
if (value.type === 'Identifier' && value.name === 'undefined') {
// Use implicit undefined
return t.returnStatement();
return createReturnStatement(terminal.loc);
}
return t.returnStatement(value);
return createReturnStatement(terminal.loc, value);
}
case 'switch': {
return createSwitchStatement(
Expand Down Expand Up @@ -1545,6 +1545,7 @@ const createThrowStatement = withLoc(t.throwStatement);
const createTryStatement = withLoc(t.tryStatement);
const createBreakStatement = withLoc(t.breakStatement);
const createContinueStatement = withLoc(t.continueStatement);
const createReturnStatement = withLoc(t.returnStatement);

function createVariableDeclarator(
id: t.LVal,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,23 @@ export function validateSourceLocations(
return;
}

/*
* Skip return statements inside arrow functions that will be simplified to expression body.
* The compiler transforms `() => { return expr }` to `() => expr` in CodegenReactiveFunction
*/
if (t.isReturnStatement(node) && node.argument != null) {
const parentBody = path.parentPath;
const parentFunc = parentBody?.parentPath;
if (
parentBody?.isBlockStatement() &&
parentFunc?.isArrowFunctionExpression() &&
parentBody.node.body.length === 1 &&
parentBody.node.directives.length === 0
) {
return;
}
}

// Collect the location if it exists
if (node.loc) {
const key = locationKey(node.loc);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ function foo(cond) {
} else {
a = $[1];
}

return a;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ function useFoo(t0) {
if (t1 !== Symbol.for("react.early_return_sentinel")) {
return t1;
}

return s;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ function useFoo(t0) {
} else {
items = $[2];
}

return items;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ function Foo() {
} else {
thing = $[0];
}

return thing;
} catch {}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ function Component(props) {
} else {
x = $[1];
}

return x;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export const FIXTURE_ENTRYPOINT = {
```javascript
function useFoo() {
const update = _temp;

return update;
}
function _temp() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ function useBar(props) {
z = t0;
}
}

return z;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ function Component(props) {
default:
}
const outerHandlers = handlers;

return outerHandlers;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ function useFoo(t0) {
}
result = t1;
}

return result;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ function component(a) {
} else {
x = $[1];
}

return x;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ function component(a) {
} else {
x = $[1];
}

return x;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ function component(a) {
} else {
z = $[1];
}

return z;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ function component(a) {
t0 = $[1];
}
const x = t0;

return x;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ function component(a, b) {
t0 = $[1];
}
const z = t0;

return z;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ function component(a) {
t0 = $[1];
}
const x = t0;

return x;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ function bar(a) {
} else {
y = $[3];
}

return y;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ function bar(a) {
} else {
y = $[1];
}

return y;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ function bar(a, b) {
} else {
y = $[5];
}

return y;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ function bar(a, b) {
} else {
y = $[2];
}

return y;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ function bar(a) {
} else {
y = $[3];
}

return y;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ function bar(a) {
} else {
y = $[1];
}

return y;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ function bar(a) {
} else {
y = $[3];
}

return y;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ function bar(a) {
} else {
y = $[1];
}

return y;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ function Component(t0) {
t2 = $[6];
}
y = t2;

return y;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ function useHook(a, b) {
t1 = $[4];
}
const x = t1;

return x;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ function Foo(props) {
t0 = $[1];
}
const onFoo = t0;

return onFoo;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ function useHook(t0) {
const z_0 = { b };

mutate(z_0);

return z;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ function component(a) {
t1 = $[3];
}
x = t1;

return x;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ function component(a) {
t1 = $[3];
}
const x = t1;

return x;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ function component(a) {
t0 = $[1];
}
const z = t0;

return z;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ function component(a) {
t1 = $[3];
}
const x = t1;

return x;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ function component(a) {
t1 = $[3];
}
const x = t1;

return x;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ function component(a) {
t0 = $[1];
}
const x = t0;

return x;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ function component(a) {
t0 = $[1];
}
const x = t0;

return x;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ function Component(props) {
}
}
}

return x;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ function foo(a, b, c) {
}
}
}

return c;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ function Component(props) {
setX(2);
foo();
}

return x;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ function Component() {
const obj = { method() {} };

identity(obj);

return 4;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ function Component() {
const fn = _temp;

invoke(fn);

return 3;
}
function _temp() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ function foo() {
for (const x = 100; false; 100) {
y = y + 1;
}

return y;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export const FIXTURE_ENTRYPOINT = {
function foo(a, b, c) {
if (a) {
}

return b;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ function foo() {
while (false) {
y = y + 1;
}

return y;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export const FIXTURE_ENTRYPOINT = {
```javascript
function foo() {
console.log("foo");

return -6;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ function foo(props) {
while (y < props.max) {
y++;
}

return y;
}

Expand Down
Loading
Loading