@teambit/typescript 0.0.894 → 0.0.895
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.
- package/dist/schema-extractor-context.d.ts +6 -3
- package/dist/schema-extractor-context.js +41 -10
- package/dist/schema-extractor-context.js.map +1 -1
- package/dist/transformers/binding-element.js +1 -8
- package/dist/transformers/binding-element.js.map +1 -1
- package/dist/transformers/{class-deceleration.d.ts → class-declaration.d.ts} +2 -1
- package/dist/transformers/class-declaration.js +130 -0
- package/dist/transformers/class-declaration.js.map +1 -0
- package/dist/transformers/enum-declaration.js +20 -2
- package/dist/transformers/enum-declaration.js.map +1 -1
- package/dist/transformers/export-declaration.js +2 -2
- package/dist/transformers/export-declaration.js.map +1 -1
- package/dist/transformers/index.d.ts +1 -1
- package/dist/transformers/index.js +5 -5
- package/dist/transformers/index.js.map +1 -1
- package/dist/transformers/interface-declaration.d.ts +1 -0
- package/dist/transformers/interface-declaration.js +47 -5
- package/dist/transformers/interface-declaration.js.map +1 -1
- package/dist/transformers/source-file-transformer.d.ts +2 -2
- package/dist/transformers/source-file-transformer.js +1 -1
- package/dist/transformers/source-file-transformer.js.map +1 -1
- package/dist/transformers/type-alias.js +1 -8
- package/dist/transformers/type-alias.js.map +1 -1
- package/dist/transformers/utils/class-element-to-schema.js +7 -11
- package/dist/transformers/utils/class-element-to-schema.js.map +1 -1
- package/dist/transformers/utils/jsdoc-to-doc-schema.d.ts +4 -3
- package/dist/transformers/utils/jsdoc-to-doc-schema.js +11 -33
- package/dist/transformers/utils/jsdoc-to-doc-schema.js.map +1 -1
- package/dist/transformers/utils/parse-type-from-quick-info.js +4 -0
- package/dist/transformers/utils/parse-type-from-quick-info.js.map +1 -1
- package/dist/transformers/utils/to-function-like-schema.js +1 -8
- package/dist/transformers/utils/to-function-like-schema.js.map +1 -1
- package/dist/transformers/utils/type-element-to-schema.js +1 -8
- package/dist/transformers/utils/type-element-to-schema.js.map +1 -1
- package/dist/transformers/utils/type-node-to-schema.js +9 -9
- package/dist/transformers/utils/type-node-to-schema.js.map +1 -1
- package/dist/transformers/variable-declaration.js +13 -11
- package/dist/transformers/variable-declaration.js.map +1 -1
- package/dist/transformers/variable-statement.js +1 -1
- package/dist/transformers/variable-statement.js.map +1 -1
- package/dist/typescript.extractor.d.ts +2 -1
- package/dist/typescript.extractor.js +4 -4
- package/dist/typescript.extractor.js.map +1 -1
- package/dist/typescript.main.runtime.js +4 -4
- package/dist/typescript.main.runtime.js.map +1 -1
- package/package-tar/teambit-typescript-0.0.895.tgz +0 -0
- package/package.json +15 -14
- package/{preview-1667878820252.js → preview-1667965305919.js} +2 -2
- package/transformers/binding-element.ts +1 -2
- package/transformers/class-declaration.ts +97 -0
- package/transformers/enum-declaration.ts +14 -3
- package/transformers/export-declaration.ts +3 -3
- package/transformers/index.ts +1 -1
- package/transformers/interface-declaration.ts +49 -5
- package/transformers/source-file-transformer.ts +2 -2
- package/transformers/type-alias.ts +1 -2
- package/transformers/utils/class-element-to-schema.ts +4 -3
- package/transformers/utils/jsdoc-to-doc-schema.ts +15 -22
- package/transformers/utils/parse-type-from-quick-info.ts +3 -0
- package/transformers/utils/to-function-like-schema.ts +2 -2
- package/transformers/utils/type-element-to-schema.ts +1 -2
- package/transformers/utils/type-node-to-schema.ts +12 -3
- package/transformers/variable-declaration.ts +21 -3
- package/transformers/variable-statement.ts +2 -2
- package/dist/transformers/class-deceleration.js +0 -87
- package/dist/transformers/class-deceleration.js.map +0 -1
- package/package-tar/teambit-typescript-0.0.894.tgz +0 -0
- package/transformers/class-deceleration.ts +0 -37
|
@@ -9,10 +9,10 @@ Object.defineProperty(exports, "BindingElementTransformer", {
|
|
|
9
9
|
return _bindingElement().BindingElementTransformer;
|
|
10
10
|
}
|
|
11
11
|
});
|
|
12
|
-
Object.defineProperty(exports, "
|
|
12
|
+
Object.defineProperty(exports, "ClassDeclarationTransformer", {
|
|
13
13
|
enumerable: true,
|
|
14
14
|
get: function () {
|
|
15
|
-
return
|
|
15
|
+
return _classDeclaration().ClassDeclarationTransformer;
|
|
16
16
|
}
|
|
17
17
|
});
|
|
18
18
|
Object.defineProperty(exports, "EnumDeclarationTransformer", {
|
|
@@ -111,9 +111,9 @@ function _typeAlias() {
|
|
|
111
111
|
};
|
|
112
112
|
return data;
|
|
113
113
|
}
|
|
114
|
-
function
|
|
115
|
-
const data = require("./class-
|
|
116
|
-
|
|
114
|
+
function _classDeclaration() {
|
|
115
|
+
const data = require("./class-declaration");
|
|
116
|
+
_classDeclaration = function () {
|
|
117
117
|
return data;
|
|
118
118
|
};
|
|
119
119
|
return data;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export { ExportDeclaration } from './export-declaration';\nexport { FunctionDeclaration } from './function-declaration';\nexport { VariableStatementTransformer } from './variable-statement';\nexport { VariableDeclaration } from './variable-declaration';\nexport { SourceFileTransformer } from './source-file-transformer';\nexport { TypeAliasTransformer } from './type-alias';\nexport {
|
|
1
|
+
{"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export { ExportDeclaration } from './export-declaration';\nexport { FunctionDeclaration } from './function-declaration';\nexport { VariableStatementTransformer } from './variable-statement';\nexport { VariableDeclaration } from './variable-declaration';\nexport { SourceFileTransformer } from './source-file-transformer';\nexport { TypeAliasTransformer } from './type-alias';\nexport { ClassDeclarationTransformer } from './class-declaration';\nexport { InterfaceDeclarationTransformer } from './interface-declaration';\nexport { EnumDeclarationTransformer } from './enum-declaration';\nexport { BindingElementTransformer } from './binding-element';\nexport { ExportAssignmentDeclaration } from './export-assignment-declaration';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA"}
|
|
@@ -6,5 +6,6 @@ import { ExportIdentifier } from '../export-identifier';
|
|
|
6
6
|
export declare class InterfaceDeclarationTransformer implements SchemaTransformer {
|
|
7
7
|
predicate(node: Node): boolean;
|
|
8
8
|
getIdentifiers(node: InterfaceDeclaration): Promise<ExportIdentifier[]>;
|
|
9
|
+
private getExpressionWithTypeArgs;
|
|
9
10
|
transform(interfaceDec: InterfaceDeclaration, context: SchemaExtractorContext): Promise<InterfaceSchema>;
|
|
10
11
|
}
|
|
@@ -1,11 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
require("core-js/modules/es.array.flat-map.js");
|
|
5
|
+
require("core-js/modules/es.array.unscopables.flat-map.js");
|
|
4
6
|
require("core-js/modules/es.promise.js");
|
|
5
7
|
Object.defineProperty(exports, "__esModule", {
|
|
6
8
|
value: true
|
|
7
9
|
});
|
|
8
10
|
exports.InterfaceDeclarationTransformer = void 0;
|
|
11
|
+
function _defineProperty2() {
|
|
12
|
+
const data = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
13
|
+
_defineProperty2 = function () {
|
|
14
|
+
return data;
|
|
15
|
+
};
|
|
16
|
+
return data;
|
|
17
|
+
}
|
|
9
18
|
function _typescript() {
|
|
10
19
|
const data = require("typescript");
|
|
11
20
|
_typescript = function () {
|
|
@@ -41,13 +50,15 @@ function _typeElementToSchema() {
|
|
|
41
50
|
};
|
|
42
51
|
return data;
|
|
43
52
|
}
|
|
44
|
-
function
|
|
45
|
-
const data = require("./utils/
|
|
46
|
-
|
|
53
|
+
function _typeNodeToSchema() {
|
|
54
|
+
const data = require("./utils/type-node-to-schema");
|
|
55
|
+
_typeNodeToSchema = function () {
|
|
47
56
|
return data;
|
|
48
57
|
};
|
|
49
58
|
return data;
|
|
50
59
|
}
|
|
60
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
61
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2().default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
51
62
|
class InterfaceDeclarationTransformer {
|
|
52
63
|
predicate(node) {
|
|
53
64
|
return node.kind === _typescript().SyntaxKind.InterfaceDeclaration;
|
|
@@ -55,10 +66,41 @@ class InterfaceDeclarationTransformer {
|
|
|
55
66
|
async getIdentifiers(node) {
|
|
56
67
|
return [new (_exportIdentifier().ExportIdentifier)(node.name.getText(), node.getSourceFile().fileName)];
|
|
57
68
|
}
|
|
69
|
+
async getExpressionWithTypeArgs(node, context) {
|
|
70
|
+
if (!node.heritageClauses) return [];
|
|
71
|
+
return (0, _pMapSeries().default)(node.heritageClauses.filter(heritageClause => heritageClause.token === _typescript().SyntaxKind.ExtendsKeyword).flatMap(h => {
|
|
72
|
+
const {
|
|
73
|
+
types
|
|
74
|
+
} = h;
|
|
75
|
+
const name = h.getText();
|
|
76
|
+
return types.map(type => _objectSpread(_objectSpread({}, type), {}, {
|
|
77
|
+
name
|
|
78
|
+
}));
|
|
79
|
+
}), async expressionWithTypeArgs => {
|
|
80
|
+
const {
|
|
81
|
+
typeArguments,
|
|
82
|
+
expression,
|
|
83
|
+
name
|
|
84
|
+
} = expressionWithTypeArgs;
|
|
85
|
+
const typeArgsNodes = typeArguments ? await (0, _pMapSeries().default)(typeArguments, t => (0, _typeNodeToSchema().typeNodeToSchema)(t, context)) : [];
|
|
86
|
+
const location = context.getLocation(expression);
|
|
87
|
+
const expressionNode = (await context.visitDefinition(expression)) || new (_semanticsEntities().UnresolvedSchema)(location, expression.getText());
|
|
88
|
+
return new (_semanticsEntities().ExpressionWithTypeArgumentsSchema)(typeArgsNodes, expressionNode, name, location);
|
|
89
|
+
});
|
|
90
|
+
}
|
|
58
91
|
async transform(interfaceDec, context) {
|
|
92
|
+
var _interfaceDec$typePar;
|
|
59
93
|
const members = await (0, _pMapSeries().default)(interfaceDec.members, member => (0, _typeElementToSchema().typeElementToSchema)(member, context));
|
|
60
|
-
const doc = await
|
|
61
|
-
|
|
94
|
+
const doc = await context.jsDocToDocSchema(interfaceDec);
|
|
95
|
+
const signature = interfaceDec.name ? await context.getQuickInfoDisplayString(interfaceDec.name) : undefined;
|
|
96
|
+
const extendsNodes = await this.getExpressionWithTypeArgs(interfaceDec, context);
|
|
97
|
+
const typeParameters = (_interfaceDec$typePar = interfaceDec.typeParameters) === null || _interfaceDec$typePar === void 0 ? void 0 : _interfaceDec$typePar.map(typeParam => {
|
|
98
|
+
return typeParam.name.getText();
|
|
99
|
+
});
|
|
100
|
+
if (!signature) {
|
|
101
|
+
throw Error(`Missing signature for interface ${interfaceDec.name.getText()} declaration`);
|
|
102
|
+
}
|
|
103
|
+
return new (_semanticsEntities().InterfaceSchema)(context.getLocation(interfaceDec), interfaceDec.name.getText(), signature, extendsNodes, members, doc, typeParameters);
|
|
62
104
|
}
|
|
63
105
|
}
|
|
64
106
|
exports.InterfaceDeclarationTransformer = InterfaceDeclarationTransformer;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["InterfaceDeclarationTransformer","predicate","node","kind","SyntaxKind","InterfaceDeclaration","getIdentifiers","ExportIdentifier","name","getText","getSourceFile","fileName","
|
|
1
|
+
{"version":3,"names":["InterfaceDeclarationTransformer","predicate","node","kind","SyntaxKind","InterfaceDeclaration","getIdentifiers","ExportIdentifier","name","getText","getSourceFile","fileName","getExpressionWithTypeArgs","context","heritageClauses","pMapSeries","filter","heritageClause","token","ExtendsKeyword","flatMap","h","types","map","type","expressionWithTypeArgs","typeArguments","expression","typeArgsNodes","t","typeNodeToSchema","location","getLocation","expressionNode","visitDefinition","UnresolvedSchema","ExpressionWithTypeArgumentsSchema","transform","interfaceDec","members","member","typeElementToSchema","doc","jsDocToDocSchema","signature","getQuickInfoDisplayString","undefined","extendsNodes","typeParameters","typeParam","Error","InterfaceSchema"],"sources":["interface-declaration.ts"],"sourcesContent":["import ts, { Node, InterfaceDeclaration, SyntaxKind } from 'typescript';\nimport pMapSeries from 'p-map-series';\nimport {\n ExpressionWithTypeArgumentsSchema,\n InterfaceSchema,\n UnresolvedSchema,\n} from '@teambit/semantics.entities.semantic-schema';\nimport { SchemaTransformer } from '../schema-transformer';\nimport { SchemaExtractorContext } from '../schema-extractor-context';\nimport { ExportIdentifier } from '../export-identifier';\nimport { typeElementToSchema } from './utils/type-element-to-schema';\nimport { typeNodeToSchema } from './utils/type-node-to-schema';\n\nexport class InterfaceDeclarationTransformer implements SchemaTransformer {\n predicate(node: Node) {\n return node.kind === SyntaxKind.InterfaceDeclaration;\n }\n\n async getIdentifiers(node: InterfaceDeclaration): Promise<ExportIdentifier[]> {\n return [new ExportIdentifier(node.name.getText(), node.getSourceFile().fileName)];\n }\n\n private async getExpressionWithTypeArgs(node: InterfaceDeclaration, context: SchemaExtractorContext) {\n if (!node.heritageClauses) return [];\n\n return pMapSeries(\n node.heritageClauses\n .filter((heritageClause: ts.HeritageClause) => heritageClause.token === SyntaxKind.ExtendsKeyword)\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) => typeNodeToSchema(t, context)) : [];\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(interfaceDec: InterfaceDeclaration, context: SchemaExtractorContext) {\n const members = await pMapSeries(interfaceDec.members, (member) => typeElementToSchema(member, context));\n const doc = await context.jsDocToDocSchema(interfaceDec);\n const signature = interfaceDec.name ? await context.getQuickInfoDisplayString(interfaceDec.name) : undefined;\n const extendsNodes = await this.getExpressionWithTypeArgs(interfaceDec, context);\n const typeParameters = interfaceDec.typeParameters?.map((typeParam) => {\n return typeParam.name.getText();\n });\n\n if (!signature) {\n throw Error(`Missing signature for interface ${interfaceDec.name.getText()} declaration`);\n }\n\n return new InterfaceSchema(\n context.getLocation(interfaceDec),\n interfaceDec.name.getText(),\n signature,\n extendsNodes,\n members,\n doc,\n typeParameters\n );\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAAA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAOA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAA+D;AAAA;AAExD,MAAMA,+BAA+B,CAA8B;EACxEC,SAAS,CAACC,IAAU,EAAE;IACpB,OAAOA,IAAI,CAACC,IAAI,KAAKC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EzB,IAAI,EAAEuB,QAAQ,CAAC;IAC7F,CAAC,CACF;EACH;EAEA,MAAMM,SAAS,CAACC,YAAkC,EAAEzB,OAA+B,EAAE;IAAA;IACnF,MAAM0B,OAAO,GAAG,MAAM,IAAAxB,qBAAU,EAACuB,YAAY,CAACC,OAAO,EAAGC,MAAM,IAAK,IAAAC,0CAAmB,EAACD,MAAM,EAAE3B,OAAO,CAAC,CAAC;IACxG,MAAM6B,GAAG,GAAG,MAAM7B,OAAO,CAAC8B,gBAAgB,CAACL,YAAY,CAAC;IACxD,MAAMM,SAAS,GAAGN,YAAY,CAAC9B,IAAI,GAAG,MAAMK,OAAO,CAACgC,yBAAyB,CAACP,YAAY,CAAC9B,IAAI,CAAC,GAAGsC,SAAS;IAC5G,MAAMC,YAAY,GAAG,MAAM,IAAI,CAACnC,yBAAyB,CAAC0B,YAAY,EAAEzB,OAAO,CAAC;IAChF,MAAMmC,cAAc,4BAAGV,YAAY,CAACU,cAAc,0DAA3B,sBAA6BzB,GAAG,CAAE0B,SAAS,IAAK;MACrE,OAAOA,SAAS,CAACzC,IAAI,CAACC,OAAO,EAAE;IACjC,CAAC,CAAC;IAEF,IAAI,CAACmC,SAAS,EAAE;MACd,MAAMM,KAAK,CAAE,mCAAkCZ,YAAY,CAAC9B,IAAI,CAACC,OAAO,EAAG,cAAa,CAAC;IAC3F;IAEA,OAAO,KAAI0C,oCAAe,EACxBtC,OAAO,CAACmB,WAAW,CAACM,YAAY,CAAC,EACjCA,YAAY,CAAC9B,IAAI,CAACC,OAAO,EAAE,EAC3BmC,SAAS,EACTG,YAAY,EACZR,OAAO,EACPG,GAAG,EACHM,cAAc,CACf;EACH;AACF;AAAC"}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { Node, SourceFile } from 'typescript';
|
|
2
|
-
import {
|
|
2
|
+
import { ModuleSchema } from '@teambit/semantics.entities.semantic-schema';
|
|
3
3
|
import { SchemaTransformer } from '../schema-transformer';
|
|
4
4
|
import { ExportIdentifier } from '../export-identifier';
|
|
5
5
|
import { SchemaExtractorContext } from '../schema-extractor-context';
|
|
6
6
|
export declare class SourceFileTransformer implements SchemaTransformer {
|
|
7
7
|
predicate(node: Node): boolean;
|
|
8
8
|
getIdentifiers(sourceFile: SourceFile, context: SchemaExtractorContext): Promise<ExportIdentifier[]>;
|
|
9
|
-
transform(node: SourceFile, context: SchemaExtractorContext): Promise<
|
|
9
|
+
transform(node: SourceFile, context: SchemaExtractorContext): Promise<ModuleSchema>;
|
|
10
10
|
/**
|
|
11
11
|
* list all exports of a source file.
|
|
12
12
|
*/
|
|
@@ -56,7 +56,7 @@ class SourceFileTransformer {
|
|
|
56
56
|
const schemas = await (0, _pMapSeries().default)(exports, exportNode => {
|
|
57
57
|
return context.computeSchema(exportNode);
|
|
58
58
|
});
|
|
59
|
-
return new (_semanticsEntities().
|
|
59
|
+
return new (_semanticsEntities().ModuleSchema)(context.getLocation(node), schemas);
|
|
60
60
|
}
|
|
61
61
|
|
|
62
62
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["SourceFileTransformer","predicate","node","kind","ts","SyntaxKind","SourceFile","getIdentifiers","sourceFile","context","exports","listExports","exportNames","Promise","all","map","getExportedIdentifiers","exportIds","flatten","reduce","acc","current","item","find","exportName","id","push","transform","schemas","pMapSeries","exportNode","computeSchema","
|
|
1
|
+
{"version":3,"names":["SourceFileTransformer","predicate","node","kind","ts","SyntaxKind","SourceFile","getIdentifiers","sourceFile","context","exports","listExports","exportNames","Promise","all","map","getExportedIdentifiers","exportIds","flatten","reduce","acc","current","item","find","exportName","id","push","transform","schemas","pMapSeries","exportNode","computeSchema","ModuleSchema","getLocation","ast","compact","statements","statement","ExportDeclaration","isExport","Boolean","modifiers","modifier","ExportKeyword"],"sources":["source-file-transformer.ts"],"sourcesContent":["import ts, { Node, SourceFile } from 'typescript';\nimport { compact, flatten } from 'lodash';\nimport pMapSeries from 'p-map-series';\nimport { ModuleSchema } from '@teambit/semantics.entities.semantic-schema';\nimport { SchemaTransformer } from '../schema-transformer';\nimport { ExportIdentifier } from '../export-identifier';\nimport { SchemaExtractorContext } from '../schema-extractor-context';\n\nexport class SourceFileTransformer implements SchemaTransformer {\n predicate(node: Node) {\n return node.kind === ts.SyntaxKind.SourceFile;\n }\n\n async getIdentifiers(sourceFile: SourceFile, context: SchemaExtractorContext) {\n const exports = this.listExports(sourceFile);\n\n const exportNames = await Promise.all(\n exports.map((node: Node) => {\n return context.getExportedIdentifiers(node);\n })\n );\n\n const exportIds = flatten(exportNames).reduce<ExportIdentifier[]>((acc, current) => {\n const item = acc.find((exportName) => exportName.id === current.id);\n if (!item) acc.push(current);\n return acc;\n }, []);\n\n return exportIds;\n }\n\n async transform(node: SourceFile, context: SchemaExtractorContext) {\n const exports = this.listExports(node);\n const schemas = await pMapSeries(exports, (exportNode) => {\n return context.computeSchema(exportNode);\n });\n\n return new ModuleSchema(context.getLocation(node), schemas);\n }\n\n /**\n * list all exports of a source file.\n */\n private listExports(ast: SourceFile): Node[] {\n return compact(\n ast.statements.map((statement) => {\n if (statement.kind === ts.SyntaxKind.ExportDeclaration) return statement;\n const isExport = Boolean(\n statement.modifiers?.find((modifier) => {\n return modifier.kind === ts.SyntaxKind.ExportKeyword;\n })\n );\n\n // eslint-disable-next-line consistent-return\n if (!isExport) return;\n return statement;\n })\n );\n }\n}\n"],"mappings":";;;;;;;;;AAAA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAKO,MAAMA,qBAAqB,CAA8B;EAC9DC,SAAS,CAACC,IAAU,EAAE;IACpB,OAAOA,IAAI,CAACC,IAAI,KAAKC,qBAAE,CAACC,UAAU,CAACC,UAAU;EAC/C;EAEA,MAAMC,cAAc,CAACC,UAAsB,EAAEC,OAA+B,EAAE;IAC5E,MAAM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H,SAAS,CAACI,SAAS,yDAAnB,qBAAqBlB,IAAI,CAAEmB,QAAQ,IAAK;QACtC,OAAOA,QAAQ,CAACvC,IAAI,KAAKC,qBAAE,CAACC,UAAU,CAACsC,aAAa;MACtD,CAAC,CAAC,CACH;;MAED;MACA,IAAI,CAACJ,QAAQ,EAAE;MACf,OAAOF,SAAS;IAClB,CAAC,CAAC,CACH;EACH;AACF;AAAC"}
|
|
@@ -34,13 +34,6 @@ function _typeNodeToSchema() {
|
|
|
34
34
|
};
|
|
35
35
|
return data;
|
|
36
36
|
}
|
|
37
|
-
function _jsdocToDocSchema() {
|
|
38
|
-
const data = require("./utils/jsdoc-to-doc-schema");
|
|
39
|
-
_jsdocToDocSchema = function () {
|
|
40
|
-
return data;
|
|
41
|
-
};
|
|
42
|
-
return data;
|
|
43
|
-
}
|
|
44
37
|
class TypeAliasTransformer {
|
|
45
38
|
predicate(node) {
|
|
46
39
|
return node.kind === _typescript().default.SyntaxKind.TypeAliasDeclaration;
|
|
@@ -54,7 +47,7 @@ class TypeAliasTransformer {
|
|
|
54
47
|
async transform(typeAlias, context) {
|
|
55
48
|
const type = await (0, _typeNodeToSchema().typeNodeToSchema)(typeAlias.type, context);
|
|
56
49
|
const displaySig = await context.getQuickInfoDisplayString(typeAlias.name);
|
|
57
|
-
const doc = await
|
|
50
|
+
const doc = await context.jsDocToDocSchema(typeAlias);
|
|
58
51
|
return new (_semanticsEntities().TypeSchema)(context.getLocation(typeAlias), this.getName(typeAlias), type, displaySig, doc);
|
|
59
52
|
}
|
|
60
53
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["TypeAliasTransformer","predicate","node","kind","ts","SyntaxKind","TypeAliasDeclaration","getIdentifiers","ExportIdentifier","name","getText","getSourceFile","fileName","getName","transform","typeAlias","context","type","typeNodeToSchema","displaySig","getQuickInfoDisplayString","doc","jsDocToDocSchema","TypeSchema","getLocation"],"sources":["type-alias.ts"],"sourcesContent":["import ts, { Node, TypeAliasDeclaration } from 'typescript';\nimport { TypeSchema } from '@teambit/semantics.entities.semantic-schema';\nimport { SchemaTransformer } from '../schema-transformer';\nimport { SchemaExtractorContext } from '../schema-extractor-context';\nimport { ExportIdentifier } from '../export-identifier';\nimport { typeNodeToSchema } from './utils/type-node-to-schema';\
|
|
1
|
+
{"version":3,"names":["TypeAliasTransformer","predicate","node","kind","ts","SyntaxKind","TypeAliasDeclaration","getIdentifiers","ExportIdentifier","name","getText","getSourceFile","fileName","getName","transform","typeAlias","context","type","typeNodeToSchema","displaySig","getQuickInfoDisplayString","doc","jsDocToDocSchema","TypeSchema","getLocation"],"sources":["type-alias.ts"],"sourcesContent":["import ts, { Node, TypeAliasDeclaration } from 'typescript';\nimport { TypeSchema } from '@teambit/semantics.entities.semantic-schema';\nimport { SchemaTransformer } from '../schema-transformer';\nimport { SchemaExtractorContext } from '../schema-extractor-context';\nimport { ExportIdentifier } from '../export-identifier';\nimport { typeNodeToSchema } from './utils/type-node-to-schema';\n\nexport class TypeAliasTransformer implements SchemaTransformer {\n predicate(node: Node) {\n return node.kind === ts.SyntaxKind.TypeAliasDeclaration;\n }\n\n async getIdentifiers(node: TypeAliasDeclaration) {\n return [new ExportIdentifier(node.name.getText(), node.getSourceFile().fileName)];\n }\n\n private getName(node: TypeAliasDeclaration): string {\n return node.name.getText();\n }\n\n async transform(typeAlias: TypeAliasDeclaration, context: SchemaExtractorContext) {\n const type = await typeNodeToSchema(typeAlias.type, context);\n const displaySig = await context.getQuickInfoDisplayString(typeAlias.name);\n const doc = await context.jsDocToDocSchema(typeAlias);\n return new TypeSchema(context.getLocation(typeAlias), this.getName(typeAlias), type, displaySig, doc);\n }\n}\n"],"mappings":";;;;;;;;AAAA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAGA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAEO,MAAMA,oBAAoB,CAA8B;EAC7DC,SAAS,CAACC,IAAU,EAAE;IACpB,OAAOA,IAAI,CAACC,IAAI,KAAKC,qBAAE,CAACC,UAAU,CAACC,oBAAoB;EACzD;EAEA,MAAMC,cAAc,CAACL,IAA0B,EAAE;IAC/C,OAAO,CAAC,KAAIM,oCAAgB,EAACN,IAAI,CAACO,IAAI,CAACC,OAAO,EAAE,EAAER,IAAI,CAACS,aAAa,EAAE,CAACC,QAAQ,CAAC,CAAC;EACnF;EAEQC,OAAO,CAACX,IAA0B,EAAU;IAClD,OAAOA,IAAI,CAACO,IAAI,CAACC,OAAO,EAAE;EAC5B;EAEA,MAAMI,SAAS,CAACC,SAA+B,EAAEC,OAA+B,EAAE;IAChF,MAAMC,IAAI,GAAG,MAAM,IAAAC,oCAAgB,EAACH,SAAS,CAACE,IAAI,EAAED,OAAO,CAAC;IAC5D,MAAMG,UAAU,GAAG,MAAMH,OAAO,CAACI,yBAAyB,CAACL,SAAS,CAACN,IAAI,CAAC;IAC1E,MAAMY,GAAG,GAAG,MAAML,OAAO,CAACM,gBAAgB,CAACP,SAAS,CAAC;IACrD,OAAO,KAAIQ,+BAAU,EAACP,OAAO,CAACQ,WAAW,CAACT,SAAS,CAAC,EAAE,IAAI,CAACF,OAAO,CAACE,SAAS,CAAC,EAAEE,IAAI,EAAEE,UAAU,EAAEE,GAAG,CAAC;EACvG;AACF;AAAC"}
|
|
@@ -47,13 +47,6 @@ function _toFunctionLikeSchema() {
|
|
|
47
47
|
};
|
|
48
48
|
return data;
|
|
49
49
|
}
|
|
50
|
-
function _jsdocToDocSchema() {
|
|
51
|
-
const data = require("./jsdoc-to-doc-schema");
|
|
52
|
-
_jsdocToDocSchema = function () {
|
|
53
|
-
return data;
|
|
54
|
-
};
|
|
55
|
-
return data;
|
|
56
|
-
}
|
|
57
50
|
async function classElementToSchema(node, context) {
|
|
58
51
|
switch (node.kind) {
|
|
59
52
|
case _typescript().SyntaxKind.Constructor:
|
|
@@ -78,18 +71,21 @@ async function classElementToSchema(node, context) {
|
|
|
78
71
|
}
|
|
79
72
|
}
|
|
80
73
|
async function constructor(node, context) {
|
|
74
|
+
var _info$body;
|
|
81
75
|
const args = await (0, _getParams().getParams)(node.parameters, context);
|
|
82
|
-
|
|
76
|
+
const info = await context.getQuickInfo(node);
|
|
77
|
+
const displaySig = info === null || info === void 0 ? void 0 : (_info$body = info.body) === null || _info$body === void 0 ? void 0 : _info$body.displayString;
|
|
78
|
+
return new (_semanticsEntities().ConstructorSchema)(context.getLocation(node), args, displaySig);
|
|
83
79
|
}
|
|
84
80
|
async function propertyDeclaration(node, context) {
|
|
85
|
-
var _info$
|
|
81
|
+
var _info$body2;
|
|
86
82
|
const name = node.name.getText();
|
|
87
83
|
const info = await context.getQuickInfo(node.name);
|
|
88
|
-
const displaySig = info === null || info === void 0 ? void 0 : (_info$
|
|
84
|
+
const displaySig = info === null || info === void 0 ? void 0 : (_info$body2 = info.body) === null || _info$body2 === void 0 ? void 0 : _info$body2.displayString;
|
|
89
85
|
const typeStr = (0, _parseTypeFromQuickInfo().parseTypeFromQuickInfo)(info);
|
|
90
86
|
const type = await context.resolveType(node, typeStr);
|
|
91
87
|
const isOptional = Boolean(node.questionToken);
|
|
92
|
-
const doc = await
|
|
88
|
+
const doc = await context.jsDocToDocSchema(node);
|
|
93
89
|
return new (_semanticsEntities().VariableLikeSchema)(context.getLocation(node), name, displaySig || '', type, isOptional, doc);
|
|
94
90
|
}
|
|
95
91
|
async function methodDeclaration(node, context) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["classElementToSchema","node","context","kind","SyntaxKind","Constructor","constructor","PropertyDeclaration","propertyDeclaration","MethodDeclaration","methodDeclaration","GetAccessor","getAccessor","SetAccessor","setAccessor","IndexSignature","indexSignature","ClassStaticBlockDeclaration","SemicolonClassElement","Error","args","getParams","parameters","
|
|
1
|
+
{"version":3,"names":["classElementToSchema","node","context","kind","SyntaxKind","Constructor","constructor","PropertyDeclaration","propertyDeclaration","MethodDeclaration","methodDeclaration","GetAccessor","getAccessor","SetAccessor","setAccessor","IndexSignature","indexSignature","ClassStaticBlockDeclaration","SemicolonClassElement","Error","args","getParams","parameters","info","getQuickInfo","displaySig","body","displayString","ConstructorSchema","getLocation","name","getText","typeStr","parseTypeFromQuickInfo","type","resolveType","isOptional","Boolean","questionToken","doc","jsDocToDocSchema","VariableLikeSchema","toFunctionLikeSchema"],"sources":["class-element-to-schema.ts"],"sourcesContent":["import {\n ClassElement,\n ConstructorDeclaration,\n GetAccessorDeclaration,\n IndexSignatureDeclaration,\n MethodDeclaration,\n PropertyDeclaration,\n SetAccessorDeclaration,\n SyntaxKind,\n} from 'typescript';\nimport { ConstructorSchema, SchemaNode, VariableLikeSchema } from '@teambit/semantics.entities.semantic-schema';\nimport { SchemaExtractorContext } from '../../schema-extractor-context';\nimport { getParams } from './get-params';\nimport { getAccessor, indexSignature, setAccessor } from './type-element-to-schema';\nimport { parseTypeFromQuickInfo } from './parse-type-from-quick-info';\nimport { toFunctionLikeSchema } from './to-function-like-schema';\n\nexport async function classElementToSchema(\n node: ClassElement,\n context: SchemaExtractorContext\n): Promise<SchemaNode | null> {\n switch (node.kind) {\n case SyntaxKind.Constructor:\n return constructor(node as ConstructorDeclaration, context);\n case SyntaxKind.PropertyDeclaration:\n return propertyDeclaration(node as PropertyDeclaration, context);\n case SyntaxKind.MethodDeclaration:\n return methodDeclaration(node as MethodDeclaration, context);\n case SyntaxKind.GetAccessor:\n return getAccessor(node as GetAccessorDeclaration, context);\n case SyntaxKind.SetAccessor:\n return setAccessor(node as SetAccessorDeclaration, context);\n case SyntaxKind.IndexSignature:\n return indexSignature(node as IndexSignatureDeclaration, context);\n case SyntaxKind.ClassStaticBlockDeclaration: // not sure what is it, but the name sounds like not something we need\n case SyntaxKind.SemicolonClassElement: // seems to be just a semicolon\n return null;\n default:\n // should never be here unless typescript added new class elements\n throw new Error(`unrecognized ClassElement type. got ${node.kind}`);\n }\n}\n\nasync function constructor(node: ConstructorDeclaration, context: SchemaExtractorContext) {\n const args = await getParams(node.parameters, context);\n const info = await context.getQuickInfo(node);\n const displaySig = info?.body?.displayString;\n return new ConstructorSchema(context.getLocation(node), args, displaySig);\n}\n\nasync function propertyDeclaration(node: PropertyDeclaration, 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 isOptional = Boolean(node.questionToken);\n const doc = await context.jsDocToDocSchema(node);\n return new VariableLikeSchema(context.getLocation(node), name, displaySig || '', type, isOptional, doc);\n}\n\nasync function methodDeclaration(node: MethodDeclaration, context: SchemaExtractorContext) {\n return toFunctionLikeSchema(node, context);\n}\n"],"mappings":";;;;;;;AAAA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAUA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAEA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAEO,eAAeA,oBAAoB,CACxCC,IAAkB,EAClBC,OAA+B,EACH;EAC5B,QAAQD,IAAI,CAACE,IAAI;IACf,KAAKC,wBAAU,CAACC,WAAW;MACzB,OAAOC,WAAW,CAACL,IAAI,EAA4BC,OAAO,CAAC;IAC7D,KAAKE,wBAAU,CAACG,mBAAmB;MACjC,OAAOC,mBAAmB,CAACP,IAAI,EAAyBC,OAAO,CAAC;IAClE,KAAKE,wBAAU,CAACK,iBAAiB;MAC/B,OAAOC,iBAAiB,CAACT,IAAI,EAAuBC,OAAO,CAAC;IAC9D,KAAKE,wBAAU,CAACO,WAAW;MACzB,OAAO,IAAAC,kCAAW,EAACX,IAAI,EAA4BC,OAAO,CAAC;IAC7D,KAAKE,wBAAU,CAACS,WAAW;MACzB,OAAO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O,CAAC;EACrD,MAAMI,UAAU,GAAGC,OAAO,CAACpC,IAAI,CAACqC,aAAa,CAAC;EAC9C,MAAMC,GAAG,GAAG,MAAMrC,OAAO,CAACsC,gBAAgB,CAACvC,IAAI,CAAC;EAChD,OAAO,KAAIwC,uCAAkB,EAACvC,OAAO,CAAC2B,WAAW,CAAC5B,IAAI,CAAC,EAAE6B,IAAI,EAAEL,UAAU,IAAI,EAAE,EAAES,IAAI,EAAEE,UAAU,EAAEG,GAAG,CAAC;AACzG;AAEA,eAAe7B,iBAAiB,CAACT,IAAuB,EAAEC,OAA+B,EAAE;EACzF,OAAO,IAAAwC,4CAAoB,EAACzC,IAAI,EAAEC,OAAO,CAAC;AAC5C"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { JSDocTag } from 'typescript';
|
|
2
|
+
import { TagSchema } from '@teambit/semantics.entities.semantic-schema';
|
|
3
|
+
import { Formatter } from '@teambit/formatter';
|
|
3
4
|
import { SchemaExtractorContext } from '../../schema-extractor-context';
|
|
4
|
-
export declare function
|
|
5
|
+
export declare function tagParser(tag: JSDocTag, context: SchemaExtractorContext, formatter: Formatter): Promise<TagSchema>;
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
3
|
require("core-js/modules/es.promise.js");
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
|
-
exports.
|
|
7
|
+
exports.tagParser = tagParser;
|
|
9
8
|
function _typescript() {
|
|
10
9
|
const data = require("typescript");
|
|
11
10
|
_typescript = function () {
|
|
@@ -13,20 +12,6 @@ function _typescript() {
|
|
|
13
12
|
};
|
|
14
13
|
return data;
|
|
15
14
|
}
|
|
16
|
-
function _tsutils() {
|
|
17
|
-
const data = require("tsutils");
|
|
18
|
-
_tsutils = function () {
|
|
19
|
-
return data;
|
|
20
|
-
};
|
|
21
|
-
return data;
|
|
22
|
-
}
|
|
23
|
-
function _pMapSeries() {
|
|
24
|
-
const data = _interopRequireDefault(require("p-map-series"));
|
|
25
|
-
_pMapSeries = function () {
|
|
26
|
-
return data;
|
|
27
|
-
};
|
|
28
|
-
return data;
|
|
29
|
-
}
|
|
30
15
|
function _semanticsEntities() {
|
|
31
16
|
const data = require("@teambit/semantics.entities.semantic-schema");
|
|
32
17
|
_semanticsEntities = function () {
|
|
@@ -43,23 +28,7 @@ function _typeNodeToSchema() {
|
|
|
43
28
|
}
|
|
44
29
|
/* eslint-disable no-fallthrough */
|
|
45
30
|
|
|
46
|
-
async function
|
|
47
|
-
if (!(0, _tsutils().canHaveJsDoc)(node)) {
|
|
48
|
-
return undefined;
|
|
49
|
-
}
|
|
50
|
-
const jsDocs = (0, _tsutils().getJsDoc)(node);
|
|
51
|
-
if (!jsDocs.length) {
|
|
52
|
-
return undefined;
|
|
53
|
-
}
|
|
54
|
-
// not sure how common it is to have multiple JSDocs. never seen it before.
|
|
55
|
-
// regardless, in typescript implementation of methods like `getJSDocDeprecatedTag()`, they use the first one. (`getFirstJSDocTag()`)
|
|
56
|
-
const jsDoc = jsDocs[0];
|
|
57
|
-
const location = context.getLocation(jsDoc);
|
|
58
|
-
const comment = (0, _typescript().getTextOfJSDocComment)(jsDoc.comment);
|
|
59
|
-
const tags = jsDoc.tags ? await (0, _pMapSeries().default)(jsDoc.tags, tag => tagParser(tag, context)) : undefined;
|
|
60
|
-
return new (_semanticsEntities().DocSchema)(location, jsDoc.getText(), comment, tags);
|
|
61
|
-
}
|
|
62
|
-
async function tagParser(tag, context) {
|
|
31
|
+
async function tagParser(tag, context, formatter) {
|
|
63
32
|
// for some reason, in some cases, if `tag.getSourceFile()` is not provided to the `getText()`, it throws "Cannot read property 'text' of undefined"
|
|
64
33
|
|
|
65
34
|
switch (tag.kind) {
|
|
@@ -106,6 +75,15 @@ async function tagParser(tag, context) {
|
|
|
106
75
|
default:
|
|
107
76
|
{
|
|
108
77
|
const tagName = tag.tagName.getText(tag.getSourceFile());
|
|
78
|
+
if (tagName === 'example') {
|
|
79
|
+
const comment = (0, _typescript().getTextOfJSDocComment)(tag.comment);
|
|
80
|
+
try {
|
|
81
|
+
const formattedComment = comment && (await formatter.formatSnippet(comment));
|
|
82
|
+
return new (_semanticsEntities().TagSchema)(context.getLocation(tag), tagName, formattedComment);
|
|
83
|
+
} catch (e) {
|
|
84
|
+
return simpleTag(tag, tagName, context);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
109
87
|
return simpleTag(tag, tagName, context);
|
|
110
88
|
}
|
|
111
89
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["tagParser","tag","context","formatter","kind","SyntaxKind","JSDocReturnTag","returnTag","JSDocPropertyTag","propertyLikeTag","JSDocParameterTag","JSDocAugmentsTag","simpleTag","TagName","augments","JSDocAuthorTag","author","JSDocClassTag","class","JSDocCallbackTag","callback","JSDocPublicTag","public","JSDocPrivateTag","private","JSDocProtectedTag","protected","JSDocReadonlyTag","readonly","JSDocOverrideTag","override","JSDocDeprecatedTag","deprecated","JSDocSeeTag","see","JSDocEnumTag","enum","JSDocThisTag","this","JSDocTypeTag","type","JSDocTemplateTag","template","JSDocTypedefTag","typedef","JSDocImplementsTag","implements","tagName","getText","getSourceFile","comment","getTextOfJSDocComment","formattedComment","formatSnippet","TagSchema","getLocation","e","typeExpression","typeNodeToSchema","undefined","ReturnTagSchema","PropertyLikeTagSchema","name"],"sources":["jsdoc-to-doc-schema.ts"],"sourcesContent":["/* eslint-disable no-fallthrough */\nimport {\n getTextOfJSDocComment,\n JSDocParameterTag,\n JSDocPropertyLikeTag,\n JSDocPropertyTag,\n JSDocReturnTag,\n JSDocTag,\n SyntaxKind,\n} from 'typescript';\nimport {\n PropertyLikeTagSchema,\n ReturnTagSchema,\n TagName,\n TagSchema,\n} from '@teambit/semantics.entities.semantic-schema';\nimport { Formatter } from '@teambit/formatter';\nimport { SchemaExtractorContext } from '../../schema-extractor-context';\nimport { typeNodeToSchema } from './type-node-to-schema';\n\nexport async function tagParser(\n tag: JSDocTag,\n context: SchemaExtractorContext,\n formatter: Formatter\n): Promise<TagSchema> {\n // for some reason, in some cases, if `tag.getSourceFile()` is not provided to the `getText()`, it throws \"Cannot read property 'text' of undefined\"\n\n switch (tag.kind) {\n case SyntaxKind.JSDocReturnTag:\n return returnTag(tag as JSDocReturnTag, context);\n case SyntaxKind.JSDocPropertyTag:\n return propertyLikeTag(tag as JSDocPropertyTag, context);\n case SyntaxKind.JSDocParameterTag:\n return propertyLikeTag(tag as JSDocParameterTag, context);\n case SyntaxKind.JSDocAugmentsTag:\n return simpleTag(tag, TagName.augments, context);\n case SyntaxKind.JSDocAuthorTag:\n return simpleTag(tag, TagName.author, context);\n case SyntaxKind.JSDocClassTag:\n return simpleTag(tag, TagName.class, context);\n case SyntaxKind.JSDocCallbackTag:\n return simpleTag(tag, TagName.callback, context);\n case SyntaxKind.JSDocPublicTag:\n return simpleTag(tag, TagName.public, context);\n case SyntaxKind.JSDocPrivateTag:\n return simpleTag(tag, TagName.private, context);\n case SyntaxKind.JSDocProtectedTag:\n return simpleTag(tag, TagName.protected, context);\n case SyntaxKind.JSDocReadonlyTag:\n return simpleTag(tag, TagName.readonly, context);\n case SyntaxKind.JSDocOverrideTag:\n return simpleTag(tag, TagName.override, context);\n case SyntaxKind.JSDocDeprecatedTag:\n return simpleTag(tag, TagName.deprecated, context);\n case SyntaxKind.JSDocSeeTag:\n return simpleTag(tag, TagName.see, context);\n case SyntaxKind.JSDocEnumTag:\n return simpleTag(tag, TagName.enum, context);\n case SyntaxKind.JSDocThisTag:\n return simpleTag(tag, TagName.this, context);\n case SyntaxKind.JSDocTypeTag:\n return simpleTag(tag, TagName.type, context);\n case SyntaxKind.JSDocTemplateTag:\n return simpleTag(tag, TagName.template, context);\n case SyntaxKind.JSDocTypedefTag:\n return simpleTag(tag, TagName.typedef, context);\n case SyntaxKind.JSDocImplementsTag:\n return simpleTag(tag, TagName.implements, context);\n default: {\n const tagName: TagName | string = tag.tagName.getText(tag.getSourceFile());\n if (tagName === 'example') {\n const comment = getTextOfJSDocComment(tag.comment);\n try {\n const formattedComment = comment && (await formatter.formatSnippet(comment));\n return new TagSchema(context.getLocation(tag), tagName, formattedComment);\n } catch (e) {\n return simpleTag(tag, tagName, context);\n }\n }\n return simpleTag(tag, tagName, context);\n }\n }\n}\n\nfunction simpleTag(tag: JSDocTag, tagName: TagName | string, context: SchemaExtractorContext): TagSchema {\n return new TagSchema(context.getLocation(tag), tagName, getTextOfJSDocComment(tag.comment));\n}\n\nasync function returnTag(tag: JSDocReturnTag, context: SchemaExtractorContext) {\n const type = tag.typeExpression?.type ? await typeNodeToSchema(tag.typeExpression?.type, context) : undefined;\n return new ReturnTagSchema(context.getLocation(tag), getTextOfJSDocComment(tag.comment), type);\n}\n\nasync function propertyLikeTag(tag: JSDocPropertyLikeTag, context: SchemaExtractorContext) {\n const type = tag.typeExpression?.type ? await typeNodeToSchema(tag.typeExpression?.type, context) : undefined;\n return new PropertyLikeTagSchema(\n context.getLocation(tag),\n tag.name.getText(),\n getTextOfJSDocComment(tag.comment),\n type\n );\n}\n"],"mappings":";;;;;;;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AASA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAQA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAlBA;;AAoBO,eAAeA,SAAS,CAC7BC,GAAa,EACbC,OAA+B,EAC/BC,SAAoB,EACA;EACpB;;EAEA,QAAQF,GAAG,CAACG,IAAI;IACd,KAAKC,wBAAU,CAACC,cAAc;MAC5B,OAAOC,SAAS,CAACN,GAAG,EAAoBC,OAAO,CAAC;IAClD,KAAKG,wBAAU,CAACG,gBAAgB;MAC9B,OAAOC,eAAe,CAACR,GAAG,EAAsBC,OAAO,CAAC;IAC1D,KAA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E,EAClB,IAAAG,mCAAqB,EAAClD,GAAG,CAACiD,OAAO,CAAC,EAClCV,IAAI,CACL;AACH"}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
require("core-js/modules/es.array.iterator.js");
|
|
4
4
|
require("core-js/modules/es.regexp.exec.js");
|
|
5
|
+
require("core-js/modules/es.string.replace.js");
|
|
5
6
|
require("core-js/modules/es.string.trim.js");
|
|
6
7
|
Object.defineProperty(exports, "__esModule", {
|
|
7
8
|
value: true
|
|
@@ -52,6 +53,9 @@ function parseTypeFromQuickInfo(quickInfo) {
|
|
|
52
53
|
const displayString = quickInfo.body.displayString;
|
|
53
54
|
const splitByColon = displayString.split(':');
|
|
54
55
|
switch (quickInfo.body.kind) {
|
|
56
|
+
case 'type parameter':
|
|
57
|
+
// (type parameter) T in concat<T, K, V>(array1: T[], array2: T[]): T[]
|
|
58
|
+
return displayString.replace(`(${quickInfo.body.kind}) `, '').split(' ')[0];
|
|
55
59
|
case 'const':
|
|
56
60
|
case 'property':
|
|
57
61
|
case 'let':
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["UNRESOLVED","parseTypeFromQuickInfo","quickInfo","body","displayString","splitByColon","split","kind","tail","join","trim","length","firstLine","splitBySpace","typeName","splitByEqual","parseReturnTypeFromQuickInfo","typeStr","array"],"sources":["parse-type-from-quick-info.ts"],"sourcesContent":["// eslint-disable-next-line import/no-unresolved\nimport protocol from 'typescript/lib/protocol';\n\nexport const UNRESOLVED = '<<unresolved>>';\n\n/**\n * try to parse the type from the quickinfo.\n * this is an error-prone process, we do our best here.\n *\n * an example of a function with many \":\"\n * `export function getObj(a: string, func: (b: number) => {}) { return { a: 1, b: 2 } };`\n * which produce the following quickinfo:\n * ```ts\n * function getObj(a: string, func: (b: number) => {}): {\n * a: number;\n * b: number;\n * }\n * ```\n *\n * some examples of quickinfo:\n *\n * function ts.signatureToDisplayParts(typechecker: TypeChecker, signature: Signature, enclosingDeclaration?: Node | undefined, flags?: TypeFormatFlags): SymbolDisplayPart[]\n *\n * const enum ts.TypeFormatFlags\n *\n * (method) ts.TypeChecker.writeSignature(signature: Signature, enclosingDeclaration?: Node | undefined, flags?: TypeFormatFlags | undefined, kind?: SignatureKind | undefined, writer?: EmitTextWriter | undefined): string\n *\n * const obj: {\n * a: number;\n * b: number;\n * }\n *\n * function getObj(a: string): {\n * a: number;\n * b: number;\n * }\n */\nexport function parseTypeFromQuickInfo(quickInfo: protocol.QuickInfoResponse | undefined): string {\n if (!quickInfo?.body?.displayString) return '';\n const displayString = quickInfo.body.displayString;\n const splitByColon = displayString.split(':');\n switch (quickInfo.body.kind) {\n case 'const':\n case 'property':\n case 'let':\n case 'var': {\n const [, ...tail] = splitByColon;\n return tail.join(':').trim();\n }\n case 'method':\n case 'function': {\n const split = displayString.split('): ');\n if (split.length !== 2) {\n // it's hard to determine where the return-type is. so it's better to show unresolved.\n // maybe, in the UI, in this case, it's best to show the signature.\n // e.g.\n // (method) IssuesList.getIssue<T extends ComponentIssue>(IssueClass: {\n // new (): T;\n // }): T | undefined\n return UNRESOLVED;\n }\n return split[1].trim();\n }\n case 'alias': {\n // e.g. (alias) class BuilderService\\nimport BuilderService\n // e.g. '(alias) type Serializable = {\\n' +\n // ' toString(): string;\\n' +\n // '}\\n' +\n // 'import Serializable'\n const firstLine = displayString.split('\\n')[0];\n const splitBySpace = firstLine.trim().split(' ');\n // first two are alias keyword and alias type\n const [, , typeName] = splitBySpace;\n return typeName;\n }\n case 'type': {\n // e.g. `type TaskSlot = SlotRegistry<BuildTask[]>`\n const splitByEqual = displayString.split('=');\n const [, ...tail] = splitByEqual;\n return tail.join('=').trim();\n }\n default:\n return splitByColon[splitByColon.length - 1].trim();\n }\n}\n\nexport function parseReturnTypeFromQuickInfo(quickInfo: protocol.QuickInfoResponse | undefined): string {\n if (!quickInfo) return '';\n const typeStr = parseTypeFromQuickInfo(quickInfo);\n const array = typeStr.split('=>');\n return array[array.length - 1].trim();\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":["UNRESOLVED","parseTypeFromQuickInfo","quickInfo","body","displayString","splitByColon","split","kind","replace","tail","join","trim","length","firstLine","splitBySpace","typeName","splitByEqual","parseReturnTypeFromQuickInfo","typeStr","array"],"sources":["parse-type-from-quick-info.ts"],"sourcesContent":["// eslint-disable-next-line import/no-unresolved\nimport protocol from 'typescript/lib/protocol';\n\nexport const UNRESOLVED = '<<unresolved>>';\n\n/**\n * try to parse the type from the quickinfo.\n * this is an error-prone process, we do our best here.\n *\n * an example of a function with many \":\"\n * `export function getObj(a: string, func: (b: number) => {}) { return { a: 1, b: 2 } };`\n * which produce the following quickinfo:\n * ```ts\n * function getObj(a: string, func: (b: number) => {}): {\n * a: number;\n * b: number;\n * }\n * ```\n *\n * some examples of quickinfo:\n *\n * function ts.signatureToDisplayParts(typechecker: TypeChecker, signature: Signature, enclosingDeclaration?: Node | undefined, flags?: TypeFormatFlags): SymbolDisplayPart[]\n *\n * const enum ts.TypeFormatFlags\n *\n * (method) ts.TypeChecker.writeSignature(signature: Signature, enclosingDeclaration?: Node | undefined, flags?: TypeFormatFlags | undefined, kind?: SignatureKind | undefined, writer?: EmitTextWriter | undefined): string\n *\n * const obj: {\n * a: number;\n * b: number;\n * }\n *\n * function getObj(a: string): {\n * a: number;\n * b: number;\n * }\n */\nexport function parseTypeFromQuickInfo(quickInfo: protocol.QuickInfoResponse | undefined): string {\n if (!quickInfo?.body?.displayString) return '';\n const displayString = quickInfo.body.displayString;\n const splitByColon = displayString.split(':');\n switch (quickInfo.body.kind) {\n case 'type parameter':\n // (type parameter) T in concat<T, K, V>(array1: T[], array2: T[]): T[]\n return displayString.replace(`(${quickInfo.body.kind}) `, '').split(' ')[0];\n case 'const':\n case 'property':\n case 'let':\n case 'var': {\n const [, ...tail] = splitByColon;\n return tail.join(':').trim();\n }\n case 'method':\n case 'function': {\n const split = displayString.split('): ');\n if (split.length !== 2) {\n // it's hard to determine where the return-type is. so it's better to show unresolved.\n // maybe, in the UI, in this case, it's best to show the signature.\n // e.g.\n // (method) IssuesList.getIssue<T extends ComponentIssue>(IssueClass: {\n // new (): T;\n // }): T | undefined\n return UNRESOLVED;\n }\n return split[1].trim();\n }\n case 'alias': {\n // e.g. (alias) class BuilderService\\nimport BuilderService\n // e.g. '(alias) type Serializable = {\\n' +\n // ' toString(): string;\\n' +\n // '}\\n' +\n // 'import Serializable'\n const firstLine = displayString.split('\\n')[0];\n const splitBySpace = firstLine.trim().split(' ');\n // first two are alias keyword and alias type\n const [, , typeName] = splitBySpace;\n return typeName;\n }\n case 'type': {\n // e.g. `type TaskSlot = SlotRegistry<BuildTask[]>`\n const splitByEqual = displayString.split('=');\n const [, ...tail] = splitByEqual;\n return tail.join('=').trim();\n }\n default:\n return splitByColon[splitByColon.length - 1].trim();\n }\n}\n\nexport function parseReturnTypeFromQuickInfo(quickInfo: protocol.QuickInfoResponse | undefined): string {\n if (!quickInfo) return '';\n const typeStr = parseTypeFromQuickInfo(quickInfo);\n const array = typeStr.split('=>');\n return array[array.length - 1].trim();\n}\n"],"mappings":";;;;;;;;;;;;AAAA;;AAGO,MAAMA,UAAU,GAAG,gBAAgB;;AAE1C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AA/BA;AAgCO,SAASC,sBAAsB,CAACC,SAAiD,EAAU;EAAA;EAChG,IAAI,EAACA,SAAS,aAATA,SAAS,kCAATA,SAAS,CAAEC,IAAI,4CAAf,gBAAiBC,aAAa,GAAE,OAAO,EAAE;EAC9C,MAAMA,aAAa,GAAGF,SAAS,CAACC,IAAI,CAACC,aAAa;EAClD,MAAMC,YAAY,GAAGD,aAAa,CAACE,KAAK,CAAC,GAAG,CAAC;EAC7C,QAAQJ,SAAS,CAACC,IAAI,CAACI,IAAI;IACzB,KAAK,gBAAgB;MACnB;MACA,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,SAAiD,EAAU;EACtG,IAAI,CAACA,SAAS,EAAE,OAAO,EAAE;EACzB,MAAMgB,OAAO,GAAGjB,sBAAsB,CAACC,SAAS,CAAC;EACjD,MAAMiB,KAAK,GAAGD,OAAO,CAACZ,KAAK,CAAC,IAAI,CAAC;EACjC,OAAOa,KAAK,CAACA,KAAK,CAACP,MAAM,GAAG,CAAC,CAAC,CAACD,IAAI,EAAE;AACvC"}
|
|
@@ -33,13 +33,6 @@ function _parseTypeFromQuickInfo() {
|
|
|
33
33
|
};
|
|
34
34
|
return data;
|
|
35
35
|
}
|
|
36
|
-
function _jsdocToDocSchema() {
|
|
37
|
-
const data = require("./jsdoc-to-doc-schema");
|
|
38
|
-
_jsdocToDocSchema = function () {
|
|
39
|
-
return data;
|
|
40
|
-
};
|
|
41
|
-
return data;
|
|
42
|
-
}
|
|
43
36
|
async function toFunctionLikeSchema(node, context, funcName) {
|
|
44
37
|
var _node$name, _info$body, _node$modifiers2, _node$typeParameters;
|
|
45
38
|
const name = funcName || ((_node$name = node.name) === null || _node$name === void 0 ? void 0 : _node$name.getText()) || '';
|
|
@@ -58,7 +51,7 @@ async function toFunctionLikeSchema(node, context, funcName) {
|
|
|
58
51
|
const modifiers = ((_node$modifiers2 = node.modifiers) === null || _node$modifiers2 === void 0 ? void 0 : _node$modifiers2.map(modifier => modifier.getText())) || [];
|
|
59
52
|
const typeParameters = (_node$typeParameters = node.typeParameters) === null || _node$typeParameters === void 0 ? void 0 : _node$typeParameters.map(typeParam => typeParam.name.getText());
|
|
60
53
|
const location = context.getLocation(node);
|
|
61
|
-
const doc = await
|
|
54
|
+
const doc = await context.jsDocToDocSchema(node);
|
|
62
55
|
return new (_semanticsEntities().FunctionLikeSchema)(location, name, args, returnType, displaySig, modifiers, doc, typeParameters);
|
|
63
56
|
}
|
|
64
57
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["toFunctionLikeSchema","node","context","funcName","name","getText","getQuickInfoFromDefaultModifier","defaultModifier","modifiers","find","modifier","kind","SyntaxKind","DefaultKeyword","getQuickInfo","ArrowFunction","equalsGreaterThanToken","info","returnTypeStr","parseTypeFromQuickInfo","displaySig","body","displayString","args","getParams","parameters","returnType","resolveType","Boolean","map","typeParameters","typeParam","location","getLocation","doc","jsDocToDocSchema","FunctionLikeSchema"],"sources":["to-function-like-schema.ts"],"sourcesContent":["import { SignatureDeclaration, SyntaxKind } from 'typescript';\nimport { FunctionLikeSchema, Modifier } from '@teambit/semantics.entities.semantic-schema';\nimport { SchemaExtractorContext } from '../../schema-extractor-context';\nimport { getParams } from './get-params';\nimport { parseTypeFromQuickInfo } from './parse-type-from-quick-info';\
|
|
1
|
+
{"version":3,"names":["toFunctionLikeSchema","node","context","funcName","name","getText","getQuickInfoFromDefaultModifier","defaultModifier","modifiers","find","modifier","kind","SyntaxKind","DefaultKeyword","getQuickInfo","ArrowFunction","equalsGreaterThanToken","info","returnTypeStr","parseTypeFromQuickInfo","displaySig","body","displayString","args","getParams","parameters","returnType","resolveType","Boolean","map","typeParameters","typeParam","location","getLocation","doc","jsDocToDocSchema","FunctionLikeSchema"],"sources":["to-function-like-schema.ts"],"sourcesContent":["import { SignatureDeclaration, SyntaxKind } from 'typescript';\nimport { FunctionLikeSchema, Modifier } from '@teambit/semantics.entities.semantic-schema';\nimport { SchemaExtractorContext } from '../../schema-extractor-context';\nimport { getParams } from './get-params';\nimport { parseTypeFromQuickInfo } from './parse-type-from-quick-info';\n\nexport async function toFunctionLikeSchema(\n node: SignatureDeclaration,\n context: SchemaExtractorContext,\n funcName?: string\n) {\n const name = funcName || node.name?.getText() || '';\n const getQuickInfoFromDefaultModifier = async () => {\n const defaultModifier = node.modifiers?.find((modifier) => modifier.kind === SyntaxKind.DefaultKeyword);\n if (defaultModifier) return context.getQuickInfo(defaultModifier);\n if (node.kind === SyntaxKind.ArrowFunction) return context.getQuickInfo(node.equalsGreaterThanToken);\n return null;\n };\n const info = node.name ? await context.getQuickInfo(node.name) : await getQuickInfoFromDefaultModifier();\n const returnTypeStr = info ? parseTypeFromQuickInfo(info) : 'any';\n const displaySig = info?.body?.displayString || '';\n const args = await getParams(node.parameters, context);\n\n const returnType = await context.resolveType(node, returnTypeStr, Boolean(info));\n const modifiers = node.modifiers?.map((modifier) => modifier.getText()) || [];\n const typeParameters = node.typeParameters?.map((typeParam) => typeParam.name.getText());\n const location = context.getLocation(node);\n const doc = await context.jsDocToDocSchema(node);\n return new FunctionLikeSchema(\n location,\n name,\n args,\n returnType,\n displaySig,\n modifiers as Modifier[],\n doc,\n typeParameters\n );\n}\n"],"mappings":";;;;;;;AAAA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAEA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAEO,eAAeA,oBAAoB,CACxCC,IAA0B,EAC1BC,OAA+B,EAC/BC,QAAiB,EACjB;EAAA;EACA,MAAMC,IAAI,GAAGD,QAAQ,mBAAIF,IAAI,CAACG,IAAI,+CAAT,WAAWC,OAAO,EAAE,KAAI,EAAE;EACnD,MAAMC,+BAA+B,GAAG,YAAY;IAAA;IAClD,MAAMC,eAAe,sBAAGN,IAAI,CAACO,SAAS,oDAAd,gBAAgBC,IAAI,CAAEC,QAAQ,IAAKA,QAAQ,CAACC,IAAI,KAAKC,wBAAU,CAACC,cAAc,CAAC;IACvG,IAAIN,eAAe,EAAE,OAAOL,OAAO,CAACY,YAAY,CAACP,eAAe,CAAC;IACjE,IAAIN,IAAI,CAACU,IAAI,KAAKC,wBAAU,CAACG,aAAa,EAAE,OAAOb,OAAO,CAACY,YAAY,CAACb,IAAI,CAACe,sBAAsB,CAAC;IACpG,OAAO,IAAI;EACb,CAAC;EACD,MAAMC,IAAI,GAAGhB,IAAI,CAACG,IAAI,GAAG,MAAMF,OAAO,CAACY,YAAY,CAACb,IAAI,CAACG,IAAI,CAAC,GAAG,MAAME,+BAA+B,EAAE;EACxG,MAAMY,aAAa,GAAGD,IAAI,GAAG,IAAAE,gDAAsB,EAACF,IAAI,CAAC,GAAG,KAAK;EACjE,MAAMG,UAAU,GAAG,CAAAH,IAAI,aAAJA,IAAI,qCAAJA,IAAI,CAAEI,IAAI,+CAAV,WAAYC,aAAa,KAAI,EAAE;EAClD,MAAMC,IAAI,GAAG,MAAM,IAAAC,sBAAS,EAACvB,IAAI,CAACwB,UAAU,EAAEvB,OAAO,CAAC;EAEtD,MAAMwB,UAAU,GAAG,MAAMxB,OAAO,CAACyB,WAAW,CAAC1B,IAAI,EAAEiB,aAAa,EAAEU,OAAO,CAACX,IAAI,CAAC,CAAC;EAChF,MAAMT,SAAS,GAAG,qBAAAP,IAAI,CAACO,SAAS,qDAAd,iBAAgBqB,GAAG,CAAEnB,QAAQ,IAAKA,QAAQ,CAACL,OAAO,EAAE,CAAC,KAAI,EAAE;EAC7E,MAAMyB,cAAc,2BAAG7B,IAAI,CAAC6B,cAAc,yDAAnB,qBAAqBD,GAAG,CAAEE,SAAS,IAAKA,SAAS,CAAC3B,IAAI,CAACC,OAAO,EAAE,CAAC;EACxF,MAAM2B,QAAQ,GAAG9B,OAAO,CAAC+B,WAAW,CAAChC,IAAI,CAAC;EAC1C,MAAMiC,GAAG,GAAG,MAAMhC,OAAO,CAACiC,gBAAgB,CAAClC,IAAI,CAAC;EAChD,OAAO,KAAImC,uCAAkB,EAC3BJ,QAAQ,EACR5B,IAAI,EACJmB,IAAI,EACJG,UAAU,EACVN,UAAU,EACVZ,SAAS,EACT0B,GAAG,EACHJ,cAAc,CACf;AACH"}
|
|
@@ -50,13 +50,6 @@ function _getParams() {
|
|
|
50
50
|
};
|
|
51
51
|
return data;
|
|
52
52
|
}
|
|
53
|
-
function _jsdocToDocSchema() {
|
|
54
|
-
const data = require("./jsdoc-to-doc-schema");
|
|
55
|
-
_jsdocToDocSchema = function () {
|
|
56
|
-
return data;
|
|
57
|
-
};
|
|
58
|
-
return data;
|
|
59
|
-
}
|
|
60
53
|
async function typeElementToSchema(node, context) {
|
|
61
54
|
switch (node.kind) {
|
|
62
55
|
case _typescript().SyntaxKind.MethodSignature:
|
|
@@ -85,7 +78,7 @@ async function propertySignature(node, context) {
|
|
|
85
78
|
const typeStr = (0, _parseTypeFromQuickInfo().parseTypeFromQuickInfo)(info);
|
|
86
79
|
const type = await context.resolveType(node, typeStr);
|
|
87
80
|
const isOptional = Boolean(node.questionToken);
|
|
88
|
-
const doc = await
|
|
81
|
+
const doc = await context.jsDocToDocSchema(node);
|
|
89
82
|
return new (_semanticsEntities().VariableLikeSchema)(context.getLocation(node), name, displaySig, type, isOptional, doc);
|
|
90
83
|
}
|
|
91
84
|
async function indexSignature(node, context) {
|