Skip to content

[Bug]: Create Proxy with a Non-object as Target or Handler #14413

@clhiker

Description

@clhiker

💻

  • Would you like to work on a fix?

How are you using Babel?

@babel/cli

Input code

(async function () {
    function v0(v1 = () => null) {
    }
    await null;
});
const v0 = { alpha: { beta: { charlie: { delta: 'hello' } } } };
for (let v0 = 0; v0 < [].length; ++v0) {
    if (v0 > 8) {
        break;
    }
}
const v3 = new Proxy(v0, {
    has: function (v3, v4) {
        return v4 === 'value' ? false : Reflect.has(v3, v4);
    }
});

Here is the PERL

Configuration file name

babel.config.json

Configuration

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

Current and expected behavior

The transpiler code run by node report an error:

var v3 = new Proxy(v0, {
         ^

TypeError: Cannot create proxy with a non-object as target or handler

This may be caused by Babel converting let variable to var. in the following new proxy, there is a bug caused by scope change

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

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions