| [9af201e] | 1 | "use strict";
|
|---|
| 2 |
|
|---|
| 3 | Object.defineProperty(exports, "__esModule", {
|
|---|
| 4 | value: true
|
|---|
| 5 | });
|
|---|
| 6 | exports.default = void 0;
|
|---|
| 7 | exports.get = get;
|
|---|
| 8 | exports.getDependencies = getDependencies;
|
|---|
| 9 | exports.isInternal = isInternal;
|
|---|
| 10 | exports.list = void 0;
|
|---|
| 11 | exports.minVersion = minVersion;
|
|---|
| 12 | var _t = require("@babel/types");
|
|---|
| 13 | var _helpersGenerated = require("./helpers-generated.js");
|
|---|
| 14 | const {
|
|---|
| 15 | cloneNode,
|
|---|
| 16 | identifier
|
|---|
| 17 | } = _t;
|
|---|
| 18 | function deep(obj, path, value) {
|
|---|
| 19 | try {
|
|---|
| 20 | const parts = path.split(".");
|
|---|
| 21 | let last = parts.shift();
|
|---|
| 22 | while (parts.length > 0) {
|
|---|
| 23 | obj = obj[last];
|
|---|
| 24 | last = parts.shift();
|
|---|
| 25 | }
|
|---|
| 26 | if (arguments.length > 2) {
|
|---|
| 27 | obj[last] = value;
|
|---|
| 28 | } else {
|
|---|
| 29 | return obj[last];
|
|---|
| 30 | }
|
|---|
| 31 | } catch (e) {
|
|---|
| 32 | e.message += ` (when accessing ${path})`;
|
|---|
| 33 | throw e;
|
|---|
| 34 | }
|
|---|
| 35 | }
|
|---|
| 36 | function permuteHelperAST(ast, metadata, bindingName, localBindings, getDependency, adjustAst) {
|
|---|
| 37 | const {
|
|---|
| 38 | locals,
|
|---|
| 39 | dependencies,
|
|---|
| 40 | exportBindingAssignments,
|
|---|
| 41 | exportName
|
|---|
| 42 | } = metadata;
|
|---|
| 43 | const bindings = new Set(localBindings || []);
|
|---|
| 44 | if (bindingName) bindings.add(bindingName);
|
|---|
| 45 | for (const [name, paths] of (Object.entries || (o => Object.keys(o).map(k => [k, o[k]])))(locals)) {
|
|---|
| 46 | let newName = name;
|
|---|
| 47 | if (bindingName && name === exportName) {
|
|---|
| 48 | newName = bindingName;
|
|---|
| 49 | } else {
|
|---|
| 50 | while (bindings.has(newName)) newName = "_" + newName;
|
|---|
| 51 | }
|
|---|
| 52 | if (newName !== name) {
|
|---|
| 53 | for (const path of paths) {
|
|---|
| 54 | deep(ast, path, identifier(newName));
|
|---|
| 55 | }
|
|---|
| 56 | }
|
|---|
| 57 | }
|
|---|
| 58 | for (const [name, paths] of (Object.entries || (o => Object.keys(o).map(k => [k, o[k]])))(dependencies)) {
|
|---|
| 59 | const ref = typeof getDependency === "function" && getDependency(name) || identifier(name);
|
|---|
| 60 | for (const path of paths) {
|
|---|
| 61 | deep(ast, path, cloneNode(ref));
|
|---|
| 62 | }
|
|---|
| 63 | }
|
|---|
| 64 | adjustAst == null || adjustAst(ast, exportName, map => {
|
|---|
| 65 | exportBindingAssignments.forEach(p => deep(ast, p, map(deep(ast, p))));
|
|---|
| 66 | });
|
|---|
| 67 | }
|
|---|
| 68 | const helperData = Object.create(null);
|
|---|
| 69 | function loadHelper(name) {
|
|---|
| 70 | if (!helperData[name]) {
|
|---|
| 71 | const helper = _helpersGenerated.default[name];
|
|---|
| 72 | if (!helper) {
|
|---|
| 73 | throw Object.assign(new ReferenceError(`Unknown helper ${name}`), {
|
|---|
| 74 | code: "BABEL_HELPER_UNKNOWN",
|
|---|
| 75 | helper: name
|
|---|
| 76 | });
|
|---|
| 77 | }
|
|---|
| 78 | helperData[name] = {
|
|---|
| 79 | minVersion: helper.minVersion,
|
|---|
| 80 | build(getDependency, bindingName, localBindings, adjustAst) {
|
|---|
| 81 | const ast = helper.ast();
|
|---|
| 82 | permuteHelperAST(ast, helper.metadata, bindingName, localBindings, getDependency, adjustAst);
|
|---|
| 83 | return {
|
|---|
| 84 | nodes: ast.body,
|
|---|
| 85 | globals: helper.metadata.globals
|
|---|
| 86 | };
|
|---|
| 87 | },
|
|---|
| 88 | getDependencies() {
|
|---|
| 89 | return Object.keys(helper.metadata.dependencies);
|
|---|
| 90 | }
|
|---|
| 91 | };
|
|---|
| 92 | }
|
|---|
| 93 | return helperData[name];
|
|---|
| 94 | }
|
|---|
| 95 | function get(name, getDependency, bindingName, localBindings, adjustAst) {
|
|---|
| 96 | if (typeof bindingName === "object") {
|
|---|
| 97 | const id = bindingName;
|
|---|
| 98 | if ((id == null ? void 0 : id.type) === "Identifier") {
|
|---|
| 99 | bindingName = id.name;
|
|---|
| 100 | } else {
|
|---|
| 101 | bindingName = undefined;
|
|---|
| 102 | }
|
|---|
| 103 | }
|
|---|
| 104 | return loadHelper(name).build(getDependency, bindingName, localBindings, adjustAst);
|
|---|
| 105 | }
|
|---|
| 106 | function minVersion(name) {
|
|---|
| 107 | return loadHelper(name).minVersion;
|
|---|
| 108 | }
|
|---|
| 109 | function getDependencies(name) {
|
|---|
| 110 | return loadHelper(name).getDependencies();
|
|---|
| 111 | }
|
|---|
| 112 | function isInternal(name) {
|
|---|
| 113 | var _helpers$name;
|
|---|
| 114 | return (_helpers$name = _helpersGenerated.default[name]) == null ? void 0 : _helpers$name.metadata.internal;
|
|---|
| 115 | }
|
|---|
| 116 | exports.ensure = name => {
|
|---|
| 117 | loadHelper(name);
|
|---|
| 118 | };
|
|---|
| 119 | const list = exports.list = Object.keys(_helpersGenerated.default).map(name => name.replace(/^_/, ""));
|
|---|
| 120 | var _default = exports.default = get;
|
|---|
| 121 |
|
|---|
| 122 | //# sourceMappingURL=index.js.map
|
|---|