babel: Spec compatibility: Calling class constructor functions as function should throw
This is probably very difficult or impossible to achieve. According to the newest draft (rev32), calling a class
constructor function like a normal function (basically everything but calling it with new
as far as I understand), should throw a TypeError
:
class Foo {}
Foo(); // should throw
Foo.call({}); // should throw
Foo.apply({}); // should throw
The spec uses an internal flag on the function object for that.
Not sure we can do anything here, just raising awareness and keep track of it.
About this issue
- Original URL
- State: closed
- Created 9 years ago
- Comments: 20 (9 by maintainers)
If there are many behaviors, will be many classes which extends each other.
You can check this example which shows what I mean: (open your browser’s console to see the output) https://babeljs.io/repl/build/master#?babili=false&browsers=&build=&builtIns=false&code_lz=GYVwdgxgLglg9mABDMArAptAggJwOYgC26YUAFAG4CGANiOgJSIDeAUIojulCDkqJFgJEZAMI0qAZ0lM2HDlx59EECdMToAHlBIATSYnFSDc-RwgJJUHCGhwcZAHTOq-GS3Zn5kkAAd0Ds6OrniSADSI1HSMANyeZgC-8YhJHElJrAACKBjY-EQk5ABEABYAnmXolRXotbVFDFk5mFC4BMSkZEUA7nAlVHBwVA2sqsaIACJEhGUe5pbWtlD2ZCEADBHN0Oi6m2gtOwBMsskWYJJwNOiONHB4XcA4cIQqagZnVjZ2OCNmH5fXW73daNP6WAE3O5kLY6XSg-T_K6Q-4wo4MOJpVgZD5QRC6aZlACS5ygVEg6EQAF5EGB0N1JgSuggKSECqQRqNwUigWR8YQZsSrGSIBSUELyXBgAz-WVGqwgA&debug=false&circleciRepo=&evaluate=true&lineWrap=true&presets=stage-0&prettier=false&targets=Node-8.9&version=7.0.0-beta.34
If you want to continue this discussion, please reach me on Slack so that we don’t spam with notifications who is whatching this issue/repo. You can ask for an invite at https://github.com/babel/notes/issues/38
Can you do something like this?
Can you post a code example which throws but shouldn’t?