swc/tests/fixture/issue-1694/case1/output/index.js
강동윤 b044d2c6dd
fix(es/transforms/compat): Support private methods (#1700)
swc_ecma_transforms_base:
 - Add some helpers.

swc_ecma_transforms_compat:
 - `class_properties`: Support private methods. (Closes #1694)
2021-05-15 20:35:24 +09:00

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();