You get a debugger and you get a debugger and you get a

Adds support for DebuggerStatement.
This commit is contained in:
Joe Savona
2023-04-26 11:27:37 -07:00
parent 1f51b10ac9
commit 8e7b68506f
12 changed files with 85 additions and 8 deletions
+14 -1
View File
@@ -866,9 +866,22 @@ function lowerStatement(
);
return;
}
case "DebuggerStatement": {
const stmt = stmtPath as NodePath<t.DebuggerStatement>;
const loc = stmt.node.loc ?? GeneratedSource;
builder.push({
id: makeInstructionId(0),
lvalue: buildTemporaryPlace(builder, loc),
value: {
kind: "Debugger",
loc,
},
loc,
});
return;
}
case "ForInStatement":
case "ClassDeclaration":
case "DebuggerStatement":
case "DeclareClass":
case "DeclareExportAllDeclaration":
case "DeclareExportDeclaration":
+2
View File
@@ -710,6 +710,8 @@ export type InstructionValue =
value: Place;
loc: SourceLocation;
}
// `debugger` statement
| { kind: "Debugger"; loc: SourceLocation }
/**
* Catch-all for statements such as type imports, nested class declarations, etc
* which are not directly represented, but included for completeness and to allow
+4
View File
@@ -478,6 +478,10 @@ export function printInstructionValue(instrValue: ReactiveValue): string {
value = `ExpressionStatement ${printPlace(instrValue.value)}`;
break;
}
case "Debugger": {
value = `Debugger`;
break;
}
default: {
assertExhaustive(
instrValue,
+2
View File
@@ -184,6 +184,7 @@ export function* eachInstructionValueOperand(
yield instrValue.value;
break;
}
case "Debugger":
case "RegExpLiteral":
case "LoadGlobal":
case "UnsupportedNode":
@@ -451,6 +452,7 @@ export function mapInstructionOperands(
instrValue.value = fn(instrValue.value);
break;
}
case "Debugger":
case "RegExpLiteral":
case "LoadGlobal":
case "UnsupportedNode":
@@ -673,6 +673,7 @@ function inferBlock(
effectKind = Effect.Mutate;
break;
}
case "Debugger":
case "LoadGlobal":
case "JSXText":
case "Primitive": {
@@ -190,6 +190,10 @@ function pruneableValue(value: InstructionValue, state: State): boolean {
}
return true;
}
case "Debugger": {
// explicitly retain debugger statements to not break debugging workflows
return false;
}
case "ExpressionStatement": {
// We create ExpressionStatements specifically for expressions that would otherwise
// be dropped but which we don't want to eliminate.
@@ -439,7 +439,6 @@ function codegenInstructionNullable(
cx: Context,
instr: ReactiveInstruction
): t.Statement | null {
let statement;
if (
instr.value.kind === "StoreLocal" ||
instr.value.kind === "Destructure" ||
@@ -514,14 +513,16 @@ function codegenInstructionNullable(
assertExhaustive(kind, `Unexpected instruction kind '${kind}'`);
}
}
} else if (instr.value.kind === "Debugger") {
return t.debuggerStatement();
} else {
const value = codegenInstructionValue(cx, instr.value);
statement = codegenInstruction(cx, instr, value);
const statement = codegenInstruction(cx, instr, value);
if (statement.type === "EmptyStatement") {
return null;
}
return statement;
}
if (statement.type === "EmptyStatement") {
return null;
}
return statement;
}
function codegenForInit(
@@ -1000,6 +1001,7 @@ function codegenInstructionValue(
value = codegenPlace(cx, instrValue.value);
break;
}
case "Debugger":
case "DeclareLocal":
case "Destructure":
case "StoreLocal": {
@@ -235,7 +235,8 @@ function mayAllocate(value: InstructionValue): boolean {
case "TemplateLiteral":
case "Primitive":
case "NextIterableOf":
case "ExpressionStatement": {
case "ExpressionStatement":
case "Debugger": {
return false;
}
case "RegExpLiteral":
@@ -417,6 +417,7 @@ function computeMemoizationInputs(
rvalues: value.children,
};
}
case "Debugger":
case "ComputedDelete":
case "PropertyDelete":
case "LoadGlobal":
@@ -212,6 +212,7 @@ function* generateInstructionTypes(
case "NextIterableOf":
case "ExpressionStatement":
case "UnsupportedNode":
case "Debugger":
break;
default:
assertExhaustive(value, `Unhandled instruction value kind: ${value}`);
@@ -0,0 +1,35 @@
## Input
```javascript
function Component(props) {
debugger;
if (props.cond) {
debugger;
} else {
while (props.cond) {
debugger;
}
}
debugger;
}
```
## Code
```javascript
function Component(props) {
debugger;
if (props.cond) {
debugger;
} else {
while (props.cond) {
debugger;
}
}
debugger;
}
```
@@ -0,0 +1,11 @@
function Component(props) {
debugger;
if (props.cond) {
debugger;
} else {
while (props.cond) {
debugger;
}
}
debugger;
}