Skip to content

Missing syntax error for new A?.b()Β #48653

@nicolo-ribaudo

Description

@nicolo-ribaudo

Bug Report

πŸ”Ž Search Terms

syntax error optional chain new arguments parentheses

πŸ•— Version & Regression Information

Only tested with 4.7 Nightly in the playground

⏯ Playground Link

Playground link with relevant code

πŸ’» Code

class A {
    b() {}
}

new A?.b()
Output
"use strict";
var _a;
class A {
    b() { }
}
(_a = new A) === null || _a === void 0 ? void 0 : _a.b();
Compiler Options
{
  "compilerOptions": {
    "strict": true,
    "noImplicitAny": true,
    "strictNullChecks": true,
    "strictFunctionTypes": true,
    "strictPropertyInitialization": true,
    "strictBindCallApply": true,
    "noImplicitThis": true,
    "noImplicitReturns": true,
    "alwaysStrict": true,
    "esModuleInterop": true,
    "declaration": true,
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true,
    "target": "ES2017",
    "jsx": "react",
    "module": "ESNext",
    "moduleResolution": "node"
  }
}

Playground Link: Provided

πŸ™ Actual behavior

new A?.b() is parsed as if it was new A()?.b()

πŸ™‚ Expected behavior

It should be a syntax error, because it's not valid JavaScript syntax.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptHelp WantedYou can do this

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions