This commit is contained in:
lalBi94
2023-03-05 13:23:23 +01:00
commit 7bc56c09b5
14034 changed files with 1834369 additions and 0 deletions

View File

@@ -0,0 +1,88 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _helperPluginUtils = require("@babel/helper-plugin-utils");
var _helperAnnotateAsPure = require("@babel/helper-annotate-as-pure");
var _helperFunctionName = require("@babel/helper-function-name");
var _helperSplitExportDeclaration = require("@babel/helper-split-export-declaration");
var _core = require("@babel/core");
var _globals = require("globals");
var _transformClass = require("./transformClass");
const getBuiltinClasses = category => Object.keys(_globals[category]).filter(name => /^[A-Z]/.test(name));
const builtinClasses = new Set([...getBuiltinClasses("builtin"), ...getBuiltinClasses("browser")]);
var _default = (0, _helperPluginUtils.declare)((api, options) => {
var _api$assumption, _api$assumption2, _api$assumption3, _api$assumption4;
api.assertVersion(7);
const {
loose = false
} = options;
const setClassMethods = (_api$assumption = api.assumption("setClassMethods")) != null ? _api$assumption : loose;
const constantSuper = (_api$assumption2 = api.assumption("constantSuper")) != null ? _api$assumption2 : loose;
const superIsCallableConstructor = (_api$assumption3 = api.assumption("superIsCallableConstructor")) != null ? _api$assumption3 : loose;
const noClassCalls = (_api$assumption4 = api.assumption("noClassCalls")) != null ? _api$assumption4 : loose;
const VISITED = new WeakSet();
return {
name: "transform-classes",
visitor: {
ExportDefaultDeclaration(path) {
if (!path.get("declaration").isClassDeclaration()) return;
(0, _helperSplitExportDeclaration.default)(path);
},
ClassDeclaration(path) {
const {
node
} = path;
const ref = node.id || path.scope.generateUidIdentifier("class");
path.replaceWith(_core.types.variableDeclaration("let", [_core.types.variableDeclarator(ref, _core.types.toExpression(node))]));
},
ClassExpression(path, state) {
const {
node
} = path;
if (VISITED.has(node)) return;
const inferred = (0, _helperFunctionName.default)(path);
if (inferred && inferred !== node) {
path.replaceWith(inferred);
return;
}
VISITED.add(node);
const [replacedPath] = path.replaceWith((0, _transformClass.default)(path, state.file, builtinClasses, loose, {
setClassMethods,
constantSuper,
superIsCallableConstructor,
noClassCalls
}));
if (replacedPath.isCallExpression()) {
(0, _helperAnnotateAsPure.default)(replacedPath);
const callee = replacedPath.get("callee");
if (callee.isArrowFunctionExpression()) {
callee.arrowFunctionToExpression();
}
}
}
}
};
});
exports.default = _default;

View File

@@ -0,0 +1,72 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = addCreateSuperHelper;
var _core = require("@babel/core");
const helperIDs = new WeakMap();
function addCreateSuperHelper(file) {
if (helperIDs.has(file)) {
return (_core.types.cloneNode || _core.types.clone)(helperIDs.get(file));
}
try {
return file.addHelper("createSuper");
} catch (_unused) {}
const id = file.scope.generateUidIdentifier("createSuper");
helperIDs.set(file, id);
const fn = helper({
CREATE_SUPER: id,
GET_PROTOTYPE_OF: file.addHelper("getPrototypeOf"),
POSSIBLE_CONSTRUCTOR_RETURN: file.addHelper("possibleConstructorReturn")
});
file.path.unshiftContainer("body", [fn]);
file.scope.registerDeclaration(file.path.get("body.0"));
return _core.types.cloneNode(id);
}
const helper = _core.template.statement`
function CREATE_SUPER(Derived) {
function isNativeReflectConstruct() {
if (typeof Reflect === "undefined" || !Reflect.construct) return false;
// core-js@3
if (Reflect.construct.sham) return false;
// Proxy can't be polyfilled. Every browser implemented
// proxies before or at the same time as Reflect.construct,
// so if they support Proxy they also support Reflect.construct.
if (typeof Proxy === "function") return true;
// Since Reflect.construct can't be properly polyfilled, some
// implementations (e.g. core-js@2) don't set the correct internal slots.
// Those polyfills don't allow us to subclass built-ins, so we need to
// use our fallback implementation.
try {
// If the internal slots aren't set, this throws an error similar to
// TypeError: this is not a Date object.
Date.prototype.toString.call(Reflect.construct(Date, [], function() {}));
return true;
} catch (e) {
return false;
}
}
return function () {
var Super = GET_PROTOTYPE_OF(Derived), result;
if (isNativeReflectConstruct()) {
// NOTE: This doesn't work if this.__proto__.constructor has been modified.
var NewTarget = GET_PROTOTYPE_OF(this).constructor;
result = Reflect.construct(Super, arguments, NewTarget);
} else {
result = Super.apply(this, arguments);
}
return POSSIBLE_CONSTRUCTOR_RETURN(this, result);
}
}
`;

File diff suppressed because it is too large Load Diff