Skip to content
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

Maximum call stack size exceeded when compiling tsx #46021

Closed
martind-gmc opened this issue Sep 23, 2021 · 2 comments · Fixed by #46354
Closed

Maximum call stack size exceeded when compiling tsx #46021

martind-gmc opened this issue Sep 23, 2021 · 2 comments · Fixed by #46354
Assignees
Labels
Bug A bug in TypeScript Crash For flagging bugs which are compiler or service crashes or unclean exits, rather than bad output Fix Available A PR has been opened for this issue

Comments

@martind-gmc
Copy link

Bug Report

Compilation of tsx file throws generic error RangeError: Maximum call stack size exceeded. When the file doesn't contain any tsx element the compilation works as expected.

Possible duplicate of:
#45632

🔎 Search Terms

Maximum call stack size exceeded

🕗 Version & Regression Information

4.3 and newer (also tested on 4.5.0-dev.20210923)

⏯ Playground Link

Playground link with relevant code

🙁 Actual behavior

RangeError: Maximum call stack size exceeded
at Object.isFunctionLikeOrClassStaticBlockDeclaration (\node_modules\typescript\lib\tsc.js:9813:27)
at isBlockScope (\node_modules\typescript\lib\tsc.js:11161:28)
at \node_modules\typescript\lib\tsc.js:11242:73
at Object.findAncestor (\npm\node_modules\typescript\lib\tsc.js:9189:26)
at Object.getEnclosingBlockScopeContainer (\npm\node_modules\typescript\lib\tsc.js:11242:19)
at checkNestedBlockScopedBinding (\npm\node_modules\typescript\lib\tsc.js:57015:32)
at checkIdentifier (\npm\node_modules\typescript\lib\tsc.js:56921:13)
at checkExpressionWorker (\npm\node_modules\typescript\lib\tsc.js:63702:28)
at checkExpression (\npm\node_modules\typescript\lib\tsc.js:63657:38)
at checkJsxExpression (\npm\node_modules\typescript\lib\tsc.js:59059:28)

🙂 Expected behavior

compilation with no error

@andrewbranch andrewbranch added Bug A bug in TypeScript Crash For flagging bugs which are compiler or service crashes or unclean exits, rather than bad output labels Sep 23, 2021
@andrewbranch andrewbranch added this to the TypeScript 4.5.1 milestone Sep 23, 2021
@sandersn
Copy link
Member

sandersn commented Oct 4, 2021

Broken by #43183

@sandersn
Copy link
Member

sandersn commented Oct 4, 2021

#43183 skips nodes whose parents are JSX elements, but that doesn't apply to JSXExpression's expressions. I don't know if it should.

Edit: Exempting the expression of a JSXExpression makes the below test pass.
(by adding !(isJsxExpression(node.parent) && node.parent.expression === node) && to hasNonBindingPatternContextualTypeWithNoGenericTypes)

Here's the test case from the playground link:

interface IData<MenuItemVariant extends ListItemVariant = ListItemVariant.OneLine> {
    menuItemsVariant?: MenuItemVariant;
}

function Menu<MenuItemVariant extends ListItemVariant = ListItemVariant.OneLine>(
    data: IData<MenuItemVariant>
) {
    const listItemVariant = data.menuItemsVariant ?? ListItemVariant.OneLine;

    // Non-tsx version compiles to js/jsx as expected
    //return ListItem({variant: listItemVariant});

    // tsx version doesn't compile and throws error as can be seen in devtools/console
    return <ListItem variant={listItemVariant} />;
}

type IListItemData = { variant: ListItemVariant.Avatar; } | { variant: ListItemVariant.OneLine; };

enum ListItemVariant {
    OneLine,
    Avatar,
}

function ListItem(_data: IListItemData) {
    return null; 
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Crash For flagging bugs which are compiler or service crashes or unclean exits, rather than bad output Fix Available A PR has been opened for this issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants