Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Compiler crash on exports.fn patternΒ #42350

Copy link
Copy link
@mihailik

Description

@mihailik
Issue body actions

Bug Report

πŸ”Ž Search Terms

πŸ•— Version & Regression Information

  • This is a crash
  • This changed between versions 4.0.5 and 4.1.3

⏯ Playground Link

2-line example

πŸ’» Code

exports.fn1();
exports.fn2 = Math.min;

πŸ™ Actual behavior

Crashing:

TypeError: Cannot read property 'length' of undefined
    at getPropertyOfType (C:\Users\mihai\danfo\node_modules\typescript\lib\tsc.js:44083:45)
    at getTypeOfDottedName (C:\Users\mihai\danfo\node_modules\typescript\lib\tsc.js:52423:44)
    at getEffectsSignature (C:\Users\mihai\danfo\node_modules\typescript\lib\tsc.js:52436:32)
    at getTypeAtFlowCall (C:\Users\mihai\danfo\node_modules\typescript\lib\tsc.js:52755:33)
    at getTypeAtFlowNode (C:\Users\mihai\danfo\node_modules\typescript\lib\tsc.js:52636:32)
    at getFlowTypeOfReference (C:\Users\mihai\danfo\node_modules\typescript\lib\tsc.js:52593:51)      
    at checkIdentifier (C:\Users\mihai\danfo\node_modules\typescript\lib\tsc.js:53580:28)
    at checkExpressionWorker (C:\Users\mihai\danfo\node_modules\typescript\lib\tsc.js:59973:28)       
    at checkExpression (C:\Users\mihai\danfo\node_modules\typescript\lib\tsc.js:59928:38)
    at checkNonNullExpression (C:\Users\mihai\danfo\node_modules\typescript\lib\tsc.js:55612:37)      

This is running tsc.js with: node --inspect-brk node_modules\typescript\lib\tsc.js repor.js --out repor.out.js --allowJs and some state in context:

image

πŸ™‚ Expected behavior

Transpile, don't crash. Can produce errors/warnings, but not crash.

Background

This happened when I tried to run TypeScript over the latest CodeMirror, and stumbled upon the file runmode.node.js (see on unpkg). Then, simplified to the minimal reproduction case.

As you can see from the caught error above, resolved.callSignatures is undefined and that causes throw here.

I assume this happens because exports isn't treated as a normal global variable even in a variable position. But in variable position it should be treated as a variable.

Note: can't simplify any more, both lines are necessary. Which means it's not just bad handling of exports, but something more conspiratorial.

Reactions are currently unavailable

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptA bug in TypeScriptFix AvailableA PR has been opened for this issueA PR has been opened for this issue

Type

No type
No fields configured for issues without a type.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions

    Morty Proxy This is a proxified and sanitized view of the page, visit original site.