ponicode
Version:
Ponicode is a quick and easy AI-powered solution for Javascript unit testing.
1 lines • 36.7 kB
JavaScript
module.exports=(()=>{"use strict";var e={2829:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.parseValue=t.findFunctionReferences=void 0;const r=n(874),i=n(6077);function o(e){if("undefined"===(t=e).getText()||r.TypeNode.isStringLiteral(t)||r.TypeNode.isNumericLiteral(t)||r.TypeNode.isTrueLiteral(t)||r.TypeNode.isFalseLiteral(t)||r.TypeNode.isNullLiteral(t)||r.TypeNode.isBigIntLiteral(t))return{type:s(e),value:r.TypeNode.isStringLiteral(e)?e.getText().slice(1,-1):e.getText()};if(r.TypeNode.isArrayLiteralExpression(e)){const t=[];for(const n of e.getElements())t.push(o(n));return{type:"array",value:t}}if(r.TypeNode.isObjectLiteralExpression(e)){const t=[];for(const n of e.getProperties()){const e=n.getFirstChildByKindOrThrow(r.SyntaxKind.Identifier).getText(),i=o(n.getLastChildOrThrow());t.push({key:e,rhs:i})}return{type:"object",value:t}}if(r.TypeNode.isNewExpression(e)){const t=e.getFirstChildByKindOrThrow(r.SyntaxKind.Identifier);return{type:"instance",value:{constructorArgs:e.getArguments().map((e=>o(e))),reach:c(t),customProperties:[]}}}if(function(e){return r.TypeNode.isIdentifier(e)||r.TypeNode.isPropertyAccessExpression(e)||r.TypeNode.isCallExpression(e)||r.TypeNode.isElementAccessExpression(e)}(e)){const t=a(e);if(r.TypeNode.isIdentifier(e)&&"unreachable"===(null==t?void 0:t.reach.reach))return function(e){const t=e.getDefinitions()[0].getNode().getParentOrThrow().getParentOrThrow();if(r.TypeNode.isVariableDeclarationList(t)){const e=t.getParentOrThrow();if(r.TypeNode.isForOfStatement(e)||r.TypeNode.isForInStatement(e)){const t=e.getFirstChildByKind(r.SyntaxKind.ArrayLiteralExpression);if(t){const e=t.getElements();return o(e[Math.floor(Math.random()*e.length)])}}else if(r.TypeNode.isVariableStatement(e))return o(e.getFirstChildByKindOrThrow(r.SyntaxKind.VariableDeclarationList).getFirstChildByKindOrThrow(r.SyntaxKind.VariableDeclaration).getFirstChildByKindOrThrow(r.SyntaxKind.EqualsToken).getNextSiblingOrThrow())}return{type:"unhandled",value:"unhandled"}}(e);if(t)return{type:"expression",value:t}}var t;return{type:"unhandled",value:"unhandled"}}function a(e,t=[]){if(r.TypeNode.isIdentifier(e))return{reach:c(e),subset:t};if(r.TypeNode.isPropertyAccessExpression(e)){const n=e.getFirstChildOrThrow(),i=e.getLastChildByKindOrThrow(r.SyntaxKind.Identifier);if(function(e){const t=e.getDefinitions()[0].getNode().getParentOrThrow().getFirstChildByKind(r.SyntaxKind.SyntaxList);return!!t&&(!!t.getFirstChildByKind(r.SyntaxKind.PrivateKeyword)||!!t.getFirstChildByKind(r.SyntaxKind.ProtectedKeyword))}(i))return;const o={type:"member",name:i.getText()};return t.unshift(o),a(n,t)}if(r.TypeNode.isCallExpression(e)){const n=e.getFirstChildOrThrow(),r={type:"call",args:e.getArguments().map((e=>o(e)))};return t.unshift(r),a(n,t)}if(r.TypeNode.isElementAccessExpression(e)){const n=e.getArgumentExpressionOrThrow();let i;const o=e.getFirstChildOrThrow();if(r.TypeNode.isNumericLiteral(n)){i=n.getText();const e={type:"array-subscript",nth:i};return t.unshift(e),a(o,t)}}}function s(e){if("undefined"===e.getText())return"undefined";switch(e.getKind()){case r.SyntaxKind.NumericLiteral:return"number";case r.SyntaxKind.StringLiteral:return"string";case r.SyntaxKind.TrueKeyword:case r.SyntaxKind.FalseKeyword:return"boolean";case r.SyntaxKind.NullKeyword:return"null";default:return"unhandled"}}function c(e){const t=e.getDefinitions();if(0===t.length)return{reach:"unreachable"};const n=t[0].getNode();let i;const o=n.getSourceFile().getFilePath();if(i=r.TypeNode.isConstructorDeclaration(n.getParentOrThrow())?n.getParentOrThrow().getParentOrThrow().getParentOrThrow():n.getParentOrThrow().getParentOrThrow(),i.getKind()!=r.SyntaxKind.SourceFile)return{reach:"unreachable"};let a;return a=o.includes("/node_modules/typescript/lib/")?{reach:"node-global",reachNames:[e.getText()]}:{reach:"member",reachNames:[e.getText()],fsPath:o},a}t.findFunctionReferences=function(e,t,n){var a;this.project.addSourceFilesAtPaths(n),this.log("Providing function references of TS file:",e,"at position",t);const{func:s}=this.getFunctionNodeAtOffsetOrThrow(e,t,!1),c=null===(a=s.getName)||void 0===a?void 0:a.call(s);if(this.log("Function name:",c),r.TypeNode.isArrowFunction(s)||r.TypeNode.isFunctionExpression(s))return[];if(0===s.getParameters().length)return[];const d=s.findReferences()[0].getReferences().map((e=>e.getNode().getFirstAncestorByKind(r.SyntaxKind.CallExpression))).filter((e=>(null==e?void 0:e.getKind())===r.SyntaxKind.CallExpression)),u=[];for(const e of d){const t=[];let n=!0;const a=e.getFirstChildByKindOrThrow(r.SyntaxKind.SyntaxList).getChildren();for(const e of a){if(e.getKind()===r.SyntaxKind.CommaToken)continue;let a;try{a=o(e)}catch(e){a={type:"unhandled",value:"unhanled"}}i.findProp(a,"type").includes("unhandled")||i.findProp(a,"reach").includes("unreachable")?t.push({type:"unhandled",value:"unhandled"}):(t.push(a),n=!1)}n||u.push(t)}return u},t.parseValue=o},226:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.findParameterTypeNodesPositions=t.findParametersReference=void 0;const r=n(874),i=n(2829),o=n(6077);t.findParametersReference=function(e,t,n){var a;this.project.addSourceFilesAtPaths(n),this.log("Providing function references of TS file:",e,"at position",t);const{func:s}=this.getFunctionNodeAtOffsetOrThrow(e,t,!1),c=null===(a=s.getName)||void 0===a?void 0:a.call(s);this.log("Function name:",c);const d=s.getParameters(),u=[];let l=!0;d.forEach((e=>{const t=e.getTypeNode();if(r.TypeNode.isTypeReferenceNode(t)){const e=t.getFirstChildByKindOrThrow(r.SyntaxKind.Identifier).getDefinitions()[0].getNode().getParent();if(r.TypeNode.isClassDeclaration(e)){const t=function(e,t){const n=t.getConstructors(),o=[];for(const t of n){const n=e.getLanguageService().findReferences(t)[0].getReferences().map((e=>e.getNode().getFirstAncestorByKind(r.SyntaxKind.NewExpression))).filter((e=>(null==e?void 0:e.getKind())===r.SyntaxKind.NewExpression));o.push(...n.map((e=>i.parseValue(e))))}return o}(this.project,e).map((e=>o.findProp(e,"type").includes("unhandled")||o.findProp(e,"reach").includes("unreachable")?{type:"unhandled",value:"unhandled"}:e)).filter((e=>"unhandled"!=e.type));t&&(l=!1),u.push(t)}else u.push([])}else u.push([])}));const f=[];if(!l)for(let e=0;e<10;e++){f.push([]);for(const t of u)t.length>0?f[e].push(t[Math.floor(Math.random()*t.length)]):f[e].push({type:"unhandled",value:"unhandled"})}return f},t.findParameterTypeNodesPositions=function(e,t){var n;this.log("Providing parameters type nodes parameters of TS file:",e,"at position",t);const{func:i}=this.getFunctionNodeAtOffsetOrThrow(e,t,!0),o=null===(n=i.getName)||void 0===n?void 0:n.call(i);this.log("Function name:",o);const a=[];return i.getParameters().forEach((e=>{const t=e.getTypeNode();if(r.TypeNode.isTypeReferenceNode(t)){const e=t.getFirstChildByKindOrThrow(r.SyntaxKind.Identifier).getDefinitions()[0].getNode().getParent();if(r.TypeNode.isClassDeclaration(e)){const t=e.getSourceFile(),n=t.getFilePath();e.getConstructors().forEach((e=>{const{line:r,column:i}=t.getLineAndColumnAtPos(e.getStart());a.push({fsPath:n,position:{line:r-1,column:i-1}})}))}}})),a}},6077:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.findProp=void 0,t.findProp=function(e,t){var n=[];return function e(t,r){Object.keys(t).forEach((function(i){i===r&&n.push(t[i]),"object"==typeof t[i]&&e(t[i],r)}))}(e,t),n}},5151:function(e,t,n){var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const i=r(n(5622)),o=r(n(2357)),a=n(874),s=n(6156),c=n(2829),d=n(226),u=n(9604),l=n(5671),f=n(3715),p=n(4343),y=n(6505);t.default=class{constructor(e){let t;this.resolveModuleName=f.resolveModuleName,this.provideParametersRepresentation=s.provideParametersRepresentation,this.provideParametersRepresentationJS=u.provideParametersRepresentationJS,this.provideParametersRepresentationJS_WithUnions=u.provideParametersRepresentationJS_WithUnions,this.isFunction=y.isFunction,this.findFunctionReferences=c.findFunctionReferences,this.findParametersReference=d.findParametersReference,this.findParameterTypeNodesPositions=d.findParameterTypeNodesPositions,this.parseConstructor=l.parseConstructor,this.getFunctionNodeAtOffsetOrThrow=p.getFunctionNodeAtOffsetOrThrow,"stderr"===e.log?this.log=console.error:e.log?this.log=e.log:this.log=()=>{},e.tsConfigFilePath&&(t=e.tsConfigFilePath),this.project=new a.Project({tsConfigFilePath:t,skipAddingFilesFromTsConfig:!0,compilerOptions:{noResolve:!1,isolatedModules:!0,allowJs:!0,checkJs:!0,outDir:"/dev/null",strict:!0}}),this.fakeProject=new a.Project({tsConfigFilePath:t,skipAddingFilesFromTsConfig:!0,compilerOptions:{noResolve:!0,isolatedModules:!0}})}getProject(){return this.project}addSourceFileAtPath(e,t){o.default(i.default.isAbsolute(e));const n=this.project.addSourceFileAtPath(e);return t&&n.getPreEmitDiagnostics(),n}}},6505:function(e,t,n){var r=this&&this.__createBinding||(Object.create?function(e,t,n,r){void 0===r&&(r=n),Object.defineProperty(e,r,{enumerable:!0,get:function(){return t[n]}})}:function(e,t,n,r){void 0===r&&(r=n),e[r]=t[n]}),i=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),o=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var n in e)"default"!==n&&Object.prototype.hasOwnProperty.call(e,n)&&r(t,e,n);return i(t,e),t};Object.defineProperty(t,"__esModule",{value:!0}),t.isFunction=void 0;const a=o(n(874)),s=n(4343);t.isFunction=function(e){const t=this.fakeProject.createSourceFile("/tmp",`let x = ${e}`,{overwrite:!0}),n=t.getStatements();let r=!1;return 1===n.length&&(r=function(e){if(e.getKind()!==a.SyntaxKind.VariableStatement)return!1;const t=e.getDeclarations();if(1!==t.length)return!1;const n=t[0];return 3===n.getChildCount()&&s.isFunctionNode(n.getChildren()[2],!1)}(n[0])),this.fakeProject.removeSourceFile(t),r}},994:function(e,t,n){var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.inferTypeOfParameters=t.debugPrintDiagnostics=t.JSTypeToText=t.classifyType=t.IGNORED_DIAGS=t.JSInputValueTypes=void 0;const i=r(n(2357)),o=n(630);function a(e){switch(!0){case e.isArray():return"array";case e.isObject():return"object";case e.isNull():return"null";case e.isUndefined():return"undefined";case e.isNumber():case e.isNumberLiteral():return"number";case e.isString():case e.isStringLiteral():return"string";case e.isBoolean():case e.isBooleanLiteral():return"boolean";default:return}}function s(e){switch(e){case"string":case"number":case"boolean":case"undefined":case"null":return e;case"array":return"Array<any>";case"object":return"{ [skey: string]: any; [nkey: number]: any }"}}t.JSInputValueTypes=["string","number","boolean","undefined","null","array","object"],t.IGNORED_DIAGS=[8010,7006],t.classifyType=a,t.JSTypeToText=s,t.debugPrintDiagnostics=function(e,n,r=!1){n.forEach((n=>{var i;!r&&t.IGNORED_DIAGS.includes(n.getCode())||(console.error(e.formatDiagnosticsWithColorAndContext([n])),console.error(null===(i=n.getSourceFile())||void 0===i?void 0:i.getFilePath()))}))},t.inferTypeOfParameters=function(e,n,r){if(0===r.getParameters().length)return{parameterTypes:[],performance:[]};const c=[],d=o.performance.now(),u=n.getPreEmitDiagnostics(),l=o.performance.now();return c.push({step:"preEmit",ms:l-d}),{parameterTypes:r.getParameters().map(((e,d)=>{const l=a(e.getType());if(l)return[l];const f=t.JSInputValueTypes.map(((e,a)=>{const u=o.performance.now(),l=function(e,n,r,a){o.performance.now();const c=n.getParameters()[r];i.default(c),c.setType(s(a));const d=e.getPreEmitDiagnostics().filter((e=>!t.IGNORED_DIAGS.includes(e.getCode()))).length;return c.removeType(),o.performance.now(),d}(n,r,d,e),f=o.performance.now();return c.push({step:`trySingleParam param(${d}) type(${a})`,ms:f-u}),l})),p=Math.min(...f);let y;return y=p>u.length?[]:t.JSInputValueTypes.filter(((e,t)=>f[t]===p)),y.length!==t.JSInputValueTypes.length?y:void 0})),performance:c}}},902:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ORM_FIELDS=t.ORM_DECORATORS=t.ARRAY_TYPES=t.GENERIC_BUILT_IN=t.BUILT_IN=t.PRIMITIVE_TYPES=void 0;const r=n(874);t.PRIMITIVE_TYPES=[r.SyntaxKind.NumberKeyword,r.SyntaxKind.StringKeyword,r.SyntaxKind.BooleanKeyword,r.SyntaxKind.BigIntKeyword,r.SyntaxKind.AnyKeyword,r.SyntaxKind.UndefinedKeyword,r.SyntaxKind.NullKeyword,r.SyntaxKind.FalseKeyword,r.SyntaxKind.TrueKeyword,r.SyntaxKind.VoidKeyword],t.BUILT_IN=["BigInt64Array","BigUint64Array","Document","DocumentFragment","Element","Float32Array","Float64Array","HTMLAudioElement","HTMLButtonElement","HTMLCanvasElement","HTMLCollection","HTMLDivElement","HTMLDocument","HTMLElement","HTMLImageElement","HTMLObjectElement","HTMLVideoElement","ImageBitmap","Int16Array","Int32Array","Int8Array","Uint16Array","Uint32Array","Uint8Array","Uint8ClampedArray","WebGLRenderingContext","WebGL2RenderingContext","OffscreenCanvas","PromiseLike","ArrayBufferLike","Date","AudioContext","AudioDestinationNode","MediaStreamAudioDestinationNode"],t.GENERIC_BUILT_IN=["DeepImmutable","Immutable","DeepImmutableObject","Readonly","Required","Pick","Omit","Exclude","NonNullable","Extract","Parameters","ConstructorParameters","ReturnType","InstanceType","ThisParameterType","OmitThisParameter","ThisType","Uppercase","Lowercase","Capitalize","Uncapitalize"],t.ARRAY_TYPES=["Array","ArrayLike","ReadOnlyArray","ArrayBuffer","ArrayBufferView","ArrayBufferLike"],t.ORM_DECORATORS=["Entity","InputType","Table"],t.ORM_FIELDS=["Column","Field"]},6811:function(e,t,n){var r=this&&this.__createBinding||(Object.create?function(e,t,n,r){void 0===r&&(r=n),Object.defineProperty(e,r,{enumerable:!0,get:function(){return t[n]}})}:function(e,t,n,r){void 0===r&&(r=n),e[r]=t[n]}),i=this&&this.__exportStar||function(e,t){for(var n in e)"default"===n||Object.prototype.hasOwnProperty.call(t,n)||r(t,e,n)};Object.defineProperty(t,"__esModule",{value:!0}),i(n(9054),t),i(n(5971),t),i(n(1457),t)},9054:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.mergeObjects=t.getParameterConstruct=t.getParameterConstructArray=void 0;const r=n(5971);function i(e,t){const n=e.hasInitializer()||e.hasQuestionToken();if(e.getTypeNode())return r.parseParameter(e.getTypeNodeOrThrow(),t,n);{const t=e.getType();return{reference:{filePath:"native",name:["any","string","number","boolean"].includes(t.getText())?t.getText():"any"}}}}t.getParameterConstructArray=function(e,t){return e.map((e=>{try{return i(e,t)}catch(e){return{reference:{filePath:"UnsupportedType",name:"any"}}}}))},t.getParameterConstruct=i,t.mergeObjects=function(e,t){return{...e,...t}}},5971:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ParseType=t.parseParameter=void 0;const r=n(874),i=n(1457),o=n(902),a=n(9054);function s(e,t,n=!1){return n?{reference:{filePath:"native",name:"Union"},typeParameters:[s(e,t),{reference:{filePath:"native",name:"undefined"}}]}:o.PRIMITIVE_TYPES.includes(e.getKind())?{reference:{filePath:"native",name:e.getType().getText()}}:[...o.BUILT_IN,...o.ARRAY_TYPES].includes(e.getText())||r.TypeNode.isLiteralTypeNode(e)?{reference:{filePath:"native",name:e.getText()}}:r.TypeNode.isFunctionTypeNode(e)?c.functionType(e,t):r.TypeNode.isIndexSignatureDeclaration(e)?c.indexSignature(e,t):r.TypeNode.isUnionTypeNode(e)?c.unionType(e,t):r.TypeNode.isIntersectionTypeNode(e)?c.intersectionType(e,t):r.TypeNode.isTupleTypeNode(e)?c.tupleType(e,t):r.TypeNode.isArrayTypeNode(e)?c.arrayType(e,t):r.TypeNode.isTypeReferenceNode(e)?c.typeReference(e,t):r.TypeNode.isTypeLiteralNode(e)?c.typeLiteral(e,t):r.TypeNode.isParenthesizedTypeNode(e)?s(e.getTypeNode(),t):{reference:{filePath:"UnsupportedType",name:"any"}}}var c;t.parseParameter=s,function(e){function t(e,t){let n=e.getFirstChildByKind(r.SyntaxKind.Identifier);n||(n=e.getFirstChildByKindOrThrow(r.SyntaxKind.QualifiedName).getLastChildByKindOrThrow(r.SyntaxKind.Identifier));const a=e.getTypeArguments().map((e=>s(e,t)));if([...o.GENERIC_BUILT_IN,...o.ARRAY_TYPES].includes(n.getText()))return{reference:{filePath:"native",name:n.getText()},typeParameters:a};const c=i.getReference(n);return"UnsupportedType"!=c.filePath&&i.updateDefinition(e,t),{reference:c,typeParameters:a}}function n(e,t){const n=e.getParameters(),r=a.getParameterConstructArray(n,t),i=s(e.getReturnTypeNodeOrThrow(),t);for(var o=0;o<n.length;o++)r[o].key=n[o].getName();return{reference:{filePath:"native",name:"FunctionType"},typeParameters:r,returnType:i}}function c(e,t){const n=s(e.getKeyTypeNode(),t),r=s(e.getReturnTypeNodeOrThrow(),t),i={keyType:n,reference:r.reference};return r.typeParameters&&(i.typeParameters=r.typeParameters),i}e.typeLiteral=function(e,t){const r=e.getProperties(),i=r.map((e=>s(e.getTypeNodeOrThrow(),t)));for(var o=0;o<r.length;o++)i[o].key=r[o].getName();return e.getIndexSignatures().forEach((e=>{i.push(c(e,t))})),e.getMethods().forEach((e=>{i.push(n(e,t))})),{reference:{filePath:"native",name:"TypeLiteral"},typeParameters:i}},e.intersectionType=function(e,t){return{reference:{filePath:"native",name:"Intersection"},typeParameters:e.getTypeNodes().map((e=>s(e,t)))}},e.unionType=function(e,t){return{reference:{filePath:"native",name:"Union"},typeParameters:e.getTypeNodes().map((e=>s(e,t)))}},e.arrayType=function(e,t){return{reference:{filePath:"native",name:"Array"},typeParameters:[s(e.getElementTypeNode(),t)]}},e.tupleType=function(e,t){return{reference:{filePath:"native",name:"Tuple"},typeParameters:e.getElements().map((e=>s(e,t)))}},e.typeReference=function(e,n){if(0===e.getTypeArguments().length){let t;const o=e.getFirstChildByKind(r.SyntaxKind.QualifiedName);t=o?o.getRight():e.getFirstChildByKindOrThrow(r.SyntaxKind.Identifier);const a=i.getReference(t);return"UnsupportedType"!=a.filePath&&i.updateDefinition(e,n),{reference:a}}return t(e,n)},e.genericType=t,e.functionType=n,e.typeParameter=function(e,t){const n=e.getDefault(),i=e.getConstraint();let o={name:e.getFirstChildByKindOrThrow(r.SyntaxKind.Identifier).getText()};return n&&(o.defaultType=s(n,t)),i&&(o.extendedType=s(i,t)),o},e.indexSignature=c}(c=t.ParseType||(t.ParseType={}))},1457:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.getReference=t.updateDefinition=void 0;const r=n(874),i=n(5971),o=n(902),a=n(9054);function s(e,t){let n;const i=e.getChildren().map((e=>e.getKind()));switch(!0){case i.includes(r.SyntaxKind.Identifier):n=e.getLastChildByKindOrThrow(r.SyntaxKind.Identifier);break;case i.includes(r.SyntaxKind.QualifiedName):n=e.getLastChildByKindOrThrow(r.SyntaxKind.QualifiedName).getLastChildByKindOrThrow(r.SyntaxKind.Identifier);break;case i.includes(r.SyntaxKind.PropertyAccessExpression):n=e.getLastChildByKindOrThrow(r.SyntaxKind.PropertyAccessExpression).getLastChildByKindOrThrow(r.SyntaxKind.Identifier);break;default:throw new Error(`Did not find an identifier node in ${e.getText()}`)}const a=u(n);if("TypeDefinitionGeneric"===a.filePath||!function(e,t){return"native"!==e.filePath&&(e.filePath in t||(t[e.filePath]={}),!(e.name in t[e.filePath])&&(t[e.filePath][e.name]=[],!0))}(a,t))return;let s,f=d(n.getDefinitions().map((e=>e.getNode().getParentOrThrow()))),p=[],y=0;for(;r.TypeNode.isExportSpecifier(f)&&y<50;)f=f.getLastChildByKindOrThrow(r.SyntaxKind.Identifier).getDefinitionNodes()[0],y+=1;if(r.TypeNode.isTypeAliasDeclaration(f)){const e=f.getTypeNodeOrThrow();p=l(f,t),s=o.PRIMITIVE_TYPES.includes(e.getKind())?[{constructKind:"TypeReference",constructParameters:[{reference:{filePath:"native",name:e.getText()}}]}]:r.TypeNode.isIntersectionTypeNode(e)?c.intersectionType(e,t):r.TypeNode.isUnionTypeNode(e)?c.unionType(e,t):r.TypeNode.isTypeLiteralNode(e)?c.typeLiteral(e,t):r.TypeNode.isTypeReferenceNode(e)?c.typeReference(e,t):r.TypeNode.isImportTypeNode(e)?c.importType(e,t):r.TypeNode.isFunctionTypeNode(e)?c.functionType(e,t):r.TypeNode.isLiteralTypeNode(e)?[{constructKind:"LiteralType",constructParameters:[{reference:{filePath:"native",name:e.getText()}}]}]:[{constructKind:"UnsupportedType",constructParameters:[{reference:{filePath:"UnsupportedType",name:e.getKindName()}}]}]}else r.TypeNode.isClassDeclaration(f)?(p=l(f,t),s=c.classDeclaration(f,t)):r.TypeNode.isInterfaceDeclaration(f)?(p=l(f,t),s=c.interfaceDeclaration(f,t)):s=r.TypeNode.isEnumDeclaration(f)?c.enumDeclaration(f):r.TypeNode.isTypeParameterDeclaration(f)?c.typeParameterDeclaration(f,t):[{constructKind:"UnsupportedType",constructParameters:[{reference:{filePath:"UnsupportedType",name:f.getKindName()}}]}];if(!r.TypeNode.isTypeParameterDeclaration(f))for(const e of s)e.genericParameters=p;a.filePath in t||(t[a.filePath]={}),t[a.filePath][a.name]=s}var c;function d(e){const t=e.map((e=>e.getKind()));return t.includes(r.SyntaxKind.ClassDeclaration)?e.filter((e=>e.getKind()===r.SyntaxKind.ClassDeclaration))[0]:t.includes(r.SyntaxKind.InterfaceDeclaration)?e.filter((e=>e.getKind()===r.SyntaxKind.InterfaceDeclaration))[0]:e[0]}function u(e){var t;const n=e.getDefinitions().map((e=>e.getNode().getParentOrThrow())),i=e.getText();if(0===n.length)return{filePath:"UnsupportedType",name:e.getText(),identifierStartIndex:e.getStart(),identifierFilePath:e.getSourceFile().getFilePath()};const o=d(n);let a;if(s=o.getParent(),r.TypeNode.isFunctionDeclaration(s)||r.TypeNode.isMethodDeclaration(s)||r.TypeNode.isFunctionExpression(s))a="FunctionTypeParameter";else if(function(e){return r.TypeNode.isClassDeclaration(e)||r.TypeNode.isInterfaceDeclaration(e)||r.TypeNode.isTypeAliasDeclaration(e)}(o.getParent()))a="TypeDefinitionGeneric";else{a=o.getSourceFile().getFilePath();let n=null===(t=o.getParentIfKind(r.SyntaxKind.ModuleBlock))||void 0===t?void 0:t.getParent();if(n&&n.getChildren().every((e=>e.getKind()!=r.SyntaxKind.ModuleKeyword)))return{filePath:a,name:`${u(n.getNameNode()).name}.${i}`,identifierStartIndex:e.getStart(),identifierFilePath:e.getSourceFile().getFilePath()}}var s;return{filePath:a,name:i,identifierStartIndex:e.getStart(),identifierFilePath:e.getSourceFile().getFilePath()}}function l(e,t){return e.getTypeParameters().map((e=>i.ParseType.typeParameter(e,t)))}t.updateDefinition=s,function(e){function t(e,t){const n=e.getProperties().filter((e=>e.getDecorators().map((e=>e.getName())).filter((e=>{const t=e.split(".");return o.ORM_FIELDS.includes(e)||o.ORM_FIELDS.includes(t[t.length-1])})).length>0)),r=n.map((e=>i.parseParameter(e.getTypeNodeOrThrow(),t)));for(var a=0;a<n.length;a++)r[a].key=n[a].getName();return[{constructKind:"PlainToClass",constructParameters:r}]}e.intersectionType=function(e,t){return[{constructKind:"Intersection",constructParameters:e.getTypeNodes().map((e=>i.parseParameter(e,t)))}]},e.unionType=function(e,t){return[{constructKind:"Union",constructParameters:e.getTypeNodes().map((e=>i.parseParameter(e,t)))}]},e.typeLiteral=function(e,t){const n=e.getProperties(),r=n.map((e=>i.parseParameter(e.getTypeNodeOrThrow(),t)));for(var o=0;o<n.length;o++)r[o].key=n[o].getName();return[{constructKind:"TypeLiteral",constructParameters:r}]},e.typeReference=function(e,t){return[{constructKind:"TypeReference",constructParameters:[i.parseParameter(e,t)]}]},e.importType=function(e,t){s(e,t);const n=e.getLastChildByKindOrThrow(r.SyntaxKind.Identifier);return[{constructKind:"ImportType",constructParameters:[{reference:{filePath:n.getDefinitionNodes()[0].getSourceFile().getFilePath(),name:n.getText()}}]}]},e.functionType=function(e,t){return[{constructKind:"function",constructParameters:[i.parseParameter(e,t)]}]},e.classDeclaration=function(e,n){if(e.getDecorators().map((e=>e.getName())).filter((e=>{const t=e.split(".");return o.ORM_DECORATORS.includes(t[t.length-1])})).length>0)return t(e,n);const i=e.getConstructors(),c=function(e,t){const n=e.getNameOrThrow(),i=e.getStaticMethods().filter((e=>e.getReturnType().isClass())).filter((e=>{const t=e.getReturnType().getText();return t.endsWith(`.${n}`)||t===n})).filter((e=>{const t=e.getFirstChildByKindOrThrow(r.SyntaxKind.SyntaxList);return!t.getFirstChildByKind(r.SyntaxKind.PrivateKeyword)&&!t.getFirstChildByKind(r.SyntaxKind.ProtectedKeyword)})),o=[];for(const e of i){const n=e.getParameters(),r=a.getParameterConstructArray(n,t),i={constructKind:"StaticConstructor",methodName:e.getName(),constructParameters:r};o.push(i)}return o}(e,n);if(i.length)for(const e of i){const t=e.getFirstChildByKind(r.SyntaxKind.SyntaxList);if((null==t?void 0:t.getFirstChildByKind(r.SyntaxKind.PrivateKeyword))||(null==t?void 0:t.getFirstChildByKind(r.SyntaxKind.ProtectedKeyword)))continue;const i=e.getParameters(),o=a.getParameterConstructArray(i,n);c.push({constructKind:"constructor",constructParameters:o})}if(c.length>0)return c;c.push({constructKind:"constructor",constructParameters:[]});const d=e.getExtends();if(d){let e=d.getLastChildByKind(r.SyntaxKind.Identifier);e||(e=d.getLastChildByKindOrThrow(r.SyntaxKind.PropertyAccessExpression).getLastChildByKindOrThrow(r.SyntaxKind.Identifier));const t=u(e);return"UnsupportedType"!=t.filePath&&s(d,n),[{constructKind:"InheritsFrom",constructParameters:[{reference:t}]}]}return c},e.interfaceDeclaration=function(t,n){const o=t.getProperties(),a=o.map((e=>i.parseParameter(e.getTypeNodeOrThrow(),n)));t.getIndexSignatures().forEach((e=>{const t=i.ParseType.indexSignature(e,n);a.push(t)})),t.getMethods().forEach((e=>{const t=i.ParseType.functionType(e,n);a.push(t)}));for(var s=0;s<o.length;s++)a[s].key=o[s].getName();return t.getExtends().forEach((t=>{const i=t.getFirstChildByKindOrThrow(r.SyntaxKind.Identifier).getDefinitionNodes()[0];if(r.TypeNode.isInterfaceDeclaration(i)){const t=e.interfaceDeclaration(i,n);a.push.apply(a,t[0].constructParameters)}})),[{constructKind:"TypeLiteral",constructParameters:a}]},e.enumDeclaration=function(e){return[{constructKind:"Enum",constructParameters:e.getMembers().map((e=>{const t=e.getValue();switch(typeof t){case"number":return{key:e.getName(),reference:{filePath:"native",name:`${t}`}};case"string":return{key:e.getName(),reference:{filePath:"native",name:`"${t}"`}};default:return{key:e.getName(),reference:{filePath:"native",name:"undefined"}}}}))}]},e.typeParameterDeclaration=function(e,t){const n=e.getParentOrThrow();return r.TypeNode.isFunctionDeclaration(n)||r.TypeNode.isMethodDeclaration(n)?[{constructKind:"TypeParameter",constructParameters:[],genericParameters:[i.ParseType.typeParameter(e,t)]}]:[]},e.typeOrmDecorators=t}(c||(c={})),t.getReference=u},8496:(e,t)=>{function n(e,t){const{reference:r,typeParameters:i}=e;r.filePath=t(r.filePath),null==i||i.forEach((e=>n(e,t)))}Object.defineProperty(t,"__esModule",{value:!0}),t.transformParametersTypeRepresentationPaths=void 0,t.transformParametersTypeRepresentationPaths=function(e,t){const{globals:r,parameters:i}=e;!function(e,t){Object.keys(e).forEach((r=>{!function(e,t){for(const r in e)for(const i of e[r])for(const e of i.constructParameters)n(e,t)}(e[r],t),r!==t(r)&&(e[t(r)]=e[r],delete e[r])}))}(r,t);for(const e of i)n(e,t)}},5671:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.parseConstructor=void 0;const r=n(874);function i(e){let t=e.getConstructors()[0];if(!t){const t=e.getExtends();if(!t)return;let n=t.getLastChildByKindOrThrow(r.SyntaxKind.Identifier).getDefinitionNodes()[0];if(r.TypeNode.isClassDeclaration(n))return i(n)}return t}t.parseConstructor=function(e,t){const n="string"==typeof e?e:e.getFilePath();this.log("Providing parameters representation of TS file:",n,"at position",t);const{func:o}=this.getFunctionNodeAtOffsetOrThrow(e,t,!0);if(r.TypeNode.isMethodDeclaration(o)){let e=i(o.getParentIfKindOrThrow(r.SyntaxKind.ClassDeclaration));if(e)return{filePath:e.getSourceFile().getFilePath(),startIndex:e.getStart()}}return{filePath:"null",startIndex:-1}}},6156:function(e,t,n){var r=this&&this.__createBinding||(Object.create?function(e,t,n,r){void 0===r&&(r=n),Object.defineProperty(e,r,{enumerable:!0,get:function(){return t[n]}})}:function(e,t,n,r){void 0===r&&(r=n),e[r]=t[n]}),i=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),o=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var n in e)"default"!==n&&Object.prototype.hasOwnProperty.call(e,n)&&r(t,e,n);return i(t,e),t};Object.defineProperty(t,"__esModule",{value:!0}),t.provideParametersRepresentation=void 0;const a=o(n(4343)),s=n(6811);t.provideParametersRepresentation=function(e,t){var n;const r="string"==typeof e?e:e.getFilePath();this.log("Providing parameters representation of TS file:",r,"at position",t);const{func:i}=this.getFunctionNodeAtOffsetOrThrow(e,t,!0),o=null===(n=i.getName)||void 0===n?void 0:n.call(i);this.log("Function name:",o);const c=i.getParameters();var d={};const u=[];let l;c.forEach((e=>{try{const t=s.getParameterConstruct(e,d);u.push(t)}catch(t){this.log(`Fetching parameter definition failed for ${e.getText()}`),u.push({reference:{filePath:"UnsupportedType",name:"any"}})}}));const f=i.getReturnTypeNode();f&&(l=s.parseParameter(f,d));const p={parameters:u,returnType:l,globals:d};return a.transformParametersTypeRepresentationPathsForWindows(p),p}},9604:function(e,t,n){var r=this&&this.__createBinding||(Object.create?function(e,t,n,r){void 0===r&&(r=n),Object.defineProperty(e,r,{enumerable:!0,get:function(){return t[n]}})}:function(e,t,n,r){void 0===r&&(r=n),e[r]=t[n]}),i=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),o=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var n in e)"default"!==n&&Object.prototype.hasOwnProperty.call(e,n)&&r(t,e,n);return i(t,e),t};Object.defineProperty(t,"__esModule",{value:!0}),t.provideParametersRepresentationJS=t.provideParametersRepresentationJS_WithUnions=void 0;const a=n(994),s=n(630),c=o(n(4343));t.provideParametersRepresentationJS_WithUnions=function(e,t){var n,r;const i="string"==typeof e?e:"<inline>";this.log("Providing parameters representation of JS file:",i,"at position",t);const o=s.performance.now(),{sourceFile:c,func:d}=this.getFunctionNodeAtOffsetOrThrow(e,t,!0),u=s.performance.now(),{parameterTypes:l,performance:f}=(null===(r=(n=d).getName)||void 0===r||r.call(n),a.inferTypeOfParameters(this.project,c,d));return{parameters:l,performance:[{step:"getFunctionNode",ms:u-o},{step:"inferTypes",ms:s.performance.now()-u},...f]}},t.provideParametersRepresentationJS=function(e,t){const{parameters:n,performance:r}=this.provideParametersRepresentationJS_WithUnions(e,t),i={parameters:n.map((e=>{return(t=e)&&0!==t.length?{reference:{filePath:"native",name:t[0]}}:{reference:{filePath:"native",name:"any"}};var t})),globals:{},performance:r};return c.transformParametersTypeRepresentationPathsForWindows(i),i}},3715:function(e,t,n){var r=this&&this.__createBinding||(Object.create?function(e,t,n,r){void 0===r&&(r=n),Object.defineProperty(e,r,{enumerable:!0,get:function(){return t[n]}})}:function(e,t,n,r){void 0===r&&(r=n),e[r]=t[n]}),i=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),o=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var n in e)"default"!==n&&Object.prototype.hasOwnProperty.call(e,n)&&r(t,e,n);return i(t,e),t},a=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.resolveModuleName=void 0;const s=a(n(2357)),c=n(874),d=o(n(4343));t.resolveModuleName=function(e,t){let n=c.ts.resolveModuleName(e,t,this.project.getCompilerOptions(),c.ts.sys);if(n.resolvedModule)return{resolvedModule:{resolvedFilePath:d.windowsPathTransformer(n.resolvedModule.resolvedFileName)},failedLookupLocations:void 0};{const e=n.failedLookupLocations||[];return s.default(Array.isArray(e)),{resolvedModule:void 0,failedLookupLocations:e}}}},4343:function(e,t,n){var r=this&&this.__createBinding||(Object.create?function(e,t,n,r){void 0===r&&(r=n),Object.defineProperty(e,r,{enumerable:!0,get:function(){return t[n]}})}:function(e,t,n,r){void 0===r&&(r=n),e[r]=t[n]}),i=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),o=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var n in e)"default"!==n&&Object.prototype.hasOwnProperty.call(e,n)&&r(t,e,n);return i(t,e),t},a=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.transformParametersTypeRepresentationPathsForWindows=t.windowsPathTransformer=t.getFunctionNodeAtOffsetOrThrow=t.isFunctionNode=t.getFunctionKinds=void 0;const s=a(n(5622)),c=n(874),d=o(n(8496));function u(e){const t=[c.SyntaxKind.FunctionDeclaration,c.SyntaxKind.FunctionExpression,c.SyntaxKind.MethodDeclaration,c.SyntaxKind.ArrowFunction];return e?[...t,c.SyntaxKind.Constructor]:t}function l(e,t){return u(t).includes(e.getKind())}t.getFunctionKinds=u,t.isFunctionNode=l,t.getFunctionNodeAtOffsetOrThrow=function(e,t,n){"object"!=typeof e&&(this.addSourceFileAtPath(e),e=this.project.getSourceFileOrThrow(e)),e.refreshFromFileSystemSync();const r=e.getDescendantAtPos(t);if(!r)throw new Error(`No child found at position ${t}`);let i,o=r;for(;;){if(o=o.getParent(),!o)throw new Error(`No function found at position ${t}`);if(l(o,n)){i=o;break}}return{sourceFile:e,func:i}},t.windowsPathTransformer=e=>s.default===s.default.win32?e.replace(/\//g,"\\"):e,t.transformParametersTypeRepresentationPathsForWindows=function(e){d.transformParametersTypeRepresentationPaths(e,t.windowsPathTransformer)}},5419:function(e,t,n){var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const i=r(n(7728)),o=JSON.parse(process.argv[2]);if(3!==process.argv.length)throw new Error("Bad configuration");new i.default(o)},7728:function(e,t,n){var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const i=r(n(1058)),o=r(n(5151));t.default=class{constructor(e){console.error("Starting language service server"),this.engine=new o.default(e),i.default.createInterface({input:process.stdin}).on("line",(e=>{e.split("\n").forEach((e=>{if(!e)return;let t;try{t=JSON.parse(e)}catch(t){throw console.error(`Failed to parse JSON: """${e}""""`),t}this.onReceiveCommand(t)}))}))}async onReceiveCommand(e){let t;try{t=await this.handleCommand(e)}catch(n){t={seq:e.seq,type:"crash",message:"string"==typeof n.message?n.message:"<non-string error message>"},console.error(n)}process.stdout.write(JSON.stringify(t)+"\n")}async handleCommand(e){switch(e.type){case"resolveModuleName":return{seq:e.seq,type:"resolveModuleName",result:this.engine.resolveModuleName(e.moduleName,e.containingFile)};case"addSourceFile":return this.engine.addSourceFileAtPath(e.filePath,e.preEmit),{seq:e.seq,type:"ok"};case"provideParametersRepresentation":{const t=this.engine.provideParametersRepresentation(e.tsFilePath,e.functionOffset);return{seq:e.seq,type:"provideParametersRepresentation",representation:t}}case"provideParametersRepresentationJS":{const t=this.engine.provideParametersRepresentationJS(e.jsFilePath,e.functionOffset);return{seq:e.seq,type:"provideParametersRepresentation",representation:t}}case"isFunction":return{seq:e.seq,type:"isFunction",isFunction:this.engine.isFunction(e.code)};case"findFunctionReferences":{const t=this.engine.findFunctionReferences(e.tsFilePath,e.functionOffset,e.sourceFiles);return{seq:e.seq,type:"findFunctionReferences",representation:t}}case"findParametersReferences":{const t=this.engine.findParametersReference(e.tsFilePath,e.functionOffset,e.sourceFiles);return{seq:e.seq,type:"findParametersReferences",representation:t}}case"findParameterTypeNodesPositions":{const t=this.engine.findParameterTypeNodesPositions(e.tsFilePath,e.functionOffset);return{seq:e.seq,type:"findParameterTypeNodesPositions",representation:t}}case"parseConstructor":{const t=this.engine.parseConstructor(e.filePath,e.functionOffset);return{seq:e.seq,type:"parseConstructor",representation:t}}}}}},2357:e=>{e.exports=require("assert")},5622:e=>{e.exports=require("path")},630:e=>{e.exports=require("perf_hooks")},1058:e=>{e.exports=require("readline")},874:e=>{e.exports=require("ts-morph")}},t={};return function n(r){if(t[r])return t[r].exports;var i=t[r]={exports:{}};return e[r].call(i.exports,i,i.exports,n),i.exports}(5419)})();