(function (global, factory) { if (typeof define === "function" && define.amd) { define(["exports", "./TempNode.js", "./NodeLib.js"], factory); } else if (typeof exports !== "undefined") { factory(exports, require("./TempNode.js"), require("./NodeLib.js")); } else { var mod = { exports: {} }; factory(mod.exports, global.TempNode, global.NodeLib); global.FunctionNode = mod.exports; } })(typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : this, function (_exports, _TempNode2, _NodeLib) { "use strict"; Object.defineProperty(_exports, "__esModule", { value: true }); _exports.FunctionNode = void 0; 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); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } function _get() { if (typeof Reflect !== "undefined" && Reflect.get) { _get = Reflect.get; } else { _get = function _get(target, property, receiver) { var base = _superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(arguments.length < 3 ? target : receiver); } return desc.value; }; } return _get.apply(this, arguments); } function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } Object.defineProperty(subClass, "prototype", { value: Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }), writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); } function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); } function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } var declarationRegexp = /^\s*([a-z_0-9]+)\s+([a-z_0-9]+)\s*\(([\s\S]*?)\)/i, propertiesRegexp = /[a-z_0-9]+/ig; var FunctionNode = /*#__PURE__*/function (_TempNode) { _inherits(FunctionNode, _TempNode); var _super = _createSuper(FunctionNode); function FunctionNode(src, includes, extensions, keywords, type) { var _this; _classCallCheck(this, FunctionNode); _this = _super.call(this, type); _this.isMethod = type === undefined; _this.isInterface = false; _this.parse(src, includes, extensions, keywords); return _this; } _createClass(FunctionNode, [{ key: "getShared", value: function /* builder, output */ getShared() { return !this.isMethod; } }, { key: "getType", value: function getType(builder) { return builder.getTypeByFormat(this.type); } }, { key: "getInputByName", value: function getInputByName(name) { var i = this.inputs.length; while (i--) { if (this.inputs[i].name === name) { return this.inputs[i]; } } } }, { key: "getIncludeByName", value: function getIncludeByName(name) { var i = this.includes.length; while (i--) { if (this.includes[i].name === name) { return this.includes[i]; } } } }, { key: "generate", value: function generate(builder, output) { var match, offset = 0, src = this.src; for (var i = 0; i < this.includes.length; i++) { builder.include(this.includes[i], this); } for (var ext in this.extensions) { builder.extensions[ext] = true; } var matches = []; while (match = propertiesRegexp.exec(this.src)) { matches.push(match); } for (var _i = 0; _i < matches.length; _i++) { var _match = matches[_i]; var prop = _match[0], isGlobal = this.isMethod ? !this.getInputByName(prop) : true; var reference = prop; if (this.keywords[prop] || this.useKeywords && isGlobal && _NodeLib.NodeLib.containsKeyword(prop)) { var node = this.keywords[prop]; if (!node) { var keyword = _NodeLib.NodeLib.getKeywordData(prop); if (keyword.cache) node = builder.keywords[prop]; node = node || _NodeLib.NodeLib.getKeyword(prop, builder); if (keyword.cache) builder.keywords[prop] = node; } reference = node.build(builder); } if (prop !== reference) { src = src.substring(0, _match.index + offset) + reference + src.substring(_match.index + prop.length + offset); offset += reference.length - prop.length; } if (this.getIncludeByName(reference) === undefined && _NodeLib.NodeLib.contains(reference)) { builder.include(_NodeLib.NodeLib.get(reference)); } } if (output === 'source') { return src; } else if (this.isMethod) { if (!this.isInterface) { builder.include(this, false, src); } return this.name; } else { return builder.format('( ' + src + ' )', this.getType(builder), output); } } }, { key: "parse", value: function parse(src, includes, extensions, keywords) { this.src = src || ''; this.includes = includes || []; this.extensions = extensions || {}; this.keywords = keywords || {}; if (this.isMethod) { var match = this.src.match(declarationRegexp); this.inputs = []; if (match && match.length == 4) { this.type = match[1]; this.name = match[2]; var inputs = match[3].match(propertiesRegexp); if (inputs) { var i = 0; while (i < inputs.length) { var qualifier = inputs[i++]; var type = void 0; if (qualifier === 'in' || qualifier === 'out' || qualifier === 'inout') { type = inputs[i++]; } else { type = qualifier; qualifier = ''; } var name = inputs[i++]; this.inputs.push({ name: name, type: type, qualifier: qualifier }); } } this.isInterface = this.src.indexOf('{') === -1; } else { this.type = ''; this.name = ''; } } } }, { key: "copy", value: function copy(source) { _get(_getPrototypeOf(FunctionNode.prototype), "copy", this).call(this, source); this.isMethod = source.isMethod; this.useKeywords = source.useKeywords; this.parse(source.src, source.includes, source.extensions, source.keywords); if (source.type !== undefined) this.type = source.type; return this; } }, { key: "toJSON", value: function toJSON(meta) { var data = this.getJSONNode(meta); if (!data) { data = this.createJSONNode(meta); data.src = this.src; data.isMethod = this.isMethod; data.useKeywords = this.useKeywords; if (!this.isMethod) data.type = this.type; data.extensions = JSON.parse(JSON.stringify(this.extensions)); data.keywords = {}; for (var keyword in this.keywords) { data.keywords[keyword] = this.keywords[keyword].toJSON(meta).uuid; } if (this.includes.length) { data.includes = []; for (var i = 0; i < this.includes.length; i++) { data.includes.push(this.includes[i].toJSON(meta).uuid); } } } return data; } }]); return FunctionNode; }(_TempNode2.TempNode); _exports.FunctionNode = FunctionNode; FunctionNode.prototype.nodeType = 'Function'; FunctionNode.prototype.useKeywords = true; });