mirror of
https://github.com/swc-project/swc.git
synced 2024-12-20 20:22:26 +03:00
b044d2c6dd
swc_ecma_transforms_base: - Add some helpers. swc_ecma_transforms_compat: - `class_properties`: Support private methods. (Closes #1694)
23 lines
687 B
JavaScript
23 lines
687 B
JavaScript
function _classCallCheck(instance, Constructor) {
|
|
if (!(instance instanceof Constructor)) {
|
|
throw new TypeError("Cannot call a class as a function");
|
|
}
|
|
}
|
|
function _classPrivateMethodGet(receiver, privateSet, fn) {
|
|
if (!privateSet.has(receiver)) {
|
|
throw new TypeError("attempted to get private field on non-instance");
|
|
}
|
|
return fn;
|
|
}
|
|
var _get = new WeakSet();
|
|
var MyClass = function MyClass() {
|
|
"use strict";
|
|
_classCallCheck(this, MyClass);
|
|
_get.add(this);
|
|
_classPrivateMethodGet(this, _get, get).call(this);
|
|
};
|
|
function get() {
|
|
console.log("Hi from a method with a private identifier called #get");
|
|
}
|
|
var instance = new MyClass();
|