google / google/closure-compiler

Constructors of ES classes require `new` but the runtime doesn't check it

Open
#2,919 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
7.7k
Forks
1.2k
Avg merge
2d 12h
Merged PRs (30d)
6

Description

In ES2015+, calling constructors of classes and builtin classes (Map, Set, WeakMap and WeakSet) without `new` throws `TypeError`.
```js
Map(); // throws `TypeError`
```
> https://www.ecma-international.org/ecma-262/6.0/#sec-map-iterable

In Closure Compiler `ADVANCED` mode, `JSC_CONSTRUCTOR_NOT_CALLABLE` warning is correctly thrown in compile time.
But in `SIMPLE` or `WHITESPACE_ONLY` mode, no warnings are detected in compile time and the runtime doesn't throw any errors.

Should the polyfill runtime of Closure Compiler for the constructors throw runtime error for `SIMPLE` and `WHITESPACE_ONLY` mode?

I will send a PR if necessary.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.