Skip to content

Maximum call stack size exceeded when compiling tsx #46021

Closed
@martind-gmc

Description

@martind-gmc

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

Activity

added
BugA bug in TypeScript
CrashFor flagging bugs which are compiler or service crashes or unclean exits, rather than bad output
on Sep 23, 2021
added this to the TypeScript 4.5.1 milestone on Sep 23, 2021
sandersn

sandersn commented on Oct 4, 2021

@sandersn
Member

Broken by #43183

sandersn

sandersn commented on Oct 4, 2021

@sandersn
Member

#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

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptCrashFor flagging bugs which are compiler or service crashes or unclean exits, rather than bad outputFix AvailableA PR has been opened for this issue

Type

No type

Projects

No projects

Relationships

None yet

    Development

    Participants

    @sandersn@andrewbranch@ahejlsberg@martind-gmc@typescript-bot

    Issue actions

      Maximum call stack size exceeded when compiling tsx · Issue #46021 · microsoft/TypeScript