basant307/AI_Governance_Project
048
1'use strict';2 3const node_fs = require('node:fs');4require('fs');5const sourceMap = require('source-map-js');6const babelParser = require('@babel/parser');7 8function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }9 10function _interopNamespaceCompat(e) {11 if (e && typeof e === 'object' && 'default' in e) return e;12 const n = Object.create(null);13 if (e) {14 for (const k in e) {15 n[k] = e[k];16 }17 }18 n.default = e;19 return n;20}21 22const sourceMap__default = /*#__PURE__*/_interopDefaultCompat(sourceMap);23const babelParser__namespace = /*#__PURE__*/_interopNamespaceCompat(babelParser);24 25function sharedPlugin(fork) {26 var types = fork.use(typesPlugin);27 var Type = types.Type;28 var builtin = types.builtInTypes;29 var isNumber = builtin.number;30 function geq(than) {31 return Type.from(32 (value) => isNumber.check(value) && value >= than,33 isNumber + " >= " + than34 );35 }36 const defaults = {37 // Functions were used because (among other reasons) that's the most38 // elegant way to allow for the emptyArray one always to give a new39 // array instance.40 "null": function() {41 return null;42 },43 "emptyArray": function() {44 return [];45 },46 "false": function() {47 return false;48 },49 "true": function() {50 return true;51 },52 "undefined": function() {53 },54 "use strict": function() {55 return "use strict";56 }57 };58 var naiveIsPrimitive = Type.or(59 builtin.string,60 builtin.number,61 builtin.boolean,62 builtin.null,63 builtin.undefined64 );65 const isPrimitive = Type.from(66 (value) => {67 if (value === null)68 return true;69 var type = typeof value;70 if (type === "object" || type === "function") {71 return false;72 }73 return true;74 },75 naiveIsPrimitive.toString()76 );77 return {78 geq,79 defaults,80 isPrimitive81 };82}83function maybeSetModuleExports(moduleGetter) {84 try {85 var nodeModule = moduleGetter();86 var originalExports = nodeModule.exports;87 var defaultExport = originalExports["default"];88 } catch {89 return;90 }91 if (defaultExport && defaultExport !== originalExports && typeof originalExports === "object") {92 Object.assign(defaultExport, originalExports, { "default": defaultExport });93 if (originalExports.__esModule) {94 Object.defineProperty(defaultExport, "__esModule", { value: true });95 }96 nodeModule.exports = defaultExport;97 }98}99 100var __defProp$2 = Object.defineProperty;101var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;102var __publicField$2 = (obj, key, value) => {103 __defNormalProp$2(obj, typeof key !== "symbol" ? key + "" : key, value);104 return value;105};106const Op$1 = Object.prototype;107const objToStr = Op$1.toString;108const hasOwn$6 = Op$1.hasOwnProperty;109class BaseType {110 assert(value, deep) {111 if (!this.check(value, deep)) {112 var str = shallowStringify(value);113 throw new Error(str + " does not match type " + this);114 }115 return true;116 }117 arrayOf() {118 const elemType = this;119 return new ArrayType(elemType);120 }121}122class ArrayType extends BaseType {123 constructor(elemType) {124 super();125 this.elemType = elemType;126 __publicField$2(this, "kind", "ArrayType");127 }128 toString() {129 return "[" + this.elemType + "]";130 }131 check(value, deep) {132 return Array.isArray(value) && value.every((elem) => this.elemType.check(elem, deep));133 }134}135class IdentityType extends BaseType {136 constructor(value) {137 super();138 this.value = value;139 __publicField$2(this, "kind", "IdentityType");140 }141 toString() {142 return String(this.value);143 }144 check(value, deep) {145 const result = value === this.value;146 if (!result && typeof deep === "function") {147 deep(this, value);148 }149 return result;150 }151}152class ObjectType extends BaseType {153 constructor(fields) {154 super();155 this.fields = fields;156 __publicField$2(this, "kind", "ObjectType");157 }158 toString() {159 return "{ " + this.fields.join(", ") + " }";160 }161 check(value, deep) {162 return objToStr.call(value) === objToStr.call({}) && this.fields.every((field) => {163 return field.type.check(value[field.name], deep);164 });165 }166}167class OrType extends BaseType {168 constructor(types) {169 super();170 this.types = types;171 __publicField$2(this, "kind", "OrType");172 }173 toString() {174 return this.types.join(" | ");175 }176 check(value, deep) {177 if (this.types.some((type) => type.check(value, !!deep))) {178 return true;179 }180 if (typeof deep === "function") {181 deep(this, value);182 }183 return false;184 }185}186class PredicateType extends BaseType {187 constructor(name, predicate) {188 super();189 this.name = name;190 this.predicate = predicate;191 __publicField$2(this, "kind", "PredicateType");192 }193 toString() {194 return this.name;195 }196 check(value, deep) {197 const result = this.predicate(value, deep);198 if (!result && typeof deep === "function") {199 deep(this, value);200 }201 return result;202 }203}204class Def {205 constructor(type, typeName) {206 this.type = type;207 this.typeName = typeName;208 __publicField$2(this, "baseNames", []);209 __publicField$2(this, "ownFields", /* @__PURE__ */ Object.create(null));210 // Includes own typeName. Populated during finalization.211 __publicField$2(this, "allSupertypes", /* @__PURE__ */ Object.create(null));212 // Linear inheritance hierarchy. Populated during finalization.213 __publicField$2(this, "supertypeList", []);214 // Includes inherited fields.215 __publicField$2(this, "allFields", /* @__PURE__ */ Object.create(null));216 // Non-hidden keys of allFields.217 __publicField$2(this, "fieldNames", []);218 // This property will be overridden as true by individual Def instances219 // when they are finalized.220 __publicField$2(this, "finalized", false);221 // False by default until .build(...) is called on an instance.222 __publicField$2(this, "buildable", false);223 __publicField$2(this, "buildParams", []);224 }225 isSupertypeOf(that) {226 if (that instanceof Def) {227 if (this.finalized !== true || that.finalized !== true) {228 throw new Error("");229 }230 return hasOwn$6.call(that.allSupertypes, this.typeName);231 } else {232 throw new Error(that + " is not a Def");233 }234 }235 checkAllFields(value, deep) {236 var allFields = this.allFields;237 if (this.finalized !== true) {238 throw new Error("" + this.typeName);239 }240 function checkFieldByName(name) {241 var field = allFields[name];242 var type = field.type;243 var child = field.getValue(value);244 return type.check(child, deep);245 }246 return value !== null && typeof value === "object" && Object.keys(allFields).every(checkFieldByName);247 }248 bases(...supertypeNames) {249 var bases = this.baseNames;250 if (this.finalized) {251 if (supertypeNames.length !== bases.length) {252 throw new Error("");253 }254 for (var i = 0; i < supertypeNames.length; i++) {255 if (supertypeNames[i] !== bases[i]) {256 throw new Error("");257 }258 }259 return this;260 }261 supertypeNames.forEach((baseName) => {262 if (bases.indexOf(baseName) < 0) {263 bases.push(baseName);264 }265 });266 return this;267 }268}269class Field {270 constructor(name, type, defaultFn, hidden) {271 this.name = name;272 this.type = type;273 this.defaultFn = defaultFn;274 __publicField$2(this, "hidden");275 this.hidden = !!hidden;276 }277 toString() {278 return JSON.stringify(this.name) + ": " + this.type;279 }280 getValue(obj) {281 var value = obj[this.name];282 if (typeof value !== "undefined") {283 return value;284 }285 if (typeof this.defaultFn === "function") {286 value = this.defaultFn.call(obj);287 }288 return value;289 }290}291function shallowStringify(value) {292 if (Array.isArray(value)) {293 return "[" + value.map(shallowStringify).join(", ") + "]";294 }295 if (value && typeof value === "object") {296 return "{ " + Object.keys(value).map(function(key) {297 return key + ": " + value[key];298 }).join(", ") + " }";299 }300 return JSON.stringify(value);301}302function typesPlugin(_fork) {303 const Type = {304 or(...types) {305 return new OrType(types.map((type) => Type.from(type)));306 },307 from(value, name) {308 if (value instanceof ArrayType || value instanceof IdentityType || value instanceof ObjectType || value instanceof OrType || value instanceof PredicateType) {309 return value;310 }311 if (value instanceof Def) {312 return value.type;313 }314 if (isArray.check(value)) {315 if (value.length !== 1) {316 throw new Error("only one element type is permitted for typed arrays");317 }318 return new ArrayType(Type.from(value[0]));319 }320 if (isObject.check(value)) {321 return new ObjectType(Object.keys(value).map((name2) => {322 return new Field(name2, Type.from(value[name2], name2));323 }));324 }325 if (typeof value === "function") {326 var bicfIndex = builtInCtorFns.indexOf(value);327 if (bicfIndex >= 0) {328 return builtInCtorTypes[bicfIndex];329 }330 if (typeof name !== "string") {331 throw new Error("missing name");332 }333 return new PredicateType(name, value);334 }335 return new IdentityType(value);336 },337 // Define a type whose name is registered in a namespace (the defCache) so338 // that future definitions will return the same type given the same name.339 // In particular, this system allows for circular and forward definitions.340 // The Def object d returned from Type.def may be used to configure the341 // type d.type by calling methods such as d.bases, d.build, and d.field.342 def(typeName) {343 return hasOwn$6.call(defCache, typeName) ? defCache[typeName] : defCache[typeName] = new DefImpl(typeName);344 },345 hasDef(typeName) {346 return hasOwn$6.call(defCache, typeName);347 }348 };349 var builtInCtorFns = [];350 var builtInCtorTypes = [];351 function defBuiltInType(name, example) {352 const objStr = objToStr.call(example);353 const type = new PredicateType(354 name,355 (value) => objToStr.call(value) === objStr356 );357 if (example && typeof example.constructor === "function") {358 builtInCtorFns.push(example.constructor);359 builtInCtorTypes.push(type);360 }361 return type;362 }363 const isString = defBuiltInType("string", "truthy");364 const isFunction = defBuiltInType("function", function() {365 });366 const isArray = defBuiltInType("array", []);367 const isObject = defBuiltInType("object", {});368 const isRegExp = defBuiltInType("RegExp", /./);369 const isDate = defBuiltInType("Date", /* @__PURE__ */ new Date());370 const isNumber = defBuiltInType("number", 3);371 const isBoolean = defBuiltInType("boolean", true);372 const isNull = defBuiltInType("null", null);373 const isUndefined = defBuiltInType("undefined", void 0);374 const isBigInt = typeof BigInt === "function" ? defBuiltInType("BigInt", BigInt(1234)) : new PredicateType("BigInt", () => false);375 const builtInTypes = {376 string: isString,377 function: isFunction,378 array: isArray,379 object: isObject,380 RegExp: isRegExp,381 Date: isDate,382 number: isNumber,383 boolean: isBoolean,384 null: isNull,385 undefined: isUndefined,386 BigInt: isBigInt387 };388 var defCache = /* @__PURE__ */ Object.create(null);389 function defFromValue(value) {390 if (value && typeof value === "object") {391 var type = value.type;392 if (typeof type === "string" && hasOwn$6.call(defCache, type)) {393 var d = defCache[type];394 if (d.finalized) {395 return d;396 }397 }398 }399 return null;400 }401 class DefImpl extends Def {402 constructor(typeName) {403 super(404 new PredicateType(typeName, (value, deep) => this.check(value, deep)),405 typeName406 );407 }408 check(value, deep) {409 if (this.finalized !== true) {410 throw new Error(411 "prematurely checking unfinalized type " + this.typeName412 );413 }414 if (value === null || typeof value !== "object") {415 return false;416 }417 var vDef = defFromValue(value);418 if (!vDef) {419 if (this.typeName === "SourceLocation" || this.typeName === "Position") {420 return this.checkAllFields(value, deep);421 }422 return false;423 }424 if (deep && vDef === this) {425 return this.checkAllFields(value, deep);426 }427 if (!this.isSupertypeOf(vDef)) {428 return false;429 }430 if (!deep) {431 return true;432 }433 return vDef.checkAllFields(value, deep) && this.checkAllFields(value, false);434 }435 build(...buildParams) {436 this.buildParams = buildParams;437 if (this.buildable) {438 return this;439 }440 this.field("type", String, () => this.typeName);441 this.buildable = true;442 const addParam = (built, param, arg, isArgAvailable) => {443 if (hasOwn$6.call(built, param))444 return;445 var all = this.allFields;446 if (!hasOwn$6.call(all, param)) {447 throw new Error("" + param);448 }449 var field = all[param];450 var type = field.type;451 var value;452 if (isArgAvailable) {453 value = arg;454 } else if (field.defaultFn) {455 value = field.defaultFn.call(built);456 } else {457 var message = "no value or default function given for field " + JSON.stringify(param) + " of " + this.typeName + "(" + this.buildParams.map(function(name) {458 return all[name];459 }).join(", ") + ")";460 throw new Error(message);461 }462 if (!type.check(value)) {463 throw new Error(464 shallowStringify(value) + " does not match field " + field + " of type " + this.typeName465 );466 }467 built[param] = value;468 };469 const builder = (...args) => {470 var argc = args.length;471 if (!this.finalized) {472 throw new Error(473 "attempting to instantiate unfinalized type " + this.typeName474 );475 }476 var built = Object.create(nodePrototype);477 this.buildParams.forEach(function(param, i) {478 if (i < argc) {479 addParam(built, param, args[i], true);480 } else {481 addParam(built, param, null, false);482 }483 });484 Object.keys(this.allFields).forEach(function(param) {485 addParam(built, param, null, false);486 });487 if (built.type !== this.typeName) {488 throw new Error("");489 }490 return built;491 };492 builder.from = (obj) => {493 if (!this.finalized) {494 throw new Error(495 "attempting to instantiate unfinalized type " + this.typeName496 );497 }498 var built = Object.create(nodePrototype);499 Object.keys(this.allFields).forEach(function(param) {500 if (hasOwn$6.call(obj, param)) {501 addParam(built, param, obj[param], true);502 } else {503 addParam(built, param, null, false);504 }505 });506 if (built.type !== this.typeName) {507 throw new Error("");508 }509 return built;510 };511 Object.defineProperty(builders, getBuilderName(this.typeName), {512 enumerable: true,513 value: builder514 });515 return this;516 }517 // The reason fields are specified using .field(...) instead of an object518 // literal syntax is somewhat subtle: the object literal syntax would519 // support only one key and one value, but with .field(...) we can pass520 // any number of arguments to specify the field.521 field(name, type, defaultFn, hidden) {522 if (this.finalized) {523 console.error("Ignoring attempt to redefine field " + JSON.stringify(name) + " of finalized type " + JSON.stringify(this.typeName));524 return this;525 }526 this.ownFields[name] = new Field(name, Type.from(type), defaultFn, hidden);527 return this;528 }529 finalize() {530 if (!this.finalized) {531 var allFields = this.allFields;532 var allSupertypes = this.allSupertypes;533 this.baseNames.forEach((name) => {534 var def = defCache[name];535 if (def instanceof Def) {536 def.finalize();537 extend(allFields, def.allFields);538 extend(allSupertypes, def.allSupertypes);539 } else {540 var message = "unknown supertype name " + JSON.stringify(name) + " for subtype " + JSON.stringify(this.typeName);541 throw new Error(message);542 }543 });544 extend(allFields, this.ownFields);545 allSupertypes[this.typeName] = this;546 this.fieldNames.length = 0;547 for (var fieldName in allFields) {548 if (hasOwn$6.call(allFields, fieldName) && !allFields[fieldName].hidden) {549 this.fieldNames.push(fieldName);550 }551 }552 Object.defineProperty(namedTypes, this.typeName, {553 enumerable: true,554 value: this.type555 });556 this.finalized = true;557 populateSupertypeList(this.typeName, this.supertypeList);558 if (this.buildable && this.supertypeList.lastIndexOf("Expression") >= 0) {559 wrapExpressionBuilderWithStatement(this.typeName);560 }561 }562 }563 }564 function getSupertypeNames(typeName) {565 if (!hasOwn$6.call(defCache, typeName)) {566 throw new Error("");567 }568 var d = defCache[typeName];569 if (d.finalized !== true) {570 throw new Error("");571 }572 return d.supertypeList.slice(1);573 }574 function computeSupertypeLookupTable(candidates) {575 var table = {};576 var typeNames = Object.keys(defCache);577 var typeNameCount = typeNames.length;578 for (var i = 0; i < typeNameCount; ++i) {579 var typeName = typeNames[i];580 var d = defCache[typeName];581 if (d.finalized !== true) {582 throw new Error("" + typeName);583 }584 for (var j = 0; j < d.supertypeList.length; ++j) {585 var superTypeName = d.supertypeList[j];586 if (hasOwn$6.call(candidates, superTypeName)) {587 table[typeName] = superTypeName;588 break;589 }590 }591 }592 return table;593 }594 var builders = /* @__PURE__ */ Object.create(null);595 var nodePrototype = {};596 function defineMethod(name, func) {597 var old = nodePrototype[name];598 if (isUndefined.check(func)) {599 delete nodePrototype[name];600 } else {601 isFunction.assert(func);602 Object.defineProperty(nodePrototype, name, {603 enumerable: true,604 // For discoverability.605 configurable: true,606 // For delete proto[name].607 value: func608 });609 }610 return old;611 }612 function getBuilderName(typeName) {613 return typeName.replace(/^[A-Z]+/, function(upperCasePrefix) {614 var len = upperCasePrefix.length;615 switch (len) {616 case 0:617 return "";618 case 1:619 return upperCasePrefix.toLowerCase();620 default:621 return upperCasePrefix.slice(622 0,623 len - 1624 ).toLowerCase() + upperCasePrefix.charAt(len - 1);625 }626 });627 }628 function getStatementBuilderName(typeName) {629 typeName = getBuilderName(typeName);630 return typeName.replace(/(Expression)?$/, "Statement");631 }632 var namedTypes = {};633 function getFieldNames(object) {634 var d = defFromValue(object);635 if (d) {636 return d.fieldNames.slice(0);637 }638 if ("type" in object) {639 throw new Error(640 "did not recognize object of type " + JSON.stringify(object.type)641 );642 }643 return Object.keys(object);644 }645 function getFieldValue(object, fieldName) {646 var d = defFromValue(object);647 if (d) {648 var field = d.allFields[fieldName];649 if (field) {650 return field.getValue(object);651 }652 }653 return object && object[fieldName];654 }655 function eachField(object, callback, context) {656 getFieldNames(object).forEach(function(name) {657 callback.call(this, name, getFieldValue(object, name));658 }, context);659 }660 function someField(object, callback, context) {661 return getFieldNames(object).some(function(name) {662 return callback.call(this, name, getFieldValue(object, name));663 }, context);664 }665 function wrapExpressionBuilderWithStatement(typeName) {666 var wrapperName = getStatementBuilderName(typeName);667 if (builders[wrapperName])668 return;669 var wrapped = builders[getBuilderName(typeName)];670 if (!wrapped)671 return;672 const builder = function(...args) {673 return builders.expressionStatement(wrapped.apply(builders, args));674 };675 builder.from = function(...args) {676 return builders.expressionStatement(wrapped.from.apply(builders, args));677 };678 builders[wrapperName] = builder;679 }680 function populateSupertypeList(typeName, list) {681 list.length = 0;682 list.push(typeName);683 var lastSeen = /* @__PURE__ */ Object.create(null);684 for (var pos = 0; pos < list.length; ++pos) {685 typeName = list[pos];686 var d = defCache[typeName];687 if (d.finalized !== true) {688 throw new Error("");689 }690 if (hasOwn$6.call(lastSeen, typeName)) {691 delete list[lastSeen[typeName]];692 }693 lastSeen[typeName] = pos;694 list.push.apply(list, d.baseNames);695 }696 for (var to = 0, from = to, len = list.length; from < len; ++from) {697 if (hasOwn$6.call(list, from)) {698 list[to++] = list[from];699 }700 }701 list.length = to;702 }703 function extend(into, from) {704 Object.keys(from).forEach(function(name) {705 into[name] = from[name];706 });707 return into;708 }709 function finalize() {710 Object.keys(defCache).forEach(function(name) {711 defCache[name].finalize();712 });713 }714 return {715 Type,716 builtInTypes,717 getSupertypeNames,718 computeSupertypeLookupTable,719 builders,720 defineMethod,721 getBuilderName,722 getStatementBuilderName,723 namedTypes,724 getFieldNames,725 getFieldValue,726 eachField,727 someField,728 finalize729 };730}731maybeSetModuleExports(() => module);732 733var Op = Object.prototype;734var hasOwn$5 = Op.hasOwnProperty;735function pathPlugin(fork) {736 var types = fork.use(typesPlugin);737 var isArray = types.builtInTypes.array;738 var isNumber = types.builtInTypes.number;739 const Path = function Path2(value, parentPath, name) {740 if (!(this instanceof Path2)) {741 throw new Error("Path constructor cannot be invoked without 'new'");742 }743 if (parentPath) {744 if (!(parentPath instanceof Path2)) {745 throw new Error("");746 }747 } else {748 parentPath = null;749 name = null;750 }751 this.value = value;752 this.parentPath = parentPath;753 this.name = name;754 this.__childCache = null;755 };756 var Pp = Path.prototype;757 function getChildCache(path) {758 return path.__childCache || (path.__childCache = /* @__PURE__ */ Object.create(null));759 }760 function getChildPath(path, name) {761 var cache = getChildCache(path);762 var actualChildValue = path.getValueProperty(name);763 var childPath = cache[name];764 if (!hasOwn$5.call(cache, name) || // Ensure consistency between cache and reality.765 childPath.value !== actualChildValue) {766 childPath = cache[name] = new path.constructor(767 actualChildValue,768 path,769 name770 );771 }772 return childPath;773 }774 Pp.getValueProperty = function getValueProperty(name) {775 return this.value[name];776 };777 Pp.get = function get(...names) {778 var path = this;779 var count = names.length;780 for (var i = 0; i < count; ++i) {781 path = getChildPath(path, names[i]);782 }783 return path;784 };785 Pp.each = function each(callback, context) {786 var childPaths = [];787 var len = this.value.length;788 var i = 0;789 for (var i = 0; i < len; ++i) {790 if (hasOwn$5.call(this.value, i)) {791 childPaths[i] = this.get(i);792 }793 }794 context = context || this;795 for (i = 0; i < len; ++i) {796 if (hasOwn$5.call(childPaths, i)) {797 callback.call(context, childPaths[i]);798 }799 }800 };801 Pp.map = function map(callback, context) {802 var result = [];803 this.each(function(childPath) {804 result.push(callback.call(this, childPath));805 }, context);806 return result;807 };808 Pp.filter = function filter(callback, context) {809 var result = [];810 this.each(function(childPath) {811 if (callback.call(this, childPath)) {812 result.push(childPath);813 }814 }, context);815 return result;816 };817 function emptyMoves() {818 }819 function getMoves(path, offset, start, end) {820 isArray.assert(path.value);821 if (offset === 0) {822 return emptyMoves;823 }824 var length = path.value.length;825 if (length < 1) {826 return emptyMoves;827 }828 var argc = arguments.length;829 if (argc === 2) {830 start = 0;831 end = length;832 } else if (argc === 3) {833 start = Math.max(start, 0);834 end = length;835 } else {836 start = Math.max(start, 0);837 end = Math.min(end, length);838 }839 isNumber.assert(start);840 isNumber.assert(end);841 var moves = /* @__PURE__ */ Object.create(null);842 var cache = getChildCache(path);843 for (var i = start; i < end; ++i) {844 if (hasOwn$5.call(path.value, i)) {845 var childPath = path.get(i);846 if (childPath.name !== i) {847 throw new Error("");848 }849 var newIndex = i + offset;850 childPath.name = newIndex;851 moves[newIndex] = childPath;852 delete cache[i];853 }854 }855 delete cache.length;856 return function() {857 for (var newIndex2 in moves) {858 var childPath2 = moves[newIndex2];859 if (childPath2.name !== +newIndex2) {860 throw new Error("");861 }862 cache[newIndex2] = childPath2;863 path.value[newIndex2] = childPath2.value;864 }865 };866 }867 Pp.shift = function shift() {868 var move = getMoves(this, -1);869 var result = this.value.shift();870 move();871 return result;872 };873 Pp.unshift = function unshift(...args) {874 var move = getMoves(this, args.length);875 var result = this.value.unshift.apply(this.value, args);876 move();877 return result;878 };879 Pp.push = function push(...args) {880 isArray.assert(this.value);881 delete getChildCache(this).length;882 return this.value.push.apply(this.value, args);883 };884 Pp.pop = function pop() {885 isArray.assert(this.value);886 var cache = getChildCache(this);887 delete cache[this.value.length - 1];888 delete cache.length;889 return this.value.pop();890 };891 Pp.insertAt = function insertAt(index) {892 var argc = arguments.length;893 var move = getMoves(this, argc - 1, index);894 if (move === emptyMoves && argc <= 1) {895 return this;896 }897 index = Math.max(index, 0);898 for (var i = 1; i < argc; ++i) {899 this.value[index + i - 1] = arguments[i];900 }901 move();902 return this;903 };904 Pp.insertBefore = function insertBefore(...args) {905 var pp = this.parentPath;906 var argc = args.length;907 var insertAtArgs = [this.name];908 for (var i = 0; i < argc; ++i) {909 insertAtArgs.push(args[i]);910 }911 return pp.insertAt.apply(pp, insertAtArgs);912 };913 Pp.insertAfter = function insertAfter(...args) {914 var pp = this.parentPath;915 var argc = args.length;916 var insertAtArgs = [this.name + 1];917 for (var i = 0; i < argc; ++i) {918 insertAtArgs.push(args[i]);919 }920 return pp.insertAt.apply(pp, insertAtArgs);921 };922 function repairRelationshipWithParent(path) {923 if (!(path instanceof Path)) {924 throw new Error("");925 }926 var pp = path.parentPath;927 if (!pp) {928 return path;929 }930 var parentValue = pp.value;931 var parentCache = getChildCache(pp);932 if (parentValue[path.name] === path.value) {933 parentCache[path.name] = path;934 } else if (isArray.check(parentValue)) {935 var i = parentValue.indexOf(path.value);936 if (i >= 0) {937 parentCache[path.name = i] = path;938 }939 } else {940 parentValue[path.name] = path.value;941 parentCache[path.name] = path;942 }943 if (parentValue[path.name] !== path.value) {944 throw new Error("");945 }946 if (path.parentPath.get(path.name) !== path) {947 throw new Error("");948 }949 return path;950 }951 Pp.replace = function replace(replacement) {952 var results = [];953 var parentValue = this.parentPath.value;954 var parentCache = getChildCache(this.parentPath);955 var count = arguments.length;956 repairRelationshipWithParent(this);957 if (isArray.check(parentValue)) {958 var originalLength = parentValue.length;959 var move = getMoves(this.parentPath, count - 1, this.name + 1);960 var spliceArgs = [this.name, 1];961 for (var i = 0; i < count; ++i) {962 spliceArgs.push(arguments[i]);963 }964 var splicedOut = parentValue.splice.apply(parentValue, spliceArgs);965 if (splicedOut[0] !== this.value) {966 throw new Error("");967 }968 if (parentValue.length !== originalLength - 1 + count) {969 throw new Error("");970 }971 move();972 if (count === 0) {973 delete this.value;974 delete parentCache[this.name];975 this.__childCache = null;976 } else {977 if (parentValue[this.name] !== replacement) {978 throw new Error("");979 }980 if (this.value !== replacement) {981 this.value = replacement;982 this.__childCache = null;983 }984 for (i = 0; i < count; ++i) {985 results.push(this.parentPath.get(this.name + i));986 }987 if (results[0] !== this) {988 throw new Error("");989 }990 }991 } else if (count === 1) {992 if (this.value !== replacement) {993 this.__childCache = null;994 }995 this.value = parentValue[this.name] = replacement;996 results.push(this);997 } else if (count === 0) {998 delete parentValue[this.name];999 delete this.value;1000 this.__childCache = null;1001 } else {1002 throw new Error("Could not replace path");1003 }1004 return results;1005 };1006 return Path;1007}1008maybeSetModuleExports(() => module);1009 1010var hasOwn$4 = Object.prototype.hasOwnProperty;1011function scopePlugin(fork) {1012 var types = fork.use(typesPlugin);1013 var Type = types.Type;1014 var namedTypes = types.namedTypes;1015 var Node = namedTypes.Node;1016 var Expression = namedTypes.Expression;1017 var isArray = types.builtInTypes.array;1018 var b = types.builders;1019 const Scope = function Scope2(path, parentScope) {1020 if (!(this instanceof Scope2)) {1021 throw new Error("Scope constructor cannot be invoked without 'new'");1022 }1023 if (!TypeParameterScopeType.check(path.value)) {1024 ScopeType.assert(path.value);1025 }1026 var depth;1027 if (parentScope) {1028 if (!(parentScope instanceof Scope2)) {1029 throw new Error("");1030 }1031 depth = parentScope.depth + 1;1032 } else {1033 parentScope = null;1034 depth = 0;1035 }1036 Object.defineProperties(this, {1037 path: { value: path },1038 node: { value: path.value },1039 isGlobal: { value: !parentScope, enumerable: true },1040 depth: { value: depth },1041 parent: { value: parentScope },1042 bindings: { value: {} },1043 types: { value: {} }1044 });1045 };1046 var ScopeType = Type.or(1047 // Program nodes introduce global scopes.1048 namedTypes.Program,1049 // Function is the supertype of FunctionExpression,1050 // FunctionDeclaration, ArrowExpression, etc.1051 namedTypes.Function,1052 // In case you didn't know, the caught parameter shadows any variable1053 // of the same name in an outer scope.1054 namedTypes.CatchClause1055 );1056 var TypeParameterScopeType = Type.or(1057 namedTypes.Function,1058 namedTypes.ClassDeclaration,1059 namedTypes.ClassExpression,1060 namedTypes.InterfaceDeclaration,1061 namedTypes.TSInterfaceDeclaration,1062 namedTypes.TypeAlias,1063 namedTypes.TSTypeAliasDeclaration1064 );1065 var FlowOrTSTypeParameterType = Type.or(1066 namedTypes.TypeParameter,1067 namedTypes.TSTypeParameter1068 );1069 Scope.isEstablishedBy = function(node) {1070 return ScopeType.check(node) || TypeParameterScopeType.check(node);1071 };1072 var Sp = Scope.prototype;1073 Sp.didScan = false;1074 Sp.declares = function(name) {1075 this.scan();1076 return hasOwn$4.call(this.bindings, name);1077 };1078 Sp.declaresType = function(name) {1079 this.scan();1080 return hasOwn$4.call(this.types, name);1081 };1082 Sp.declareTemporary = function(prefix) {1083 if (prefix) {1084 if (!/^[a-z$_]/i.test(prefix)) {1085 throw new Error("");1086 }1087 } else {1088 prefix = "t$";1089 }1090 prefix += this.depth.toString(36) + "$";1091 this.scan();1092 var index = 0;1093 while (this.declares(prefix + index)) {1094 ++index;1095 }1096 var name = prefix + index;1097 return this.bindings[name] = types.builders.identifier(name);1098 };1099 Sp.injectTemporary = function(identifier, init) {1100 identifier || (identifier = this.declareTemporary());1101 var bodyPath = this.path.get("body");1102 if (namedTypes.BlockStatement.check(bodyPath.value)) {1103 bodyPath = bodyPath.get("body");1104 }1105 bodyPath.unshift(1106 b.variableDeclaration(1107 "var",1108 [b.variableDeclarator(identifier, init || null)]1109 )1110 );1111 return identifier;1112 };1113 Sp.scan = function(force) {1114 if (force || !this.didScan) {1115 for (var name in this.bindings) {1116 delete this.bindings[name];1117 }1118 for (var name in this.types) {1119 delete this.types[name];1120 }1121 scanScope(this.path, this.bindings, this.types);1122 this.didScan = true;1123 }1124 };1125 Sp.getBindings = function() {1126 this.scan();1127 return this.bindings;1128 };1129 Sp.getTypes = function() {1130 this.scan();1131 return this.types;1132 };1133 function scanScope(path, bindings, scopeTypes) {1134 var node = path.value;1135 if (TypeParameterScopeType.check(node)) {1136 const params = path.get("typeParameters", "params");1137 if (isArray.check(params.value)) {1138 params.each((childPath) => {1139 addTypeParameter(childPath, scopeTypes);1140 });1141 }1142 }1143 if (ScopeType.check(node)) {1144 if (namedTypes.CatchClause.check(node)) {1145 addPattern(path.get("param"), bindings);1146 } else {1147 recursiveScanScope(path, bindings, scopeTypes);1148 }1149 }1150 }1151 function recursiveScanScope(path, bindings, scopeTypes) {1152 var node = path.value;1153 if (path.parent && namedTypes.FunctionExpression.check(path.parent.node) && path.parent.node.id) {1154 addPattern(path.parent.get("id"), bindings);1155 }1156 if (!node) ; else if (isArray.check(node)) {1157 path.each((childPath) => {1158 recursiveScanChild(childPath, bindings, scopeTypes);1159 });1160 } else if (namedTypes.Function.check(node)) {1161 path.get("params").each((paramPath) => {1162 addPattern(paramPath, bindings);1163 });1164 recursiveScanChild(path.get("body"), bindings, scopeTypes);1165 recursiveScanScope(path.get("typeParameters"), bindings, scopeTypes);1166 } else if (namedTypes.TypeAlias && namedTypes.TypeAlias.check(node) || namedTypes.InterfaceDeclaration && namedTypes.InterfaceDeclaration.check(node) || namedTypes.TSTypeAliasDeclaration && namedTypes.TSTypeAliasDeclaration.check(node) || namedTypes.TSInterfaceDeclaration && namedTypes.TSInterfaceDeclaration.check(node)) {1167 addTypePattern(path.get("id"), scopeTypes);1168 } else if (namedTypes.VariableDeclarator.check(node)) {1169 addPattern(path.get("id"), bindings);1170 recursiveScanChild(path.get("init"), bindings, scopeTypes);1171 } else if (node.type === "ImportSpecifier" || node.type === "ImportNamespaceSpecifier" || node.type === "ImportDefaultSpecifier") {1172 addPattern(1173 // Esprima used to use the .name field to refer to the local1174 // binding identifier for ImportSpecifier nodes, but .id for1175 // ImportNamespaceSpecifier and ImportDefaultSpecifier nodes.1176 // ESTree/Acorn/ESpree use .local for all three node types.1177 path.get(node.local ? "local" : node.name ? "name" : "id"),1178 bindings1179 );1180 } else if (Node.check(node) && !Expression.check(node)) {1181 types.eachField(node, function(name, child) {1182 var childPath = path.get(name);1183 if (!pathHasValue(childPath, child)) {1184 throw new Error("");1185 }1186 recursiveScanChild(childPath, bindings, scopeTypes);1187 });1188 }1189 }1190 function pathHasValue(path, value) {1191 if (path.value === value) {1192 return true;1193 }1194 if (Array.isArray(path.value) && path.value.length === 0 && Array.isArray(value) && value.length === 0) {1195 return true;1196 }1197 return false;1198 }1199 function recursiveScanChild(path, bindings, scopeTypes) {1200 var node = path.value;