Skip to content

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

@TysonAndre

Description

@TysonAndre

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

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFixedA PR has been merged 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