Skip to content

[compiler] Improve source map coverage for variable declarations/reassignments #33060

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

Open
wants to merge 2 commits into
base: gh/josephsavona/72/base
Choose a base branch
from
Open
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 @@ -1293,7 +1293,11 @@ function codegenInstructionNullable(
suggestions: null,
});
return createVariableDeclaration(instr.loc, 'const', [
t.variableDeclarator(codegenLValue(cx, lvalue), value),
createVariableDeclarator(
lvalue.kind === 'Identifier' ? lvalue.identifier.loc : null,
codegenLValue(cx, lvalue),
value,
),
]);
}
case InstructionKind.Function: {
Expand Down Expand Up @@ -1333,7 +1337,11 @@ function codegenInstructionNullable(
suggestions: null,
});
return createVariableDeclaration(instr.loc, 'let', [
t.variableDeclarator(codegenLValue(cx, lvalue), value),
createVariableDeclarator(
lvalue.kind === 'Identifier' ? lvalue.identifier.loc : null,
codegenLValue(cx, lvalue),
value,
),
]);
}
case InstructionKind.Reassign: {
Expand All @@ -1343,7 +1351,8 @@ function codegenInstructionNullable(
loc: instr.value.loc,
suggestions: null,
});
const expr = t.assignmentExpression(
const expr = createAssignmentExpression(
instr.loc,
'=',
codegenLValue(cx, lvalue),
value,
Expand Down Expand Up @@ -1546,6 +1555,8 @@ const createBinaryExpression = withLoc(t.binaryExpression);
const createExpressionStatement = withLoc(t.expressionStatement);
const _createLabelledStatement = withLoc(t.labeledStatement);
const createVariableDeclaration = withLoc(t.variableDeclaration);
const createVariableDeclarator = withLoc(t.variableDeclarator);
const createAssignmentExpression = withLoc(t.assignmentExpression);
const createFunctionDeclaration = withLoc(t.functionDeclaration);
const _createWhileStatement = withLoc(t.whileStatement);
const createTaggedTemplateExpression = withLoc(t.taggedTemplateExpression);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ function Component() {
let y;
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
y = x = {};

const foo = () => {
x = makeArray();
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ function useTest() {
const t1 = (w = 42);
const t2 = w;
let t3;

w = 999;
t3 = 2;
t0 = makeArray(t1, t2, t3);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ function useTest() {
const t1 = (w.x = 42);
const t2 = w.x;
let t3;

w.x = 999;
t3 = 2;
t0 = makeArray(t1, t2, t3);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ function useTest() {
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
const t1 = print(1);
let t2;

print(2);
t2 = 2;
t0 = makeArray(t1, t2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ function Component(props) {
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
Component = Stringify;
let t0;

t0 = Component;
Component = t0;
$[0] = Component;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import { ValidateMemoization } from "shared-runtime";
function Component(props) {
const $ = _c(2);
let t0;

const x$0 = [];
x$0.push(props?.a.b?.c.d?.e);
x$0.push(props.a?.b.c?.d.e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import { ValidateMemoization } from "shared-runtime";
function Component(props) {
const $ = _c(2);
let t0;

const x$0 = [];
x$0.push(props?.a.b?.c.d?.e);
x$0.push(props.a?.b.c?.d.e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@

```javascript
// @sourceMaps
export const Button = () => {
return <button>Click me</button>;
export const Button = name => {
const greeting = `Hello, ${name}`;
return <button>{greeting}</button>;
};

```
Expand All @@ -13,14 +14,16 @@ export const Button = () => {

```javascript
import { c as _c } from "react/compiler-runtime"; // @sourceMaps
export const Button = () => {
const $ = _c(1);
export const Button = (name) => {
const $ = _c(2);
const greeting = `Hello, ${name}`;
let t0;
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
t0 = <button>Click me</button>;
$[0] = t0;
if ($[0] !== greeting) {
t0 = <button>{greeting}</button>;
$[0] = greeting;
$[1] = t0;
} else {
t0 = $[0];
t0 = $[1];
}
return t0;
};
Expand All @@ -34,15 +37,17 @@ export const Button = () => {
"version": 3,
"names": [
"Button",
"name",
"greeting",
"t0"
],
"sources": [
"sourcemaps-simple.ts"
],
"sourcesContent": [
"// @sourceMaps\nexport const Button = () => {\n return <button>Click me</button>;\n};\n"
"// @sourceMaps\nexport const Button = name => {\n const greeting = `Hello, ${name}`;\n return <button>{greeting}</button>;\n};\n"
],
"mappings": "kDAAA;AACA,OAAO,MAAMA,MAAM,GAAGA,CAAA,K;SACb,OAAyB,CAAjB,QAAQ,EAAhB,MAAyB,C,qCAAzBC,EAAyB,C,CACjC",
"mappings": "kDAAA;AACA,OAAO,MAAMA,MAAM,GAAGA,CAAAC,IAAA,K;EACpB,M,WAAiBC,UAAUD,IAAI,EAAjB,C;SACP,OAA2B,CAAlBC,SAAO,CAAE,EAAlB,MAA2B,C,qDAA3BC,EAA2B,C,CACnC",
"ignoreList": []
}
```
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// @sourceMaps
export const Button = () => {
return <button>Click me</button>;
export const Button = name => {
const greeting = `Hello, ${name}`;
return <button>{greeting}</button>;
};
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ function Component(props) {

useHook();
let t0;

const x = makeObject_Primitives();
x.value = props.value;
mutate(x, free, part);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ function component(a) {
```javascript
function component(a) {
let t0;

mutate(a);
t0 = undefined;
}
Expand Down
Loading