microsoft / TypeScript

TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
https://www.typescriptlang.org
Apache License 2.0
99.69k stars 12.35k forks source link

super reference in private method throws #44515

Open dnalborczyk opened 3 years ago

dnalborczyk commented 3 years ago

Bug Report

🔎 Search Terms

private, super

🕗 Version & Regression Information

v4.3.2, also tested with nightly in playground

works with ESNext setting (which just strips out the types), Babel, V8

⏯ Playground Link

https://www.typescriptlang.org/play?ts=4.3.2#code/MYGwhgzhAECC3QN4CgEIC4FMLoBQEolU0SAnTdAV1IDtoByLHe4hAX2Q+VEhgCFomAB5YaAExjwUJAMQAzAPYKCREmQrU6ESgAdMpAHRM8+VtC4kARmFIrpahOSq1o6ABYBLCAflKCZji5gBRocaEtoAF5oGkwAd2g+AgNrW1NuEIgFEEwDEAUAc1xLfCA

💻 Code

class A  {
    test() {
        return 'test'
    }
}

class B extends A {
    #foo() {
        return super.test()
    }

    bar() {
        return this.#foo()
    }
}

const b = new B().bar()

console.log(b)

// [ERR]: "Executed JavaScript Failed:" 
// [ERR]: 'super' keyword unexpected here 

🙁 Actual behavior

throws error

🙂 Expected behavior

prints 'test'

niklavskatlaps commented 1 year ago

It also seems to be working with target set to ES2022.

dnalborczyk commented 1 year ago

It also seems to be working with target set to ES2022.

because there is no down leveling, just the types are being removed.