mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
Invariant if codegen tries to emit a temporary as an identifier
For T181507827 — adds an invariant in codegen when emitting identifiers to ensure that we only create babel Identifier nodes for nodes that the compiler has explicitly promoted to valid, named identifiers. This means that we'll fail for unnamed temporaries (previously caught), as well as promoted temporaries that somehow didn't get renamed by RenameVariables (newly caught).
This commit is contained in:
+9
-6
@@ -2060,11 +2060,14 @@ function codegenPlace(cx: Context, place: Place): t.Expression | t.JSXText {
|
||||
}
|
||||
|
||||
function convertIdentifier(identifier: Identifier): t.Identifier {
|
||||
CompilerError.invariant(identifier.name !== null, {
|
||||
reason: `Expected temporaries to be promoted to named identifiers in an earlier pass`,
|
||||
loc: GeneratedSource,
|
||||
description: `identifier ${identifier.id} is unnamed`,
|
||||
suggestions: null,
|
||||
});
|
||||
CompilerError.invariant(
|
||||
identifier.name !== null && identifier.name.kind === "named",
|
||||
{
|
||||
reason: `Expected temporaries to be promoted to named identifiers in an earlier pass`,
|
||||
loc: GeneratedSource,
|
||||
description: `identifier ${identifier.id} is unnamed`,
|
||||
suggestions: null,
|
||||
}
|
||||
);
|
||||
return t.identifier(identifier.name.value);
|
||||
}
|
||||
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
|
||||
## Input
|
||||
|
||||
```javascript
|
||||
function Component(props) {
|
||||
const callback = () => {
|
||||
try {
|
||||
return [];
|
||||
} catch (e) {
|
||||
return;
|
||||
}
|
||||
};
|
||||
return callback();
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
|
||||
## Error
|
||||
|
||||
```
|
||||
[ReactForget] Invariant: Expected temporaries to be promoted to named identifiers in an earlier pass. identifier 16 is unnamed
|
||||
```
|
||||
|
||||
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
function Component(props) {
|
||||
const callback = () => {
|
||||
try {
|
||||
return [];
|
||||
} catch (e) {
|
||||
return;
|
||||
}
|
||||
};
|
||||
return callback();
|
||||
}
|
||||
Reference in New Issue
Block a user