Skip to content

Cannot read property 'prototype' of undefined #10837

Closed
@nin-jin

Description

@nin-jin

script.ts

class A extends B {}
class B { static foo() {} }

Produces broken js that throws subject exception

var __extends = (this && this.__extends) || function (d, b) {
    for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
    function __() { this.constructor = d; }
    d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
var A = (function (_super) {
    __extends(A, _super);
    function A() {
        _super.apply(this, arguments);
    }
    return A;
}(B));
var B = (function () {
    function B() {
    }
    B.foo = function () { };
    return B;
}());

We need to produce js like this

var __extends = (this && this.__extends) || function (d, b) {
    if( Object.setPrototypeOf ) Object.setPrototypeOf( d , b )
    else for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
    function __() { this.constructor = d; }
    d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
function A() {
    B.apply(this);
}
__extends(A, B);
function B() {
}
B.foo = function () { };
  1. This is short and clear code.
  2. This code are close to code writed by human.
  3. This works right in modern browsers.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions