@teambit/typescript 0.0.750 → 0.0.753
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/exceptions/transformer-not-found.js +1 -1
- package/dist/exceptions/transformer-not-found.js.map +1 -1
- package/dist/schema-extractor-context.js +1 -1
- package/dist/schema-extractor-context.js.map +1 -1
- package/dist/transformers/binding-element.d.ts +17 -0
- package/dist/transformers/binding-element.js +83 -0
- package/dist/transformers/binding-element.js.map +1 -0
- package/dist/transformers/export-declaration.d.ts +1 -1
- package/dist/transformers/export-declaration.js +25 -25
- package/dist/transformers/export-declaration.js.map +1 -1
- package/dist/transformers/function-declaration.js +4 -4
- package/dist/transformers/function-declaration.js.map +1 -1
- package/dist/transformers/index.d.ts +1 -1
- package/dist/transformers/index.js +15 -15
- package/dist/transformers/index.js.map +1 -1
- package/dist/transformers/utils/class-element-to-schema.js +6 -5
- package/dist/transformers/utils/class-element-to-schema.js.map +1 -1
- package/dist/transformers/utils/get-params.js +1 -1
- package/dist/transformers/utils/get-params.js.map +1 -1
- package/dist/transformers/utils/{to-function-schema.d.ts → to-function-like-schema.d.ts} +0 -0
- package/dist/transformers/utils/{to-function-schema.js → to-function-like-schema.js} +4 -3
- package/dist/transformers/utils/to-function-like-schema.js.map +1 -0
- package/dist/transformers/utils/type-element-to-schema.js +12 -7
- package/dist/transformers/utils/type-element-to-schema.js.map +1 -1
- package/dist/transformers/variable-declaration.js +1 -1
- package/dist/transformers/variable-declaration.js.map +1 -1
- package/dist/typescript.extractor.d.ts +2 -2
- package/dist/typescript.extractor.js +7 -1
- package/dist/typescript.extractor.js.map +1 -1
- package/dist/typescript.main.runtime.js +1 -1
- package/dist/typescript.main.runtime.js.map +1 -1
- package/exceptions/transformer-not-found.ts +1 -1
- package/package-tar/teambit-typescript-0.0.753.tgz +0 -0
- package/package.json +16 -16
- package/{preview-1654226751250.js → preview-1654572446572.js} +2 -2
- package/transformers/binding-element.ts +32 -0
- package/transformers/export-declaration.ts +21 -19
- package/transformers/function-declaration.ts +1 -1
- package/transformers/index.ts +1 -1
- package/transformers/utils/class-element-to-schema.ts +3 -2
- package/transformers/utils/get-params.ts +1 -0
- package/transformers/utils/{to-function-schema.ts → to-function-like-schema.ts} +11 -1
- package/transformers/utils/type-element-to-schema.ts +9 -3
- package/transformers/variable-declaration.ts +1 -1
- package/dist/transformers/literal-type.d.ts +0 -9
- package/dist/transformers/literal-type.js +0 -50
- package/dist/transformers/literal-type.js.map +0 -1
- package/dist/transformers/utils/to-function-schema.js.map +0 -1
- package/package-tar/teambit-typescript-0.0.750.tgz +0 -0
- package/transformers/literal-type.ts +0 -19
|
@@ -48,7 +48,7 @@ function _jsdocToDocSchema() {
|
|
|
48
48
|
}
|
|
49
49
|
|
|
50
50
|
async function toFunctionLikeSchema(node, context, funcName) {
|
|
51
|
-
var _node$name, _info$body, _node$modifiers;
|
|
51
|
+
var _node$name, _info$body, _node$modifiers, _node$typeParameters;
|
|
52
52
|
|
|
53
53
|
const name = funcName || ((_node$name = node.name) === null || _node$name === void 0 ? void 0 : _node$name.getText()) || '';
|
|
54
54
|
const info = node.name ? await context.getQuickInfo(node.name) : null;
|
|
@@ -57,9 +57,10 @@ async function toFunctionLikeSchema(node, context, funcName) {
|
|
|
57
57
|
const args = await (0, _getParams().getParams)(node.parameters, context);
|
|
58
58
|
const returnType = await context.resolveType(node, returnTypeStr, Boolean(info));
|
|
59
59
|
const modifiers = ((_node$modifiers = node.modifiers) === null || _node$modifiers === void 0 ? void 0 : _node$modifiers.map(modifier => modifier.getText())) || [];
|
|
60
|
+
const typeParameters = (_node$typeParameters = node.typeParameters) === null || _node$typeParameters === void 0 ? void 0 : _node$typeParameters.map(typeParam => typeParam.name.getText());
|
|
60
61
|
const location = context.getLocation(node);
|
|
61
62
|
const doc = await (0, _jsdocToDocSchema().jsDocToDocSchema)(node, context);
|
|
62
|
-
return new (_semanticsEntities().FunctionLikeSchema)(location, name, args, returnType, displaySig, modifiers, doc);
|
|
63
|
+
return new (_semanticsEntities().FunctionLikeSchema)(location, name, args, returnType, displaySig, modifiers, doc, typeParameters);
|
|
63
64
|
}
|
|
64
65
|
|
|
65
|
-
//# sourceMappingURL=to-function-schema.js.map
|
|
66
|
+
//# sourceMappingURL=to-function-like-schema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["toFunctionLikeSchema","node","context","funcName","name","getText","info","getQuickInfo","returnTypeStr","parseTypeFromQuickInfo","displaySig","body","displayString","args","getParams","parameters","returnType","resolveType","Boolean","modifiers","map","modifier","typeParameters","typeParam","location","getLocation","doc","jsDocToDocSchema","FunctionLikeSchema"],"sources":["to-function-like-schema.ts"],"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';\nimport { jsDocToDocSchema } from './jsdoc-to-doc-schema';\n\nexport async function toFunctionLikeSchema(\n node: SignatureDeclaration,\n context: SchemaExtractorContext,\n funcName?: string\n) {\n const name = funcName || node.name?.getText() || '';\n const info = node.name ? await context.getQuickInfo(node.name) : null;\n const returnTypeStr = info ? parseTypeFromQuickInfo(info) : 'any';\n const displaySig = info?.body?.displayString || '';\n const args = await getParams(node.parameters, context);\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 jsDocToDocSchema(node, context);\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":";;;;;;;;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAEA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAC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AAvB,CAAlB;EACA,OAAO,KAAI0B,uCAAJ,EACLJ,QADK,EAELpB,IAFK,EAGLS,IAHK,EAILG,UAJK,EAKLN,UALK,EAMLS,SANK,EAOLO,GAPK,EAQLJ,cARK,CAAP;AAUD"}
|
|
@@ -30,10 +30,10 @@ function _semanticsEntities() {
|
|
|
30
30
|
return data;
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
function
|
|
34
|
-
const data = require("./to-function-schema");
|
|
33
|
+
function _toFunctionLikeSchema() {
|
|
34
|
+
const data = require("./to-function-like-schema");
|
|
35
35
|
|
|
36
|
-
|
|
36
|
+
_toFunctionLikeSchema = function () {
|
|
37
37
|
return data;
|
|
38
38
|
};
|
|
39
39
|
|
|
@@ -73,13 +73,13 @@ function _getParams() {
|
|
|
73
73
|
async function typeElementToSchema(node, context) {
|
|
74
74
|
switch (node.kind) {
|
|
75
75
|
case _typescript().SyntaxKind.MethodSignature:
|
|
76
|
-
return (0,
|
|
76
|
+
return (0, _toFunctionLikeSchema().toFunctionLikeSchema)(node, context);
|
|
77
77
|
|
|
78
78
|
case _typescript().SyntaxKind.ConstructSignature:
|
|
79
|
-
return (0,
|
|
79
|
+
return (0, _toFunctionLikeSchema().toFunctionLikeSchema)(node, context, 'new');
|
|
80
80
|
|
|
81
81
|
case _typescript().SyntaxKind.CallSignature:
|
|
82
|
-
|
|
82
|
+
return callSignature(node, context);
|
|
83
83
|
|
|
84
84
|
case _typescript().SyntaxKind.PropertySignature:
|
|
85
85
|
return propertySignature(node, context);
|
|
@@ -106,7 +106,8 @@ async function propertySignature(node, context) {
|
|
|
106
106
|
const displaySig = (info === null || info === void 0 ? void 0 : (_info$body = info.body) === null || _info$body === void 0 ? void 0 : _info$body.displayString) || '';
|
|
107
107
|
const typeStr = (0, _parseTypeFromQuickInfo().parseTypeFromQuickInfo)(info);
|
|
108
108
|
const type = await context.resolveType(node, typeStr);
|
|
109
|
-
|
|
109
|
+
const isOptional = Boolean(node.questionToken);
|
|
110
|
+
return new (_semanticsEntities().VariableSchema)(context.getLocation(node), name, displaySig, type, isOptional);
|
|
110
111
|
}
|
|
111
112
|
|
|
112
113
|
async function indexSignature(node, context) {
|
|
@@ -131,4 +132,8 @@ async function setAccessor(node, context) {
|
|
|
131
132
|
return new (_semanticsEntities().SetAccessorSchema)(context.getLocation(node), node.name.getText(), params[0], displaySig);
|
|
132
133
|
}
|
|
133
134
|
|
|
135
|
+
async function callSignature(node, context) {
|
|
136
|
+
return (0, _toFunctionLikeSchema().toFunctionLikeSchema)(node, context);
|
|
137
|
+
}
|
|
138
|
+
|
|
134
139
|
//# sourceMappingURL=type-element-to-schema.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["typeElementToSchema","node","context","kind","SyntaxKind","MethodSignature","toFunctionLikeSchema","ConstructSignature","CallSignature","
|
|
1
|
+
{"version":3,"names":["typeElementToSchema","node","context","kind","SyntaxKind","MethodSignature","toFunctionLikeSchema","ConstructSignature","CallSignature","callSignature","PropertySignature","propertySignature","IndexSignature","indexSignature","GetAccessor","getAccessor","SetAccessor","setAccessor","Error","name","getText","info","isComputedPropertyName","undefined","getQuickInfo","displaySig","body","displayString","typeStr","parseTypeFromQuickInfo","type","resolveType","isOptional","Boolean","questionToken","VariableSchema","getLocation","params","getParams","parameters","typeNodeToSchema","IndexSignatureSchema","GetAccessorSchema","getQuickInfoDisplayString","SetAccessorSchema"],"sources":["type-element-to-schema.ts"],"sourcesContent":["import ts, {\n SyntaxKind,\n TypeElement,\n MethodSignature,\n isComputedPropertyName,\n IndexSignatureDeclaration,\n GetAccessorDeclaration,\n SetAccessorDeclaration,\n ConstructSignatureDeclaration,\n CallSignatureDeclaration,\n} from 'typescript';\nimport {\n GetAccessorSchema,\n IndexSignatureSchema,\n SchemaNode,\n SetAccessorSchema,\n VariableSchema,\n} from '@teambit/semantics.entities.semantic-schema';\nimport { toFunctionLikeSchema } from './to-function-like-schema';\nimport { SchemaExtractorContext } from '../../schema-extractor-context';\nimport { parseTypeFromQuickInfo } from './parse-type-from-quick-info';\nimport { typeNodeToSchema } from './type-node-to-schema';\nimport { getParams } from './get-params';\n\nexport async function typeElementToSchema(node: TypeElement, context: SchemaExtractorContext): Promise<SchemaNode> {\n switch (node.kind) {\n case SyntaxKind.MethodSignature:\n return toFunctionLikeSchema(node as MethodSignature, context);\n case SyntaxKind.ConstructSignature:\n return toFunctionLikeSchema(node as ConstructSignatureDeclaration, context, 'new');\n case SyntaxKind.CallSignature:\n return callSignature(node as CallSignatureDeclaration, context);\n case SyntaxKind.PropertySignature:\n return propertySignature(node as ts.PropertySignature, context);\n case SyntaxKind.IndexSignature:\n return indexSignature(node as IndexSignatureDeclaration, context);\n case SyntaxKind.GetAccessor:\n return getAccessor(node as GetAccessorDeclaration, context);\n case SyntaxKind.SetAccessor:\n return setAccessor(node as SetAccessorDeclaration, context);\n default:\n throw new Error(`typeElementToSchema expect type-element node. got ${node.kind}`);\n }\n}\n\nasync function propertySignature(node: ts.PropertySignature, context: SchemaExtractorContext) {\n const name = node.name.getText();\n const info = isComputedPropertyName(node.name) ? undefined : 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 return new VariableSchema(context.getLocation(node), name, displaySig, type, isOptional);\n}\n\nexport async function indexSignature(node: IndexSignatureDeclaration, context: SchemaExtractorContext) {\n const params = await getParams(node.parameters, context);\n const type = await typeNodeToSchema(node.type, context);\n return new IndexSignatureSchema(context.getLocation(node), params, type);\n}\n\nexport async function getAccessor(node: GetAccessorDeclaration, context: SchemaExtractorContext) {\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 return new GetAccessorSchema(context.getLocation(node), node.name.getText(), type, displaySig);\n}\n\nexport async function setAccessor(node: SetAccessorDeclaration, context: SchemaExtractorContext) {\n const params = await getParams(node.parameters, context);\n const displaySig = await context.getQuickInfoDisplayString(node.name);\n return new SetAccessorSchema(context.getLocation(node), node.name.getText(), params[0], displaySig);\n}\n\nasync function callSignature(node: CallSignatureDeclaration, context: SchemaExtractorContext) {\n return toFunctionLikeSchema(node, context);\n}\n"],"mappings":";;;;;;;;;;;;AAAA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAWA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAOA;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;;AAEO,eAAeA,mBAAf,CAAmCC,IAAnC,EAAsDC,OAAtD,EAA4G;EACjH,QAAQD,IAAI,CAACE,IAAb;IACE,KAAKC,wBAAA,CAAWC,eAAhB;MACE,OAAO,IAAAC,4CAAA,EAAqBL,IAArB,EAA8CC,OAA9C,CAAP;;IACF,KAAKE,wBAAA,CAAWG,kBAAhB;MACE,OAAO,IAAAD,4CAAA,EAAqBL,IAArB,EAA4DC,OAA5D,EAAqE,KAArE,CAAP;;IACF,KAAKE,wBAAA,CAAWI,aAAhB;MACE,OAAOC,aAAa,CAACR,IAAD,EAAmCC,OAAnC,CAApB;;IACF,KAAKE,wBAAA,CAAWM,iBAAhB;MACE,OAAOC,iBAAiB,CAACV,IAAD,EAA+BC,OAA/B,CAAxB;;IACF,KAAKE,wBAAA,CAAWQ,cAAhB;MACE,OAAOC,cAAc,CAACZ,IAAD,EAAoCC,OAApC,CAArB;;IACF,KAAKE,wBAAA,CAAWU,WAAhB;MACE,OAAOC,WAAW,CAACd,IAAD,EAAiCC,OAAjC,CAAlB;;IACF,KAAKE,wBAAA,CAAWY,WAAhB;MACE,OAAOC,WAAW,CAAChB,IAAD,EAAiCC,OAAjC,CAAlB;;IACF;MACE,MAAM,I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
103
|
|
|
104
104
|
const typeStr = (0, _parseTypeFromQuickInfo().parseTypeFromQuickInfo)(info);
|
|
105
105
|
const type = await context.resolveType(varDec, typeStr);
|
|
106
|
-
return new (_semanticsEntities().VariableSchema)(location, name, displaySig, type);
|
|
106
|
+
return new (_semanticsEntities().VariableSchema)(location, name, displaySig, type, false);
|
|
107
107
|
}
|
|
108
108
|
|
|
109
109
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["VariableDeclaration","predicate","node","kind","ts","SyntaxKind","getName","name","getText","getIdentifiers","ExportIdentifier","getSourceFile","fileName","transform","varDec","context","info","getQuickInfo","displaySig","body","displayString","location","getLocation","initializer","ArrowFunction","args","getParams","parameters","typeStr","parseReturnTypeFromQuickInfo","returnType","resolveType","modifiers","map","modifier","doc","jsDocToDocSchema","FunctionLikeSchema","parseTypeFromQuickInfo","type","VariableSchema"],"sources":["variable-declaration.ts"],"sourcesContent":["import { SchemaNode, VariableSchema, FunctionLikeSchema, Modifier } from '@teambit/semantics.entities.semantic-schema';\nimport ts, { Node, VariableDeclaration as VariableDeclarationNode, ArrowFunction } from 'typescript';\nimport { SchemaTransformer } from '../schema-transformer';\nimport { SchemaExtractorContext } from '../schema-extractor-context';\nimport { ExportIdentifier } from '../export-identifier';\nimport { getParams } from './utils/get-params';\nimport { parseReturnTypeFromQuickInfo, parseTypeFromQuickInfo } from './utils/parse-type-from-quick-info';\nimport { jsDocToDocSchema } from './utils/jsdoc-to-doc-schema';\n\nexport class VariableDeclaration implements SchemaTransformer {\n predicate(node: Node) {\n return node.kind === ts.SyntaxKind.VariableDeclaration;\n }\n\n getName(node: VariableDeclarationNode) {\n return node.name.getText();\n }\n\n async getIdentifiers(node: VariableDeclarationNode) {\n return [new ExportIdentifier(node.name.getText(), node.getSourceFile().fileName)];\n }\n\n async transform(varDec: VariableDeclarationNode, context: SchemaExtractorContext): Promise<SchemaNode> {\n const name = this.getName(varDec);\n const info = await context.getQuickInfo(varDec.name);\n const displaySig = info?.body?.displayString || '';\n const location = context.getLocation(varDec);\n if (varDec.initializer?.kind === ts.SyntaxKind.ArrowFunction) {\n const args = await getParams((varDec.initializer as ArrowFunction).parameters, context);\n const typeStr = parseReturnTypeFromQuickInfo(info);\n const returnType = await context.resolveType(varDec, typeStr);\n const modifiers = varDec.modifiers?.map((modifier) => modifier.getText()) || [];\n const doc = await jsDocToDocSchema(varDec, context);\n return new FunctionLikeSchema(location, name, args, returnType, displaySig, modifiers as Modifier[], doc);\n }\n const typeStr = parseTypeFromQuickInfo(info);\n const type = await context.resolveType(varDec, typeStr);\n return new VariableSchema(location, name, displaySig, type);\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;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAEO,MAAMA,mBAAN,CAAuD;EAC5DC,SAAS,CAACC,IAAD,EAAa;IACpB,OAAOA,IAAI,CAACC,IAAL,KAAcC,qBAAA,CAAGC,UAAH,CAAcL,mBAAnC;EACD;;EAEDM,OAAO,CAACJ,IAAD,EAAgC;IACrC,OAAOA,IAAI,CAACK,IAAL,CAAUC,OAAV,EAAP;EACD;;EAEmB,MAAdC,cAAc,CAACP,IAAD,EAAgC;IAClD,OAAO,CAAC,KAAIQ,oCAAJ,EAAqBR,IAAI,CAACK,IAAL,CAAUC,OAAV,EAArB,EAA0CN,IAAI,CAACS,aAAL,GAAqBC,QAA/D,CAAD,CAAP;EACD;;EAEc,MAATC,SAAS,CAACC,MAAD,EAAkCC,OAAlC,EAAwF;IAAA;;IACrG,MAAMR,IAAI,GAAG,KAAKD,OAAL,CAAaQ,MAAb,CAAb;IACA,MAAME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mCW,UAAnC,EAA+CqB,IAA/C,CAAP;EACD;;AA7B2D"}
|
|
1
|
+
{"version":3,"names":["VariableDeclaration","predicate","node","kind","ts","SyntaxKind","getName","name","getText","getIdentifiers","ExportIdentifier","getSourceFile","fileName","transform","varDec","context","info","getQuickInfo","displaySig","body","displayString","location","getLocation","initializer","ArrowFunction","args","getParams","parameters","typeStr","parseReturnTypeFromQuickInfo","returnType","resolveType","modifiers","map","modifier","doc","jsDocToDocSchema","FunctionLikeSchema","parseTypeFromQuickInfo","type","VariableSchema"],"sources":["variable-declaration.ts"],"sourcesContent":["import { SchemaNode, VariableSchema, FunctionLikeSchema, Modifier } from '@teambit/semantics.entities.semantic-schema';\nimport ts, { Node, VariableDeclaration as VariableDeclarationNode, ArrowFunction } from 'typescript';\nimport { SchemaTransformer } from '../schema-transformer';\nimport { SchemaExtractorContext } from '../schema-extractor-context';\nimport { ExportIdentifier } from '../export-identifier';\nimport { getParams } from './utils/get-params';\nimport { parseReturnTypeFromQuickInfo, parseTypeFromQuickInfo } from './utils/parse-type-from-quick-info';\nimport { jsDocToDocSchema } from './utils/jsdoc-to-doc-schema';\n\nexport class VariableDeclaration implements SchemaTransformer {\n predicate(node: Node) {\n return node.kind === ts.SyntaxKind.VariableDeclaration;\n }\n\n getName(node: VariableDeclarationNode) {\n return node.name.getText();\n }\n\n async getIdentifiers(node: VariableDeclarationNode) {\n return [new ExportIdentifier(node.name.getText(), node.getSourceFile().fileName)];\n }\n\n async transform(varDec: VariableDeclarationNode, context: SchemaExtractorContext): Promise<SchemaNode> {\n const name = this.getName(varDec);\n const info = await context.getQuickInfo(varDec.name);\n const displaySig = info?.body?.displayString || '';\n const location = context.getLocation(varDec);\n if (varDec.initializer?.kind === ts.SyntaxKind.ArrowFunction) {\n const args = await getParams((varDec.initializer as ArrowFunction).parameters, context);\n const typeStr = parseReturnTypeFromQuickInfo(info);\n const returnType = await context.resolveType(varDec, typeStr);\n const modifiers = varDec.modifiers?.map((modifier) => modifier.getText()) || [];\n const doc = await jsDocToDocSchema(varDec, context);\n return new FunctionLikeSchema(location, name, args, returnType, displaySig, modifiers as Modifier[], doc);\n }\n const typeStr = parseTypeFromQuickInfo(info);\n const type = await context.resolveType(varDec, typeStr);\n return new VariableSchema(location, name, displaySig, type, false);\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;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAEO,MAAMA,mBAAN,CAAuD;EAC5DC,SAAS,CAACC,IAAD,EAAa;IACpB,OAAOA,IAAI,CAACC,IAAL,KAAcC,qBAAA,CAAGC,UAAH,CAAcL,mBAAnC;EACD;;EAEDM,OAAO,CAACJ,IAAD,EAAgC;IACrC,OAAOA,IAAI,CAACK,IAAL,CAAUC,OAAV,EAAP;EACD;;EAEmB,MAAdC,cAAc,CAACP,IAAD,EAAgC;IAClD,OAAO,CAAC,KAAIQ,oCAAJ,EAAqBR,IAAI,CAACK,IAAL,CAAUC,OAAV,EAArB,EAA0CN,IAAI,CAACS,aAAL,GAAqBC,QAA/D,CAAD,CAAP;EACD;;EAEc,MAATC,SAAS,CAACC,MAAD,EAAkCC,OAAlC,EAAwF;IAAA;;IACrG,MAAMR,IAAI,GAAG,KAAKD,OAAL,CAAaQ,MAAb,CAAb;IACA,MAAME,IAAI,GAAG,MAAMD,OAAO,CAACE,YAAR,CAAqBH,MAAM,CAACP,IAA5B,CAAnB;IACA,MAAMW,UAAU,GAAG,CAAAF,IAAI,SAAJ,IAAAA,IAAI,WAAJ,0BAAAA,IAAI,CAAEG,IAAN,0DAAYC,aAAZ,KAA6B,EAAhD;IACA,MAAMC,QAAQ,GAAGN,OAAO,CAACO,WAAR,CAAoBR,MAApB,CAAjB;;IACA,IAAI,wBAAAA,MAAM,CAACS,WAAP,4EAAoBpB,IAApB,MAA6BC,qBAAA,CAAGC,UAAH,CAAcmB,aAA/C,EAA8D;MAAA;;MAC5D,MAAMC,IAAI,GAAG,MAAM,IAAAC,sBAAA,EAAWZ,MAAM,CAACS,WAAR,CAAsCI,UAAhD,EAA4DZ,OAA5D,CAAnB;MACA,MAAMa,OAAO,GAAG,IAAAC,sDAAA,EAA6Bb,IAA7B,CAAhB;MACA,MAAMc,UAAU,GAAG,MAAMf,OAAO,CAACgB,WAAR,CAAoBjB,MAApB,EAA4Bc,OAA5B,CAAzB;MACA,MAAMI,SAAS,GAAG,sBAAAlB,MAAM,CAACkB,SAAP,wEAAkBC,GAAlB,CAAuBC,QAAD,IAAcA,QAAQ,CAAC1B,OAAT,EAApC,MAA2D,EAA7E;MACA,MAAM2B,GAAG,GAAG,MAAM,IAAAC,oCAAA,EAAiBtB,MAAjB,EAAyBC,OAAzB,CAAlB;MACA,OAAO,KAAIsB,uCAAJ,EAAuBhB,QAAvB,EAAiCd,IAAjC,EAAuCkB,IAAvC,EAA6CK,UAA7C,EAAyDZ,UAAzD,EAAqEc,SAArE,EAA8FG,GAA9F,CAAP;IACD;;IACD,MAAMP,OAAO,GAAG,IAAAU,gDAAA,EAAuBtB,IAAvB,CAAhB;IACA,MAAMuB,IAAI,GAAG,MAAMxB,OAAO,CAACgB,WAAR,CAAoBjB,MAApB,EAA4Bc,OAA5B,CAAnB;IACA,OAAO,KAAIY,mCAAJ,EAAmBnB,QAAnB,EAA6Bd,IAA7B,EAAmCW,UAAnC,EAA+CqB,IAA/C,EAAqD,KAArD,CAAP;EACD;;AA7B2D"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Node, SourceFile } from 'typescript';
|
|
2
2
|
import { SchemaExtractor } from '@teambit/schema';
|
|
3
3
|
import type { Workspace } from '@teambit/workspace';
|
|
4
4
|
import { DependencyResolverMain } from '@teambit/dependency-resolver';
|
|
@@ -15,7 +15,7 @@ export declare class TypeScriptExtractor implements SchemaExtractor {
|
|
|
15
15
|
private depResolver;
|
|
16
16
|
private workspace;
|
|
17
17
|
constructor(tsconfig: any, schemaTransformerSlot: SchemaTransformerSlot, tsMain: TypescriptMain, rootPath: string, depResolver: DependencyResolverMain, workspace: Workspace | undefined);
|
|
18
|
-
parseSourceFile(file: AbstractVinyl):
|
|
18
|
+
parseSourceFile(file: AbstractVinyl): SourceFile;
|
|
19
19
|
/**
|
|
20
20
|
* extract a component schema.
|
|
21
21
|
*/
|
|
@@ -93,7 +93,13 @@ class TypeScriptExtractor {
|
|
|
93
93
|
}
|
|
94
94
|
|
|
95
95
|
parseSourceFile(file) {
|
|
96
|
-
|
|
96
|
+
const sourceFile = _typescript().default.createSourceFile(file.path, file.contents.toString('utf8'), _typescript().default.ScriptTarget.Latest, true
|
|
97
|
+
/** don't pass the scriptKind, it'll be determined automatically by typescript by the filepath */
|
|
98
|
+
); // leave this commented out, it's helpful when there are issues with ASTs. consider throwing in this case.
|
|
99
|
+
// console.log("sourceFile Errors", file.path, sourceFile.parseDiagnostics);
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
return sourceFile;
|
|
97
103
|
}
|
|
98
104
|
/**
|
|
99
105
|
* extract a component schema.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["TypeScriptExtractor","constructor","tsconfig","schemaTransformerSlot","tsMain","rootPath","depResolver","workspace","undefined","parseSourceFile","file","ts","createSourceFile","path","contents","toString","ScriptTarget","Latest","
|
|
1
|
+
{"version":3,"names":["TypeScriptExtractor","constructor","tsconfig","schemaTransformerSlot","tsMain","rootPath","depResolver","workspace","undefined","parseSourceFile","file","sourceFile","ts","createSourceFile","path","contents","toString","ScriptTarget","Latest","extract","component","tsserver","getTsServer","mainFile","mainAst","context","createContext","exportNames","computeExportedIdentifiers","setExports","ExportList","moduleSchema","computeSchema","flatExportsRecursively","apiScheme","location","getLocation","APISchema","id","node","transformer","getTransformer","getIdentifiers","TransformerNotFound","componentDeps","getComponentDeps","SchemaExtractorContext","deps","getDependencies","getComponentDependencies","getTsserverClient","initTsserverClient","transform","getComponentIDByPath","getComponentIdByPath","transformers","flatten","values","find","singleTransformer","predicate"],"sources":["typescript.extractor.ts"],"sourcesContent":["import ts, { Node, SourceFile } from 'typescript';\nimport { SchemaExtractor } from '@teambit/schema';\nimport { TsserverClient } from '@teambit/ts-server';\nimport type { Workspace } from '@teambit/workspace';\nimport { ComponentDependency, DependencyResolverMain } from '@teambit/dependency-resolver';\nimport { SchemaNode, APISchema, Module } from '@teambit/semantics.entities.semantic-schema';\nimport { Component } from '@teambit/component';\nimport { AbstractVinyl } from '@teambit/legacy/dist/consumer/component/sources';\nimport { flatten } from 'lodash';\nimport { TypescriptMain, SchemaTransformerSlot } from './typescript.main.runtime';\nimport { TransformerNotFound } from './exceptions';\nimport { SchemaExtractorContext } from './schema-extractor-context';\nimport { ExportList } from './export-list';\n\nexport class TypeScriptExtractor implements SchemaExtractor {\n constructor(\n private tsconfig: any,\n private schemaTransformerSlot: SchemaTransformerSlot,\n private tsMain: TypescriptMain,\n private rootPath: string,\n private depResolver: DependencyResolverMain,\n private workspace: Workspace | undefined\n ) {}\n\n parseSourceFile(file: AbstractVinyl): SourceFile {\n const sourceFile = ts.createSourceFile(\n file.path,\n file.contents.toString('utf8'),\n ts.ScriptTarget.Latest,\n true\n /** don't pass the scriptKind, it'll be determined automatically by typescript by the filepath */\n );\n // leave this commented out, it's helpful when there are issues with ASTs. consider throwing in this case.\n // console.log(\"sourceFile Errors\", file.path, sourceFile.parseDiagnostics);\n return sourceFile;\n }\n\n /**\n * extract a component schema.\n */\n async extract(component: Component): Promise<APISchema> {\n const tsserver = await this.getTsServer();\n const mainFile = component.mainFile;\n const mainAst = this.parseSourceFile(mainFile);\n const context = await this.createContext(tsserver, component);\n const exportNames = await this.computeExportedIdentifiers(mainAst, context);\n context.setExports(new ExportList(exportNames));\n const moduleSchema = (await this.computeSchema(mainAst, context)) as Module;\n moduleSchema.flatExportsRecursively();\n const apiScheme = moduleSchema;\n const location = context.getLocation(mainAst);\n\n return new APISchema(location, apiScheme, component.id);\n }\n\n async computeExportedIdentifiers(node: Node, context: SchemaExtractorContext) {\n const transformer = this.getTransformer(node, context);\n if (!transformer || !transformer.getIdentifiers) {\n throw new TransformerNotFound(node, context.component, context.getLocation(node));\n }\n return transformer.getIdentifiers(node, context);\n }\n\n private async createContext(tsserver: TsserverClient, component: Component): Promise<SchemaExtractorContext> {\n const componentDeps = await this.getComponentDeps(component);\n return new SchemaExtractorContext(tsserver, component, this, componentDeps);\n }\n\n private async getComponentDeps(component: Component): Promise<ComponentDependency[]> {\n const deps = await this.depResolver.getDependencies(component);\n const componentDeps = deps.getComponentDependencies();\n return componentDeps;\n }\n\n private tsserver: TsserverClient | undefined = undefined;\n\n private async getTsServer() {\n if (!this.tsserver) {\n const tsserver = this.tsMain.getTsserverClient();\n if (tsserver) {\n this.tsserver = tsserver;\n return tsserver;\n }\n\n this.tsserver = await this.tsMain.initTsserverClient(this.rootPath);\n return this.tsserver;\n }\n\n return this.tsserver;\n }\n\n async computeSchema(node: Node, context: SchemaExtractorContext): Promise<SchemaNode> {\n const transformer = this.getTransformer(node, context);\n // leave the next line commented out, it is used for debugging\n // console.log('transformer', transformer.constructor.name, node.getText());\n return transformer.transform(node, context);\n }\n\n async getComponentIDByPath(file: string) {\n if (!this.workspace) {\n return null;\n }\n return this.workspace.getComponentIdByPath(file);\n }\n\n /**\n * select the correct transformer for a node.\n */\n private getTransformer(node: Node, context: SchemaExtractorContext) {\n const transformers = flatten(this.schemaTransformerSlot.values());\n const transformer = transformers.find((singleTransformer) => singleTransformer.predicate(node));\n\n if (!transformer) throw new TransformerNotFound(node, context.component, context.getLocation(node));\n\n return transformer;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA;EAAA;;EAAA;IAAA;EAAA;;E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 -391,7 +391,7 @@ class TypescriptMain {
|
|
|
391
391
|
const logger = loggerExt.createLogger(_typescript3().TypescriptAspect.id);
|
|
392
392
|
aspectLoader.registerPlugins([new (_schemaTransformer().SchemaTransformerPlugin)(schemaTransformerSlot)]);
|
|
393
393
|
const tsMain = new TypescriptMain(logger, schemaTransformerSlot, workspace, depResolver);
|
|
394
|
-
schemaTransformerSlot.register([new (_transformers().ExportDeclaration)(), new (_transformers().FunctionDeclaration)(), new (_transformers().VariableStatementTransformer)(), new (_transformers().VariableDeclaration)(), new (_transformers().SourceFileTransformer)(), new (_transformers().TypeAliasTransformer)(), new (_transformers().ClassDecelerationTransformer)(), new (_transformers().
|
|
394
|
+
schemaTransformerSlot.register([new (_transformers().ExportDeclaration)(), new (_transformers().FunctionDeclaration)(), new (_transformers().VariableStatementTransformer)(), new (_transformers().VariableDeclaration)(), new (_transformers().SourceFileTransformer)(), new (_transformers().TypeAliasTransformer)(), new (_transformers().ClassDecelerationTransformer)(), new (_transformers().InterfaceDeclarationTransformer)(), new (_transformers().EnumDeclarationTransformer)(), new (_transformers().BindingElementTransformer)()]);
|
|
395
395
|
|
|
396
396
|
if (workspace) {
|
|
397
397
|
workspace.registerOnPreWatch(tsMain.onPreWatch.bind(this));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["TypescriptMain","constructor","logger","schemaTransformerSlot","workspace","depResolver","createCompiler","options","transformers","tsModule","ts","configMutator","TypescriptConfigMutator","transformerContext","afterMutation","runTransformersWithContext","clone","TypescriptCompiler","TypescriptAspect","id","raw","getTsserverClient","tsServer","initTsserverClient","projectPath","files","TsserverClient","init","initTsserverClientFromWorkspace","Error","path","createCjsCompiler","getCjsTransformer","createEsmCompiler","getEsmTransformer","cjsTransformer","config","setModule","esmTransformer","createSchemaExtractor","tsconfig","TypeScriptExtractor","getCjsPackageJsonProps","main","types","getEsmPackageJsonProps","type","getSupportedFilesForTsserver","components","map","c","filesystem","flat","f","filter","endsWith","onPreWatch","watchOpts","spawnTSServer","verbose","checkTypes","printTypeErrors","Boolean","onComponentChange","component","results","pMapSeries","file","onFileChange","provider","schema","loggerExt","aspectLoader","cli","registerParser","TypeScriptParser","createLogger","registerPlugins","SchemaTransformerPlugin","tsMain","register","ExportDeclaration","FunctionDeclaration","VariableStatementTransformer","VariableDeclaration","SourceFileTransformer","TypeAliasTransformer","ClassDecelerationTransformer","LiteralTypeTransformer","InterfaceDeclarationTransformer","EnumDeclarationTransformer","registerOnPreWatch","bind","registerOnComponentChange","registerOnComponentAdd","checkTypesCmd","CheckTypesCmd","MainRuntime","SchemaAspect","LoggerAspect","AspectLoaderAspect","WorkspaceAspect","CLIAspect","DependencyResolverAspect","Slot","withType","addRuntime","context","Array","isArray","newConfig","reduce","acc","transformer"],"sources":["typescript.main.runtime.ts"],"sourcesContent":["import ts from 'typescript';\nimport { Slot, SlotRegistry } from '@teambit/harmony';\nimport { CLIAspect, CLIMain, MainRuntime } from '@teambit/cli';\nimport { Compiler } from '@teambit/compiler';\nimport { Logger, LoggerAspect, LoggerMain } from '@teambit/logger';\nimport { SchemaAspect, SchemaExtractor, SchemaMain } from '@teambit/schema';\nimport { PackageJsonProps } from '@teambit/pkg';\nimport { TypescriptConfigMutator } from '@teambit/typescript.modules.ts-config-mutator';\nimport { WorkspaceAspect } from '@teambit/workspace';\nimport type { WatchOptions, Workspace } from '@teambit/workspace';\nimport { DependencyResolverAspect, DependencyResolverMain } from '@teambit/dependency-resolver';\nimport pMapSeries from 'p-map-series';\nimport { TsserverClient, TsserverClientOpts } from '@teambit/ts-server';\nimport AspectLoaderAspect, { AspectLoaderMain } from '@teambit/aspect-loader';\nimport type { Component } from '@teambit/component';\nimport { TypeScriptExtractor } from './typescript.extractor';\nimport { TypeScriptCompilerOptions } from './compiler-options';\nimport { TypescriptAspect } from './typescript.aspect';\nimport { TypescriptCompiler } from './typescript.compiler';\nimport { TypeScriptParser } from './typescript.parser';\nimport { SchemaTransformer } from './schema-transformer';\nimport { SchemaTransformerPlugin } from './schema-transformer.plugin';\nimport {\n ExportDeclaration,\n TypeAliasTransformer,\n FunctionDeclaration,\n VariableStatementTransformer,\n VariableDeclaration,\n SourceFileTransformer,\n ClassDecelerationTransformer,\n LiteralTypeTransformer,\n InterfaceDeclarationTransformer,\n EnumDeclarationTransformer,\n} from './transformers';\nimport { CheckTypesCmd } from './cmds/check-types.cmd';\n\nexport type TsMode = 'build' | 'dev';\n\nexport type SchemaTransformerSlot = SlotRegistry<SchemaTransformer[]>;\n\nexport type TsConfigTransformContext = {\n // mode: TsMode;\n};\n\nexport type TsConfigTransformer = (\n config: TypescriptConfigMutator,\n context: TsConfigTransformContext\n) => TypescriptConfigMutator;\n\nexport class TypescriptMain {\n constructor(\n private logger: Logger,\n private schemaTransformerSlot: SchemaTransformerSlot,\n private workspace: Workspace,\n private depResolver: DependencyResolverMain\n ) {}\n\n private tsServer: TsserverClient;\n /**\n * create a new compiler.\n */\n createCompiler(\n options: TypeScriptCompilerOptions,\n transformers: TsConfigTransformer[] = [],\n tsModule = ts\n ): Compiler {\n const configMutator = new TypescriptConfigMutator(options);\n const transformerContext: TsConfigTransformContext = {};\n const afterMutation = runTransformersWithContext(configMutator.clone(), transformers, transformerContext);\n return new TypescriptCompiler(TypescriptAspect.id, this.logger, afterMutation.raw, tsModule);\n }\n\n /**\n * get TsserverClient instance if initiated already, otherwise, return undefined.\n */\n getTsserverClient(): TsserverClient | undefined {\n return this.tsServer;\n }\n\n /**\n * starts a tsserver process to communicate with its API.\n * @param projectPath absolute path of the project root directory\n * @param options TsserverClientOpts\n * @param files optionally, if check-types is enabled, provide files to open and type check.\n * @returns TsserverClient\n */\n async initTsserverClient(\n projectPath: string,\n options: TsserverClientOpts = {},\n files: string[] = []\n ): Promise<TsserverClient> {\n this.tsServer = new TsserverClient(projectPath, this.logger, options, files);\n this.tsServer.init();\n return this.tsServer;\n }\n\n /**\n * starts a tsserver process to communicate with its API. use only when running on the workspace.\n * @param options TsserverClientOpts\n * @param files optionally, if check-types is enabled, provide files to open and type check.\n * @returns TsserverClient\n */\n async initTsserverClientFromWorkspace(\n options: TsserverClientOpts = {},\n files: string[] = []\n ): Promise<TsserverClient> {\n if (!this.workspace) {\n throw new Error(`initTsserverClientFromWorkspace: workspace was not found`);\n }\n return this.initTsserverClient(this.workspace.path, options, files);\n }\n\n /**\n * Create a compiler instance and run the cjs transformer for it\n * @param options\n * @param transformers\n * @param tsModule\n * @returns\n */\n createCjsCompiler(options: TypeScriptCompilerOptions, transformers: TsConfigTransformer[] = [], tsModule = ts) {\n return this.createCompiler(options, [this.getCjsTransformer(), ...transformers], tsModule);\n }\n\n /**\n * Create a compiler instance and run the esm transformer for it\n * @param options\n * @param transformers\n * @param tsModule\n * @returns\n */\n createEsmCompiler(options: TypeScriptCompilerOptions, transformers: TsConfigTransformer[] = [], tsModule = ts) {\n return this.createCompiler(options, [this.getEsmTransformer(), ...transformers], tsModule);\n }\n\n /**\n * Create a transformer that change the ts module to CommonJS\n * @returns\n */\n getCjsTransformer(): TsConfigTransformer {\n const cjsTransformer = (config: TypescriptConfigMutator) => {\n config.setModule('CommonJS');\n return config;\n };\n return cjsTransformer;\n }\n\n /**\n * Create a transformer that change the ts module to ES2020\n * @returns\n */\n getEsmTransformer(): TsConfigTransformer {\n const esmTransformer = (config: TypescriptConfigMutator) => {\n config.setModule('ES2020');\n return config;\n };\n return esmTransformer;\n }\n\n /**\n * create an instance of a typescript semantic schema extractor.\n */\n createSchemaExtractor(tsconfig: any, path?: string): SchemaExtractor {\n return new TypeScriptExtractor(\n tsconfig,\n this.schemaTransformerSlot,\n this,\n path || this.workspace.path,\n this.depResolver,\n this.workspace\n );\n }\n\n /**\n * add the default package json properties to the component\n * :TODO @gilad why do we need this DSL? can't I just get the args here.\n */\n getCjsPackageJsonProps(): PackageJsonProps {\n return {\n main: 'dist/{main}.js',\n types: '{main}.ts',\n };\n }\n\n /**\n * add type: module to the package.json props and the default props\n * :TODO @gilad why do we need this DSL? can't I just get the args here.\n */\n getEsmPackageJsonProps(): PackageJsonProps {\n return {\n // main: 'dist-esm/{main}.js',\n main: 'dist/{main}.js',\n type: 'module',\n types: '{main}.ts',\n };\n }\n\n public getSupportedFilesForTsserver(components: Component[]): string[] {\n const files = components\n .map((c) => c.filesystem.files)\n .flat()\n .map((f) => f.path);\n return files.filter((f) => f.endsWith('.ts') || f.endsWith('.tsx'));\n }\n\n private async onPreWatch(components: Component[], watchOpts: WatchOptions) {\n const workspace = this.workspace;\n if (!workspace || !watchOpts.spawnTSServer) {\n return;\n }\n const { verbose, checkTypes } = watchOpts;\n const files = checkTypes ? this.getSupportedFilesForTsserver(components) : [];\n const printTypeErrors = Boolean(checkTypes);\n await this.initTsserverClientFromWorkspace({ verbose, checkTypes, printTypeErrors }, files);\n }\n\n private async onComponentChange(component: Component, files: string[]) {\n if (!this.tsServer) {\n return {\n results: 'N/A',\n };\n }\n await pMapSeries(files, (file) => this.tsServer.onFileChange(file));\n return {\n results: 'succeed',\n };\n }\n\n static runtime = MainRuntime;\n static dependencies = [\n SchemaAspect,\n LoggerAspect,\n AspectLoaderAspect,\n WorkspaceAspect,\n CLIAspect,\n DependencyResolverAspect,\n ];\n static slots = [Slot.withType<SchemaTransformer[]>()];\n\n static async provider(\n [schema, loggerExt, aspectLoader, workspace, cli, depResolver]: [\n SchemaMain,\n LoggerMain,\n AspectLoaderMain,\n Workspace,\n CLIMain,\n DependencyResolverMain\n ],\n config,\n [schemaTransformerSlot]: [SchemaTransformerSlot]\n ) {\n schema.registerParser(new TypeScriptParser());\n const logger = loggerExt.createLogger(TypescriptAspect.id);\n aspectLoader.registerPlugins([new SchemaTransformerPlugin(schemaTransformerSlot)]);\n const tsMain = new TypescriptMain(logger, schemaTransformerSlot, workspace, depResolver);\n schemaTransformerSlot.register([\n new ExportDeclaration(),\n new FunctionDeclaration(),\n new VariableStatementTransformer(),\n new VariableDeclaration(),\n new SourceFileTransformer(),\n new TypeAliasTransformer(),\n new ClassDecelerationTransformer(),\n new LiteralTypeTransformer(),\n new InterfaceDeclarationTransformer(),\n new EnumDeclarationTransformer(),\n ]);\n\n if (workspace) {\n workspace.registerOnPreWatch(tsMain.onPreWatch.bind(this));\n workspace.registerOnComponentChange(tsMain.onComponentChange.bind(this));\n workspace.registerOnComponentAdd(tsMain.onComponentChange.bind(this));\n }\n\n const checkTypesCmd = new CheckTypesCmd(tsMain, workspace, logger);\n cli.register(checkTypesCmd);\n\n return tsMain;\n }\n}\n\nTypescriptAspect.addRuntime(TypescriptMain);\n\nexport function runTransformersWithContext(\n config: TypescriptConfigMutator,\n transformers: TsConfigTransformer[] = [],\n context: TsConfigTransformContext\n): TypescriptConfigMutator {\n if (!Array.isArray(transformers)) return config;\n const newConfig = transformers.reduce((acc, transformer) => {\n return transformer(acc, context);\n }, config);\n return newConfig;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;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;;AAEA;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;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAEA;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;;AAEA;EAAA;;EAAA;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AAV,CAA6BZ,MAAM,CAACvB,UAAP,CAAkBoC,IAAlB,CAAuB,IAAvB,CAA7B;MACAxF,SAAS,CAACyF,yBAAV,CAAoCd,MAAM,CAAChB,iBAAP,CAAyB6B,IAAzB,CAA8B,IAA9B,CAApC;MACAxF,SAAS,CAAC0F,sBAAV,CAAiCf,MAAM,CAAChB,iBAAP,CAAyB6B,IAAzB,CAA8B,IAA9B,CAAjC;IACD;;IAED,MAAMG,aAAa,GAAG,KAAIC,2BAAJ,EAAkBjB,MAAlB,EAA0B3E,SAA1B,EAAqCF,MAArC,CAAtB;IACAuE,GAAG,CAACO,QAAJ,CAAae,aAAb;IAEA,OAAOhB,MAAP;EACD;;AApOyB;;;gCAAf/E,c,aAkLMiG,kB;gCAlLNjG,c,kBAmLW,CACpBkG,sBADoB,EAEpBC,sBAFoB,EAGpBC,uBAHoB,EAIpBC,4BAJoB,EAKpBC,gBALoB,EAMpBC,8CANoB,C;gCAnLXvG,c,WA2LI,CAACwG,eAAA,CAAKC,QAAL,EAAD,C;;AA4CjBvF,+BAAA,CAAiBwF,UAAjB,CAA4B1G,cAA5B;;AAEO,SAASe,0BAAT,CACLqB,MADK,EAEL5B,YAAmC,GAAG,EAFjC,EAGLmG,OAHK,EAIoB;EACzB,IAAI,CAACC,KAAK,CAACC,OAAN,CAAcrG,YAAd,CAAL,EAAkC,OAAO4B,MAAP;EAClC,MAAM0E,SAAS,GAAGtG,YAAY,CAACuG,MAAb,CAAoB,CAACC,GAAD,EAAMC,WAAN,KAAsB;IAC1D,OAAOA,WAAW,CAACD,GAAD,EAAML,OAAN,CAAlB;EACD,CAFiB,EAEfvE,MAFe,CAAlB;EAGA,OAAO0E,SAAP;AACD"}
|
|
1
|
+
{"version":3,"names":["TypescriptMain","constructor","logger","schemaTransformerSlot","workspace","depResolver","createCompiler","options","transformers","tsModule","ts","configMutator","TypescriptConfigMutator","transformerContext","afterMutation","runTransformersWithContext","clone","TypescriptCompiler","TypescriptAspect","id","raw","getTsserverClient","tsServer","initTsserverClient","projectPath","files","TsserverClient","init","initTsserverClientFromWorkspace","Error","path","createCjsCompiler","getCjsTransformer","createEsmCompiler","getEsmTransformer","cjsTransformer","config","setModule","esmTransformer","createSchemaExtractor","tsconfig","TypeScriptExtractor","getCjsPackageJsonProps","main","types","getEsmPackageJsonProps","type","getSupportedFilesForTsserver","components","map","c","filesystem","flat","f","filter","endsWith","onPreWatch","watchOpts","spawnTSServer","verbose","checkTypes","printTypeErrors","Boolean","onComponentChange","component","results","pMapSeries","file","onFileChange","provider","schema","loggerExt","aspectLoader","cli","registerParser","TypeScriptParser","createLogger","registerPlugins","SchemaTransformerPlugin","tsMain","register","ExportDeclaration","FunctionDeclaration","VariableStatementTransformer","VariableDeclaration","SourceFileTransformer","TypeAliasTransformer","ClassDecelerationTransformer","InterfaceDeclarationTransformer","EnumDeclarationTransformer","BindingElementTransformer","registerOnPreWatch","bind","registerOnComponentChange","registerOnComponentAdd","checkTypesCmd","CheckTypesCmd","MainRuntime","SchemaAspect","LoggerAspect","AspectLoaderAspect","WorkspaceAspect","CLIAspect","DependencyResolverAspect","Slot","withType","addRuntime","context","Array","isArray","newConfig","reduce","acc","transformer"],"sources":["typescript.main.runtime.ts"],"sourcesContent":["import ts from 'typescript';\nimport { Slot, SlotRegistry } from '@teambit/harmony';\nimport { CLIAspect, CLIMain, MainRuntime } from '@teambit/cli';\nimport { Compiler } from '@teambit/compiler';\nimport { Logger, LoggerAspect, LoggerMain } from '@teambit/logger';\nimport { SchemaAspect, SchemaExtractor, SchemaMain } from '@teambit/schema';\nimport { PackageJsonProps } from '@teambit/pkg';\nimport { TypescriptConfigMutator } from '@teambit/typescript.modules.ts-config-mutator';\nimport { WorkspaceAspect } from '@teambit/workspace';\nimport type { WatchOptions, Workspace } from '@teambit/workspace';\nimport { DependencyResolverAspect, DependencyResolverMain } from '@teambit/dependency-resolver';\nimport pMapSeries from 'p-map-series';\nimport { TsserverClient, TsserverClientOpts } from '@teambit/ts-server';\nimport AspectLoaderAspect, { AspectLoaderMain } from '@teambit/aspect-loader';\nimport type { Component } from '@teambit/component';\nimport { TypeScriptExtractor } from './typescript.extractor';\nimport { TypeScriptCompilerOptions } from './compiler-options';\nimport { TypescriptAspect } from './typescript.aspect';\nimport { TypescriptCompiler } from './typescript.compiler';\nimport { TypeScriptParser } from './typescript.parser';\nimport { SchemaTransformer } from './schema-transformer';\nimport { SchemaTransformerPlugin } from './schema-transformer.plugin';\nimport {\n ExportDeclaration,\n TypeAliasTransformer,\n FunctionDeclaration,\n VariableStatementTransformer,\n VariableDeclaration,\n SourceFileTransformer,\n ClassDecelerationTransformer,\n InterfaceDeclarationTransformer,\n EnumDeclarationTransformer,\n BindingElementTransformer,\n} from './transformers';\nimport { CheckTypesCmd } from './cmds/check-types.cmd';\n\nexport type TsMode = 'build' | 'dev';\n\nexport type SchemaTransformerSlot = SlotRegistry<SchemaTransformer[]>;\n\nexport type TsConfigTransformContext = {\n // mode: TsMode;\n};\n\nexport type TsConfigTransformer = (\n config: TypescriptConfigMutator,\n context: TsConfigTransformContext\n) => TypescriptConfigMutator;\n\nexport class TypescriptMain {\n constructor(\n private logger: Logger,\n private schemaTransformerSlot: SchemaTransformerSlot,\n private workspace: Workspace,\n private depResolver: DependencyResolverMain\n ) {}\n\n private tsServer: TsserverClient;\n /**\n * create a new compiler.\n */\n createCompiler(\n options: TypeScriptCompilerOptions,\n transformers: TsConfigTransformer[] = [],\n tsModule = ts\n ): Compiler {\n const configMutator = new TypescriptConfigMutator(options);\n const transformerContext: TsConfigTransformContext = {};\n const afterMutation = runTransformersWithContext(configMutator.clone(), transformers, transformerContext);\n return new TypescriptCompiler(TypescriptAspect.id, this.logger, afterMutation.raw, tsModule);\n }\n\n /**\n * get TsserverClient instance if initiated already, otherwise, return undefined.\n */\n getTsserverClient(): TsserverClient | undefined {\n return this.tsServer;\n }\n\n /**\n * starts a tsserver process to communicate with its API.\n * @param projectPath absolute path of the project root directory\n * @param options TsserverClientOpts\n * @param files optionally, if check-types is enabled, provide files to open and type check.\n * @returns TsserverClient\n */\n async initTsserverClient(\n projectPath: string,\n options: TsserverClientOpts = {},\n files: string[] = []\n ): Promise<TsserverClient> {\n this.tsServer = new TsserverClient(projectPath, this.logger, options, files);\n this.tsServer.init();\n return this.tsServer;\n }\n\n /**\n * starts a tsserver process to communicate with its API. use only when running on the workspace.\n * @param options TsserverClientOpts\n * @param files optionally, if check-types is enabled, provide files to open and type check.\n * @returns TsserverClient\n */\n async initTsserverClientFromWorkspace(\n options: TsserverClientOpts = {},\n files: string[] = []\n ): Promise<TsserverClient> {\n if (!this.workspace) {\n throw new Error(`initTsserverClientFromWorkspace: workspace was not found`);\n }\n return this.initTsserverClient(this.workspace.path, options, files);\n }\n\n /**\n * Create a compiler instance and run the cjs transformer for it\n * @param options\n * @param transformers\n * @param tsModule\n * @returns\n */\n createCjsCompiler(options: TypeScriptCompilerOptions, transformers: TsConfigTransformer[] = [], tsModule = ts) {\n return this.createCompiler(options, [this.getCjsTransformer(), ...transformers], tsModule);\n }\n\n /**\n * Create a compiler instance and run the esm transformer for it\n * @param options\n * @param transformers\n * @param tsModule\n * @returns\n */\n createEsmCompiler(options: TypeScriptCompilerOptions, transformers: TsConfigTransformer[] = [], tsModule = ts) {\n return this.createCompiler(options, [this.getEsmTransformer(), ...transformers], tsModule);\n }\n\n /**\n * Create a transformer that change the ts module to CommonJS\n * @returns\n */\n getCjsTransformer(): TsConfigTransformer {\n const cjsTransformer = (config: TypescriptConfigMutator) => {\n config.setModule('CommonJS');\n return config;\n };\n return cjsTransformer;\n }\n\n /**\n * Create a transformer that change the ts module to ES2020\n * @returns\n */\n getEsmTransformer(): TsConfigTransformer {\n const esmTransformer = (config: TypescriptConfigMutator) => {\n config.setModule('ES2020');\n return config;\n };\n return esmTransformer;\n }\n\n /**\n * create an instance of a typescript semantic schema extractor.\n */\n createSchemaExtractor(tsconfig: any, path?: string): SchemaExtractor {\n return new TypeScriptExtractor(\n tsconfig,\n this.schemaTransformerSlot,\n this,\n path || this.workspace.path,\n this.depResolver,\n this.workspace\n );\n }\n\n /**\n * add the default package json properties to the component\n * :TODO @gilad why do we need this DSL? can't I just get the args here.\n */\n getCjsPackageJsonProps(): PackageJsonProps {\n return {\n main: 'dist/{main}.js',\n types: '{main}.ts',\n };\n }\n\n /**\n * add type: module to the package.json props and the default props\n * :TODO @gilad why do we need this DSL? can't I just get the args here.\n */\n getEsmPackageJsonProps(): PackageJsonProps {\n return {\n // main: 'dist-esm/{main}.js',\n main: 'dist/{main}.js',\n type: 'module',\n types: '{main}.ts',\n };\n }\n\n public getSupportedFilesForTsserver(components: Component[]): string[] {\n const files = components\n .map((c) => c.filesystem.files)\n .flat()\n .map((f) => f.path);\n return files.filter((f) => f.endsWith('.ts') || f.endsWith('.tsx'));\n }\n\n private async onPreWatch(components: Component[], watchOpts: WatchOptions) {\n const workspace = this.workspace;\n if (!workspace || !watchOpts.spawnTSServer) {\n return;\n }\n const { verbose, checkTypes } = watchOpts;\n const files = checkTypes ? this.getSupportedFilesForTsserver(components) : [];\n const printTypeErrors = Boolean(checkTypes);\n await this.initTsserverClientFromWorkspace({ verbose, checkTypes, printTypeErrors }, files);\n }\n\n private async onComponentChange(component: Component, files: string[]) {\n if (!this.tsServer) {\n return {\n results: 'N/A',\n };\n }\n await pMapSeries(files, (file) => this.tsServer.onFileChange(file));\n return {\n results: 'succeed',\n };\n }\n\n static runtime = MainRuntime;\n static dependencies = [\n SchemaAspect,\n LoggerAspect,\n AspectLoaderAspect,\n WorkspaceAspect,\n CLIAspect,\n DependencyResolverAspect,\n ];\n static slots = [Slot.withType<SchemaTransformer[]>()];\n\n static async provider(\n [schema, loggerExt, aspectLoader, workspace, cli, depResolver]: [\n SchemaMain,\n LoggerMain,\n AspectLoaderMain,\n Workspace,\n CLIMain,\n DependencyResolverMain\n ],\n config,\n [schemaTransformerSlot]: [SchemaTransformerSlot]\n ) {\n schema.registerParser(new TypeScriptParser());\n const logger = loggerExt.createLogger(TypescriptAspect.id);\n aspectLoader.registerPlugins([new SchemaTransformerPlugin(schemaTransformerSlot)]);\n const tsMain = new TypescriptMain(logger, schemaTransformerSlot, workspace, depResolver);\n schemaTransformerSlot.register([\n new ExportDeclaration(),\n new FunctionDeclaration(),\n new VariableStatementTransformer(),\n new VariableDeclaration(),\n new SourceFileTransformer(),\n new TypeAliasTransformer(),\n new ClassDecelerationTransformer(),\n new InterfaceDeclarationTransformer(),\n new EnumDeclarationTransformer(),\n new BindingElementTransformer(),\n ]);\n\n if (workspace) {\n workspace.registerOnPreWatch(tsMain.onPreWatch.bind(this));\n workspace.registerOnComponentChange(tsMain.onComponentChange.bind(this));\n workspace.registerOnComponentAdd(tsMain.onComponentChange.bind(this));\n }\n\n const checkTypesCmd = new CheckTypesCmd(tsMain, workspace, logger);\n cli.register(checkTypesCmd);\n\n return tsMain;\n }\n}\n\nTypescriptAspect.addRuntime(TypescriptMain);\n\nexport function runTransformersWithContext(\n config: TypescriptConfigMutator,\n transformers: TsConfigTransformer[] = [],\n context: TsConfigTransformContext\n): TypescriptConfigMutator {\n if (!Array.isArray(transformers)) return config;\n const newConfig = transformers.reduce((acc, transformer) => {\n return transformer(acc, context);\n }, config);\n return newConfig;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;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;;AAEA;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;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;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OAAN,CAAlB;EACD,CAFiB,EAEfvE,MAFe,CAAlB;EAGA,OAAO0E,SAAP;AACD"}
|
|
@@ -8,7 +8,7 @@ export class TransformerNotFound extends Error {
|
|
|
8
8
|
`typescript: could not find schema transformer for node of kind ${node.kind} (${
|
|
9
9
|
ts.SyntaxKind[node.kind]
|
|
10
10
|
}) in component ${component.id.toString()}.
|
|
11
|
-
location: ${
|
|
11
|
+
location: ${node.getSourceFile().fileName}, line: ${location.line}, character: ${location.character}.
|
|
12
12
|
node-text: ${node.getText()}`
|
|
13
13
|
);
|
|
14
14
|
}
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@teambit/typescript",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.753",
|
|
4
4
|
"homepage": "https://bit.dev/teambit/typescript/typescript",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"componentId": {
|
|
7
7
|
"scope": "teambit.typescript",
|
|
8
8
|
"name": "typescript",
|
|
9
|
-
"version": "0.0.
|
|
9
|
+
"version": "0.0.753"
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"lodash": "4.17.21",
|
|
@@ -18,21 +18,21 @@
|
|
|
18
18
|
"@babel/runtime": "7.12.18",
|
|
19
19
|
"core-js": "^3.0.0",
|
|
20
20
|
"@teambit/harmony": "0.3.3",
|
|
21
|
-
"@teambit/compiler": "0.0.
|
|
21
|
+
"@teambit/compiler": "0.0.753",
|
|
22
22
|
"@teambit/typescript.modules.ts-config-mutator": "0.0.68",
|
|
23
|
-
"@teambit/component": "0.0.
|
|
24
|
-
"@teambit/dependency-resolver": "0.0.
|
|
25
|
-
"@teambit/semantics.entities.semantic-schema": "0.0.
|
|
23
|
+
"@teambit/component": "0.0.753",
|
|
24
|
+
"@teambit/dependency-resolver": "0.0.753",
|
|
25
|
+
"@teambit/semantics.entities.semantic-schema": "0.0.18",
|
|
26
26
|
"@teambit/ts-server": "0.0.32",
|
|
27
|
-
"@teambit/aspect-loader": "0.0.
|
|
27
|
+
"@teambit/aspect-loader": "0.0.753",
|
|
28
28
|
"@teambit/bit-error": "0.0.394",
|
|
29
|
-
"@teambit/builder": "0.0.
|
|
30
|
-
"@teambit/isolator": "0.0.
|
|
31
|
-
"@teambit/logger": "0.0.
|
|
32
|
-
"@teambit/schema": "0.0.
|
|
33
|
-
"@teambit/workspace": "0.0.
|
|
34
|
-
"@teambit/cli": "0.0.
|
|
35
|
-
"@teambit/pkg": "0.0.
|
|
29
|
+
"@teambit/builder": "0.0.753",
|
|
30
|
+
"@teambit/isolator": "0.0.753",
|
|
31
|
+
"@teambit/logger": "0.0.590",
|
|
32
|
+
"@teambit/schema": "0.0.753",
|
|
33
|
+
"@teambit/workspace": "0.0.753",
|
|
34
|
+
"@teambit/cli": "0.0.497",
|
|
35
|
+
"@teambit/pkg": "0.0.753"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"@types/lodash": "4.14.165",
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
"@teambit/typescript.aspect-docs.typescript": "0.0.138"
|
|
49
49
|
},
|
|
50
50
|
"peerDependencies": {
|
|
51
|
-
"@teambit/legacy": "1.0.
|
|
51
|
+
"@teambit/legacy": "1.0.277",
|
|
52
52
|
"react-dom": "^16.8.0 || ^17.0.0",
|
|
53
53
|
"react": "^16.8.0 || ^17.0.0"
|
|
54
54
|
},
|
|
@@ -76,7 +76,7 @@
|
|
|
76
76
|
"react": "-"
|
|
77
77
|
},
|
|
78
78
|
"peerDependencies": {
|
|
79
|
-
"@teambit/legacy": "1.0.
|
|
79
|
+
"@teambit/legacy": "1.0.277",
|
|
80
80
|
"react-dom": "^16.8.0 || ^17.0.0",
|
|
81
81
|
"react": "^16.8.0 || ^17.0.0"
|
|
82
82
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export const compositions = [require('/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.typescript_typescript@0.0.
|
|
2
|
-
export const overview = [require('/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.typescript_typescript@0.0.
|
|
1
|
+
export const compositions = [require('/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.typescript_typescript@0.0.753/dist/typescript.composition.js')]
|
|
2
|
+
export const overview = [require('/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.typescript_typescript@0.0.753/dist/typescript.docs.mdx')]
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import ts, { BindingElement, Node } from 'typescript';
|
|
2
|
+
import { VariableSchema } from '@teambit/semantics.entities.semantic-schema';
|
|
3
|
+
import { SchemaTransformer } from '../schema-transformer';
|
|
4
|
+
import { SchemaExtractorContext } from '../schema-extractor-context';
|
|
5
|
+
import { ExportIdentifier } from '../export-identifier';
|
|
6
|
+
import { parseTypeFromQuickInfo } from './utils/parse-type-from-quick-info';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* for example:
|
|
10
|
+
*
|
|
11
|
+
* const objBindingElem = { elem1: 1, elem2: 2 };
|
|
12
|
+
* const { elem1 } = objBindingElem;
|
|
13
|
+
* export { elem1 };
|
|
14
|
+
*/
|
|
15
|
+
export class BindingElementTransformer implements SchemaTransformer {
|
|
16
|
+
predicate(node: Node) {
|
|
17
|
+
return node.kind === ts.SyntaxKind.BindingElement;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
async getIdentifiers(node: BindingElement) {
|
|
21
|
+
return [new ExportIdentifier(node.name.getText(), node.getSourceFile().fileName)];
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
async transform(node: BindingElement, context: SchemaExtractorContext) {
|
|
25
|
+
const name = node.name.getText();
|
|
26
|
+
const info = await context.getQuickInfo(node.name);
|
|
27
|
+
const displaySig = info?.body?.displayString || '';
|
|
28
|
+
const typeStr = parseTypeFromQuickInfo(info);
|
|
29
|
+
const type = await context.resolveType(node, typeStr);
|
|
30
|
+
return new VariableSchema(context.getLocation(node), name, displaySig, type, false);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -35,11 +35,24 @@ export class ExportDeclaration implements SchemaTransformer {
|
|
|
35
35
|
return [];
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
async transform(
|
|
39
|
-
const exportDec = node as ExportDeclarationNode;
|
|
38
|
+
async transform(exportDec: ExportDeclarationNode, context: SchemaExtractorContext): Promise<SchemaNode> {
|
|
40
39
|
const exportClause = exportDec.exportClause;
|
|
40
|
+
|
|
41
|
+
// it's export-all, e.g. `export * from './button'`;
|
|
42
|
+
if (!exportClause) {
|
|
43
|
+
const specifier = exportDec.moduleSpecifier;
|
|
44
|
+
if (!specifier) {
|
|
45
|
+
throw new Error(`fatal: no specifier`);
|
|
46
|
+
}
|
|
47
|
+
const sourceFile = await context.getSourceFileFromNode(specifier);
|
|
48
|
+
if (!sourceFile) {
|
|
49
|
+
throw new Error(`unable to find the source-file`);
|
|
50
|
+
}
|
|
51
|
+
return context.computeSchema(sourceFile);
|
|
52
|
+
}
|
|
53
|
+
|
|
41
54
|
// e.g. `export { button1, button2 } as Composition from './button';
|
|
42
|
-
if (exportClause
|
|
55
|
+
if (exportClause.kind === SyntaxKind.NamedExports) {
|
|
43
56
|
exportClause as NamedExports;
|
|
44
57
|
const schemas = await Promise.all(
|
|
45
58
|
exportClause.elements.map(async (element) => {
|
|
@@ -47,10 +60,10 @@ export class ExportDeclaration implements SchemaTransformer {
|
|
|
47
60
|
})
|
|
48
61
|
);
|
|
49
62
|
|
|
50
|
-
return new Module(context.getLocation(
|
|
63
|
+
return new Module(context.getLocation(exportDec), compact(schemas));
|
|
51
64
|
}
|
|
52
65
|
// e.g. `export * as Composition from './button';
|
|
53
|
-
if (exportClause
|
|
66
|
+
if (exportClause.kind === SyntaxKind.NamespaceExport) {
|
|
54
67
|
exportClause as NamespaceExport;
|
|
55
68
|
const namespace = exportClause.name.getText();
|
|
56
69
|
const filePath = await context.getFilePathByNode(exportClause.name);
|
|
@@ -60,7 +73,7 @@ export class ExportDeclaration implements SchemaTransformer {
|
|
|
60
73
|
const sourceFile = context.getSourceFileInsideComponent(filePath);
|
|
61
74
|
if (!sourceFile) {
|
|
62
75
|
// it's a namespace from another component or an external package.
|
|
63
|
-
return context.getTypeRefForExternalPath(namespace, filePath, context.getLocation(
|
|
76
|
+
return context.getTypeRefForExternalPath(namespace, filePath, context.getLocation(exportDec));
|
|
64
77
|
}
|
|
65
78
|
const result = await context.computeSchema(sourceFile);
|
|
66
79
|
if (!(result instanceof Module)) {
|
|
@@ -69,19 +82,8 @@ export class ExportDeclaration implements SchemaTransformer {
|
|
|
69
82
|
result.namespace = namespace;
|
|
70
83
|
return result;
|
|
71
84
|
}
|
|
72
|
-
// it's export-all, e.g. `export * from './button'`;
|
|
73
|
-
if (!exportClause) {
|
|
74
|
-
const specifier = exportDec.moduleSpecifier;
|
|
75
|
-
if (!specifier) {
|
|
76
|
-
throw new Error(`fatal: no specifier`);
|
|
77
|
-
}
|
|
78
|
-
const sourceFile = await context.getSourceFileFromNode(specifier);
|
|
79
|
-
if (!sourceFile) {
|
|
80
|
-
throw new Error(`unable to find the source-file`);
|
|
81
|
-
}
|
|
82
|
-
return context.computeSchema(sourceFile);
|
|
83
|
-
}
|
|
84
85
|
|
|
85
|
-
|
|
86
|
+
// should never reach here. exportClause can be either NamespaceExport or NamedExports
|
|
87
|
+
throw new Error(`unrecognized exportClause type`);
|
|
86
88
|
}
|
|
87
89
|
}
|
|
@@ -3,7 +3,7 @@ import ts, { Node, FunctionDeclaration as FunctionDeclarationNode } from 'typesc
|
|
|
3
3
|
import { SchemaExtractorContext } from '../schema-extractor-context';
|
|
4
4
|
import { SchemaTransformer } from '../schema-transformer';
|
|
5
5
|
import { ExportIdentifier } from '../export-identifier';
|
|
6
|
-
import { toFunctionLikeSchema } from './utils/to-function-schema';
|
|
6
|
+
import { toFunctionLikeSchema } from './utils/to-function-like-schema';
|
|
7
7
|
|
|
8
8
|
export class FunctionDeclaration implements SchemaTransformer {
|
|
9
9
|
predicate(node: Node) {
|
package/transformers/index.ts
CHANGED
|
@@ -5,6 +5,6 @@ export { VariableDeclaration } from './variable-declaration';
|
|
|
5
5
|
export { SourceFileTransformer } from './source-file-transformer';
|
|
6
6
|
export { TypeAliasTransformer } from './type-alias';
|
|
7
7
|
export { ClassDecelerationTransformer } from './class-deceleration';
|
|
8
|
-
export { LiteralTypeTransformer } from './literal-type';
|
|
9
8
|
export { InterfaceDeclarationTransformer } from './interface-declaration';
|
|
10
9
|
export { EnumDeclarationTransformer } from './enum-declaration';
|
|
10
|
+
export { BindingElementTransformer } from './binding-element';
|
|
@@ -13,7 +13,7 @@ import { SchemaExtractorContext } from '../../schema-extractor-context';
|
|
|
13
13
|
import { getParams } from './get-params';
|
|
14
14
|
import { getAccessor, indexSignature, setAccessor } from './type-element-to-schema';
|
|
15
15
|
import { parseTypeFromQuickInfo } from './parse-type-from-quick-info';
|
|
16
|
-
import { toFunctionLikeSchema } from './to-function-schema';
|
|
16
|
+
import { toFunctionLikeSchema } from './to-function-like-schema';
|
|
17
17
|
|
|
18
18
|
export async function classElementToSchema(
|
|
19
19
|
node: ClassElement,
|
|
@@ -52,8 +52,9 @@ async function propertyDeclaration(node: PropertyDeclaration, context: SchemaExt
|
|
|
52
52
|
const displaySig = info?.body?.displayString;
|
|
53
53
|
const typeStr = parseTypeFromQuickInfo(info);
|
|
54
54
|
const type = await context.resolveType(node, typeStr);
|
|
55
|
+
const isOptional = Boolean(node.questionToken);
|
|
55
56
|
|
|
56
|
-
return new VariableSchema(context.getLocation(node), name, displaySig || '', type);
|
|
57
|
+
return new VariableSchema(context.getLocation(node), name, displaySig || '', type, isOptional);
|
|
57
58
|
}
|
|
58
59
|
|
|
59
60
|
async function methodDeclaration(node: MethodDeclaration, context: SchemaExtractorContext) {
|
|
@@ -17,7 +17,17 @@ export async function toFunctionLikeSchema(
|
|
|
17
17
|
const args = await getParams(node.parameters, context);
|
|
18
18
|
const returnType = await context.resolveType(node, returnTypeStr, Boolean(info));
|
|
19
19
|
const modifiers = node.modifiers?.map((modifier) => modifier.getText()) || [];
|
|
20
|
+
const typeParameters = node.typeParameters?.map((typeParam) => typeParam.name.getText());
|
|
20
21
|
const location = context.getLocation(node);
|
|
21
22
|
const doc = await jsDocToDocSchema(node, context);
|
|
22
|
-
return new FunctionLikeSchema(
|
|
23
|
+
return new FunctionLikeSchema(
|
|
24
|
+
location,
|
|
25
|
+
name,
|
|
26
|
+
args,
|
|
27
|
+
returnType,
|
|
28
|
+
displaySig,
|
|
29
|
+
modifiers as Modifier[],
|
|
30
|
+
doc,
|
|
31
|
+
typeParameters
|
|
32
|
+
);
|
|
23
33
|
}
|