Skip to content

@babel/parser should disallow unparenthesized super call after new #17868

Description

@JLHwung

💻

  • Would you like to work on a fix?

How are you using Babel?

Programmatic API (babel.transform, babel.parse)

Input code

class C extends class {} {
  constructor() { new super() }
}

REPL

Configuration file name

No response

Configuration

REPL

Current and expected behavior

Current: The parser parses successfully
Expect: The parser should reject new super()

Environment

REPL

Possible solution

check callee.type in parseNewCallee.

Additional context

Per spec:

NewExpression[Yield, Await] :
    MemberExpression[?Yield, ?Await]
    new NewExpression[?Yield, ?Await] 

MemberExpression[Yield, Await] :
    PrimaryExpression[?Yield, ?Await]
    MemberExpression[?Yield, ?Await] [ Expression[+In, ?Yield, ?Await] ]
    MemberExpression[?Yield, ?Await] . IdentifierName
    MemberExpression[?Yield, ?Await] TemplateLiteral[?Yield, ?Await, +Tagged]
    SuperProperty[?Yield, ?Await]
    MetaProperty
    new MemberExpression[?Yield, ?Await] Arguments[?Yield, ?Await]
    MemberExpression[?Yield, ?Await] . PrivateIdentifier 

new super() is not covered by the NewExpression production since the MemberExpression production within new MemberExpression Arguments does not cover lone super.

V8/SM/JSC/TypeScript all reject this case.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions