New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uncaught TypeError: Constructor Map requires 'new'. #6453

Closed
pmunin opened this Issue Oct 9, 2017 · 2 comments

Comments

Projects
None yet
3 participants
@pmunin

pmunin commented Oct 9, 2017

Bug

Input Code

Here is link to babel playground

class MyMap extends Map {
    constructor() {
        super();
    }
    test() {
        return "Hallo world";
    }
}
var myMap = new MyMap();
console.log(myMap instanceof MyMap);
console.log(myMap.test());

Babel Configuration (.babelrc, package.json, cli command)

{
"presets": [
        "env"
    ]
}

Expected Behavior

Should output in console:
true
"Hallo world"

Current Behavior

If I run it in Chrome v61 directly - works fine, but if I precompile it with babel then the following error logged:

Uncaught TypeError: Constructor Map requires 'new'
    at MyMap.Map (<anonymous>)
    at new MyMap (<anonymous>:17:99)
    at <anonymous>:30:13

Possible Solution

There is a way to identify if the function is class by executing ".arguments" or ".caller". For regular functions it will return a value or undefined. But for classes (custom or system, like Map or Set) it will throw error 'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions or the arguments objects for calls to them - maybe this can be used to solve this

Context

Cannot extend Map class

Your Environment

software version(s)
Babel 6.26.0 latest available online at 10/9/2017
node n/a
npm n/a
Operating System Win7 x64
@babel-bot

This comment has been minimized.

Show comment
Hide comment
@babel-bot

babel-bot Oct 9, 2017

Collaborator

Hey @pmunin! We really appreciate you taking the time to report an issue. The collaborators
on this project attempt to help as many people as possible, but we're a limited number of volunteers,
so it's possible this won't be addressed swiftly.

If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack
community that typically always has someone willing to help. You can sign-up here
for an invite.

Collaborator

babel-bot commented Oct 9, 2017

Hey @pmunin! We really appreciate you taking the time to report an issue. The collaborators
on this project attempt to help as many people as possible, but we're a limited number of volunteers,
so it's possible this won't be addressed swiftly.

If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack
community that typically always has someone willing to help. You can sign-up here
for an invite.

@hzoo

This comment has been minimized.

Show comment
Hide comment
@hzoo

hzoo Oct 13, 2017

Member

Thanks for reporting! Babel doesn't handle extending natives in that way still, https://babeljs.io/docs/usage/caveats/#classes

Duplicate of #4480

Since you are using preset-env already, you can always can the target so that it outputs native classes if you are able to

Member

hzoo commented Oct 13, 2017

Thanks for reporting! Babel doesn't handle extending natives in that way still, https://babeljs.io/docs/usage/caveats/#classes

Duplicate of #4480

Since you are using preset-env already, you can always can the target so that it outputs native classes if you are able to

@hzoo hzoo closed this Oct 13, 2017

@hzoo hzoo added the i: duplicate label Oct 13, 2017

@lock lock bot added the outdated label Jun 23, 2018

@lock lock bot locked as resolved and limited conversation to collaborators Jun 23, 2018

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