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

Exception in getSpecialPropertyAssignmentKind when handling || in const value #15616

Closed
TysonAndre opened this issue May 5, 2017 · 6 comments
Assignees
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue

Comments

@TysonAndre
Copy link

TypeScript Version: 2.4.0-dev.20170505 (nightly)

Code

// (Using react version "15.4.2")
// This is a .js file, using --checkJS (and extra lines were cut out)
define(function(require) {
    'use strict';

    const { Component} = require('react');

    const DEFAULT_MESSAGE = 'Uh-oh, something went wrong...';

    class Errors extends Component {
        _renderMessage(error) {
            const message = error.message || DEFAULT_MESSAGE;
        }
    }
});
# install tsc 20170505 and react 15.4.2 first
tsc --allowJs --checkJs --strict --noEmit example.js

Expected behavior:
Does not crash
Actual behavior:
Crashes because operatorToken is not an object, and the code is trying to access expr.operatorToken.kind

Additionally, with this patch to diagnose the cause, I saw more info

    function getSpecialPropertyAssignmentKind(expression) {
        if (!isInJavaScriptFile(expression)) {
            return 0;
        }     
        var expr = expression;
// begin patch
        if (!expr.operatorToken) {
            console.log('getSpecialPropertyAssignmentKind op', expr);  // This logged, for the '||' operator?
            return 0;
        }     
        if (!expr.left) {
            console.log('getSpecialPropertyAssignmentKind left', expr);
            return 0;
        } 
// end patch

Output: https://gist.github.com/TysonAndre/ba9ccf4ada6401d71f877c07f2700dfb

@mhegazy
Copy link
Contributor

mhegazy commented May 5, 2017

I am unable to reproduce the original issue, can you share more context..

c:\test\15616>type a.js
// (Using react version "15.4.2")
// This is a .js file, using --checkJS (and extra lines were cut out)
define(function(require) {
    'use strict';

    const { Component} = require('react');

    const DEFAULT_MESSAGE = 'Uh-oh, something went wrong...';

    class Errors extends Component {
        _renderMessage(error) {
            const message = error.message || DEFAULT_MESSAGE;
        }
    }
});

c:\test\15616>type jsconfig.json
{
    "compilerOptions": {
        "checkJs": true,
        "noEmit": true
    }
}

c:\test\15616>ls node_modules\@types
[.]         [..]        [react]     [requirejs]
               0 File(s)              0 bytes
               4 Dir(s)  40,390,402,048 bytes free

c:\test\15616>tsc --v
Version 2.3.2

c:\test\15616>tsc --p jsconfig.json

c:\test\15616>echo %ERRORLEVEL%
0

@mhegazy mhegazy added the Needs More Info The issue still hasn't been fully clarified label May 5, 2017
@TysonAndre
Copy link
Author

TysonAndre commented May 5, 2017

  1. Try the exact command I gave, without a jsConfig?
  2. I stated I was using 2.4.0-dev in the ticket, you're using something different (I can reproduce in 2.4.0-dev-2017-05-05 but this isn't an issue in 2.3.2)
» tsc  --version                               
Version 2.4.0-dev.20170505
» tsc --allowJs --checkJs --strict --noEmit example.js

@mhegazy
Copy link
Contributor

mhegazy commented May 5, 2017

I see.. thanks looks like a regression from #15586. @sandersn can you take a look.

@mhegazy mhegazy added Bug A bug in TypeScript and removed Needs More Info The issue still hasn't been fully clarified labels May 5, 2017
@mhegazy mhegazy added this to the TypeScript 2.4 milestone May 5, 2017
@chris-codaio
Copy link

Looks like this is blocking the start of our JS -> TS migration. Looking forward to a fix :)

@sandersn
Copy link
Member

sandersn commented May 8, 2017

The better check is just whether the declaration is a BinaryExpression, since multiple kinds of Javascript declarations use assignment, and those are the only declarations whose kind is BinaryExpression.

#15594 has this fix too, but I'll give it its own PR to get it in faster.

@sandersn
Copy link
Member

sandersn commented May 8, 2017

OK, fix is up at #15669

@sandersn sandersn added the Fixed A PR has been merged for this issue label May 8, 2017
@microsoft microsoft locked and limited conversation to collaborators Jun 14, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue
Projects
None yet
Development

No branches or pull requests

4 participants