@teambit/typescript 0.0.736 → 0.0.737
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 +2 -1
- package/dist/schema-extractor-context.js +15 -6
- package/dist/schema-extractor-context.js.map +1 -1
- package/dist/transformers/class-deceleration.js +2 -2
- package/dist/transformers/class-deceleration.js.map +1 -1
- package/dist/transformers/constructor.js +1 -1
- package/dist/transformers/constructor.js.map +1 -1
- package/dist/transformers/export-declaration.js +1 -1
- package/dist/transformers/export-declaration.js.map +1 -1
- package/dist/transformers/index-signature.js +1 -1
- package/dist/transformers/index-signature.js.map +1 -1
- package/dist/transformers/interface-declaration.js +1 -1
- package/dist/transformers/interface-declaration.js.map +1 -1
- package/dist/transformers/literal-type.d.ts +2 -1
- package/dist/transformers/literal-type.js +2 -2
- package/dist/transformers/literal-type.js.map +1 -1
- package/dist/transformers/property-declaration.js +1 -1
- package/dist/transformers/property-declaration.js.map +1 -1
- package/dist/transformers/property-signature.js +1 -1
- package/dist/transformers/property-signature.js.map +1 -1
- 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 -1
- package/dist/transformers/type-alias.js.map +1 -1
- package/dist/transformers/utils/get-params.js +6 -2
- package/dist/transformers/utils/get-params.js.map +1 -1
- package/dist/transformers/utils/to-function-schema.js +2 -2
- package/dist/transformers/utils/to-function-schema.js.map +1 -1
- package/dist/transformers/utils/type-node-to-schema.js +17 -10
- package/dist/transformers/utils/type-node-to-schema.js.map +1 -1
- package/dist/transformers/variable-declaration.js +3 -3
- package/dist/transformers/variable-declaration.js.map +1 -1
- package/dist/transformers/variable-statement.js +2 -3
- package/dist/transformers/variable-statement.js.map +1 -1
- package/dist/typescript.extractor.js +3 -3
- package/dist/typescript.extractor.js.map +1 -1
- package/dist/typescript.parser.d.ts +2 -2
- package/dist/typescript.parser.js +4 -4
- package/dist/typescript.parser.js.map +1 -1
- package/package-tar/teambit-typescript-0.0.737.tgz +0 -0
- package/package.json +11 -11
- package/{preview-1652844422371.js → preview-1652930732694.js} +2 -2
- package/transformers/class-deceleration.ts +2 -2
- package/transformers/constructor.ts +1 -1
- package/transformers/export-declaration.ts +1 -1
- package/transformers/index-signature.ts +1 -1
- package/transformers/interface-declaration.ts +1 -1
- package/transformers/literal-type.ts +3 -2
- package/transformers/property-declaration.ts +1 -1
- package/transformers/property-signature.ts +1 -1
- package/transformers/source-file-transformer.ts +1 -1
- package/transformers/type-alias.ts +1 -1
- package/transformers/utils/get-params.ts +5 -1
- package/transformers/utils/to-function-schema.ts +2 -2
- package/transformers/utils/type-node-to-schema.ts +16 -10
- package/transformers/variable-declaration.ts +3 -3
- package/transformers/variable-statement.ts +1 -2
- package/tsconfig.json +1 -1
- package/dist/transformers/export-declaration-type.d.ts +0 -0
- package/dist/transformers/export-declaration-type.js +0 -3
- package/dist/transformers/export-declaration-type.js.map +0 -1
- package/package-tar/teambit-typescript-0.0.736.tgz +0 -0
- package/transformers/export-declaration-type.ts +0 -0
|
@@ -14,7 +14,8 @@ export declare class SchemaExtractorContext {
|
|
|
14
14
|
/**
|
|
15
15
|
* returns the location of a node in a source file.
|
|
16
16
|
*/
|
|
17
|
-
getLocation(node: Node, targetSourceFile?: ts.SourceFile): Location;
|
|
17
|
+
getLocation(node: Node, targetSourceFile?: ts.SourceFile, absolutePath?: boolean): Location;
|
|
18
|
+
getPathRelativeToComponent(filePath: string): string;
|
|
18
19
|
/**
|
|
19
20
|
* returns a signature for a node.
|
|
20
21
|
*/
|
|
@@ -119,17 +119,22 @@ class SchemaExtractorContext {
|
|
|
119
119
|
*/
|
|
120
120
|
|
|
121
121
|
|
|
122
|
-
getLocation(node, targetSourceFile) {
|
|
122
|
+
getLocation(node, targetSourceFile, absolutePath = false) {
|
|
123
123
|
const sourceFile = targetSourceFile || node.getSourceFile();
|
|
124
124
|
const position = sourceFile.getLineAndCharacterOfPosition(node.getStart());
|
|
125
125
|
const line = position.line + 1;
|
|
126
126
|
const character = position.character + 1;
|
|
127
127
|
return {
|
|
128
|
-
file: sourceFile.fileName,
|
|
128
|
+
file: absolutePath ? sourceFile.fileName : this.getPathRelativeToComponent(sourceFile.fileName),
|
|
129
129
|
line,
|
|
130
130
|
character
|
|
131
131
|
};
|
|
132
132
|
}
|
|
133
|
+
|
|
134
|
+
getPathRelativeToComponent(filePath) {
|
|
135
|
+
const basePath = this.component.filesystem.files[0].base;
|
|
136
|
+
return (0, _path().relative)(basePath, filePath);
|
|
137
|
+
}
|
|
133
138
|
/**
|
|
134
139
|
* returns a signature for a node.
|
|
135
140
|
*/
|
|
@@ -346,7 +351,11 @@ class SchemaExtractorContext {
|
|
|
346
351
|
async resolveType(node, typeStr, isTypeStrFromQuickInfo = true) {
|
|
347
352
|
var _this$_exports;
|
|
348
353
|
|
|
349
|
-
|
|
354
|
+
const location = this.getLocation(node);
|
|
355
|
+
|
|
356
|
+
if ((_this$_exports = this._exports) !== null && _this$_exports !== void 0 && _this$_exports.includes(typeStr)) {
|
|
357
|
+
return new (_semanticsEntities().TypeRefSchema)(location, typeStr);
|
|
358
|
+
}
|
|
350
359
|
|
|
351
360
|
if (node.type && _typescript().default.isTypeNode(node.type)) {
|
|
352
361
|
// if a node has "type" prop, it has the type data of the node. this normally happens when the code has the type
|
|
@@ -378,12 +387,12 @@ class SchemaExtractorContext {
|
|
|
378
387
|
|
|
379
388
|
const unknownExactType = async () => {
|
|
380
389
|
if (isTypeStrFromQuickInfo) {
|
|
381
|
-
return new (_semanticsEntities().InferenceTypeSchema)(typeStr);
|
|
390
|
+
return new (_semanticsEntities().InferenceTypeSchema)(location, typeStr);
|
|
382
391
|
}
|
|
383
392
|
|
|
384
393
|
const info = await this.getQuickInfo(node);
|
|
385
394
|
const type = (0, _parseTypeFromQuickInfo().parseTypeFromQuickInfo)(info);
|
|
386
|
-
return new (_semanticsEntities().InferenceTypeSchema)(type);
|
|
395
|
+
return new (_semanticsEntities().InferenceTypeSchema)(location, type);
|
|
387
396
|
};
|
|
388
397
|
|
|
389
398
|
if (!definition) {
|
|
@@ -413,7 +422,7 @@ class SchemaExtractorContext {
|
|
|
413
422
|
|
|
414
423
|
const pkgName = this.parsePackageNameFromPath(definition.file); // TODO: find component id is exists, otherwise add the package name.
|
|
415
424
|
|
|
416
|
-
return new (_semanticsEntities().TypeRefSchema)(typeStr, undefined, pkgName);
|
|
425
|
+
return new (_semanticsEntities().TypeRefSchema)(location, typeStr, undefined, pkgName);
|
|
417
426
|
}
|
|
418
427
|
|
|
419
428
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["schema-extractor-context.ts"],"names":["SchemaExtractorContext","constructor","tsserver","component","extractor","undefined","computeSchema","node","getLocation","targetSourceFile","sourceFile","getSourceFile","position","getLineAndCharacterOfPosition","getStart","line","character","file","fileName","getSignature","getSignatureHelp","getPath","getPosition","offset","getPositionOfLineAndCharacter","getQuickInfo","getQuickInfoDisplayString","quickInfo","body","displayString","typeDefinition","getTypeDefinition","visitTypeDefinition","findFileInComponent","filePath","filesystem","files","find","path","includes","strings","map","format","endsWith","string","parsePackageNameFromPath","parts","split","length","lastPart","replace","sep","pkgParts","startsWith","pkgName","parseSourceFile","getSourceFileFromNode","def","getDefinition","firstDef","definition","startPosition","start","pos","nodeAtPos","visitDefinition","visit","parent","references","isExported","isFromComponent","getFileExports","exportDec","specifierPathStr","moduleSpecifier","getText","specifierPath","substring","absPath","computeExportedIdentifiers","setExports","exports","_exports","getExportedIdentifiers","jump","err","TransformerNotFound","resolveType","typeStr","isTypeStrFromQuickInfo","TypeRefSchema","type","ts","isTypeNode","getDef","headTypeDefinition","unknownExactType","InferenceTypeSchema","info","isDefInSameLocation","loc","schemaNode"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;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;AACD,KAND;;AAQA,UAAMN,IAAI,GAAG,KAAKgB,mBAAL,CAAyB2B,UAAU,CAAC3C,IAApC,CAAb;;AACA,QAAIA,IAAJ,EAAU;AACR,UAAIkF,mBAAmB,EAAvB,EAA2B;AACzB,eAAOH,gBAAgB,EAAvB;AACD;;AACD,YAAMK,UAAU,GAAG,MAAM,KAAKjB,IAAL,CAAUnE,IAAV,EAAgB2C,UAAU,CAACE,KAA3B,CAAzB;AACA,aAAOuC,UAAU,IAAIL,gBAAgB,EAArC;AACD;;AACD,UAAM1C,OAAO,GAAG,KAAKT,wBAAL,CAA8Be,UAAU,CAAC3C,IAAzC,CAAhB,CAvDqB,CAwDrB;;AACA,WAAO,KAAIyE,kCAAJ,EAAkBF,OAAlB,EAA2BnF,SAA3B,EAAsCiD,OAAtC,CAAP;AACD;;AA7RiC","sourcesContent":["import { TsserverClient } from '@teambit/ts-server';\nimport ts, { ExportDeclaration, Node, TypeNode } from 'typescript';\nimport { getTokenAtPosition } from 'tsutils';\nimport { head } from 'lodash';\n// @ts-ignore david we should figure fix this.\nimport type { AbstractVinyl } from '@teambit/legacy/dist/consumer/component/sources';\nimport { resolve, sep } from 'path';\nimport { Component } from '@teambit/component';\nimport { TypeRefSchema, SchemaNode, InferenceTypeSchema, Location } from '@teambit/semantics.entities.semantic-schema';\nimport { TypeScriptExtractor } from './typescript.extractor';\nimport { ExportList } from './export-list';\nimport { typeNodeToSchema } from './transformers/utils/type-node-to-schema';\nimport { TransformerNotFound } from './exceptions';\nimport { parseTypeFromQuickInfo } from './transformers/utils/parse-type-from-quick-info';\n\nexport class SchemaExtractorContext {\n constructor(\n readonly tsserver: TsserverClient,\n readonly component: Component,\n readonly extractor: TypeScriptExtractor\n ) {}\n\n computeSchema(node: Node) {\n return this.extractor.computeSchema(node, this);\n }\n\n /**\n * returns the location of a node in a source file.\n */\n getLocation(node: Node, targetSourceFile?: ts.SourceFile): Location {\n const sourceFile = targetSourceFile || node.getSourceFile();\n const position = sourceFile.getLineAndCharacterOfPosition(node.getStart());\n const line = position.line + 1;\n const character = position.character + 1;\n\n return {\n file: sourceFile.fileName,\n line,\n character,\n };\n }\n\n /**\n * returns a signature for a node.\n */\n async getSignature(node: Node) {\n return this.tsserver.getSignatureHelp(this.getPath(node), this.getLocation(node));\n }\n\n /**\n * get the position for the tsserver.\n */\n getPosition(sourceFile: ts.SourceFile, line: number, offset: number): number {\n return sourceFile.getPositionOfLineAndCharacter(line - 1, offset - 1);\n }\n\n /**\n * get the path for a source file.\n */\n getPath(node: Node) {\n const sourceFile = node.getSourceFile();\n return sourceFile.fileName;\n }\n\n /**\n * create a reference to a type from a component.\n * think if we don't need this because of type ref\n */\n // createRef() {\n // return {};\n // }\n\n getQuickInfo(node: Node) {\n return this.tsserver.getQuickInfo(this.getPath(node), this.getLocation(node));\n }\n\n async getQuickInfoDisplayString(node: Node): Promise<string> {\n const quickInfo = await this.tsserver.getQuickInfo(this.getPath(node), this.getLocation(node));\n return quickInfo?.body?.displayString || '';\n }\n\n /**\n * returns the type definition for a type.\n */\n typeDefinition(node: Node) {\n return this.tsserver.getTypeDefinition(this.getPath(node), this.getLocation(node));\n }\n\n visitTypeDefinition() {}\n\n private findFileInComponent(filePath: string) {\n return this.component.filesystem.files.find((file) => {\n // TODO: fix this line to support further extensions.\n if (file.path.includes(filePath)) {\n const strings = ['ts', 'tsx', 'js', 'jsx'].map((format) => {\n if (filePath.endsWith(format)) return filePath;\n return `${filePath}.${format}`;\n });\n\n return strings.find((string) => string === file.path);\n }\n\n return false;\n });\n }\n\n private parsePackageNameFromPath(path: string) {\n const parts = path.split('node_modules');\n if (parts.length === 1) return '';\n const lastPart = parts[parts.length - 1].replace(sep, '');\n const pkgParts = lastPart.split('/');\n if (lastPart.startsWith('@')) {\n // scoped package\n return `${pkgParts[0]}/${pkgParts[1]}`;\n }\n const pkgName = pkgParts[0];\n if (pkgName === 'typescript') {\n // it's a built-in type, such as \"string\".\n return '';\n }\n return pkgName;\n }\n\n /**\n * return the file if part of the component.\n * otherwise, a reference to the target package and the type name.\n */\n private getSourceFile(filePath: string) {\n const file = this.findFileInComponent(filePath);\n if (!file) return undefined;\n return this.extractor.parseSourceFile(file);\n }\n\n async getSourceFileFromNode(node: Node) {\n const def = await this.tsserver.getDefinition(this.getPath(node), this.getLocation(node));\n\n const firstDef = head(def.body);\n if (!firstDef) {\n return undefined;\n }\n\n const sourceFile = this.getSourceFile(firstDef.file);\n\n return sourceFile;\n }\n\n /**\n * get a definition for a given node.\n */\n async definition(node: Node): Promise<Node | undefined> {\n const def = await this.tsserver.getDefinition(this.getPath(node), this.getLocation(node));\n\n const firstDef = head(def.body);\n if (!firstDef) {\n return undefined;\n }\n\n const startPosition = firstDef.start;\n const sourceFile = this.getSourceFile(firstDef.file);\n if (!sourceFile) {\n return undefined; // learn how to return a reference to a different component here.\n }\n const pos = this.getPosition(sourceFile, startPosition.line, startPosition.offset);\n const nodeAtPos = getTokenAtPosition(sourceFile, pos);\n return nodeAtPos;\n }\n\n /**\n * visit a definition for node - e.g. return it's schema.\n */\n async visitDefinition(node: Node): Promise<SchemaNode | undefined> {\n const definition = await this.definition(node);\n if (!definition) {\n return undefined;\n }\n return this.visit(definition.parent);\n }\n\n async visit(node: Node): Promise<SchemaNode> {\n return this.extractor.computeSchema(node, this);\n }\n\n references() {}\n\n isExported() {}\n\n isFromComponent() {}\n\n async getFileExports(exportDec: ExportDeclaration) {\n const file = exportDec.getSourceFile().fileName;\n const specifierPathStr = exportDec.moduleSpecifier?.getText() || '';\n const specifierPath = specifierPathStr.substring(1, specifierPathStr.length - 1);\n const absPath = resolve(file, '..', specifierPath);\n const sourceFile = this.getSourceFile(absPath);\n if (!sourceFile) return [];\n return this.extractor.computeExportedIdentifiers(sourceFile, this);\n }\n\n _exports: ExportList | undefined = undefined;\n\n setExports(exports: ExportList) {\n this._exports = exports;\n return this;\n }\n\n getExportedIdentifiers(node: Node) {\n return this.extractor.computeExportedIdentifiers(node, this);\n }\n\n async jump(file: AbstractVinyl, start: any): Promise<SchemaNode | undefined> {\n const sourceFile = this.extractor.parseSourceFile(file);\n const pos = this.getPosition(sourceFile, start.line, start.offset);\n const nodeAtPos = getTokenAtPosition(sourceFile, pos);\n if (!nodeAtPos) return undefined;\n\n // this causes some infinite loops. it's helpful for getting more data from types that are not exported.\n // e.g.\n // ```ts\n // class Bar {}\n // export const getBar = () => new Bar();\n // ```\n // if (nodeAtPos.kind === ts.SyntaxKind.Identifier) {\n // // @todo: make sure with Ran that it's fine. Maybe it's better to do: `this.visit(nodeAtPos.parent);`\n // return this.visitDefinition(nodeAtPos);\n // }\n try {\n return await this.visit(nodeAtPos);\n } catch (err) {\n if (err instanceof TransformerNotFound) {\n return undefined;\n }\n throw err;\n }\n }\n\n /**\n * resolve a type by a node and its identifier.\n */\n async resolveType(\n node: Node & { type?: TypeNode },\n typeStr: string,\n isTypeStrFromQuickInfo = true\n ): Promise<SchemaNode> {\n if (this._exports?.includes(typeStr)) return new TypeRefSchema(typeStr);\n if (node.type && ts.isTypeNode(node.type)) {\n // if a node has \"type\" prop, it has the type data of the node. this normally happens when the code has the type\n // explicitly, e.g. `const str: string` vs implicitly `const str = 'some-string'`, which the node won't have \"type\"\n return typeNodeToSchema(node.type, this);\n }\n /**\n * tsserver has two different calls: \"definition\" and \"typeDefinition\".\n * normally, we need the \"typeDefinition\" to get the type data of a node.\n * sometimes, it has no data, for example when the node is of type TypeReference, and then using \"definition\" is\n * helpful. (couldn't find a rule when to use each one. e.g. \"VariableDeclaration\" sometimes has data only in\n * \"definition\" but it's not clear when/why).\n */\n const getDef = async () => {\n const typeDefinition = await this.typeDefinition(node);\n const headTypeDefinition = head(typeDefinition?.body);\n if (headTypeDefinition) {\n return headTypeDefinition;\n }\n const definition = await this.tsserver.getDefinition(node.getSourceFile().fileName, this.getLocation(node));\n return head(definition?.body);\n };\n const definition = await getDef();\n\n // when we can't figure out the component/package/type of this node, we'll use the typeStr as the type.\n const unknownExactType = async () => {\n if (isTypeStrFromQuickInfo) {\n return new InferenceTypeSchema(typeStr);\n }\n const info = await this.getQuickInfo(node);\n const type = parseTypeFromQuickInfo(info);\n return new InferenceTypeSchema(type);\n };\n if (!definition) {\n return unknownExactType();\n }\n\n // the reason for this check is to avoid infinite loop when calling `this.jump` with the same file+location\n const isDefInSameLocation = () => {\n if (definition.file !== node.getSourceFile().fileName) {\n return false;\n }\n const loc = this.getLocation(node);\n return loc.line === definition.start.line && loc.character === definition.start.offset;\n };\n\n const file = this.findFileInComponent(definition.file);\n if (file) {\n if (isDefInSameLocation()) {\n return unknownExactType();\n }\n const schemaNode = await this.jump(file, definition.start);\n return schemaNode || unknownExactType();\n }\n const pkgName = this.parsePackageNameFromPath(definition.file);\n // TODO: find component id is exists, otherwise add the package name.\n return new TypeRefSchema(typeStr, undefined, pkgName);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["schema-extractor-context.ts"],"names":["SchemaExtractorContext","constructor","tsserver","component","extractor","undefined","computeSchema","node","getLocation","targetSourceFile","absolutePath","sourceFile","getSourceFile","position","getLineAndCharacterOfPosition","getStart","line","character","file","fileName","getPathRelativeToComponent","filePath","basePath","filesystem","files","base","getSignature","getSignatureHelp","getPath","getPosition","offset","getPositionOfLineAndCharacter","getQuickInfo","getQuickInfoDisplayString","quickInfo","body","displayString","typeDefinition","getTypeDefinition","visitTypeDefinition","findFileInComponent","find","path","includes","strings","map","format","endsWith","string","parsePackageNameFromPath","parts","split","length","lastPart","replace","sep","pkgParts","startsWith","pkgName","parseSourceFile","getSourceFileFromNode","def","getDefinition","firstDef","definition","startPosition","start","pos","nodeAtPos","visitDefinition","visit","parent","references","isExported","isFromComponent","getFileExports","exportDec","specifierPathStr","moduleSpecifier","getText","specifierPath","substring","absPath","computeExportedIdentifiers","setExports","exports","_exports","getExportedIdentifiers","jump","err","TransformerNotFound","resolveType","typeStr","isTypeStrFromQuickInfo","location","TypeRefSchema","type","ts","isTypeNode","getDef","headTypeDefinition","unknownExactType","InferenceTypeSchema","info","isDefInSame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CAAkBzB,IAAlB,CAAnB;AACA,YAAMyF,IAAI,GAAG,sDAAuBO,IAAvB,CAAb;AACA,aAAO,KAAID,wCAAJ,EAAwBR,QAAxB,EAAkCE,IAAlC,CAAP;AACD,KAPD;;AAQA,QAAI,CAAChC,UAAL,EAAiB;AACf,aAAOqC,gBAAgB,EAAvB;AACD,KAvCoB,CAyCrB;;;AACA,UAAMG,mBAAmB,GAAG,MAAM;AAChC,UAAIxC,UAAU,CAAC9C,IAAX,KAAoBX,IAAI,CAACK,aAAL,GAAqBO,QAA7C,EAAuD;AACrD,eAAO,KAAP;AACD;;AACD,YAAMsF,GAAG,GAAG,KAAKjG,WAAL,CAAiBD,IAAjB,CAAZ;AACA,aAAOkG,GAAG,CAACzF,IAAJ,KAAagD,UAAU,CAACE,KAAX,CAAiBlD,IAA9B,IAAsCyF,GAAG,CAACxF,SAAJ,KAAkB+C,UAAU,CAACE,KAAX,CAAiBpC,MAAhF;AACD,KAND;;AAQA,UAAMZ,IAAI,GAAG,KAAKsB,mBAAL,CAAyBwB,UAAU,CAAC9C,IAApC,CAAb;;AACA,QAAIA,IAAJ,EAAU;AACR,UAAIsF,mBAAmB,EAAvB,EAA2B;AACzB,eAAOH,gBAAgB,EAAvB;AACD;;AACD,YAAMK,UAAU,GAAG,MAAM,KAAKlB,IAAL,CAAUtE,IAAV,EAAgB8C,UAAU,CAACE,KAA3B,CAAzB;AACA,aAAOwC,UAAU,IAAIL,gBAAgB,EAArC;AACD;;AACD,UAAM3C,OAAO,GAAG,KAAKT,wBAAL,CAA8Be,UAAU,CAAC9C,IAAzC,CAAhB,CA1DqB,CA2DrB;;AACA,WAAO,KAAI6E,kCAAJ,EAAkBD,QAAlB,EAA4BF,OAA5B,EAAqCvF,SAArC,EAAgDqD,OAAhD,CAAP;AACD;;AArSiC","sourcesContent":["import { TsserverClient } from '@teambit/ts-server';\nimport ts, { ExportDeclaration, Node, TypeNode } from 'typescript';\nimport { getTokenAtPosition } from 'tsutils';\nimport { head } from 'lodash';\n// @ts-ignore david we should figure fix this.\nimport type { AbstractVinyl } from '@teambit/legacy/dist/consumer/component/sources';\nimport { resolve, sep, relative } from 'path';\nimport { Component } from '@teambit/component';\nimport { TypeRefSchema, SchemaNode, InferenceTypeSchema, Location } from '@teambit/semantics.entities.semantic-schema';\nimport { TypeScriptExtractor } from './typescript.extractor';\nimport { ExportList } from './export-list';\nimport { typeNodeToSchema } from './transformers/utils/type-node-to-schema';\nimport { TransformerNotFound } from './exceptions';\nimport { parseTypeFromQuickInfo } from './transformers/utils/parse-type-from-quick-info';\n\nexport class SchemaExtractorContext {\n constructor(\n readonly tsserver: TsserverClient,\n readonly component: Component,\n readonly extractor: TypeScriptExtractor\n ) {}\n\n computeSchema(node: Node) {\n return this.extractor.computeSchema(node, this);\n }\n\n /**\n * returns the location of a node in a source file.\n */\n getLocation(node: Node, targetSourceFile?: ts.SourceFile, absolutePath = false): Location {\n const sourceFile = targetSourceFile || node.getSourceFile();\n const position = sourceFile.getLineAndCharacterOfPosition(node.getStart());\n const line = position.line + 1;\n const character = position.character + 1;\n\n return {\n file: absolutePath ? sourceFile.fileName : this.getPathRelativeToComponent(sourceFile.fileName),\n line,\n character,\n };\n }\n\n getPathRelativeToComponent(filePath: string): string {\n const basePath = this.component.filesystem.files[0].base;\n return relative(basePath, filePath);\n }\n\n /**\n * returns a signature for a node.\n */\n async getSignature(node: Node) {\n return this.tsserver.getSignatureHelp(this.getPath(node), this.getLocation(node));\n }\n\n /**\n * get the position for the tsserver.\n */\n getPosition(sourceFile: ts.SourceFile, line: number, offset: number): number {\n return sourceFile.getPositionOfLineAndCharacter(line - 1, offset - 1);\n }\n\n /**\n * get the path for a source file.\n */\n getPath(node: Node) {\n const sourceFile = node.getSourceFile();\n return sourceFile.fileName;\n }\n\n /**\n * create a reference to a type from a component.\n * think if we don't need this because of type ref\n */\n // createRef() {\n // return {};\n // }\n\n getQuickInfo(node: Node) {\n return this.tsserver.getQuickInfo(this.getPath(node), this.getLocation(node));\n }\n\n async getQuickInfoDisplayString(node: Node): Promise<string> {\n const quickInfo = await this.tsserver.getQuickInfo(this.getPath(node), this.getLocation(node));\n return quickInfo?.body?.displayString || '';\n }\n\n /**\n * returns the type definition for a type.\n */\n typeDefinition(node: Node) {\n return this.tsserver.getTypeDefinition(this.getPath(node), this.getLocation(node));\n }\n\n visitTypeDefinition() {}\n\n private findFileInComponent(filePath: string) {\n return this.component.filesystem.files.find((file) => {\n // TODO: fix this line to support further extensions.\n if (file.path.includes(filePath)) {\n const strings = ['ts', 'tsx', 'js', 'jsx'].map((format) => {\n if (filePath.endsWith(format)) return filePath;\n return `${filePath}.${format}`;\n });\n\n return strings.find((string) => string === file.path);\n }\n\n return false;\n });\n }\n\n private parsePackageNameFromPath(path: string) {\n const parts = path.split('node_modules');\n if (parts.length === 1) return '';\n const lastPart = parts[parts.length - 1].replace(sep, '');\n const pkgParts = lastPart.split('/');\n if (lastPart.startsWith('@')) {\n // scoped package\n return `${pkgParts[0]}/${pkgParts[1]}`;\n }\n const pkgName = pkgParts[0];\n if (pkgName === 'typescript') {\n // it's a built-in type, such as \"string\".\n return '';\n }\n return pkgName;\n }\n\n /**\n * return the file if part of the component.\n * otherwise, a reference to the target package and the type name.\n */\n private getSourceFile(filePath: string) {\n const file = this.findFileInComponent(filePath);\n if (!file) return undefined;\n return this.extractor.parseSourceFile(file);\n }\n\n async getSourceFileFromNode(node: Node) {\n const def = await this.tsserver.getDefinition(this.getPath(node), this.getLocation(node));\n\n const firstDef = head(def.body);\n if (!firstDef) {\n return undefined;\n }\n\n const sourceFile = this.getSourceFile(firstDef.file);\n\n return sourceFile;\n }\n\n /**\n * get a definition for a given node.\n */\n async definition(node: Node): Promise<Node | undefined> {\n const def = await this.tsserver.getDefinition(this.getPath(node), this.getLocation(node));\n\n const firstDef = head(def.body);\n if (!firstDef) {\n return undefined;\n }\n\n const startPosition = firstDef.start;\n const sourceFile = this.getSourceFile(firstDef.file);\n if (!sourceFile) {\n return undefined; // learn how to return a reference to a different component here.\n }\n const pos = this.getPosition(sourceFile, startPosition.line, startPosition.offset);\n const nodeAtPos = getTokenAtPosition(sourceFile, pos);\n return nodeAtPos;\n }\n\n /**\n * visit a definition for node - e.g. return it's schema.\n */\n async visitDefinition(node: Node): Promise<SchemaNode | undefined> {\n const definition = await this.definition(node);\n if (!definition) {\n return undefined;\n }\n return this.visit(definition.parent);\n }\n\n async visit(node: Node): Promise<SchemaNode> {\n return this.extractor.computeSchema(node, this);\n }\n\n references() {}\n\n isExported() {}\n\n isFromComponent() {}\n\n async getFileExports(exportDec: ExportDeclaration) {\n const file = exportDec.getSourceFile().fileName;\n const specifierPathStr = exportDec.moduleSpecifier?.getText() || '';\n const specifierPath = specifierPathStr.substring(1, specifierPathStr.length - 1);\n const absPath = resolve(file, '..', specifierPath);\n const sourceFile = this.getSourceFile(absPath);\n if (!sourceFile) return [];\n return this.extractor.computeExportedIdentifiers(sourceFile, this);\n }\n\n _exports: ExportList | undefined = undefined;\n\n setExports(exports: ExportList) {\n this._exports = exports;\n return this;\n }\n\n getExportedIdentifiers(node: Node) {\n return this.extractor.computeExportedIdentifiers(node, this);\n }\n\n async jump(file: AbstractVinyl, start: any): Promise<SchemaNode | undefined> {\n const sourceFile = this.extractor.parseSourceFile(file);\n const pos = this.getPosition(sourceFile, start.line, start.offset);\n const nodeAtPos = getTokenAtPosition(sourceFile, pos);\n if (!nodeAtPos) return undefined;\n\n // this causes some infinite loops. it's helpful for getting more data from types that are not exported.\n // e.g.\n // ```ts\n // class Bar {}\n // export const getBar = () => new Bar();\n // ```\n // if (nodeAtPos.kind === ts.SyntaxKind.Identifier) {\n // // @todo: make sure with Ran that it's fine. Maybe it's better to do: `this.visit(nodeAtPos.parent);`\n // return this.visitDefinition(nodeAtPos);\n // }\n try {\n return await this.visit(nodeAtPos);\n } catch (err) {\n if (err instanceof TransformerNotFound) {\n return undefined;\n }\n throw err;\n }\n }\n\n /**\n * resolve a type by a node and its identifier.\n */\n async resolveType(\n node: Node & { type?: TypeNode },\n typeStr: string,\n isTypeStrFromQuickInfo = true\n ): Promise<SchemaNode> {\n const location = this.getLocation(node);\n if (this._exports?.includes(typeStr)) {\n return new TypeRefSchema(location, typeStr);\n }\n if (node.type && ts.isTypeNode(node.type)) {\n // if a node has \"type\" prop, it has the type data of the node. this normally happens when the code has the type\n // explicitly, e.g. `const str: string` vs implicitly `const str = 'some-string'`, which the node won't have \"type\"\n return typeNodeToSchema(node.type, this);\n }\n /**\n * tsserver has two different calls: \"definition\" and \"typeDefinition\".\n * normally, we need the \"typeDefinition\" to get the type data of a node.\n * sometimes, it has no data, for example when the node is of type TypeReference, and then using \"definition\" is\n * helpful. (couldn't find a rule when to use each one. e.g. \"VariableDeclaration\" sometimes has data only in\n * \"definition\" but it's not clear when/why).\n */\n const getDef = async () => {\n const typeDefinition = await this.typeDefinition(node);\n const headTypeDefinition = head(typeDefinition?.body);\n if (headTypeDefinition) {\n return headTypeDefinition;\n }\n const definition = await this.tsserver.getDefinition(node.getSourceFile().fileName, this.getLocation(node));\n return head(definition?.body);\n };\n const definition = await getDef();\n\n // when we can't figure out the component/package/type of this node, we'll use the typeStr as the type.\n const unknownExactType = async () => {\n if (isTypeStrFromQuickInfo) {\n return new InferenceTypeSchema(location, typeStr);\n }\n const info = await this.getQuickInfo(node);\n const type = parseTypeFromQuickInfo(info);\n return new InferenceTypeSchema(location, type);\n };\n if (!definition) {\n return unknownExactType();\n }\n\n // the reason for this check is to avoid infinite loop when calling `this.jump` with the same file+location\n const isDefInSameLocation = () => {\n if (definition.file !== node.getSourceFile().fileName) {\n return false;\n }\n const loc = this.getLocation(node);\n return loc.line === definition.start.line && loc.character === definition.start.offset;\n };\n\n const file = this.findFileInComponent(definition.file);\n if (file) {\n if (isDefInSameLocation()) {\n return unknownExactType();\n }\n const schemaNode = await this.jump(file, definition.start);\n return schemaNode || unknownExactType();\n }\n const pkgName = this.parsePackageNameFromPath(definition.file);\n // TODO: find component id is exists, otherwise add the package name.\n return new TypeRefSchema(location, typeStr, undefined, pkgName);\n }\n}\n"]}
|
|
@@ -116,7 +116,7 @@ class ClassDecelerationTransformer {
|
|
|
116
116
|
const displaySig = (info === null || info === void 0 ? void 0 : (_info$body = info.body) === null || _info$body === void 0 ? void 0 : _info$body.displayString) || '';
|
|
117
117
|
const typeStr = (0, _parseTypeFromQuickInfo().parseTypeFromQuickInfo)(info);
|
|
118
118
|
const type = await context.resolveType(getter, typeStr);
|
|
119
|
-
return new (_semanticsEntities().GetAccessorSchema)(getter.name.getText(), type, displaySig);
|
|
119
|
+
return new (_semanticsEntities().GetAccessorSchema)(context.getLocation(getter), getter.name.getText(), type, displaySig);
|
|
120
120
|
}
|
|
121
121
|
|
|
122
122
|
case _typescript().default.SyntaxKind.SetAccessor:
|
|
@@ -124,7 +124,7 @@ class ClassDecelerationTransformer {
|
|
|
124
124
|
const setter = member;
|
|
125
125
|
const params = await (0, _getParams().getParams)(setter.parameters, context);
|
|
126
126
|
const displaySig = await context.getQuickInfoDisplayString(setter.name);
|
|
127
|
-
return new (_semanticsEntities().SetAccessorSchema)(setter.name.getText(), params[0], displaySig);
|
|
127
|
+
return new (_semanticsEntities().SetAccessorSchema)(context.getLocation(setter), setter.name.getText(), params[0], displaySig);
|
|
128
128
|
}
|
|
129
129
|
|
|
130
130
|
default:
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["class-deceleration.ts"],"names":["ClassDecelerationTransformer","predicate","node","kind","ts","SyntaxKind","ClassDeclaration","getName","name","getText","getIdentifiers","ExportIdentifier","getSourceFile","fileName","transform","context","className","members","member","isPrivate","modifiers","some","modifier","PrivateKeyword","GetAccessor","getter","info","getQuickInfo","displaySig","body","displayString","typeStr","type","resolveType","GetAccessorSchema","SetAccessor","setter","params","parameters","getQuickInfoDisplayString","SetAccessorSchema","computeSchema","ClassSchema"
|
|
1
|
+
{"version":3,"sources":["class-deceleration.ts"],"names":["ClassDecelerationTransformer","predicate","node","kind","ts","SyntaxKind","ClassDeclaration","getName","name","getText","getIdentifiers","ExportIdentifier","getSourceFile","fileName","transform","context","className","members","member","isPrivate","modifiers","some","modifier","PrivateKeyword","GetAccessor","getter","info","getQuickInfo","displaySig","body","displayString","typeStr","type","resolveType","GetAccessorSchema","getLocation","SetAccessor","setter","params","parameters","getQuickInfoDisplayString","SetAccessorSchema","computeSchema","ClassSchema"],"mappings":";;;;;;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAGA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEO,MAAMA,4BAAN,CAAgE;AACrEC,EAAAA,SAAS,CAACC,IAAD,EAAa;AACpB,WAAOA,IAAI,CAACC,IAAL,KAAcC,sBAAGC,UAAH,CAAcC,gBAAnC;AACD,GAHoE,CAKrE;;;AACQC,EAAAA,OAAO,CAACL,IAAD,EAAyB;AAAA;;AACtC,WAAO,eAAAA,IAAI,CAACM,IAAL,0DAAWC,OAAX,OAAwB,SAA/B;AACD;;AAEmB,QAAdC,cAAc,CAACR,IAAD,EAAyB;AAC3C,WAAO,CAAC,KAAIS,oCAAJ,EAAqB,KAAKJ,OAAL,CAAaL,IAAb,CAArB,EAAyCA,IAAI,CAACU,aAAL,GAAqBC,QAA9D,CAAD,CAAP;AACD;;AAEc,QAATC,SAAS,CAACZ,IAAD,EAAyBa,OAAzB,EAA0D;AACvE,UAAMC,SAAS,GAAG,KAAKT,OAAL,CAAaL,IAAb,CAAlB;AACA,UAAMe,OAAO,GAAG,MAAM,2BAAWf,IAAI,CAACe,OAAhB,EAAyB,MAAOC,MAAP,IAAkB;AAAA;;AAC/D,YAAMC,SAAS,wBA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AM,CAAC,CAAD,CAAhF,EAAqFV,UAArF,CAAP;AACD;;AACD;AACE,iBAAOb,OAAO,CAAC2B,aAAR,CAAsBxB,MAAtB,CAAP;AAhBJ;AAkBD,KAvBqB,CAAtB;AAwBA,WAAO,KAAIyB,gCAAJ,EAAgB3B,SAAhB,EAA2B,uBAAQC,OAAR,CAA3B,EAA6CF,OAAO,CAACoB,WAAR,CAAoBjC,IAApB,CAA7C,CAAP;AACD;;AAzCoE","sourcesContent":["import pMapSeries from 'p-map-series';\nimport { compact } from 'lodash';\nimport { ClassSchema, GetAccessorSchema, SetAccessorSchema } from '@teambit/semantics.entities.semantic-schema';\nimport ts, { Node, ClassDeclaration } from 'typescript';\nimport { SchemaTransformer } from '../schema-transformer';\nimport { SchemaExtractorContext } from '../schema-extractor-context';\nimport { ExportIdentifier } from '../export-identifier';\nimport { parseTypeFromQuickInfo } from './utils/parse-type-from-quick-info';\nimport { getParams } from './utils/get-params';\n\nexport class ClassDecelerationTransformer 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 ExportIdentifier(this.getName(node), node.getSourceFile().fileName)];\n }\n\n async transform(node: ClassDeclaration, context: SchemaExtractorContext) {\n const className = this.getName(node);\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 switch (member.kind) {\n case ts.SyntaxKind.GetAccessor: {\n const getter = member as ts.GetAccessorDeclaration;\n const info = await context.getQuickInfo(getter.name);\n const displaySig = info?.body?.displayString || '';\n const typeStr = parseTypeFromQuickInfo(info);\n const type = await context.resolveType(getter, typeStr);\n return new GetAccessorSchema(context.getLocation(getter), getter.name.getText(), type, displaySig);\n }\n case ts.SyntaxKind.SetAccessor: {\n const setter = member as ts.SetAccessorDeclaration;\n const params = await getParams(setter.parameters, context);\n const displaySig = await context.getQuickInfoDisplayString(setter.name);\n return new SetAccessorSchema(context.getLocation(setter), setter.name.getText(), params[0], displaySig);\n }\n default:\n return context.computeSchema(member);\n }\n });\n return new ClassSchema(className, compact(members), context.getLocation(node));\n }\n}\n"]}
|
|
@@ -60,7 +60,7 @@ class Constructor {
|
|
|
60
60
|
|
|
61
61
|
async transform(constructorDec, context) {
|
|
62
62
|
const args = await (0, _getParams().getParams)(constructorDec.parameters, context);
|
|
63
|
-
return new (_semanticsEntities().ConstructorSchema)(args);
|
|
63
|
+
return new (_semanticsEntities().ConstructorSchema)(context.getLocation(constructorDec), args);
|
|
64
64
|
}
|
|
65
65
|
|
|
66
66
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["constructor.ts"],"names":["Constructor","predicate","node","kind","ts","SyntaxKind","getIdentifiers","ExportIdentifier","getSourceFile","fileName","transform","constructorDec","context","args","parameters","ConstructorSchema"],"mappings":";;;;;;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAGA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEO,MAAMA,WAAN,CAA+C;AACpDC,EAAAA,SAAS,CAACC,IAAD,EAAa;AACpB,WAAOA,IAAI,CAACC,IAAL,KAAcC,sBAAGC,UAAH,CAAcL,WAAnC;AACD;;AAEmB,QAAdM,cAAc,CAACJ,IAAD,EAA+B;AACjD,WAAO,CAAC,KAAIK,oCAAJ,EAAqB,aAArB,EAAoCL,IAAI,CAACM,aAAL,GAAqBC,QAAzD,CAAD,CAAP;AACD;;AAEc,QAATC,SAAS,CAACC,cAAD,EAAyCC,OAAzC,EAA+F;AAC5G,UAAMC,IAAI,GAAG,MAAM,4BAAUF,cAAc,CAACG,UAAzB,EAAqCF,OAArC,CAAnB;AAEA,WAAO,KAAIG,sCAAJ,
|
|
1
|
+
{"version":3,"sources":["constructor.ts"],"names":["Constructor","predicate","node","kind","ts","SyntaxKind","getIdentifiers","ExportIdentifier","getSourceFile","fileName","transform","constructorDec","context","args","parameters","ConstructorSchema","getLocation"],"mappings":";;;;;;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAGA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEO,MAAMA,WAAN,CAA+C;AACpDC,EAAAA,SAAS,CAACC,IAAD,EAAa;AACpB,WAAOA,IAAI,CAACC,IAAL,KAAcC,sBAAGC,UAAH,CAAcL,WAAnC;AACD;;AAEmB,QAAdM,cAAc,CAACJ,IAAD,EAA+B;AACjD,WAAO,CAAC,KAAIK,oCAAJ,EAAqB,aAArB,EAAoCL,IAAI,CAACM,aAAL,GAAqBC,QAAzD,CAAD,CAAP;AACD;;AAEc,QAATC,SAAS,CAACC,cAAD,EAAyCC,OAAzC,EAA+F;AAC5G,UAAMC,IAAI,GAAG,MAAM,4BAAUF,cAAc,CAACG,UAAzB,EAAqCF,OAArC,CAAnB;AAEA,WAAO,KAAIG,sCAAJ,EAAsBH,OAAO,CAACI,WAAR,CAAoBL,cAApB,CAAtB,EAA2DE,IAA3D,CAAP;AACD;;AAbmD","sourcesContent":["import { SchemaNode, ConstructorSchema } from '@teambit/semantics.entities.semantic-schema';\nimport ts, { Node, ConstructorDeclaration } from 'typescript';\nimport { SchemaExtractorContext } from '../schema-extractor-context';\nimport { SchemaTransformer } from '../schema-transformer';\nimport { ExportIdentifier } from '../export-identifier';\nimport { getParams } from './utils/get-params';\n\nexport class Constructor implements SchemaTransformer {\n predicate(node: Node) {\n return node.kind === ts.SyntaxKind.Constructor;\n }\n\n async getIdentifiers(node: ConstructorDeclaration) {\n return [new ExportIdentifier('constructor', node.getSourceFile().fileName)];\n }\n\n async transform(constructorDec: ConstructorDeclaration, context: SchemaExtractorContext): Promise<SchemaNode> {\n const args = await getParams(constructorDec.parameters, context);\n\n return new ConstructorSchema(context.getLocation(constructorDec), args);\n }\n}\n"]}
|
|
@@ -88,7 +88,7 @@ class ExportDeclaration {
|
|
|
88
88
|
const schemas = await Promise.all(exportClause.elements.map(async element => {
|
|
89
89
|
return context.visitDefinition(element.name);
|
|
90
90
|
}));
|
|
91
|
-
return new (_semanticsEntities().Module)((0, _lodash().compact)(schemas));
|
|
91
|
+
return new (_semanticsEntities().Module)(context.getLocation(node), (0, _lodash().compact)(schemas));
|
|
92
92
|
} // e.g. `export * as Composition from './button';
|
|
93
93
|
|
|
94
94
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["export-declaration.ts"],"names":["ExportDeclaration","predicate","node","kind","SyntaxKind","getIdentifiers","exportDec","context","exportClause","ts","NamedExports","elements","map","elm","ExportIdentifier","name","getText","getSourceFile","fileName","NamespaceExport","moduleSpecifier","getFileExports","transform","schemas","Promise","all","element","visitDefinition","Module","namespace","sourceFile","getSourceFileFromNode","Error","result","computeSchema","specifier"],"mappings":";;;;;;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AASA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;;;;;AAEO,MAAMA,iBAAN,CAAqD;AAC1DC,EAAAA,SAAS,CAACC,IAAD,EAAa;AACpB,WAAOA,IAAI,CAACC,IAAL,KAAcC,yBAAWJ,iBAAhC;AACD;;AAEmB,QAAdK,cAAc,CAACC,SAAD,EAAmCC,OAAnC,EAAoE;AAAA;;AACtF,QAAI,0BAAAD,SAAS,CAACE,YAAV,gFAAwBL,IAAxB,MAAiCM,sBAAGL,U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portDeclaration","predicate","node","kind","SyntaxKind","getIdentifiers","exportDec","context","exportClause","ts","NamedExports","elements","map","elm","ExportIdentifier","name","getText","getSourceFile","fileName","NamespaceExport","moduleSpecifier","getFileExports","transform","schemas","Promise","all","element","visitDefinition","Module","getLocation","namespace","sourceFile","getSourceFileFromNode","Error","result","computeSchema","specifier"],"mappings":";;;;;;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AASA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;;;;;AAEO,MAAMA,iBAAN,CAAqD;AAC1DC,EAAAA,SAAS,CAACC,IAAD,EAAa;AACpB,WAAOA,IAAI,CAACC,IAAL,KAAcC,yBAAWJ,iBAAhC;AACD;;AAEmB,QAAdK,cAAc,CAACC,SAAD,EAAmCC,OAAnC,EAAoE;AAAA;;AACtF,QAAI,0BAAAD,SAAS,CAACE,YAAV,gFAAwBL,IAAxB,MAAiCM,sBAAGL,UAAH,CAAcM,YAAnD,EAAiE;AAC/DJ,MAAAA,SAAS,CAACE,YAAV;AACA,aAAOF,SAAS,CAACE,YAAV,CAAuBG,QAAvB,CAAgCC,GAAhC,CAAqCC,GAAD,IAAS;AAClD,eAAO,KAAIC,oCAAJ,EAAqBD,GAAG,CAACE,IAAJ,CAASC,OAAT,EAArB,EAAyCH,GAAG,CAACI,aAAJ,GAAoBC,QAA7D,CAAP;AACD,OAFM,CAAP;AAGD;;AAED,QAAI,2BAAAZ,SAAS,CAACE,YAAV,kFAAwBL,IAAxB,MAAiCM,sBAAGL,UAAH,CAAce,eAAnD,EAAoE;AAClE,aAAO,CAAC,KAAIL,oCAAJ,EAAqBR,SAAS,CAACE,YAAV,CAAuBO,IAAvB,CAA4BC,OAA5B,EAArB,EAA4DV,SAAS,CAACW,aAAV,GAA0BC,QAAtF,CAAD,CAAP;AACD;;AAED,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AYN,2BAApB,CAAJ,EAAiC;AAC/B,cAAM,IAAIK,KAAJ,CAAW,wCAAX,CAAN;AACD;;AACDC,MAAAA,MAAM,CAACJ,SAAP,GAAmBA,SAAnB;AACA,aAAOI,MAAP;AACD,KA5B+E,CA6BhF;;;AACA,QAAI,CAAC1B,YAAL,EAAmB;AACjB,YAAM4B,SAAS,GAAG9B,SAAS,CAACc,eAA5B;;AACA,UAAI,CAACgB,SAAL,EAAgB;AACd,cAAM,IAAIH,KAAJ,CAAW,qBAAX,CAAN;AACD;;AACD,YAAMF,UAAU,GAAG,MAAMxB,OAAO,CAACyB,qBAAR,CAA8BI,SAA9B,CAAzB;;AACA,UAAI,CAACL,UAAL,EAAiB;AACf,cAAM,IAAIE,KAAJ,CAAW,gCAAX,CAAN;AACD;;AACD,aAAO1B,OAAO,CAAC4B,aAAR,CAAsBJ,UAAtB,CAAP;AACD;;AAED,UAAM,IAAIE,KAAJ,CAAU,0BAAV,CAAN;AACD;;AAnEyD","sourcesContent":["import { SchemaNode, Module } from '@teambit/semantics.entities.semantic-schema';\nimport { compact } from 'lodash';\nimport ts, {\n Node,\n SyntaxKind,\n ExportDeclaration as ExportDeclarationNode,\n NamedExports,\n NamespaceExport,\n} from 'typescript';\nimport { SchemaExtractorContext } from '../schema-extractor-context';\nimport { SchemaTransformer } from '../schema-transformer';\nimport { ExportIdentifier } from '../export-identifier';\n\nexport class ExportDeclaration implements SchemaTransformer {\n predicate(node: Node) {\n return node.kind === SyntaxKind.ExportDeclaration;\n }\n\n async getIdentifiers(exportDec: ExportDeclarationNode, context: SchemaExtractorContext) {\n if (exportDec.exportClause?.kind === ts.SyntaxKind.NamedExports) {\n exportDec.exportClause as NamedExports;\n return exportDec.exportClause.elements.map((elm) => {\n return new ExportIdentifier(elm.name.getText(), elm.getSourceFile().fileName);\n });\n }\n\n if (exportDec.exportClause?.kind === ts.SyntaxKind.NamespaceExport) {\n return [new ExportIdentifier(exportDec.exportClause.name.getText(), exportDec.getSourceFile().fileName)];\n }\n\n if (exportDec.moduleSpecifier) {\n return context.getFileExports(exportDec);\n }\n\n return [];\n }\n\n async transform(node: Node, context: SchemaExtractorContext): Promise<SchemaNode> {\n const exportDec = node as ExportDeclarationNode;\n const exportClause = exportDec.exportClause;\n // e.g. `export { button1, button2 } as Composition from './button';\n if (exportClause?.kind === SyntaxKind.NamedExports) {\n exportClause as NamedExports;\n const schemas = await Promise.all(\n exportClause.elements.map(async (element) => {\n return context.visitDefinition(element.name);\n })\n );\n\n return new Module(context.getLocation(node), compact(schemas));\n }\n // e.g. `export * as Composition from './button';\n if (exportClause?.kind === SyntaxKind.NamespaceExport) {\n exportClause as NamespaceExport;\n const namespace = exportClause.name.getText();\n const sourceFile = await context.getSourceFileFromNode(exportClause.name);\n if (!sourceFile) {\n throw new Error(`unable to find the source-file for \"${namespace}\"`);\n }\n const result = await context.computeSchema(sourceFile);\n if (!(result instanceof Module)) {\n throw new Error(`expect result to be instance of Module`);\n }\n result.namespace = namespace;\n return result;\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 if (!sourceFile) {\n throw new Error(`unable to find the source-file`);\n }\n return context.computeSchema(sourceFile);\n }\n\n throw new Error('unrecognized export type');\n }\n}\n"]}
|
|
@@ -61,7 +61,7 @@ class IndexSignature {
|
|
|
61
61
|
async transform(indexSig, context) {
|
|
62
62
|
const params = await (0, _getParams().getParams)(indexSig.parameters, context);
|
|
63
63
|
const type = await (0, _typeNodeToSchema().typeNodeToSchema)(indexSig.type, context);
|
|
64
|
-
return new (_semanticsEntities().IndexSignatureSchema)(params, type);
|
|
64
|
+
return new (_semanticsEntities().IndexSignatureSchema)(context.getLocation(indexSig), params, type);
|
|
65
65
|
}
|
|
66
66
|
|
|
67
67
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["index-signature.ts"],"names":["IndexSignature","predicate","node","kind","ts","SyntaxKind","getIdentifiers","transform","indexSig","context","params","parameters","type","IndexSignatureSchema"],"mappings":";;;;;;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAGA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEO,MAAMA,cAAN,CAAkD;AACvDC,EAAAA,SAAS,CAACC,IAAD,EAAa;AACpB,WAAOA,IAAI,CAACC,IAAL,KAAcC,sBAAGC,UAAH,CAAcL,cAAnC;AACD;;AAEmB,QAAdM,cAAc,GAAG;AACrB,WAAO,EAAP;AACD;;AAEc,QAATC,SAAS,CAACC,QAAD,EAAsCC,OAAtC,EAA4F;AACzG,UAAMC,MAAM,GAAG,MAAM,4BAAUF,QAAQ,CAACG,UAAnB,EAA+BF,OAA/B,CAArB;AACA,UAAMG,IAAI,GAAG,MAAM,0CAAiBJ,QAAQ,CAACI,IAA1B,EAAgCH,OAAhC,CAAnB;AACA,WAAO,KAAII,yCAAJ,
|
|
1
|
+
{"version":3,"sources":["index-signature.ts"],"names":["IndexSignature","predicate","node","kind","ts","SyntaxKind","getIdentifiers","transform","indexSig","context","params","parameters","type","IndexSignatureSchema","getLocation"],"mappings":";;;;;;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAGA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEO,MAAMA,cAAN,CAAkD;AACvDC,EAAAA,SAAS,CAACC,IAAD,EAAa;AACpB,WAAOA,IAAI,CAACC,IAAL,KAAcC,sBAAGC,UAAH,CAAcL,cAAnC;AACD;;AAEmB,QAAdM,cAAc,GAAG;AACrB,WAAO,EAAP;AACD;;AAEc,QAATC,SAAS,CAACC,QAAD,EAAsCC,OAAtC,EAA4F;AACzG,UAAMC,MAAM,GAAG,MAAM,4BAAUF,QAAQ,CAACG,UAAnB,EAA+BF,OAA/B,CAArB;AACA,UAAMG,IAAI,GAAG,MAAM,0CAAiBJ,QAAQ,CAACI,IAA1B,EAAgCH,OAAhC,CAAnB;AACA,WAAO,KAAII,yCAAJ,EAAyBJ,OAAO,CAACK,WAAR,CAAoBN,QAApB,CAAzB,EAAwDE,MAAxD,EAAgEE,IAAhE,CAAP;AACD;;AAbsD","sourcesContent":["import { SchemaNode, IndexSignatureSchema } from '@teambit/semantics.entities.semantic-schema';\nimport ts, { Node, IndexSignatureDeclaration } from 'typescript';\nimport { SchemaTransformer } from '../schema-transformer';\nimport { SchemaExtractorContext } from '../schema-extractor-context';\nimport { getParams } from './utils/get-params';\nimport { typeNodeToSchema } from './utils/type-node-to-schema';\n\nexport class IndexSignature implements SchemaTransformer {\n predicate(node: Node) {\n return node.kind === ts.SyntaxKind.IndexSignature;\n }\n\n async getIdentifiers() {\n return [];\n }\n\n async transform(indexSig: IndexSignatureDeclaration, context: SchemaExtractorContext): Promise<SchemaNode> {\n const params = await getParams(indexSig.parameters, context);\n const type = await typeNodeToSchema(indexSig.type, context);\n return new IndexSignatureSchema(context.getLocation(indexSig), params, type);\n }\n}\n"]}
|
|
@@ -63,7 +63,7 @@ class InterfaceDeclarationTransformer {
|
|
|
63
63
|
const typeSchema = await context.computeSchema(member);
|
|
64
64
|
return typeSchema;
|
|
65
65
|
});
|
|
66
|
-
return new (_semanticsEntities().InterfaceSchema)(interfaceDec.name.getText(), members);
|
|
66
|
+
return new (_semanticsEntities().InterfaceSchema)(context.getLocation(interfaceDec), interfaceDec.name.getText(), members);
|
|
67
67
|
}
|
|
68
68
|
|
|
69
69
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["interface-declaration.ts"],"names":["InterfaceDeclarationTransformer","predicate","node","kind","ts","SyntaxKind","InterfaceDeclaration","getIdentifiers","ExportIdentifier","name","getText","getSourceFile","fileName","transform","interfaceDec","context","members","member","typeSchema","computeSchema","InterfaceSchema"],"mappings":";;;;;;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAGA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEO,MAAMA,+BAAN,CAAmE;AACxEC,EAAAA,SAAS,CAACC,IAAD,EAAa;AACpB,WAAOA,IAAI,CAACC,IAAL,KAAcC,sBAAGC,UAAH,CAAcC,oBAAnC;AACD;;AAEmB,QAAdC,cAAc,CAACL,IAAD,EAA0D;AAC5E,WAAO,CAAC,KAAIM,oCAAJ,EAAqBN,IAAI,CAACO,IAAL,CAAUC,OAAV,EAArB,EAA0CR,IAAI,CAACS,aAAL,GAAqBC,QAA/D,CAAD,CAAP;AACD;;AAEc,QAATC,SAAS,CAACC,YAAD,EAAqCC,OAArC,EAAsE;AACnF,UAAMC,OAAO,GAAG,MAAM,2BAAWF,YAAY,CAACE,OAAxB,EAAiC,MAAOC,MAAP,IAAkB;AACvE,YAAMC,UAAU,GAAG,MAAMH,OAAO,CAACI,aAAR,CAAsBF,MAAtB,CAAzB;AACA,aAAOC,UAAP;AACD,KAHqB,CAAtB;AAIA,WAAO,KAAIE,oCAAJ,
|
|
1
|
+
{"version":3,"sources":["interface-declaration.ts"],"names":["InterfaceDeclarationTransformer","predicate","node","kind","ts","SyntaxKind","InterfaceDeclaration","getIdentifiers","ExportIdentifier","name","getText","getSourceFile","fileName","transform","interfaceDec","context","members","member","typeSchema","computeSchema","InterfaceSchema","getLocation"],"mappings":";;;;;;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAGA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEO,MAAMA,+BAAN,CAAmE;AACxEC,EAAAA,SAAS,CAACC,IAAD,EAAa;AACpB,WAAOA,IAAI,CAACC,IAAL,KAAcC,sBAAGC,UAAH,CAAcC,oBAAnC;AACD;;AAEmB,QAAdC,cAAc,CAACL,IAAD,EAA0D;AAC5E,WAAO,CAAC,KAAIM,oCAAJ,EAAqBN,IAAI,CAACO,IAAL,CAAUC,OAAV,EAArB,EAA0CR,IAAI,CAACS,aAAL,GAAqBC,QAA/D,CAAD,CAAP;AACD;;AAEc,QAATC,SAAS,CAACC,YAAD,EAAqCC,OAArC,EAAsE;AACnF,UAAMC,OAAO,GAAG,MAAM,2BAAWF,YAAY,CAACE,OAAxB,EAAiC,MAAOC,MAAP,IAAkB;AACvE,YAAMC,UAAU,GAAG,MAAMH,OAAO,CAACI,aAAR,CAAsBF,MAAtB,CAAzB;AACA,aAAOC,UAAP;AACD,KAHqB,CAAtB;AAIA,WAAO,KAAIE,oCAAJ,EAAoBL,OAAO,CAACM,WAAR,CAAoBP,YAApB,CAApB,EAAuDA,YAAY,CAACL,IAAb,CAAkBC,OAAlB,EAAvD,EAAoFM,OAApF,CAAP;AACD;;AAfuE","sourcesContent":["import ts, { Node, InterfaceDeclaration } from 'typescript';\nimport pMapSeries from 'p-map-series';\nimport { InterfaceSchema } from '@teambit/semantics.entities.semantic-schema';\nimport { SchemaTransformer } from '../schema-transformer';\nimport { SchemaExtractorContext } from '../schema-extractor-context';\nimport { ExportIdentifier } from '../export-identifier';\n\nexport class InterfaceDeclarationTransformer implements SchemaTransformer {\n predicate(node: Node) {\n return node.kind === ts.SyntaxKind.InterfaceDeclaration;\n }\n\n async getIdentifiers(node: InterfaceDeclaration): Promise<ExportIdentifier[]> {\n return [new ExportIdentifier(node.name.getText(), node.getSourceFile().fileName)];\n }\n\n async transform(interfaceDec: InterfaceDeclaration, context: SchemaExtractorContext) {\n const members = await pMapSeries(interfaceDec.members, async (member) => {\n const typeSchema = await context.computeSchema(member);\n return typeSchema;\n });\n return new InterfaceSchema(context.getLocation(interfaceDec), interfaceDec.name.getText(), members);\n }\n}\n"]}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { LiteralTypeNode, Node } from 'typescript';
|
|
2
2
|
import { TypeRefSchema } from '@teambit/semantics.entities.semantic-schema';
|
|
3
3
|
import { SchemaTransformer } from '../schema-transformer';
|
|
4
|
+
import { SchemaExtractorContext } from '../schema-extractor-context';
|
|
4
5
|
export declare class LiteralTypeTransformer implements SchemaTransformer {
|
|
5
6
|
predicate(node: Node): boolean;
|
|
6
7
|
getIdentifiers(): Promise<never[]>;
|
|
7
|
-
transform(literalType: LiteralTypeNode): Promise<TypeRefSchema>;
|
|
8
|
+
transform(literalType: LiteralTypeNode, context: SchemaExtractorContext): Promise<TypeRefSchema>;
|
|
8
9
|
}
|
|
@@ -38,9 +38,9 @@ class LiteralTypeTransformer {
|
|
|
38
38
|
return [];
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
async transform(literalType) {
|
|
41
|
+
async transform(literalType, context) {
|
|
42
42
|
const type = literalType.literal.getText();
|
|
43
|
-
return new (_semanticsEntities().TypeRefSchema)(type);
|
|
43
|
+
return new (_semanticsEntities().TypeRefSchema)(context.getLocation(literalType), type);
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["literal-type.ts"],"names":["LiteralTypeTransformer","predicate","node","kind","ts","SyntaxKind","LiteralType","getIdentifiers","transform","literalType","type","literal","getText","TypeRefSchema"],"mappings":";;;;;;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;
|
|
1
|
+
{"version":3,"sources":["literal-type.ts"],"names":["LiteralTypeTransformer","predicate","node","kind","ts","SyntaxKind","LiteralType","getIdentifiers","transform","literalType","context","type","literal","getText","TypeRefSchema","getLocation"],"mappings":";;;;;;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAIO,MAAMA,sBAAN,CAA0D;AAC/DC,EAAAA,SAAS,CAACC,IAAD,EAAa;AACpB,WAAOA,IAAI,CAACC,IAAL,KAAcC,sBAAGC,UAAH,CAAcC,WAAnC;AACD;;AAEmB,QAAdC,cAAc,GAAG;AACrB,WAAO,EAAP;AACD;;AAEc,QAATC,SAAS,CAACC,WAAD,EAA+BC,OAA/B,EAAgE;AAC7E,UAAMC,IAAI,GAAGF,WAAW,CAACG,OAAZ,CAAoBC,OAApB,EAAb;AACA,WAAO,KAAIC,kCAAJ,EAAkBJ,OAAO,CAACK,WAAR,CAAoBN,WAApB,CAAlB,EAAoDE,IAApD,CAAP;AACD;;AAZ8D","sourcesContent":["import ts, { LiteralTypeNode, Node } from 'typescript';\nimport { TypeRefSchema } from '@teambit/semantics.entities.semantic-schema';\nimport { SchemaTransformer } from '../schema-transformer';\nimport { SchemaExtractorContext } from '../schema-extractor-context';\n\nexport class LiteralTypeTransformer implements SchemaTransformer {\n predicate(node: Node) {\n return node.kind === ts.SyntaxKind.LiteralType;\n }\n\n async getIdentifiers() {\n return [];\n }\n\n async transform(literalType: LiteralTypeNode, context: SchemaExtractorContext) {\n const type = literalType.literal.getText();\n return new TypeRefSchema(context.getLocation(literalType), type);\n }\n}\n"]}
|
|
@@ -70,7 +70,7 @@ class PropertyDeclaration {
|
|
|
70
70
|
const displaySig = info === null || info === void 0 ? void 0 : (_info$body = info.body) === null || _info$body === void 0 ? void 0 : _info$body.displayString;
|
|
71
71
|
const typeStr = (0, _parseTypeFromQuickInfo().parseTypeFromQuickInfo)(info);
|
|
72
72
|
const type = await context.resolveType(propertyDec, typeStr);
|
|
73
|
-
return new (_semanticsEntities().VariableSchema)(name
|
|
73
|
+
return new (_semanticsEntities().VariableSchema)(context.getLocation(propertyDec), name, displaySig || '', type);
|
|
74
74
|
}
|
|
75
75
|
|
|
76
76
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["property-declaration.ts"],"names":["PropertyDeclaration","predicate","node","kind","ts","SyntaxKind","getName","name","getText","getIdentifiers","ExportIdentifier","getSourceFile","fileName","transform","propertyDec","context","info","getQuickInfo","displaySig","body","displayString","typeStr","type","resolveType","VariableSchema"],"mappings":";;;;;;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAGA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEO,MAAMA,mBAAN,CAAuD;AAC5DC,EAAAA,SAAS,CAACC,IAAD,EAAa;AACpB,WAAOA,IAAI,CAACC,IAAL,KAAcC,sBAAGC,UAAH,CAAcL,mBAAnC;AACD;;AAEDM,EAAAA,OAAO,CAACJ,IAAD,EAAgC;AACrC,WAAOA,IAAI,CAACK,IAAL,CAAUC,OAAV,EAAP;AACD;;AAEmB,QAAdC,cAAc,CAACP,IAAD,EAAgC;AAClD,WAAO,CAAC,KAAIQ,oCAAJ,EAAqBR,IAAI,CAACK,IAAL,CAAUC,OAAV,EAArB,EAA0CN,IAAI,CAACS,aAAL,GAAqBC,QAA/D,CAAD,CAAP;AACD;;AAEc,QAATC,SAAS,CAACC,WAAD,EAAuCC,OAAvC,EAA6F;AAAA;;AAC1G,UAAMR,IAAI,GAAG,KAAKD,OAAL,CAAaQ,WAAb,CAAb;AACA,UAAME,IAAI,GAAG,MAAMD,OAAO,CAACE,YAAR,CAAqBH,WAAW,CAACP,IAAjC,CAAnB;AACA,UAAMW,UAAU,GAAGF,IAAH,aAAGA,IAAH,qCAAGA,IAAI,CAAEG,IAAT,+CAAG,WAAYC,aAA/B;AACA,UAAMC,OAAO,GAAG,sDAAuBL,IAAvB,CAAhB;AACA,UAAMM,IAAI,GAAG,MAAMP,OAAO,CAACQ,WAAR,CAAoBT,WAApB,EAAiCO,OAAjC,CAAnB;AAEA,WAAO,KAAIG,mCAAJ,
|
|
1
|
+
{"version":3,"sources":["property-declaration.ts"],"names":["PropertyDeclaration","predicate","node","kind","ts","SyntaxKind","getName","name","getText","getIdentifiers","ExportIdentifier","getSourceFile","fileName","transform","propertyDec","context","info","getQuickInfo","displaySig","body","displayString","typeStr","type","resolveType","VariableSchema","getLocation"],"mappings":";;;;;;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAGA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEO,MAAMA,mBAAN,CAAuD;AAC5DC,EAAAA,SAAS,CAACC,IAAD,EAAa;AACpB,WAAOA,IAAI,CAACC,IAAL,KAAcC,sBAAGC,UAAH,CAAcL,mBAAnC;AACD;;AAEDM,EAAAA,OAAO,CAACJ,IAAD,EAAgC;AACrC,WAAOA,IAAI,CAACK,IAAL,CAAUC,OAAV,EAAP;AACD;;AAEmB,QAAdC,cAAc,CAACP,IAAD,EAAgC;AAClD,WAAO,CAAC,KAAIQ,oCAAJ,EAAqBR,IAAI,CAACK,IAAL,CAAUC,OAAV,EAArB,EAA0CN,IAAI,CAACS,aAAL,GAAqBC,QAA/D,CAAD,CAAP;AACD;;AAEc,QAATC,SAAS,CAACC,WAAD,EAAuCC,OAAvC,EAA6F;AAAA;;AAC1G,UAAMR,IAAI,GAAG,KAAKD,OAAL,CAAaQ,WAAb,CAAb;AACA,UAAME,IAAI,GAAG,MAAMD,OAAO,CAACE,YAAR,CAAqBH,WAAW,CAACP,IAAjC,CAAnB;AACA,UAAMW,UAAU,GAAGF,IAAH,aAAGA,IAAH,qCAAGA,IAAI,CAAEG,IAAT,+CAAG,WAAYC,aAA/B;AACA,UAAMC,OAAO,GAAG,sDAAuBL,IAAvB,CAAhB;AACA,UAAMM,IAAI,GAAG,MAAMP,OAAO,CAACQ,WAAR,CAAoBT,WAApB,EAAiCO,OAAjC,CAAnB;AAEA,WAAO,KAAIG,mCAAJ,EAAmBT,OAAO,CAACU,WAAR,CAAoBX,WAApB,CAAnB,EAAqDP,IAArD,EAA2DW,UAAU,IAAI,EAAzE,EAA6EI,IAA7E,CAAP;AACD;;AArB2D","sourcesContent":["import { SchemaNode, VariableSchema } from '@teambit/semantics.entities.semantic-schema';\nimport ts, { Node, PropertyDeclaration as PropertyDeclarationNode } from 'typescript';\nimport { SchemaTransformer } from '../schema-transformer';\nimport { SchemaExtractorContext } from '../schema-extractor-context';\nimport { ExportIdentifier } from '../export-identifier';\nimport { parseTypeFromQuickInfo } from './utils/parse-type-from-quick-info';\n\nexport class PropertyDeclaration implements SchemaTransformer {\n predicate(node: Node) {\n return node.kind === ts.SyntaxKind.PropertyDeclaration;\n }\n\n getName(node: PropertyDeclarationNode) {\n return node.name.getText();\n }\n\n async getIdentifiers(node: PropertyDeclarationNode) {\n return [new ExportIdentifier(node.name.getText(), node.getSourceFile().fileName)];\n }\n\n async transform(propertyDec: PropertyDeclarationNode, context: SchemaExtractorContext): Promise<SchemaNode> {\n const name = this.getName(propertyDec);\n const info = await context.getQuickInfo(propertyDec.name);\n const displaySig = info?.body?.displayString;\n const typeStr = parseTypeFromQuickInfo(info);\n const type = await context.resolveType(propertyDec, typeStr);\n\n return new VariableSchema(context.getLocation(propertyDec), name, displaySig || '', type);\n }\n}\n"]}
|
|
@@ -77,7 +77,7 @@ class PropertySignature {
|
|
|
77
77
|
|
|
78
78
|
const typeStr = (0, _parseTypeFromQuickInfo().parseTypeFromQuickInfo)(info);
|
|
79
79
|
const type = await context.resolveType(prop, typeStr);
|
|
80
|
-
return new (_semanticsEntities().VariableSchema)(name, displaySig, type);
|
|
80
|
+
return new (_semanticsEntities().VariableSchema)(context.getLocation(prop), name, displaySig, type);
|
|
81
81
|
}
|
|
82
82
|
|
|
83
83
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["property-signature.ts"],"names":["PropertySignature","predicate","node","kind","ts","SyntaxKind","getName","name","getText","getIdentifiers","transform","prop","context","info","getQuickInfo","displaySig","body","displayString","type","FunctionType","propType","typeStr","resolveType","VariableSchema"],"mappings":";;;;;;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAGA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEO,MAAMA,iBAAN,CAAqD;AAC1DC,EAAAA,SAAS,CAACC,IAAD,EAAa;AACpB,WAAOA,IAAI,CAACC,IAAL,KAAcC,sBAAGC,UAAH,CAAcL,iBAAnC;AACD;;AAEDM,EAAAA,OAAO,CAACJ,IAAD,EAA8B;AACnC,WAAOA,IAAI,CAACK,IAAL,CAAUC,OAAV,EAAP;AACD;;AAEmB,QAAdC,cAAc,GAAG;AACrB,WAAO,EAAP;AACD;;AAEc,QAATC,SAAS,CAACC,IAAD,EAA8BC,OAA9B,EAAoF;AAAA;;AACjG,UAAML,IAAI,GAAG,KAAKD,OAAL,CAAaK,IAAb,CAAb;AACA,UAAME,IAAI,GAAG,MAAMD,OAAO,CAACE,YAAR,CAAqBH,IAAI,CAACJ,IAA1B,CAAnB;AACA,UAAMQ,UAAU,GAAG,CAAAF,IAAI,SAAJ,IAAAA,IAAI,WAAJ,0BAAAA,IAAI,CAAEG,IAAN,0DAAYC,aAAZ,KAA6B,EAAhD;;AACA,QAAI,eAAAN,IAAI,CAACO,IAAL,0DAAWf,IAAX,MAAoBC,sBAAGC,UAAH,CAAcc,YAAtC,EAAoD;AAClD;AACA,YAAMC,QAAQ,GAAGT,IAAI,CAACO,IAAtB;AACA,aAAO,0CAAiBE,QAAjB,EAA2BR,OAA3B,CAAP;AACD;;AACD,UAAMS,OAAO,GAAG,sDAAuBR,IAAvB,CAAhB;AACA,UAAMK,IAAI,GAAG,MAAMN,OAAO,CAACU,WAAR,CAAoBX,IAApB,EAA0BU,OAA1B,CAAnB;AACA,WAAO,KAAIE,mCAAJ,
|
|
1
|
+
{"version":3,"sources":["property-signature.ts"],"names":["PropertySignature","predicate","node","kind","ts","SyntaxKind","getName","name","getText","getIdentifiers","transform","prop","context","info","getQuickInfo","displaySig","body","displayString","type","FunctionType","propType","typeStr","resolveType","VariableSchema","getLocation"],"mappings":";;;;;;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAGA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEO,MAAMA,iBAAN,CAAqD;AAC1DC,EAAAA,SAAS,CAACC,IAAD,EAAa;AACpB,WAAOA,IAAI,CAACC,IAAL,KAAcC,sBAAGC,UAAH,CAAcL,iBAAnC;AACD;;AAEDM,EAAAA,OAAO,CAACJ,IAAD,EAA8B;AACnC,WAAOA,IAAI,CAACK,IAAL,CAAUC,OAAV,EAAP;AACD;;AAEmB,QAAdC,cAAc,GAAG;AACrB,WAAO,EAAP;AACD;;AAEc,QAATC,SAAS,CAACC,IAAD,EAA8BC,OAA9B,EAAoF;AAAA;;AACjG,UAAML,IAAI,GAAG,KAAKD,OAAL,CAAaK,IAAb,CAAb;AACA,UAAME,IAAI,GAAG,MAAMD,OAAO,CAACE,YAAR,CAAqBH,IAAI,CAACJ,IAA1B,CAAnB;AACA,UAAMQ,UAAU,GAAG,CAAAF,IAAI,SAAJ,IAAAA,IAAI,WAAJ,0BAAAA,IAAI,CAAEG,IAAN,0DAAYC,aAAZ,KAA6B,EAAhD;;AACA,QAAI,eAAAN,IAAI,CAACO,IAAL,0DAAWf,IAAX,MAAoBC,sBAAGC,UAAH,CAAcc,YAAtC,EAAoD;AAClD;AACA,YAAMC,QAAQ,GAAGT,IAAI,CAACO,IAAtB;AACA,aAAO,0CAAiBE,QAAjB,EAA2BR,OAA3B,CAAP;AACD;;AACD,UAAMS,OAAO,GAAG,sDAAuBR,IAAvB,CAAhB;AACA,UAAMK,IAAI,GAAG,MAAMN,OAAO,CAACU,WAAR,CAAoBX,IAApB,EAA0BU,OAA1B,CAAnB;AACA,WAAO,KAAIE,mCAAJ,EAAmBX,OAAO,CAACY,WAAR,CAAoBb,IAApB,CAAnB,EAA8CJ,IAA9C,EAAoDQ,UAApD,EAAgEG,IAAhE,CAAP;AACD;;AAzByD","sourcesContent":["import { SchemaNode, VariableSchema } from '@teambit/semantics.entities.semantic-schema';\nimport ts, { FunctionTypeNode, Node, PropertySignature as PropertySignatureNode } from 'typescript';\nimport { SchemaTransformer } from '../schema-transformer';\nimport { SchemaExtractorContext } from '../schema-extractor-context';\nimport { parseTypeFromQuickInfo } from './utils/parse-type-from-quick-info';\nimport { typeNodeToSchema } from './utils/type-node-to-schema';\n\nexport class PropertySignature implements SchemaTransformer {\n predicate(node: Node) {\n return node.kind === ts.SyntaxKind.PropertySignature;\n }\n\n getName(node: PropertySignatureNode) {\n return node.name.getText();\n }\n\n async getIdentifiers() {\n return [];\n }\n\n async transform(prop: PropertySignatureNode, context: SchemaExtractorContext): Promise<SchemaNode> {\n const name = this.getName(prop);\n const info = await context.getQuickInfo(prop.name);\n const displaySig = info?.body?.displayString || '';\n if (prop.type?.kind === ts.SyntaxKind.FunctionType) {\n // e.g. `propertySig: () => void;` inside interface\n const propType = prop.type as FunctionTypeNode;\n return typeNodeToSchema(propType, context);\n }\n const typeStr = parseTypeFromQuickInfo(info);\n const type = await context.resolveType(prop, typeStr);\n return new VariableSchema(context.getLocation(prop), name, displaySig, type);\n }\n}\n"]}
|
|
@@ -74,7 +74,7 @@ class SourceFileTransformer {
|
|
|
74
74
|
const schemas = await (0, _pMapSeries().default)(exports, exportNode => {
|
|
75
75
|
return context.computeSchema(exportNode);
|
|
76
76
|
});
|
|
77
|
-
return new (_semanticsEntities().Module)(schemas);
|
|
77
|
+
return new (_semanticsEntities().Module)(context.getLocation(node), schemas);
|
|
78
78
|
}
|
|
79
79
|
/**
|
|
80
80
|
* list all exports of a source file.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["source-file-transformer.ts"],"names":["SourceFileTransformer","predicate","node","kind","ts","SyntaxKind","SourceFile","getIdentifiers","sourceFile","context","exports","listExports","exportNames","Promise","all","map","getExportedIdentifiers","exportIds","reduce","acc","current","item","find","exportName","id","push","transform","schemas","exportNode","computeSchema","Module","ast","statements","statement","ExportDeclaration","isExport","Boolean","modifiers","modifier","ExportKeyword"],"mappings":";;;;;;;;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAKO,MAAMA,qBAAN,CAAyD;AAC9DC,EAAAA,SAAS,CAACC,IAAD,EAAa;AACpB,WAAOA,IAAI,CAACC,IAAL,KAAcC,sBAAGC,UAAH,CAAcC,UAAnC;AACD;;AAEmB,QAAdC,cAAc,CAACC,UAAD,EAAyBC,OAAzB,EAA0D;AAC5E,UAAMC,OAAO,GAAG,KAAKC,WAAL,CAAiBH,UAAjB,CAAhB;AAEA,UAAMI,WAAW,GAAG,MAAMC,OAAO,CAACC,GAAR,CACxBJ,OAAO,CAACK,GAAR,CAAab,IAAD,IAAgB;AAC1B,aAAOO,OAAO,CAACO,sBAAR,CAA+Bd,IAA/B,CAAP;AACD,KAFD,CADwB,CAA1B;AAMA,UAAMe,SAAS,GAAG,uBAAQL,WAAR,EAAqBM,MAArB,CAAgD,CAACC,GAAD,EAAMC,OAAN,KAAkB;AAClF,YAAMC,IAAI,GAAGF,GAAG,CAACG,IAAJ,CAAUC,UAAD,IAAgBA,UAAU,CAACC,EAAX,KAAkBJ,OAAO,CAACI,EAAnD,CAAb;AACA,UAAI,CAACH,IAAL,EAAWF,GAAG,CAACM,IAAJ,CAASL,OAAT;AACX,aAAOD,GAAP;AACD,KAJiB,EAIf,EAJe,CAAlB;AAMA,WAAOF,SAAP;AACD;;AAEc,QAATS,SAAS,CAACxB,IAAD,EAAmBO,OAAnB,EAAoD;AACjE,UAAMC,OAAO,GAAG,KAAKC,WAAL,CAAiBT,IAAjB,CAAhB;AACA,UAAMyB,OAAO,GAAG,MAAM,2BAAWjB,OAAX,EAAqBkB,UAAD,IAAgB;AACxD,aAAOnB,OAAO,CAACoB,aAAR,CAAsBD,UAAtB,CAAP;AACD,KAFqB,CAAtB;AAIA,WAAO,KAAIE,2BAAJ,
|
|
1
|
+
{"version":3,"sources":["source-file-transformer.ts"],"names":["SourceFileTransformer","predicate","node","kind","ts","SyntaxKind","SourceFile","getIdentifiers","sourceFile","context","exports","listExports","exportNames","Promise","all","map","getExportedIdentifiers","exportIds","reduce","acc","current","item","find","exportName","id","push","transform","schemas","exportNode","computeSchema","Module","getLocation","ast","statements","statement","ExportDeclaration","isExport","Boolean","modifiers","modifier","ExportKeyword"],"mappings":";;;;;;;;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAKO,MAAMA,qBAAN,CAAyD;AAC9DC,EAAAA,SAAS,CAACC,IAAD,EAAa;AACpB,WAAOA,IAAI,CAACC,IAAL,KAAcC,sBAAGC,UAAH,CAAcC,UAAnC;AACD;;AAEmB,QAAdC,cAAc,CAACC,UAAD,EAAyBC,OAAzB,EAA0D;AAC5E,UAAMC,OAAO,GAAG,KAAKC,WAAL,CAAiBH,UAAjB,CAAhB;AAEA,UAAMI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Q,CAACpC,IAAT,KAAkBC,sBAAGC,UAAH,CAAcmC,aAAvC;AACD,OAFD,CADsB,CAAxB,CAFgC,CAQhC;;AACA,UAAI,CAACJ,QAAL,EAAe;AACf,aAAOF,SAAP;AACD,KAXD,CADK,CAAP;AAcD;;AAlD6D","sourcesContent":["import ts, { Node, SourceFile } from 'typescript';\nimport { compact, flatten } from 'lodash';\nimport pMapSeries from 'p-map-series';\nimport { Module } 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 Module(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"]}
|
|
@@ -68,7 +68,7 @@ class TypeAliasTransformer {
|
|
|
68
68
|
const type = await (0, _typeNodeToSchema().typeNodeToSchema)(typeAlias.type, context);
|
|
69
69
|
const info = await context.getQuickInfo(typeAlias.name);
|
|
70
70
|
const displaySig = info === null || info === void 0 ? void 0 : (_info$body = info.body) === null || _info$body === void 0 ? void 0 : _info$body.displayString;
|
|
71
|
-
return new (_semanticsEntities().TypeSchema)(this.getName(typeAlias), type, displaySig);
|
|
71
|
+
return new (_semanticsEntities().TypeSchema)(context.getLocation(typeAlias), this.getName(typeAlias), type, displaySig || '');
|
|
72
72
|
}
|
|
73
73
|
|
|
74
74
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["type-alias.ts"],"names":["TypeAliasTransformer","predicate","node","kind","ts","SyntaxKind","TypeAliasDeclaration","getIdentifiers","ExportIdentifier","name","getText","getSourceFile","fileName","getName","transform","typeAlias","context","type","info","getQuickInfo","displaySig","body","displayString","TypeSchema"],"mappings":";;;;;;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAGA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEO,MAAMA,oBAAN,CAAwD;AAC7DC,EAAAA,SAAS,CAACC,IAAD,EAAa;AACpB,WAAOA,IAAI,CAACC,IAAL,KAAcC,sBAAGC,UAAH,CAAcC,oBAAnC;AACD;;AAEmB,QAAdC,cAAc,CAACL,IAAD,EAA6B;AAC/C,WAAO,CAAC,KAAIM,oCAAJ,EAAqBN,IAAI,CAACO,IAAL,CAAUC,OAAV,EAArB,EAA0CR,IAAI,CAACS,aAAL,GAAqBC,QAA/D,CAAD,CAAP;AACD;;AAEOC,EAAAA,OAAO,CAACX,IAAD,EAAqC;AAClD,WAAOA,IAAI,CAACO,IAAL,CAAUC,OAAV,EAAP;AACD;;AAEc,QAATI,SAAS,CAACC,SAAD,EAAkCC,OAAlC,EAAmE;AAAA;;AAChF,UAAMC,IAAI,GAAG,MAAM,0CAAiBF,SAAS,CAACE,IAA3B,EAAiCD,OAAjC,CAAnB;AACA,UAAME,IAAI,GAAG,MAAMF,OAAO,CAACG,YAAR,CAAqBJ,SAAS,CAACN,IAA/B,CAAnB;AACA,UAAMW,UAAU,GAAGF,IAAH,aAAGA,IAAH,qCAAGA,IAAI,CAAEG,IAAT,+CAAG,WAAYC,aAA/B;AACA,WAAO,KAAIC,+BAAJ,
|
|
1
|
+
{"version":3,"sources":["type-alias.ts"],"names":["TypeAliasTransformer","predicate","node","kind","ts","SyntaxKind","TypeAliasDeclaration","getIdentifiers","ExportIdentifier","name","getText","getSourceFile","fileName","getName","transform","typeAlias","context","type","info","getQuickInfo","displaySig","body","displayString","TypeSchema","getLocation"],"mappings":";;;;;;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAGA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEO,MAAMA,oBAAN,CAAwD;AAC7DC,EAAAA,SAAS,CAACC,IAAD,EAAa;AACpB,WAAOA,IAAI,CAACC,IAAL,KAAcC,sBAAGC,UAAH,CAAcC,oBAAnC;AACD;;AAEmB,QAAdC,cAAc,CAACL,IAAD,EAA6B;AAC/C,WAAO,CAAC,KAAIM,oCAAJ,EAAqBN,IAAI,CAACO,IAAL,CAAUC,OAAV,EAArB,EAA0CR,IAAI,CAACS,aAAL,GAAqBC,QAA/D,CAAD,CAAP;AACD;;AAEOC,EAAAA,OAAO,CAACX,IAAD,EAAqC;AAClD,WAAOA,IAAI,CAACO,IAAL,CAAUC,OAAV,EAAP;AACD;;AAEc,QAATI,SAAS,CAACC,SAAD,EAAkCC,OAAlC,EAAmE;AAAA;;AAChF,UAAMC,IAAI,GAAG,MAAM,0CAAiBF,SAAS,CAACE,IAA3B,EAAiCD,OAAjC,CAAnB;AACA,UAAME,IAAI,GAAG,MAAMF,OAAO,CAACG,YAAR,CAAqBJ,SAAS,CAACN,IAA/B,CAAnB;AACA,UAAMW,UAAU,GAAGF,IAAH,aAAGA,IAAH,qCAAGA,IAAI,CAAEG,IAAT,+CAAG,WAAYC,aAA/B;AACA,WAAO,KAAIC,+BAAJ,EAAeP,OAAO,CAACQ,WAAR,CAAoBT,SAApB,CAAf,EAA+C,KAAKF,OAAL,CAAaE,SAAb,CAA/C,EAAwEE,IAAxE,EAA8EG,UAAU,IAAI,EAA5F,CAAP;AACD;;AAlB4D","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 info = await context.getQuickInfo(typeAlias.name);\n const displaySig = info?.body?.displayString;\n return new TypeSchema(context.getLocation(typeAlias), this.getName(typeAlias), type, displaySig || '');\n }\n}\n"]}
|
|
@@ -51,9 +51,13 @@ function _typeNodeToSchema() {
|
|
|
51
51
|
|
|
52
52
|
async function getParams(parameterNodes, context) {
|
|
53
53
|
return (0, _pMapSeries().default)(parameterNodes, async param => {
|
|
54
|
-
return new (_semanticsEntities().ParameterSchema)(param.name.getText(), await getParamType(param, context), param.initializer ? param.initializer.getText() : undefined);
|
|
54
|
+
return new (_semanticsEntities().ParameterSchema)(context.getLocation(param), param.name.getText(), await getParamType(param, context), param.initializer ? param.initializer.getText() : undefined);
|
|
55
55
|
});
|
|
56
56
|
}
|
|
57
|
+
/**
|
|
58
|
+
* @todo: probably not needed. just call context.resolveType instead.
|
|
59
|
+
*/
|
|
60
|
+
|
|
57
61
|
|
|
58
62
|
async function getParamType(param, context) {
|
|
59
63
|
if (param.type) {
|
|
@@ -63,7 +67,7 @@ async function getParamType(param, context) {
|
|
|
63
67
|
|
|
64
68
|
const info = await context.getQuickInfo(param.name);
|
|
65
69
|
const parsed = (0, _parseTypeFromQuickInfo().parseTypeFromQuickInfo)(info);
|
|
66
|
-
return new (_semanticsEntities().TypeRefSchema)(parsed || 'any');
|
|
70
|
+
return new (_semanticsEntities().TypeRefSchema)(context.getLocation(param), parsed || 'any');
|
|
67
71
|
}
|
|
68
72
|
|
|
69
73
|
//# sourceMappingURL=get-params.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["get-params.ts"],"names":["getParams","parameterNodes","context","param","ParameterSchema","name","getText","getParamType","initializer","undefined","type","info","getQuickInfo","parsed","TypeRefSchema"],"mappings":";;;;;;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAGA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEO,eAAeA,SAAf,CACLC,cADK,EAELC,OAFK,EAGuB;AAC5B,SAAO,2BAAWD,cAAX,EAA2B,MAAOE,KAAP,IAAiB;AACjD,WAAO,KAAIC,oCAAJ,
|
|
1
|
+
{"version":3,"sources":["get-params.ts"],"names":["getParams","parameterNodes","context","param","ParameterSchema","getLocation","name","getText","getParamType","initializer","undefined","type","info","getQuickInfo","parsed","TypeRefSchema"],"mappings":";;;;;;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAGA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEO,eAAeA,SAAf,CACLC,cADK,EAELC,OAFK,EAGuB;AAC5B,SAAO,2BAAWD,cAAX,EAA2B,MAAOE,KAAP,IAAiB;AACjD,WAAO,KAAIC,oCAAJ,EACLF,OAAO,CAACG,WAAR,CAAoBF,KAApB,CADK,EAELA,KAAK,CAACG,IAAN,CAAWC,OAAX,EAFK,EAGL,MAAMC,YAAY,CAACL,KAAD,EAAQD,OAAR,CAHb,EAILC,KAAK,CAACM,WAAN,GAAoBN,KAAK,CAACM,WAAN,CAAkBF,OAAlB,EAApB,GAAkDG,SAJ7C,CAAP;AAMD,GAPM,CAAP;AAQD;AAED;AACA;AACA;;;AACA,eAAeF,YAAf,CAA4BL,KAA5B,EAAyDD,OAAzD,EAA+G;AAC7G,MAAIC,KAAK,CAACQ,IAAV,EAAgB;AACd,UAAMA,IAAI,GAAGR,KAAK,CAACQ,IAAnB;AACA,WAAO,0CAAiBA,IAAjB,EAAuBT,OAAvB,CAAP;AACD;;AACD,QAAMU,IAAI,GAAG,MAAMV,OAAO,CAACW,YAAR,CAAqBV,KAAK,CAACG,IAA3B,CAAnB;AACA,QAAMQ,MAAM,GAAG,sDAAuBF,IAAvB,CAAf;AACA,SAAO,KAAIG,kCAAJ,EAAkBb,OAAO,CAACG,WAAR,CAAoBF,KAApB,CAAlB,EAA8CW,MAAM,IAAI,KAAxD,CAAP;AACD","sourcesContent":["import { ParameterSchema, SchemaNode, TypeRefSchema } from '@teambit/semantics.entities.semantic-schema';\nimport pMapSeries from 'p-map-series';\nimport { ParameterDeclaration, NodeArray } from 'typescript';\nimport { SchemaExtractorContext } from '../../schema-extractor-context';\nimport { parseTypeFromQuickInfo } from './parse-type-from-quick-info';\nimport { typeNodeToSchema } from './type-node-to-schema';\n\nexport async function getParams(\n parameterNodes: NodeArray<ParameterDeclaration>,\n context: SchemaExtractorContext\n): Promise<ParameterSchema[]> {\n return pMapSeries(parameterNodes, async (param) => {\n return new ParameterSchema(\n context.getLocation(param),\n param.name.getText(),\n await getParamType(param, context),\n param.initializer ? param.initializer.getText() : undefined\n );\n });\n}\n\n/**\n * @todo: probably not needed. just call context.resolveType instead.\n */\nasync function getParamType(param: ParameterDeclaration, context: SchemaExtractorContext): Promise<SchemaNode> {\n if (param.type) {\n const type = param.type;\n return typeNodeToSchema(type, context);\n }\n const info = await context.getQuickInfo(param.name);\n const parsed = parseTypeFromQuickInfo(info);\n return new TypeRefSchema(context.getLocation(param), parsed || 'any');\n}\n"]}
|
|
@@ -44,12 +44,12 @@ async function toFunctionLikeSchema(node, context) {
|
|
|
44
44
|
|
|
45
45
|
const info = await context.getQuickInfo(node.name);
|
|
46
46
|
const returnTypeStr = (0, _parseTypeFromQuickInfo().parseTypeFromQuickInfo)(info);
|
|
47
|
-
const displaySig = info === null || info === void 0 ? void 0 : (_info$body = info.body) === null || _info$body === void 0 ? void 0 : _info$body.displayString;
|
|
47
|
+
const displaySig = (info === null || info === void 0 ? void 0 : (_info$body = info.body) === null || _info$body === void 0 ? void 0 : _info$body.displayString) || '';
|
|
48
48
|
const args = await (0, _getParams().getParams)(node.parameters, context);
|
|
49
49
|
const returnType = await context.resolveType(node, returnTypeStr);
|
|
50
50
|
const modifiers = ((_node$modifiers = node.modifiers) === null || _node$modifiers === void 0 ? void 0 : _node$modifiers.map(modifier => modifier.getText())) || [];
|
|
51
51
|
const location = context.getLocation(node);
|
|
52
|
-
return new (_semanticsEntities().FunctionLikeSchema)(name, args, returnType, displaySig
|
|
52
|
+
return new (_semanticsEntities().FunctionLikeSchema)(location, name, args, returnType, displaySig, modifiers);
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
//# sourceMappingURL=to-function-schema.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["to-function-schema.ts"],"names":["toFunctionLikeSchema","node","context","name","getText","info","getQuickInfo","returnTypeStr","displaySig","body","displayString","args","parameters","returnType","resolveType","modifiers","map","modifier","location","getLocation","FunctionLikeSchema"],"mappings":";;;;;;;;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEO,eAAeA,oBAAf,CAAoCC,IAApC,EAAgEC,OAAhE,EAAiG;AAAA;;AACtG,QAAMC,IAAI,GAAG,eAAAF,IAAI,CAACE,IAAL,0DAAWC,OAAX,OAAwB,EAArC,CADsG,CAEtG;;AACA,QAAMC,IAAI,GAAG,MAAMH,OAAO,CAACI,YAAR,CAAqBL,IAAI,CAACE,IAA1B,CAAnB;AACA,QAAMI,aAAa,GAAG,sDAAuBF,IAAvB,CAAtB;AACA,QAAMG,UAAU,
|
|
1
|
+
{"version":3,"sources":["to-function-schema.ts"],"names":["toFunctionLikeSchema","node","context","name","getText","info","getQuickInfo","returnTypeStr","displaySig","body","displayString","args","parameters","returnType","resolveType","modifiers","map","modifier","location","getLocation","FunctionLikeSchema"],"mappings":";;;;;;;;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEO,eAAeA,oBAAf,CAAoCC,IAApC,EAAgEC,OAAhE,EAAiG;AAAA;;AACtG,QAAMC,IAAI,GAAG,eAAAF,IAAI,CAACE,IAAL,0DAAWC,OAAX,OAAwB,EAArC,CADsG,CAEtG;;AACA,QAAMC,IAAI,GAAG,MAAMH,OAAO,CAACI,YAAR,CAAqBL,IAAI,CAACE,IAA1B,CAAnB;AACA,QAAMI,aAAa,GAAG,sDAAuBF,IAAvB,CAAtB;AACA,QAAMG,UAAU,GAAG,CAAAH,IAAI,SAAJ,IAAAA,IAAI,WAAJ,0BAAAA,IAAI,CAAEI,IAAN,0DAAYC,aAAZ,KAA6B,EAAhD;AACA,QAAMC,IAAI,GAAG,MAAM,4BAAUV,IAAI,CAACW,UAAf,EAA2BV,OAA3B,CAAnB;AACA,QAAMW,UAAU,GAAG,MAAMX,OAAO,CAACY,WAAR,CAAoBb,IAApB,EAA0BM,aAA1B,CAAzB;AACA,QAAMQ,SAAS,GAAG,oBAAAd,IAAI,CAACc,SAAL,oEAAgBC,GAAhB,CAAqBC,QAAD,IAAcA,QAAQ,CAACb,OAAT,EAAlC,MAAyD,EAA3E;AACA,QAAMc,QAAQ,GAAGhB,OAAO,CAACiB,WAAR,CAAoBlB,IAApB,CAAjB;AAEA,SAAO,KAAImB,uCAAJ,EAAuBF,QAAvB,EAAiCf,IAAjC,EAAuCQ,IAAvC,EAA6CE,UAA7C,EAAyDL,UAAzD,EAAqEO,SAArE,CAAP;AACD","sourcesContent":["import { SignatureDeclaration } 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(node: SignatureDeclaration, context: SchemaExtractorContext) {\n const name = node.name?.getText() || '';\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const info = await context.getQuickInfo(node.name!);\n const returnTypeStr = parseTypeFromQuickInfo(info);\n const displaySig = info?.body?.displayString || '';\n const args = await getParams(node.parameters, context);\n const returnType = await context.resolveType(node, returnTypeStr);\n const modifiers = node.modifiers?.map((modifier) => modifier.getText()) || [];\n const location = context.getLocation(node);\n\n return new FunctionLikeSchema(location, name, args, returnType, displaySig, modifiers as Modifier[]);\n}\n"]}
|