@teambit/typescript 0.0.741 → 0.0.744
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/transformers/class-deceleration.js +10 -40
- package/dist/transformers/class-deceleration.js.map +1 -1
- package/dist/transformers/index.d.ts +0 -6
- package/dist/transformers/index.js +0 -96
- package/dist/transformers/index.js.map +1 -1
- package/dist/transformers/interface-declaration.js +13 -6
- package/dist/transformers/interface-declaration.js.map +1 -1
- package/dist/transformers/utils/class-element-to-schema.d.ts +4 -0
- package/dist/transformers/utils/class-element-to-schema.js +122 -0
- package/dist/transformers/utils/class-element-to-schema.js.map +1 -0
- package/dist/transformers/utils/jsdoc-to-doc-schema.d.ts +4 -0
- package/dist/transformers/utils/jsdoc-to-doc-schema.js +163 -0
- package/dist/transformers/utils/jsdoc-to-doc-schema.js.map +1 -0
- package/dist/transformers/utils/to-function-schema.d.ts +1 -1
- package/dist/transformers/utils/to-function-schema.js +17 -7
- package/dist/transformers/utils/to-function-schema.js.map +1 -1
- package/dist/transformers/utils/type-element-to-schema.d.ts +7 -0
- package/dist/transformers/utils/type-element-to-schema.js +134 -0
- package/dist/transformers/utils/type-element-to-schema.js.map +1 -0
- package/dist/transformers/utils/type-node-to-schema.js +32 -7
- package/dist/transformers/utils/type-node-to-schema.js.map +1 -1
- package/dist/transformers/variable-declaration.js +15 -1
- package/dist/transformers/variable-declaration.js.map +1 -1
- package/dist/typescript.extractor.js +1 -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/package-tar/teambit-typescript-0.0.744.tgz +0 -0
- package/package.json +17 -17
- package/{preview-1653494536947.js → preview-1653827208409.js} +2 -2
- package/transformers/class-deceleration.ts +7 -26
- package/transformers/index.ts +0 -6
- package/transformers/interface-declaration.ts +4 -6
- package/transformers/utils/class-element-to-schema.ts +61 -0
- package/transformers/utils/jsdoc-to-doc-schema.ts +81 -0
- package/transformers/utils/to-function-schema.ts +12 -8
- package/transformers/utils/type-element-to-schema.ts +72 -0
- package/transformers/utils/type-node-to-schema.ts +15 -6
- package/transformers/variable-declaration.ts +5 -2
- package/dist/transformers/constructor.d.ts +0 -10
- package/dist/transformers/constructor.js +0 -70
- package/dist/transformers/constructor.js.map +0 -1
- package/dist/transformers/index-signature.d.ts +0 -9
- package/dist/transformers/index-signature.js +0 -71
- package/dist/transformers/index-signature.js.map +0 -1
- package/dist/transformers/method-declaration.d.ts +0 -11
- package/dist/transformers/method-declaration.js +0 -65
- package/dist/transformers/method-declaration.js.map +0 -1
- package/dist/transformers/method-signature.d.ts +0 -10
- package/dist/transformers/method-signature.js +0 -53
- package/dist/transformers/method-signature.js.map +0 -1
- package/dist/transformers/property-declaration.d.ts +0 -11
- package/dist/transformers/property-declaration.js +0 -80
- package/dist/transformers/property-declaration.js.map +0 -1
- package/dist/transformers/property-signature.d.ts +0 -10
- package/dist/transformers/property-signature.js +0 -72
- package/dist/transformers/property-signature.js.map +0 -1
- package/package-tar/teambit-typescript-0.0.741.tgz +0 -0
- package/transformers/constructor.ts +0 -22
- package/transformers/index-signature.ts +0 -22
- package/transformers/method-declaration.ts +0 -24
- package/transformers/method-signature.ts +0 -23
- package/transformers/property-declaration.ts +0 -30
- package/transformers/property-signature.ts +0 -28
|
@@ -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","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;;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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AHK,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
|
+
{"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":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pBC,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"}
|
|
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.744",
|
|
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.744"
|
|
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.744",
|
|
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.744",
|
|
24
|
+
"@teambit/dependency-resolver": "0.0.744",
|
|
25
|
+
"@teambit/semantics.entities.semantic-schema": "0.0.16",
|
|
26
26
|
"@teambit/ts-server": "0.0.32",
|
|
27
|
-
"@teambit/aspect-loader": "0.0.
|
|
27
|
+
"@teambit/aspect-loader": "0.0.744",
|
|
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.744",
|
|
30
|
+
"@teambit/isolator": "0.0.744",
|
|
31
|
+
"@teambit/logger": "0.0.586",
|
|
32
|
+
"@teambit/schema": "0.0.744",
|
|
33
|
+
"@teambit/workspace": "0.0.744",
|
|
34
|
+
"@teambit/cli": "0.0.493",
|
|
35
|
+
"@teambit/pkg": "0.0.744"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"@types/lodash": "4.14.165",
|
|
@@ -45,10 +45,10 @@
|
|
|
45
45
|
"@types/jest": "^26.0.0",
|
|
46
46
|
"@types/react-dom": "^17.0.5",
|
|
47
47
|
"@types/node": "12.20.4",
|
|
48
|
-
"@teambit/typescript.aspect-docs.typescript": "0.0.
|
|
48
|
+
"@teambit/typescript.aspect-docs.typescript": "0.0.138"
|
|
49
49
|
},
|
|
50
50
|
"peerDependencies": {
|
|
51
|
-
"@teambit/legacy": "1.0.
|
|
51
|
+
"@teambit/legacy": "1.0.273",
|
|
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.273",
|
|
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.744/dist/typescript.composition.js')]
|
|
2
|
+
export const overview = [require('/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.typescript_typescript@0.0.744/dist/typescript.docs.mdx')]
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import pMapSeries from 'p-map-series';
|
|
2
2
|
import { compact } from 'lodash';
|
|
3
|
-
import { ClassSchema
|
|
4
|
-
import ts, { Node, ClassDeclaration
|
|
3
|
+
import { ClassSchema } from '@teambit/semantics.entities.semantic-schema';
|
|
4
|
+
import ts, { Node, ClassDeclaration } from 'typescript';
|
|
5
5
|
import { SchemaTransformer } from '../schema-transformer';
|
|
6
6
|
import { SchemaExtractorContext } from '../schema-extractor-context';
|
|
7
7
|
import { ExportIdentifier } from '../export-identifier';
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
8
|
+
import { jsDocToDocSchema } from './utils/jsdoc-to-doc-schema';
|
|
9
|
+
import { classElementToSchema } from './utils/class-element-to-schema';
|
|
10
10
|
|
|
11
11
|
export class ClassDecelerationTransformer implements SchemaTransformer {
|
|
12
12
|
predicate(node: Node) {
|
|
@@ -29,28 +29,9 @@ export class ClassDecelerationTransformer implements SchemaTransformer {
|
|
|
29
29
|
if (isPrivate) {
|
|
30
30
|
return null;
|
|
31
31
|
}
|
|
32
|
-
|
|
33
|
-
return null;
|
|
34
|
-
}
|
|
35
|
-
switch (member.kind) {
|
|
36
|
-
case ts.SyntaxKind.GetAccessor: {
|
|
37
|
-
const getter = member as ts.GetAccessorDeclaration;
|
|
38
|
-
const info = await context.getQuickInfo(getter.name);
|
|
39
|
-
const displaySig = info?.body?.displayString || '';
|
|
40
|
-
const typeStr = parseTypeFromQuickInfo(info);
|
|
41
|
-
const type = await context.resolveType(getter, typeStr);
|
|
42
|
-
return new GetAccessorSchema(context.getLocation(getter), getter.name.getText(), type, displaySig);
|
|
43
|
-
}
|
|
44
|
-
case ts.SyntaxKind.SetAccessor: {
|
|
45
|
-
const setter = member as ts.SetAccessorDeclaration;
|
|
46
|
-
const params = await getParams(setter.parameters, context);
|
|
47
|
-
const displaySig = await context.getQuickInfoDisplayString(setter.name);
|
|
48
|
-
return new SetAccessorSchema(context.getLocation(setter), setter.name.getText(), params[0], displaySig);
|
|
49
|
-
}
|
|
50
|
-
default:
|
|
51
|
-
return context.computeSchema(member);
|
|
52
|
-
}
|
|
32
|
+
return classElementToSchema(member, context);
|
|
53
33
|
});
|
|
54
|
-
|
|
34
|
+
const doc = await jsDocToDocSchema(node, context);
|
|
35
|
+
return new ClassSchema(className, compact(members), context.getLocation(node), doc);
|
|
55
36
|
}
|
|
56
37
|
}
|
package/transformers/index.ts
CHANGED
|
@@ -1,16 +1,10 @@
|
|
|
1
1
|
export { ExportDeclaration } from './export-declaration';
|
|
2
2
|
export { FunctionDeclaration } from './function-declaration';
|
|
3
|
-
export { MethodDeclaration } from './method-declaration';
|
|
4
|
-
export { PropertyDeclaration } from './property-declaration';
|
|
5
3
|
export { VariableStatementTransformer } from './variable-statement';
|
|
6
4
|
export { VariableDeclaration } from './variable-declaration';
|
|
7
5
|
export { SourceFileTransformer } from './source-file-transformer';
|
|
8
6
|
export { TypeAliasTransformer } from './type-alias';
|
|
9
7
|
export { ClassDecelerationTransformer } from './class-deceleration';
|
|
10
|
-
export { Constructor } from './constructor';
|
|
11
|
-
export { PropertySignature } from './property-signature';
|
|
12
8
|
export { LiteralTypeTransformer } from './literal-type';
|
|
13
|
-
export { IndexSignature } from './index-signature';
|
|
14
9
|
export { InterfaceDeclarationTransformer } from './interface-declaration';
|
|
15
|
-
export { MethodSignatureTransformer } from './method-signature';
|
|
16
10
|
export { EnumDeclarationTransformer } from './enum-declaration';
|
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Node, InterfaceDeclaration, SyntaxKind } from 'typescript';
|
|
2
2
|
import pMapSeries from 'p-map-series';
|
|
3
3
|
import { InterfaceSchema } from '@teambit/semantics.entities.semantic-schema';
|
|
4
4
|
import { SchemaTransformer } from '../schema-transformer';
|
|
5
5
|
import { SchemaExtractorContext } from '../schema-extractor-context';
|
|
6
6
|
import { ExportIdentifier } from '../export-identifier';
|
|
7
|
+
import { typeElementToSchema } from './utils/type-element-to-schema';
|
|
7
8
|
|
|
8
9
|
export class InterfaceDeclarationTransformer implements SchemaTransformer {
|
|
9
10
|
predicate(node: Node) {
|
|
10
|
-
return node.kind ===
|
|
11
|
+
return node.kind === SyntaxKind.InterfaceDeclaration;
|
|
11
12
|
}
|
|
12
13
|
|
|
13
14
|
async getIdentifiers(node: InterfaceDeclaration): Promise<ExportIdentifier[]> {
|
|
@@ -15,10 +16,7 @@ export class InterfaceDeclarationTransformer implements SchemaTransformer {
|
|
|
15
16
|
}
|
|
16
17
|
|
|
17
18
|
async transform(interfaceDec: InterfaceDeclaration, context: SchemaExtractorContext) {
|
|
18
|
-
const members = await pMapSeries(interfaceDec.members,
|
|
19
|
-
const typeSchema = await context.computeSchema(member);
|
|
20
|
-
return typeSchema;
|
|
21
|
-
});
|
|
19
|
+
const members = await pMapSeries(interfaceDec.members, (member) => typeElementToSchema(member, context));
|
|
22
20
|
return new InterfaceSchema(context.getLocation(interfaceDec), interfaceDec.name.getText(), members);
|
|
23
21
|
}
|
|
24
22
|
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ClassElement,
|
|
3
|
+
ConstructorDeclaration,
|
|
4
|
+
GetAccessorDeclaration,
|
|
5
|
+
IndexSignatureDeclaration,
|
|
6
|
+
MethodDeclaration,
|
|
7
|
+
PropertyDeclaration,
|
|
8
|
+
SetAccessorDeclaration,
|
|
9
|
+
SyntaxKind,
|
|
10
|
+
} from 'typescript';
|
|
11
|
+
import { ConstructorSchema, SchemaNode, VariableSchema } from '@teambit/semantics.entities.semantic-schema';
|
|
12
|
+
import { SchemaExtractorContext } from '../../schema-extractor-context';
|
|
13
|
+
import { getParams } from './get-params';
|
|
14
|
+
import { getAccessor, indexSignature, setAccessor } from './type-element-to-schema';
|
|
15
|
+
import { parseTypeFromQuickInfo } from './parse-type-from-quick-info';
|
|
16
|
+
import { toFunctionLikeSchema } from './to-function-schema';
|
|
17
|
+
|
|
18
|
+
export async function classElementToSchema(
|
|
19
|
+
node: ClassElement,
|
|
20
|
+
context: SchemaExtractorContext
|
|
21
|
+
): Promise<SchemaNode | null> {
|
|
22
|
+
switch (node.kind) {
|
|
23
|
+
case SyntaxKind.Constructor:
|
|
24
|
+
return constructor(node as ConstructorDeclaration, context);
|
|
25
|
+
case SyntaxKind.PropertyDeclaration:
|
|
26
|
+
return propertyDeclaration(node as PropertyDeclaration, context);
|
|
27
|
+
case SyntaxKind.MethodDeclaration:
|
|
28
|
+
return methodDeclaration(node as MethodDeclaration, context);
|
|
29
|
+
case SyntaxKind.GetAccessor:
|
|
30
|
+
return getAccessor(node as GetAccessorDeclaration, context);
|
|
31
|
+
case SyntaxKind.SetAccessor:
|
|
32
|
+
return setAccessor(node as SetAccessorDeclaration, context);
|
|
33
|
+
case SyntaxKind.IndexSignature:
|
|
34
|
+
return indexSignature(node as IndexSignatureDeclaration, context);
|
|
35
|
+
case SyntaxKind.ClassStaticBlockDeclaration: // not sure what is it, but the name sounds like not something we need
|
|
36
|
+
case SyntaxKind.SemicolonClassElement: // seems to be just a semicolon
|
|
37
|
+
return null;
|
|
38
|
+
default:
|
|
39
|
+
// should never be here unless typescript added new class elements
|
|
40
|
+
throw new Error(`unrecognized ClassElement type. got ${node.kind}`);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
async function constructor(node: ConstructorDeclaration, context: SchemaExtractorContext) {
|
|
45
|
+
const args = await getParams(node.parameters, context);
|
|
46
|
+
return new ConstructorSchema(context.getLocation(node), args);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
async function propertyDeclaration(node: PropertyDeclaration, context: SchemaExtractorContext) {
|
|
50
|
+
const name = node.name.getText();
|
|
51
|
+
const info = await context.getQuickInfo(node.name);
|
|
52
|
+
const displaySig = info?.body?.displayString;
|
|
53
|
+
const typeStr = parseTypeFromQuickInfo(info);
|
|
54
|
+
const type = await context.resolveType(node, typeStr);
|
|
55
|
+
|
|
56
|
+
return new VariableSchema(context.getLocation(node), name, displaySig || '', type);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
async function methodDeclaration(node: MethodDeclaration, context: SchemaExtractorContext) {
|
|
60
|
+
return toFunctionLikeSchema(node, context);
|
|
61
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/* eslint-disable no-fallthrough */
|
|
2
|
+
import { getTextOfJSDocComment, JSDocReturnTag, JSDocTag, Node, SyntaxKind } from 'typescript';
|
|
3
|
+
import { getJsDoc, canHaveJsDoc } from 'tsutils';
|
|
4
|
+
import pMapSeries from 'p-map-series';
|
|
5
|
+
import { DocSchema, ReturnTagSchema, TagName, TagSchema } from '@teambit/semantics.entities.semantic-schema';
|
|
6
|
+
import { SchemaExtractorContext } from '../../schema-extractor-context';
|
|
7
|
+
import { typeNodeToSchema } from './type-node-to-schema';
|
|
8
|
+
|
|
9
|
+
export async function jsDocToDocSchema(node: Node, context: SchemaExtractorContext): Promise<DocSchema | undefined> {
|
|
10
|
+
if (!canHaveJsDoc(node)) {
|
|
11
|
+
return undefined;
|
|
12
|
+
}
|
|
13
|
+
const jsDocs = getJsDoc(node);
|
|
14
|
+
if (!jsDocs.length) {
|
|
15
|
+
return undefined;
|
|
16
|
+
}
|
|
17
|
+
// not sure how common it is to have multiple JSDocs. never seen it before.
|
|
18
|
+
// regardless, in typescript implementation of methods like `getJSDocDeprecatedTag()`, they use the first one. (`getFirstJSDocTag()`)
|
|
19
|
+
const jsDoc = jsDocs[0];
|
|
20
|
+
const location = context.getLocation(jsDoc);
|
|
21
|
+
const comment = getTextOfJSDocComment(jsDoc.comment);
|
|
22
|
+
const tags = jsDoc.tags ? await pMapSeries(jsDoc.tags, (tag) => tagParser(tag, context)) : undefined;
|
|
23
|
+
return new DocSchema(location, comment, tags);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
async function tagParser(tag: JSDocTag, context: SchemaExtractorContext): Promise<TagSchema> {
|
|
27
|
+
let tagName: TagName | string = tag.tagName.getText();
|
|
28
|
+
switch (tag.kind) {
|
|
29
|
+
case SyntaxKind.JSDocReturnTag:
|
|
30
|
+
return returnTag(tag as JSDocReturnTag, context);
|
|
31
|
+
case SyntaxKind.JSDocAugmentsTag:
|
|
32
|
+
tagName = TagName.augments;
|
|
33
|
+
case SyntaxKind.JSDocAuthorTag:
|
|
34
|
+
tagName = TagName.author;
|
|
35
|
+
case SyntaxKind.JSDocClassTag:
|
|
36
|
+
tagName = TagName.class;
|
|
37
|
+
case SyntaxKind.JSDocCallbackTag:
|
|
38
|
+
tagName = TagName.callback;
|
|
39
|
+
case SyntaxKind.JSDocPublicTag:
|
|
40
|
+
tagName = TagName.public;
|
|
41
|
+
case SyntaxKind.JSDocPrivateTag:
|
|
42
|
+
tagName = TagName.private;
|
|
43
|
+
case SyntaxKind.JSDocProtectedTag:
|
|
44
|
+
tagName = TagName.protected;
|
|
45
|
+
case SyntaxKind.JSDocReadonlyTag:
|
|
46
|
+
tagName = TagName.readonly;
|
|
47
|
+
case SyntaxKind.JSDocOverrideTag:
|
|
48
|
+
tagName = TagName.override;
|
|
49
|
+
case SyntaxKind.JSDocDeprecatedTag:
|
|
50
|
+
tagName = TagName.deprecated;
|
|
51
|
+
case SyntaxKind.JSDocSeeTag:
|
|
52
|
+
tagName = TagName.see;
|
|
53
|
+
case SyntaxKind.JSDocEnumTag:
|
|
54
|
+
tagName = TagName.enum;
|
|
55
|
+
case SyntaxKind.JSDocParameterTag:
|
|
56
|
+
tagName = TagName.parameter;
|
|
57
|
+
case SyntaxKind.JSDocThisTag:
|
|
58
|
+
tagName = TagName.this;
|
|
59
|
+
case SyntaxKind.JSDocTypeTag:
|
|
60
|
+
tagName = TagName.type;
|
|
61
|
+
case SyntaxKind.JSDocTemplateTag:
|
|
62
|
+
tagName = TagName.template;
|
|
63
|
+
case SyntaxKind.JSDocTypedefTag:
|
|
64
|
+
tagName = TagName.typedef;
|
|
65
|
+
case SyntaxKind.JSDocPropertyTag:
|
|
66
|
+
tagName = TagName.property;
|
|
67
|
+
case SyntaxKind.JSDocImplementsTag:
|
|
68
|
+
tagName = TagName.implements;
|
|
69
|
+
default:
|
|
70
|
+
return simpleTag(tag, tagName, context);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function simpleTag(tag: JSDocTag, tagName: TagName | string, context: SchemaExtractorContext): TagSchema {
|
|
75
|
+
return new TagSchema(context.getLocation(tag), tagName, getTextOfJSDocComment(tag.comment));
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
async function returnTag(tag: JSDocReturnTag, context: SchemaExtractorContext) {
|
|
79
|
+
const type = tag.typeExpression?.type ? await typeNodeToSchema(tag.typeExpression?.type, context) : undefined;
|
|
80
|
+
return new ReturnTagSchema(context.getLocation(tag), TagName.return, getTextOfJSDocComment(tag.comment), type);
|
|
81
|
+
}
|
|
@@ -3,17 +3,21 @@ import { FunctionLikeSchema, Modifier } from '@teambit/semantics.entities.semant
|
|
|
3
3
|
import { SchemaExtractorContext } from '../../schema-extractor-context';
|
|
4
4
|
import { getParams } from './get-params';
|
|
5
5
|
import { parseTypeFromQuickInfo } from './parse-type-from-quick-info';
|
|
6
|
+
import { jsDocToDocSchema } from './jsdoc-to-doc-schema';
|
|
6
7
|
|
|
7
|
-
export async function toFunctionLikeSchema(
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
export async function toFunctionLikeSchema(
|
|
9
|
+
node: SignatureDeclaration,
|
|
10
|
+
context: SchemaExtractorContext,
|
|
11
|
+
funcName?: string
|
|
12
|
+
) {
|
|
13
|
+
const name = funcName || node.name?.getText() || '';
|
|
14
|
+
const info = node.name ? await context.getQuickInfo(node.name) : null;
|
|
15
|
+
const returnTypeStr = info ? parseTypeFromQuickInfo(info) : 'any';
|
|
12
16
|
const displaySig = info?.body?.displayString || '';
|
|
13
17
|
const args = await getParams(node.parameters, context);
|
|
14
|
-
const returnType = await context.resolveType(node, returnTypeStr);
|
|
18
|
+
const returnType = await context.resolveType(node, returnTypeStr, Boolean(info));
|
|
15
19
|
const modifiers = node.modifiers?.map((modifier) => modifier.getText()) || [];
|
|
16
20
|
const location = context.getLocation(node);
|
|
17
|
-
|
|
18
|
-
return new FunctionLikeSchema(location, name, args, returnType, displaySig, modifiers as Modifier[]);
|
|
21
|
+
const doc = await jsDocToDocSchema(node, context);
|
|
22
|
+
return new FunctionLikeSchema(location, name, args, returnType, displaySig, modifiers as Modifier[], doc);
|
|
19
23
|
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import ts, {
|
|
2
|
+
SyntaxKind,
|
|
3
|
+
TypeElement,
|
|
4
|
+
MethodSignature,
|
|
5
|
+
isComputedPropertyName,
|
|
6
|
+
IndexSignatureDeclaration,
|
|
7
|
+
GetAccessorDeclaration,
|
|
8
|
+
SetAccessorDeclaration,
|
|
9
|
+
ConstructSignatureDeclaration,
|
|
10
|
+
} from 'typescript';
|
|
11
|
+
import {
|
|
12
|
+
GetAccessorSchema,
|
|
13
|
+
IndexSignatureSchema,
|
|
14
|
+
SchemaNode,
|
|
15
|
+
SetAccessorSchema,
|
|
16
|
+
VariableSchema,
|
|
17
|
+
} from '@teambit/semantics.entities.semantic-schema';
|
|
18
|
+
import { toFunctionLikeSchema } from './to-function-schema';
|
|
19
|
+
import { SchemaExtractorContext } from '../../schema-extractor-context';
|
|
20
|
+
import { parseTypeFromQuickInfo } from './parse-type-from-quick-info';
|
|
21
|
+
import { typeNodeToSchema } from './type-node-to-schema';
|
|
22
|
+
import { getParams } from './get-params';
|
|
23
|
+
|
|
24
|
+
export async function typeElementToSchema(node: TypeElement, context: SchemaExtractorContext): Promise<SchemaNode> {
|
|
25
|
+
switch (node.kind) {
|
|
26
|
+
case SyntaxKind.MethodSignature:
|
|
27
|
+
return toFunctionLikeSchema(node as MethodSignature, context);
|
|
28
|
+
case SyntaxKind.ConstructSignature:
|
|
29
|
+
return toFunctionLikeSchema(node as ConstructSignatureDeclaration, context, 'new');
|
|
30
|
+
case SyntaxKind.CallSignature:
|
|
31
|
+
throw new Error(`CallSignature was not implemented yet`);
|
|
32
|
+
case SyntaxKind.PropertySignature:
|
|
33
|
+
return propertySignature(node as ts.PropertySignature, context);
|
|
34
|
+
case SyntaxKind.IndexSignature:
|
|
35
|
+
return indexSignature(node as IndexSignatureDeclaration, context);
|
|
36
|
+
case SyntaxKind.GetAccessor:
|
|
37
|
+
return getAccessor(node as GetAccessorDeclaration, context);
|
|
38
|
+
case SyntaxKind.SetAccessor:
|
|
39
|
+
return setAccessor(node as SetAccessorDeclaration, context);
|
|
40
|
+
default:
|
|
41
|
+
throw new Error(`typeElementToSchema expect type-element node. got ${node.kind}`);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
async function propertySignature(node: ts.PropertySignature, context: SchemaExtractorContext) {
|
|
46
|
+
const name = node.name.getText();
|
|
47
|
+
const info = isComputedPropertyName(node.name) ? undefined : await context.getQuickInfo(node.name);
|
|
48
|
+
const displaySig = info?.body?.displayString || '';
|
|
49
|
+
const typeStr = parseTypeFromQuickInfo(info);
|
|
50
|
+
const type = await context.resolveType(node, typeStr);
|
|
51
|
+
return new VariableSchema(context.getLocation(node), name, displaySig, type);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export async function indexSignature(node: IndexSignatureDeclaration, context: SchemaExtractorContext) {
|
|
55
|
+
const params = await getParams(node.parameters, context);
|
|
56
|
+
const type = await typeNodeToSchema(node.type, context);
|
|
57
|
+
return new IndexSignatureSchema(context.getLocation(node), params, type);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export async function getAccessor(node: GetAccessorDeclaration, context: SchemaExtractorContext) {
|
|
61
|
+
const info = await context.getQuickInfo(node.name);
|
|
62
|
+
const displaySig = info?.body?.displayString || '';
|
|
63
|
+
const typeStr = parseTypeFromQuickInfo(info);
|
|
64
|
+
const type = await context.resolveType(node, typeStr);
|
|
65
|
+
return new GetAccessorSchema(context.getLocation(node), node.name.getText(), type, displaySig);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export async function setAccessor(node: SetAccessorDeclaration, context: SchemaExtractorContext) {
|
|
69
|
+
const params = await getParams(node.parameters, context);
|
|
70
|
+
const displaySig = await context.getQuickInfoDisplayString(node.name);
|
|
71
|
+
return new SetAccessorSchema(context.getLocation(node), node.name.getText(), params[0], displaySig);
|
|
72
|
+
}
|
|
@@ -17,6 +17,7 @@ import {
|
|
|
17
17
|
IndexedAccessTypeNode,
|
|
18
18
|
TemplateLiteralTypeNode,
|
|
19
19
|
TemplateLiteralTypeSpan,
|
|
20
|
+
ThisTypeNode,
|
|
20
21
|
} from 'typescript';
|
|
21
22
|
import {
|
|
22
23
|
SchemaNode,
|
|
@@ -36,10 +37,14 @@ import {
|
|
|
36
37
|
IndexedAccessSchema,
|
|
37
38
|
TemplateLiteralTypeSpanSchema,
|
|
38
39
|
TemplateLiteralTypeSchema,
|
|
40
|
+
ThisTypeSchema,
|
|
41
|
+
Modifier,
|
|
39
42
|
} from '@teambit/semantics.entities.semantic-schema';
|
|
40
43
|
import pMapSeries from 'p-map-series';
|
|
41
44
|
import { SchemaExtractorContext } from '../../schema-extractor-context';
|
|
42
45
|
import { getParams } from './get-params';
|
|
46
|
+
import { typeElementToSchema } from './type-element-to-schema';
|
|
47
|
+
import { jsDocToDocSchema } from './jsdoc-to-doc-schema';
|
|
43
48
|
|
|
44
49
|
// eslint-disable-next-line complexity
|
|
45
50
|
export async function typeNodeToSchema(node: TypeNode, context: SchemaExtractorContext): Promise<SchemaNode> {
|
|
@@ -78,13 +83,14 @@ export async function typeNodeToSchema(node: TypeNode, context: SchemaExtractorC
|
|
|
78
83
|
return templateLiteralTypeSpan(node as TemplateLiteralTypeSpan, context);
|
|
79
84
|
case SyntaxKind.TemplateLiteralType:
|
|
80
85
|
return templateLiteralType(node as TemplateLiteralTypeNode, context);
|
|
86
|
+
case SyntaxKind.ThisType:
|
|
87
|
+
return thisType(node as ThisTypeNode, context);
|
|
81
88
|
case SyntaxKind.ConstructorType:
|
|
82
89
|
case SyntaxKind.NamedTupleMember:
|
|
83
90
|
case SyntaxKind.OptionalType:
|
|
84
91
|
case SyntaxKind.RestType:
|
|
85
92
|
case SyntaxKind.ConditionalType:
|
|
86
93
|
case SyntaxKind.InferType:
|
|
87
|
-
case SyntaxKind.ThisType:
|
|
88
94
|
case SyntaxKind.MappedType:
|
|
89
95
|
case SyntaxKind.ImportType:
|
|
90
96
|
case SyntaxKind.ExpressionWithTypeArguments:
|
|
@@ -153,10 +159,7 @@ async function unionType(node: UnionTypeNode, context: SchemaExtractorContext) {
|
|
|
153
159
|
* this "TypeLiteral" is an object with properties, such as: `{ a: string; b: number }`, similar to Interface.
|
|
154
160
|
*/
|
|
155
161
|
async function typeLiteral(node: TypeLiteralNode, context: SchemaExtractorContext) {
|
|
156
|
-
const members = await pMapSeries(node.members,
|
|
157
|
-
const typeSchema = await context.computeSchema(member);
|
|
158
|
-
return typeSchema;
|
|
159
|
-
});
|
|
162
|
+
const members = await pMapSeries(node.members, (member) => typeElementToSchema(member, context));
|
|
160
163
|
const location = context.getLocation(node);
|
|
161
164
|
return new TypeLiteralSchema(location, members);
|
|
162
165
|
}
|
|
@@ -183,7 +186,9 @@ async function functionType(node: FunctionTypeNode, context: SchemaExtractorCont
|
|
|
183
186
|
const params = await getParams(node.parameters, context);
|
|
184
187
|
const returnType = await typeNodeToSchema(node.type, context);
|
|
185
188
|
const location = context.getLocation(node);
|
|
186
|
-
|
|
189
|
+
const modifiers = node.modifiers?.map((modifier) => modifier.getText()) || [];
|
|
190
|
+
const doc = await jsDocToDocSchema(node, context);
|
|
191
|
+
return new FunctionLikeSchema(location, name, params, returnType, '', modifiers as Modifier[], doc);
|
|
187
192
|
}
|
|
188
193
|
|
|
189
194
|
/**
|
|
@@ -261,3 +266,7 @@ async function templateLiteralTypeSpan(node: TemplateLiteralTypeSpan, context: S
|
|
|
261
266
|
const literal = node.literal.text;
|
|
262
267
|
return new TemplateLiteralTypeSpanSchema(context.getLocation(node), literal, type);
|
|
263
268
|
}
|
|
269
|
+
|
|
270
|
+
async function thisType(node: ThisTypeNode, context: SchemaExtractorContext) {
|
|
271
|
+
return new ThisTypeSchema(context.getLocation(node));
|
|
272
|
+
}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { SchemaNode, VariableSchema, FunctionLikeSchema } from '@teambit/semantics.entities.semantic-schema';
|
|
1
|
+
import { SchemaNode, VariableSchema, FunctionLikeSchema, Modifier } from '@teambit/semantics.entities.semantic-schema';
|
|
2
2
|
import ts, { Node, VariableDeclaration as VariableDeclarationNode, ArrowFunction } from 'typescript';
|
|
3
3
|
import { SchemaTransformer } from '../schema-transformer';
|
|
4
4
|
import { SchemaExtractorContext } from '../schema-extractor-context';
|
|
5
5
|
import { ExportIdentifier } from '../export-identifier';
|
|
6
6
|
import { getParams } from './utils/get-params';
|
|
7
7
|
import { parseReturnTypeFromQuickInfo, parseTypeFromQuickInfo } from './utils/parse-type-from-quick-info';
|
|
8
|
+
import { jsDocToDocSchema } from './utils/jsdoc-to-doc-schema';
|
|
8
9
|
|
|
9
10
|
export class VariableDeclaration implements SchemaTransformer {
|
|
10
11
|
predicate(node: Node) {
|
|
@@ -28,7 +29,9 @@ export class VariableDeclaration implements SchemaTransformer {
|
|
|
28
29
|
const args = await getParams((varDec.initializer as ArrowFunction).parameters, context);
|
|
29
30
|
const typeStr = parseReturnTypeFromQuickInfo(info);
|
|
30
31
|
const returnType = await context.resolveType(varDec, typeStr);
|
|
31
|
-
|
|
32
|
+
const modifiers = varDec.modifiers?.map((modifier) => modifier.getText()) || [];
|
|
33
|
+
const doc = await jsDocToDocSchema(varDec, context);
|
|
34
|
+
return new FunctionLikeSchema(location, name, args, returnType, displaySig, modifiers as Modifier[], doc);
|
|
32
35
|
}
|
|
33
36
|
const typeStr = parseTypeFromQuickInfo(info);
|
|
34
37
|
const type = await context.resolveType(varDec, typeStr);
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { SchemaNode } from '@teambit/semantics.entities.semantic-schema';
|
|
2
|
-
import { Node, ConstructorDeclaration } from 'typescript';
|
|
3
|
-
import { SchemaExtractorContext } from '../schema-extractor-context';
|
|
4
|
-
import { SchemaTransformer } from '../schema-transformer';
|
|
5
|
-
import { ExportIdentifier } from '../export-identifier';
|
|
6
|
-
export declare class Constructor implements SchemaTransformer {
|
|
7
|
-
predicate(node: Node): boolean;
|
|
8
|
-
getIdentifiers(node: ConstructorDeclaration): Promise<ExportIdentifier[]>;
|
|
9
|
-
transform(constructorDec: ConstructorDeclaration, context: SchemaExtractorContext): Promise<SchemaNode>;
|
|
10
|
-
}
|