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