UNPKG

@umijs/deps

Version:
1,747 lines (1,444 loc) 4.82 MB
module.exports = /******/ (function() { // webpackBootstrap /******/ var __webpack_modules__ = ({ /***/ 7560: /***/ (function(__unused_webpack_module, exports, __webpack_require__) { "use strict"; Object.defineProperty(exports, "__esModule", ({ value: true })); exports.codeFrameFromAst = codeFrameFromAst; exports.codeFrameFromSource = codeFrameFromSource; var _wastPrinter = __webpack_require__(90217); function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } var SHOW_LINES_AROUND_POINTER = 5; function repeat(char, nb) { return Array(nb).fill(char).join(""); } // TODO(sven): allow arbitrary ast nodes function codeFrameFromAst(ast, loc) { return codeFrameFromSource((0, _wastPrinter.print)(ast), loc); } function codeFrameFromSource(source, loc) { var start = loc.start, end = loc.end; var length = 1; if (_typeof(end) === "object") { length = end.column - start.column + 1; } return source.split("\n").reduce(function (acc, line, lineNbr) { if (Math.abs(start.line - lineNbr) < SHOW_LINES_AROUND_POINTER) { acc += line + "\n"; } // Add a new line with the pointer padded left if (lineNbr === start.line - 1) { acc += repeat(" ", start.column - 1); acc += repeat("^", length); acc += "\n"; } return acc; }, ""); } /***/ }), /***/ 77691: /***/ (function(__unused_webpack_module, exports) { "use strict"; Object.defineProperty(exports, "__esModule", ({ value: true })); exports.makeTransition = makeTransition; exports.FSM = void 0; function _sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } function _slicedToArray(arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return _sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } var STOP = Symbol("STOP"); function makeTransition(regex, nextState) { var _ref = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}, _ref$n = _ref.n, n = _ref$n === void 0 ? 1 : _ref$n, allowedSeparator = _ref.allowedSeparator; return function (instance) { if (allowedSeparator) { if (instance.input[instance.ptr] === allowedSeparator) { if (regex.test(instance.input.substring(instance.ptr - 1, instance.ptr))) { // Consume the separator and stay in current state return [instance.currentState, 1]; } else { return [instance.terminatingState, 0]; } } } if (regex.test(instance.input.substring(instance.ptr, instance.ptr + n))) { return [nextState, n]; } return false; }; } function combineTransitions(transitions) { return function () { var match = false; var currentTransitions = transitions[this.currentState] || []; for (var i = 0; i < currentTransitions.length; ++i) { match = currentTransitions[i](this); if (match !== false) { break; } } return match || [this.terminatingState, 0]; }; } var FSM = /*#__PURE__*/ function () { function FSM(transitions, initialState) { var terminatingState = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : STOP; _classCallCheck(this, FSM); this.initialState = initialState; this.terminatingState = terminatingState; if (terminatingState === STOP || !transitions[terminatingState]) { transitions[terminatingState] = []; } this.transitionFunction = combineTransitions.call(this, transitions); } _createClass(FSM, [{ key: "run", value: function run(input) { this.input = input; this.ptr = 0; this.currentState = this.initialState; var value = ""; var eatLength, nextState; while (this.currentState !== this.terminatingState && this.ptr < this.input.length) { var _transitionFunction = this.transitionFunction(); var _transitionFunction2 = _slicedToArray(_transitionFunction, 2); nextState = _transitionFunction2[0]; eatLength = _transitionFunction2[1]; value += this.input.substring(this.ptr, this.ptr += eatLength); this.currentState = nextState; } return value; } }]); return FSM; }(); exports.FSM = FSM; /***/ }), /***/ 62556: /***/ (function(__unused_webpack_module, exports, __webpack_require__) { "use strict"; Object.defineProperty(exports, "__esModule", ({ value: true })); exports.moduleContextFromModuleAST = moduleContextFromModuleAST; exports.ModuleContext = void 0; var _ast = __webpack_require__(53357); function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } function moduleContextFromModuleAST(m) { var moduleContext = new ModuleContext(); if (!(m.type === "Module")) { throw new Error('m.type === "Module"' + " error: " + (undefined || "unknown")); } m.fields.forEach(function (field) { switch (field.type) { case "Start": { moduleContext.setStart(field.index); break; } case "TypeInstruction": { moduleContext.addType(field); break; } case "Func": { moduleContext.addFunction(field); break; } case "Global": { moduleContext.defineGlobal(field); break; } case "ModuleImport": { switch (field.descr.type) { case "GlobalType": { moduleContext.importGlobal(field.descr.valtype, field.descr.mutability); break; } case "Memory": { moduleContext.addMemory(field.descr.limits.min, field.descr.limits.max); break; } case "FuncImportDescr": { moduleContext.importFunction(field.descr); break; } case "Table": { // FIXME(sven): not implemented yet break; } default: throw new Error("Unsupported ModuleImport of type " + JSON.stringify(field.descr.type)); } break; } case "Memory": { moduleContext.addMemory(field.limits.min, field.limits.max); break; } } }); return moduleContext; } /** * Module context for type checking */ var ModuleContext = /*#__PURE__*/ function () { function ModuleContext() { _classCallCheck(this, ModuleContext); this.funcs = []; this.funcsOffsetByIdentifier = []; this.types = []; this.globals = []; this.globalsOffsetByIdentifier = []; this.mems = []; // Current stack frame this.locals = []; this.labels = []; this.return = []; this.debugName = "unknown"; this.start = null; } /** * Set start segment */ _createClass(ModuleContext, [{ key: "setStart", value: function setStart(index) { this.start = index.value; } /** * Get start function */ }, { key: "getStart", value: function getStart() { return this.start; } /** * Reset the active stack frame */ }, { key: "newContext", value: function newContext(debugName, expectedResult) { this.locals = []; this.labels = [expectedResult]; this.return = expectedResult; this.debugName = debugName; } /** * Functions */ }, { key: "addFunction", value: function addFunction(func /*: Func*/ ) { // eslint-disable-next-line prefer-const var _ref = func.signature || {}, _ref$params = _ref.params, args = _ref$params === void 0 ? [] : _ref$params, _ref$results = _ref.results, result = _ref$results === void 0 ? [] : _ref$results; args = args.map(function (arg) { return arg.valtype; }); this.funcs.push({ args: args, result: result }); if (typeof func.name !== "undefined") { this.funcsOffsetByIdentifier[func.name.value] = this.funcs.length - 1; } } }, { key: "importFunction", value: function importFunction(funcimport) { if ((0, _ast.isSignature)(funcimport.signature)) { // eslint-disable-next-line prefer-const var _funcimport$signature = funcimport.signature, args = _funcimport$signature.params, result = _funcimport$signature.results; args = args.map(function (arg) { return arg.valtype; }); this.funcs.push({ args: args, result: result }); } else { if (!(0, _ast.isNumberLiteral)(funcimport.signature)) { throw new Error('isNumberLiteral(funcimport.signature)' + " error: " + (undefined || "unknown")); } var typeId = funcimport.signature.value; if (!this.hasType(typeId)) { throw new Error('this.hasType(typeId)' + " error: " + (undefined || "unknown")); } var signature = this.getType(typeId); this.funcs.push({ args: signature.params.map(function (arg) { return arg.valtype; }), result: signature.results }); } if (typeof funcimport.id !== "undefined") { // imports are first, we can assume their index in the array this.funcsOffsetByIdentifier[funcimport.id.value] = this.funcs.length - 1; } } }, { key: "hasFunction", value: function hasFunction(index) { return typeof this.getFunction(index) !== "undefined"; } }, { key: "getFunction", value: function getFunction(index) { if (typeof index !== "number") { throw new Error("getFunction only supported for number index"); } return this.funcs[index]; } }, { key: "getFunctionOffsetByIdentifier", value: function getFunctionOffsetByIdentifier(name) { if (!(typeof name === "string")) { throw new Error('typeof name === "string"' + " error: " + (undefined || "unknown")); } return this.funcsOffsetByIdentifier[name]; } /** * Labels */ }, { key: "addLabel", value: function addLabel(result) { this.labels.unshift(result); } }, { key: "hasLabel", value: function hasLabel(index) { return this.labels.length > index && index >= 0; } }, { key: "getLabel", value: function getLabel(index) { return this.labels[index]; } }, { key: "popLabel", value: function popLabel() { this.labels.shift(); } /** * Locals */ }, { key: "hasLocal", value: function hasLocal(index) { return typeof this.getLocal(index) !== "undefined"; } }, { key: "getLocal", value: function getLocal(index) { return this.locals[index]; } }, { key: "addLocal", value: function addLocal(type) { this.locals.push(type); } /** * Types */ }, { key: "addType", value: function addType(type) { if (!(type.functype.type === "Signature")) { throw new Error('type.functype.type === "Signature"' + " error: " + (undefined || "unknown")); } this.types.push(type.functype); } }, { key: "hasType", value: function hasType(index) { return this.types[index] !== undefined; } }, { key: "getType", value: function getType(index) { return this.types[index]; } /** * Globals */ }, { key: "hasGlobal", value: function hasGlobal(index) { return this.globals.length > index && index >= 0; } }, { key: "getGlobal", value: function getGlobal(index) { return this.globals[index].type; } }, { key: "getGlobalOffsetByIdentifier", value: function getGlobalOffsetByIdentifier(name) { if (!(typeof name === "string")) { throw new Error('typeof name === "string"' + " error: " + (undefined || "unknown")); } return this.globalsOffsetByIdentifier[name]; } }, { key: "defineGlobal", value: function defineGlobal(global /*: Global*/ ) { var type = global.globalType.valtype; var mutability = global.globalType.mutability; this.globals.push({ type: type, mutability: mutability }); if (typeof global.name !== "undefined") { this.globalsOffsetByIdentifier[global.name.value] = this.globals.length - 1; } } }, { key: "importGlobal", value: function importGlobal(type, mutability) { this.globals.push({ type: type, mutability: mutability }); } }, { key: "isMutableGlobal", value: function isMutableGlobal(index) { return this.globals[index].mutability === "var"; } }, { key: "isImmutableGlobal", value: function isImmutableGlobal(index) { return this.globals[index].mutability === "const"; } /** * Memories */ }, { key: "hasMemory", value: function hasMemory(index) { return this.mems.length > index && index >= 0; } }, { key: "addMemory", value: function addMemory(min, max) { this.mems.push({ min: min, max: max }); } }, { key: "getMemory", value: function getMemory(index) { return this.mems[index]; } }]); return ModuleContext; }(); exports.ModuleContext = ModuleContext; /***/ }), /***/ 81843: /***/ (function(__unused_webpack_module, exports) { "use strict"; Object.defineProperty(exports, "__esModule", ({ value: true })); exports.cloneNode = cloneNode; function cloneNode(n) { // $FlowIgnore var newObj = {}; for (var k in n) { newObj[k] = n[k]; } return newObj; } /***/ }), /***/ 53357: /***/ (function(__unused_webpack_module, exports, __webpack_require__) { "use strict"; Object.defineProperty(exports, "__esModule", ({ value: true })); var _exportNames = { numberLiteralFromRaw: true, withLoc: true, withRaw: true, funcParam: true, indexLiteral: true, memIndexLiteral: true, instruction: true, objectInstruction: true, traverse: true, signatures: true, cloneNode: true }; Object.defineProperty(exports, "numberLiteralFromRaw", ({ enumerable: true, get: function get() { return _nodeHelpers.numberLiteralFromRaw; } })); Object.defineProperty(exports, "withLoc", ({ enumerable: true, get: function get() { return _nodeHelpers.withLoc; } })); Object.defineProperty(exports, "withRaw", ({ enumerable: true, get: function get() { return _nodeHelpers.withRaw; } })); Object.defineProperty(exports, "funcParam", ({ enumerable: true, get: function get() { return _nodeHelpers.funcParam; } })); Object.defineProperty(exports, "indexLiteral", ({ enumerable: true, get: function get() { return _nodeHelpers.indexLiteral; } })); Object.defineProperty(exports, "memIndexLiteral", ({ enumerable: true, get: function get() { return _nodeHelpers.memIndexLiteral; } })); Object.defineProperty(exports, "instruction", ({ enumerable: true, get: function get() { return _nodeHelpers.instruction; } })); Object.defineProperty(exports, "objectInstruction", ({ enumerable: true, get: function get() { return _nodeHelpers.objectInstruction; } })); Object.defineProperty(exports, "traverse", ({ enumerable: true, get: function get() { return _traverse.traverse; } })); Object.defineProperty(exports, "signatures", ({ enumerable: true, get: function get() { return _signatures.signatures; } })); Object.defineProperty(exports, "cloneNode", ({ enumerable: true, get: function get() { return _clone.cloneNode; } })); var _nodes = __webpack_require__(78168); Object.keys(_nodes).forEach(function (key) { if (key === "default" || key === "__esModule") return; if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return; Object.defineProperty(exports, key, { enumerable: true, get: function get() { return _nodes[key]; } }); }); var _nodeHelpers = __webpack_require__(76601); var _traverse = __webpack_require__(7353); var _signatures = __webpack_require__(79649); var _utils = __webpack_require__(84395); Object.keys(_utils).forEach(function (key) { if (key === "default" || key === "__esModule") return; if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return; Object.defineProperty(exports, key, { enumerable: true, get: function get() { return _utils[key]; } }); }); var _clone = __webpack_require__(81843); /***/ }), /***/ 76601: /***/ (function(__unused_webpack_module, exports, __webpack_require__) { "use strict"; Object.defineProperty(exports, "__esModule", ({ value: true })); exports.numberLiteralFromRaw = numberLiteralFromRaw; exports.instruction = instruction; exports.objectInstruction = objectInstruction; exports.withLoc = withLoc; exports.withRaw = withRaw; exports.funcParam = funcParam; exports.indexLiteral = indexLiteral; exports.memIndexLiteral = memIndexLiteral; var _wastParser = __webpack_require__(78532); var _nodes = __webpack_require__(78168); function numberLiteralFromRaw(rawValue) { var instructionType = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "i32"; var original = rawValue; // Remove numeric separators _ if (typeof rawValue === "string") { rawValue = rawValue.replace(/_/g, ""); } if (typeof rawValue === "number") { return (0, _nodes.numberLiteral)(rawValue, String(original)); } else { switch (instructionType) { case "i32": { return (0, _nodes.numberLiteral)((0, _wastParser.parse32I)(rawValue), String(original)); } case "u32": { return (0, _nodes.numberLiteral)((0, _wastParser.parseU32)(rawValue), String(original)); } case "i64": { return (0, _nodes.longNumberLiteral)((0, _wastParser.parse64I)(rawValue), String(original)); } case "f32": { return (0, _nodes.floatLiteral)((0, _wastParser.parse32F)(rawValue), (0, _wastParser.isNanLiteral)(rawValue), (0, _wastParser.isInfLiteral)(rawValue), String(original)); } // f64 default: { return (0, _nodes.floatLiteral)((0, _wastParser.parse64F)(rawValue), (0, _wastParser.isNanLiteral)(rawValue), (0, _wastParser.isInfLiteral)(rawValue), String(original)); } } } } function instruction(id) { var args = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : []; var namedArgs = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; return (0, _nodes.instr)(id, undefined, args, namedArgs); } function objectInstruction(id, object) { var args = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : []; var namedArgs = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {}; return (0, _nodes.instr)(id, object, args, namedArgs); } /** * Decorators */ function withLoc(n, end, start) { var loc = { start: start, end: end }; n.loc = loc; return n; } function withRaw(n, raw) { n.raw = raw; return n; } function funcParam(valtype, id) { return { id: id, valtype: valtype }; } function indexLiteral(value) { // $FlowIgnore var x = numberLiteralFromRaw(value, "u32"); return x; } function memIndexLiteral(value) { // $FlowIgnore var x = numberLiteralFromRaw(value, "u32"); return x; } /***/ }), /***/ 38420: /***/ (function(__unused_webpack_module, exports) { "use strict"; Object.defineProperty(exports, "__esModule", ({ value: true })); exports.createPath = createPath; function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } function findParent(_ref, cb) { var parentPath = _ref.parentPath; if (parentPath == null) { throw new Error("node is root"); } var currentPath = parentPath; while (cb(currentPath) !== false) { // Hit the root node, stop // $FlowIgnore if (currentPath.parentPath == null) { return null; } // $FlowIgnore currentPath = currentPath.parentPath; } return currentPath.node; } function insertBefore(context, newNode) { return insert(context, newNode); } function insertAfter(context, newNode) { return insert(context, newNode, 1); } function insert(_ref2, newNode) { var node = _ref2.node, inList = _ref2.inList, parentPath = _ref2.parentPath, parentKey = _ref2.parentKey; var indexOffset = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0; if (!inList) { throw new Error('inList' + " error: " + ("insert can only be used for nodes that are within lists" || 0)); } if (!(parentPath != null)) { throw new Error('parentPath != null' + " error: " + ("Can not remove root node" || 0)); } // $FlowIgnore var parentList = parentPath.node[parentKey]; var indexInList = parentList.findIndex(function (n) { return n === node; }); parentList.splice(indexInList + indexOffset, 0, newNode); } function remove(_ref3) { var node = _ref3.node, parentKey = _ref3.parentKey, parentPath = _ref3.parentPath; if (!(parentPath != null)) { throw new Error('parentPath != null' + " error: " + ("Can not remove root node" || 0)); } // $FlowIgnore var parentNode = parentPath.node; // $FlowIgnore var parentProperty = parentNode[parentKey]; if (Array.isArray(parentProperty)) { // $FlowIgnore parentNode[parentKey] = parentProperty.filter(function (n) { return n !== node; }); } else { // $FlowIgnore delete parentNode[parentKey]; } node._deleted = true; } function stop(context) { context.shouldStop = true; } function replaceWith(context, newNode) { // $FlowIgnore var parentNode = context.parentPath.node; // $FlowIgnore var parentProperty = parentNode[context.parentKey]; if (Array.isArray(parentProperty)) { var indexInList = parentProperty.findIndex(function (n) { return n === context.node; }); parentProperty.splice(indexInList, 1, newNode); } else { // $FlowIgnore parentNode[context.parentKey] = newNode; } context.node._deleted = true; context.node = newNode; } // bind the context to the first argument of node operations function bindNodeOperations(operations, context) { var keys = Object.keys(operations); var boundOperations = {}; keys.forEach(function (key) { boundOperations[key] = operations[key].bind(null, context); }); return boundOperations; } function createPathOperations(context) { // $FlowIgnore return bindNodeOperations({ findParent: findParent, replaceWith: replaceWith, remove: remove, insertBefore: insertBefore, insertAfter: insertAfter, stop: stop }, context); } function createPath(context) { var path = _extends({}, context); // $FlowIgnore Object.assign(path, createPathOperations(path)); // $FlowIgnore return path; } /***/ }), /***/ 78168: /***/ (function(__unused_webpack_module, exports) { "use strict"; Object.defineProperty(exports, "__esModule", ({ value: true })); exports.module = _module; exports.moduleMetadata = moduleMetadata; exports.moduleNameMetadata = moduleNameMetadata; exports.functionNameMetadata = functionNameMetadata; exports.localNameMetadata = localNameMetadata; exports.binaryModule = binaryModule; exports.quoteModule = quoteModule; exports.sectionMetadata = sectionMetadata; exports.producersSectionMetadata = producersSectionMetadata; exports.producerMetadata = producerMetadata; exports.producerMetadataVersionedName = producerMetadataVersionedName; exports.loopInstruction = loopInstruction; exports.instr = instr; exports.ifInstruction = ifInstruction; exports.stringLiteral = stringLiteral; exports.numberLiteral = numberLiteral; exports.longNumberLiteral = longNumberLiteral; exports.floatLiteral = floatLiteral; exports.elem = elem; exports.indexInFuncSection = indexInFuncSection; exports.valtypeLiteral = valtypeLiteral; exports.typeInstruction = typeInstruction; exports.start = start; exports.globalType = globalType; exports.leadingComment = leadingComment; exports.blockComment = blockComment; exports.data = data; exports.global = global; exports.table = table; exports.memory = memory; exports.funcImportDescr = funcImportDescr; exports.moduleImport = moduleImport; exports.moduleExportDescr = moduleExportDescr; exports.moduleExport = moduleExport; exports.limit = limit; exports.signature = signature; exports.program = program; exports.identifier = identifier; exports.blockInstruction = blockInstruction; exports.callInstruction = callInstruction; exports.callIndirectInstruction = callIndirectInstruction; exports.byteArray = byteArray; exports.func = func; exports.internalBrUnless = internalBrUnless; exports.internalGoto = internalGoto; exports.internalCallExtern = internalCallExtern; exports.internalEndAndReturn = internalEndAndReturn; exports.assertInternalCallExtern = exports.assertInternalGoto = exports.assertInternalBrUnless = exports.assertFunc = exports.assertByteArray = exports.assertCallIndirectInstruction = exports.assertCallInstruction = exports.assertBlockInstruction = exports.assertIdentifier = exports.assertProgram = exports.assertSignature = exports.assertLimit = exports.assertModuleExport = exports.assertModuleExportDescr = exports.assertModuleImport = exports.assertFuncImportDescr = exports.assertMemory = exports.assertTable = exports.assertGlobal = exports.assertData = exports.assertBlockComment = exports.assertLeadingComment = exports.assertGlobalType = exports.assertStart = exports.assertTypeInstruction = exports.assertValtypeLiteral = exports.assertIndexInFuncSection = exports.assertElem = exports.assertFloatLiteral = exports.assertLongNumberLiteral = exports.assertNumberLiteral = exports.assertStringLiteral = exports.assertIfInstruction = exports.assertInstr = exports.assertLoopInstruction = exports.assertProducerMetadataVersionedName = exports.assertProducerMetadata = exports.assertProducersSectionMetadata = exports.assertSectionMetadata = exports.assertQuoteModule = exports.assertBinaryModule = exports.assertLocalNameMetadata = exports.assertFunctionNameMetadata = exports.assertModuleNameMetadata = exports.assertModuleMetadata = exports.assertModule = exports.isIntrinsic = exports.isImportDescr = exports.isNumericLiteral = exports.isExpression = exports.isInstruction = exports.isBlock = exports.isNode = exports.isInternalEndAndReturn = exports.isInternalCallExtern = exports.isInternalGoto = exports.isInternalBrUnless = exports.isFunc = exports.isByteArray = exports.isCallIndirectInstruction = exports.isCallInstruction = exports.isBlockInstruction = exports.isIdentifier = exports.isProgram = exports.isSignature = exports.isLimit = exports.isModuleExport = exports.isModuleExportDescr = exports.isModuleImport = exports.isFuncImportDescr = exports.isMemory = exports.isTable = exports.isGlobal = exports.isData = exports.isBlockComment = exports.isLeadingComment = exports.isGlobalType = exports.isStart = exports.isTypeInstruction = exports.isValtypeLiteral = exports.isIndexInFuncSection = exports.isElem = exports.isFloatLiteral = exports.isLongNumberLiteral = exports.isNumberLiteral = exports.isStringLiteral = exports.isIfInstruction = exports.isInstr = exports.isLoopInstruction = exports.isProducerMetadataVersionedName = exports.isProducerMetadata = exports.isProducersSectionMetadata = exports.isSectionMetadata = exports.isQuoteModule = exports.isBinaryModule = exports.isLocalNameMetadata = exports.isFunctionNameMetadata = exports.isModuleNameMetadata = exports.isModuleMetadata = exports.isModule = void 0; exports.nodeAndUnionTypes = exports.unionTypesMap = exports.assertInternalEndAndReturn = void 0; function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } // THIS FILE IS AUTOGENERATED // see scripts/generateNodeUtils.js function isTypeOf(t) { return function (n) { return n.type === t; }; } function assertTypeOf(t) { return function (n) { return function () { if (!(n.type === t)) { throw new Error('n.type === t' + " error: " + (undefined || "unknown")); } }(); }; } function _module(id, fields, metadata) { if (id !== null && id !== undefined) { if (!(typeof id === "string")) { throw new Error('typeof id === "string"' + " error: " + ("Argument id must be of type string, given: " + _typeof(id) || 0)); } } if (!(_typeof(fields) === "object" && typeof fields.length !== "undefined")) { throw new Error('typeof fields === "object" && typeof fields.length !== "undefined"' + " error: " + (undefined || "unknown")); } var node = { type: "Module", id: id, fields: fields }; if (typeof metadata !== "undefined") { node.metadata = metadata; } return node; } function moduleMetadata(sections, functionNames, localNames, producers) { if (!(_typeof(sections) === "object" && typeof sections.length !== "undefined")) { throw new Error('typeof sections === "object" && typeof sections.length !== "undefined"' + " error: " + (undefined || "unknown")); } if (functionNames !== null && functionNames !== undefined) { if (!(_typeof(functionNames) === "object" && typeof functionNames.length !== "undefined")) { throw new Error('typeof functionNames === "object" && typeof functionNames.length !== "undefined"' + " error: " + (undefined || "unknown")); } } if (localNames !== null && localNames !== undefined) { if (!(_typeof(localNames) === "object" && typeof localNames.length !== "undefined")) { throw new Error('typeof localNames === "object" && typeof localNames.length !== "undefined"' + " error: " + (undefined || "unknown")); } } if (producers !== null && producers !== undefined) { if (!(_typeof(producers) === "object" && typeof producers.length !== "undefined")) { throw new Error('typeof producers === "object" && typeof producers.length !== "undefined"' + " error: " + (undefined || "unknown")); } } var node = { type: "ModuleMetadata", sections: sections }; if (typeof functionNames !== "undefined" && functionNames.length > 0) { node.functionNames = functionNames; } if (typeof localNames !== "undefined" && localNames.length > 0) { node.localNames = localNames; } if (typeof producers !== "undefined" && producers.length > 0) { node.producers = producers; } return node; } function moduleNameMetadata(value) { if (!(typeof value === "string")) { throw new Error('typeof value === "string"' + " error: " + ("Argument value must be of type string, given: " + _typeof(value) || 0)); } var node = { type: "ModuleNameMetadata", value: value }; return node; } function functionNameMetadata(value, index) { if (!(typeof value === "string")) { throw new Error('typeof value === "string"' + " error: " + ("Argument value must be of type string, given: " + _typeof(value) || 0)); } if (!(typeof index === "number")) { throw new Error('typeof index === "number"' + " error: " + ("Argument index must be of type number, given: " + _typeof(index) || 0)); } var node = { type: "FunctionNameMetadata", value: value, index: index }; return node; } function localNameMetadata(value, localIndex, functionIndex) { if (!(typeof value === "string")) { throw new Error('typeof value === "string"' + " error: " + ("Argument value must be of type string, given: " + _typeof(value) || 0)); } if (!(typeof localIndex === "number")) { throw new Error('typeof localIndex === "number"' + " error: " + ("Argument localIndex must be of type number, given: " + _typeof(localIndex) || 0)); } if (!(typeof functionIndex === "number")) { throw new Error('typeof functionIndex === "number"' + " error: " + ("Argument functionIndex must be of type number, given: " + _typeof(functionIndex) || 0)); } var node = { type: "LocalNameMetadata", value: value, localIndex: localIndex, functionIndex: functionIndex }; return node; } function binaryModule(id, blob) { if (id !== null && id !== undefined) { if (!(typeof id === "string")) { throw new Error('typeof id === "string"' + " error: " + ("Argument id must be of type string, given: " + _typeof(id) || 0)); } } if (!(_typeof(blob) === "object" && typeof blob.length !== "undefined")) { throw new Error('typeof blob === "object" && typeof blob.length !== "undefined"' + " error: " + (undefined || "unknown")); } var node = { type: "BinaryModule", id: id, blob: blob }; return node; } function quoteModule(id, string) { if (id !== null && id !== undefined) { if (!(typeof id === "string")) { throw new Error('typeof id === "string"' + " error: " + ("Argument id must be of type string, given: " + _typeof(id) || 0)); } } if (!(_typeof(string) === "object" && typeof string.length !== "undefined")) { throw new Error('typeof string === "object" && typeof string.length !== "undefined"' + " error: " + (undefined || "unknown")); } var node = { type: "QuoteModule", id: id, string: string }; return node; } function sectionMetadata(section, startOffset, size, vectorOfSize) { if (!(typeof startOffset === "number")) { throw new Error('typeof startOffset === "number"' + " error: " + ("Argument startOffset must be of type number, given: " + _typeof(startOffset) || 0)); } var node = { type: "SectionMetadata", section: section, startOffset: startOffset, size: size, vectorOfSize: vectorOfSize }; return node; } function producersSectionMetadata(producers) { if (!(_typeof(producers) === "object" && typeof producers.length !== "undefined")) { throw new Error('typeof producers === "object" && typeof producers.length !== "undefined"' + " error: " + (undefined || "unknown")); } var node = { type: "ProducersSectionMetadata", producers: producers }; return node; } function producerMetadata(language, processedBy, sdk) { if (!(_typeof(language) === "object" && typeof language.length !== "undefined")) { throw new Error('typeof language === "object" && typeof language.length !== "undefined"' + " error: " + (undefined || "unknown")); } if (!(_typeof(processedBy) === "object" && typeof processedBy.length !== "undefined")) { throw new Error('typeof processedBy === "object" && typeof processedBy.length !== "undefined"' + " error: " + (undefined || "unknown")); } if (!(_typeof(sdk) === "object" && typeof sdk.length !== "undefined")) { throw new Error('typeof sdk === "object" && typeof sdk.length !== "undefined"' + " error: " + (undefined || "unknown")); } var node = { type: "ProducerMetadata", language: language, processedBy: processedBy, sdk: sdk }; return node; } function producerMetadataVersionedName(name, version) { if (!(typeof name === "string")) { throw new Error('typeof name === "string"' + " error: " + ("Argument name must be of type string, given: " + _typeof(name) || 0)); } if (!(typeof version === "string")) { throw new Error('typeof version === "string"' + " error: " + ("Argument version must be of type string, given: " + _typeof(version) || 0)); } var node = { type: "ProducerMetadataVersionedName", name: name, version: version }; return node; } function loopInstruction(label, resulttype, instr) { if (!(_typeof(instr) === "object" && typeof instr.length !== "undefined")) { throw new Error('typeof instr === "object" && typeof instr.length !== "undefined"' + " error: " + (undefined || "unknown")); } var node = { type: "LoopInstruction", id: "loop", label: label, resulttype: resulttype, instr: instr }; return node; } function instr(id, object, args, namedArgs) { if (!(typeof id === "string")) { throw new Error('typeof id === "string"' + " error: " + ("Argument id must be of type string, given: " + _typeof(id) || 0)); } if (!(_typeof(args) === "object" && typeof args.length !== "undefined")) { throw new Error('typeof args === "object" && typeof args.length !== "undefined"' + " error: " + (undefined || "unknown")); } var node = { type: "Instr", id: id, args: args }; if (typeof object !== "undefined") { node.object = object; } if (typeof namedArgs !== "undefined" && Object.keys(namedArgs).length !== 0) { node.namedArgs = namedArgs; } return node; } function ifInstruction(testLabel, test, result, consequent, alternate) { if (!(_typeof(test) === "object" && typeof test.length !== "undefined")) { throw new Error('typeof test === "object" && typeof test.length !== "undefined"' + " error: " + (undefined || "unknown")); } if (!(_typeof(consequent) === "object" && typeof consequent.length !== "undefined")) { throw new Error('typeof consequent === "object" && typeof consequent.length !== "undefined"' + " error: " + (undefined || "unknown")); } if (!(_typeof(alternate) === "object" && typeof alternate.length !== "undefined")) { throw new Error('typeof alternate === "object" && typeof alternate.length !== "undefined"' + " error: " + (undefined || "unknown")); } var node = { type: "IfInstruction", id: "if", testLabel: testLabel, test: test, result: result, consequent: consequent, alternate: alternate }; return node; } function stringLiteral(value) { if (!(typeof value === "string")) { throw new Error('typeof value === "string"' + " error: " + ("Argument value must be of type string, given: " + _typeof(value) || 0)); } var node = { type: "StringLiteral", value: value }; return node; } function numberLiteral(value, raw) { if (!(typeof value === "number")) { throw new Error('typeof value === "number"' + " error: " + ("Argument value must be of type number, given: " + _typeof(value) || 0)); } if (!(typeof raw === "string")) { throw new Error('typeof raw === "string"' + " error: " + ("Argument raw must be of type string, given: " + _typeof(raw) || 0)); } var node = { type: "NumberLiteral", value: value, raw: raw }; return node; } function longNumberLiteral(value, raw) { if (!(typeof raw === "string")) { throw new Error('typeof raw === "string"' + " error: " + ("Argument raw must be of type string, given: " + _typeof(raw) || 0)); } var node = { type: "LongNumberLiteral", value: value, raw: raw }; return node; } function floatLiteral(value, nan, inf, raw) { if (!(typeof value === "number")) { throw new Error('typeof value === "number"' + " error: " + ("Argument value must be of type number, given: " + _typeof(value) || 0)); } if (nan !== null && nan !== undefined) { if (!(typeof nan === "boolean")) { throw new Error('typeof nan === "boolean"' + " error: " + ("Argument nan must be of type boolean, given: " + _typeof(nan) || 0)); } } if (inf !== null && inf !== undefined) { if (!(typeof inf === "boolean")) { throw new Error('typeof inf === "boolean"' + " error: " + ("Argument inf must be of type boolean, given: " + _typeof(inf) || 0)); } } if (!(typeof raw === "string")) { throw new Error('typeof raw === "string"' + " error: " + ("Argument raw must be of type string, given: " + _typeof(raw) || 0)); } var node = { type: "FloatLiteral", value: value, raw: raw }; if (nan === true) { node.nan = true; } if (inf === true) { node.inf = true; } return node; } function elem(table, offset, funcs) { if (!(_typeof(offset) === "object" && typeof offset.length !== "undefined")) { throw new Error('typeof offset === "object" && typeof offset.length !== "undefined"' + " error: " + (undefined || "unknown")); } if (!(_typeof(funcs) === "object" && typeof funcs.length !== "undefined")) { throw new Error('typeof funcs === "object" && typeof funcs.length !== "undefined"' + " error: " + (undefined || "unknown")); } var node = { type: "Elem", table: table, offset: offset, funcs: funcs }; return node; } function indexInFuncSection(index) { var node = { type: "IndexInFuncSection", index: index }; return node; } function valtypeLiteral(name) { var node = { type: "ValtypeLiteral", name: name }; return node; } function typeInstruction(id, functype) { var node = { type: "TypeInstruction", id: id, functype: functype }; return node; } function start(index) { var node = { type: "Start", index: index }; return node; } function globalType(valtype, mutability) { var node = { type: "GlobalType", valtype: valtype, mutability: mutability }; return node; } function leadingComment(value) { if (!(typeof value === "string")) { throw new Error('typeof value === "string"' + " error: " + ("Argument value must be of type string, given: " + _typeof(value) || 0)); } var node = { type: "LeadingComment", value: value }; return node; } function blockComment(value) { if (!(typeof value === "string")) { throw new Error('typeof value === "string"' + " error: " + ("Argument value must be of type string, given: " + _typeof(value) || 0)); } var node = { type: "BlockComment", value: value }; return node; } function data(memoryIndex, offset, init) { var node = { type: "Data", memoryIndex: memoryIndex, offset: offset, init: init }; return node; } function global(globalType, init, name) { if (!(_typeof(init) === "object" && typeof init.length !== "undefined")) { throw new Error('typeof init === "object" && typeof init.length !== "undefined"' + " error: " + (undefined || "unknown")); } var node = { type: "Global", globalType: globalType, init: init, name: name }; return node; } function table(elementType, limits, name, elements) { if (!(limits.type === "Limit")) { throw new Error('limits.type === "Limit"' + " error: " + ("Argument limits must be of type Limit, given: " + limits.type || 0)); } if (elements !== null && elements !== undefined) { if (!(_typeof(elements) === "object" && typeof elements.length !== "undefined")) { throw new Error('typeof elements === "object" && typeof elements.length !== "undefined"' + " error: " + (undefined || "unknown")); } } var node = { type: "Table", elementType: elementType, limits: limits, name: name }; if (typeof elements !== "undefined" && elements.length > 0) { node.elements = elements; } return node; } function memory(limits, id) { var node = { type: "Memory", limits: limits, id: id }; return node; } function funcImportDescr(id, signature) { var node = { type: "FuncImportDescr", id: id, signature: signature }; return node; } function moduleImport(module, name, descr) { if (!(typeof module === "string")) { throw new Error('typeof module === "string"' + " error: " + ("Argument module must be of type string, given: " + _typeof(module) || 0)); } if (!(typeof name === "string")) { throw new Error('typeof name === "string"' + " error: " + ("Argument name must be of type string, given: " + _typeof(name) || 0)); } var node = { type: "ModuleImport", module: module, name: name, descr: descr }; return node; } function moduleExportDescr(exportType, id) { var node = { type: "ModuleExportDescr", exportType: exportType, id: id }; return node; } function moduleExport(name, descr) { if (!(typeof name === "string")) { throw new Error('typeof name === "string"' + " error: " + ("Argument name must be of type string, given: " + _typeof(name) || 0)); } var node = { type: "ModuleExport", name: name, descr: descr }; return node; } function limit(min, max) { if (!(typeof min === "number")) { throw new Error('typeof min === "number"' + " error: " + ("Argument min must be of type number, given: " + _typeof(min) || 0)); } if (max !== null && max !== undefined) { if (!(typeof max === "number")) { throw new Error('typeof max === "number"' + " error: " + ("Argument max must be of type number, given: " + _typeof(max) || 0)); } } var node = { type: "Limit", min: min }; if (typeof max !== "undefined") { node.max = max; } return node; } function signature(params, results) { if (!(_typeof(params) === "object" && typeof params.length !== "undefined")) { throw new Error('typeof params === "object" && typeof params.length !== "undefined"' + " error: " + (undefined || "unknown")); } if (!(_typeof(results) === "object" && typeof results.length !== "undefined")) { throw new Error('typeof results === "object" && typeof results.length !== "undefined"' + " error: " + (undefined || "unknown")); } var node = { type: "Signature", params: params, results: results }; return node; } function program(body) { if (!(_typeof(body) === "object" && typeof body.length !== "undefined")) { throw new Error('typeof body === "object" && typeof body.length !== "undefined"' + " error: " + (undefined || "unknown")); } var node = { type: "Program", body: body }; return node; } function identifier(value, raw) { if (!(typeof value === "string")) { throw new Error('typeof value === "string"' + " error: " + ("Argument value must be of type string, given: " + _typeof(value) || 0)); } if (raw !== null && raw !== undefined) { if (!(typeof raw === "string")) { throw new Error('typeof raw === "string"' + " error: " + ("Argument raw must be of type string, given: " + _typeof(raw) || 0)); } } var node = { type: "Identifier", value: value }; if (typeof raw !== "undefined") { node.raw = raw; } return node; } function blockInstruction(label, instr, result) { if (!(_typeof(instr) === "object" && typeof instr.length !== "undefined")) { throw new Error('typeof instr === "object" && typeof instr.length !== "undefined"' + " error: " + (undefined || "unknown")); } var node = { type: "BlockInstruction", id: "block", label: label, instr: instr, result: result }; return node; } function callInstruction(index, instrArgs, numeric) { if (instrArgs !== null && instrArgs !== undefined) { if (!(_typeof(instrArgs) === "object" && typeof instrArgs.length !== "undefined")) { throw new Error('typeof instrArgs === "object" && typeof instrArgs.length !== "undefined"' + " error: " + (undefined || "unknown")); } } var node = { type: "CallInstruction", id: "call", index: index }; if (typeof instrArgs !== "undefined" && instrArgs.length > 0) { node.instrArgs = instrArgs; } if (typeof numeric !== "undefined") { node.numeric = numeric; } return node; } function callIndirectInstruction(signature, intrs) { if (intrs !== null && intrs !== undefined) { if (!(_typeof(intrs) === "object" && typeof intrs.length !== "undefined")) { throw new Error('typeof intrs === "object" && typeof intrs.length !== "undefined"' + " error: " + (undefined || "unknown")); } } var node = { type: "CallIndirectInstruction", id: "call_indirect", signatur