-
Notifications
You must be signed in to change notification settings - Fork 46.8k
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
[compiler] Implement support for hoisted and recursive functions #30922
Merged
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1001,6 +1001,20 @@ function codegenTerminal( | |
loc: iterableItem.loc, | ||
suggestions: null, | ||
}); | ||
case InstructionKind.HoistedFunction: | ||
CompilerError.invariant(false, { | ||
reason: 'Unexpected HoistedFunction variable in for..in collection', | ||
description: null, | ||
loc: iterableItem.loc, | ||
suggestions: null, | ||
}); | ||
case InstructionKind.Function: | ||
CompilerError.invariant(false, { | ||
reason: 'Unexpected Function variable in for..in collection', | ||
description: null, | ||
loc: iterableItem.loc, | ||
suggestions: null, | ||
}); | ||
default: | ||
assertExhaustive( | ||
iterableItem.value.lvalue.kind, | ||
|
@@ -1103,6 +1117,20 @@ function codegenTerminal( | |
loc: iterableItem.loc, | ||
suggestions: null, | ||
}); | ||
case InstructionKind.HoistedFunction: | ||
CompilerError.invariant(false, { | ||
reason: 'Unexpected HoistedFunction variable in for..of collection', | ||
description: null, | ||
loc: iterableItem.loc, | ||
suggestions: null, | ||
}); | ||
case InstructionKind.Function: | ||
CompilerError.invariant(false, { | ||
reason: 'Unexpected Function variable in for..of collection', | ||
description: null, | ||
loc: iterableItem.loc, | ||
suggestions: null, | ||
}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here |
||
default: | ||
assertExhaustive( | ||
iterableItem.value.lvalue.kind, | ||
|
@@ -1261,6 +1289,35 @@ function codegenInstructionNullable( | |
t.variableDeclarator(codegenLValue(cx, lvalue), value), | ||
]); | ||
} | ||
case InstructionKind.Function: { | ||
CompilerError.invariant(instr.lvalue === null, { | ||
reason: `Function declaration cannot be referenced as an expression`, | ||
description: null, | ||
loc: instr.value.loc, | ||
suggestions: null, | ||
}); | ||
const genLvalue = codegenLValue(cx, lvalue); | ||
CompilerError.invariant(genLvalue.type === 'Identifier', { | ||
reason: 'Expected an identifier as a function declaration lvalue', | ||
description: null, | ||
loc: instr.value.loc, | ||
suggestions: null, | ||
}); | ||
CompilerError.invariant(value?.type === 'FunctionExpression', { | ||
reason: 'Expected a function as a function declaration value', | ||
description: null, | ||
loc: instr.value.loc, | ||
suggestions: null, | ||
}); | ||
return createFunctionDeclaration( | ||
instr.loc, | ||
genLvalue, | ||
value.params, | ||
value.body, | ||
value.generator, | ||
value.async, | ||
); | ||
} | ||
case InstructionKind.Let: { | ||
CompilerError.invariant(instr.lvalue === null, { | ||
reason: `Const declaration cannot be referenced as an expression`, | ||
|
@@ -1321,6 +1378,15 @@ function codegenInstructionNullable( | |
suggestions: null, | ||
}); | ||
} | ||
case InstructionKind.HoistedFunction: { | ||
CompilerError.invariant(false, { | ||
reason: | ||
'Expected HoistedFunction to have been pruned in PruneHoistedContexts', | ||
description: null, | ||
loc: instr.loc, | ||
suggestions: null, | ||
}); | ||
} | ||
default: { | ||
assertExhaustive(kind, `Unexpected instruction kind \`${kind}\``); | ||
} | ||
|
@@ -1486,6 +1552,7 @@ const createBinaryExpression = withLoc(t.binaryExpression); | |
const createExpressionStatement = withLoc(t.expressionStatement); | ||
const _createLabelledStatement = withLoc(t.labeledStatement); | ||
const createVariableDeclaration = withLoc(t.variableDeclaration); | ||
const createFunctionDeclaration = withLoc(t.functionDeclaration); | ||
const _createWhileStatement = withLoc(t.whileStatement); | ||
const createTaggedTemplateExpression = withLoc(t.taggedTemplateExpression); | ||
const createLogicalExpression = withLoc(t.logicalExpression); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 0 additions & 29 deletions
29
...er/src/__tests__/fixtures/compiler/error.hoisted-function-declaration.expect.md
This file was deleted.
Oops, something went wrong.
8 changes: 0 additions & 8 deletions
8
...ugin-react-compiler/src/__tests__/fixtures/compiler/error.hoisted-function-declaration.js
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 0 additions & 30 deletions
30
.../__tests__/fixtures/compiler/error.todo-recursive-function-expression.expect.md
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we could just collapse all these unsupported cases