@teambit/typescript 0.0.738 → 0.0.739
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.d.ts +2 -1
- package/dist/exceptions/transformer-not-found.js +3 -2
- package/dist/exceptions/transformer-not-found.js.map +1 -1
- package/dist/schema-extractor-context.d.ts +4 -1
- package/dist/schema-extractor-context.js +20 -2
- package/dist/schema-extractor-context.js.map +1 -1
- package/dist/transformers/class-deceleration.js +9 -1
- package/dist/transformers/class-deceleration.js.map +1 -1
- package/dist/transformers/enum-declaration.d.ts +10 -0
- package/dist/transformers/enum-declaration.js +60 -0
- package/dist/transformers/enum-declaration.js.map +1 -0
- package/dist/transformers/index.d.ts +1 -0
- package/dist/transformers/index.js +16 -0
- package/dist/transformers/index.js.map +1 -1
- package/dist/transformers/utils/get-params.js +53 -7
- package/dist/transformers/utils/get-params.js.map +1 -1
- package/dist/transformers/utils/parse-type-from-quick-info.d.ts +1 -0
- package/dist/transformers/utils/parse-type-from-quick-info.js +12 -3
- package/dist/transformers/utils/parse-type-from-quick-info.js.map +1 -1
- package/dist/transformers/utils/type-node-to-schema.js +34 -4
- package/dist/transformers/utils/type-node-to-schema.js.map +1 -1
- package/dist/typescript.extractor.d.ts +7 -1
- package/dist/typescript.extractor.js +30 -9
- package/dist/typescript.extractor.js.map +1 -1
- package/dist/typescript.main.runtime.d.ts +11 -2
- package/dist/typescript.main.runtime.js +17 -6
- package/dist/typescript.main.runtime.js.map +1 -1
- package/exceptions/transformer-not-found.ts +4 -2
- package/package-tar/teambit-typescript-0.0.739.tgz +0 -0
- package/package.json +12 -11
- package/{preview-1653227849497.js → preview-1653362849981.js} +2 -2
- package/transformers/class-deceleration.ts +4 -1
- package/transformers/enum-declaration.ts +20 -0
- package/transformers/index.ts +1 -0
- package/transformers/utils/get-params.ts +53 -9
- package/transformers/utils/parse-type-from-quick-info.ts +9 -1
- package/transformers/utils/type-node-to-schema.ts +37 -4
- package/package-tar/teambit-typescript-0.0.738.tgz +0 -0
|
@@ -89,16 +89,22 @@ async function typeNodeToSchema(node, context) {
|
|
|
89
89
|
case _typescript().SyntaxKind.TupleType:
|
|
90
90
|
return tupleType(node, context);
|
|
91
91
|
|
|
92
|
+
case _typescript().SyntaxKind.ParenthesizedType:
|
|
93
|
+
return parenthesizedType(node, context);
|
|
94
|
+
|
|
92
95
|
case _typescript().SyntaxKind.TypePredicate:
|
|
96
|
+
return typePredicate(node, context);
|
|
97
|
+
|
|
98
|
+
case _typescript().SyntaxKind.IndexedAccessType:
|
|
99
|
+
return indexedAccessType(node, context);
|
|
100
|
+
|
|
93
101
|
case _typescript().SyntaxKind.ConstructorType:
|
|
94
102
|
case _typescript().SyntaxKind.NamedTupleMember:
|
|
95
103
|
case _typescript().SyntaxKind.OptionalType:
|
|
96
104
|
case _typescript().SyntaxKind.RestType:
|
|
97
105
|
case _typescript().SyntaxKind.ConditionalType:
|
|
98
106
|
case _typescript().SyntaxKind.InferType:
|
|
99
|
-
case _typescript().SyntaxKind.ParenthesizedType:
|
|
100
107
|
case _typescript().SyntaxKind.ThisType:
|
|
101
|
-
case _typescript().SyntaxKind.IndexedAccessType:
|
|
102
108
|
case _typescript().SyntaxKind.MappedType:
|
|
103
109
|
case _typescript().SyntaxKind.TemplateLiteralType:
|
|
104
110
|
case _typescript().SyntaxKind.TemplateLiteralTypeSpan:
|
|
@@ -115,11 +121,11 @@ async function typeNodeToSchema(node, context) {
|
|
|
115
121
|
case _typescript().SyntaxKind.JSDocNamepathType:
|
|
116
122
|
case _typescript().SyntaxKind.JSDocSignature:
|
|
117
123
|
case _typescript().SyntaxKind.JSDocTypeLiteral:
|
|
118
|
-
throw new Error(`TypeNode
|
|
124
|
+
throw new Error(`TypeNode ${node.kind} (probably ${_typescript().SyntaxKind[node.kind]}) was not implemented yet.
|
|
119
125
|
context: ${node.getText()}`);
|
|
120
126
|
|
|
121
127
|
default:
|
|
122
|
-
throw new Error(`Node
|
|
128
|
+
throw new Error(`Node ${node.kind} (probably ${_typescript().SyntaxKind[node.kind]}) is not a TypeNode.
|
|
123
129
|
context: ${node.getText()}`);
|
|
124
130
|
}
|
|
125
131
|
}
|
|
@@ -192,6 +198,12 @@ async function typeLiteral(node, context) {
|
|
|
192
198
|
async function typeReference(node, context) {
|
|
193
199
|
const name = node.typeName.getText();
|
|
194
200
|
const type = await context.resolveType(node, name, false);
|
|
201
|
+
|
|
202
|
+
if (node.typeArguments && type instanceof _semanticsEntities().TypeRefSchema) {
|
|
203
|
+
const args = await (0, _pMapSeries().default)(node.typeArguments, arg => typeNodeToSchema(arg, context));
|
|
204
|
+
type.typeArgs = args;
|
|
205
|
+
}
|
|
206
|
+
|
|
195
207
|
return type;
|
|
196
208
|
}
|
|
197
209
|
|
|
@@ -256,4 +268,22 @@ async function tupleType(node, context) {
|
|
|
256
268
|
return new (_semanticsEntities().TupleTypeSchema)(context.getLocation(node), elements);
|
|
257
269
|
}
|
|
258
270
|
|
|
271
|
+
async function parenthesizedType(node, context) {
|
|
272
|
+
const type = await typeNodeToSchema(node.type, context);
|
|
273
|
+
return new (_semanticsEntities().ParenthesizedTypeSchema)(context.getLocation(node), type);
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
async function typePredicate(node, context) {
|
|
277
|
+
const parameterName = (0, _typescript().isIdentifier)(node.parameterName) ? node.parameterName.getText() : 'this';
|
|
278
|
+
const type = node.type ? await typeNodeToSchema(node.type, context) : undefined;
|
|
279
|
+
const hasAssertsModifier = Boolean(node.assertsModifier);
|
|
280
|
+
return new (_semanticsEntities().TypePredicateSchema)(context.getLocation(node), parameterName, type, hasAssertsModifier);
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
async function indexedAccessType(node, context) {
|
|
284
|
+
const objectType = await typeNodeToSchema(node.objectType, context);
|
|
285
|
+
const indexType = await typeNodeToSchema(node.indexType, context);
|
|
286
|
+
return new (_semanticsEntities().IndexedAccessSchema)(context.getLocation(node), objectType, indexType);
|
|
287
|
+
}
|
|
288
|
+
|
|
259
289
|
//# sourceMappingURL=type-node-to-schema.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["typeNodeToSchema","node","context","location","getLocation","isKeywordType","KeywordTypeSchema","getText","kind","SyntaxKind","IntersectionType","intersectionType","UnionType","unionType","TypeReference","typeReference","TypeLiteral","typeLiteral","LiteralType","LiteralTypeSchema","FunctionType","functionType","TypeQuery","typeQuery","ArrayType","arrayType","TypeOperator","typeOperator","TupleType","tupleType","TypePredicate","ConstructorType","NamedTupleMember","OptionalType","RestType","ConditionalType","InferType","ParenthesizedType","ThisType","IndexedAccessType","MappedType","TemplateLiteralType","TemplateLiteralTypeSpan","ImportType","ExpressionWithTypeArguments","JSDocTypeExpression","JSDocAllType","JSDocUnknownType","JSDocNonNullableType","JSDocNullableType","JSDocOptionalType","JSDocFunctionType","JSDocVariadicType","JSDocNamepathType","JSDocSignature","JSDocTypeLiteral","Error","AnyKeyword","BigIntKeyword","BooleanKeyword","IntrinsicKeyword","NeverKeyword","NumberKeyword","ObjectKeyword","StringKeyword","SymbolKeyword","UndefinedKeyword","UnknownKeyword","VoidKeyword","types","pMapSeries","type","typeSchema","TypeIntersectionSchema","TypeUnionSchema","members","member","computeSchema","TypeLiteralSchema","name","typeName","resolveType","params","getParams","parameters","returnType","FunctionLikeSchema","displaySig","getQuickInfoDisplayString","exprName","TypeQuerySchema","elementType","TypeArraySchema","operatorName","getOperatorName","operator","TypeOperatorSchema","KeyOfKeyword","UniqueKeyword","ReadonlyKeyword","elements","elem","TupleTypeSchema"],"sources":["type-node-to-schema.ts"],"sourcesContent":["import {\n TypeNode,\n SyntaxKind,\n KeywordTypeNode,\n FunctionTypeNode,\n TypeQueryNode,\n TypeReferenceNode,\n ArrayTypeNode,\n TypeOperatorNode,\n TupleTypeNode,\n IntersectionTypeNode,\n UnionTypeNode,\n TypeLiteralNode,\n} from 'typescript';\nimport {\n SchemaNode,\n TypeIntersectionSchema,\n TypeUnionSchema,\n TypeLiteralSchema,\n TypeQuerySchema,\n LiteralTypeSchema,\n KeywordTypeSchema,\n TypeArraySchema,\n TypeOperatorSchema,\n TupleTypeSchema,\n FunctionLikeSchema,\n} from '@teambit/semantics.entities.semantic-schema';\nimport pMapSeries from 'p-map-series';\nimport { SchemaExtractorContext } from '../../schema-extractor-context';\nimport { getParams } from './get-params';\n\n// eslint-disable-next-line complexity\nexport async function typeNodeToSchema(node: TypeNode, context: SchemaExtractorContext): Promise<SchemaNode> {\n const location = context.getLocation(node);\n if (isKeywordType(node)) {\n return new KeywordTypeSchema(location, node.getText());\n }\n switch (node.kind) {\n case SyntaxKind.IntersectionType:\n return intersectionType(node as IntersectionTypeNode, context);\n case SyntaxKind.UnionType:\n return unionType(node as UnionTypeNode, context);\n case SyntaxKind.TypeReference:\n return typeReference(node as TypeReferenceNode, context);\n case SyntaxKind.TypeLiteral:\n return typeLiteral(node as TypeLiteralNode, context);\n case SyntaxKind.LiteralType: // e.g. string/boolean\n return new LiteralTypeSchema(location, node.getText());\n case SyntaxKind.FunctionType:\n return functionType(node as FunctionTypeNode, context);\n case SyntaxKind.TypeQuery:\n return typeQuery(node as TypeQueryNode, context);\n case SyntaxKind.ArrayType:\n return arrayType(node as ArrayTypeNode, context);\n case SyntaxKind.TypeOperator:\n return typeOperator(node as TypeOperatorNode, context);\n case SyntaxKind.TupleType:\n return tupleType(node as TupleTypeNode, context);\n case SyntaxKind.TypePredicate:\n case SyntaxKind.ConstructorType:\n case SyntaxKind.NamedTupleMember:\n case SyntaxKind.OptionalType:\n case SyntaxKind.RestType:\n case SyntaxKind.ConditionalType:\n case SyntaxKind.InferType:\n case SyntaxKind.ParenthesizedType:\n case SyntaxKind.ThisType:\n case SyntaxKind.IndexedAccessType:\n case SyntaxKind.MappedType:\n case SyntaxKind.TemplateLiteralType:\n case SyntaxKind.TemplateLiteralTypeSpan:\n case SyntaxKind.ImportType:\n case SyntaxKind.ExpressionWithTypeArguments:\n case SyntaxKind.JSDocTypeExpression:\n case SyntaxKind.JSDocAllType:\n case SyntaxKind.JSDocUnknownType:\n case SyntaxKind.JSDocNonNullableType:\n case SyntaxKind.JSDocNullableType:\n case SyntaxKind.JSDocOptionalType:\n case SyntaxKind.JSDocFunctionType:\n case SyntaxKind.JSDocVariadicType:\n case SyntaxKind.JSDocNamepathType:\n case SyntaxKind.JSDocSignature:\n case SyntaxKind.JSDocTypeLiteral:\n throw new Error(`TypeNode \"${SyntaxKind[node.kind]}\" was not implemented yet.\ncontext: ${node.getText()}`);\n default:\n throw new Error(`Node \"${SyntaxKind[node.kind]}\" is not a TypeNode.\ncontext: ${node.getText()}`);\n }\n}\n\n/**\n * whether it's kind of `ts.KeywordTypeSyntaxKind`\n */\nfunction isKeywordType(node: TypeNode): node is KeywordTypeNode {\n switch (node.kind) {\n case SyntaxKind.AnyKeyword:\n case SyntaxKind.BigIntKeyword:\n case SyntaxKind.BooleanKeyword:\n case SyntaxKind.IntrinsicKeyword:\n case SyntaxKind.NeverKeyword:\n case SyntaxKind.NumberKeyword:\n case SyntaxKind.ObjectKeyword:\n case SyntaxKind.StringKeyword:\n case SyntaxKind.SymbolKeyword:\n case SyntaxKind.UndefinedKeyword:\n case SyntaxKind.UnknownKeyword:\n case SyntaxKind.VoidKeyword:\n return true;\n default:\n return false;\n }\n}\n\nasync function intersectionType(node: IntersectionTypeNode, context: SchemaExtractorContext) {\n const types = await pMapSeries(node.types, async (type) => {\n const typeSchema = await typeNodeToSchema(type, context);\n return typeSchema;\n });\n const location = context.getLocation(node);\n return new TypeIntersectionSchema(location, types);\n}\n\nasync function unionType(node: UnionTypeNode, context: SchemaExtractorContext) {\n const types = await pMapSeries(node.types, async (type) => {\n const typeSchema = await typeNodeToSchema(type, context);\n return typeSchema;\n });\n const location = context.getLocation(node);\n return new TypeUnionSchema(location, types);\n}\n\n/**\n * not to be confused with \"LiteralType\", which is string/boolean/null.\n * this \"TypeLiteral\" is an object with properties, such as: `{ a: string; b: number }`, similar to Interface.\n */\nasync function typeLiteral(node: TypeLiteralNode, context: SchemaExtractorContext) {\n const members = await pMapSeries(node.members, async (member) => {\n const typeSchema = await context.computeSchema(member);\n return typeSchema;\n });\n const location = context.getLocation(node);\n return new TypeLiteralSchema(location, members);\n}\n\n/**\n * In the following example, `AriaButtonProps` is a type reference\n * ```ts\n * import type { AriaButtonProps } from '@react-types/button';\n * export type ButtonProps = AriaButtonProps & { a: string };\n * ```\n */\nasync function typeReference(node: TypeReferenceNode, context: SchemaExtractorContext) {\n const name = node.typeName.getText();\n const type = await context.resolveType(node, name, false);\n return type;\n}\n\nasync function functionType(node: FunctionTypeNode, context: SchemaExtractorContext): Promise<SchemaNode> {\n const name = node.name?.getText() || '';\n const params = await getParams(node.parameters, context);\n const returnType = await typeNodeToSchema(node.type, context);\n const location = context.getLocation(node);\n return new FunctionLikeSchema(location, name, params, returnType, '');\n}\n\n/**\n * e.g. `typeof Foo`\n */\nasync function typeQuery(node: TypeQueryNode, context: SchemaExtractorContext) {\n const displaySig = await context.getQuickInfoDisplayString(node.exprName);\n const type = await context.resolveType(node.exprName, node.exprName.getText(), false);\n const location = context.getLocation(node);\n return new TypeQuerySchema(location, type, displaySig);\n}\n\nasync function arrayType(node: ArrayTypeNode, context: SchemaExtractorContext) {\n const type = await typeNodeToSchema(node.elementType, context);\n const location = context.getLocation(node);\n return new TypeArraySchema(location, type);\n}\n\n/**\n * e.g. keyof typeof Foo\n */\nasync function typeOperator(node: TypeOperatorNode, context: SchemaExtractorContext) {\n const operatorName = getOperatorName(node.operator);\n const type = await typeNodeToSchema(node.type, context);\n return new TypeOperatorSchema(context.getLocation(node), operatorName, type);\n}\n\nfunction getOperatorName(operator: SyntaxKind.KeyOfKeyword | SyntaxKind.UniqueKeyword | SyntaxKind.ReadonlyKeyword) {\n switch (operator) {\n case SyntaxKind.KeyOfKeyword:\n return 'keyof';\n case SyntaxKind.UniqueKeyword:\n return 'unique';\n case SyntaxKind.ReadonlyKeyword:\n return 'readonly';\n default:\n throw new Error(`getOperatorName: unable to find operator name for ${operator}`);\n }\n}\n\nasync function tupleType(node: TupleTypeNode, context: SchemaExtractorContext) {\n const elements = await pMapSeries(node.elements, async (elem) => {\n const typeSchema = await typeNodeToSchema(elem, context);\n return typeSchema;\n });\n return new TupleTypeSchema(context.getLocation(node), elements);\n}\n"],"mappings":";;;;;;;;;;;AAAA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAcA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAaA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAEA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAEA;AACO,eAAeA,gBAAf,CAAgCC,IAAhC,EAAgDC,OAAhD,EAAsG;EAC3G,MAAMC,QAAQ,GAAGD,OAAO,CAACE,WAAR,CAAoBH,IAApB,CAAjB;;EACA,IAAII,aAAa,CAACJ,IAAD,CAAjB,EAAyB;IACvB,OAAO,KAAIK,sCAAJ,EAAsBH,QAAtB,EAAgCF,IAAI,CAACM,OAAL,EAAhC,CAAP;EACD;;EACD,QAAQN,IAAI,CAACO,IAAb;IACE,KAAKC,wBAAA,CAAWC,gBAAhB;MACE,OAAOC,gBAAgB,CAACV,IAAD,EAA+BC,OAA/B,CAAvB;;IACF,KAAKO,wBAAA,CAAWG,SAAhB;MACE,OAAOC,SAAS,CAACZ,IAAD,EAAwBC,OAAxB,CAAhB;;IACF,KAAKO,wBAAA,CAAWK,aAAhB;MACE,OAAOC,aAAa,CAACd,IAAD,EAA4BC,OAA5B,CAApB;;IACF,KAAKO,wBAAA,CAAWO,WAAhB;MACE,OAAOC,WAAW,CAAChB,IAAD,EAA0BC,OAA1B,CAAlB;;IACF,KAAKO,wBAAA,CAAWS,WAAhB;MAA6B;MAC3B,OAAO,KAAIC,sCAAJ,EAAsBhB,QAAtB,EAAgCF,IAAI,CAACM,OAAL,EAAhC,CAAP;;IACF,KAAKE,wBAAA,CAAWW,YAAhB;MACE,OAAOC,YAAY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Schema","node","context","location","getLocation","isKeywordType","KeywordTypeSchema","getText","kind","SyntaxKind","IntersectionType","intersectionType","UnionType","unionType","TypeReference","typeReference","TypeLiteral","typeLiteral","LiteralType","LiteralTypeSchema","FunctionType","functionType","TypeQuery","typeQuery","ArrayType","arrayType","TypeOperator","typeOperator","TupleType","tupleType","ParenthesizedType","parenthesizedType","TypePredicate","typePredicate","IndexedAccessType","indexedAccessType","ConstructorType","NamedTupleMember","OptionalType","RestType","ConditionalType","InferType","ThisType","MappedType","TemplateLiteralType","TemplateLiteralTypeSpan","ImportType","ExpressionWithTypeArguments","JSDocTypeExpression","JSDocAllType","JSDocUnknownType","JSDocNonNullableType","JSDocNullableType","JSDocOptionalType","JSDocFunctionType","JSDocVariadicType","JSDocNamepathType","JSDocSignature","JSDocTypeLiteral","Error","AnyKeyword","BigIntKeyword","BooleanKeyword","IntrinsicKeyword","NeverKeyword","NumberKeyword","ObjectKeyword","StringKeyword","SymbolKeyword","UndefinedKeyword","UnknownKeyword","VoidKeyword","types","pMapSeries","type","typeSchema","TypeIntersectionSchema","TypeUnionSchema","members","member","computeSchema","TypeLiteralSchema","name","typeName","resolveType","typeArguments","TypeRefSchema","args","arg","typeArgs","params","getParams","parameters","returnType","FunctionLikeSchema","displaySig","getQuickInfoDisplayString","exprName","TypeQuerySchema","elementType","TypeArraySchema","operatorName","getOperatorName","operator","TypeOperatorSchema","KeyOfKeyword","UniqueKeyword","ReadonlyKeyword","elements","elem","TupleTypeSchema","ParenthesizedTypeSchema","parameterName","isIdentifier","undefined","hasAssertsModifier","Boolean","assertsModifier","TypePredicateSchema","objectType","indexType","IndexedAccessSchema"],"sources":["type-node-to-schema.ts"],"sourcesContent":["import {\n TypeNode,\n SyntaxKind,\n KeywordTypeNode,\n FunctionTypeNode,\n TypeQueryNode,\n TypeReferenceNode,\n ArrayTypeNode,\n TypeOperatorNode,\n TupleTypeNode,\n IntersectionTypeNode,\n UnionTypeNode,\n TypeLiteralNode,\n ParenthesizedTypeNode,\n TypePredicateNode,\n isIdentifier,\n IndexedAccessTypeNode,\n} from 'typescript';\nimport {\n SchemaNode,\n TypeRefSchema,\n TypeIntersectionSchema,\n TypeUnionSchema,\n TypeLiteralSchema,\n TypeQuerySchema,\n LiteralTypeSchema,\n KeywordTypeSchema,\n TypeArraySchema,\n TypeOperatorSchema,\n TupleTypeSchema,\n FunctionLikeSchema,\n ParenthesizedTypeSchema,\n TypePredicateSchema,\n IndexedAccessSchema,\n} from '@teambit/semantics.entities.semantic-schema';\nimport pMapSeries from 'p-map-series';\nimport { SchemaExtractorContext } from '../../schema-extractor-context';\nimport { getParams } from './get-params';\n\n// eslint-disable-next-line complexity\nexport async function typeNodeToSchema(node: TypeNode, context: SchemaExtractorContext): Promise<SchemaNode> {\n const location = context.getLocation(node);\n if (isKeywordType(node)) {\n return new KeywordTypeSchema(location, node.getText());\n }\n switch (node.kind) {\n case SyntaxKind.IntersectionType:\n return intersectionType(node as IntersectionTypeNode, context);\n case SyntaxKind.UnionType:\n return unionType(node as UnionTypeNode, context);\n case SyntaxKind.TypeReference:\n return typeReference(node as TypeReferenceNode, context);\n case SyntaxKind.TypeLiteral:\n return typeLiteral(node as TypeLiteralNode, context);\n case SyntaxKind.LiteralType: // e.g. string/boolean\n return new LiteralTypeSchema(location, node.getText());\n case SyntaxKind.FunctionType:\n return functionType(node as FunctionTypeNode, context);\n case SyntaxKind.TypeQuery:\n return typeQuery(node as TypeQueryNode, context);\n case SyntaxKind.ArrayType:\n return arrayType(node as ArrayTypeNode, context);\n case SyntaxKind.TypeOperator:\n return typeOperator(node as TypeOperatorNode, context);\n case SyntaxKind.TupleType:\n return tupleType(node as TupleTypeNode, context);\n case SyntaxKind.ParenthesizedType:\n return parenthesizedType(node as ParenthesizedTypeNode, context);\n case SyntaxKind.TypePredicate:\n return typePredicate(node as TypePredicateNode, context);\n case SyntaxKind.IndexedAccessType:\n return indexedAccessType(node as IndexedAccessTypeNode, context);\n case SyntaxKind.ConstructorType:\n case SyntaxKind.NamedTupleMember:\n case SyntaxKind.OptionalType:\n case SyntaxKind.RestType:\n case SyntaxKind.ConditionalType:\n case SyntaxKind.InferType:\n case SyntaxKind.ThisType:\n case SyntaxKind.MappedType:\n case SyntaxKind.TemplateLiteralType:\n case SyntaxKind.TemplateLiteralTypeSpan:\n case SyntaxKind.ImportType:\n case SyntaxKind.ExpressionWithTypeArguments:\n case SyntaxKind.JSDocTypeExpression:\n case SyntaxKind.JSDocAllType:\n case SyntaxKind.JSDocUnknownType:\n case SyntaxKind.JSDocNonNullableType:\n case SyntaxKind.JSDocNullableType:\n case SyntaxKind.JSDocOptionalType:\n case SyntaxKind.JSDocFunctionType:\n case SyntaxKind.JSDocVariadicType:\n case SyntaxKind.JSDocNamepathType:\n case SyntaxKind.JSDocSignature:\n case SyntaxKind.JSDocTypeLiteral:\n throw new Error(`TypeNode ${node.kind} (probably ${SyntaxKind[node.kind]}) was not implemented yet.\ncontext: ${node.getText()}`);\n default:\n throw new Error(`Node ${node.kind} (probably ${SyntaxKind[node.kind]}) is not a TypeNode.\ncontext: ${node.getText()}`);\n }\n}\n\n/**\n * whether it's kind of `ts.KeywordTypeSyntaxKind`\n */\nfunction isKeywordType(node: TypeNode): node is KeywordTypeNode {\n switch (node.kind) {\n case SyntaxKind.AnyKeyword:\n case SyntaxKind.BigIntKeyword:\n case SyntaxKind.BooleanKeyword:\n case SyntaxKind.IntrinsicKeyword:\n case SyntaxKind.NeverKeyword:\n case SyntaxKind.NumberKeyword:\n case SyntaxKind.ObjectKeyword:\n case SyntaxKind.StringKeyword:\n case SyntaxKind.SymbolKeyword:\n case SyntaxKind.UndefinedKeyword:\n case SyntaxKind.UnknownKeyword:\n case SyntaxKind.VoidKeyword:\n return true;\n default:\n return false;\n }\n}\n\nasync function intersectionType(node: IntersectionTypeNode, context: SchemaExtractorContext) {\n const types = await pMapSeries(node.types, async (type) => {\n const typeSchema = await typeNodeToSchema(type, context);\n return typeSchema;\n });\n const location = context.getLocation(node);\n return new TypeIntersectionSchema(location, types);\n}\n\nasync function unionType(node: UnionTypeNode, context: SchemaExtractorContext) {\n const types = await pMapSeries(node.types, async (type) => {\n const typeSchema = await typeNodeToSchema(type, context);\n return typeSchema;\n });\n const location = context.getLocation(node);\n return new TypeUnionSchema(location, types);\n}\n\n/**\n * not to be confused with \"LiteralType\", which is string/boolean/null.\n * this \"TypeLiteral\" is an object with properties, such as: `{ a: string; b: number }`, similar to Interface.\n */\nasync function typeLiteral(node: TypeLiteralNode, context: SchemaExtractorContext) {\n const members = await pMapSeries(node.members, async (member) => {\n const typeSchema = await context.computeSchema(member);\n return typeSchema;\n });\n const location = context.getLocation(node);\n return new TypeLiteralSchema(location, members);\n}\n\n/**\n * In the following example, `AriaButtonProps` is a type reference\n * ```ts\n * import type { AriaButtonProps } from '@react-types/button';\n * export type ButtonProps = AriaButtonProps & { a: string };\n * ```\n */\nasync function typeReference(node: TypeReferenceNode, context: SchemaExtractorContext) {\n const name = node.typeName.getText();\n const type = await context.resolveType(node, name, false);\n if (node.typeArguments && type instanceof TypeRefSchema) {\n const args = await pMapSeries(node.typeArguments, (arg) => typeNodeToSchema(arg, context));\n type.typeArgs = args;\n }\n return type;\n}\n\nasync function functionType(node: FunctionTypeNode, context: SchemaExtractorContext): Promise<SchemaNode> {\n const name = node.name?.getText() || '';\n const params = await getParams(node.parameters, context);\n const returnType = await typeNodeToSchema(node.type, context);\n const location = context.getLocation(node);\n return new FunctionLikeSchema(location, name, params, returnType, '');\n}\n\n/**\n * e.g. `typeof Foo`\n */\nasync function typeQuery(node: TypeQueryNode, context: SchemaExtractorContext) {\n const displaySig = await context.getQuickInfoDisplayString(node.exprName);\n const type = await context.resolveType(node.exprName, node.exprName.getText(), false);\n const location = context.getLocation(node);\n return new TypeQuerySchema(location, type, displaySig);\n}\n\nasync function arrayType(node: ArrayTypeNode, context: SchemaExtractorContext) {\n const type = await typeNodeToSchema(node.elementType, context);\n const location = context.getLocation(node);\n return new TypeArraySchema(location, type);\n}\n\n/**\n * e.g. keyof typeof Foo\n */\nasync function typeOperator(node: TypeOperatorNode, context: SchemaExtractorContext) {\n const operatorName = getOperatorName(node.operator);\n const type = await typeNodeToSchema(node.type, context);\n return new TypeOperatorSchema(context.getLocation(node), operatorName, type);\n}\n\nfunction getOperatorName(operator: SyntaxKind.KeyOfKeyword | SyntaxKind.UniqueKeyword | SyntaxKind.ReadonlyKeyword) {\n switch (operator) {\n case SyntaxKind.KeyOfKeyword:\n return 'keyof';\n case SyntaxKind.UniqueKeyword:\n return 'unique';\n case SyntaxKind.ReadonlyKeyword:\n return 'readonly';\n default:\n throw new Error(`getOperatorName: unable to find operator name for ${operator}`);\n }\n}\n\nasync function tupleType(node: TupleTypeNode, context: SchemaExtractorContext) {\n const elements = await pMapSeries(node.elements, async (elem) => {\n const typeSchema = await typeNodeToSchema(elem, context);\n return typeSchema;\n });\n return new TupleTypeSchema(context.getLocation(node), elements);\n}\n\nasync function parenthesizedType(node: ParenthesizedTypeNode, context: SchemaExtractorContext) {\n const type = await typeNodeToSchema(node.type, context);\n return new ParenthesizedTypeSchema(context.getLocation(node), type);\n}\n\nasync function typePredicate(node: TypePredicateNode, context: SchemaExtractorContext) {\n const parameterName = isIdentifier(node.parameterName) ? node.parameterName.getText() : 'this';\n const type = node.type ? await typeNodeToSchema(node.type, context) : undefined;\n const hasAssertsModifier = Boolean(node.assertsModifier);\n return new TypePredicateSchema(context.getLocation(node), parameterName, type, hasAssertsModifier);\n}\n\nasync function indexedAccessType(node: IndexedAccessTypeNode, context: SchemaExtractorContext) {\n const objectType = await typeNodeToSchema(node.objectType, context);\n const indexType = await typeNodeToSchema(node.indexType, context);\n return new IndexedAccessSchema(context.getLocation(node), objectType, indexType);\n}\n"],"mappings":";;;;;;;;;;;AAAA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAkBA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAiBA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAEA;EAAA;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,CAAP;AACD"}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import ts, { Node } from 'typescript';
|
|
2
2
|
import { SchemaExtractor } from '@teambit/schema';
|
|
3
|
+
import type { Workspace } from '@teambit/workspace';
|
|
4
|
+
import { DependencyResolverMain } from '@teambit/dependency-resolver';
|
|
3
5
|
import { SchemaNode, APISchema } from '@teambit/semantics.entities.semantic-schema';
|
|
4
6
|
import { Component } from '@teambit/component';
|
|
5
7
|
import { AbstractVinyl } from '@teambit/legacy/dist/consumer/component/sources';
|
|
@@ -10,7 +12,9 @@ export declare class TypeScriptExtractor implements SchemaExtractor {
|
|
|
10
12
|
private schemaTransformerSlot;
|
|
11
13
|
private tsMain;
|
|
12
14
|
private rootPath;
|
|
13
|
-
|
|
15
|
+
private depResolver;
|
|
16
|
+
private workspace;
|
|
17
|
+
constructor(tsconfig: any, schemaTransformerSlot: SchemaTransformerSlot, tsMain: TypescriptMain, rootPath: string, depResolver: DependencyResolverMain, workspace: Workspace | undefined);
|
|
14
18
|
parseSourceFile(file: AbstractVinyl): ts.SourceFile;
|
|
15
19
|
/**
|
|
16
20
|
* extract a component schema.
|
|
@@ -18,9 +22,11 @@ export declare class TypeScriptExtractor implements SchemaExtractor {
|
|
|
18
22
|
extract(component: Component): Promise<APISchema>;
|
|
19
23
|
computeExportedIdentifiers(node: Node, context: SchemaExtractorContext): Promise<import("./export-identifier").ExportIdentifier[]>;
|
|
20
24
|
private createContext;
|
|
25
|
+
private getComponentDeps;
|
|
21
26
|
private tsserver;
|
|
22
27
|
private getTsServer;
|
|
23
28
|
computeSchema(node: Node, context: SchemaExtractorContext): Promise<SchemaNode>;
|
|
29
|
+
getComponentIDByPath(file: string): Promise<import("@teambit/component").ComponentID | null | undefined>;
|
|
24
30
|
/**
|
|
25
31
|
* select the correct transformer for a node.
|
|
26
32
|
*/
|
|
@@ -82,11 +82,13 @@ function _exportList() {
|
|
|
82
82
|
}
|
|
83
83
|
|
|
84
84
|
class TypeScriptExtractor {
|
|
85
|
-
constructor(tsconfig, schemaTransformerSlot, tsMain, rootPath) {
|
|
85
|
+
constructor(tsconfig, schemaTransformerSlot, tsMain, rootPath, depResolver, workspace) {
|
|
86
86
|
this.tsconfig = tsconfig;
|
|
87
87
|
this.schemaTransformerSlot = schemaTransformerSlot;
|
|
88
88
|
this.tsMain = tsMain;
|
|
89
89
|
this.rootPath = rootPath;
|
|
90
|
+
this.depResolver = depResolver;
|
|
91
|
+
this.workspace = workspace;
|
|
90
92
|
(0, _defineProperty2().default)(this, "tsserver", undefined);
|
|
91
93
|
}
|
|
92
94
|
|
|
@@ -102,7 +104,7 @@ class TypeScriptExtractor {
|
|
|
102
104
|
const tsserver = await this.getTsServer();
|
|
103
105
|
const mainFile = component.mainFile;
|
|
104
106
|
const mainAst = this.parseSourceFile(mainFile);
|
|
105
|
-
const context = this.createContext(tsserver, component);
|
|
107
|
+
const context = await this.createContext(tsserver, component);
|
|
106
108
|
const exportNames = await this.computeExportedIdentifiers(mainAst, context);
|
|
107
109
|
context.setExports(new (_exportList().ExportList)(exportNames));
|
|
108
110
|
const moduleSchema = await this.computeSchema(mainAst, context);
|
|
@@ -113,13 +115,24 @@ class TypeScriptExtractor {
|
|
|
113
115
|
}
|
|
114
116
|
|
|
115
117
|
async computeExportedIdentifiers(node, context) {
|
|
116
|
-
const transformer = this.getTransformer(node, context
|
|
117
|
-
|
|
118
|
+
const transformer = this.getTransformer(node, context);
|
|
119
|
+
|
|
120
|
+
if (!transformer || !transformer.getIdentifiers) {
|
|
121
|
+
throw new (_exceptions().TransformerNotFound)(node, context.component, context.getLocation(node));
|
|
122
|
+
}
|
|
123
|
+
|
|
118
124
|
return transformer.getIdentifiers(node, context);
|
|
119
125
|
}
|
|
120
126
|
|
|
121
|
-
createContext(tsserver, component) {
|
|
122
|
-
|
|
127
|
+
async createContext(tsserver, component) {
|
|
128
|
+
const componentDeps = await this.getComponentDeps(component);
|
|
129
|
+
return new (_schemaExtractorContext().SchemaExtractorContext)(tsserver, component, this, componentDeps);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
async getComponentDeps(component) {
|
|
133
|
+
const deps = await this.depResolver.getDependencies(component);
|
|
134
|
+
const componentDeps = deps.getComponentDependencies();
|
|
135
|
+
return componentDeps;
|
|
123
136
|
}
|
|
124
137
|
|
|
125
138
|
async getTsServer() {
|
|
@@ -139,20 +152,28 @@ class TypeScriptExtractor {
|
|
|
139
152
|
}
|
|
140
153
|
|
|
141
154
|
async computeSchema(node, context) {
|
|
142
|
-
const transformer = this.getTransformer(node, context
|
|
155
|
+
const transformer = this.getTransformer(node, context); // leave the next line commented out, it is used for debugging
|
|
143
156
|
// console.log('transformer', transformer.constructor.name, node.getText());
|
|
144
157
|
|
|
145
158
|
return transformer.transform(node, context);
|
|
146
159
|
}
|
|
160
|
+
|
|
161
|
+
async getComponentIDByPath(file) {
|
|
162
|
+
if (!this.workspace) {
|
|
163
|
+
return null;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
return this.workspace.getComponentIdByPath(file);
|
|
167
|
+
}
|
|
147
168
|
/**
|
|
148
169
|
* select the correct transformer for a node.
|
|
149
170
|
*/
|
|
150
171
|
|
|
151
172
|
|
|
152
|
-
getTransformer(node,
|
|
173
|
+
getTransformer(node, context) {
|
|
153
174
|
const transformers = (0, _lodash().flatten)(this.schemaTransformerSlot.values());
|
|
154
175
|
const transformer = transformers.find(singleTransformer => singleTransformer.predicate(node));
|
|
155
|
-
if (!transformer) throw new (_exceptions().TransformerNotFound)(node, component);
|
|
176
|
+
if (!transformer) throw new (_exceptions().TransformerNotFound)(node, context.component, context.getLocation(node));
|
|
156
177
|
return transformer;
|
|
157
178
|
}
|
|
158
179
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["TypeScriptExtractor","constructor","tsconfig","schemaTransformerSlot","tsMain","rootPath","undefined","parseSourceFile","file","ts","createSourceFile","path","contents","toString","ScriptTarget","Latest","compilerOptions","extract","component","tsserver","getTsServer","mainFile","mainAst","context","createContext","exportNames","computeExportedIdentifiers","setExports","ExportList","moduleSchema","computeSchema","flatExportsRecursively","apiScheme","location","getLocation","APISchema","node","transformer","getTransformer","getIdentifiers","TransformerNotFound","SchemaExtractorContext","getTsserverClient","initTsserverClient","transform","transformers","flatten","values","find","singleTransformer","predicate"],"sources":["typescript.extractor.ts"],"sourcesContent":["import ts, { Node } from 'typescript';\nimport { SchemaExtractor } from '@teambit/schema';\nimport { TsserverClient } from '@teambit/ts-server';\nimport { SchemaNode, APISchema, Module } from '@teambit/semantics.entities.semantic-schema';\nimport { Component } from '@teambit/component';\
|
|
1
|
+
{"version":3,"names":["TypeScriptExtractor","constructor","tsconfig","schemaTransformerSlot","tsMain","rootPath","depResolver","workspace","undefined","parseSourceFile","file","ts","createSourceFile","path","contents","toString","ScriptTarget","Latest","compilerOptions","extract","component","tsserver","getTsServer","mainFile","mainAst","context","createContext","exportNames","computeExportedIdentifiers","setExports","ExportList","moduleSchema","computeSchema","flatExportsRecursively","apiScheme","location","getLocation","APISchema","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 } 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) {\n return ts.createSourceFile(\n file.path,\n file.contents.toString('utf8'),\n ts.ScriptTarget.Latest,\n true,\n this.tsconfig.compilerOptions\n );\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);\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;;EAAA;AAAA;;AAKA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAGA;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,MAAMA,mBAAN,CAAqD;EAC1DC,WAAW,CACDC,QADC,EAEDC,qBAFC,EAGDC,MAHC,EAIDC,QAJC,EAKDC,WALC,EAMDC,SANC,EAOT;IAAA,KANQL,QAMR,GANQA,QAMR;IAAA,KALQC,qBAKR,GALQA,qBAKR;IAAA,KAJQC,MAIR,GAJQA,MAIR;IAAA,KAHQC,QAGR,GAHQA,QAGR;IAAA,KAFQC,WAER,GAFQA,WAER;IAAA,KADQC,SACR,GADQA,SACR;IAAA,kDAiD6CC,SAjD7C;EAAE;;EAEJC,eAAe,CAACC,IAAD,EAAsB;IACnC,OAAOC,qBAAA,CAAGC,gBAAH,CACLF,IAAI,CAACG,IADA,EAELH,IAAI,CAACI,QAAL,CAAcC,QAAd,CAAuB,MAAvB,CAFK,EAGLJ,qBAAA,CAAGK,YAAH,CAAgBC,MA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M6B,YAAY,GAAG,IAAAC,iBAAA,EAAQ,KAAKpD,qBAAL,CAA2BqD,MAA3B,EAAR,CAArB;IACA,MAAMjB,WAAW,GAAGe,YAAY,CAACG,IAAb,CAAmBC,iBAAD,IAAuBA,iBAAiB,CAACC,SAAlB,CAA4BrB,IAA5B,CAAzC,CAApB;IAEA,IAAI,CAACC,WAAL,EAAkB,MAAM,KAAIG,iCAAJ,EAAwBJ,IAAxB,EAA8Bb,OAAO,CAACL,SAAtC,EAAiDK,OAAO,CAACW,WAAR,CAAoBE,IAApB,CAAjD,CAAN;IAElB,OAAOC,WAAP;EACD;;AAlGyD"}
|
|
@@ -7,6 +7,7 @@ import { SchemaExtractor, SchemaMain } from '@teambit/schema';
|
|
|
7
7
|
import { PackageJsonProps } from '@teambit/pkg';
|
|
8
8
|
import { TypescriptConfigMutator } from '@teambit/typescript.modules.ts-config-mutator';
|
|
9
9
|
import type { Workspace } from '@teambit/workspace';
|
|
10
|
+
import { DependencyResolverMain } from '@teambit/dependency-resolver';
|
|
10
11
|
import { TsserverClient, TsserverClientOpts } from '@teambit/ts-server';
|
|
11
12
|
import { AspectLoaderMain } from '@teambit/aspect-loader';
|
|
12
13
|
import type { Component } from '@teambit/component';
|
|
@@ -20,7 +21,8 @@ export declare class TypescriptMain {
|
|
|
20
21
|
private logger;
|
|
21
22
|
private schemaTransformerSlot;
|
|
22
23
|
private workspace;
|
|
23
|
-
|
|
24
|
+
private depResolver;
|
|
25
|
+
constructor(logger: Logger, schemaTransformerSlot: SchemaTransformerSlot, workspace: Workspace, depResolver: DependencyResolverMain);
|
|
24
26
|
private tsServer;
|
|
25
27
|
/**
|
|
26
28
|
* create a new compiler.
|
|
@@ -91,6 +93,13 @@ export declare class TypescriptMain {
|
|
|
91
93
|
static runtime: import("@teambit/harmony").RuntimeDefinition;
|
|
92
94
|
static dependencies: import("@teambit/harmony").Aspect[];
|
|
93
95
|
static slots: ((registerFn: () => string) => SlotRegistry<SchemaTransformer[]>)[];
|
|
94
|
-
static provider([schema, loggerExt, aspectLoader, workspace, cli
|
|
96
|
+
static provider([schema, loggerExt, aspectLoader, workspace, cli, depResolver]: [
|
|
97
|
+
SchemaMain,
|
|
98
|
+
LoggerMain,
|
|
99
|
+
AspectLoaderMain,
|
|
100
|
+
Workspace,
|
|
101
|
+
CLIMain,
|
|
102
|
+
DependencyResolverMain
|
|
103
|
+
], config: any, [schemaTransformerSlot]: [SchemaTransformerSlot]): Promise<TypescriptMain>;
|
|
95
104
|
}
|
|
96
105
|
export declare function runTransformersWithContext(config: TypescriptConfigMutator, transformers: TsConfigTransformer[] | undefined, context: TsConfigTransformContext): TypescriptConfigMutator;
|
|
@@ -96,6 +96,16 @@ function _workspace() {
|
|
|
96
96
|
return data;
|
|
97
97
|
}
|
|
98
98
|
|
|
99
|
+
function _dependencyResolver() {
|
|
100
|
+
const data = require("@teambit/dependency-resolver");
|
|
101
|
+
|
|
102
|
+
_dependencyResolver = function () {
|
|
103
|
+
return data;
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
return data;
|
|
107
|
+
}
|
|
108
|
+
|
|
99
109
|
function _pMapSeries() {
|
|
100
110
|
const data = _interopRequireDefault(require("p-map-series"));
|
|
101
111
|
|
|
@@ -197,10 +207,11 @@ function _checkTypes() {
|
|
|
197
207
|
}
|
|
198
208
|
|
|
199
209
|
class TypescriptMain {
|
|
200
|
-
constructor(logger, schemaTransformerSlot, workspace) {
|
|
210
|
+
constructor(logger, schemaTransformerSlot, workspace, depResolver) {
|
|
201
211
|
this.logger = logger;
|
|
202
212
|
this.schemaTransformerSlot = schemaTransformerSlot;
|
|
203
213
|
this.workspace = workspace;
|
|
214
|
+
this.depResolver = depResolver;
|
|
204
215
|
(0, _defineProperty2().default)(this, "tsServer", void 0);
|
|
205
216
|
}
|
|
206
217
|
|
|
@@ -308,7 +319,7 @@ class TypescriptMain {
|
|
|
308
319
|
|
|
309
320
|
|
|
310
321
|
createSchemaExtractor(tsconfig, path) {
|
|
311
|
-
return new (_typescript2().TypeScriptExtractor)(tsconfig, this.schemaTransformerSlot, this, path || this.workspace.path);
|
|
322
|
+
return new (_typescript2().TypeScriptExtractor)(tsconfig, this.schemaTransformerSlot, this, path || this.workspace.path, this.depResolver, this.workspace);
|
|
312
323
|
}
|
|
313
324
|
/**
|
|
314
325
|
* add the default package json properties to the component
|
|
@@ -375,12 +386,12 @@ class TypescriptMain {
|
|
|
375
386
|
};
|
|
376
387
|
}
|
|
377
388
|
|
|
378
|
-
static async provider([schema, loggerExt, aspectLoader, workspace, cli], config, [schemaTransformerSlot]) {
|
|
389
|
+
static async provider([schema, loggerExt, aspectLoader, workspace, cli, depResolver], config, [schemaTransformerSlot]) {
|
|
379
390
|
schema.registerParser(new (_typescript5().TypeScriptParser)());
|
|
380
391
|
const logger = loggerExt.createLogger(_typescript3().TypescriptAspect.id);
|
|
381
392
|
aspectLoader.registerPlugins([new (_schemaTransformer().SchemaTransformerPlugin)(schemaTransformerSlot)]);
|
|
382
|
-
const tsMain = new TypescriptMain(logger, schemaTransformerSlot, workspace);
|
|
383
|
-
schemaTransformerSlot.register([new (_transformers().ExportDeclaration)(), new (_transformers().FunctionDeclaration)(), new (_transformers().MethodDeclaration)(), new (_transformers().PropertyDeclaration)(), new (_transformers().VariableStatementTransformer)(), new (_transformers().VariableDeclaration)(), new (_transformers().Constructor)(), new (_transformers().SourceFileTransformer)(), new (_transformers().TypeAliasTransformer)(), new (_transformers().ClassDecelerationTransformer)(), new (_transformers().PropertySignature)(), new (_transformers().LiteralTypeTransformer)(), new (_transformers().IndexSignature)(), new (_transformers().InterfaceDeclarationTransformer)(), new (_transformers().MethodSignatureTransformer)()]);
|
|
393
|
+
const tsMain = new TypescriptMain(logger, schemaTransformerSlot, workspace, depResolver);
|
|
394
|
+
schemaTransformerSlot.register([new (_transformers().ExportDeclaration)(), new (_transformers().FunctionDeclaration)(), new (_transformers().MethodDeclaration)(), new (_transformers().PropertyDeclaration)(), new (_transformers().VariableStatementTransformer)(), new (_transformers().VariableDeclaration)(), new (_transformers().Constructor)(), new (_transformers().SourceFileTransformer)(), new (_transformers().TypeAliasTransformer)(), new (_transformers().ClassDecelerationTransformer)(), new (_transformers().PropertySignature)(), new (_transformers().LiteralTypeTransformer)(), new (_transformers().IndexSignature)(), new (_transformers().InterfaceDeclarationTransformer)(), new (_transformers().MethodSignatureTransformer)(), new (_transformers().EnumDeclarationTransformer)()]);
|
|
384
395
|
|
|
385
396
|
if (workspace) {
|
|
386
397
|
workspace.registerOnPreWatch(tsMain.onPreWatch.bind(this));
|
|
@@ -397,7 +408,7 @@ class TypescriptMain {
|
|
|
397
408
|
|
|
398
409
|
exports.TypescriptMain = TypescriptMain;
|
|
399
410
|
(0, _defineProperty2().default)(TypescriptMain, "runtime", _cli().MainRuntime);
|
|
400
|
-
(0, _defineProperty2().default)(TypescriptMain, "dependencies", [_schema().SchemaAspect, _logger().LoggerAspect, _aspectLoader().default, _workspace().WorkspaceAspect, _cli().CLIAspect]);
|
|
411
|
+
(0, _defineProperty2().default)(TypescriptMain, "dependencies", [_schema().SchemaAspect, _logger().LoggerAspect, _aspectLoader().default, _workspace().WorkspaceAspect, _cli().CLIAspect, _dependencyResolver().DependencyResolverAspect]);
|
|
401
412
|
(0, _defineProperty2().default)(TypescriptMain, "slots", [_harmony().Slot.withType()]);
|
|
402
413
|
|
|
403
414
|
_typescript3().TypescriptAspect.addRuntime(TypescriptMain);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["TypescriptMain","constructor","logger","schemaTransformerSlot","workspace","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","MethodDeclaration","PropertyDeclaration","VariableStatementTransformer","VariableDeclaration","Constructor","SourceFileTransformer","TypeAliasTransformer","ClassDecelerationTransformer","PropertySignature","LiteralTypeTransformer","IndexSignature","InterfaceDeclarationTransformer","MethodSignatureTransformer","registerOnPreWatch","bind","registerOnComponentChange","registerOnComponentAdd","checkTypesCmd","CheckTypesCmd","MainRuntime","SchemaAspect","LoggerAspect","AspectLoaderAspect","WorkspaceAspect","CLIAspect","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 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 MethodDeclaration,\n PropertyDeclaration,\n VariableStatementTransformer,\n VariableDeclaration,\n SourceFileTransformer,\n ClassDecelerationTransformer,\n Constructor,\n PropertySignature,\n LiteralTypeTransformer,\n IndexSignature,\n InterfaceDeclarationTransformer,\n MethodSignatureTransformer,\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 ) {}\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(tsconfig, this.schemaTransformerSlot, this, path || this.workspace.path);\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 = [SchemaAspect, LoggerAspect, AspectLoaderAspect, WorkspaceAspect, CLIAspect];\n static slots = [Slot.withType<SchemaTransformer[]>()];\n\n static async provider(\n [schema, loggerExt, aspectLoader, workspace, cli]: [SchemaMain, LoggerMain, AspectLoaderMain, Workspace, CLIMain],\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);\n schemaTransformerSlot.register([\n new ExportDeclaration(),\n new FunctionDeclaration(),\n new MethodDeclaration(),\n new PropertyDeclaration(),\n new VariableStatementTransformer(),\n new VariableDeclaration(),\n new Constructor(),\n new SourceFileTransformer(),\n new TypeAliasTransformer(),\n new ClassDecelerationTransformer(),\n new PropertySignature(),\n new LiteralTypeTransformer(),\n new IndexSignature(),\n new InterfaceDeclarationTransformer(),\n new MethodSignatureTransformer(),\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;;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;AA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0CAAJ,GAf6B,CAA/B;;IAkBA,IAAI1F,SAAJ,EAAe;MACbA,SAAS,CAAC2F,kBAAV,CAA6BjB,MAAM,CAACvB,UAAP,CAAkByC,IAAlB,CAAuB,IAAvB,CAA7B;MACA5F,SAAS,CAAC6F,yBAAV,CAAoCnB,MAAM,CAAChB,iBAAP,CAAyBkC,IAAzB,CAA8B,IAA9B,CAApC;MACA5F,SAAS,CAAC8F,sBAAV,CAAiCpB,MAAM,CAAChB,iBAAP,CAAyBkC,IAAzB,CAA8B,IAA9B,CAAjC;IACD;;IAED,MAAMG,aAAa,GAAG,KAAIC,2BAAJ,EAAkBtB,MAAlB,EAA0B1E,SAA1B,EAAqCF,MAArC,CAAtB;IACAsE,GAAG,CAACO,QAAJ,CAAaoB,aAAb;IAEA,OAAOrB,MAAP;EACD;;AAnNyB;;;gCAAf9E,c,aA0KMqG,kB;gCA1KNrG,c,kBA2KW,CAACsG,sBAAD,EAAeC,sBAAf,EAA6BC,uBAA7B,EAAiDC,4BAAjD,EAAkEC,gBAAlE,C;gCA3KX1G,c,WA4KI,CAAC2G,eAAA,CAAKC,QAAL,EAAD,C;;AA0CjB3F,+BAAA,CAAiB4F,UAAjB,CAA4B7G,cAA5B;;AAEO,SAASc,0BAAT,CACLqB,MADK,EAEL5B,YAAmC,GAAG,EAFjC,EAGLuG,OAHK,EAIoB;EACzB,IAAI,CAACC,KAAK,CAACC,OAAN,CAAczG,YAAd,CAAL,EAAkC,OAAO4B,MAAP;EAClC,MAAM8E,SAAS,GAAG1G,YAAY,CAAC2G,MAAb,CAAoB,CAACC,GAAD,EAAMC,WAAN,KAAsB;IAC1D,OAAOA,WAAW,CAACD,GAAD,EAAML,OAAN,CAAlB;EACD,CAFiB,EAEf3E,MAFe,CAAlB;EAGA,OAAO8E,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","MethodDeclaration","PropertyDeclaration","VariableStatementTransformer","VariableDeclaration","Constructor","SourceFileTransformer","TypeAliasTransformer","ClassDecelerationTransformer","PropertySignature","LiteralTypeTransformer","IndexSignature","InterfaceDeclarationTransformer","MethodSignatureTransformer","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 MethodDeclaration,\n PropertyDeclaration,\n VariableStatementTransformer,\n VariableDeclaration,\n SourceFileTransformer,\n ClassDecelerationTransformer,\n Constructor,\n PropertySignature,\n LiteralTypeTransformer,\n IndexSignature,\n InterfaceDeclarationTransformer,\n MethodSignatureTransformer,\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 MethodDeclaration(),\n new PropertyDeclaration(),\n new VariableStatementTransformer(),\n new VariableDeclaration(),\n new Constructor(),\n new SourceFileTransformer(),\n new TypeAliasTransformer(),\n new ClassDecelerationTransformer(),\n new PropertySignature(),\n new LiteralTypeTransformer(),\n new IndexSignature(),\n new InterfaceDeclarationTransformer(),\n new MethodSignatureTransformer(),\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;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wG,sBADoB,EAEpBC,sBAFoB,EAGpBC,uBAHoB,EAIpBC,4BAJoB,EAKpBC,gBALoB,EAMpBC,8CANoB,C;gCAnLX7G,c,WA2LI,CAAC8G,eAAA,CAAKC,QAAL,EAAD,C;;AAkDjB7F,+BAAA,CAAiB8F,UAAjB,CAA4BhH,cAA5B;;AAEO,SAASe,0BAAT,CACLqB,MADK,EAEL5B,YAAmC,GAAG,EAFjC,EAGLyG,OAHK,EAIoB;EACzB,IAAI,CAACC,KAAK,CAACC,OAAN,CAAc3G,YAAd,CAAL,EAAkC,OAAO4B,MAAP;EAClC,MAAMgF,SAAS,GAAG5G,YAAY,CAAC6G,MAAb,CAAoB,CAACC,GAAD,EAAMC,WAAN,KAAsB;IAC1D,OAAOA,WAAW,CAACD,GAAD,EAAML,OAAN,CAAlB;EACD,CAFiB,EAEf7E,MAFe,CAAlB;EAGA,OAAOgF,SAAP;AACD"}
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import ts, { Node } from 'typescript';
|
|
2
2
|
import { Component } from '@teambit/component';
|
|
3
|
+
import { Location } from '@teambit/semantics.entities.semantic-schema';
|
|
3
4
|
|
|
4
5
|
export class TransformerNotFound extends Error {
|
|
5
|
-
constructor(readonly node: Node, readonly component: Component) {
|
|
6
|
+
constructor(readonly node: Node, readonly component: Component, location: Location) {
|
|
6
7
|
super(
|
|
7
8
|
`typescript: could not find schema transformer for node of kind ${node.kind} (${
|
|
8
9
|
ts.SyntaxKind[node.kind]
|
|
9
10
|
}) in component ${component.id.toString()}.
|
|
10
|
-
|
|
11
|
+
location: ${location.file}, line: ${location.line}, character: ${location.character}.
|
|
12
|
+
node-text: ${node.getText()}`
|
|
11
13
|
);
|
|
12
14
|
}
|
|
13
15
|
}
|
|
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.739",
|
|
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.739"
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"lodash": "4.17.21",
|
|
@@ -18,20 +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.739",
|
|
22
22
|
"@teambit/typescript.modules.ts-config-mutator": "0.0.68",
|
|
23
|
-
"@teambit/component": "0.0.
|
|
24
|
-
"@teambit/
|
|
23
|
+
"@teambit/component": "0.0.739",
|
|
24
|
+
"@teambit/dependency-resolver": "0.0.739",
|
|
25
|
+
"@teambit/semantics.entities.semantic-schema": "0.0.12",
|
|
25
26
|
"@teambit/ts-server": "0.0.32",
|
|
26
|
-
"@teambit/aspect-loader": "0.0.
|
|
27
|
+
"@teambit/aspect-loader": "0.0.739",
|
|
27
28
|
"@teambit/bit-error": "0.0.394",
|
|
28
|
-
"@teambit/builder": "0.0.
|
|
29
|
-
"@teambit/isolator": "0.0.
|
|
29
|
+
"@teambit/builder": "0.0.739",
|
|
30
|
+
"@teambit/isolator": "0.0.739",
|
|
30
31
|
"@teambit/logger": "0.0.583",
|
|
31
|
-
"@teambit/schema": "0.0.
|
|
32
|
+
"@teambit/schema": "0.0.739",
|
|
33
|
+
"@teambit/workspace": "0.0.739",
|
|
32
34
|
"@teambit/cli": "0.0.491",
|
|
33
|
-
"@teambit/pkg": "0.0.
|
|
34
|
-
"@teambit/workspace": "0.0.738"
|
|
35
|
+
"@teambit/pkg": "0.0.739"
|
|
35
36
|
},
|
|
36
37
|
"devDependencies": {
|
|
37
38
|
"@types/lodash": "4.14.165",
|
|
@@ -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.739/dist/typescript.composition.js')]
|
|
2
|
+
export const overview = [require('/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.typescript_typescript@0.0.739/dist/typescript.docs.mdx')]
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import pMapSeries from 'p-map-series';
|
|
2
2
|
import { compact } from 'lodash';
|
|
3
3
|
import { ClassSchema, GetAccessorSchema, SetAccessorSchema } from '@teambit/semantics.entities.semantic-schema';
|
|
4
|
-
import ts, { Node, ClassDeclaration } from 'typescript';
|
|
4
|
+
import ts, { Node, ClassDeclaration, isSemicolonClassElement } from 'typescript';
|
|
5
5
|
import { SchemaTransformer } from '../schema-transformer';
|
|
6
6
|
import { SchemaExtractorContext } from '../schema-extractor-context';
|
|
7
7
|
import { ExportIdentifier } from '../export-identifier';
|
|
@@ -29,6 +29,9 @@ export class ClassDecelerationTransformer implements SchemaTransformer {
|
|
|
29
29
|
if (isPrivate) {
|
|
30
30
|
return null;
|
|
31
31
|
}
|
|
32
|
+
if (isSemicolonClassElement(member)) {
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
32
35
|
switch (member.kind) {
|
|
33
36
|
case ts.SyntaxKind.GetAccessor: {
|
|
34
37
|
const getter = member as ts.GetAccessorDeclaration;
|