Skip to content

[Bug]: Right-Hand Side of 'instanceof' is not an Object #14406

@clhiker

Description

@clhiker

💻

  • Would you like to work on a fix?

How are you using Babel?

@babel/cli

Input code

function v1() {
    let v1 = new.target;    
}
var v3 = new v1();

Here is the REPL

Configuration file name

babel.config.json

Configuration

{
  "sourceType": "unambiguous",
  "presets": ["@babel/preset-env"],
  "plugins": [
    "@babel/plugin-transform-runtime"
  ]
}

Current and expected behavior

Inside the function, this bug will be triggered when the variable name and function name happen to be the same and the variable is a new target. The transpiled code run by node will report the following error:

 var v1 = this instanceof v1 ? this.constructor : void 0;
                ^

TypeError: Right-hand side of 'instanceof' is not an object

Environment

  • babel
  • ├── @babel/cli@7.17.0=6
  • ├── @babel/generator@7.17.3
  • ├── @babel/plugin-transform-runtime@7.17.0
  • ├── @babel/preset-env@7.16.11
  • Node: [v17.3.0]
  • npm version [8.5.2]
  • os [ubuntu 20.04]

Possible solution

No response

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    outdatedA closed issue/PR that is archived due to age. Recommended to make a new issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions