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AAK,WAAW,GAAG,MAC5D,IAAK,EAAM,OAGS,EAAK,MAAK,GAAuB,UAAhB,EAAI,WAKzC,EAAK,KAAK,CAAC,QAAS,QAAS,SAAU,IAAI,MAC7C,CAEA,mBAAA,CAAoB,EAAM,GACxB,IAAK,EAAK,KAAM,OAGhB,MAAM,EAAO,KAAK,uBAAuB,EAAK,MAC9C,IAAK,EAAM,OAGX,MAAM,EAAc,EAAK,MAAK,GAAuB,UAAhB,EAAI,UAErC,GAAkD,MAAnC,EAAY,SAAS,OAAO,GAC7C,EAAY,SAAW,IAAI,KAE3B,EAAK,KAAK,CAAC,QAAS,QAAS,SAAU,IAAI,MAE/C,CAEA,sBAAA,CAAuB,GACrB,OAAO,EAAS,MACd,KAAK,GAAG,WAAW,cAAe,MAAO,SACzC,KAAK,GAAG,WAAW,cAAe,MAAO,SACzC,KAAK,GAAG,WAAW,eAAgB,MAAO,UAC1C,KAAK,GAAG,WAAW,cAAe,OAAO,EAAS,SAAS,KAE/D,CAEA,eAAA,CAAgB,GAEd,MAAM,GACQ,EADR,GAEC,EAED,EAAU,CACd,OAAQ,GAAG,WAAW,OACtB,WAAW,EACX,OAAQ,GAAG,aAAa,OACxB,uBAAwB,EACxB,IAAK,EAAe,gBAAa,GAInC,OADe,GAAG,gBAAgB,EAAQ,CAAC,gBAAiB,IAC9C,UAChB,EAGF,OAAO,QAAU,IAAI","file":"/npm/esdoc2-typescript-plugin@2.0.0/src/Plugin.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/esdoc2-typescript-plugin@2.0.0/src/Plugin.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","const path = require('path');\nconst ts = require('typescript');\nconst CommentParser = require('esdoc2/out/src/Parser/CommentParser').default;\n\nclass Plugin {\n  constructor() {\n    this._enable = true;\n  }\n\n  onStart(ev) {\n    if (!ev.data.option) return;\n    if ('enable' in ev.data.option) this._enable = ev.data.option.enable;\n  }\n\n  onHandleConfig(ev) {\n    if (!this._enable) return;\n\n    if (!ev.data.config.includes)  ev.data.config.includes = [];\n    ev.data.config.includes.push('\\\\.ts$', '\\\\.js$');\n  }\n\n  onHandleCodeParser(ev) {\n    if (!this._enable) return;\n\n    const esParser = ev.data.parser;\n    const esParserOption = ev.data.parserOption;\n    const filePath = ev.data.filePath;\n\n    // ev.data.parser = this._tsParser.bind(this, esParser, esParserOption, filePath);\n\n    ev.data.parser = (code) =>{\n      try {\n        return this._tsParser(esParser, esParserOption, filePath, code);\n      } catch(e) {\n        console.log(e)\n      }\n    };\n  }\n\n  // https://github.com/Microsoft/TypeScript/blob/master/src/services/transpile.ts#L26\n  _tsParser(esParser, esParserOption, filePath, code) {\n    // return if not typescript\n    if (path.extname(filePath) !== '.ts') return esParser(code);\n\n    // create ast and get target nodes\n    const sourceFile = ts.createSourceFile(filePath, code, ts.ScriptTarget.Latest, true);\n    const nodes = this._getTargetTSNodes(sourceFile);\n\n    // rewrite jsdoc comment\n    nodes.sort((a,b) => b.pos - a.pos); // hack: transpile comment with reverse\n    const codeChars = [...code];\n    for (const node of nodes) {\n      const jsDocNode = this._getJSDocNode( node);\n      if (jsDocNode && jsDocNode.comment) codeChars.splice(jsDocNode.pos, jsDocNode.end - jsDocNode.pos);\n\n      const newComment = this._transpileComment(node, jsDocNode ? jsDocNode.comment : '', code);\n      codeChars.splice(node.pos, 0, newComment);\n    }\n    const newTSCode = codeChars.join('');\n\n    // transpile typescript to es\n    const esCode = this._transpileTS2ES(newTSCode);\n\n    return esParser(esCode);\n  }\n\n  _getTargetTSNodes(sourceFile) {\n    const nodes = [];\n    walk(sourceFile);\n    return nodes;\n\n    function walk(node) {\n      switch (node.kind) {\n        case ts.SyntaxKind.ClassDeclaration:\n        case ts.SyntaxKind.MethodDeclaration:\n        case ts.SyntaxKind.PropertyDeclaration:\n        case ts.SyntaxKind.GetAccessor:\n        case ts.SyntaxKind.SetAccessor:\n        case ts.SyntaxKind.FunctionDeclaration:\n          nodes.push(node);\n          break;\n      }\n\n      ts.forEachChild(node, walk);\n    }\n  }\n\n  _getJSDocNode(node) {\n    if (!node.jsDoc) return null;\n\n    return node.jsDoc[node.jsDoc.length - 1];\n  }\n\n  _transpileComment(node, comment, code) {\n    const esNode = {type: 'CommentBlock', value: `*\\n${comment}`};\n    const tags = CommentParser.parse(esNode);\n\n    this._applyLOC(node, tags, code);\n\n    switch(node.kind) {\n      case ts.SyntaxKind.ClassDeclaration:\n        // do nothing\n        break;\n      case ts.SyntaxKind.MethodDeclaration:\n        this._applyCallableParam(node, tags);\n        this._applyCallableReturn(node, tags);\n        break;\n      case ts.SyntaxKind.PropertyDeclaration:\n        this._applyClassProperty(node, tags);\n        break;\n      case ts.SyntaxKind.GetAccessor:\n        this._applyClassMethodGetter(node, tags);\n        break;\n      case ts.SyntaxKind.SetAccessor:\n        this._applyClassMethodSetter(node, tags);\n        break;\n      case ts.SyntaxKind.FunctionDeclaration:\n        this._applyCallableParam(node, tags);\n        this._applyCallableReturn(node, tags);\n        break;\n    }\n\n    return `\\n/*${CommentParser.buildComment(tags)} */\\n`;\n  }\n\n  _applyLOC(node, tags, code) {\n    let loc = 1;\n    const codeChars = [...code];\n    for (let i = 0; i < node.name.end; i++) {\n      if (codeChars[i] === '\\n') loc++;\n    }\n    tags.push({tagName: '@lineNumber', tagValue: `${loc}`});\n  }\n\n  _applyCallableParam(node, tags) {\n    const types = node.parameters.map(param => {\n      return {\n        type: this._getTypeFromAnnotation(param.type),\n        name: param.name.text\n      };\n    });\n\n    const paramTags = tags.filter(tag => tag.tagName === '@param');\n\n    // merge\n    // case: params without comments\n    if (paramTags.length === 0 && types.length) {\n      const tmp = types.map(({type, name}) => {\n        return {\n          tagName: '@param',\n          tagValue: `{${type}} ${name}`\n        };\n      });\n      tags.push(...tmp);\n      return;\n    }\n\n    // case: params with comments\n    if (paramTags.length === types.length) {\n      for (let i = 0; i < paramTags.length; i++) {\n        const paramTag = paramTags[i];\n        const type = types[i];\n        if (paramTag.tagValue.charAt(0) !== '{') { // does not have type\n          paramTag.tagValue = `{${type.type}} ${paramTag.tagValue}`;\n        }\n      }\n      return;\n    }\n\n    // case: mismatch params and comments\n    throw new Error('mismatch params and comments');\n  }\n\n  _applyCallableReturn(node, tags) {\n    if (!node.type) return;\n\n    // get type\n    const type = this._getTypeFromAnnotation(node.type);\n    if (!type) return;\n\n    // get comments\n    const returnTag = tags.find(tag => tag.tagName === '@return' || tag.tagName === '@returns');\n\n    // merge\n    if (returnTag && returnTag.tagValue.charAt(0) !== '{') { // return with comment but does not have type\n      returnTag.tagValue = `{${type}} ${returnTag.tagValue}`;\n    } else {\n      tags.push({tagName: '@return', tagValue: `{${type}}`});\n    }\n  }\n\n  _applyClassMethodGetter(node, tags) {\n    if (!node.type) return;\n\n    // get type\n    const type = this._getTypeFromAnnotation(node.type);\n    if (!type) return;\n\n    // get comments\n    const typeComment = tags.find(tag => tag.tagName === '@type');\n\n    if (typeComment && typeComment.tagValue.charAt(0) !== '{') { // type with comment but does not have tpe\n      typeComment.tagValue = `{${type}}`;\n    } else {\n      tags.push({tagName: '@type', tagValue: `{${type}}`});\n    }\n  }\n\n  _applyClassMethodSetter(node, tags) {\n    if (!node.parameters) return;\n\n    // get type\n    const type = this._getTypeFromAnnotation(node.parameters[0].type);\n    if (!type) return;\n\n    // get comment\n    const typeComment = tags.find(tag => tag.tagName === '@type');\n    if (typeComment) return;\n\n    // merge\n    // case: param without comment\n    tags.push({tagName: '@type', tagValue: `{${type}}`});\n  }\n\n  _applyClassProperty(node, tags) {\n    if (!node.type) return;\n\n    // get type\n    const type = this._getTypeFromAnnotation(node.type);\n    if (!type) return;\n\n    // get comments\n    const typeComment = tags.find(tag => tag.tagName === '@type');\n\n    if (typeComment && typeComment.tagValue.charAt(0) !== '{') { // type with comment but does not have tpe\n      typeComment.tagValue = `{${type}}`;\n    } else {\n      tags.push({tagName: '@type', tagValue: `{${type}}`});\n    }\n  }\n\n  _getTypeFromAnnotation(typeNode) {\n    switch(typeNode.kind) {\n      case ts.SyntaxKind.NumberKeyword: return 'number';\n      case ts.SyntaxKind.StringKeyword: return 'string';\n      case ts.SyntaxKind.BooleanKeyword: return 'boolean';\n      case ts.SyntaxKind.TypeReference: return typeNode.typeName.text;\n    }\n  }\n\n  _transpileTS2ES(tsCode) {\n    // todo\n    const esOption = {\n      decorators: true,\n      jsx: true,\n    };\n    const options = {\n      module: ts.ModuleKind.ES2015,\n      noResolve: true,\n      target: ts.ScriptTarget.Latest,\n      experimentalDecorators: esOption.decorators,\n      jsx: esOption.jsx ? 'preserve' : undefined,\n    };\n\n    const result = ts.transpileModule(tsCode, {compilerOptions: options});\n    return result.outputText;\n  }\n}\n\nmodule.exports = new Plugin();\n"]}