@teambit/typescript 1.0.107 → 1.0.108

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (86) hide show
  1. package/compiler-options.ts +27 -0
  2. package/dedupe-path.spec.ts +34 -0
  3. package/dist/cmds/write-tsconfig.cmd.d.ts +2 -2
  4. package/dist/compiler-options.d.ts +2 -2
  5. package/dist/extractor-options.d.ts +1 -1
  6. package/dist/identifier-list.d.ts +1 -1
  7. package/dist/identifier.d.ts +3 -3
  8. package/dist/{preview-1703590665075.js → preview-1703647408454.js} +2 -2
  9. package/dist/schema-extractor-context.d.ts +11 -11
  10. package/dist/schema-extractor-context.js +13 -17
  11. package/dist/schema-extractor-context.js.map +1 -1
  12. package/dist/schema-transformer.d.ts +2 -2
  13. package/dist/sourceFileTransformers/export.js +1 -2
  14. package/dist/sourceFileTransformers/export.js.map +1 -1
  15. package/dist/sourceFileTransformers/function.js +2 -3
  16. package/dist/sourceFileTransformers/function.js.map +1 -1
  17. package/dist/sourceFileTransformers/import.js +1 -2
  18. package/dist/sourceFileTransformers/import.js.map +1 -1
  19. package/dist/sourceFileTransformers/index.d.ts +1 -1
  20. package/dist/sourceFileTransformers/transform.js +1 -1
  21. package/dist/sourceFileTransformers/transform.js.map +1 -1
  22. package/dist/transformers/binding-element.js +1 -2
  23. package/dist/transformers/binding-element.js.map +1 -1
  24. package/dist/transformers/class-declaration.js +3 -6
  25. package/dist/transformers/class-declaration.js.map +1 -1
  26. package/dist/transformers/constructor.js +3 -4
  27. package/dist/transformers/constructor.js.map +1 -1
  28. package/dist/transformers/enum-declaration.js +1 -2
  29. package/dist/transformers/enum-declaration.js.map +1 -1
  30. package/dist/transformers/export-declaration.js +5 -7
  31. package/dist/transformers/export-declaration.js.map +1 -1
  32. package/dist/transformers/function-like.js +5 -8
  33. package/dist/transformers/function-like.js.map +1 -1
  34. package/dist/transformers/get-accessor.js +1 -2
  35. package/dist/transformers/get-accessor.js.map +1 -1
  36. package/dist/transformers/import-declaration.js +2 -3
  37. package/dist/transformers/import-declaration.js.map +1 -1
  38. package/dist/transformers/interface-declaration.js +1 -2
  39. package/dist/transformers/interface-declaration.js.map +1 -1
  40. package/dist/transformers/parameter.js +1 -2
  41. package/dist/transformers/parameter.js.map +1 -1
  42. package/dist/transformers/property-declaration.js +1 -2
  43. package/dist/transformers/property-declaration.js.map +1 -1
  44. package/dist/transformers/source-file-transformer.js +3 -5
  45. package/dist/transformers/source-file-transformer.js.map +1 -1
  46. package/dist/transformers/utils/jsdoc-to-doc-schema.js +2 -4
  47. package/dist/transformers/utils/jsdoc-to-doc-schema.js.map +1 -1
  48. package/dist/transformers/utils/parse-type-from-quick-info.js +1 -2
  49. package/dist/transformers/utils/parse-type-from-quick-info.js.map +1 -1
  50. package/dist/transformers/variable-declaration.js +8 -12
  51. package/dist/transformers/variable-declaration.js.map +1 -1
  52. package/dist/tsconfig-writer.d.ts +2 -2
  53. package/dist/tsconfig-writer.js +1 -4
  54. package/dist/tsconfig-writer.js.map +1 -1
  55. package/dist/typescript.composition.d.ts +2 -2
  56. package/dist/typescript.extractor.d.ts +3 -3
  57. package/dist/typescript.extractor.js +5 -7
  58. package/dist/typescript.extractor.js.map +1 -1
  59. package/dist/typescript.main.runtime.d.ts +7 -7
  60. package/dist/typescript.main.runtime.js +1 -2
  61. package/dist/typescript.main.runtime.js.map +1 -1
  62. package/dist/typescript.parser.js +7 -8
  63. package/dist/typescript.parser.js.map +1 -1
  64. package/dist/typescript.parser.spec.js +12 -15
  65. package/dist/typescript.parser.spec.js.map +1 -1
  66. package/export-identifier.ts +14 -0
  67. package/extractor-options.ts +21 -0
  68. package/identifier-list.ts +14 -0
  69. package/identifier.ts +23 -0
  70. package/index.ts +14 -0
  71. package/package.json +27 -34
  72. package/remove-types-task.ts +33 -0
  73. package/schema-extractor-context.ts +625 -0
  74. package/schema-transformer.plugin.ts +14 -0
  75. package/schema-transformer.ts +23 -0
  76. package/transform-source-file.spec.ts +155 -0
  77. package/tsconfig-writer.ts +249 -0
  78. package/tsconfig.json +16 -21
  79. package/types/asset.d.ts +15 -3
  80. package/typescript.aspect.ts +5 -0
  81. package/typescript.compiler.spec.ts +63 -0
  82. package/typescript.compiler.ts +286 -0
  83. package/typescript.extractor.ts +247 -0
  84. package/typescript.main.runtime.ts +442 -0
  85. package/typescript.parser.spec.ts +221 -0
  86. package/typescript.parser.ts +123 -0
@@ -37,9 +37,8 @@ const functionNamesTransformer = mapping => {
37
37
  };
38
38
  const visit = node => {
39
39
  if (_typescript().default.isFunctionDeclaration(node) || _typescript().default.isArrowFunction(node) || _typescript().default.isFunctionExpression(node)) {
40
- var _node$name, _Object$entries$find;
41
- const functionName = ((_node$name = node.name) === null || _node$name === void 0 ? void 0 : _node$name.getText()) ?? '';
42
- const newName = ((_Object$entries$find = Object.entries(mapping).find(([key]) => functionName.includes(key))) === null || _Object$entries$find === void 0 ? void 0 : _Object$entries$find[1]) ?? functionName;
40
+ const functionName = node.name?.getText() ?? '';
41
+ const newName = Object.entries(mapping).find(([key]) => functionName.includes(key))?.[1] ?? functionName;
43
42
  const parameters = node.parameters.map(param => {
44
43
  const newParamType = param.type ? _typescript().default.visitNode(param.type, updateTypeReference) : param.type;
45
44
  if (_typescript().default.isIdentifier(param.name)) {
@@ -1 +1 @@
1
- {"version":3,"names":["_typescript","data","_interopRequireDefault","require","_replaceName","obj","__esModule","default","functionNamesTransformer","mapping","context","updateTypeReference","node","ts","isTypeReferenceNode","typeName","getText","getSourceFile","newTypeName","replaceName","factory","updateTypeReferenceNode","createIdentifier","typeArguments","visitEachChild","e","visit","isFunctionDeclaration","isArrowFunction","isFunctionExpression","_node$name","_Object$entries$find","functionName","name","newName","Object","entries","find","key","includes","parameters","map","param","newParamType","type","visitNode","isIdentifier","oldName","newParamName","keys","updateParameterDeclaration","decorators","modifiers","dotDotDotToken","questionToken","initializer","isObjectBindingPattern","elements","element","newElementName","updateBindingElement","propertyName","createObjectBindingPattern","updatedBody","body","isBlock","updateReturnStatement","updateFunctionDeclaration","asteriskToken","typeParameters","updateArrowFunction","equalsGreaterThanToken","updateFunctionExpression","updatedStatements","statement","statements","isReturnStatement","expression","isJsxElement","jsxElement","openingElement","tagName","newTagName","updatedTagName","updatedOpeningElement","updateJsxOpeningElement","attributes","updatedClosingElement","closingElement","updateJsxClosingElement","createJsxClosingElement","updatedJsxElement","createJsxElement","children","updatedStatement","createReturnStatement","push","updateBlock","isExpressionStatement","text","updatedExpression","updatedReturnStatement","createBlock","exports"],"sources":["function.ts"],"sourcesContent":["import ts from 'typescript';\nimport { SourceFileTransformer } from '.';\nimport { replaceName } from './replaceName';\n\nexport const functionNamesTransformer: SourceFileTransformer = (mapping: Record<string, string>) => {\n return (context) => {\n const updateTypeReference: ts.Visitor = (node) => {\n try {\n if (ts.isTypeReferenceNode(node) && node.typeName) {\n const typeName = node.typeName.getText(node.getSourceFile());\n const newTypeName = replaceName(typeName, mapping);\n if (newTypeName) {\n return ts.factory.updateTypeReferenceNode(\n node,\n ts.factory.createIdentifier(newTypeName),\n node.typeArguments\n );\n }\n }\n return ts.visitEachChild(node, updateTypeReference, context);\n } catch (e) {\n return node;\n }\n };\n\n const visit: ts.Visitor = (node) => {\n if (ts.isFunctionDeclaration(node) || ts.isArrowFunction(node) || ts.isFunctionExpression(node)) {\n const functionName = node.name?.getText() ?? '';\n const newName = Object.entries(mapping).find(([key]) => functionName.includes(key))?.[1] ?? functionName;\n const parameters = node.parameters.map((param) => {\n const newParamType = param.type ? ts.visitNode(param.type, updateTypeReference) : param.type;\n if (ts.isIdentifier(param.name)) {\n const oldName = param.name.getText();\n const newParamName = Object.keys(mapping).find((key) => oldName.includes(key));\n if (newParamName) {\n return ts.factory.updateParameterDeclaration(\n param,\n param.decorators,\n param.modifiers,\n param.dotDotDotToken,\n ts.factory.createIdentifier(newParamName),\n param.questionToken,\n newParamType,\n param.initializer\n );\n }\n } else if (ts.isObjectBindingPattern(param.name)) {\n const elements = param.name.elements.map((element) => {\n const newElementName = mapping[element.name.getText()];\n if (newElementName) {\n return ts.factory.updateBindingElement(\n element,\n element.dotDotDotToken,\n element.propertyName,\n ts.factory.createIdentifier(newElementName),\n element.initializer\n );\n }\n return element;\n });\n const newParamName = ts.factory.createObjectBindingPattern(elements);\n return ts.factory.updateParameterDeclaration(\n param,\n param.decorators,\n param.modifiers,\n param.dotDotDotToken,\n newParamName,\n param.questionToken,\n newParamType,\n param.initializer\n );\n }\n return param;\n });\n\n if (ts.isFunctionDeclaration(node)) {\n const updatedBody = node.body && ts.isBlock(node.body) ? updateReturnStatement(node.body) : node.body;\n return ts.factory.updateFunctionDeclaration(\n node,\n node.decorators,\n node.modifiers,\n node.asteriskToken,\n newName ? ts.factory.createIdentifier(newName) : node.name,\n node.typeParameters,\n parameters,\n node.type,\n updatedBody\n );\n }\n if (ts.isArrowFunction(node)) {\n const updatedBody = node.body && ts.isBlock(node.body) ? updateReturnStatement(node.body) : node.body;\n return ts.factory.updateArrowFunction(\n node,\n node.modifiers,\n node.typeParameters,\n parameters,\n node.type,\n node.equalsGreaterThanToken,\n updatedBody\n );\n }\n if (ts.isFunctionExpression(node)) {\n const updatedBody = node.body && ts.isBlock(node.body) ? updateReturnStatement(node.body) : node.body;\n return ts.factory.updateFunctionExpression(\n node,\n node.modifiers,\n node.asteriskToken,\n newName ? ts.factory.createIdentifier(newName) : node.name,\n node.typeParameters,\n parameters,\n node.type,\n updatedBody\n );\n }\n }\n return ts.visitEachChild(node, visit, context);\n };\n\n function updateReturnStatement(body: ts.ConciseBody): ts.Block {\n if (ts.isBlock(body)) {\n const updatedStatements: ts.Statement[] = [];\n for (const statement of body.statements) {\n if (ts.isReturnStatement(statement) && statement.expression && ts.isJsxElement(statement.expression)) {\n const jsxElement = statement.expression;\n const openingElement = jsxElement.openingElement;\n const tagName = openingElement.tagName.getText();\n const newTagName = mapping[tagName];\n if (newTagName) {\n const updatedTagName = ts.factory.createIdentifier(newTagName);\n const updatedOpeningElement = ts.factory.updateJsxOpeningElement(\n openingElement,\n updatedTagName,\n openingElement.typeArguments,\n openingElement.attributes\n );\n const updatedClosingElement = jsxElement.closingElement\n ? ts.factory.updateJsxClosingElement(jsxElement.closingElement, updatedTagName)\n : ts.factory.createJsxClosingElement(updatedTagName);\n const updatedJsxElement = ts.factory.createJsxElement(\n updatedOpeningElement,\n jsxElement.children,\n updatedClosingElement\n );\n const updatedStatement = ts.factory.createReturnStatement(updatedJsxElement);\n updatedStatements.push(updatedStatement);\n } else {\n updatedStatements.push(statement);\n }\n } else {\n updatedStatements.push(statement);\n }\n }\n return ts.factory.updateBlock(body, updatedStatements);\n }\n if (\n ts.isExpressionStatement(body) &&\n ts.isReturnStatement(body.expression) &&\n body.expression.expression &&\n ts.isIdentifier(body.expression.expression)\n ) {\n const oldName = body.expression.expression.text;\n const newName = mapping[oldName];\n if (newName) {\n const updatedExpression = ts.factory.createIdentifier(newName);\n const updatedReturnStatement = ts.factory.createReturnStatement(updatedExpression);\n return ts.factory.createBlock([updatedReturnStatement], true);\n }\n }\n return ts.factory.createBlock([], true);\n }\n return (node) => ts.visitNode(node, visit);\n };\n};\n"],"mappings":";;;;;;AAAA,SAAAA,YAAA;EAAA,MAAAC,IAAA,GAAAC,sBAAA,CAAAC,OAAA;EAAAH,WAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAEA,SAAAG,aAAA;EAAA,MAAAH,IAAA,GAAAE,OAAA;EAAAC,YAAA,YAAAA,CAAA;IAAA,OAAAH,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAA4C,SAAAC,uBAAAG,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAErC,MAAMG,wBAA+C,GAAIC,OAA+B,IAAK;EAClG,OAAQC,OAAO,IAAK;IAClB,MAAMC,mBAA+B,GAAIC,IAAI,IAAK;MAChD,IAAI;QACF,IAAIC,qBAAE,CAACC,mB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AACa,UAAU,CAAC,IACrCb,IAAI,CAACa,UAAU,CAACA,UAAU,IAC1BhE,qBAAE,CAACiC,YAAY,CAACkB,IAAI,CAACa,UAAU,CAACA,UAAU,CAAC,EAC3C;QACA,MAAM9B,OAAO,GAAGiB,IAAI,CAACa,UAAU,CAACA,UAAU,CAACsB,IAAI;QAC/C,MAAMjE,OAAO,GAAGzB,OAAO,CAACsC,OAAO,CAAC;QAChC,IAAIb,OAAO,EAAE;UACX,MAAMkE,iBAAiB,GAAGvF,qBAAE,CAACO,OAAO,CAACE,gBAAgB,CAACY,OAAO,CAAC;UAC9D,MAAMmE,sBAAsB,GAAGxF,qBAAE,CAACO,OAAO,CAAC2E,qBAAqB,CAACK,iBAAiB,CAAC;UAClF,OAAOvF,qBAAE,CAACO,OAAO,CAACkF,WAAW,CAAC,CAACD,sBAAsB,CAAC,EAAE,IAAI,CAAC;QAC/D;MACF;MACA,OAAOxF,qBAAE,CAACO,OAAO,CAACkF,WAAW,CAAC,EAAE,EAAE,IAAI,CAAC;IACzC;IACA,OAAQ1F,IAAI,IAAKC,qBAAE,CAACgC,SAAS,CAACjC,IAAI,EAAEc,KAAK,CAAC;EAC5C,CAAC;AACH,CAAC;AAAC6E,OAAA,CAAA/F,wBAAA,GAAAA,wBAAA"}
1
+ {"version":3,"names":["_typescript","data","_interopRequireDefault","require","_replaceName","obj","__esModule","default","functionNamesTransformer","mapping","context","updateTypeReference","node","ts","isTypeReferenceNode","typeName","getText","getSourceFile","newTypeName","replaceName","factory","updateTypeReferenceNode","createIdentifier","typeArguments","visitEachChild","e","visit","isFunctionDeclaration","isArrowFunction","isFunctionExpression","functionName","name","newName","Object","entries","find","key","includes","parameters","map","param","newParamType","type","visitNode","isIdentifier","oldName","newParamName","keys","updateParameterDeclaration","decorators","modifiers","dotDotDotToken","questionToken","initializer","isObjectBindingPattern","elements","element","newElementName","updateBindingElement","propertyName","createObjectBindingPattern","updatedBody","body","isBlock","updateReturnStatement","updateFunctionDeclaration","asteriskToken","typeParameters","updateArrowFunction","equalsGreaterThanToken","updateFunctionExpression","updatedStatements","statement","statements","isReturnStatement","expression","isJsxElement","jsxElement","openingElement","tagName","newTagName","updatedTagName","updatedOpeningElement","updateJsxOpeningElement","attributes","updatedClosingElement","closingElement","updateJsxClosingElement","createJsxClosingElement","updatedJsxElement","createJsxElement","children","updatedStatement","createReturnStatement","push","updateBlock","isExpressionStatement","text","updatedExpression","updatedReturnStatement","createBlock","exports"],"sources":["function.ts"],"sourcesContent":["import ts from 'typescript';\nimport { SourceFileTransformer } from '.';\nimport { replaceName } from './replaceName';\n\nexport const functionNamesTransformer: SourceFileTransformer = (mapping: Record<string, string>) => {\n return (context) => {\n const updateTypeReference: ts.Visitor = (node) => {\n try {\n if (ts.isTypeReferenceNode(node) && node.typeName) {\n const typeName = node.typeName.getText(node.getSourceFile());\n const newTypeName = replaceName(typeName, mapping);\n if (newTypeName) {\n return ts.factory.updateTypeReferenceNode(\n node,\n ts.factory.createIdentifier(newTypeName),\n node.typeArguments\n );\n }\n }\n return ts.visitEachChild(node, updateTypeReference, context);\n } catch (e) {\n return node;\n }\n };\n\n const visit: ts.Visitor = (node) => {\n if (ts.isFunctionDeclaration(node) || ts.isArrowFunction(node) || ts.isFunctionExpression(node)) {\n const functionName = node.name?.getText() ?? '';\n const newName = Object.entries(mapping).find(([key]) => functionName.includes(key))?.[1] ?? functionName;\n const parameters = node.parameters.map((param) => {\n const newParamType = param.type ? ts.visitNode(param.type, updateTypeReference) : param.type;\n if (ts.isIdentifier(param.name)) {\n const oldName = param.name.getText();\n const newParamName = Object.keys(mapping).find((key) => oldName.includes(key));\n if (newParamName) {\n return ts.factory.updateParameterDeclaration(\n param,\n param.decorators,\n param.modifiers,\n param.dotDotDotToken,\n ts.factory.createIdentifier(newParamName),\n param.questionToken,\n newParamType,\n param.initializer\n );\n }\n } else if (ts.isObjectBindingPattern(param.name)) {\n const elements = param.name.elements.map((element) => {\n const newElementName = mapping[element.name.getText()];\n if (newElementName) {\n return ts.factory.updateBindingElement(\n element,\n element.dotDotDotToken,\n element.propertyName,\n ts.factory.createIdentifier(newElementName),\n element.initializer\n );\n }\n return element;\n });\n const newParamName = ts.factory.createObjectBindingPattern(elements);\n return ts.factory.updateParameterDeclaration(\n param,\n param.decorators,\n param.modifiers,\n param.dotDotDotToken,\n newParamName,\n param.questionToken,\n newParamType,\n param.initializer\n );\n }\n return param;\n });\n\n if (ts.isFunctionDeclaration(node)) {\n const updatedBody = node.body && ts.isBlock(node.body) ? updateReturnStatement(node.body) : node.body;\n return ts.factory.updateFunctionDeclaration(\n node,\n node.decorators,\n node.modifiers,\n node.asteriskToken,\n newName ? ts.factory.createIdentifier(newName) : node.name,\n node.typeParameters,\n parameters,\n node.type,\n updatedBody\n );\n }\n if (ts.isArrowFunction(node)) {\n const updatedBody = node.body && ts.isBlock(node.body) ? updateReturnStatement(node.body) : node.body;\n return ts.factory.updateArrowFunction(\n node,\n node.modifiers,\n node.typeParameters,\n parameters,\n node.type,\n node.equalsGreaterThanToken,\n updatedBody\n );\n }\n if (ts.isFunctionExpression(node)) {\n const updatedBody = node.body && ts.isBlock(node.body) ? updateReturnStatement(node.body) : node.body;\n return ts.factory.updateFunctionExpression(\n node,\n node.modifiers,\n node.asteriskToken,\n newName ? ts.factory.createIdentifier(newName) : node.name,\n node.typeParameters,\n parameters,\n node.type,\n updatedBody\n );\n }\n }\n return ts.visitEachChild(node, visit, context);\n };\n\n function updateReturnStatement(body: ts.ConciseBody): ts.Block {\n if (ts.isBlock(body)) {\n const updatedStatements: ts.Statement[] = [];\n for (const statement of body.statements) {\n if (ts.isReturnStatement(statement) && statement.expression && ts.isJsxElement(statement.expression)) {\n const jsxElement = statement.expression;\n const openingElement = jsxElement.openingElement;\n const tagName = openingElement.tagName.getText();\n const newTagName = mapping[tagName];\n if (newTagName) {\n const updatedTagName = ts.factory.createIdentifier(newTagName);\n const updatedOpeningElement = ts.factory.updateJsxOpeningElement(\n openingElement,\n updatedTagName,\n openingElement.typeArguments,\n openingElement.attributes\n );\n const updatedClosingElement = jsxElement.closingElement\n ? ts.factory.updateJsxClosingElement(jsxElement.closingElement, updatedTagName)\n : ts.factory.createJsxClosingElement(updatedTagName);\n const updatedJsxElement = ts.factory.createJsxElement(\n updatedOpeningElement,\n jsxElement.children,\n updatedClosingElement\n );\n const updatedStatement = ts.factory.createReturnStatement(updatedJsxElement);\n updatedStatements.push(updatedStatement);\n } else {\n updatedStatements.push(statement);\n }\n } else {\n updatedStatements.push(statement);\n }\n }\n return ts.factory.updateBlock(body, updatedStatements);\n }\n if (\n ts.isExpressionStatement(body) &&\n ts.isReturnStatement(body.expression) &&\n body.expression.expression &&\n ts.isIdentifier(body.expression.expression)\n ) {\n const oldName = body.expression.expression.text;\n const newName = mapping[oldName];\n if (newName) {\n const updatedExpression = ts.factory.createIdentifier(newName);\n const updatedReturnStatement = ts.factory.createReturnStatement(updatedExpression);\n return ts.factory.createBlock([updatedReturnStatement], true);\n }\n }\n return ts.factory.createBlock([], true);\n }\n return (node) => ts.visitNode(node, visit);\n };\n};\n"],"mappings":";;;;;;AAAA,SAAAA,YAAA;EAAA,MAAAC,IAAA,GAAAC,sBAAA,CAAAC,OAAA;EAAAH,WAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAEA,SAAAG,aAAA;EAAA,MAAAH,IAAA,GAAAE,OAAA;EAAAC,YAAA,YAAAA,CAAA;IAAA,OAAAH,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAA4C,SAAAC,uBAAAG,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAErC,MAAMG,wBAA+C,GAAIC,OAA+B,IAAK;EAClG,OAAQC,OAAO,IAAK;IAClB,MAAMC,mBAA+B,GAAIC,IAAI,IAAK;MAChD,IAAI;QACF,IAAIC,qBAAE,CAACC,mBAAmB,CAACF,IAAI,CAAC,IAAIA,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AAGiB,IAAI,CAACa,UAAU,CAACA,UAAU,CAACsB,IAAI;QAC/C,MAAMjE,OAAO,GAAGvB,OAAO,CAACoC,OAAO,CAAC;QAChC,IAAIb,OAAO,EAAE;UACX,MAAMkE,iBAAiB,GAAGrF,qBAAE,CAACO,OAAO,CAACE,gBAAgB,CAACU,OAAO,CAAC;UAC9D,MAAMmE,sBAAsB,GAAGtF,qBAAE,CAACO,OAAO,CAACyE,qBAAqB,CAACK,iBAAiB,CAAC;UAClF,OAAOrF,qBAAE,CAACO,OAAO,CAACgF,WAAW,CAAC,CAACD,sBAAsB,CAAC,EAAE,IAAI,CAAC;QAC/D;MACF;MACA,OAAOtF,qBAAE,CAACO,OAAO,CAACgF,WAAW,CAAC,EAAE,EAAE,IAAI,CAAC;IACzC;IACA,OAAQxF,IAAI,IAAKC,qBAAE,CAAC8B,SAAS,CAAC/B,IAAI,EAAEc,KAAK,CAAC;EAC5C,CAAC;AACH,CAAC;AAAC2E,OAAA,CAAA7F,wBAAA,GAAAA,wBAAA"}
@@ -16,14 +16,13 @@ const importTransformer = mapping => {
16
16
  return context => {
17
17
  const visit = node => {
18
18
  if (_typescript().default.isImportDeclaration(node)) {
19
- var _node$importClause;
20
19
  let moduleSpecifier = node.moduleSpecifier.getText().slice(1, -1);
21
20
  for (const [oldName, newName] of Object.entries(mapping)) {
22
21
  if (moduleSpecifier.includes(oldName)) {
23
22
  moduleSpecifier = moduleSpecifier.replace(oldName, newName);
24
23
  }
25
24
  }
26
- if ((_node$importClause = node.importClause) !== null && _node$importClause !== void 0 && _node$importClause.namedBindings && _typescript().default.isNamedImports(node.importClause.namedBindings)) {
25
+ if (node.importClause?.namedBindings && _typescript().default.isNamedImports(node.importClause.namedBindings)) {
27
26
  const transformedBindings = node.importClause.namedBindings.elements.map(element => {
28
27
  let originalName = element.propertyName ? element.propertyName.text : element.name.text;
29
28
  const aliasName = element.name.text;
@@ -1 +1 @@
1
- {"version":3,"names":["_typescript","data","_interopRequireDefault","require","obj","__esModule","default","importTransformer","mapping","context","visit","node","ts","isImportDeclaration","_node$importClause","moduleSpecifier","getText","slice","oldName","newName","Object","entries","includes","replace","importClause","namedBindings","isNamedImports","transformedBindings","elements","map","element","originalName","propertyName","text","name","aliasName","startsWith","endsWith","factory","updateImportSpecifier","createIdentifier","undefined","updatedImportClause","updateImportClause","isTypeOnly","createNamedImports","updateImportDeclaration","decorators","modifiers","createStringLiteral","isImportEqualsDeclaration","moduleReference","updatedImportEqualsDeclaration","updateImportEqualsDeclaration","createExternalModuleReference","isCallExpression","isIdentifier","expression","firstArg","arguments","isStringLiteral","updatedArg","updateCallExpression","typeArguments","visitEachChild","visitNode","exports"],"sources":["import.ts"],"sourcesContent":["import ts from 'typescript';\nimport { SourceFileTransformer } from '.';\n\nexport const importTransformer: SourceFileTransformer = (mapping: Record<string, string>) => {\n return (context) => {\n const visit: ts.Visitor = (node) => {\n if (ts.isImportDeclaration(node)) {\n let moduleSpecifier = node.moduleSpecifier.getText().slice(1, -1);\n for (const [oldName, newName] of Object.entries(mapping)) {\n if (moduleSpecifier.includes(oldName)) {\n moduleSpecifier = moduleSpecifier.replace(oldName, newName);\n }\n }\n\n if (node.importClause?.namedBindings && ts.isNamedImports(node.importClause.namedBindings)) {\n const transformedBindings = node.importClause.namedBindings.elements.map((element) => {\n let originalName = element.propertyName ? element.propertyName.text : element.name.text;\n const aliasName = element.name.text;\n\n for (const [oldName, newName] of Object.entries(mapping)) {\n if (originalName.startsWith(oldName) || originalName.endsWith(oldName)) {\n originalName = originalName.replace(oldName, newName);\n }\n }\n\n return ts.factory.updateImportSpecifier(\n element,\n false,\n element.propertyName ? ts.factory.createIdentifier(originalName) : undefined,\n ts.factory.createIdentifier(aliasName)\n );\n });\n\n const updatedImportClause = ts.factory.updateImportClause(\n node.importClause,\n node.importClause.isTypeOnly,\n node.importClause.name,\n ts.factory.createNamedImports(transformedBindings)\n );\n\n return ts.factory.updateImportDeclaration(\n node,\n node.decorators,\n node.modifiers,\n updatedImportClause,\n ts.factory.createStringLiteral(moduleSpecifier),\n undefined\n );\n }\n\n return ts.factory.updateImportDeclaration(\n node,\n node.decorators,\n node.modifiers,\n node.importClause,\n ts.factory.createStringLiteral(moduleSpecifier),\n undefined\n );\n }\n if (ts.isImportEqualsDeclaration(node)) {\n let moduleSpecifier = node.moduleReference.getText().slice(1, -1);\n for (const [oldName, newName] of Object.entries(mapping)) {\n if (moduleSpecifier.includes(oldName)) {\n moduleSpecifier = moduleSpecifier.replace(oldName, newName);\n }\n }\n\n const updatedImportEqualsDeclaration = ts.factory.updateImportEqualsDeclaration(\n node,\n node.decorators,\n node.modifiers,\n node.isTypeOnly,\n node.name,\n ts.factory.createExternalModuleReference(ts.factory.createStringLiteral(moduleSpecifier))\n );\n\n return updatedImportEqualsDeclaration;\n }\n\n if (ts.isCallExpression(node) && ts.isIdentifier(node.expression) && node.expression.text === 'require') {\n const [firstArg] = node.arguments;\n\n if (ts.isStringLiteral(firstArg)) {\n let moduleSpecifier = firstArg.text;\n\n for (const [oldName, newName] of Object.entries(mapping)) {\n if (moduleSpecifier.includes(oldName)) {\n moduleSpecifier = moduleSpecifier.replace(oldName, newName);\n }\n }\n\n const updatedArg = ts.factory.createStringLiteral(moduleSpecifier);\n return ts.factory.updateCallExpression(node, node.expression, node.typeArguments, [\n updatedArg,\n ...node.arguments.slice(1),\n ]);\n }\n }\n\n return ts.visitEachChild(node, visit, context);\n };\n return (node) => ts.visitNode(node, visit);\n };\n};\n"],"mappings":";;;;;;AAAA,SAAAA,YAAA;EAAA,MAAAC,IAAA,GAAAC,sBAAA,CAAAC,OAAA;EAAAH,WAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAA4B,SAAAC,uBAAAE,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAGrB,MAAMG,iBAAwC,GAAIC,OAA+B,IAAK;EAC3F,OAAQC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8C,UAAU,EAAE9C,IAAI,CAACoD,aAAa,EAAE,CAChFF,UAAU,EACV,GAAGlD,IAAI,CAACgD,SAAS,CAAC1C,KAAK,CAAC,CAAC,CAAC,CAC3B,CAAC;QACJ;MACF;MAEA,OAAOL,qBAAE,CAACoD,cAAc,CAACrD,IAAI,EAAED,KAAK,EAAED,OAAO,CAAC;IAChD,CAAC;IACD,OAAQE,IAAI,IAAKC,qBAAE,CAACqD,SAAS,CAACtD,IAAI,EAAED,KAAK,CAAC;EAC5C,CAAC;AACH,CAAC;AAACwD,OAAA,CAAA3D,iBAAA,GAAAA,iBAAA"}
1
+ {"version":3,"names":["_typescript","data","_interopRequireDefault","require","obj","__esModule","default","importTransformer","mapping","context","visit","node","ts","isImportDeclaration","moduleSpecifier","getText","slice","oldName","newName","Object","entries","includes","replace","importClause","namedBindings","isNamedImports","transformedBindings","elements","map","element","originalName","propertyName","text","name","aliasName","startsWith","endsWith","factory","updateImportSpecifier","createIdentifier","undefined","updatedImportClause","updateImportClause","isTypeOnly","createNamedImports","updateImportDeclaration","decorators","modifiers","createStringLiteral","isImportEqualsDeclaration","moduleReference","updatedImportEqualsDeclaration","updateImportEqualsDeclaration","createExternalModuleReference","isCallExpression","isIdentifier","expression","firstArg","arguments","isStringLiteral","updatedArg","updateCallExpression","typeArguments","visitEachChild","visitNode","exports"],"sources":["import.ts"],"sourcesContent":["import ts from 'typescript';\nimport { SourceFileTransformer } from '.';\n\nexport const importTransformer: SourceFileTransformer = (mapping: Record<string, string>) => {\n return (context) => {\n const visit: ts.Visitor = (node) => {\n if (ts.isImportDeclaration(node)) {\n let moduleSpecifier = node.moduleSpecifier.getText().slice(1, -1);\n for (const [oldName, newName] of Object.entries(mapping)) {\n if (moduleSpecifier.includes(oldName)) {\n moduleSpecifier = moduleSpecifier.replace(oldName, newName);\n }\n }\n\n if (node.importClause?.namedBindings && ts.isNamedImports(node.importClause.namedBindings)) {\n const transformedBindings = node.importClause.namedBindings.elements.map((element) => {\n let originalName = element.propertyName ? element.propertyName.text : element.name.text;\n const aliasName = element.name.text;\n\n for (const [oldName, newName] of Object.entries(mapping)) {\n if (originalName.startsWith(oldName) || originalName.endsWith(oldName)) {\n originalName = originalName.replace(oldName, newName);\n }\n }\n\n return ts.factory.updateImportSpecifier(\n element,\n false,\n element.propertyName ? ts.factory.createIdentifier(originalName) : undefined,\n ts.factory.createIdentifier(aliasName)\n );\n });\n\n const updatedImportClause = ts.factory.updateImportClause(\n node.importClause,\n node.importClause.isTypeOnly,\n node.importClause.name,\n ts.factory.createNamedImports(transformedBindings)\n );\n\n return ts.factory.updateImportDeclaration(\n node,\n node.decorators,\n node.modifiers,\n updatedImportClause,\n ts.factory.createStringLiteral(moduleSpecifier),\n undefined\n );\n }\n\n return ts.factory.updateImportDeclaration(\n node,\n node.decorators,\n node.modifiers,\n node.importClause,\n ts.factory.createStringLiteral(moduleSpecifier),\n undefined\n );\n }\n if (ts.isImportEqualsDeclaration(node)) {\n let moduleSpecifier = node.moduleReference.getText().slice(1, -1);\n for (const [oldName, newName] of Object.entries(mapping)) {\n if (moduleSpecifier.includes(oldName)) {\n moduleSpecifier = moduleSpecifier.replace(oldName, newName);\n }\n }\n\n const updatedImportEqualsDeclaration = ts.factory.updateImportEqualsDeclaration(\n node,\n node.decorators,\n node.modifiers,\n node.isTypeOnly,\n node.name,\n ts.factory.createExternalModuleReference(ts.factory.createStringLiteral(moduleSpecifier))\n );\n\n return updatedImportEqualsDeclaration;\n }\n\n if (ts.isCallExpression(node) && ts.isIdentifier(node.expression) && node.expression.text === 'require') {\n const [firstArg] = node.arguments;\n\n if (ts.isStringLiteral(firstArg)) {\n let moduleSpecifier = firstArg.text;\n\n for (const [oldName, newName] of Object.entries(mapping)) {\n if (moduleSpecifier.includes(oldName)) {\n moduleSpecifier = moduleSpecifier.replace(oldName, newName);\n }\n }\n\n const updatedArg = ts.factory.createStringLiteral(moduleSpecifier);\n return ts.factory.updateCallExpression(node, node.expression, node.typeArguments, [\n updatedArg,\n ...node.arguments.slice(1),\n ]);\n }\n }\n\n return ts.visitEachChild(node, visit, context);\n };\n return (node) => ts.visitNode(node, visit);\n };\n};\n"],"mappings":";;;;;;AAAA,SAAAA,YAAA;EAAA,MAAAC,IAAA,GAAAC,sBAAA,CAAAC,OAAA;EAAAH,WAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAA4B,SAAAC,uBAAAE,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAGrB,MAAMG,iBAAwC,GAAIC,OAA+B,IAAK;EAC3F,OAAQC,OAAO,IAAK;IAClB,MAAMC,KAAiB,GAAIC,IAAI,IAAK;MAClC,IAAIC,qBAAE,CAACC,mBAAmB,CAACF,IAAI,CAAC,EAAE;QAChC,IAAIG,eAAe,GAAGH,IAAI,CAACG,eAAe,CAACC,OAAO,CAAC,CAAC,CAACC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;QACjE,KAAK,MAAM,CAACC,OAAO,EAAEC,OAAO,CAAC,IAAIC,MAAM,CAACC,OAAO,CAACZ,OAAO,CAAC,EAAE;UACxD,IAAIM,eAAe,CAACO,QAAQ,CAACJ,OAAO,CAAC,EAAE;YACrCH,eAAe,GAAGA,eAAe,CAACQ,OAAO,CAACL,OAAO,EAAEC,OAAO,CAAC;UAC7D;QACF;QAEA,IAAIP,IAAI,CAACY,YAAY,EAAEC,aAAa,IAAIZ,qBAAE,CAACa,cAAc,CAACd,IAAI,CAACY,YAAY,CAACC,aAAa,CAAC,EAAE;UAC1F,MAAME,mBAAmB,GAAGf,IAAI,CAACY,YAAY,CAACC,aAAa,CAACG,QAAQ,CAACC,GAAG,CAAEC,OAAO,IAAK;YACpF,IAAIC,YAAY,GAAGD,OAAO,CAACE,YAAY,GAAGF,OAAO,CAACE,YAAY,CAACC,IAAI,GAAGH,OAAO,CAACI,IAAI,CAACD,IAAI;YACv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AACZ,OAAO,CAAC,EAAE;YACxD,IAAIM,eAAe,CAACO,QAAQ,CAACJ,OAAO,CAAC,EAAE;cACrCH,eAAe,GAAGA,eAAe,CAACQ,OAAO,CAACL,OAAO,EAAEC,OAAO,CAAC;YAC7D;UACF;UAEA,MAAM0C,UAAU,GAAGhD,qBAAE,CAACyB,OAAO,CAACW,mBAAmB,CAAClC,eAAe,CAAC;UAClE,OAAOF,qBAAE,CAACyB,OAAO,CAACwB,oBAAoB,CAAClD,IAAI,EAAEA,IAAI,CAAC6C,UAAU,EAAE7C,IAAI,CAACmD,aAAa,EAAE,CAChFF,UAAU,EACV,GAAGjD,IAAI,CAAC+C,SAAS,CAAC1C,KAAK,CAAC,CAAC,CAAC,CAC3B,CAAC;QACJ;MACF;MAEA,OAAOJ,qBAAE,CAACmD,cAAc,CAACpD,IAAI,EAAED,KAAK,EAAED,OAAO,CAAC;IAChD,CAAC;IACD,OAAQE,IAAI,IAAKC,qBAAE,CAACoD,SAAS,CAACrD,IAAI,EAAED,KAAK,CAAC;EAC5C,CAAC;AACH,CAAC;AAACuD,OAAA,CAAA1D,iBAAA,GAAAA,iBAAA"}
@@ -1,5 +1,5 @@
1
1
  import ts from 'typescript';
2
- export declare type SourceFileTransformer = (mapping: Record<string, string>) => ts.TransformerFactory<ts.SourceFile>;
2
+ export type SourceFileTransformer = (mapping: Record<string, string>) => ts.TransformerFactory<ts.SourceFile>;
3
3
  export { classNamesTransformer } from './class';
4
4
  export { interfaceNamesTransformer } from './interface';
5
5
  export { variableNamesTransformer } from './variable';
@@ -64,7 +64,7 @@ async function transformSourceFile(sourceFilePath, sourceFileContent, transforme
64
64
  const regex = new RegExp(emptyLineComment, 'g');
65
65
  transformedSourceFileStr = transformedSourceFileStr.replace(regex, '');
66
66
  try {
67
- const formattedSourceFileStr = await (formatter === null || formatter === void 0 ? void 0 : formatter.formatSnippet(transformedSourceFileStr, sourceFilePath));
67
+ const formattedSourceFileStr = await formatter?.formatSnippet(transformedSourceFileStr, sourceFilePath);
68
68
  return formattedSourceFileStr || transformedSourceFileStr;
69
69
  } catch {
70
70
  // We can ignore if the formatter fails
@@ -1 +1 @@
1
- {"version":3,"names":["_typescript","data","_interopRequireDefault","require","path","_interopRequireWildcard","_emptyLineEncoder","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","prototype","hasOwnProperty","call","i","set","obj","transformSourceFile","sourceFilePath","sourceFileContent","transformers","formatter","updates","ext","extname","compatibleExts","includes","transformed","entries","forEach","oldStr","newStr","oldStringRegex","RegExp","replace","encoder","EmptyLineEncoder","encode","sourceFile","ts","createSourceFile","ScriptTarget","Latest","ScriptKind","TSX","transformedResult","transform","transformedSourceFile","printer","createPrinter","removeComments","transformedSourceFileStr","printFile","decode","emptyLineComment","emptyLineMarker","regex","formattedSourceFileStr","formatSnippet"],"sources":["transform.ts"],"sourcesContent":["import { Formatter } from '@teambit/formatter';\nimport ts from 'typescript';\nimport * as path from 'path';\nimport { EmptyLineEncoder } from './empty-line-encoder';\n/**\n * Transforms a TypeScript source file using the provided transformer.\n *\n * @param sourceFilePath Path to the TypeScript source file.\n * @param sourceFileContent The content of the source file.\n * @param transformers The transformers to be applied on the source file.\n * @param formatter (Optional) An optional formatter to format the transformed code. If no formatter is provided, the function returns the transformed source file as a string without any formatting.\n * @returns A promise that resolves to the transformed source file as a string.\n */\nexport async function transformSourceFile(\n sourceFilePath: string,\n sourceFileContent: string,\n transformers: ts.TransformerFactory<ts.SourceFile>[],\n formatter?: Formatter,\n updates?: Record<string, string>\n): Promise<string> {\n const ext = path.extname(sourceFilePath);\n const compatibleExts = ['.ts', '.tsx', '.js', '.jsx'];\n if (!compatibleExts.includes(ext)) {\n if (!updates) return sourceFileContent;\n let transformed = sourceFileContent;\n Object.entries(updates).forEach(([oldStr, newStr]) => {\n const oldStringRegex = new RegExp(oldStr, 'g');\n transformed = transformed.replace(oldStringRegex, newStr);\n });\n return transformed;\n }\n\n const encoder = new EmptyLineEncoder();\n sourceFileContent = encoder.encode(sourceFileContent);\n\n const sourceFile = ts.createSourceFile(\n sourceFilePath,\n sourceFileContent,\n ts.ScriptTarget.Latest,\n true,\n ts.ScriptKind.TSX\n );\n\n const transformedResult: ts.TransformationResult<ts.SourceFile> = ts.transform<ts.SourceFile>(\n sourceFile,\n transformers\n );\n const transformedSourceFile: ts.SourceFile = transformedResult.transformed[0] as ts.SourceFile;\n\n const printer: ts.Printer = ts.createPrinter({\n removeComments: false,\n });\n\n let transformedSourceFileStr = printer.printFile(transformedSourceFile);\n transformedSourceFileStr = encoder.decode(transformedSourceFileStr);\n // Remove trailing empty line markers\n const emptyLineComment = `\\\\s*\\\\/\\\\*${encoder.emptyLineMarker}\\\\*\\\\/\\\\s*$`;\n const regex = new RegExp(emptyLineComment, 'g');\n transformedSourceFileStr = transformedSourceFileStr.replace(regex, '');\n\n try {\n const formattedSourceFileStr = await formatter?.formatSnippet(transformedSourceFileStr, sourceFilePath);\n return formattedSourceFileStr || transformedSourceFileStr;\n } catch {\n // We can ignore if the formatter fails\n // TODO: log the error\n // ignore\n }\n return transformedSourceFileStr;\n}\n"],"mappings":";;;;;;AACA,SAAAA,YAAA;EAAA,MAAAC,IAAA,GAAAC,sBAAA,CAAAC,OAAA;EAAAH,WAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAG,KAAA;EAAA,MAAAH,IAAA,GAAAI,uBAAA,CAAAF,OAAA;EAAAC,IAAA,YAAAA,CAAA;IAAA,OAAAH,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAK,kBAAA;EAAA,MAAAL,IAAA,GAAAE,OAAA;EAAAG,iBAAA,YAAAA,CAAA;IAAA,OAAAL,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAAwD,SAAAM,yBAAAC,CAAA,6BAAAC,OAAA,mBAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA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AC;EACvEI,wBAAwB,GAAGhB,OAAO,CAACkB,MAAM,CAACF,wBAAwB,CAAC;EACnE;EACA,MAAMG,gBAAgB,GAAI,aAAYnB,OAAO,CAACoB,eAAgB,aAAY;EAC1E,MAAMC,KAAK,GAAG,IAAIvB,MAAM,CAACqB,gBAAgB,EAAE,GAAG,CAAC;EAC/CH,wBAAwB,GAAGA,wBAAwB,CAACjB,OAAO,CAACsB,KAAK,EAAE,EAAE,CAAC;EAEtE,IAAI;IACF,MAAMC,sBAAsB,GAAG,OAAMpC,SAAS,aAATA,SAAS,uBAATA,SAAS,CAAEqC,aAAa,CAACP,wBAAwB,EAAEjC,cAAc,CAAC;IACvG,OAAOuC,sBAAsB,IAAIN,wBAAwB;EAC3D,CAAC,CAAC,MAAM;IACN;IACA;IACA;EAAA;EAEF,OAAOA,wBAAwB;AACjC"}
1
+ {"version":3,"names":["_typescript","data","_interopRequireDefault","require","path","_interopRequireWildcard","_emptyLineEncoder","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","prototype","hasOwnProperty","call","i","set","obj","transformSourceFile","sourceFilePath","sourceFileContent","transformers","formatter","updates","ext","extname","compatibleExts","includes","transformed","entries","forEach","oldStr","newStr","oldStringRegex","RegExp","replace","encoder","EmptyLineEncoder","encode","sourceFile","ts","createSourceFile","ScriptTarget","Latest","ScriptKind","TSX","transformedResult","transform","transformedSourceFile","printer","createPrinter","removeComments","transformedSourceFileStr","printFile","decode","emptyLineComment","emptyLineMarker","regex","formattedSourceFileStr","formatSnippet"],"sources":["transform.ts"],"sourcesContent":["import { Formatter } from '@teambit/formatter';\nimport ts from 'typescript';\nimport * as path from 'path';\nimport { EmptyLineEncoder } from './empty-line-encoder';\n/**\n * Transforms a TypeScript source file using the provided transformer.\n *\n * @param sourceFilePath Path to the TypeScript source file.\n * @param sourceFileContent The content of the source file.\n * @param transformers The transformers to be applied on the source file.\n * @param formatter (Optional) An optional formatter to format the transformed code. If no formatter is provided, the function returns the transformed source file as a string without any formatting.\n * @returns A promise that resolves to the transformed source file as a string.\n */\nexport async function transformSourceFile(\n sourceFilePath: string,\n sourceFileContent: string,\n transformers: ts.TransformerFactory<ts.SourceFile>[],\n formatter?: Formatter,\n updates?: Record<string, string>\n): Promise<string> {\n const ext = path.extname(sourceFilePath);\n const compatibleExts = ['.ts', '.tsx', '.js', '.jsx'];\n if (!compatibleExts.includes(ext)) {\n if (!updates) return sourceFileContent;\n let transformed = sourceFileContent;\n Object.entries(updates).forEach(([oldStr, newStr]) => {\n const oldStringRegex = new RegExp(oldStr, 'g');\n transformed = transformed.replace(oldStringRegex, newStr);\n });\n return transformed;\n }\n\n const encoder = new EmptyLineEncoder();\n sourceFileContent = encoder.encode(sourceFileContent);\n\n const sourceFile = ts.createSourceFile(\n sourceFilePath,\n sourceFileContent,\n ts.ScriptTarget.Latest,\n true,\n ts.ScriptKind.TSX\n );\n\n const transformedResult: ts.TransformationResult<ts.SourceFile> = ts.transform<ts.SourceFile>(\n sourceFile,\n transformers\n );\n const transformedSourceFile: ts.SourceFile = transformedResult.transformed[0] as ts.SourceFile;\n\n const printer: ts.Printer = ts.createPrinter({\n removeComments: false,\n });\n\n let transformedSourceFileStr = printer.printFile(transformedSourceFile);\n transformedSourceFileStr = encoder.decode(transformedSourceFileStr);\n // Remove trailing empty line markers\n const emptyLineComment = `\\\\s*\\\\/\\\\*${encoder.emptyLineMarker}\\\\*\\\\/\\\\s*$`;\n const regex = new RegExp(emptyLineComment, 'g');\n transformedSourceFileStr = transformedSourceFileStr.replace(regex, '');\n\n try {\n const formattedSourceFileStr = await formatter?.formatSnippet(transformedSourceFileStr, sourceFilePath);\n return formattedSourceFileStr || transformedSourceFileStr;\n } catch {\n // We can ignore if the formatter fails\n // TODO: log the error\n // ignore\n }\n return transformedSourceFileStr;\n}\n"],"mappings":";;;;;;AACA,SAAAA,YAAA;EAAA,MAAAC,IAAA,GAAAC,sBAAA,CAAAC,OAA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gB,CACpCtB,cAAc,EACdC,iBAAiB,EACjBoB,qBAAE,CAACE,YAAY,CAACC,MAAM,EACtB,IAAI,EACJH,qBAAE,CAACI,UAAU,CAACC,GAChB,CAAC;EAED,MAAMC,iBAAyD,GAAGN,qBAAE,CAACO,SAAS,CAC5ER,UAAU,EACVlB,YACF,CAAC;EACD,MAAM2B,qBAAoC,GAAGF,iBAAiB,CAAClB,WAAW,CAAC,CAAC,CAAkB;EAE9F,MAAMqB,OAAmB,GAAGT,qBAAE,CAACU,aAAa,CAAC;IAC3CC,cAAc,EAAE;EAClB,CAAC,CAAC;EAEF,IAAIC,wBAAwB,GAAGH,OAAO,CAACI,SAAS,CAACL,qBAAqB,CAAC;EACvEI,wBAAwB,GAAGhB,OAAO,CAACkB,MAAM,CAACF,wBAAwB,CAAC;EACnE;EACA,MAAMG,gBAAgB,GAAI,aAAYnB,OAAO,CAACoB,eAAgB,aAAY;EAC1E,MAAMC,KAAK,GAAG,IAAIvB,MAAM,CAACqB,gBAAgB,EAAE,GAAG,CAAC;EAC/CH,wBAAwB,GAAGA,wBAAwB,CAACjB,OAAO,CAACsB,KAAK,EAAE,EAAE,CAAC;EAEtE,IAAI;IACF,MAAMC,sBAAsB,GAAG,MAAMpC,SAAS,EAAEqC,aAAa,CAACP,wBAAwB,EAAEjC,cAAc,CAAC;IACvG,OAAOuC,sBAAsB,IAAIN,wBAAwB;EAC3D,CAAC,CAAC,MAAM;IACN;IACA;IACA;EAAA;EAEF,OAAOA,wBAAwB;AACjC"}
@@ -48,10 +48,9 @@ class BindingElementTransformer {
48
48
  return [new (_identifier().Identifier)(node.name.getText(), node.getSourceFile().fileName)];
49
49
  }
50
50
  async transform(node, context) {
51
- var _info$body;
52
51
  const name = node.name.getText();
53
52
  const info = await context.getQuickInfo(node.name);
54
- const displaySig = (info === null || info === void 0 || (_info$body = info.body) === null || _info$body === void 0 ? void 0 : _info$body.displayString) || '';
53
+ const displaySig = info?.body?.displayString || '';
55
54
  const typeStr = (0, _parseTypeFromQuickInfo().parseTypeFromQuickInfo)(info);
56
55
  const type = await context.resolveType(node, typeStr);
57
56
  const doc = await context.jsDocToDocSchema(node);
@@ -1 +1 @@
1
- {"version":3,"names":["_typescript","data","_interopRequireDefault","require","_semanticsEntities","_parseTypeFromQuickInfo","_identifier","obj","__esModule","default","BindingElementTransformer","predicate","node","kind","ts","SyntaxKind","BindingElement","getIdentifiers","Identifier","name","getText","getSourceFile","fileName","transform","context","_info$body","info","getQuickInfo","displaySig","body","displayString","typeStr","parseTypeFromQuickInfo","type","resolveType","doc","jsDocToDocSchema","defaultValue","initializer","undefined","VariableLikeSchema","getLocation","exports"],"sources":["binding-element.ts"],"sourcesContent":["import ts, { BindingElement, Node } from 'typescript';\nimport { VariableLikeSchema } from '@teambit/semantics.entities.semantic-schema';\nimport { SchemaTransformer } from '../schema-transformer';\nimport { SchemaExtractorContext } from '../schema-extractor-context';\nimport { parseTypeFromQuickInfo } from './utils/parse-type-from-quick-info';\nimport { Identifier } from '../identifier';\n\n/**\n * for example:\n *\n * const objBindingElem = { elem1: 1, elem2: 2 };\n * const { elem1 } = objBindingElem;\n * export { elem1 };\n */\nexport class BindingElementTransformer implements SchemaTransformer {\n predicate(node: Node) {\n return node.kind === ts.SyntaxKind.BindingElement;\n }\n\n async getIdentifiers(node: BindingElement) {\n return [new Identifier(node.name.getText(), node.getSourceFile().fileName)];\n }\n\n async transform(node: BindingElement, context: SchemaExtractorContext) {\n const name = node.name.getText();\n const info = await context.getQuickInfo(node.name);\n const displaySig = info?.body?.displayString || '';\n const typeStr = parseTypeFromQuickInfo(info);\n const type = await context.resolveType(node, typeStr);\n const doc = await context.jsDocToDocSchema(node);\n const defaultValue = node.initializer ? node.initializer.getText() : undefined;\n return new VariableLikeSchema(context.getLocation(node), name, displaySig, type, false, doc, defaultValue);\n }\n}\n"],"mappings":";;;;;;AAAA,SAAAA,YAAA;EAAA,MAAAC,IAAA,GAAAC,sBAAA,CAAAC,OAAA;EAAAH,WAAA,YA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I,cAAAJ,UAAA,uBAAVA,UAAA,CAAYK,aAAa,KAAI,EAAE;IAClD,MAAMC,OAAO,GAAG,IAAAC,gDAAsB,EAACN,IAAI,CAAC;IAC5C,MAAMO,IAAI,GAAG,MAAMT,OAAO,CAACU,WAAW,CAACtB,IAAI,EAAEmB,OAAO,CAAC;IACrD,MAAMI,GAAG,GAAG,MAAMX,OAAO,CAACY,gBAAgB,CAACxB,IAAI,CAAC;IAChD,MAAMyB,YAAY,GAAGzB,IAAI,CAAC0B,WAAW,GAAG1B,IAAI,CAAC0B,WAAW,CAAClB,OAAO,CAAC,CAAC,GAAGmB,SAAS;IAC9E,OAAO,KAAIC,uCAAkB,EAAChB,OAAO,CAACiB,WAAW,CAAC7B,IAAI,CAAC,EAAEO,IAAI,EAAES,UAAU,EAAEK,IAAI,EAAE,KAAK,EAAEE,GAAG,EAAEE,YAAY,CAAC;EAC5G;AACF;AAACK,OAAA,CAAAhC,yBAAA,GAAAA,yBAAA"}
1
+ {"version":3,"names":["_typescript","data","_interopRequireDefault","require","_semanticsEntities","_parseTypeFromQuickInfo","_identifier","obj","__esModule","default","BindingElementTransformer","predicate","node","kind","ts","SyntaxKind","BindingElement","getIdentifiers","Identifier","name","getText","getSourceFile","fileName","transform","context","info","getQuickInfo","displaySig","body","displayString","typeStr","parseTypeFromQuickInfo","type","resolveType","doc","jsDocToDocSchema","defaultValue","initializer","undefined","VariableLikeSchema","getLocation","exports"],"sources":["binding-element.ts"],"sourcesContent":["import ts, { BindingElement, Node } from 'typescript';\nimport { VariableLikeSchema } from '@teambit/semantics.entities.semantic-schema';\nimport { SchemaTransformer } from '../schema-transformer';\nimport { SchemaExtractorContext } from '../schema-extractor-context';\nimport { parseTypeFromQuickInfo } from './utils/parse-type-from-quick-info';\nimport { Identifier } from '../identifier';\n\n/**\n * for example:\n *\n * const objBindingElem = { elem1: 1, elem2: 2 };\n * const { elem1 } = objBindingElem;\n * export { elem1 };\n */\nexport class BindingElementTransformer implements SchemaTransformer {\n predicate(node: Node) {\n return node.kind === ts.SyntaxKind.BindingElement;\n }\n\n async getIdentifiers(node: BindingElement) {\n return [new Identifier(node.name.getText(), node.getSourceFile().fileName)];\n }\n\n async transform(node: BindingElement, context: SchemaExtractorContext) {\n const name = node.name.getText();\n const info = await context.getQuickInfo(node.name);\n const displaySig = info?.body?.displayString || '';\n const typeStr = parseTypeFromQuickInfo(info);\n const type = await context.resolveType(node, typeStr);\n const doc = await context.jsDocToDocSchema(node);\n const defaultValue = node.initializer ? node.initializer.getText() : undefined;\n return new VariableLikeSchema(context.getLocation(node), name, displaySig, type, false, doc, defaultValue);\n }\n}\n"],"mappings":";;;;;;AAAA,SAAAA,YAAA;EAAA,MAAAC,IAAA,GAAAC,sBAAA,CAAAC,OAAA;EAAAH,WAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAG,mBAAA;EAAA,MAAAH,IAAA,GAAAE,OAAA;EAAAC,kBAAA,YAAAA,CAAA;IAAA,OAAAH,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAGA,SAAAI,wBAAA;EAAA,MAAAJ,IAAA,GAAAE,OAAA;EAAAE,uBAAA,YAAAA,CAAA;IAAA,OAAAJ,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAK,YAAA;EAAA,MAAAL,IAAA,GAAAE,OAAA;EAAAG,WAAA,YAAAA,CAAA;IAAA,OAAAL,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAA2C,SAAAC,uBAAAK,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAE3C;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMG,yBAAyB,CAA8B;EAClEC,SAASA,CAACC,IAAU,EAAE;IACpB,OAAOA,IAAI,CAACC,IAAI,KAAKC,qBAAE,CAACC,UAAU,CAACC,cAAc;EACnD;EAEA,MAAMC,cAAcA,CAACL,IAAoB,EAAE;IACzC,OAAO,CAAC,KAAIM,wBAAU,EAACN,IAAI,CAACO,IAAI,CAACC,OAAO,CAAC,CAAC,EAAER,IAAI,CAACS,aAAa,CAAC,CAAC,CAACC,QAAQ,CAAC,CAAC;EAC7E;EAEA,MAAMC,SAASA,CAACX,IAAoB,EAAEY,OAA+B,EAAE;IACrE,MAAML,IAAI,GAAGP,IAAI,CAACO,IAAI,CAACC,OAAO,CAAC,CAAC;IAChC,MAAMK,IAAI,GAAG,MAAMD,OAAO,CAACE,YAAY,CAACd,IAAI,CAACO,IAAI,CAAC;IAClD,MAAMQ,UAAU,GAAGF,IAAI,EAAEG,IAAI,EAAEC,aAAa,IAAI,EAAE;IAClD,MAAMC,OAAO,GAAG,IAAAC,gDAAsB,EAACN,IAAI,CAAC;IAC5C,MAAMO,IAAI,GAAG,MAAMR,OAAO,CAACS,WAAW,CAACrB,IAAI,EAAEkB,OAAO,CAAC;IACrD,MAAMI,GAAG,GAAG,MAAMV,OAAO,CAACW,gBAAgB,CAACvB,IAAI,CAAC;IAChD,MAAMwB,YAAY,GAAGxB,IAAI,CAACyB,WAAW,GAAGzB,IAAI,CAACyB,WAAW,CAACjB,OAAO,CAAC,CAAC,GAAGkB,SAAS;IAC9E,OAAO,KAAIC,uCAAkB,EAACf,OAAO,CAACgB,WAAW,CAAC5B,IAAI,CAAC,EAAEO,IAAI,EAAEQ,UAAU,EAAEK,IAAI,EAAE,KAAK,EAAEE,GAAG,EAAEE,YAAY,CAAC;EAC5G;AACF;AAACK,OAAA,CAAA/B,yBAAA,GAAAA,yBAAA"}
@@ -52,8 +52,7 @@ class ClassDeclarationTransformer {
52
52
 
53
53
  // @todo: in case of `export default class` the class has no name.
54
54
  getName(node) {
55
- var _node$name;
56
- return ((_node$name = node.name) === null || _node$name === void 0 ? void 0 : _node$name.getText()) || 'default';
55
+ return node.name?.getText() || 'default';
57
56
  }
58
57
  async getIdentifiers(node) {
59
58
  return [new (_identifier().Identifier)(this.getName(node), node.getSourceFile().fileName)];
@@ -81,17 +80,15 @@ class ClassDeclarationTransformer {
81
80
  });
82
81
  }
83
82
  async transform(node, context) {
84
- var _node$typeParameters;
85
83
  const className = this.getName(node);
86
84
  const extendsExpressionsWithTypeArgs = await this.getExpressionWithTypeArgs(node, context, _typescript().default.SyntaxKind.ExtendsKeyword);
87
85
  const implementsExpressionsWithTypeArgs = await this.getExpressionWithTypeArgs(node, context, _typescript().default.SyntaxKind.ImplementsKeyword);
88
- const typeParameters = (_node$typeParameters = node.typeParameters) === null || _node$typeParameters === void 0 ? void 0 : _node$typeParameters.map(typeParam => {
86
+ const typeParameters = node.typeParameters?.map(typeParam => {
89
87
  return typeParam.name.getText();
90
88
  });
91
89
  const signature = node.name ? await context.getQuickInfoDisplayString(node.name) : undefined;
92
90
  const members = await (0, _pMapSeries().default)(node.members, async member => {
93
- var _member$modifiers;
94
- const isPrivate = (_member$modifiers = member.modifiers) === null || _member$modifiers === void 0 ? void 0 : _member$modifiers.some(modifier => modifier.kind === _typescript().default.SyntaxKind.PrivateKeyword);
91
+ const isPrivate = member.modifiers?.some(modifier => modifier.kind === _typescript().default.SyntaxKind.PrivateKeyword);
95
92
  if (isPrivate) {
96
93
  return null;
97
94
  }
@@ -1 +1 @@
1
- {"version":3,"names":["_pMapSeries","data","_interopRequireDefault","require","_lodash","_semanticsEntities","_typescript","_identifier","obj","__esModule","default","ownKeys","e","r","t","Object","keys","getOwnPropertySymbols","o","filter","getOwnPropertyDescriptor","enumerable","push","apply","_objectSpread","arguments","length","forEach","_defineProperty","getOwnPropertyDescriptors","defineProperties","defineProperty","key","value","_toPropertyKey","configurable","writable","i","_toPrimitive","String","Symbol","toPrimitive","call","TypeError","Number","ClassDeclarationTransformer","predicate","node","kind","ts","SyntaxKind","ClassDeclaration","getName","_node$name","name","getText","getIdentifiers","Identifier","getSourceFile","fileName","getExpressionWithTypeArgs","context","token","heritageClauses","pMapSeries","heritageClause","flatMap","h","types","map","type","expressionWithTypeArgs","typeArguments","expression","typeArgsNodes","computeSchema","location","getLocation","expressionNode","visitDefinition","UnresolvedSchema","ExpressionWithTypeArgumentsSchema","transform","_node$typeParameters","className","extendsExpressionsWithTypeArgs","ExtendsKeyword","implementsExpressionsWithTypeArgs","ImplementsKeyword","typeParameters","typeParam","signature","getQuickInfoDisplayString","undefined","members","member","_member$modifiers","isPrivate","modifiers","some","modifier","PrivateKeyword","doc","jsDocToDocSchema","Error","ClassSchema","compact","exports"],"sources":["class-declaration.ts"],"sourcesContent":["import pMapSeries from 'p-map-series';\nimport { compact } from 'lodash';\nimport {\n ClassSchema,\n UnresolvedSchema,\n ExpressionWithTypeArgumentsSchema,\n} from '@teambit/semantics.entities.semantic-schema';\nimport ts, { Node, ClassDeclaration } from 'typescript';\nimport { SchemaTransformer } from '../schema-transformer';\nimport { SchemaExtractorContext } from '../schema-extractor-context';\nimport { Identifier } from '../identifier';\n\nexport class ClassDeclarationTransformer implements SchemaTransformer {\n predicate(node: Node) {\n return node.kind === ts.SyntaxKind.ClassDeclaration;\n }\n\n // @todo: in case of `export default class` the class has no name.\n private getName(node: ClassDeclaration) {\n return node.name?.getText() || 'default';\n }\n\n async getIdentifiers(node: ClassDeclaration) {\n return [new Identifier(this.getName(node), node.getSourceFile().fileName)];\n }\n\n private async getExpressionWithTypeArgs(\n node: ClassDeclaration,\n context: SchemaExtractorContext,\n token: ts.SyntaxKind.ExtendsKeyword | ts.SyntaxKind.ImplementsKeyword\n ) {\n if (!node.heritageClauses) return [];\n\n return pMapSeries(\n node.heritageClauses\n .filter((heritageClause: ts.HeritageClause) => heritageClause.token === token)\n .flatMap((h: ts.HeritageClause) => {\n const { types } = h;\n const name = h.getText();\n return types.map((type) => ({ ...type, name }));\n }),\n async (expressionWithTypeArgs: ts.ExpressionWithTypeArguments & { name: string }) => {\n const { typeArguments, expression, name } = expressionWithTypeArgs;\n const typeArgsNodes = typeArguments ? await pMapSeries(typeArguments, (t) => context.computeSchema(t)) : [];\n const location = context.getLocation(expression);\n const expressionNode =\n (await context.visitDefinition(expression)) || new UnresolvedSchema(location, expression.getText());\n return new ExpressionWithTypeArgumentsSchema(typeArgsNodes, expressionNode, name, location);\n }\n );\n }\n\n async transform(node: ClassDeclaration, context: SchemaExtractorContext) {\n const className = this.getName(node);\n const extendsExpressionsWithTypeArgs = await this.getExpressionWithTypeArgs(\n node,\n context,\n ts.SyntaxKind.ExtendsKeyword\n );\n\n const implementsExpressionsWithTypeArgs = await this.getExpressionWithTypeArgs(\n node,\n context,\n ts.SyntaxKind.ImplementsKeyword\n );\n\n const typeParameters = node.typeParameters?.map((typeParam) => {\n return typeParam.name.getText();\n });\n const signature = node.name ? await context.getQuickInfoDisplayString(node.name) : undefined;\n const members = await pMapSeries(node.members, async (member) => {\n const isPrivate = member.modifiers?.some((modifier) => modifier.kind === ts.SyntaxKind.PrivateKeyword);\n if (isPrivate) {\n return null;\n }\n return context.computeSchema(member);\n });\n const doc = await context.jsDocToDocSchema(node);\n\n if (!signature) {\n throw Error(`Missing signature for class ${className} declaration`);\n }\n\n return new ClassSchema(\n className,\n compact(members),\n context.getLocation(node),\n signature,\n doc,\n typeParameters,\n extendsExpressionsWithTypeArgs,\n implementsExpressionsWithTypeArgs\n );\n }\n}\n"],"mappings":";;;;;;AAAA,SAAAA,YAAA;EAAA,MAAAC,IAAA,GAAAC,sBAAA,CAAAC,OAAA;EAAAH,WAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAG,QAAA;EAAA,MAAAH,IAAA,GAAAE,OAAA;EAAAC,OAAA,YAAAA,CAAA;IAAA,OAAAH,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAI,mBAAA;EAAA,MAAAJ,IAAA,GAAAE,OAAA;EAAAE,kBAAA,YAAAA,CAAA;IAAA,OAAAJ,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAKA,SAAAK,YAAA;EAAA,MAAAL,IAAA,GA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BAAgB,CAACxD,IAAI,CAAC;IAEhD,IAAI,CAAC4C,SAAS,EAAE;MACd,MAAMa,KAAK,CAAE,+BAA8BpB,SAAU,cAAa,CAAC;IACrE;IAEA,OAAO,KAAIqB,gCAAW,EACpBrB,SAAS,EACT,IAAAsB,iBAAO,EAACZ,OAAO,CAAC,EAChBjC,OAAO,CAACgB,WAAW,CAAC9B,IAAI,CAAC,EACzB4C,SAAS,EACTW,GAAG,EACHb,cAAc,EACdJ,8BAA8B,EAC9BE,iCACF,CAAC;EACH;AACF;AAACoB,OAAA,CAAA9D,2BAAA,GAAAA,2BAAA"}
1
+ {"version":3,"names":["_pMapSeries","data","_interopRequireDefault","require","_lodash","_semanticsEntities","_typescript","_identifier","obj","__esModule","default","ownKeys","e","r","t","Object","keys","getOwnPropertySymbols","o","filter","getOwnPropertyDescriptor","enumerable","push","apply","_objectSpread","arguments","length","forEach","_defineProperty","getOwnPropertyDescriptors","defineProperties","defineProperty","key","value","_toPropertyKey","configurable","writable","i","_toPrimitive","String","Symbol","toPrimitive","call","TypeError","Number","ClassDeclarationTransformer","predicate","node","kind","ts","SyntaxKind","ClassDeclaration","getName","name","getText","getIdentifiers","Identifier","getSourceFile","fileName","getExpressionWithTypeArgs","context","token","heritageClauses","pMapSeries","heritageClause","flatMap","h","types","map","type","expressionWithTypeArgs","typeArguments","expression","typeArgsNodes","computeSchema","location","getLocation","expressionNode","visitDefinition","UnresolvedSchema","ExpressionWithTypeArgumentsSchema","transform","className","extendsExpressionsWithTypeArgs","ExtendsKeyword","implementsExpressionsWithTypeArgs","ImplementsKeyword","typeParameters","typeParam","signature","getQuickInfoDisplayString","undefined","members","member","isPrivate","modifiers","some","modifier","PrivateKeyword","doc","jsDocToDocSchema","Error","ClassSchema","compact","exports"],"sources":["class-declaration.ts"],"sourcesContent":["import pMapSeries from 'p-map-series';\nimport { compact } from 'lodash';\nimport {\n ClassSchema,\n UnresolvedSchema,\n ExpressionWithTypeArgumentsSchema,\n} from '@teambit/semantics.entities.semantic-schema';\nimport ts, { Node, ClassDeclaration } from 'typescript';\nimport { SchemaTransformer } from '../schema-transformer';\nimport { SchemaExtractorContext } from '../schema-extractor-context';\nimport { Identifier } from '../identifier';\n\nexport class ClassDeclarationTransformer implements SchemaTransformer {\n predicate(node: Node) {\n return node.kind === ts.SyntaxKind.ClassDeclaration;\n }\n\n // @todo: in case of `export default class` the class has no name.\n private getName(node: ClassDeclaration) {\n return node.name?.getText() || 'default';\n }\n\n async getIdentifiers(node: ClassDeclaration) {\n return [new Identifier(this.getName(node), node.getSourceFile().fileName)];\n }\n\n private async getExpressionWithTypeArgs(\n node: ClassDeclaration,\n context: SchemaExtractorContext,\n token: ts.SyntaxKind.ExtendsKeyword | ts.SyntaxKind.ImplementsKeyword\n ) {\n if (!node.heritageClauses) return [];\n\n return pMapSeries(\n node.heritageClauses\n .filter((heritageClause: ts.HeritageClause) => heritageClause.token === token)\n .flatMap((h: ts.HeritageClause) => {\n const { types } = h;\n const name = h.getText();\n return types.map((type) => ({ ...type, name }));\n }),\n async (expressionWithTypeArgs: ts.ExpressionWithTypeArguments & { name: string }) => {\n const { typeArguments, expression, name } = expressionWithTypeArgs;\n const typeArgsNodes = typeArguments ? await pMapSeries(typeArguments, (t) => context.computeSchema(t)) : [];\n const location = context.getLocation(expression);\n const expressionNode =\n (await context.visitDefinition(expression)) || new UnresolvedSchema(location, expression.getText());\n return new ExpressionWithTypeArgumentsSchema(typeArgsNodes, expressionNode, name, location);\n }\n );\n }\n\n async transform(node: ClassDeclaration, context: SchemaExtractorContext) {\n const className = this.getName(node);\n const extendsExpressionsWithTypeArgs = await this.getExpressionWithTypeArgs(\n node,\n context,\n ts.SyntaxKind.ExtendsKeyword\n );\n\n const implementsExpressionsWithTypeArgs = await this.getExpressionWithTypeArgs(\n node,\n context,\n ts.SyntaxKind.ImplementsKeyword\n );\n\n const typeParameters = node.typeParameters?.map((typeParam) => {\n return typeParam.name.getText();\n });\n const signature = node.name ? await context.getQuickInfoDisplayString(node.name) : undefined;\n const members = await pMapSeries(node.members, async (member) => {\n const isPrivate = member.modifiers?.some((modifier) => modifier.kind === ts.SyntaxKind.PrivateKeyword);\n if (isPrivate) {\n return null;\n }\n return context.computeSchema(member);\n });\n const doc = await context.jsDocToDocSchema(node);\n\n if (!signature) {\n throw Error(`Missing signature for class ${className} declaration`);\n }\n\n return new ClassSchema(\n className,\n compact(members),\n context.getLocation(node),\n signature,\n doc,\n typeParameters,\n extendsExpressionsWithTypeArgs,\n implementsExpressionsWithTypeArgs\n );\n }\n}\n"],"mappings":";;;;;;AAAA,SAAAA,YAAA;EAAA,MAAAC,IAAA,GAAAC,sBAAA,CAAAC,OAAA;EAAAH,WAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAG,QAAA;EAAA,MAAAH,IAAA,GAAAE,OAAA;EAAAC,OAAA,YAAAA,CAAA;IAAA,OAAAH,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAI,mBAAA;EAAA,MAAAJ,IAAA,GAAAE,OAAA;EAAAE,kBAAA,YAAAA,CAAA;IAAA,OAAAJ,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAKA,SAAAK,YAAA;EAAA,MAAAL,IAAA,GAAAC,sBAAA,CAAAC,OAAA;EAAAG,WAAA,YAAAA,CAAA;IAAA,OAAAL,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAGA,SAAAM,YAAA;EAAA,MAAAN,IAAA,GAAAE,OAAA;EAAAI,WAAA,YAAAA,CAAA;IAAA,OAAAN,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAA2C,SAAAC,uBAAAM,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAAA,SAAAG,QAAAC,CAAA,EAAAC,CAAA,QAAAC,CAAA,GAAAC,MAAA,CAAAC,IAAA,CAAAJ,CAAA,OA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CAACnC,IAAI,CAACC,OAAO,CAAC,CAAC;IACjC,CAAC,CAAC;IACF,MAAMmC,SAAS,GAAG1C,IAAI,CAACM,IAAI,GAAG,MAAMO,OAAO,CAAC8B,yBAAyB,CAAC3C,IAAI,CAACM,IAAI,CAAC,GAAGsC,SAAS;IAC5F,MAAMC,OAAO,GAAG,MAAM,IAAA7B,qBAAU,EAAChB,IAAI,CAAC6C,OAAO,EAAE,MAAOC,MAAM,IAAK;MAC/D,MAAMC,SAAS,GAAGD,MAAM,CAACE,SAAS,EAAEC,IAAI,CAAEC,QAAQ,IAAKA,QAAQ,CAACjD,IAAI,KAAKC,qBAAE,CAACC,UAAU,CAACgD,cAAc,CAAC;MACtG,IAAIJ,SAAS,EAAE;QACb,OAAO,IAAI;MACb;MACA,OAAOlC,OAAO,CAACc,aAAa,CAACmB,MAAM,CAAC;IACtC,CAAC,CAAC;IACF,MAAMM,GAAG,GAAG,MAAMvC,OAAO,CAACwC,gBAAgB,CAACrD,IAAI,CAAC;IAEhD,IAAI,CAAC0C,SAAS,EAAE;MACd,MAAMY,KAAK,CAAE,+BAA8BnB,SAAU,cAAa,CAAC;IACrE;IAEA,OAAO,KAAIoB,gCAAW,EACpBpB,SAAS,EACT,IAAAqB,iBAAO,EAACX,OAAO,CAAC,EAChBhC,OAAO,CAACgB,WAAW,CAAC7B,IAAI,CAAC,EACzB0C,SAAS,EACTU,GAAG,EACHZ,cAAc,EACdJ,8BAA8B,EAC9BE,iCACF,CAAC;EACH;AACF;AAACmB,OAAA,CAAA3D,2BAAA,GAAAA,2BAAA"}
@@ -34,13 +34,12 @@ class ConstructorTransformer {
34
34
  return [];
35
35
  }
36
36
  async transform(node, context) {
37
- var _info$body, _node$parent, _node$modifiers;
38
37
  const args = await (0, _pMapSeries().default)(node.parameters, async param => context.computeSchema(param));
39
38
  const info = await context.getQuickInfo(node);
40
- const displaySig = (info === null || info === void 0 || (_info$body = info.body) === null || _info$body === void 0 ? void 0 : _info$body.displayString) || '';
41
- const name = ((_node$parent = node.parent) === null || _node$parent === void 0 || (_node$parent = _node$parent.name) === null || _node$parent === void 0 ? void 0 : _node$parent.getText()) || '';
39
+ const displaySig = info?.body?.displayString || '';
40
+ const name = node.parent?.name?.getText() || '';
42
41
  const returns = new (_semanticsEntities().ThisTypeSchema)(context.getLocation(node.parent), name);
43
- const modifiers = ((_node$modifiers = node.modifiers) === null || _node$modifiers === void 0 ? void 0 : _node$modifiers.map(modifier => modifier.getText())) || [];
42
+ const modifiers = node.modifiers?.map(modifier => modifier.getText()) || [];
44
43
  const doc = await context.jsDocToDocSchema(node);
45
44
  return new (_semanticsEntities().ConstructorSchema)(context.getLocation(node), args, returns, displaySig, modifiers, doc);
46
45
  }
@@ -1 +1 @@
1
- {"version":3,"names":["_typescript","data","_interopRequireDefault","require","_semanticsEntities","_pMapSeries","obj","__esModule","default","ConstructorTransformer","predicate","node","kind","ts","SyntaxKind","Constructor","getIdentifiers","transform","context","_info$body","_node$parent","_node$modifiers","args","pMapSeries","parameters","param","computeSchema","info","getQuickInfo","displaySig","body","displayString","name","parent","getText","returns","ThisTypeSchema","getLocation","modifiers","map","modifier","doc","jsDocToDocSchema","ConstructorSchema","exports"],"sources":["constructor.ts"],"sourcesContent":["import ts, { Node, ConstructorDeclaration } from 'typescript';\nimport {\n ConstructorSchema,\n ParameterSchema,\n ThisTypeSchema,\n Modifier,\n} from '@teambit/semantics.entities.semantic-schema';\nimport pMapSeries from 'p-map-series';\nimport { SchemaTransformer } from '../schema-transformer';\nimport { SchemaExtractorContext } from '../schema-extractor-context';\nimport { Identifier } from '../identifier';\n\nexport class ConstructorTransformer implements SchemaTransformer {\n predicate(node: Node) {\n return node.kind === ts.SyntaxKind.Constructor;\n }\n\n async getIdentifiers(): Promise<Identifier[]> {\n return [];\n }\n\n async transform(node: ConstructorDeclaration, context: SchemaExtractorContext) {\n const args = await pMapSeries(node.parameters, async (param) => context.computeSchema(param));\n const info = await context.getQuickInfo(node);\n const displaySig = info?.body?.displayString || '';\n const name = node.parent?.name?.getText() || '';\n const returns = new ThisTypeSchema(context.getLocation(node.parent), name);\n const modifiers = node.modifiers?.map((modifier) => modifier.getText()) || [];\n const doc = await context.jsDocToDocSchema(node);\n\n return new ConstructorSchema(\n context.getLocation(node),\n args as ParameterSchema[],\n returns,\n displaySig,\n modifiers as Modifier[],\n doc\n );\n }\n}\n"],"mappings":";;;;;;AAAA,SAAAA,YAAA;EAAA,MAAAC,IAAA,GAAAC,sBAAA,CAAAC,OAAA;EAAAH,WAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAG,mBAAA;EAAA,MAAAH,IAAA,GAAAE,OAAA;EAAAC,kBAAA,YAAAA,CAAA;IAAA,OAAAH,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAMA,SAAAI,YAAA;EAAA,MAAAJ,IAAA,GAAAC,sBAAA,CAAAC,OAAA;EAAAE,WAAA,YAAAA,CAAA;IAAA,OAAAJ,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAAsC,SAAAC,uBAAAI,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAK/B,MAAMG,sBAAsB,CAA8B;EAC/DC,SAASA,CAACC,IAAU,EAAE;IACpB,OAAOA,IAAI,CAACC,IAAI,KAAKC,qBAAE,CAACC,UAAU,CAACC,WAAW;EAChD;EAEA,MAAMC,cAAcA,CAAA,EAA0B;IAC5C,OAAO,EAAE;EACX;EAEA,MAAMC,SAASA,CAACN,IAA4B,EAAEO,OAA+B,EAAE;IAAA,IAAAC,UAAA,EAAAC,YAAA,EAAAC,eAAA;IAC7E,MAAMC,IAAI,GAAG,MAAM,IAAAC,qBAAU,EAACZ,IAAI,CAACa,UAAU,EAAE,MAAOC,KAAK,IAAKP,OAAO,CAACQ,aAAa,CAACD,KAAK,CAAC,CAAC;IAC7F,MAAME,IAAI,GAAG,MAAMT,OAAO,CAACU,YAAY,CAACjB,IAAI,CAAC;IAC7C,MAAMkB,UAAU,GAAG,CAAAF,IAAI,aAAJA,IAAI,gBAAAR,UAAA,GAAJQ,IAAI,CAAEG,IAAI,cAAAX,UAAA,uBAAVA,UAAA,CAAYY,aAAa,KAAI,EAAE;IAClD,MAAMC,IAAI,GAAG,EAAAZ,YAAA,GAAAT,IAAI,CAACsB,MAAM,cAAAb,YAAA,gBAAAA,YAAA,GAAXA,YAAA,CAAaY,IAAI,cAAAZ,YAAA,uBAAjBA,YAAA,CAAmBc,OAAO,CAAC,CAAC,KAAI,EAAE;IAC/C,MAAMC,OAAO,GAAG,KAAIC,mCAAc,EAAClB,OAAO,CAACmB,WAAW,CAAC1B,IAAI,CAACsB,MAAM,CAAC,EAAED,IAAI,CAAC;IAC1E,MAAMM,SAAS,GAAG,EAAAjB,eAAA,GAAAV,IAAI,CAAC2B,SAAS,cAAAjB,eAAA,uBAAdA,eAAA,CAAgBkB,GAAG,CAAEC,QAAQ,IAAKA,QAAQ,CAACN,OAAO,CAAC,CAAC,CAAC,KAAI,EAAE;IAC7E,MAAMO,GAAG,GAAG,MAAMvB,OAAO,CAACwB,gBAAgB,CAAC/B,IAAI,CAAC;IAEhD,OAAO,KAAIgC,sCAAiB,EAC1BzB,OAAO,CAACmB,WAAW,CAAC1B,IAAI,CAAC,EACzBW,IAAI,EACJa,OAAO,EACPN,UAAU,EACVS,SAAS,EACTG,GACF,CAAC;EACH;AACF;AAACG,OAAA,CAAAnC,sBAAA,GAAAA,sBAAA"}
1
+ {"version":3,"names":["_typescript","data","_interopRequireDefault","require","_semanticsEntities","_pMapSeries","obj","__esModule","default","ConstructorTransformer","predicate","node","kind","ts","SyntaxKind","Constructor","getIdentifiers","transform","context","args","pMapSeries","parameters","param","computeSchema","info","getQuickInfo","displaySig","body","displayString","name","parent","getText","returns","ThisTypeSchema","getLocation","modifiers","map","modifier","doc","jsDocToDocSchema","ConstructorSchema","exports"],"sources":["constructor.ts"],"sourcesContent":["import ts, { Node, ConstructorDeclaration } from 'typescript';\nimport {\n ConstructorSchema,\n ParameterSchema,\n ThisTypeSchema,\n Modifier,\n} from '@teambit/semantics.entities.semantic-schema';\nimport pMapSeries from 'p-map-series';\nimport { SchemaTransformer } from '../schema-transformer';\nimport { SchemaExtractorContext } from '../schema-extractor-context';\nimport { Identifier } from '../identifier';\n\nexport class ConstructorTransformer implements SchemaTransformer {\n predicate(node: Node) {\n return node.kind === ts.SyntaxKind.Constructor;\n }\n\n async getIdentifiers(): Promise<Identifier[]> {\n return [];\n }\n\n async transform(node: ConstructorDeclaration, context: SchemaExtractorContext) {\n const args = await pMapSeries(node.parameters, async (param) => context.computeSchema(param));\n const info = await context.getQuickInfo(node);\n const displaySig = info?.body?.displayString || '';\n const name = node.parent?.name?.getText() || '';\n const returns = new ThisTypeSchema(context.getLocation(node.parent), name);\n const modifiers = node.modifiers?.map((modifier) => modifier.getText()) || [];\n const doc = await context.jsDocToDocSchema(node);\n\n return new ConstructorSchema(\n context.getLocation(node),\n args as ParameterSchema[],\n returns,\n displaySig,\n modifiers as Modifier[],\n doc\n );\n }\n}\n"],"mappings":";;;;;;AAAA,SAAAA,YAAA;EAAA,MAAAC,IAAA,GAAAC,sBAAA,CAAAC,OAAA;EAAAH,WAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAG,mBAAA;EAAA,MAAAH,IAAA,GAAAE,OAAA;EAAAC,kBAAA,YAAAA,CAAA;IAAA,OAAAH,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAMA,SAAAI,YAAA;EAAA,MAAAJ,IAAA,GAAAC,sBAAA,CAAAC,OAAA;EAAAE,WAAA,YAAAA,CAAA;IAAA,OAAAJ,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAAsC,SAAAC,uBAAAI,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAA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  const name = enumDec.name.getText();
45
45
  const members = await (0, _pMapSeries().default)(enumDec.members, async member => {
46
- var _member$initializer;
47
46
  const memberName = member.name.getText();
48
47
  const memberSignature = await context.getQuickInfoDisplayString(member);
49
48
  const memberDoc = await context.jsDocToDocSchema(member);
50
49
  const memberLocation = await context.getLocation(member);
51
- const memberValue = (_member$initializer = member.initializer) === null || _member$initializer === void 0 ? void 0 : _member$initializer.getText();
50
+ const memberValue = member.initializer?.getText();
52
51
  return new (_semanticsEntities().EnumMemberSchema)(memberLocation, memberName, memberSignature, memberValue, memberDoc);
53
52
  });
54
53
  const signature = await context.getQuickInfoDisplayString(enumDec.name);
@@ -1 +1 @@
1
- {"version":3,"names":["_typescript","data","_interopRequireDefault","require","_semanticsEntities","_pMapSeries","_identifier","obj","__esModule","default","EnumDeclarationTransformer","predicate","node","kind","ts","SyntaxKind","EnumDeclaration","getIdentifiers","Identifier","name","getText","getSourceFile","fileName","transform","enumDec","context","members","pMapSeries","member","_member$initializer","memberName","memberSignature","getQuickInfoDisplayString","memberDoc","jsDocToDocSchema","memberLocation","getLocation","memberValue","initializer","EnumMemberSchema","signature","doc","EnumSchema","exports"],"sources":["enum-declaration.ts"],"sourcesContent":["import ts, { Node, EnumDeclaration } from 'typescript';\nimport { EnumMemberSchema, EnumSchema } from '@teambit/semantics.entities.semantic-schema';\nimport pMapSeries from 'p-map-series';\nimport { SchemaTransformer } from '../schema-transformer';\nimport { SchemaExtractorContext } from '../schema-extractor-context';\nimport { Identifier } from '../identifier';\n\nexport class EnumDeclarationTransformer implements SchemaTransformer {\n predicate(node: Node) {\n return node.kind === ts.SyntaxKind.EnumDeclaration;\n }\n\n async getIdentifiers(node: EnumDeclaration): Promise<Identifier[]> {\n return [new Identifier(node.name.getText(), node.getSourceFile().fileName)];\n }\n\n async transform(enumDec: EnumDeclaration, context: SchemaExtractorContext) {\n const name = enumDec.name.getText();\n const members = await pMapSeries(enumDec.members, async (member) => {\n const memberName = member.name.getText();\n const memberSignature = await context.getQuickInfoDisplayString(member);\n const memberDoc = await context.jsDocToDocSchema(member);\n const memberLocation = await context.getLocation(member);\n const memberValue = member.initializer?.getText();\n return new EnumMemberSchema(memberLocation, memberName, memberSignature, memberValue, memberDoc);\n });\n const signature = await context.getQuickInfoDisplayString(enumDec.name);\n const doc = await context.jsDocToDocSchema(enumDec);\n return new EnumSchema(context.getLocation(enumDec), name, members, signature, doc);\n }\n}\n"],"mappings":";;;;;;AAAA,SAAAA,YAAA;EAAA,MAAAC,IAAA,GAAAC,sBAAA,CAAAC,OAAA;EAAAH,WAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAG,mBAAA;EAAA,MAAAH,IAAA,GAAAE,OAAA;EAAAC,kBAAA,YAAAA,CAAA;IAAA,OAAAH,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAI,YAAA;EAAA,MAAAJ,IAAA,GAAAC,sBAAA,CAAAC,OAAA;EAAAE,WAAA,YAAAA,CAAA;IAAA,OAAAJ,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAGA,SAAAK,YAAA;EAAA,MAAAL,IAAA,GAAAE,OAAA;EAAAG,WAAA,YAAAA,CAAA;IAAA,OAAAL,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAA2C,SAAAC,uBAAAK,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAEpC,MAAMG,0BAA0B,CAA8B;EACnEC,SAASA,CAACC,IAAU,EAAE;IACpB,OAAOA,IAAI,CAACC,IAAI,KAAKC,qBAAE,CAACC,UAAU,CAACC,eAAe;EACpD;EAEA,MAAMC,cAAcA,CAACL,IAAqB,EAAyB;IACjE,OAAO,CAAC,KAAIM,wBAAU,EAACN,IAAI,CAACO,IAAI,CAACC,OAAO,CAAC,CAAC,EAAER,IAAI,CAACS,aAAa,CAAC,CAAC,CAACC,QAAQ,CAAC,CAAC;EAC7E;EAEA,MAAMC,SAASA,CAACC,OAAwB,EAAEC,OAA+B,EAAE;IACzE,MAAMN,IAAI,GAAGK,OAAO,CAACL,IAAI,CAACC,OAAO,CAAC,CAAC;IACnC,MAAMM,OAAO,GAAG,MAAM,IAAAC,qBAAU,EAACH,OAAO,CAACE,OAAO,EAAE,MAAOE,MAAM,IAAK;MAAA,IAAAC,mBAAA;MAClE,MAAMC,UAAU,GAAGF,MAAM,CAACT,IAAI,CAACC,OAAO,CAAC,CAAC;MACxC,MAAMW,eAAe,GAAG,MAAMN,OAAO,CAACO,yBAAyB,CAACJ,MAAM,CAAC;MACvE,MAAMK,SAAS,GAAG,MAAMR,OAAO,CAACS,gBAAgB,CAACN,MAAM,CAAC;MACxD,MAAMO,cAAc,GAAG,MAAMV,OAAO,CAACW,WAAW,CAACR,MAAM,CAAC;MACxD,MAAMS,WAAW,IAAAR,mBAAA,GAAGD,MAAM,CAACU,WAAW,cAAAT,mBAAA,uBAAlBA,mBAAA,CAAoBT,OAAO,CAAC,CAAC;MACjD,OAAO,KAAImB,qCAAgB,EAACJ,cAAc,EAAEL,UAAU,EAAEC,eAAe,EAAEM,WAAW,EAAEJ,SAAS,CAAC;IAClG,CAAC,CAAC;IACF,MAAMO,SAAS,GAAG,MAAMf,OAAO,CAACO,yBAAyB,CAACR,OAAO,CAACL,IAAI,CAAC;IACvE,MAAMsB,GAAG,GAAG,MAAMhB,OAAO,CAACS,gBAAgB,CAACV,OAAO,CAAC;IACnD,OAAO,KAAIkB,+BAAU,EAACjB,OAAO,CAACW,WAAW,CAACZ,OAAO,CAAC,EAAEL,IAAI,EAAEO,OAAO,EAAEc,SAAS,EAAEC,GAAG,CAAC;EACpF;AACF;AAACE,OAAA,CAAAjC,0BAAA,GAAAA,0BAAA"}
1
+ {"version":3,"names":["_typescript","data","_interopRequireDefault","require","_semanticsEntities","_pMapSeries","_identifier","obj","__esModule","default","EnumDeclarationTransformer","predicate","node","kind","ts","SyntaxKind","EnumDeclaration","getIdentifiers","Identifier","name","getText","getSourceFile","fileName","transform","enumDec","context","members","pMapSeries","member","memberName","memberSignature","getQuickInfoDisplayString","memberDoc","jsDocToDocSchema","memberLocation","getLocation","memberValue","initializer","EnumMemberSchema","signature","doc","EnumSchema","exports"],"sources":["enum-declaration.ts"],"sourcesContent":["import ts, { Node, EnumDeclaration } from 'typescript';\nimport { EnumMemberSchema, EnumSchema } from '@teambit/semantics.entities.semantic-schema';\nimport pMapSeries from 'p-map-series';\nimport { SchemaTransformer } from '../schema-transformer';\nimport { SchemaExtractorContext } from '../schema-extractor-context';\nimport { Identifier } from '../identifier';\n\nexport class EnumDeclarationTransformer implements SchemaTransformer {\n predicate(node: Node) {\n return node.kind === ts.SyntaxKind.EnumDeclaration;\n }\n\n async getIdentifiers(node: EnumDeclaration): Promise<Identifier[]> {\n return [new Identifier(node.name.getText(), node.getSourceFile().fileName)];\n }\n\n async transform(enumDec: EnumDeclaration, context: SchemaExtractorContext) {\n const name = enumDec.name.getText();\n const members = await pMapSeries(enumDec.members, async (member) => {\n const memberName = member.name.getText();\n const memberSignature = await context.getQuickInfoDisplayString(member);\n const memberDoc = await context.jsDocToDocSchema(member);\n const memberLocation = await context.getLocation(member);\n const memberValue = member.initializer?.getText();\n return new EnumMemberSchema(memberLocation, memberName, memberSignature, memberValue, memberDoc);\n });\n const signature = await context.getQuickInfoDisplayString(enumDec.name);\n const doc = await context.jsDocToDocSchema(enumDec);\n return new EnumSchema(context.getLocation(enumDec), name, members, signature, doc);\n }\n}\n"],"mappings":";;;;;;AAAA,SAAAA,YAAA;EAAA,MAAAC,IAAA,GAAAC,sBAAA,CAAAC,OAAA;EAAAH,WAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAG,mBAAA;EAAA,MAAAH,IAAA,GAAAE,OAAA;EAAAC,kBAAA,YAAAA,CAAA;IAAA,OAAAH,IAAA;EAAA;EAAA,OAAAA,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AAW,GAAGR,MAAM,CAACS,WAAW,EAAEjB,OAAO,CAAC,CAAC;MACjD,OAAO,KAAIkB,qCAAgB,EAACJ,cAAc,EAAEL,UAAU,EAAEC,eAAe,EAAEM,WAAW,EAAEJ,SAAS,CAAC;IAClG,CAAC,CAAC;IACF,MAAMO,SAAS,GAAG,MAAMd,OAAO,CAACM,yBAAyB,CAACP,OAAO,CAACL,IAAI,CAAC;IACvE,MAAMqB,GAAG,GAAG,MAAMf,OAAO,CAACQ,gBAAgB,CAACT,OAAO,CAAC;IACnD,OAAO,KAAIiB,+BAAU,EAAChB,OAAO,CAACU,WAAW,CAACX,OAAO,CAAC,EAAEL,IAAI,EAAEO,OAAO,EAAEa,SAAS,EAAEC,GAAG,CAAC;EACpF;AACF;AAACE,OAAA,CAAAhC,0BAAA,GAAAA,0BAAA"}
@@ -32,24 +32,22 @@ class ExportDeclarationTransformer {
32
32
  return node.kind === _typescript().SyntaxKind.ExportDeclaration;
33
33
  }
34
34
  async getIdentifiers(exportDec, context) {
35
- var _exportDec$moduleSpec, _exportDec$exportClau, _exportDec$exportClau2;
36
35
  // e.g. `export { button1, button2 } as Composition from './button';
37
- const rawSourceFilePath = (_exportDec$moduleSpec = exportDec.moduleSpecifier) === null || _exportDec$moduleSpec === void 0 ? void 0 : _exportDec$moduleSpec.getText();
36
+ const rawSourceFilePath = exportDec.moduleSpecifier?.getText();
38
37
 
39
38
  // strip off quotes ''
40
- const sourceFilePath = rawSourceFilePath && rawSourceFilePath.substring(1, (rawSourceFilePath === null || rawSourceFilePath === void 0 ? void 0 : rawSourceFilePath.length) - 1);
41
- if (((_exportDec$exportClau = exportDec.exportClause) === null || _exportDec$exportClau === void 0 ? void 0 : _exportDec$exportClau.kind) === _typescript().default.SyntaxKind.NamedExports) {
39
+ const sourceFilePath = rawSourceFilePath && rawSourceFilePath.substring(1, rawSourceFilePath?.length - 1);
40
+ if (exportDec.exportClause?.kind === _typescript().default.SyntaxKind.NamedExports) {
42
41
  return exportDec.exportClause.elements.map(elm => {
43
- var _elm$propertyName;
44
42
  const alias = elm.propertyName && elm.name.getText() || undefined;
45
- const id = ((_elm$propertyName = elm.propertyName) === null || _elm$propertyName === void 0 ? void 0 : _elm$propertyName.getText()) || elm.name.getText();
43
+ const id = elm.propertyName?.getText() || elm.name.getText();
46
44
  const fileName = elm.getSourceFile().fileName;
47
45
  return new (_exportIdentifier().ExportIdentifier)(id, fileName, alias, sourceFilePath);
48
46
  });
49
47
  }
50
48
 
51
49
  // e.g. `export * as Composition from './button';
52
- if (((_exportDec$exportClau2 = exportDec.exportClause) === null || _exportDec$exportClau2 === void 0 ? void 0 : _exportDec$exportClau2.kind) === _typescript().default.SyntaxKind.NamespaceExport) {
50
+ if (exportDec.exportClause?.kind === _typescript().default.SyntaxKind.NamespaceExport) {
53
51
  return [new (_exportIdentifier().ExportIdentifier)(exportDec.exportClause.name.getText(), exportDec.getSourceFile().fileName, undefined, sourceFilePath)];
54
52
  }
55
53
  if (exportDec.moduleSpecifier) {
@@ -1 +1 @@
1
- {"version":3,"names":["_semanticsEntities","data","require","_typescript","_interopRequireWildcard","_exportIdentifier","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","prototype","hasOwnProperty","call","i","set","ExportDeclarationTransformer","predicate","node","kind","SyntaxKind","ExportDeclaration","getIdentifiers","exportDec","context","_exportDec$moduleSpec","_exportDec$exportClau","_exportDec$exportClau2","rawSourceFilePath","moduleSpecifier","getText","sourceFilePath","substring","length","exportClause","ts","NamedExports","elements","map","elm","_elm$propertyName","alias","propertyName","name","undefined","id","fileName","getSourceFile","ExportIdentifier","NamespaceExport","getFileExports","transform","specifier","Error","sourceFile","getSourceFileFromNode","UnImplementedSchema","getLocation","computeSchema","schemas","namedExport","ModuleSchema","namespaceExport","exports","isSameNode","nodeA","nodeB","pos","end","Promise","all","element","exportSpecifierToSchemaNode","definitionInfo","UnresolvedSchema","definitionNode","definition","resolveType","parent","getLocationAsString","ExportSpecifier","namespace","filePath","getFilePathByNode","getSourceFileInsideComponent","getTypeRefForExternalPath","result"],"sources":["export-declaration.ts"],"sourcesContent":["import {\n SchemaNode,\n ModuleSchema,\n UnresolvedSchema,\n UnImplementedSchema,\n} from '@teambit/semantics.entities.semantic-schema';\nimport ts, {\n Node,\n SyntaxKind,\n ExportDeclaration as ExportDeclarationNode,\n NamedExports,\n NamespaceExport,\n ExportSpecifier,\n} from 'typescript';\nimport { SchemaExtractorContext } from '../schema-extractor-context';\nimport { SchemaTransformer } from '../schema-transformer';\nimport { ExportIdentifier } from '../export-identifier';\n\nexport class ExportDeclarationTransformer implements SchemaTransformer {\n predicate(node: Node) {\n return node.kind === SyntaxKind.ExportDeclaration;\n }\n\n async getIdentifiers(exportDec: ExportDeclarationNode, context: SchemaExtractorContext) {\n // e.g. `export { button1, button2 } as Composition from './button';\n const rawSourceFilePath = exportDec.moduleSpecifier?.getText();\n\n // strip off quotes ''\n const sourceFilePath = rawSourceFilePath && rawSourceFilePath.substring(1, rawSourceFilePath?.length - 1);\n\n if (exportDec.exportClause?.kind === ts.SyntaxKind.NamedExports) {\n return exportDec.exportClause.elements.map((elm) => {\n const alias = (elm.propertyName && elm.name.getText()) || undefined;\n const id = elm.propertyName?.getText() || elm.name.getText();\n const fileName = elm.getSourceFile().fileName;\n\n return new ExportIdentifier(id, fileName, alias, sourceFilePath);\n });\n }\n\n // e.g. `export * as Composition from './button';\n if (exportDec.exportClause?.kind === ts.SyntaxKind.NamespaceExport) {\n return [\n new ExportIdentifier(\n exportDec.exportClause.name.getText(),\n exportDec.getSourceFile().fileName,\n undefined,\n sourceFilePath\n ),\n ];\n }\n\n if (exportDec.moduleSpecifier) {\n return context.getFileExports(exportDec);\n }\n\n return [];\n }\n\n async transform(exportDec: ExportDeclarationNode, context: SchemaExtractorContext): Promise<SchemaNode> {\n const exportClause = exportDec.exportClause;\n\n // it's export-all, e.g. `export * from './button'`;\n if (!exportClause) {\n const specifier = exportDec.moduleSpecifier;\n if (!specifier) {\n throw new Error(`fatal: no specifier`);\n }\n const sourceFile = await context.getSourceFileFromNode(specifier);\n // export * from 'webpack', export-all from a package\n if (!sourceFile) {\n return new UnImplementedSchema(\n context.getLocation(exportDec),\n exportDec.getText(),\n SyntaxKind[SyntaxKind.ExportDeclaration]\n );\n }\n return context.computeSchema(sourceFile);\n }\n\n // e.g. `export { button1, button2 } as Composition from './button';\n if (exportClause.kind === SyntaxKind.NamedExports) {\n const schemas = await namedExport(exportClause, context);\n return new ModuleSchema(context.getLocation(exportDec), schemas, []);\n }\n // e.g. `export * as Composition from './button';\n if (exportClause.kind === SyntaxKind.NamespaceExport) {\n return namespaceExport(exportClause, exportDec, context);\n }\n\n // should never reach here. exportClause can be either NamespaceExport or NamedExports\n throw new Error(`unrecognized exportClause type`);\n }\n}\n\nfunction isSameNode(nodeA: Node, nodeB: Node): boolean {\n return nodeA.kind === nodeB.kind && nodeA.pos === nodeB.pos && nodeA.end === nodeB.end;\n}\n\nasync function namedExport(exportClause: NamedExports, context: SchemaExtractorContext): Promise<SchemaNode[]> {\n const schemas = await Promise.all(\n exportClause.elements.map(async (element) => {\n return exportSpecifierToSchemaNode(element, context);\n })\n );\n\n return schemas;\n}\n\nasync function exportSpecifierToSchemaNode(element: ExportSpecifier, context: SchemaExtractorContext) {\n try {\n const definitionInfo = await context.definitionInfo(element);\n if (!definitionInfo) {\n // happens for example when the main index.ts file exports variable from an mdx file.\n // tsserver is unable to get the definition node because it doesn't know to parse mdx files.\n return new UnresolvedSchema(context.getLocation(element.name), element.name.getText());\n }\n\n const definitionNode = await context.definition(definitionInfo);\n\n if (!definitionNode) {\n return await context.resolveType(element, element.name.getText(), false);\n }\n\n // if it is reexported from another export\n if (isSameNode(element, definitionNode.parent)) {\n // the definition node is the same node as element.name. tsserver wasn't able to find the source for it\n // normally, \"bit install\" should fix it. another option is to open vscode and look for errors.\n throw new Error(`error: tsserver is unable to locate the identifier \"${element.name.getText()}\" at ${context.getLocationAsString(\n element.name\n )}.\nmake sure \"bit status\" is clean and there are no errors about missing packages/links.\nalso, make sure the tsconfig.json in the root has the \"jsx\" setting defined.`);\n }\n\n if (definitionNode.parent.kind === SyntaxKind.ExportSpecifier)\n return exportSpecifierToSchemaNode(definitionNode.parent as ExportSpecifier, context);\n\n return await context.computeSchema(definitionNode.parent);\n } catch (e) {\n return new UnresolvedSchema(context.getLocation(element.name), element.name.getText());\n }\n}\n\nasync function namespaceExport(\n exportClause: NamespaceExport,\n exportDec: ExportDeclarationNode,\n context: SchemaExtractorContext\n) {\n const namespace = exportClause.name.getText();\n const filePath = await context.getFilePathByNode(exportClause.name);\n if (!filePath) {\n throw new Error(`unable to find the file-path for \"${namespace}\"`);\n }\n const sourceFile = context.getSourceFileInsideComponent(filePath);\n if (!sourceFile) {\n // it's a namespace from another component or an external package.\n return context.getTypeRefForExternalPath(namespace, filePath, context.getLocation(exportDec));\n }\n const result = await context.computeSchema(sourceFile);\n if (!(result instanceof ModuleSchema)) {\n throw new Error(`expect result to be instance of Module`);\n }\n result.namespace = namespace;\n return result;\n}\n"],"mappings":";;;;;;AAAA,SAAAA,mBAAA;EAAA,MAAAC,IAAA,GAAAC,OAAA;EAAAF,kBAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAMA,SAAAE,YAAA;EAAA,MAAAF,IAAA,GAAAG,uBAAA,CAAAF,OAAA;EAAAC,WAAA,YAAAA,CAAA;IAAA,OAAAF,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAUA,SAAAI,kBAAA;EAAA,MAAAJ,IAAA,GAAAC,OAAA;EAAAG,iBAAA,YAAAA,CAAA;IAAA,OAAAJ,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAAwD,SAAAK,yBAAAC,CAAA,6BAAAC,OAAA,mBAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,CAAA,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,CAAC;EACtD,IAAI,EAAEgC,MAAM,YAAYzB,iCAAY,CAAC,EAAE;IACrC,MAAM,IAAIR,KAAK,CAAE,wCAAuC,CAAC;EAC3D;EACAiC,MAAM,CAACL,SAAS,GAAGA,SAAS;EAC5B,OAAOK,MAAM;AACf"}
1
+ {"version":3,"names":["_semanticsEntities","data","require","_typescript","_interopRequireWildcard","_exportIdentifier","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","prototype","hasOwnProperty","call","i","set","ExportDeclarationTransformer","predicate","node","kind","SyntaxKind","ExportDeclaration","getIdentifiers","exportDec","context","rawSourceFilePath","moduleSpecifier","getText","sourceFilePath","substring","length","exportClause","ts","NamedExports","elements","map","elm","alias","propertyName","name","undefined","id","fileName","getSourceFile","ExportIdentifier","NamespaceExport","getFileExports","transform","specifier","Error","sourceFile","getSourceFileFromNode","UnImplementedSchema","getLocation","computeSchema","schemas","namedExport","ModuleSchema","namespaceExport","exports","isSameNode","nodeA","nodeB","pos","end","Promise","all","element","exportSpecifierToSchemaNode","definitionInfo","UnresolvedSchema","definitionNode","definition","resolveType","parent","getLocationAsString","ExportSpecifier","namespace","filePath","getFilePathByNode","getSourceFileInsideComponent","getTypeRefForExternalPath","result"],"sources":["export-declaration.ts"],"sourcesContent":["import {\n SchemaNode,\n ModuleSchema,\n UnresolvedSchema,\n UnImplementedSchema,\n} from '@teambit/semantics.entities.semantic-schema';\nimport ts, {\n Node,\n SyntaxKind,\n ExportDeclaration as ExportDeclarationNode,\n NamedExports,\n NamespaceExport,\n ExportSpecifier,\n} from 'typescript';\nimport { SchemaExtractorContext } from '../schema-extractor-context';\nimport { SchemaTransformer } from '../schema-transformer';\nimport { ExportIdentifier } from '../export-identifier';\n\nexport class ExportDeclarationTransformer implements SchemaTransformer {\n predicate(node: Node) {\n return node.kind === SyntaxKind.ExportDeclaration;\n }\n\n async getIdentifiers(exportDec: ExportDeclarationNode, context: SchemaExtractorContext) {\n // e.g. `export { button1, button2 } as Composition from './button';\n const rawSourceFilePath = exportDec.moduleSpecifier?.getText();\n\n // strip off quotes ''\n const sourceFilePath = rawSourceFilePath && rawSourceFilePath.substring(1, rawSourceFilePath?.length - 1);\n\n if (exportDec.exportClause?.kind === ts.SyntaxKind.NamedExports) {\n return exportDec.exportClause.elements.map((elm) => {\n const alias = (elm.propertyName && elm.name.getText()) || undefined;\n const id = elm.propertyName?.getText() || elm.name.getText();\n const fileName = elm.getSourceFile().fileName;\n\n return new ExportIdentifier(id, fileName, alias, sourceFilePath);\n });\n }\n\n // e.g. `export * as Composition from './button';\n if (exportDec.exportClause?.kind === ts.SyntaxKind.NamespaceExport) {\n return [\n new ExportIdentifier(\n exportDec.exportClause.name.getText(),\n exportDec.getSourceFile().fileName,\n undefined,\n sourceFilePath\n ),\n ];\n }\n\n if (exportDec.moduleSpecifier) {\n return context.getFileExports(exportDec);\n }\n\n return [];\n }\n\n async transform(exportDec: ExportDeclarationNode, context: SchemaExtractorContext): Promise<SchemaNode> {\n const exportClause = exportDec.exportClause;\n\n // it's export-all, e.g. `export * from './button'`;\n if (!exportClause) {\n const specifier = exportDec.moduleSpecifier;\n if (!specifier) {\n throw new Error(`fatal: no specifier`);\n }\n const sourceFile = await context.getSourceFileFromNode(specifier);\n // export * from 'webpack', export-all from a package\n if (!sourceFile) {\n return new UnImplementedSchema(\n context.getLocation(exportDec),\n exportDec.getText(),\n SyntaxKind[SyntaxKind.ExportDeclaration]\n );\n }\n return context.computeSchema(sourceFile);\n }\n\n // e.g. `export { button1, button2 } as Composition from './button';\n if (exportClause.kind === SyntaxKind.NamedExports) {\n const schemas = await namedExport(exportClause, context);\n return new ModuleSchema(context.getLocation(exportDec), schemas, []);\n }\n // e.g. `export * as Composition from './button';\n if (exportClause.kind === SyntaxKind.NamespaceExport) {\n return namespaceExport(exportClause, exportDec, context);\n }\n\n // should never reach here. exportClause can be either NamespaceExport or NamedExports\n throw new Error(`unrecognized exportClause type`);\n }\n}\n\nfunction isSameNode(nodeA: Node, nodeB: Node): boolean {\n return nodeA.kind === nodeB.kind && nodeA.pos === nodeB.pos && nodeA.end === nodeB.end;\n}\n\nasync function namedExport(exportClause: NamedExports, context: SchemaExtractorContext): Promise<SchemaNode[]> {\n const schemas = await Promise.all(\n exportClause.elements.map(async (element) => {\n return exportSpecifierToSchemaNode(element, context);\n })\n );\n\n return schemas;\n}\n\nasync function exportSpecifierToSchemaNode(element: ExportSpecifier, context: SchemaExtractorContext) {\n try {\n const definitionInfo = await context.definitionInfo(element);\n if (!definitionInfo) {\n // happens for example when the main index.ts file exports variable from an mdx file.\n // tsserver is unable to get the definition node because it doesn't know to parse mdx files.\n return new UnresolvedSchema(context.getLocation(element.name), element.name.getText());\n }\n\n const definitionNode = await context.definition(definitionInfo);\n\n if (!definitionNode) {\n return await context.resolveType(element, element.name.getText(), false);\n }\n\n // if it is reexported from another export\n if (isSameNode(element, definitionNode.parent)) {\n // the definition node is the same node as element.name. tsserver wasn't able to find the source for it\n // normally, \"bit install\" should fix it. another option is to open vscode and look for errors.\n throw new Error(`error: tsserver is unable to locate the identifier \"${element.name.getText()}\" at ${context.getLocationAsString(\n element.name\n )}.\nmake sure \"bit status\" is clean and there are no errors about missing packages/links.\nalso, make sure the tsconfig.json in the root has the \"jsx\" setting defined.`);\n }\n\n if (definitionNode.parent.kind === SyntaxKind.ExportSpecifier)\n return exportSpecifierToSchemaNode(definitionNode.parent as ExportSpecifier, context);\n\n return await context.computeSchema(definitionNode.parent);\n } catch (e) {\n return new UnresolvedSchema(context.getLocation(element.name), element.name.getText());\n }\n}\n\nasync function namespaceExport(\n exportClause: NamespaceExport,\n exportDec: ExportDeclarationNode,\n context: SchemaExtractorContext\n) {\n const namespace = exportClause.name.getText();\n const filePath = await context.getFilePathByNode(exportClause.name);\n if (!filePath) {\n throw new Error(`unable to find the file-path for \"${namespace}\"`);\n }\n const sourceFile = context.getSourceFileInsideComponent(filePath);\n if (!sourceFile) {\n // it's a namespace from another component or an external package.\n return context.getTypeRefForExternalPath(namespace, filePath, context.getLocation(exportDec));\n }\n const result = await context.computeSchema(sourceFile);\n if (!(result instanceof ModuleSchema)) {\n throw new Error(`expect result to be instance of Module`);\n }\n result.namespace = namespace;\n return result;\n}\n"],"mappings":";;;;;;AAAA,SAAAA,mBAAA;EAAA,MAAAC,IAAA,GAAAC,OAAA;EAAAF,kBAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAMA,SAAAE,YAAA;EAAA,MAAAF,IAAA,GAAAG,uBAAA,CAAAF,OAAA;EAAAC,WAAA,YAAAA,CAAA;IAAA,OAAAF,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAUA,SAAAI,kBAAA;EAAA,MAAAJ,IAAA,GAAAC,OAAA;EAAAG,iBAAA,YAAAA,CAAA;IAAA,OAAAJ,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAAwD,SAAAK,yBAAAC,CAAA,6BAAAC,OAAA,mBAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,CAAA,WAAAA,CAAA,GAAAG,CAAA,GAAAD,CAAA,KAAAF,CAAA;AAAA,SAAAH,wBAAAG,CAAA,EAAAE,CAAA,SAAAA,CAAA,IAAAF,CAAA,IAAAA,CAAA,CAAAI,UAAA,SAAAJ,CAAA,eAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,WAAAK,OAAA,EAAAL,CAAA,QAAAG,CAAA,GAAAJ,wBAAA,CAAAG,CAAA,OAAAC,CAAA,IAAAA,CAAA,CAAAG,GAAA,CAAAN,CAAA,UAAAG,CAAA,CAAAI,GAAA,CAAAP,CAAA,OAAAQ,CAAA,KAAAC,SAAA,UAAAC,CAAA,GAAAC,MAAA,CAAAC,cAAA,IAAAD,MAAA,CAAAE,wBAAA,WAAAC,CAAA,IAAAd,CAAA,oBAAAc,CAAA,IAAAH,M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AChD,YAAY,CAACQ,IAAI,CAAC;EACnE,IAAI,CAACuC,QAAQ,EAAE;IACb,MAAM,IAAI7B,KAAK,CAAE,qCAAoC4B,SAAU,GAAE,CAAC;EACpE;EACA,MAAM3B,UAAU,GAAG1B,OAAO,CAACwD,4BAA4B,CAACF,QAAQ,CAAC;EACjE,IAAI,CAAC5B,UAAU,EAAE;IACf;IACA,OAAO1B,OAAO,CAACyD,yBAAyB,CAACJ,SAAS,EAAEC,QAAQ,EAAEtD,OAAO,CAAC6B,WAAW,CAAC9B,SAAS,CAAC,CAAC;EAC/F;EACA,MAAM2D,MAAM,GAAG,MAAM1D,OAAO,CAAC8B,aAAa,CAACJ,UAAU,CAAC;EACtD,IAAI,EAAEgC,MAAM,YAAYzB,iCAAY,CAAC,EAAE;IACrC,MAAM,IAAIR,KAAK,CAAE,wCAAuC,CAAC;EAC3D;EACAiC,MAAM,CAACL,SAAS,GAAGA,SAAS;EAC5B,OAAOK,MAAM;AACf"}
@@ -50,27 +50,24 @@ class FunctionLikeTransformer {
50
50
  return [new (_identifier().Identifier)(this.getName(funcDec), funcDec.getSourceFile().fileName)];
51
51
  }
52
52
  getName(funcDec) {
53
- var _funcDec$name;
54
53
  if (funcDec.kind === _typescript().default.SyntaxKind.ConstructSignature) return 'new';
55
- return ((_funcDec$name = funcDec.name) === null || _funcDec$name === void 0 ? void 0 : _funcDec$name.getText()) || '';
54
+ return funcDec.name?.getText() || '';
56
55
  }
57
56
  async transform(node, context) {
58
- var _info$body, _node$modifiers2, _node$typeParameters;
59
57
  const name = this.getName(node);
60
58
  const getQuickInfoFromDefaultModifier = async () => {
61
- var _node$modifiers;
62
- const defaultModifier = (_node$modifiers = node.modifiers) === null || _node$modifiers === void 0 ? void 0 : _node$modifiers.find(modifier => modifier.kind === _typescript().default.SyntaxKind.DefaultKeyword);
59
+ const defaultModifier = node.modifiers?.find(modifier => modifier.kind === _typescript().default.SyntaxKind.DefaultKeyword);
63
60
  if (defaultModifier) return context.getQuickInfo(defaultModifier);
64
61
  if (node.kind === _typescript().default.SyntaxKind.ArrowFunction) return context.getQuickInfo(node.equalsGreaterThanToken);
65
62
  return null;
66
63
  };
67
64
  const info = node.name ? await context.getQuickInfo(node.name) : await getQuickInfoFromDefaultModifier();
68
65
  const returnTypeStr = info ? (0, _parseTypeFromQuickInfo().parseTypeFromQuickInfo)(info) : 'any';
69
- const displaySig = (info === null || info === void 0 || (_info$body = info.body) === null || _info$body === void 0 ? void 0 : _info$body.displayString) || '';
66
+ const displaySig = info?.body?.displayString || '';
70
67
  const args = await (0, _pMapSeries().default)(node.parameters, async param => context.computeSchema(param));
71
68
  const returnType = await context.resolveType(node, returnTypeStr, Boolean(info));
72
- const modifiers = ((_node$modifiers2 = node.modifiers) === null || _node$modifiers2 === void 0 ? void 0 : _node$modifiers2.map(modifier => modifier.getText())) || [];
73
- const typeParameters = (_node$typeParameters = node.typeParameters) === null || _node$typeParameters === void 0 ? void 0 : _node$typeParameters.map(typeParam => typeParam.name.getText());
69
+ const modifiers = node.modifiers?.map(modifier => modifier.getText()) || [];
70
+ const typeParameters = node.typeParameters?.map(typeParam => typeParam.name.getText());
74
71
  const location = context.getLocation(node);
75
72
  const doc = await context.jsDocToDocSchema(node);
76
73
  return new (_semanticsEntities().FunctionLikeSchema)(location, name, args, returnType, displaySig, modifiers, doc, typeParameters);