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

Fix "RangeError: Maximum call stack size exceeded" #31

Merged
merged 2 commits into from Mar 2, 2019

Conversation

jm9e
Copy link
Contributor

@jm9e jm9e commented Jan 31, 2019

Spread operator

The spread operator on line 153 sometimes causes a "RangeError: Maximum call stack size exceeded" error.
My suggestion is to replace it with an ordinary for-in loop.

See also here:
https://stackoverflow.com/questions/22123769/rangeerror-maximum-call-stack-size-exceeded-why

Here is the original error:

The 'no-circular-imports' rule threw an error in '....ts':
RangeError: Maximum call stack size exceeded
    at getAllCycles (...\tslint-no-circular-imports\noCircularImportsRule.js:188:30)
    at walk (...\tslint-no-circular-imports\noCircularImportsRule.js:120:25)
    at Rule.AbstractRule.applyWithFunction (...\tslint-no-circular-imports\node_modules\tslint\lib\language\rule\abstractRule.js:39:9)
    at Rule.applyWithProgram (...\tslint-no-circular-imports\noCircularImportsRule.js:66:21)
    at Linter.applyRule (...\node_modules\tslint\lib\linter.js:206:29)
    at ...\node_modules\tslint\lib\linter.js:150:85
    at Object.flatMap (...\node_modules\tslint\lib\utils.js:160:29)
    at Linter.getAllFailures (...\node_modules\tslint\lib\linter.js:150:32)
    at Linter.lint (...\node_modules\tslint\lib\linter.js:105:33)
    at ...\node_modules\tslint\lib\runner.js:214:32

Type check

I also asserted node.parent to be of type SourceFile.
I get an error without that check because node.parent can also be of type ModuleBlock which would not have a property fileName.

noCircularImportsRule.ts:118:34 - error TS2339: Property 'fileName' does not exist on type 'ModuleBlock | SourceFile'.
      Property 'fileName' does not exist on type 'ModuleBlock'.

    118     const fileName = node.parent.fileName
                                         ~~~~~~~~

noCircularImportsRule.ts:118:34 - error TS2339: Property 'fileName' does not exist on type 'ModuleBlock | SourceFile'.
  Property 'fileName' does not exist on type 'ModuleBlock'.

118     const fileName = node.parent.fileName
                                     ~~~~~~~~
Fixes the following error:
The 'no-circular-imports' rule threw an error in '...':
RangeError: Maximum call stack size exceeded
@krzysztof-miemiec
Copy link

Looks good to me, can't wait till it gets merged 🎉

@bcherny
Copy link
Owner

bcherny commented Mar 2, 2019

Thanks for the contribution @jm9e!

@bcherny bcherny merged commit 45fcb1c into bcherny:master Mar 2, 2019
@bcherny
Copy link
Owner

bcherny commented Mar 2, 2019

Published 0.6.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants