From c70f1959f3d8058c8ba8598062ff07a97b501ffe Mon Sep 17 00:00:00 2001 From: Ron S Date: Sat, 18 Sep 2021 15:25:32 -0400 Subject: [PATCH 01/13] refactor: Update for TS 4.4 --- package.json | 4 ++-- src/transformer.ts | 6 ++---- src/types.ts | 2 +- src/utils/ts-helpers.ts | 3 +-- yarn.lock | 16 ++++++++-------- 5 files changed, 14 insertions(+), 17 deletions(-) diff --git a/package.json b/package.json index 6d66d68e..256de488 100755 --- a/package.json +++ b/package.json @@ -58,11 +58,11 @@ "prettier": "^2.3.2", "rimraf": "^3.0.2", "standard-version": "^9.3.1", - "ts-expose-internals": "^4.3.2", + "ts-expose-internals": "^4.4.3", "ts-jest": "^27.0.4", "ts-node": "^10.1.0", "ts-patch": "^1.4.2", - "typescript": "^4.3.5" + "typescript": "^4.4.3" }, "peerDependencies": { "typescript": ">=3.6.5" diff --git a/src/transformer.ts b/src/transformer.ts index 634055c3..2858ef95 100755 --- a/src/transformer.ts +++ b/src/transformer.ts @@ -87,8 +87,7 @@ export default function transformer( } const { configFile, paths } = compilerOptions; - // TODO - Remove typecast when tryParsePatterns is recognized (probably after ts v4.4) - const { tryParsePatterns } = tsInstance as any; + const tryParsePatterns: typeof ts.tryParsePatterns | undefined = tsInstance.tryParsePatterns; const tsTransformPathsContext: TsTransformPathsContext = { compilerOptions, @@ -108,8 +107,7 @@ export default function transformer( pathsPatterns: paths && (tryParsePatterns - ? // TODO - Remove typecast when pathPatterns is recognized (probably after ts v4.4) - (configFile?.configFileSpecs as any)?.pathPatterns || tryParsePatterns(paths) + ? configFile?.configFileSpecs?.pathPatterns || tryParsePatterns(paths) : tsInstance.getOwnKeys(paths)), }; diff --git a/src/types.ts b/src/types.ts index 50826816..f1967744 100755 --- a/src/types.ts +++ b/src/types.ts @@ -48,7 +48,7 @@ export interface TsTransformPathsContext { readonly rootDirs?: string[]; readonly excludeMatchers: IMinimatch[] | undefined; readonly outputFileNamesCache: Map; - readonly pathsPatterns: (string | Pattern)[] | undefined; + readonly pathsPatterns: readonly (string | Pattern)[] | undefined; readonly emitHost: EmitHost; readonly isTsNode: boolean; } diff --git a/src/utils/ts-helpers.ts b/src/utils/ts-helpers.ts index 8c4e9deb..3235679f 100755 --- a/src/utils/ts-helpers.ts +++ b/src/utils/ts-helpers.ts @@ -12,7 +12,6 @@ import type { REGISTER_INSTANCE } from "ts-node"; */ export function getOutputDirForSourceFile(context: VisitorContext, sourceFile: SourceFile): string { const { - tsInstance, emitHost, outputFileNamesCache, compilerOptions, @@ -49,7 +48,7 @@ export function isModulePathsMatch(context: VisitorContext, moduleName: string): pathsPatterns, tsInstance: { matchPatternOrExact }, } = context; - return !!(pathsPatterns && matchPatternOrExact(pathsPatterns as readonly string[], moduleName)); + return !!(pathsPatterns && matchPatternOrExact(pathsPatterns, moduleName)); } /** diff --git a/yarn.lock b/yarn.lock index 16b40e9e..1082261b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3637,10 +3637,10 @@ trim-off-newlines@^1.0.0: resolved "https://registry.yarnpkg.com/trim-off-newlines/-/trim-off-newlines-1.0.1.tgz#9f9ba9d9efa8764c387698bcbfeb2c848f11adb3" integrity sha1-n5up2e+odkw4dpi8v+sshI8RrbM= -ts-expose-internals@^4.3.2: - version "4.3.2" - resolved "https://registry.yarnpkg.com/ts-expose-internals/-/ts-expose-internals-4.3.2.tgz#99ea3fd7b2b0750e994143c20fe269a5d434dee1" - integrity sha512-QqBZDp8fOVFW+/+taGQXx6K/gmU+/Zs9yLxcZcrMObHhmvqBzuImjIU7ZTY/HfcZStO2eXWtJrIlFNjepCV1ew== +ts-expose-internals@^4.4.3: + version "4.4.3" + resolved "https://registry.yarnpkg.com/ts-expose-internals/-/ts-expose-internals-4.4.3.tgz#02cd43988403b35d266ac69bf5bee02a885093f4" + integrity sha512-hvdD6g3aOdh6vnTMBpKfy+mfG4uTxN7aq5PYC1/s0MCqEKY3+1QD0o1yEgafIGzp9Bi4k7ciaB/lPWV8s55xTQ== ts-jest@^27.0.4: version "27.0.4" @@ -3734,10 +3734,10 @@ typedarray@^0.0.6: resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777" integrity sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c= -typescript@^4.3.5: - version "4.3.5" - resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.3.5.tgz#4d1c37cc16e893973c45a06886b7113234f119f4" - integrity sha512-DqQgihaQ9cUrskJo9kIyW/+g0Vxsk8cDtZ52a3NGh0YNTfpUSArXSohyUGnvbPazEPLu398C0UxmKSOrPumUzA== +typescript@^4.4.3: + version "4.4.3" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.4.3.tgz#bdc5407caa2b109efd4f82fe130656f977a29324" + integrity sha512-4xfscpisVgqqDfPaJo5vkd+Qd/ItkoagnHpufr+i2QCHBsNYp+G7UAoyFl8aPtx879u38wPV65rZ8qbGZijalA== uglify-js@^3.1.4: version "3.13.5" From e38c6227e1d7a6961dd8c2104b9c4c6b23db42d0 Mon Sep 17 00:00:00 2001 From: Ron S Date: Sat, 18 Sep 2021 15:27:21 -0400 Subject: [PATCH 02/13] feat: Add `outputMode` option for esm output --- .editorconfig | 6 +- package.json | 6 +- src/transformer.ts | 13 +- src/types.ts | 43 +- src/utils/general-utils.ts | 2 + src/utils/path.ts | 178 ++++++++ src/utils/resolve-module-name.ts | 179 ++++---- src/utils/resolve-path-update-node.ts | 14 +- src/utils/ts-helpers.ts | 13 +- test/package.json | 2 +- test/projects/extras/package.json | 2 +- test/projects/general/tsconfig.json | 4 +- test/projects/project-ref/package.json | 2 +- test/projects/project-ref/tsconfig.base.json | 5 +- test/tests/transformer/specific.test.ts | 449 +++++++++++-------- test/yarn.lock | 38 +- types/index.d.ts | 4 +- yarn.lock | 12 +- 18 files changed, 643 insertions(+), 329 deletions(-) create mode 100755 src/utils/path.ts diff --git a/.editorconfig b/.editorconfig index 2733847d..f8256e8a 100644 --- a/.editorconfig +++ b/.editorconfig @@ -34,7 +34,7 @@ ij_javascript_align_multiline_extends_list = false ij_javascript_align_multiline_for = true ij_javascript_align_multiline_parameters = true ij_javascript_align_multiline_parameters_in_calls = false -ij_javascript_align_multiline_ternary_operation = false +ij_javascript_align_multiline_ternary_operation = true ij_javascript_align_object_properties = 0 ij_javascript_align_union_types = false ij_javascript_align_var_statements = 0 @@ -218,7 +218,7 @@ ij_typescript_align_multiline_extends_list = false ij_typescript_align_multiline_for = true ij_typescript_align_multiline_parameters = true ij_typescript_align_multiline_parameters_in_calls = false -ij_typescript_align_multiline_ternary_operation = false +ij_typescript_align_multiline_ternary_operation = true ij_typescript_align_object_properties = 0 ij_typescript_align_union_types = false ij_typescript_align_var_statements = 0 @@ -363,7 +363,7 @@ ij_typescript_ternary_operation_signs_on_next_line = false ij_typescript_ternary_operation_wrap = off ij_typescript_union_types_wrap = on_every_item ij_typescript_use_chained_calls_group_indents = false -ij_typescript_use_double_quotes = false +ij_typescript_use_double_quotes = true ij_typescript_use_explicit_js_extension = global ij_typescript_use_path_mapping = always ij_typescript_use_public_modifier = false diff --git a/package.json b/package.json index 256de488..bf8b9e1f 100755 --- a/package.json +++ b/package.json @@ -12,8 +12,8 @@ "--------------": "", "format": "prettier --write \"{src,test}/**/{*.js,!(*.d).ts}\"", "clean": "rimraf dist **/*.tsbuildinfo", - "clean:all": "yarn run clean && rimraf node_modules test/node_modules test/.yarn-cache", - "reset": "yarn run clean:all && yarn install", + "clean:all": "yarn run clean && rimraf node_modules **/node_modules test/.yarn-cache", + "reset": "yarn run clean:all && yarn install && yarn build", "-------------- ": "", "prebuild": "rimraf dist", "install:tests": "cd test && yarn install && cd projects/extras && yarn install", @@ -61,7 +61,7 @@ "ts-expose-internals": "^4.4.3", "ts-jest": "^27.0.4", "ts-node": "^10.1.0", - "ts-patch": "^1.4.2", + "ts-patch": "^1.4.4", "typescript": "^4.4.3" }, "peerDependencies": { diff --git a/src/transformer.ts b/src/transformer.ts index 2858ef95..7f73babe 100755 --- a/src/transformer.ts +++ b/src/transformer.ts @@ -20,10 +20,14 @@ function getTsProperties(args: Parameters) { let fileNames: readonly string[] | undefined; let isTsNode = false; - const { 0: program, 2: extras, 3: manualTransformOptions } = args; + const [program, pluginConfig, extras, manualTransformOptions] = args; tsInstance = extras?.ts ?? ts; compilerOptions = manualTransformOptions?.compilerOptions!; + const config = { + ...pluginConfig, + outputMode: pluginConfig?.outputMode === "esm" ? "esm" : "commonjs", + }; if (program) { compilerOptions ??= program.getCompilerOptions(); @@ -41,7 +45,7 @@ function getTsProperties(args: Parameters) { fileNames = tsNodeProps.fileNames; } - return { tsInstance, compilerOptions, fileNames, isTsNode }; + return { tsInstance, compilerOptions, fileNames, isTsNode, config }; } // endregion @@ -68,11 +72,11 @@ export default function transformer( tsInstance, compilerOptions, fileNames, - isTsNode + isTsNode, + config } = getTsProperties([ program, pluginConfig, transformerExtras, manualTransformOptions ]); const rootDirs = compilerOptions.rootDirs?.filter(path.isAbsolute); - const config: TsTransformPathsConfig = pluginConfig ?? {}; const getCanonicalFileName = tsInstance.createGetCanonicalFileName(tsInstance.sys.useCaseSensitiveFileNames); let emitHost = transformationContext.getEmitHost(); @@ -121,6 +125,7 @@ export default function transformer( return nodeVisitor.bind(this); }, factory: createHarmonyFactory(tsTransformPathsContext), + outputMode: config.outputMode === 'esm' && sourceFile.isDeclarationFile ? 'esm' : 'commonjs' }; return tsInstance.visitEachChild(sourceFile, visitorContext.getVisitor(), transformationContext); diff --git a/src/types.ts b/src/types.ts index f1967744..39bbe3aa 100755 --- a/src/types.ts +++ b/src/types.ts @@ -1,17 +1,17 @@ -import tsThree from "./declarations/typescript3"; import ts, { CompilerOptions, EmitHost, Pattern, SourceFile } from "typescript"; -import { PluginConfig } from "ts-patch"; import { HarmonyFactory } from "./utils/harmony-factory"; import { IMinimatch } from "minimatch"; +import { RequireSome } from "./utils"; /* ****************************************************************************************************************** */ // region: TS Types /* ****************************************************************************************************************** */ -export type TypeScriptLatest = typeof ts; -export type TypeScriptThree = typeof tsThree; export type ImportOrExportDeclaration = ts.ImportDeclaration | ts.ExportDeclaration; export type ImportOrExportClause = ts.ImportDeclaration["importClause"] | ts.ExportDeclaration["exportClause"]; +export type TransformerExtras = { + ts: typeof ts; +} // endregion @@ -19,9 +19,10 @@ export type ImportOrExportClause = ts.ImportDeclaration["importClause"] | ts.Exp // region: Config /* ****************************************************************************************************************** */ -export interface TsTransformPathsConfig extends PluginConfig { +export interface TsTransformPathsConfig { readonly useRootDirs?: boolean; readonly exclude?: string[]; + readonly outputMode?: "commonjs" | "esm"; } // endregion @@ -31,26 +32,27 @@ export interface TsTransformPathsConfig extends PluginConfig { /* ****************************************************************************************************************** */ export interface TsTransformPathsContext { - /** - * TS Instance passed from ts-patch / ttypescript with TS4+ typings - */ - readonly tsInstance: TypeScriptLatest; - /** - * TS Instance passed from ts-patch / ttypescript with TS3 typings - */ - readonly tsThreeInstance: TypeScriptThree; + readonly tsInstance: typeof ts; readonly tsFactory?: ts.NodeFactory; - readonly program?: ts.Program | tsThree.Program; - readonly config: TsTransformPathsConfig; + readonly program?: ts.Program; + readonly config: RequireSome; readonly compilerOptions: CompilerOptions; - readonly elisionMap: Map>; readonly transformationContext: ts.TransformationContext; readonly rootDirs?: string[]; - readonly excludeMatchers: IMinimatch[] | undefined; - readonly outputFileNamesCache: Map; + readonly isTsNode: boolean; + readonly isTranspileOnly: boolean; + + /** @internal - Do not remove internal flag — this uses an internal TS type */ readonly pathsPatterns: readonly (string | Pattern)[] | undefined; + /** @internal - Do not remove internal flag — this uses an internal TS type */ readonly emitHost: EmitHost; - readonly isTsNode: boolean; + + /** @internal */ + readonly elisionMap: Map>; + /** @internal */ + readonly excludeMatchers: IMinimatch[] | undefined; + /** @internal */ + readonly outputFileNamesCache: Map; } export interface VisitorContext extends TsTransformPathsContext { @@ -58,6 +60,9 @@ export interface VisitorContext extends TsTransformPathsContext { readonly sourceFile: ts.SourceFile; readonly isDeclarationFile: boolean; readonly originalSourceFile: ts.SourceFile; + readonly outputMode: 'esm' | 'commonjs'; + + /** @internal */ getVisitor(): (node: ts.Node) => ts.VisitResult; } diff --git a/src/utils/general-utils.ts b/src/utils/general-utils.ts index 89652cb9..73cba2f5 100755 --- a/src/utils/general-utils.ts +++ b/src/utils/general-utils.ts @@ -12,3 +12,5 @@ export const isBaseDir = (baseDir: string, testDir: string): boolean => { return relative ? !relative.startsWith("..") && !path.isAbsolute(relative) : true; }; export const maybeAddRelativeLocalPrefix = (p: string) => (p[0] === "." ? p : `./${p}`); + +export type RequireSome = T & Pick, K>; diff --git a/src/utils/path.ts b/src/utils/path.ts new file mode 100755 index 00000000..7bf74226 --- /dev/null +++ b/src/utils/path.ts @@ -0,0 +1,178 @@ +// noinspection JSUnusedLocalSymbols,JSUnusedAssignment + +import path from "path"; +import { normalizePath, Pattern, removePrefix, removeSuffix, ResolvedModuleFull } from "typescript"; + +/* ****************************************************************************************************************** */ +// region: Types +/* ****************************************************************************************************************** */ + +export interface OutputPathDetail { + isImplicitExtension: boolean + isExternalLibraryImport: boolean + resolvedExt: string | undefined; + resolvedPath: string; + outputPath: string | undefined; + suppliedExt: string | undefined; + implicitPath?: string; + /** Package name from package.json */ + packageName?: string; + /** Package name as written (could differ due to npm aliasing) */ + suppliedPackageName?: string + suppliedPackagePath?: string + packagePath?: string; + tsPathMatch?: string; +} + +// endregion + +/* ****************************************************************************************************************** */ +// region: Helpers +/* ****************************************************************************************************************** */ + +const pkgRegex = /^((@[^/]+\/[^/@]+)|([^@/]+))(?:\/([^@]+?))?$/; + +/** @internal */ +function getPaths(supplied: string, resolved: string) { + let endMatchPos = 0; + for (let i = 0; i < supplied.length && i < resolved.length; i++) { + if (supplied[i] !== resolved[i]) { + endMatchPos = i; + break; + } + } + + const outputPath = supplied.slice(0, endMatchPos); + const implicitPath = resolved.slice(endMatchPos); + + return { outputPath, implicitPath }; +} + +function getPackagePaths(moduleName: string, suppliedExt: string, subModule: string) { + const { 1: suppliedPackageName, 2: suppliedPackagePath } = pkgRegex.exec(moduleName)!; + + const packagePathNoExt = fixupPartialPath(suppliedPackagePath, suppliedExt); + + if (!subModule) return { outputPath: packagePathNoExt }; + + const subModuleNoExt = fixupPartialPath(subModule, path.extname(subModule)); + + return { + ...getPaths(packagePathNoExt, subModuleNoExt), + suppliedPackageName, + suppliedPackagePath + }; +} + +function getModulePaths( + moduleName: string, + suppliedExt: string, + resolvedFileName: string, + resolvedExt: string, + tsPathMatch: string | Pattern | undefined +) { + // In this case, the file ending is a fixed path, so no further information needs to be determined + if (typeof tsPathMatch === "string" || tsPathMatch?.suffix) return { outputPath: void 0 }; + + const resolvedFileNameNoExt = fixupPartialPath(resolvedFileName, resolvedExt); + const modulePathNoExt = tsPathMatch?.prefix + ? fixupPartialPath(removePrefix(moduleName, tsPathMatch?.prefix), suppliedExt) + : fixupPath(moduleName, suppliedExt); + + return getPaths(modulePathNoExt, resolvedFileNameNoExt); +} + +function getTsPathMatch(match: string | Pattern): string { + return typeof match === "string" ? match : [match.prefix, match.suffix].join("*"); +} + +// endregion + +/* ****************************************************************************************************************** */ +// region: Utils +/* ****************************************************************************************************************** */ + +export function joinPaths(...paths: (string | undefined)[]): string { + return normalizePath(path.join('', ...paths.filter(p => typeof p === 'string') as string[])); +} + +/** + * Remove leading or trailing slashes + * @p path to fix + * @extName extname to remove + */ +export function fixupPartialPath(p: string, extName?: string): string { + p = p.replace(/^[/\\]*(.+?)[/\\]*$/g, "$1"); + if (extName && p.slice(-extName.length) === extName) p = p.slice(0, p.length - extName.length); + return p; +} + +/** + * Remove trailing slashes + * @p path to fix + * @extName extname to remove + */ +export function fixupPath(p: string, extName?: string): string { + p = p.replace(/^(.+?)[/\\]*$/g, "$1"); + if (extName && p.slice(-extName.length) === extName) p = p.slice(0, p.length - extName.length); + return p; +} + +/** @internal — Uses internal TS type */ +export function getOutputPathDetail( + moduleName: string, + resolvedModule: ResolvedModuleFull, + pathMatch: string | Pattern | undefined +): OutputPathDetail { + moduleName = fixupPath(moduleName); + let suppliedExtName = path.extname(moduleName); + const suppliedBaseName = path.basename(moduleName); + let suppliedBaseNameNoExt = path.basename(moduleName, suppliedExtName); + + const resolvedFileName = resolvedModule.originalPath ?? resolvedModule.resolvedFileName; + const resolvedExtName = path.extname(resolvedFileName); + const resolvedFileNameNoExt = removeSuffix(resolvedFileName, resolvedExtName); + const resolvedBaseName = path.basename(resolvedFileName); + const resolvedBaseNameNoExt = path.basename(resolvedFileName, suppliedExtName); + + const tsPathMatch = pathMatch && getTsPathMatch(pathMatch); + + const { isExternalLibraryImport, packageId } = resolvedModule; + const packageName = packageId?.name; + const packageFileName = packageId && fixupPartialPath(packageId.subModuleName); + const packageExtName = packageFileName && path.extname(packageFileName); + const packageFileNameNoExt = packageFileName && removeSuffix(packageFileName, resolvedExtName); + const packageBaseName = packageFileName && path.basename(packageFileName); + const packageBaseNameNoExt = packageFileName && path.basename(packageFileName, packageExtName); + + const effectiveResolvedFileName = packageFileNameNoExt || resolvedFileNameNoExt; + const effectiveResolvedBaseName = packageBaseName || resolvedBaseName; + const effectiveResolvedBaseNameNoExt = packageBaseNameNoExt || resolvedBaseNameNoExt; + const effectiveResolvedExtName = packageExtName || resolvedExtName; + + // Detect and fix invalid extname due to implicit ext (ie. `file.accounting.ts` could decide `accounting` is the extension) + if (suppliedExtName && effectiveResolvedBaseNameNoExt && suppliedBaseName && effectiveResolvedBaseNameNoExt === suppliedBaseName) { + suppliedBaseNameNoExt = suppliedBaseName; + suppliedExtName = ""; + } + + const isImplicitExtension = !suppliedExtName; + + const pathDetail = resolvedModule.isExternalLibraryImport + ? getPackagePaths(moduleName, suppliedExtName, packageId!.subModuleName) + : getModulePaths(moduleName, suppliedExtName, resolvedFileName, resolvedExtName, tsPathMatch); + + return { + isImplicitExtension, + isExternalLibraryImport: !!isExternalLibraryImport, + resolvedExt: effectiveResolvedExtName, + suppliedExt: suppliedExtName, + resolvedPath: effectiveResolvedFileName, + tsPathMatch, + packageName, + packagePath: packageFileName, + ...pathDetail, + }; +} + +// endregion diff --git a/src/utils/resolve-module-name.ts b/src/utils/resolve-module-name.ts index b31158b3..b853dc76 100755 --- a/src/utils/resolve-module-name.ts +++ b/src/utils/resolve-module-name.ts @@ -1,33 +1,27 @@ import { VisitorContext } from "../types"; import { isBaseDir, isURL, maybeAddRelativeLocalPrefix } from "./general-utils"; -import * as path from "path"; -import { removeFileExtension, removeSuffix, ResolvedModuleFull, SourceFile } from "typescript"; -import { getOutputDirForSourceFile } from "./ts-helpers"; +import { Node, Pattern, removeFileExtension, ResolvedModuleFull, SourceFile } from "typescript"; +import { getOutputPathDetail, joinPaths, OutputPathDetail } from "./path"; +import { getOutputPathForSourceFile } from "./ts-helpers"; +import path from "path"; /* ****************************************************************************************************************** */ // region: Types /* ****************************************************************************************************************** */ export interface ResolvedModule { - /** - * Absolute path to resolved module - */ - resolvedPath: string | undefined; - /** - * Output path - */ + resolvedPath?: string; outputPath: string; - /** - * Resolved to URL - */ - isURL: boolean; } -enum IndexType { - NonIndex, - Explicit, - Implicit, - ImplicitPackage, +interface GetReturnPathContext { + visitorContext: VisitorContext + node: Node + moduleName: string + pathDetail?: OutputPathDetail + resolvedModule?: ResolvedModuleFull + resolvedSourceFile?: SourceFile + outputPath: string | (string | undefined)[] } // endregion @@ -36,57 +30,6 @@ enum IndexType { // region: Helpers /* ****************************************************************************************************************** */ -function getPathDetail(moduleName: string, resolvedModule: ResolvedModuleFull) { - let resolvedFileName = resolvedModule.originalPath ?? resolvedModule.resolvedFileName; - const implicitPackageIndex = resolvedModule.packageId?.subModuleName; - - const resolvedDir = implicitPackageIndex - ? removeSuffix(resolvedFileName, `/${implicitPackageIndex}`) - : path.dirname(resolvedFileName); - const resolvedBaseName = implicitPackageIndex ? void 0 : path.basename(resolvedFileName); - const resolvedBaseNameNoExtension = resolvedBaseName && removeFileExtension(resolvedBaseName); - const resolvedExtName = resolvedBaseName && path.extname(resolvedFileName); - - let baseName = !implicitPackageIndex ? path.basename(moduleName) : void 0; - let baseNameNoExtension = baseName && removeFileExtension(baseName); - let extName = baseName && path.extname(moduleName); - - // Account for possible false extensions. Example scenario: - // moduleName = './file.accounting' - // resolvedBaseName = 'file.accounting.ts' - // ('accounting' would be considered the extension) - if (resolvedBaseNameNoExtension && baseName && resolvedBaseNameNoExtension === baseName) { - baseNameNoExtension = baseName; - extName = void 0; - } - - // prettier-ignore - const indexType = - implicitPackageIndex ? IndexType.ImplicitPackage : - baseNameNoExtension === 'index' && resolvedBaseNameNoExtension === 'index' ? IndexType.Explicit : - baseNameNoExtension !== 'index' && resolvedBaseNameNoExtension === 'index' ? IndexType.Implicit : - IndexType.NonIndex; - - if (indexType === IndexType.Implicit) { - baseName = void 0; - baseNameNoExtension = void 0; - extName = void 0; - } - - return { - baseName, - baseNameNoExtension, - extName, - resolvedBaseName, - resolvedBaseNameNoExtension, - resolvedExtName, - resolvedDir, - indexType, - implicitPackageIndex, - resolvedFileName, - }; -} - function getResolvedSourceFile(context: VisitorContext, fileName: string): SourceFile { let res: SourceFile | undefined; const { program, tsInstance } = context; @@ -110,6 +53,33 @@ function getResolvedSourceFile(context: VisitorContext, fileName: string): Sourc return tsInstance.createSourceFile(fileName, ``, tsInstance.ScriptTarget.ESNext, /* setParentNodes */ false); } +function getReturnPath(ctx: GetReturnPathContext) { + const { pathDetail, outputPath } = ctx; + const { outputMode } = ctx.visitorContext; + const { + resolvedExt, + suppliedExt, + resolvedPath, + isImplicitExtension, + implicitPath, + } = ctx.pathDetail ?? {}; + + const isEsm = outputMode === "esm"; + const paths = [ outputPath ].flat(); + + let res = joinPaths(...paths); + if (!res) + throw new Error(`Could not resolve path! Please file an issue!\nDetail: ${JSON.stringify(pathDetail, null,2)}`); + + if (pathDetail) { + const ext = isEsm ? resolvedExt : isImplicitExtension ? void 0 : suppliedExt; + const implicit = isEsm ? implicitPath : void 0; + if (ext) res = joinPaths(res, implicit, ext); + } + + return { resolvedPath: resolvedPath, outputPath: res }; +} + // endregion /* ****************************************************************************************************************** */ @@ -119,7 +89,12 @@ function getResolvedSourceFile(context: VisitorContext, fileName: string): Sourc /** * Resolve a module name */ -export function resolveModuleName(context: VisitorContext, moduleName: string): ResolvedModule | undefined { +export function resolveModuleName( + context: VisitorContext, + node: Node, + moduleName: string, + pathMatch: string | Pattern | undefined +): ResolvedModule | undefined { const { tsInstance, compilerOptions, sourceFile, config, rootDirs } = context; // Attempt to resolve with TS Compiler API @@ -133,28 +108,41 @@ export function resolveModuleName(context: VisitorContext, moduleName: string): // Handle non-resolvable module if (!resolvedModule) { const maybeURL = failedLookupLocations[0]; - if (!isURL(maybeURL)) return void 0; - return { - isURL: true, - resolvedPath: void 0, - outputPath: maybeURL, - }; + const pathIsUrl = isURL(maybeURL); + + if (pathIsUrl && !context.resolver) return void 0; + return getReturnPath({ + moduleName, + visitorContext: context, + node, + outputPath: pathIsUrl ? maybeURL : moduleName + }); } const resolvedSourceFile = getResolvedSourceFile(context, resolvedModule.resolvedFileName); + const pathDetail = getOutputPathDetail(moduleName, resolvedModule, pathMatch); + + const { isExternalLibraryImport } = pathDetail; + + // External packages without a path match hit do not require path relativization + if (isExternalLibraryImport && !pathMatch) { + const { suppliedPackageName, outputPath } = pathDetail; + return getReturnPath({ + moduleName, + node, + visitorContext: context, + resolvedModule, + resolvedSourceFile, + pathDetail, + outputPath: [ suppliedPackageName, outputPath ] + }); + } - const { indexType, resolvedBaseNameNoExtension, resolvedFileName, implicitPackageIndex, extName, resolvedDir } = - getPathDetail(moduleName, resolvedModule); - - /* Determine output filename */ - let outputBaseName = resolvedBaseNameNoExtension ?? ""; - - if (indexType === IndexType.Implicit) outputBaseName = outputBaseName.replace(/(\/index$)|(^index$)/, ""); - if (outputBaseName && extName) outputBaseName = `${outputBaseName}${extName}`; - - /* Determine output dir */ - let srcFileOutputDir = getOutputDirForSourceFile(context, sourceFile); - let moduleFileOutputDir = implicitPackageIndex ? resolvedDir : getOutputDirForSourceFile(context, resolvedSourceFile); + /* Determine output dirs */ + let srcFileOutputDir = path.dirname(getOutputPathForSourceFile(context, sourceFile)); + let moduleFileOutputDir = path.dirname( + resolvedModule.packageId ? pathDetail.outputPath! : getOutputPathForSourceFile(context, resolvedSourceFile) + ); // Handle rootDirs remapping if (config.useRootDirs && rootDirs) { @@ -175,9 +163,18 @@ export function resolveModuleName(context: VisitorContext, moduleName: string): const outputDir = path.relative(srcFileOutputDir, moduleFileOutputDir); /* Compose final output path */ - const outputPath = maybeAddRelativeLocalPrefix(tsInstance.normalizePath(path.join(outputDir, outputBaseName))); + const outputBaseName = pathDetail.implicitPath ? void 0 : path.basename(pathDetail.resolvedPath, pathDetail.resolvedExt); + const outputPath = maybeAddRelativeLocalPrefix(joinPaths(outputDir, outputBaseName)); - return { isURL: false, outputPath, resolvedPath: resolvedFileName }; + return getReturnPath({ + moduleName, + node, + visitorContext: context, + resolvedModule, + resolvedSourceFile, + pathDetail, + outputPath + }); } // endregion diff --git a/src/utils/resolve-path-update-node.ts b/src/utils/resolve-path-update-node.ts index 7fd2181c..81285950 100755 --- a/src/utils/resolve-path-update-node.ts +++ b/src/utils/resolve-path-update-node.ts @@ -1,7 +1,7 @@ import ts from "typescript"; import { VisitorContext } from "../types"; import { isURL, maybeAddRelativeLocalPrefix } from "./general-utils"; -import { isModulePathsMatch } from "./ts-helpers"; +import { getTsPathsMatch } from "./ts-helpers"; import { resolveModuleName } from "./resolve-module-name"; /* ****************************************************************************************************************** */ @@ -17,7 +17,7 @@ export function resolvePathAndUpdateNode( moduleName: string, updaterFn: (newPath: ts.StringLiteral) => ts.Node | undefined ): ts.Node | undefined { - const { sourceFile, tsInstance, factory } = context; + const { sourceFile, tsInstance, factory, outputMode } = context; const { normalizePath } = tsInstance; /* Handle JSDoc statement tags */ @@ -35,16 +35,18 @@ export function resolvePathAndUpdateNode( } /* Resolve Module */ - // Skip if no paths match found - if (!isModulePathsMatch(context, moduleName)) return node; + const pathsMatch = getTsPathsMatch(context, moduleName); - const res = resolveModuleName(context, moduleName); + // Don't process if not necessary + if (!pathsMatch && !context.resolver && outputMode !== "esm") return node; + + const res = resolveModuleName(context, node, moduleName, pathsMatch); if (!res) return node; const { outputPath, resolvedPath } = res; /* Skip if matches exclusion */ - if (context.excludeMatchers) + if (resolvedPath && context.excludeMatchers) for (const matcher of context.excludeMatchers) if (matcher.match(outputPath) || (resolvedPath && matcher.match(resolvedPath))) return node; diff --git a/src/utils/ts-helpers.ts b/src/utils/ts-helpers.ts index 3235679f..daa522bf 100755 --- a/src/utils/ts-helpers.ts +++ b/src/utils/ts-helpers.ts @@ -1,5 +1,4 @@ import ts, { GetCanonicalFileName, SourceFile } from "typescript"; -import path from "path"; import { VisitorContext } from "../types"; import type { REGISTER_INSTANCE } from "ts-node"; @@ -10,7 +9,7 @@ import type { REGISTER_INSTANCE } from "ts-node"; /** * Determine output file path for source file */ -export function getOutputDirForSourceFile(context: VisitorContext, sourceFile: SourceFile): string { +export function getOutputPathForSourceFile(context: VisitorContext, sourceFile: SourceFile): string { const { emitHost, outputFileNamesCache, @@ -33,22 +32,20 @@ export function getOutputDirForSourceFile(context: VisitorContext, sourceFile: S `https://github.com/LeDDGroup/typescript-transform-paths/issues` ); - const res = path.dirname(outputPath); + outputFileNamesCache.set(sourceFile, outputPath); - outputFileNamesCache.set(sourceFile, res); - - return tsInstance.normalizePath(res); + return outputPath; } /** * Determine if moduleName matches config in paths */ -export function isModulePathsMatch(context: VisitorContext, moduleName: string): boolean { +export function getTsPathsMatch(context: VisitorContext, moduleName: string): string | ts.Pattern | undefined { const { pathsPatterns, tsInstance: { matchPatternOrExact }, } = context; - return !!(pathsPatterns && matchPatternOrExact(pathsPatterns, moduleName)); + return pathsPatterns && matchPatternOrExact(pathsPatterns, moduleName); } /** diff --git a/test/package.json b/test/package.json index 2952315b..88e47c8f 100755 --- a/test/package.json +++ b/test/package.json @@ -5,7 +5,7 @@ "prepare": "node prepare.js" }, "devDependencies": { - "typescript-transform-paths": "link:../src", + "typescript-transform-paths": "link:../", "ts-expose-internals": "^4.1.2", "typescript": "npm:typescript@latest", "typescript-three": "npm:typescript@3.6.5", diff --git a/test/projects/extras/package.json b/test/projects/extras/package.json index c9d4ede6..5968d6db 100755 --- a/test/projects/extras/package.json +++ b/test/projects/extras/package.json @@ -3,6 +3,6 @@ "name": "@tests/extras", "version": "0.0.0", "dependencies": { - "typescript-transform-paths": "link:../../../" + "typescript-transform-paths": "*" } } diff --git a/test/projects/general/tsconfig.json b/test/projects/general/tsconfig.json index 5b773121..132e2028 100644 --- a/test/projects/general/tsconfig.json +++ b/test/projects/general/tsconfig.json @@ -16,8 +16,8 @@ "esModuleInterop": true, "plugins": [ - { "transform": "../../src/index.ts" }, - { "transform": "../../src/index.ts", "afterDeclarations": true } + { "transform": "../../../src/index.ts" }, + { "transform": "../../../src/index.ts", "afterDeclarations": true } ] } } diff --git a/test/projects/project-ref/package.json b/test/projects/project-ref/package.json index 7ff64a33..a4602890 100755 --- a/test/projects/project-ref/package.json +++ b/test/projects/project-ref/package.json @@ -3,6 +3,6 @@ "name": "@tests/project-ref", "version": "0.0.0", "dependencies": { - "typescript-transform-paths": "link:../../../" + "typescript-transform-paths": "*" } } diff --git a/test/projects/project-ref/tsconfig.base.json b/test/projects/project-ref/tsconfig.base.json index e562473b..b5bd3845 100755 --- a/test/projects/project-ref/tsconfig.base.json +++ b/test/projects/project-ref/tsconfig.base.json @@ -13,11 +13,12 @@ "#b/*": [ "./b/*" ] }, "plugins": [ + // Note - Paths are relative to one level deeper, due to tsp not resolving from base config dir { - "transform": "./src/index.ts", + "transform": "../../../../src/index.ts", }, { - "transform": "./src/index.ts", + "transform": "../../../../src/index.ts", "afterDeclarations": true } ] diff --git a/test/tests/transformer/specific.test.ts b/test/tests/transformer/specific.test.ts index 9f6f04ad..e6521368 100755 --- a/test/tests/transformer/specific.test.ts +++ b/test/tests/transformer/specific.test.ts @@ -1,3 +1,15 @@ +/** + * Note: To make debug testing easier, you can use the following environment variables to control what tests run: + * + * TS_MODULES - comma separated string of name fields in `tsModules` (config.ts) + * MODES - comma separated string of `modes` (see config heading below) + * OUTPUT_MODES - comma separated string of `outputModes` (see config heading below) + * + * Example — only test latest TS, using program and ts-node, with outputMode 'esm': + * TS_MODULES=latest; + * MODES=program,ts-node; + * OUTPUT_MODES=esm; + */ // noinspection ES6UnusedImports import {} from "ts-expose-internals"; import * as path from "path"; @@ -18,11 +30,8 @@ import TS from "typescript"; const baseConfig: TsTransformPathsConfig = { exclude: ["**/excluded/**", "excluded-file.*"] }; -/* Test Mapping */ const modes = ["program", "manual", "ts-node"] as const; -const testConfigs: { label: string; tsInstance: any; mode: typeof modes[number]; tsSpecifier: string }[] = []; -for (const cfg of tsModules) - testConfigs.push(...modes.map((mode) => ({ label: cfg[0], tsInstance: cfg[1], mode, tsSpecifier: cfg[2] }))); +const outputModes = ["[default]", "commonjs", "esm"] as const; /* File Paths */ const projectRoot = ts.normalizePath(path.join(projectsPaths, "specific")); @@ -35,14 +44,68 @@ const typeElisionIndex = ts.normalizePath(path.join(projectRoot, "src/type-elisi const subPackagesFile = ts.normalizePath(path.join(projectRoot, "src/sub-packages.ts")); const moduleAugmentFile = ts.normalizePath(path.join(projectRoot, "src/module-augment.ts")); +/* ****************************************************************************************************************** * + * Setup + * ****************************************************************************************************************** */ + +const testConfigs = (function prepareConfigs() { + let { TS_MODULES, MODES, OUTPUT_MODES } = process.env; + const opt = { + modules: TS_MODULES?.split(",").map((m) => m.trim().toLowerCase()), + modes: MODES?.split(",").map((m) => m.trim().toLowerCase()), + outputModes: OUTPUT_MODES?.split(",").map((m) => m.trim().toLowerCase()), + }; + + const cfgTsModules = !opt.modules ? tsModules : tsModules.filter((m) => opt.modules!.includes(m[0].toLowerCase())); + const cfgModes = !opt.modes ? modes : modes.filter((m) => opt.modes!.includes(m.toLowerCase())); + const cfgOutputModes = !opt.outputModes + ? outputModes + : outputModes.filter((m) => opt.outputModes!.includes(m.toLowerCase())); + + const res: { + label: string; + tsInstance: any; + mode: typeof modes[number]; + tsSpecifier: string; + config: TsTransformPathsConfig; + outputMode: typeof outputModes[number]; + }[] = []; + + cfgTsModules.forEach((cfg) => + cfgOutputModes.forEach((outputMode) => + res.push( + ...cfgModes.map((mode) => ({ + label: cfg[0], + tsInstance: cfg[1], + mode, + tsSpecifier: cfg[2], + config: { + ...baseConfig, + outputMode: outputMode === "[default]" ? void 0 : outputMode, + }, + outputMode, + })) + ) + ) + ); + + return res; +})(); + /* ****************************************************************************************************************** * * Types * ****************************************************************************************************************** */ +interface TransformedMatchesOpt { + base?: EmittedFiles[]; + kind?: ("dts" | "js")[]; + noEsmFix?: boolean; +} + declare global { namespace jest { interface Matchers { - transformedMatches(expected: RegExp | string, opt?: { base?: EmittedFiles[]; kind?: ("dts" | "js")[] }): void; + transformedMatches(expected: RegExp | string, opt?: TransformedMatchesOpt): void; } } } @@ -52,194 +115,228 @@ declare global { * ****************************************************************************************************************** */ describe(`Specific Tests`, () => { - describe.each(testConfigs)(`TypeScript $label - Mode: $mode`, ({ tsInstance, mode, tsSpecifier }) => { - const tsVersion = +tsInstance.versionMajorMinor.split(".").slice(0, 2).join(""); - let normalEmit: EmittedFiles; - let rootDirsEmit: EmittedFiles; - let skipDts = false; - - beforeAll(() => { - switch (mode) { - case "program": - const program = createTsProgram({ - tsInstance, - tsConfigFile, - pluginOptions: { - ...baseConfig, - useRootDirs: false, - }, - }); - normalEmit = getEmitResultFromProgram(program); - - const rootDirsProgram = createTsProgram({ - tsInstance, - tsConfigFile, - pluginOptions: { - ...baseConfig, - useRootDirs: true, - }, - }); - rootDirsEmit = getEmitResultFromProgram(rootDirsProgram); - break; - case "manual": { - skipDts = true; - const pcl = tsInstance.getParsedCommandLineOfConfigFile( - tsConfigFile, - {}, - tsInstance.sys - )! as TS.ParsedCommandLine; - normalEmit = getManualEmitResult({ ...baseConfig, useRootDirs: false }, tsInstance, pcl); - rootDirsEmit = getManualEmitResult({ ...baseConfig, useRootDirs: true }, tsInstance, pcl); - break; - } - case "ts-node": { - const pcl = tsInstance.getParsedCommandLineOfConfigFile( - tsConfigFile, - {}, - tsInstance.sys - )! as TS.ParsedCommandLine; - skipDts = true; - normalEmit = getTsNodeEmitResult({ ...baseConfig, useRootDirs: false }, pcl, tsSpecifier); - rootDirsEmit = getTsNodeEmitResult({ ...baseConfig, useRootDirs: true }, pcl, tsSpecifier); + describe.each(testConfigs)( + `TypeScript $label - Mode: $mode - OutputMode: $outputMode`, + ({ tsInstance, mode, tsSpecifier, config, outputMode }) => { + const tsVersion = +tsInstance.versionMajorMinor.split(".").slice(0, 2).join(""); + let normalEmit: EmittedFiles; + let rootDirsEmit: EmittedFiles; + let skipDts = false; + + beforeAll(() => { + switch (mode) { + case "program": + const program = createTsProgram({ + tsInstance, + tsConfigFile, + pluginOptions: { + ...config, + useRootDirs: false, + }, + }); + normalEmit = getEmitResultFromProgram(program); + + const rootDirsProgram = createTsProgram({ + tsInstance, + tsConfigFile, + pluginOptions: { + ...config, + useRootDirs: true, + }, + }); + rootDirsEmit = getEmitResultFromProgram(rootDirsProgram); + break; + case "manual": { + skipDts = true; + const pcl = tsInstance.getParsedCommandLineOfConfigFile( + tsConfigFile, + {}, + tsInstance.sys + )! as TS.ParsedCommandLine; + normalEmit = getManualEmitResult({ ...config, useRootDirs: false }, tsInstance, pcl); + rootDirsEmit = getManualEmitResult({ ...config, useRootDirs: true }, tsInstance, pcl); + break; + } + case "ts-node": { + const pcl = tsInstance.getParsedCommandLineOfConfigFile( + tsConfigFile, + {}, + tsInstance.sys + )! as TS.ParsedCommandLine; + skipDts = true; + normalEmit = getTsNodeEmitResult({ ...config, useRootDirs: false }, pcl, tsSpecifier); + rootDirsEmit = getTsNodeEmitResult({ ...config, useRootDirs: true }, pcl, tsSpecifier); + } } - } - - expect.extend({ - transformedMatches( - fileName: string, - expected: RegExp | string, - opt?: { base?: EmittedFiles[]; kind?: ("dts" | "js")[] } - ) { - const bases = opt?.base ?? [normalEmit, rootDirsEmit]; - const kinds = (opt?.kind ?? ["dts", "js"]).filter((k) => !skipDts || k !== "dts"); - - let failed: boolean = false; - const messages: string[] = []; - for (const base of bases) { - for (const kind of kinds) { - const content = base[fileName][kind]; - const isValid = typeof expected === "string" ? content.indexOf(expected) >= 0 : expected.test(content); - if (!isValid) { - failed = true; - messages.push( - `File: ${fileName}\nKind: ${kind}\nrootDirs: ${base === normalEmit}\n\n` + - `Expected: \`${expected}\`\nReceived:\n\t${content.replace(/(\r?\n)+/g, "$1\t")}` - ); + + expect.extend({ + transformedMatches(fileName: string, expected: RegExp | string, opt?: TransformedMatchesOpt) { + const bases = opt?.base ?? [normalEmit, rootDirsEmit]; + const kinds = (opt?.kind ?? ["dts", "js"]).filter((k) => !skipDts || k !== "dts"); + + let failed: boolean = false; + const messages: string[] = []; + for (const base of bases) { + for (const kind of kinds) { + const content = base[fileName][kind]; + const exp = getExpected(kind); + const isValid = typeof exp === "string" ? content.indexOf(exp) >= 0 : exp.test(content); + if (!isValid) { + failed = true; + messages.push( + `File: ${fileName}\nKind: ${kind}\nrootDirs: ${base === normalEmit}\n\n` + + `Expected: \`${exp}\`\nReceived:\n\t${content.replace(/(\r?\n)+/g, "$1\t")}` + ); + } } } - } - return { message: () => messages.join("\n\n"), pass: !failed }; - }, + return { message: () => messages.join("\n\n"), pass: !failed }; + + function getExpected(kind: "dts" | "js") { + if (!(expected instanceof RegExp) && !opt?.noEsmFix && kind === "js" && outputMode === "esm") { + const regEx = /"\.(.+?)"/g; + let res: string = ""; + + let match: RegExpExecArray | null; + let lastIndex = 0; + while ((match = regEx.exec(expected)) !== null) { + let p = match[1]; + if (!path.extname(p)) p += ".js"; + res += expected.slice(lastIndex, match.index) + `".${p}"`; + lastIndex = res.length; + } + + return res; + } + + return expected; + } + }, + }); + }); + + describe(`Options`, () => { + test(`(useRootDirs: true) Re-maps for rootDirs`, () => { + expect(genFile).transformedMatches(`import "./src-file"`, { base: [rootDirsEmit] }); + expect(srcFile).transformedMatches(`import "./gen-file"`, { base: [rootDirsEmit] }); + expect(indexFile).transformedMatches(`export { b } from "./dir/gen-file"`, { base: [rootDirsEmit] }); + expect(indexFile).transformedMatches(`export { a } from "./dir/src-file"`, { base: [rootDirsEmit] }); + }); + + test(`(useRootDirs: false) Ignores rootDirs`, () => { + expect(genFile).transformedMatches(`import "../../src/dir/src-file"`, { base: [normalEmit] }); + expect(srcFile).transformedMatches(`import "../../generated/dir/gen-file"`, { base: [normalEmit] }); + expect(indexFile).transformedMatches(`export { b } from "../generated/dir/gen-file"`, { base: [normalEmit] }); + expect(indexFile).transformedMatches(`export { a } from "./dir/src-file"`, { base: [normalEmit] }); + }); + + test(`(exclude) Doesn't transform for exclusion patterns`, () => { + expect(indexFile).transformedMatches( + /export { bb } from "#exclusion\/ex";\s*export { dd } from "#root\/excluded-file"/ + ); + }); }); - }); - - describe(`Options`, () => { - test(`(useRootDirs: true) Re-maps for rootDirs`, () => { - expect(genFile).transformedMatches(`import "./src-file"`, { base: [rootDirsEmit] }); - expect(srcFile).transformedMatches(`import "./gen-file"`, { base: [rootDirsEmit] }); - expect(indexFile).transformedMatches(`export { b } from "./dir/gen-file"`, { base: [rootDirsEmit] }); - expect(indexFile).transformedMatches(`export { a } from "./dir/src-file"`, { base: [rootDirsEmit] }); + + describe(`Tags`, () => { + test(`(@no-transform-path) Doesn't transform path`, () => { + for (let i = 1; i <= 4; i++) + expect(tagFile).transformedMatches(`import * as skipTransform${i} from "#root\/index`); + }); + + test(`(@transform-path) Transforms path with explicit value`, () => { + expect(tagFile).transformedMatches(`import * as explicitTransform1 from "./dir/src-file"`, { + noEsmFix: true, + }); + expect(tagFile).transformedMatches(`import * as explicitTransform2 from "http://www.go.com/react.js"`); + expect(tagFile).transformedMatches(`import * as explicitTransform3 from "./dir/src-file"`, { + noEsmFix: true, + }); + expect(tagFile).transformedMatches(`import * as explicitTransform4 from "http://www.go.com/react.js"`); + }); }); - test(`(useRootDirs: false) Ignores rootDirs`, () => { - expect(genFile).transformedMatches(`import "../../src/dir/src-file"`, { base: [normalEmit] }); - expect(srcFile).transformedMatches(`import "../../generated/dir/gen-file"`, { base: [normalEmit] }); - expect(indexFile).transformedMatches(`export { b } from "../generated/dir/gen-file"`, { base: [normalEmit] }); - expect(indexFile).transformedMatches(`export { a } from "./dir/src-file"`, { base: [normalEmit] }); + (mode === "program" ? test : test.skip)(`Type elision works properly`, () => { + expect(typeElisionIndex).transformedMatches( + outputMode === "esm" + ? /import { ConstB } from "\.\/a\.js";\s*export { ConstB };/ + : /import { ConstB } from "\.\/a";\s*export { ConstB };/, + { kind: ["js"] } + ); + expect(typeElisionIndex).transformedMatches( + /import { ConstB, TypeA } from "\.\/a";\s*import { TypeA as TypeA2 } from "\.\/a";\s*export { ConstB, TypeA };\s*export { TypeA2 };/, + { kind: ["dts"] } + ); }); - test(`(exclude) Doesn't transform for exclusion patterns`, () => { + (!skipDts && tsVersion >= 38 ? test : test.skip)(`Import type-only transforms`, () => { + expect(indexFile).transformedMatches(`import type { A as ATypeOnly } from "./dir/src-file"`, { kind: ["dts"] }); + }); + + test(`Copies comments in async import`, () => { + expect(indexFile).transformedMatches(`import(/* webpackChunkName: "Comment" */ "./dir/src-file");`, { + kind: ["js"], + }); expect(indexFile).transformedMatches( - /export { bb } from "#exclusion\/ex";\s*export { dd } from "#root\/excluded-file"/ + /\/\/ comment 1\r?\n\s*\r?\n\/\*\r?\n\s*comment 2\r?\n\s*\*\/\r?\n\s*"\.\/dir\/src-file(\.js)?"/, + { kind: ["js"] } ); }); - }); - describe(`Tags`, () => { - test(`(@no-transform-path) Doesn't transform path`, () => { - for (let i = 1; i <= 4; i++) - expect(tagFile).transformedMatches(`import * as skipTransform${i} from "#root\/index`); + test(`Preserves explicit extensions`, () => { + expect(indexFile).transformedMatches(`export { JsonValue } from "./data.json"`); + expect(indexFile).transformedMatches(`export { GeneralConstA } from "./general"`); + expect(indexFile).transformedMatches(`export { GeneralConstB } from "./general.js"`); }); - test(`(@transform-path) Transforms path with explicit value`, () => { - expect(tagFile).transformedMatches(`import * as explicitTransform1 from "./dir/src-file"`); - expect(tagFile).transformedMatches(`import * as explicitTransform2 from "http://www.go.com/react.js"`); - expect(tagFile).transformedMatches(`import * as explicitTransform3 from "./dir/src-file"`); - expect(tagFile).transformedMatches(`import * as explicitTransform4 from "http://www.go.com/react.js"`); + test(`Properly handles implicit index filenames`, () => { + const implicitMatch = `export { ConstB } from "./type-elision"`; + const explicitMatch = `export { ConstB } from "./type-elision/index.js"`; + + expect(indexFile).transformedMatches(outputMode === "esm" ? explicitMatch : implicitMatch, { kind: ["js"] }); + expect(indexFile).transformedMatches(implicitMatch, { kind: ["dts"] }); }); - }); - (mode === "program" ? test : test.skip)(`Type elision works properly`, () => { - expect(typeElisionIndex).transformedMatches(/import { ConstB } from "\.\/a";\s*export { ConstB };/, { - kind: ["js"], + test(`Resolves sub-modules properly`, () => { + const a = { + js: `export { packageAConst } from "./packages/pkg-a"`, + full: `export { packageAConst, PackageAType } from "./packages/pkg-a"`, + }; + const b = { + js: `export { packageBConst } from "./packages/pkg-b"`, + full: `export { packageBConst, PackageBType } from "./packages/pkg-b"`, + }; + const c = { + js: `export { packageCConst } from "./packages/pkg-c"`, + full: `export { packageCConst, PackageCType } from "./packages/pkg-c"`, + }; + const sub = { + js: `export { subPackageConst } from "./packages/pkg-a/sub-pkg"`, + full: `export { SubPackageType, subPackageConst } from "./packages/pkg-a/sub-pkg"`, + }; + + for (const exp of [a, b, c, sub]) { + expect(subPackagesFile).transformedMatches(mode !== "program" ? exp.full : exp.js, { + kind: ["js"], + noEsmFix: true, + }); + if (!skipDts) expect(subPackagesFile).transformedMatches(exp.full, { kind: ["dts"] }); + } + + expect(subPackagesFile).transformedMatches(`export { packageCConst as C2 } from "./packages/pkg-c/main"`); + expect(subPackagesFile).transformedMatches(`export { packageCConst as C3 } from "./packages/pkg-c/main.js"`); + expect(subPackagesFile).transformedMatches( + `export { subPackageConst as C4 } from "./packages/pkg-a/sub-pkg/main"` + ); + expect(subPackagesFile).transformedMatches( + `export { subPackageConst as C5 } from "./packages/pkg-a/sub-pkg/main.js"` + ); }); - expect(typeElisionIndex).transformedMatches( - /import { ConstB, TypeA } from "\.\/a";\s*import { TypeA as TypeA2 } from "\.\/a";\s*export { ConstB, TypeA };\s*export { TypeA2 };/, - { kind: ["dts"] } - ); - }); - - (!skipDts && tsVersion >= 38 ? test : test.skip)(`Import type-only transforms`, () => { - expect(indexFile).transformedMatches(`import type { A as ATypeOnly } from "./dir/src-file"`, { kind: ["dts"] }); - }); - - test(`Copies comments in async import`, () => { - expect(indexFile).transformedMatches(`import(/* webpackChunkName: "Comment" */ "./dir/src-file");`, { - kind: ["js"], + + (!skipDts ? test : test.skip)(`Resolves module augmentation`, () => { + expect(moduleAugmentFile).transformedMatches(`declare module "./general" {`, { kind: ["dts"] }); + expect(moduleAugmentFile).transformedMatches(`declare module "./excluded-file" {`, { kind: ["dts"] }); }); - expect(indexFile).transformedMatches( - /\/\/ comment 1\r?\n\s*\r?\n\/\*\r?\n\s*comment 2\r?\n\s*\*\/\r?\n\s*"\.\/dir\/src-file"/, - { kind: ["js"] } - ); - }); - - test(`Preserves explicit extensions`, () => { - expect(indexFile).transformedMatches(`export { JsonValue } from "./data.json"`); - expect(indexFile).transformedMatches(`export { GeneralConstA } from "./general"`); - expect(indexFile).transformedMatches(`export { GeneralConstB } from "./general.js"`); - }); - - test(`Does not output implicit index filenames`, () => { - expect(indexFile).transformedMatches(`export { ConstB } from "./type-elision"`); - }); - - test(`Resolves sub-modules properly`, () => { - const a = { - js: `export { packageAConst } from "./packages/pkg-a"`, - full: `export { packageAConst, PackageAType } from "./packages/pkg-a"`, - }; - const b = { - js: `export { packageBConst } from "./packages/pkg-b"`, - full: `export { packageBConst, PackageBType } from "./packages/pkg-b"`, - }; - const c = { - js: `export { packageCConst } from "./packages/pkg-c"`, - full: `export { packageCConst, PackageCType } from "./packages/pkg-c"`, - }; - const sub = { - js: `export { subPackageConst } from "./packages/pkg-a/sub-pkg"`, - full: `export { SubPackageType, subPackageConst } from "./packages/pkg-a/sub-pkg"`, - }; - - for (const exp of [a, b, c, sub]) { - expect(subPackagesFile).transformedMatches(mode !== "program" ? exp.full : exp.js, { kind: ["js"] }); - if (!skipDts) expect(subPackagesFile).transformedMatches(exp.full, { kind: ["dts"] }); - } - - expect(subPackagesFile).transformedMatches(`export { packageCConst as C2 } from "./packages/pkg-c/main"`); - expect(subPackagesFile).transformedMatches(`export { packageCConst as C3 } from "./packages/pkg-c/main.js"`); - expect(subPackagesFile).transformedMatches( - `export { subPackageConst as C4 } from "./packages/pkg-a/sub-pkg/main"` - ); - expect(subPackagesFile).transformedMatches( - `export { subPackageConst as C5 } from "./packages/pkg-a/sub-pkg/main.js"` - ); - }); - - (!skipDts ? test : test.skip)(`Resolves module augmentation`, () => { - expect(moduleAugmentFile).transformedMatches(`declare module "./general" {`, { kind: ["dts"] }); - expect(moduleAugmentFile).transformedMatches(`declare module "./excluded-file" {`, { kind: ["dts"] }); - }); - }); + } + ); }); diff --git a/test/yarn.lock b/test/yarn.lock index 91932f59..21acc4c4 100755 --- a/test/yarn.lock +++ b/test/yarn.lock @@ -74,6 +74,18 @@ glob@^7.0.0: once "^1.3.0" path-is-absolute "^1.0.0" +glob@^7.1.7: + version "7.1.7" + resolved "https://registry.yarnpkg.com/glob/-/glob-7.1.7.tgz#3b193e9233f01d42d0b3f78294bbeeb418f94a90" + integrity sha512-OvD9ENzPLbegENnYP5UUfJIirTg4+XwMWGaQfQTY0JenxNvvIKP3U3/tAQSPIu/lHxXYSZmpXlUHeqAIdKzBLQ== + dependencies: + fs.realpath "^1.0.0" + inflight "^1.0.4" + inherits "2" + minimatch "^3.0.4" + once "^1.3.0" + path-is-absolute "^1.0.0" + global-prefix@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/global-prefix/-/global-prefix-3.0.0.tgz#fc85f73064df69f50421f47f883fe5b913ba9b97" @@ -125,6 +137,13 @@ is-core-module@^2.1.0: dependencies: has "^1.0.3" +is-core-module@^2.2.0: + version "2.6.0" + resolved "https://registry.yarnpkg.com/is-core-module/-/is-core-module-2.6.0.tgz#d7553b2526fe59b92ba3e40c8df757ec8a709e19" + integrity sha512-wShG8vs60jKfPWpF2KZRaAtvt3a20OAn7+IJ6hLPECpSABLcKtFKTTI4ZtH5QcBruBHlq+WsdHWyz0BCZW7svQ== + dependencies: + has "^1.0.3" + isexe@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/isexe/-/isexe-2.0.0.tgz#e8fbf374dc556ff8947a10dcb0572d633f2cfa10" @@ -179,6 +198,14 @@ resolve@^1.1.6: is-core-module "^2.1.0" path-parse "^1.0.6" +resolve@^1.20.0: + version "1.20.0" + resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.20.0.tgz#629a013fb3f70755d6f0b7935cc1c2c5378b1975" + integrity sha512-wENBPt4ySzg4ybFQW2TT1zMQucPK95HSh/nq2CFTZVOGut2+pQvSsgtda4d26YrYcr067wjbmzOG8byDPBX63A== + dependencies: + is-core-module "^2.2.0" + path-parse "^1.0.6" + shelljs@^0.8.4: version "0.8.4" resolved "https://registry.yarnpkg.com/shelljs/-/shelljs-0.8.4.tgz#de7684feeb767f8716b326078a8a00875890e3c2" @@ -216,11 +243,14 @@ ts-expose-internals@^4.1.2: resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.6.5.tgz#dae20114a7b4ff4bd642db9c8c699f2953e8bbdb" integrity sha512-BEjlc0Z06ORZKbtcxGrIvvwYs5hAnuo6TKdNFL55frVDlB+na3z5bsLhFaIxmT+dPWgBIjMo6aNnTOgHHmHgiQ== -"typescript-transform-paths@link:..": - version "0.0.0" - uid "" +typescript-transform-paths@*: + version "3.3.1" + resolved "https://registry.yarnpkg.com/typescript-transform-paths/-/typescript-transform-paths-3.3.1.tgz#74526bc1b6dc575ffe269cc81833db7bd81763e1" + integrity sha512-c+8Cqd2rsRtTU68rJI0NX/OtqgBDddNs1fIxm1nCNyhn0WpoyqtpUxc1w9Ke5c5kgE4/OT5xYbKf2cf694RYEg== + dependencies: + minimatch "^3.0.4" -"typescript-transform-paths@link:../src": +"typescript-transform-paths@link:..": version "0.0.0" uid "" diff --git a/types/index.d.ts b/types/index.d.ts index 0d8eddb1..67aef4ad 100755 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -8,9 +8,7 @@ import ts from 'typescript' export interface TsTransformPathsConfig { readonly useRootDirs?: boolean; readonly exclude?: string[]; - readonly afterDeclarations?: boolean; - readonly tsConfig?: string; - readonly transform?: string + readonly outputMode?: 'commonjs' | 'esm' } export interface TransformerExtras { diff --git a/yarn.lock b/yarn.lock index 1082261b..4b622de8 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1827,7 +1827,7 @@ glob@^7.0.0, glob@^7.1.1, glob@^7.1.2, glob@^7.1.3: once "^1.3.0" path-is-absolute "^1.0.0" -glob@^7.1.4: +glob@^7.1.4, glob@^7.1.7: version "7.1.7" resolved "https://registry.yarnpkg.com/glob/-/glob-7.1.7.tgz#3b193e9233f01d42d0b3f78294bbeeb418f94a90" integrity sha512-OvD9ENzPLbegENnYP5UUfJIirTg4+XwMWGaQfQTY0JenxNvvIKP3U3/tAQSPIu/lHxXYSZmpXlUHeqAIdKzBLQ== @@ -3674,14 +3674,16 @@ ts-node@^10.1.0: source-map-support "^0.5.17" yn "3.1.1" -ts-patch@^1.4.2: - version "1.4.2" - resolved "https://registry.yarnpkg.com/ts-patch/-/ts-patch-1.4.2.tgz#2b763dc1de5a24631062844735ca169821c2c604" - integrity sha512-Nj3mjvQM3t8cB4wGfLKeE8zBT+cx1mDjttOcx9nb2fEl6Q/5u79w19tQniv2eLmeYEbki/+wdQc0zszPEpOxOg== +ts-patch@^1.4.4: + version "1.4.4" + resolved "https://registry.yarnpkg.com/ts-patch/-/ts-patch-1.4.4.tgz#c4814af4ab36183ddcf04c178f0153ce6ef48245" + integrity sha512-b0CxxrkrCGsD22gl5BtSFlXzyTFP2mbOVffxMOWRrwdSh37sM01wzxSY4wlbBiHHHAJICmaaDgESzJ8lKkVoZA== dependencies: chalk "^4.1.0" + glob "^7.1.7" global-prefix "^3.0.0" minimist "^1.2.5" + resolve "^1.20.0" shelljs "^0.8.4" strip-ansi "^6.0.0" From e3e75ffa98923278bd0d7f4694bb17bd8595f88d Mon Sep 17 00:00:00 2001 From: Ron S Date: Sat, 18 Sep 2021 19:43:15 -0400 Subject: [PATCH 03/13] build(git): Update CI workflow --- .github/workflows/main.yml | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index c1b69cb3..a5eed62b 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,6 +1,11 @@ name: Node.js CI -on: [ push, pull_request ] +on: + pull_request: + branches: [ master ] + types: [ opened, synchronize, closed ] + push: + branches: [ master ] jobs: build: @@ -14,25 +19,13 @@ jobs: - name: Checkout uses: actions/checkout@v2 - - name: Determine Yarn Cache Path - id: yarn-cache-dir-path - run: echo "::set-output name=dir::$(yarn cache dir)" - - - uses: actions/cache@v1 - id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`) - with: - path: ${{ steps.yarn-cache-dir-path.outputs.dir }} - key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} - restore-keys: | - ${{ runner.os }}-yarn- - - name: Use Node.js ${{ matrix.node-version }} uses: actions/setup-node@v1 with: node-version: ${{ matrix.node-version }} - - name: Install Packages - run: yarn install --frozen-lockfile + - name: Install + run: yarn run clean:all && yarn install --frozen-lockfile - name: Build run: yarn build From 32c541d3ea3795b28aebf9a59b54bc428f95bc3b Mon Sep 17 00:00:00 2001 From: Ron S Date: Sat, 18 Sep 2021 20:35:30 -0400 Subject: [PATCH 04/13] refactor: Drop test yarnrc and lockfile --- .gitignore | 1 + test/.yarnrc | 1 - test/yarn.lock | 272 ------------------------------------------------- 3 files changed, 1 insertion(+), 273 deletions(-) delete mode 100755 test/.yarnrc delete mode 100755 test/yarn.lock diff --git a/.gitignore b/.gitignore index 6cfcd46f..f310fc56 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ # Yarn .yarn-cache +./test/yarn.lock # Built *.js.map diff --git a/test/.yarnrc b/test/.yarnrc deleted file mode 100755 index c5a57595..00000000 --- a/test/.yarnrc +++ /dev/null @@ -1 +0,0 @@ ---cache-folder .yarn-cache diff --git a/test/yarn.lock b/test/yarn.lock deleted file mode 100755 index 21acc4c4..00000000 --- a/test/yarn.lock +++ /dev/null @@ -1,272 +0,0 @@ -# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. -# yarn lockfile v1 - - -ansi-regex@^5.0.0: - version "5.0.0" - resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-5.0.0.tgz#388539f55179bf39339c81af30a654d69f87cb75" - integrity sha512-bY6fj56OUQ0hU1KjFNDQuJFezqKdrAyFdIevADiqrWHwSlbmBNMHp5ak2f40Pm8JTFyM2mqxkG6ngkHO11f/lg== - -ansi-styles@^4.1.0: - version "4.3.0" - resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-4.3.0.tgz#edd803628ae71c04c85ae7a0906edad34b648937" - integrity sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg== - dependencies: - color-convert "^2.0.1" - -balanced-match@^1.0.0: - version "1.0.0" - resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-1.0.0.tgz#89b4d199ab2bee49de164ea02b89ce462d71b767" - integrity sha1-ibTRmasr7kneFk6gK4nORi1xt2c= - -brace-expansion@^1.1.7: - version "1.1.11" - resolved "https://registry.yarnpkg.com/brace-expansion/-/brace-expansion-1.1.11.tgz#3c7fcbf529d87226f3d2f52b966ff5271eb441dd" - integrity sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA== - dependencies: - balanced-match "^1.0.0" - concat-map "0.0.1" - -chalk@^4.1.0: - version "4.1.0" - resolved "https://registry.yarnpkg.com/chalk/-/chalk-4.1.0.tgz#4e14870a618d9e2edd97dd8345fd9d9dc315646a" - integrity sha512-qwx12AxXe2Q5xQ43Ac//I6v5aXTipYrSESdOgzrN+9XjgEpyjpKuvSGaN4qE93f7TQTlerQQ8S+EQ0EyDoVL1A== - dependencies: - ansi-styles "^4.1.0" - supports-color "^7.1.0" - -color-convert@^2.0.1: - version "2.0.1" - resolved "https://registry.yarnpkg.com/color-convert/-/color-convert-2.0.1.tgz#72d3a68d598c9bdb3af2ad1e84f21d896abd4de3" - integrity sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ== - dependencies: - color-name "~1.1.4" - -color-name@~1.1.4: - version "1.1.4" - resolved "https://registry.yarnpkg.com/color-name/-/color-name-1.1.4.tgz#c2a09a87acbde69543de6f63fa3995c826c536a2" - integrity sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA== - -concat-map@0.0.1: - version "0.0.1" - resolved "https://registry.yarnpkg.com/concat-map/-/concat-map-0.0.1.tgz#d8a96bd77fd68df7793a73036a3ba0d5405d477b" - integrity sha1-2Klr13/Wjfd5OnMDajug1UBdR3s= - -fs.realpath@^1.0.0: - version "1.0.0" - resolved "https://registry.yarnpkg.com/fs.realpath/-/fs.realpath-1.0.0.tgz#1504ad2523158caa40db4a2787cb01411994ea4f" - integrity sha1-FQStJSMVjKpA20onh8sBQRmU6k8= - -function-bind@^1.1.1: - version "1.1.1" - resolved "https://registry.yarnpkg.com/function-bind/-/function-bind-1.1.1.tgz#a56899d3ea3c9bab874bb9773b7c5ede92f4895d" - integrity sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A== - -glob@^7.0.0: - version "7.1.6" - resolved "https://registry.yarnpkg.com/glob/-/glob-7.1.6.tgz#141f33b81a7c2492e125594307480c46679278a6" - integrity sha512-LwaxwyZ72Lk7vZINtNNrywX0ZuLyStrdDtabefZKAY5ZGJhVtgdznluResxNmPitE0SAO+O26sWTHeKSI2wMBA== - dependencies: - fs.realpath "^1.0.0" - inflight "^1.0.4" - inherits "2" - minimatch "^3.0.4" - once "^1.3.0" - path-is-absolute "^1.0.0" - -glob@^7.1.7: - version "7.1.7" - resolved "https://registry.yarnpkg.com/glob/-/glob-7.1.7.tgz#3b193e9233f01d42d0b3f78294bbeeb418f94a90" - integrity sha512-OvD9ENzPLbegENnYP5UUfJIirTg4+XwMWGaQfQTY0JenxNvvIKP3U3/tAQSPIu/lHxXYSZmpXlUHeqAIdKzBLQ== - dependencies: - fs.realpath "^1.0.0" - inflight "^1.0.4" - inherits "2" - minimatch "^3.0.4" - once "^1.3.0" - path-is-absolute "^1.0.0" - -global-prefix@^3.0.0: - version "3.0.0" - resolved "https://registry.yarnpkg.com/global-prefix/-/global-prefix-3.0.0.tgz#fc85f73064df69f50421f47f883fe5b913ba9b97" - integrity sha512-awConJSVCHVGND6x3tmMaKcQvwXLhjdkmomy2W+Goaui8YPgYgXJZewhg3fWC+DlfqqQuWg8AwqjGTD2nAPVWg== - dependencies: - ini "^1.3.5" - kind-of "^6.0.2" - which "^1.3.1" - -has-flag@^4.0.0: - version "4.0.0" - resolved "https://registry.yarnpkg.com/has-flag/-/has-flag-4.0.0.tgz#944771fd9c81c81265c4d6941860da06bb59479b" - integrity sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ== - -has@^1.0.3: - version "1.0.3" - resolved "https://registry.yarnpkg.com/has/-/has-1.0.3.tgz#722d7cbfc1f6aa8241f16dd814e011e1f41e8796" - integrity sha512-f2dvO0VU6Oej7RkWJGrehjbzMAjFp5/VKPp5tTpWIV4JHHZK1/BxbFRtf/siA2SWTe09caDmVtYYzWEIbBS4zw== - dependencies: - function-bind "^1.1.1" - -inflight@^1.0.4: - version "1.0.6" - resolved "https://registry.yarnpkg.com/inflight/-/inflight-1.0.6.tgz#49bd6331d7d02d0c09bc910a1075ba8165b56df9" - integrity sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk= - dependencies: - once "^1.3.0" - wrappy "1" - -inherits@2: - version "2.0.4" - resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.4.tgz#0fa2c64f932917c3433a0ded55363aae37416b7c" - integrity sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ== - -ini@^1.3.5: - version "1.3.5" - resolved "https://registry.yarnpkg.com/ini/-/ini-1.3.5.tgz#eee25f56db1c9ec6085e0c22778083f596abf927" - integrity sha512-RZY5huIKCMRWDUqZlEi72f/lmXKMvuszcMBduliQ3nnWbx9X/ZBQO7DijMEYS9EhHBb2qacRUMtC7svLwe0lcw== - -interpret@^1.0.0: - version "1.4.0" - resolved "https://registry.yarnpkg.com/interpret/-/interpret-1.4.0.tgz#665ab8bc4da27a774a40584e812e3e0fa45b1a1e" - integrity sha512-agE4QfB2Lkp9uICn7BAqoscw4SZP9kTE2hxiFI3jBPmXJfdqiahTbUuKGsMoN2GtqL9AxhYioAcVvgsb1HvRbA== - -is-core-module@^2.1.0: - version "2.1.0" - resolved "https://registry.yarnpkg.com/is-core-module/-/is-core-module-2.1.0.tgz#a4cc031d9b1aca63eecbd18a650e13cb4eeab946" - integrity sha512-YcV7BgVMRFRua2FqQzKtTDMz8iCuLEyGKjr70q8Zm1yy2qKcurbFEd79PAdHV77oL3NrAaOVQIbMmiHQCHB7ZA== - dependencies: - has "^1.0.3" - -is-core-module@^2.2.0: - version "2.6.0" - resolved "https://registry.yarnpkg.com/is-core-module/-/is-core-module-2.6.0.tgz#d7553b2526fe59b92ba3e40c8df757ec8a709e19" - integrity sha512-wShG8vs60jKfPWpF2KZRaAtvt3a20OAn7+IJ6hLPECpSABLcKtFKTTI4ZtH5QcBruBHlq+WsdHWyz0BCZW7svQ== - dependencies: - has "^1.0.3" - -isexe@^2.0.0: - version "2.0.0" - resolved "https://registry.yarnpkg.com/isexe/-/isexe-2.0.0.tgz#e8fbf374dc556ff8947a10dcb0572d633f2cfa10" - integrity sha1-6PvzdNxVb/iUehDcsFctYz8s+hA= - -kind-of@^6.0.2: - version "6.0.3" - resolved "https://registry.yarnpkg.com/kind-of/-/kind-of-6.0.3.tgz#07c05034a6c349fa06e24fa35aa76db4580ce4dd" - integrity sha512-dcS1ul+9tmeD95T+x28/ehLgd9mENa3LsvDTtzm3vyBEO7RPptvAD+t44WVXaUjTBRcrpFeFlC8WCruUR456hw== - -minimatch@^3.0.4: - version "3.0.4" - resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-3.0.4.tgz#5166e286457f03306064be5497e8dbb0c3d32083" - integrity sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA== - dependencies: - brace-expansion "^1.1.7" - -minimist@^1.2.5: - version "1.2.5" - resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.5.tgz#67d66014b66a6a8aaa0c083c5fd58df4e4e97602" - integrity sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw== - -once@^1.3.0: - version "1.4.0" - resolved "https://registry.yarnpkg.com/once/-/once-1.4.0.tgz#583b1aa775961d4b113ac17d9c50baef9dd76bd1" - integrity sha1-WDsap3WWHUsROsF9nFC6753Xa9E= - dependencies: - wrappy "1" - -path-is-absolute@^1.0.0: - version "1.0.1" - resolved "https://registry.yarnpkg.com/path-is-absolute/-/path-is-absolute-1.0.1.tgz#174b9268735534ffbc7ace6bf53a5a9e1b5c5f5f" - integrity sha1-F0uSaHNVNP+8es5r9TpanhtcX18= - -path-parse@^1.0.6: - version "1.0.6" - resolved "https://registry.yarnpkg.com/path-parse/-/path-parse-1.0.6.tgz#d62dbb5679405d72c4737ec58600e9ddcf06d24c" - integrity sha512-GSmOT2EbHrINBf9SR7CDELwlJ8AENk3Qn7OikK4nFYAu3Ote2+JYNVvkpAEQm3/TLNEJFD/xZJjzyxg3KBWOzw== - -rechoir@^0.6.2: - version "0.6.2" - resolved "https://registry.yarnpkg.com/rechoir/-/rechoir-0.6.2.tgz#85204b54dba82d5742e28c96756ef43af50e3384" - integrity sha1-hSBLVNuoLVdC4oyWdW70OvUOM4Q= - dependencies: - resolve "^1.1.6" - -resolve@^1.1.6: - version "1.19.0" - resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.19.0.tgz#1af5bf630409734a067cae29318aac7fa29a267c" - integrity sha512-rArEXAgsBG4UgRGcynxWIWKFvh/XZCcS8UJdHhwy91zwAvCZIbcs+vAbflgBnNjYMs/i/i+/Ux6IZhML1yPvxg== - dependencies: - is-core-module "^2.1.0" - path-parse "^1.0.6" - -resolve@^1.20.0: - version "1.20.0" - resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.20.0.tgz#629a013fb3f70755d6f0b7935cc1c2c5378b1975" - integrity sha512-wENBPt4ySzg4ybFQW2TT1zMQucPK95HSh/nq2CFTZVOGut2+pQvSsgtda4d26YrYcr067wjbmzOG8byDPBX63A== - dependencies: - is-core-module "^2.2.0" - path-parse "^1.0.6" - -shelljs@^0.8.4: - version "0.8.4" - resolved "https://registry.yarnpkg.com/shelljs/-/shelljs-0.8.4.tgz#de7684feeb767f8716b326078a8a00875890e3c2" - integrity sha512-7gk3UZ9kOfPLIAbslLzyWeGiEqx9e3rxwZM0KE6EL8GlGwjym9Mrlx5/p33bWTu9YG6vcS4MBxYZDHYr5lr8BQ== - dependencies: - glob "^7.0.0" - interpret "^1.0.0" - rechoir "^0.6.2" - -strip-ansi@^6.0.0: - version "6.0.0" - resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.0.tgz#0b1571dd7669ccd4f3e06e14ef1eed26225ae532" - integrity sha512-AuvKTrTfQNYNIctbR1K/YGTR1756GycPsg7b9bdV9Duqur4gv6aKqHXah67Z8ImS7WEz5QVcOtlfW2rZEugt6w== - dependencies: - ansi-regex "^5.0.0" - -supports-color@^7.1.0: - version "7.2.0" - resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-7.2.0.tgz#1b7dcdcb32b8138801b3e478ba6a51caa89648da" - integrity sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw== - dependencies: - has-flag "^4.0.0" - -ts-expose-internals@^4.1.2: - version "4.1.2" - resolved "https://registry.yarnpkg.com/ts-expose-internals/-/ts-expose-internals-4.1.2.tgz#c89a64be5b7ae6634d2f0f25dffa798e2931d136" - integrity sha512-J5xYsQocO5tjP2UMkGlOb5U+joore0AiL1drA5bMPganlQR/9gPmQVO55pQDeHVfy8OATqZaBT5JweyjI6f3eA== - -"ts-patch@link:../node_modules/ts-patch": - version "0.0.0" - uid "" - -"typescript-three@npm:typescript@3.6.5": - version "3.6.5" - resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.6.5.tgz#dae20114a7b4ff4bd642db9c8c699f2953e8bbdb" - integrity sha512-BEjlc0Z06ORZKbtcxGrIvvwYs5hAnuo6TKdNFL55frVDlB+na3z5bsLhFaIxmT+dPWgBIjMo6aNnTOgHHmHgiQ== - -typescript-transform-paths@*: - version "3.3.1" - resolved "https://registry.yarnpkg.com/typescript-transform-paths/-/typescript-transform-paths-3.3.1.tgz#74526bc1b6dc575ffe269cc81833db7bd81763e1" - integrity sha512-c+8Cqd2rsRtTU68rJI0NX/OtqgBDddNs1fIxm1nCNyhn0WpoyqtpUxc1w9Ke5c5kgE4/OT5xYbKf2cf694RYEg== - dependencies: - minimatch "^3.0.4" - -"typescript-transform-paths@link:..": - version "0.0.0" - uid "" - -"typescript@npm:typescript@latest": - version "4.3.5" - resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.3.5.tgz#4d1c37cc16e893973c45a06886b7113234f119f4" - integrity sha512-DqQgihaQ9cUrskJo9kIyW/+g0Vxsk8cDtZ52a3NGh0YNTfpUSArXSohyUGnvbPazEPLu398C0UxmKSOrPumUzA== - -which@^1.3.1: - version "1.3.1" - resolved "https://registry.yarnpkg.com/which/-/which-1.3.1.tgz#a45043d54f5805316da8d62f9f50918d3da70b0a" - integrity sha512-HxJdYWq1MTIQbJ3nw0cqssHoTNU267KlrDuGZ1WYlxDStUtKUhOaJmh112/TZmHxxUfuJqPXSOm7tDyas0OSIQ== - dependencies: - isexe "^2.0.0" - -wrappy@1: - version "1.0.2" - resolved "https://registry.yarnpkg.com/wrappy/-/wrappy-1.0.2.tgz#b5243d8f3ec1aa35f1364605bc0d1036e30ab69f" - integrity sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8= From c35ef186aa0def24a4032d306cc0774f7e686d9e Mon Sep 17 00:00:00 2001 From: Ron S Date: Sat, 18 Sep 2021 20:36:50 -0400 Subject: [PATCH 05/13] fix: `ts-node` without --transpileOnly fails to transform paths (fixes #138) --- src/transformer.ts | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/transformer.ts b/src/transformer.ts index 7f73babe..aad16fe1 100755 --- a/src/transformer.ts +++ b/src/transformer.ts @@ -18,6 +18,7 @@ function getTsProperties(args: Parameters) { let tsInstance: typeof ts; let compilerOptions: ts.CompilerOptions; let fileNames: readonly string[] | undefined; + let isTranspileOnly = false; let isTsNode = false; const [program, pluginConfig, extras, manualTransformOptions] = args; @@ -29,23 +30,25 @@ function getTsProperties(args: Parameters) { outputMode: pluginConfig?.outputMode === "esm" ? "esm" : "commonjs", }; + const tsNodeProps = getTsNodeRegistrationProperties(tsInstance); + if (tsNodeProps) isTsNode = true; + if (program) { - compilerOptions ??= program.getCompilerOptions(); + compilerOptions ??= Object.assign({}, program.getCompilerOptions(), tsNodeProps?.compilerOptions); } else if (manualTransformOptions) { fileNames = manualTransformOptions.fileNames; } else { - const tsNodeProps = getTsNodeRegistrationProperties(tsInstance); if (!tsNodeProps) throw new Error( `Cannot transform without a Program, ts-node instance, or manual parameters supplied. ` + `Make sure you're using ts-patch or ts-node with transpileOnly.` ); - isTsNode = true; + isTranspileOnly = true; compilerOptions = tsNodeProps.compilerOptions; fileNames = tsNodeProps.fileNames; } - return { tsInstance, compilerOptions, fileNames, isTsNode, config }; + return { tsInstance, compilerOptions, fileNames, isTranspileOnly, config, isTsNode }; } // endregion @@ -72,6 +75,7 @@ export default function transformer( tsInstance, compilerOptions, fileNames, + isTranspileOnly, isTsNode, config } = getTsProperties([ program, pluginConfig, transformerExtras, manualTransformOptions ]); @@ -86,7 +90,7 @@ export default function transformer( `No EmitHost found and could not determine files to be processed. Please file an issue with a reproduction!` ); emitHost = createSyntheticEmitHost(compilerOptions, tsInstance, getCanonicalFileName, fileNames as string[]); - } else if (isTsNode) { + } else if (isTranspileOnly) { Object.assign(emitHost, { getCompilerOptions: () => compilerOptions }); } @@ -103,6 +107,7 @@ export default function transformer( transformationContext, tsInstance, emitHost, + isTranspileOnly, isTsNode, tsThreeInstance: cast(tsInstance), excludeMatchers: config.exclude?.map((globPattern) => new Minimatch(globPattern, { matchBase: true })), From 125d379e3722276c7de90f7d7895bc0364aae4e8 Mon Sep 17 00:00:00 2001 From: Ron S Date: Sat, 25 Sep 2021 22:29:52 -0400 Subject: [PATCH 06/13] refactor: Ensure package types are built & validated --- package.json | 11 ++++++----- src/index.ts | 2 +- src/transformer.ts | 6 ++---- src/utils/harmony-factory.ts | 5 ++++- src/utils/resolve-module-name.ts | 1 + src/utils/ts-type-conversion.ts | 10 +++++++--- tsconfig.json | 3 ++- types/index.d.ts | 34 -------------------------------- 8 files changed, 23 insertions(+), 49 deletions(-) delete mode 100755 types/index.d.ts diff --git a/package.json b/package.json index bf8b9e1f..6fcc842f 100755 --- a/package.json +++ b/package.json @@ -3,19 +3,20 @@ "version": "3.3.1", "description": "Transforms module resolution paths using TypeScript path mapping and/or custom paths", "main": "dist/index.js", - "types": "types/index.d.ts", + "types": "dist/index.d.ts", "scripts": { "compile": "tsc", - "build": "yarn run clean && yarn run compile", + "build": "yarn run clean && yarn run compile && yarn run check:built-types", "test": "jest", "release": "standard-version", "--------------": "", "format": "prettier --write \"{src,test}/**/{*.js,!(*.d).ts}\"", - "clean": "rimraf dist **/*.tsbuildinfo", - "clean:all": "yarn run clean && rimraf node_modules **/node_modules test/.yarn-cache", + "clean": "npx rimraf dist **/*.tsbuildinfo", + "clean:all": "yarn run clean && npx rimraf node_modules **/node_modules test/.yarn-cache", "reset": "yarn run clean:all && yarn install && yarn build", + "check:built-types": "tsc dist/index.d.ts --esModuleInterop", "-------------- ": "", - "prebuild": "rimraf dist", + "prebuild": "npx rimraf dist", "install:tests": "cd test && yarn install && cd projects/extras && yarn install", "prepare": "yarn run install:tests" }, diff --git a/src/index.ts b/src/index.ts index 337f0c94..dffb7865 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,5 +1,5 @@ import transformer from "./transformer"; export default transformer; -export { TsTransformPathsConfig } from "./types"; +export { TsTransformPathsConfig, TransformerExtras } from "./types"; export { register } from "./register"; diff --git a/src/transformer.ts b/src/transformer.ts index aad16fe1..a3d36a3e 100755 --- a/src/transformer.ts +++ b/src/transformer.ts @@ -2,13 +2,12 @@ import {} from "ts-expose-internals"; import path from "path"; import ts from "typescript"; -import { cast } from "./utils"; -import { TsTransformPathsConfig, TsTransformPathsContext, TypeScriptThree, VisitorContext } from "./types"; +import { TransformerExtras, TsTransformPathsConfig, TsTransformPathsContext, VisitorContext } from "./types"; import { nodeVisitor } from "./visitor"; import { createHarmonyFactory } from "./utils/harmony-factory"; import { Minimatch } from "minimatch"; import { createSyntheticEmitHost, getTsNodeRegistrationProperties } from "./utils/ts-helpers"; -import { TransformerExtras } from "ts-patch"; + /* ****************************************************************************************************************** */ // region: Helpers @@ -109,7 +108,6 @@ export default function transformer( emitHost, isTranspileOnly, isTsNode, - tsThreeInstance: cast(tsInstance), excludeMatchers: config.exclude?.map((globPattern) => new Minimatch(globPattern, { matchBase: true })), outputFileNamesCache: new Map(), // Get paths patterns appropriate for TS compiler version diff --git a/src/utils/harmony-factory.ts b/src/utils/harmony-factory.ts index d9ac1be4..b8b5a9f3 100755 --- a/src/utils/harmony-factory.ts +++ b/src/utils/harmony-factory.ts @@ -8,6 +8,8 @@ import TS, { NamedExportBindings, NamedImportBindings, } from "typescript"; +import { cast } from "./general-utils"; +import * as TsThree from '../declarations/typescript3'; import { TsTransformPathsContext } from "../types"; import { downSampleTsTypes } from "./ts-type-conversion"; @@ -27,7 +29,8 @@ export interface HarmonyFactory extends TS.NodeFactory {} * Creates a node factory compatible with TS v3+ */ export function createHarmonyFactory(context: TsTransformPathsContext): HarmonyFactory { - const { tsThreeInstance } = context; + const { tsInstance } = context; + const tsThreeInstance = cast(tsInstance); return new Proxy(context.tsFactory ?? context.tsInstance, { get(target, prop) { diff --git a/src/utils/resolve-module-name.ts b/src/utils/resolve-module-name.ts index b853dc76..5b1765da 100755 --- a/src/utils/resolve-module-name.ts +++ b/src/utils/resolve-module-name.ts @@ -88,6 +88,7 @@ function getReturnPath(ctx: GetReturnPathContext) { /** * Resolve a module name + * @internal — Uses internal TS type */ export function resolveModuleName( context: VisitorContext, diff --git a/src/utils/ts-type-conversion.ts b/src/utils/ts-type-conversion.ts index 1750eff8..6ffc2745 100755 --- a/src/utils/ts-type-conversion.ts +++ b/src/utils/ts-type-conversion.ts @@ -28,13 +28,13 @@ type TypeMapping = [ type TsType = Exclude; type TsThreeType = Exclude; -export type TsTypeConversion = { +type TsTypeConversion = { [i in keyof Tuple]: Tuple[i] extends any[] ? TsTypeConversion : DownSampleTsType; } & { length: Tuple["length"] }; type DownSampleTsType = T extends TsType ? Extract[1] : T; -export type UpSampleTsTypes = { +type UpSampleTsTypes = { [i in keyof Tuple]: Tuple[i] extends any[] ? UpSampleTsTypes : UpSampleTsType; } & { length: Tuple["length"] }; @@ -48,13 +48,15 @@ type UpSampleTsType = T extends TsThreeType ? Extract(...args: T): TsTypeConversion { return args as TsTypeConversion; } /** * Convert TS4 to TS3 type + * @internal */ export function downSampleTsType(v: T): DownSampleTsType { return v as DownSampleTsType; @@ -62,6 +64,7 @@ export function downSampleTsType(v: T): DownSampleTsType { /** * Convert TS3 to TS4 types + * @internal */ export function upSampleTsTypes(...args: T): UpSampleTsTypes { return args as UpSampleTsTypes; @@ -69,6 +72,7 @@ export function upSampleTsTypes(...args: T): UpSampleT /** * Convert TS3 to TS4 type + * @internal */ export function upSampleTsType(v: T): UpSampleTsType { return v as UpSampleTsType; diff --git a/tsconfig.json b/tsconfig.json index a9717747..84819c04 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -6,6 +6,7 @@ "compilerOptions": { "rootDir": "src", "outDir": "dist", - "declaration": true + "declaration": true, + "stripInternal": true } } diff --git a/types/index.d.ts b/types/index.d.ts deleted file mode 100755 index 67aef4ad..00000000 --- a/types/index.d.ts +++ /dev/null @@ -1,34 +0,0 @@ -import TSNode from 'ts-node' -import ts from 'typescript' - -/* ****************************************************************************************************************** * - * Hardcoded declarations file for npm package - * ****************************************************************************************************************** */ - -export interface TsTransformPathsConfig { - readonly useRootDirs?: boolean; - readonly exclude?: string[]; - readonly outputMode?: 'commonjs' | 'esm' -} - -export interface TransformerExtras { - /** - * Originating TypeScript instance - */ - ts: typeof ts; -} - -export function register(): TSNode.RegisterOptions | undefined - -export default function transformer( - program?: ts.Program, - pluginConfig?: TsTransformPathsConfig, - transformerExtras?: TransformerExtras, - /** - * Supply if manually transforming with compiler API via 'transformNodes' / 'transformModule' - */ - manualTransformOptions?: { - compilerOptions?: ts.CompilerOptions; - fileNames?: string[]; - } -): ts.CustomTransformer From c09ad4561daf09c68664fb5db593ec46a9c95109 Mon Sep 17 00:00:00 2001 From: Ron S Date: Sat, 30 Oct 2021 20:21:10 -0400 Subject: [PATCH 07/13] refactor: Initial v4 rewrite --- .all-contributorsrc | 171 - .editorconfig | 4 +- .github/workflows/main.yml | 1 + .github/workflows/publish.yml | 1 + .idea/inspectionProfiles/Project_Default.xml | 6 + jest.config.ts | 1 + package.json | 20 +- register.js | 2 +- .../node-register.ts} | 39 +- src/declarations/typescript3.d.ts | 13717 ---------------- src/index.ts | 28 +- src/resolve/extensions.ts | 23 + src/resolve/index-checker.ts | 120 + src/resolve/index.ts | 1 + src/resolve/output-path-detail.ts | 123 + src/resolve/resolve-module-name.ts | 234 + .../resolve-path-update-node.ts | 57 +- .../elide-import-export.ts | 5 +- src/transform/index.ts | 1 + src/transform/transformer.ts | 168 + src/{ => transform}/visitor.ts | 43 +- src/transformer.ts | 139 - src/ts/harmony-factory.ts | 98 + src/ts/index.ts | 2 + src/{utils => ts}/ts-helpers.ts | 80 +- src/types.ts | 293 +- src/utils.ts | 78 + src/utils/general-utils.ts | 16 - src/utils/harmony-factory.ts | 78 - src/utils/index.ts | 4 - src/utils/path.ts | 178 - src/utils/resolve-module-name.ts | 181 - src/utils/ts-type-conversion.ts | 81 - test/README.md | 124 + test/config.ts | 29 - test/package.json | 13 +- test/prepare.js | 26 +- test/projects/extras/package.json | 5 +- test/projects/extras/tsconfig.json | 2 +- test/projects/general/core/index.ts | 7 +- test/projects/general/tsconfig.json | 16 +- test/projects/project-ref/a/tsconfig.json | 1 + test/projects/project-ref/b/index.ts | 3 + test/projects/project-ref/b/tests.ts | 7 + test/projects/project-ref/b/tsconfig.json | 4 +- test/projects/project-ref/tsconfig.base.json | 19 +- test/projects/project-ref/tsconfig.json | 1 + test/projects/resolution/package.json | 11 + .../packages/external/esm/dir/main.d.ts | 1 + .../packages/external/esm/dir/main.js | 3 + .../packages/external/esm/dir/mod.d.ts | 1 + .../packages/external/esm/dir/mod.mjs | 1 + .../packages/external/esm/package.json | 10 + .../packages/external/root-idx}/index.d.ts | 0 .../packages/external/root-idx}/index.js | 0 .../packages/external/root-idx/other.d.ts | 1 + .../packages/external/root-idx/other.js | 1 + .../packages/external/root-idx}/package.json | 4 +- .../external/root-idx}/sub-pkg/main.d.ts | 0 .../external/root-idx}/sub-pkg/main.js | 0 .../external/root-idx}/sub-pkg/package.json | 0 .../external/root-named-idx}/main.d.ts | 0 .../packages/external/root-named-idx}/main.js | 0 .../external/root-named-idx/package.json | 6 + .../external/subdir-idx}/package.json | 4 +- .../external/subdir-idx}/subdir/main.d.ts | 0 .../external/subdir-idx}/subdir/main.js | 0 .../packages/internal/esm/dir/main.d.ts | 1 + .../packages/internal/esm/dir/main.js | 3 + .../packages/internal/esm/dir/mod.d.ts | 1 + .../packages/internal/esm/dir/mod.mjs | 1 + .../packages/internal/esm/package.json | 10 + .../packages/internal/root-idx/index.d.ts | 2 + .../packages/internal/root-idx/index.js | 3 + .../packages/internal/root-idx/package.json | 6 + .../internal/root-idx/sub-pkg/main.d.ts | 2 + .../internal/root-idx/sub-pkg/main.js | 3 + .../internal/root-idx/sub-pkg}/package.json | 4 +- .../internal/root-named-idx/main.d.ts | 2 + .../packages/internal/root-named-idx/main.js | 3 + .../internal/root-named-idx/package.json | 6 + .../packages/internal/subdir-idx/package.json | 6 + .../internal/subdir-idx/subdir/main.d.ts | 2 + .../internal/subdir-idx/subdir/main.js | 3 + test/projects/resolution/src/esm.ts | 28 + test/projects/resolution/src/indexes.ts | 51 + test/projects/resolution/src/local/index.ts | 0 test/projects/resolution/src/tricky.ts | 33 + test/projects/resolution/tests.ts | 37 + test/projects/resolution/tsconfig.json | 25 + .../root-dirs/generated/dir/gen-file.ts | 7 + test/projects/root-dirs/package.json | 5 + test/projects/root-dirs/src/dir/src-file.ts | 7 + test/projects/root-dirs/src/index.ts | 9 + test/projects/root-dirs/tests.ts | 13 + test/projects/root-dirs/tsconfig.json | 18 + .../specific/generated/dir/gen-file.ts | 3 - test/projects/specific/src/dir/src-file.ts | 4 - test/projects/specific/src/index.ts | 49 +- test/projects/specific/src/module-augment.ts | 6 +- test/projects/specific/src/sub-packages.ts | 13 - test/projects/specific/src/tags.ts | 10 + .../specific/src/type-elision/index.ts | 14 + test/projects/specific/tests.ts | 34 + test/projects/specific/tsconfig.json | 9 +- test/projects/specific/yarn.lock | 8 - test/src/config.ts | 22 + test/src/index.ts | 2 + test/src/setup.ts | 61 + test/src/ts-helpers.ts | 215 + test/src/ut-global/globals.d.ts | 117 + test/src/ut-global/package.json | 6 + test/src/ut-global/tsconfig.json | 7 + test/src/ut/index.ts | 3 + test/src/ut/matchers/to-resolve.ts | 47 + test/src/ut/project/index.ts | 1 + test/src/ut/project/load-project.ts | 154 + test/src/ut/project/project-walker.ts | 344 + test/src/ut/test-map.ts | 77 + test/src/ut/types.ts | 63 + test/src/ut/utils/create-config-spread.ts | 34 + test/src/ut/utils/node-helpers.ts | 66 + .../node-register.test.ts} | 35 +- test/tests/extras.test.ts | 41 - test/tests/project-ref.test.ts | 37 - test/tests/projects/extras.test.ts | 64 + test/tests/projects/general.test.ts | 92 + test/tests/projects/project-ref.test.ts | 26 + test/tests/projects/resolution.test.ts | 32 + test/tests/projects/root-dirs.test.ts | 23 + test/tests/projects/specific.test.ts | 25 + test/tests/transformer/general.test.ts | 63 - test/tests/transformer/specific.test.ts | 342 - test/transformer-wrapper/index.d.ts | 4 + test/transformer-wrapper/index.js | 3 + test/transformer-wrapper/package.json | 7 + test/tsconfig.json | 7 +- test/utils/helpers.ts | 203 - test/utils/index.ts | 1 - test/yarn.lock | 269 + tsconfig.json | 1 - yarn.lock | 31 +- 142 files changed, 3698 insertions(+), 15561 deletions(-) delete mode 100644 .all-contributorsrc create mode 100755 .idea/inspectionProfiles/Project_Default.xml rename src/{register.ts => compatibility/node-register.ts} (82%) delete mode 100755 src/declarations/typescript3.d.ts create mode 100755 src/resolve/extensions.ts create mode 100755 src/resolve/index-checker.ts create mode 100755 src/resolve/index.ts create mode 100755 src/resolve/output-path-detail.ts create mode 100755 src/resolve/resolve-module-name.ts rename src/{utils => resolve}/resolve-path-update-node.ts (62%) rename src/{utils => transform}/elide-import-export.ts (98%) create mode 100755 src/transform/index.ts create mode 100755 src/transform/transformer.ts rename src/{ => transform}/visitor.ts (72%) delete mode 100755 src/transformer.ts create mode 100755 src/ts/harmony-factory.ts create mode 100755 src/ts/index.ts rename src/{utils => ts}/ts-helpers.ts (54%) create mode 100755 src/utils.ts delete mode 100755 src/utils/general-utils.ts delete mode 100755 src/utils/harmony-factory.ts delete mode 100755 src/utils/index.ts delete mode 100755 src/utils/path.ts delete mode 100755 src/utils/resolve-module-name.ts delete mode 100755 src/utils/ts-type-conversion.ts create mode 100755 test/README.md delete mode 100755 test/config.ts create mode 100755 test/projects/project-ref/b/tests.ts create mode 100755 test/projects/resolution/package.json create mode 100755 test/projects/resolution/packages/external/esm/dir/main.d.ts create mode 100755 test/projects/resolution/packages/external/esm/dir/main.js create mode 100755 test/projects/resolution/packages/external/esm/dir/mod.d.ts create mode 100755 test/projects/resolution/packages/external/esm/dir/mod.mjs create mode 100755 test/projects/resolution/packages/external/esm/package.json rename test/projects/{specific/src/packages/pkg-a => resolution/packages/external/root-idx}/index.d.ts (100%) rename test/projects/{specific/src/packages/pkg-a => resolution/packages/external/root-idx}/index.js (100%) create mode 100755 test/projects/resolution/packages/external/root-idx/other.d.ts create mode 100755 test/projects/resolution/packages/external/root-idx/other.js rename test/projects/{specific/src/packages/pkg-a => resolution/packages/external/root-idx}/package.json (50%) rename test/projects/{specific/src/packages/pkg-a => resolution/packages/external/root-idx}/sub-pkg/main.d.ts (100%) rename test/projects/{specific/src/packages/pkg-a => resolution/packages/external/root-idx}/sub-pkg/main.js (100%) rename test/projects/{specific/src/packages/pkg-a => resolution/packages/external/root-idx}/sub-pkg/package.json (100%) rename test/projects/{specific/src/packages/pkg-c => resolution/packages/external/root-named-idx}/main.d.ts (100%) rename test/projects/{specific/src/packages/pkg-c => resolution/packages/external/root-named-idx}/main.js (100%) create mode 100755 test/projects/resolution/packages/external/root-named-idx/package.json rename test/projects/{specific/src/packages/pkg-b => resolution/packages/external/subdir-idx}/package.json (53%) rename test/projects/{specific/src/packages/pkg-b => resolution/packages/external/subdir-idx}/subdir/main.d.ts (100%) rename test/projects/{specific/src/packages/pkg-b => resolution/packages/external/subdir-idx}/subdir/main.js (100%) create mode 100755 test/projects/resolution/packages/internal/esm/dir/main.d.ts create mode 100755 test/projects/resolution/packages/internal/esm/dir/main.js create mode 100755 test/projects/resolution/packages/internal/esm/dir/mod.d.ts create mode 100755 test/projects/resolution/packages/internal/esm/dir/mod.mjs create mode 100755 test/projects/resolution/packages/internal/esm/package.json create mode 100755 test/projects/resolution/packages/internal/root-idx/index.d.ts create mode 100755 test/projects/resolution/packages/internal/root-idx/index.js create mode 100755 test/projects/resolution/packages/internal/root-idx/package.json create mode 100755 test/projects/resolution/packages/internal/root-idx/sub-pkg/main.d.ts create mode 100755 test/projects/resolution/packages/internal/root-idx/sub-pkg/main.js rename test/projects/{specific/src/packages/pkg-c => resolution/packages/internal/root-idx/sub-pkg}/package.json (56%) create mode 100755 test/projects/resolution/packages/internal/root-named-idx/main.d.ts create mode 100755 test/projects/resolution/packages/internal/root-named-idx/main.js create mode 100755 test/projects/resolution/packages/internal/root-named-idx/package.json create mode 100755 test/projects/resolution/packages/internal/subdir-idx/package.json create mode 100755 test/projects/resolution/packages/internal/subdir-idx/subdir/main.d.ts create mode 100755 test/projects/resolution/packages/internal/subdir-idx/subdir/main.js create mode 100755 test/projects/resolution/src/esm.ts create mode 100755 test/projects/resolution/src/indexes.ts create mode 100755 test/projects/resolution/src/local/index.ts create mode 100755 test/projects/resolution/src/tricky.ts create mode 100755 test/projects/resolution/tests.ts create mode 100755 test/projects/resolution/tsconfig.json create mode 100755 test/projects/root-dirs/generated/dir/gen-file.ts create mode 100755 test/projects/root-dirs/package.json create mode 100755 test/projects/root-dirs/src/dir/src-file.ts create mode 100755 test/projects/root-dirs/src/index.ts create mode 100755 test/projects/root-dirs/tests.ts create mode 100755 test/projects/root-dirs/tsconfig.json delete mode 100755 test/projects/specific/generated/dir/gen-file.ts delete mode 100755 test/projects/specific/src/dir/src-file.ts delete mode 100755 test/projects/specific/src/sub-packages.ts create mode 100755 test/projects/specific/tests.ts delete mode 100755 test/projects/specific/yarn.lock create mode 100755 test/src/config.ts create mode 100755 test/src/index.ts create mode 100755 test/src/setup.ts create mode 100755 test/src/ts-helpers.ts create mode 100755 test/src/ut-global/globals.d.ts create mode 100755 test/src/ut-global/package.json create mode 100755 test/src/ut-global/tsconfig.json create mode 100755 test/src/ut/index.ts create mode 100755 test/src/ut/matchers/to-resolve.ts create mode 100755 test/src/ut/project/index.ts create mode 100755 test/src/ut/project/load-project.ts create mode 100755 test/src/ut/project/project-walker.ts create mode 100755 test/src/ut/test-map.ts create mode 100755 test/src/ut/types.ts create mode 100755 test/src/ut/utils/create-config-spread.ts create mode 100755 test/src/ut/utils/node-helpers.ts rename test/tests/{register.test.ts => compatibility/node-register.test.ts} (90%) delete mode 100755 test/tests/extras.test.ts delete mode 100755 test/tests/project-ref.test.ts create mode 100755 test/tests/projects/extras.test.ts create mode 100755 test/tests/projects/general.test.ts create mode 100755 test/tests/projects/project-ref.test.ts create mode 100755 test/tests/projects/resolution.test.ts create mode 100755 test/tests/projects/root-dirs.test.ts create mode 100755 test/tests/projects/specific.test.ts delete mode 100755 test/tests/transformer/general.test.ts delete mode 100755 test/tests/transformer/specific.test.ts create mode 100755 test/transformer-wrapper/index.d.ts create mode 100755 test/transformer-wrapper/index.js create mode 100755 test/transformer-wrapper/package.json delete mode 100755 test/utils/helpers.ts delete mode 100755 test/utils/index.ts create mode 100755 test/yarn.lock diff --git a/.all-contributorsrc b/.all-contributorsrc deleted file mode 100644 index 2a751582..00000000 --- a/.all-contributorsrc +++ /dev/null @@ -1,171 +0,0 @@ -{ - "projectName": "typescript-transform-paths", - "projectOwner": "LeDDGroup", - "repoType": "github", - "repoHost": "https://github.com", - "files": [ - "README.md" - ], - "imageSize": 100, - "commit": true, - "commitConvention": "angular", - "contributors": [ - { - "login": "danielpza", - "name": "Daniel Perez Alvarez", - "avatar_url": "https://avatars2.githubusercontent.com/u/17787042?v=4", - "profile": "https://github.com/danielpza", - "contributions": [ - "code", - "maintenance", - "test" - ] - }, - { - "login": "anion155", - "name": "Михайлов Антон", - "avatar_url": "https://avatars1.githubusercontent.com/u/4786672?v=4", - "profile": "https://github.com/anion155", - "contributions": [ - "code", - "bug", - "test" - ] - }, - { - "login": "joshuaavalon", - "name": "Joshua Avalon", - "avatar_url": "https://avatars0.githubusercontent.com/u/7152420?v=4", - "profile": "https://joshuaavalon.io", - "contributions": [ - "bug", - "platform" - ] - }, - { - "login": "roblav96", - "name": "Robert Laverty", - "avatar_url": "https://avatars1.githubusercontent.com/u/1457327?v=4", - "profile": "https://roblav96.github.io/resume", - "contributions": [ - "bug", - "test" - ] - }, - { - "login": "oleersoy", - "name": "Ole Ersoy", - "avatar_url": "https://avatars3.githubusercontent.com/u/1163873?v=4", - "profile": "https://github.com/oleersoy", - "contributions": [ - "bug", - "blog" - ] - }, - { - "login": "sbmw", - "name": "sbmw", - "avatar_url": "https://avatars0.githubusercontent.com/u/30099628?v=4", - "profile": "https://github.com/sbmw", - "contributions": [ - "bug" - ] - }, - { - "login": "richardspence", - "name": "richardspence", - "avatar_url": "https://avatars2.githubusercontent.com/u/9914123?v=4", - "profile": "https://github.com/richardspence", - "contributions": [ - "bug" - ] - }, - { - "login": "viT-1", - "name": "Vitaly Pinchuk", - "avatar_url": "https://avatars1.githubusercontent.com/u/19496430?v=4", - "profile": "http://codepen.io/viT-1/", - "contributions": [ - "bug" - ] - }, - { - "login": "laij84", - "name": "laij84", - "avatar_url": "https://avatars0.githubusercontent.com/u/18145822?v=4", - "profile": "https://github.com/laij84", - "contributions": [ - "bug" - ] - }, - { - "login": "dko-slapdash", - "name": "dko-slapdash", - "avatar_url": "https://avatars0.githubusercontent.com/u/46383452?v=4", - "profile": "https://github.com/dko-slapdash", - "contributions": [ - "bug" - ] - }, - { - "login": "hedwiggggg", - "name": "hedwiggggg", - "avatar_url": "https://avatars1.githubusercontent.com/u/42947316?v=4", - "profile": "https://github.com/hedwiggggg", - "contributions": [ - "bug", - "test", - "code" - ] - }, - { - "login": "kuskoman", - "name": "kuskoman", - "avatar_url": "https://avatars3.githubusercontent.com/u/15456923?v=4", - "profile": "https://github.com/kuskoman", - "contributions": [ - "doc" - ] - }, - { - "login": "booninite", - "name": "alex weidner", - "avatar_url": "https://avatars3.githubusercontent.com/u/13647495?v=4", - "profile": "https://github.com/booninite", - "contributions": [ - "bug" - ] - }, - { - "login": "nonara", - "name": "Ron S.", - "avatar_url": "https://avatars0.githubusercontent.com/u/1427565?v=4", - "profile": "https://github.com/nonara", - "contributions": [ - "bug", - "test", - "code" - ] - }, - { - "login": "vladimiry", - "name": "Vladimir Yakovlev", - "avatar_url": "https://avatars2.githubusercontent.com/u/1560781?v=4", - "profile": "https://github.com/vladimiry", - "contributions": [ - "bug" - ] - }, - { - "login": "vwpo", - "name": "vwpo", - "avatar_url": "https://avatars3.githubusercontent.com/u/57674261?v=4", - "profile": "https://github.com/vwpo", - "contributions": [ - "bug" - ] - } - ], - "contributorsPerLine": 7, - "skipCi": true -} diff --git a/.editorconfig b/.editorconfig index f8256e8a..b67b1aed 100644 --- a/.editorconfig +++ b/.editorconfig @@ -34,7 +34,7 @@ ij_javascript_align_multiline_extends_list = false ij_javascript_align_multiline_for = true ij_javascript_align_multiline_parameters = true ij_javascript_align_multiline_parameters_in_calls = false -ij_javascript_align_multiline_ternary_operation = true +ij_javascript_align_multiline_ternary_operation = false ij_javascript_align_object_properties = 0 ij_javascript_align_union_types = false ij_javascript_align_var_statements = 0 @@ -218,7 +218,7 @@ ij_typescript_align_multiline_extends_list = false ij_typescript_align_multiline_for = true ij_typescript_align_multiline_parameters = true ij_typescript_align_multiline_parameters_in_calls = false -ij_typescript_align_multiline_ternary_operation = true +ij_typescript_align_multiline_ternary_operation = false ij_typescript_align_object_properties = 0 ij_typescript_align_union_types = false ij_typescript_align_var_statements = 0 diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index a5eed62b..e66711a3 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -34,3 +34,4 @@ jobs: run: yarn test env: CI: true + TEST_TARGET: dist diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 7824f55a..9e766a06 100755 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -41,6 +41,7 @@ jobs: run: yarn test env: CI: true + TEST_TARGET: dist - name: Generate Release Body run: npx extract-changelog-release > RELEASE_BODY.md diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100755 index 00000000..37498d0a --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/jest.config.ts b/jest.config.ts index e2d81f09..0b92e5af 100755 --- a/jest.config.ts +++ b/jest.config.ts @@ -12,6 +12,7 @@ const config: Config.InitialOptions = { }, modulePaths: [ "" ], roots: [ '' ], + setupFilesAfterEnv: [ "./test/src/setup.ts" ] } export default config; diff --git a/package.json b/package.json index 6fcc842f..bb2ced5d 100755 --- a/package.json +++ b/package.json @@ -7,17 +7,19 @@ "scripts": { "compile": "tsc", "build": "yarn run clean && yarn run compile && yarn run check:built-types", + "check:built-types": "tsc dist/index.d.ts --esModuleInterop", + "-------------- ": "", "test": "jest", - "release": "standard-version", + "test:src": "cross-env TEST_TARGET=src jest", + "test:dist": "cross-env TEST_TARGET=dist jest", "--------------": "", "format": "prettier --write \"{src,test}/**/{*.js,!(*.d).ts}\"", "clean": "npx rimraf dist **/*.tsbuildinfo", "clean:all": "yarn run clean && npx rimraf node_modules **/node_modules test/.yarn-cache", "reset": "yarn run clean:all && yarn install && yarn build", - "check:built-types": "tsc dist/index.d.ts --esModuleInterop", "-------------- ": "", "prebuild": "npx rimraf dist", - "install:tests": "cd test && yarn install && cd projects/extras && yarn install", + "install:tests": "cd test && yarn install", "prepare": "yarn run install:tests" }, "keywords": [ @@ -55,20 +57,26 @@ "@types/jest": "^26.0.24", "@types/minimatch": "^3.0.5", "@types/node": "^16.4.10", + "@types/ts-expose-internals": "npm:ts-expose-internals@4.4.3", + "cross-env": "^7.0.3", "jest": "^27.0.6", "prettier": "^2.3.2", "rimraf": "^3.0.2", "standard-version": "^9.3.1", - "ts-expose-internals": "^4.4.3", "ts-jest": "^27.0.4", "ts-node": "^10.1.0", "ts-patch": "^1.4.4", - "typescript": "^4.4.3" + "ts3": "npm:typescript@3.7.7", + "ts45": "npm:typescript@4.5.0-beta", + "typescript": "latest" }, "peerDependencies": { - "typescript": ">=3.6.5" + "typescript": ">=4.2.2" }, "dependencies": { "minimatch": "^3.0.4" + }, + "prettier": { + "singleQuote": true } } diff --git a/register.js b/register.js index 09242271..c6f41b0e 100755 --- a/register.js +++ b/register.js @@ -8,4 +8,4 @@ try { } tsNode.register(); -require('./').register(); +require('./').nodeRegister(); diff --git a/src/register.ts b/src/compatibility/node-register.ts similarity index 82% rename from src/register.ts rename to src/compatibility/node-register.ts index 3ac76fd7..242892c3 100755 --- a/src/register.ts +++ b/src/compatibility/node-register.ts @@ -1,19 +1,30 @@ import type TSNode from "ts-node"; import type { REGISTER_INSTANCE } from "ts-node"; -import ts from "typescript"; -import transformer from "./transformer"; +import type TS from "typescript"; +import { transformer } from "../transform"; /* ****************************************************************************************************************** */ // region: Helpers /* ****************************************************************************************************************** */ -function getProjectTransformerConfig(pcl: ts.ParsedCommandLine) { +const checkModuleIsTsTp = (m: string) => { + let transformerModule: any; + try { + transformerModule = require(m); + } catch {} + + if (!transformerModule) return m === 'typescript-transform-paths'; + + return transformerModule.isTsTp; +} + +function getProjectTransformerConfig(pcl: TS.ParsedCommandLine) { const plugins = pcl.options.plugins as Record[] | undefined; if (!plugins) return; const res: { afterDeclarations?: Record; before?: Record } = {}; for (const plugin of plugins) { - if (plugin.transform === "typescript-transform-paths" && !plugin.after) + if (plugin.transform && checkModuleIsTsTp(plugin.transform) && !plugin.after) res[plugin.afterDeclarations ? "afterDeclarations" : "before"] = plugin; } @@ -21,20 +32,20 @@ function getProjectTransformerConfig(pcl: ts.ParsedCommandLine) { } function getTransformers( - program?: ts.Program, + program?: TS.Program, beforeConfig?: Record, afterDeclarationsConfig?: Record -): ts.CustomTransformers { +): TS.CustomTransformers { return { ...(beforeConfig && { before: [transformer(program, beforeConfig)] }), ...(afterDeclarationsConfig && { afterDeclarations: [transformer(program, afterDeclarationsConfig)] }), - } as ts.CustomTransformers; + } as TS.CustomTransformers; } export function mergeTransformers( - baseTransformers: ts.CustomTransformers, - transformers: ts.CustomTransformers -): ts.CustomTransformers { + baseTransformers: TS.CustomTransformers, + transformers: TS.CustomTransformers +): TS.CustomTransformers { const res = { ...((baseTransformers.before || transformers.before) && { before: [...(transformers.before ?? []), ...(baseTransformers.before ?? [])], @@ -57,8 +68,8 @@ export function mergeTransformers( // region: TsNode Registration Utility /* ****************************************************************************************************************** */ -export function register(): TSNode.RegisterOptions | undefined { - const { tsNodeInstance, tsNode } = register.initialize(); +export function nodeRegister(): TSNode.RegisterOptions | undefined { + const { tsNodeInstance, tsNode } = nodeRegister.initialize(); const transformerConfig = getProjectTransformerConfig(tsNodeInstance.config); if (!transformerConfig) return; @@ -89,7 +100,7 @@ export function register(): TSNode.RegisterOptions | undefined { return registerOptions; } -export namespace register { +export namespace nodeRegister { export function initialize(): { tsNode: typeof TSNode; instanceSymbol: typeof REGISTER_INSTANCE; @@ -117,6 +128,4 @@ export namespace register { } } -export default register; - // endregion diff --git a/src/declarations/typescript3.d.ts b/src/declarations/typescript3.d.ts deleted file mode 100755 index 6b59236a..00000000 --- a/src/declarations/typescript3.d.ts +++ /dev/null @@ -1,13717 +0,0 @@ -/*! ***************************************************************************** -Copyright (c) Microsoft Corporation. All rights reserved. -Licensed under the Apache License, Version 2.0 (the "License"); you may not use -this file except in compliance with the License. You may obtain a copy of the -License at http://www.apache.org/licenses/LICENSE-2.0 - -THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED -WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -MERCHANTABLITY OR NON-INFRINGEMENT. - -See the Apache Version 2.0 License for specific language governing permissions -and limitations under the License. -***************************************************************************** */ - -declare namespace ts { - const versionMajorMinor = "3.7"; - /** The version of the TypeScript compiler release */ - const version: string; -} -declare namespace ts { - /** - * Type of objects whose values are all of the same type. - * The `in` and `for-in` operators can *not* be safely used, - * since `Object.prototype` may be modified by outside code. - */ - interface MapLike { - [index: string]: T; - } - interface SortedReadonlyArray extends ReadonlyArray { - " __sortedArrayBrand": any; - } - interface SortedArray extends Array { - " __sortedArrayBrand": any; - } - /** ES6 Map interface, only read methods included. */ - interface ReadonlyMap { - get(key: string): T | undefined; - has(key: string): boolean; - forEach(action: (value: T, key: string) => void): void; - readonly size: number; - keys(): Iterator; - values(): Iterator; - entries(): Iterator<[string, T]>; - } - /** ES6 Map interface. */ - interface Map extends ReadonlyMap { - set(key: string, value: T): this; - delete(key: string): boolean; - clear(): void; - } - /** ES6 Iterator type. */ - interface Iterator { - next(): { - value: T; - done?: false; - } | { - value: never; - done: true; - }; - } - /** Array that is only intended to be pushed to, never read. */ - interface Push { - push(...values: T[]): void; - } - type EqualityComparer = (a: T, b: T) => boolean; - type Comparer = (a: T, b: T) => Comparison; - enum Comparison { - LessThan = -1, - EqualTo = 0, - GreaterThan = 1 - } -} -declare namespace ts { - const emptyArray: never[]; - /** Create a new map. If a template object is provided, the map will copy entries from it. */ - function createMap(): Map; - function createMapFromEntries(entries: [string, T][]): Map; - function createMapFromTemplate(template: MapLike): Map; - const MapCtr: new () => Map; - function shimMap(): new () => Map; - function length(array: ReadonlyArray | undefined): number; - /** - * Iterates through 'array' by index and performs the callback on each element of array until the callback - * returns a truthy value, then returns that value. - * If no such value is found, the callback is applied to each element of array and undefined is returned. - */ - function forEach(array: ReadonlyArray | undefined, callback: (element: T, index: number) => U | undefined): U | undefined; - /** Like `forEach`, but suitable for use with numbers and strings (which may be falsy). */ - function firstDefined(array: ReadonlyArray | undefined, callback: (element: T, index: number) => U | undefined): U | undefined; - function firstDefinedIterator(iter: Iterator, callback: (element: T) => U | undefined): U | undefined; - function zipWith(arrayA: ReadonlyArray, arrayB: ReadonlyArray, callback: (a: T, b: U, index: number) => V): V[]; - function zipToIterator(arrayA: ReadonlyArray, arrayB: ReadonlyArray): Iterator<[T, U]>; - function zipToMap(keys: ReadonlyArray, values: ReadonlyArray): Map; - /** - * Iterates through `array` by index and performs the callback on each element of array until the callback - * returns a falsey value, then returns false. - * If no such value is found, the callback is applied to each element of array and `true` is returned. - */ - function every(array: ReadonlyArray, callback: (element: T, index: number) => boolean): boolean; - /** Works like Array.prototype.find, returning `undefined` if no element satisfying the predicate is found. */ - function find(array: ReadonlyArray, predicate: (element: T, index: number) => element is U): U | undefined; - function find(array: ReadonlyArray, predicate: (element: T, index: number) => boolean): T | undefined; - function findLast(array: ReadonlyArray, predicate: (element: T, index: number) => element is U): U | undefined; - function findLast(array: ReadonlyArray, predicate: (element: T, index: number) => boolean): T | undefined; - /** Works like Array.prototype.findIndex, returning `-1` if no element satisfying the predicate is found. */ - function findIndex(array: ReadonlyArray, predicate: (element: T, index: number) => boolean, startIndex?: number): number; - function findLastIndex(array: ReadonlyArray, predicate: (element: T, index: number) => boolean, startIndex?: number): number; - /** - * Returns the first truthy result of `callback`, or else fails. - * This is like `forEach`, but never returns undefined. - */ - function findMap(array: ReadonlyArray, callback: (element: T, index: number) => U | undefined): U; - function contains(array: ReadonlyArray | undefined, value: T, equalityComparer?: EqualityComparer): boolean; - function arraysEqual(a: ReadonlyArray, b: ReadonlyArray, equalityComparer?: EqualityComparer): boolean; - function indexOfAnyCharCode(text: string, charCodes: ReadonlyArray, start?: number): number; - function countWhere(array: ReadonlyArray, predicate: (x: T, i: number) => boolean): number; - /** - * Filters an array by a predicate function. Returns the same array instance if the predicate is - * true for all elements, otherwise returns a new array instance containing the filtered subset. - */ - function filter(array: T[], f: (x: T) => x is U): U[]; - function filter(array: T[], f: (x: T) => boolean): T[]; - function filter(array: ReadonlyArray, f: (x: T) => x is U): ReadonlyArray; - function filter(array: ReadonlyArray, f: (x: T) => boolean): ReadonlyArray; - function filter(array: T[] | undefined, f: (x: T) => x is U): U[] | undefined; - function filter(array: T[] | undefined, f: (x: T) => boolean): T[] | undefined; - function filter(array: ReadonlyArray | undefined, f: (x: T) => x is U): ReadonlyArray | undefined; - function filter(array: ReadonlyArray | undefined, f: (x: T) => boolean): ReadonlyArray | undefined; - function filterMutate(array: T[], f: (x: T, i: number, array: T[]) => boolean): void; - function clear(array: {}[]): void; - function map(array: ReadonlyArray, f: (x: T, i: number) => U): U[]; - function map(array: ReadonlyArray | undefined, f: (x: T, i: number) => U): U[] | undefined; - function mapIterator(iter: Iterator, mapFn: (x: T) => U): Iterator; - function sameMap(array: T[], f: (x: T, i: number) => T): T[]; - function sameMap(array: ReadonlyArray, f: (x: T, i: number) => T): ReadonlyArray; - function sameMap(array: T[] | undefined, f: (x: T, i: number) => T): T[] | undefined; - function sameMap(array: ReadonlyArray | undefined, f: (x: T, i: number) => T): ReadonlyArray | undefined; - /** - * Flattens an array containing a mix of array or non-array elements. - * - * @param array The array to flatten. - */ - function flatten(array: T[][] | ReadonlyArray | undefined>): T[]; - /** - * Maps an array. If the mapped value is an array, it is spread into the result. - * - * @param array The array to map. - * @param mapfn The callback used to map the result into one or more values. - */ - function flatMap(array: ReadonlyArray | undefined, mapfn: (x: T, i: number) => U | ReadonlyArray | undefined): ReadonlyArray; - function flatMapToMutable(array: ReadonlyArray | undefined, mapfn: (x: T, i: number) => U | ReadonlyArray | undefined): U[]; - function flatMapIterator(iter: Iterator, mapfn: (x: T) => ReadonlyArray | Iterator | undefined): Iterator; - /** - * Maps an array. If the mapped value is an array, it is spread into the result. - * Avoids allocation if all elements map to themselves. - * - * @param array The array to map. - * @param mapfn The callback used to map the result into one or more values. - */ - function sameFlatMap(array: T[], mapfn: (x: T, i: number) => T | ReadonlyArray): T[]; - function sameFlatMap(array: ReadonlyArray, mapfn: (x: T, i: number) => T | ReadonlyArray): ReadonlyArray; - function mapAllOrFail(array: ReadonlyArray, mapFn: (x: T, i: number) => U | undefined): U[] | undefined; - function mapDefined(array: ReadonlyArray | undefined, mapFn: (x: T, i: number) => U | undefined): U[]; - function mapDefinedIterator(iter: Iterator, mapFn: (x: T) => U | undefined): Iterator; - const emptyIterator: Iterator; - function singleIterator(value: T): Iterator; - /** - * Maps contiguous spans of values with the same key. - * - * @param array The array to map. - * @param keyfn A callback used to select the key for an element. - * @param mapfn A callback used to map a contiguous chunk of values to a single value. - */ - function spanMap(array: ReadonlyArray, keyfn: (x: T, i: number) => K, mapfn: (chunk: T[], key: K, start: number, end: number) => U): U[]; - function spanMap(array: ReadonlyArray | undefined, keyfn: (x: T, i: number) => K, mapfn: (chunk: T[], key: K, start: number, end: number) => U): U[] | undefined; - function mapEntries(map: ReadonlyMap, f: (key: string, value: T) => [string, U]): Map; - function mapEntries(map: ReadonlyMap | undefined, f: (key: string, value: T) => [string, U]): Map | undefined; - function some(array: ReadonlyArray | undefined): array is ReadonlyArray; - function some(array: ReadonlyArray | undefined, predicate: (value: T) => boolean): boolean; - /** Calls the callback with (start, afterEnd) index pairs for each range where 'pred' is true. */ - function getRangesWhere(arr: ReadonlyArray, pred: (t: T) => boolean, cb: (start: number, afterEnd: number) => void): void; - function concatenate(array1: T[], array2: T[]): T[]; - function concatenate(array1: ReadonlyArray, array2: ReadonlyArray): ReadonlyArray; - function concatenate(array1: T[] | undefined, array2: T[] | undefined): T[]; - function concatenate(array1: ReadonlyArray | undefined, array2: ReadonlyArray | undefined): ReadonlyArray; - /** - * Deduplicates an unsorted array. - * @param equalityComparer An `EqualityComparer` used to determine if two values are duplicates. - * @param comparer An optional `Comparer` used to sort entries before comparison, though the - * result will remain in the original order in `array`. - */ - function deduplicate(array: ReadonlyArray, equalityComparer: EqualityComparer, comparer?: Comparer): T[]; - function insertSorted(array: SortedArray, insert: T, compare: Comparer): void; - function sortAndDeduplicate(array: ReadonlyArray): SortedReadonlyArray; - function sortAndDeduplicate(array: ReadonlyArray, comparer: Comparer, equalityComparer?: EqualityComparer): SortedReadonlyArray; - function arrayIsEqualTo(array1: ReadonlyArray | undefined, array2: ReadonlyArray | undefined, equalityComparer?: (a: T, b: T, index: number) => boolean): boolean; - /** - * Compacts an array, removing any falsey elements. - */ - function compact(array: (T | undefined | null | false | 0 | "")[]): T[]; - function compact(array: ReadonlyArray): ReadonlyArray; - function compact(array: T[]): T[]; - function compact(array: ReadonlyArray): ReadonlyArray; - /** - * Gets the relative complement of `arrayA` with respect to `arrayB`, returning the elements that - * are not present in `arrayA` but are present in `arrayB`. Assumes both arrays are sorted - * based on the provided comparer. - */ - function relativeComplement(arrayA: T[] | undefined, arrayB: T[] | undefined, comparer: Comparer): T[] | undefined; - function sum, K extends string>(array: ReadonlyArray, prop: K): number; - /** - * Appends a value to an array, returning the array. - * - * @param to The array to which `value` is to be appended. If `to` is `undefined`, a new array - * is created if `value` was appended. - * @param value The value to append to the array. If `value` is `undefined`, nothing is - * appended. - */ - function append[number] | undefined>(to: TArray, value: TValue): [undefined, undefined] extends [TArray, TValue] ? TArray : NonNullable[number][]; - function append(to: T[], value: T | undefined): T[]; - function append(to: T[] | undefined, value: T): T[]; - function append(to: T[] | undefined, value: T | undefined): T[] | undefined; - function append(to: Push, value: T | undefined): void; - /** - * Appends a range of value to an array, returning the array. - * - * @param to The array to which `value` is to be appended. If `to` is `undefined`, a new array - * is created if `value` was appended. - * @param from The values to append to the array. If `from` is `undefined`, nothing is - * appended. If an element of `from` is `undefined`, that element is not appended. - * @param start The offset in `from` at which to start copying values. - * @param end The offset in `from` at which to stop copying values (non-inclusive). - */ - function addRange(to: T[], from: ReadonlyArray | undefined, start?: number, end?: number): T[]; - function addRange(to: T[] | undefined, from: ReadonlyArray | undefined, start?: number, end?: number): T[] | undefined; - /** - * @return Whether the value was added. - */ - function pushIfUnique(array: T[], toAdd: T, equalityComparer?: EqualityComparer): boolean; - /** - * Unlike `pushIfUnique`, this can take `undefined` as an input, and returns a new array. - */ - function appendIfUnique(array: T[] | undefined, toAdd: T, equalityComparer?: EqualityComparer): T[]; - /** - * Returns a new sorted array. - */ - function sort(array: ReadonlyArray, comparer?: Comparer): SortedReadonlyArray; - function arrayIterator(array: ReadonlyArray): Iterator; - function arrayReverseIterator(array: ReadonlyArray): Iterator; - /** - * Stable sort of an array. Elements equal to each other maintain their relative position in the array. - */ - function stableSort(array: ReadonlyArray, comparer: Comparer): SortedReadonlyArray; - function rangeEquals(array1: ReadonlyArray, array2: ReadonlyArray, pos: number, end: number): boolean; - /** - * Returns the element at a specific offset in an array if non-empty, `undefined` otherwise. - * A negative offset indicates the element should be retrieved from the end of the array. - */ - function elementAt(array: ReadonlyArray | undefined, offset: number): T | undefined; - /** - * Returns the first element of an array if non-empty, `undefined` otherwise. - */ - function firstOrUndefined(array: ReadonlyArray): T | undefined; - function first(array: ReadonlyArray): T; - /** - * Returns the last element of an array if non-empty, `undefined` otherwise. - */ - function lastOrUndefined(array: ReadonlyArray): T | undefined; - function last(array: ReadonlyArray): T; - /** - * Returns the only element of an array if it contains only one element, `undefined` otherwise. - */ - function singleOrUndefined(array: ReadonlyArray | undefined): T | undefined; - /** - * Returns the only element of an array if it contains only one element; otherwise, returns the - * array. - */ - function singleOrMany(array: T[]): T | T[]; - function singleOrMany(array: ReadonlyArray): T | ReadonlyArray; - function singleOrMany(array: T[] | undefined): T | T[] | undefined; - function singleOrMany(array: ReadonlyArray | undefined): T | ReadonlyArray | undefined; - function replaceElement(array: ReadonlyArray, index: number, value: T): T[]; - /** - * Performs a binary search, finding the index at which `value` occurs in `array`. - * If no such index is found, returns the 2's-complement of first index at which - * `array[index]` exceeds `value`. - * @param array A sorted array whose first element must be no larger than number - * @param value The value to be searched for in the array. - * @param keySelector A callback used to select the search key from `value` and each element of - * `array`. - * @param keyComparer A callback used to compare two keys in a sorted array. - * @param offset An offset into `array` at which to start the search. - */ - function binarySearch(array: ReadonlyArray, value: T, keySelector: (v: T) => U, keyComparer: Comparer, offset?: number): number; - /** - * Performs a binary search, finding the index at which an object with `key` occurs in `array`. - * If no such index is found, returns the 2's-complement of first index at which - * `array[index]` exceeds `key`. - * @param array A sorted array whose first element must be no larger than number - * @param key The key to be searched for in the array. - * @param keySelector A callback used to select the search key from each element of `array`. - * @param keyComparer A callback used to compare two keys in a sorted array. - * @param offset An offset into `array` at which to start the search. - */ - function binarySearchKey(array: ReadonlyArray, key: U, keySelector: (v: T) => U, keyComparer: Comparer, offset?: number): number; - function reduceLeft(array: ReadonlyArray | undefined, f: (memo: U, value: T, i: number) => U, initial: U, start?: number, count?: number): U; - function reduceLeft(array: ReadonlyArray, f: (memo: T, value: T, i: number) => T): T | undefined; - /** - * Indicates whether a map-like contains an own property with the specified key. - * - * @param map A map-like. - * @param key A property key. - */ - function hasProperty(map: MapLike, key: string): boolean; - /** - * Gets the value of an owned property in a map-like. - * - * @param map A map-like. - * @param key A property key. - */ - function getProperty(map: MapLike, key: string): T | undefined; - /** - * Gets the owned, enumerable property keys of a map-like. - */ - function getOwnKeys(map: MapLike): string[]; - function getAllKeys(obj: object): string[]; - function getOwnValues(sparseArray: T[]): T[]; - /** Shims `Array.from`. */ - function arrayFrom(iterator: Iterator | IterableIterator, map: (t: T) => U): U[]; - function arrayFrom(iterator: Iterator | IterableIterator): T[]; - function assign(t: T, ...args: (T | undefined)[]): T; - /** - * Performs a shallow equality comparison of the contents of two map-likes. - * - * @param left A map-like whose properties should be compared. - * @param right A map-like whose properties should be compared. - */ - function equalOwnProperties(left: MapLike | undefined, right: MapLike | undefined, equalityComparer?: EqualityComparer): boolean; - /** - * Creates a map from the elements of an array. - * - * @param array the array of input elements. - * @param makeKey a function that produces a key for a given element. - * - * This function makes no effort to avoid collisions; if any two elements produce - * the same key with the given 'makeKey' function, then the element with the higher - * index in the array will be the one associated with the produced key. - */ - function arrayToMap(array: ReadonlyArray, makeKey: (value: T) => string | undefined): Map; - function arrayToMap(array: ReadonlyArray, makeKey: (value: T) => string | undefined, makeValue: (value: T) => U): Map; - function arrayToNumericMap(array: ReadonlyArray, makeKey: (value: T) => number): T[]; - function arrayToNumericMap(array: ReadonlyArray, makeKey: (value: T) => number, makeValue: (value: T) => U): U[]; - function arrayToMultiMap(values: ReadonlyArray, makeKey: (value: T) => string): MultiMap; - function arrayToMultiMap(values: ReadonlyArray, makeKey: (value: T) => string, makeValue: (value: T) => U): MultiMap; - function group(values: ReadonlyArray, getGroupId: (value: T) => string): ReadonlyArray>; - function clone(object: T): T; - function extend(first: T1, second: T2): T1 & T2; - function copyProperties(first: T1, second: T2): void; - function maybeBind(obj: T, fn: ((this: T, ...args: A) => R) | undefined): ((...args: A) => R) | undefined; - interface MultiMap extends Map { - /** - * Adds the value to an array of values associated with the key, and returns the array. - * Creates the array if it does not already exist. - */ - add(key: string, value: T): T[]; - /** - * Removes a value from an array of values associated with the key. - * Does not preserve the order of those values. - * Does nothing if `key` is not in `map`, or `value` is not in `map[key]`. - */ - remove(key: string, value: T): void; - } - function createMultiMap(): MultiMap; - /** - * Tests whether a value is an array. - */ - function isArray(value: any): value is ReadonlyArray<{}>; - function toArray(value: T | T[]): T[]; - function toArray(value: T | ReadonlyArray): ReadonlyArray; - /** - * Tests whether a value is string - */ - function isString(text: unknown): text is string; - function isNumber(x: unknown): x is number; - function tryCast(value: TIn | undefined, test: (value: TIn) => value is TOut): TOut | undefined; - function tryCast(value: T, test: (value: T) => boolean): T | undefined; - function cast(value: TIn | undefined, test: (value: TIn) => value is TOut): TOut; - /** Does nothing. */ - function noop(_?: {} | null | undefined): void; - /** Do nothing and return false */ - function returnFalse(): false; - /** Do nothing and return true */ - function returnTrue(): true; - /** Do nothing and return undefined */ - function returnUndefined(): undefined; - /** Returns its argument. */ - function identity(x: T): T; - /** Returns lower case string */ - function toLowerCase(x: string): string; - /** Throws an error because a function is not implemented. */ - function notImplemented(): never; - function memoize(callback: () => T): () => T; - /** - * High-order function, composes functions. Note that functions are composed inside-out; - * for example, `compose(a, b)` is the equivalent of `x => b(a(x))`. - * - * @param args The functions to compose. - */ - function compose(...args: ((t: T) => T)[]): (t: T) => T; - enum AssertionLevel { - None = 0, - Normal = 1, - Aggressive = 2, - VeryAggressive = 3 - } - /** - * Safer version of `Function` which should not be called. - * Every function should be assignable to this, but this should not be assignable to every function. - */ - type AnyFunction = (...args: never[]) => void; - type AnyConstructor = new (...args: unknown[]) => unknown; - function equateValues(a: T, b: T): boolean; - /** - * Compare the equality of two strings using a case-sensitive ordinal comparison. - * - * Case-sensitive comparisons compare both strings one code-point at a time using the integer - * value of each code-point after applying `toUpperCase` to each string. We always map both - * strings to their upper-case form as some unicode characters do not properly round-trip to - * lowercase (such as `ẞ` (German sharp capital s)). - */ - function equateStringsCaseInsensitive(a: string, b: string): boolean; - /** - * Compare the equality of two strings using a case-sensitive ordinal comparison. - * - * Case-sensitive comparisons compare both strings one code-point at a time using the - * integer value of each code-point. - */ - function equateStringsCaseSensitive(a: string, b: string): boolean; - /** - * Compare two numeric values for their order relative to each other. - * To compare strings, use any of the `compareStrings` functions. - */ - function compareValues(a: number | undefined, b: number | undefined): Comparison; - function min(a: T, b: T, compare: Comparer): T; - /** - * Compare two strings using a case-insensitive ordinal comparison. - * - * Ordinal comparisons are based on the difference between the unicode code points of both - * strings. Characters with multiple unicode representations are considered unequal. Ordinal - * comparisons provide predictable ordering, but place "a" after "B". - * - * Case-insensitive comparisons compare both strings one code-point at a time using the integer - * value of each code-point after applying `toUpperCase` to each string. We always map both - * strings to their upper-case form as some unicode characters do not properly round-trip to - * lowercase (such as `ẞ` (German sharp capital s)). - */ - function compareStringsCaseInsensitive(a: string, b: string): Comparison; - /** - * Compare two strings using a case-sensitive ordinal comparison. - * - * Ordinal comparisons are based on the difference between the unicode code points of both - * strings. Characters with multiple unicode representations are considered unequal. Ordinal - * comparisons provide predictable ordering, but place "a" after "B". - * - * Case-sensitive comparisons compare both strings one code-point at a time using the integer - * value of each code-point. - */ - function compareStringsCaseSensitive(a: string | undefined, b: string | undefined): Comparison; - function getStringComparer(ignoreCase?: boolean): typeof compareStringsCaseSensitive; - function getUILocale(): string | undefined; - function setUILocale(value: string | undefined): void; - /** - * Compare two strings in a using the case-sensitive sort behavior of the UI locale. - * - * Ordering is not predictable between different host locales, but is best for displaying - * ordered data for UI presentation. Characters with multiple unicode representations may - * be considered equal. - * - * Case-sensitive comparisons compare strings that differ in base characters, or - * accents/diacritic marks, or case as unequal. - */ - function compareStringsCaseSensitiveUI(a: string, b: string): Comparison; - function compareProperties(a: T | undefined, b: T | undefined, key: K, comparer: Comparer): Comparison; - /** True is greater than false. */ - function compareBooleans(a: boolean, b: boolean): Comparison; - /** - * Given a name and a list of names that are *not* equal to the name, return a spelling suggestion if there is one that is close enough. - * Names less than length 3 only check for case-insensitive equality, not Levenshtein distance. - * - * If there is a candidate that's the same except for case, return that. - * If there is a candidate that's within one edit of the name, return that. - * Otherwise, return the candidate with the smallest Levenshtein distance, - * except for candidates: - * * With no name - * * Whose length differs from the target name by more than 0.34 of the length of the name. - * * Whose levenshtein distance is more than 0.4 of the length of the name - * (0.4 allows 1 substitution/transposition for every 5 characters, - * and 1 insertion/deletion at 3 characters) - */ - function getSpellingSuggestion(name: string, candidates: T[], getName: (candidate: T) => string | undefined): T | undefined; - function endsWith(str: string, suffix: string): boolean; - function removeSuffix(str: string, suffix: string): string; - function tryRemoveSuffix(str: string, suffix: string): string | undefined; - function stringContains(str: string, substring: string): boolean; - function fileExtensionIs(path: string, extension: string): boolean; - function fileExtensionIsOneOf(path: string, extensions: ReadonlyArray): boolean; - /** - * Takes a string like "jquery-min.4.2.3" and returns "jquery" - */ - function removeMinAndVersionNumbers(fileName: string): string; - /** Remove an item from an array, moving everything to its right one space left. */ - function orderedRemoveItem(array: T[], item: T): boolean; - /** Remove an item by index from an array, moving everything to its right one space left. */ - function orderedRemoveItemAt(array: T[], index: number): void; - function unorderedRemoveItemAt(array: T[], index: number): void; - /** Remove the *first* occurrence of `item` from the array. */ - function unorderedRemoveItem(array: T[], item: T): boolean; - type GetCanonicalFileName = (fileName: string) => string; - function createGetCanonicalFileName(useCaseSensitiveFileNames: boolean): GetCanonicalFileName; - /** Represents a "prefix*suffix" pattern. */ - interface Pattern { - prefix: string; - suffix: string; - } - function patternText({ prefix, suffix }: Pattern): string; - /** - * Given that candidate matches pattern, returns the text matching the '*'. - * E.g.: matchedText(tryParsePattern("foo*baz"), "foobarbaz") === "bar" - */ - function matchedText(pattern: Pattern, candidate: string): string; - /** Return the object corresponding to the best pattern to match `candidate`. */ - function findBestPatternMatch(values: ReadonlyArray, getPattern: (value: T) => Pattern, candidate: string): T | undefined; - function startsWith(str: string, prefix: string): boolean; - function removePrefix(str: string, prefix: string): string; - function tryRemovePrefix(str: string, prefix: string, getCanonicalFileName?: GetCanonicalFileName): string | undefined; - function and(f: (arg: T) => boolean, g: (arg: T) => boolean): (arg: T) => boolean; - function or(f: (arg: T) => boolean, g: (arg: T) => boolean): (arg: T) => boolean; - function assertType(_: T): void; - function singleElementArray(t: T | undefined): T[] | undefined; - function enumerateInsertsAndDeletes(newItems: ReadonlyArray, oldItems: ReadonlyArray, comparer: (a: T, b: U) => Comparison, inserted: (newItem: T) => void, deleted: (oldItem: U) => void, unchanged?: (oldItem: U, newItem: T) => void): void; - function fill(length: number, cb: (index: number) => T): T[]; - function cartesianProduct(arrays: readonly T[][]): T[][]; -} -declare namespace ts { - namespace Debug { - let currentAssertionLevel: AssertionLevel; - let isDebugging: boolean; - function shouldAssert(level: AssertionLevel): boolean; - function assert(expression: boolean, message?: string, verboseDebugInfo?: string | (() => string), stackCrawlMark?: AnyFunction): void; - function assertEqual(a: T, b: T, msg?: string, msg2?: string): void; - function assertLessThan(a: number, b: number, msg?: string): void; - function assertLessThanOrEqual(a: number, b: number): void; - function assertGreaterThanOrEqual(a: number, b: number): void; - function fail(message?: string, stackCrawlMark?: AnyFunction): never; - function assertDefined(value: T | null | undefined, message?: string): T; - function assertEachDefined>(value: A, message?: string): A; - function assertNever(member: never, message?: string, stackCrawlMark?: AnyFunction): never; - function getFunctionName(func: AnyFunction): any; - function formatSymbol(symbol: Symbol): string; - /** - * Formats an enum value as a string for debugging and debug assertions. - */ - function formatEnum(value: number | undefined, enumObject: any, isFlags?: boolean): string; - function formatSyntaxKind(kind: SyntaxKind | undefined): string; - function formatNodeFlags(flags: NodeFlags | undefined): string; - function formatModifierFlags(flags: ModifierFlags | undefined): string; - function formatTransformFlags(flags: TransformFlags | undefined): string; - function formatEmitFlags(flags: EmitFlags | undefined): string; - function formatSymbolFlags(flags: SymbolFlags | undefined): string; - function formatTypeFlags(flags: TypeFlags | undefined): string; - function formatObjectFlags(flags: ObjectFlags | undefined): string; - function failBadSyntaxKind(node: Node, message?: string): never; - const assertEachNode: (nodes: Node[], test: (node: Node) => boolean, message?: string | undefined) => void; - const assertNode: (node: Node | undefined, test: ((node: Node | undefined) => boolean) | undefined, message?: string | undefined) => void; - const assertOptionalNode: (node: Node, test: (node: Node) => boolean, message?: string | undefined) => void; - const assertOptionalToken: (node: Node, kind: SyntaxKind, message?: string | undefined) => void; - const assertMissingNode: typeof noop; - /** - * Injects debug information into frequently used types. - */ - function enableDebugInfo(): void; - } -} -declare namespace ts { - /** Gets a timestamp with (at least) ms resolution */ - const timestamp: () => number; -} -/** Performance measurements for the compiler. */ -declare namespace ts.performance { - interface Timer { - enter(): void; - exit(): void; - } - function createTimerIf(condition: boolean, measureName: string, startMarkName: string, endMarkName: string): Timer; - function createTimer(measureName: string, startMarkName: string, endMarkName: string): Timer; - const nullTimer: Timer; - /** - * Marks a performance event. - * - * @param markName The name of the mark. - */ - function mark(markName: string): void; - /** - * Adds a performance measurement with the specified name. - * - * @param measureName The name of the performance measurement. - * @param startMarkName The name of the starting mark. If not supplied, the point at which the - * profiler was enabled is used. - * @param endMarkName The name of the ending mark. If not supplied, the current timestamp is - * used. - */ - function measure(measureName: string, startMarkName?: string, endMarkName?: string): void; - /** - * Gets the number of times a marker was encountered. - * - * @param markName The name of the mark. - */ - function getCount(markName: string): number; - /** - * Gets the total duration of all measurements with the supplied name. - * - * @param measureName The name of the measure whose durations should be accumulated. - */ - function getDuration(measureName: string): number; - /** - * Iterate over each measure, performing some action - * - * @param cb The action to perform for each measure - */ - function forEachMeasure(cb: (measureName: string, duration: number) => void): void; - /** Enables (and resets) performance measurements for the compiler. */ - function enable(): void; - /** Disables performance measurements for the compiler. */ - function disable(): void; -} -declare namespace ts { - export {}; -} -declare namespace ts { - /** - * Describes a precise semantic version number, https://semver.org - */ - class Version { - static readonly zero: Version; - readonly major: number; - readonly minor: number; - readonly patch: number; - readonly prerelease: ReadonlyArray; - readonly build: ReadonlyArray; - constructor(text: string); - constructor(major: number, minor?: number, patch?: number, prerelease?: string, build?: string); - static tryParse(text: string): Version | undefined; - compareTo(other: Version | undefined): Comparison.LessThan | Comparison.LessThan | Comparison | Comparison.GreaterThan; - increment(field: "major" | "minor" | "patch"): Version; - toString(): string; - } - /** - * Describes a semantic version range, per https://github.com/npm/node-semver#ranges - */ - class VersionRange { - private _alternatives; - constructor(spec: string); - static tryParse(text: string): VersionRange | undefined; - test(version: Version | string): boolean; - toString(): string; - } -} -declare namespace ts { - export type Path = string & { - __pathBrand: any; - }; - export interface TextRange { - pos: number; - end: number; - } - export type JSDocSyntaxKind = SyntaxKind.EndOfFileToken | SyntaxKind.WhitespaceTrivia | SyntaxKind.AtToken | SyntaxKind.NewLineTrivia | SyntaxKind.AsteriskToken | SyntaxKind.OpenBraceToken | SyntaxKind.CloseBraceToken | SyntaxKind.LessThanToken | SyntaxKind.GreaterThanToken | SyntaxKind.OpenBracketToken | SyntaxKind.CloseBracketToken | SyntaxKind.EqualsToken | SyntaxKind.CommaToken | SyntaxKind.DotToken | SyntaxKind.Identifier | SyntaxKind.BacktickToken | SyntaxKind.Unknown | KeywordSyntaxKind; - export type KeywordSyntaxKind = SyntaxKind.AbstractKeyword | SyntaxKind.AnyKeyword | SyntaxKind.AsKeyword | SyntaxKind.BigIntKeyword | SyntaxKind.BooleanKeyword | SyntaxKind.BreakKeyword | SyntaxKind.CaseKeyword | SyntaxKind.CatchKeyword | SyntaxKind.ClassKeyword | SyntaxKind.ContinueKeyword | SyntaxKind.ConstKeyword | SyntaxKind.ConstructorKeyword | SyntaxKind.DebuggerKeyword | SyntaxKind.DeclareKeyword | SyntaxKind.DefaultKeyword | SyntaxKind.DeleteKeyword | SyntaxKind.DoKeyword | SyntaxKind.ElseKeyword | SyntaxKind.EnumKeyword | SyntaxKind.ExportKeyword | SyntaxKind.ExtendsKeyword | SyntaxKind.FalseKeyword | SyntaxKind.FinallyKeyword | SyntaxKind.ForKeyword | SyntaxKind.FromKeyword | SyntaxKind.FunctionKeyword | SyntaxKind.GetKeyword | SyntaxKind.IfKeyword | SyntaxKind.ImplementsKeyword | SyntaxKind.ImportKeyword | SyntaxKind.InKeyword | SyntaxKind.InferKeyword | SyntaxKind.InstanceOfKeyword | SyntaxKind.InterfaceKeyword | SyntaxKind.IsKeyword | SyntaxKind.KeyOfKeyword | SyntaxKind.LetKeyword | SyntaxKind.ModuleKeyword | SyntaxKind.NamespaceKeyword | SyntaxKind.NeverKeyword | SyntaxKind.NewKeyword | SyntaxKind.NullKeyword | SyntaxKind.NumberKeyword | SyntaxKind.ObjectKeyword | SyntaxKind.PackageKeyword | SyntaxKind.PrivateKeyword | SyntaxKind.ProtectedKeyword | SyntaxKind.PublicKeyword | SyntaxKind.ReadonlyKeyword | SyntaxKind.RequireKeyword | SyntaxKind.GlobalKeyword | SyntaxKind.ReturnKeyword | SyntaxKind.SetKeyword | SyntaxKind.StaticKeyword | SyntaxKind.StringKeyword | SyntaxKind.SuperKeyword | SyntaxKind.SwitchKeyword | SyntaxKind.SymbolKeyword | SyntaxKind.ThisKeyword | SyntaxKind.ThrowKeyword | SyntaxKind.TrueKeyword | SyntaxKind.TryKeyword | SyntaxKind.TypeKeyword | SyntaxKind.TypeOfKeyword | SyntaxKind.UndefinedKeyword | SyntaxKind.UniqueKeyword | SyntaxKind.UnknownKeyword | SyntaxKind.VarKeyword | SyntaxKind.VoidKeyword | SyntaxKind.WhileKeyword | SyntaxKind.WithKeyword | SyntaxKind.YieldKeyword | SyntaxKind.AsyncKeyword | SyntaxKind.AwaitKeyword | SyntaxKind.OfKeyword; - export type JsxTokenSyntaxKind = SyntaxKind.LessThanSlashToken | SyntaxKind.EndOfFileToken | SyntaxKind.ConflictMarkerTrivia | SyntaxKind.JsxText | SyntaxKind.JsxTextAllWhiteSpaces | SyntaxKind.OpenBraceToken | SyntaxKind.LessThanToken; - export enum SyntaxKind { - Unknown = 0, - EndOfFileToken = 1, - SingleLineCommentTrivia = 2, - MultiLineCommentTrivia = 3, - NewLineTrivia = 4, - WhitespaceTrivia = 5, - ShebangTrivia = 6, - ConflictMarkerTrivia = 7, - NumericLiteral = 8, - BigIntLiteral = 9, - StringLiteral = 10, - JsxText = 11, - JsxTextAllWhiteSpaces = 12, - RegularExpressionLiteral = 13, - NoSubstitutionTemplateLiteral = 14, - TemplateHead = 15, - TemplateMiddle = 16, - TemplateTail = 17, - OpenBraceToken = 18, - CloseBraceToken = 19, - OpenParenToken = 20, - CloseParenToken = 21, - OpenBracketToken = 22, - CloseBracketToken = 23, - DotToken = 24, - DotDotDotToken = 25, - SemicolonToken = 26, - CommaToken = 27, - LessThanToken = 28, - LessThanSlashToken = 29, - GreaterThanToken = 30, - LessThanEqualsToken = 31, - GreaterThanEqualsToken = 32, - EqualsEqualsToken = 33, - ExclamationEqualsToken = 34, - EqualsEqualsEqualsToken = 35, - ExclamationEqualsEqualsToken = 36, - EqualsGreaterThanToken = 37, - PlusToken = 38, - MinusToken = 39, - AsteriskToken = 40, - AsteriskAsteriskToken = 41, - SlashToken = 42, - PercentToken = 43, - PlusPlusToken = 44, - MinusMinusToken = 45, - LessThanLessThanToken = 46, - GreaterThanGreaterThanToken = 47, - GreaterThanGreaterThanGreaterThanToken = 48, - AmpersandToken = 49, - BarToken = 50, - CaretToken = 51, - ExclamationToken = 52, - TildeToken = 53, - AmpersandAmpersandToken = 54, - BarBarToken = 55, - QuestionToken = 56, - ColonToken = 57, - AtToken = 58, - /** Only the JSDoc scanner produces BacktickToken. The normal scanner produces NoSubstitutionTemplateLiteral and related kinds. */ - BacktickToken = 59, - EqualsToken = 60, - PlusEqualsToken = 61, - MinusEqualsToken = 62, - AsteriskEqualsToken = 63, - AsteriskAsteriskEqualsToken = 64, - SlashEqualsToken = 65, - PercentEqualsToken = 66, - LessThanLessThanEqualsToken = 67, - GreaterThanGreaterThanEqualsToken = 68, - GreaterThanGreaterThanGreaterThanEqualsToken = 69, - AmpersandEqualsToken = 70, - BarEqualsToken = 71, - CaretEqualsToken = 72, - Identifier = 73, - BreakKeyword = 74, - CaseKeyword = 75, - CatchKeyword = 76, - ClassKeyword = 77, - ConstKeyword = 78, - ContinueKeyword = 79, - DebuggerKeyword = 80, - DefaultKeyword = 81, - DeleteKeyword = 82, - DoKeyword = 83, - ElseKeyword = 84, - EnumKeyword = 85, - ExportKeyword = 86, - ExtendsKeyword = 87, - FalseKeyword = 88, - FinallyKeyword = 89, - ForKeyword = 90, - FunctionKeyword = 91, - IfKeyword = 92, - ImportKeyword = 93, - InKeyword = 94, - InstanceOfKeyword = 95, - NewKeyword = 96, - NullKeyword = 97, - ReturnKeyword = 98, - SuperKeyword = 99, - SwitchKeyword = 100, - ThisKeyword = 101, - ThrowKeyword = 102, - TrueKeyword = 103, - TryKeyword = 104, - TypeOfKeyword = 105, - VarKeyword = 106, - VoidKeyword = 107, - WhileKeyword = 108, - WithKeyword = 109, - ImplementsKeyword = 110, - InterfaceKeyword = 111, - LetKeyword = 112, - PackageKeyword = 113, - PrivateKeyword = 114, - ProtectedKeyword = 115, - PublicKeyword = 116, - StaticKeyword = 117, - YieldKeyword = 118, - AbstractKeyword = 119, - AsKeyword = 120, - AnyKeyword = 121, - AsyncKeyword = 122, - AwaitKeyword = 123, - BooleanKeyword = 124, - ConstructorKeyword = 125, - DeclareKeyword = 126, - GetKeyword = 127, - InferKeyword = 128, - IsKeyword = 129, - KeyOfKeyword = 130, - ModuleKeyword = 131, - NamespaceKeyword = 132, - NeverKeyword = 133, - ReadonlyKeyword = 134, - RequireKeyword = 135, - NumberKeyword = 136, - ObjectKeyword = 137, - SetKeyword = 138, - StringKeyword = 139, - SymbolKeyword = 140, - TypeKeyword = 141, - UndefinedKeyword = 142, - UniqueKeyword = 143, - UnknownKeyword = 144, - FromKeyword = 145, - GlobalKeyword = 146, - BigIntKeyword = 147, - OfKeyword = 148, - QualifiedName = 149, - ComputedPropertyName = 150, - TypeParameter = 151, - Parameter = 152, - Decorator = 153, - PropertySignature = 154, - PropertyDeclaration = 155, - MethodSignature = 156, - MethodDeclaration = 157, - Constructor = 158, - GetAccessor = 159, - SetAccessor = 160, - CallSignature = 161, - ConstructSignature = 162, - IndexSignature = 163, - TypePredicate = 164, - TypeReference = 165, - FunctionType = 166, - ConstructorType = 167, - TypeQuery = 168, - TypeLiteral = 169, - ArrayType = 170, - TupleType = 171, - OptionalType = 172, - RestType = 173, - UnionType = 174, - IntersectionType = 175, - ConditionalType = 176, - InferType = 177, - ParenthesizedType = 178, - ThisType = 179, - TypeOperator = 180, - IndexedAccessType = 181, - MappedType = 182, - LiteralType = 183, - ImportType = 184, - ObjectBindingPattern = 185, - ArrayBindingPattern = 186, - BindingElement = 187, - ArrayLiteralExpression = 188, - ObjectLiteralExpression = 189, - PropertyAccessExpression = 190, - ElementAccessExpression = 191, - CallExpression = 192, - NewExpression = 193, - TaggedTemplateExpression = 194, - TypeAssertionExpression = 195, - ParenthesizedExpression = 196, - FunctionExpression = 197, - ArrowFunction = 198, - DeleteExpression = 199, - TypeOfExpression = 200, - VoidExpression = 201, - AwaitExpression = 202, - PrefixUnaryExpression = 203, - PostfixUnaryExpression = 204, - BinaryExpression = 205, - ConditionalExpression = 206, - TemplateExpression = 207, - YieldExpression = 208, - SpreadElement = 209, - ClassExpression = 210, - OmittedExpression = 211, - ExpressionWithTypeArguments = 212, - AsExpression = 213, - NonNullExpression = 214, - MetaProperty = 215, - SyntheticExpression = 216, - TemplateSpan = 217, - SemicolonClassElement = 218, - Block = 219, - VariableStatement = 220, - EmptyStatement = 221, - ExpressionStatement = 222, - IfStatement = 223, - DoStatement = 224, - WhileStatement = 225, - ForStatement = 226, - ForInStatement = 227, - ForOfStatement = 228, - ContinueStatement = 229, - BreakStatement = 230, - ReturnStatement = 231, - WithStatement = 232, - SwitchStatement = 233, - LabeledStatement = 234, - ThrowStatement = 235, - TryStatement = 236, - DebuggerStatement = 237, - VariableDeclaration = 238, - VariableDeclarationList = 239, - FunctionDeclaration = 240, - ClassDeclaration = 241, - InterfaceDeclaration = 242, - TypeAliasDeclaration = 243, - EnumDeclaration = 244, - ModuleDeclaration = 245, - ModuleBlock = 246, - CaseBlock = 247, - NamespaceExportDeclaration = 248, - ImportEqualsDeclaration = 249, - ImportDeclaration = 250, - ImportClause = 251, - NamespaceImport = 252, - NamedImports = 253, - ImportSpecifier = 254, - ExportAssignment = 255, - ExportDeclaration = 256, - NamedExports = 257, - ExportSpecifier = 258, - MissingDeclaration = 259, - ExternalModuleReference = 260, - JsxElement = 261, - JsxSelfClosingElement = 262, - JsxOpeningElement = 263, - JsxClosingElement = 264, - JsxFragment = 265, - JsxOpeningFragment = 266, - JsxClosingFragment = 267, - JsxAttribute = 268, - JsxAttributes = 269, - JsxSpreadAttribute = 270, - JsxExpression = 271, - CaseClause = 272, - DefaultClause = 273, - HeritageClause = 274, - CatchClause = 275, - PropertyAssignment = 276, - ShorthandPropertyAssignment = 277, - SpreadAssignment = 278, - EnumMember = 279, - UnparsedPrologue = 280, - UnparsedPrepend = 281, - UnparsedText = 282, - UnparsedInternalText = 283, - UnparsedSyntheticReference = 284, - SourceFile = 285, - Bundle = 286, - UnparsedSource = 287, - InputFiles = 288, - JSDocTypeExpression = 289, - JSDocAllType = 290, - JSDocUnknownType = 291, - JSDocNullableType = 292, - JSDocNonNullableType = 293, - JSDocOptionalType = 294, - JSDocFunctionType = 295, - JSDocVariadicType = 296, - JSDocNamepathType = 297, - JSDocComment = 298, - JSDocTypeLiteral = 299, - JSDocSignature = 300, - JSDocTag = 301, - JSDocAugmentsTag = 302, - JSDocAuthorTag = 303, - JSDocClassTag = 304, - JSDocCallbackTag = 305, - JSDocEnumTag = 306, - JSDocParameterTag = 307, - JSDocReturnTag = 308, - JSDocThisTag = 309, - JSDocTypeTag = 310, - JSDocTemplateTag = 311, - JSDocTypedefTag = 312, - JSDocPropertyTag = 313, - SyntaxList = 314, - NotEmittedStatement = 315, - PartiallyEmittedExpression = 316, - CommaListExpression = 317, - MergeDeclarationMarker = 318, - EndOfDeclarationMarker = 319, - Count = 320, - FirstAssignment = 60, - LastAssignment = 72, - FirstCompoundAssignment = 61, - LastCompoundAssignment = 72, - FirstReservedWord = 74, - LastReservedWord = 109, - FirstKeyword = 74, - LastKeyword = 148, - FirstFutureReservedWord = 110, - LastFutureReservedWord = 118, - FirstTypeNode = 164, - LastTypeNode = 184, - FirstPunctuation = 18, - LastPunctuation = 72, - FirstToken = 0, - LastToken = 148, - FirstTriviaToken = 2, - LastTriviaToken = 7, - FirstLiteralToken = 8, - LastLiteralToken = 14, - FirstTemplateToken = 14, - LastTemplateToken = 17, - FirstBinaryOperator = 28, - LastBinaryOperator = 72, - FirstNode = 149, - FirstJSDocNode = 289, - LastJSDocNode = 313, - FirstJSDocTagNode = 301, - LastJSDocTagNode = 313, - FirstContextualKeyword = 119, - LastContextualKeyword = 148 - } - export enum NodeFlags { - None = 0, - Let = 1, - Const = 2, - NestedNamespace = 4, - Synthesized = 8, - Namespace = 16, - ExportContext = 32, - ContainsThis = 64, - HasImplicitReturn = 128, - HasExplicitReturn = 256, - GlobalAugmentation = 512, - HasAsyncFunctions = 1024, - DisallowInContext = 2048, - YieldContext = 4096, - DecoratorContext = 8192, - AwaitContext = 16384, - ThisNodeHasError = 32768, - JavaScriptFile = 65536, - ThisNodeOrAnySubNodesHasError = 131072, - HasAggregatedChildData = 262144, - PossiblyContainsDynamicImport = 524288, - PossiblyContainsImportMeta = 1048576, - JSDoc = 2097152, - Ambient = 4194304, - InWithStatement = 8388608, - JsonFile = 16777216, - BlockScoped = 3, - ReachabilityCheckFlags = 384, - ReachabilityAndEmitFlags = 1408, - ContextFlags = 12679168, - TypeExcludesFlags = 20480, - PermanentlySetIncrementalFlags = 1572864 - } - export enum ModifierFlags { - None = 0, - Export = 1, - Ambient = 2, - Public = 4, - Private = 8, - Protected = 16, - Static = 32, - Readonly = 64, - Abstract = 128, - Async = 256, - Default = 512, - Const = 2048, - HasComputedFlags = 536870912, - AccessibilityModifier = 28, - ParameterPropertyModifier = 92, - NonPublicAccessibilityModifier = 24, - TypeScriptModifier = 2270, - ExportDefault = 513, - All = 3071 - } - export enum JsxFlags { - None = 0, - /** An element from a named property of the JSX.IntrinsicElements interface */ - IntrinsicNamedElement = 1, - /** An element inferred from the string index signature of the JSX.IntrinsicElements interface */ - IntrinsicIndexedElement = 2, - IntrinsicElement = 3 - } - export enum RelationComparisonResult { - Succeeded = 1, - Failed = 2, - FailedAndReported = 3 - } - export interface Node extends TextRange { - kind: SyntaxKind; - flags: NodeFlags; - modifierFlagsCache: ModifierFlags; - transformFlags: TransformFlags; - decorators?: NodeArray; - modifiers?: ModifiersArray; - id?: number; - parent: Node; - original?: Node; - symbol: Symbol; - locals?: SymbolTable; - nextContainer?: Node; - localSymbol?: Symbol; - flowNode?: FlowNode; - emitNode?: EmitNode; - contextualType?: Type; - inferenceContext?: InferenceContext; - } - export interface JSDocContainer { - jsDoc?: JSDoc[]; - jsDocCache?: ReadonlyArray; - } - export type HasJSDoc = ParameterDeclaration | CallSignatureDeclaration | ConstructSignatureDeclaration | MethodSignature | PropertySignature | ArrowFunction | ParenthesizedExpression | SpreadAssignment | ShorthandPropertyAssignment | PropertyAssignment | FunctionExpression | LabeledStatement | ExpressionStatement | VariableStatement | FunctionDeclaration | ConstructorDeclaration | MethodDeclaration | PropertyDeclaration | AccessorDeclaration | ClassLikeDeclaration | InterfaceDeclaration | TypeAliasDeclaration | EnumMember | EnumDeclaration | ModuleDeclaration | ImportEqualsDeclaration | IndexSignatureDeclaration | FunctionTypeNode | ConstructorTypeNode | JSDocFunctionType | ExportDeclaration | EndOfFileToken; - export type HasType = SignatureDeclaration | VariableDeclaration | ParameterDeclaration | PropertySignature | PropertyDeclaration | TypePredicateNode | ParenthesizedTypeNode | TypeOperatorNode | MappedTypeNode | AssertionExpression | TypeAliasDeclaration | JSDocTypeExpression | JSDocNonNullableType | JSDocNullableType | JSDocOptionalType | JSDocVariadicType; - export type HasInitializer = HasExpressionInitializer | ForStatement | ForInStatement | ForOfStatement | JsxAttribute; - export type HasExpressionInitializer = VariableDeclaration | ParameterDeclaration | BindingElement | PropertySignature | PropertyDeclaration | PropertyAssignment | EnumMember; - export type MutableNodeArray = NodeArray & T[]; - export interface NodeArray extends ReadonlyArray, TextRange { - hasTrailingComma?: boolean; - transformFlags: TransformFlags; - } - export interface Token extends Node { - kind: TKind; - } - export type DotDotDotToken = Token; - export type QuestionToken = Token; - export type ExclamationToken = Token; - export type ColonToken = Token; - export type EqualsToken = Token; - export type AsteriskToken = Token; - export type EqualsGreaterThanToken = Token; - export type EndOfFileToken = Token & JSDocContainer; - export type ReadonlyToken = Token; - export type AwaitKeywordToken = Token; - export type PlusToken = Token; - export type MinusToken = Token; - export type Modifier = Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token; - export type ModifiersArray = NodeArray; - export enum GeneratedIdentifierFlags { - None = 0, - Auto = 1, - Loop = 2, - Unique = 3, - Node = 4, - KindMask = 7, - ReservedInNestedScopes = 8, - Optimistic = 16, - FileLevel = 32 - } - export interface Identifier extends PrimaryExpression, Declaration { - kind: SyntaxKind.Identifier; - /** - * Prefer to use `id.unescapedText`. (Note: This is available only in services, not internally to the TypeScript compiler.) - * Text of identifier, but if the identifier begins with two underscores, this will begin with three. - */ - escapedText: __String; - originalKeywordKind?: SyntaxKind; - autoGenerateFlags?: GeneratedIdentifierFlags; - autoGenerateId?: number; - isInJSDocNamespace?: boolean; - typeArguments?: NodeArray; - jsdocDotPos?: number; - } - export interface TransientIdentifier extends Identifier { - resolvedSymbol: Symbol; - } - export interface GeneratedIdentifier extends Identifier { - autoGenerateFlags: GeneratedIdentifierFlags; - } - export interface QualifiedName extends Node { - kind: SyntaxKind.QualifiedName; - left: EntityName; - right: Identifier; - jsdocDotPos?: number; - } - export type EntityName = Identifier | QualifiedName; - export type PropertyName = Identifier | StringLiteral | NumericLiteral | ComputedPropertyName; - export type DeclarationName = Identifier | StringLiteralLike | NumericLiteral | ComputedPropertyName | BindingPattern; - export interface Declaration extends Node { - _declarationBrand: any; - } - export interface NamedDeclaration extends Declaration { - name?: DeclarationName; - } - export interface DynamicNamedDeclaration extends NamedDeclaration { - name: ComputedPropertyName; - } - export interface LateBoundDeclaration extends DynamicNamedDeclaration { - name: LateBoundName; - } - export interface DeclarationStatement extends NamedDeclaration, Statement { - name?: Identifier | StringLiteral | NumericLiteral; - } - export interface ComputedPropertyName extends Node { - parent: Declaration; - kind: SyntaxKind.ComputedPropertyName; - expression: Expression; - } - export interface LateBoundName extends ComputedPropertyName { - expression: EntityNameExpression; - } - export interface Decorator extends Node { - kind: SyntaxKind.Decorator; - parent: NamedDeclaration; - expression: LeftHandSideExpression; - } - export interface TypeParameterDeclaration extends NamedDeclaration { - kind: SyntaxKind.TypeParameter; - parent: DeclarationWithTypeParameterChildren | InferTypeNode; - name: Identifier; - /** Note: Consider calling `getEffectiveConstraintOfTypeParameter` */ - constraint?: TypeNode; - default?: TypeNode; - expression?: Expression; - } - export interface SignatureDeclarationBase extends NamedDeclaration, JSDocContainer { - kind: SignatureDeclaration["kind"]; - name?: PropertyName; - typeParameters?: NodeArray; - parameters: NodeArray; - type?: TypeNode; - typeArguments?: NodeArray; - } - export type SignatureDeclaration = CallSignatureDeclaration | ConstructSignatureDeclaration | MethodSignature | IndexSignatureDeclaration | FunctionTypeNode | ConstructorTypeNode | JSDocFunctionType | FunctionDeclaration | MethodDeclaration | ConstructorDeclaration | AccessorDeclaration | FunctionExpression | ArrowFunction; - export interface CallSignatureDeclaration extends SignatureDeclarationBase, TypeElement { - kind: SyntaxKind.CallSignature; - } - export interface ConstructSignatureDeclaration extends SignatureDeclarationBase, TypeElement { - kind: SyntaxKind.ConstructSignature; - } - export type BindingName = Identifier | BindingPattern; - export interface VariableDeclaration extends NamedDeclaration { - kind: SyntaxKind.VariableDeclaration; - parent: VariableDeclarationList | CatchClause; - name: BindingName; - exclamationToken?: ExclamationToken; - type?: TypeNode; - initializer?: Expression; - } - export interface VariableDeclarationList extends Node { - kind: SyntaxKind.VariableDeclarationList; - parent: VariableStatement | ForStatement | ForOfStatement | ForInStatement; - declarations: NodeArray; - } - export interface ParameterDeclaration extends NamedDeclaration, JSDocContainer { - kind: SyntaxKind.Parameter; - parent: SignatureDeclaration; - dotDotDotToken?: DotDotDotToken; - name: BindingName; - questionToken?: QuestionToken; - type?: TypeNode; - initializer?: Expression; - } - export interface BindingElement extends NamedDeclaration { - kind: SyntaxKind.BindingElement; - parent: BindingPattern; - propertyName?: PropertyName; - dotDotDotToken?: DotDotDotToken; - name: BindingName; - initializer?: Expression; - } - export type BindingElementGrandparent = BindingElement["parent"]["parent"]; - export interface PropertySignature extends TypeElement, JSDocContainer { - kind: SyntaxKind.PropertySignature; - name: PropertyName; - questionToken?: QuestionToken; - type?: TypeNode; - initializer?: Expression; - } - export interface PropertyDeclaration extends ClassElement, JSDocContainer { - kind: SyntaxKind.PropertyDeclaration; - parent: ClassLikeDeclaration; - name: PropertyName; - questionToken?: QuestionToken; - exclamationToken?: ExclamationToken; - type?: TypeNode; - initializer?: Expression; - } - export interface ObjectLiteralElement extends NamedDeclaration { - _objectLiteralBrand: any; - name?: PropertyName; - } - /** Unlike ObjectLiteralElement, excludes JSXAttribute and JSXSpreadAttribute. */ - export type ObjectLiteralElementLike = PropertyAssignment | ShorthandPropertyAssignment | SpreadAssignment | MethodDeclaration | AccessorDeclaration; - export interface PropertyAssignment extends ObjectLiteralElement, JSDocContainer { - parent: ObjectLiteralExpression; - kind: SyntaxKind.PropertyAssignment; - name: PropertyName; - questionToken?: QuestionToken; - initializer: Expression; - } - export interface ShorthandPropertyAssignment extends ObjectLiteralElement, JSDocContainer { - parent: ObjectLiteralExpression; - kind: SyntaxKind.ShorthandPropertyAssignment; - name: Identifier; - questionToken?: QuestionToken; - exclamationToken?: ExclamationToken; - equalsToken?: Token; - objectAssignmentInitializer?: Expression; - } - export interface SpreadAssignment extends ObjectLiteralElement, JSDocContainer { - parent: ObjectLiteralExpression; - kind: SyntaxKind.SpreadAssignment; - expression: Expression; - } - export type VariableLikeDeclaration = VariableDeclaration | ParameterDeclaration | BindingElement | PropertyDeclaration | PropertyAssignment | PropertySignature | JsxAttribute | ShorthandPropertyAssignment | EnumMember | JSDocPropertyTag | JSDocParameterTag; - export interface PropertyLikeDeclaration extends NamedDeclaration { - name: PropertyName; - } - export interface ObjectBindingPattern extends Node { - kind: SyntaxKind.ObjectBindingPattern; - parent: VariableDeclaration | ParameterDeclaration | BindingElement; - elements: NodeArray; - } - export interface ArrayBindingPattern extends Node { - kind: SyntaxKind.ArrayBindingPattern; - parent: VariableDeclaration | ParameterDeclaration | BindingElement; - elements: NodeArray; - } - export type BindingPattern = ObjectBindingPattern | ArrayBindingPattern; - export type ArrayBindingElement = BindingElement | OmittedExpression; - /** - * Several node kinds share function-like features such as a signature, - * a name, and a body. These nodes should extend FunctionLikeDeclarationBase. - * Examples: - * - FunctionDeclaration - * - MethodDeclaration - * - AccessorDeclaration - */ - export interface FunctionLikeDeclarationBase extends SignatureDeclarationBase { - _functionLikeDeclarationBrand: any; - asteriskToken?: AsteriskToken; - questionToken?: QuestionToken; - exclamationToken?: ExclamationToken; - body?: Block | Expression; - } - export type FunctionLikeDeclaration = FunctionDeclaration | MethodDeclaration | GetAccessorDeclaration | SetAccessorDeclaration | ConstructorDeclaration | FunctionExpression | ArrowFunction; - /** @deprecated Use SignatureDeclaration */ - export type FunctionLike = SignatureDeclaration; - export interface FunctionDeclaration extends FunctionLikeDeclarationBase, DeclarationStatement { - kind: SyntaxKind.FunctionDeclaration; - name?: Identifier; - body?: FunctionBody; - } - export interface MethodSignature extends SignatureDeclarationBase, TypeElement { - kind: SyntaxKind.MethodSignature; - parent: ObjectTypeDeclaration; - name: PropertyName; - } - export interface MethodDeclaration extends FunctionLikeDeclarationBase, ClassElement, ObjectLiteralElement, JSDocContainer { - kind: SyntaxKind.MethodDeclaration; - parent: ClassLikeDeclaration | ObjectLiteralExpression; - name: PropertyName; - body?: FunctionBody; - } - export interface ConstructorDeclaration extends FunctionLikeDeclarationBase, ClassElement, JSDocContainer { - kind: SyntaxKind.Constructor; - parent: ClassLikeDeclaration; - body?: FunctionBody; - returnFlowNode?: FlowNode; - } - /** For when we encounter a semicolon in a class declaration. ES6 allows these as class elements. */ - export interface SemicolonClassElement extends ClassElement { - kind: SyntaxKind.SemicolonClassElement; - parent: ClassLikeDeclaration; - } - export interface GetAccessorDeclaration extends FunctionLikeDeclarationBase, ClassElement, ObjectLiteralElement, JSDocContainer { - kind: SyntaxKind.GetAccessor; - parent: ClassLikeDeclaration | ObjectLiteralExpression; - name: PropertyName; - body?: FunctionBody; - } - export interface SetAccessorDeclaration extends FunctionLikeDeclarationBase, ClassElement, ObjectLiteralElement, JSDocContainer { - kind: SyntaxKind.SetAccessor; - parent: ClassLikeDeclaration | ObjectLiteralExpression; - name: PropertyName; - body?: FunctionBody; - } - export type AccessorDeclaration = GetAccessorDeclaration | SetAccessorDeclaration; - export interface IndexSignatureDeclaration extends SignatureDeclarationBase, ClassElement, TypeElement { - kind: SyntaxKind.IndexSignature; - parent: ObjectTypeDeclaration; - } - export interface TypeNode extends Node { - _typeNodeBrand: any; - } - export interface KeywordTypeNode extends TypeNode { - kind: SyntaxKind.AnyKeyword | SyntaxKind.UnknownKeyword | SyntaxKind.NumberKeyword | SyntaxKind.BigIntKeyword | SyntaxKind.ObjectKeyword | SyntaxKind.BooleanKeyword | SyntaxKind.StringKeyword | SyntaxKind.SymbolKeyword | SyntaxKind.ThisKeyword | SyntaxKind.VoidKeyword | SyntaxKind.UndefinedKeyword | SyntaxKind.NullKeyword | SyntaxKind.NeverKeyword; - } - export interface ImportTypeNode extends NodeWithTypeArguments { - kind: SyntaxKind.ImportType; - isTypeOf?: boolean; - argument: TypeNode; - qualifier?: EntityName; - } - export type LiteralImportTypeNode = ImportTypeNode & { - argument: LiteralTypeNode & { - literal: StringLiteral; - }; - }; - export interface ThisTypeNode extends TypeNode { - kind: SyntaxKind.ThisType; - } - export type FunctionOrConstructorTypeNode = FunctionTypeNode | ConstructorTypeNode; - export interface FunctionOrConstructorTypeNodeBase extends TypeNode, SignatureDeclarationBase { - kind: SyntaxKind.FunctionType | SyntaxKind.ConstructorType; - type: TypeNode; - } - export interface FunctionTypeNode extends FunctionOrConstructorTypeNodeBase { - kind: SyntaxKind.FunctionType; - } - export interface ConstructorTypeNode extends FunctionOrConstructorTypeNodeBase { - kind: SyntaxKind.ConstructorType; - } - export interface NodeWithTypeArguments extends TypeNode { - typeArguments?: NodeArray; - } - export type TypeReferenceType = TypeReferenceNode | ExpressionWithTypeArguments; - export interface TypeReferenceNode extends NodeWithTypeArguments { - kind: SyntaxKind.TypeReference; - typeName: EntityName; - } - export interface TypePredicateNode extends TypeNode { - kind: SyntaxKind.TypePredicate; - parent: SignatureDeclaration | JSDocTypeExpression; - parameterName: Identifier | ThisTypeNode; - type: TypeNode; - } - export interface TypeQueryNode extends TypeNode { - kind: SyntaxKind.TypeQuery; - exprName: EntityName; - } - export interface TypeLiteralNode extends TypeNode, Declaration { - kind: SyntaxKind.TypeLiteral; - members: NodeArray; - } - export interface ArrayTypeNode extends TypeNode { - kind: SyntaxKind.ArrayType; - elementType: TypeNode; - } - export interface TupleTypeNode extends TypeNode { - kind: SyntaxKind.TupleType; - elementTypes: NodeArray; - } - export interface OptionalTypeNode extends TypeNode { - kind: SyntaxKind.OptionalType; - type: TypeNode; - } - export interface RestTypeNode extends TypeNode { - kind: SyntaxKind.RestType; - type: TypeNode; - } - export type UnionOrIntersectionTypeNode = UnionTypeNode | IntersectionTypeNode; - export interface UnionTypeNode extends TypeNode { - kind: SyntaxKind.UnionType; - types: NodeArray; - } - export interface IntersectionTypeNode extends TypeNode { - kind: SyntaxKind.IntersectionType; - types: NodeArray; - } - export interface ConditionalTypeNode extends TypeNode { - kind: SyntaxKind.ConditionalType; - checkType: TypeNode; - extendsType: TypeNode; - trueType: TypeNode; - falseType: TypeNode; - } - export interface InferTypeNode extends TypeNode { - kind: SyntaxKind.InferType; - typeParameter: TypeParameterDeclaration; - } - export interface ParenthesizedTypeNode extends TypeNode { - kind: SyntaxKind.ParenthesizedType; - type: TypeNode; - } - export interface TypeOperatorNode extends TypeNode { - kind: SyntaxKind.TypeOperator; - operator: SyntaxKind.KeyOfKeyword | SyntaxKind.UniqueKeyword | SyntaxKind.ReadonlyKeyword; - type: TypeNode; - } - export interface UniqueTypeOperatorNode extends TypeOperatorNode { - operator: SyntaxKind.UniqueKeyword; - } - export interface IndexedAccessTypeNode extends TypeNode { - kind: SyntaxKind.IndexedAccessType; - objectType: TypeNode; - indexType: TypeNode; - } - export interface MappedTypeNode extends TypeNode, Declaration { - kind: SyntaxKind.MappedType; - readonlyToken?: ReadonlyToken | PlusToken | MinusToken; - typeParameter: TypeParameterDeclaration; - questionToken?: QuestionToken | PlusToken | MinusToken; - type?: TypeNode; - } - export interface LiteralTypeNode extends TypeNode { - kind: SyntaxKind.LiteralType; - literal: BooleanLiteral | LiteralExpression | PrefixUnaryExpression; - } - export interface StringLiteral extends LiteralExpression { - kind: SyntaxKind.StringLiteral; - textSourceNode?: Identifier | StringLiteralLike | NumericLiteral; - /** Note: this is only set when synthesizing a node, not during parsing. */ - singleQuote?: boolean; - } - export type StringLiteralLike = StringLiteral | NoSubstitutionTemplateLiteral; - export interface Expression extends Node { - _expressionBrand: any; - } - export interface OmittedExpression extends Expression { - kind: SyntaxKind.OmittedExpression; - } - export interface PartiallyEmittedExpression extends LeftHandSideExpression { - kind: SyntaxKind.PartiallyEmittedExpression; - expression: Expression; - } - export interface UnaryExpression extends Expression { - _unaryExpressionBrand: any; - } - /** Deprecated, please use UpdateExpression */ - export type IncrementExpression = UpdateExpression; - export interface UpdateExpression extends UnaryExpression { - _updateExpressionBrand: any; - } - export type PrefixUnaryOperator = SyntaxKind.PlusPlusToken | SyntaxKind.MinusMinusToken | SyntaxKind.PlusToken | SyntaxKind.MinusToken | SyntaxKind.TildeToken | SyntaxKind.ExclamationToken; - export interface PrefixUnaryExpression extends UpdateExpression { - kind: SyntaxKind.PrefixUnaryExpression; - operator: PrefixUnaryOperator; - operand: UnaryExpression; - } - export type PostfixUnaryOperator = SyntaxKind.PlusPlusToken | SyntaxKind.MinusMinusToken; - export interface PostfixUnaryExpression extends UpdateExpression { - kind: SyntaxKind.PostfixUnaryExpression; - operand: LeftHandSideExpression; - operator: PostfixUnaryOperator; - } - export interface LeftHandSideExpression extends UpdateExpression { - _leftHandSideExpressionBrand: any; - } - export interface MemberExpression extends LeftHandSideExpression { - _memberExpressionBrand: any; - } - export interface PrimaryExpression extends MemberExpression { - _primaryExpressionBrand: any; - } - export interface NullLiteral extends PrimaryExpression, TypeNode { - kind: SyntaxKind.NullKeyword; - } - export interface BooleanLiteral extends PrimaryExpression, TypeNode { - kind: SyntaxKind.TrueKeyword | SyntaxKind.FalseKeyword; - } - export interface ThisExpression extends PrimaryExpression, KeywordTypeNode { - kind: SyntaxKind.ThisKeyword; - } - export interface SuperExpression extends PrimaryExpression { - kind: SyntaxKind.SuperKeyword; - } - export interface ImportExpression extends PrimaryExpression { - kind: SyntaxKind.ImportKeyword; - } - export interface DeleteExpression extends UnaryExpression { - kind: SyntaxKind.DeleteExpression; - expression: UnaryExpression; - } - export interface TypeOfExpression extends UnaryExpression { - kind: SyntaxKind.TypeOfExpression; - expression: UnaryExpression; - } - export interface VoidExpression extends UnaryExpression { - kind: SyntaxKind.VoidExpression; - expression: UnaryExpression; - } - export interface AwaitExpression extends UnaryExpression { - kind: SyntaxKind.AwaitExpression; - expression: UnaryExpression; - } - export interface YieldExpression extends Expression { - kind: SyntaxKind.YieldExpression; - asteriskToken?: AsteriskToken; - expression?: Expression; - } - export interface SyntheticExpression extends Expression { - kind: SyntaxKind.SyntheticExpression; - isSpread: boolean; - type: Type; - } - export type ExponentiationOperator = SyntaxKind.AsteriskAsteriskToken; - export type MultiplicativeOperator = SyntaxKind.AsteriskToken | SyntaxKind.SlashToken | SyntaxKind.PercentToken; - export type MultiplicativeOperatorOrHigher = ExponentiationOperator | MultiplicativeOperator; - export type AdditiveOperator = SyntaxKind.PlusToken | SyntaxKind.MinusToken; - export type AdditiveOperatorOrHigher = MultiplicativeOperatorOrHigher | AdditiveOperator; - export type ShiftOperator = SyntaxKind.LessThanLessThanToken | SyntaxKind.GreaterThanGreaterThanToken | SyntaxKind.GreaterThanGreaterThanGreaterThanToken; - export type ShiftOperatorOrHigher = AdditiveOperatorOrHigher | ShiftOperator; - export type RelationalOperator = SyntaxKind.LessThanToken | SyntaxKind.LessThanEqualsToken | SyntaxKind.GreaterThanToken | SyntaxKind.GreaterThanEqualsToken | SyntaxKind.InstanceOfKeyword | SyntaxKind.InKeyword; - export type RelationalOperatorOrHigher = ShiftOperatorOrHigher | RelationalOperator; - export type EqualityOperator = SyntaxKind.EqualsEqualsToken | SyntaxKind.EqualsEqualsEqualsToken | SyntaxKind.ExclamationEqualsEqualsToken | SyntaxKind.ExclamationEqualsToken; - export type EqualityOperatorOrHigher = RelationalOperatorOrHigher | EqualityOperator; - export type BitwiseOperator = SyntaxKind.AmpersandToken | SyntaxKind.BarToken | SyntaxKind.CaretToken; - export type BitwiseOperatorOrHigher = EqualityOperatorOrHigher | BitwiseOperator; - export type LogicalOperator = SyntaxKind.AmpersandAmpersandToken | SyntaxKind.BarBarToken; - export type LogicalOperatorOrHigher = BitwiseOperatorOrHigher | LogicalOperator; - export type CompoundAssignmentOperator = SyntaxKind.PlusEqualsToken | SyntaxKind.MinusEqualsToken | SyntaxKind.AsteriskAsteriskEqualsToken | SyntaxKind.AsteriskEqualsToken | SyntaxKind.SlashEqualsToken | SyntaxKind.PercentEqualsToken | SyntaxKind.AmpersandEqualsToken | SyntaxKind.BarEqualsToken | SyntaxKind.CaretEqualsToken | SyntaxKind.LessThanLessThanEqualsToken | SyntaxKind.GreaterThanGreaterThanGreaterThanEqualsToken | SyntaxKind.GreaterThanGreaterThanEqualsToken; - export type AssignmentOperator = SyntaxKind.EqualsToken | CompoundAssignmentOperator; - export type AssignmentOperatorOrHigher = LogicalOperatorOrHigher | AssignmentOperator; - export type BinaryOperator = AssignmentOperatorOrHigher | SyntaxKind.CommaToken; - export type BinaryOperatorToken = Token; - export interface BinaryExpression extends Expression, Declaration { - kind: SyntaxKind.BinaryExpression; - left: Expression; - operatorToken: BinaryOperatorToken; - right: Expression; - } - export type AssignmentOperatorToken = Token; - export interface AssignmentExpression extends BinaryExpression { - left: LeftHandSideExpression; - operatorToken: TOperator; - } - export interface ObjectDestructuringAssignment extends AssignmentExpression { - left: ObjectLiteralExpression; - } - export interface ArrayDestructuringAssignment extends AssignmentExpression { - left: ArrayLiteralExpression; - } - export type DestructuringAssignment = ObjectDestructuringAssignment | ArrayDestructuringAssignment; - export type BindingOrAssignmentElement = VariableDeclaration | ParameterDeclaration | BindingElement | PropertyAssignment | ShorthandPropertyAssignment | SpreadAssignment | OmittedExpression | SpreadElement | ArrayLiteralExpression | ObjectLiteralExpression | AssignmentExpression | Identifier | PropertyAccessExpression | ElementAccessExpression; - export type BindingOrAssignmentElementRestIndicator = DotDotDotToken | SpreadElement | SpreadAssignment; - export type BindingOrAssignmentElementTarget = BindingOrAssignmentPattern | Identifier | PropertyAccessExpression | ElementAccessExpression | OmittedExpression; - export type ObjectBindingOrAssignmentPattern = ObjectBindingPattern | ObjectLiteralExpression; - export type ArrayBindingOrAssignmentPattern = ArrayBindingPattern | ArrayLiteralExpression; - export type AssignmentPattern = ObjectLiteralExpression | ArrayLiteralExpression; - export type BindingOrAssignmentPattern = ObjectBindingOrAssignmentPattern | ArrayBindingOrAssignmentPattern; - export interface ConditionalExpression extends Expression { - kind: SyntaxKind.ConditionalExpression; - condition: Expression; - questionToken: QuestionToken; - whenTrue: Expression; - colonToken: ColonToken; - whenFalse: Expression; - } - export type FunctionBody = Block; - export type ConciseBody = FunctionBody | Expression; - export interface FunctionExpression extends PrimaryExpression, FunctionLikeDeclarationBase, JSDocContainer { - kind: SyntaxKind.FunctionExpression; - name?: Identifier; - body: FunctionBody; - } - export interface ArrowFunction extends Expression, FunctionLikeDeclarationBase, JSDocContainer { - kind: SyntaxKind.ArrowFunction; - equalsGreaterThanToken: EqualsGreaterThanToken; - body: ConciseBody; - name: never; - } - export interface LiteralLikeNode extends Node { - text: string; - isUnterminated?: boolean; - hasExtendedUnicodeEscape?: boolean; - } - export interface TemplateLiteralLikeNode extends LiteralLikeNode { - rawText?: string; - } - export interface LiteralExpression extends LiteralLikeNode, PrimaryExpression { - _literalExpressionBrand: any; - } - export interface RegularExpressionLiteral extends LiteralExpression { - kind: SyntaxKind.RegularExpressionLiteral; - } - export interface NoSubstitutionTemplateLiteral extends LiteralExpression, TemplateLiteralLikeNode { - kind: SyntaxKind.NoSubstitutionTemplateLiteral; - } - export enum TokenFlags { - None = 0, - PrecedingLineBreak = 1, - PrecedingJSDocComment = 2, - Unterminated = 4, - ExtendedUnicodeEscape = 8, - Scientific = 16, - Octal = 32, - HexSpecifier = 64, - BinarySpecifier = 128, - OctalSpecifier = 256, - ContainsSeparator = 512, - UnicodeEscape = 1024, - BinaryOrOctalSpecifier = 384, - NumericLiteralFlags = 1008 - } - export interface NumericLiteral extends LiteralExpression { - kind: SyntaxKind.NumericLiteral; - numericLiteralFlags: TokenFlags; - } - export interface BigIntLiteral extends LiteralExpression { - kind: SyntaxKind.BigIntLiteral; - } - export interface TemplateHead extends TemplateLiteralLikeNode { - kind: SyntaxKind.TemplateHead; - parent: TemplateExpression; - } - export interface TemplateMiddle extends TemplateLiteralLikeNode { - kind: SyntaxKind.TemplateMiddle; - parent: TemplateSpan; - } - export interface TemplateTail extends TemplateLiteralLikeNode { - kind: SyntaxKind.TemplateTail; - parent: TemplateSpan; - } - export type TemplateLiteral = TemplateExpression | NoSubstitutionTemplateLiteral; - export interface TemplateExpression extends PrimaryExpression { - kind: SyntaxKind.TemplateExpression; - head: TemplateHead; - templateSpans: NodeArray; - } - export interface TemplateSpan extends Node { - kind: SyntaxKind.TemplateSpan; - parent: TemplateExpression; - expression: Expression; - literal: TemplateMiddle | TemplateTail; - } - export interface ParenthesizedExpression extends PrimaryExpression, JSDocContainer { - kind: SyntaxKind.ParenthesizedExpression; - expression: Expression; - } - export interface ArrayLiteralExpression extends PrimaryExpression { - kind: SyntaxKind.ArrayLiteralExpression; - elements: NodeArray; - multiLine?: boolean; - } - export interface SpreadElement extends Expression { - kind: SyntaxKind.SpreadElement; - parent: ArrayLiteralExpression | CallExpression | NewExpression; - expression: Expression; - } - /** - * This interface is a base interface for ObjectLiteralExpression and JSXAttributes to extend from. JSXAttributes is similar to - * ObjectLiteralExpression in that it contains array of properties; however, JSXAttributes' properties can only be - * JSXAttribute or JSXSpreadAttribute. ObjectLiteralExpression, on the other hand, can only have properties of type - * ObjectLiteralElement (e.g. PropertyAssignment, ShorthandPropertyAssignment etc.) - */ - export interface ObjectLiteralExpressionBase extends PrimaryExpression, Declaration { - properties: NodeArray; - } - export interface ObjectLiteralExpression extends ObjectLiteralExpressionBase { - kind: SyntaxKind.ObjectLiteralExpression; - multiLine?: boolean; - } - export type EntityNameExpression = Identifier | PropertyAccessEntityNameExpression; - export type EntityNameOrEntityNameExpression = EntityName | EntityNameExpression; - export type AccessExpression = PropertyAccessExpression | ElementAccessExpression; - export interface PropertyAccessExpression extends MemberExpression, NamedDeclaration { - kind: SyntaxKind.PropertyAccessExpression; - expression: LeftHandSideExpression; - name: Identifier; - } - export interface SuperPropertyAccessExpression extends PropertyAccessExpression { - expression: SuperExpression; - } - /** Brand for a PropertyAccessExpression which, like a QualifiedName, consists of a sequence of identifiers separated by dots. */ - export interface PropertyAccessEntityNameExpression extends PropertyAccessExpression { - _propertyAccessExpressionLikeQualifiedNameBrand?: any; - expression: EntityNameExpression; - } - export interface ElementAccessExpression extends MemberExpression { - kind: SyntaxKind.ElementAccessExpression; - expression: LeftHandSideExpression; - argumentExpression: Expression; - } - export interface SuperElementAccessExpression extends ElementAccessExpression { - expression: SuperExpression; - } - export type SuperProperty = SuperPropertyAccessExpression | SuperElementAccessExpression; - export interface CallExpression extends LeftHandSideExpression, Declaration { - kind: SyntaxKind.CallExpression; - expression: LeftHandSideExpression; - typeArguments?: NodeArray; - arguments: NodeArray; - } - /** @internal */ - export type BindableObjectDefinePropertyCall = CallExpression & { - arguments: { - 0: EntityNameExpression; - 1: StringLiteralLike | NumericLiteral; - 2: ObjectLiteralExpression; - }; - }; - export interface SuperCall extends CallExpression { - expression: SuperExpression; - } - export interface ImportCall extends CallExpression { - expression: ImportExpression; - } - export interface ExpressionWithTypeArguments extends NodeWithTypeArguments { - kind: SyntaxKind.ExpressionWithTypeArguments; - parent: HeritageClause | JSDocAugmentsTag; - expression: LeftHandSideExpression; - } - export interface NewExpression extends PrimaryExpression, Declaration { - kind: SyntaxKind.NewExpression; - expression: LeftHandSideExpression; - typeArguments?: NodeArray; - arguments?: NodeArray; - } - export interface TaggedTemplateExpression extends MemberExpression { - kind: SyntaxKind.TaggedTemplateExpression; - tag: LeftHandSideExpression; - typeArguments?: NodeArray; - template: TemplateLiteral; - } - export type CallLikeExpression = CallExpression | NewExpression | TaggedTemplateExpression | Decorator | JsxOpeningLikeElement; - export interface AsExpression extends Expression { - kind: SyntaxKind.AsExpression; - expression: Expression; - type: TypeNode; - } - export interface TypeAssertion extends UnaryExpression { - kind: SyntaxKind.TypeAssertionExpression; - type: TypeNode; - expression: UnaryExpression; - } - export type AssertionExpression = TypeAssertion | AsExpression; - export interface NonNullExpression extends LeftHandSideExpression { - kind: SyntaxKind.NonNullExpression; - expression: Expression; - } - export interface MetaProperty extends PrimaryExpression { - kind: SyntaxKind.MetaProperty; - keywordToken: SyntaxKind.NewKeyword | SyntaxKind.ImportKeyword; - name: Identifier; - } - export interface ImportMetaProperty extends MetaProperty { - keywordToken: SyntaxKind.ImportKeyword; - name: Identifier & { - escapedText: __String & "meta"; - }; - } - export interface JsxElement extends PrimaryExpression { - kind: SyntaxKind.JsxElement; - openingElement: JsxOpeningElement; - children: NodeArray; - closingElement: JsxClosingElement; - } - export type JsxOpeningLikeElement = JsxSelfClosingElement | JsxOpeningElement; - export type JsxAttributeLike = JsxAttribute | JsxSpreadAttribute; - export type JsxTagNameExpression = Identifier | ThisExpression | JsxTagNamePropertyAccess; - export interface JsxTagNamePropertyAccess extends PropertyAccessExpression { - expression: JsxTagNameExpression; - } - export interface JsxAttributes extends ObjectLiteralExpressionBase { - kind: SyntaxKind.JsxAttributes; - parent: JsxOpeningLikeElement; - } - export interface JsxOpeningElement extends Expression { - kind: SyntaxKind.JsxOpeningElement; - parent: JsxElement; - tagName: JsxTagNameExpression; - typeArguments?: NodeArray; - attributes: JsxAttributes; - } - export interface JsxSelfClosingElement extends PrimaryExpression { - kind: SyntaxKind.JsxSelfClosingElement; - tagName: JsxTagNameExpression; - typeArguments?: NodeArray; - attributes: JsxAttributes; - } - export interface JsxFragment extends PrimaryExpression { - kind: SyntaxKind.JsxFragment; - openingFragment: JsxOpeningFragment; - children: NodeArray; - closingFragment: JsxClosingFragment; - } - export interface JsxOpeningFragment extends Expression { - kind: SyntaxKind.JsxOpeningFragment; - parent: JsxFragment; - } - export interface JsxClosingFragment extends Expression { - kind: SyntaxKind.JsxClosingFragment; - parent: JsxFragment; - } - export interface JsxAttribute extends ObjectLiteralElement { - kind: SyntaxKind.JsxAttribute; - parent: JsxAttributes; - name: Identifier; - initializer?: StringLiteral | JsxExpression; - } - export interface JsxSpreadAttribute extends ObjectLiteralElement { - kind: SyntaxKind.JsxSpreadAttribute; - parent: JsxAttributes; - expression: Expression; - } - export interface JsxClosingElement extends Node { - kind: SyntaxKind.JsxClosingElement; - parent: JsxElement; - tagName: JsxTagNameExpression; - } - export interface JsxExpression extends Expression { - kind: SyntaxKind.JsxExpression; - parent: JsxElement | JsxAttributeLike; - dotDotDotToken?: Token; - expression?: Expression; - } - export interface JsxText extends LiteralLikeNode { - kind: SyntaxKind.JsxText; - containsOnlyTriviaWhiteSpaces: boolean; - parent: JsxElement; - } - export type JsxChild = JsxText | JsxExpression | JsxElement | JsxSelfClosingElement | JsxFragment; - export interface Statement extends Node { - _statementBrand: any; - } - export interface NotEmittedStatement extends Statement { - kind: SyntaxKind.NotEmittedStatement; - } - /** - * Marks the end of transformed declaration to properly emit exports. - */ - export interface EndOfDeclarationMarker extends Statement { - kind: SyntaxKind.EndOfDeclarationMarker; - } - /** - * A list of comma-separated expressions. This node is only created by transformations. - */ - export interface CommaListExpression extends Expression { - kind: SyntaxKind.CommaListExpression; - elements: NodeArray; - } - /** - * Marks the beginning of a merged transformed declaration. - */ - export interface MergeDeclarationMarker extends Statement { - kind: SyntaxKind.MergeDeclarationMarker; - } - export interface EmptyStatement extends Statement { - kind: SyntaxKind.EmptyStatement; - } - export interface DebuggerStatement extends Statement { - kind: SyntaxKind.DebuggerStatement; - } - export interface MissingDeclaration extends DeclarationStatement { - kind: SyntaxKind.MissingDeclaration; - name?: Identifier; - } - export type BlockLike = SourceFile | Block | ModuleBlock | CaseOrDefaultClause; - export interface Block extends Statement { - kind: SyntaxKind.Block; - statements: NodeArray; - multiLine?: boolean; - } - export interface VariableStatement extends Statement, JSDocContainer { - kind: SyntaxKind.VariableStatement; - declarationList: VariableDeclarationList; - } - export interface ExpressionStatement extends Statement, JSDocContainer { - kind: SyntaxKind.ExpressionStatement; - expression: Expression; - } - export interface PrologueDirective extends ExpressionStatement { - expression: StringLiteral; - } - export interface IfStatement extends Statement { - kind: SyntaxKind.IfStatement; - expression: Expression; - thenStatement: Statement; - elseStatement?: Statement; - } - export interface IterationStatement extends Statement { - statement: Statement; - } - export interface DoStatement extends IterationStatement { - kind: SyntaxKind.DoStatement; - expression: Expression; - } - export interface WhileStatement extends IterationStatement { - kind: SyntaxKind.WhileStatement; - expression: Expression; - } - export type ForInitializer = VariableDeclarationList | Expression; - export interface ForStatement extends IterationStatement { - kind: SyntaxKind.ForStatement; - initializer?: ForInitializer; - condition?: Expression; - incrementor?: Expression; - } - export type ForInOrOfStatement = ForInStatement | ForOfStatement; - export interface ForInStatement extends IterationStatement { - kind: SyntaxKind.ForInStatement; - initializer: ForInitializer; - expression: Expression; - } - export interface ForOfStatement extends IterationStatement { - kind: SyntaxKind.ForOfStatement; - awaitModifier?: AwaitKeywordToken; - initializer: ForInitializer; - expression: Expression; - } - export interface BreakStatement extends Statement { - kind: SyntaxKind.BreakStatement; - label?: Identifier; - } - export interface ContinueStatement extends Statement { - kind: SyntaxKind.ContinueStatement; - label?: Identifier; - } - export type BreakOrContinueStatement = BreakStatement | ContinueStatement; - export interface ReturnStatement extends Statement { - kind: SyntaxKind.ReturnStatement; - expression?: Expression; - } - export interface WithStatement extends Statement { - kind: SyntaxKind.WithStatement; - expression: Expression; - statement: Statement; - } - export interface SwitchStatement extends Statement { - kind: SyntaxKind.SwitchStatement; - expression: Expression; - caseBlock: CaseBlock; - possiblyExhaustive?: boolean; - } - export interface CaseBlock extends Node { - kind: SyntaxKind.CaseBlock; - parent: SwitchStatement; - clauses: NodeArray; - } - export interface CaseClause extends Node { - kind: SyntaxKind.CaseClause; - parent: CaseBlock; - expression: Expression; - statements: NodeArray; - } - export interface DefaultClause extends Node { - kind: SyntaxKind.DefaultClause; - parent: CaseBlock; - statements: NodeArray; - } - export type CaseOrDefaultClause = CaseClause | DefaultClause; - export interface LabeledStatement extends Statement, JSDocContainer { - kind: SyntaxKind.LabeledStatement; - label: Identifier; - statement: Statement; - } - export interface ThrowStatement extends Statement { - kind: SyntaxKind.ThrowStatement; - expression?: Expression; - } - export interface TryStatement extends Statement { - kind: SyntaxKind.TryStatement; - tryBlock: Block; - catchClause?: CatchClause; - finallyBlock?: Block; - } - export interface CatchClause extends Node { - kind: SyntaxKind.CatchClause; - parent: TryStatement; - variableDeclaration?: VariableDeclaration; - block: Block; - } - export type ObjectTypeDeclaration = ClassLikeDeclaration | InterfaceDeclaration | TypeLiteralNode; - export type DeclarationWithTypeParameters = DeclarationWithTypeParameterChildren | JSDocTypedefTag | JSDocCallbackTag | JSDocSignature; - export type DeclarationWithTypeParameterChildren = SignatureDeclaration | ClassLikeDeclaration | InterfaceDeclaration | TypeAliasDeclaration | JSDocTemplateTag; - export interface ClassLikeDeclarationBase extends NamedDeclaration, JSDocContainer { - kind: SyntaxKind.ClassDeclaration | SyntaxKind.ClassExpression; - name?: Identifier; - typeParameters?: NodeArray; - heritageClauses?: NodeArray; - members: NodeArray; - } - export interface ClassDeclaration extends ClassLikeDeclarationBase, DeclarationStatement { - kind: SyntaxKind.ClassDeclaration; - /** May be undefined in `export default class { ... }`. */ - name?: Identifier; - } - export interface ClassExpression extends ClassLikeDeclarationBase, PrimaryExpression { - kind: SyntaxKind.ClassExpression; - } - export type ClassLikeDeclaration = ClassDeclaration | ClassExpression; - export interface ClassElement extends NamedDeclaration { - _classElementBrand: any; - name?: PropertyName; - } - export interface TypeElement extends NamedDeclaration { - _typeElementBrand: any; - name?: PropertyName; - questionToken?: QuestionToken; - } - export interface InterfaceDeclaration extends DeclarationStatement, JSDocContainer { - kind: SyntaxKind.InterfaceDeclaration; - name: Identifier; - typeParameters?: NodeArray; - heritageClauses?: NodeArray; - members: NodeArray; - } - export interface HeritageClause extends Node { - kind: SyntaxKind.HeritageClause; - parent: InterfaceDeclaration | ClassLikeDeclaration; - token: SyntaxKind.ExtendsKeyword | SyntaxKind.ImplementsKeyword; - types: NodeArray; - } - export interface TypeAliasDeclaration extends DeclarationStatement, JSDocContainer { - kind: SyntaxKind.TypeAliasDeclaration; - name: Identifier; - typeParameters?: NodeArray; - type: TypeNode; - } - export interface EnumMember extends NamedDeclaration, JSDocContainer { - kind: SyntaxKind.EnumMember; - parent: EnumDeclaration; - name: PropertyName; - initializer?: Expression; - } - export interface EnumDeclaration extends DeclarationStatement, JSDocContainer { - kind: SyntaxKind.EnumDeclaration; - name: Identifier; - members: NodeArray; - } - export type ModuleName = Identifier | StringLiteral; - export type ModuleBody = NamespaceBody | JSDocNamespaceBody; - export interface AmbientModuleDeclaration extends ModuleDeclaration { - body?: ModuleBlock; - } - export interface ModuleDeclaration extends DeclarationStatement, JSDocContainer { - kind: SyntaxKind.ModuleDeclaration; - parent: ModuleBody | SourceFile; - name: ModuleName; - body?: ModuleBody | JSDocNamespaceDeclaration; - } - export type NamespaceBody = ModuleBlock | NamespaceDeclaration; - export interface NamespaceDeclaration extends ModuleDeclaration { - name: Identifier; - body: NamespaceBody; - } - export type JSDocNamespaceBody = Identifier | JSDocNamespaceDeclaration; - export interface JSDocNamespaceDeclaration extends ModuleDeclaration { - name: Identifier; - body?: JSDocNamespaceBody; - } - export interface ModuleBlock extends Node, Statement { - kind: SyntaxKind.ModuleBlock; - parent: ModuleDeclaration; - statements: NodeArray; - } - export type ModuleReference = EntityName | ExternalModuleReference; - /** - * One of: - * - import x = require("mod"); - * - import x = M.x; - */ - export interface ImportEqualsDeclaration extends DeclarationStatement, JSDocContainer { - kind: SyntaxKind.ImportEqualsDeclaration; - parent: SourceFile | ModuleBlock; - name: Identifier; - moduleReference: ModuleReference; - } - export interface ExternalModuleReference extends Node { - kind: SyntaxKind.ExternalModuleReference; - parent: ImportEqualsDeclaration; - expression: Expression; - } - export interface ImportDeclaration extends Statement { - kind: SyntaxKind.ImportDeclaration; - parent: SourceFile | ModuleBlock; - importClause?: ImportClause; - /** If this is not a StringLiteral it will be a grammar error. */ - moduleSpecifier: Expression; - } - export type NamedImportBindings = NamespaceImport | NamedImports; - export interface ImportClause extends NamedDeclaration { - kind: SyntaxKind.ImportClause; - parent: ImportDeclaration; - name?: Identifier; - namedBindings?: NamedImportBindings; - } - export interface NamespaceImport extends NamedDeclaration { - kind: SyntaxKind.NamespaceImport; - parent: ImportClause; - name: Identifier; - } - export interface NamespaceExportDeclaration extends DeclarationStatement { - kind: SyntaxKind.NamespaceExportDeclaration; - name: Identifier; - } - export interface ExportDeclaration extends DeclarationStatement, JSDocContainer { - kind: SyntaxKind.ExportDeclaration; - parent: SourceFile | ModuleBlock; - /** Will not be assigned in the case of `export * from "foo";` */ - exportClause?: NamedExports; - /** If this is not a StringLiteral it will be a grammar error. */ - moduleSpecifier?: Expression; - } - export interface NamedImports extends Node { - kind: SyntaxKind.NamedImports; - parent: ImportClause; - elements: NodeArray; - } - export interface NamedExports extends Node { - kind: SyntaxKind.NamedExports; - parent: ExportDeclaration; - elements: NodeArray; - } - export type NamedImportsOrExports = NamedImports | NamedExports; - export interface ImportSpecifier extends NamedDeclaration { - kind: SyntaxKind.ImportSpecifier; - parent: NamedImports; - propertyName?: Identifier; - name: Identifier; - } - export interface ExportSpecifier extends NamedDeclaration { - kind: SyntaxKind.ExportSpecifier; - parent: NamedExports; - propertyName?: Identifier; - name: Identifier; - } - export type ImportOrExportSpecifier = ImportSpecifier | ExportSpecifier; - /** - * This is either an `export =` or an `export default` declaration. - * Unless `isExportEquals` is set, this node was parsed as an `export default`. - */ - export interface ExportAssignment extends DeclarationStatement { - kind: SyntaxKind.ExportAssignment; - parent: SourceFile; - isExportEquals?: boolean; - expression: Expression; - } - export interface FileReference extends TextRange { - fileName: string; - } - export interface CheckJsDirective extends TextRange { - enabled: boolean; - } - export type CommentKind = SyntaxKind.SingleLineCommentTrivia | SyntaxKind.MultiLineCommentTrivia; - export interface CommentRange extends TextRange { - hasTrailingNewLine?: boolean; - kind: CommentKind; - } - export interface SynthesizedComment extends CommentRange { - text: string; - pos: -1; - end: -1; - } - export interface JSDocTypeExpression extends TypeNode { - kind: SyntaxKind.JSDocTypeExpression; - type: TypeNode; - } - export interface JSDocType extends TypeNode { - _jsDocTypeBrand: any; - } - export interface JSDocAllType extends JSDocType { - kind: SyntaxKind.JSDocAllType; - } - export interface JSDocUnknownType extends JSDocType { - kind: SyntaxKind.JSDocUnknownType; - } - export interface JSDocNonNullableType extends JSDocType { - kind: SyntaxKind.JSDocNonNullableType; - type: TypeNode; - } - export interface JSDocNullableType extends JSDocType { - kind: SyntaxKind.JSDocNullableType; - type: TypeNode; - } - export interface JSDocOptionalType extends JSDocType { - kind: SyntaxKind.JSDocOptionalType; - type: TypeNode; - } - export interface JSDocFunctionType extends JSDocType, SignatureDeclarationBase { - kind: SyntaxKind.JSDocFunctionType; - } - export interface JSDocVariadicType extends JSDocType { - kind: SyntaxKind.JSDocVariadicType; - type: TypeNode; - } - export interface JSDocNamepathType extends JSDocType { - kind: SyntaxKind.JSDocNamepathType; - type: TypeNode; - } - export type JSDocTypeReferencingNode = JSDocVariadicType | JSDocOptionalType | JSDocNullableType | JSDocNonNullableType; - export interface JSDoc extends Node { - kind: SyntaxKind.JSDocComment; - parent: HasJSDoc; - tags?: NodeArray; - comment?: string; - } - export interface JSDocTag extends Node { - parent: JSDoc | JSDocTypeLiteral; - tagName: Identifier; - comment?: string; - } - export interface JSDocUnknownTag extends JSDocTag { - kind: SyntaxKind.JSDocTag; - } - /** - * Note that `@extends` is a synonym of `@augments`. - * Both tags are represented by this interface. - */ - export interface JSDocAugmentsTag extends JSDocTag { - kind: SyntaxKind.JSDocAugmentsTag; - class: ExpressionWithTypeArguments & { - expression: Identifier | PropertyAccessEntityNameExpression; - }; - } - export interface JSDocAuthorTag extends JSDocTag { - kind: SyntaxKind.JSDocAuthorTag; - } - export interface JSDocClassTag extends JSDocTag { - kind: SyntaxKind.JSDocClassTag; - } - export interface JSDocEnumTag extends JSDocTag, Declaration { - parent: JSDoc; - kind: SyntaxKind.JSDocEnumTag; - typeExpression?: JSDocTypeExpression; - } - export interface JSDocThisTag extends JSDocTag { - kind: SyntaxKind.JSDocThisTag; - typeExpression?: JSDocTypeExpression; - } - export interface JSDocTemplateTag extends JSDocTag { - kind: SyntaxKind.JSDocTemplateTag; - constraint: JSDocTypeExpression | undefined; - typeParameters: NodeArray; - } - export interface JSDocReturnTag extends JSDocTag { - kind: SyntaxKind.JSDocReturnTag; - typeExpression?: JSDocTypeExpression; - } - export interface JSDocTypeTag extends JSDocTag { - kind: SyntaxKind.JSDocTypeTag; - typeExpression: JSDocTypeExpression; - } - export interface JSDocTypedefTag extends JSDocTag, NamedDeclaration { - parent: JSDoc; - kind: SyntaxKind.JSDocTypedefTag; - fullName?: JSDocNamespaceDeclaration | Identifier; - name?: Identifier; - typeExpression?: JSDocTypeExpression | JSDocTypeLiteral; - } - export interface JSDocCallbackTag extends JSDocTag, NamedDeclaration { - parent: JSDoc; - kind: SyntaxKind.JSDocCallbackTag; - fullName?: JSDocNamespaceDeclaration | Identifier; - name?: Identifier; - typeExpression: JSDocSignature; - } - export interface JSDocSignature extends JSDocType, Declaration { - kind: SyntaxKind.JSDocSignature; - typeParameters?: ReadonlyArray; - parameters: ReadonlyArray; - type: JSDocReturnTag | undefined; - } - export interface JSDocPropertyLikeTag extends JSDocTag, Declaration { - parent: JSDoc; - name: EntityName; - typeExpression?: JSDocTypeExpression; - /** Whether the property name came before the type -- non-standard for JSDoc, but Typescript-like */ - isNameFirst: boolean; - isBracketed: boolean; - } - export interface JSDocPropertyTag extends JSDocPropertyLikeTag { - kind: SyntaxKind.JSDocPropertyTag; - } - export interface JSDocParameterTag extends JSDocPropertyLikeTag { - kind: SyntaxKind.JSDocParameterTag; - } - export interface JSDocTypeLiteral extends JSDocType { - kind: SyntaxKind.JSDocTypeLiteral; - jsDocPropertyTags?: ReadonlyArray; - /** If true, then this type literal represents an *array* of its type. */ - isArrayType?: boolean; - } - export enum FlowFlags { - Unreachable = 1, - Start = 2, - BranchLabel = 4, - LoopLabel = 8, - Assignment = 16, - TrueCondition = 32, - FalseCondition = 64, - SwitchClause = 128, - ArrayMutation = 256, - Referenced = 512, - Shared = 1024, - PreFinally = 2048, - AfterFinally = 4096, - /** @internal */ - Cached = 8192, - Label = 12, - Condition = 96 - } - export interface FlowLock { - locked?: boolean; - } - export interface AfterFinallyFlow extends FlowNodeBase, FlowLock { - antecedent: FlowNode; - } - export interface PreFinallyFlow extends FlowNodeBase { - antecedent: FlowNode; - lock: FlowLock; - } - export type FlowNode = AfterFinallyFlow | PreFinallyFlow | FlowStart | FlowLabel | FlowAssignment | FlowCondition | FlowSwitchClause | FlowArrayMutation; - export interface FlowNodeBase { - flags: FlowFlags; - id?: number; - } - export interface FlowStart extends FlowNodeBase { - container?: FunctionExpression | ArrowFunction | MethodDeclaration; - } - export interface FlowLabel extends FlowNodeBase { - antecedents: FlowNode[] | undefined; - } - export interface FlowAssignment extends FlowNodeBase { - node: Expression | VariableDeclaration | BindingElement; - antecedent: FlowNode; - } - export interface FlowCondition extends FlowNodeBase { - expression: Expression; - antecedent: FlowNode; - } - export interface FlowSwitchClause extends FlowNodeBase { - switchStatement: SwitchStatement; - clauseStart: number; - clauseEnd: number; - antecedent: FlowNode; - } - export interface FlowArrayMutation extends FlowNodeBase { - node: CallExpression | BinaryExpression; - antecedent: FlowNode; - } - export type FlowType = Type | IncompleteType; - export interface IncompleteType { - flags: TypeFlags; - type: Type; - } - export interface AmdDependency { - path: string; - name?: string; - } - /** - * Subset of properties from SourceFile that are used in multiple utility functions - */ - export interface SourceFileLike { - readonly text: string; - lineMap?: ReadonlyArray; - getPositionOfLineAndCharacter?(line: number, character: number, allowEdits?: true): number; - } - export interface RedirectInfo { - /** Source file this redirects to. */ - readonly redirectTarget: SourceFile; - /** - * Source file for the duplicate package. This will not be used by the Program, - * but we need to keep this around so we can watch for changes in underlying. - */ - readonly unredirected: SourceFile; - } - export interface SourceFile extends Declaration { - kind: SyntaxKind.SourceFile; - statements: NodeArray; - endOfFileToken: Token; - fileName: string; - path: Path; - text: string; - /** Resolved path can be different from path property, - * when file is included through project reference is mapped to its output instead of source - * in that case resolvedPath = path to output file - * path = input file's path - */ - resolvedPath: Path; - /** Original file name that can be different from fileName, - * when file is included through project reference is mapped to its output instead of source - * in that case originalFileName = name of input file - * fileName = output file's name - */ - originalFileName: string; - /** - * If two source files are for the same version of the same package, one will redirect to the other. - * (See `createRedirectSourceFile` in program.ts.) - * The redirect will have this set. The redirected-to source file will be in `redirectTargetsMap`. - */ - redirectInfo?: RedirectInfo; - amdDependencies: ReadonlyArray; - moduleName?: string; - referencedFiles: ReadonlyArray; - typeReferenceDirectives: ReadonlyArray; - libReferenceDirectives: ReadonlyArray; - languageVariant: LanguageVariant; - isDeclarationFile: boolean; - renamedDependencies?: ReadonlyMap; - /** - * lib.d.ts should have a reference comment like - * - * /// - * - * If any other file has this comment, it signals not to include lib.d.ts - * because this containing file is intended to act as a default library. - */ - hasNoDefaultLib: boolean; - languageVersion: ScriptTarget; - scriptKind: ScriptKind; - /** - * The first "most obvious" node that makes a file an external module. - * This is intended to be the first top-level import/export, - * but could be arbitrarily nested (e.g. `import.meta`). - */ - externalModuleIndicator?: Node; - commonJsModuleIndicator?: Node; - jsGlobalAugmentations?: SymbolTable; - identifiers: Map; - nodeCount: number; - identifierCount: number; - symbolCount: number; - parseDiagnostics: DiagnosticWithLocation[]; - bindDiagnostics: DiagnosticWithLocation[]; - bindSuggestionDiagnostics?: DiagnosticWithLocation[]; - jsDocDiagnostics?: DiagnosticWithLocation[]; - additionalSyntacticDiagnostics?: ReadonlyArray; - lineMap: ReadonlyArray; - classifiableNames?: ReadonlyUnderscoreEscapedMap; - resolvedModules?: Map; - resolvedTypeReferenceDirectiveNames: Map; - imports: ReadonlyArray; - moduleAugmentations: ReadonlyArray; - patternAmbientModules?: PatternAmbientModule[]; - ambientModuleNames: ReadonlyArray; - checkJsDirective?: CheckJsDirective; - version: string; - pragmas: ReadonlyPragmaMap; - localJsxNamespace?: __String; - localJsxFactory?: EntityName; - exportedModulesFromDeclarationEmit?: ExportedModulesFromDeclarationEmit; - } - export type ExportedModulesFromDeclarationEmit = ReadonlyArray; - export interface Bundle extends Node { - kind: SyntaxKind.Bundle; - prepends: ReadonlyArray; - sourceFiles: ReadonlyArray; - syntheticFileReferences?: ReadonlyArray; - syntheticTypeReferences?: ReadonlyArray; - syntheticLibReferences?: ReadonlyArray; - hasNoDefaultLib?: boolean; - } - export interface InputFiles extends Node { - kind: SyntaxKind.InputFiles; - javascriptPath?: string; - javascriptText: string; - javascriptMapPath?: string; - javascriptMapText?: string; - declarationPath?: string; - declarationText: string; - declarationMapPath?: string; - declarationMapText?: string; - buildInfoPath?: string; - buildInfo?: BuildInfo; - oldFileOfCurrentEmit?: boolean; - } - export interface UnparsedSource extends Node { - kind: SyntaxKind.UnparsedSource; - fileName: string; - text: string; - prologues: ReadonlyArray; - helpers: ReadonlyArray | undefined; - referencedFiles: ReadonlyArray; - typeReferenceDirectives: ReadonlyArray | undefined; - libReferenceDirectives: ReadonlyArray; - hasNoDefaultLib?: boolean; - sourceMapPath?: string; - sourceMapText?: string; - syntheticReferences?: ReadonlyArray; - texts: ReadonlyArray; - oldFileOfCurrentEmit?: boolean; - parsedSourceMap?: RawSourceMap | false | undefined; - getLineAndCharacterOfPosition(pos: number): LineAndCharacter; - } - export type UnparsedSourceText = UnparsedPrepend | UnparsedTextLike; - export type UnparsedNode = UnparsedPrologue | UnparsedSourceText | UnparsedSyntheticReference; - export interface UnparsedSection extends Node { - kind: SyntaxKind; - data?: string; - parent: UnparsedSource; - } - export interface UnparsedPrologue extends UnparsedSection { - kind: SyntaxKind.UnparsedPrologue; - data: string; - parent: UnparsedSource; - } - export interface UnparsedPrepend extends UnparsedSection { - kind: SyntaxKind.UnparsedPrepend; - data: string; - parent: UnparsedSource; - texts: ReadonlyArray; - } - export interface UnparsedTextLike extends UnparsedSection { - kind: SyntaxKind.UnparsedText | SyntaxKind.UnparsedInternalText; - parent: UnparsedSource; - } - export interface UnparsedSyntheticReference extends UnparsedSection { - kind: SyntaxKind.UnparsedSyntheticReference; - parent: UnparsedSource; - section: BundleFileHasNoDefaultLib | BundleFileReference; - } - export interface JsonSourceFile extends SourceFile { - statements: NodeArray; - } - export interface TsConfigSourceFile extends JsonSourceFile { - extendedSourceFiles?: string[]; - } - export interface JsonMinusNumericLiteral extends PrefixUnaryExpression { - kind: SyntaxKind.PrefixUnaryExpression; - operator: SyntaxKind.MinusToken; - operand: NumericLiteral; - } - export interface JsonObjectExpressionStatement extends ExpressionStatement { - expression: ObjectLiteralExpression | ArrayLiteralExpression | JsonMinusNumericLiteral | NumericLiteral | StringLiteral | BooleanLiteral | NullLiteral; - } - export interface ScriptReferenceHost { - getCompilerOptions(): CompilerOptions; - getSourceFile(fileName: string): SourceFile | undefined; - getSourceFileByPath(path: Path): SourceFile | undefined; - getCurrentDirectory(): string; - } - export interface ParseConfigHost { - useCaseSensitiveFileNames: boolean; - readDirectory(rootDir: string, extensions: ReadonlyArray, excludes: ReadonlyArray | undefined, includes: ReadonlyArray, depth?: number): ReadonlyArray; - /** - * Gets a value indicating whether the specified path exists and is a file. - * @param path The path to test. - */ - fileExists(path: string): boolean; - readFile(path: string): string | undefined; - trace?(s: string): void; - } - /** - * Branded string for keeping track of when we've turned an ambiguous path - * specified like "./blah" to an absolute path to an actual - * tsconfig file, e.g. "/root/blah/tsconfig.json" - */ - export type ResolvedConfigFileName = string & { - _isResolvedConfigFileName: never; - }; - export type WriteFileCallback = (fileName: string, data: string, writeByteOrderMark: boolean, onError?: (message: string) => void, sourceFiles?: ReadonlyArray) => void; - export class OperationCanceledException { - } - export interface CancellationToken { - isCancellationRequested(): boolean; - /** @throws OperationCanceledException if isCancellationRequested is true */ - throwIfCancellationRequested(): void; - } - export enum RefFileKind { - Import = 0, - ReferenceFile = 1, - TypeReferenceDirective = 2 - } - export interface RefFile { - kind: RefFileKind; - index: number; - file: Path; - } - export interface Program extends ScriptReferenceHost { - /** - * Get a list of root file names that were passed to a 'createProgram' - */ - getRootFileNames(): ReadonlyArray; - /** - * Get a list of files in the program - */ - getSourceFiles(): ReadonlyArray; - /** - * Get a list of file names that were passed to 'createProgram' or referenced in a - * program source file but could not be located. - */ - getMissingFilePaths(): ReadonlyArray; - getRefFileMap(): MultiMap | undefined; - /** - * Emits the JavaScript and declaration files. If targetSourceFile is not specified, then - * the JavaScript and declaration files will be produced for all the files in this program. - * If targetSourceFile is specified, then only the JavaScript and declaration for that - * specific file will be generated. - * - * If writeFile is not specified then the writeFile callback from the compiler host will be - * used for writing the JavaScript and declaration files. Otherwise, the writeFile parameter - * will be invoked when writing the JavaScript and declaration files. - */ - emit(targetSourceFile?: SourceFile, writeFile?: WriteFileCallback, cancellationToken?: CancellationToken, emitOnlyDtsFiles?: boolean, customTransformers?: CustomTransformers): EmitResult; - getOptionsDiagnostics(cancellationToken?: CancellationToken): ReadonlyArray; - getGlobalDiagnostics(cancellationToken?: CancellationToken): ReadonlyArray; - getSyntacticDiagnostics(sourceFile?: SourceFile, cancellationToken?: CancellationToken): ReadonlyArray; - /** The first time this is called, it will return global diagnostics (no location). */ - getSemanticDiagnostics(sourceFile?: SourceFile, cancellationToken?: CancellationToken): ReadonlyArray; - getDeclarationDiagnostics(sourceFile?: SourceFile, cancellationToken?: CancellationToken): ReadonlyArray; - getConfigFileParsingDiagnostics(): ReadonlyArray; - getSuggestionDiagnostics(sourceFile: SourceFile, cancellationToken?: CancellationToken): ReadonlyArray; - /** - * Gets a type checker that can be used to semantically analyze source files in the program. - */ - getTypeChecker(): TypeChecker; - getCommonSourceDirectory(): string; - getDiagnosticsProducingTypeChecker(): TypeChecker; - dropDiagnosticsProducingTypeChecker(): void; - getClassifiableNames(): UnderscoreEscapedMap; - getNodeCount(): number; - getIdentifierCount(): number; - getSymbolCount(): number; - getTypeCount(): number; - getRelationCacheSizes(): { - assignable: number; - identity: number; - subtype: number; - }; - getFileProcessingDiagnostics(): DiagnosticCollection; - getResolvedTypeReferenceDirectives(): Map; - isSourceFileFromExternalLibrary(file: SourceFile): boolean; - isSourceFileDefaultLibrary(file: SourceFile): boolean; - structureIsReused?: StructureIsReused; - getSourceFileFromReference(referencingFile: SourceFile | UnparsedSource, ref: FileReference): SourceFile | undefined; - getLibFileFromReference(ref: FileReference): SourceFile | undefined; - /** Given a source file, get the name of the package it was imported from. */ - sourceFileToPackageName: Map; - /** Set of all source files that some other source file redirects to. */ - redirectTargetsMap: MultiMap; - /** Is the file emitted file */ - isEmittedFile(file: string): boolean; - getResolvedModuleWithFailedLookupLocationsFromCache(moduleName: string, containingFile: string): ResolvedModuleWithFailedLookupLocations | undefined; - getProjectReferences(): ReadonlyArray | undefined; - getResolvedProjectReferences(): ReadonlyArray | undefined; - getProjectReferenceRedirect(fileName: string): string | undefined; - getResolvedProjectReferenceToRedirect(fileName: string): ResolvedProjectReference | undefined; - forEachResolvedProjectReference(cb: (resolvedProjectReference: ResolvedProjectReference | undefined, resolvedProjectReferencePath: Path) => T | undefined): T | undefined; - getResolvedProjectReferenceByPath(projectReferencePath: Path): ResolvedProjectReference | undefined; - getProgramBuildInfo?(): ProgramBuildInfo | undefined; - emitBuildInfo(writeFile?: WriteFileCallback, cancellationToken?: CancellationToken): EmitResult; - } - export type RedirectTargetsMap = ReadonlyMap>; - export interface ResolvedProjectReference { - commandLine: ParsedCommandLine; - sourceFile: SourceFile; - references?: ReadonlyArray; - } - export enum StructureIsReused { - Not = 0, - SafeModules = 1, - Completely = 2 - } - export type CustomTransformerFactory = (context: TransformationContext) => CustomTransformer; - export interface CustomTransformer { - transformSourceFile(node: SourceFile): SourceFile; - transformBundle(node: Bundle): Bundle; - } - export interface CustomTransformers { - /** Custom transformers to evaluate before built-in .js transformations. */ - before?: (TransformerFactory | CustomTransformerFactory)[]; - /** Custom transformers to evaluate after built-in .js transformations. */ - after?: (TransformerFactory | CustomTransformerFactory)[]; - /** Custom transformers to evaluate after built-in .d.ts transformations. */ - afterDeclarations?: (TransformerFactory | CustomTransformerFactory)[]; - } - export interface EmitTransformers { - scriptTransformers: readonly TransformerFactory[]; - declarationTransformers: readonly TransformerFactory[]; - } - export interface SourceMapSpan { - /** Line number in the .js file. */ - emittedLine: number; - /** Column number in the .js file. */ - emittedColumn: number; - /** Line number in the .ts file. */ - sourceLine: number; - /** Column number in the .ts file. */ - sourceColumn: number; - /** Optional name (index into names array) associated with this span. */ - nameIndex?: number; - /** .ts file (index into sources array) associated with this span */ - sourceIndex: number; - } - export interface SourceMapEmitResult { - inputSourceFileNames: ReadonlyArray; - sourceMap: RawSourceMap; - } - /** Return code used by getEmitOutput function to indicate status of the function */ - export enum ExitStatus { - Success = 0, - DiagnosticsPresent_OutputsSkipped = 1, - DiagnosticsPresent_OutputsGenerated = 2, - InvalidProject_OutputsSkipped = 3, - ProjectReferenceCycle_OutputsSkupped = 4 - } - export interface EmitResult { - emitSkipped: boolean; - /** Contains declaration emit diagnostics */ - diagnostics: ReadonlyArray; - emittedFiles?: string[]; - sourceMaps?: SourceMapEmitResult[]; - exportedModulesFromDeclarationEmit?: ExportedModulesFromDeclarationEmit; - } - export interface TypeCheckerHost extends ModuleSpecifierResolutionHost { - getCompilerOptions(): CompilerOptions; - getSourceFiles(): ReadonlyArray; - getSourceFile(fileName: string): SourceFile | undefined; - getResolvedTypeReferenceDirectives(): ReadonlyMap; - getProjectReferenceRedirect(fileName: string): string | undefined; - readonly redirectTargetsMap: RedirectTargetsMap; - } - export interface TypeChecker { - getTypeOfSymbolAtLocation(symbol: Symbol, node: Node): Type; - getDeclaredTypeOfSymbol(symbol: Symbol): Type; - getPropertiesOfType(type: Type): Symbol[]; - getPropertyOfType(type: Type, propertyName: string): Symbol | undefined; - getTypeOfPropertyOfType(type: Type, propertyName: string): Type | undefined; - getIndexInfoOfType(type: Type, kind: IndexKind): IndexInfo | undefined; - getSignaturesOfType(type: Type, kind: SignatureKind): ReadonlyArray; - getIndexTypeOfType(type: Type, kind: IndexKind): Type | undefined; - getBaseTypes(type: InterfaceType): BaseType[]; - getBaseTypeOfLiteralType(type: Type): Type; - getWidenedType(type: Type): Type; - getPromisedTypeOfPromise(promise: Type, errorNode?: Node): Type | undefined; - getReturnTypeOfSignature(signature: Signature): Type; - /** - * Gets the type of a parameter at a given position in a signature. - * Returns `any` if the index is not valid. - */ - getParameterType(signature: Signature, parameterIndex: number): Type; - getNullableType(type: Type, flags: TypeFlags): Type; - getNonNullableType(type: Type): Type; - /** Note that the resulting nodes cannot be checked. */ - typeToTypeNode(type: Type, enclosingDeclaration?: Node, flags?: NodeBuilderFlags): TypeNode | undefined; - typeToTypeNode(type: Type, enclosingDeclaration?: Node, flags?: NodeBuilderFlags, tracker?: SymbolTracker): TypeNode | undefined; - /** Note that the resulting nodes cannot be checked. */ - signatureToSignatureDeclaration(signature: Signature, kind: SyntaxKind, enclosingDeclaration?: Node, flags?: NodeBuilderFlags): (SignatureDeclaration & { - typeArguments?: NodeArray; - }) | undefined; - signatureToSignatureDeclaration(signature: Signature, kind: SyntaxKind, enclosingDeclaration?: Node, flags?: NodeBuilderFlags, tracker?: SymbolTracker): (SignatureDeclaration & { - typeArguments?: NodeArray; - }) | undefined; - /** Note that the resulting nodes cannot be checked. */ - indexInfoToIndexSignatureDeclaration(indexInfo: IndexInfo, kind: IndexKind, enclosingDeclaration?: Node, flags?: NodeBuilderFlags): IndexSignatureDeclaration | undefined; - indexInfoToIndexSignatureDeclaration(indexInfo: IndexInfo, kind: IndexKind, enclosingDeclaration?: Node, flags?: NodeBuilderFlags, tracker?: SymbolTracker): IndexSignatureDeclaration | undefined; - /** Note that the resulting nodes cannot be checked. */ - symbolToEntityName(symbol: Symbol, meaning: SymbolFlags, enclosingDeclaration?: Node, flags?: NodeBuilderFlags): EntityName | undefined; - /** Note that the resulting nodes cannot be checked. */ - symbolToExpression(symbol: Symbol, meaning: SymbolFlags, enclosingDeclaration?: Node, flags?: NodeBuilderFlags): Expression | undefined; - /** Note that the resulting nodes cannot be checked. */ - symbolToTypeParameterDeclarations(symbol: Symbol, enclosingDeclaration?: Node, flags?: NodeBuilderFlags): NodeArray | undefined; - /** Note that the resulting nodes cannot be checked. */ - symbolToParameterDeclaration(symbol: Symbol, enclosingDeclaration?: Node, flags?: NodeBuilderFlags): ParameterDeclaration | undefined; - /** Note that the resulting nodes cannot be checked. */ - typeParameterToDeclaration(parameter: TypeParameter, enclosingDeclaration?: Node, flags?: NodeBuilderFlags): TypeParameterDeclaration | undefined; - getSymbolsInScope(location: Node, meaning: SymbolFlags): Symbol[]; - getSymbolAtLocation(node: Node): Symbol | undefined; - getSymbolsOfParameterPropertyDeclaration(parameter: ParameterDeclaration, parameterName: string): Symbol[]; - /** - * The function returns the value (local variable) symbol of an identifier in the short-hand property assignment. - * This is necessary as an identifier in short-hand property assignment can contains two meaning: property name and property value. - */ - getShorthandAssignmentValueSymbol(location: Node): Symbol | undefined; - getExportSpecifierLocalTargetSymbol(location: ExportSpecifier): Symbol | undefined; - /** - * If a symbol is a local symbol with an associated exported symbol, returns the exported symbol. - * Otherwise returns its input. - * For example, at `export type T = number;`: - * - `getSymbolAtLocation` at the location `T` will return the exported symbol for `T`. - * - But the result of `getSymbolsInScope` will contain the *local* symbol for `T`, not the exported symbol. - * - Calling `getExportSymbolOfSymbol` on that local symbol will return the exported symbol. - */ - getExportSymbolOfSymbol(symbol: Symbol): Symbol; - getPropertySymbolOfDestructuringAssignment(location: Identifier): Symbol | undefined; - getTypeOfAssignmentPattern(pattern: AssignmentPattern): Type; - getTypeAtLocation(node: Node): Type; - getTypeFromTypeNode(node: TypeNode): Type; - signatureToString(signature: Signature, enclosingDeclaration?: Node, flags?: TypeFormatFlags, kind?: SignatureKind): string; - typeToString(type: Type, enclosingDeclaration?: Node, flags?: TypeFormatFlags): string; - symbolToString(symbol: Symbol, enclosingDeclaration?: Node, meaning?: SymbolFlags, flags?: SymbolFormatFlags): string; - typePredicateToString(predicate: TypePredicate, enclosingDeclaration?: Node, flags?: TypeFormatFlags): string; - writeSignature(signature: Signature, enclosingDeclaration?: Node, flags?: TypeFormatFlags, kind?: SignatureKind, writer?: EmitTextWriter): string; - writeType(type: Type, enclosingDeclaration?: Node, flags?: TypeFormatFlags, writer?: EmitTextWriter): string; - writeSymbol(symbol: Symbol, enclosingDeclaration?: Node, meaning?: SymbolFlags, flags?: SymbolFormatFlags, writer?: EmitTextWriter): string; - writeTypePredicate(predicate: TypePredicate, enclosingDeclaration?: Node, flags?: TypeFormatFlags, writer?: EmitTextWriter): string; - getFullyQualifiedName(symbol: Symbol): string; - getAugmentedPropertiesOfType(type: Type): Symbol[]; - getRootSymbols(symbol: Symbol): ReadonlyArray; - getContextualType(node: Expression): Type | undefined; - getContextualTypeForObjectLiteralElement(element: ObjectLiteralElementLike): Type | undefined; - getContextualTypeForArgumentAtIndex(call: CallLikeExpression, argIndex: number): Type | undefined; - getContextualTypeForJsxAttribute(attribute: JsxAttribute | JsxSpreadAttribute): Type | undefined; - isContextSensitive(node: Expression | MethodDeclaration | ObjectLiteralElementLike | JsxAttributeLike): boolean; - /** - * returns unknownSignature in the case of an error. - * returns undefined if the node is not valid. - * @param argumentCount Apparent number of arguments, passed in case of a possibly incomplete call. This should come from an ArgumentListInfo. See `signatureHelp.ts`. - */ - getResolvedSignature(node: CallLikeExpression, candidatesOutArray?: Signature[], argumentCount?: number): Signature | undefined; - getResolvedSignatureForSignatureHelp(node: CallLikeExpression, candidatesOutArray?: Signature[], argumentCount?: number): Signature | undefined; - getExpandedParameters(sig: Signature): ReadonlyArray; - hasEffectiveRestParameter(sig: Signature): boolean; - getSignatureFromDeclaration(declaration: SignatureDeclaration): Signature | undefined; - isImplementationOfOverload(node: SignatureDeclaration): boolean | undefined; - isUndefinedSymbol(symbol: Symbol): boolean; - isArgumentsSymbol(symbol: Symbol): boolean; - isUnknownSymbol(symbol: Symbol): boolean; - getMergedSymbol(symbol: Symbol): Symbol; - getConstantValue(node: EnumMember | PropertyAccessExpression | ElementAccessExpression): string | number | undefined; - isValidPropertyAccess(node: PropertyAccessExpression | QualifiedName | ImportTypeNode, propertyName: string): boolean; - /** Exclude accesses to private properties or methods with a `this` parameter that `type` doesn't satisfy. */ - isValidPropertyAccessForCompletions(node: PropertyAccessExpression | ImportTypeNode | QualifiedName, type: Type, property: Symbol): boolean; - /** Follow all aliases to get the original symbol. */ - getAliasedSymbol(symbol: Symbol): Symbol; - /** Follow a *single* alias to get the immediately aliased symbol. */ - getImmediateAliasedSymbol(symbol: Symbol): Symbol | undefined; - getExportsOfModule(moduleSymbol: Symbol): Symbol[]; - /** Unlike `getExportsOfModule`, this includes properties of an `export =` value. */ - getExportsAndPropertiesOfModule(moduleSymbol: Symbol): Symbol[]; - getJsxIntrinsicTagNamesAt(location: Node): Symbol[]; - isOptionalParameter(node: ParameterDeclaration): boolean; - getAmbientModules(): Symbol[]; - tryGetMemberInModuleExports(memberName: string, moduleSymbol: Symbol): Symbol | undefined; - /** - * Unlike `tryGetMemberInModuleExports`, this includes properties of an `export =` value. - * Does *not* return properties of primitive types. - */ - tryGetMemberInModuleExportsAndProperties(memberName: string, moduleSymbol: Symbol): Symbol | undefined; - getApparentType(type: Type): Type; - getSuggestionForNonexistentProperty(name: Identifier | string, containingType: Type): string | undefined; - getSuggestionForNonexistentSymbol(location: Node, name: string, meaning: SymbolFlags): string | undefined; - getSuggestionForNonexistentExport(node: Identifier, target: Symbol): string | undefined; - getBaseConstraintOfType(type: Type): Type | undefined; - getDefaultFromTypeParameter(type: Type): Type | undefined; - getAnyType(): Type; - getStringType(): Type; - getNumberType(): Type; - getBooleanType(): Type; - getFalseType(fresh?: boolean): Type; - getTrueType(fresh?: boolean): Type; - getVoidType(): Type; - getUndefinedType(): Type; - getNullType(): Type; - getESSymbolType(): Type; - getNeverType(): Type; - getUnionType(types: Type[], subtypeReduction?: UnionReduction): Type; - createArrayType(elementType: Type): Type; - getElementTypeOfArrayType(arrayType: Type): Type | undefined; - createPromiseType(type: Type): Type; - createAnonymousType(symbol: Symbol, members: SymbolTable, callSignatures: Signature[], constructSignatures: Signature[], stringIndexInfo: IndexInfo | undefined, numberIndexInfo: IndexInfo | undefined): Type; - createSignature(declaration: SignatureDeclaration, typeParameters: TypeParameter[] | undefined, thisParameter: Symbol | undefined, parameters: Symbol[], resolvedReturnType: Type, typePredicate: TypePredicate | undefined, minArgumentCount: number, hasRestParameter: boolean, hasLiteralTypes: boolean): Signature; - createSymbol(flags: SymbolFlags, name: __String): TransientSymbol; - createIndexInfo(type: Type, isReadonly: boolean, declaration?: SignatureDeclaration): IndexInfo; - isSymbolAccessible(symbol: Symbol, enclosingDeclaration: Node | undefined, meaning: SymbolFlags, shouldComputeAliasToMarkVisible: boolean): SymbolAccessibilityResult; - tryFindAmbientModuleWithoutAugmentations(moduleName: string): Symbol | undefined; - getSymbolWalker(accept?: (symbol: Symbol) => boolean): SymbolWalker; - getDiagnostics(sourceFile?: SourceFile, cancellationToken?: CancellationToken): Diagnostic[]; - getGlobalDiagnostics(): Diagnostic[]; - getEmitResolver(sourceFile?: SourceFile, cancellationToken?: CancellationToken): EmitResolver; - getNodeCount(): number; - getIdentifierCount(): number; - getSymbolCount(): number; - getTypeCount(): number; - getRelationCacheSizes(): { - assignable: number; - identity: number; - subtype: number; - }; - isArrayType(type: Type): boolean; - isTupleType(type: Type): boolean; - isArrayLikeType(type: Type): boolean; - getObjectFlags(type: Type): ObjectFlags; - /** - * True if `contextualType` should not be considered for completions because - * e.g. it specifies `kind: "a"` and obj has `kind: "b"`. - */ - isTypeInvalidDueToUnionDiscriminant(contextualType: Type, obj: ObjectLiteralExpression | JsxAttributes): boolean; - /** - * For a union, will include a property if it's defined in *any* of the member types. - * So for `{ a } | { b }`, this will include both `a` and `b`. - * Does not include properties of primitive types. - */ - getAllPossiblePropertiesOfTypes(type: ReadonlyArray): Symbol[]; - resolveName(name: string, location: Node, meaning: SymbolFlags, excludeGlobals: boolean): Symbol | undefined; - getJsxNamespace(location?: Node): string; - /** - * Note that this will return undefined in the following case: - * // a.ts - * export namespace N { export class C { } } - * // b.ts - * <> - * Where `C` is the symbol we're looking for. - * This should be called in a loop climbing parents of the symbol, so we'll get `N`. - */ - getAccessibleSymbolChain(symbol: Symbol, enclosingDeclaration: Node | undefined, meaning: SymbolFlags, useOnlyExternalAliasing: boolean): Symbol[] | undefined; - getTypePredicateOfSignature(signature: Signature): TypePredicate | undefined; - /** - * An external module with an 'export =' declaration resolves to the target of the 'export =' declaration, - * and an external module with no 'export =' declaration resolves to the module itself. - */ - resolveExternalModuleSymbol(symbol: Symbol): Symbol; - /** @param node A location where we might consider accessing `this`. Not necessarily a ThisExpression. */ - tryGetThisTypeAt(node: Node, includeGlobalThis?: boolean): Type | undefined; - getTypeArgumentConstraint(node: TypeNode): Type | undefined; - /** - * Does *not* get *all* suggestion diagnostics, just the ones that were convenient to report in the checker. - * Others are added in computeSuggestionDiagnostics. - */ - getSuggestionDiagnostics(file: SourceFile, cancellationToken?: CancellationToken): ReadonlyArray; - /** - * Depending on the operation performed, it may be appropriate to throw away the checker - * if the cancellation token is triggered. Typically, if it is used for error checking - * and the operation is cancelled, then it should be discarded, otherwise it is safe to keep. - */ - runWithCancellationToken(token: CancellationToken, cb: (checker: TypeChecker) => T): T; - getLocalTypeParametersOfClassOrInterfaceOrTypeAlias(symbol: Symbol): ReadonlyArray | undefined; - } - export enum UnionReduction { - None = 0, - Literal = 1, - Subtype = 2 - } - export enum NodeBuilderFlags { - None = 0, - NoTruncation = 1, - WriteArrayAsGenericType = 2, - GenerateNamesForShadowedTypeParams = 4, - UseStructuralFallback = 8, - ForbidIndexedAccessSymbolReferences = 16, - WriteTypeArgumentsOfSignature = 32, - UseFullyQualifiedType = 64, - UseOnlyExternalAliasing = 128, - SuppressAnyReturnType = 256, - WriteTypeParametersInQualifiedName = 512, - MultilineObjectLiterals = 1024, - WriteClassExpressionAsTypeLiteral = 2048, - UseTypeOfFunction = 4096, - OmitParameterModifiers = 8192, - UseAliasDefinedOutsideCurrentScope = 16384, - AllowThisInObjectLiteral = 32768, - AllowQualifedNameInPlaceOfIdentifier = 65536, - AllowAnonymousIdentifier = 131072, - AllowEmptyUnionOrIntersection = 262144, - AllowEmptyTuple = 524288, - AllowUniqueESSymbolType = 1048576, - AllowEmptyIndexInfoType = 2097152, - AllowNodeModulesRelativePaths = 67108864, - DoNotIncludeSymbolChain = 134217728, - IgnoreErrors = 70221824, - InObjectTypeLiteral = 4194304, - InTypeAlias = 8388608, - InInitialEntityName = 16777216, - InReverseMappedType = 33554432 - } - export enum TypeFormatFlags { - None = 0, - NoTruncation = 1, - WriteArrayAsGenericType = 2, - UseStructuralFallback = 8, - WriteTypeArgumentsOfSignature = 32, - UseFullyQualifiedType = 64, - SuppressAnyReturnType = 256, - MultilineObjectLiterals = 1024, - WriteClassExpressionAsTypeLiteral = 2048, - UseTypeOfFunction = 4096, - OmitParameterModifiers = 8192, - UseAliasDefinedOutsideCurrentScope = 16384, - AllowUniqueESSymbolType = 1048576, - AddUndefined = 131072, - WriteArrowStyleSignature = 262144, - InArrayType = 524288, - InElementType = 2097152, - InFirstTypeArgument = 4194304, - InTypeAlias = 8388608, - /** @deprecated */ WriteOwnNameForAnyLike = 0, - NodeBuilderFlagsMask = 9469291 - } - export enum SymbolFormatFlags { - None = 0, - WriteTypeParametersOrArguments = 1, - UseOnlyExternalAliasing = 2, - AllowAnyNodeKind = 4, - UseAliasDefinedOutsideCurrentScope = 8, - DoNotIncludeSymbolChain = 16 - } - export interface SymbolWalker { - /** Note: Return values are not ordered. */ - walkType(root: Type): { - visitedTypes: ReadonlyArray; - visitedSymbols: ReadonlyArray; - }; - /** Note: Return values are not ordered. */ - walkSymbol(root: Symbol): { - visitedTypes: ReadonlyArray; - visitedSymbols: ReadonlyArray; - }; - } - interface SymbolWriter extends SymbolTracker { - writeKeyword(text: string): void; - writeOperator(text: string): void; - writePunctuation(text: string): void; - writeSpace(text: string): void; - writeStringLiteral(text: string): void; - writeParameter(text: string): void; - writeProperty(text: string): void; - writeSymbol(text: string, symbol: Symbol): void; - writeLine(): void; - increaseIndent(): void; - decreaseIndent(): void; - clear(): void; - } - export enum SymbolAccessibility { - Accessible = 0, - NotAccessible = 1, - CannotBeNamed = 2 - } - export enum SyntheticSymbolKind { - UnionOrIntersection = 0, - Spread = 1 - } - export enum TypePredicateKind { - This = 0, - Identifier = 1 - } - export interface TypePredicateBase { - kind: TypePredicateKind; - type: Type; - } - export interface ThisTypePredicate extends TypePredicateBase { - kind: TypePredicateKind.This; - } - export interface IdentifierTypePredicate extends TypePredicateBase { - kind: TypePredicateKind.Identifier; - parameterName: string; - parameterIndex: number; - } - export type TypePredicate = IdentifierTypePredicate | ThisTypePredicate; - export type AnyImportSyntax = ImportDeclaration | ImportEqualsDeclaration; - export type AnyImportOrReExport = AnyImportSyntax | ExportDeclaration; - export interface ValidImportTypeNode extends ImportTypeNode { - argument: LiteralTypeNode & { - literal: StringLiteral; - }; - } - export type AnyValidImportOrReExport = (ImportDeclaration | ExportDeclaration) & { - moduleSpecifier: StringLiteral; - } | ImportEqualsDeclaration & { - moduleReference: ExternalModuleReference & { - expression: StringLiteral; - }; - } | RequireOrImportCall | ValidImportTypeNode; - export type RequireOrImportCall = CallExpression & { - arguments: [StringLiteralLike]; - }; - export type LateVisibilityPaintedStatement = AnyImportSyntax | VariableStatement | ClassDeclaration | FunctionDeclaration | ModuleDeclaration | TypeAliasDeclaration | InterfaceDeclaration | EnumDeclaration; - export interface SymbolVisibilityResult { - accessibility: SymbolAccessibility; - aliasesToMakeVisible?: LateVisibilityPaintedStatement[]; - errorSymbolName?: string; - errorNode?: Node; - } - export interface SymbolAccessibilityResult extends SymbolVisibilityResult { - errorModuleName?: string; - } - export interface AllAccessorDeclarations { - firstAccessor: AccessorDeclaration; - secondAccessor: AccessorDeclaration | undefined; - getAccessor: GetAccessorDeclaration | undefined; - setAccessor: SetAccessorDeclaration | undefined; - } - /** Indicates how to serialize the name for a TypeReferenceNode when emitting decorator metadata */ - export enum TypeReferenceSerializationKind { - Unknown = 0, - TypeWithConstructSignatureAndValue = 1, - VoidNullableOrNeverType = 2, - NumberLikeType = 3, - BigIntLikeType = 4, - StringLikeType = 5, - BooleanType = 6, - ArrayLikeType = 7, - ESSymbolType = 8, - Promise = 9, - TypeWithCallSignature = 10, - ObjectType = 11 - } - export interface EmitResolver { - hasGlobalName(name: string): boolean; - getReferencedExportContainer(node: Identifier, prefixLocals?: boolean): SourceFile | ModuleDeclaration | EnumDeclaration | undefined; - getReferencedImportDeclaration(node: Identifier): Declaration | undefined; - getReferencedDeclarationWithCollidingName(node: Identifier): Declaration | undefined; - isDeclarationWithCollidingName(node: Declaration): boolean; - isValueAliasDeclaration(node: Node): boolean; - isReferencedAliasDeclaration(node: Node, checkChildren?: boolean): boolean; - isTopLevelValueImportEqualsWithEntityName(node: ImportEqualsDeclaration): boolean; - getNodeCheckFlags(node: Node): NodeCheckFlags; - isDeclarationVisible(node: Declaration | AnyImportSyntax): boolean; - isLateBound(node: Declaration): node is LateBoundDeclaration; - collectLinkedAliases(node: Identifier, setVisibility?: boolean): Node[] | undefined; - isImplementationOfOverload(node: FunctionLike): boolean | undefined; - isRequiredInitializedParameter(node: ParameterDeclaration): boolean; - isOptionalUninitializedParameterProperty(node: ParameterDeclaration): boolean; - isExpandoFunctionDeclaration(node: FunctionDeclaration): boolean; - getPropertiesOfContainerFunction(node: Declaration): Symbol[]; - createTypeOfDeclaration(declaration: AccessorDeclaration | VariableLikeDeclaration | PropertyAccessExpression, enclosingDeclaration: Node, flags: NodeBuilderFlags, tracker: SymbolTracker, addUndefined?: boolean): TypeNode | undefined; - createReturnTypeOfSignatureDeclaration(signatureDeclaration: SignatureDeclaration, enclosingDeclaration: Node, flags: NodeBuilderFlags, tracker: SymbolTracker): TypeNode | undefined; - createTypeOfExpression(expr: Expression, enclosingDeclaration: Node, flags: NodeBuilderFlags, tracker: SymbolTracker): TypeNode | undefined; - createLiteralConstValue(node: VariableDeclaration | PropertyDeclaration | PropertySignature | ParameterDeclaration, tracker: SymbolTracker): Expression; - isSymbolAccessible(symbol: Symbol, enclosingDeclaration: Node | undefined, meaning: SymbolFlags | undefined, shouldComputeAliasToMarkVisible: boolean): SymbolAccessibilityResult; - isEntityNameVisible(entityName: EntityNameOrEntityNameExpression, enclosingDeclaration: Node): SymbolVisibilityResult; - getConstantValue(node: EnumMember | PropertyAccessExpression | ElementAccessExpression): string | number | undefined; - getReferencedValueDeclaration(reference: Identifier): Declaration | undefined; - getTypeReferenceSerializationKind(typeName: EntityName, location?: Node): TypeReferenceSerializationKind; - isOptionalParameter(node: ParameterDeclaration): boolean; - moduleExportsSomeValue(moduleReferenceExpression: Expression): boolean; - isArgumentsLocalBinding(node: Identifier): boolean; - getExternalModuleFileFromDeclaration(declaration: ImportEqualsDeclaration | ImportDeclaration | ExportDeclaration | ModuleDeclaration | ImportTypeNode): SourceFile | undefined; - getTypeReferenceDirectivesForEntityName(name: EntityNameOrEntityNameExpression): string[] | undefined; - getTypeReferenceDirectivesForSymbol(symbol: Symbol, meaning?: SymbolFlags): string[] | undefined; - isLiteralConstDeclaration(node: VariableDeclaration | PropertyDeclaration | PropertySignature | ParameterDeclaration): boolean; - getJsxFactoryEntity(location?: Node): EntityName | undefined; - getAllAccessorDeclarations(declaration: AccessorDeclaration): AllAccessorDeclarations; - getSymbolOfExternalModuleSpecifier(node: StringLiteralLike): Symbol | undefined; - isBindingCapturedByNode(node: Node, decl: VariableDeclaration | BindingElement): boolean; - } - export enum SymbolFlags { - None = 0, - FunctionScopedVariable = 1, - BlockScopedVariable = 2, - Property = 4, - EnumMember = 8, - Function = 16, - Class = 32, - Interface = 64, - ConstEnum = 128, - RegularEnum = 256, - ValueModule = 512, - NamespaceModule = 1024, - TypeLiteral = 2048, - ObjectLiteral = 4096, - Method = 8192, - Constructor = 16384, - GetAccessor = 32768, - SetAccessor = 65536, - Signature = 131072, - TypeParameter = 262144, - TypeAlias = 524288, - ExportValue = 1048576, - Alias = 2097152, - Prototype = 4194304, - ExportStar = 8388608, - Optional = 16777216, - Transient = 33554432, - Assignment = 67108864, - ModuleExports = 134217728, - All = 67108863, - Enum = 384, - Variable = 3, - Value = 111551, - Type = 788968, - Namespace = 1920, - Module = 1536, - Accessor = 98304, - FunctionScopedVariableExcludes = 111550, - BlockScopedVariableExcludes = 111551, - ParameterExcludes = 111551, - PropertyExcludes = 0, - EnumMemberExcludes = 900095, - FunctionExcludes = 110991, - ClassExcludes = 899503, - InterfaceExcludes = 788872, - RegularEnumExcludes = 899327, - ConstEnumExcludes = 899967, - ValueModuleExcludes = 110735, - NamespaceModuleExcludes = 0, - MethodExcludes = 103359, - GetAccessorExcludes = 46015, - SetAccessorExcludes = 78783, - TypeParameterExcludes = 526824, - TypeAliasExcludes = 788968, - AliasExcludes = 2097152, - ModuleMember = 2623475, - ExportHasLocal = 944, - BlockScoped = 418, - PropertyOrAccessor = 98308, - ClassMember = 106500, - Classifiable = 2885600, - LateBindingContainer = 6240 - } - export interface Symbol { - flags: SymbolFlags; - escapedName: __String; - declarations: Declaration[]; - valueDeclaration: Declaration; - members?: SymbolTable; - exports?: SymbolTable; - globalExports?: SymbolTable; - id?: number; - mergeId?: number; - parent?: Symbol; - exportSymbol?: Symbol; - nameType?: Type; - constEnumOnlyModule?: boolean; - isReferenced?: SymbolFlags; - isReplaceableByMethod?: boolean; - isAssigned?: boolean; - } - export interface SymbolLinks { - immediateTarget?: Symbol; - target?: Symbol; - type?: Type; - uniqueESSymbolType?: Type; - declaredType?: Type; - resolvedJSDocType?: Type; - typeParameters?: TypeParameter[]; - outerTypeParameters?: TypeParameter[]; - instantiations?: Map; - inferredClassSymbol?: Map; - mapper?: TypeMapper; - referenced?: boolean; - containingType?: UnionOrIntersectionType; - leftSpread?: Symbol; - rightSpread?: Symbol; - syntheticOrigin?: Symbol; - isDiscriminantProperty?: boolean; - resolvedExports?: SymbolTable; - resolvedMembers?: SymbolTable; - exportsChecked?: boolean; - typeParametersChecked?: boolean; - isDeclarationWithCollidingName?: boolean; - bindingElement?: BindingElement; - exportsSomeValue?: boolean; - enumKind?: EnumKind; - originatingImport?: ImportDeclaration | ImportCall; - lateSymbol?: Symbol; - specifierCache?: Map; - extendedContainers?: Symbol[]; - extendedContainersByFile?: Map; - variances?: VarianceFlags[]; - deferralConstituents?: Type[]; - deferralParent?: Type; - } - export enum EnumKind { - Numeric = 0, - Literal = 1 - } - export enum CheckFlags { - Instantiated = 1, - SyntheticProperty = 2, - SyntheticMethod = 4, - Readonly = 8, - ReadPartial = 16, - WritePartial = 32, - HasNonUniformType = 64, - HasLiteralType = 128, - ContainsPublic = 256, - ContainsProtected = 512, - ContainsPrivate = 1024, - ContainsStatic = 2048, - Late = 4096, - ReverseMapped = 8192, - OptionalParameter = 16384, - RestParameter = 32768, - DeferredType = 65536, - Synthetic = 6, - Discriminant = 192, - Partial = 48 - } - export interface TransientSymbol extends Symbol, SymbolLinks { - checkFlags: CheckFlags; - } - export interface ReverseMappedSymbol extends TransientSymbol { - propertyType: Type; - mappedType: MappedType; - constraintType: IndexType; - } - export enum InternalSymbolName { - Call = "__call", - Constructor = "__constructor", - New = "__new", - Index = "__index", - ExportStar = "__export", - Global = "__global", - Missing = "__missing", - Type = "__type", - Object = "__object", - JSXAttributes = "__jsxAttributes", - Class = "__class", - Function = "__function", - Computed = "__computed", - Resolving = "__resolving__", - ExportEquals = "export=", - Default = "default", - This = "this" - } - /** - * This represents a string whose leading underscore have been escaped by adding extra leading underscores. - * The shape of this brand is rather unique compared to others we've used. - * Instead of just an intersection of a string and an object, it is that union-ed - * with an intersection of void and an object. This makes it wholly incompatible - * with a normal string (which is good, it cannot be misused on assignment or on usage), - * while still being comparable with a normal string via === (also good) and castable from a string. - */ - export type __String = (string & { - __escapedIdentifier: void; - }) | (void & { - __escapedIdentifier: void; - }) | InternalSymbolName; - /** ReadonlyMap where keys are `__String`s. */ - export interface ReadonlyUnderscoreEscapedMap { - get(key: __String): T | undefined; - has(key: __String): boolean; - forEach(action: (value: T, key: __String) => void): void; - readonly size: number; - keys(): Iterator<__String>; - values(): Iterator; - entries(): Iterator<[__String, T]>; - } - /** Map where keys are `__String`s. */ - export interface UnderscoreEscapedMap extends ReadonlyUnderscoreEscapedMap { - set(key: __String, value: T): this; - delete(key: __String): boolean; - clear(): void; - } - /** SymbolTable based on ES6 Map interface. */ - export type SymbolTable = UnderscoreEscapedMap; - /** Used to track a `declare module "foo*"`-like declaration. */ - export interface PatternAmbientModule { - pattern: Pattern; - symbol: Symbol; - } - export enum NodeCheckFlags { - TypeChecked = 1, - LexicalThis = 2, - CaptureThis = 4, - CaptureNewTarget = 8, - SuperInstance = 256, - SuperStatic = 512, - ContextChecked = 1024, - AsyncMethodWithSuper = 2048, - AsyncMethodWithSuperBinding = 4096, - CaptureArguments = 8192, - EnumValuesComputed = 16384, - LexicalModuleMergesWithClass = 32768, - LoopWithCapturedBlockScopedBinding = 65536, - ContainsCapturedBlockScopeBinding = 131072, - CapturedBlockScopedBinding = 262144, - BlockScopedBindingInLoop = 524288, - ClassWithBodyScopedClassBinding = 1048576, - BodyScopedClassBinding = 2097152, - NeedsLoopOutParameter = 4194304, - AssignmentsMarked = 8388608, - ClassWithConstructorReference = 16777216, - ConstructorReferenceInClass = 33554432 - } - export interface NodeLinks { - flags: NodeCheckFlags; - resolvedType?: Type; - resolvedEnumType?: Type; - resolvedSignature?: Signature; - resolvedSymbol?: Symbol; - resolvedIndexInfo?: IndexInfo; - maybeTypePredicate?: boolean; - enumMemberValue?: string | number; - isVisible?: boolean; - containsArgumentsReference?: boolean; - hasReportedStatementInAmbientContext?: boolean; - jsxFlags: JsxFlags; - resolvedJsxElementAttributesType?: Type; - resolvedJsxElementAllAttributesType?: Type; - hasSuperCall?: boolean; - superCall?: SuperCall; - switchTypes?: Type[]; - jsxNamespace?: Symbol | false; - contextFreeType?: Type; - deferredNodes?: Map; - capturedBlockScopeBindings?: Symbol[]; - } - export enum TypeFlags { - Any = 1, - Unknown = 2, - String = 4, - Number = 8, - Boolean = 16, - Enum = 32, - BigInt = 64, - StringLiteral = 128, - NumberLiteral = 256, - BooleanLiteral = 512, - EnumLiteral = 1024, - BigIntLiteral = 2048, - ESSymbol = 4096, - UniqueESSymbol = 8192, - Void = 16384, - Undefined = 32768, - Null = 65536, - Never = 131072, - TypeParameter = 262144, - Object = 524288, - Union = 1048576, - Intersection = 2097152, - Index = 4194304, - IndexedAccess = 8388608, - Conditional = 16777216, - Substitution = 33554432, - NonPrimitive = 67108864, - AnyOrUnknown = 3, - Nullable = 98304, - Literal = 2944, - Unit = 109440, - StringOrNumberLiteral = 384, - StringOrNumberLiteralOrUnique = 8576, - DefinitelyFalsy = 117632, - PossiblyFalsy = 117724, - Intrinsic = 67359327, - Primitive = 131068, - StringLike = 132, - NumberLike = 296, - BigIntLike = 2112, - BooleanLike = 528, - EnumLike = 1056, - ESSymbolLike = 12288, - VoidLike = 49152, - DisjointDomains = 67238908, - UnionOrIntersection = 3145728, - StructuredType = 3670016, - TypeVariable = 8650752, - InstantiableNonPrimitive = 58982400, - InstantiablePrimitive = 4194304, - Instantiable = 63176704, - StructuredOrInstantiable = 66846720, - ObjectFlagsType = 3899392, - Simplifiable = 25165824, - Narrowable = 133970943, - NotUnionOrUnit = 67637251, - NotPrimitiveUnion = 66994211, - IncludesMask = 68943871, - IncludesStructuredOrInstantiable = 262144, - IncludesNonWideningType = 2097152, - IncludesWildcard = 4194304, - IncludesEmptyObject = 8388608, - GenericMappedType = 131072 - } - export type DestructuringPattern = BindingPattern | ObjectLiteralExpression | ArrayLiteralExpression; - export interface Type { - flags: TypeFlags; - id: number; - checker: TypeChecker; - symbol: Symbol; - pattern?: DestructuringPattern; - aliasSymbol?: Symbol; - aliasTypeArguments?: ReadonlyArray; - aliasTypeArgumentsContainsMarker?: boolean; - permissiveInstantiation?: Type; - restrictiveInstantiation?: Type; - immediateBaseConstraint?: Type; - widened?: Type; - } - export interface IntrinsicType extends Type { - intrinsicName: string; - objectFlags: ObjectFlags; - } - export interface NullableType extends IntrinsicType { - objectFlags: ObjectFlags; - } - export interface FreshableIntrinsicType extends IntrinsicType { - freshType: IntrinsicType; - regularType: IntrinsicType; - } - export type FreshableType = LiteralType | FreshableIntrinsicType; - export interface LiteralType extends Type { - value: string | number | PseudoBigInt; - freshType: LiteralType; - regularType: LiteralType; - } - export interface UniqueESSymbolType extends Type { - symbol: Symbol; - escapedName: __String; - } - export interface StringLiteralType extends LiteralType { - value: string; - } - export interface NumberLiteralType extends LiteralType { - value: number; - } - export interface BigIntLiteralType extends LiteralType { - value: PseudoBigInt; - } - export interface EnumType extends Type { - } - export enum ObjectFlags { - Class = 1, - Interface = 2, - Reference = 4, - Tuple = 8, - Anonymous = 16, - Mapped = 32, - Instantiated = 64, - ObjectLiteral = 128, - EvolvingArray = 256, - ObjectLiteralPatternWithComputedProperties = 512, - ContainsSpread = 1024, - ReverseMapped = 2048, - JsxAttributes = 4096, - MarkerType = 8192, - JSLiteral = 16384, - FreshLiteral = 32768, - ArrayLiteral = 65536, - PrimitiveUnion = 131072, - ContainsWideningType = 262144, - ContainsObjectOrArrayLiteral = 524288, - NonInferrableType = 1048576, - ClassOrInterface = 3, - RequiresWidening = 786432, - PropagatingFlags = 1835008 - } - export type ObjectFlagsType = NullableType | ObjectType | UnionType | IntersectionType; - export interface ObjectType extends Type { - objectFlags: ObjectFlags; - members?: SymbolTable; - properties?: Symbol[]; - callSignatures?: ReadonlyArray; - constructSignatures?: ReadonlyArray; - stringIndexInfo?: IndexInfo; - numberIndexInfo?: IndexInfo; - } - /** Class and interface types (ObjectFlags.Class and ObjectFlags.Interface). */ - export interface InterfaceType extends ObjectType { - typeParameters: TypeParameter[] | undefined; - outerTypeParameters: TypeParameter[] | undefined; - localTypeParameters: TypeParameter[] | undefined; - thisType: TypeParameter | undefined; - resolvedBaseConstructorType?: Type; - resolvedBaseTypes: BaseType[]; - } - export type BaseType = ObjectType | IntersectionType; - export interface InterfaceTypeWithDeclaredMembers extends InterfaceType { - declaredProperties: Symbol[]; - declaredCallSignatures: Signature[]; - declaredConstructSignatures: Signature[]; - declaredStringIndexInfo?: IndexInfo; - declaredNumberIndexInfo?: IndexInfo; - } - /** - * Type references (ObjectFlags.Reference). When a class or interface has type parameters or - * a "this" type, references to the class or interface are made using type references. The - * typeArguments property specifies the types to substitute for the type parameters of the - * class or interface and optionally includes an extra element that specifies the type to - * substitute for "this" in the resulting instantiation. When no extra argument is present, - * the type reference itself is substituted for "this". The typeArguments property is undefined - * if the class or interface has no type parameters and the reference isn't specifying an - * explicit "this" argument. - */ - export interface TypeReference extends ObjectType { - target: GenericType; - typeArguments?: ReadonlyArray; - literalType?: TypeReference; - } - export enum VarianceFlags { - Invariant = 0, - Covariant = 1, - Contravariant = 2, - Bivariant = 3, - Independent = 4, - VarianceMask = 7, - Unmeasurable = 8, - Unreliable = 16, - AllowsStructuralFallback = 24 - } - export interface GenericType extends InterfaceType, TypeReference { - instantiations: Map; - variances?: VarianceFlags[]; - } - export interface TupleType extends GenericType { - minLength: number; - hasRestElement: boolean; - readonly: boolean; - associatedNames?: __String[]; - } - export interface TupleTypeReference extends TypeReference { - target: TupleType; - } - export interface UnionOrIntersectionType extends Type { - types: Type[]; - objectFlags: ObjectFlags; - propertyCache: SymbolTable; - resolvedProperties: Symbol[]; - resolvedIndexType: IndexType; - resolvedStringIndexType: IndexType; - resolvedBaseConstraint: Type; - couldContainTypeVariables: boolean; - } - export interface UnionType extends UnionOrIntersectionType { - possiblePropertyCache?: SymbolTable; - } - export interface IntersectionType extends UnionOrIntersectionType { - resolvedApparentType: Type; - } - export type StructuredType = ObjectType | UnionType | IntersectionType; - export interface AnonymousType extends ObjectType { - target?: AnonymousType; - mapper?: TypeMapper; - } - export interface MappedType extends AnonymousType { - declaration: MappedTypeNode; - typeParameter?: TypeParameter; - constraintType?: Type; - templateType?: Type; - modifiersType?: Type; - resolvedApparentType?: Type; - } - export interface EvolvingArrayType extends ObjectType { - elementType: Type; - finalArrayType?: Type; - } - export interface ReverseMappedType extends ObjectType { - source: Type; - mappedType: MappedType; - constraintType: IndexType; - } - export interface ResolvedType extends ObjectType, UnionOrIntersectionType { - members: SymbolTable; - properties: Symbol[]; - callSignatures: ReadonlyArray; - constructSignatures: ReadonlyArray; - } - export interface FreshObjectLiteralType extends ResolvedType { - regularType: ResolvedType; - } - export interface IterationTypes { - readonly yieldType: Type; - readonly returnType: Type; - readonly nextType: Type; - } - export interface IterableOrIteratorType extends ObjectType, UnionType { - iterationTypesOfGeneratorReturnType?: IterationTypes; - iterationTypesOfAsyncGeneratorReturnType?: IterationTypes; - iterationTypesOfIterable?: IterationTypes; - iterationTypesOfIterator?: IterationTypes; - iterationTypesOfAsyncIterable?: IterationTypes; - iterationTypesOfAsyncIterator?: IterationTypes; - iterationTypesOfIteratorResult?: IterationTypes; - } - export interface PromiseOrAwaitableType extends ObjectType, UnionType { - promiseTypeOfPromiseConstructor?: Type; - promisedTypeOfPromise?: Type; - awaitedTypeOfType?: Type; - } - export interface SyntheticDefaultModuleType extends Type { - syntheticType?: Type; - } - export interface InstantiableType extends Type { - resolvedBaseConstraint?: Type; - resolvedIndexType?: IndexType; - resolvedStringIndexType?: IndexType; - } - export interface TypeParameter extends InstantiableType { - /** Retrieve using getConstraintFromTypeParameter */ - constraint?: Type; - default?: Type; - target?: TypeParameter; - mapper?: TypeMapper; - isThisType?: boolean; - resolvedDefaultType?: Type; - } - export interface IndexedAccessType extends InstantiableType { - objectType: Type; - indexType: Type; - constraint?: Type; - simplifiedForReading?: Type; - simplifiedForWriting?: Type; - } - export type TypeVariable = TypeParameter | IndexedAccessType; - export interface IndexType extends InstantiableType { - type: InstantiableType | UnionOrIntersectionType; - stringsOnly: boolean; - } - export interface ConditionalRoot { - node: ConditionalTypeNode; - checkType: Type; - extendsType: Type; - trueType: Type; - falseType: Type; - isDistributive: boolean; - inferTypeParameters?: TypeParameter[]; - outerTypeParameters?: TypeParameter[]; - instantiations?: Map; - aliasSymbol?: Symbol; - aliasTypeArguments?: Type[]; - } - export interface ConditionalType extends InstantiableType { - root: ConditionalRoot; - checkType: Type; - extendsType: Type; - resolvedTrueType: Type; - resolvedFalseType: Type; - resolvedInferredTrueType?: Type; - resolvedDefaultConstraint?: Type; - mapper?: TypeMapper; - combinedMapper?: TypeMapper; - } - export interface SubstitutionType extends InstantiableType { - typeVariable: TypeVariable; - substitute: Type; - } - export enum JsxReferenceKind { - Component = 0, - Function = 1, - Mixed = 2 - } - export enum SignatureKind { - Call = 0, - Construct = 1 - } - export interface Signature { - declaration?: SignatureDeclaration | JSDocSignature; - typeParameters?: ReadonlyArray; - parameters: ReadonlyArray; - thisParameter?: Symbol; - resolvedReturnType?: Type; - resolvedTypePredicate?: TypePredicate; - minArgumentCount: number; - hasRestParameter: boolean; - hasLiteralTypes: boolean; - target?: Signature; - mapper?: TypeMapper; - unionSignatures?: Signature[]; - erasedSignatureCache?: Signature; - canonicalSignatureCache?: Signature; - isolatedSignatureType?: ObjectType; - instantiations?: Map; - } - export enum IndexKind { - String = 0, - Number = 1 - } - export interface IndexInfo { - type: Type; - isReadonly: boolean; - declaration?: IndexSignatureDeclaration; - } - export type TypeMapper = (t: TypeParameter) => Type; - export enum InferencePriority { - NakedTypeVariable = 1, - HomomorphicMappedType = 2, - PartialHomomorphicMappedType = 4, - MappedTypeConstraint = 8, - ReturnType = 16, - LiteralKeyof = 32, - NoConstraints = 64, - AlwaysStrict = 128, - MaxValue = 256, - PriorityImpliesCombination = 56, - Circularity = -1 - } - export interface InferenceInfo { - typeParameter: TypeParameter; - candidates: Type[] | undefined; - contraCandidates: Type[] | undefined; - inferredType?: Type; - priority?: InferencePriority; - topLevel: boolean; - isFixed: boolean; - } - export enum InferenceFlags { - None = 0, - NoDefault = 1, - AnyDefault = 2, - SkippedGenericFunction = 4 - } - /** - * Ternary values are defined such that - * x & y is False if either x or y is False. - * x & y is Maybe if either x or y is Maybe, but neither x or y is False. - * x & y is True if both x and y are True. - * x | y is False if both x and y are False. - * x | y is Maybe if either x or y is Maybe, but neither x or y is True. - * x | y is True if either x or y is True. - */ - export enum Ternary { - False = 0, - Maybe = 1, - True = -1 - } - export type TypeComparer = (s: Type, t: Type, reportErrors?: boolean) => Ternary; - export interface InferenceContext { - inferences: InferenceInfo[]; - signature?: Signature; - flags: InferenceFlags; - compareTypes: TypeComparer; - mapper: TypeMapper; - nonFixingMapper: TypeMapper; - returnMapper?: TypeMapper; - inferredTypeParameters?: ReadonlyArray; - } - export interface WideningContext { - parent?: WideningContext; - propertyName?: __String; - siblings?: Type[]; - resolvedProperties?: Symbol[]; - } - export enum AssignmentDeclarationKind { - None = 0, - ExportsProperty = 1, - ModuleExports = 2, - PrototypeProperty = 3, - ThisProperty = 4, - Property = 5, - Prototype = 6, - ObjectDefinePropertyValue = 7, - ObjectDefinePropertyExports = 8, - ObjectDefinePrototypeProperty = 9 - } - /** @deprecated Use FileExtensionInfo instead. */ - export type JsFileExtensionInfo = FileExtensionInfo; - export interface FileExtensionInfo { - extension: string; - isMixedContent: boolean; - scriptKind?: ScriptKind; - } - export interface DiagnosticMessage { - key: string; - category: DiagnosticCategory; - code: number; - message: string; - reportsUnnecessary?: {}; - } - /** - * A linked list of formatted diagnostic messages to be used as part of a multiline message. - * It is built from the bottom up, leaving the head to be the "main" diagnostic. - * While it seems that DiagnosticMessageChain is structurally similar to DiagnosticMessage, - * the difference is that messages are all preformatted in DMC. - */ - export interface DiagnosticMessageChain { - messageText: string; - category: DiagnosticCategory; - code: number; - next?: DiagnosticMessageChain[]; - } - export interface Diagnostic extends DiagnosticRelatedInformation { - /** May store more in future. For now, this will simply be `true` to indicate when a diagnostic is an unused-identifier diagnostic. */ - reportsUnnecessary?: {}; - source?: string; - relatedInformation?: DiagnosticRelatedInformation[]; - } - export interface DiagnosticRelatedInformation { - category: DiagnosticCategory; - code: number; - file: SourceFile | undefined; - start: number | undefined; - length: number | undefined; - messageText: string | DiagnosticMessageChain; - } - export interface DiagnosticWithLocation extends Diagnostic { - file: SourceFile; - start: number; - length: number; - } - export enum DiagnosticCategory { - Warning = 0, - Error = 1, - Suggestion = 2, - Message = 3 - } - export function diagnosticCategoryName(d: { - category: DiagnosticCategory; - }, lowerCase?: boolean): string; - export enum ModuleResolutionKind { - Classic = 1, - NodeJs = 2 - } - export interface PluginImport { - name: string; - } - export interface ProjectReference { - /** A normalized path on disk */ - path: string; - /** The path as the user originally wrote it */ - originalPath?: string; - /** True if the output of this reference should be prepended to the output of this project. Only valid for --outFile compilations */ - prepend?: boolean; - /** True if it is intended that this reference form a circularity */ - circular?: boolean; - } - export type CompilerOptionsValue = string | number | boolean | (string | number)[] | string[] | MapLike | PluginImport[] | ProjectReference[] | null | undefined; - export interface CompilerOptions { - all?: boolean; - allowJs?: boolean; - allowNonTsExtensions?: boolean; - allowSyntheticDefaultImports?: boolean; - allowUmdGlobalAccess?: boolean; - allowUnreachableCode?: boolean; - allowUnusedLabels?: boolean; - alwaysStrict?: boolean; - baseUrl?: string; - /** An error if set - this should only go through the -b pipeline and not actually be observed */ - build?: boolean; - charset?: string; - checkJs?: boolean; - configFilePath?: string; - /** configFile is set as non enumerable property so as to avoid checking of json source files */ - readonly configFile?: TsConfigSourceFile; - declaration?: boolean; - declarationMap?: boolean; - emitDeclarationOnly?: boolean; - declarationDir?: string; - diagnostics?: boolean; - extendedDiagnostics?: boolean; - disableSizeLimit?: boolean; - downlevelIteration?: boolean; - emitBOM?: boolean; - emitDecoratorMetadata?: boolean; - experimentalDecorators?: boolean; - forceConsistentCasingInFileNames?: boolean; - help?: boolean; - importHelpers?: boolean; - init?: boolean; - inlineSourceMap?: boolean; - inlineSources?: boolean; - isolatedModules?: boolean; - jsx?: JsxEmit; - keyofStringsOnly?: boolean; - lib?: string[]; - listEmittedFiles?: boolean; - listFiles?: boolean; - locale?: string; - mapRoot?: string; - maxNodeModuleJsDepth?: number; - module?: ModuleKind; - moduleResolution?: ModuleResolutionKind; - newLine?: NewLineKind; - noEmit?: boolean; - noEmitForJsFiles?: boolean; - noEmitHelpers?: boolean; - noEmitOnError?: boolean; - noErrorTruncation?: boolean; - noFallthroughCasesInSwitch?: boolean; - noImplicitAny?: boolean; - noImplicitReturns?: boolean; - noImplicitThis?: boolean; - noStrictGenericChecks?: boolean; - noUnusedLocals?: boolean; - noUnusedParameters?: boolean; - noImplicitUseStrict?: boolean; - noLib?: boolean; - noResolve?: boolean; - out?: string; - outDir?: string; - outFile?: string; - paths?: MapLike; - plugins?: PluginImport[]; - preserveConstEnums?: boolean; - preserveSymlinks?: boolean; - preserveWatchOutput?: boolean; - project?: string; - pretty?: boolean; - reactNamespace?: string; - jsxFactory?: string; - composite?: boolean; - incremental?: boolean; - tsBuildInfoFile?: string; - removeComments?: boolean; - rootDir?: string; - rootDirs?: string[]; - skipLibCheck?: boolean; - skipDefaultLibCheck?: boolean; - sourceMap?: boolean; - sourceRoot?: string; - strict?: boolean; - strictFunctionTypes?: boolean; - strictBindCallApply?: boolean; - strictNullChecks?: boolean; - strictPropertyInitialization?: boolean; - stripInternal?: boolean; - suppressExcessPropertyErrors?: boolean; - suppressImplicitAnyIndexErrors?: boolean; - suppressOutputPathCheck?: boolean; - target?: ScriptTarget; - traceResolution?: boolean; - resolveJsonModule?: boolean; - types?: string[]; - /** Paths used to compute primary types search locations */ - typeRoots?: string[]; - version?: boolean; - watch?: boolean; - esModuleInterop?: boolean; - showConfig?: boolean; - [option: string]: CompilerOptionsValue | TsConfigSourceFile | undefined; - } - export interface TypeAcquisition { - enableAutoDiscovery?: boolean; - enable?: boolean; - include?: string[]; - exclude?: string[]; - [option: string]: string[] | boolean | undefined; - } - export enum ModuleKind { - None = 0, - CommonJS = 1, - AMD = 2, - UMD = 3, - System = 4, - ES2015 = 5, - ESNext = 99 - } - export enum JsxEmit { - None = 0, - Preserve = 1, - React = 2, - ReactNative = 3 - } - export enum NewLineKind { - CarriageReturnLineFeed = 0, - LineFeed = 1 - } - export interface LineAndCharacter { - /** 0-based. */ - line: number; - character: number; - } - export enum ScriptKind { - Unknown = 0, - JS = 1, - JSX = 2, - TS = 3, - TSX = 4, - External = 5, - JSON = 6, - /** - * Used on extensions that doesn't define the ScriptKind but the content defines it. - * Deferred extensions are going to be included in all project contexts. - */ - Deferred = 7 - } - export enum ScriptTarget { - ES3 = 0, - ES5 = 1, - ES2015 = 2, - ES2016 = 3, - ES2017 = 4, - ES2018 = 5, - ES2019 = 6, - ES2020 = 7, - ESNext = 99, - JSON = 100, - Latest = 99 - } - export enum LanguageVariant { - Standard = 0, - JSX = 1 - } - /** Either a parsed command line or a parsed tsconfig.json */ - export interface ParsedCommandLine { - options: CompilerOptions; - typeAcquisition?: TypeAcquisition; - fileNames: string[]; - projectReferences?: ReadonlyArray; - raw?: any; - errors: Diagnostic[]; - wildcardDirectories?: MapLike; - compileOnSave?: boolean; - configFileSpecs?: ConfigFileSpecs; - } - export enum WatchDirectoryFlags { - None = 0, - Recursive = 1 - } - export interface ConfigFileSpecs { - filesSpecs: ReadonlyArray | undefined; - /** - * Present to report errors (user specified specs), validatedIncludeSpecs are used for file name matching - */ - includeSpecs?: ReadonlyArray; - /** - * Present to report errors (user specified specs), validatedExcludeSpecs are used for file name matching - */ - excludeSpecs?: ReadonlyArray; - validatedIncludeSpecs?: ReadonlyArray; - validatedExcludeSpecs?: ReadonlyArray; - wildcardDirectories: MapLike; - } - export interface ExpandResult { - fileNames: string[]; - wildcardDirectories: MapLike; - spec: ConfigFileSpecs; - } - export interface CreateProgramOptions { - rootNames: ReadonlyArray; - options: CompilerOptions; - projectReferences?: ReadonlyArray; - host?: CompilerHost; - oldProgram?: Program; - configFileParsingDiagnostics?: ReadonlyArray; - } - export interface CommandLineOptionBase { - name: string; - type: "string" | "number" | "boolean" | "object" | "list" | Map; - isFilePath?: boolean; - shortName?: string; - description?: DiagnosticMessage; - paramType?: DiagnosticMessage; - isTSConfigOnly?: boolean; - isCommandLineOnly?: boolean; - showInSimplifiedHelpView?: boolean; - category?: DiagnosticMessage; - strictFlag?: true; - affectsSourceFile?: true; - affectsModuleResolution?: true; - affectsBindDiagnostics?: true; - affectsSemanticDiagnostics?: true; - affectsEmit?: true; - } - export interface CommandLineOptionOfPrimitiveType extends CommandLineOptionBase { - type: "string" | "number" | "boolean"; - } - export interface CommandLineOptionOfCustomType extends CommandLineOptionBase { - type: Map; - } - export interface TsConfigOnlyOption extends CommandLineOptionBase { - type: "object"; - elementOptions?: Map; - extraKeyDiagnosticMessage?: DiagnosticMessage; - } - export interface CommandLineOptionOfListType extends CommandLineOptionBase { - type: "list"; - element: CommandLineOptionOfCustomType | CommandLineOptionOfPrimitiveType | TsConfigOnlyOption; - } - export type CommandLineOption = CommandLineOptionOfCustomType | CommandLineOptionOfPrimitiveType | TsConfigOnlyOption | CommandLineOptionOfListType; - export enum CharacterCodes { - nullCharacter = 0, - maxAsciiCharacter = 127, - lineFeed = 10, - carriageReturn = 13, - lineSeparator = 8232, - paragraphSeparator = 8233, - nextLine = 133, - space = 32, - nonBreakingSpace = 160, - enQuad = 8192, - emQuad = 8193, - enSpace = 8194, - emSpace = 8195, - threePerEmSpace = 8196, - fourPerEmSpace = 8197, - sixPerEmSpace = 8198, - figureSpace = 8199, - punctuationSpace = 8200, - thinSpace = 8201, - hairSpace = 8202, - zeroWidthSpace = 8203, - narrowNoBreakSpace = 8239, - ideographicSpace = 12288, - mathematicalSpace = 8287, - ogham = 5760, - _ = 95, - $ = 36, - _0 = 48, - _1 = 49, - _2 = 50, - _3 = 51, - _4 = 52, - _5 = 53, - _6 = 54, - _7 = 55, - _8 = 56, - _9 = 57, - a = 97, - b = 98, - c = 99, - d = 100, - e = 101, - f = 102, - g = 103, - h = 104, - i = 105, - j = 106, - k = 107, - l = 108, - m = 109, - n = 110, - o = 111, - p = 112, - q = 113, - r = 114, - s = 115, - t = 116, - u = 117, - v = 118, - w = 119, - x = 120, - y = 121, - z = 122, - A = 65, - B = 66, - C = 67, - D = 68, - E = 69, - F = 70, - G = 71, - H = 72, - I = 73, - J = 74, - K = 75, - L = 76, - M = 77, - N = 78, - O = 79, - P = 80, - Q = 81, - R = 82, - S = 83, - T = 84, - U = 85, - V = 86, - W = 87, - X = 88, - Y = 89, - Z = 90, - ampersand = 38, - asterisk = 42, - at = 64, - backslash = 92, - backtick = 96, - bar = 124, - caret = 94, - closeBrace = 125, - closeBracket = 93, - closeParen = 41, - colon = 58, - comma = 44, - dot = 46, - doubleQuote = 34, - equals = 61, - exclamation = 33, - greaterThan = 62, - hash = 35, - lessThan = 60, - minus = 45, - openBrace = 123, - openBracket = 91, - openParen = 40, - percent = 37, - plus = 43, - question = 63, - semicolon = 59, - singleQuote = 39, - slash = 47, - tilde = 126, - backspace = 8, - formFeed = 12, - byteOrderMark = 65279, - tab = 9, - verticalTab = 11 - } - export interface ModuleResolutionHost { - fileExists(fileName: string): boolean; - readFile(fileName: string): string | undefined; - trace?(s: string): void; - directoryExists?(directoryName: string): boolean; - /** - * Resolve a symbolic link. - * @see https://nodejs.org/api/fs.html#fs_fs_realpathsync_path_options - */ - realpath?(path: string): string; - getCurrentDirectory?(): string; - getDirectories?(path: string): string[]; - } - /** - * Represents the result of module resolution. - * Module resolution will pick up tsx/jsx/js files even if '--jsx' and '--allowJs' are turned off. - * The Program will then filter results based on these flags. - * - * Prefer to return a `ResolvedModuleFull` so that the file type does not have to be inferred. - */ - export interface ResolvedModule { - /** Path of the file the module was resolved to. */ - resolvedFileName: string; - /** True if `resolvedFileName` comes from `node_modules`. */ - isExternalLibraryImport?: boolean; - } - /** - * ResolvedModule with an explicitly provided `extension` property. - * Prefer this over `ResolvedModule`. - * If changing this, remember to change `moduleResolutionIsEqualTo`. - */ - export interface ResolvedModuleFull extends ResolvedModule { - readonly originalPath?: string; - /** - * Extension of resolvedFileName. This must match what's at the end of resolvedFileName. - * This is optional for backwards-compatibility, but will be added if not provided. - */ - extension: Extension; - packageId?: PackageId; - } - /** - * Unique identifier with a package name and version. - * If changing this, remember to change `packageIdIsEqual`. - */ - export interface PackageId { - /** - * Name of the package. - * Should not include `@types`. - * If accessing a non-index file, this should include its name e.g. "foo/bar". - */ - name: string; - /** - * Name of a submodule within this package. - * May be "". - */ - subModuleName: string; - /** Version of the package, e.g. "1.2.3" */ - version: string; - } - export enum Extension { - Ts = ".ts", - Tsx = ".tsx", - Dts = ".d.ts", - Js = ".js", - Jsx = ".jsx", - Json = ".json", - TsBuildInfo = ".tsbuildinfo" - } - export interface ResolvedModuleWithFailedLookupLocations { - readonly resolvedModule: ResolvedModuleFull | undefined; - readonly failedLookupLocations: ReadonlyArray; - } - export interface ResolvedTypeReferenceDirective { - primary: boolean; - resolvedFileName: string | undefined; - packageId?: PackageId; - /** True if `resolvedFileName` comes from `node_modules`. */ - isExternalLibraryImport?: boolean; - } - export interface ResolvedTypeReferenceDirectiveWithFailedLookupLocations { - readonly resolvedTypeReferenceDirective: ResolvedTypeReferenceDirective | undefined; - readonly failedLookupLocations: ReadonlyArray; - } - export type HasInvalidatedResolution = (sourceFile: Path) => boolean; - export interface CompilerHost extends ModuleResolutionHost { - getSourceFile(fileName: string, languageVersion: ScriptTarget, onError?: (message: string) => void, shouldCreateNewSourceFile?: boolean): SourceFile | undefined; - getSourceFileByPath?(fileName: string, path: Path, languageVersion: ScriptTarget, onError?: (message: string) => void, shouldCreateNewSourceFile?: boolean): SourceFile | undefined; - getCancellationToken?(): CancellationToken; - getDefaultLibFileName(options: CompilerOptions): string; - getDefaultLibLocation?(): string; - writeFile: WriteFileCallback; - getCurrentDirectory(): string; - getCanonicalFileName(fileName: string): string; - useCaseSensitiveFileNames(): boolean; - getNewLine(): string; - readDirectory?(rootDir: string, extensions: ReadonlyArray, excludes: ReadonlyArray | undefined, includes: ReadonlyArray, depth?: number): string[]; - resolveModuleNames?(moduleNames: string[], containingFile: string, reusedNames: string[] | undefined, redirectedReference: ResolvedProjectReference | undefined, options: CompilerOptions): (ResolvedModule | undefined)[]; - /** - * This method is a companion for 'resolveModuleNames' and is used to resolve 'types' references to actual type declaration files - */ - resolveTypeReferenceDirectives?(typeReferenceDirectiveNames: string[], containingFile: string, redirectedReference: ResolvedProjectReference | undefined, options: CompilerOptions): (ResolvedTypeReferenceDirective | undefined)[]; - getEnvironmentVariable?(name: string): string | undefined; - onReleaseOldSourceFile?(oldSourceFile: SourceFile, oldOptions: CompilerOptions, hasSourceFileByPath: boolean): void; - hasInvalidatedResolution?: HasInvalidatedResolution; - hasChangedAutomaticTypeDirectiveNames?: boolean; - createHash?(data: string): string; - getParsedCommandLine?(fileName: string): ParsedCommandLine | undefined; - createDirectory?(directory: string): void; - } - export enum TransformFlags { - None = 0, - ContainsTypeScript = 1, - ContainsJsx = 2, - ContainsESNext = 4, - ContainsES2019 = 8, - ContainsES2018 = 16, - ContainsES2017 = 32, - ContainsES2016 = 64, - ContainsES2015 = 128, - ContainsGenerator = 256, - ContainsDestructuringAssignment = 512, - ContainsTypeScriptClassSyntax = 1024, - ContainsLexicalThis = 2048, - ContainsRestOrSpread = 4096, - ContainsObjectRestOrSpread = 8192, - ContainsComputedPropertyName = 16384, - ContainsBlockScopedBinding = 32768, - ContainsBindingPattern = 65536, - ContainsYield = 131072, - ContainsHoistedDeclarationOrCompletion = 262144, - ContainsDynamicImport = 524288, - ContainsClassFields = 1048576, - HasComputedFlags = 536870912, - AssertTypeScript = 1, - AssertJsx = 2, - AssertESNext = 4, - AssertES2019 = 8, - AssertES2018 = 16, - AssertES2017 = 32, - AssertES2016 = 64, - AssertES2015 = 128, - AssertGenerator = 256, - AssertDestructuringAssignment = 512, - OuterExpressionExcludes = 536870912, - PropertyAccessExcludes = 536870912, - NodeExcludes = 536870912, - ArrowFunctionExcludes = 537371648, - FunctionExcludes = 537373696, - ConstructorExcludes = 537372672, - MethodOrAccessorExcludes = 537372672, - PropertyExcludes = 536872960, - ClassExcludes = 536888320, - ModuleExcludes = 537168896, - TypeExcludes = -2, - ObjectLiteralExcludes = 536896512, - ArrayLiteralOrCallOrNewExcludes = 536875008, - VariableDeclarationListExcludes = 536944640, - ParameterExcludes = 536870912, - CatchClauseExcludes = 536879104, - BindingPatternExcludes = 536875008, - PropertyNamePropagatingFlags = 2048 - } - export interface SourceMapRange extends TextRange { - source?: SourceMapSource; - } - export interface SourceMapSource { - fileName: string; - text: string; - lineMap: ReadonlyArray; - skipTrivia?: (pos: number) => number; - } - export interface EmitNode { - annotatedNodes?: Node[]; - flags: EmitFlags; - leadingComments?: SynthesizedComment[]; - trailingComments?: SynthesizedComment[]; - commentRange?: TextRange; - sourceMapRange?: SourceMapRange; - tokenSourceMapRanges?: (SourceMapRange | undefined)[]; - constantValue?: string | number; - externalHelpersModuleName?: Identifier; - externalHelpers?: boolean; - helpers?: EmitHelper[]; - startsOnNewLine?: boolean; - } - export enum EmitFlags { - None = 0, - SingleLine = 1, - AdviseOnEmitNode = 2, - NoSubstitution = 4, - CapturesThis = 8, - NoLeadingSourceMap = 16, - NoTrailingSourceMap = 32, - NoSourceMap = 48, - NoNestedSourceMaps = 64, - NoTokenLeadingSourceMaps = 128, - NoTokenTrailingSourceMaps = 256, - NoTokenSourceMaps = 384, - NoLeadingComments = 512, - NoTrailingComments = 1024, - NoComments = 1536, - NoNestedComments = 2048, - HelperName = 4096, - ExportName = 8192, - LocalName = 16384, - InternalName = 32768, - Indented = 65536, - NoIndentation = 131072, - AsyncFunctionBody = 262144, - ReuseTempVariableScope = 524288, - CustomPrologue = 1048576, - NoHoisting = 2097152, - HasEndOfDeclarationMarker = 4194304, - Iterator = 8388608, - NoAsciiEscaping = 16777216, - TypeScriptClassWrapper = 33554432, - NeverApplyImportHelper = 67108864 - } - export interface EmitHelper { - readonly name: string; - readonly scoped: boolean; - readonly text: string | ((node: EmitHelperUniqueNameCallback) => string); - readonly priority?: number; - } - export interface UnscopedEmitHelper extends EmitHelper { - readonly scoped: false; - readonly importName?: string; - readonly text: string; - } - export type UniqueNameHandler = (baseName: string, checkFn?: (name: string) => boolean, optimistic?: boolean) => string; - export type EmitHelperUniqueNameCallback = (name: string) => string; - /** - * Used by the checker, this enum keeps track of external emit helpers that should be type - * checked. - */ - export enum ExternalEmitHelpers { - Extends = 1, - Assign = 2, - Rest = 4, - Decorate = 8, - Metadata = 16, - Param = 32, - Awaiter = 64, - Generator = 128, - Values = 256, - Read = 512, - Spread = 1024, - SpreadArrays = 2048, - Await = 4096, - AsyncGenerator = 8192, - AsyncDelegator = 16384, - AsyncValues = 32768, - ExportStar = 65536, - MakeTemplateObject = 131072, - FirstEmitHelper = 1, - LastEmitHelper = 131072, - ForOfIncludes = 256, - ForAwaitOfIncludes = 32768, - AsyncGeneratorIncludes = 12288, - AsyncDelegatorIncludes = 53248, - SpreadIncludes = 1536 - } - export enum EmitHint { - SourceFile = 0, - Expression = 1, - IdentifierName = 2, - MappedTypeParameter = 3, - Unspecified = 4, - EmbeddedStatement = 5 - } - export interface EmitHost extends ScriptReferenceHost, ModuleSpecifierResolutionHost { - getSourceFiles(): ReadonlyArray; - useCaseSensitiveFileNames(): boolean; - getCurrentDirectory(): string; - isSourceFileFromExternalLibrary(file: SourceFile): boolean; - getResolvedProjectReferenceToRedirect(fileName: string): ResolvedProjectReference | undefined; - getLibFileFromReference(ref: FileReference): SourceFile | undefined; - getCommonSourceDirectory(): string; - getCanonicalFileName(fileName: string): string; - getNewLine(): string; - isEmitBlocked(emitFileName: string): boolean; - getPrependNodes(): ReadonlyArray; - writeFile: WriteFileCallback; - getProgramBuildInfo(): ProgramBuildInfo | undefined; - getSourceFileFromReference: Program["getSourceFileFromReference"]; - readonly redirectTargetsMap: RedirectTargetsMap; - } - export interface TransformationContext { - getEmitResolver(): EmitResolver; - getEmitHost(): EmitHost; - /** Gets the compiler options supplied to the transformer. */ - getCompilerOptions(): CompilerOptions; - /** Starts a new lexical environment. */ - startLexicalEnvironment(): void; - /** Suspends the current lexical environment, usually after visiting a parameter list. */ - suspendLexicalEnvironment(): void; - /** Resumes a suspended lexical environment, usually before visiting a function body. */ - resumeLexicalEnvironment(): void; - /** Ends a lexical environment, returning any declarations. */ - endLexicalEnvironment(): Statement[] | undefined; - /** Hoists a function declaration to the containing scope. */ - hoistFunctionDeclaration(node: FunctionDeclaration): void; - /** Hoists a variable declaration to the containing scope. */ - hoistVariableDeclaration(node: Identifier): void; - /** Records a request for a non-scoped emit helper in the current context. */ - requestEmitHelper(helper: EmitHelper): void; - /** Gets and resets the requested non-scoped emit helpers. */ - readEmitHelpers(): EmitHelper[] | undefined; - /** Enables expression substitutions in the pretty printer for the provided SyntaxKind. */ - enableSubstitution(kind: SyntaxKind): void; - /** Determines whether expression substitutions are enabled for the provided node. */ - isSubstitutionEnabled(node: Node): boolean; - /** - * Hook used by transformers to substitute expressions just before they - * are emitted by the pretty printer. - * - * NOTE: Transformation hooks should only be modified during `Transformer` initialization, - * before returning the `NodeTransformer` callback. - */ - onSubstituteNode: (hint: EmitHint, node: Node) => Node; - /** - * Enables before/after emit notifications in the pretty printer for the provided - * SyntaxKind. - */ - enableEmitNotification(kind: SyntaxKind): void; - /** - * Determines whether before/after emit notifications should be raised in the pretty - * printer when it emits a node. - */ - isEmitNotificationEnabled(node: Node): boolean; - /** - * Hook used to allow transformers to capture state before or after - * the printer emits a node. - * - * NOTE: Transformation hooks should only be modified during `Transformer` initialization, - * before returning the `NodeTransformer` callback. - */ - onEmitNode: (hint: EmitHint, node: Node, emitCallback: (hint: EmitHint, node: Node) => void) => void; - addDiagnostic(diag: DiagnosticWithLocation): void; - } - export interface TransformationResult { - /** Gets the transformed source files. */ - transformed: T[]; - /** Gets diagnostics for the transformation. */ - diagnostics?: DiagnosticWithLocation[]; - /** - * Gets a substitute for a node, if one is available; otherwise, returns the original node. - * - * @param hint A hint as to the intended usage of the node. - * @param node The node to substitute. - */ - substituteNode(hint: EmitHint, node: Node): Node; - /** - * Emits a node with possible notification. - * - * @param hint A hint as to the intended usage of the node. - * @param node The node to emit. - * @param emitCallback A callback used to emit the node. - */ - emitNodeWithNotification(hint: EmitHint, node: Node, emitCallback: (hint: EmitHint, node: Node) => void): void; - /** - * Clean up EmitNode entries on any parse-tree nodes. - */ - dispose(): void; - } - /** - * A function that is used to initialize and return a `Transformer` callback, which in turn - * will be used to transform one or more nodes. - */ - export type TransformerFactory = (context: TransformationContext) => Transformer; - /** - * A function that transforms a node. - */ - export type Transformer = (node: T) => T; - /** - * A function that accepts and possibly transforms a node. - */ - export type Visitor = (node: Node) => VisitResult; - export type VisitResult = T | T[] | undefined; - export interface Printer { - /** - * Print a node and its subtree as-is, without any emit transformations. - * @param hint A value indicating the purpose of a node. This is primarily used to - * distinguish between an `Identifier` used in an expression position, versus an - * `Identifier` used as an `IdentifierName` as part of a declaration. For most nodes you - * should just pass `Unspecified`. - * @param node The node to print. The node and its subtree are printed as-is, without any - * emit transformations. - * @param sourceFile A source file that provides context for the node. The source text of - * the file is used to emit the original source content for literals and identifiers, while - * the identifiers of the source file are used when generating unique names to avoid - * collisions. - */ - printNode(hint: EmitHint, node: Node, sourceFile: SourceFile): string; - /** - * Prints a list of nodes using the given format flags - */ - printList(format: ListFormat, list: NodeArray, sourceFile: SourceFile): string; - /** - * Prints a source file as-is, without any emit transformations. - */ - printFile(sourceFile: SourceFile): string; - /** - * Prints a bundle of source files as-is, without any emit transformations. - */ - printBundle(bundle: Bundle): string; - writeNode(hint: EmitHint, node: Node, sourceFile: SourceFile | undefined, writer: EmitTextWriter): void; - writeList(format: ListFormat, list: NodeArray | undefined, sourceFile: SourceFile | undefined, writer: EmitTextWriter): void; - writeFile(sourceFile: SourceFile, writer: EmitTextWriter, sourceMapGenerator: SourceMapGenerator | undefined): void; - writeBundle(bundle: Bundle, writer: EmitTextWriter, sourceMapGenerator: SourceMapGenerator | undefined): void; - bundleFileInfo?: BundleFileInfo; - } - export enum BundleFileSectionKind { - Prologue = "prologue", - EmitHelpers = "emitHelpers", - NoDefaultLib = "no-default-lib", - Reference = "reference", - Type = "type", - Lib = "lib", - Prepend = "prepend", - Text = "text", - Internal = "internal" - } - export interface BundleFileSectionBase extends TextRange { - kind: BundleFileSectionKind; - data?: string; - } - export interface BundleFilePrologue extends BundleFileSectionBase { - kind: BundleFileSectionKind.Prologue; - data: string; - } - export interface BundleFileEmitHelpers extends BundleFileSectionBase { - kind: BundleFileSectionKind.EmitHelpers; - data: string; - } - export interface BundleFileHasNoDefaultLib extends BundleFileSectionBase { - kind: BundleFileSectionKind.NoDefaultLib; - } - export interface BundleFileReference extends BundleFileSectionBase { - kind: BundleFileSectionKind.Reference | BundleFileSectionKind.Type | BundleFileSectionKind.Lib; - data: string; - } - export interface BundleFilePrepend extends BundleFileSectionBase { - kind: BundleFileSectionKind.Prepend; - data: string; - texts: BundleFileTextLike[]; - } - export type BundleFileTextLikeKind = BundleFileSectionKind.Text | BundleFileSectionKind.Internal; - export interface BundleFileTextLike extends BundleFileSectionBase { - kind: BundleFileTextLikeKind; - } - export type BundleFileSection = BundleFilePrologue | BundleFileEmitHelpers | BundleFileHasNoDefaultLib | BundleFileReference | BundleFilePrepend | BundleFileTextLike; - export interface SourceFilePrologueDirectiveExpression extends TextRange { - text: string; - } - export interface SourceFilePrologueDirective extends TextRange { - expression: SourceFilePrologueDirectiveExpression; - } - export interface SourceFilePrologueInfo { - file: number; - text: string; - directives: SourceFilePrologueDirective[]; - } - export interface SourceFileInfo { - helpers?: string[]; - prologues?: SourceFilePrologueInfo[]; - } - export interface BundleFileInfo { - sections: BundleFileSection[]; - sources?: SourceFileInfo; - } - export interface BundleBuildInfo { - js?: BundleFileInfo; - dts?: BundleFileInfo; - commonSourceDirectory: string; - sourceFiles: ReadonlyArray; - } - export interface BuildInfo { - bundle?: BundleBuildInfo; - program?: ProgramBuildInfo; - version: string; - } - export interface PrintHandlers { - /** - * A hook used by the Printer when generating unique names to avoid collisions with - * globally defined names that exist outside of the current source file. - */ - hasGlobalName?(name: string): boolean; - /** - * A hook used by the Printer to provide notifications prior to emitting a node. A - * compatible implementation **must** invoke `emitCallback` with the provided `hint` and - * `node` values. - * @param hint A hint indicating the intended purpose of the node. - * @param node The node to emit. - * @param emitCallback A callback that, when invoked, will emit the node. - * @example - * ```ts - * var printer = createPrinter(printerOptions, { - * onEmitNode(hint, node, emitCallback) { - * // set up or track state prior to emitting the node... - * emitCallback(hint, node); - * // restore state after emitting the node... - * } - * }); - * ``` - */ - onEmitNode?(hint: EmitHint, node: Node | undefined, emitCallback: (hint: EmitHint, node: Node | undefined) => void): void; - /** - * A hook used by the Printer to perform just-in-time substitution of a node. This is - * primarily used by node transformations that need to substitute one node for another, - * such as replacing `myExportedVar` with `exports.myExportedVar`. - * @param hint A hint indicating the intended purpose of the node. - * @param node The node to emit. - * @example - * ```ts - * var printer = createPrinter(printerOptions, { - * substituteNode(hint, node) { - * // perform substitution if necessary... - * return node; - * } - * }); - * ``` - */ - substituteNode?(hint: EmitHint, node: Node): Node; - onEmitSourceMapOfNode?: (hint: EmitHint, node: Node, emitCallback: (hint: EmitHint, node: Node) => void) => void; - onEmitSourceMapOfToken?: (node: Node | undefined, token: SyntaxKind, writer: (s: string) => void, pos: number, emitCallback: (token: SyntaxKind, writer: (s: string) => void, pos: number) => number) => number; - onEmitSourceMapOfPosition?: (pos: number) => void; - onSetSourceFile?: (node: SourceFile) => void; - onBeforeEmitNodeArray?: (nodes: NodeArray | undefined) => void; - onAfterEmitNodeArray?: (nodes: NodeArray | undefined) => void; - onBeforeEmitToken?: (node: Node) => void; - onAfterEmitToken?: (node: Node) => void; - } - export interface PrinterOptions { - removeComments?: boolean; - newLine?: NewLineKind; - omitTrailingSemicolon?: boolean; - noEmitHelpers?: boolean; - module?: CompilerOptions["module"]; - target?: CompilerOptions["target"]; - sourceMap?: boolean; - inlineSourceMap?: boolean; - inlineSources?: boolean; - extendedDiagnostics?: boolean; - onlyPrintJsDocStyle?: boolean; - neverAsciiEscape?: boolean; - writeBundleFileInfo?: boolean; - recordInternalSection?: boolean; - stripInternal?: boolean; - relativeToBuildInfo?: (path: string) => string; - } - export interface RawSourceMap { - version: 3; - file: string; - sourceRoot?: string | null; - sources: string[]; - sourcesContent?: (string | null)[] | null; - mappings: string; - names?: string[] | null; - } - /** - * Generates a source map. - */ - export interface SourceMapGenerator { - getSources(): ReadonlyArray; - /** - * Adds a source to the source map. - */ - addSource(fileName: string): number; - /** - * Set the content for a source. - */ - setSourceContent(sourceIndex: number, content: string | null): void; - /** - * Adds a name. - */ - addName(name: string): number; - /** - * Adds a mapping without source information. - */ - addMapping(generatedLine: number, generatedCharacter: number): void; - /** - * Adds a mapping with source information. - */ - addMapping(generatedLine: number, generatedCharacter: number, sourceIndex: number, sourceLine: number, sourceCharacter: number, nameIndex?: number): void; - /** - * Appends a source map. - */ - appendSourceMap(generatedLine: number, generatedCharacter: number, sourceMap: RawSourceMap, sourceMapPath: string, start?: LineAndCharacter, end?: LineAndCharacter): void; - /** - * Gets the source map as a `RawSourceMap` object. - */ - toJSON(): RawSourceMap; - /** - * Gets the string representation of the source map. - */ - toString(): string; - } - export interface DocumentPositionMapperHost { - getSourceFileLike(fileName: string): SourceFileLike | undefined; - getCanonicalFileName(path: string): string; - log(text: string): void; - } - /** - * Maps positions between source and generated files. - */ - export interface DocumentPositionMapper { - getSourcePosition(input: DocumentPosition): DocumentPosition; - getGeneratedPosition(input: DocumentPosition): DocumentPosition; - } - export interface DocumentPosition { - fileName: string; - pos: number; - } - export interface EmitTextWriter extends SymbolWriter { - write(s: string): void; - writeTrailingSemicolon(text: string): void; - writeComment(text: string): void; - getText(): string; - rawWrite(s: string): void; - writeLiteral(s: string): void; - getTextPos(): number; - getLine(): number; - getColumn(): number; - getIndent(): number; - isAtStartOfLine(): boolean; - getTextPosWithWriteLine?(): number; - } - export interface GetEffectiveTypeRootsHost { - directoryExists?(directoryName: string): boolean; - getCurrentDirectory?(): string; - } - /** @internal */ - export interface ModuleSpecifierResolutionHost extends GetEffectiveTypeRootsHost { - useCaseSensitiveFileNames?(): boolean; - fileExists?(path: string): boolean; - readFile?(path: string): string | undefined; - } - export interface SymbolTracker { - trackSymbol?(symbol: Symbol, enclosingDeclaration?: Node, meaning?: SymbolFlags): void; - reportInaccessibleThisError?(): void; - reportPrivateInBaseOfClassExpression?(propertyName: string): void; - reportInaccessibleUniqueSymbolError?(): void; - reportLikelyUnsafeImportRequiredError?(specifier: string): void; - moduleResolverHost?: ModuleSpecifierResolutionHost & { - getSourceFiles(): ReadonlyArray; - getCommonSourceDirectory(): string; - }; - trackReferencedAmbientModule?(decl: ModuleDeclaration, symbol: Symbol): void; - trackExternalModuleSymbolOfImportTypeNode?(symbol: Symbol): void; - } - export interface TextSpan { - start: number; - length: number; - } - export interface TextChangeRange { - span: TextSpan; - newLength: number; - } - export interface DiagnosticCollection { - add(diagnostic: Diagnostic): void; - lookup(diagnostic: Diagnostic): Diagnostic | undefined; - getGlobalDiagnostics(): Diagnostic[]; - getDiagnostics(fileName: string): DiagnosticWithLocation[]; - getDiagnostics(): Diagnostic[]; - reattachFileDiagnostics(newFile: SourceFile): void; - } - export interface SyntaxList extends Node { - _children: Node[]; - } - export enum ListFormat { - None = 0, - SingleLine = 0, - MultiLine = 1, - PreserveLines = 2, - LinesMask = 3, - NotDelimited = 0, - BarDelimited = 4, - AmpersandDelimited = 8, - CommaDelimited = 16, - AsteriskDelimited = 32, - DelimitersMask = 60, - AllowTrailingComma = 64, - Indented = 128, - SpaceBetweenBraces = 256, - SpaceBetweenSiblings = 512, - Braces = 1024, - Parenthesis = 2048, - AngleBrackets = 4096, - SquareBrackets = 8192, - BracketsMask = 15360, - OptionalIfUndefined = 16384, - OptionalIfEmpty = 32768, - Optional = 49152, - PreferNewLine = 65536, - NoTrailingNewLine = 131072, - NoInterveningComments = 262144, - NoSpaceIfEmpty = 524288, - SingleElement = 1048576, - Modifiers = 262656, - HeritageClauses = 512, - SingleLineTypeLiteralMembers = 768, - MultiLineTypeLiteralMembers = 32897, - TupleTypeElements = 528, - UnionTypeConstituents = 516, - IntersectionTypeConstituents = 520, - ObjectBindingPatternElements = 525136, - ArrayBindingPatternElements = 524880, - ObjectLiteralExpressionProperties = 526226, - ArrayLiteralExpressionElements = 8914, - CommaListElements = 528, - CallExpressionArguments = 2576, - NewExpressionArguments = 18960, - TemplateExpressionSpans = 262144, - SingleLineBlockStatements = 768, - MultiLineBlockStatements = 129, - VariableDeclarationList = 528, - SingleLineFunctionBodyStatements = 768, - MultiLineFunctionBodyStatements = 1, - ClassHeritageClauses = 0, - ClassMembers = 129, - InterfaceMembers = 129, - EnumMembers = 145, - CaseBlockClauses = 129, - NamedImportsOrExportsElements = 525136, - JsxElementOrFragmentChildren = 262144, - JsxElementAttributes = 262656, - CaseOrDefaultClauseStatements = 163969, - HeritageClauseTypes = 528, - SourceFileStatements = 131073, - Decorators = 49153, - TypeArguments = 53776, - TypeParameters = 53776, - Parameters = 2576, - IndexSignatureParameters = 8848, - JSDocComment = 33 - } - export enum PragmaKindFlags { - None = 0, - /** - * Triple slash comment of the form - * /// - */ - TripleSlashXML = 1, - /** - * Single line comment of the form - * // @pragma-name argval1 argval2 - * or - * /// @pragma-name argval1 argval2 - */ - SingleLine = 2, - /** - * Multiline non-jsdoc pragma of the form - * /* @pragma-name argval1 argval2 * / - */ - MultiLine = 4, - All = 7, - Default = 7 - } - export interface PragmaArgumentSpecification { - name: TName; - optional?: boolean; - captureSpan?: boolean; - } - export interface PragmaDefinition { - args?: readonly [PragmaArgumentSpecification] | readonly [PragmaArgumentSpecification, PragmaArgumentSpecification] | readonly [PragmaArgumentSpecification, PragmaArgumentSpecification, PragmaArgumentSpecification] | readonly [PragmaArgumentSpecification, PragmaArgumentSpecification, PragmaArgumentSpecification, PragmaArgumentSpecification]; - kind?: PragmaKindFlags; - } - export const commentPragmas: { - readonly "reference": { - readonly args: readonly [{ - readonly name: "types"; - readonly optional: true; - readonly captureSpan: true; - }, { - readonly name: "lib"; - readonly optional: true; - readonly captureSpan: true; - }, { - readonly name: "path"; - readonly optional: true; - readonly captureSpan: true; - }, { - readonly name: "no-default-lib"; - readonly optional: true; - }]; - readonly kind: PragmaKindFlags; - }; - readonly "amd-dependency": { - readonly args: readonly [{ - readonly name: "path"; - }, { - readonly name: "name"; - readonly optional: true; - }]; - readonly kind: PragmaKindFlags; - }; - readonly "amd-module": { - readonly args: readonly [{ - readonly name: "name"; - }]; - readonly kind: PragmaKindFlags; - }; - readonly "ts-check": { - readonly kind: PragmaKindFlags; - }; - readonly "ts-nocheck": { - readonly kind: PragmaKindFlags; - }; - readonly "jsx": { - readonly args: readonly [{ - readonly name: "factory"; - }]; - readonly kind: PragmaKindFlags; - }; - }; - export type PragmaArgTypeMaybeCapture = TDesc extends { - captureSpan: true; - } ? { - value: string; - pos: number; - end: number; - } : string; - export type PragmaArgTypeOptional = TDesc extends { - optional: true; - } ? { - [K in TName]?: PragmaArgTypeMaybeCapture; - } : { - [K in TName]: PragmaArgTypeMaybeCapture; - }; - type UnionToIntersection = (U extends any ? (k: U) => void : never) extends ((k: infer I) => void) ? I : never; - type ArgumentDefinitionToFieldUnion[]> = { - [K in keyof T]: PragmaArgTypeOptional; - }[Extract]; - /** - * Maps a pragma definition into the desired shape for its arguments object - */ - export type PragmaArgumentType = ConcretePragmaSpecs[KPrag] extends { - args: readonly PragmaArgumentSpecification[]; - } ? UnionToIntersection> : never; - export type ConcretePragmaSpecs = typeof commentPragmas; - export type PragmaPseudoMap = { - [K in keyof ConcretePragmaSpecs]: { - arguments: PragmaArgumentType; - range: CommentRange; - }; - }; - export type PragmaPseudoMapEntry = { - [K in keyof PragmaPseudoMap]: { - name: K; - args: PragmaPseudoMap[K]; - }; - }[keyof PragmaPseudoMap]; - export interface ReadonlyPragmaMap extends ReadonlyMap { - get(key: TKey): PragmaPseudoMap[TKey] | PragmaPseudoMap[TKey][]; - forEach(action: (value: PragmaPseudoMap[TKey] | PragmaPseudoMap[TKey][], key: TKey) => void): void; - } - /** - * A strongly-typed es6 map of pragma entries, the values of which are either a single argument - * value (if only one was found), or an array of multiple argument values if the pragma is present - * in multiple places - */ - export interface PragmaMap extends Map, ReadonlyPragmaMap { - set(key: TKey, value: PragmaPseudoMap[TKey] | PragmaPseudoMap[TKey][]): this; - get(key: TKey): PragmaPseudoMap[TKey] | PragmaPseudoMap[TKey][]; - forEach(action: (value: PragmaPseudoMap[TKey] | PragmaPseudoMap[TKey][], key: TKey) => void): void; - } - export interface UserPreferences { - readonly disableSuggestions?: boolean; - readonly quotePreference?: "auto" | "double" | "single"; - readonly includeCompletionsForModuleExports?: boolean; - readonly includeCompletionsWithInsertText?: boolean; - readonly importModuleSpecifierPreference?: "relative" | "non-relative"; - /** Determines whether we import `foo/index.ts` as "foo", "foo/index", or "foo/index.js" */ - readonly importModuleSpecifierEnding?: "minimal" | "index" | "js"; - readonly allowTextChangesInNewFiles?: boolean; - readonly providePrefixAndSuffixTextForRename?: boolean; - } - /** Represents a bigint literal value without requiring bigint support */ - export interface PseudoBigInt { - negative: boolean; - base10Value: string; - } - export {}; -} -declare function setTimeout(handler: (...args: any[]) => void, timeout: number): any; -declare function clearTimeout(handle: any): void; -declare namespace ts { - /** - * djb2 hashing algorithm - * http://www.cse.yorku.ca/~oz/hash.html - */ - export function generateDjb2Hash(data: string): string; - /** - * Set a high stack trace limit to provide more information in case of an error. - * Called for command-line and server use cases. - * Not called if TypeScript is used as a library. - */ - export function setStackTraceLimit(): void; - export enum FileWatcherEventKind { - Created = 0, - Changed = 1, - Deleted = 2 - } - export type FileWatcherCallback = (fileName: string, eventKind: FileWatcherEventKind) => void; - export type DirectoryWatcherCallback = (fileName: string) => void; - export interface WatchedFile { - readonly fileName: string; - readonly callback: FileWatcherCallback; - mtime: Date; - } - export enum PollingInterval { - High = 2000, - Medium = 500, - Low = 250 - } - export type HostWatchFile = (fileName: string, callback: FileWatcherCallback, pollingInterval: PollingInterval | undefined) => FileWatcher; - export type HostWatchDirectory = (fileName: string, callback: DirectoryWatcherCallback, recursive?: boolean) => FileWatcher; - export const missingFileModifiedTime: Date; - export let unchangedPollThresholds: { - [PollingInterval.Low]: number; - [PollingInterval.Medium]: number; - [PollingInterval.High]: number; - }; - export function setCustomPollingValues(system: System): void; - export function createDynamicPriorityPollingWatchFile(host: { - getModifiedTime: System["getModifiedTime"]; - setTimeout: System["setTimeout"]; - }): HostWatchFile; - export function createSingleFileWatcherPerName(watchFile: HostWatchFile, useCaseSensitiveFileNames: boolean): HostWatchFile; - /** - * Returns true if file status changed - */ - export function onWatchedFileStat(watchedFile: WatchedFile, modifiedTime: Date): boolean; - export function getFileWatcherEventKind(oldTime: number, newTime: number): FileWatcherEventKind; - export const ignoredPaths: string[]; - export let sysLog: (s: string) => void; - export interface RecursiveDirectoryWatcherHost { - watchDirectory: HostWatchDirectory; - useCaseSensitiveFileNames: boolean; - getAccessibleSortedChildDirectories(path: string): ReadonlyArray; - directoryExists(dir: string): boolean; - realpath(s: string): string; - } - /** - * Watch the directory recursively using host provided method to watch child directories - * that means if this is recursive watcher, watch the children directories as well - * (eg on OS that dont support recursive watch using fs.watch use fs.watchFile) - */ - export function createRecursiveDirectoryWatcher(host: RecursiveDirectoryWatcherHost): (directoryName: string, callback: DirectoryWatcherCallback) => FileWatcher; - export type BufferEncoding = "ascii" | "utf8" | "utf-8" | "utf16le" | "ucs2" | "ucs-2" | "base64" | "latin1" | "binary" | "hex"; - interface NodeBuffer extends Uint8Array { - constructor: any; - write(str: string, encoding?: BufferEncoding): number; - write(str: string, offset: number, encoding?: BufferEncoding): number; - write(str: string, offset: number, length: number, encoding?: BufferEncoding): number; - toString(encoding?: string, start?: number, end?: number): string; - toJSON(): { - type: "Buffer"; - data: number[]; - }; - equals(otherBuffer: Uint8Array): boolean; - compare(otherBuffer: Uint8Array, targetStart?: number, targetEnd?: number, sourceStart?: number, sourceEnd?: number): number; - copy(targetBuffer: Uint8Array, targetStart?: number, sourceStart?: number, sourceEnd?: number): number; - slice(begin?: number, end?: number): Buffer; - subarray(begin?: number, end?: number): Buffer; - writeUIntLE(value: number, offset: number, byteLength: number): number; - writeUIntBE(value: number, offset: number, byteLength: number): number; - writeIntLE(value: number, offset: number, byteLength: number): number; - writeIntBE(value: number, offset: number, byteLength: number): number; - readUIntLE(offset: number, byteLength: number): number; - readUIntBE(offset: number, byteLength: number): number; - readIntLE(offset: number, byteLength: number): number; - readIntBE(offset: number, byteLength: number): number; - readUInt8(offset: number): number; - readUInt16LE(offset: number): number; - readUInt16BE(offset: number): number; - readUInt32LE(offset: number): number; - readUInt32BE(offset: number): number; - readInt8(offset: number): number; - readInt16LE(offset: number): number; - readInt16BE(offset: number): number; - readInt32LE(offset: number): number; - readInt32BE(offset: number): number; - readFloatLE(offset: number): number; - readFloatBE(offset: number): number; - readDoubleLE(offset: number): number; - readDoubleBE(offset: number): number; - reverse(): this; - swap16(): Buffer; - swap32(): Buffer; - swap64(): Buffer; - writeUInt8(value: number, offset: number): number; - writeUInt16LE(value: number, offset: number): number; - writeUInt16BE(value: number, offset: number): number; - writeUInt32LE(value: number, offset: number): number; - writeUInt32BE(value: number, offset: number): number; - writeInt8(value: number, offset: number): number; - writeInt16LE(value: number, offset: number): number; - writeInt16BE(value: number, offset: number): number; - writeInt32LE(value: number, offset: number): number; - writeInt32BE(value: number, offset: number): number; - writeFloatLE(value: number, offset: number): number; - writeFloatBE(value: number, offset: number): number; - writeDoubleLE(value: number, offset: number): number; - writeDoubleBE(value: number, offset: number): number; - readBigUInt64BE(offset?: number): bigint; - readBigUInt64LE(offset?: number): bigint; - readBigInt64BE(offset?: number): bigint; - readBigInt64LE(offset?: number): bigint; - writeBigInt64BE(value: bigint, offset?: number): number; - writeBigInt64LE(value: bigint, offset?: number): number; - writeBigUInt64BE(value: bigint, offset?: number): number; - writeBigUInt64LE(value: bigint, offset?: number): number; - fill(value: string | Uint8Array | number, offset?: number, end?: number, encoding?: BufferEncoding): this; - indexOf(value: string | number | Uint8Array, byteOffset?: number, encoding?: BufferEncoding): number; - lastIndexOf(value: string | number | Uint8Array, byteOffset?: number, encoding?: BufferEncoding): number; - entries(): IterableIterator<[number, number]>; - includes(value: string | number | Buffer, byteOffset?: number, encoding?: BufferEncoding): boolean; - keys(): IterableIterator; - values(): IterableIterator; - } - interface Buffer extends NodeBuffer { - } - export interface System { - args: string[]; - newLine: string; - useCaseSensitiveFileNames: boolean; - write(s: string): void; - writeOutputIsTTY?(): boolean; - readFile(path: string, encoding?: string): string | undefined; - getFileSize?(path: string): number; - writeFile(path: string, data: string, writeByteOrderMark?: boolean): void; - /** - * @pollingInterval - this parameter is used in polling-based watchers and ignored in watchers that - * use native OS file watching - */ - watchFile?(path: string, callback: FileWatcherCallback, pollingInterval?: number): FileWatcher; - watchDirectory?(path: string, callback: DirectoryWatcherCallback, recursive?: boolean): FileWatcher; - resolvePath(path: string): string; - fileExists(path: string): boolean; - directoryExists(path: string): boolean; - createDirectory(path: string): void; - getExecutingFilePath(): string; - getCurrentDirectory(): string; - getDirectories(path: string): string[]; - readDirectory(path: string, extensions?: ReadonlyArray, exclude?: ReadonlyArray, include?: ReadonlyArray, depth?: number): string[]; - getModifiedTime?(path: string): Date | undefined; - setModifiedTime?(path: string, time: Date): void; - deleteFile?(path: string): void; - /** - * A good implementation is node.js' `crypto.createHash`. (https://nodejs.org/api/crypto.html#crypto_crypto_createhash_algorithm) - */ - createHash?(data: string): string; - /** This must be cryptographically secure. Only implement this method using `crypto.createHash("sha256")`. */ - createSHA256Hash?(data: string): string; - getMemoryUsage?(): number; - exit(exitCode?: number): void; - realpath?(path: string): string; - getEnvironmentVariable(name: string): string; - tryEnableSourceMapsForHost?(): void; - debugMode?: boolean; - setTimeout?(callback: (...args: any[]) => void, ms: number, ...args: any[]): any; - clearTimeout?(timeoutId: any): void; - clearScreen?(): void; - setBlocking?(): void; - base64decode?(input: string): string; - base64encode?(input: string): string; - bufferFrom?(input: string, encoding?: string): Buffer; - } - export interface FileWatcher { - close(): void; - } - export function getNodeMajorVersion(): number | undefined; - export let sys: System; - export {}; -} -declare namespace ts { - const Diagnostics: { - Unterminated_string_literal: DiagnosticMessage; - Identifier_expected: DiagnosticMessage; - _0_expected: DiagnosticMessage; - A_file_cannot_have_a_reference_to_itself: DiagnosticMessage; - Trailing_comma_not_allowed: DiagnosticMessage; - Asterisk_Slash_expected: DiagnosticMessage; - An_element_access_expression_should_take_an_argument: DiagnosticMessage; - Unexpected_token: DiagnosticMessage; - A_rest_parameter_or_binding_pattern_may_not_have_a_trailing_comma: DiagnosticMessage; - A_rest_parameter_must_be_last_in_a_parameter_list: DiagnosticMessage; - Parameter_cannot_have_question_mark_and_initializer: DiagnosticMessage; - A_required_parameter_cannot_follow_an_optional_parameter: DiagnosticMessage; - An_index_signature_cannot_have_a_rest_parameter: DiagnosticMessage; - An_index_signature_parameter_cannot_have_an_accessibility_modifier: DiagnosticMessage; - An_index_signature_parameter_cannot_have_a_question_mark: DiagnosticMessage; - An_index_signature_parameter_cannot_have_an_initializer: DiagnosticMessage; - An_index_signature_must_have_a_type_annotation: DiagnosticMessage; - An_index_signature_parameter_must_have_a_type_annotation: DiagnosticMessage; - An_index_signature_parameter_type_must_be_string_or_number: DiagnosticMessage; - readonly_modifier_can_only_appear_on_a_property_declaration_or_index_signature: DiagnosticMessage; - Accessibility_modifier_already_seen: DiagnosticMessage; - _0_modifier_must_precede_1_modifier: DiagnosticMessage; - _0_modifier_already_seen: DiagnosticMessage; - _0_modifier_cannot_appear_on_a_class_element: DiagnosticMessage; - super_must_be_followed_by_an_argument_list_or_member_access: DiagnosticMessage; - Only_ambient_modules_can_use_quoted_names: DiagnosticMessage; - Statements_are_not_allowed_in_ambient_contexts: DiagnosticMessage; - A_declare_modifier_cannot_be_used_in_an_already_ambient_context: DiagnosticMessage; - Initializers_are_not_allowed_in_ambient_contexts: DiagnosticMessage; - _0_modifier_cannot_be_used_in_an_ambient_context: DiagnosticMessage; - _0_modifier_cannot_be_used_with_a_class_declaration: DiagnosticMessage; - _0_modifier_cannot_be_used_here: DiagnosticMessage; - _0_modifier_cannot_appear_on_a_data_property: DiagnosticMessage; - _0_modifier_cannot_appear_on_a_module_or_namespace_element: DiagnosticMessage; - A_0_modifier_cannot_be_used_with_an_interface_declaration: DiagnosticMessage; - Top_level_declarations_in_d_ts_files_must_start_with_either_a_declare_or_export_modifier: DiagnosticMessage; - A_rest_parameter_cannot_be_optional: DiagnosticMessage; - A_rest_parameter_cannot_have_an_initializer: DiagnosticMessage; - A_set_accessor_must_have_exactly_one_parameter: DiagnosticMessage; - A_set_accessor_cannot_have_an_optional_parameter: DiagnosticMessage; - A_set_accessor_parameter_cannot_have_an_initializer: DiagnosticMessage; - A_set_accessor_cannot_have_rest_parameter: DiagnosticMessage; - A_get_accessor_cannot_have_parameters: DiagnosticMessage; - Type_0_is_not_a_valid_async_function_return_type_in_ES5_SlashES3_because_it_does_not_refer_to_a_Promise_compatible_constructor_value: DiagnosticMessage; - Accessors_are_only_available_when_targeting_ECMAScript_5_and_higher: DiagnosticMessage; - An_async_function_or_method_must_have_a_valid_awaitable_return_type: DiagnosticMessage; - The_return_type_of_an_async_function_must_either_be_a_valid_promise_or_must_not_contain_a_callable_then_member: DiagnosticMessage; - A_promise_must_have_a_then_method: DiagnosticMessage; - The_first_parameter_of_the_then_method_of_a_promise_must_be_a_callback: DiagnosticMessage; - Enum_member_must_have_initializer: DiagnosticMessage; - Type_is_referenced_directly_or_indirectly_in_the_fulfillment_callback_of_its_own_then_method: DiagnosticMessage; - An_export_assignment_cannot_be_used_in_a_namespace: DiagnosticMessage; - The_return_type_of_an_async_function_or_method_must_be_the_global_Promise_T_type: DiagnosticMessage; - In_ambient_enum_declarations_member_initializer_must_be_constant_expression: DiagnosticMessage; - Unexpected_token_A_constructor_method_accessor_or_property_was_expected: DiagnosticMessage; - Unexpected_token_A_type_parameter_name_was_expected_without_curly_braces: DiagnosticMessage; - _0_modifier_cannot_appear_on_a_type_member: DiagnosticMessage; - _0_modifier_cannot_appear_on_an_index_signature: DiagnosticMessage; - A_0_modifier_cannot_be_used_with_an_import_declaration: DiagnosticMessage; - Invalid_reference_directive_syntax: DiagnosticMessage; - Octal_literals_are_not_available_when_targeting_ECMAScript_5_and_higher_Use_the_syntax_0: DiagnosticMessage; - _0_modifier_cannot_appear_on_a_constructor_declaration: DiagnosticMessage; - _0_modifier_cannot_appear_on_a_parameter: DiagnosticMessage; - Only_a_single_variable_declaration_is_allowed_in_a_for_in_statement: DiagnosticMessage; - Type_parameters_cannot_appear_on_a_constructor_declaration: DiagnosticMessage; - Type_annotation_cannot_appear_on_a_constructor_declaration: DiagnosticMessage; - An_accessor_cannot_have_type_parameters: DiagnosticMessage; - A_set_accessor_cannot_have_a_return_type_annotation: DiagnosticMessage; - An_index_signature_must_have_exactly_one_parameter: DiagnosticMessage; - _0_list_cannot_be_empty: DiagnosticMessage; - Type_parameter_list_cannot_be_empty: DiagnosticMessage; - Type_argument_list_cannot_be_empty: DiagnosticMessage; - Invalid_use_of_0_in_strict_mode: DiagnosticMessage; - with_statements_are_not_allowed_in_strict_mode: DiagnosticMessage; - delete_cannot_be_called_on_an_identifier_in_strict_mode: DiagnosticMessage; - A_for_await_of_statement_is_only_allowed_within_an_async_function_or_async_generator: DiagnosticMessage; - A_continue_statement_can_only_be_used_within_an_enclosing_iteration_statement: DiagnosticMessage; - A_break_statement_can_only_be_used_within_an_enclosing_iteration_or_switch_statement: DiagnosticMessage; - Jump_target_cannot_cross_function_boundary: DiagnosticMessage; - A_return_statement_can_only_be_used_within_a_function_body: DiagnosticMessage; - Expression_expected: DiagnosticMessage; - Type_expected: DiagnosticMessage; - A_default_clause_cannot_appear_more_than_once_in_a_switch_statement: DiagnosticMessage; - Duplicate_label_0: DiagnosticMessage; - A_continue_statement_can_only_jump_to_a_label_of_an_enclosing_iteration_statement: DiagnosticMessage; - A_break_statement_can_only_jump_to_a_label_of_an_enclosing_statement: DiagnosticMessage; - An_object_literal_cannot_have_multiple_properties_with_the_same_name_in_strict_mode: DiagnosticMessage; - An_object_literal_cannot_have_multiple_get_Slashset_accessors_with_the_same_name: DiagnosticMessage; - An_object_literal_cannot_have_property_and_accessor_with_the_same_name: DiagnosticMessage; - An_export_assignment_cannot_have_modifiers: DiagnosticMessage; - Octal_literals_are_not_allowed_in_strict_mode: DiagnosticMessage; - Variable_declaration_list_cannot_be_empty: DiagnosticMessage; - Digit_expected: DiagnosticMessage; - Hexadecimal_digit_expected: DiagnosticMessage; - Unexpected_end_of_text: DiagnosticMessage; - Invalid_character: DiagnosticMessage; - Declaration_or_statement_expected: DiagnosticMessage; - Statement_expected: DiagnosticMessage; - case_or_default_expected: DiagnosticMessage; - Property_or_signature_expected: DiagnosticMessage; - Enum_member_expected: DiagnosticMessage; - Variable_declaration_expected: DiagnosticMessage; - Argument_expression_expected: DiagnosticMessage; - Property_assignment_expected: DiagnosticMessage; - Expression_or_comma_expected: DiagnosticMessage; - Parameter_declaration_expected: DiagnosticMessage; - Type_parameter_declaration_expected: DiagnosticMessage; - Type_argument_expected: DiagnosticMessage; - String_literal_expected: DiagnosticMessage; - Line_break_not_permitted_here: DiagnosticMessage; - or_expected: DiagnosticMessage; - Declaration_expected: DiagnosticMessage; - Import_declarations_in_a_namespace_cannot_reference_a_module: DiagnosticMessage; - Cannot_use_imports_exports_or_module_augmentations_when_module_is_none: DiagnosticMessage; - File_name_0_differs_from_already_included_file_name_1_only_in_casing: DiagnosticMessage; - const_declarations_must_be_initialized: DiagnosticMessage; - const_declarations_can_only_be_declared_inside_a_block: DiagnosticMessage; - let_declarations_can_only_be_declared_inside_a_block: DiagnosticMessage; - Unterminated_template_literal: DiagnosticMessage; - Unterminated_regular_expression_literal: DiagnosticMessage; - An_object_member_cannot_be_declared_optional: DiagnosticMessage; - A_yield_expression_is_only_allowed_in_a_generator_body: DiagnosticMessage; - Computed_property_names_are_not_allowed_in_enums: DiagnosticMessage; - A_computed_property_name_in_an_ambient_context_must_refer_to_an_expression_whose_type_is_a_literal_type_or_a_unique_symbol_type: DiagnosticMessage; - A_computed_property_name_in_a_class_property_declaration_must_refer_to_an_expression_whose_type_is_a_literal_type_or_a_unique_symbol_type: DiagnosticMessage; - A_computed_property_name_in_a_method_overload_must_refer_to_an_expression_whose_type_is_a_literal_type_or_a_unique_symbol_type: DiagnosticMessage; - A_computed_property_name_in_an_interface_must_refer_to_an_expression_whose_type_is_a_literal_type_or_a_unique_symbol_type: DiagnosticMessage; - A_computed_property_name_in_a_type_literal_must_refer_to_an_expression_whose_type_is_a_literal_type_or_a_unique_symbol_type: DiagnosticMessage; - A_comma_expression_is_not_allowed_in_a_computed_property_name: DiagnosticMessage; - extends_clause_already_seen: DiagnosticMessage; - extends_clause_must_precede_implements_clause: DiagnosticMessage; - Classes_can_only_extend_a_single_class: DiagnosticMessage; - implements_clause_already_seen: DiagnosticMessage; - Interface_declaration_cannot_have_implements_clause: DiagnosticMessage; - Binary_digit_expected: DiagnosticMessage; - Octal_digit_expected: DiagnosticMessage; - Unexpected_token_expected: DiagnosticMessage; - Property_destructuring_pattern_expected: DiagnosticMessage; - Array_element_destructuring_pattern_expected: DiagnosticMessage; - A_destructuring_declaration_must_have_an_initializer: DiagnosticMessage; - An_implementation_cannot_be_declared_in_ambient_contexts: DiagnosticMessage; - Modifiers_cannot_appear_here: DiagnosticMessage; - Merge_conflict_marker_encountered: DiagnosticMessage; - A_rest_element_cannot_have_an_initializer: DiagnosticMessage; - A_parameter_property_may_not_be_declared_using_a_binding_pattern: DiagnosticMessage; - Only_a_single_variable_declaration_is_allowed_in_a_for_of_statement: DiagnosticMessage; - The_variable_declaration_of_a_for_in_statement_cannot_have_an_initializer: DiagnosticMessage; - The_variable_declaration_of_a_for_of_statement_cannot_have_an_initializer: DiagnosticMessage; - An_import_declaration_cannot_have_modifiers: DiagnosticMessage; - Module_0_has_no_default_export: DiagnosticMessage; - An_export_declaration_cannot_have_modifiers: DiagnosticMessage; - Export_declarations_are_not_permitted_in_a_namespace: DiagnosticMessage; - Catch_clause_variable_cannot_have_a_type_annotation: DiagnosticMessage; - Catch_clause_variable_cannot_have_an_initializer: DiagnosticMessage; - An_extended_Unicode_escape_value_must_be_between_0x0_and_0x10FFFF_inclusive: DiagnosticMessage; - Unterminated_Unicode_escape_sequence: DiagnosticMessage; - Line_terminator_not_permitted_before_arrow: DiagnosticMessage; - Import_assignment_cannot_be_used_when_targeting_ECMAScript_modules_Consider_using_import_Asterisk_as_ns_from_mod_import_a_from_mod_import_d_from_mod_or_another_module_format_instead: DiagnosticMessage; - Export_assignment_cannot_be_used_when_targeting_ECMAScript_modules_Consider_using_export_default_or_another_module_format_instead: DiagnosticMessage; - Cannot_re_export_a_type_when_the_isolatedModules_flag_is_provided: DiagnosticMessage; - Decorators_are_not_valid_here: DiagnosticMessage; - Decorators_cannot_be_applied_to_multiple_get_Slashset_accessors_of_the_same_name: DiagnosticMessage; - All_files_must_be_modules_when_the_isolatedModules_flag_is_provided: DiagnosticMessage; - Invalid_use_of_0_Class_definitions_are_automatically_in_strict_mode: DiagnosticMessage; - A_class_declaration_without_the_default_modifier_must_have_a_name: DiagnosticMessage; - Identifier_expected_0_is_a_reserved_word_in_strict_mode: DiagnosticMessage; - Identifier_expected_0_is_a_reserved_word_in_strict_mode_Class_definitions_are_automatically_in_strict_mode: DiagnosticMessage; - Identifier_expected_0_is_a_reserved_word_in_strict_mode_Modules_are_automatically_in_strict_mode: DiagnosticMessage; - Invalid_use_of_0_Modules_are_automatically_in_strict_mode: DiagnosticMessage; - Identifier_expected_esModule_is_reserved_as_an_exported_marker_when_transforming_ECMAScript_modules: DiagnosticMessage; - Export_assignment_is_not_supported_when_module_flag_is_system: DiagnosticMessage; - Experimental_support_for_decorators_is_a_feature_that_is_subject_to_change_in_a_future_release_Set_the_experimentalDecorators_option_in_your_tsconfig_or_jsconfig_to_remove_this_warning: DiagnosticMessage; - Generators_are_only_available_when_targeting_ECMAScript_2015_or_higher: DiagnosticMessage; - Generators_are_not_allowed_in_an_ambient_context: DiagnosticMessage; - An_overload_signature_cannot_be_declared_as_a_generator: DiagnosticMessage; - _0_tag_already_specified: DiagnosticMessage; - Signature_0_must_be_a_type_predicate: DiagnosticMessage; - Cannot_find_parameter_0: DiagnosticMessage; - Type_predicate_0_is_not_assignable_to_1: DiagnosticMessage; - Parameter_0_is_not_in_the_same_position_as_parameter_1: DiagnosticMessage; - A_type_predicate_is_only_allowed_in_return_type_position_for_functions_and_methods: DiagnosticMessage; - A_type_predicate_cannot_reference_a_rest_parameter: DiagnosticMessage; - A_type_predicate_cannot_reference_element_0_in_a_binding_pattern: DiagnosticMessage; - An_export_assignment_can_only_be_used_in_a_module: DiagnosticMessage; - An_import_declaration_can_only_be_used_in_a_namespace_or_module: DiagnosticMessage; - An_export_declaration_can_only_be_used_in_a_module: DiagnosticMessage; - An_ambient_module_declaration_is_only_allowed_at_the_top_level_in_a_file: DiagnosticMessage; - A_namespace_declaration_is_only_allowed_in_a_namespace_or_module: DiagnosticMessage; - The_return_type_of_a_property_decorator_function_must_be_either_void_or_any: DiagnosticMessage; - The_return_type_of_a_parameter_decorator_function_must_be_either_void_or_any: DiagnosticMessage; - Unable_to_resolve_signature_of_class_decorator_when_called_as_an_expression: DiagnosticMessage; - Unable_to_resolve_signature_of_parameter_decorator_when_called_as_an_expression: DiagnosticMessage; - Unable_to_resolve_signature_of_property_decorator_when_called_as_an_expression: DiagnosticMessage; - Unable_to_resolve_signature_of_method_decorator_when_called_as_an_expression: DiagnosticMessage; - abstract_modifier_can_only_appear_on_a_class_method_or_property_declaration: DiagnosticMessage; - _0_modifier_cannot_be_used_with_1_modifier: DiagnosticMessage; - Abstract_methods_can_only_appear_within_an_abstract_class: DiagnosticMessage; - Method_0_cannot_have_an_implementation_because_it_is_marked_abstract: DiagnosticMessage; - An_interface_property_cannot_have_an_initializer: DiagnosticMessage; - A_type_literal_property_cannot_have_an_initializer: DiagnosticMessage; - A_class_member_cannot_have_the_0_keyword: DiagnosticMessage; - A_decorator_can_only_decorate_a_method_implementation_not_an_overload: DiagnosticMessage; - Function_declarations_are_not_allowed_inside_blocks_in_strict_mode_when_targeting_ES3_or_ES5: DiagnosticMessage; - Function_declarations_are_not_allowed_inside_blocks_in_strict_mode_when_targeting_ES3_or_ES5_Class_definitions_are_automatically_in_strict_mode: DiagnosticMessage; - Function_declarations_are_not_allowed_inside_blocks_in_strict_mode_when_targeting_ES3_or_ES5_Modules_are_automatically_in_strict_mode: DiagnosticMessage; - _0_tag_cannot_be_used_independently_as_a_top_level_JSDoc_tag: DiagnosticMessage; - A_const_initializer_in_an_ambient_context_must_be_a_string_or_numeric_literal_or_literal_enum_reference: DiagnosticMessage; - A_definite_assignment_assertion_is_not_permitted_in_this_context: DiagnosticMessage; - A_rest_element_must_be_last_in_a_tuple_type: DiagnosticMessage; - A_required_element_cannot_follow_an_optional_element: DiagnosticMessage; - Definite_assignment_assertions_can_only_be_used_along_with_a_type_annotation: DiagnosticMessage; - Module_0_can_only_be_default_imported_using_the_1_flag: DiagnosticMessage; - Keywords_cannot_contain_escape_characters: DiagnosticMessage; - with_statements_are_not_allowed_in_an_async_function_block: DiagnosticMessage; - await_expression_is_only_allowed_within_an_async_function: DiagnosticMessage; - can_only_be_used_in_an_object_literal_property_inside_a_destructuring_assignment: DiagnosticMessage; - The_body_of_an_if_statement_cannot_be_the_empty_statement: DiagnosticMessage; - Global_module_exports_may_only_appear_in_module_files: DiagnosticMessage; - Global_module_exports_may_only_appear_in_declaration_files: DiagnosticMessage; - Global_module_exports_may_only_appear_at_top_level: DiagnosticMessage; - A_parameter_property_cannot_be_declared_using_a_rest_parameter: DiagnosticMessage; - An_abstract_accessor_cannot_have_an_implementation: DiagnosticMessage; - A_default_export_can_only_be_used_in_an_ECMAScript_style_module: DiagnosticMessage; - Type_of_await_operand_must_either_be_a_valid_promise_or_must_not_contain_a_callable_then_member: DiagnosticMessage; - Type_of_yield_operand_in_an_async_generator_must_either_be_a_valid_promise_or_must_not_contain_a_callable_then_member: DiagnosticMessage; - Type_of_iterated_elements_of_a_yield_Asterisk_operand_must_either_be_a_valid_promise_or_must_not_contain_a_callable_then_member: DiagnosticMessage; - Dynamic_import_is_only_supported_when_module_flag_is_commonjs_or_esNext: DiagnosticMessage; - Dynamic_import_must_have_one_specifier_as_an_argument: DiagnosticMessage; - Specifier_of_dynamic_import_cannot_be_spread_element: DiagnosticMessage; - Dynamic_import_cannot_have_type_arguments: DiagnosticMessage; - String_literal_with_double_quotes_expected: DiagnosticMessage; - Property_value_can_only_be_string_literal_numeric_literal_true_false_null_object_literal_or_array_literal: DiagnosticMessage; - _0_accepts_too_few_arguments_to_be_used_as_a_decorator_here_Did_you_mean_to_call_it_first_and_write_0: DiagnosticMessage; - A_property_of_an_interface_or_type_literal_whose_type_is_a_unique_symbol_type_must_be_readonly: DiagnosticMessage; - A_property_of_a_class_whose_type_is_a_unique_symbol_type_must_be_both_static_and_readonly: DiagnosticMessage; - A_variable_whose_type_is_a_unique_symbol_type_must_be_const: DiagnosticMessage; - unique_symbol_types_may_not_be_used_on_a_variable_declaration_with_a_binding_name: DiagnosticMessage; - unique_symbol_types_are_only_allowed_on_variables_in_a_variable_statement: DiagnosticMessage; - unique_symbol_types_are_not_allowed_here: DiagnosticMessage; - An_index_signature_parameter_type_cannot_be_a_type_alias_Consider_writing_0_Colon_1_Colon_2_instead: DiagnosticMessage; - An_index_signature_parameter_type_cannot_be_a_union_type_Consider_using_a_mapped_object_type_instead: DiagnosticMessage; - infer_declarations_are_only_permitted_in_the_extends_clause_of_a_conditional_type: DiagnosticMessage; - Module_0_does_not_refer_to_a_value_but_is_used_as_a_value_here: DiagnosticMessage; - Module_0_does_not_refer_to_a_type_but_is_used_as_a_type_here_Did_you_mean_typeof_import_0: DiagnosticMessage; - Type_arguments_cannot_be_used_here: DiagnosticMessage; - The_import_meta_meta_property_is_only_allowed_when_the_module_option_is_esnext_or_system: DiagnosticMessage; - A_label_is_not_allowed_here: DiagnosticMessage; - An_expression_of_type_void_cannot_be_tested_for_truthiness: DiagnosticMessage; - This_parameter_is_not_allowed_with_use_strict_directive: DiagnosticMessage; - use_strict_directive_cannot_be_used_with_non_simple_parameter_list: DiagnosticMessage; - Non_simple_parameter_declared_here: DiagnosticMessage; - use_strict_directive_used_here: DiagnosticMessage; - Print_the_final_configuration_instead_of_building: DiagnosticMessage; - An_identifier_or_keyword_cannot_immediately_follow_a_numeric_literal: DiagnosticMessage; - A_bigint_literal_cannot_use_exponential_notation: DiagnosticMessage; - A_bigint_literal_must_be_an_integer: DiagnosticMessage; - readonly_type_modifier_is_only_permitted_on_array_and_tuple_literal_types: DiagnosticMessage; - A_const_assertions_can_only_be_applied_to_references_to_enum_members_or_string_number_boolean_array_or_object_literals: DiagnosticMessage; - Did_you_mean_to_mark_this_function_as_async: DiagnosticMessage; - Duplicate_identifier_0: DiagnosticMessage; - Initializer_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor: DiagnosticMessage; - Static_members_cannot_reference_class_type_parameters: DiagnosticMessage; - Circular_definition_of_import_alias_0: DiagnosticMessage; - Cannot_find_name_0: DiagnosticMessage; - Module_0_has_no_exported_member_1: DiagnosticMessage; - File_0_is_not_a_module: DiagnosticMessage; - Cannot_find_module_0: DiagnosticMessage; - Module_0_has_already_exported_a_member_named_1_Consider_explicitly_re_exporting_to_resolve_the_ambiguity: DiagnosticMessage; - An_export_assignment_cannot_be_used_in_a_module_with_other_exported_elements: DiagnosticMessage; - Type_0_recursively_references_itself_as_a_base_type: DiagnosticMessage; - A_class_may_only_extend_another_class: DiagnosticMessage; - An_interface_can_only_extend_an_object_type_or_intersection_of_object_types_with_statically_known_members: DiagnosticMessage; - Type_parameter_0_has_a_circular_constraint: DiagnosticMessage; - Generic_type_0_requires_1_type_argument_s: DiagnosticMessage; - Type_0_is_not_generic: DiagnosticMessage; - Global_type_0_must_be_a_class_or_interface_type: DiagnosticMessage; - Global_type_0_must_have_1_type_parameter_s: DiagnosticMessage; - Cannot_find_global_type_0: DiagnosticMessage; - Named_property_0_of_types_1_and_2_are_not_identical: DiagnosticMessage; - Interface_0_cannot_simultaneously_extend_types_1_and_2: DiagnosticMessage; - Excessive_stack_depth_comparing_types_0_and_1: DiagnosticMessage; - Type_0_is_not_assignable_to_type_1: DiagnosticMessage; - Cannot_redeclare_exported_variable_0: DiagnosticMessage; - Property_0_is_missing_in_type_1: DiagnosticMessage; - Property_0_is_private_in_type_1_but_not_in_type_2: DiagnosticMessage; - Types_of_property_0_are_incompatible: DiagnosticMessage; - Property_0_is_optional_in_type_1_but_required_in_type_2: DiagnosticMessage; - Types_of_parameters_0_and_1_are_incompatible: DiagnosticMessage; - Index_signature_is_missing_in_type_0: DiagnosticMessage; - Index_signatures_are_incompatible: DiagnosticMessage; - this_cannot_be_referenced_in_a_module_or_namespace_body: DiagnosticMessage; - this_cannot_be_referenced_in_current_location: DiagnosticMessage; - this_cannot_be_referenced_in_constructor_arguments: DiagnosticMessage; - this_cannot_be_referenced_in_a_static_property_initializer: DiagnosticMessage; - super_can_only_be_referenced_in_a_derived_class: DiagnosticMessage; - super_cannot_be_referenced_in_constructor_arguments: DiagnosticMessage; - Super_calls_are_not_permitted_outside_constructors_or_in_nested_functions_inside_constructors: DiagnosticMessage; - super_property_access_is_permitted_only_in_a_constructor_member_function_or_member_accessor_of_a_derived_class: DiagnosticMessage; - Property_0_does_not_exist_on_type_1: DiagnosticMessage; - Only_public_and_protected_methods_of_the_base_class_are_accessible_via_the_super_keyword: DiagnosticMessage; - Property_0_is_private_and_only_accessible_within_class_1: DiagnosticMessage; - An_index_expression_argument_must_be_of_type_string_number_symbol_or_any: DiagnosticMessage; - This_syntax_requires_an_imported_helper_named_1_but_module_0_has_no_exported_member_1: DiagnosticMessage; - Type_0_does_not_satisfy_the_constraint_1: DiagnosticMessage; - Argument_of_type_0_is_not_assignable_to_parameter_of_type_1: DiagnosticMessage; - Call_target_does_not_contain_any_signatures: DiagnosticMessage; - Untyped_function_calls_may_not_accept_type_arguments: DiagnosticMessage; - Value_of_type_0_is_not_callable_Did_you_mean_to_include_new: DiagnosticMessage; - This_expression_is_not_callable: DiagnosticMessage; - Only_a_void_function_can_be_called_with_the_new_keyword: DiagnosticMessage; - This_expression_is_not_constructable: DiagnosticMessage; - Conversion_of_type_0_to_type_1_may_be_a_mistake_because_neither_type_sufficiently_overlaps_with_the_other_If_this_was_intentional_convert_the_expression_to_unknown_first: DiagnosticMessage; - Object_literal_may_only_specify_known_properties_and_0_does_not_exist_in_type_1: DiagnosticMessage; - This_syntax_requires_an_imported_helper_but_module_0_cannot_be_found: DiagnosticMessage; - A_function_whose_declared_type_is_neither_void_nor_any_must_return_a_value: DiagnosticMessage; - An_arithmetic_operand_must_be_of_type_any_number_bigint_or_an_enum_type: DiagnosticMessage; - The_operand_of_an_increment_or_decrement_operator_must_be_a_variable_or_a_property_access: DiagnosticMessage; - The_left_hand_side_of_an_instanceof_expression_must_be_of_type_any_an_object_type_or_a_type_parameter: DiagnosticMessage; - The_right_hand_side_of_an_instanceof_expression_must_be_of_type_any_or_of_a_type_assignable_to_the_Function_interface_type: DiagnosticMessage; - The_left_hand_side_of_an_in_expression_must_be_of_type_any_string_number_or_symbol: DiagnosticMessage; - The_right_hand_side_of_an_in_expression_must_be_of_type_any_an_object_type_or_a_type_parameter: DiagnosticMessage; - The_left_hand_side_of_an_arithmetic_operation_must_be_of_type_any_number_bigint_or_an_enum_type: DiagnosticMessage; - The_right_hand_side_of_an_arithmetic_operation_must_be_of_type_any_number_bigint_or_an_enum_type: DiagnosticMessage; - The_left_hand_side_of_an_assignment_expression_must_be_a_variable_or_a_property_access: DiagnosticMessage; - Operator_0_cannot_be_applied_to_types_1_and_2: DiagnosticMessage; - Function_lacks_ending_return_statement_and_return_type_does_not_include_undefined: DiagnosticMessage; - This_condition_will_always_return_0_since_the_types_1_and_2_have_no_overlap: DiagnosticMessage; - Type_parameter_name_cannot_be_0: DiagnosticMessage; - A_parameter_property_is_only_allowed_in_a_constructor_implementation: DiagnosticMessage; - A_rest_parameter_must_be_of_an_array_type: DiagnosticMessage; - A_parameter_initializer_is_only_allowed_in_a_function_or_constructor_implementation: DiagnosticMessage; - Parameter_0_cannot_be_referenced_in_its_initializer: DiagnosticMessage; - Initializer_of_parameter_0_cannot_reference_identifier_1_declared_after_it: DiagnosticMessage; - Duplicate_string_index_signature: DiagnosticMessage; - Duplicate_number_index_signature: DiagnosticMessage; - A_super_call_must_be_the_first_statement_in_the_constructor_when_a_class_contains_initialized_properties_or_has_parameter_properties: DiagnosticMessage; - Constructors_for_derived_classes_must_contain_a_super_call: DiagnosticMessage; - A_get_accessor_must_return_a_value: DiagnosticMessage; - Getter_and_setter_accessors_do_not_agree_in_visibility: DiagnosticMessage; - get_and_set_accessor_must_have_the_same_type: DiagnosticMessage; - A_signature_with_an_implementation_cannot_use_a_string_literal_type: DiagnosticMessage; - Specialized_overload_signature_is_not_assignable_to_any_non_specialized_signature: DiagnosticMessage; - Overload_signatures_must_all_be_exported_or_non_exported: DiagnosticMessage; - Overload_signatures_must_all_be_ambient_or_non_ambient: DiagnosticMessage; - Overload_signatures_must_all_be_public_private_or_protected: DiagnosticMessage; - Overload_signatures_must_all_be_optional_or_required: DiagnosticMessage; - Function_overload_must_be_static: DiagnosticMessage; - Function_overload_must_not_be_static: DiagnosticMessage; - Function_implementation_name_must_be_0: DiagnosticMessage; - Constructor_implementation_is_missing: DiagnosticMessage; - Function_implementation_is_missing_or_not_immediately_following_the_declaration: DiagnosticMessage; - Multiple_constructor_implementations_are_not_allowed: DiagnosticMessage; - Duplicate_function_implementation: DiagnosticMessage; - This_overload_signature_is_not_compatible_with_its_implementation_signature: DiagnosticMessage; - Individual_declarations_in_merged_declaration_0_must_be_all_exported_or_all_local: DiagnosticMessage; - Duplicate_identifier_arguments_Compiler_uses_arguments_to_initialize_rest_parameters: DiagnosticMessage; - Declaration_name_conflicts_with_built_in_global_identifier_0: DiagnosticMessage; - Duplicate_identifier_this_Compiler_uses_variable_declaration_this_to_capture_this_reference: DiagnosticMessage; - Expression_resolves_to_variable_declaration_this_that_compiler_uses_to_capture_this_reference: DiagnosticMessage; - Duplicate_identifier_super_Compiler_uses_super_to_capture_base_class_reference: DiagnosticMessage; - Expression_resolves_to_super_that_compiler_uses_to_capture_base_class_reference: DiagnosticMessage; - Subsequent_variable_declarations_must_have_the_same_type_Variable_0_must_be_of_type_1_but_here_has_type_2: DiagnosticMessage; - The_left_hand_side_of_a_for_in_statement_cannot_use_a_type_annotation: DiagnosticMessage; - The_left_hand_side_of_a_for_in_statement_must_be_of_type_string_or_any: DiagnosticMessage; - The_left_hand_side_of_a_for_in_statement_must_be_a_variable_or_a_property_access: DiagnosticMessage; - The_right_hand_side_of_a_for_in_statement_must_be_of_type_any_an_object_type_or_a_type_parameter_but_here_has_type_0: DiagnosticMessage; - Setters_cannot_return_a_value: DiagnosticMessage; - Return_type_of_constructor_signature_must_be_assignable_to_the_instance_type_of_the_class: DiagnosticMessage; - The_with_statement_is_not_supported_All_symbols_in_a_with_block_will_have_type_any: DiagnosticMessage; - Property_0_of_type_1_is_not_assignable_to_string_index_type_2: DiagnosticMessage; - Property_0_of_type_1_is_not_assignable_to_numeric_index_type_2: DiagnosticMessage; - Numeric_index_type_0_is_not_assignable_to_string_index_type_1: DiagnosticMessage; - Class_name_cannot_be_0: DiagnosticMessage; - Class_0_incorrectly_extends_base_class_1: DiagnosticMessage; - Property_0_in_type_1_is_not_assignable_to_the_same_property_in_base_type_2: DiagnosticMessage; - Class_static_side_0_incorrectly_extends_base_class_static_side_1: DiagnosticMessage; - Type_of_computed_property_s_value_is_0_which_is_not_assignable_to_type_1: DiagnosticMessage; - Class_0_incorrectly_implements_interface_1: DiagnosticMessage; - A_class_can_only_implement_an_object_type_or_intersection_of_object_types_with_statically_known_members: DiagnosticMessage; - Class_0_defines_instance_member_function_1_but_extended_class_2_defines_it_as_instance_member_accessor: DiagnosticMessage; - Class_0_defines_instance_member_function_1_but_extended_class_2_defines_it_as_instance_member_property: DiagnosticMessage; - Class_0_defines_instance_member_property_1_but_extended_class_2_defines_it_as_instance_member_function: DiagnosticMessage; - Class_0_defines_instance_member_accessor_1_but_extended_class_2_defines_it_as_instance_member_function: DiagnosticMessage; - Interface_name_cannot_be_0: DiagnosticMessage; - All_declarations_of_0_must_have_identical_type_parameters: DiagnosticMessage; - Interface_0_incorrectly_extends_interface_1: DiagnosticMessage; - Enum_name_cannot_be_0: DiagnosticMessage; - In_an_enum_with_multiple_declarations_only_one_declaration_can_omit_an_initializer_for_its_first_enum_element: DiagnosticMessage; - A_namespace_declaration_cannot_be_in_a_different_file_from_a_class_or_function_with_which_it_is_merged: DiagnosticMessage; - A_namespace_declaration_cannot_be_located_prior_to_a_class_or_function_with_which_it_is_merged: DiagnosticMessage; - Ambient_modules_cannot_be_nested_in_other_modules_or_namespaces: DiagnosticMessage; - Ambient_module_declaration_cannot_specify_relative_module_name: DiagnosticMessage; - Module_0_is_hidden_by_a_local_declaration_with_the_same_name: DiagnosticMessage; - Import_name_cannot_be_0: DiagnosticMessage; - Import_or_export_declaration_in_an_ambient_module_declaration_cannot_reference_module_through_relative_module_name: DiagnosticMessage; - Import_declaration_conflicts_with_local_declaration_of_0: DiagnosticMessage; - Duplicate_identifier_0_Compiler_reserves_name_1_in_top_level_scope_of_a_module: DiagnosticMessage; - Types_have_separate_declarations_of_a_private_property_0: DiagnosticMessage; - Property_0_is_protected_but_type_1_is_not_a_class_derived_from_2: DiagnosticMessage; - Property_0_is_protected_in_type_1_but_public_in_type_2: DiagnosticMessage; - Property_0_is_protected_and_only_accessible_within_class_1_and_its_subclasses: DiagnosticMessage; - Property_0_is_protected_and_only_accessible_through_an_instance_of_class_1: DiagnosticMessage; - The_0_operator_is_not_allowed_for_boolean_types_Consider_using_1_instead: DiagnosticMessage; - Block_scoped_variable_0_used_before_its_declaration: DiagnosticMessage; - Class_0_used_before_its_declaration: DiagnosticMessage; - Enum_0_used_before_its_declaration: DiagnosticMessage; - Cannot_redeclare_block_scoped_variable_0: DiagnosticMessage; - An_enum_member_cannot_have_a_numeric_name: DiagnosticMessage; - The_type_argument_for_type_parameter_0_cannot_be_inferred_from_the_usage_Consider_specifying_the_type_arguments_explicitly: DiagnosticMessage; - Variable_0_is_used_before_being_assigned: DiagnosticMessage; - Type_argument_candidate_1_is_not_a_valid_type_argument_because_it_is_not_a_supertype_of_candidate_0: DiagnosticMessage; - Type_alias_0_circularly_references_itself: DiagnosticMessage; - Type_alias_name_cannot_be_0: DiagnosticMessage; - An_AMD_module_cannot_have_multiple_name_assignments: DiagnosticMessage; - Type_0_is_not_an_array_type: DiagnosticMessage; - A_rest_element_must_be_last_in_a_destructuring_pattern: DiagnosticMessage; - A_binding_pattern_parameter_cannot_be_optional_in_an_implementation_signature: DiagnosticMessage; - A_computed_property_name_must_be_of_type_string_number_symbol_or_any: DiagnosticMessage; - this_cannot_be_referenced_in_a_computed_property_name: DiagnosticMessage; - super_cannot_be_referenced_in_a_computed_property_name: DiagnosticMessage; - A_computed_property_name_cannot_reference_a_type_parameter_from_its_containing_type: DiagnosticMessage; - Cannot_find_global_value_0: DiagnosticMessage; - The_0_operator_cannot_be_applied_to_type_symbol: DiagnosticMessage; - Symbol_reference_does_not_refer_to_the_global_Symbol_constructor_object: DiagnosticMessage; - A_computed_property_name_of_the_form_0_must_be_of_type_symbol: DiagnosticMessage; - Spread_operator_in_new_expressions_is_only_available_when_targeting_ECMAScript_5_and_higher: DiagnosticMessage; - Enum_declarations_must_all_be_const_or_non_const: DiagnosticMessage; - const_enum_member_initializers_can_only_contain_literal_values_and_other_computed_enum_values: DiagnosticMessage; - const_enums_can_only_be_used_in_property_or_index_access_expressions_or_the_right_hand_side_of_an_import_declaration_or_export_assignment_or_type_query: DiagnosticMessage; - A_const_enum_member_can_only_be_accessed_using_a_string_literal: DiagnosticMessage; - const_enum_member_initializer_was_evaluated_to_a_non_finite_value: DiagnosticMessage; - const_enum_member_initializer_was_evaluated_to_disallowed_value_NaN: DiagnosticMessage; - Property_0_does_not_exist_on_const_enum_1: DiagnosticMessage; - let_is_not_allowed_to_be_used_as_a_name_in_let_or_const_declarations: DiagnosticMessage; - Cannot_initialize_outer_scoped_variable_0_in_the_same_scope_as_block_scoped_declaration_1: DiagnosticMessage; - The_left_hand_side_of_a_for_of_statement_cannot_use_a_type_annotation: DiagnosticMessage; - Export_declaration_conflicts_with_exported_declaration_of_0: DiagnosticMessage; - The_left_hand_side_of_a_for_of_statement_must_be_a_variable_or_a_property_access: DiagnosticMessage; - Type_0_must_have_a_Symbol_iterator_method_that_returns_an_iterator: DiagnosticMessage; - An_iterator_must_have_a_next_method: DiagnosticMessage; - The_type_returned_by_the_0_method_of_an_iterator_must_have_a_value_property: DiagnosticMessage; - The_left_hand_side_of_a_for_in_statement_cannot_be_a_destructuring_pattern: DiagnosticMessage; - Cannot_redeclare_identifier_0_in_catch_clause: DiagnosticMessage; - Tuple_type_0_of_length_1_has_no_element_at_index_2: DiagnosticMessage; - Using_a_string_in_a_for_of_statement_is_only_supported_in_ECMAScript_5_and_higher: DiagnosticMessage; - Type_0_is_not_an_array_type_or_a_string_type: DiagnosticMessage; - The_arguments_object_cannot_be_referenced_in_an_arrow_function_in_ES3_and_ES5_Consider_using_a_standard_function_expression: DiagnosticMessage; - This_module_can_only_be_referenced_with_ECMAScript_imports_Slashexports_by_turning_on_the_0_flag_and_referencing_its_default_export: DiagnosticMessage; - Module_0_uses_export_and_cannot_be_used_with_export_Asterisk: DiagnosticMessage; - An_interface_can_only_extend_an_identifier_Slashqualified_name_with_optional_type_arguments: DiagnosticMessage; - A_class_can_only_implement_an_identifier_Slashqualified_name_with_optional_type_arguments: DiagnosticMessage; - A_rest_element_cannot_contain_a_binding_pattern: DiagnosticMessage; - _0_is_referenced_directly_or_indirectly_in_its_own_type_annotation: DiagnosticMessage; - Cannot_find_namespace_0: DiagnosticMessage; - Type_0_must_have_a_Symbol_asyncIterator_method_that_returns_an_async_iterator: DiagnosticMessage; - A_generator_cannot_have_a_void_type_annotation: DiagnosticMessage; - _0_is_referenced_directly_or_indirectly_in_its_own_base_expression: DiagnosticMessage; - Type_0_is_not_a_constructor_function_type: DiagnosticMessage; - No_base_constructor_has_the_specified_number_of_type_arguments: DiagnosticMessage; - Base_constructor_return_type_0_is_not_an_object_type_or_intersection_of_object_types_with_statically_known_members: DiagnosticMessage; - Base_constructors_must_all_have_the_same_return_type: DiagnosticMessage; - Cannot_create_an_instance_of_an_abstract_class: DiagnosticMessage; - Overload_signatures_must_all_be_abstract_or_non_abstract: DiagnosticMessage; - Abstract_method_0_in_class_1_cannot_be_accessed_via_super_expression: DiagnosticMessage; - Classes_containing_abstract_methods_must_be_marked_abstract: DiagnosticMessage; - Non_abstract_class_0_does_not_implement_inherited_abstract_member_1_from_class_2: DiagnosticMessage; - All_declarations_of_an_abstract_method_must_be_consecutive: DiagnosticMessage; - Cannot_assign_an_abstract_constructor_type_to_a_non_abstract_constructor_type: DiagnosticMessage; - A_this_based_type_guard_is_not_compatible_with_a_parameter_based_type_guard: DiagnosticMessage; - An_async_iterator_must_have_a_next_method: DiagnosticMessage; - Duplicate_identifier_0_Compiler_uses_declaration_1_to_support_async_functions: DiagnosticMessage; - Expression_resolves_to_variable_declaration_0_that_compiler_uses_to_support_async_functions: DiagnosticMessage; - The_arguments_object_cannot_be_referenced_in_an_async_function_or_method_in_ES3_and_ES5_Consider_using_a_standard_function_or_method: DiagnosticMessage; - yield_expressions_cannot_be_used_in_a_parameter_initializer: DiagnosticMessage; - await_expressions_cannot_be_used_in_a_parameter_initializer: DiagnosticMessage; - Initializer_provides_no_value_for_this_binding_element_and_the_binding_element_has_no_default_value: DiagnosticMessage; - A_this_type_is_available_only_in_a_non_static_member_of_a_class_or_interface: DiagnosticMessage; - The_inferred_type_of_0_references_an_inaccessible_1_type_A_type_annotation_is_necessary: DiagnosticMessage; - A_module_cannot_have_multiple_default_exports: DiagnosticMessage; - Duplicate_identifier_0_Compiler_reserves_name_1_in_top_level_scope_of_a_module_containing_async_functions: DiagnosticMessage; - Property_0_is_incompatible_with_index_signature: DiagnosticMessage; - Object_is_possibly_null: DiagnosticMessage; - Object_is_possibly_undefined: DiagnosticMessage; - Object_is_possibly_null_or_undefined: DiagnosticMessage; - A_function_returning_never_cannot_have_a_reachable_end_point: DiagnosticMessage; - Enum_type_0_has_members_with_initializers_that_are_not_literals: DiagnosticMessage; - Type_0_cannot_be_used_to_index_type_1: DiagnosticMessage; - Type_0_has_no_matching_index_signature_for_type_1: DiagnosticMessage; - Type_0_cannot_be_used_as_an_index_type: DiagnosticMessage; - Cannot_assign_to_0_because_it_is_not_a_variable: DiagnosticMessage; - Cannot_assign_to_0_because_it_is_a_read_only_property: DiagnosticMessage; - The_target_of_an_assignment_must_be_a_variable_or_a_property_access: DiagnosticMessage; - Index_signature_in_type_0_only_permits_reading: DiagnosticMessage; - Duplicate_identifier_newTarget_Compiler_uses_variable_declaration_newTarget_to_capture_new_target_meta_property_reference: DiagnosticMessage; - Expression_resolves_to_variable_declaration_newTarget_that_compiler_uses_to_capture_new_target_meta_property_reference: DiagnosticMessage; - A_mixin_class_must_have_a_constructor_with_a_single_rest_parameter_of_type_any: DiagnosticMessage; - Property_0_has_conflicting_declarations_and_is_inaccessible_in_type_1: DiagnosticMessage; - The_type_returned_by_the_0_method_of_an_async_iterator_must_be_a_promise_for_a_type_with_a_value_property: DiagnosticMessage; - Type_0_is_not_an_array_type_or_does_not_have_a_Symbol_iterator_method_that_returns_an_iterator: DiagnosticMessage; - Type_0_is_not_an_array_type_or_a_string_type_or_does_not_have_a_Symbol_iterator_method_that_returns_an_iterator: DiagnosticMessage; - Property_0_does_not_exist_on_type_1_Did_you_mean_2: DiagnosticMessage; - Cannot_find_name_0_Did_you_mean_1: DiagnosticMessage; - Computed_values_are_not_permitted_in_an_enum_with_string_valued_members: DiagnosticMessage; - Expected_0_arguments_but_got_1: DiagnosticMessage; - Expected_at_least_0_arguments_but_got_1: DiagnosticMessage; - Expected_0_arguments_but_got_1_or_more: DiagnosticMessage; - Expected_at_least_0_arguments_but_got_1_or_more: DiagnosticMessage; - Expected_0_type_arguments_but_got_1: DiagnosticMessage; - Type_0_has_no_properties_in_common_with_type_1: DiagnosticMessage; - Value_of_type_0_has_no_properties_in_common_with_type_1_Did_you_mean_to_call_it: DiagnosticMessage; - Object_literal_may_only_specify_known_properties_but_0_does_not_exist_in_type_1_Did_you_mean_to_write_2: DiagnosticMessage; - Base_class_expressions_cannot_reference_class_type_parameters: DiagnosticMessage; - The_containing_function_or_module_body_is_too_large_for_control_flow_analysis: DiagnosticMessage; - Property_0_has_no_initializer_and_is_not_definitely_assigned_in_the_constructor: DiagnosticMessage; - Property_0_is_used_before_being_assigned: DiagnosticMessage; - A_rest_element_cannot_have_a_property_name: DiagnosticMessage; - Enum_declarations_can_only_merge_with_namespace_or_other_enum_declarations: DiagnosticMessage; - Type_0_is_not_an_array_type_or_a_string_type_Use_compiler_option_downlevelIteration_to_allow_iterating_of_iterators: DiagnosticMessage; - Object_is_of_type_unknown: DiagnosticMessage; - Rest_signatures_are_incompatible: DiagnosticMessage; - Property_0_is_incompatible_with_rest_element_type: DiagnosticMessage; - A_rest_element_type_must_be_an_array_type: DiagnosticMessage; - No_overload_expects_0_arguments_but_overloads_do_exist_that_expect_either_1_or_2_arguments: DiagnosticMessage; - Property_0_is_a_static_member_of_type_1: DiagnosticMessage; - Return_type_annotation_circularly_references_itself: DiagnosticMessage; - Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_node_Try_npm_i_types_Slashnode: DiagnosticMessage; - Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_jQuery_Try_npm_i_types_Slashjquery: DiagnosticMessage; - Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_a_test_runner_Try_npm_i_types_Slashjest_or_npm_i_types_Slashmocha: DiagnosticMessage; - Cannot_find_name_0_Do_you_need_to_change_your_target_library_Try_changing_the_lib_compiler_option_to_es2015_or_later: DiagnosticMessage; - Cannot_find_name_0_Do_you_need_to_change_your_target_library_Try_changing_the_lib_compiler_option_to_include_dom: DiagnosticMessage; - _0_only_refers_to_a_type_but_is_being_used_as_a_value_here_Do_you_need_to_change_your_target_library_Try_changing_the_lib_compiler_option_to_es2015_or_later: DiagnosticMessage; - Enum_type_0_circularly_references_itself: DiagnosticMessage; - JSDoc_type_0_circularly_references_itself: DiagnosticMessage; - Cannot_assign_to_0_because_it_is_a_constant: DiagnosticMessage; - Type_instantiation_is_excessively_deep_and_possibly_infinite: DiagnosticMessage; - Expression_produces_a_union_type_that_is_too_complex_to_represent: DiagnosticMessage; - Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_node_Try_npm_i_types_Slashnode_and_then_add_node_to_the_types_field_in_your_tsconfig: DiagnosticMessage; - Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_jQuery_Try_npm_i_types_Slashjquery_and_then_add_jquery_to_the_types_field_in_your_tsconfig: DiagnosticMessage; - Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_a_test_runner_Try_npm_i_types_Slashjest_or_npm_i_types_Slashmocha_and_then_add_jest_or_mocha_to_the_types_field_in_your_tsconfig: DiagnosticMessage; - This_module_is_declared_with_using_export_and_can_only_be_used_with_a_default_import_when_using_the_0_flag: DiagnosticMessage; - JSX_element_attributes_type_0_may_not_be_a_union_type: DiagnosticMessage; - The_return_type_of_a_JSX_element_constructor_must_return_an_object_type: DiagnosticMessage; - JSX_element_implicitly_has_type_any_because_the_global_type_JSX_Element_does_not_exist: DiagnosticMessage; - Property_0_in_type_1_is_not_assignable_to_type_2: DiagnosticMessage; - JSX_element_type_0_does_not_have_any_construct_or_call_signatures: DiagnosticMessage; - JSX_element_type_0_is_not_a_constructor_function_for_JSX_elements: DiagnosticMessage; - Property_0_of_JSX_spread_attribute_is_not_assignable_to_target_property: DiagnosticMessage; - JSX_element_class_does_not_support_attributes_because_it_does_not_have_a_0_property: DiagnosticMessage; - The_global_type_JSX_0_may_not_have_more_than_one_property: DiagnosticMessage; - JSX_spread_child_must_be_an_array_type: DiagnosticMessage; - Cannot_augment_module_0_with_value_exports_because_it_resolves_to_a_non_module_entity: DiagnosticMessage; - A_member_initializer_in_a_enum_declaration_cannot_reference_members_declared_after_it_including_members_defined_in_other_enums: DiagnosticMessage; - Merged_declaration_0_cannot_include_a_default_export_declaration_Consider_adding_a_separate_export_default_0_declaration_instead: DiagnosticMessage; - Non_abstract_class_expression_does_not_implement_inherited_abstract_member_0_from_class_1: DiagnosticMessage; - Exported_external_package_typings_file_cannot_contain_tripleslash_references_Please_contact_the_package_author_to_update_the_package_definition: DiagnosticMessage; - Exported_external_package_typings_file_0_is_not_a_module_Please_contact_the_package_author_to_update_the_package_definition: DiagnosticMessage; - JSX_expressions_must_have_one_parent_element: DiagnosticMessage; - Type_0_provides_no_match_for_the_signature_1: DiagnosticMessage; - super_is_only_allowed_in_members_of_object_literal_expressions_when_option_target_is_ES2015_or_higher: DiagnosticMessage; - super_can_only_be_referenced_in_members_of_derived_classes_or_object_literal_expressions: DiagnosticMessage; - Cannot_export_0_Only_local_declarations_can_be_exported_from_a_module: DiagnosticMessage; - Cannot_find_name_0_Did_you_mean_the_static_member_1_0: DiagnosticMessage; - Cannot_find_name_0_Did_you_mean_the_instance_member_this_0: DiagnosticMessage; - Invalid_module_name_in_augmentation_module_0_cannot_be_found: DiagnosticMessage; - Invalid_module_name_in_augmentation_Module_0_resolves_to_an_untyped_module_at_1_which_cannot_be_augmented: DiagnosticMessage; - Exports_and_export_assignments_are_not_permitted_in_module_augmentations: DiagnosticMessage; - Imports_are_not_permitted_in_module_augmentations_Consider_moving_them_to_the_enclosing_external_module: DiagnosticMessage; - export_modifier_cannot_be_applied_to_ambient_modules_and_module_augmentations_since_they_are_always_visible: DiagnosticMessage; - Augmentations_for_the_global_scope_can_only_be_directly_nested_in_external_modules_or_ambient_module_declarations: DiagnosticMessage; - Augmentations_for_the_global_scope_should_have_declare_modifier_unless_they_appear_in_already_ambient_context: DiagnosticMessage; - Cannot_augment_module_0_because_it_resolves_to_a_non_module_entity: DiagnosticMessage; - Cannot_assign_a_0_constructor_type_to_a_1_constructor_type: DiagnosticMessage; - Constructor_of_class_0_is_private_and_only_accessible_within_the_class_declaration: DiagnosticMessage; - Constructor_of_class_0_is_protected_and_only_accessible_within_the_class_declaration: DiagnosticMessage; - Cannot_extend_a_class_0_Class_constructor_is_marked_as_private: DiagnosticMessage; - Accessors_must_both_be_abstract_or_non_abstract: DiagnosticMessage; - A_type_predicate_s_type_must_be_assignable_to_its_parameter_s_type: DiagnosticMessage; - Type_0_is_not_comparable_to_type_1: DiagnosticMessage; - A_function_that_is_called_with_the_new_keyword_cannot_have_a_this_type_that_is_void: DiagnosticMessage; - A_0_parameter_must_be_the_first_parameter: DiagnosticMessage; - A_constructor_cannot_have_a_this_parameter: DiagnosticMessage; - get_and_set_accessor_must_have_the_same_this_type: DiagnosticMessage; - this_implicitly_has_type_any_because_it_does_not_have_a_type_annotation: DiagnosticMessage; - The_this_context_of_type_0_is_not_assignable_to_method_s_this_of_type_1: DiagnosticMessage; - The_this_types_of_each_signature_are_incompatible: DiagnosticMessage; - _0_refers_to_a_UMD_global_but_the_current_file_is_a_module_Consider_adding_an_import_instead: DiagnosticMessage; - All_declarations_of_0_must_have_identical_modifiers: DiagnosticMessage; - Cannot_find_type_definition_file_for_0: DiagnosticMessage; - Cannot_extend_an_interface_0_Did_you_mean_implements: DiagnosticMessage; - An_import_path_cannot_end_with_a_0_extension_Consider_importing_1_instead: DiagnosticMessage; - _0_is_a_primitive_but_1_is_a_wrapper_object_Prefer_using_0_when_possible: DiagnosticMessage; - _0_only_refers_to_a_type_but_is_being_used_as_a_value_here: DiagnosticMessage; - Namespace_0_has_no_exported_member_1: DiagnosticMessage; - Left_side_of_comma_operator_is_unused_and_has_no_side_effects: DiagnosticMessage; - The_Object_type_is_assignable_to_very_few_other_types_Did_you_mean_to_use_the_any_type_instead: DiagnosticMessage; - An_async_function_or_method_must_return_a_Promise_Make_sure_you_have_a_declaration_for_Promise_or_include_ES2015_in_your_lib_option: DiagnosticMessage; - Spread_types_may_only_be_created_from_object_types: DiagnosticMessage; - Static_property_0_conflicts_with_built_in_property_Function_0_of_constructor_function_1: DiagnosticMessage; - Rest_types_may_only_be_created_from_object_types: DiagnosticMessage; - The_target_of_an_object_rest_assignment_must_be_a_variable_or_a_property_access: DiagnosticMessage; - _0_only_refers_to_a_type_but_is_being_used_as_a_namespace_here: DiagnosticMessage; - The_operand_of_a_delete_operator_must_be_a_property_reference: DiagnosticMessage; - The_operand_of_a_delete_operator_cannot_be_a_read_only_property: DiagnosticMessage; - An_async_function_or_method_in_ES5_SlashES3_requires_the_Promise_constructor_Make_sure_you_have_a_declaration_for_the_Promise_constructor_or_include_ES2015_in_your_lib_option: DiagnosticMessage; - Required_type_parameters_may_not_follow_optional_type_parameters: DiagnosticMessage; - Generic_type_0_requires_between_1_and_2_type_arguments: DiagnosticMessage; - Cannot_use_namespace_0_as_a_value: DiagnosticMessage; - Cannot_use_namespace_0_as_a_type: DiagnosticMessage; - _0_are_specified_twice_The_attribute_named_0_will_be_overwritten: DiagnosticMessage; - A_dynamic_import_call_returns_a_Promise_Make_sure_you_have_a_declaration_for_Promise_or_include_ES2015_in_your_lib_option: DiagnosticMessage; - A_dynamic_import_call_in_ES5_SlashES3_requires_the_Promise_constructor_Make_sure_you_have_a_declaration_for_the_Promise_constructor_or_include_ES2015_in_your_lib_option: DiagnosticMessage; - Cannot_access_0_1_because_0_is_a_type_but_not_a_namespace_Did_you_mean_to_retrieve_the_type_of_the_property_1_in_0_with_0_1: DiagnosticMessage; - The_expression_of_an_export_assignment_must_be_an_identifier_or_qualified_name_in_an_ambient_context: DiagnosticMessage; - Abstract_property_0_in_class_1_cannot_be_accessed_in_the_constructor: DiagnosticMessage; - Type_parameter_0_has_a_circular_default: DiagnosticMessage; - Subsequent_property_declarations_must_have_the_same_type_Property_0_must_be_of_type_1_but_here_has_type_2: DiagnosticMessage; - Duplicate_property_0: DiagnosticMessage; - Type_0_is_not_assignable_to_type_1_Two_different_types_with_this_name_exist_but_they_are_unrelated: DiagnosticMessage; - Class_0_incorrectly_implements_class_1_Did_you_mean_to_extend_1_and_inherit_its_members_as_a_subclass: DiagnosticMessage; - Cannot_invoke_an_object_which_is_possibly_null: DiagnosticMessage; - Cannot_invoke_an_object_which_is_possibly_undefined: DiagnosticMessage; - Cannot_invoke_an_object_which_is_possibly_null_or_undefined: DiagnosticMessage; - Module_0_has_no_exported_member_1_Did_you_mean_2: DiagnosticMessage; - Class_name_cannot_be_Object_when_targeting_ES5_with_module_0: DiagnosticMessage; - Cannot_find_lib_definition_for_0: DiagnosticMessage; - Cannot_find_lib_definition_for_0_Did_you_mean_1: DiagnosticMessage; - _0_is_declared_here: DiagnosticMessage; - Property_0_is_used_before_its_initialization: DiagnosticMessage; - An_arrow_function_cannot_have_a_this_parameter: DiagnosticMessage; - Implicit_conversion_of_a_symbol_to_a_string_will_fail_at_runtime_Consider_wrapping_this_expression_in_String: DiagnosticMessage; - Cannot_find_module_0_Consider_using_resolveJsonModule_to_import_module_with_json_extension: DiagnosticMessage; - Property_0_was_also_declared_here: DiagnosticMessage; - It_is_highly_likely_that_you_are_missing_a_semicolon: DiagnosticMessage; - Did_you_mean_for_0_to_be_constrained_to_type_new_args_Colon_any_1: DiagnosticMessage; - Operator_0_cannot_be_applied_to_type_1: DiagnosticMessage; - BigInt_literals_are_not_available_when_targeting_lower_than_ESNext: DiagnosticMessage; - An_outer_value_of_this_is_shadowed_by_this_container: DiagnosticMessage; - Type_0_is_missing_the_following_properties_from_type_1_Colon_2: DiagnosticMessage; - Type_0_is_missing_the_following_properties_from_type_1_Colon_2_and_3_more: DiagnosticMessage; - Property_0_is_missing_in_type_1_but_required_in_type_2: DiagnosticMessage; - The_inferred_type_of_0_cannot_be_named_without_a_reference_to_1_This_is_likely_not_portable_A_type_annotation_is_necessary: DiagnosticMessage; - No_overload_expects_0_type_arguments_but_overloads_do_exist_that_expect_either_1_or_2_type_arguments: DiagnosticMessage; - Type_parameter_defaults_can_only_reference_previously_declared_type_parameters: DiagnosticMessage; - This_JSX_tag_s_0_prop_expects_type_1_which_requires_multiple_children_but_only_a_single_child_was_provided: DiagnosticMessage; - This_JSX_tag_s_0_prop_expects_a_single_child_of_type_1_but_multiple_children_were_provided: DiagnosticMessage; - _0_components_don_t_accept_text_as_child_elements_Text_in_JSX_has_the_type_string_but_the_expected_type_of_1_is_2: DiagnosticMessage; - Cannot_access_ambient_const_enums_when_the_isolatedModules_flag_is_provided: DiagnosticMessage; - _0_refers_to_a_value_but_is_being_used_as_a_type_here: DiagnosticMessage; - The_implementation_signature_is_declared_here: DiagnosticMessage; - Circularity_originates_in_type_at_this_location: DiagnosticMessage; - The_first_export_default_is_here: DiagnosticMessage; - Another_export_default_is_here: DiagnosticMessage; - super_may_not_use_type_arguments: DiagnosticMessage; - No_constituent_of_type_0_is_callable: DiagnosticMessage; - Not_all_constituents_of_type_0_are_callable: DiagnosticMessage; - Type_0_has_no_call_signatures: DiagnosticMessage; - Each_member_of_the_union_type_0_has_signatures_but_none_of_those_signatures_are_compatible_with_each_other: DiagnosticMessage; - No_constituent_of_type_0_is_constructable: DiagnosticMessage; - Not_all_constituents_of_type_0_are_constructable: DiagnosticMessage; - Type_0_has_no_construct_signatures: DiagnosticMessage; - Each_member_of_the_union_type_0_has_construct_signatures_but_none_of_those_signatures_are_compatible_with_each_other: DiagnosticMessage; - Cannot_iterate_value_because_the_next_method_of_its_iterator_expects_type_1_but_for_of_will_always_send_0: DiagnosticMessage; - Cannot_iterate_value_because_the_next_method_of_its_iterator_expects_type_1_but_array_spread_will_always_send_0: DiagnosticMessage; - Cannot_iterate_value_because_the_next_method_of_its_iterator_expects_type_1_but_array_destructuring_will_always_send_0: DiagnosticMessage; - Cannot_delegate_iteration_to_value_because_the_next_method_of_its_iterator_expects_type_1_but_the_containing_generator_will_always_send_0: DiagnosticMessage; - The_0_property_of_an_iterator_must_be_a_method: DiagnosticMessage; - The_0_property_of_an_async_iterator_must_be_a_method: DiagnosticMessage; - No_overload_matches_this_call: DiagnosticMessage; - The_last_overload_gave_the_following_error: DiagnosticMessage; - The_last_overload_is_declared_here: DiagnosticMessage; - Overload_0_of_1_2_gave_the_following_error: DiagnosticMessage; - Did_you_forget_to_use_await: DiagnosticMessage; - Import_declaration_0_is_using_private_name_1: DiagnosticMessage; - Type_parameter_0_of_exported_class_has_or_is_using_private_name_1: DiagnosticMessage; - Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1: DiagnosticMessage; - Type_parameter_0_of_constructor_signature_from_exported_interface_has_or_is_using_private_name_1: DiagnosticMessage; - Type_parameter_0_of_call_signature_from_exported_interface_has_or_is_using_private_name_1: DiagnosticMessage; - Type_parameter_0_of_public_static_method_from_exported_class_has_or_is_using_private_name_1: DiagnosticMessage; - Type_parameter_0_of_public_method_from_exported_class_has_or_is_using_private_name_1: DiagnosticMessage; - Type_parameter_0_of_method_from_exported_interface_has_or_is_using_private_name_1: DiagnosticMessage; - Type_parameter_0_of_exported_function_has_or_is_using_private_name_1: DiagnosticMessage; - Implements_clause_of_exported_class_0_has_or_is_using_private_name_1: DiagnosticMessage; - extends_clause_of_exported_class_0_has_or_is_using_private_name_1: DiagnosticMessage; - extends_clause_of_exported_interface_0_has_or_is_using_private_name_1: DiagnosticMessage; - Exported_variable_0_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named: DiagnosticMessage; - Exported_variable_0_has_or_is_using_name_1_from_private_module_2: DiagnosticMessage; - Exported_variable_0_has_or_is_using_private_name_1: DiagnosticMessage; - Public_static_property_0_of_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named: DiagnosticMessage; - Public_static_property_0_of_exported_class_has_or_is_using_name_1_from_private_module_2: DiagnosticMessage; - Public_static_property_0_of_exported_class_has_or_is_using_private_name_1: DiagnosticMessage; - Public_property_0_of_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named: DiagnosticMessage; - Public_property_0_of_exported_class_has_or_is_using_name_1_from_private_module_2: DiagnosticMessage; - Public_property_0_of_exported_class_has_or_is_using_private_name_1: DiagnosticMessage; - Property_0_of_exported_interface_has_or_is_using_name_1_from_private_module_2: DiagnosticMessage; - Property_0_of_exported_interface_has_or_is_using_private_name_1: DiagnosticMessage; - Parameter_type_of_public_static_setter_0_from_exported_class_has_or_is_using_name_1_from_private_module_2: DiagnosticMessage; - Parameter_type_of_public_static_setter_0_from_exported_class_has_or_is_using_private_name_1: DiagnosticMessage; - Parameter_type_of_public_setter_0_from_exported_class_has_or_is_using_name_1_from_private_module_2: DiagnosticMessage; - Parameter_type_of_public_setter_0_from_exported_class_has_or_is_using_private_name_1: DiagnosticMessage; - Return_type_of_public_static_getter_0_from_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named: DiagnosticMessage; - Return_type_of_public_static_getter_0_from_exported_class_has_or_is_using_name_1_from_private_module_2: DiagnosticMessage; - Return_type_of_public_static_getter_0_from_exported_class_has_or_is_using_private_name_1: DiagnosticMessage; - Return_type_of_public_getter_0_from_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named: DiagnosticMessage; - Return_type_of_public_getter_0_from_exported_class_has_or_is_using_name_1_from_private_module_2: DiagnosticMessage; - Return_type_of_public_getter_0_from_exported_class_has_or_is_using_private_name_1: DiagnosticMessage; - Return_type_of_constructor_signature_from_exported_interface_has_or_is_using_name_0_from_private_module_1: DiagnosticMessage; - Return_type_of_constructor_signature_from_exported_interface_has_or_is_using_private_name_0: DiagnosticMessage; - Return_type_of_call_signature_from_exported_interface_has_or_is_using_name_0_from_private_module_1: DiagnosticMessage; - Return_type_of_call_signature_from_exported_interface_has_or_is_using_private_name_0: DiagnosticMessage; - Return_type_of_index_signature_from_exported_interface_has_or_is_using_name_0_from_private_module_1: DiagnosticMessage; - Return_type_of_index_signature_from_exported_interface_has_or_is_using_private_name_0: DiagnosticMessage; - Return_type_of_public_static_method_from_exported_class_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named: DiagnosticMessage; - Return_type_of_public_static_method_from_exported_class_has_or_is_using_name_0_from_private_module_1: DiagnosticMessage; - Return_type_of_public_static_method_from_exported_class_has_or_is_using_private_name_0: DiagnosticMessage; - Return_type_of_public_method_from_exported_class_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named: DiagnosticMessage; - Return_type_of_public_method_from_exported_class_has_or_is_using_name_0_from_private_module_1: DiagnosticMessage; - Return_type_of_public_method_from_exported_class_has_or_is_using_private_name_0: DiagnosticMessage; - Return_type_of_method_from_exported_interface_has_or_is_using_name_0_from_private_module_1: DiagnosticMessage; - Return_type_of_method_from_exported_interface_has_or_is_using_private_name_0: DiagnosticMessage; - Return_type_of_exported_function_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named: DiagnosticMessage; - Return_type_of_exported_function_has_or_is_using_name_0_from_private_module_1: DiagnosticMessage; - Return_type_of_exported_function_has_or_is_using_private_name_0: DiagnosticMessage; - Parameter_0_of_constructor_from_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named: DiagnosticMessage; - Parameter_0_of_constructor_from_exported_class_has_or_is_using_name_1_from_private_module_2: DiagnosticMessage; - Parameter_0_of_constructor_from_exported_class_has_or_is_using_private_name_1: DiagnosticMessage; - Parameter_0_of_constructor_signature_from_exported_interface_has_or_is_using_name_1_from_private_module_2: DiagnosticMessage; - Parameter_0_of_constructor_signature_from_exported_interface_has_or_is_using_private_name_1: DiagnosticMessage; - Parameter_0_of_call_signature_from_exported_interface_has_or_is_using_name_1_from_private_module_2: DiagnosticMessage; - Parameter_0_of_call_signature_from_exported_interface_has_or_is_using_private_name_1: DiagnosticMessage; - Parameter_0_of_public_static_method_from_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named: DiagnosticMessage; - Parameter_0_of_public_static_method_from_exported_class_has_or_is_using_name_1_from_private_module_2: DiagnosticMessage; - Parameter_0_of_public_static_method_from_exported_class_has_or_is_using_private_name_1: DiagnosticMessage; - Parameter_0_of_public_method_from_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named: DiagnosticMessage; - Parameter_0_of_public_method_from_exported_class_has_or_is_using_name_1_from_private_module_2: DiagnosticMessage; - Parameter_0_of_public_method_from_exported_class_has_or_is_using_private_name_1: DiagnosticMessage; - Parameter_0_of_method_from_exported_interface_has_or_is_using_name_1_from_private_module_2: DiagnosticMessage; - Parameter_0_of_method_from_exported_interface_has_or_is_using_private_name_1: DiagnosticMessage; - Parameter_0_of_exported_function_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named: DiagnosticMessage; - Parameter_0_of_exported_function_has_or_is_using_name_1_from_private_module_2: DiagnosticMessage; - Parameter_0_of_exported_function_has_or_is_using_private_name_1: DiagnosticMessage; - Exported_type_alias_0_has_or_is_using_private_name_1: DiagnosticMessage; - Default_export_of_the_module_has_or_is_using_private_name_0: DiagnosticMessage; - Type_parameter_0_of_exported_type_alias_has_or_is_using_private_name_1: DiagnosticMessage; - Conflicting_definitions_for_0_found_at_1_and_2_Consider_installing_a_specific_version_of_this_library_to_resolve_the_conflict: DiagnosticMessage; - Parameter_0_of_index_signature_from_exported_interface_has_or_is_using_name_1_from_private_module_2: DiagnosticMessage; - Parameter_0_of_index_signature_from_exported_interface_has_or_is_using_private_name_1: DiagnosticMessage; - Property_0_of_exported_class_expression_may_not_be_private_or_protected: DiagnosticMessage; - Public_static_method_0_of_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named: DiagnosticMessage; - Public_static_method_0_of_exported_class_has_or_is_using_name_1_from_private_module_2: DiagnosticMessage; - Public_static_method_0_of_exported_class_has_or_is_using_private_name_1: DiagnosticMessage; - Public_method_0_of_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named: DiagnosticMessage; - Public_method_0_of_exported_class_has_or_is_using_name_1_from_private_module_2: DiagnosticMessage; - Public_method_0_of_exported_class_has_or_is_using_private_name_1: DiagnosticMessage; - Method_0_of_exported_interface_has_or_is_using_name_1_from_private_module_2: DiagnosticMessage; - Method_0_of_exported_interface_has_or_is_using_private_name_1: DiagnosticMessage; - Type_parameter_0_of_exported_mapped_object_type_is_using_private_name_1: DiagnosticMessage; - The_type_0_is_readonly_and_cannot_be_assigned_to_the_mutable_type_1: DiagnosticMessage; - Private_or_protected_member_0_cannot_be_accessed_on_a_type_parameter: DiagnosticMessage; - The_current_host_does_not_support_the_0_option: DiagnosticMessage; - Cannot_find_the_common_subdirectory_path_for_the_input_files: DiagnosticMessage; - File_specification_cannot_end_in_a_recursive_directory_wildcard_Asterisk_Asterisk_Colon_0: DiagnosticMessage; - Cannot_read_file_0_Colon_1: DiagnosticMessage; - Failed_to_parse_file_0_Colon_1: DiagnosticMessage; - Unknown_compiler_option_0: DiagnosticMessage; - Compiler_option_0_requires_a_value_of_type_1: DiagnosticMessage; - Could_not_write_file_0_Colon_1: DiagnosticMessage; - Option_project_cannot_be_mixed_with_source_files_on_a_command_line: DiagnosticMessage; - Option_isolatedModules_can_only_be_used_when_either_option_module_is_provided_or_option_target_is_ES2015_or_higher: DiagnosticMessage; - Option_0_can_only_be_used_when_either_option_inlineSourceMap_or_option_sourceMap_is_provided: DiagnosticMessage; - Option_0_cannot_be_specified_without_specifying_option_1: DiagnosticMessage; - Option_0_cannot_be_specified_with_option_1: DiagnosticMessage; - A_tsconfig_json_file_is_already_defined_at_Colon_0: DiagnosticMessage; - Cannot_write_file_0_because_it_would_overwrite_input_file: DiagnosticMessage; - Cannot_write_file_0_because_it_would_be_overwritten_by_multiple_input_files: DiagnosticMessage; - Cannot_find_a_tsconfig_json_file_at_the_specified_directory_Colon_0: DiagnosticMessage; - The_specified_path_does_not_exist_Colon_0: DiagnosticMessage; - Invalid_value_for_reactNamespace_0_is_not_a_valid_identifier: DiagnosticMessage; - Option_paths_cannot_be_used_without_specifying_baseUrl_option: DiagnosticMessage; - Pattern_0_can_have_at_most_one_Asterisk_character: DiagnosticMessage; - Substitution_0_in_pattern_1_in_can_have_at_most_one_Asterisk_character: DiagnosticMessage; - Substitutions_for_pattern_0_should_be_an_array: DiagnosticMessage; - Substitution_0_for_pattern_1_has_incorrect_type_expected_string_got_2: DiagnosticMessage; - File_specification_cannot_contain_a_parent_directory_that_appears_after_a_recursive_directory_wildcard_Asterisk_Asterisk_Colon_0: DiagnosticMessage; - Substitutions_for_pattern_0_shouldn_t_be_an_empty_array: DiagnosticMessage; - Invalid_value_for_jsxFactory_0_is_not_a_valid_identifier_or_qualified_name: DiagnosticMessage; - Adding_a_tsconfig_json_file_will_help_organize_projects_that_contain_both_TypeScript_and_JavaScript_files_Learn_more_at_https_Colon_Slash_Slashaka_ms_Slashtsconfig: DiagnosticMessage; - Option_0_cannot_be_specified_without_specifying_option_1_or_option_2: DiagnosticMessage; - Option_resolveJsonModule_cannot_be_specified_without_node_module_resolution_strategy: DiagnosticMessage; - Option_resolveJsonModule_can_only_be_specified_when_module_code_generation_is_commonjs_amd_es2015_or_esNext: DiagnosticMessage; - Unknown_build_option_0: DiagnosticMessage; - Build_option_0_requires_a_value_of_type_1: DiagnosticMessage; - Option_incremental_can_only_be_specified_using_tsconfig_emitting_to_single_file_or_when_option_tsBuildInfoFile_is_specified: DiagnosticMessage; - _0_is_assignable_to_the_constraint_of_type_1_but_1_could_be_instantiated_with_a_different_subtype_of_constraint_2: DiagnosticMessage; - Generates_a_sourcemap_for_each_corresponding_d_ts_file: DiagnosticMessage; - Concatenate_and_emit_output_to_single_file: DiagnosticMessage; - Generates_corresponding_d_ts_file: DiagnosticMessage; - Specify_the_location_where_debugger_should_locate_map_files_instead_of_generated_locations: DiagnosticMessage; - Specify_the_location_where_debugger_should_locate_TypeScript_files_instead_of_source_locations: DiagnosticMessage; - Watch_input_files: DiagnosticMessage; - Redirect_output_structure_to_the_directory: DiagnosticMessage; - Do_not_erase_const_enum_declarations_in_generated_code: DiagnosticMessage; - Do_not_emit_outputs_if_any_errors_were_reported: DiagnosticMessage; - Do_not_emit_comments_to_output: DiagnosticMessage; - Do_not_emit_outputs: DiagnosticMessage; - Allow_default_imports_from_modules_with_no_default_export_This_does_not_affect_code_emit_just_typechecking: DiagnosticMessage; - Skip_type_checking_of_declaration_files: DiagnosticMessage; - Do_not_resolve_the_real_path_of_symlinks: DiagnosticMessage; - Only_emit_d_ts_declaration_files: DiagnosticMessage; - Specify_ECMAScript_target_version_Colon_ES3_default_ES5_ES2015_ES2016_ES2017_ES2018_ES2019_or_ESNEXT: DiagnosticMessage; - Specify_module_code_generation_Colon_none_commonjs_amd_system_umd_es2015_or_ESNext: DiagnosticMessage; - Print_this_message: DiagnosticMessage; - Print_the_compiler_s_version: DiagnosticMessage; - Compile_the_project_given_the_path_to_its_configuration_file_or_to_a_folder_with_a_tsconfig_json: DiagnosticMessage; - Syntax_Colon_0: DiagnosticMessage; - options: DiagnosticMessage; - file: DiagnosticMessage; - Examples_Colon_0: DiagnosticMessage; - Options_Colon: DiagnosticMessage; - Version_0: DiagnosticMessage; - Insert_command_line_options_and_files_from_a_file: DiagnosticMessage; - Starting_compilation_in_watch_mode: DiagnosticMessage; - File_change_detected_Starting_incremental_compilation: DiagnosticMessage; - KIND: DiagnosticMessage; - FILE: DiagnosticMessage; - VERSION: DiagnosticMessage; - LOCATION: DiagnosticMessage; - DIRECTORY: DiagnosticMessage; - STRATEGY: DiagnosticMessage; - FILE_OR_DIRECTORY: DiagnosticMessage; - Generates_corresponding_map_file: DiagnosticMessage; - Compiler_option_0_expects_an_argument: DiagnosticMessage; - Unterminated_quoted_string_in_response_file_0: DiagnosticMessage; - Argument_for_0_option_must_be_Colon_1: DiagnosticMessage; - Locale_must_be_of_the_form_language_or_language_territory_For_example_0_or_1: DiagnosticMessage; - Unsupported_locale_0: DiagnosticMessage; - Unable_to_open_file_0: DiagnosticMessage; - Corrupted_locale_file_0: DiagnosticMessage; - Raise_error_on_expressions_and_declarations_with_an_implied_any_type: DiagnosticMessage; - File_0_not_found: DiagnosticMessage; - File_0_has_unsupported_extension_The_only_supported_extensions_are_1: DiagnosticMessage; - Suppress_noImplicitAny_errors_for_indexing_objects_lacking_index_signatures: DiagnosticMessage; - Do_not_emit_declarations_for_code_that_has_an_internal_annotation: DiagnosticMessage; - Specify_the_root_directory_of_input_files_Use_to_control_the_output_directory_structure_with_outDir: DiagnosticMessage; - File_0_is_not_under_rootDir_1_rootDir_is_expected_to_contain_all_source_files: DiagnosticMessage; - Specify_the_end_of_line_sequence_to_be_used_when_emitting_files_Colon_CRLF_dos_or_LF_unix: DiagnosticMessage; - NEWLINE: DiagnosticMessage; - Option_0_can_only_be_specified_in_tsconfig_json_file: DiagnosticMessage; - Enables_experimental_support_for_ES7_decorators: DiagnosticMessage; - Enables_experimental_support_for_emitting_type_metadata_for_decorators: DiagnosticMessage; - Enables_experimental_support_for_ES7_async_functions: DiagnosticMessage; - Specify_module_resolution_strategy_Colon_node_Node_js_or_classic_TypeScript_pre_1_6: DiagnosticMessage; - Initializes_a_TypeScript_project_and_creates_a_tsconfig_json_file: DiagnosticMessage; - Successfully_created_a_tsconfig_json_file: DiagnosticMessage; - Suppress_excess_property_checks_for_object_literals: DiagnosticMessage; - Stylize_errors_and_messages_using_color_and_context_experimental: DiagnosticMessage; - Do_not_report_errors_on_unused_labels: DiagnosticMessage; - Report_error_when_not_all_code_paths_in_function_return_a_value: DiagnosticMessage; - Report_errors_for_fallthrough_cases_in_switch_statement: DiagnosticMessage; - Do_not_report_errors_on_unreachable_code: DiagnosticMessage; - Disallow_inconsistently_cased_references_to_the_same_file: DiagnosticMessage; - Specify_library_files_to_be_included_in_the_compilation: DiagnosticMessage; - Specify_JSX_code_generation_Colon_preserve_react_native_or_react: DiagnosticMessage; - File_0_has_an_unsupported_extension_so_skipping_it: DiagnosticMessage; - Only_amd_and_system_modules_are_supported_alongside_0: DiagnosticMessage; - Base_directory_to_resolve_non_absolute_module_names: DiagnosticMessage; - Deprecated_Use_jsxFactory_instead_Specify_the_object_invoked_for_createElement_when_targeting_react_JSX_emit: DiagnosticMessage; - Enable_tracing_of_the_name_resolution_process: DiagnosticMessage; - Resolving_module_0_from_1: DiagnosticMessage; - Explicitly_specified_module_resolution_kind_Colon_0: DiagnosticMessage; - Module_resolution_kind_is_not_specified_using_0: DiagnosticMessage; - Module_name_0_was_successfully_resolved_to_1: DiagnosticMessage; - Module_name_0_was_not_resolved: DiagnosticMessage; - paths_option_is_specified_looking_for_a_pattern_to_match_module_name_0: DiagnosticMessage; - Module_name_0_matched_pattern_1: DiagnosticMessage; - Trying_substitution_0_candidate_module_location_Colon_1: DiagnosticMessage; - Resolving_module_name_0_relative_to_base_url_1_2: DiagnosticMessage; - Loading_module_as_file_Slash_folder_candidate_module_location_0_target_file_type_1: DiagnosticMessage; - File_0_does_not_exist: DiagnosticMessage; - File_0_exist_use_it_as_a_name_resolution_result: DiagnosticMessage; - Loading_module_0_from_node_modules_folder_target_file_type_1: DiagnosticMessage; - Found_package_json_at_0: DiagnosticMessage; - package_json_does_not_have_a_0_field: DiagnosticMessage; - package_json_has_0_field_1_that_references_2: DiagnosticMessage; - Allow_javascript_files_to_be_compiled: DiagnosticMessage; - Option_0_should_have_array_of_strings_as_a_value: DiagnosticMessage; - Checking_if_0_is_the_longest_matching_prefix_for_1_2: DiagnosticMessage; - Expected_type_of_0_field_in_package_json_to_be_1_got_2: DiagnosticMessage; - baseUrl_option_is_set_to_0_using_this_value_to_resolve_non_relative_module_name_1: DiagnosticMessage; - rootDirs_option_is_set_using_it_to_resolve_relative_module_name_0: DiagnosticMessage; - Longest_matching_prefix_for_0_is_1: DiagnosticMessage; - Loading_0_from_the_root_dir_1_candidate_location_2: DiagnosticMessage; - Trying_other_entries_in_rootDirs: DiagnosticMessage; - Module_resolution_using_rootDirs_has_failed: DiagnosticMessage; - Do_not_emit_use_strict_directives_in_module_output: DiagnosticMessage; - Enable_strict_null_checks: DiagnosticMessage; - Unknown_option_excludes_Did_you_mean_exclude: DiagnosticMessage; - Raise_error_on_this_expressions_with_an_implied_any_type: DiagnosticMessage; - Resolving_type_reference_directive_0_containing_file_1_root_directory_2: DiagnosticMessage; - Resolving_using_primary_search_paths: DiagnosticMessage; - Resolving_from_node_modules_folder: DiagnosticMessage; - Type_reference_directive_0_was_successfully_resolved_to_1_primary_Colon_2: DiagnosticMessage; - Type_reference_directive_0_was_not_resolved: DiagnosticMessage; - Resolving_with_primary_search_path_0: DiagnosticMessage; - Root_directory_cannot_be_determined_skipping_primary_search_paths: DiagnosticMessage; - Resolving_type_reference_directive_0_containing_file_1_root_directory_not_set: DiagnosticMessage; - Type_declaration_files_to_be_included_in_compilation: DiagnosticMessage; - Looking_up_in_node_modules_folder_initial_location_0: DiagnosticMessage; - Containing_file_is_not_specified_and_root_directory_cannot_be_determined_skipping_lookup_in_node_modules_folder: DiagnosticMessage; - Resolving_type_reference_directive_0_containing_file_not_set_root_directory_1: DiagnosticMessage; - Resolving_type_reference_directive_0_containing_file_not_set_root_directory_not_set: DiagnosticMessage; - Resolving_real_path_for_0_result_1: DiagnosticMessage; - Cannot_compile_modules_using_option_0_unless_the_module_flag_is_amd_or_system: DiagnosticMessage; - File_name_0_has_a_1_extension_stripping_it: DiagnosticMessage; - _0_is_declared_but_its_value_is_never_read: DiagnosticMessage; - Report_errors_on_unused_locals: DiagnosticMessage; - Report_errors_on_unused_parameters: DiagnosticMessage; - The_maximum_dependency_depth_to_search_under_node_modules_and_load_JavaScript_files: DiagnosticMessage; - Cannot_import_type_declaration_files_Consider_importing_0_instead_of_1: DiagnosticMessage; - Property_0_is_declared_but_its_value_is_never_read: DiagnosticMessage; - Import_emit_helpers_from_tslib: DiagnosticMessage; - Auto_discovery_for_typings_is_enabled_in_project_0_Running_extra_resolution_pass_for_module_1_using_cache_location_2: DiagnosticMessage; - Parse_in_strict_mode_and_emit_use_strict_for_each_source_file: DiagnosticMessage; - Module_0_was_resolved_to_1_but_jsx_is_not_set: DiagnosticMessage; - Module_0_was_resolved_as_locally_declared_ambient_module_in_file_1: DiagnosticMessage; - Module_0_was_resolved_as_ambient_module_declared_in_1_since_this_file_was_not_modified: DiagnosticMessage; - Specify_the_JSX_factory_function_to_use_when_targeting_react_JSX_emit_e_g_React_createElement_or_h: DiagnosticMessage; - Resolution_for_module_0_was_found_in_cache_from_location_1: DiagnosticMessage; - Directory_0_does_not_exist_skipping_all_lookups_in_it: DiagnosticMessage; - Show_diagnostic_information: DiagnosticMessage; - Show_verbose_diagnostic_information: DiagnosticMessage; - Emit_a_single_file_with_source_maps_instead_of_having_a_separate_file: DiagnosticMessage; - Emit_the_source_alongside_the_sourcemaps_within_a_single_file_requires_inlineSourceMap_or_sourceMap_to_be_set: DiagnosticMessage; - Transpile_each_file_as_a_separate_module_similar_to_ts_transpileModule: DiagnosticMessage; - Print_names_of_generated_files_part_of_the_compilation: DiagnosticMessage; - Print_names_of_files_part_of_the_compilation: DiagnosticMessage; - The_locale_used_when_displaying_messages_to_the_user_e_g_en_us: DiagnosticMessage; - Do_not_generate_custom_helper_functions_like_extends_in_compiled_output: DiagnosticMessage; - Do_not_include_the_default_library_file_lib_d_ts: DiagnosticMessage; - Do_not_add_triple_slash_references_or_imported_modules_to_the_list_of_compiled_files: DiagnosticMessage; - Deprecated_Use_skipLibCheck_instead_Skip_type_checking_of_default_library_declaration_files: DiagnosticMessage; - List_of_folders_to_include_type_definitions_from: DiagnosticMessage; - Disable_size_limitations_on_JavaScript_projects: DiagnosticMessage; - The_character_set_of_the_input_files: DiagnosticMessage; - Emit_a_UTF_8_Byte_Order_Mark_BOM_in_the_beginning_of_output_files: DiagnosticMessage; - Do_not_truncate_error_messages: DiagnosticMessage; - Output_directory_for_generated_declaration_files: DiagnosticMessage; - A_series_of_entries_which_re_map_imports_to_lookup_locations_relative_to_the_baseUrl: DiagnosticMessage; - List_of_root_folders_whose_combined_content_represents_the_structure_of_the_project_at_runtime: DiagnosticMessage; - Show_all_compiler_options: DiagnosticMessage; - Deprecated_Use_outFile_instead_Concatenate_and_emit_output_to_single_file: DiagnosticMessage; - Command_line_Options: DiagnosticMessage; - Basic_Options: DiagnosticMessage; - Strict_Type_Checking_Options: DiagnosticMessage; - Module_Resolution_Options: DiagnosticMessage; - Source_Map_Options: DiagnosticMessage; - Additional_Checks: DiagnosticMessage; - Experimental_Options: DiagnosticMessage; - Advanced_Options: DiagnosticMessage; - Provide_full_support_for_iterables_in_for_of_spread_and_destructuring_when_targeting_ES5_or_ES3: DiagnosticMessage; - Enable_all_strict_type_checking_options: DiagnosticMessage; - List_of_language_service_plugins: DiagnosticMessage; - Scoped_package_detected_looking_in_0: DiagnosticMessage; - Reusing_resolution_of_module_0_to_file_1_from_old_program: DiagnosticMessage; - Reusing_module_resolutions_originating_in_0_since_resolutions_are_unchanged_from_old_program: DiagnosticMessage; - Disable_strict_checking_of_generic_signatures_in_function_types: DiagnosticMessage; - Enable_strict_checking_of_function_types: DiagnosticMessage; - Enable_strict_checking_of_property_initialization_in_classes: DiagnosticMessage; - Numeric_separators_are_not_allowed_here: DiagnosticMessage; - Multiple_consecutive_numeric_separators_are_not_permitted: DiagnosticMessage; - Whether_to_keep_outdated_console_output_in_watch_mode_instead_of_clearing_the_screen: DiagnosticMessage; - All_imports_in_import_declaration_are_unused: DiagnosticMessage; - Found_1_error_Watching_for_file_changes: DiagnosticMessage; - Found_0_errors_Watching_for_file_changes: DiagnosticMessage; - Resolve_keyof_to_string_valued_property_names_only_no_numbers_or_symbols: DiagnosticMessage; - _0_is_declared_but_never_used: DiagnosticMessage; - Include_modules_imported_with_json_extension: DiagnosticMessage; - All_destructured_elements_are_unused: DiagnosticMessage; - All_variables_are_unused: DiagnosticMessage; - Definitions_of_the_following_identifiers_conflict_with_those_in_another_file_Colon_0: DiagnosticMessage; - Conflicts_are_in_this_file: DiagnosticMessage; - _0_was_also_declared_here: DiagnosticMessage; - and_here: DiagnosticMessage; - All_type_parameters_are_unused: DiagnosticMessage; - package_json_has_a_typesVersions_field_with_version_specific_path_mappings: DiagnosticMessage; - package_json_does_not_have_a_typesVersions_entry_that_matches_version_0: DiagnosticMessage; - package_json_has_a_typesVersions_entry_0_that_matches_compiler_version_1_looking_for_a_pattern_to_match_module_name_2: DiagnosticMessage; - package_json_has_a_typesVersions_entry_0_that_is_not_a_valid_semver_range: DiagnosticMessage; - An_argument_for_0_was_not_provided: DiagnosticMessage; - An_argument_matching_this_binding_pattern_was_not_provided: DiagnosticMessage; - Did_you_mean_to_call_this_expression: DiagnosticMessage; - Did_you_mean_to_use_new_with_this_expression: DiagnosticMessage; - Enable_strict_bind_call_and_apply_methods_on_functions: DiagnosticMessage; - Using_compiler_options_of_project_reference_redirect_0: DiagnosticMessage; - Found_1_error: DiagnosticMessage; - Found_0_errors: DiagnosticMessage; - Module_name_0_was_successfully_resolved_to_1_with_Package_ID_2: DiagnosticMessage; - Type_reference_directive_0_was_successfully_resolved_to_1_with_Package_ID_2_primary_Colon_3: DiagnosticMessage; - package_json_had_a_falsy_0_field: DiagnosticMessage; - Projects_to_reference: DiagnosticMessage; - Enable_project_compilation: DiagnosticMessage; - Project_references_may_not_form_a_circular_graph_Cycle_detected_Colon_0: DiagnosticMessage; - Composite_projects_may_not_disable_declaration_emit: DiagnosticMessage; - Output_file_0_has_not_been_built_from_source_file_1: DiagnosticMessage; - Referenced_project_0_must_have_setting_composite_Colon_true: DiagnosticMessage; - File_0_is_not_listed_within_the_file_list_of_project_1_Projects_must_list_all_files_or_use_an_include_pattern: DiagnosticMessage; - Cannot_prepend_project_0_because_it_does_not_have_outFile_set: DiagnosticMessage; - Output_file_0_from_project_1_does_not_exist: DiagnosticMessage; - Project_0_is_out_of_date_because_oldest_output_1_is_older_than_newest_input_2: DiagnosticMessage; - Project_0_is_up_to_date_because_newest_input_1_is_older_than_oldest_output_2: DiagnosticMessage; - Project_0_is_out_of_date_because_output_file_1_does_not_exist: DiagnosticMessage; - Project_0_is_out_of_date_because_its_dependency_1_is_out_of_date: DiagnosticMessage; - Project_0_is_up_to_date_with_d_ts_files_from_its_dependencies: DiagnosticMessage; - Projects_in_this_build_Colon_0: DiagnosticMessage; - A_non_dry_build_would_delete_the_following_files_Colon_0: DiagnosticMessage; - A_non_dry_build_would_build_project_0: DiagnosticMessage; - Building_project_0: DiagnosticMessage; - Updating_output_timestamps_of_project_0: DiagnosticMessage; - delete_this_Project_0_is_up_to_date_because_it_was_previously_built: DiagnosticMessage; - Project_0_is_up_to_date: DiagnosticMessage; - Skipping_build_of_project_0_because_its_dependency_1_has_errors: DiagnosticMessage; - Project_0_can_t_be_built_because_its_dependency_1_has_errors: DiagnosticMessage; - Build_one_or_more_projects_and_their_dependencies_if_out_of_date: DiagnosticMessage; - Delete_the_outputs_of_all_projects: DiagnosticMessage; - Enable_verbose_logging: DiagnosticMessage; - Show_what_would_be_built_or_deleted_if_specified_with_clean: DiagnosticMessage; - Build_all_projects_including_those_that_appear_to_be_up_to_date: DiagnosticMessage; - Option_build_must_be_the_first_command_line_argument: DiagnosticMessage; - Options_0_and_1_cannot_be_combined: DiagnosticMessage; - Updating_unchanged_output_timestamps_of_project_0: DiagnosticMessage; - Project_0_is_out_of_date_because_output_of_its_dependency_1_has_changed: DiagnosticMessage; - Updating_output_of_project_0: DiagnosticMessage; - A_non_dry_build_would_update_timestamps_for_output_of_project_0: DiagnosticMessage; - A_non_dry_build_would_update_output_of_project_0: DiagnosticMessage; - Cannot_update_output_of_project_0_because_there_was_error_reading_file_1: DiagnosticMessage; - Cannot_write_file_0_because_it_will_overwrite_tsbuildinfo_file_generated_by_referenced_project_1: DiagnosticMessage; - Enable_incremental_compilation: DiagnosticMessage; - Composite_projects_may_not_disable_incremental_compilation: DiagnosticMessage; - Specify_file_to_store_incremental_compilation_information: DiagnosticMessage; - Project_0_is_out_of_date_because_output_for_it_was_generated_with_version_1_that_differs_with_current_version_2: DiagnosticMessage; - Skipping_build_of_project_0_because_its_dependency_1_was_not_built: DiagnosticMessage; - Project_0_can_t_be_built_because_its_dependency_1_was_not_built: DiagnosticMessage; - The_expected_type_comes_from_property_0_which_is_declared_here_on_type_1: DiagnosticMessage; - The_expected_type_comes_from_this_index_signature: DiagnosticMessage; - The_expected_type_comes_from_the_return_type_of_this_signature: DiagnosticMessage; - Variable_0_implicitly_has_an_1_type: DiagnosticMessage; - Parameter_0_implicitly_has_an_1_type: DiagnosticMessage; - Member_0_implicitly_has_an_1_type: DiagnosticMessage; - new_expression_whose_target_lacks_a_construct_signature_implicitly_has_an_any_type: DiagnosticMessage; - _0_which_lacks_return_type_annotation_implicitly_has_an_1_return_type: DiagnosticMessage; - Function_expression_which_lacks_return_type_annotation_implicitly_has_an_0_return_type: DiagnosticMessage; - Construct_signature_which_lacks_return_type_annotation_implicitly_has_an_any_return_type: DiagnosticMessage; - Function_type_which_lacks_return_type_annotation_implicitly_has_an_0_return_type: DiagnosticMessage; - Element_implicitly_has_an_any_type_because_index_expression_is_not_of_type_number: DiagnosticMessage; - Could_not_find_a_declaration_file_for_module_0_1_implicitly_has_an_any_type: DiagnosticMessage; - Element_implicitly_has_an_any_type_because_type_0_has_no_index_signature: DiagnosticMessage; - Object_literal_s_property_0_implicitly_has_an_1_type: DiagnosticMessage; - Rest_parameter_0_implicitly_has_an_any_type: DiagnosticMessage; - Call_signature_which_lacks_return_type_annotation_implicitly_has_an_any_return_type: DiagnosticMessage; - _0_implicitly_has_type_any_because_it_does_not_have_a_type_annotation_and_is_referenced_directly_or_indirectly_in_its_own_initializer: DiagnosticMessage; - _0_implicitly_has_return_type_any_because_it_does_not_have_a_return_type_annotation_and_is_referenced_directly_or_indirectly_in_one_of_its_return_expressions: DiagnosticMessage; - Function_implicitly_has_return_type_any_because_it_does_not_have_a_return_type_annotation_and_is_referenced_directly_or_indirectly_in_one_of_its_return_expressions: DiagnosticMessage; - Generator_implicitly_has_yield_type_0_because_it_does_not_yield_any_values_Consider_supplying_a_return_type_annotation: DiagnosticMessage; - JSX_element_implicitly_has_type_any_because_no_interface_JSX_0_exists: DiagnosticMessage; - Unreachable_code_detected: DiagnosticMessage; - Unused_label: DiagnosticMessage; - Fallthrough_case_in_switch: DiagnosticMessage; - Not_all_code_paths_return_a_value: DiagnosticMessage; - Binding_element_0_implicitly_has_an_1_type: DiagnosticMessage; - Property_0_implicitly_has_type_any_because_its_set_accessor_lacks_a_parameter_type_annotation: DiagnosticMessage; - Property_0_implicitly_has_type_any_because_its_get_accessor_lacks_a_return_type_annotation: DiagnosticMessage; - Variable_0_implicitly_has_type_1_in_some_locations_where_its_type_cannot_be_determined: DiagnosticMessage; - Try_npm_install_types_Slash_1_if_it_exists_or_add_a_new_declaration_d_ts_file_containing_declare_module_0: DiagnosticMessage; - Dynamic_import_s_specifier_must_be_of_type_string_but_here_has_type_0: DiagnosticMessage; - Enables_emit_interoperability_between_CommonJS_and_ES_Modules_via_creation_of_namespace_objects_for_all_imports_Implies_allowSyntheticDefaultImports: DiagnosticMessage; - Type_originates_at_this_import_A_namespace_style_import_cannot_be_called_or_constructed_and_will_cause_a_failure_at_runtime_Consider_using_a_default_import_or_import_require_here_instead: DiagnosticMessage; - Mapped_object_type_implicitly_has_an_any_template_type: DiagnosticMessage; - If_the_0_package_actually_exposes_this_module_consider_sending_a_pull_request_to_amend_https_Colon_Slash_Slashgithub_com_SlashDefinitelyTyped_SlashDefinitelyTyped_Slashtree_Slashmaster_Slashtypes_Slash_1: DiagnosticMessage; - The_containing_arrow_function_captures_the_global_value_of_this: DiagnosticMessage; - Module_0_was_resolved_to_1_but_resolveJsonModule_is_not_used: DiagnosticMessage; - Variable_0_implicitly_has_an_1_type_but_a_better_type_may_be_inferred_from_usage: DiagnosticMessage; - Parameter_0_implicitly_has_an_1_type_but_a_better_type_may_be_inferred_from_usage: DiagnosticMessage; - Member_0_implicitly_has_an_1_type_but_a_better_type_may_be_inferred_from_usage: DiagnosticMessage; - Variable_0_implicitly_has_type_1_in_some_locations_but_a_better_type_may_be_inferred_from_usage: DiagnosticMessage; - Rest_parameter_0_implicitly_has_an_any_type_but_a_better_type_may_be_inferred_from_usage: DiagnosticMessage; - Property_0_implicitly_has_type_any_but_a_better_type_for_its_get_accessor_may_be_inferred_from_usage: DiagnosticMessage; - Property_0_implicitly_has_type_any_but_a_better_type_for_its_set_accessor_may_be_inferred_from_usage: DiagnosticMessage; - _0_implicitly_has_an_1_return_type_but_a_better_type_may_be_inferred_from_usage: DiagnosticMessage; - Parameter_has_a_name_but_no_type_Did_you_mean_0_Colon_1: DiagnosticMessage; - Element_implicitly_has_an_any_type_because_type_0_has_no_index_signature_Did_you_mean_to_call_1: DiagnosticMessage; - Element_implicitly_has_an_any_type_because_expression_of_type_0_can_t_be_used_to_index_type_1: DiagnosticMessage; - No_index_signature_with_a_parameter_of_type_0_was_found_on_type_1: DiagnosticMessage; - _0_which_lacks_return_type_annotation_implicitly_has_an_1_yield_type: DiagnosticMessage; - You_cannot_rename_this_element: DiagnosticMessage; - You_cannot_rename_elements_that_are_defined_in_the_standard_TypeScript_library: DiagnosticMessage; - import_can_only_be_used_in_a_ts_file: DiagnosticMessage; - export_can_only_be_used_in_a_ts_file: DiagnosticMessage; - type_parameter_declarations_can_only_be_used_in_a_ts_file: DiagnosticMessage; - implements_clauses_can_only_be_used_in_a_ts_file: DiagnosticMessage; - interface_declarations_can_only_be_used_in_a_ts_file: DiagnosticMessage; - module_declarations_can_only_be_used_in_a_ts_file: DiagnosticMessage; - type_aliases_can_only_be_used_in_a_ts_file: DiagnosticMessage; - _0_can_only_be_used_in_a_ts_file: DiagnosticMessage; - types_can_only_be_used_in_a_ts_file: DiagnosticMessage; - type_arguments_can_only_be_used_in_a_ts_file: DiagnosticMessage; - parameter_modifiers_can_only_be_used_in_a_ts_file: DiagnosticMessage; - non_null_assertions_can_only_be_used_in_a_ts_file: DiagnosticMessage; - enum_declarations_can_only_be_used_in_a_ts_file: DiagnosticMessage; - type_assertion_expressions_can_only_be_used_in_a_ts_file: DiagnosticMessage; - Octal_literal_types_must_use_ES2015_syntax_Use_the_syntax_0: DiagnosticMessage; - Octal_literals_are_not_allowed_in_enums_members_initializer_Use_the_syntax_0: DiagnosticMessage; - Report_errors_in_js_files: DiagnosticMessage; - JSDoc_types_can_only_be_used_inside_documentation_comments: DiagnosticMessage; - JSDoc_typedef_tag_should_either_have_a_type_annotation_or_be_followed_by_property_or_member_tags: DiagnosticMessage; - JSDoc_0_is_not_attached_to_a_class: DiagnosticMessage; - JSDoc_0_1_does_not_match_the_extends_2_clause: DiagnosticMessage; - JSDoc_param_tag_has_name_0_but_there_is_no_parameter_with_that_name: DiagnosticMessage; - Class_declarations_cannot_have_more_than_one_augments_or_extends_tag: DiagnosticMessage; - Expected_0_type_arguments_provide_these_with_an_extends_tag: DiagnosticMessage; - Expected_0_1_type_arguments_provide_these_with_an_extends_tag: DiagnosticMessage; - JSDoc_may_only_appear_in_the_last_parameter_of_a_signature: DiagnosticMessage; - JSDoc_param_tag_has_name_0_but_there_is_no_parameter_with_that_name_It_would_match_arguments_if_it_had_an_array_type: DiagnosticMessage; - The_type_of_a_function_declaration_must_match_the_function_s_signature: DiagnosticMessage; - You_cannot_rename_a_module_via_a_global_import: DiagnosticMessage; - Qualified_name_0_is_not_allowed_without_a_leading_param_object_1: DiagnosticMessage; - Only_identifiers_Slashqualified_names_with_optional_type_arguments_are_currently_supported_in_a_class_extends_clause: DiagnosticMessage; - class_expressions_are_not_currently_supported: DiagnosticMessage; - Language_service_is_disabled: DiagnosticMessage; - JSX_attributes_must_only_be_assigned_a_non_empty_expression: DiagnosticMessage; - JSX_elements_cannot_have_multiple_attributes_with_the_same_name: DiagnosticMessage; - Expected_corresponding_JSX_closing_tag_for_0: DiagnosticMessage; - JSX_attribute_expected: DiagnosticMessage; - Cannot_use_JSX_unless_the_jsx_flag_is_provided: DiagnosticMessage; - A_constructor_cannot_contain_a_super_call_when_its_class_extends_null: DiagnosticMessage; - An_unary_expression_with_the_0_operator_is_not_allowed_in_the_left_hand_side_of_an_exponentiation_expression_Consider_enclosing_the_expression_in_parentheses: DiagnosticMessage; - A_type_assertion_expression_is_not_allowed_in_the_left_hand_side_of_an_exponentiation_expression_Consider_enclosing_the_expression_in_parentheses: DiagnosticMessage; - JSX_element_0_has_no_corresponding_closing_tag: DiagnosticMessage; - super_must_be_called_before_accessing_this_in_the_constructor_of_a_derived_class: DiagnosticMessage; - Unknown_type_acquisition_option_0: DiagnosticMessage; - super_must_be_called_before_accessing_a_property_of_super_in_the_constructor_of_a_derived_class: DiagnosticMessage; - _0_is_not_a_valid_meta_property_for_keyword_1_Did_you_mean_2: DiagnosticMessage; - Meta_property_0_is_only_allowed_in_the_body_of_a_function_declaration_function_expression_or_constructor: DiagnosticMessage; - JSX_fragment_has_no_corresponding_closing_tag: DiagnosticMessage; - Expected_corresponding_closing_tag_for_JSX_fragment: DiagnosticMessage; - JSX_fragment_is_not_supported_when_using_jsxFactory: DiagnosticMessage; - JSX_fragment_is_not_supported_when_using_an_inline_JSX_factory_pragma: DiagnosticMessage; - Circularity_detected_while_resolving_configuration_Colon_0: DiagnosticMessage; - A_path_in_an_extends_option_must_be_relative_or_rooted_but_0_is_not: DiagnosticMessage; - The_files_list_in_config_file_0_is_empty: DiagnosticMessage; - No_inputs_were_found_in_config_file_0_Specified_include_paths_were_1_and_exclude_paths_were_2: DiagnosticMessage; - File_is_a_CommonJS_module_it_may_be_converted_to_an_ES6_module: DiagnosticMessage; - This_constructor_function_may_be_converted_to_a_class_declaration: DiagnosticMessage; - Import_may_be_converted_to_a_default_import: DiagnosticMessage; - JSDoc_types_may_be_moved_to_TypeScript_types: DiagnosticMessage; - require_call_may_be_converted_to_an_import: DiagnosticMessage; - This_may_be_converted_to_an_async_function: DiagnosticMessage; - await_has_no_effect_on_the_type_of_this_expression: DiagnosticMessage; - Add_missing_super_call: DiagnosticMessage; - Make_super_call_the_first_statement_in_the_constructor: DiagnosticMessage; - Change_extends_to_implements: DiagnosticMessage; - Remove_declaration_for_Colon_0: DiagnosticMessage; - Remove_import_from_0: DiagnosticMessage; - Implement_interface_0: DiagnosticMessage; - Implement_inherited_abstract_class: DiagnosticMessage; - Add_0_to_unresolved_variable: DiagnosticMessage; - Remove_destructuring: DiagnosticMessage; - Remove_variable_statement: DiagnosticMessage; - Remove_template_tag: DiagnosticMessage; - Remove_type_parameters: DiagnosticMessage; - Import_0_from_module_1: DiagnosticMessage; - Change_0_to_1: DiagnosticMessage; - Add_0_to_existing_import_declaration_from_1: DiagnosticMessage; - Declare_property_0: DiagnosticMessage; - Add_index_signature_for_property_0: DiagnosticMessage; - Disable_checking_for_this_file: DiagnosticMessage; - Ignore_this_error_message: DiagnosticMessage; - Initialize_property_0_in_the_constructor: DiagnosticMessage; - Initialize_static_property_0: DiagnosticMessage; - Change_spelling_to_0: DiagnosticMessage; - Declare_method_0: DiagnosticMessage; - Declare_static_method_0: DiagnosticMessage; - Prefix_0_with_an_underscore: DiagnosticMessage; - Rewrite_as_the_indexed_access_type_0: DiagnosticMessage; - Declare_static_property_0: DiagnosticMessage; - Call_decorator_expression: DiagnosticMessage; - Add_async_modifier_to_containing_function: DiagnosticMessage; - Replace_infer_0_with_unknown: DiagnosticMessage; - Replace_all_unused_infer_with_unknown: DiagnosticMessage; - Import_default_0_from_module_1: DiagnosticMessage; - Add_default_import_0_to_existing_import_declaration_from_1: DiagnosticMessage; - Add_parameter_name: DiagnosticMessage; - Convert_function_to_an_ES2015_class: DiagnosticMessage; - Convert_function_0_to_class: DiagnosticMessage; - Extract_to_0_in_1: DiagnosticMessage; - Extract_function: DiagnosticMessage; - Extract_constant: DiagnosticMessage; - Extract_to_0_in_enclosing_scope: DiagnosticMessage; - Extract_to_0_in_1_scope: DiagnosticMessage; - Annotate_with_type_from_JSDoc: DiagnosticMessage; - Annotate_with_types_from_JSDoc: DiagnosticMessage; - Infer_type_of_0_from_usage: DiagnosticMessage; - Infer_parameter_types_from_usage: DiagnosticMessage; - Convert_to_default_import: DiagnosticMessage; - Install_0: DiagnosticMessage; - Replace_import_with_0: DiagnosticMessage; - Use_synthetic_default_member: DiagnosticMessage; - Convert_to_ES6_module: DiagnosticMessage; - Add_undefined_type_to_property_0: DiagnosticMessage; - Add_initializer_to_property_0: DiagnosticMessage; - Add_definite_assignment_assertion_to_property_0: DiagnosticMessage; - Add_all_missing_members: DiagnosticMessage; - Infer_all_types_from_usage: DiagnosticMessage; - Delete_all_unused_declarations: DiagnosticMessage; - Prefix_all_unused_declarations_with_where_possible: DiagnosticMessage; - Fix_all_detected_spelling_errors: DiagnosticMessage; - Add_initializers_to_all_uninitialized_properties: DiagnosticMessage; - Add_definite_assignment_assertions_to_all_uninitialized_properties: DiagnosticMessage; - Add_undefined_type_to_all_uninitialized_properties: DiagnosticMessage; - Change_all_jsdoc_style_types_to_TypeScript: DiagnosticMessage; - Change_all_jsdoc_style_types_to_TypeScript_and_add_undefined_to_nullable_types: DiagnosticMessage; - Implement_all_unimplemented_interfaces: DiagnosticMessage; - Install_all_missing_types_packages: DiagnosticMessage; - Rewrite_all_as_indexed_access_types: DiagnosticMessage; - Convert_all_to_default_imports: DiagnosticMessage; - Make_all_super_calls_the_first_statement_in_their_constructor: DiagnosticMessage; - Add_qualifier_to_all_unresolved_variables_matching_a_member_name: DiagnosticMessage; - Change_all_extended_interfaces_to_implements: DiagnosticMessage; - Add_all_missing_super_calls: DiagnosticMessage; - Implement_all_inherited_abstract_classes: DiagnosticMessage; - Add_all_missing_async_modifiers: DiagnosticMessage; - Add_ts_ignore_to_all_error_messages: DiagnosticMessage; - Annotate_everything_with_types_from_JSDoc: DiagnosticMessage; - Add_to_all_uncalled_decorators: DiagnosticMessage; - Convert_all_constructor_functions_to_classes: DiagnosticMessage; - Generate_get_and_set_accessors: DiagnosticMessage; - Convert_require_to_import: DiagnosticMessage; - Convert_all_require_to_import: DiagnosticMessage; - Move_to_a_new_file: DiagnosticMessage; - Remove_unreachable_code: DiagnosticMessage; - Remove_all_unreachable_code: DiagnosticMessage; - Add_missing_typeof: DiagnosticMessage; - Remove_unused_label: DiagnosticMessage; - Remove_all_unused_labels: DiagnosticMessage; - Convert_0_to_mapped_object_type: DiagnosticMessage; - Convert_namespace_import_to_named_imports: DiagnosticMessage; - Convert_named_imports_to_namespace_import: DiagnosticMessage; - Add_or_remove_braces_in_an_arrow_function: DiagnosticMessage; - Add_braces_to_arrow_function: DiagnosticMessage; - Remove_braces_from_arrow_function: DiagnosticMessage; - Convert_default_export_to_named_export: DiagnosticMessage; - Convert_named_export_to_default_export: DiagnosticMessage; - Add_missing_enum_member_0: DiagnosticMessage; - Add_all_missing_imports: DiagnosticMessage; - Convert_to_async_function: DiagnosticMessage; - Convert_all_to_async_functions: DiagnosticMessage; - Add_unknown_conversion_for_non_overlapping_types: DiagnosticMessage; - Add_unknown_to_all_conversions_of_non_overlapping_types: DiagnosticMessage; - Add_missing_new_operator_to_call: DiagnosticMessage; - Add_missing_new_operator_to_all_calls: DiagnosticMessage; - Add_names_to_all_parameters_without_names: DiagnosticMessage; - Enable_the_experimentalDecorators_option_in_your_configuration_file: DiagnosticMessage; - Convert_parameters_to_destructured_object: DiagnosticMessage; - Allow_accessing_UMD_globals_from_modules: DiagnosticMessage; - Extract_type: DiagnosticMessage; - Extract_to_type_alias: DiagnosticMessage; - Extract_to_typedef: DiagnosticMessage; - Infer_this_type_of_0_from_usage: DiagnosticMessage; - Add_const_to_unresolved_variable: DiagnosticMessage; - Add_const_to_all_unresolved_variables: DiagnosticMessage; - Add_await: DiagnosticMessage; - Add_await_to_initializer_for_0: DiagnosticMessage; - Fix_all_expressions_possibly_missing_await: DiagnosticMessage; - Remove_unnecessary_await: DiagnosticMessage; - Remove_all_unnecessary_uses_of_await: DiagnosticMessage; - Enable_the_jsx_flag_in_your_configuration_file: DiagnosticMessage; - Add_await_to_initializers: DiagnosticMessage; - No_value_exists_in_scope_for_the_shorthand_property_0_Either_declare_one_or_provide_an_initializer: DiagnosticMessage; - Classes_may_not_have_a_field_named_constructor: DiagnosticMessage; - JSX_expressions_may_not_use_the_comma_operator_Did_you_mean_to_write_an_array: DiagnosticMessage; - }; -} -declare namespace ts { - type ErrorCallback = (message: DiagnosticMessage, length: number) => void; - function tokenIsIdentifierOrKeyword(token: SyntaxKind): boolean; - function tokenIsIdentifierOrKeywordOrGreaterThan(token: SyntaxKind): boolean; - interface Scanner { - getStartPos(): number; - getToken(): SyntaxKind; - getTextPos(): number; - getTokenPos(): number; - getTokenText(): string; - getTokenValue(): string; - hasUnicodeEscape(): boolean; - hasExtendedUnicodeEscape(): boolean; - hasPrecedingLineBreak(): boolean; - isIdentifier(): boolean; - isReservedWord(): boolean; - isUnterminated(): boolean; - getTokenFlags(): TokenFlags; - reScanGreaterToken(): SyntaxKind; - reScanSlashToken(): SyntaxKind; - reScanTemplateToken(): SyntaxKind; - scanJsxIdentifier(): SyntaxKind; - scanJsxAttributeValue(): SyntaxKind; - reScanJsxToken(): JsxTokenSyntaxKind; - reScanLessThanToken(): SyntaxKind; - scanJsxToken(): JsxTokenSyntaxKind; - scanJsDocToken(): JSDocSyntaxKind; - scan(): SyntaxKind; - getText(): string; - setText(text: string | undefined, start?: number, length?: number): void; - setOnError(onError: ErrorCallback | undefined): void; - setScriptTarget(scriptTarget: ScriptTarget): void; - setLanguageVariant(variant: LanguageVariant): void; - setTextPos(textPos: number): void; - setInJSDocType(inType: boolean): void; - lookAhead(callback: () => T): T; - scanRange(start: number, length: number, callback: () => T): T; - tryScan(callback: () => T): T; - } - function isUnicodeIdentifierStart(code: number, languageVersion: ScriptTarget | undefined): boolean; - function tokenToString(t: SyntaxKind): string | undefined; - function stringToToken(s: string): SyntaxKind | undefined; - function computeLineStarts(text: string): number[]; - function getPositionOfLineAndCharacter(sourceFile: SourceFileLike, line: number, character: number): number; - function getPositionOfLineAndCharacter(sourceFile: SourceFileLike, line: number, character: number, allowEdits?: true): number; - function computePositionOfLineAndCharacter(lineStarts: ReadonlyArray, line: number, character: number, debugText?: string, allowEdits?: true): number; - function getLineStarts(sourceFile: SourceFileLike): ReadonlyArray; - /** - * We assume the first line starts at position 0 and 'position' is non-negative. - */ - function computeLineAndCharacterOfPosition(lineStarts: ReadonlyArray, position: number): LineAndCharacter; - function getLineAndCharacterOfPosition(sourceFile: SourceFileLike, position: number): LineAndCharacter; - function isWhiteSpaceLike(ch: number): boolean; - /** Does not include line breaks. For that, see isWhiteSpaceLike. */ - function isWhiteSpaceSingleLine(ch: number): boolean; - function isLineBreak(ch: number): boolean; - function isOctalDigit(ch: number): boolean; - function couldStartTrivia(text: string, pos: number): boolean; - function skipTrivia(text: string, pos: number, stopAfterLineBreak?: boolean, stopAtComments?: boolean): number; - function isShebangTrivia(text: string, pos: number): boolean; - function scanShebangTrivia(text: string, pos: number): number; - function forEachLeadingCommentRange(text: string, pos: number, cb: (pos: number, end: number, kind: CommentKind, hasTrailingNewLine: boolean) => U): U | undefined; - function forEachLeadingCommentRange(text: string, pos: number, cb: (pos: number, end: number, kind: CommentKind, hasTrailingNewLine: boolean, state: T) => U, state: T): U | undefined; - function forEachTrailingCommentRange(text: string, pos: number, cb: (pos: number, end: number, kind: CommentKind, hasTrailingNewLine: boolean) => U): U | undefined; - function forEachTrailingCommentRange(text: string, pos: number, cb: (pos: number, end: number, kind: CommentKind, hasTrailingNewLine: boolean, state: T) => U, state: T): U | undefined; - function reduceEachLeadingCommentRange(text: string, pos: number, cb: (pos: number, end: number, kind: CommentKind, hasTrailingNewLine: boolean, state: T, memo: U) => U, state: T, initial: U): U | undefined; - function reduceEachTrailingCommentRange(text: string, pos: number, cb: (pos: number, end: number, kind: CommentKind, hasTrailingNewLine: boolean, state: T, memo: U) => U, state: T, initial: U): U | undefined; - function getLeadingCommentRanges(text: string, pos: number): CommentRange[] | undefined; - function getTrailingCommentRanges(text: string, pos: number): CommentRange[] | undefined; - /** Optionally, get the shebang */ - function getShebang(text: string): string | undefined; - function isIdentifierStart(ch: number, languageVersion: ScriptTarget | undefined): boolean; - function isIdentifierPart(ch: number, languageVersion: ScriptTarget | undefined): boolean; - function isIdentifierText(name: string, languageVersion: ScriptTarget | undefined): boolean; - function createScanner(languageVersion: ScriptTarget, skipTrivia: boolean, languageVariant?: LanguageVariant, textInitial?: string, onError?: ErrorCallback, start?: number, length?: number): Scanner; -} -declare namespace ts { - function isExternalModuleNameRelative(moduleName: string): boolean; - function sortAndDeduplicateDiagnostics(diagnostics: ReadonlyArray): SortedReadonlyArray; -} -declare namespace ts { - const resolvingEmptyArray: never[]; - const emptyMap: ReadonlyMap & ReadonlyPragmaMap; - const emptyUnderscoreEscapedMap: ReadonlyUnderscoreEscapedMap; - const externalHelpersModuleNameText = "tslib"; - const defaultMaximumTruncationLength = 160; - function getDeclarationOfKind(symbol: Symbol, kind: T["kind"]): T | undefined; - /** Create a new escaped identifier map. */ - function createUnderscoreEscapedMap(): UnderscoreEscapedMap; - function hasEntries(map: ReadonlyUnderscoreEscapedMap | undefined): map is ReadonlyUnderscoreEscapedMap; - function createSymbolTable(symbols?: ReadonlyArray): SymbolTable; - function toPath(fileName: string, basePath: string | undefined, getCanonicalFileName: (path: string) => string): Path; - function changesAffectModuleResolution(oldOptions: CompilerOptions, newOptions: CompilerOptions): boolean; - function optionsHaveModuleResolutionChanges(oldOptions: CompilerOptions, newOptions: CompilerOptions): boolean; - /** - * Iterates through the parent chain of a node and performs the callback on each parent until the callback - * returns a truthy value, then returns that value. - * If no such value is found, it applies the callback until the parent pointer is undefined or the callback returns "quit" - * At that point findAncestor returns undefined. - */ - function findAncestor(node: Node | undefined, callback: (element: Node) => element is T): T | undefined; - function findAncestor(node: Node | undefined, callback: (element: Node) => boolean | "quit"): Node | undefined; - function forEachAncestor(node: Node, callback: (n: Node) => T | undefined | "quit"): T | undefined; - /** - * Calls `callback` for each entry in the map, returning the first truthy result. - * Use `map.forEach` instead for normal iteration. - */ - function forEachEntry(map: ReadonlyUnderscoreEscapedMap, callback: (value: T, key: __String) => U | undefined): U | undefined; - function forEachEntry(map: ReadonlyMap, callback: (value: T, key: string) => U | undefined): U | undefined; - /** `forEachEntry` for just keys. */ - function forEachKey(map: ReadonlyUnderscoreEscapedMap<{}>, callback: (key: __String) => T | undefined): T | undefined; - function forEachKey(map: ReadonlyMap<{}>, callback: (key: string) => T | undefined): T | undefined; - /** Copy entries from `source` to `target`. */ - function copyEntries(source: ReadonlyUnderscoreEscapedMap, target: UnderscoreEscapedMap): void; - function copyEntries(source: ReadonlyMap, target: Map): void; - /** - * Creates a set from the elements of an array. - * - * @param array the array of input elements. - */ - function arrayToSet(array: ReadonlyArray): Map; - function arrayToSet(array: ReadonlyArray, makeKey: (value: T) => string | undefined): Map; - function arrayToSet(array: ReadonlyArray, makeKey: (value: T) => __String | undefined): UnderscoreEscapedMap; - function cloneMap(map: SymbolTable): SymbolTable; - function cloneMap(map: ReadonlyMap): Map; - function cloneMap(map: ReadonlyUnderscoreEscapedMap): UnderscoreEscapedMap; - function usingSingleLineStringWriter(action: (writer: EmitTextWriter) => void): string; - function getFullWidth(node: Node): number; - function getResolvedModule(sourceFile: SourceFile | undefined, moduleNameText: string): ResolvedModuleFull | undefined; - function setResolvedModule(sourceFile: SourceFile, moduleNameText: string, resolvedModule: ResolvedModuleFull): void; - function setResolvedTypeReferenceDirective(sourceFile: SourceFile, typeReferenceDirectiveName: string, resolvedTypeReferenceDirective?: ResolvedTypeReferenceDirective): void; - function projectReferenceIsEqualTo(oldRef: ProjectReference, newRef: ProjectReference): boolean; - function moduleResolutionIsEqualTo(oldResolution: ResolvedModuleFull, newResolution: ResolvedModuleFull): boolean; - function packageIdToString({ name, subModuleName, version }: PackageId): string; - function typeDirectiveIsEqualTo(oldResolution: ResolvedTypeReferenceDirective, newResolution: ResolvedTypeReferenceDirective): boolean; - function hasChangesInResolutions(names: ReadonlyArray, newResolutions: ReadonlyArray, oldResolutions: ReadonlyMap | undefined, comparer: (oldResolution: T, newResolution: T) => boolean): boolean; - function containsParseError(node: Node): boolean; - function getSourceFileOfNode(node: Node): SourceFile; - function getSourceFileOfNode(node: Node | undefined): SourceFile | undefined; - function isStatementWithLocals(node: Node): boolean; - function getStartPositionOfLine(line: number, sourceFile: SourceFileLike): number; - function nodePosToString(node: Node): string; - function getEndLinePosition(line: number, sourceFile: SourceFileLike): number; - /** - * Returns a value indicating whether a name is unique globally or within the current file. - * Note: This does not consider whether a name appears as a free identifier or not, so at the expression `x.y` this includes both `x` and `y`. - */ - function isFileLevelUniqueName(sourceFile: SourceFile, name: string, hasGlobalName?: PrintHandlers["hasGlobalName"]): boolean; - function nodeIsMissing(node: Node | undefined): boolean; - function nodeIsPresent(node: Node | undefined): boolean; - /** - * Prepends statements to an array while taking care of prologue directives. - */ - function insertStatementsAfterStandardPrologue(to: T[], from: ReadonlyArray | undefined): T[]; - function insertStatementsAfterCustomPrologue(to: T[], from: ReadonlyArray | undefined): T[]; - /** - * Prepends statements to an array while taking care of prologue directives. - */ - function insertStatementAfterStandardPrologue(to: T[], statement: T | undefined): T[]; - function insertStatementAfterCustomPrologue(to: T[], statement: T | undefined): T[]; - /** - * Determine if the given comment is a triple-slash - * - * @return true if the comment is a triple-slash comment else false - */ - function isRecognizedTripleSlashComment(text: string, commentPos: number, commentEnd: number): boolean; - function isPinnedComment(text: string, start: number): boolean; - function getTokenPosOfNode(node: Node, sourceFile?: SourceFileLike, includeJsDoc?: boolean): number; - function getNonDecoratorTokenPosOfNode(node: Node, sourceFile?: SourceFileLike): number; - function getSourceTextOfNodeFromSourceFile(sourceFile: SourceFile, node: Node, includeTrivia?: boolean): string; - function getTextOfNodeFromSourceText(sourceText: string, node: Node, includeTrivia?: boolean): string; - function getTextOfNode(node: Node, includeTrivia?: boolean): string; - /** - * Note: it is expected that the `nodeArray` and the `node` are within the same file. - * For example, searching for a `SourceFile` in a `SourceFile[]` wouldn't work. - */ - function indexOfNode(nodeArray: ReadonlyArray, node: Node): number; - /** - * Gets flags that control emit behavior of a node. - */ - function getEmitFlags(node: Node): EmitFlags; - function getLiteralText(node: LiteralLikeNode, sourceFile: SourceFile, neverAsciiEscape: boolean | undefined): string; - function getTextOfConstantValue(value: string | number): string; - function makeIdentifierFromModuleName(moduleName: string): string; - function isBlockOrCatchScoped(declaration: Declaration): boolean; - function isCatchClauseVariableDeclarationOrBindingElement(declaration: Declaration): boolean; - function isAmbientModule(node: Node): node is AmbientModuleDeclaration; - function isModuleWithStringLiteralName(node: Node): node is ModuleDeclaration; - function isNonGlobalAmbientModule(node: Node): node is ModuleDeclaration & { - name: StringLiteral; - }; - /** - * An effective module (namespace) declaration is either - * 1. An actual declaration: namespace X { ... } - * 2. A Javascript declaration, which is: - * An identifier in a nested property access expression: Y in `X.Y.Z = { ... }` - */ - function isEffectiveModuleDeclaration(node: Node): boolean; - /** Given a symbol for a module, checks that it is a shorthand ambient module. */ - function isShorthandAmbientModuleSymbol(moduleSymbol: Symbol): boolean; - function isBlockScopedContainerTopLevel(node: Node): boolean; - function isGlobalScopeAugmentation(module: ModuleDeclaration): boolean; - function isExternalModuleAugmentation(node: Node): node is AmbientModuleDeclaration; - function isModuleAugmentationExternal(node: AmbientModuleDeclaration): boolean; - function getNonAugmentationDeclaration(symbol: Symbol): Declaration | undefined; - function isEffectiveExternalModule(node: SourceFile, compilerOptions: CompilerOptions): boolean; - /** - * Returns whether the source file will be treated as if it were in strict mode at runtime. - */ - function isEffectiveStrictModeSourceFile(node: SourceFile, compilerOptions: CompilerOptions): boolean; - function isBlockScope(node: Node, parentNode: Node): boolean; - function isDeclarationWithTypeParameters(node: Node): node is DeclarationWithTypeParameters; - function isDeclarationWithTypeParameterChildren(node: Node): node is DeclarationWithTypeParameterChildren; - function isAnyImportSyntax(node: Node): node is AnyImportSyntax; - function isLateVisibilityPaintedStatement(node: Node): node is LateVisibilityPaintedStatement; - function isAnyImportOrReExport(node: Node): node is AnyImportOrReExport; - function getEnclosingBlockScopeContainer(node: Node): Node; - function declarationNameToString(name: DeclarationName | QualifiedName | undefined): string; - function getNameFromIndexInfo(info: IndexInfo): string | undefined; - function getTextOfPropertyName(name: PropertyName | NoSubstitutionTemplateLiteral): __String; - function entityNameToString(name: EntityNameOrEntityNameExpression): string; - function createDiagnosticForNode(node: Node, message: DiagnosticMessage, arg0?: string | number, arg1?: string | number, arg2?: string | number, arg3?: string | number): DiagnosticWithLocation; - function createDiagnosticForNodeArray(sourceFile: SourceFile, nodes: NodeArray, message: DiagnosticMessage, arg0?: string | number, arg1?: string | number, arg2?: string | number, arg3?: string | number): DiagnosticWithLocation; - function createDiagnosticForNodeInSourceFile(sourceFile: SourceFile, node: Node, message: DiagnosticMessage, arg0?: string | number, arg1?: string | number, arg2?: string | number, arg3?: string | number): DiagnosticWithLocation; - function createDiagnosticForNodeFromMessageChain(node: Node, messageChain: DiagnosticMessageChain, relatedInformation?: DiagnosticRelatedInformation[]): DiagnosticWithLocation; - function getSpanOfTokenAtPosition(sourceFile: SourceFile, pos: number): TextSpan; - function getErrorSpanForNode(sourceFile: SourceFile, node: Node): TextSpan; - function isExternalOrCommonJsModule(file: SourceFile): boolean; - function isJsonSourceFile(file: SourceFile): file is JsonSourceFile; - function isEnumConst(node: EnumDeclaration): boolean; - function isDeclarationReadonly(declaration: Declaration): boolean; - function isVarConst(node: VariableDeclaration | VariableDeclarationList): boolean; - function isLet(node: Node): boolean; - function isSuperCall(n: Node): n is SuperCall; - function isImportCall(n: Node): n is ImportCall; - function isImportMeta(n: Node): n is ImportMetaProperty; - function isLiteralImportTypeNode(n: Node): n is LiteralImportTypeNode; - function isPrologueDirective(node: Node): node is PrologueDirective; - function getLeadingCommentRangesOfNode(node: Node, sourceFileOfNode: SourceFile): CommentRange[] | undefined; - function getJSDocCommentRanges(node: Node, text: string): CommentRange[] | undefined; - const fullTripleSlashReferencePathRegEx: RegExp; - const fullTripleSlashAMDReferencePathRegEx: RegExp; - function isPartOfTypeNode(node: Node): boolean; - function isChildOfNodeWithKind(node: Node, kind: SyntaxKind): boolean; - function forEachReturnStatement(body: Block, visitor: (stmt: ReturnStatement) => T): T | undefined; - function forEachYieldExpression(body: Block, visitor: (expr: YieldExpression) => void): void; - /** - * Gets the most likely element type for a TypeNode. This is not an exhaustive test - * as it assumes a rest argument can only be an array type (either T[], or Array). - * - * @param node The type node. - */ - function getRestParameterElementType(node: TypeNode | undefined): TypeNode | undefined; - function getMembersOfDeclaration(node: Declaration): NodeArray | undefined; - function isVariableLike(node: Node): node is VariableLikeDeclaration; - function isVariableLikeOrAccessor(node: Node): node is AccessorDeclaration | VariableLikeDeclaration; - function isVariableDeclarationInVariableStatement(node: VariableDeclaration): boolean; - function isValidESSymbolDeclaration(node: Node): node is VariableDeclaration | PropertyDeclaration | SignatureDeclaration; - function introducesArgumentsExoticObject(node: Node): boolean; - function unwrapInnermostStatementOfLabel(node: LabeledStatement, beforeUnwrapLabelCallback?: (node: LabeledStatement) => void): Statement; - function isFunctionBlock(node: Node): boolean; - function isObjectLiteralMethod(node: Node): node is MethodDeclaration; - function isObjectLiteralOrClassExpressionMethod(node: Node): node is MethodDeclaration; - function isIdentifierTypePredicate(predicate: TypePredicate): predicate is IdentifierTypePredicate; - function isThisTypePredicate(predicate: TypePredicate): predicate is ThisTypePredicate; - function getPropertyAssignment(objectLiteral: ObjectLiteralExpression, key: string, key2?: string): ReadonlyArray; - function getTsConfigObjectLiteralExpression(tsConfigSourceFile: TsConfigSourceFile | undefined): ObjectLiteralExpression | undefined; - function getTsConfigPropArrayElementValue(tsConfigSourceFile: TsConfigSourceFile | undefined, propKey: string, elementValue: string): StringLiteral | undefined; - function getTsConfigPropArray(tsConfigSourceFile: TsConfigSourceFile | undefined, propKey: string): ReadonlyArray; - function getContainingFunction(node: Node): SignatureDeclaration | undefined; - function getContainingFunctionDeclaration(node: Node): FunctionLikeDeclaration | undefined; - function getContainingClass(node: Node): ClassLikeDeclaration | undefined; - function getThisContainer(node: Node, includeArrowFunctions: boolean): Node; - function getNewTargetContainer(node: Node): Node | undefined; - /** - * Given an super call/property node, returns the closest node where - * - a super call/property access is legal in the node and not legal in the parent node the node. - * i.e. super call is legal in constructor but not legal in the class body. - * - the container is an arrow function (so caller might need to call getSuperContainer again in case it needs to climb higher) - * - a super call/property is definitely illegal in the container (but might be legal in some subnode) - * i.e. super property access is illegal in function declaration but can be legal in the statement list - */ - function getSuperContainer(node: Node, stopOnFunctions: boolean): Node; - function getImmediatelyInvokedFunctionExpression(func: Node): CallExpression | undefined; - function isSuperOrSuperProperty(node: Node): node is SuperExpression | SuperProperty; - /** - * Determines whether a node is a property or element access expression for `super`. - */ - function isSuperProperty(node: Node): node is SuperProperty; - /** - * Determines whether a node is a property or element access expression for `this`. - */ - function isThisProperty(node: Node): boolean; - function getEntityNameFromTypeNode(node: TypeNode): EntityNameOrEntityNameExpression | undefined; - function getInvokedExpression(node: CallLikeExpression): Expression; - function nodeCanBeDecorated(node: ClassDeclaration): true; - function nodeCanBeDecorated(node: ClassElement, parent: Node): boolean; - function nodeCanBeDecorated(node: Node, parent: Node, grandparent: Node): boolean; - function nodeIsDecorated(node: ClassDeclaration): boolean; - function nodeIsDecorated(node: ClassElement, parent: Node): boolean; - function nodeIsDecorated(node: Node, parent: Node, grandparent: Node): boolean; - function nodeOrChildIsDecorated(node: ClassDeclaration): boolean; - function nodeOrChildIsDecorated(node: ClassElement, parent: Node): boolean; - function nodeOrChildIsDecorated(node: Node, parent: Node, grandparent: Node): boolean; - function childIsDecorated(node: ClassDeclaration): boolean; - function childIsDecorated(node: Node, parent: Node): boolean; - function isJSXTagName(node: Node): boolean; - function isExpressionNode(node: Node): boolean; - function isInExpressionContext(node: Node): boolean; - function isExternalModuleImportEqualsDeclaration(node: Node): boolean; - function getExternalModuleImportEqualsDeclarationExpression(node: Node): Expression; - function isInternalModuleImportEqualsDeclaration(node: Node): node is ImportEqualsDeclaration; - function isSourceFileJS(file: SourceFile): boolean; - function isSourceFileNotJS(file: SourceFile): boolean; - function isInJSFile(node: Node | undefined): boolean; - function isInJsonFile(node: Node | undefined): boolean; - function isInJSDoc(node: Node | undefined): boolean; - function isJSDocIndexSignature(node: TypeReferenceNode | ExpressionWithTypeArguments): boolean | undefined; - /** - * Returns true if the node is a CallExpression to the identifier 'require' with - * exactly one argument (of the form 'require("name")'). - * This function does not test if the node is in a JavaScript file or not. - */ - function isRequireCall(callExpression: Node, checkArgumentIsStringLiteralLike: true): callExpression is RequireOrImportCall & { - expression: Identifier; - arguments: [StringLiteralLike]; - }; - function isRequireCall(callExpression: Node, checkArgumentIsStringLiteralLike: boolean): callExpression is CallExpression; - function isSingleOrDoubleQuote(charCode: number): boolean; - function isStringDoubleQuoted(str: StringLiteralLike, sourceFile: SourceFile): boolean; - function getDeclarationOfExpando(node: Node): Node | undefined; - function isAssignmentDeclaration(decl: Declaration): boolean; - /** Get the initializer, taking into account defaulted Javascript initializers */ - function getEffectiveInitializer(node: HasExpressionInitializer): Expression | undefined; - /** Get the declaration initializer when it is container-like (See getExpandoInitializer). */ - function getDeclaredExpandoInitializer(node: HasExpressionInitializer): Expression | undefined; - /** - * Get the assignment 'initializer' -- the righthand side-- when the initializer is container-like (See getExpandoInitializer). - * We treat the right hand side of assignments with container-like initalizers as declarations. - */ - function getAssignedExpandoInitializer(node: Node | undefined): Expression | undefined; - /** - * Recognized expando initializers are: - * 1. (function() {})() -- IIFEs - * 2. function() { } -- Function expressions - * 3. class { } -- Class expressions - * 4. {} -- Empty object literals - * 5. { ... } -- Non-empty object literals, when used to initialize a prototype, like `C.prototype = { m() { } }` - * - * This function returns the provided initializer, or undefined if it is not valid. - */ - function getExpandoInitializer(initializer: Node, isPrototypeAssignment: boolean): Expression | undefined; - function isDefaultedExpandoInitializer(node: BinaryExpression): boolean | undefined; - /** Given an expando initializer, return its declaration name, or the left-hand side of the assignment if it's part of an assignment declaration. */ - function getNameOfExpando(node: Declaration): DeclarationName | undefined; - function getRightMostAssignedExpression(node: Expression): Expression; - function isExportsIdentifier(node: Node): boolean; - function isModuleExportsPropertyAccessExpression(node: Node): boolean; - function getAssignmentDeclarationKind(expr: BinaryExpression | CallExpression): AssignmentDeclarationKind; - function isBindableObjectDefinePropertyCall(expr: CallExpression): expr is BindableObjectDefinePropertyCall; - function getAssignmentDeclarationPropertyAccessKind(lhs: PropertyAccessExpression): AssignmentDeclarationKind; - function getInitializerOfBinaryExpression(expr: BinaryExpression): Expression; - function isPrototypePropertyAssignment(node: Node): boolean; - function isSpecialPropertyDeclaration(expr: PropertyAccessExpression): boolean; - function isFunctionSymbol(symbol: Symbol | undefined): boolean | undefined; - function importFromModuleSpecifier(node: StringLiteralLike): AnyValidImportOrReExport; - function tryGetImportFromModuleSpecifier(node: StringLiteralLike): AnyValidImportOrReExport | undefined; - function getExternalModuleName(node: AnyImportOrReExport | ImportTypeNode): Expression | undefined; - function getNamespaceDeclarationNode(node: ImportDeclaration | ImportEqualsDeclaration | ExportDeclaration): ImportEqualsDeclaration | NamespaceImport | undefined; - function isDefaultImport(node: ImportDeclaration | ImportEqualsDeclaration | ExportDeclaration): boolean; - function hasQuestionToken(node: Node): boolean; - function isJSDocConstructSignature(node: Node): boolean; - function isJSDocTypeAlias(node: Node): node is JSDocTypedefTag | JSDocCallbackTag | JSDocEnumTag; - function isTypeAlias(node: Node): node is JSDocTypedefTag | JSDocCallbackTag | JSDocEnumTag | TypeAliasDeclaration; - function getSingleInitializerOfVariableStatementOrPropertyDeclaration(node: Node): Expression | undefined; - function getJSDocCommentsAndTags(hostNode: Node): ReadonlyArray; - /** Does the opposite of `getJSDocParameterTags`: given a JSDoc parameter, finds the parameter corresponding to it. */ - function getParameterSymbolFromJSDoc(node: JSDocParameterTag): Symbol | undefined; - function getHostSignatureFromJSDoc(node: Node): SignatureDeclaration | undefined; - function getHostSignatureFromJSDocHost(host: HasJSDoc): SignatureDeclaration | undefined; - function getJSDocHost(node: Node): HasJSDoc; - function getTypeParameterFromJsDoc(node: TypeParameterDeclaration & { - parent: JSDocTemplateTag; - }): TypeParameterDeclaration | undefined; - function hasRestParameter(s: SignatureDeclaration | JSDocSignature): boolean; - function isRestParameter(node: ParameterDeclaration | JSDocParameterTag): boolean; - enum AssignmentKind { - None = 0, - Definite = 1, - Compound = 2 - } - function getAssignmentTargetKind(node: Node): AssignmentKind; - function isAssignmentTarget(node: Node): boolean; - type NodeWithPossibleHoistedDeclaration = Block | VariableStatement | WithStatement | IfStatement | SwitchStatement | CaseBlock | CaseClause | DefaultClause | LabeledStatement | ForStatement | ForInStatement | ForOfStatement | DoStatement | WhileStatement | TryStatement | CatchClause; - /** - * Indicates whether a node could contain a `var` VariableDeclarationList that contributes to - * the same `var` declaration scope as the node's parent. - */ - function isNodeWithPossibleHoistedDeclaration(node: Node): node is NodeWithPossibleHoistedDeclaration; - type ValueSignatureDeclaration = FunctionDeclaration | MethodDeclaration | ConstructorDeclaration | AccessorDeclaration | FunctionExpression | ArrowFunction; - function isValueSignatureDeclaration(node: Node): node is ValueSignatureDeclaration; - function walkUpParenthesizedTypes(node: Node): Node; - function walkUpParenthesizedExpressions(node: Node): Node; - function skipParentheses(node: Expression): Expression; - function skipParentheses(node: Node): Node; - function isDeleteTarget(node: Node): boolean; - function isNodeDescendantOf(node: Node, ancestor: Node | undefined): boolean; - function isDeclarationName(name: Node): boolean; - function getDeclarationFromName(name: Node): Declaration | undefined; - function isLiteralComputedPropertyDeclarationName(node: Node): boolean; - function isIdentifierName(node: Identifier): boolean; - function isAliasSymbolDeclaration(node: Node): boolean; - function exportAssignmentIsAlias(node: ExportAssignment | BinaryExpression): boolean; - function getEffectiveBaseTypeNode(node: ClassLikeDeclaration | InterfaceDeclaration): ExpressionWithTypeArguments | undefined; - function getClassExtendsHeritageElement(node: ClassLikeDeclaration | InterfaceDeclaration): ExpressionWithTypeArguments | undefined; - function getClassImplementsHeritageClauseElements(node: ClassLikeDeclaration): NodeArray | undefined; - /** Returns the node in an `extends` or `implements` clause of a class or interface. */ - function getAllSuperTypeNodes(node: Node): ReadonlyArray; - function getInterfaceBaseTypeNodes(node: InterfaceDeclaration): NodeArray | undefined; - function getHeritageClause(clauses: NodeArray | undefined, kind: SyntaxKind): HeritageClause | undefined; - function getAncestor(node: Node | undefined, kind: SyntaxKind): Node | undefined; - function isKeyword(token: SyntaxKind): boolean; - function isContextualKeyword(token: SyntaxKind): boolean; - function isNonContextualKeyword(token: SyntaxKind): boolean; - function isFutureReservedKeyword(token: SyntaxKind): boolean; - function isStringANonContextualKeyword(name: string): boolean; - function isIdentifierANonContextualKeyword({ originalKeywordKind }: Identifier): boolean; - type TriviaKind = SyntaxKind.SingleLineCommentTrivia | SyntaxKind.MultiLineCommentTrivia | SyntaxKind.NewLineTrivia | SyntaxKind.WhitespaceTrivia | SyntaxKind.ShebangTrivia | SyntaxKind.ConflictMarkerTrivia; - function isTrivia(token: SyntaxKind): token is TriviaKind; - enum FunctionFlags { - Normal = 0, - Generator = 1, - Async = 2, - Invalid = 4, - AsyncGenerator = 3 - } - function getFunctionFlags(node: SignatureDeclaration | undefined): FunctionFlags; - function isAsyncFunction(node: Node): boolean; - function isStringOrNumericLiteralLike(node: Node): node is StringLiteralLike | NumericLiteral; - function isSignedNumericLiteral(node: Node): node is PrefixUnaryExpression & { - operand: NumericLiteral; - }; - /** - * A declaration has a dynamic name if all of the following are true: - * 1. The declaration has a computed property name. - * 2. The computed name is *not* expressed as a StringLiteral. - * 3. The computed name is *not* expressed as a NumericLiteral. - * 4. The computed name is *not* expressed as a PlusToken or MinusToken - * immediately followed by a NumericLiteral. - * 5. The computed name is *not* expressed as `Symbol.`, where `` - * is a property of the Symbol constructor that denotes a built-in - * Symbol. - */ - function hasDynamicName(declaration: Declaration): declaration is DynamicNamedDeclaration; - function isDynamicName(name: DeclarationName): boolean; - /** - * Checks if the expression is of the form: - * Symbol.name - * where Symbol is literally the word "Symbol", and name is any identifierName - */ - function isWellKnownSymbolSyntactically(node: Expression): boolean; - function getPropertyNameForPropertyNameNode(name: PropertyName): __String | undefined; - type PropertyNameLiteral = Identifier | StringLiteralLike | NumericLiteral; - function isPropertyNameLiteral(node: Node): node is PropertyNameLiteral; - function getTextOfIdentifierOrLiteral(node: PropertyNameLiteral): string; - function getEscapedTextOfIdentifierOrLiteral(node: PropertyNameLiteral): __String; - function getPropertyNameForKnownSymbolName(symbolName: string): __String; - function isKnownSymbol(symbol: Symbol): boolean; - /** - * Includes the word "Symbol" with unicode escapes - */ - function isESSymbolIdentifier(node: Node): boolean; - function isPushOrUnshiftIdentifier(node: Identifier): boolean; - function isParameterDeclaration(node: VariableLikeDeclaration): boolean; - function getRootDeclaration(node: Node): Node; - function nodeStartsNewLexicalEnvironment(node: Node): boolean; - function nodeIsSynthesized(range: TextRange): boolean; - function getOriginalSourceFile(sourceFile: SourceFile): SourceFile; - enum Associativity { - Left = 0, - Right = 1 - } - function getExpressionAssociativity(expression: Expression): Associativity; - function getOperatorAssociativity(kind: SyntaxKind, operator: SyntaxKind, hasArguments?: boolean): Associativity; - function getExpressionPrecedence(expression: Expression): number; - function getOperator(expression: Expression): SyntaxKind; - function getOperatorPrecedence(nodeKind: SyntaxKind, operatorKind: SyntaxKind, hasArguments?: boolean): number; - function getBinaryOperatorPrecedence(kind: SyntaxKind): number; - function createDiagnosticCollection(): DiagnosticCollection; - /** - * Based heavily on the abstract 'Quote'/'QuoteJSONString' operation from ECMA-262 (24.3.2.2), - * but augmented for a few select characters (e.g. lineSeparator, paragraphSeparator, nextLine) - * Note that this doesn't actually wrap the input in double quotes. - */ - function escapeString(s: string, quoteChar?: CharacterCodes.doubleQuote | CharacterCodes.singleQuote | CharacterCodes.backtick): string; - /** - * Strip off existed single quotes or double quotes from a given string - * - * @return non-quoted string - */ - function stripQuotes(name: string): string; - function startsWithQuote(name: string): boolean; - function isIntrinsicJsxName(name: __String | string): boolean; - function escapeNonAsciiString(s: string, quoteChar?: CharacterCodes.doubleQuote | CharacterCodes.singleQuote | CharacterCodes.backtick): string; - function getIndentString(level: number): string; - function getIndentSize(): number; - function createTextWriter(newLine: string): EmitTextWriter; - function getTrailingSemicolonOmittingWriter(writer: EmitTextWriter): EmitTextWriter; - function getResolvedExternalModuleName(host: EmitHost, file: SourceFile, referenceFile?: SourceFile): string; - function getExternalModuleNameFromDeclaration(host: EmitHost, resolver: EmitResolver, declaration: ImportEqualsDeclaration | ImportDeclaration | ExportDeclaration | ModuleDeclaration | ImportTypeNode): string | undefined; - /** - * Resolves a local path to a path which is absolute to the base of the emit - */ - function getExternalModuleNameFromPath(host: EmitHost, fileName: string, referencePath?: string): string; - function getOwnEmitOutputFilePath(fileName: string, host: EmitHost, extension: string): string; - function getDeclarationEmitOutputFilePath(fileName: string, host: EmitHost): string; - function getDeclarationEmitOutputFilePathWorker(fileName: string, options: CompilerOptions, currentDirectory: string, commonSourceDirectory: string, getCanonicalFileName: GetCanonicalFileName): string; - interface EmitFileNames { - jsFilePath?: string | undefined; - sourceMapFilePath?: string | undefined; - declarationFilePath?: string | undefined; - declarationMapPath?: string | undefined; - buildInfoPath?: string | undefined; - } - /** - * Gets the source files that are expected to have an emit output. - * - * Originally part of `forEachExpectedEmitFile`, this functionality was extracted to support - * transformations. - * - * @param host An EmitHost. - * @param targetSourceFile An optional target source file to emit. - */ - function getSourceFilesToEmit(host: EmitHost, targetSourceFile?: SourceFile): ReadonlyArray; - /** Don't call this for `--outFile`, just for `--outDir` or plain emit. `--outFile` needs additional checks. */ - function sourceFileMayBeEmitted(sourceFile: SourceFile, options: CompilerOptions, isSourceFileFromExternalLibrary: (file: SourceFile) => boolean, getResolvedProjectReferenceToRedirect: (fileName: string) => ResolvedProjectReference | undefined): boolean; - function getSourceFilePathInNewDir(fileName: string, host: EmitHost, newDirPath: string): string; - function getSourceFilePathInNewDirWorker(fileName: string, newDirPath: string, currentDirectory: string, commonSourceDirectory: string, getCanonicalFileName: GetCanonicalFileName): string; - function writeFile(host: { - writeFile: WriteFileCallback; - }, diagnostics: DiagnosticCollection, fileName: string, data: string, writeByteOrderMark: boolean, sourceFiles?: ReadonlyArray): void; - function getLineOfLocalPosition(currentSourceFile: SourceFile, pos: number): number; - function getLineOfLocalPositionFromLineMap(lineMap: ReadonlyArray, pos: number): number; - function getFirstConstructorWithBody(node: ClassLikeDeclaration): ConstructorDeclaration & { - body: FunctionBody; - } | undefined; - function getSetAccessorValueParameter(accessor: SetAccessorDeclaration): ParameterDeclaration | undefined; - /** Get the type annotation for the value parameter. */ - function getSetAccessorTypeAnnotationNode(accessor: SetAccessorDeclaration): TypeNode | undefined; - function getThisParameter(signature: SignatureDeclaration | JSDocSignature): ParameterDeclaration | undefined; - function parameterIsThisKeyword(parameter: ParameterDeclaration): boolean; - function isThisIdentifier(node: Node | undefined): boolean; - function identifierIsThisKeyword(id: Identifier): boolean; - function getAllAccessorDeclarations(declarations: readonly Declaration[], accessor: AccessorDeclaration): AllAccessorDeclarations; - /** - * Gets the effective type annotation of a variable, parameter, or property. If the node was - * parsed in a JavaScript file, gets the type annotation from JSDoc. - */ - function getEffectiveTypeAnnotationNode(node: Node): TypeNode | undefined; - function getTypeAnnotationNode(node: Node): TypeNode | undefined; - /** - * Gets the effective return type annotation of a signature. If the node was parsed in a - * JavaScript file, gets the return type annotation from JSDoc. - */ - function getEffectiveReturnTypeNode(node: SignatureDeclaration | JSDocSignature): TypeNode | undefined; - function getJSDocTypeParameterDeclarations(node: DeclarationWithTypeParameters): ReadonlyArray; - /** - * Gets the effective type annotation of the value parameter of a set accessor. If the node - * was parsed in a JavaScript file, gets the type annotation from JSDoc. - */ - function getEffectiveSetAccessorTypeAnnotationNode(node: SetAccessorDeclaration): TypeNode | undefined; - function emitNewLineBeforeLeadingComments(lineMap: ReadonlyArray, writer: EmitTextWriter, node: TextRange, leadingComments: ReadonlyArray | undefined): void; - function emitNewLineBeforeLeadingCommentsOfPosition(lineMap: ReadonlyArray, writer: EmitTextWriter, pos: number, leadingComments: ReadonlyArray | undefined): void; - function emitNewLineBeforeLeadingCommentOfPosition(lineMap: ReadonlyArray, writer: EmitTextWriter, pos: number, commentPos: number): void; - function emitComments(text: string, lineMap: ReadonlyArray, writer: EmitTextWriter, comments: ReadonlyArray | undefined, leadingSeparator: boolean, trailingSeparator: boolean, newLine: string, writeComment: (text: string, lineMap: ReadonlyArray, writer: EmitTextWriter, commentPos: number, commentEnd: number, newLine: string) => void): void; - /** - * Detached comment is a comment at the top of file or function body that is separated from - * the next statement by space. - */ - function emitDetachedComments(text: string, lineMap: ReadonlyArray, writer: EmitTextWriter, writeComment: (text: string, lineMap: ReadonlyArray, writer: EmitTextWriter, commentPos: number, commentEnd: number, newLine: string) => void, node: TextRange, newLine: string, removeComments: boolean): { - nodePos: number; - detachedCommentEndPos: number; - } | undefined; - function writeCommentRange(text: string, lineMap: ReadonlyArray, writer: EmitTextWriter, commentPos: number, commentEnd: number, newLine: string): void; - function hasModifiers(node: Node): boolean; - function hasModifier(node: Node, flags: ModifierFlags): boolean; - function hasStaticModifier(node: Node): boolean; - function hasReadonlyModifier(node: Node): boolean; - function getSelectedModifierFlags(node: Node, flags: ModifierFlags): ModifierFlags; - function getModifierFlags(node: Node): ModifierFlags; - function getModifierFlagsNoCache(node: Node): ModifierFlags; - function modifierToFlag(token: SyntaxKind): ModifierFlags; - function isLogicalOperator(token: SyntaxKind): boolean; - function isAssignmentOperator(token: SyntaxKind): boolean; - /** Get `C` given `N` if `N` is in the position `class C extends N` where `N` is an ExpressionWithTypeArguments. */ - function tryGetClassExtendingExpressionWithTypeArguments(node: Node): ClassLikeDeclaration | undefined; - interface ClassImplementingOrExtendingExpressionWithTypeArguments { - readonly class: ClassLikeDeclaration; - readonly isImplements: boolean; - } - function tryGetClassImplementingOrExtendingExpressionWithTypeArguments(node: Node): ClassImplementingOrExtendingExpressionWithTypeArguments | undefined; - function isAssignmentExpression(node: Node, excludeCompoundAssignment: true): node is AssignmentExpression; - function isAssignmentExpression(node: Node, excludeCompoundAssignment?: false): node is AssignmentExpression; - function isDestructuringAssignment(node: Node): node is DestructuringAssignment; - function isExpressionWithTypeArgumentsInClassExtendsClause(node: Node): node is ExpressionWithTypeArguments; - function isEntityNameExpression(node: Node): node is EntityNameExpression; - function isPropertyAccessEntityNameExpression(node: Node): node is PropertyAccessEntityNameExpression; - function tryGetPropertyAccessOrIdentifierToString(expr: Expression): string | undefined; - function isPrototypeAccess(node: Node): node is PropertyAccessExpression; - function isRightSideOfQualifiedNameOrPropertyAccess(node: Node): boolean; - function isEmptyObjectLiteral(expression: Node): boolean; - function isEmptyArrayLiteral(expression: Node): boolean; - function getLocalSymbolForExportDefault(symbol: Symbol): Symbol | undefined; - /** Return ".ts", ".d.ts", or ".tsx", if that is the extension. */ - function tryExtractTSExtension(fileName: string): string | undefined; - /** - * Converts a string to a base-64 encoded ASCII string. - */ - function convertToBase64(input: string): string; - function base64encode(host: { - base64encode?(input: string): string; - } | undefined, input: string): string; - function base64decode(host: { - base64decode?(input: string): string; - } | undefined, input: string): string; - function readJson(path: string, host: { - readFile(fileName: string): string | undefined; - }): object; - function directoryProbablyExists(directoryName: string, host: { - directoryExists?: (directoryName: string) => boolean; - }): boolean; - function getNewLineCharacter(options: CompilerOptions | PrinterOptions, getNewLine?: () => string): string; - /** - * Creates a new TextRange from the provided pos and end. - * - * @param pos The start position. - * @param end The end position. - */ - function createRange(pos: number, end?: number): TextRange; - /** - * Creates a new TextRange from a provided range with a new end position. - * - * @param range A TextRange. - * @param end The new end position. - */ - function moveRangeEnd(range: TextRange, end: number): TextRange; - /** - * Creates a new TextRange from a provided range with a new start position. - * - * @param range A TextRange. - * @param pos The new Start position. - */ - function moveRangePos(range: TextRange, pos: number): TextRange; - /** - * Moves the start position of a range past any decorators. - */ - function moveRangePastDecorators(node: Node): TextRange; - /** - * Moves the start position of a range past any decorators or modifiers. - */ - function moveRangePastModifiers(node: Node): TextRange; - /** - * Determines whether a TextRange has the same start and end positions. - * - * @param range A TextRange. - */ - function isCollapsedRange(range: TextRange): boolean; - /** - * Creates a new TextRange for a token at the provides start position. - * - * @param pos The start position. - * @param token The token. - */ - function createTokenRange(pos: number, token: SyntaxKind): TextRange; - function rangeIsOnSingleLine(range: TextRange, sourceFile: SourceFile): boolean; - function rangeStartPositionsAreOnSameLine(range1: TextRange, range2: TextRange, sourceFile: SourceFile): boolean; - function rangeEndPositionsAreOnSameLine(range1: TextRange, range2: TextRange, sourceFile: SourceFile): boolean; - function rangeStartIsOnSameLineAsRangeEnd(range1: TextRange, range2: TextRange, sourceFile: SourceFile): boolean; - function rangeEndIsOnSameLineAsRangeStart(range1: TextRange, range2: TextRange, sourceFile: SourceFile): boolean; - function isNodeArrayMultiLine(list: NodeArray, sourceFile: SourceFile): boolean; - function positionsAreOnSameLine(pos1: number, pos2: number, sourceFile: SourceFile): boolean; - function getStartPositionOfRange(range: TextRange, sourceFile: SourceFile): number; - /** - * Determines whether a name was originally the declaration name of an enum or namespace - * declaration. - */ - function isDeclarationNameOfEnumOrNamespace(node: Identifier): boolean; - function getInitializedVariables(node: VariableDeclarationList): readonly VariableDeclaration[]; - function isWatchSet(options: CompilerOptions): boolean | undefined; - function closeFileWatcher(watcher: FileWatcher): void; - function getCheckFlags(symbol: Symbol): CheckFlags; - function getDeclarationModifierFlagsFromSymbol(s: Symbol): ModifierFlags; - function skipAlias(symbol: Symbol, checker: TypeChecker): Symbol; - /** See comment on `declareModuleMember` in `binder.ts`. */ - function getCombinedLocalAndExportSymbolFlags(symbol: Symbol): SymbolFlags; - function isWriteOnlyAccess(node: Node): boolean; - function isWriteAccess(node: Node): boolean; - function compareDataObjects(dst: any, src: any): boolean; - /** - * clears already present map by calling onDeleteExistingValue callback before deleting that key/value - */ - function clearMap(map: { - forEach: Map["forEach"]; - clear: Map["clear"]; - }, onDeleteValue: (valueInMap: T, key: string) => void): void; - interface MutateMapSkippingNewValuesOptions { - onDeleteValue(existingValue: T, key: string): void; - /** - * If present this is called with the key when there is value for that key both in new map as well as existing map provided - * Caller can then decide to update or remove this key. - * If the key is removed, caller will get callback of createNewValue for that key. - * If this callback is not provided, the value of such keys is not updated. - */ - onExistingValue?(existingValue: T, valueInNewMap: U, key: string): void; - } - /** - * Mutates the map with newMap such that keys in map will be same as newMap. - */ - function mutateMapSkippingNewValues(map: Map, newMap: ReadonlyMap, options: MutateMapSkippingNewValuesOptions): void; - interface MutateMapOptions extends MutateMapSkippingNewValuesOptions { - createNewValue(key: string, valueInNewMap: U): T; - } - /** - * Mutates the map with newMap such that keys in map will be same as newMap. - */ - function mutateMap(map: Map, newMap: ReadonlyMap, options: MutateMapOptions): void; - /** Calls `callback` on `directory` and every ancestor directory it has, returning the first defined result. */ - function forEachAncestorDirectory(directory: string, callback: (directory: string) => T | undefined): T | undefined; - function isAbstractConstructorType(type: Type): boolean; - function isAbstractConstructorSymbol(symbol: Symbol): boolean; - function getClassLikeDeclarationOfSymbol(symbol: Symbol): ClassLikeDeclaration | undefined; - function getObjectFlags(type: Type): ObjectFlags; - function typeHasCallOrConstructSignatures(type: Type, checker: TypeChecker): boolean; - function forSomeAncestorDirectory(directory: string, callback: (directory: string) => boolean): boolean; - function isUMDExportSymbol(symbol: Symbol | undefined): boolean; - function showModuleSpecifier({ moduleSpecifier }: ImportDeclaration): string; - function getLastChild(node: Node): Node | undefined; - /** Add a value to a set, and return true if it wasn't already present. */ - function addToSeen(seen: Map, key: string | number): boolean; - function addToSeen(seen: Map, key: string | number, value: T): boolean; - function isObjectTypeDeclaration(node: Node): node is ObjectTypeDeclaration; - function isTypeNodeKind(kind: SyntaxKind): boolean; - function isAccessExpression(node: Node): node is AccessExpression; - function isBundleFileTextLike(section: BundleFileSection): section is BundleFileTextLike; -} -declare namespace ts { - function getDefaultLibFileName(options: CompilerOptions): string; - function textSpanEnd(span: TextSpan): number; - function textSpanIsEmpty(span: TextSpan): boolean; - function textSpanContainsPosition(span: TextSpan, position: number): boolean; - function textRangeContainsPositionInclusive(span: TextRange, position: number): boolean; - function textSpanContainsTextSpan(span: TextSpan, other: TextSpan): boolean; - function textSpanOverlapsWith(span: TextSpan, other: TextSpan): boolean; - function textSpanOverlap(span1: TextSpan, span2: TextSpan): TextSpan | undefined; - function textSpanIntersectsWithTextSpan(span: TextSpan, other: TextSpan): boolean; - function textSpanIntersectsWith(span: TextSpan, start: number, length: number): boolean; - function decodedTextSpanIntersectsWith(start1: number, length1: number, start2: number, length2: number): boolean; - function textSpanIntersectsWithPosition(span: TextSpan, position: number): boolean; - function textSpanIntersection(span1: TextSpan, span2: TextSpan): TextSpan | undefined; - function createTextSpan(start: number, length: number): TextSpan; - function createTextSpanFromBounds(start: number, end: number): TextSpan; - function textChangeRangeNewSpan(range: TextChangeRange): TextSpan; - function textChangeRangeIsUnchanged(range: TextChangeRange): boolean; - function createTextChangeRange(span: TextSpan, newLength: number): TextChangeRange; - let unchangedTextChangeRange: TextChangeRange; - /** - * Called to merge all the changes that occurred across several versions of a script snapshot - * into a single change. i.e. if a user keeps making successive edits to a script we will - * have a text change from V1 to V2, V2 to V3, ..., Vn. - * - * This function will then merge those changes into a single change range valid between V1 and - * Vn. - */ - function collapseTextChangeRangesAcrossMultipleVersions(changes: ReadonlyArray): TextChangeRange; - function getTypeParameterOwner(d: Declaration): Declaration | undefined; - type ParameterPropertyDeclaration = ParameterDeclaration & { - parent: ConstructorDeclaration; - name: Identifier; - }; - function isParameterPropertyDeclaration(node: Node): node is ParameterPropertyDeclaration; - function isEmptyBindingPattern(node: BindingName): node is BindingPattern; - function isEmptyBindingElement(node: BindingElement): boolean; - function walkUpBindingElementsAndPatterns(binding: BindingElement): VariableDeclaration | ParameterDeclaration; - function getCombinedModifierFlags(node: Declaration): ModifierFlags; - function getCombinedNodeFlags(node: Node): NodeFlags; - /** - * Checks to see if the locale is in the appropriate format, - * and if it is, attempts to set the appropriate language. - */ - function validateLocaleAndSetLanguage(locale: string, sys: { - getExecutingFilePath(): string; - resolvePath(path: string): string; - fileExists(fileName: string): boolean; - readFile(fileName: string): string | undefined; - }, errors?: Push): void; - function getOriginalNode(node: Node): Node; - function getOriginalNode(node: Node, nodeTest: (node: Node) => node is T): T; - function getOriginalNode(node: Node | undefined): Node | undefined; - function getOriginalNode(node: Node | undefined, nodeTest: (node: Node | undefined) => node is T): T | undefined; - /** - * Gets a value indicating whether a node originated in the parse tree. - * - * @param node The node to test. - */ - function isParseTreeNode(node: Node): boolean; - /** - * Gets the original parse tree node for a node. - * - * @param node The original node. - * @returns The original parse tree node if found; otherwise, undefined. - */ - function getParseTreeNode(node: Node): Node; - /** - * Gets the original parse tree node for a node. - * - * @param node The original node. - * @param nodeTest A callback used to ensure the correct type of parse tree node is returned. - * @returns The original parse tree node if found; otherwise, undefined. - */ - function getParseTreeNode(node: Node | undefined, nodeTest?: (node: Node) => node is T): T | undefined; - /** Add an extra underscore to identifiers that start with two underscores to avoid issues with magic names like '__proto__' */ - function escapeLeadingUnderscores(identifier: string): __String; - /** - * Remove extra underscore from escaped identifier text content. - * - * @param identifier The escaped identifier text. - * @returns The unescaped identifier text. - */ - function unescapeLeadingUnderscores(identifier: __String): string; - function idText(identifier: Identifier): string; - function symbolName(symbol: Symbol): string; - function getNameOfJSDocTypedef(declaration: JSDocTypedefTag): Identifier | undefined; - /** @internal */ - function isNamedDeclaration(node: Node): node is NamedDeclaration & { - name: DeclarationName; - }; - /** @internal */ - function getNonAssignedNameOfDeclaration(declaration: Declaration | Expression): DeclarationName | undefined; - function getNameOfDeclaration(declaration: Declaration | Expression): DeclarationName | undefined; - /** - * Gets the JSDoc parameter tags for the node if present. - * - * @remarks Returns any JSDoc param tag whose name matches the provided - * parameter, whether a param tag on a containing function - * expression, or a param tag on a variable declaration whose - * initializer is the containing function. The tags closest to the - * node are returned first, so in the previous example, the param - * tag on the containing function expression would be first. - * - * For binding patterns, parameter tags are matched by position. - */ - function getJSDocParameterTags(param: ParameterDeclaration): ReadonlyArray; - /** - * Gets the JSDoc type parameter tags for the node if present. - * - * @remarks Returns any JSDoc template tag whose names match the provided - * parameter, whether a template tag on a containing function - * expression, or a template tag on a variable declaration whose - * initializer is the containing function. The tags closest to the - * node are returned first, so in the previous example, the template - * tag on the containing function expression would be first. - */ - function getJSDocTypeParameterTags(param: TypeParameterDeclaration): ReadonlyArray; - /** - * Return true if the node has JSDoc parameter tags. - * - * @remarks Includes parameter tags that are not directly on the node, - * for example on a variable declaration whose initializer is a function expression. - */ - function hasJSDocParameterTags(node: FunctionLikeDeclaration | SignatureDeclaration): boolean; - /** Gets the JSDoc augments tag for the node if present */ - function getJSDocAugmentsTag(node: Node): JSDocAugmentsTag | undefined; - /** Gets the JSDoc class tag for the node if present */ - function getJSDocClassTag(node: Node): JSDocClassTag | undefined; - /** Gets the JSDoc enum tag for the node if present */ - function getJSDocEnumTag(node: Node): JSDocEnumTag | undefined; - /** Gets the JSDoc this tag for the node if present */ - function getJSDocThisTag(node: Node): JSDocThisTag | undefined; - /** Gets the JSDoc return tag for the node if present */ - function getJSDocReturnTag(node: Node): JSDocReturnTag | undefined; - /** Gets the JSDoc template tag for the node if present */ - function getJSDocTemplateTag(node: Node): JSDocTemplateTag | undefined; - /** Gets the JSDoc type tag for the node if present and valid */ - function getJSDocTypeTag(node: Node): JSDocTypeTag | undefined; - /** - * Gets the type node for the node if provided via JSDoc. - * - * @remarks The search includes any JSDoc param tag that relates - * to the provided parameter, for example a type tag on the - * parameter itself, or a param tag on a containing function - * expression, or a param tag on a variable declaration whose - * initializer is the containing function. The tags closest to the - * node are examined first, so in the previous example, the type - * tag directly on the node would be returned. - */ - function getJSDocType(node: Node): TypeNode | undefined; - /** - * Gets the return type node for the node if provided via JSDoc return tag or type tag. - * - * @remarks `getJSDocReturnTag` just gets the whole JSDoc tag. This function - * gets the type from inside the braces, after the fat arrow, etc. - */ - function getJSDocReturnType(node: Node): TypeNode | undefined; - /** Get all JSDoc tags related to a node, including those on parent nodes. */ - function getJSDocTags(node: Node): ReadonlyArray; - /** Gets all JSDoc tags of a specified kind, or undefined if not present. */ - function getAllJSDocTagsOfKind(node: Node, kind: SyntaxKind): ReadonlyArray; - /** - * Gets the effective type parameters. If the node was parsed in a - * JavaScript file, gets the type parameters from the `@template` tag from JSDoc. - */ - function getEffectiveTypeParameterDeclarations(node: DeclarationWithTypeParameters): ReadonlyArray; - function getEffectiveConstraintOfTypeParameter(node: TypeParameterDeclaration): TypeNode | undefined; -} -declare namespace ts { - function isNumericLiteral(node: Node): node is NumericLiteral; - function isBigIntLiteral(node: Node): node is BigIntLiteral; - function isStringLiteral(node: Node): node is StringLiteral; - function isJsxText(node: Node): node is JsxText; - function isRegularExpressionLiteral(node: Node): node is RegularExpressionLiteral; - function isNoSubstitutionTemplateLiteral(node: Node): node is NoSubstitutionTemplateLiteral; - function isTemplateHead(node: Node): node is TemplateHead; - function isTemplateMiddle(node: Node): node is TemplateMiddle; - function isTemplateTail(node: Node): node is TemplateTail; - function isIdentifier(node: Node): node is Identifier; - function isQualifiedName(node: Node): node is QualifiedName; - function isComputedPropertyName(node: Node): node is ComputedPropertyName; - function isTypeParameterDeclaration(node: Node): node is TypeParameterDeclaration; - function isParameter(node: Node): node is ParameterDeclaration; - function isDecorator(node: Node): node is Decorator; - function isPropertySignature(node: Node): node is PropertySignature; - function isPropertyDeclaration(node: Node): node is PropertyDeclaration; - function isMethodSignature(node: Node): node is MethodSignature; - function isMethodDeclaration(node: Node): node is MethodDeclaration; - function isConstructorDeclaration(node: Node): node is ConstructorDeclaration; - function isGetAccessorDeclaration(node: Node): node is GetAccessorDeclaration; - function isSetAccessorDeclaration(node: Node): node is SetAccessorDeclaration; - function isCallSignatureDeclaration(node: Node): node is CallSignatureDeclaration; - function isConstructSignatureDeclaration(node: Node): node is ConstructSignatureDeclaration; - function isIndexSignatureDeclaration(node: Node): node is IndexSignatureDeclaration; - function isGetOrSetAccessorDeclaration(node: Node): node is AccessorDeclaration; - function isTypePredicateNode(node: Node): node is TypePredicateNode; - function isTypeReferenceNode(node: Node): node is TypeReferenceNode; - function isFunctionTypeNode(node: Node): node is FunctionTypeNode; - function isConstructorTypeNode(node: Node): node is ConstructorTypeNode; - function isTypeQueryNode(node: Node): node is TypeQueryNode; - function isTypeLiteralNode(node: Node): node is TypeLiteralNode; - function isArrayTypeNode(node: Node): node is ArrayTypeNode; - function isTupleTypeNode(node: Node): node is TupleTypeNode; - function isUnionTypeNode(node: Node): node is UnionTypeNode; - function isIntersectionTypeNode(node: Node): node is IntersectionTypeNode; - function isConditionalTypeNode(node: Node): node is ConditionalTypeNode; - function isInferTypeNode(node: Node): node is InferTypeNode; - function isParenthesizedTypeNode(node: Node): node is ParenthesizedTypeNode; - function isThisTypeNode(node: Node): node is ThisTypeNode; - function isTypeOperatorNode(node: Node): node is TypeOperatorNode; - function isIndexedAccessTypeNode(node: Node): node is IndexedAccessTypeNode; - function isMappedTypeNode(node: Node): node is MappedTypeNode; - function isLiteralTypeNode(node: Node): node is LiteralTypeNode; - function isImportTypeNode(node: Node): node is ImportTypeNode; - function isObjectBindingPattern(node: Node): node is ObjectBindingPattern; - function isArrayBindingPattern(node: Node): node is ArrayBindingPattern; - function isBindingElement(node: Node): node is BindingElement; - function isArrayLiteralExpression(node: Node): node is ArrayLiteralExpression; - function isObjectLiteralExpression(node: Node): node is ObjectLiteralExpression; - function isPropertyAccessExpression(node: Node): node is PropertyAccessExpression; - function isElementAccessExpression(node: Node): node is ElementAccessExpression; - function isCallExpression(node: Node): node is CallExpression; - function isNewExpression(node: Node): node is NewExpression; - function isTaggedTemplateExpression(node: Node): node is TaggedTemplateExpression; - function isTypeAssertion(node: Node): node is TypeAssertion; - function isConstTypeReference(node: Node): boolean; - function isParenthesizedExpression(node: Node): node is ParenthesizedExpression; - function skipPartiallyEmittedExpressions(node: Expression): Expression; - function skipPartiallyEmittedExpressions(node: Node): Node; - function isFunctionExpression(node: Node): node is FunctionExpression; - function isArrowFunction(node: Node): node is ArrowFunction; - function isDeleteExpression(node: Node): node is DeleteExpression; - function isTypeOfExpression(node: Node): node is TypeOfExpression; - function isVoidExpression(node: Node): node is VoidExpression; - function isAwaitExpression(node: Node): node is AwaitExpression; - function isPrefixUnaryExpression(node: Node): node is PrefixUnaryExpression; - function isPostfixUnaryExpression(node: Node): node is PostfixUnaryExpression; - function isBinaryExpression(node: Node): node is BinaryExpression; - function isConditionalExpression(node: Node): node is ConditionalExpression; - function isTemplateExpression(node: Node): node is TemplateExpression; - function isYieldExpression(node: Node): node is YieldExpression; - function isSpreadElement(node: Node): node is SpreadElement; - function isClassExpression(node: Node): node is ClassExpression; - function isOmittedExpression(node: Node): node is OmittedExpression; - function isExpressionWithTypeArguments(node: Node): node is ExpressionWithTypeArguments; - function isAsExpression(node: Node): node is AsExpression; - function isNonNullExpression(node: Node): node is NonNullExpression; - function isMetaProperty(node: Node): node is MetaProperty; - function isTemplateSpan(node: Node): node is TemplateSpan; - function isSemicolonClassElement(node: Node): node is SemicolonClassElement; - function isBlock(node: Node): node is Block; - function isVariableStatement(node: Node): node is VariableStatement; - function isEmptyStatement(node: Node): node is EmptyStatement; - function isExpressionStatement(node: Node): node is ExpressionStatement; - function isIfStatement(node: Node): node is IfStatement; - function isDoStatement(node: Node): node is DoStatement; - function isWhileStatement(node: Node): node is WhileStatement; - function isForStatement(node: Node): node is ForStatement; - function isForInStatement(node: Node): node is ForInStatement; - function isForOfStatement(node: Node): node is ForOfStatement; - function isContinueStatement(node: Node): node is ContinueStatement; - function isBreakStatement(node: Node): node is BreakStatement; - function isBreakOrContinueStatement(node: Node): node is BreakOrContinueStatement; - function isReturnStatement(node: Node): node is ReturnStatement; - function isWithStatement(node: Node): node is WithStatement; - function isSwitchStatement(node: Node): node is SwitchStatement; - function isLabeledStatement(node: Node): node is LabeledStatement; - function isThrowStatement(node: Node): node is ThrowStatement; - function isTryStatement(node: Node): node is TryStatement; - function isDebuggerStatement(node: Node): node is DebuggerStatement; - function isVariableDeclaration(node: Node): node is VariableDeclaration; - function isVariableDeclarationList(node: Node): node is VariableDeclarationList; - function isFunctionDeclaration(node: Node): node is FunctionDeclaration; - function isClassDeclaration(node: Node): node is ClassDeclaration; - function isInterfaceDeclaration(node: Node): node is InterfaceDeclaration; - function isTypeAliasDeclaration(node: Node): node is TypeAliasDeclaration; - function isEnumDeclaration(node: Node): node is EnumDeclaration; - function isModuleDeclaration(node: Node): node is ModuleDeclaration; - function isModuleBlock(node: Node): node is ModuleBlock; - function isCaseBlock(node: Node): node is CaseBlock; - function isNamespaceExportDeclaration(node: Node): node is NamespaceExportDeclaration; - function isImportEqualsDeclaration(node: Node): node is ImportEqualsDeclaration; - function isImportDeclaration(node: Node): node is ImportDeclaration; - function isImportClause(node: Node): node is ImportClause; - function isNamespaceImport(node: Node): node is NamespaceImport; - function isNamedImports(node: Node): node is NamedImports; - function isImportSpecifier(node: Node): node is ImportSpecifier; - function isExportAssignment(node: Node): node is ExportAssignment; - function isExportDeclaration(node: Node): node is ExportDeclaration; - function isNamedExports(node: Node): node is NamedExports; - function isExportSpecifier(node: Node): node is ExportSpecifier; - function isMissingDeclaration(node: Node): node is MissingDeclaration; - function isExternalModuleReference(node: Node): node is ExternalModuleReference; - function isJsxElement(node: Node): node is JsxElement; - function isJsxSelfClosingElement(node: Node): node is JsxSelfClosingElement; - function isJsxOpeningElement(node: Node): node is JsxOpeningElement; - function isJsxClosingElement(node: Node): node is JsxClosingElement; - function isJsxFragment(node: Node): node is JsxFragment; - function isJsxOpeningFragment(node: Node): node is JsxOpeningFragment; - function isJsxClosingFragment(node: Node): node is JsxClosingFragment; - function isJsxAttribute(node: Node): node is JsxAttribute; - function isJsxAttributes(node: Node): node is JsxAttributes; - function isJsxSpreadAttribute(node: Node): node is JsxSpreadAttribute; - function isJsxExpression(node: Node): node is JsxExpression; - function isCaseClause(node: Node): node is CaseClause; - function isDefaultClause(node: Node): node is DefaultClause; - function isHeritageClause(node: Node): node is HeritageClause; - function isCatchClause(node: Node): node is CatchClause; - function isPropertyAssignment(node: Node): node is PropertyAssignment; - function isShorthandPropertyAssignment(node: Node): node is ShorthandPropertyAssignment; - function isSpreadAssignment(node: Node): node is SpreadAssignment; - function isEnumMember(node: Node): node is EnumMember; - function isSourceFile(node: Node): node is SourceFile; - function isBundle(node: Node): node is Bundle; - function isUnparsedSource(node: Node): node is UnparsedSource; - function isUnparsedPrepend(node: Node): node is UnparsedPrepend; - function isUnparsedTextLike(node: Node): node is UnparsedTextLike; - function isUnparsedNode(node: Node): node is UnparsedNode; - function isJSDocTypeExpression(node: Node): node is JSDocTypeExpression; - function isJSDocAllType(node: JSDocAllType): node is JSDocAllType; - function isJSDocUnknownType(node: Node): node is JSDocUnknownType; - function isJSDocNullableType(node: Node): node is JSDocNullableType; - function isJSDocNonNullableType(node: Node): node is JSDocNonNullableType; - function isJSDocOptionalType(node: Node): node is JSDocOptionalType; - function isJSDocFunctionType(node: Node): node is JSDocFunctionType; - function isJSDocVariadicType(node: Node): node is JSDocVariadicType; - function isJSDoc(node: Node): node is JSDoc; - function isJSDocAuthorTag(node: Node): node is JSDocAuthorTag; - function isJSDocAugmentsTag(node: Node): node is JSDocAugmentsTag; - function isJSDocClassTag(node: Node): node is JSDocClassTag; - function isJSDocEnumTag(node: Node): node is JSDocEnumTag; - function isJSDocThisTag(node: Node): node is JSDocThisTag; - function isJSDocParameterTag(node: Node): node is JSDocParameterTag; - function isJSDocReturnTag(node: Node): node is JSDocReturnTag; - function isJSDocTypeTag(node: Node): node is JSDocTypeTag; - function isJSDocTemplateTag(node: Node): node is JSDocTemplateTag; - function isJSDocTypedefTag(node: Node): node is JSDocTypedefTag; - function isJSDocPropertyTag(node: Node): node is JSDocPropertyTag; - function isJSDocPropertyLikeTag(node: Node): node is JSDocPropertyLikeTag; - function isJSDocTypeLiteral(node: Node): node is JSDocTypeLiteral; - function isJSDocCallbackTag(node: Node): node is JSDocCallbackTag; - function isJSDocSignature(node: Node): node is JSDocSignature; -} -declare namespace ts { - function isSyntaxList(n: Node): n is SyntaxList; - function isNode(node: Node): boolean; - function isNodeKind(kind: SyntaxKind): boolean; - /** - * True if node is of some token syntax kind. - * For example, this is true for an IfKeyword but not for an IfStatement. - * Literals are considered tokens, except TemplateLiteral, but does include TemplateHead/Middle/Tail. - */ - function isToken(n: Node): boolean; - function isNodeArray(array: ReadonlyArray): array is NodeArray; - function isLiteralKind(kind: SyntaxKind): boolean; - function isLiteralExpression(node: Node): node is LiteralExpression; - function isTemplateLiteralKind(kind: SyntaxKind): boolean; - type TemplateLiteralToken = NoSubstitutionTemplateLiteral | TemplateHead | TemplateMiddle | TemplateTail; - function isTemplateLiteralToken(node: Node): node is TemplateLiteralToken; - function isTemplateMiddleOrTemplateTail(node: Node): node is TemplateMiddle | TemplateTail; - function isImportOrExportSpecifier(node: Node): node is ImportSpecifier | ExportSpecifier; - function isStringTextContainingNode(node: Node): node is StringLiteral | TemplateLiteralToken; - function isGeneratedIdentifier(node: Node): node is GeneratedIdentifier; - function isModifierKind(token: SyntaxKind): token is Modifier["kind"]; - function isParameterPropertyModifier(kind: SyntaxKind): boolean; - function isClassMemberModifier(idToken: SyntaxKind): boolean; - function isModifier(node: Node): node is Modifier; - function isEntityName(node: Node): node is EntityName; - function isPropertyName(node: Node): node is PropertyName; - function isBindingName(node: Node): node is BindingName; - function isFunctionLike(node: Node): node is SignatureDeclaration; - function isFunctionLikeDeclaration(node: Node): node is FunctionLikeDeclaration; - function isFunctionLikeKind(kind: SyntaxKind): boolean; - function isFunctionOrModuleBlock(node: Node): boolean; - function isClassElement(node: Node): node is ClassElement; - function isClassLike(node: Node): node is ClassLikeDeclaration; - function isAccessor(node: Node): node is AccessorDeclaration; - function isMethodOrAccessor(node: Node): node is MethodDeclaration | AccessorDeclaration; - function isTypeElement(node: Node): node is TypeElement; - function isClassOrTypeElement(node: Node): node is ClassElement | TypeElement; - function isObjectLiteralElementLike(node: Node): node is ObjectLiteralElementLike; - /** - * Node test that determines whether a node is a valid type node. - * This differs from the `isPartOfTypeNode` function which determines whether a node is *part* - * of a TypeNode. - */ - function isTypeNode(node: Node): node is TypeNode; - function isFunctionOrConstructorTypeNode(node: Node): node is FunctionTypeNode | ConstructorTypeNode; - function isBindingPattern(node: Node | undefined): node is BindingPattern; - function isAssignmentPattern(node: Node): node is AssignmentPattern; - function isArrayBindingElement(node: Node): node is ArrayBindingElement; - /** - * Determines whether the BindingOrAssignmentElement is a BindingElement-like declaration - */ - function isDeclarationBindingElement(bindingElement: BindingOrAssignmentElement): bindingElement is VariableDeclaration | ParameterDeclaration | BindingElement; - /** - * Determines whether a node is a BindingOrAssignmentPattern - */ - function isBindingOrAssignmentPattern(node: BindingOrAssignmentElementTarget): node is BindingOrAssignmentPattern; - /** - * Determines whether a node is an ObjectBindingOrAssignmentPattern - */ - function isObjectBindingOrAssignmentPattern(node: BindingOrAssignmentElementTarget): node is ObjectBindingOrAssignmentPattern; - /** - * Determines whether a node is an ArrayBindingOrAssignmentPattern - */ - function isArrayBindingOrAssignmentPattern(node: BindingOrAssignmentElementTarget): node is ArrayBindingOrAssignmentPattern; - function isPropertyAccessOrQualifiedNameOrImportTypeNode(node: Node): node is PropertyAccessExpression | QualifiedName | ImportTypeNode; - function isPropertyAccessOrQualifiedName(node: Node): node is PropertyAccessExpression | QualifiedName; - function isCallLikeExpression(node: Node): node is CallLikeExpression; - function isCallOrNewExpression(node: Node): node is CallExpression | NewExpression; - function isTemplateLiteral(node: Node): node is TemplateLiteral; - function isLeftHandSideExpression(node: Node): node is LeftHandSideExpression; - function isUnaryExpression(node: Node): node is UnaryExpression; - function isUnaryExpressionWithWrite(expr: Node): expr is PrefixUnaryExpression | PostfixUnaryExpression; - /** - * Determines whether a node is an expression based only on its kind. - * Use `isExpressionNode` if not in transforms. - */ - function isExpression(node: Node): node is Expression; - function isAssertionExpression(node: Node): node is AssertionExpression; - function isPartiallyEmittedExpression(node: Node): node is PartiallyEmittedExpression; - function isNotEmittedStatement(node: Node): node is NotEmittedStatement; - function isNotEmittedOrPartiallyEmittedNode(node: Node): node is NotEmittedStatement | PartiallyEmittedExpression; - function isIterationStatement(node: Node, lookInLabeledStatements: false): node is IterationStatement; - function isIterationStatement(node: Node, lookInLabeledStatements: boolean): node is IterationStatement | LabeledStatement; - function isForInOrOfStatement(node: Node): node is ForInOrOfStatement; - function isConciseBody(node: Node): node is ConciseBody; - function isFunctionBody(node: Node): node is FunctionBody; - function isForInitializer(node: Node): node is ForInitializer; - function isModuleBody(node: Node): node is ModuleBody; - function isNamespaceBody(node: Node): node is NamespaceBody; - function isJSDocNamespaceBody(node: Node): node is JSDocNamespaceBody; - function isNamedImportBindings(node: Node): node is NamedImportBindings; - function isModuleOrEnumDeclaration(node: Node): node is ModuleDeclaration | EnumDeclaration; - function isDeclaration(node: Node): node is NamedDeclaration; - function isDeclarationStatement(node: Node): node is DeclarationStatement; - /** - * Determines whether the node is a statement that is not also a declaration - */ - function isStatementButNotDeclaration(node: Node): node is Statement; - function isStatement(node: Node): node is Statement; - function isModuleReference(node: Node): node is ModuleReference; - function isJsxTagNameExpression(node: Node): node is JsxTagNameExpression; - function isJsxChild(node: Node): node is JsxChild; - function isJsxAttributeLike(node: Node): node is JsxAttributeLike; - function isStringLiteralOrJsxExpression(node: Node): node is StringLiteral | JsxExpression; - function isJsxOpeningLikeElement(node: Node): node is JsxOpeningLikeElement; - function isCaseOrDefaultClause(node: Node): node is CaseOrDefaultClause; - /** True if node is of some JSDoc syntax kind. */ - function isJSDocNode(node: Node): boolean; - /** True if node is of a kind that may contain comment text. */ - function isJSDocCommentContainingNode(node: Node): boolean; - function isJSDocTag(node: Node): node is JSDocTag; - function isSetAccessor(node: Node): node is SetAccessorDeclaration; - function isGetAccessor(node: Node): node is GetAccessorDeclaration; - /** True if has jsdoc nodes attached to it. */ - function hasJSDocNodes(node: Node): node is HasJSDoc; - /** True if has type node attached to it. */ - function hasType(node: Node): node is HasType; - /** True if has initializer node attached to it. */ - function hasInitializer(node: Node): node is HasInitializer; - /** True if has initializer node attached to it. */ - function hasOnlyExpressionInitializer(node: Node): node is HasExpressionInitializer; - function isObjectLiteralElement(node: Node): node is ObjectLiteralElement; - function isTypeReferenceType(node: Node): node is TypeReferenceType; - function guessIndentation(lines: string[]): number | undefined; - function isStringLiteralLike(node: Node): node is StringLiteralLike; -} -declare namespace ts { - function isNamedImportsOrExports(node: Node): node is NamedImportsOrExports; - interface ObjectAllocator { - getNodeConstructor(): new (kind: SyntaxKind, pos?: number, end?: number) => Node; - getTokenConstructor(): new (kind: TKind, pos?: number, end?: number) => Token; - getIdentifierConstructor(): new (kind: SyntaxKind.Identifier, pos?: number, end?: number) => Identifier; - getSourceFileConstructor(): new (kind: SyntaxKind.SourceFile, pos?: number, end?: number) => SourceFile; - getSymbolConstructor(): new (flags: SymbolFlags, name: __String) => Symbol; - getTypeConstructor(): new (checker: TypeChecker, flags: TypeFlags) => Type; - getSignatureConstructor(): new (checker: TypeChecker) => Signature; - getSourceMapSourceConstructor(): new (fileName: string, text: string, skipTrivia?: (pos: number) => number) => SourceMapSource; - } - let objectAllocator: ObjectAllocator; - function formatStringFromArgs(text: string, args: ArrayLike, baseIndex?: number): string; - let localizedDiagnosticMessages: MapLike | undefined; - function getLocaleSpecificMessage(message: DiagnosticMessage): string; - function createFileDiagnostic(file: SourceFile, start: number, length: number, message: DiagnosticMessage, ...args: (string | number | undefined)[]): DiagnosticWithLocation; - function formatMessage(_dummy: any, message: DiagnosticMessage, ...args: (string | number | undefined)[]): string; - function createCompilerDiagnostic(message: DiagnosticMessage, ...args: (string | number | undefined)[]): Diagnostic; - function createCompilerDiagnosticFromMessageChain(chain: DiagnosticMessageChain): Diagnostic; - function chainDiagnosticMessages(details: DiagnosticMessageChain | DiagnosticMessageChain[] | undefined, message: DiagnosticMessage, ...args: (string | number | undefined)[]): DiagnosticMessageChain; - function concatenateDiagnosticMessageChains(headChain: DiagnosticMessageChain, tailChain: DiagnosticMessageChain): void; - function compareDiagnostics(d1: Diagnostic, d2: Diagnostic): Comparison; - function compareDiagnosticsSkipRelatedInformation(d1: Diagnostic, d2: Diagnostic): Comparison; - function getEmitScriptTarget(compilerOptions: CompilerOptions): ScriptTarget; - function getEmitModuleKind(compilerOptions: { - module?: CompilerOptions["module"]; - target?: CompilerOptions["target"]; - }): ModuleKind.None | ModuleKind.CommonJS | ModuleKind; - function getEmitModuleResolutionKind(compilerOptions: CompilerOptions): ModuleResolutionKind; - function hasJsonModuleEmitEnabled(options: CompilerOptions): boolean; - function unreachableCodeIsError(options: CompilerOptions): boolean; - function unusedLabelIsError(options: CompilerOptions): boolean; - function getAreDeclarationMapsEnabled(options: CompilerOptions): boolean; - function getAllowSyntheticDefaultImports(compilerOptions: CompilerOptions): boolean; - function getEmitDeclarations(compilerOptions: CompilerOptions): boolean; - function isIncrementalCompilation(options: CompilerOptions): boolean; - type StrictOptionName = "noImplicitAny" | "noImplicitThis" | "strictNullChecks" | "strictFunctionTypes" | "strictBindCallApply" | "strictPropertyInitialization" | "alwaysStrict"; - function getStrictOptionValue(compilerOptions: CompilerOptions, flag: StrictOptionName): boolean; - function compilerOptionsAffectSemanticDiagnostics(newOptions: CompilerOptions, oldOptions: CompilerOptions): boolean; - function compilerOptionsAffectEmit(newOptions: CompilerOptions, oldOptions: CompilerOptions): boolean; - function getCompilerOptionValue(options: CompilerOptions, option: CommandLineOption): unknown; - function hasZeroOrOneAsteriskCharacter(str: string): boolean; - /** - * Internally, we represent paths as strings with '/' as the directory separator. - * When we make system calls (eg: LanguageServiceHost.getDirectory()), - * we expect the host to correctly handle paths in our specified format. - */ - const directorySeparator = "/"; - /** - * Normalize path separators. - */ - function normalizeSlashes(path: string): string; - /** - * Returns length of the root part of a path or URL (i.e. length of "/", "x:/", "//server/share/, file:///user/files"). - * - * For example: - * ```ts - * getRootLength("a") === 0 // "" - * getRootLength("/") === 1 // "/" - * getRootLength("c:") === 2 // "c:" - * getRootLength("c:d") === 0 // "" - * getRootLength("c:/") === 3 // "c:/" - * getRootLength("c:\\") === 3 // "c:\\" - * getRootLength("//server") === 7 // "//server" - * getRootLength("//server/share") === 8 // "//server/" - * getRootLength("\\\\server") === 7 // "\\\\server" - * getRootLength("\\\\server\\share") === 8 // "\\\\server\\" - * getRootLength("file:///path") === 8 // "file:///" - * getRootLength("file:///c:") === 10 // "file:///c:" - * getRootLength("file:///c:d") === 8 // "file:///" - * getRootLength("file:///c:/path") === 11 // "file:///c:/" - * getRootLength("file://server") === 13 // "file://server" - * getRootLength("file://server/path") === 14 // "file://server/" - * getRootLength("http://server") === 13 // "http://server" - * getRootLength("http://server/path") === 14 // "http://server/" - * ``` - */ - function getRootLength(path: string): number; - function normalizePath(path: string): string; - function normalizePathAndParts(path: string): { - path: string; - parts: string[]; - }; - /** - * Returns the path except for its basename. Semantics align with NodeJS's `path.dirname` - * except that we support URL's as well. - * - * ```ts - * getDirectoryPath("/path/to/file.ext") === "/path/to" - * getDirectoryPath("/path/to/") === "/path" - * getDirectoryPath("/") === "/" - * ``` - */ - function getDirectoryPath(path: Path): Path; - /** - * Returns the path except for its basename. Semantics align with NodeJS's `path.dirname` - * except that we support URL's as well. - * - * ```ts - * getDirectoryPath("/path/to/file.ext") === "/path/to" - * getDirectoryPath("/path/to/") === "/path" - * getDirectoryPath("/") === "/" - * ``` - */ - function getDirectoryPath(path: string): string; - function startsWithDirectory(fileName: string, directoryName: string, getCanonicalFileName: GetCanonicalFileName): boolean; - function isUrl(path: string): boolean; - function pathIsRelative(path: string): boolean; - /** - * Determines whether a path is an absolute path (e.g. starts with `/`, or a dos path - * like `c:`, `c:\` or `c:/`). - */ - function isRootedDiskPath(path: string): boolean; - /** - * Determines whether a path consists only of a path root. - */ - function isDiskPathRoot(path: string): boolean; - function convertToRelativePath(absoluteOrRelativePath: string, basePath: string, getCanonicalFileName: (path: string) => string): string; - /** - * Parse a path into an array containing a root component (at index 0) and zero or more path - * components (at indices > 0). The result is not normalized. - * If the path is relative, the root component is `""`. - * If the path is absolute, the root component includes the first path separator (`/`). - */ - function getPathComponents(path: string, currentDirectory?: string): string[]; - /** - * Reduce an array of path components to a more simplified path by navigating any - * `"."` or `".."` entries in the path. - */ - function reducePathComponents(components: ReadonlyArray): string[]; - /** - * Parse a path into an array containing a root component (at index 0) and zero or more path - * components (at indices > 0). The result is normalized. - * If the path is relative, the root component is `""`. - * If the path is absolute, the root component includes the first path separator (`/`). - */ - function getNormalizedPathComponents(path: string, currentDirectory: string | undefined): string[]; - function getNormalizedAbsolutePath(fileName: string, currentDirectory: string | undefined): string; - /** - * Formats a parsed path consisting of a root component (at index 0) and zero or more path - * segments (at indices > 0). - */ - function getPathFromPathComponents(pathComponents: ReadonlyArray): string; - function getNormalizedAbsolutePathWithoutRoot(fileName: string, currentDirectory: string | undefined): string; -} -declare namespace ts { - function getPathComponentsRelativeTo(from: string, to: string, stringEqualityComparer: (a: string, b: string) => boolean, getCanonicalFileName: GetCanonicalFileName): string[]; - function getRelativePathFromFile(from: string, to: string, getCanonicalFileName: GetCanonicalFileName): string; - /** - * Gets a relative path that can be used to traverse between `from` and `to`. - */ - function getRelativePathFromDirectory(from: string, to: string, ignoreCase: boolean): string; - /** - * Gets a relative path that can be used to traverse between `from` and `to`. - */ - function getRelativePathFromDirectory(fromDirectory: string, to: string, getCanonicalFileName: GetCanonicalFileName): string; - function getRelativePathToDirectoryOrUrl(directoryPathOrUrl: string, relativeOrAbsolutePath: string, currentDirectory: string, getCanonicalFileName: GetCanonicalFileName, isAbsolutePathAnUrl: boolean): string; - /** - * Ensures a path is either absolute (prefixed with `/` or `c:`) or dot-relative (prefixed - * with `./` or `../`) so as not to be confused with an unprefixed module name. - */ - function ensurePathIsNonModuleName(path: string): string; - /** - * Returns the path except for its containing directory name. - * Semantics align with NodeJS's `path.basename` except that we support URL's as well. - * - * ```ts - * getBaseFileName("/path/to/file.ext") === "file.ext" - * getBaseFileName("/path/to/") === "to" - * getBaseFileName("/") === "" - * ``` - */ - function getBaseFileName(path: string): string; - /** - * Gets the portion of a path following the last (non-terminal) separator (`/`). - * Semantics align with NodeJS's `path.basename` except that we support URL's as well. - * If the base name has any one of the provided extensions, it is removed. - * - * ```ts - * getBaseFileName("/path/to/file.ext", ".ext", true) === "file" - * getBaseFileName("/path/to/file.js", ".ext", true) === "file.js" - * ``` - */ - function getBaseFileName(path: string, extensions: string | ReadonlyArray, ignoreCase: boolean): string; - /** - * Combines paths. If a path is absolute, it replaces any previous path. - */ - function combinePaths(path: string, ...paths: (string | undefined)[]): string; - /** - * Combines and resolves paths. If a path is absolute, it replaces any previous path. Any - * `.` and `..` path components are resolved. - */ - function resolvePath(path: string, ...paths: (string | undefined)[]): string; - /** - * Determines whether a path has a trailing separator (`/` or `\\`). - */ - function hasTrailingDirectorySeparator(path: string): boolean; - /** - * Removes a trailing directory separator from a path. - * @param path The path. - */ - function removeTrailingDirectorySeparator(path: Path): Path; - function removeTrailingDirectorySeparator(path: string): string; - /** - * Adds a trailing directory separator to a path, if it does not already have one. - * @param path The path. - */ - function ensureTrailingDirectorySeparator(path: Path): Path; - function ensureTrailingDirectorySeparator(path: string): string; - /** - * Performs a case-sensitive comparison of two paths. - */ - function comparePathsCaseSensitive(a: string, b: string): Comparison.LessThan | Comparison.LessThan | Comparison | Comparison.GreaterThan; - /** - * Performs a case-insensitive comparison of two paths. - */ - function comparePathsCaseInsensitive(a: string, b: string): Comparison.LessThan | Comparison.LessThan | Comparison | Comparison.GreaterThan; - function comparePaths(a: string, b: string, ignoreCase?: boolean): Comparison; - function comparePaths(a: string, b: string, currentDirectory: string, ignoreCase?: boolean): Comparison; - function containsPath(parent: string, child: string, ignoreCase?: boolean): boolean; - function containsPath(parent: string, child: string, currentDirectory: string, ignoreCase?: boolean): boolean; - function tryRemoveDirectoryPrefix(path: string, dirPath: string, getCanonicalFileName: GetCanonicalFileName): string | undefined; - function regExpEscape(text: string): string; - function hasExtension(fileName: string): boolean; - const commonPackageFolders: ReadonlyArray; - function getRegularExpressionForWildcard(specs: ReadonlyArray | undefined, basePath: string, usage: "files" | "directories" | "exclude"): string | undefined; - function getRegularExpressionsForWildcards(specs: ReadonlyArray | undefined, basePath: string, usage: "files" | "directories" | "exclude"): ReadonlyArray | undefined; - /** - * An "includes" path "foo" is implicitly a glob "foo/** /*" (without the space) if its last component has no extension, - * and does not contain any glob characters itself. - */ - function isImplicitGlob(lastPathComponent: string): boolean; - interface FileSystemEntries { - readonly files: ReadonlyArray; - readonly directories: ReadonlyArray; - } - interface FileMatcherPatterns { - /** One pattern for each "include" spec. */ - includeFilePatterns: ReadonlyArray | undefined; - /** One pattern matching one of any of the "include" specs. */ - includeFilePattern: string | undefined; - includeDirectoryPattern: string | undefined; - excludePattern: string | undefined; - basePaths: ReadonlyArray; - } - /** @param path directory of the tsconfig.json */ - function getFileMatcherPatterns(path: string, excludes: ReadonlyArray | undefined, includes: ReadonlyArray | undefined, useCaseSensitiveFileNames: boolean, currentDirectory: string): FileMatcherPatterns; - function getRegexFromPattern(pattern: string, useCaseSensitiveFileNames: boolean): RegExp; - /** @param path directory of the tsconfig.json */ - function matchFiles(path: string, extensions: ReadonlyArray | undefined, excludes: ReadonlyArray | undefined, includes: ReadonlyArray | undefined, useCaseSensitiveFileNames: boolean, currentDirectory: string, depth: number | undefined, getFileSystemEntries: (path: string) => FileSystemEntries, realpath: (path: string) => string): string[]; - function ensureScriptKind(fileName: string, scriptKind: ScriptKind | undefined): ScriptKind; - function getScriptKindFromFileName(fileName: string): ScriptKind; - /** - * List of supported extensions in order of file resolution precedence. - */ - const supportedTSExtensions: ReadonlyArray; - const supportedTSExtensionsWithJson: ReadonlyArray; - /** Must have ".d.ts" first because if ".ts" goes first, that will be detected as the extension instead of ".d.ts". */ - const supportedTSExtensionsForExtractExtension: ReadonlyArray; - const supportedJSExtensions: ReadonlyArray; - const supportedJSAndJsonExtensions: ReadonlyArray; - function getSupportedExtensions(options?: CompilerOptions): ReadonlyArray; - function getSupportedExtensions(options?: CompilerOptions, extraFileExtensions?: ReadonlyArray): ReadonlyArray; - function getSuppoertedExtensionsWithJsonIfResolveJsonModule(options: CompilerOptions | undefined, supportedExtensions: ReadonlyArray): ReadonlyArray; - function hasJSFileExtension(fileName: string): boolean; - function hasJSOrJsonFileExtension(fileName: string): boolean; - function hasTSFileExtension(fileName: string): boolean; - function isSupportedSourceFileName(fileName: string, compilerOptions?: CompilerOptions, extraFileExtensions?: ReadonlyArray): boolean; - /** - * Extension boundaries by priority. Lower numbers indicate higher priorities, and are - * aligned to the offset of the highest priority extension in the - * allSupportedExtensions array. - */ - enum ExtensionPriority { - TypeScriptFiles = 0, - DeclarationAndJavaScriptFiles = 2, - Highest = 0, - Lowest = 2 - } - function getExtensionPriority(path: string, supportedExtensions: ReadonlyArray): ExtensionPriority; - /** - * Adjusts an extension priority to be the highest priority within the same range. - */ - function adjustExtensionPriority(extensionPriority: ExtensionPriority, supportedExtensions: ReadonlyArray): ExtensionPriority; - /** - * Gets the next lowest extension priority for a given priority. - */ - function getNextLowestExtensionPriority(extensionPriority: ExtensionPriority, supportedExtensions: ReadonlyArray): ExtensionPriority; - function removeFileExtension(path: string): string; - function tryRemoveExtension(path: string, extension: string): string | undefined; - function removeExtension(path: string, extension: string): string; - function changeExtension(path: T, newExtension: string): T; - function changeAnyExtension(path: string, ext: string): string; - function changeAnyExtension(path: string, ext: string, extensions: string | ReadonlyArray, ignoreCase: boolean): string; - function tryParsePattern(pattern: string): Pattern | undefined; - function positionIsSynthesized(pos: number): boolean; - /** True if an extension is one of the supported TypeScript extensions. */ - function extensionIsTS(ext: Extension): boolean; - function resolutionExtensionIsTSOrJson(ext: Extension): boolean; - /** - * Gets the extension from a path. - * Path must have a valid extension. - */ - function extensionFromPath(path: string): Extension; - function isAnySupportedFileExtension(path: string): boolean; - function tryGetExtensionFromPath(path: string): Extension | undefined; - /** - * Gets the file extension for a path. - */ - function getAnyExtensionFromPath(path: string): string; - /** - * Gets the file extension for a path, provided it is one of the provided extensions. - */ - function getAnyExtensionFromPath(path: string, extensions: string | ReadonlyArray, ignoreCase: boolean): string; - function isCheckJsEnabledForFile(sourceFile: SourceFile, compilerOptions: CompilerOptions): boolean | undefined; - const emptyFileSystemEntries: FileSystemEntries; - /** - * patternStrings contains both pattern strings (containing "*") and regular strings. - * Return an exact match if possible, or a pattern match, or undefined. - * (These are verified by verifyCompilerOptions to have 0 or 1 "*" characters.) - */ - function matchPatternOrExact(patternStrings: ReadonlyArray, candidate: string): string | Pattern | undefined; - type Mutable = { - -readonly [K in keyof T]: T[K]; - }; - function sliceAfter(arr: ReadonlyArray, value: T): ReadonlyArray; - function addRelatedInfo(diagnostic: T, ...relatedInformation: DiagnosticRelatedInformation[]): T; - function minAndMax(arr: ReadonlyArray, getValue: (value: T) => number): { - readonly min: number; - readonly max: number; - }; - interface ReadonlyNodeSet { - has(node: TNode): boolean; - forEach(cb: (node: TNode) => void): void; - some(pred: (node: TNode) => boolean): boolean; - } - class NodeSet implements ReadonlyNodeSet { - private map; - add(node: TNode): void; - tryAdd(node: TNode): boolean; - has(node: TNode): boolean; - forEach(cb: (node: TNode) => void): void; - some(pred: (node: TNode) => boolean): boolean; - } - interface ReadonlyNodeMap { - get(node: TNode): TValue | undefined; - has(node: TNode): boolean; - } - class NodeMap implements ReadonlyNodeMap { - private map; - get(node: TNode): TValue | undefined; - getOrUpdate(node: TNode, setValue: () => TValue): TValue; - set(node: TNode, value: TValue): void; - has(node: TNode): boolean; - forEach(cb: (value: TValue, node: TNode) => void): void; - } - function rangeOfNode(node: Node): TextRange; - function rangeOfTypeParameters(typeParameters: NodeArray): TextRange; - function skipTypeChecking(sourceFile: SourceFile, options: CompilerOptions): boolean | undefined; - function isJsonEqual(a: unknown, b: unknown): boolean; - function getOrUpdate(map: Map, key: string, getDefault: () => T): T; - /** - * Converts a bigint literal string, e.g. `0x1234n`, - * to its decimal string representation, e.g. `4660`. - */ - function parsePseudoBigInt(stringValue: string): string; - function pseudoBigIntToString({ negative, base10Value }: PseudoBigInt): string; -} -declare namespace ts { - function createNode(kind: SyntaxKind, pos?: number, end?: number): Node; - function isJSDocLikeText(text: string, start: number): boolean; - /** - * Invokes a callback for each child of the given node. The 'cbNode' callback is invoked for all child nodes - * stored in properties. If a 'cbNodes' callback is specified, it is invoked for embedded arrays; otherwise, - * embedded arrays are flattened and the 'cbNode' callback is invoked for each element. If a callback returns - * a truthy value, iteration stops and that value is returned. Otherwise, undefined is returned. - * - * @param node a given node to visit its children - * @param cbNode a callback to be invoked for all child nodes - * @param cbNodes a callback to be invoked for embedded array - * - * @remarks `forEachChild` must visit the children of a node in the order - * that they appear in the source code. The language service depends on this property to locate nodes by position. - */ - function forEachChild(node: Node, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined; - function createSourceFile(fileName: string, sourceText: string, languageVersion: ScriptTarget, setParentNodes?: boolean, scriptKind?: ScriptKind): SourceFile; - function parseIsolatedEntityName(text: string, languageVersion: ScriptTarget): EntityName | undefined; - /** - * Parse json text into SyntaxTree and return node and parse errors if any - * @param fileName - * @param sourceText - */ - function parseJsonText(fileName: string, sourceText: string): JsonSourceFile; - function isExternalModule(file: SourceFile): boolean; - function updateSourceFile(sourceFile: SourceFile, newText: string, textChangeRange: TextChangeRange, aggressiveChecks?: boolean): SourceFile; - function parseIsolatedJSDocComment(content: string, start?: number, length?: number): { - jsDoc: JSDoc; - diagnostics: Diagnostic[]; - } | undefined; - function parseJSDocTypeExpressionForTests(content: string, start?: number, length?: number): { - jsDocTypeExpression: JSDocTypeExpression; - diagnostics: Diagnostic[]; - } | undefined; - /** @internal */ - function isDeclarationFileName(fileName: string): boolean; - interface PragmaContext { - languageVersion: ScriptTarget; - pragmas?: PragmaMap; - checkJsDirective?: CheckJsDirective; - referencedFiles: FileReference[]; - typeReferenceDirectives: FileReference[]; - libReferenceDirectives: FileReference[]; - amdDependencies: AmdDependency[]; - hasNoDefaultLib?: boolean; - moduleName?: string; - } - function processCommentPragmas(context: PragmaContext, sourceText: string): void; - type PragmaDiagnosticReporter = (pos: number, length: number, message: DiagnosticMessage) => void; - function processPragmasIntoFields(context: PragmaContext, reportDiagnostic: PragmaDiagnosticReporter): void; - /** @internal */ - function tagNamesAreEquivalent(lhs: JsxTagNameExpression, rhs: JsxTagNameExpression): boolean; -} -declare namespace ts { - export const compileOnSaveCommandLineOption: CommandLineOption; - /** - * An array of supported "lib" reference file names used to determine the order for inclusion - * when referenced, as well as for spelling suggestions. This ensures the correct ordering for - * overload resolution when a type declared in one lib is extended by another. - */ - export const libs: string[]; - /** - * A map of lib names to lib files. This map is used both for parsing the "lib" command line - * option as well as for resolving lib reference directives. - */ - export const libMap: Map; - export const commonOptionsWithBuild: CommandLineOption[]; - export const optionDeclarations: CommandLineOption[]; - export const semanticDiagnosticsOptionDeclarations: ReadonlyArray; - export const affectsEmitOptionDeclarations: ReadonlyArray; - export const moduleResolutionOptionDeclarations: ReadonlyArray; - export const sourceFileAffectingCompilerOptions: ReadonlyArray; - export const buildOpts: CommandLineOption[]; - export const typeAcquisitionDeclarations: CommandLineOption[]; - export interface OptionNameMap { - optionNameMap: Map; - shortOptionNames: Map; - } - export const defaultInitCompilerOptions: CompilerOptions; - export function convertEnableAutoDiscoveryToEnable(typeAcquisition: TypeAcquisition): TypeAcquisition; - export function getOptionNameMap(): OptionNameMap; - export function createOptionNameMap(optionDeclarations: ReadonlyArray): OptionNameMap; - export function createCompilerDiagnosticForInvalidCustomType(opt: CommandLineOptionOfCustomType): Diagnostic; - export function parseCustomTypeOption(opt: CommandLineOptionOfCustomType, value: string, errors: Push): string | number | undefined; - export function parseListTypeOption(opt: CommandLineOptionOfListType, value: string | undefined, errors: Push): (string | number)[] | undefined; - export function parseCommandLine(commandLine: ReadonlyArray, readFile?: (path: string) => string | undefined): ParsedCommandLine; - /** @internal */ - export function getOptionFromName(optionName: string, allowShort?: boolean): CommandLineOption | undefined; - export interface ParsedBuildCommand { - buildOptions: BuildOptions; - projects: string[]; - errors: Diagnostic[]; - } - export function parseBuildCommand(args: string[]): ParsedBuildCommand; - export function printVersion(): void; - export function printHelp(optionsList: ReadonlyArray, syntaxPrefix?: string): void; - export type DiagnosticReporter = (diagnostic: Diagnostic) => void; - /** - * Reports config file diagnostics - */ - export interface ConfigFileDiagnosticsReporter { - /** - * Reports unrecoverable error when parsing config file - */ - onUnRecoverableConfigFileDiagnostic: DiagnosticReporter; - } - /** - * Interface extending ParseConfigHost to support ParseConfigFile that reads config file and reports errors - */ - export interface ParseConfigFileHost extends ParseConfigHost, ConfigFileDiagnosticsReporter { - getCurrentDirectory(): string; - } - /** - * Reads the config file, reports errors if any and exits if the config file cannot be found - */ - export function getParsedCommandLineOfConfigFile(configFileName: string, optionsToExtend: CompilerOptions, host: ParseConfigFileHost, extendedConfigCache?: Map): ParsedCommandLine | undefined; - /** - * Read tsconfig.json file - * @param fileName The path to the config file - */ - export function readConfigFile(fileName: string, readFile: (path: string) => string | undefined): { - config?: any; - error?: Diagnostic; - }; - /** - * Parse the text of the tsconfig.json file - * @param fileName The path to the config file - * @param jsonText The text of the config file - */ - export function parseConfigFileTextToJson(fileName: string, jsonText: string): { - config?: any; - error?: Diagnostic; - }; - /** - * Read tsconfig.json file - * @param fileName The path to the config file - */ - export function readJsonConfigFile(fileName: string, readFile: (path: string) => string | undefined): TsConfigSourceFile; - interface JsonConversionNotifier { - /** - * Notifies parent option object is being set with the optionKey and a valid optionValue - * Currently it notifies only if there is element with type object (parentOption) and - * has element's option declarations map associated with it - * @param parentOption parent option name in which the option and value are being set - * @param option option declaration which is being set with the value - * @param value value of the option - */ - onSetValidOptionKeyValueInParent(parentOption: string, option: CommandLineOption, value: CompilerOptionsValue): void; - /** - * Notify when valid root key value option is being set - * @param key option key - * @param keyNode node corresponding to node in the source file - * @param value computed value of the key - * @param ValueNode node corresponding to value in the source file - */ - onSetValidOptionKeyValueInRoot(key: string, keyNode: PropertyName, value: CompilerOptionsValue, valueNode: Expression): void; - /** - * Notify when unknown root key value option is being set - * @param key option key - * @param keyNode node corresponding to node in the source file - * @param value computed value of the key - * @param ValueNode node corresponding to value in the source file - */ - onSetUnknownOptionKeyValueInRoot(key: string, keyNode: PropertyName, value: CompilerOptionsValue, valueNode: Expression): void; - } - /** - * Convert the json syntax tree into the json value - */ - export function convertToObject(sourceFile: JsonSourceFile, errors: Push): any; - /** - * Convert the json syntax tree into the json value and report errors - * This returns the json value (apart from checking errors) only if returnValue provided is true. - * Otherwise it just checks the errors and returns undefined - */ - export function convertToObjectWorker(sourceFile: JsonSourceFile, errors: Push, returnValue: boolean, knownRootOptions: CommandLineOption | undefined, jsonConversionNotifier: JsonConversionNotifier | undefined): any; - /** @internal */ - export interface TSConfig { - compilerOptions: CompilerOptions; - compileOnSave: boolean | undefined; - exclude?: ReadonlyArray; - files: ReadonlyArray | undefined; - include?: ReadonlyArray; - references: ReadonlyArray | undefined; - } - /** - * Generate an uncommented, complete tsconfig for use with "--showConfig" - * @param configParseResult options to be generated into tsconfig.json - * @param configFileName name of the parsed config file - output paths will be generated relative to this - * @param host provides current directory and case sensitivity services - */ - /** @internal */ - export function convertToTSConfig(configParseResult: ParsedCommandLine, configFileName: string, host: { - getCurrentDirectory(): string; - useCaseSensitiveFileNames: boolean; - }): TSConfig; - /** - * Generate tsconfig configuration when running command line "--init" - * @param options commandlineOptions to be generated into tsconfig.json - * @param fileNames array of filenames to be generated into tsconfig.json - */ - export function generateTSConfig(options: CompilerOptions, fileNames: ReadonlyArray, newLine: string): string; - /** - * Parse the contents of a config file (tsconfig.json). - * @param json The contents of the config file to parse - * @param host Instance of ParseConfigHost used to enumerate files in folder. - * @param basePath A root directory to resolve relative path entries in the config - * file to. e.g. outDir - */ - export function parseJsonConfigFileContent(json: any, host: ParseConfigHost, basePath: string, existingOptions?: CompilerOptions, configFileName?: string, resolutionStack?: Path[], extraFileExtensions?: ReadonlyArray, extendedConfigCache?: Map): ParsedCommandLine; - /** - * Parse the contents of a config file (tsconfig.json). - * @param jsonNode The contents of the config file to parse - * @param host Instance of ParseConfigHost used to enumerate files in folder. - * @param basePath A root directory to resolve relative path entries in the config - * file to. e.g. outDir - */ - export function parseJsonSourceFileConfigFileContent(sourceFile: TsConfigSourceFile, host: ParseConfigHost, basePath: string, existingOptions?: CompilerOptions, configFileName?: string, resolutionStack?: Path[], extraFileExtensions?: ReadonlyArray, extendedConfigCache?: Map): ParsedCommandLine; - export function setConfigFileInOptions(options: CompilerOptions, configFile: TsConfigSourceFile | undefined): void; - export function canJsonReportNoInutFiles(raw: any): boolean; - export function updateErrorForNoInputFiles(result: ExpandResult, configFileName: string, configFileSpecs: ConfigFileSpecs, configParseDiagnostics: Diagnostic[], canJsonReportNoInutFiles: boolean): boolean; - export interface ParsedTsconfig { - raw: any; - options?: CompilerOptions; - typeAcquisition?: TypeAcquisition; - /** - * Note that the case of the config path has not yet been normalized, as no files have been imported into the project yet - */ - extendedConfigPath?: string; - } - export interface ExtendedConfigCacheEntry { - extendedResult: TsConfigSourceFile; - extendedConfig: ParsedTsconfig | undefined; - } - export function convertCompilerOptionsFromJson(jsonOptions: any, basePath: string, configFileName?: string): { - options: CompilerOptions; - errors: Diagnostic[]; - }; - export function convertTypeAcquisitionFromJson(jsonOptions: any, basePath: string, configFileName?: string): { - options: TypeAcquisition; - errors: Diagnostic[]; - }; - /** - * Gets the file names from the provided config file specs that contain, files, include, exclude and - * other properties needed to resolve the file names - * @param spec The config file specs extracted with file names to include, wildcards to include/exclude and other details - * @param basePath The base path for any relative file specifications. - * @param options Compiler options. - * @param host The host used to resolve files and directories. - * @param extraFileExtensions optionaly file extra file extension information from host - */ - export function getFileNamesFromConfigSpecs(spec: ConfigFileSpecs, basePath: string, options: CompilerOptions, host: ParseConfigHost, extraFileExtensions?: ReadonlyArray): ExpandResult; - /** - * Produces a cleaned version of compiler options with personally identifying info (aka, paths) removed. - * Also converts enum values back to strings. - */ - export function convertCompilerOptionsForTelemetry(opts: CompilerOptions): CompilerOptions; - export {}; -} -declare namespace ts { - function trace(host: ModuleResolutionHost, message: DiagnosticMessage, ...args: any[]): void; - function isTraceEnabled(compilerOptions: CompilerOptions, host: ModuleResolutionHost): boolean; - /** Array that is only intended to be pushed to, never read. */ - interface Push { - push(value: T): void; - } - function getPackageJsonTypesVersionsPaths(typesVersions: MapLike>): { - version: string; - paths: MapLike; - } | undefined; - function getEffectiveTypeRoots(options: CompilerOptions, host: GetEffectiveTypeRootsHost): string[] | undefined; - /** - * @param {string | undefined} containingFile - file that contains type reference directive, can be undefined if containing file is unknown. - * This is possible in case if resolution is performed for directives specified via 'types' parameter. In this case initial path for secondary lookups - * is assumed to be the same as root directory of the project. - */ - function resolveTypeReferenceDirective(typeReferenceDirectiveName: string, containingFile: string | undefined, options: CompilerOptions, host: ModuleResolutionHost, redirectedReference?: ResolvedProjectReference): ResolvedTypeReferenceDirectiveWithFailedLookupLocations; - /** - * Given a set of options, returns the set of type directive names - * that should be included for this program automatically. - * This list could either come from the config file, - * or from enumerating the types root + initial secondary types lookup location. - * More type directives might appear in the program later as a result of loading actual source files; - * this list is only the set of defaults that are implicitly included. - */ - function getAutomaticTypeDirectiveNames(options: CompilerOptions, host: ModuleResolutionHost): string[]; - /** - * Cached module resolutions per containing directory. - * This assumes that any module id will have the same resolution for sibling files located in the same folder. - */ - interface ModuleResolutionCache extends NonRelativeModuleNameResolutionCache { - getOrCreateCacheForDirectory(directoryName: string, redirectedReference?: ResolvedProjectReference): Map; - directoryToModuleNameMap: CacheWithRedirects>; - } - /** - * Stored map from non-relative module name to a table: directory -> result of module lookup in this directory - * We support only non-relative module names because resolution of relative module names is usually more deterministic and thus less expensive. - */ - interface NonRelativeModuleNameResolutionCache { - getOrCreateCacheForModuleName(nonRelativeModuleName: string, redirectedReference?: ResolvedProjectReference): PerModuleNameCache; - moduleNameToDirectoryMap: CacheWithRedirects; - } - interface PerModuleNameCache { - get(directory: string): ResolvedModuleWithFailedLookupLocations | undefined; - set(directory: string, result: ResolvedModuleWithFailedLookupLocations): void; - } - function createModuleResolutionCache(currentDirectory: string, getCanonicalFileName: (s: string) => string, options?: CompilerOptions): ModuleResolutionCache; - interface CacheWithRedirects { - ownMap: Map; - redirectsMap: Map>; - getOrCreateMapOfCacheRedirects(redirectedReference: ResolvedProjectReference | undefined): Map; - clear(): void; - setOwnOptions(newOptions: CompilerOptions): void; - setOwnMap(newOwnMap: Map): void; - } - function createCacheWithRedirects(options?: CompilerOptions): CacheWithRedirects; - function createModuleResolutionCacheWithMaps(directoryToModuleNameMap: CacheWithRedirects>, moduleNameToDirectoryMap: CacheWithRedirects, currentDirectory: string, getCanonicalFileName: GetCanonicalFileName): ModuleResolutionCache; - function resolveModuleNameFromCache(moduleName: string, containingFile: string, cache: ModuleResolutionCache): ResolvedModuleWithFailedLookupLocations | undefined; - function resolveModuleName(moduleName: string, containingFile: string, compilerOptions: CompilerOptions, host: ModuleResolutionHost, cache?: ModuleResolutionCache, redirectedReference?: ResolvedProjectReference): ResolvedModuleWithFailedLookupLocations; - /** - * Expose resolution logic to allow us to use Node module resolution logic from arbitrary locations. - * No way to do this with `require()`: https://github.com/nodejs/node/issues/5963 - * Throws an error if the module can't be resolved. - */ - function resolveJSModule(moduleName: string, initialDir: string, host: ModuleResolutionHost): string; - function tryResolveJSModule(moduleName: string, initialDir: string, host: ModuleResolutionHost): string | undefined; - function nodeModuleNameResolver(moduleName: string, containingFile: string, compilerOptions: CompilerOptions, host: ModuleResolutionHost, cache?: ModuleResolutionCache, redirectedReference?: ResolvedProjectReference): ResolvedModuleWithFailedLookupLocations; - function nodeModuleNameResolver(moduleName: string, containingFile: string, compilerOptions: CompilerOptions, host: ModuleResolutionHost, cache?: ModuleResolutionCache, redirectedReference?: ResolvedProjectReference, lookupConfig?: boolean): ResolvedModuleWithFailedLookupLocations; - const nodeModulesPathPart = "/node_modules/"; - function pathContainsNodeModules(path: string): boolean; - function parsePackageName(moduleName: string): { - packageName: string; - rest: string; - }; - function getTypesPackageName(packageName: string): string; - function mangleScopedPackageName(packageName: string): string; - function getPackageNameFromTypesPackageName(mangledName: string): string; - function unmangleScopedPackageName(typesPackageName: string): string; - function classicNameResolver(moduleName: string, containingFile: string, compilerOptions: CompilerOptions, host: ModuleResolutionHost, cache?: NonRelativeModuleNameResolutionCache, redirectedReference?: ResolvedProjectReference): ResolvedModuleWithFailedLookupLocations; - /** - * A host may load a module from a global cache of typings. - * This is the minumum code needed to expose that functionality; the rest is in the host. - */ - function loadModuleFromGlobalCache(moduleName: string, projectName: string | undefined, compilerOptions: CompilerOptions, host: ModuleResolutionHost, globalCache: string): ResolvedModuleWithFailedLookupLocations; -} -declare namespace ts { - enum ModuleInstanceState { - NonInstantiated = 0, - Instantiated = 1, - ConstEnumOnly = 2 - } - function getModuleInstanceState(node: ModuleDeclaration): ModuleInstanceState; - function bindSourceFile(file: SourceFile, options: CompilerOptions): void; - function isExportsOrModuleExportsOrAlias(sourceFile: SourceFile, node: Expression): boolean; - /** - * Computes the transform flags for a node, given the transform flags of its subtree - * - * @param node The node to analyze - * @param subtreeFlags Transform flags computed for this node's subtree - */ - function computeTransformFlagsForNode(node: Node, subtreeFlags: TransformFlags): TransformFlags; - /** - * Gets the transform flags to exclude when unioning the transform flags of a subtree. - * - * NOTE: This needs to be kept up-to-date with the exclusions used in `computeTransformFlagsForNode`. - * For performance reasons, `computeTransformFlagsForNode` uses local constant values rather - * than calling this function. - */ - function getTransformFlagsSubtreeExclusions(kind: SyntaxKind): TransformFlags; -} -/** @internal */ -declare namespace ts { - function createGetSymbolWalker(getRestTypeOfSignature: (sig: Signature) => Type, getTypePredicateOfSignature: (sig: Signature) => TypePredicate | undefined, getReturnTypeOfSignature: (sig: Signature) => Type, getBaseTypes: (type: Type) => Type[], resolveStructuredTypeMembers: (type: ObjectType) => ResolvedType, getTypeOfSymbol: (sym: Symbol) => Type, getResolvedSymbol: (node: Node) => Symbol, getIndexTypeOfStructuredType: (type: Type, kind: IndexKind) => Type | undefined, getConstraintOfTypeParameter: (typeParameter: TypeParameter) => Type | undefined, getFirstIdentifier: (node: EntityNameOrEntityNameExpression) => Identifier): (accept?: (symbol: Symbol) => boolean) => SymbolWalker; -} -declare namespace ts { - function getNodeId(node: Node): number; - function getSymbolId(symbol: Symbol): number; - function isInstantiatedModule(node: ModuleDeclaration, preserveConstEnums: boolean): boolean; - function createTypeChecker(host: TypeCheckerHost, produceDiagnostics: boolean): TypeChecker; -} -declare namespace ts { - function updateNode(updated: T, original: T): T; - function createNodeArray(elements?: T[], hasTrailingComma?: boolean): MutableNodeArray; - function createNodeArray(elements?: ReadonlyArray, hasTrailingComma?: boolean): NodeArray; - /** - * Creates a shallow, memberwise clone of a node with no source map location. - */ - function getSynthesizedClone(node: T): T; - function createLiteral(value: string | StringLiteral | NoSubstitutionTemplateLiteral | NumericLiteral | Identifier, isSingleQuote: boolean): StringLiteral; - /** If a node is passed, creates a string literal whose source text is read from a source node during emit. */ - function createLiteral(value: string | StringLiteral | NoSubstitutionTemplateLiteral | NumericLiteral | Identifier): StringLiteral; - function createLiteral(value: number | PseudoBigInt): NumericLiteral; - function createLiteral(value: boolean): BooleanLiteral; - function createLiteral(value: string | number | PseudoBigInt | boolean): PrimaryExpression; - function createNumericLiteral(value: string, numericLiteralFlags?: TokenFlags): NumericLiteral; - function createBigIntLiteral(value: string): BigIntLiteral; - function createStringLiteral(text: string): StringLiteral; - function createRegularExpressionLiteral(text: string): RegularExpressionLiteral; - function createIdentifier(text: string): Identifier; - function createIdentifier(text: string, typeArguments: ReadonlyArray | undefined): Identifier; - function updateIdentifier(node: Identifier): Identifier; - function updateIdentifier(node: Identifier, typeArguments: NodeArray | undefined): Identifier; - /** Create a unique temporary variable. */ - function createTempVariable(recordTempVariable: ((node: Identifier) => void) | undefined): Identifier; - function createTempVariable(recordTempVariable: ((node: Identifier) => void) | undefined, reservedInNestedScopes: boolean): GeneratedIdentifier; - /** Create a unique temporary variable for use in a loop. */ - function createLoopVariable(): Identifier; - /** Create a unique name based on the supplied text. */ - function createUniqueName(text: string): Identifier; - function createOptimisticUniqueName(text: string): GeneratedIdentifier; - /** Create a unique name based on the supplied text. */ - function createOptimisticUniqueName(text: string): Identifier; - /** Create a unique name based on the supplied text. This does not consider names injected by the transformer. */ - function createFileLevelUniqueName(text: string): Identifier; - /** Create a unique name generated for a node. */ - function getGeneratedNameForNode(node: Node | undefined): Identifier; - function getGeneratedNameForNode(node: Node | undefined, flags: GeneratedIdentifierFlags): Identifier; - function createToken(token: TKind): Token; - function createSuper(): SuperExpression; - function createThis(): ThisExpression & Token; - function createNull(): NullLiteral & Token; - function createTrue(): BooleanLiteral & Token; - function createFalse(): BooleanLiteral & Token; - function createModifier(kind: T): Token; - function createModifiersFromModifierFlags(flags: ModifierFlags): Modifier[]; - function createQualifiedName(left: EntityName, right: string | Identifier): QualifiedName; - function updateQualifiedName(node: QualifiedName, left: EntityName, right: Identifier): QualifiedName; - function createComputedPropertyName(expression: Expression): ComputedPropertyName; - function updateComputedPropertyName(node: ComputedPropertyName, expression: Expression): ComputedPropertyName; - function createTypeParameterDeclaration(name: string | Identifier, constraint?: TypeNode, defaultType?: TypeNode): TypeParameterDeclaration; - function updateTypeParameterDeclaration(node: TypeParameterDeclaration, name: Identifier, constraint: TypeNode | undefined, defaultType: TypeNode | undefined): TypeParameterDeclaration; - function createParameter(decorators: ReadonlyArray | undefined, modifiers: ReadonlyArray | undefined, dotDotDotToken: DotDotDotToken | undefined, name: string | BindingName, questionToken?: QuestionToken, type?: TypeNode, initializer?: Expression): ParameterDeclaration; - function updateParameter(node: ParameterDeclaration, decorators: ReadonlyArray | undefined, modifiers: ReadonlyArray | undefined, dotDotDotToken: DotDotDotToken | undefined, name: string | BindingName, questionToken: QuestionToken | undefined, type: TypeNode | undefined, initializer: Expression | undefined): ParameterDeclaration; - function createDecorator(expression: Expression): Decorator; - function updateDecorator(node: Decorator, expression: Expression): Decorator; - function createPropertySignature(modifiers: ReadonlyArray | undefined, name: PropertyName | string, questionToken: QuestionToken | undefined, type: TypeNode | undefined, initializer: Expression | undefined): PropertySignature; - function updatePropertySignature(node: PropertySignature, modifiers: ReadonlyArray | undefined, name: PropertyName, questionToken: QuestionToken | undefined, type: TypeNode | undefined, initializer: Expression | undefined): PropertySignature; - function createProperty(decorators: ReadonlyArray | undefined, modifiers: ReadonlyArray | undefined, name: string | PropertyName, questionOrExclamationToken: QuestionToken | ExclamationToken | undefined, type: TypeNode | undefined, initializer: Expression | undefined): PropertyDeclaration; - function updateProperty(node: PropertyDeclaration, decorators: ReadonlyArray | undefined, modifiers: ReadonlyArray | undefined, name: string | PropertyName, questionOrExclamationToken: QuestionToken | ExclamationToken | undefined, type: TypeNode | undefined, initializer: Expression | undefined): PropertyDeclaration; - function createMethodSignature(typeParameters: ReadonlyArray | undefined, parameters: ReadonlyArray, type: TypeNode | undefined, name: string | PropertyName, questionToken: QuestionToken | undefined): MethodSignature; - function updateMethodSignature(node: MethodSignature, typeParameters: NodeArray | undefined, parameters: NodeArray, type: TypeNode | undefined, name: PropertyName, questionToken: QuestionToken | undefined): MethodSignature; - function createMethod(decorators: ReadonlyArray | undefined, modifiers: ReadonlyArray | undefined, asteriskToken: AsteriskToken | undefined, name: string | PropertyName, questionToken: QuestionToken | undefined, typeParameters: ReadonlyArray | undefined, parameters: ReadonlyArray, type: TypeNode | undefined, body: Block | undefined): MethodDeclaration; - function updateMethod(node: MethodDeclaration, decorators: ReadonlyArray | undefined, modifiers: ReadonlyArray | undefined, asteriskToken: AsteriskToken | undefined, name: PropertyName, questionToken: QuestionToken | undefined, typeParameters: ReadonlyArray | undefined, parameters: ReadonlyArray, type: TypeNode | undefined, body: Block | undefined): MethodDeclaration; - function createConstructor(decorators: ReadonlyArray | undefined, modifiers: ReadonlyArray | undefined, parameters: ReadonlyArray, body: Block | undefined): ConstructorDeclaration; - function updateConstructor(node: ConstructorDeclaration, decorators: ReadonlyArray | undefined, modifiers: ReadonlyArray | undefined, parameters: ReadonlyArray, body: Block | undefined): ConstructorDeclaration; - function createGetAccessor(decorators: ReadonlyArray | undefined, modifiers: ReadonlyArray | undefined, name: string | PropertyName, parameters: ReadonlyArray, type: TypeNode | undefined, body: Block | undefined): GetAccessorDeclaration; - function updateGetAccessor(node: GetAccessorDeclaration, decorators: ReadonlyArray | undefined, modifiers: ReadonlyArray | undefined, name: PropertyName, parameters: ReadonlyArray, type: TypeNode | undefined, body: Block | undefined): GetAccessorDeclaration; - function createSetAccessor(decorators: ReadonlyArray | undefined, modifiers: ReadonlyArray | undefined, name: string | PropertyName, parameters: ReadonlyArray, body: Block | undefined): SetAccessorDeclaration; - function updateSetAccessor(node: SetAccessorDeclaration, decorators: ReadonlyArray | undefined, modifiers: ReadonlyArray | undefined, name: PropertyName, parameters: ReadonlyArray, body: Block | undefined): SetAccessorDeclaration; - function createCallSignature(typeParameters: ReadonlyArray | undefined, parameters: ReadonlyArray, type: TypeNode | undefined): CallSignatureDeclaration; - function updateCallSignature(node: CallSignatureDeclaration, typeParameters: NodeArray | undefined, parameters: NodeArray, type: TypeNode | undefined): CallSignatureDeclaration; - function createConstructSignature(typeParameters: ReadonlyArray | undefined, parameters: ReadonlyArray, type: TypeNode | undefined): ConstructSignatureDeclaration; - function updateConstructSignature(node: ConstructSignatureDeclaration, typeParameters: NodeArray | undefined, parameters: NodeArray, type: TypeNode | undefined): ConstructSignatureDeclaration; - function createIndexSignature(decorators: ReadonlyArray | undefined, modifiers: ReadonlyArray | undefined, parameters: ReadonlyArray, type: TypeNode): IndexSignatureDeclaration; - function updateIndexSignature(node: IndexSignatureDeclaration, decorators: ReadonlyArray | undefined, modifiers: ReadonlyArray | undefined, parameters: ReadonlyArray, type: TypeNode): IndexSignatureDeclaration; - function createSignatureDeclaration(kind: SyntaxKind, typeParameters: ReadonlyArray | undefined, parameters: ReadonlyArray, type: TypeNode | undefined, typeArguments?: ReadonlyArray | undefined): SignatureDeclaration; - function createKeywordTypeNode(kind: KeywordTypeNode["kind"]): KeywordTypeNode; - function createTypePredicateNode(parameterName: Identifier | ThisTypeNode | string, type: TypeNode): TypePredicateNode; - function updateTypePredicateNode(node: TypePredicateNode, parameterName: Identifier | ThisTypeNode, type: TypeNode): TypePredicateNode; - function createTypeReferenceNode(typeName: string | EntityName, typeArguments: ReadonlyArray | undefined): TypeReferenceNode; - function updateTypeReferenceNode(node: TypeReferenceNode, typeName: EntityName, typeArguments: NodeArray | undefined): TypeReferenceNode; - function createFunctionTypeNode(typeParameters: ReadonlyArray | undefined, parameters: ReadonlyArray, type: TypeNode | undefined): FunctionTypeNode; - function updateFunctionTypeNode(node: FunctionTypeNode, typeParameters: NodeArray | undefined, parameters: NodeArray, type: TypeNode | undefined): FunctionTypeNode; - function createConstructorTypeNode(typeParameters: ReadonlyArray | undefined, parameters: ReadonlyArray, type: TypeNode | undefined): ConstructorTypeNode; - function updateConstructorTypeNode(node: ConstructorTypeNode, typeParameters: NodeArray | undefined, parameters: NodeArray, type: TypeNode | undefined): ConstructorTypeNode; - function createTypeQueryNode(exprName: EntityName): TypeQueryNode; - function updateTypeQueryNode(node: TypeQueryNode, exprName: EntityName): TypeQueryNode; - function createTypeLiteralNode(members: ReadonlyArray | undefined): TypeLiteralNode; - function updateTypeLiteralNode(node: TypeLiteralNode, members: NodeArray): TypeLiteralNode; - function createArrayTypeNode(elementType: TypeNode): ArrayTypeNode; - function updateArrayTypeNode(node: ArrayTypeNode, elementType: TypeNode): ArrayTypeNode; - function createTupleTypeNode(elementTypes: ReadonlyArray): TupleTypeNode; - function updateTupleTypeNode(node: TupleTypeNode, elementTypes: ReadonlyArray): TupleTypeNode; - function createOptionalTypeNode(type: TypeNode): OptionalTypeNode; - function updateOptionalTypeNode(node: OptionalTypeNode, type: TypeNode): OptionalTypeNode; - function createRestTypeNode(type: TypeNode): RestTypeNode; - function updateRestTypeNode(node: RestTypeNode, type: TypeNode): RestTypeNode; - function createUnionTypeNode(types: ReadonlyArray): UnionTypeNode; - function updateUnionTypeNode(node: UnionTypeNode, types: NodeArray): UnionTypeNode; - function createIntersectionTypeNode(types: ReadonlyArray): IntersectionTypeNode; - function updateIntersectionTypeNode(node: IntersectionTypeNode, types: NodeArray): IntersectionTypeNode; - function createUnionOrIntersectionTypeNode(kind: SyntaxKind.UnionType | SyntaxKind.IntersectionType, types: ReadonlyArray): UnionOrIntersectionTypeNode; - function createConditionalTypeNode(checkType: TypeNode, extendsType: TypeNode, trueType: TypeNode, falseType: TypeNode): ConditionalTypeNode; - function updateConditionalTypeNode(node: ConditionalTypeNode, checkType: TypeNode, extendsType: TypeNode, trueType: TypeNode, falseType: TypeNode): ConditionalTypeNode; - function createInferTypeNode(typeParameter: TypeParameterDeclaration): InferTypeNode; - function updateInferTypeNode(node: InferTypeNode, typeParameter: TypeParameterDeclaration): InferTypeNode; - function createImportTypeNode(argument: TypeNode, qualifier?: EntityName, typeArguments?: ReadonlyArray, isTypeOf?: boolean): ImportTypeNode; - function updateImportTypeNode(node: ImportTypeNode, argument: TypeNode, qualifier?: EntityName, typeArguments?: ReadonlyArray, isTypeOf?: boolean): ImportTypeNode; - function createParenthesizedType(type: TypeNode): ParenthesizedTypeNode; - function updateParenthesizedType(node: ParenthesizedTypeNode, type: TypeNode): ParenthesizedTypeNode; - function createThisTypeNode(): ThisTypeNode; - function createTypeOperatorNode(type: TypeNode): TypeOperatorNode; - function createTypeOperatorNode(operator: SyntaxKind.KeyOfKeyword | SyntaxKind.UniqueKeyword | SyntaxKind.ReadonlyKeyword, type: TypeNode): TypeOperatorNode; - function updateTypeOperatorNode(node: TypeOperatorNode, type: TypeNode): TypeOperatorNode; - function createIndexedAccessTypeNode(objectType: TypeNode, indexType: TypeNode): IndexedAccessTypeNode; - function updateIndexedAccessTypeNode(node: IndexedAccessTypeNode, objectType: TypeNode, indexType: TypeNode): IndexedAccessTypeNode; - function createMappedTypeNode(readonlyToken: ReadonlyToken | PlusToken | MinusToken | undefined, typeParameter: TypeParameterDeclaration, questionToken: QuestionToken | PlusToken | MinusToken | undefined, type: TypeNode | undefined): MappedTypeNode; - function updateMappedTypeNode(node: MappedTypeNode, readonlyToken: ReadonlyToken | PlusToken | MinusToken | undefined, typeParameter: TypeParameterDeclaration, questionToken: QuestionToken | PlusToken | MinusToken | undefined, type: TypeNode | undefined): MappedTypeNode; - function createLiteralTypeNode(literal: LiteralTypeNode["literal"]): LiteralTypeNode; - function updateLiteralTypeNode(node: LiteralTypeNode, literal: LiteralTypeNode["literal"]): LiteralTypeNode; - function createObjectBindingPattern(elements: ReadonlyArray): ObjectBindingPattern; - function updateObjectBindingPattern(node: ObjectBindingPattern, elements: ReadonlyArray): ObjectBindingPattern; - function createArrayBindingPattern(elements: ReadonlyArray): ArrayBindingPattern; - function updateArrayBindingPattern(node: ArrayBindingPattern, elements: ReadonlyArray): ArrayBindingPattern; - function createBindingElement(dotDotDotToken: DotDotDotToken | undefined, propertyName: string | PropertyName | undefined, name: string | BindingName, initializer?: Expression): BindingElement; - function updateBindingElement(node: BindingElement, dotDotDotToken: DotDotDotToken | undefined, propertyName: PropertyName | undefined, name: BindingName, initializer: Expression | undefined): BindingElement; - function createArrayLiteral(elements?: ReadonlyArray, multiLine?: boolean): ArrayLiteralExpression; - function updateArrayLiteral(node: ArrayLiteralExpression, elements: ReadonlyArray): ArrayLiteralExpression; - function createObjectLiteral(properties?: ReadonlyArray, multiLine?: boolean): ObjectLiteralExpression; - function updateObjectLiteral(node: ObjectLiteralExpression, properties: ReadonlyArray): ObjectLiteralExpression; - function createPropertyAccess(expression: Expression, name: string | Identifier): PropertyAccessExpression; - function updatePropertyAccess(node: PropertyAccessExpression, expression: Expression, name: Identifier): PropertyAccessExpression; - function createElementAccess(expression: Expression, index: number | Expression): ElementAccessExpression; - function updateElementAccess(node: ElementAccessExpression, expression: Expression, argumentExpression: Expression): ElementAccessExpression; - function createCall(expression: Expression, typeArguments: ReadonlyArray | undefined, argumentsArray: ReadonlyArray | undefined): CallExpression; - function updateCall(node: CallExpression, expression: Expression, typeArguments: ReadonlyArray | undefined, argumentsArray: ReadonlyArray): CallExpression; - function createNew(expression: Expression, typeArguments: ReadonlyArray | undefined, argumentsArray: ReadonlyArray | undefined): NewExpression; - function updateNew(node: NewExpression, expression: Expression, typeArguments: ReadonlyArray | undefined, argumentsArray: ReadonlyArray | undefined): NewExpression; - /** @deprecated */ function createTaggedTemplate(tag: Expression, template: TemplateLiteral): TaggedTemplateExpression; - function createTaggedTemplate(tag: Expression, typeArguments: ReadonlyArray | undefined, template: TemplateLiteral): TaggedTemplateExpression; - /** @internal */ - function createTaggedTemplate(tag: Expression, typeArgumentsOrTemplate: ReadonlyArray | TemplateLiteral | undefined, template?: TemplateLiteral): TaggedTemplateExpression; - /** @deprecated */ function updateTaggedTemplate(node: TaggedTemplateExpression, tag: Expression, template: TemplateLiteral): TaggedTemplateExpression; - function updateTaggedTemplate(node: TaggedTemplateExpression, tag: Expression, typeArguments: ReadonlyArray | undefined, template: TemplateLiteral): TaggedTemplateExpression; - function createTypeAssertion(type: TypeNode, expression: Expression): TypeAssertion; - function updateTypeAssertion(node: TypeAssertion, type: TypeNode, expression: Expression): TypeAssertion; - function createParen(expression: Expression): ParenthesizedExpression; - function updateParen(node: ParenthesizedExpression, expression: Expression): ParenthesizedExpression; - function createFunctionExpression(modifiers: ReadonlyArray | undefined, asteriskToken: AsteriskToken | undefined, name: string | Identifier | undefined, typeParameters: ReadonlyArray | undefined, parameters: ReadonlyArray | undefined, type: TypeNode | undefined, body: Block): FunctionExpression; - function updateFunctionExpression(node: FunctionExpression, modifiers: ReadonlyArray | undefined, asteriskToken: AsteriskToken | undefined, name: Identifier | undefined, typeParameters: ReadonlyArray | undefined, parameters: ReadonlyArray, type: TypeNode | undefined, body: Block): FunctionExpression; - function createArrowFunction(modifiers: ReadonlyArray | undefined, typeParameters: ReadonlyArray | undefined, parameters: ReadonlyArray, type: TypeNode | undefined, equalsGreaterThanToken: EqualsGreaterThanToken | undefined, body: ConciseBody): ArrowFunction; - function updateArrowFunction(node: ArrowFunction, modifiers: ReadonlyArray | undefined, typeParameters: ReadonlyArray | undefined, parameters: ReadonlyArray, type: TypeNode | undefined, equalsGreaterThanToken: Token, body: ConciseBody): ArrowFunction; - function createDelete(expression: Expression): DeleteExpression; - function updateDelete(node: DeleteExpression, expression: Expression): DeleteExpression; - function createTypeOf(expression: Expression): TypeOfExpression; - function updateTypeOf(node: TypeOfExpression, expression: Expression): TypeOfExpression; - function createVoid(expression: Expression): VoidExpression; - function updateVoid(node: VoidExpression, expression: Expression): VoidExpression; - function createAwait(expression: Expression): AwaitExpression; - function updateAwait(node: AwaitExpression, expression: Expression): AwaitExpression; - function createPrefix(operator: PrefixUnaryOperator, operand: Expression): PrefixUnaryExpression; - function updatePrefix(node: PrefixUnaryExpression, operand: Expression): PrefixUnaryExpression; - function createPostfix(operand: Expression, operator: PostfixUnaryOperator): PostfixUnaryExpression; - function updatePostfix(node: PostfixUnaryExpression, operand: Expression): PostfixUnaryExpression; - function createBinary(left: Expression, operator: BinaryOperator | BinaryOperatorToken, right: Expression): BinaryExpression; - function updateBinary(node: BinaryExpression, left: Expression, right: Expression, operator?: BinaryOperator | BinaryOperatorToken): BinaryExpression; - /** @deprecated */ function createConditional(condition: Expression, whenTrue: Expression, whenFalse: Expression): ConditionalExpression; - function createConditional(condition: Expression, questionToken: QuestionToken, whenTrue: Expression, colonToken: ColonToken, whenFalse: Expression): ConditionalExpression; - function updateConditional(node: ConditionalExpression, condition: Expression, questionToken: Token, whenTrue: Expression, colonToken: Token, whenFalse: Expression): ConditionalExpression; - function createTemplateExpression(head: TemplateHead, templateSpans: ReadonlyArray): TemplateExpression; - function updateTemplateExpression(node: TemplateExpression, head: TemplateHead, templateSpans: ReadonlyArray): TemplateExpression; - function createTemplateHead(text: string, rawText?: string): TemplateHead; - function createTemplateMiddle(text: string, rawText?: string): TemplateMiddle; - function createTemplateTail(text: string, rawText?: string): TemplateTail; - function createNoSubstitutionTemplateLiteral(text: string, rawText?: string): NoSubstitutionTemplateLiteral; - function createYield(expression?: Expression): YieldExpression; - function createYield(asteriskToken: AsteriskToken | undefined, expression: Expression): YieldExpression; - function updateYield(node: YieldExpression, asteriskToken: AsteriskToken | undefined, expression: Expression): YieldExpression; - function createSpread(expression: Expression): SpreadElement; - function updateSpread(node: SpreadElement, expression: Expression): SpreadElement; - function createClassExpression(modifiers: ReadonlyArray | undefined, name: string | Identifier | undefined, typeParameters: ReadonlyArray | undefined, heritageClauses: ReadonlyArray | undefined, members: ReadonlyArray): ClassExpression; - function updateClassExpression(node: ClassExpression, modifiers: ReadonlyArray | undefined, name: Identifier | undefined, typeParameters: ReadonlyArray | undefined, heritageClauses: ReadonlyArray | undefined, members: ReadonlyArray): ClassExpression; - function createOmittedExpression(): OmittedExpression; - function createExpressionWithTypeArguments(typeArguments: ReadonlyArray | undefined, expression: Expression): ExpressionWithTypeArguments; - function updateExpressionWithTypeArguments(node: ExpressionWithTypeArguments, typeArguments: ReadonlyArray | undefined, expression: Expression): ExpressionWithTypeArguments; - function createAsExpression(expression: Expression, type: TypeNode): AsExpression; - function updateAsExpression(node: AsExpression, expression: Expression, type: TypeNode): AsExpression; - function createNonNullExpression(expression: Expression): NonNullExpression; - function updateNonNullExpression(node: NonNullExpression, expression: Expression): NonNullExpression; - function createMetaProperty(keywordToken: MetaProperty["keywordToken"], name: Identifier): MetaProperty; - function updateMetaProperty(node: MetaProperty, name: Identifier): MetaProperty; - function createTemplateSpan(expression: Expression, literal: TemplateMiddle | TemplateTail): TemplateSpan; - function updateTemplateSpan(node: TemplateSpan, expression: Expression, literal: TemplateMiddle | TemplateTail): TemplateSpan; - function createSemicolonClassElement(): SemicolonClassElement; - function createBlock(statements: ReadonlyArray, multiLine?: boolean): Block; - function updateBlock(node: Block, statements: ReadonlyArray): Block; - function createVariableStatement(modifiers: ReadonlyArray | undefined, declarationList: VariableDeclarationList | ReadonlyArray): VariableStatement; - function updateVariableStatement(node: VariableStatement, modifiers: ReadonlyArray | undefined, declarationList: VariableDeclarationList): VariableStatement; - function createEmptyStatement(): EmptyStatement; - function createExpressionStatement(expression: Expression): ExpressionStatement; - function updateExpressionStatement(node: ExpressionStatement, expression: Expression): ExpressionStatement; - /** @deprecated Use `createExpressionStatement` instead. */ - const createStatement: typeof createExpressionStatement; - /** @deprecated Use `updateExpressionStatement` instead. */ - const updateStatement: typeof updateExpressionStatement; - function createIf(expression: Expression, thenStatement: Statement, elseStatement?: Statement): IfStatement; - function updateIf(node: IfStatement, expression: Expression, thenStatement: Statement, elseStatement: Statement | undefined): IfStatement; - function createDo(statement: Statement, expression: Expression): DoStatement; - function updateDo(node: DoStatement, statement: Statement, expression: Expression): DoStatement; - function createWhile(expression: Expression, statement: Statement): WhileStatement; - function updateWhile(node: WhileStatement, expression: Expression, statement: Statement): WhileStatement; - function createFor(initializer: ForInitializer | undefined, condition: Expression | undefined, incrementor: Expression | undefined, statement: Statement): ForStatement; - function updateFor(node: ForStatement, initializer: ForInitializer | undefined, condition: Expression | undefined, incrementor: Expression | undefined, statement: Statement): ForStatement; - function createForIn(initializer: ForInitializer, expression: Expression, statement: Statement): ForInStatement; - function updateForIn(node: ForInStatement, initializer: ForInitializer, expression: Expression, statement: Statement): ForInStatement; - function createForOf(awaitModifier: AwaitKeywordToken | undefined, initializer: ForInitializer, expression: Expression, statement: Statement): ForOfStatement; - function updateForOf(node: ForOfStatement, awaitModifier: AwaitKeywordToken | undefined, initializer: ForInitializer, expression: Expression, statement: Statement): ForOfStatement; - function createContinue(label?: string | Identifier): ContinueStatement; - function updateContinue(node: ContinueStatement, label: Identifier | undefined): ContinueStatement; - function createBreak(label?: string | Identifier): BreakStatement; - function updateBreak(node: BreakStatement, label: Identifier | undefined): BreakStatement; - function createReturn(expression?: Expression): ReturnStatement; - function updateReturn(node: ReturnStatement, expression: Expression | undefined): ReturnStatement; - function createWith(expression: Expression, statement: Statement): WithStatement; - function updateWith(node: WithStatement, expression: Expression, statement: Statement): WithStatement; - function createSwitch(expression: Expression, caseBlock: CaseBlock): SwitchStatement; - function updateSwitch(node: SwitchStatement, expression: Expression, caseBlock: CaseBlock): SwitchStatement; - function createLabel(label: string | Identifier, statement: Statement): LabeledStatement; - function updateLabel(node: LabeledStatement, label: Identifier, statement: Statement): LabeledStatement; - function createThrow(expression: Expression): ThrowStatement; - function updateThrow(node: ThrowStatement, expression: Expression): ThrowStatement; - function createTry(tryBlock: Block, catchClause: CatchClause | undefined, finallyBlock: Block | undefined): TryStatement; - function updateTry(node: TryStatement, tryBlock: Block, catchClause: CatchClause | undefined, finallyBlock: Block | undefined): TryStatement; - function createDebuggerStatement(): DebuggerStatement; - function createVariableDeclaration(name: string | BindingName, type?: TypeNode, initializer?: Expression): VariableDeclaration; - function updateVariableDeclaration(node: VariableDeclaration, name: BindingName, type: TypeNode | undefined, initializer: Expression | undefined): VariableDeclaration; - function createVariableDeclarationList(declarations: ReadonlyArray, flags?: NodeFlags): VariableDeclarationList; - function updateVariableDeclarationList(node: VariableDeclarationList, declarations: ReadonlyArray): VariableDeclarationList; - function createFunctionDeclaration(decorators: ReadonlyArray | undefined, modifiers: ReadonlyArray | undefined, asteriskToken: AsteriskToken | undefined, name: string | Identifier | undefined, typeParameters: ReadonlyArray | undefined, parameters: ReadonlyArray, type: TypeNode | undefined, body: Block | undefined): FunctionDeclaration; - function updateFunctionDeclaration(node: FunctionDeclaration, decorators: ReadonlyArray | undefined, modifiers: ReadonlyArray | undefined, asteriskToken: AsteriskToken | undefined, name: Identifier | undefined, typeParameters: ReadonlyArray | undefined, parameters: ReadonlyArray, type: TypeNode | undefined, body: Block | undefined): FunctionDeclaration; - function createClassDeclaration(decorators: ReadonlyArray | undefined, modifiers: ReadonlyArray | undefined, name: string | Identifier | undefined, typeParameters: ReadonlyArray | undefined, heritageClauses: ReadonlyArray | undefined, members: ReadonlyArray): ClassDeclaration; - function updateClassDeclaration(node: ClassDeclaration, decorators: ReadonlyArray | undefined, modifiers: ReadonlyArray | undefined, name: Identifier | undefined, typeParameters: ReadonlyArray | undefined, heritageClauses: ReadonlyArray | undefined, members: ReadonlyArray): ClassDeclaration; - function createInterfaceDeclaration(decorators: ReadonlyArray | undefined, modifiers: ReadonlyArray | undefined, name: string | Identifier, typeParameters: ReadonlyArray | undefined, heritageClauses: ReadonlyArray | undefined, members: ReadonlyArray): InterfaceDeclaration; - function updateInterfaceDeclaration(node: InterfaceDeclaration, decorators: ReadonlyArray | undefined, modifiers: ReadonlyArray | undefined, name: Identifier, typeParameters: ReadonlyArray | undefined, heritageClauses: ReadonlyArray | undefined, members: ReadonlyArray): InterfaceDeclaration; - function createTypeAliasDeclaration(decorators: ReadonlyArray | undefined, modifiers: ReadonlyArray | undefined, name: string | Identifier, typeParameters: ReadonlyArray | undefined, type: TypeNode): TypeAliasDeclaration; - function updateTypeAliasDeclaration(node: TypeAliasDeclaration, decorators: ReadonlyArray | undefined, modifiers: ReadonlyArray | undefined, name: Identifier, typeParameters: ReadonlyArray | undefined, type: TypeNode): TypeAliasDeclaration; - function createEnumDeclaration(decorators: ReadonlyArray | undefined, modifiers: ReadonlyArray | undefined, name: string | Identifier, members: ReadonlyArray): EnumDeclaration; - function updateEnumDeclaration(node: EnumDeclaration, decorators: ReadonlyArray | undefined, modifiers: ReadonlyArray | undefined, name: Identifier, members: ReadonlyArray): EnumDeclaration; - function createModuleDeclaration(decorators: ReadonlyArray | undefined, modifiers: ReadonlyArray | undefined, name: ModuleName, body: ModuleBody | undefined, flags?: NodeFlags): ModuleDeclaration; - function updateModuleDeclaration(node: ModuleDeclaration, decorators: ReadonlyArray | undefined, modifiers: ReadonlyArray | undefined, name: ModuleName, body: ModuleBody | undefined): ModuleDeclaration; - function createModuleBlock(statements: ReadonlyArray): ModuleBlock; - function updateModuleBlock(node: ModuleBlock, statements: ReadonlyArray): ModuleBlock; - function createCaseBlock(clauses: ReadonlyArray): CaseBlock; - function updateCaseBlock(node: CaseBlock, clauses: ReadonlyArray): CaseBlock; - function createNamespaceExportDeclaration(name: string | Identifier): NamespaceExportDeclaration; - function updateNamespaceExportDeclaration(node: NamespaceExportDeclaration, name: Identifier): NamespaceExportDeclaration; - function createImportEqualsDeclaration(decorators: ReadonlyArray | undefined, modifiers: ReadonlyArray | undefined, name: string | Identifier, moduleReference: ModuleReference): ImportEqualsDeclaration; - function updateImportEqualsDeclaration(node: ImportEqualsDeclaration, decorators: ReadonlyArray | undefined, modifiers: ReadonlyArray | undefined, name: Identifier, moduleReference: ModuleReference): ImportEqualsDeclaration; - function createImportDeclaration(decorators: ReadonlyArray | undefined, modifiers: ReadonlyArray | undefined, importClause: ImportClause | undefined, moduleSpecifier: Expression): ImportDeclaration; - function updateImportDeclaration(node: ImportDeclaration, decorators: ReadonlyArray | undefined, modifiers: ReadonlyArray | undefined, importClause: ImportClause | undefined, moduleSpecifier: Expression): ImportDeclaration; - function createImportClause(name: Identifier | undefined, namedBindings: NamedImportBindings | undefined): ImportClause; - function updateImportClause(node: ImportClause, name: Identifier | undefined, namedBindings: NamedImportBindings | undefined): ImportClause; - function createNamespaceImport(name: Identifier): NamespaceImport; - function updateNamespaceImport(node: NamespaceImport, name: Identifier): NamespaceImport; - function createNamedImports(elements: ReadonlyArray): NamedImports; - function updateNamedImports(node: NamedImports, elements: ReadonlyArray): NamedImports; - function createImportSpecifier(propertyName: Identifier | undefined, name: Identifier): ImportSpecifier; - function updateImportSpecifier(node: ImportSpecifier, propertyName: Identifier | undefined, name: Identifier): ImportSpecifier; - function createExportAssignment(decorators: ReadonlyArray | undefined, modifiers: ReadonlyArray | undefined, isExportEquals: boolean | undefined, expression: Expression): ExportAssignment; - function updateExportAssignment(node: ExportAssignment, decorators: ReadonlyArray | undefined, modifiers: ReadonlyArray | undefined, expression: Expression): ExportAssignment; - function createExportDeclaration(decorators: ReadonlyArray | undefined, modifiers: ReadonlyArray | undefined, exportClause: NamedExports | undefined, moduleSpecifier?: Expression): ExportDeclaration; - function updateExportDeclaration(node: ExportDeclaration, decorators: ReadonlyArray | undefined, modifiers: ReadonlyArray | undefined, exportClause: NamedExports | undefined, moduleSpecifier: Expression | undefined): ExportDeclaration; - function createNamedExports(elements: ReadonlyArray): NamedExports; - function updateNamedExports(node: NamedExports, elements: ReadonlyArray): NamedExports; - function createExportSpecifier(propertyName: string | Identifier | undefined, name: string | Identifier): ExportSpecifier; - function updateExportSpecifier(node: ExportSpecifier, propertyName: Identifier | undefined, name: Identifier): ExportSpecifier; - function createExternalModuleReference(expression: Expression): ExternalModuleReference; - function updateExternalModuleReference(node: ExternalModuleReference, expression: Expression): ExternalModuleReference; - function createJSDocTypeExpression(type: TypeNode): JSDocTypeExpression; - function createJSDocTypeTag(typeExpression: JSDocTypeExpression, comment?: string): JSDocTypeTag; - function createJSDocReturnTag(typeExpression?: JSDocTypeExpression, comment?: string): JSDocReturnTag; - /** @internal */ - function createJSDocThisTag(typeExpression?: JSDocTypeExpression): JSDocThisTag; - function createJSDocParamTag(name: EntityName, isBracketed: boolean, typeExpression?: JSDocTypeExpression, comment?: string): JSDocParameterTag; - function createJSDocComment(comment?: string | undefined, tags?: NodeArray | undefined): JSDoc; - function createJsxElement(openingElement: JsxOpeningElement, children: ReadonlyArray, closingElement: JsxClosingElement): JsxElement; - function updateJsxElement(node: JsxElement, openingElement: JsxOpeningElement, children: ReadonlyArray, closingElement: JsxClosingElement): JsxElement; - function createJsxSelfClosingElement(tagName: JsxTagNameExpression, typeArguments: ReadonlyArray | undefined, attributes: JsxAttributes): JsxSelfClosingElement; - function updateJsxSelfClosingElement(node: JsxSelfClosingElement, tagName: JsxTagNameExpression, typeArguments: ReadonlyArray | undefined, attributes: JsxAttributes): JsxSelfClosingElement; - function createJsxOpeningElement(tagName: JsxTagNameExpression, typeArguments: ReadonlyArray | undefined, attributes: JsxAttributes): JsxOpeningElement; - function updateJsxOpeningElement(node: JsxOpeningElement, tagName: JsxTagNameExpression, typeArguments: ReadonlyArray | undefined, attributes: JsxAttributes): JsxOpeningElement; - function createJsxClosingElement(tagName: JsxTagNameExpression): JsxClosingElement; - function updateJsxClosingElement(node: JsxClosingElement, tagName: JsxTagNameExpression): JsxClosingElement; - function createJsxFragment(openingFragment: JsxOpeningFragment, children: ReadonlyArray, closingFragment: JsxClosingFragment): JsxFragment; - function createJsxText(text: string, containsOnlyTriviaWhiteSpaces?: boolean): JsxText; - function updateJsxText(node: JsxText, text: string, containsOnlyTriviaWhiteSpaces?: boolean): JsxText; - function createJsxOpeningFragment(): JsxOpeningFragment; - function createJsxJsxClosingFragment(): JsxClosingFragment; - function updateJsxFragment(node: JsxFragment, openingFragment: JsxOpeningFragment, children: ReadonlyArray, closingFragment: JsxClosingFragment): JsxFragment; - function createJsxAttribute(name: Identifier, initializer: StringLiteral | JsxExpression): JsxAttribute; - function updateJsxAttribute(node: JsxAttribute, name: Identifier, initializer: StringLiteral | JsxExpression): JsxAttribute; - function createJsxAttributes(properties: ReadonlyArray): JsxAttributes; - function updateJsxAttributes(node: JsxAttributes, properties: ReadonlyArray): JsxAttributes; - function createJsxSpreadAttribute(expression: Expression): JsxSpreadAttribute; - function updateJsxSpreadAttribute(node: JsxSpreadAttribute, expression: Expression): JsxSpreadAttribute; - function createJsxExpression(dotDotDotToken: DotDotDotToken | undefined, expression: Expression | undefined): JsxExpression; - function updateJsxExpression(node: JsxExpression, expression: Expression | undefined): JsxExpression; - function createCaseClause(expression: Expression, statements: ReadonlyArray): CaseClause; - function updateCaseClause(node: CaseClause, expression: Expression, statements: ReadonlyArray): CaseClause; - function createDefaultClause(statements: ReadonlyArray): DefaultClause; - function updateDefaultClause(node: DefaultClause, statements: ReadonlyArray): DefaultClause; - function createHeritageClause(token: HeritageClause["token"], types: ReadonlyArray): HeritageClause; - function updateHeritageClause(node: HeritageClause, types: ReadonlyArray): HeritageClause; - function createCatchClause(variableDeclaration: string | VariableDeclaration | undefined, block: Block): CatchClause; - function updateCatchClause(node: CatchClause, variableDeclaration: VariableDeclaration | undefined, block: Block): CatchClause; - function createPropertyAssignment(name: string | PropertyName, initializer: Expression): PropertyAssignment; - function updatePropertyAssignment(node: PropertyAssignment, name: PropertyName, initializer: Expression): PropertyAssignment; - function createShorthandPropertyAssignment(name: string | Identifier, objectAssignmentInitializer?: Expression): ShorthandPropertyAssignment; - function updateShorthandPropertyAssignment(node: ShorthandPropertyAssignment, name: Identifier, objectAssignmentInitializer: Expression | undefined): ShorthandPropertyAssignment; - function createSpreadAssignment(expression: Expression): SpreadAssignment; - function updateSpreadAssignment(node: SpreadAssignment, expression: Expression): SpreadAssignment; - function createEnumMember(name: string | PropertyName, initializer?: Expression): EnumMember; - function updateEnumMember(node: EnumMember, name: PropertyName, initializer: Expression | undefined): EnumMember; - function updateSourceFileNode(node: SourceFile, statements: ReadonlyArray, isDeclarationFile?: boolean, referencedFiles?: SourceFile["referencedFiles"], typeReferences?: SourceFile["typeReferenceDirectives"], hasNoDefaultLib?: boolean, libReferences?: SourceFile["libReferenceDirectives"]): SourceFile; - /** - * Creates a shallow, memberwise clone of a node for mutation. - */ - function getMutableClone(node: T): T; - /** - * Creates a synthetic statement to act as a placeholder for a not-emitted statement in - * order to preserve comments. - * - * @param original The original statement. - */ - function createNotEmittedStatement(original: Node): NotEmittedStatement; - /** - * Creates a synthetic element to act as a placeholder for the end of an emitted declaration in - * order to properly emit exports. - */ - function createEndOfDeclarationMarker(original: Node): EndOfDeclarationMarker; - /** - * Creates a synthetic element to act as a placeholder for the beginning of a merged declaration in - * order to properly emit exports. - */ - function createMergeDeclarationMarker(original: Node): MergeDeclarationMarker; - /** - * Creates a synthetic expression to act as a placeholder for a not-emitted expression in - * order to preserve comments or sourcemap positions. - * - * @param expression The inner expression to emit. - * @param original The original outer expression. - * @param location The location for the expression. Defaults to the positions from "original" if provided. - */ - function createPartiallyEmittedExpression(expression: Expression, original?: Node): PartiallyEmittedExpression; - function updatePartiallyEmittedExpression(node: PartiallyEmittedExpression, expression: Expression): PartiallyEmittedExpression; - function createCommaList(elements: ReadonlyArray): CommaListExpression; - function updateCommaList(node: CommaListExpression, elements: ReadonlyArray): CommaListExpression; - function createBundle(sourceFiles: ReadonlyArray, prepends?: ReadonlyArray): Bundle; - function createUnparsedSourceFile(text: string): UnparsedSource; - function createUnparsedSourceFile(inputFile: InputFiles, type: "js" | "dts", stripInternal?: boolean): UnparsedSource; - function createUnparsedSourceFile(text: string, mapPath: string | undefined, map: string | undefined): UnparsedSource; - function createInputFiles(javascriptText: string, declarationText: string): InputFiles; - function createInputFiles(readFileText: (path: string) => string | undefined, javascriptPath: string, javascriptMapPath: string | undefined, declarationPath: string, declarationMapPath: string | undefined, buildInfoPath: string | undefined): InputFiles; - function createInputFiles(javascriptText: string, declarationText: string, javascriptMapPath: string | undefined, javascriptMapText: string | undefined, declarationMapPath: string | undefined, declarationMapText: string | undefined): InputFiles; - function createInputFiles(javascriptText: string, declarationText: string, javascriptMapPath: string | undefined, javascriptMapText: string | undefined, declarationMapPath: string | undefined, declarationMapText: string | undefined, javascriptPath: string | undefined, declarationPath: string | undefined, buildInfoPath?: string | undefined, buildInfo?: BuildInfo, oldFileOfCurrentEmit?: boolean): InputFiles; - function updateBundle(node: Bundle, sourceFiles: ReadonlyArray, prepends?: ReadonlyArray): Bundle; - function createImmediatelyInvokedFunctionExpression(statements: ReadonlyArray): CallExpression; - function createImmediatelyInvokedFunctionExpression(statements: ReadonlyArray, param: ParameterDeclaration, paramValue: Expression): CallExpression; - function createImmediatelyInvokedArrowFunction(statements: ReadonlyArray): CallExpression; - function createImmediatelyInvokedArrowFunction(statements: ReadonlyArray, param: ParameterDeclaration, paramValue: Expression): CallExpression; - function createComma(left: Expression, right: Expression): Expression; - function createLessThan(left: Expression, right: Expression): Expression; - function createAssignment(left: ObjectLiteralExpression | ArrayLiteralExpression, right: Expression): DestructuringAssignment; - function createAssignment(left: Expression, right: Expression): BinaryExpression; - function createStrictEquality(left: Expression, right: Expression): BinaryExpression; - function createStrictInequality(left: Expression, right: Expression): BinaryExpression; - function createAdd(left: Expression, right: Expression): BinaryExpression; - function createSubtract(left: Expression, right: Expression): BinaryExpression; - function createPostfixIncrement(operand: Expression): PostfixUnaryExpression; - function createLogicalAnd(left: Expression, right: Expression): BinaryExpression; - function createLogicalOr(left: Expression, right: Expression): BinaryExpression; - function createLogicalNot(operand: Expression): PrefixUnaryExpression; - function createVoidZero(): VoidExpression; - function createExportDefault(expression: Expression): ExportAssignment; - function createExternalModuleExport(exportName: Identifier): ExportDeclaration; - /** - * Clears any EmitNode entries from parse-tree nodes. - * @param sourceFile A source file. - */ - function disposeEmitNodes(sourceFile: SourceFile): void; - /** - * Associates a node with the current transformation, initializing - * various transient transformation properties. - */ - function getOrCreateEmitNode(node: Node): EmitNode; - /** - * Sets `EmitFlags.NoComments` on a node and removes any leading and trailing synthetic comments. - * @internal - */ - function removeAllComments(node: T): T; - function setTextRange(range: T, location: TextRange | undefined): T; - /** - * Sets flags that control emit behavior of a node. - */ - function setEmitFlags(node: T, emitFlags: EmitFlags): T; - /** - * Sets flags that control emit behavior of a node. - */ - function addEmitFlags(node: T, emitFlags: EmitFlags): T; - /** - * Gets a custom text range to use when emitting source maps. - */ - function getSourceMapRange(node: Node): SourceMapRange; - /** - * Sets a custom text range to use when emitting source maps. - */ - function setSourceMapRange(node: T, range: SourceMapRange | undefined): T; - /** - * Create an external source map source file reference - */ - function createSourceMapSource(fileName: string, text: string, skipTrivia?: (pos: number) => number): SourceMapSource; - /** - * Gets the TextRange to use for source maps for a token of a node. - */ - function getTokenSourceMapRange(node: Node, token: SyntaxKind): SourceMapRange | undefined; - /** - * Sets the TextRange to use for source maps for a token of a node. - */ - function setTokenSourceMapRange(node: T, token: SyntaxKind, range: SourceMapRange | undefined): T; - /** - * Gets a custom text range to use when emitting comments. - */ - function getStartsOnNewLine(node: Node): boolean | undefined; - /** - * Sets a custom text range to use when emitting comments. - */ - function setStartsOnNewLine(node: T, newLine: boolean): T; - /** - * Gets a custom text range to use when emitting comments. - */ - function getCommentRange(node: Node): TextRange; - /** - * Sets a custom text range to use when emitting comments. - */ - function setCommentRange(node: T, range: TextRange): T; - function getSyntheticLeadingComments(node: Node): SynthesizedComment[] | undefined; - function setSyntheticLeadingComments(node: T, comments: SynthesizedComment[] | undefined): T; - function addSyntheticLeadingComment(node: T, kind: SyntaxKind.SingleLineCommentTrivia | SyntaxKind.MultiLineCommentTrivia, text: string, hasTrailingNewLine?: boolean): T; - function getSyntheticTrailingComments(node: Node): SynthesizedComment[] | undefined; - function setSyntheticTrailingComments(node: T, comments: SynthesizedComment[] | undefined): T; - function addSyntheticTrailingComment(node: T, kind: SyntaxKind.SingleLineCommentTrivia | SyntaxKind.MultiLineCommentTrivia, text: string, hasTrailingNewLine?: boolean): T; - function moveSyntheticComments(node: T, original: Node): T; - /** - * Gets the constant value to emit for an expression. - */ - function getConstantValue(node: PropertyAccessExpression | ElementAccessExpression): string | number | undefined; - /** - * Sets the constant value to emit for an expression. - */ - function setConstantValue(node: PropertyAccessExpression | ElementAccessExpression, value: string | number): PropertyAccessExpression | ElementAccessExpression; - /** - * Adds an EmitHelper to a node. - */ - function addEmitHelper(node: T, helper: EmitHelper): T; - /** - * Add EmitHelpers to a node. - */ - function addEmitHelpers(node: T, helpers: EmitHelper[] | undefined): T; - /** - * Removes an EmitHelper from a node. - */ - function removeEmitHelper(node: Node, helper: EmitHelper): boolean; - /** - * Gets the EmitHelpers of a node. - */ - function getEmitHelpers(node: Node): EmitHelper[] | undefined; - /** - * Moves matching emit helpers from a source node to a target node. - */ - function moveEmitHelpers(source: Node, target: Node, predicate: (helper: EmitHelper) => boolean): void; - function compareEmitHelpers(x: EmitHelper, y: EmitHelper): Comparison.LessThan | Comparison.LessThan | Comparison | Comparison.GreaterThan; - function setOriginalNode(node: T, original: Node | undefined): T; -} -declare namespace ts { - const nullTransformationContext: TransformationContext; - type TypeOfTag = "undefined" | "number" | "boolean" | "string" | "symbol" | "object" | "function"; - function createTypeCheck(value: Expression, tag: TypeOfTag): BinaryExpression; - function createMemberAccessForPropertyName(target: Expression, memberName: PropertyName, location?: TextRange): MemberExpression; - function createFunctionCall(func: Expression, thisArg: Expression, argumentsList: ReadonlyArray, location?: TextRange): CallExpression; - function createFunctionApply(func: Expression, thisArg: Expression, argumentsExpression: Expression, location?: TextRange): CallExpression; - function createArraySlice(array: Expression, start?: number | Expression): CallExpression; - function createArrayConcat(array: Expression, values: ReadonlyArray): CallExpression; - function createMathPow(left: Expression, right: Expression, location?: TextRange): CallExpression; - function createExpressionForJsxElement(jsxFactoryEntity: EntityName | undefined, reactNamespace: string, tagName: Expression, props: Expression, children: ReadonlyArray, parentElement: JsxOpeningLikeElement, location: TextRange): LeftHandSideExpression; - function createExpressionForJsxFragment(jsxFactoryEntity: EntityName | undefined, reactNamespace: string, children: ReadonlyArray, parentElement: JsxOpeningFragment, location: TextRange): LeftHandSideExpression; - /** - * Gets an identifier for the name of an *unscoped* emit helper. - */ - function getUnscopedHelperName(name: string): Identifier; - const valuesHelper: UnscopedEmitHelper; - function createValuesHelper(context: TransformationContext, expression: Expression, location?: TextRange): CallExpression; - const readHelper: UnscopedEmitHelper; - function createReadHelper(context: TransformationContext, iteratorRecord: Expression, count: number | undefined, location?: TextRange): CallExpression; - const spreadHelper: UnscopedEmitHelper; - function createSpreadHelper(context: TransformationContext, argumentList: ReadonlyArray, location?: TextRange): CallExpression; - const spreadArraysHelper: UnscopedEmitHelper; - function createSpreadArraysHelper(context: TransformationContext, argumentList: ReadonlyArray, location?: TextRange): CallExpression; - function createForOfBindingStatement(node: ForInitializer, boundValue: Expression): Statement; - function insertLeadingStatement(dest: Statement, source: Statement): Block; - function restoreEnclosingLabel(node: Statement, outermostLabeledStatement: LabeledStatement | undefined, afterRestoreLabelCallback?: (node: LabeledStatement) => void): Statement; - interface CallBinding { - target: LeftHandSideExpression; - thisArg: Expression; - } - function createCallBinding(expression: Expression, recordTempVariable: (temp: Identifier) => void, languageVersion?: ScriptTarget, cacheIdentifiers?: boolean): CallBinding; - function inlineExpressions(expressions: ReadonlyArray): Expression; - function createExpressionFromEntityName(node: EntityName | Expression): Expression; - function createExpressionForPropertyName(memberName: PropertyName): Expression; - function createExpressionForObjectLiteralElementLike(node: ObjectLiteralExpression, property: ObjectLiteralElementLike, receiver: Expression): Expression | undefined; - /** - * Gets the internal name of a declaration. This is primarily used for declarations that can be - * referred to by name in the body of an ES5 class function body. An internal name will *never* - * be prefixed with an module or namespace export modifier like "exports." when emitted as an - * expression. An internal name will also *never* be renamed due to a collision with a block - * scoped variable. - * - * @param node The declaration. - * @param allowComments A value indicating whether comments may be emitted for the name. - * @param allowSourceMaps A value indicating whether source maps may be emitted for the name. - */ - function getInternalName(node: Declaration, allowComments?: boolean, allowSourceMaps?: boolean): Identifier; - /** - * Gets whether an identifier should only be referred to by its internal name. - */ - function isInternalName(node: Identifier): boolean; - /** - * Gets the local name of a declaration. This is primarily used for declarations that can be - * referred to by name in the declaration's immediate scope (classes, enums, namespaces). A - * local name will *never* be prefixed with an module or namespace export modifier like - * "exports." when emitted as an expression. - * - * @param node The declaration. - * @param allowComments A value indicating whether comments may be emitted for the name. - * @param allowSourceMaps A value indicating whether source maps may be emitted for the name. - */ - function getLocalName(node: Declaration, allowComments?: boolean, allowSourceMaps?: boolean): Identifier; - /** - * Gets whether an identifier should only be referred to by its local name. - */ - function isLocalName(node: Identifier): boolean; - /** - * Gets the export name of a declaration. This is primarily used for declarations that can be - * referred to by name in the declaration's immediate scope (classes, enums, namespaces). An - * export name will *always* be prefixed with an module or namespace export modifier like - * `"exports."` when emitted as an expression if the name points to an exported symbol. - * - * @param node The declaration. - * @param allowComments A value indicating whether comments may be emitted for the name. - * @param allowSourceMaps A value indicating whether source maps may be emitted for the name. - */ - function getExportName(node: Declaration, allowComments?: boolean, allowSourceMaps?: boolean): Identifier; - /** - * Gets whether an identifier should only be referred to by its export representation if the - * name points to an exported symbol. - */ - function isExportName(node: Identifier): boolean; - /** - * Gets the name of a declaration for use in declarations. - * - * @param node The declaration. - * @param allowComments A value indicating whether comments may be emitted for the name. - * @param allowSourceMaps A value indicating whether source maps may be emitted for the name. - */ - function getDeclarationName(node: Declaration, allowComments?: boolean, allowSourceMaps?: boolean): Identifier; - /** - * Gets the exported name of a declaration for use in expressions. - * - * An exported name will *always* be prefixed with an module or namespace export modifier like - * "exports." if the name points to an exported symbol. - * - * @param ns The namespace identifier. - * @param node The declaration. - * @param allowComments A value indicating whether comments may be emitted for the name. - * @param allowSourceMaps A value indicating whether source maps may be emitted for the name. - */ - function getExternalModuleOrNamespaceExportName(ns: Identifier | undefined, node: Declaration, allowComments?: boolean, allowSourceMaps?: boolean): Identifier | PropertyAccessExpression; - /** - * Gets a namespace-qualified name for use in expressions. - * - * @param ns The namespace identifier. - * @param name The name. - * @param allowComments A value indicating whether comments may be emitted for the name. - * @param allowSourceMaps A value indicating whether source maps may be emitted for the name. - */ - function getNamespaceMemberName(ns: Identifier, name: Identifier, allowComments?: boolean, allowSourceMaps?: boolean): PropertyAccessExpression; - function convertToFunctionBody(node: ConciseBody, multiLine?: boolean): Block; - function convertFunctionDeclarationToExpression(node: FunctionDeclaration): FunctionExpression; - /** - * Add any necessary prologue-directives into target statement-array. - * The function needs to be called during each transformation step. - * This function needs to be called whenever we transform the statement - * list of a source file, namespace, or function-like body. - * - * @param target: result statements array - * @param source: origin statements array - * @param ensureUseStrict: boolean determining whether the function need to add prologue-directives - * @param visitor: Optional callback used to visit any custom prologue directives. - */ - function addPrologue(target: Statement[], source: ReadonlyArray, ensureUseStrict?: boolean, visitor?: (node: Node) => VisitResult): number; - /** - * Add just the standard (string-expression) prologue-directives into target statement-array. - * The function needs to be called during each transformation step. - * This function needs to be called whenever we transform the statement - * list of a source file, namespace, or function-like body. - */ - function addStandardPrologue(target: Statement[], source: ReadonlyArray, ensureUseStrict?: boolean): number; - /** - * Add just the custom prologue-directives into target statement-array. - * The function needs to be called during each transformation step. - * This function needs to be called whenever we transform the statement - * list of a source file, namespace, or function-like body. - */ - function addCustomPrologue(target: Statement[], source: ReadonlyArray, statementOffset: number, visitor?: (node: Node) => VisitResult): number; - function addCustomPrologue(target: Statement[], source: ReadonlyArray, statementOffset: number | undefined, visitor?: (node: Node) => VisitResult): number | undefined; - function findUseStrictPrologue(statements: ReadonlyArray): Statement | undefined; - function startsWithUseStrict(statements: ReadonlyArray): boolean; - /** - * Ensures "use strict" directive is added - * - * @param statements An array of statements - */ - function ensureUseStrict(statements: NodeArray): NodeArray; - /** - * Wraps the operand to a BinaryExpression in parentheses if they are needed to preserve the intended - * order of operations. - * - * @param binaryOperator The operator for the BinaryExpression. - * @param operand The operand for the BinaryExpression. - * @param isLeftSideOfBinary A value indicating whether the operand is the left side of the - * BinaryExpression. - */ - function parenthesizeBinaryOperand(binaryOperator: SyntaxKind, operand: Expression, isLeftSideOfBinary: boolean, leftOperand?: Expression): Expression; - function parenthesizeForConditionalHead(condition: Expression): Expression; - function parenthesizeSubexpressionOfConditionalExpression(e: Expression): Expression; - /** - * [Per the spec](https://tc39.github.io/ecma262/#prod-ExportDeclaration), `export default` accepts _AssigmentExpression_ but - * has a lookahead restriction for `function`, `async function`, and `class`. - * - * Basically, that means we need to parenthesize in the following cases: - * - * - BinaryExpression of CommaToken - * - CommaList (synthetic list of multiple comma expressions) - * - FunctionExpression - * - ClassExpression - */ - function parenthesizeDefaultExpression(e: Expression): Expression; - /** - * Wraps an expression in parentheses if it is needed in order to use the expression - * as the expression of a NewExpression node. - * - * @param expression The Expression node. - */ - function parenthesizeForNew(expression: Expression): LeftHandSideExpression; - /** - * Wraps an expression in parentheses if it is needed in order to use the expression for - * property or element access. - * - * @param expr The expression node. - */ - function parenthesizeForAccess(expression: Expression): LeftHandSideExpression; - function parenthesizePostfixOperand(operand: Expression): LeftHandSideExpression; - function parenthesizePrefixOperand(operand: Expression): UnaryExpression; - function parenthesizeListElements(elements: NodeArray): NodeArray; - function parenthesizeExpressionForList(expression: Expression): Expression; - function parenthesizeExpressionForExpressionStatement(expression: Expression): Expression; - function parenthesizeConditionalTypeMember(member: TypeNode): TypeNode; - function parenthesizeElementTypeMember(member: TypeNode): TypeNode; - function parenthesizeArrayTypeMember(member: TypeNode): TypeNode; - function parenthesizeElementTypeMembers(members: ReadonlyArray): NodeArray; - function parenthesizeTypeParameters(typeParameters: ReadonlyArray | undefined): MutableNodeArray | undefined; - function getLeftmostExpression(node: Expression, stopAtCallExpressions: boolean): Expression; - function parenthesizeConciseBody(body: ConciseBody): ConciseBody; - function isCommaSequence(node: Expression): node is (BinaryExpression & { - operatorToken: Token; - }) | CommaListExpression; - enum OuterExpressionKinds { - Parentheses = 1, - Assertions = 2, - PartiallyEmittedExpressions = 4, - All = 7 - } - type OuterExpression = ParenthesizedExpression | TypeAssertion | AsExpression | NonNullExpression | PartiallyEmittedExpression; - function isOuterExpression(node: Node, kinds?: OuterExpressionKinds): node is OuterExpression; - function skipOuterExpressions(node: Expression, kinds?: OuterExpressionKinds): Expression; - function skipOuterExpressions(node: Node, kinds?: OuterExpressionKinds): Node; - function skipAssertions(node: Expression): Expression; - function skipAssertions(node: Node): Node; - function recreateOuterExpressions(outerExpression: Expression | undefined, innerExpression: Expression, kinds?: OuterExpressionKinds): Expression; - function startOnNewLine(node: T): T; - function getExternalHelpersModuleName(node: SourceFile): Identifier | undefined; - function hasRecordedExternalHelpers(sourceFile: SourceFile): boolean; - function createExternalHelpersImportDeclarationIfNeeded(sourceFile: SourceFile, compilerOptions: CompilerOptions, hasExportStarsToExportValues?: boolean, hasImportStar?: boolean, hasImportDefault?: boolean): ImportDeclaration | undefined; - function getOrCreateExternalHelpersModuleNameIfNeeded(node: SourceFile, compilerOptions: CompilerOptions, hasExportStarsToExportValues?: boolean, hasImportStarOrImportDefault?: boolean): Identifier | undefined; - /** - * Get the name of that target module from an import or export declaration - */ - function getLocalNameForExternalImport(node: ImportDeclaration | ExportDeclaration | ImportEqualsDeclaration, sourceFile: SourceFile): Identifier | undefined; - /** - * Get the name of a target module from an import/export declaration as should be written in the emitted output. - * The emitted output name can be different from the input if: - * 1. The module has a /// - * 2. --out or --outFile is used, making the name relative to the rootDir - * 3- The containing SourceFile has an entry in renamedDependencies for the import as requested by some module loaders (e.g. System). - * Otherwise, a new StringLiteral node representing the module name will be returned. - */ - function getExternalModuleNameLiteral(importNode: ImportDeclaration | ExportDeclaration | ImportEqualsDeclaration, sourceFile: SourceFile, host: EmitHost, resolver: EmitResolver, compilerOptions: CompilerOptions): StringLiteral | undefined; - /** - * Get the name of a module as should be written in the emitted output. - * The emitted output name can be different from the input if: - * 1. The module has a /// - * 2. --out or --outFile is used, making the name relative to the rootDir - * Otherwise, a new StringLiteral node representing the module name will be returned. - */ - function tryGetModuleNameFromFile(file: SourceFile | undefined, host: EmitHost, options: CompilerOptions): StringLiteral | undefined; - /** - * Gets the initializer of an BindingOrAssignmentElement. - */ - function getInitializerOfBindingOrAssignmentElement(bindingElement: BindingOrAssignmentElement): Expression | undefined; - /** - * Gets the name of an BindingOrAssignmentElement. - */ - function getTargetOfBindingOrAssignmentElement(bindingElement: BindingOrAssignmentElement): BindingOrAssignmentElementTarget | undefined; - /** - * Determines whether an BindingOrAssignmentElement is a rest element. - */ - function getRestIndicatorOfBindingOrAssignmentElement(bindingElement: BindingOrAssignmentElement): BindingOrAssignmentElementRestIndicator | undefined; - /** - * Gets the property name of a BindingOrAssignmentElement - */ - function getPropertyNameOfBindingOrAssignmentElement(bindingElement: BindingOrAssignmentElement): PropertyName | undefined; - /** - * Gets the elements of a BindingOrAssignmentPattern - */ - function getElementsOfBindingOrAssignmentPattern(name: BindingOrAssignmentPattern): ReadonlyArray; - function convertToArrayAssignmentElement(element: BindingOrAssignmentElement): Expression; - function convertToObjectAssignmentElement(element: BindingOrAssignmentElement): ObjectLiteralElementLike; - function convertToAssignmentPattern(node: BindingOrAssignmentPattern): AssignmentPattern; - function convertToObjectAssignmentPattern(node: ObjectBindingOrAssignmentPattern): ObjectLiteralExpression; - function convertToArrayAssignmentPattern(node: ArrayBindingOrAssignmentPattern): ArrayLiteralExpression; - function convertToAssignmentElementTarget(node: BindingOrAssignmentElementTarget): Expression; -} -declare namespace ts { - /** - * Visits a Node using the supplied visitor, possibly returning a new Node in its place. - * - * @param node The Node to visit. - * @param visitor The callback used to visit the Node. - * @param test A callback to execute to verify the Node is valid. - * @param lift An optional callback to execute to lift a NodeArray into a valid Node. - */ - function visitNode(node: T | undefined, visitor: Visitor | undefined, test?: (node: Node) => boolean, lift?: (node: NodeArray) => T): T; - /** - * Visits a Node using the supplied visitor, possibly returning a new Node in its place. - * - * @param node The Node to visit. - * @param visitor The callback used to visit the Node. - * @param test A callback to execute to verify the Node is valid. - * @param lift An optional callback to execute to lift a NodeArray into a valid Node. - */ - function visitNode(node: T | undefined, visitor: Visitor | undefined, test?: (node: Node) => boolean, lift?: (node: NodeArray) => T): T | undefined; - /** - * Visits a NodeArray using the supplied visitor, possibly returning a new NodeArray in its place. - * - * @param nodes The NodeArray to visit. - * @param visitor The callback used to visit a Node. - * @param test A node test to execute for each node. - * @param start An optional value indicating the starting offset at which to start visiting. - * @param count An optional value indicating the maximum number of nodes to visit. - */ - function visitNodes(nodes: NodeArray | undefined, visitor: Visitor, test?: (node: Node) => boolean, start?: number, count?: number): NodeArray; - /** - * Visits a NodeArray using the supplied visitor, possibly returning a new NodeArray in its place. - * - * @param nodes The NodeArray to visit. - * @param visitor The callback used to visit a Node. - * @param test A node test to execute for each node. - * @param start An optional value indicating the starting offset at which to start visiting. - * @param count An optional value indicating the maximum number of nodes to visit. - */ - function visitNodes(nodes: NodeArray | undefined, visitor: Visitor, test?: (node: Node) => boolean, start?: number, count?: number): NodeArray | undefined; - /** - * Starts a new lexical environment and visits a statement list, ending the lexical environment - * and merging hoisted declarations upon completion. - */ - function visitLexicalEnvironment(statements: NodeArray, visitor: Visitor, context: TransformationContext, start?: number, ensureUseStrict?: boolean): NodeArray; - /** - * Starts a new lexical environment and visits a parameter list, suspending the lexical - * environment upon completion. - */ - function visitParameterList(nodes: NodeArray | undefined, visitor: Visitor, context: TransformationContext, nodesVisitor?: typeof visitNodes): NodeArray; - /** - * Resumes a suspended lexical environment and visits a function body, ending the lexical - * environment and merging hoisted declarations upon completion. - */ - function visitFunctionBody(node: FunctionBody, visitor: Visitor, context: TransformationContext): FunctionBody; - /** - * Resumes a suspended lexical environment and visits a function body, ending the lexical - * environment and merging hoisted declarations upon completion. - */ - function visitFunctionBody(node: FunctionBody | undefined, visitor: Visitor, context: TransformationContext): FunctionBody | undefined; - /** - * Resumes a suspended lexical environment and visits a concise body, ending the lexical - * environment and merging hoisted declarations upon completion. - */ - function visitFunctionBody(node: ConciseBody, visitor: Visitor, context: TransformationContext): ConciseBody; - /** - * Visits each child of a Node using the supplied visitor, possibly returning a new Node of the same kind in its place. - * - * @param node The Node whose children will be visited. - * @param visitor The callback used to visit each child. - * @param context A lexical environment context for the visitor. - */ - function visitEachChild(node: T, visitor: Visitor, context: TransformationContext): T; - /** - * Visits each child of a Node using the supplied visitor, possibly returning a new Node of the same kind in its place. - * - * @param node The Node whose children will be visited. - * @param visitor The callback used to visit each child. - * @param context A lexical environment context for the visitor. - */ - function visitEachChild(node: T | undefined, visitor: Visitor, context: TransformationContext, nodesVisitor?: typeof visitNodes, tokenVisitor?: Visitor): T | undefined; -} -declare namespace ts { - /** - * Similar to `reduceLeft`, performs a reduction against each child of a node. - * NOTE: Unlike `forEachChild`, this does *not* visit every node. - * - * @param node The node containing the children to reduce. - * @param initial The initial value to supply to the reduction. - * @param f The callback function - */ - function reduceEachChild(node: Node | undefined, initial: T, cbNode: (memo: T, node: Node) => T, cbNodeArray?: (memo: T, nodes: NodeArray) => T): T; - /** - * Merges generated lexical declarations into a new statement list. - */ - function mergeLexicalEnvironment(statements: NodeArray, declarations: ReadonlyArray | undefined): NodeArray; - /** - * Appends generated lexical declarations to an array of statements. - */ - function mergeLexicalEnvironment(statements: Statement[], declarations: ReadonlyArray | undefined): Statement[]; - /** - * Lifts a NodeArray containing only Statement nodes to a block. - * - * @param nodes The NodeArray. - */ - function liftToBlock(nodes: ReadonlyArray): Statement; - /** - * Aggregates the TransformFlags for a Node and its subtree. - */ - function aggregateTransformFlags(node: T): T; -} -declare namespace ts { - interface SourceMapGeneratorOptions { - extendedDiagnostics?: boolean; - } - function createSourceMapGenerator(host: EmitHost, file: string, sourceRoot: string, sourcesDirectoryPath: string, generatorOptions: SourceMapGeneratorOptions): SourceMapGenerator; - interface LineInfo { - getLineCount(): number; - getLineText(line: number): string; - } - function getLineInfo(text: string, lineStarts: ReadonlyArray): LineInfo; - /** - * Tries to find the sourceMappingURL comment at the end of a file. - */ - function tryGetSourceMappingURL(lineInfo: LineInfo): string | undefined; - function isRawSourceMap(x: any): x is RawSourceMap; - function tryParseRawSourceMap(text: string): RawSourceMap | undefined; - interface MappingsDecoder extends Iterator { - readonly pos: number; - readonly error: string | undefined; - readonly state: Required; - } - interface Mapping { - generatedLine: number; - generatedCharacter: number; - sourceIndex?: number; - sourceLine?: number; - sourceCharacter?: number; - nameIndex?: number; - } - interface SourceMapping extends Mapping { - sourceIndex: number; - sourceLine: number; - sourceCharacter: number; - } - function decodeMappings(mappings: string): MappingsDecoder; - function sameMapping(left: T, right: T): boolean; - function isSourceMapping(mapping: Mapping): mapping is SourceMapping; - function createDocumentPositionMapper(host: DocumentPositionMapperHost, map: RawSourceMap, mapPath: string): DocumentPositionMapper; - const identitySourceMapConsumer: DocumentPositionMapper; -} -declare namespace ts { - function getOriginalNodeId(node: Node): number; - interface ExternalModuleInfo { - externalImports: (ImportDeclaration | ImportEqualsDeclaration | ExportDeclaration)[]; - externalHelpersImportDeclaration: ImportDeclaration | undefined; - exportSpecifiers: Map; - exportedBindings: Identifier[][]; - exportedNames: Identifier[] | undefined; - exportEquals: ExportAssignment | undefined; - hasExportStarsToExportValues: boolean; - } - function chainBundle(transformSourceFile: (x: SourceFile) => SourceFile): (x: SourceFile | Bundle) => SourceFile | Bundle; - function getImportNeedsImportStarHelper(node: ImportDeclaration): boolean; - function getImportNeedsImportDefaultHelper(node: ImportDeclaration): boolean; - function collectExternalModuleInfo(sourceFile: SourceFile, resolver: EmitResolver, compilerOptions: CompilerOptions): ExternalModuleInfo; - /** - * Used in the module transformer to check if an expression is reasonably without sideeffect, - * and thus better to copy into multiple places rather than to cache in a temporary variable - * - this is mostly subjective beyond the requirement that the expression not be sideeffecting - */ - function isSimpleCopiableExpression(expression: Expression): boolean; - /** - * A simple inlinable expression is an expression which can be copied into multiple locations - * without risk of repeating any sideeffects and whose value could not possibly change between - * any such locations - */ - function isSimpleInlineableExpression(expression: Expression): boolean; - /** - * Adds super call and preceding prologue directives into the list of statements. - * - * @param ctor The constructor node. - * @param result The list of statements. - * @param visitor The visitor to apply to each node added to the result array. - * @returns index of the statement that follows super call - */ - function addPrologueDirectivesAndInitialSuperCall(ctor: ConstructorDeclaration, result: Statement[], visitor: Visitor): number; - /** - * @param input Template string input strings - * @param args Names which need to be made file-level unique - */ - function helperString(input: TemplateStringsArray, ...args: string[]): (uniqueName: EmitHelperUniqueNameCallback) => string; - /** - * Gets all property declarations with initializers on either the static or instance side of a class. - * - * @param node The class node. - * @param isStatic A value indicating whether to get properties from the static or instance side of the class. - */ - function getInitializedProperties(node: ClassExpression | ClassDeclaration, isStatic: boolean): ReadonlyArray; - /** - * Gets a value indicating whether a class element is a static property declaration with an initializer. - * - * @param member The class element node. - */ - function isStaticInitializedProperty(member: ClassElement): member is PropertyDeclaration & { - initializer: Expression; - }; - /** - * Gets a value indicating whether a class element is an instance property declaration with an initializer. - * - * @param member The class element node. - */ - function isInstanceInitializedProperty(member: ClassElement): member is PropertyDeclaration & { - initializer: Expression; - }; - /** - * Gets a value indicating whether a class element is either a static or an instance property declaration with an initializer. - * - * @param member The class element node. - * @param isStatic A value indicating whether the member should be a static or instance member. - */ - function isInitializedProperty(member: ClassElement): member is PropertyDeclaration & { - initializer: Expression; - }; -} -declare namespace ts { - enum FlattenLevel { - All = 0, - ObjectRest = 1 - } - /** - * Flattens a DestructuringAssignment or a VariableDeclaration to an expression. - * - * @param node The node to flatten. - * @param visitor An optional visitor used to visit initializers. - * @param context The transformation context. - * @param level Indicates the extent to which flattening should occur. - * @param needsValue An optional value indicating whether the value from the right-hand-side of - * the destructuring assignment is needed as part of a larger expression. - * @param createAssignmentCallback An optional callback used to create the assignment expression. - */ - function flattenDestructuringAssignment(node: VariableDeclaration | DestructuringAssignment, visitor: ((node: Node) => VisitResult) | undefined, context: TransformationContext, level: FlattenLevel, needsValue?: boolean, createAssignmentCallback?: (name: Identifier, value: Expression, location?: TextRange) => Expression): Expression; - /** - * Flattens a VariableDeclaration or ParameterDeclaration to one or more variable declarations. - * - * @param node The node to flatten. - * @param visitor An optional visitor used to visit initializers. - * @param context The transformation context. - * @param boundValue The value bound to the declaration. - * @param skipInitializer A value indicating whether to ignore the initializer of `node`. - * @param hoistTempVariables Indicates whether temporary variables should not be recorded in-line. - * @param level Indicates the extent to which flattening should occur. - */ - function flattenDestructuringBinding(node: VariableDeclaration | ParameterDeclaration, visitor: (node: Node) => VisitResult, context: TransformationContext, level: FlattenLevel, rval?: Expression, hoistTempVariables?: boolean, skipInitializer?: boolean): VariableDeclaration[]; - const restHelper: UnscopedEmitHelper; -} -declare namespace ts { - function transformTypeScript(context: TransformationContext): (node: SourceFile | Bundle) => SourceFile | Bundle; - const decorateHelper: UnscopedEmitHelper; - const metadataHelper: UnscopedEmitHelper; - const paramHelper: UnscopedEmitHelper; -} -declare namespace ts { - /** - * Transforms ECMAScript Class Syntax. - * TypeScript parameter property syntax is transformed in the TypeScript transformer. - * For now, this transforms public field declarations using TypeScript class semantics - * (where the declarations get elided and initializers are transformed as assignments in the constructor). - * Eventually, this transform will change to the ECMAScript semantics (with Object.defineProperty). - */ - function transformClassFields(context: TransformationContext): (x: SourceFile | Bundle) => SourceFile | Bundle; -} -declare namespace ts { - function transformES2017(context: TransformationContext): (x: SourceFile | Bundle) => SourceFile | Bundle; - /** Creates a variable named `_super` with accessor properties for the given property names. */ - function createSuperAccessVariableStatement(resolver: EmitResolver, node: FunctionLikeDeclaration, names: UnderscoreEscapedMap): VariableStatement; - const awaiterHelper: UnscopedEmitHelper; - const asyncSuperHelper: EmitHelper; - const advancedAsyncSuperHelper: EmitHelper; -} -declare namespace ts { - function transformES2018(context: TransformationContext): (x: SourceFile | Bundle) => SourceFile | Bundle; - const assignHelper: UnscopedEmitHelper; - function createAssignHelper(context: TransformationContext, attributesSegments: Expression[]): CallExpression; - const awaitHelper: UnscopedEmitHelper; - const asyncGeneratorHelper: UnscopedEmitHelper; - const asyncDelegator: UnscopedEmitHelper; - const asyncValues: UnscopedEmitHelper; -} -declare namespace ts { - function transformES2019(context: TransformationContext): (x: SourceFile | Bundle) => SourceFile | Bundle; -} -declare namespace ts { - function transformESNext(context: TransformationContext): (x: SourceFile | Bundle) => SourceFile | Bundle; -} -declare namespace ts { - function transformJsx(context: TransformationContext): (x: SourceFile | Bundle) => SourceFile | Bundle; -} -declare namespace ts { - function transformES2016(context: TransformationContext): (x: SourceFile | Bundle) => SourceFile | Bundle; -} -declare namespace ts { - function transformES2015(context: TransformationContext): (x: SourceFile | Bundle) => SourceFile | Bundle; - const extendsHelper: UnscopedEmitHelper; - const templateObjectHelper: UnscopedEmitHelper; -} -declare namespace ts { - /** - * Transforms ES5 syntax into ES3 syntax. - * - * @param context Context and state information for the transformation. - */ - function transformES5(context: TransformationContext): (x: SourceFile | Bundle) => SourceFile | Bundle; -} -declare namespace ts { - function transformGenerators(context: TransformationContext): (x: SourceFile | Bundle) => SourceFile | Bundle; - const generatorHelper: UnscopedEmitHelper; -} -declare namespace ts { - function transformModule(context: TransformationContext): (x: SourceFile | Bundle) => SourceFile | Bundle; - const importStarHelper: UnscopedEmitHelper; - const importDefaultHelper: UnscopedEmitHelper; -} -declare namespace ts { - function transformSystemModule(context: TransformationContext): (x: SourceFile | Bundle) => SourceFile | Bundle; -} -declare namespace ts { - function transformES2015Module(context: TransformationContext): (x: SourceFile | Bundle) => SourceFile | Bundle; -} -declare namespace ts { - type GetSymbolAccessibilityDiagnostic = (symbolAccessibilityResult: SymbolAccessibilityResult) => (SymbolAccessibilityDiagnostic | undefined); - interface SymbolAccessibilityDiagnostic { - errorNode: Node; - diagnosticMessage: DiagnosticMessage; - typeName?: DeclarationName | QualifiedName; - } - type DeclarationDiagnosticProducing = VariableDeclaration | PropertyDeclaration | PropertySignature | BindingElement | SetAccessorDeclaration | GetAccessorDeclaration | ConstructSignatureDeclaration | CallSignatureDeclaration | MethodDeclaration | MethodSignature | FunctionDeclaration | ParameterDeclaration | TypeParameterDeclaration | ExpressionWithTypeArguments | ImportEqualsDeclaration | TypeAliasDeclaration | ConstructorDeclaration | IndexSignatureDeclaration | PropertyAccessExpression; - function canProduceDiagnostics(node: Node): node is DeclarationDiagnosticProducing; - function createGetSymbolAccessibilityDiagnosticForNodeName(node: DeclarationDiagnosticProducing): (symbolAccessibilityResult: SymbolAccessibilityResult) => SymbolAccessibilityDiagnostic | undefined; - function createGetSymbolAccessibilityDiagnosticForNode(node: DeclarationDiagnosticProducing): (symbolAccessibilityResult: SymbolAccessibilityResult) => SymbolAccessibilityDiagnostic | undefined; -} -declare namespace ts { - function getDeclarationDiagnostics(host: EmitHost, resolver: EmitResolver, file: SourceFile | undefined): DiagnosticWithLocation[] | undefined; - function isInternalDeclaration(node: Node, currentSourceFile: SourceFile): boolean | 0 | undefined; - /** - * Transforms a ts file into a .d.ts file - * This process requires type information, which is retrieved through the emit resolver. Because of this, - * in many places this transformer assumes it will be operating on parse tree nodes directly. - * This means that _no transforms should be allowed to occur before this one_. - */ - function transformDeclarations(context: TransformationContext): { - (node: Bundle): Bundle; - (node: SourceFile): SourceFile; - (node: SourceFile | Bundle): SourceFile | Bundle; - }; -} -declare namespace ts { - const noTransformers: EmitTransformers; - function getTransformers(compilerOptions: CompilerOptions, customTransformers?: CustomTransformers, emitOnlyDtsFiles?: boolean): EmitTransformers; - function noEmitSubstitution(_hint: EmitHint, node: Node): Node; - function noEmitNotification(hint: EmitHint, node: Node, callback: (hint: EmitHint, node: Node) => void): void; - /** - * Transforms an array of SourceFiles by passing them through each transformer. - * - * @param resolver The emit resolver provided by the checker. - * @param host The emit host object used to interact with the file system. - * @param options Compiler options to surface in the `TransformationContext`. - * @param nodes An array of nodes to transform. - * @param transforms An array of `TransformerFactory` callbacks. - * @param allowDtsFiles A value indicating whether to allow the transformation of .d.ts files. - */ - function transformNodes(resolver: EmitResolver | undefined, host: EmitHost | undefined, options: CompilerOptions, nodes: ReadonlyArray, transformers: ReadonlyArray>, allowDtsFiles: boolean): TransformationResult; -} -declare namespace ts { - function isBuildInfoFile(file: string): boolean; - /** - * Iterates over the source files that are expected to have an emit output. - * - * @param host An EmitHost. - * @param action The action to execute. - * @param sourceFilesOrTargetSourceFile - * If an array, the full list of source files to emit. - * Else, calls `getSourceFilesToEmit` with the (optional) target source file to determine the list of source files to emit. - */ - function forEachEmittedFile(host: EmitHost, action: (emitFileNames: EmitFileNames, sourceFileOrBundle: SourceFile | Bundle | undefined) => T, sourceFilesOrTargetSourceFile?: ReadonlyArray | SourceFile, emitOnlyDtsFiles?: boolean, onlyBuildInfo?: boolean, includeBuildInfo?: boolean): T | undefined; - function getOutputPathForBuildInfo(options: CompilerOptions): string | undefined; - function getOutputPathsForBundle(options: CompilerOptions, forceDtsPaths: boolean): EmitFileNames; - function getOutputPathsFor(sourceFile: SourceFile | Bundle, host: EmitHost, forceDtsPaths: boolean): EmitFileNames; - function getOutputExtension(sourceFile: SourceFile, options: CompilerOptions): Extension; - function getOutputDeclarationFileName(inputFileName: string, configFile: ParsedCommandLine, ignoreCase: boolean): string; - function getAllProjectOutputs(configFile: ParsedCommandLine, ignoreCase: boolean): ReadonlyArray; - function getFirstProjectOutput(configFile: ParsedCommandLine, ignoreCase: boolean): string; - function emitFiles(resolver: EmitResolver, host: EmitHost, targetSourceFile: SourceFile | undefined, { scriptTransformers, declarationTransformers }: EmitTransformers, emitOnlyDtsFiles?: boolean, onlyBuildInfo?: boolean): EmitResult; - function getBuildInfoText(buildInfo: BuildInfo): string; - function getBuildInfo(buildInfoText: string): BuildInfo; - const notImplementedResolver: EmitResolver; - /** File that isnt present resulting in error or output files */ - type EmitUsingBuildInfoResult = string | ReadonlyArray; - interface EmitUsingBuildInfoHost extends ModuleResolutionHost { - getCurrentDirectory(): string; - getCanonicalFileName(fileName: string): string; - useCaseSensitiveFileNames(): boolean; - getNewLine(): string; - } - function emitUsingBuildInfo(config: ParsedCommandLine, host: EmitUsingBuildInfoHost, getCommandLine: (ref: ProjectReference) => ParsedCommandLine | undefined, customTransformers?: CustomTransformers): EmitUsingBuildInfoResult; - function createPrinter(printerOptions?: PrinterOptions, handlers?: PrintHandlers): Printer; -} -declare namespace ts { - /** - * Partial interface of the System thats needed to support the caching of directory structure - */ - interface DirectoryStructureHost { - fileExists(path: string): boolean; - readFile(path: string, encoding?: string): string | undefined; - directoryExists?(path: string): boolean; - getDirectories?(path: string): string[]; - readDirectory?(path: string, extensions?: ReadonlyArray, exclude?: ReadonlyArray, include?: ReadonlyArray, depth?: number): string[]; - realpath?(path: string): string; - createDirectory?(path: string): void; - writeFile?(path: string, data: string, writeByteOrderMark?: boolean): void; - } - interface FileAndDirectoryExistence { - fileExists: boolean; - directoryExists: boolean; - } - interface CachedDirectoryStructureHost extends DirectoryStructureHost { - useCaseSensitiveFileNames: boolean; - getDirectories(path: string): string[]; - readDirectory(path: string, extensions?: ReadonlyArray, exclude?: ReadonlyArray, include?: ReadonlyArray, depth?: number): string[]; - /** Returns the queried result for the file exists and directory exists if at all it was done */ - addOrDeleteFileOrDirectory(fileOrDirectory: string, fileOrDirectoryPath: Path): FileAndDirectoryExistence | undefined; - addOrDeleteFile(fileName: string, filePath: Path, eventKind: FileWatcherEventKind): void; - clearCache(): void; - } - function createCachedDirectoryStructureHost(host: DirectoryStructureHost, currentDirectory: string, useCaseSensitiveFileNames: boolean): CachedDirectoryStructureHost | undefined; - enum ConfigFileProgramReloadLevel { - None = 0, - /** Update the file name list from the disk */ - Partial = 1, - /** Reload completely by re-reading contents of config file from disk and updating program */ - Full = 2 - } - /** - * Updates the existing missing file watches with the new set of missing files after new program is created - */ - function updateMissingFilePathsWatch(program: Program, missingFileWatches: Map, createMissingFileWatch: (missingFilePath: Path) => FileWatcher): void; - interface WildcardDirectoryWatcher { - watcher: FileWatcher; - flags: WatchDirectoryFlags; - } - /** - * Updates the existing wild card directory watches with the new set of wild card directories from the config file - * after new program is created because the config file was reloaded or program was created first time from the config file - * Note that there is no need to call this function when the program is updated with additional files without reloading config files, - * as wildcard directories wont change unless reloading config file - */ - function updateWatchingWildcardDirectories(existingWatchedForWildcards: Map, wildcardDirectories: Map, watchDirectory: (directory: string, flags: WatchDirectoryFlags) => FileWatcher): void; - function isEmittedFileOfProgram(program: Program | undefined, file: string): boolean; - enum WatchLogLevel { - None = 0, - TriggerOnly = 1, - Verbose = 2 - } - interface WatchFileHost { - watchFile(path: string, callback: FileWatcherCallback, pollingInterval?: number): FileWatcher; - } - interface WatchDirectoryHost { - watchDirectory(path: string, callback: DirectoryWatcherCallback, recursive?: boolean): FileWatcher; - } - type WatchFile = (host: WatchFileHost, file: string, callback: FileWatcherCallback, pollingInterval: PollingInterval, detailInfo1: X, detailInfo2?: Y) => FileWatcher; - type FilePathWatcherCallback = (fileName: string, eventKind: FileWatcherEventKind, filePath: Path) => void; - type WatchFilePath = (host: WatchFileHost, file: string, callback: FilePathWatcherCallback, pollingInterval: PollingInterval, path: Path, detailInfo1: X, detailInfo2?: Y) => FileWatcher; - type WatchDirectory = (host: WatchDirectoryHost, directory: string, callback: DirectoryWatcherCallback, flags: WatchDirectoryFlags, detailInfo1: X, detailInfo2?: Y) => FileWatcher; - interface WatchFactory { - watchFile: WatchFile; - watchFilePath: WatchFilePath; - watchDirectory: WatchDirectory; - } - function getWatchFactory(watchLogLevel: WatchLogLevel, log: (s: string) => void, getDetailWatchInfo?: GetDetailWatchInfo): WatchFactory; - type GetDetailWatchInfo = (detailInfo1: X, detailInfo2: Y | undefined) => string; - function closeFileWatcherOf(objWithWatcher: T): void; -} -declare namespace ts { - export function findConfigFile(searchPath: string, fileExists: (fileName: string) => boolean, configName?: string): string | undefined; - export function resolveTripleslashReference(moduleName: string, containingFile: string): string; - export function computeCommonSourceDirectoryOfFilenames(fileNames: string[], currentDirectory: string, getCanonicalFileName: GetCanonicalFileName): string; - export function createCompilerHost(options: CompilerOptions, setParentNodes?: boolean): CompilerHost; - export function createCompilerHostWorker(options: CompilerOptions, setParentNodes?: boolean, system?: System): CompilerHost; - interface CompilerHostLikeForCache { - fileExists(fileName: string): boolean; - readFile(fileName: string, encoding?: string): string | undefined; - directoryExists?(directory: string): boolean; - createDirectory?(directory: string): void; - writeFile?: WriteFileCallback; - } - export function changeCompilerHostLikeToUseCache(host: CompilerHostLikeForCache, toPath: (fileName: string) => Path, getSourceFile?: CompilerHost["getSourceFile"]): { - originalReadFile: (fileName: string, encoding?: string | undefined) => string | undefined; - originalFileExists: (fileName: string) => boolean; - originalDirectoryExists: ((directory: string) => boolean) | undefined; - originalCreateDirectory: ((directory: string) => void) | undefined; - originalWriteFile: WriteFileCallback | undefined; - getSourceFileWithCache: ((fileName: string, languageVersion: ScriptTarget, onError?: ((message: string) => void) | undefined, shouldCreateNewSourceFile?: boolean | undefined) => SourceFile | undefined) | undefined; - readFileWithCache: (fileName: string) => string | undefined; - }; - export function getPreEmitDiagnostics(program: Program, sourceFile?: SourceFile, cancellationToken?: CancellationToken): ReadonlyArray; - export function getPreEmitDiagnostics(program: BuilderProgram, sourceFile?: SourceFile, cancellationToken?: CancellationToken): ReadonlyArray; - export interface FormatDiagnosticsHost { - getCurrentDirectory(): string; - getCanonicalFileName(fileName: string): string; - getNewLine(): string; - } - export function formatDiagnostics(diagnostics: ReadonlyArray, host: FormatDiagnosticsHost): string; - export function formatDiagnostic(diagnostic: Diagnostic, host: FormatDiagnosticsHost): string; - /** @internal */ - export enum ForegroundColorEscapeSequences { - Grey = "\u001B[90m", - Red = "\u001B[91m", - Yellow = "\u001B[93m", - Blue = "\u001B[94m", - Cyan = "\u001B[96m" - } - /** @internal */ - export function formatColorAndReset(text: string, formatStyle: string): string; - export function formatLocation(file: SourceFile, start: number, host: FormatDiagnosticsHost, color?: typeof formatColorAndReset): string; - export function formatDiagnosticsWithColorAndContext(diagnostics: ReadonlyArray, host: FormatDiagnosticsHost): string; - export function flattenDiagnosticMessageText(diag: string | DiagnosticMessageChain | undefined, newLine: string, indent?: number): string; - export function loadWithLocalCache(names: string[], containingFile: string, redirectedReference: ResolvedProjectReference | undefined, loader: (name: string, containingFile: string, redirectedReference: ResolvedProjectReference | undefined) => T): T[]; - /** - * Determines if program structure is upto date or needs to be recreated - */ - export function isProgramUptoDate(program: Program | undefined, rootFileNames: string[], newOptions: CompilerOptions, getSourceVersion: (path: Path) => string | undefined, fileExists: (fileName: string) => boolean, hasInvalidatedResolution: HasInvalidatedResolution, hasChangedAutomaticTypeDirectiveNames: boolean, projectReferences: ReadonlyArray | undefined): boolean; - export function getConfigFileParsingDiagnostics(configFileParseResult: ParsedCommandLine): ReadonlyArray; - /** - * Create a new 'Program' instance. A Program is an immutable collection of 'SourceFile's and a 'CompilerOptions' - * that represent a compilation unit. - * - * Creating a program proceeds from a set of root files, expanding the set of inputs by following imports and - * triple-slash-reference-path directives transitively. '@types' and triple-slash-reference-types are also pulled in. - * - * @param createProgramOptions - The options for creating a program. - * @returns A 'Program' object. - */ - export function createProgram(createProgramOptions: CreateProgramOptions): Program; - /** - * Create a new 'Program' instance. A Program is an immutable collection of 'SourceFile's and a 'CompilerOptions' - * that represent a compilation unit. - * - * Creating a program proceeds from a set of root files, expanding the set of inputs by following imports and - * triple-slash-reference-path directives transitively. '@types' and triple-slash-reference-types are also pulled in. - * - * @param rootNames - A set of root files. - * @param options - The compiler options which should be used. - * @param host - The host interacts with the underlying file system. - * @param oldProgram - Reuses an old program structure. - * @param configFileParsingDiagnostics - error during config file parsing - * @returns A 'Program' object. - */ - export function createProgram(rootNames: ReadonlyArray, options: CompilerOptions, host?: CompilerHost, oldProgram?: Program, configFileParsingDiagnostics?: ReadonlyArray): Program; - interface CompilerHostLike { - useCaseSensitiveFileNames(): boolean; - getCurrentDirectory(): string; - fileExists(fileName: string): boolean; - readFile(fileName: string): string | undefined; - readDirectory?(rootDir: string, extensions: ReadonlyArray, excludes: ReadonlyArray | undefined, includes: ReadonlyArray, depth?: number): string[]; - trace?(s: string): void; - onUnRecoverableConfigFileDiagnostic?: DiagnosticReporter; - } - export function parseConfigHostFromCompilerHostLike(host: CompilerHostLike, directoryStructureHost?: DirectoryStructureHost): ParseConfigFileHost; - /** @deprecated */ export interface ResolveProjectReferencePathHost { - fileExists(fileName: string): boolean; - } - export function createPrependNodes(projectReferences: ReadonlyArray | undefined, getCommandLine: (ref: ProjectReference, index: number) => ParsedCommandLine | undefined, readFile: (path: string) => string | undefined): InputFiles[]; - /** - * Returns the target config filename of a project reference. - * Note: The file might not exist. - */ - export function resolveProjectReferencePath(ref: ProjectReference): ResolvedConfigFileName; - /** @deprecated */ export function resolveProjectReferencePath(host: ResolveProjectReferencePathHost, ref: ProjectReference): ResolvedConfigFileName; - /** - * Returns a DiagnosticMessage if we won't include a resolved module due to its extension. - * The DiagnosticMessage's parameters are the imported module name, and the filename it resolved to. - * This returns a diagnostic even if the module will be an untyped module. - */ - export function getResolutionDiagnostic(options: CompilerOptions, { extension }: ResolvedModuleFull): DiagnosticMessage | undefined; - export {}; -} -declare namespace ts { - interface EmitOutput { - outputFiles: OutputFile[]; - emitSkipped: boolean; - exportedModulesFromDeclarationEmit?: ExportedModulesFromDeclarationEmit; - } - interface OutputFile { - name: string; - writeByteOrderMark: boolean; - text: string; - } -} -declare namespace ts { - function getFileEmitOutput(program: Program, sourceFile: SourceFile, emitOnlyDtsFiles: boolean, cancellationToken?: CancellationToken, customTransformers?: CustomTransformers): EmitOutput; - interface ReusableBuilderState { - /** - * Information of the file eg. its version, signature etc - */ - fileInfos: ReadonlyMap; - /** - * Contains the map of ReferencedSet=Referenced files of the file if module emit is enabled - * Otherwise undefined - * Thus non undefined value indicates, module emit - */ - readonly referencedMap?: ReadonlyMap | undefined; - /** - * Contains the map of exported modules ReferencedSet=exported module files from the file if module emit is enabled - * Otherwise undefined - */ - readonly exportedModulesMap?: ReadonlyMap | undefined; - } - interface BuilderState { - /** - * Information of the file eg. its version, signature etc - */ - fileInfos: Map; - /** - * Contains the map of ReferencedSet=Referenced files of the file if module emit is enabled - * Otherwise undefined - * Thus non undefined value indicates, module emit - */ - readonly referencedMap: ReadonlyMap | undefined; - /** - * Contains the map of exported modules ReferencedSet=exported module files from the file if module emit is enabled - * Otherwise undefined - */ - readonly exportedModulesMap: Map | undefined; - /** - * Map of files that have already called update signature. - * That means hence forth these files are assumed to have - * no change in their signature for this version of the program - */ - hasCalledUpdateShapeSignature: Map; - /** - * Cache of all files excluding default library file for the current program - */ - allFilesExcludingDefaultLibraryFile?: ReadonlyArray; - /** - * Cache of all the file names - */ - allFileNames?: ReadonlyArray; - } - function cloneMapOrUndefined(map: ReadonlyMap | undefined): Map | undefined; -} -declare namespace ts.BuilderState { - /** - * Information about the source file: Its version and optional signature from last emit - */ - interface FileInfo { - readonly version: string; - signature: string | undefined; - } - /** - * Referenced files with values for the keys as referenced file's path to be true - */ - type ReferencedSet = ReadonlyMap; - /** - * Compute the hash to store the shape of the file - */ - type ComputeHash = (data: string) => string; - /** - * Exported modules to from declaration emit being computed. - * This can contain false in the affected file path to specify that there are no exported module(types from other modules) for this file - */ - type ComputingExportedModulesMap = Map; - /** - * Returns true if oldState is reusable, that is the emitKind = module/non module has not changed - */ - function canReuseOldState(newReferencedMap: ReadonlyMap | undefined, oldState: Readonly | undefined): boolean | undefined; - /** - * Creates the state of file references and signature for the new program from oldState if it is safe - */ - function create(newProgram: Program, getCanonicalFileName: GetCanonicalFileName, oldState?: Readonly): BuilderState; - /** - * Releases needed properties - */ - function releaseCache(state: BuilderState): void; - /** - * Creates a clone of the state - */ - function clone(state: Readonly): BuilderState; - /** - * Gets the files affected by the path from the program - */ - function getFilesAffectedBy(state: BuilderState, programOfThisState: Program, path: Path, cancellationToken: CancellationToken | undefined, computeHash: ComputeHash, cacheToUpdateSignature?: Map, exportedModulesMapCache?: ComputingExportedModulesMap): ReadonlyArray; - /** - * Updates the signatures from the cache into state's fileinfo signatures - * This should be called whenever it is safe to commit the state of the builder - */ - function updateSignaturesFromCache(state: BuilderState, signatureCache: Map): void; - /** - * Returns if the shape of the signature has changed since last emit - */ - function updateShapeSignature(state: Readonly, programOfThisState: Program, sourceFile: SourceFile, cacheToUpdateSignature: Map, cancellationToken: CancellationToken | undefined, computeHash: ComputeHash, exportedModulesMapCache?: ComputingExportedModulesMap): boolean; - /** - * Updates the exported modules from cache into state's exported modules map - * This should be called whenever it is safe to commit the state of the builder - */ - function updateExportedFilesMapFromCache(state: BuilderState, exportedModulesMapCache: ComputingExportedModulesMap | undefined): void; - /** - * Get all the dependencies of the sourceFile - */ - function getAllDependencies(state: BuilderState, programOfThisState: Program, sourceFile: SourceFile): ReadonlyArray; -} -declare namespace ts { - interface ReusableDiagnostic extends ReusableDiagnosticRelatedInformation { - /** May store more in future. For now, this will simply be `true` to indicate when a diagnostic is an unused-identifier diagnostic. */ - reportsUnnecessary?: {}; - source?: string; - relatedInformation?: ReusableDiagnosticRelatedInformation[]; - } - interface ReusableDiagnosticRelatedInformation { - category: DiagnosticCategory; - code: number; - file: string | undefined; - start: number | undefined; - length: number | undefined; - messageText: string | ReusableDiagnosticMessageChain; - } - type ReusableDiagnosticMessageChain = DiagnosticMessageChain; - interface ReusableBuilderProgramState extends ReusableBuilderState { - /** - * Cache of semantic diagnostics for files with their Path being the key - */ - semanticDiagnosticsPerFile?: ReadonlyMap | ReadonlyArray> | undefined; - /** - * The map has key by source file's path that has been changed - */ - changedFilesSet?: ReadonlyMap; - /** - * Set of affected files being iterated - */ - affectedFiles?: ReadonlyArray | undefined; - /** - * Current changed file for iterating over affected files - */ - currentChangedFilePath?: Path | undefined; - /** - * Map of file signatures, with key being file path, calculated while getting current changed file's affected files - * These will be committed whenever the iteration through affected files of current changed file is complete - */ - currentAffectedFilesSignatures?: ReadonlyMap | undefined; - /** - * Newly computed visible to outside referencedSet - */ - currentAffectedFilesExportedModulesMap?: Readonly | undefined; - /** - * True if the semantic diagnostics were copied from the old state - */ - semanticDiagnosticsFromOldState?: Map; - /** - * program corresponding to this state - */ - program?: Program | undefined; - /** - * compilerOptions for the program - */ - compilerOptions: CompilerOptions; - /** - * Files pending to be emitted - */ - affectedFilesPendingEmit?: ReadonlyArray | undefined; - /** - * Current index to retrieve pending affected file - */ - affectedFilesPendingEmitIndex?: number | undefined; - hasReusableDiagnostic?: true; - } - /** - * State to store the changed files, affected files and cache semantic diagnostics - */ - interface BuilderProgramState extends BuilderState { - /** - * Cache of semantic diagnostics for files with their Path being the key - */ - semanticDiagnosticsPerFile: Map> | undefined; - /** - * The map has key by source file's path that has been changed - */ - changedFilesSet: Map; - /** - * Set of affected files being iterated - */ - affectedFiles: ReadonlyArray | undefined; - /** - * Current index to retrieve affected file from - */ - affectedFilesIndex: number | undefined; - /** - * Current changed file for iterating over affected files - */ - currentChangedFilePath: Path | undefined; - /** - * Map of file signatures, with key being file path, calculated while getting current changed file's affected files - * These will be committed whenever the iteration through affected files of current changed file is complete - */ - currentAffectedFilesSignatures: Map | undefined; - /** - * Newly computed visible to outside referencedSet - */ - currentAffectedFilesExportedModulesMap: BuilderState.ComputingExportedModulesMap | undefined; - /** - * Already seen affected files - */ - seenAffectedFiles: Map | undefined; - /** - * whether this program has cleaned semantic diagnostics cache for lib files - */ - cleanedDiagnosticsOfLibFiles?: boolean; - /** - * True if the semantic diagnostics were copied from the old state - */ - semanticDiagnosticsFromOldState?: Map; - /** - * program corresponding to this state - */ - program: Program | undefined; - /** - * compilerOptions for the program - */ - compilerOptions: CompilerOptions; - /** - * Files pending to be emitted - */ - affectedFilesPendingEmit: ReadonlyArray | undefined; - /** - * Current index to retrieve pending affected file - */ - affectedFilesPendingEmitIndex: number | undefined; - /** - * true if build info is emitted - */ - emittedBuildInfo?: boolean; - /** - * Already seen affected files - */ - seenEmittedFiles: Map | undefined; - /** - * true if program has been emitted - */ - programEmitComplete?: true; - } - type ProgramBuildInfoDiagnostic = string | [string, ReadonlyArray]; - interface ProgramBuildInfo { - fileInfos: MapLike; - options: CompilerOptions; - referencedMap?: MapLike; - exportedModulesMap?: MapLike; - semanticDiagnosticsPerFile?: ProgramBuildInfoDiagnostic[]; - } - enum BuilderProgramKind { - SemanticDiagnosticsBuilderProgram = 0, - EmitAndSemanticDiagnosticsBuilderProgram = 1 - } - interface BuilderCreationParameters { - newProgram: Program; - host: BuilderProgramHost; - oldProgram: BuilderProgram | undefined; - configFileParsingDiagnostics: ReadonlyArray; - } - function getBuilderCreationParameters(newProgramOrRootNames: Program | ReadonlyArray | undefined, hostOrOptions: BuilderProgramHost | CompilerOptions | undefined, oldProgramOrHost?: BuilderProgram | CompilerHost, configFileParsingDiagnosticsOrOldProgram?: ReadonlyArray | BuilderProgram, configFileParsingDiagnostics?: ReadonlyArray, projectReferences?: ReadonlyArray): BuilderCreationParameters; - function createBuilderProgram(kind: BuilderProgramKind.SemanticDiagnosticsBuilderProgram, builderCreationParameters: BuilderCreationParameters): SemanticDiagnosticsBuilderProgram; - function createBuilderProgram(kind: BuilderProgramKind.EmitAndSemanticDiagnosticsBuilderProgram, builderCreationParameters: BuilderCreationParameters): EmitAndSemanticDiagnosticsBuilderProgram; - function createBuildProgramUsingProgramBuildInfo(program: ProgramBuildInfo, buildInfoPath: string, host: ReadBuildProgramHost): EmitAndSemanticDiagnosticsBuilderProgram; - function createRedirectedBuilderProgram(state: { - program: Program | undefined; - compilerOptions: CompilerOptions; - }, configFileParsingDiagnostics: ReadonlyArray): BuilderProgram; -} -declare namespace ts { - type AffectedFileResult = { - result: T; - affected: SourceFile | Program; - } | undefined; - interface BuilderProgramHost { - /** - * return true if file names are treated with case sensitivity - */ - useCaseSensitiveFileNames(): boolean; - /** - * If provided this would be used this hash instead of actual file shape text for detecting changes - */ - createHash?: (data: string) => string; - /** - * When emit or emitNextAffectedFile are called without writeFile, - * this callback if present would be used to write files - */ - writeFile?: WriteFileCallback; - } - /** - * Builder to manage the program state changes - */ - interface BuilderProgram { - getState(): ReusableBuilderProgramState; - backupState(): void; - restoreState(): void; - /** - * Returns current program - */ - getProgram(): Program; - /** - * Returns current program that could be undefined if the program was released - */ - getProgramOrUndefined(): Program | undefined; - /** - * Releases reference to the program, making all the other operations that need program to fail. - */ - releaseProgram(): void; - /** - * Get compiler options of the program - */ - getCompilerOptions(): CompilerOptions; - /** - * Get the source file in the program with file name - */ - getSourceFile(fileName: string): SourceFile | undefined; - /** - * Get a list of files in the program - */ - getSourceFiles(): ReadonlyArray; - /** - * Get the diagnostics for compiler options - */ - getOptionsDiagnostics(cancellationToken?: CancellationToken): ReadonlyArray; - /** - * Get the diagnostics that dont belong to any file - */ - getGlobalDiagnostics(cancellationToken?: CancellationToken): ReadonlyArray; - /** - * Get the diagnostics from config file parsing - */ - getConfigFileParsingDiagnostics(): ReadonlyArray; - /** - * Get the syntax diagnostics, for all source files if source file is not supplied - */ - getSyntacticDiagnostics(sourceFile?: SourceFile, cancellationToken?: CancellationToken): ReadonlyArray; - /** - * Get the declaration diagnostics, for all source files if source file is not supplied - */ - getDeclarationDiagnostics(sourceFile?: SourceFile, cancellationToken?: CancellationToken): ReadonlyArray; - /** - * Get all the dependencies of the file - */ - getAllDependencies(sourceFile: SourceFile): ReadonlyArray; - /** - * Gets the semantic diagnostics from the program corresponding to this state of file (if provided) or whole program - * The semantic diagnostics are cached and managed here - * Note that it is assumed that when asked about semantic diagnostics through this API, - * the file has been taken out of affected files so it is safe to use cache or get from program and cache the diagnostics - * In case of SemanticDiagnosticsBuilderProgram if the source file is not provided, - * it will iterate through all the affected files, to ensure that cache stays valid and yet provide a way to get all semantic diagnostics - */ - getSemanticDiagnostics(sourceFile?: SourceFile, cancellationToken?: CancellationToken): ReadonlyArray; - /** - * Emits the JavaScript and declaration files. - * When targetSource file is specified, emits the files corresponding to that source file, - * otherwise for the whole program. - * In case of EmitAndSemanticDiagnosticsBuilderProgram, when targetSourceFile is specified, - * it is assumed that that file is handled from affected file list. If targetSourceFile is not specified, - * it will only emit all the affected files instead of whole program - * - * The first of writeFile if provided, writeFile of BuilderProgramHost if provided, writeFile of compiler host - * in that order would be used to write the files - */ - emit(targetSourceFile?: SourceFile, writeFile?: WriteFileCallback, cancellationToken?: CancellationToken, emitOnlyDtsFiles?: boolean, customTransformers?: CustomTransformers): EmitResult; - /** - * Get the current directory of the program - */ - getCurrentDirectory(): string; - } - /** - * The builder that caches the semantic diagnostics for the program and handles the changed files and affected files - */ - interface SemanticDiagnosticsBuilderProgram extends BuilderProgram { - /** - * Gets the semantic diagnostics from the program for the next affected file and caches it - * Returns undefined if the iteration is complete - */ - getSemanticDiagnosticsOfNextAffectedFile(cancellationToken?: CancellationToken, ignoreSourceFile?: (sourceFile: SourceFile) => boolean): AffectedFileResult>; - } - /** - * The builder that can handle the changes in program and iterate through changed file to emit the files - * The semantic diagnostics are cached per file and managed by clearing for the changed/affected files - */ - interface EmitAndSemanticDiagnosticsBuilderProgram extends SemanticDiagnosticsBuilderProgram { - /** - * Emits the next affected file's emit result (EmitResult and sourceFiles emitted) or returns undefined if iteration is complete - * The first of writeFile if provided, writeFile of BuilderProgramHost if provided, writeFile of compiler host - * in that order would be used to write the files - */ - emitNextAffectedFile(writeFile?: WriteFileCallback, cancellationToken?: CancellationToken, emitOnlyDtsFiles?: boolean, customTransformers?: CustomTransformers): AffectedFileResult; - } - /** - * Create the builder to manage semantic diagnostics and cache them - */ - function createSemanticDiagnosticsBuilderProgram(newProgram: Program, host: BuilderProgramHost, oldProgram?: SemanticDiagnosticsBuilderProgram, configFileParsingDiagnostics?: ReadonlyArray): SemanticDiagnosticsBuilderProgram; - function createSemanticDiagnosticsBuilderProgram(rootNames: ReadonlyArray | undefined, options: CompilerOptions | undefined, host?: CompilerHost, oldProgram?: SemanticDiagnosticsBuilderProgram, configFileParsingDiagnostics?: ReadonlyArray, projectReferences?: ReadonlyArray): SemanticDiagnosticsBuilderProgram; - /** - * Create the builder that can handle the changes in program and iterate through changed files - * to emit the those files and manage semantic diagnostics cache as well - */ - function createEmitAndSemanticDiagnosticsBuilderProgram(newProgram: Program, host: BuilderProgramHost, oldProgram?: EmitAndSemanticDiagnosticsBuilderProgram, configFileParsingDiagnostics?: ReadonlyArray): EmitAndSemanticDiagnosticsBuilderProgram; - function createEmitAndSemanticDiagnosticsBuilderProgram(rootNames: ReadonlyArray | undefined, options: CompilerOptions | undefined, host?: CompilerHost, oldProgram?: EmitAndSemanticDiagnosticsBuilderProgram, configFileParsingDiagnostics?: ReadonlyArray, projectReferences?: ReadonlyArray): EmitAndSemanticDiagnosticsBuilderProgram; - /** - * Creates a builder thats just abstraction over program and can be used with watch - */ - function createAbstractBuilder(newProgram: Program, host: BuilderProgramHost, oldProgram?: BuilderProgram, configFileParsingDiagnostics?: ReadonlyArray): BuilderProgram; - function createAbstractBuilder(rootNames: ReadonlyArray | undefined, options: CompilerOptions | undefined, host?: CompilerHost, oldProgram?: BuilderProgram, configFileParsingDiagnostics?: ReadonlyArray, projectReferences?: ReadonlyArray): BuilderProgram; -} -declare namespace ts { - /** This is the cache of module/typedirectives resolution that can be retained across program */ - export interface ResolutionCache { - startRecordingFilesWithChangedResolutions(): void; - finishRecordingFilesWithChangedResolutions(): Path[] | undefined; - resolveModuleNames(moduleNames: string[], containingFile: string, reusedNames: string[] | undefined, redirectedReference?: ResolvedProjectReference): (ResolvedModuleFull | undefined)[]; - getResolvedModuleWithFailedLookupLocationsFromCache(moduleName: string, containingFile: string): CachedResolvedModuleWithFailedLookupLocations | undefined; - resolveTypeReferenceDirectives(typeDirectiveNames: string[], containingFile: string, redirectedReference?: ResolvedProjectReference): (ResolvedTypeReferenceDirective | undefined)[]; - invalidateResolutionOfFile(filePath: Path): void; - removeResolutionsOfFile(filePath: Path): void; - removeResolutionsFromProjectReferenceRedirects(filePath: Path): void; - setFilesWithInvalidatedNonRelativeUnresolvedImports(filesWithUnresolvedImports: Map>): void; - createHasInvalidatedResolution(forceAllFilesAsInvalidated?: boolean): HasInvalidatedResolution; - startCachingPerDirectoryResolution(): void; - finishCachingPerDirectoryResolution(): void; - updateTypeRootsWatch(): void; - closeTypeRootsWatch(): void; - clear(): void; - } - interface ResolutionWithFailedLookupLocations { - readonly failedLookupLocations: ReadonlyArray; - isInvalidated?: boolean; - refCount?: number; - } - interface CachedResolvedModuleWithFailedLookupLocations extends ResolvedModuleWithFailedLookupLocations, ResolutionWithFailedLookupLocations { - } - export interface ResolutionCacheHost extends ModuleResolutionHost { - toPath(fileName: string): Path; - getCanonicalFileName: GetCanonicalFileName; - getCompilationSettings(): CompilerOptions; - watchDirectoryOfFailedLookupLocation(directory: string, cb: DirectoryWatcherCallback, flags: WatchDirectoryFlags): FileWatcher; - onInvalidatedResolution(): void; - watchTypeRootsDirectory(directory: string, cb: DirectoryWatcherCallback, flags: WatchDirectoryFlags): FileWatcher; - onChangedAutomaticTypeDirectiveNames(): void; - getCachedDirectoryStructureHost(): CachedDirectoryStructureHost | undefined; - projectName?: string; - getGlobalCache?(): string | undefined; - globalCacheResolutionModuleName?(externalModuleName: string): string; - writeLog(s: string): void; - maxNumberOfFilesToIterateForInvalidation?: number; - getCurrentProgram(): Program | undefined; - fileIsOpen(filePath: Path): boolean; - } - export function isPathIgnored(path: Path): boolean; - /** - * Filter out paths like - * "/", "/user", "/user/username", "/user/username/folderAtRoot", - * "c:/", "c:/users", "c:/users/username", "c:/users/username/folderAtRoot", "c:/folderAtRoot" - * @param dirPath - */ - export function canWatchDirectory(dirPath: Path): boolean; - export const maxNumberOfFilesToIterateForInvalidation = 256; - export function createResolutionCache(resolutionHost: ResolutionCacheHost, rootDirForResolution: string | undefined, logChangesWhenResolvingModule: boolean): ResolutionCache; - export {}; -} -declare namespace ts.moduleSpecifiers { - function updateModuleSpecifier(compilerOptions: CompilerOptions, importingSourceFileName: Path, toFileName: string, host: ModuleSpecifierResolutionHost, files: ReadonlyArray, redirectTargetsMap: RedirectTargetsMap, oldImportSpecifier: string): string | undefined; - function getModuleSpecifier(compilerOptions: CompilerOptions, importingSourceFile: SourceFile, importingSourceFileName: Path, toFileName: string, host: ModuleSpecifierResolutionHost, files: ReadonlyArray, preferences: UserPreferences | undefined, redirectTargetsMap: RedirectTargetsMap): string; - function getModuleSpecifiers(moduleSymbol: Symbol, compilerOptions: CompilerOptions, importingSourceFile: SourceFile, host: ModuleSpecifierResolutionHost, files: ReadonlyArray, userPreferences: UserPreferences, redirectTargetsMap: RedirectTargetsMap): ReadonlyArray; - function countPathComponents(path: string): number; -} -declare namespace ts { - /** - * Create a function that reports error by writing to the system and handles the formating of the diagnostic - */ - export function createDiagnosticReporter(system: System, pretty?: boolean): DiagnosticReporter; - export const screenStartingMessageCodes: number[]; - /** - * Create a function that reports watch status by writing to the system and handles the formating of the diagnostic - */ - export function createWatchStatusReporter(system: System, pretty?: boolean): WatchStatusReporter; - /** Parses config file using System interface */ - export function parseConfigFileWithSystem(configFileName: string, optionsToExtend: CompilerOptions, system: System, reportDiagnostic: DiagnosticReporter): ParsedCommandLine | undefined; - export function getErrorCountForSummary(diagnostics: ReadonlyArray): number; - export function getWatchErrorSummaryDiagnosticMessage(errorCount: number): DiagnosticMessage; - export function getErrorSummaryText(errorCount: number, newLine: string): string; - /** - * Program structure needed to emit the files and report diagnostics - */ - export interface ProgramToEmitFilesAndReportErrors { - getCurrentDirectory(): string; - getCompilerOptions(): CompilerOptions; - getSourceFiles(): ReadonlyArray; - getSyntacticDiagnostics(sourceFile?: SourceFile, cancellationToken?: CancellationToken): ReadonlyArray; - getOptionsDiagnostics(cancellationToken?: CancellationToken): ReadonlyArray; - getGlobalDiagnostics(cancellationToken?: CancellationToken): ReadonlyArray; - getSemanticDiagnostics(sourceFile?: SourceFile, cancellationToken?: CancellationToken): ReadonlyArray; - getConfigFileParsingDiagnostics(): ReadonlyArray; - emit(targetSourceFile?: SourceFile, writeFile?: WriteFileCallback, cancellationToken?: CancellationToken, emitOnlyDtsFiles?: boolean, customTransformers?: CustomTransformers): EmitResult; - } - export function listFiles(program: ProgramToEmitFilesAndReportErrors, writeFileName: (s: string) => void): void; - /** - * Helper that emit files, report diagnostics and lists emitted and/or source files depending on compiler options - */ - export function emitFilesAndReportErrors(program: ProgramToEmitFilesAndReportErrors, reportDiagnostic: DiagnosticReporter, writeFileName?: (s: string) => void, reportSummary?: ReportEmitErrorSummary, writeFile?: WriteFileCallback, cancellationToken?: CancellationToken, emitOnlyDtsFiles?: boolean, customTransformers?: CustomTransformers): { - emitResult: EmitResult; - diagnostics: Diagnostic[]; - }; - export function emitFilesAndReportErrorsAndGetExitStatus(program: ProgramToEmitFilesAndReportErrors, reportDiagnostic: DiagnosticReporter, writeFileName?: (s: string) => void, reportSummary?: ReportEmitErrorSummary, writeFile?: WriteFileCallback, cancellationToken?: CancellationToken, emitOnlyDtsFiles?: boolean, customTransformers?: CustomTransformers): ExitStatus.Success | ExitStatus.DiagnosticsPresent_OutputsSkipped | ExitStatus.DiagnosticsPresent_OutputsGenerated; - export const noopFileWatcher: FileWatcher; - export function createWatchHost(system?: System, reportWatchStatus?: WatchStatusReporter): WatchHost; - export enum WatchType { - ConfigFile = "Config file", - SourceFile = "Source file", - MissingFile = "Missing file", - WildcardDirectory = "Wild card directory", - FailedLookupLocations = "Failed Lookup Locations", - TypeRoots = "Type roots" - } - interface WatchFactory extends ts.WatchFactory { - writeLog: (s: string) => void; - } - export function createWatchFactory(host: { - trace?(s: string): void; - }, options: { - extendedDiagnostics?: boolean; - diagnostics?: boolean; - }): WatchFactory; - export function createCompilerHostFromProgramHost(host: ProgramHost, getCompilerOptions: () => CompilerOptions, directoryStructureHost?: DirectoryStructureHost): CompilerHost; - export function setGetSourceFileAsHashVersioned(compilerHost: CompilerHost, host: { - createHash?(data: string): string; - }): void; - /** - * Creates the watch compiler host that can be extended with config file or root file names and options host - */ - export function createProgramHost(system: System, createProgram: CreateProgram | undefined): ProgramHost; - /** - * Creates the watch compiler host from system for config file in watch mode - */ - export function createWatchCompilerHostOfConfigFile(configFileName: string, optionsToExtend: CompilerOptions | undefined, system: System, createProgram?: CreateProgram, reportDiagnostic?: DiagnosticReporter, reportWatchStatus?: WatchStatusReporter): WatchCompilerHostOfConfigFile; - /** - * Creates the watch compiler host from system for compiling root files and options in watch mode - */ - export function createWatchCompilerHostOfFilesAndCompilerOptions(rootFiles: string[], options: CompilerOptions, system: System, createProgram?: CreateProgram, reportDiagnostic?: DiagnosticReporter, reportWatchStatus?: WatchStatusReporter, projectReferences?: ReadonlyArray): WatchCompilerHostOfFilesAndCompilerOptions; - export interface IncrementalCompilationOptions { - rootNames: ReadonlyArray; - options: CompilerOptions; - configFileParsingDiagnostics?: ReadonlyArray; - projectReferences?: ReadonlyArray; - host?: CompilerHost; - reportDiagnostic?: DiagnosticReporter; - reportErrorSummary?: ReportEmitErrorSummary; - afterProgramEmitAndDiagnostics?(program: EmitAndSemanticDiagnosticsBuilderProgram): void; - system?: System; - } - export function performIncrementalCompilation(input: IncrementalCompilationOptions): ExitStatus.Success | ExitStatus.DiagnosticsPresent_OutputsSkipped | ExitStatus.DiagnosticsPresent_OutputsGenerated; - export {}; -} -declare namespace ts { - interface ReadBuildProgramHost { - useCaseSensitiveFileNames(): boolean; - getCurrentDirectory(): string; - readFile(fileName: string): string | undefined; - } - function readBuilderProgram(compilerOptions: CompilerOptions, host: ReadBuildProgramHost): EmitAndSemanticDiagnosticsBuilderProgram | undefined; - function createIncrementalCompilerHost(options: CompilerOptions, system?: System): CompilerHost; - interface IncrementalProgramOptions { - rootNames: ReadonlyArray; - options: CompilerOptions; - configFileParsingDiagnostics?: ReadonlyArray; - projectReferences?: ReadonlyArray; - host?: CompilerHost; - createProgram?: CreateProgram; - } - function createIncrementalProgram({ rootNames, options, configFileParsingDiagnostics, projectReferences, host, createProgram }: IncrementalProgramOptions): T; - type WatchStatusReporter = (diagnostic: Diagnostic, newLine: string, options: CompilerOptions) => void; - /** Create the program with rootNames and options, if they are undefined, oldProgram and new configFile diagnostics create new program */ - type CreateProgram = (rootNames: ReadonlyArray | undefined, options: CompilerOptions | undefined, host?: CompilerHost, oldProgram?: T, configFileParsingDiagnostics?: ReadonlyArray, projectReferences?: ReadonlyArray | undefined) => T; - /** Host that has watch functionality used in --watch mode */ - interface WatchHost { - /** If provided, called with Diagnostic message that informs about change in watch status */ - onWatchStatusChange?(diagnostic: Diagnostic, newLine: string, options: CompilerOptions): void; - /** Used to watch changes in source files, missing files needed to update the program or config file */ - watchFile(path: string, callback: FileWatcherCallback, pollingInterval?: number): FileWatcher; - /** Used to watch resolved module's failed lookup locations, config file specs, type roots where auto type reference directives are added */ - watchDirectory(path: string, callback: DirectoryWatcherCallback, recursive?: boolean): FileWatcher; - /** If provided, will be used to set delayed compilation, so that multiple changes in short span are compiled together */ - setTimeout?(callback: (...args: any[]) => void, ms: number, ...args: any[]): any; - /** If provided, will be used to reset existing delayed compilation */ - clearTimeout?(timeoutId: any): void; - } - interface ProgramHost { - /** - * Used to create the program when need for program creation or recreation detected - */ - createProgram: CreateProgram; - useCaseSensitiveFileNames(): boolean; - getNewLine(): string; - getCurrentDirectory(): string; - getDefaultLibFileName(options: CompilerOptions): string; - getDefaultLibLocation?(): string; - createHash?(data: string): string; - /** - * Use to check file presence for source files and - * if resolveModuleNames is not provided (complier is in charge of module resolution) then module files as well - */ - fileExists(path: string): boolean; - /** - * Use to read file text for source files and - * if resolveModuleNames is not provided (complier is in charge of module resolution) then module files as well - */ - readFile(path: string, encoding?: string): string | undefined; - /** If provided, used for module resolution as well as to handle directory structure */ - directoryExists?(path: string): boolean; - /** If provided, used in resolutions as well as handling directory structure */ - getDirectories?(path: string): string[]; - /** If provided, used to cache and handle directory structure modifications */ - readDirectory?(path: string, extensions?: ReadonlyArray, exclude?: ReadonlyArray, include?: ReadonlyArray, depth?: number): string[]; - /** Symbol links resolution */ - realpath?(path: string): string; - /** If provided would be used to write log about compilation */ - trace?(s: string): void; - /** If provided is used to get the environment variable */ - getEnvironmentVariable?(name: string): string | undefined; - /** If provided, used to resolve the module names, otherwise typescript's default module resolution */ - resolveModuleNames?(moduleNames: string[], containingFile: string, reusedNames: string[] | undefined, redirectedReference: ResolvedProjectReference | undefined, options: CompilerOptions): (ResolvedModule | undefined)[]; - /** If provided, used to resolve type reference directives, otherwise typescript's default resolution */ - resolveTypeReferenceDirectives?(typeReferenceDirectiveNames: string[], containingFile: string, redirectedReference: ResolvedProjectReference | undefined, options: CompilerOptions): (ResolvedTypeReferenceDirective | undefined)[]; - } - /** Internal interface used to wire emit through same host */ - interface ProgramHost { - createDirectory?(path: string): void; - writeFile?(path: string, data: string, writeByteOrderMark?: boolean): void; - onCachedDirectoryStructureHostCreate?(host: CachedDirectoryStructureHost): void; - } - interface WatchCompilerHost extends ProgramHost, WatchHost { - /** If provided, callback to invoke after every new program creation */ - afterProgramCreate?(program: T): void; - maxNumberOfFilesToIterateForInvalidation?: number; - } - /** - * Host to create watch with root files and options - */ - interface WatchCompilerHostOfFilesAndCompilerOptions extends WatchCompilerHost { - /** root files to use to generate program */ - rootFiles: string[]; - /** Compiler options */ - options: CompilerOptions; - /** Project References */ - projectReferences?: ReadonlyArray; - } - /** - * Host to create watch with config file - */ - interface WatchCompilerHostOfConfigFile extends WatchCompilerHost, ConfigFileDiagnosticsReporter { - /** Name of the config file to compile */ - configFileName: string; - /** Options to extend */ - optionsToExtend?: CompilerOptions; - /** - * Used to generate source file names from the config file and its include, exclude, files rules - * and also to cache the directory stucture - */ - readDirectory(path: string, extensions?: ReadonlyArray, exclude?: ReadonlyArray, include?: ReadonlyArray, depth?: number): string[]; - } - /** - * Host to create watch with config file that is already parsed (from tsc) - */ - interface WatchCompilerHostOfConfigFile extends WatchCompilerHost { - optionsToExtend?: CompilerOptions; - configFileParsingResult?: ParsedCommandLine; - } - interface Watch { - /** Synchronize with host and get updated program */ - getProgram(): T; - /** Gets the existing program without synchronizing with changes on host */ - getCurrentProgram(): T; - /** Closes the watch */ - close(): void; - } - /** - * Creates the watch what generates program using the config file - */ - interface WatchOfConfigFile extends Watch { - } - /** - * Creates the watch that generates program using the root files and compiler options - */ - interface WatchOfFilesAndCompilerOptions extends Watch { - /** Updates the root files in the program, only if this is not config file compilation */ - updateRootFileNames(fileNames: string[]): void; - } - /** - * Create the watch compiler host for either configFile or fileNames and its options - */ - function createWatchCompilerHost(configFileName: string, optionsToExtend: CompilerOptions | undefined, system: System, createProgram?: CreateProgram, reportDiagnostic?: DiagnosticReporter, reportWatchStatus?: WatchStatusReporter): WatchCompilerHostOfConfigFile; - function createWatchCompilerHost(rootFiles: string[], options: CompilerOptions, system: System, createProgram?: CreateProgram, reportDiagnostic?: DiagnosticReporter, reportWatchStatus?: WatchStatusReporter, projectReferences?: ReadonlyArray): WatchCompilerHostOfFilesAndCompilerOptions; - /** - * Creates the watch from the host for root files and compiler options - */ - function createWatchProgram(host: WatchCompilerHostOfFilesAndCompilerOptions): WatchOfFilesAndCompilerOptions; - /** - * Creates the watch from the host for config file - */ - function createWatchProgram(host: WatchCompilerHostOfConfigFile): WatchOfConfigFile; -} -declare namespace ts { - enum UpToDateStatusType { - Unbuildable = 0, - UpToDate = 1, - /** - * The project appears out of date because its upstream inputs are newer than its outputs, - * but all of its outputs are actually newer than the previous identical outputs of its (.d.ts) inputs. - * This means we can Pseudo-build (just touch timestamps), as if we had actually built this project. - */ - UpToDateWithUpstreamTypes = 2, - /** - * The project appears out of date because its upstream inputs are newer than its outputs, - * but all of its outputs are actually newer than the previous identical outputs of its (.d.ts) inputs. - * This means we can Pseudo-build (just manipulate outputs), as if we had actually built this project. - */ - OutOfDateWithPrepend = 3, - OutputMissing = 4, - OutOfDateWithSelf = 5, - OutOfDateWithUpstream = 6, - UpstreamOutOfDate = 7, - UpstreamBlocked = 8, - ComputingUpstream = 9, - TsVersionOutputOfDate = 10, - /** - * Projects with no outputs (i.e. "solution" files) - */ - ContainerOnly = 11 - } - type UpToDateStatus = Status.Unbuildable | Status.UpToDate | Status.OutOfDateWithPrepend | Status.OutputMissing | Status.OutOfDateWithSelf | Status.OutOfDateWithUpstream | Status.UpstreamOutOfDate | Status.UpstreamBlocked | Status.ComputingUpstream | Status.TsVersionOutOfDate | Status.ContainerOnly; - namespace Status { - /** - * The project can't be built at all in its current state. For example, - * its config file cannot be parsed, or it has a syntax error or missing file - */ - interface Unbuildable { - type: UpToDateStatusType.Unbuildable; - reason: string; - } - /** - * This project doesn't have any outputs, so "is it up to date" is a meaningless question. - */ - interface ContainerOnly { - type: UpToDateStatusType.ContainerOnly; - } - /** - * The project is up to date with respect to its inputs. - * We track what the newest input file is. - */ - interface UpToDate { - type: UpToDateStatusType.UpToDate | UpToDateStatusType.UpToDateWithUpstreamTypes; - newestInputFileTime?: Date; - newestInputFileName?: string; - newestDeclarationFileContentChangedTime?: Date; - newestOutputFileTime?: Date; - newestOutputFileName?: string; - oldestOutputFileName: string; - } - /** - * The project is up to date with respect to its inputs except for prepend output changed (no declaration file change in prepend). - */ - interface OutOfDateWithPrepend { - type: UpToDateStatusType.OutOfDateWithPrepend; - outOfDateOutputFileName: string; - newerProjectName: string; - } - /** - * One or more of the outputs of the project does not exist. - */ - interface OutputMissing { - type: UpToDateStatusType.OutputMissing; - /** - * The name of the first output file that didn't exist - */ - missingOutputFileName: string; - } - /** - * One or more of the project's outputs is older than its newest input. - */ - interface OutOfDateWithSelf { - type: UpToDateStatusType.OutOfDateWithSelf; - outOfDateOutputFileName: string; - newerInputFileName: string; - } - /** - * This project depends on an out-of-date project, so shouldn't be built yet - */ - interface UpstreamOutOfDate { - type: UpToDateStatusType.UpstreamOutOfDate; - upstreamProjectName: string; - } - /** - * This project depends an upstream project with build errors - */ - interface UpstreamBlocked { - type: UpToDateStatusType.UpstreamBlocked; - upstreamProjectName: string; - upstreamProjectBlocked: boolean; - } - /** - * Computing status of upstream projects referenced - */ - interface ComputingUpstream { - type: UpToDateStatusType.ComputingUpstream; - } - interface TsVersionOutOfDate { - type: UpToDateStatusType.TsVersionOutputOfDate; - version: string; - } - /** - * One or more of the project's outputs is older than the newest output of - * an upstream project. - */ - interface OutOfDateWithUpstream { - type: UpToDateStatusType.OutOfDateWithUpstream; - outOfDateOutputFileName: string; - newerProjectName: string; - } - } - function resolveConfigFileProjectName(project: string): ResolvedConfigFileName; -} -declare namespace ts { - interface BuildOptions { - dry?: boolean; - force?: boolean; - verbose?: boolean; - clean?: boolean; - watch?: boolean; - help?: boolean; - preserveWatchOutput?: boolean; - listEmittedFiles?: boolean; - listFiles?: boolean; - pretty?: boolean; - incremental?: boolean; - traceResolution?: boolean; - diagnostics?: boolean; - extendedDiagnostics?: boolean; - locale?: string; - [option: string]: CompilerOptionsValue | undefined; - } - type ResolvedConfigFilePath = ResolvedConfigFileName & Path; - type ReportEmitErrorSummary = (errorCount: number) => void; - interface SolutionBuilderHostBase extends ProgramHost { - createDirectory?(path: string): void; - /** - * Should provide create directory and writeFile if done of invalidatedProjects is not invoked with - * writeFileCallback - */ - writeFile?(path: string, data: string, writeByteOrderMark?: boolean): void; - getModifiedTime(fileName: string): Date | undefined; - setModifiedTime(fileName: string, date: Date): void; - deleteFile(fileName: string): void; - getParsedCommandLine?(fileName: string): ParsedCommandLine | undefined; - reportDiagnostic: DiagnosticReporter; - reportSolutionBuilderStatus: DiagnosticReporter; - afterProgramEmitAndDiagnostics?(program: T): void; - now?(): Date; - } - interface SolutionBuilderHost extends SolutionBuilderHostBase { - reportErrorSummary?: ReportEmitErrorSummary; - } - interface SolutionBuilderWithWatchHost extends SolutionBuilderHostBase, WatchHost { - } - type BuildOrder = readonly ResolvedConfigFileName[]; - interface CircularBuildOrder { - buildOrder: BuildOrder; - circularDiagnostics: readonly Diagnostic[]; - } - type AnyBuildOrder = BuildOrder | CircularBuildOrder; - function isCircularBuildOrder(buildOrder: AnyBuildOrder): buildOrder is CircularBuildOrder; - function getBuildOrderFromAnyBuildOrder(anyBuildOrder: AnyBuildOrder): BuildOrder; - interface SolutionBuilder { - build(project?: string, cancellationToken?: CancellationToken): ExitStatus; - clean(project?: string): ExitStatus; - buildReferences(project: string, cancellationToken?: CancellationToken): ExitStatus; - cleanReferences(project?: string): ExitStatus; - getNextInvalidatedProject(cancellationToken?: CancellationToken): InvalidatedProject | undefined; - getBuildOrder(): AnyBuildOrder; - getUpToDateStatusOfProject(project: string): UpToDateStatus; - invalidateProject(configFilePath: ResolvedConfigFilePath, reloadLevel?: ConfigFileProgramReloadLevel): void; - buildNextInvalidatedProject(): void; - } - /** - * Create a function that reports watch status by writing to the system and handles the formating of the diagnostic - */ - function createBuilderStatusReporter(system: System, pretty?: boolean): DiagnosticReporter; - function createSolutionBuilderHost(system?: System, createProgram?: CreateProgram, reportDiagnostic?: DiagnosticReporter, reportSolutionBuilderStatus?: DiagnosticReporter, reportErrorSummary?: ReportEmitErrorSummary): SolutionBuilderHost; - function createSolutionBuilderWithWatchHost(system?: System, createProgram?: CreateProgram, reportDiagnostic?: DiagnosticReporter, reportSolutionBuilderStatus?: DiagnosticReporter, reportWatchStatus?: WatchStatusReporter): SolutionBuilderWithWatchHost; - function createSolutionBuilder(host: SolutionBuilderHost, rootNames: ReadonlyArray, defaultOptions: BuildOptions): SolutionBuilder; - function createSolutionBuilderWithWatch(host: SolutionBuilderWithWatchHost, rootNames: ReadonlyArray, defaultOptions: BuildOptions): SolutionBuilder; - enum InvalidatedProjectKind { - Build = 0, - UpdateBundle = 1, - UpdateOutputFileStamps = 2 - } - interface InvalidatedProjectBase { - readonly kind: InvalidatedProjectKind; - readonly project: ResolvedConfigFileName; - readonly projectPath: ResolvedConfigFilePath; - readonly buildOrder: readonly ResolvedConfigFileName[]; - /** - * To dispose this project and ensure that all the necessary actions are taken and state is updated accordingly - */ - done(cancellationToken?: CancellationToken, writeFile?: WriteFileCallback, customTransformers?: CustomTransformers): ExitStatus; - getCompilerOptions(): CompilerOptions; - getCurrentDirectory(): string; - } - interface UpdateOutputFileStampsProject extends InvalidatedProjectBase { - readonly kind: InvalidatedProjectKind.UpdateOutputFileStamps; - updateOutputFileStatmps(): void; - } - interface BuildInvalidedProject extends InvalidatedProjectBase { - readonly kind: InvalidatedProjectKind.Build; - getBuilderProgram(): T | undefined; - getProgram(): Program | undefined; - getSourceFile(fileName: string): SourceFile | undefined; - getSourceFiles(): ReadonlyArray; - getOptionsDiagnostics(cancellationToken?: CancellationToken): ReadonlyArray; - getGlobalDiagnostics(cancellationToken?: CancellationToken): ReadonlyArray; - getConfigFileParsingDiagnostics(): ReadonlyArray; - getSyntacticDiagnostics(sourceFile?: SourceFile, cancellationToken?: CancellationToken): ReadonlyArray; - getAllDependencies(sourceFile: SourceFile): ReadonlyArray; - getSemanticDiagnostics(sourceFile?: SourceFile, cancellationToken?: CancellationToken): ReadonlyArray; - getSemanticDiagnosticsOfNextAffectedFile(cancellationToken?: CancellationToken, ignoreSourceFile?: (sourceFile: SourceFile) => boolean): AffectedFileResult>; - emit(targetSourceFile?: SourceFile, writeFile?: WriteFileCallback, cancellationToken?: CancellationToken, emitOnlyDtsFiles?: boolean, customTransformers?: CustomTransformers): EmitResult | undefined; - } - interface UpdateBundleProject extends InvalidatedProjectBase { - readonly kind: InvalidatedProjectKind.UpdateBundle; - emit(writeFile?: WriteFileCallback, customTransformers?: CustomTransformers): EmitResult | BuildInvalidedProject | undefined; - } - type InvalidatedProject = UpdateOutputFileStampsProject | BuildInvalidedProject | UpdateBundleProject; -} -declare namespace ts.server { - const ActionSet: ActionSet; - const ActionInvalidate: ActionInvalidate; - const ActionPackageInstalled: ActionPackageInstalled; - const EventTypesRegistry: EventTypesRegistry; - const EventBeginInstallTypes: EventBeginInstallTypes; - const EventEndInstallTypes: EventEndInstallTypes; - const EventInitializationFailed: EventInitializationFailed; - namespace Arguments { - const GlobalCacheLocation = "--globalTypingsCacheLocation"; - const LogFile = "--logFile"; - const EnableTelemetry = "--enableTelemetry"; - const TypingSafeListLocation = "--typingSafeListLocation"; - const TypesMapLocation = "--typesMapLocation"; - /** - * This argument specifies the location of the NPM executable. - * typingsInstaller will run the command with `${npmLocation} install ...`. - */ - const NpmLocation = "--npmLocation"; - /** - * Flag indicating that the typings installer should try to validate the default npm location. - * If the default npm is not found when this flag is enabled, fallback to `npm install` - */ - const ValidateDefaultNpmLocation = "--validateDefaultNpmLocation"; - } - function hasArgument(argumentName: string): boolean; - function findArgument(argumentName: string): string | undefined; - function nowString(): string; -} -declare namespace ts.server { - type ActionSet = "action::set"; - type ActionInvalidate = "action::invalidate"; - type ActionPackageInstalled = "action::packageInstalled"; - type EventTypesRegistry = "event::typesRegistry"; - type EventBeginInstallTypes = "event::beginInstallTypes"; - type EventEndInstallTypes = "event::endInstallTypes"; - type EventInitializationFailed = "event::initializationFailed"; - interface TypingInstallerResponse { - readonly kind: ActionSet | ActionInvalidate | EventTypesRegistry | ActionPackageInstalled | EventBeginInstallTypes | EventEndInstallTypes | EventInitializationFailed; - } - interface TypingInstallerRequestWithProjectName { - readonly projectName: string; - } - type TypingInstallerRequestUnion = DiscoverTypings | CloseProject | TypesRegistryRequest | InstallPackageRequest; - interface DiscoverTypings extends TypingInstallerRequestWithProjectName { - readonly fileNames: string[]; - readonly projectRootPath: Path; - readonly compilerOptions: CompilerOptions; - readonly typeAcquisition: TypeAcquisition; - readonly unresolvedImports: SortedReadonlyArray; - readonly cachePath?: string; - readonly kind: "discover"; - } - interface CloseProject extends TypingInstallerRequestWithProjectName { - readonly kind: "closeProject"; - } - interface TypesRegistryRequest { - readonly kind: "typesRegistry"; - } - interface InstallPackageRequest extends TypingInstallerRequestWithProjectName { - readonly kind: "installPackage"; - readonly fileName: Path; - readonly packageName: string; - readonly projectRootPath: Path; - } - interface TypesRegistryResponse extends TypingInstallerResponse { - readonly kind: EventTypesRegistry; - readonly typesRegistry: MapLike>; - } - interface PackageInstalledResponse extends ProjectResponse { - readonly kind: ActionPackageInstalled; - readonly success: boolean; - readonly message: string; - } - interface InitializationFailedResponse extends TypingInstallerResponse { - readonly kind: EventInitializationFailed; - readonly message: string; - } - interface ProjectResponse extends TypingInstallerResponse { - readonly projectName: string; - } - interface InvalidateCachedTypings extends ProjectResponse { - readonly kind: ActionInvalidate; - } - interface InstallTypes extends ProjectResponse { - readonly kind: EventBeginInstallTypes | EventEndInstallTypes; - readonly eventId: number; - readonly typingsInstallerVersion: string; - readonly packagesToInstall: ReadonlyArray; - } - interface BeginInstallTypes extends InstallTypes { - readonly kind: EventBeginInstallTypes; - } - interface EndInstallTypes extends InstallTypes { - readonly kind: EventEndInstallTypes; - readonly installSuccess: boolean; - } - interface InstallTypingHost extends JsTyping.TypingResolutionHost { - useCaseSensitiveFileNames: boolean; - writeFile(path: string, content: string): void; - createDirectory(path: string): void; - watchFile?(path: string, callback: FileWatcherCallback, pollingInterval?: number): FileWatcher; - watchDirectory?(path: string, callback: DirectoryWatcherCallback, recursive?: boolean): FileWatcher; - } - interface SetTypings extends ProjectResponse { - readonly typeAcquisition: TypeAcquisition; - readonly compilerOptions: CompilerOptions; - readonly typings: string[]; - readonly unresolvedImports: SortedReadonlyArray; - readonly kind: ActionSet; - } - type TypingInstallerResponseUnion = SetTypings | InvalidateCachedTypings | TypesRegistryResponse | PackageInstalledResponse | InstallTypes | InitializationFailedResponse; -} -declare namespace ts.JsTyping { - interface TypingResolutionHost { - directoryExists(path: string): boolean; - fileExists(fileName: string): boolean; - readFile(path: string, encoding?: string): string | undefined; - readDirectory(rootDir: string, extensions: ReadonlyArray, excludes: ReadonlyArray | undefined, includes: ReadonlyArray | undefined, depth?: number): string[]; - } - interface CachedTyping { - typingLocation: string; - version: Version; - } - function isTypingUpToDate(cachedTyping: CachedTyping, availableTypingVersions: MapLike): boolean; - const nodeCoreModuleList: ReadonlyArray; - const nodeCoreModules: Map; - function nonRelativeModuleNameForTypingCache(moduleName: string): string; - /** - * A map of loose file names to library names that we are confident require typings - */ - type SafeList = ReadonlyMap; - function loadSafeList(host: TypingResolutionHost, safeListPath: Path): SafeList; - function loadTypesMap(host: TypingResolutionHost, typesMapPath: Path): SafeList | undefined; - /** - * @param host is the object providing I/O related operations. - * @param fileNames are the file names that belong to the same project - * @param projectRootPath is the path to the project root directory - * @param safeListPath is the path used to retrieve the safe list - * @param packageNameToTypingLocation is the map of package names to their cached typing locations and installed versions - * @param typeAcquisition is used to customize the typing acquisition process - * @param compilerOptions are used as a source for typing inference - */ - function discoverTypings(host: TypingResolutionHost, log: ((message: string) => void) | undefined, fileNames: string[], projectRootPath: Path, safeList: SafeList, packageNameToTypingLocation: ReadonlyMap, typeAcquisition: TypeAcquisition, unresolvedImports: ReadonlyArray, typesRegistry: ReadonlyMap>): { - cachedTypingPaths: string[]; - newTypingNames: string[]; - filesToWatch: string[]; - }; - enum NameValidationResult { - Ok = 0, - EmptyName = 1, - NameTooLong = 2, - NameStartsWithDot = 3, - NameStartsWithUnderscore = 4, - NameContainsNonURISafeCharacters = 5 - } - interface ScopedPackageNameValidationResult { - name: string; - isScopeName: boolean; - result: NameValidationResult; - } - type PackageNameValidationResult = NameValidationResult | ScopedPackageNameValidationResult; - /** - * Validates package name using rules defined at https://docs.npmjs.com/files/package.json - */ - function validatePackageName(packageName: string): PackageNameValidationResult; - function renderPackageNameValidationFailure(result: PackageNameValidationResult, typing: string): string; -} -declare namespace ts { - interface Node { - getSourceFile(): SourceFile; - getChildCount(sourceFile?: SourceFile): number; - getChildAt(index: number, sourceFile?: SourceFile): Node; - getChildren(sourceFile?: SourceFile): Node[]; - getChildren(sourceFile?: SourceFileLike): Node[]; - getStart(sourceFile?: SourceFile, includeJsDocComment?: boolean): number; - getStart(sourceFile?: SourceFileLike, includeJsDocComment?: boolean): number; - getFullStart(): number; - getEnd(): number; - getWidth(sourceFile?: SourceFileLike): number; - getFullWidth(): number; - getLeadingTriviaWidth(sourceFile?: SourceFile): number; - getFullText(sourceFile?: SourceFile): string; - getText(sourceFile?: SourceFile): string; - getFirstToken(sourceFile?: SourceFile): Node | undefined; - getLastToken(sourceFile?: SourceFile): Node | undefined; - forEachChild(cbNode: (node: Node) => T | undefined, cbNodeArray?: (nodes: NodeArray) => T | undefined): T | undefined; - } - interface Identifier { - readonly text: string; - } - interface Symbol { - readonly name: string; - getFlags(): SymbolFlags; - getEscapedName(): __String; - getName(): string; - getDeclarations(): Declaration[] | undefined; - getDocumentationComment(typeChecker: TypeChecker | undefined): SymbolDisplayPart[]; - getJsDocTags(): JSDocTagInfo[]; - } - interface Type { - getFlags(): TypeFlags; - getSymbol(): Symbol | undefined; - getProperties(): Symbol[]; - getProperty(propertyName: string): Symbol | undefined; - getApparentProperties(): Symbol[]; - getCallSignatures(): ReadonlyArray; - getConstructSignatures(): ReadonlyArray; - getStringIndexType(): Type | undefined; - getNumberIndexType(): Type | undefined; - getBaseTypes(): BaseType[] | undefined; - getNonNullableType(): Type; - getConstraint(): Type | undefined; - getDefault(): Type | undefined; - isUnion(): this is UnionType; - isIntersection(): this is IntersectionType; - isUnionOrIntersection(): this is UnionOrIntersectionType; - isLiteral(): this is LiteralType; - isStringLiteral(): this is StringLiteralType; - isNumberLiteral(): this is NumberLiteralType; - isTypeParameter(): this is TypeParameter; - isClassOrInterface(): this is InterfaceType; - isClass(): this is InterfaceType; - } - interface Signature { - getDeclaration(): SignatureDeclaration; - getTypeParameters(): TypeParameter[] | undefined; - getParameters(): Symbol[]; - getReturnType(): Type; - getDocumentationComment(typeChecker: TypeChecker | undefined): SymbolDisplayPart[]; - getJsDocTags(): JSDocTagInfo[]; - } - interface SourceFile { - version: string; - scriptSnapshot: IScriptSnapshot | undefined; - nameTable: UnderscoreEscapedMap | undefined; - getNamedDeclarations(): Map>; - getLineAndCharacterOfPosition(pos: number): LineAndCharacter; - getLineEndOfPosition(pos: number): number; - getLineStarts(): ReadonlyArray; - getPositionOfLineAndCharacter(line: number, character: number): number; - update(newText: string, textChangeRange: TextChangeRange): SourceFile; - sourceMapper?: DocumentPositionMapper; - } - interface SourceFileLike { - getLineAndCharacterOfPosition(pos: number): LineAndCharacter; - } - interface SourceMapSource { - getLineAndCharacterOfPosition(pos: number): LineAndCharacter; - } - /** - * Represents an immutable snapshot of a script at a specified time.Once acquired, the - * snapshot is observably immutable. i.e. the same calls with the same parameters will return - * the same values. - */ - interface IScriptSnapshot { - /** Gets a portion of the script snapshot specified by [start, end). */ - getText(start: number, end: number): string; - /** Gets the length of this script snapshot. */ - getLength(): number; - /** - * Gets the TextChangeRange that describe how the text changed between this text and - * an older version. This information is used by the incremental parser to determine - * what sections of the script need to be re-parsed. 'undefined' can be returned if the - * change range cannot be determined. However, in that case, incremental parsing will - * not happen and the entire document will be re - parsed. - */ - getChangeRange(oldSnapshot: IScriptSnapshot): TextChangeRange | undefined; - /** Releases all resources held by this script snapshot */ - dispose?(): void; - } - namespace ScriptSnapshot { - function fromString(text: string): IScriptSnapshot; - } - interface PreProcessedFileInfo { - referencedFiles: FileReference[]; - typeReferenceDirectives: FileReference[]; - libReferenceDirectives: FileReference[]; - importedFiles: FileReference[]; - ambientExternalModules?: string[]; - isLibFile: boolean; - } - interface HostCancellationToken { - isCancellationRequested(): boolean; - } - interface InstallPackageOptions { - fileName: Path; - packageName: string; - } - interface LanguageServiceHost extends GetEffectiveTypeRootsHost { - getCompilationSettings(): CompilerOptions; - getNewLine?(): string; - getProjectVersion?(): string; - getScriptFileNames(): string[]; - getScriptKind?(fileName: string): ScriptKind; - getScriptVersion(fileName: string): string; - getScriptSnapshot(fileName: string): IScriptSnapshot | undefined; - getProjectReferences?(): ReadonlyArray | undefined; - getLocalizedDiagnosticMessages?(): any; - getCancellationToken?(): HostCancellationToken; - getCurrentDirectory(): string; - getDefaultLibFileName(options: CompilerOptions): string; - log?(s: string): void; - trace?(s: string): void; - error?(s: string): void; - useCaseSensitiveFileNames?(): boolean; - readDirectory?(path: string, extensions?: ReadonlyArray, exclude?: ReadonlyArray, include?: ReadonlyArray, depth?: number): string[]; - readFile?(path: string, encoding?: string): string | undefined; - realpath?(path: string): string; - fileExists?(path: string): boolean; - getTypeRootsVersion?(): number; - resolveModuleNames?(moduleNames: string[], containingFile: string, reusedNames: string[] | undefined, redirectedReference: ResolvedProjectReference | undefined, options: CompilerOptions): (ResolvedModule | undefined)[]; - getResolvedModuleWithFailedLookupLocationsFromCache?(modulename: string, containingFile: string): ResolvedModuleWithFailedLookupLocations | undefined; - resolveTypeReferenceDirectives?(typeDirectiveNames: string[], containingFile: string, redirectedReference: ResolvedProjectReference | undefined, options: CompilerOptions): (ResolvedTypeReferenceDirective | undefined)[]; - hasInvalidatedResolution?: HasInvalidatedResolution; - hasChangedAutomaticTypeDirectiveNames?: boolean; - getDirectories?(directoryName: string): string[]; - /** - * Gets a set of custom transformers to use during emit. - */ - getCustomTransformers?(): CustomTransformers | undefined; - isKnownTypesPackageName?(name: string): boolean; - installPackage?(options: InstallPackageOptions): Promise; - writeFile?(fileName: string, content: string): void; - getDocumentPositionMapper?(generatedFileName: string, sourceFileName?: string): DocumentPositionMapper | undefined; - getSourceFileLike?(fileName: string): SourceFileLike | undefined; - } - const emptyOptions: {}; - type WithMetadata = T & { - metadata?: unknown; - }; - interface LanguageService { - cleanupSemanticCache(): void; - getSyntacticDiagnostics(fileName: string): DiagnosticWithLocation[]; - /** The first time this is called, it will return global diagnostics (no location). */ - getSemanticDiagnostics(fileName: string): Diagnostic[]; - getSuggestionDiagnostics(fileName: string): DiagnosticWithLocation[]; - getCompilerOptionsDiagnostics(): Diagnostic[]; - /** - * @deprecated Use getEncodedSyntacticClassifications instead. - */ - getSyntacticClassifications(fileName: string, span: TextSpan): ClassifiedSpan[]; - /** - * @deprecated Use getEncodedSemanticClassifications instead. - */ - getSemanticClassifications(fileName: string, span: TextSpan): ClassifiedSpan[]; - getEncodedSyntacticClassifications(fileName: string, span: TextSpan): Classifications; - getEncodedSemanticClassifications(fileName: string, span: TextSpan): Classifications; - getCompletionsAtPosition(fileName: string, position: number, options: GetCompletionsAtPositionOptions | undefined): WithMetadata | undefined; - getCompletionEntryDetails(fileName: string, position: number, name: string, formatOptions: FormatCodeOptions | FormatCodeSettings | undefined, source: string | undefined, preferences: UserPreferences | undefined): CompletionEntryDetails | undefined; - getCompletionEntrySymbol(fileName: string, position: number, name: string, source: string | undefined): Symbol | undefined; - getQuickInfoAtPosition(fileName: string, position: number): QuickInfo | undefined; - getNameOrDottedNameSpan(fileName: string, startPos: number, endPos: number): TextSpan | undefined; - getBreakpointStatementAtPosition(fileName: string, position: number): TextSpan | undefined; - getSignatureHelpItems(fileName: string, position: number, options: SignatureHelpItemsOptions | undefined): SignatureHelpItems | undefined; - getRenameInfo(fileName: string, position: number, options?: RenameInfoOptions): RenameInfo; - findRenameLocations(fileName: string, position: number, findInStrings: boolean, findInComments: boolean, providePrefixAndSuffixTextForRename?: boolean): ReadonlyArray | undefined; - getSmartSelectionRange(fileName: string, position: number): SelectionRange; - getDefinitionAtPosition(fileName: string, position: number): ReadonlyArray | undefined; - getDefinitionAndBoundSpan(fileName: string, position: number): DefinitionInfoAndBoundSpan | undefined; - getTypeDefinitionAtPosition(fileName: string, position: number): ReadonlyArray | undefined; - getImplementationAtPosition(fileName: string, position: number): ReadonlyArray | undefined; - getReferencesAtPosition(fileName: string, position: number): ReferenceEntry[] | undefined; - findReferences(fileName: string, position: number): ReferencedSymbol[] | undefined; - getDocumentHighlights(fileName: string, position: number, filesToSearch: string[]): DocumentHighlights[] | undefined; - /** @deprecated */ - getOccurrencesAtPosition(fileName: string, position: number): ReadonlyArray | undefined; - getNavigateToItems(searchValue: string, maxResultCount?: number, fileName?: string, excludeDtsFiles?: boolean): NavigateToItem[]; - getNavigationBarItems(fileName: string): NavigationBarItem[]; - getNavigationTree(fileName: string): NavigationTree; - getOutliningSpans(fileName: string): OutliningSpan[]; - getTodoComments(fileName: string, descriptors: TodoCommentDescriptor[]): TodoComment[]; - getBraceMatchingAtPosition(fileName: string, position: number): TextSpan[]; - getIndentationAtPosition(fileName: string, position: number, options: EditorOptions | EditorSettings): number; - getFormattingEditsForRange(fileName: string, start: number, end: number, options: FormatCodeOptions | FormatCodeSettings): TextChange[]; - getFormattingEditsForDocument(fileName: string, options: FormatCodeOptions | FormatCodeSettings): TextChange[]; - getFormattingEditsAfterKeystroke(fileName: string, position: number, key: string, options: FormatCodeOptions | FormatCodeSettings): TextChange[]; - getDocCommentTemplateAtPosition(fileName: string, position: number): TextInsertion | undefined; - isValidBraceCompletionAtPosition(fileName: string, position: number, openingBrace: number): boolean; - /** - * This will return a defined result if the position is after the `>` of the opening tag, or somewhere in the text, of a JSXElement with no closing tag. - * Editors should call this after `>` is typed. - */ - getJsxClosingTagAtPosition(fileName: string, position: number): JsxClosingTagInfo | undefined; - getSpanOfEnclosingComment(fileName: string, position: number, onlyMultiLine: boolean): TextSpan | undefined; - toLineColumnOffset?(fileName: string, position: number): LineAndCharacter; - /** @internal */ - getSourceMapper(): SourceMapper; - getCodeFixesAtPosition(fileName: string, start: number, end: number, errorCodes: ReadonlyArray, formatOptions: FormatCodeSettings, preferences: UserPreferences): ReadonlyArray; - getCombinedCodeFix(scope: CombinedCodeFixScope, fixId: {}, formatOptions: FormatCodeSettings, preferences: UserPreferences): CombinedCodeActions; - applyCodeActionCommand(action: CodeActionCommand, formatSettings?: FormatCodeSettings): Promise; - applyCodeActionCommand(action: CodeActionCommand[], formatSettings?: FormatCodeSettings): Promise; - applyCodeActionCommand(action: CodeActionCommand | CodeActionCommand[], formatSettings?: FormatCodeSettings): Promise; - /** @deprecated `fileName` will be ignored */ - applyCodeActionCommand(fileName: string, action: CodeActionCommand): Promise; - /** @deprecated `fileName` will be ignored */ - applyCodeActionCommand(fileName: string, action: CodeActionCommand[]): Promise; - /** @deprecated `fileName` will be ignored */ - applyCodeActionCommand(fileName: string, action: CodeActionCommand | CodeActionCommand[]): Promise; - getApplicableRefactors(fileName: string, positionOrRange: number | TextRange, preferences: UserPreferences | undefined): ApplicableRefactorInfo[]; - getEditsForRefactor(fileName: string, formatOptions: FormatCodeSettings, positionOrRange: number | TextRange, refactorName: string, actionName: string, preferences: UserPreferences | undefined): RefactorEditInfo | undefined; - organizeImports(scope: OrganizeImportsScope, formatOptions: FormatCodeSettings, preferences: UserPreferences | undefined): ReadonlyArray; - getEditsForFileRename(oldFilePath: string, newFilePath: string, formatOptions: FormatCodeSettings, preferences: UserPreferences | undefined): ReadonlyArray; - getEmitOutput(fileName: string, emitOnlyDtsFiles?: boolean): EmitOutput; - getProgram(): Program | undefined; - getNonBoundSourceFile(fileName: string): SourceFile; - dispose(): void; - } - interface JsxClosingTagInfo { - readonly newText: string; - } - interface CombinedCodeFixScope { - type: "file"; - fileName: string; - } - type OrganizeImportsScope = CombinedCodeFixScope; - type CompletionsTriggerCharacter = "." | '"' | "'" | "`" | "/" | "@" | "<"; - interface GetCompletionsAtPositionOptions extends UserPreferences { - /** - * If the editor is asking for completions because a certain character was typed - * (as opposed to when the user explicitly requested them) this should be set. - */ - triggerCharacter?: CompletionsTriggerCharacter; - /** @deprecated Use includeCompletionsForModuleExports */ - includeExternalModuleExports?: boolean; - /** @deprecated Use includeCompletionsWithInsertText */ - includeInsertTextCompletions?: boolean; - } - type SignatureHelpTriggerCharacter = "," | "(" | "<"; - type SignatureHelpRetriggerCharacter = SignatureHelpTriggerCharacter | ")"; - interface SignatureHelpItemsOptions { - triggerReason?: SignatureHelpTriggerReason; - } - type SignatureHelpTriggerReason = SignatureHelpInvokedReason | SignatureHelpCharacterTypedReason | SignatureHelpRetriggeredReason; - /** - * Signals that the user manually requested signature help. - * The language service will unconditionally attempt to provide a result. - */ - interface SignatureHelpInvokedReason { - kind: "invoked"; - triggerCharacter?: undefined; - } - /** - * Signals that the signature help request came from a user typing a character. - * Depending on the character and the syntactic context, the request may or may not be served a result. - */ - interface SignatureHelpCharacterTypedReason { - kind: "characterTyped"; - /** - * Character that was responsible for triggering signature help. - */ - triggerCharacter: SignatureHelpTriggerCharacter; - } - /** - * Signals that this signature help request came from typing a character or moving the cursor. - * This should only occur if a signature help session was already active and the editor needs to see if it should adjust. - * The language service will unconditionally attempt to provide a result. - * `triggerCharacter` can be `undefined` for a retrigger caused by a cursor move. - */ - interface SignatureHelpRetriggeredReason { - kind: "retrigger"; - /** - * Character that was responsible for triggering signature help. - */ - triggerCharacter?: SignatureHelpRetriggerCharacter; - } - interface ApplyCodeActionCommandResult { - successMessage: string; - } - interface Classifications { - spans: number[]; - endOfLineState: EndOfLineState; - } - interface ClassifiedSpan { - textSpan: TextSpan; - classificationType: ClassificationTypeNames; - } - /** - * Navigation bar interface designed for visual studio's dual-column layout. - * This does not form a proper tree. - * The navbar is returned as a list of top-level items, each of which has a list of child items. - * Child items always have an empty array for their `childItems`. - */ - interface NavigationBarItem { - text: string; - kind: ScriptElementKind; - kindModifiers: string; - spans: TextSpan[]; - childItems: NavigationBarItem[]; - indent: number; - bolded: boolean; - grayed: boolean; - } - /** - * Node in a tree of nested declarations in a file. - * The top node is always a script or module node. - */ - interface NavigationTree { - /** Name of the declaration, or a short description, e.g. "". */ - text: string; - kind: ScriptElementKind; - /** ScriptElementKindModifier separated by commas, e.g. "public,abstract" */ - kindModifiers: string; - /** - * Spans of the nodes that generated this declaration. - * There will be more than one if this is the result of merging. - */ - spans: TextSpan[]; - nameSpan: TextSpan | undefined; - /** Present if non-empty */ - childItems?: NavigationTree[]; - } - interface TodoCommentDescriptor { - text: string; - priority: number; - } - interface TodoComment { - descriptor: TodoCommentDescriptor; - message: string; - position: number; - } - interface TextChange { - span: TextSpan; - newText: string; - } - interface FileTextChanges { - fileName: string; - textChanges: TextChange[]; - isNewFile?: boolean; - } - interface CodeAction { - /** Description of the code action to display in the UI of the editor */ - description: string; - /** Text changes to apply to each file as part of the code action */ - changes: FileTextChanges[]; - /** - * If the user accepts the code fix, the editor should send the action back in a `applyAction` request. - * This allows the language service to have side effects (e.g. installing dependencies) upon a code fix. - */ - commands?: CodeActionCommand[]; - } - interface CodeFixAction extends CodeAction { - /** Short name to identify the fix, for use by telemetry. */ - fixName: string; - /** - * If present, one may call 'getCombinedCodeFix' with this fixId. - * This may be omitted to indicate that the code fix can't be applied in a group. - */ - fixId?: {}; - fixAllDescription?: string; - } - interface CombinedCodeActions { - changes: ReadonlyArray; - commands?: ReadonlyArray; - } - type CodeActionCommand = InstallPackageAction; - interface InstallPackageAction { - readonly type: "install package"; - readonly file: string; - readonly packageName: string; - } - /** - * A set of one or more available refactoring actions, grouped under a parent refactoring. - */ - interface ApplicableRefactorInfo { - /** - * The programmatic name of the refactoring - */ - name: string; - /** - * A description of this refactoring category to show to the user. - * If the refactoring gets inlined (see below), this text will not be visible. - */ - description: string; - /** - * Inlineable refactorings can have their actions hoisted out to the top level - * of a context menu. Non-inlineanable refactorings should always be shown inside - * their parent grouping. - * - * If not specified, this value is assumed to be 'true' - */ - inlineable?: boolean; - actions: RefactorActionInfo[]; - } - /** - * Represents a single refactoring action - for example, the "Extract Method..." refactor might - * offer several actions, each corresponding to a surround class or closure to extract into. - */ - interface RefactorActionInfo { - /** - * The programmatic name of the refactoring action - */ - name: string; - /** - * A description of this refactoring action to show to the user. - * If the parent refactoring is inlined away, this will be the only text shown, - * so this description should make sense by itself if the parent is inlineable=true - */ - description: string; - } - /** - * A set of edits to make in response to a refactor action, plus an optional - * location where renaming should be invoked from - */ - interface RefactorEditInfo { - edits: FileTextChanges[]; - renameFilename?: string; - renameLocation?: number; - commands?: CodeActionCommand[]; - } - interface TextInsertion { - newText: string; - /** The position in newText the caret should point to after the insertion. */ - caretOffset: number; - } - interface DocumentSpan { - textSpan: TextSpan; - fileName: string; - /** - * If the span represents a location that was remapped (e.g. via a .d.ts.map file), - * then the original filename and span will be specified here - */ - originalTextSpan?: TextSpan; - originalFileName?: string; - /** - * If DocumentSpan.textSpan is the span for name of the declaration, - * then this is the span for relevant declaration - */ - contextSpan?: TextSpan; - originalContextSpan?: TextSpan; - } - interface RenameLocation extends DocumentSpan { - readonly prefixText?: string; - readonly suffixText?: string; - } - interface ReferenceEntry extends DocumentSpan { - isWriteAccess: boolean; - isDefinition: boolean; - isInString?: true; - } - interface ImplementationLocation extends DocumentSpan { - kind: ScriptElementKind; - displayParts: SymbolDisplayPart[]; - } - interface DocumentHighlights { - fileName: string; - highlightSpans: HighlightSpan[]; - } - enum HighlightSpanKind { - none = "none", - definition = "definition", - reference = "reference", - writtenReference = "writtenReference" - } - interface HighlightSpan { - fileName?: string; - isInString?: true; - textSpan: TextSpan; - contextSpan?: TextSpan; - kind: HighlightSpanKind; - } - interface NavigateToItem { - name: string; - kind: ScriptElementKind; - kindModifiers: string; - matchKind: "exact" | "prefix" | "substring" | "camelCase"; - isCaseSensitive: boolean; - fileName: string; - textSpan: TextSpan; - containerName: string; - containerKind: ScriptElementKind; - } - enum IndentStyle { - None = 0, - Block = 1, - Smart = 2 - } - interface EditorOptions { - BaseIndentSize?: number; - IndentSize: number; - TabSize: number; - NewLineCharacter: string; - ConvertTabsToSpaces: boolean; - IndentStyle: IndentStyle; - } - interface EditorSettings { - baseIndentSize?: number; - indentSize?: number; - tabSize?: number; - newLineCharacter?: string; - convertTabsToSpaces?: boolean; - indentStyle?: IndentStyle; - } - interface FormatCodeOptions extends EditorOptions { - InsertSpaceAfterCommaDelimiter: boolean; - InsertSpaceAfterSemicolonInForStatements: boolean; - InsertSpaceBeforeAndAfterBinaryOperators: boolean; - InsertSpaceAfterConstructor?: boolean; - InsertSpaceAfterKeywordsInControlFlowStatements: boolean; - InsertSpaceAfterFunctionKeywordForAnonymousFunctions: boolean; - InsertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis: boolean; - InsertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets: boolean; - InsertSpaceAfterOpeningAndBeforeClosingNonemptyBraces?: boolean; - InsertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces: boolean; - InsertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces?: boolean; - InsertSpaceAfterTypeAssertion?: boolean; - InsertSpaceBeforeFunctionParenthesis?: boolean; - PlaceOpenBraceOnNewLineForFunctions: boolean; - PlaceOpenBraceOnNewLineForControlBlocks: boolean; - insertSpaceBeforeTypeAnnotation?: boolean; - } - interface FormatCodeSettings extends EditorSettings { - readonly insertSpaceAfterCommaDelimiter?: boolean; - readonly insertSpaceAfterSemicolonInForStatements?: boolean; - readonly insertSpaceBeforeAndAfterBinaryOperators?: boolean; - readonly insertSpaceAfterConstructor?: boolean; - readonly insertSpaceAfterKeywordsInControlFlowStatements?: boolean; - readonly insertSpaceAfterFunctionKeywordForAnonymousFunctions?: boolean; - readonly insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis?: boolean; - readonly insertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets?: boolean; - readonly insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces?: boolean; - readonly insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces?: boolean; - readonly insertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces?: boolean; - readonly insertSpaceAfterTypeAssertion?: boolean; - readonly insertSpaceBeforeFunctionParenthesis?: boolean; - readonly placeOpenBraceOnNewLineForFunctions?: boolean; - readonly placeOpenBraceOnNewLineForControlBlocks?: boolean; - readonly insertSpaceBeforeTypeAnnotation?: boolean; - readonly indentMultiLineObjectLiteralBeginningOnBlankLine?: boolean; - } - function getDefaultFormatCodeSettings(newLineCharacter?: string): FormatCodeSettings; - const testFormatSettings: FormatCodeSettings; - interface DefinitionInfo extends DocumentSpan { - kind: ScriptElementKind; - name: string; - containerKind: ScriptElementKind; - containerName: string; - } - interface DefinitionInfoAndBoundSpan { - definitions?: ReadonlyArray; - textSpan: TextSpan; - } - interface ReferencedSymbolDefinitionInfo extends DefinitionInfo { - displayParts: SymbolDisplayPart[]; - } - interface ReferencedSymbol { - definition: ReferencedSymbolDefinitionInfo; - references: ReferenceEntry[]; - } - enum SymbolDisplayPartKind { - aliasName = 0, - className = 1, - enumName = 2, - fieldName = 3, - interfaceName = 4, - keyword = 5, - lineBreak = 6, - numericLiteral = 7, - stringLiteral = 8, - localName = 9, - methodName = 10, - moduleName = 11, - operator = 12, - parameterName = 13, - propertyName = 14, - punctuation = 15, - space = 16, - text = 17, - typeParameterName = 18, - enumMemberName = 19, - functionName = 20, - regularExpressionLiteral = 21 - } - interface SymbolDisplayPart { - text: string; - kind: string; - } - interface JSDocTagInfo { - name: string; - text?: string; - } - interface QuickInfo { - kind: ScriptElementKind; - kindModifiers: string; - textSpan: TextSpan; - displayParts?: SymbolDisplayPart[]; - documentation?: SymbolDisplayPart[]; - tags?: JSDocTagInfo[]; - } - type RenameInfo = RenameInfoSuccess | RenameInfoFailure; - interface RenameInfoSuccess { - canRename: true; - /** - * File or directory to rename. - * If set, `getEditsForFileRename` should be called instead of `findRenameLocations`. - */ - fileToRename?: string; - displayName: string; - fullDisplayName: string; - kind: ScriptElementKind; - kindModifiers: string; - triggerSpan: TextSpan; - } - interface RenameInfoFailure { - canRename: false; - localizedErrorMessage: string; - } - interface RenameInfoOptions { - readonly allowRenameOfImportPath?: boolean; - } - interface SignatureHelpParameter { - name: string; - documentation: SymbolDisplayPart[]; - displayParts: SymbolDisplayPart[]; - isOptional: boolean; - } - interface SelectionRange { - textSpan: TextSpan; - parent?: SelectionRange; - } - /** - * Represents a single signature to show in signature help. - * The id is used for subsequent calls into the language service to ask questions about the - * signature help item in the context of any documents that have been updated. i.e. after - * an edit has happened, while signature help is still active, the host can ask important - * questions like 'what parameter is the user currently contained within?'. - */ - interface SignatureHelpItem { - isVariadic: boolean; - prefixDisplayParts: SymbolDisplayPart[]; - suffixDisplayParts: SymbolDisplayPart[]; - separatorDisplayParts: SymbolDisplayPart[]; - parameters: SignatureHelpParameter[]; - documentation: SymbolDisplayPart[]; - tags: JSDocTagInfo[]; - } - /** - * Represents a set of signature help items, and the preferred item that should be selected. - */ - interface SignatureHelpItems { - items: SignatureHelpItem[]; - applicableSpan: TextSpan; - selectedItemIndex: number; - argumentIndex: number; - argumentCount: number; - } - interface CompletionInfo { - /** Not true for all global completions. This will be true if the enclosing scope matches a few syntax kinds. See `isSnippetScope`. */ - isGlobalCompletion: boolean; - isMemberCompletion: boolean; - /** - * true when the current location also allows for a new identifier - */ - isNewIdentifierLocation: boolean; - entries: CompletionEntry[]; - } - interface CompletionEntry { - name: string; - kind: ScriptElementKind; - kindModifiers?: string; - sortText: string; - insertText?: string; - /** - * An optional span that indicates the text to be replaced by this completion item. - * If present, this span should be used instead of the default one. - * It will be set if the required span differs from the one generated by the default replacement behavior. - */ - replacementSpan?: TextSpan; - hasAction?: true; - source?: string; - isRecommended?: true; - } - interface CompletionEntryDetails { - name: string; - kind: ScriptElementKind; - kindModifiers: string; - displayParts: SymbolDisplayPart[]; - documentation?: SymbolDisplayPart[]; - tags?: JSDocTagInfo[]; - codeActions?: CodeAction[]; - source?: SymbolDisplayPart[]; - } - interface OutliningSpan { - /** The span of the document to actually collapse. */ - textSpan: TextSpan; - /** The span of the document to display when the user hovers over the collapsed span. */ - hintSpan: TextSpan; - /** The text to display in the editor for the collapsed region. */ - bannerText: string; - /** - * Whether or not this region should be automatically collapsed when - * the 'Collapse to Definitions' command is invoked. - */ - autoCollapse: boolean; - /** - * Classification of the contents of the span - */ - kind: OutliningSpanKind; - } - enum OutliningSpanKind { - /** Single or multi-line comments */ - Comment = "comment", - /** Sections marked by '// #region' and '// #endregion' comments */ - Region = "region", - /** Declarations and expressions */ - Code = "code", - /** Contiguous blocks of import declarations */ - Imports = "imports" - } - enum OutputFileType { - JavaScript = 0, - SourceMap = 1, - Declaration = 2 - } - enum EndOfLineState { - None = 0, - InMultiLineCommentTrivia = 1, - InSingleQuoteStringLiteral = 2, - InDoubleQuoteStringLiteral = 3, - InTemplateHeadOrNoSubstitutionTemplate = 4, - InTemplateMiddleOrTail = 5, - InTemplateSubstitutionPosition = 6 - } - enum TokenClass { - Punctuation = 0, - Keyword = 1, - Operator = 2, - Comment = 3, - Whitespace = 4, - Identifier = 5, - NumberLiteral = 6, - BigIntLiteral = 7, - StringLiteral = 8, - RegExpLiteral = 9 - } - interface ClassificationResult { - finalLexState: EndOfLineState; - entries: ClassificationInfo[]; - } - interface ClassificationInfo { - length: number; - classification: TokenClass; - } - interface Classifier { - /** - * Gives lexical classifications of tokens on a line without any syntactic context. - * For instance, a token consisting of the text 'string' can be either an identifier - * named 'string' or the keyword 'string', however, because this classifier is not aware, - * it relies on certain heuristics to give acceptable results. For classifications where - * speed trumps accuracy, this function is preferable; however, for true accuracy, the - * syntactic classifier is ideal. In fact, in certain editing scenarios, combining the - * lexical, syntactic, and semantic classifiers may issue the best user experience. - * - * @param text The text of a line to classify. - * @param lexState The state of the lexical classifier at the end of the previous line. - * @param syntacticClassifierAbsent Whether the client is *not* using a syntactic classifier. - * If there is no syntactic classifier (syntacticClassifierAbsent=true), - * certain heuristics may be used in its place; however, if there is a - * syntactic classifier (syntacticClassifierAbsent=false), certain - * classifications which may be incorrectly categorized will be given - * back as Identifiers in order to allow the syntactic classifier to - * subsume the classification. - * @deprecated Use getLexicalClassifications instead. - */ - getClassificationsForLine(text: string, lexState: EndOfLineState, syntacticClassifierAbsent: boolean): ClassificationResult; - getEncodedLexicalClassifications(text: string, endOfLineState: EndOfLineState, syntacticClassifierAbsent: boolean): Classifications; - } - enum ScriptElementKind { - unknown = "", - warning = "warning", - /** predefined type (void) or keyword (class) */ - keyword = "keyword", - /** top level script node */ - scriptElement = "script", - /** module foo {} */ - moduleElement = "module", - /** class X {} */ - classElement = "class", - /** var x = class X {} */ - localClassElement = "local class", - /** interface Y {} */ - interfaceElement = "interface", - /** type T = ... */ - typeElement = "type", - /** enum E */ - enumElement = "enum", - enumMemberElement = "enum member", - /** - * Inside module and script only - * const v = .. - */ - variableElement = "var", - /** Inside function */ - localVariableElement = "local var", - /** - * Inside module and script only - * function f() { } - */ - functionElement = "function", - /** Inside function */ - localFunctionElement = "local function", - /** class X { [public|private]* foo() {} } */ - memberFunctionElement = "method", - /** class X { [public|private]* [get|set] foo:number; } */ - memberGetAccessorElement = "getter", - memberSetAccessorElement = "setter", - /** - * class X { [public|private]* foo:number; } - * interface Y { foo:number; } - */ - memberVariableElement = "property", - /** class X { constructor() { } } */ - constructorImplementationElement = "constructor", - /** interface Y { ():number; } */ - callSignatureElement = "call", - /** interface Y { []:number; } */ - indexSignatureElement = "index", - /** interface Y { new():Y; } */ - constructSignatureElement = "construct", - /** function foo(*Y*: string) */ - parameterElement = "parameter", - typeParameterElement = "type parameter", - primitiveType = "primitive type", - label = "label", - alias = "alias", - constElement = "const", - letElement = "let", - directory = "directory", - externalModuleName = "external module name", - /** - * - */ - jsxAttribute = "JSX attribute", - /** String literal */ - string = "string" - } - enum ScriptElementKindModifier { - none = "", - publicMemberModifier = "public", - privateMemberModifier = "private", - protectedMemberModifier = "protected", - exportedModifier = "export", - ambientModifier = "declare", - staticModifier = "static", - abstractModifier = "abstract", - optionalModifier = "optional", - dtsModifier = ".d.ts", - tsModifier = ".ts", - tsxModifier = ".tsx", - jsModifier = ".js", - jsxModifier = ".jsx", - jsonModifier = ".json" - } - enum ClassificationTypeNames { - comment = "comment", - identifier = "identifier", - keyword = "keyword", - numericLiteral = "number", - bigintLiteral = "bigint", - operator = "operator", - stringLiteral = "string", - whiteSpace = "whitespace", - text = "text", - punctuation = "punctuation", - className = "class name", - enumName = "enum name", - interfaceName = "interface name", - moduleName = "module name", - typeParameterName = "type parameter name", - typeAliasName = "type alias name", - parameterName = "parameter name", - docCommentTagName = "doc comment tag name", - jsxOpenTagName = "jsx open tag name", - jsxCloseTagName = "jsx close tag name", - jsxSelfClosingTagName = "jsx self closing tag name", - jsxAttribute = "jsx attribute", - jsxText = "jsx text", - jsxAttributeStringLiteralValue = "jsx attribute string literal value" - } - enum ClassificationType { - comment = 1, - identifier = 2, - keyword = 3, - numericLiteral = 4, - operator = 5, - stringLiteral = 6, - regularExpressionLiteral = 7, - whiteSpace = 8, - text = 9, - punctuation = 10, - className = 11, - enumName = 12, - interfaceName = 13, - moduleName = 14, - typeParameterName = 15, - typeAliasName = 16, - parameterName = 17, - docCommentTagName = 18, - jsxOpenTagName = 19, - jsxCloseTagName = 20, - jsxSelfClosingTagName = 21, - jsxAttribute = 22, - jsxText = 23, - jsxAttributeStringLiteralValue = 24, - bigintLiteral = 25 - } -} -interface PromiseConstructor { - new (executor: (resolve: (value?: T | PromiseLike) => void, reject: (reason?: any) => void) => void): Promise; - reject(reason: any): Promise; - all(values: (T | PromiseLike)[]): Promise; -} -declare var Promise: PromiseConstructor; -declare namespace ts { - const scanner: Scanner; - enum SemanticMeaning { - None = 0, - Value = 1, - Type = 2, - Namespace = 4, - All = 7 - } - function getMeaningFromDeclaration(node: Node): SemanticMeaning; - function getMeaningFromLocation(node: Node): SemanticMeaning; - function isInRightSideOfInternalImportEqualsDeclaration(node: Node): boolean; - function isCallExpressionTarget(node: Node): boolean; - function isNewExpressionTarget(node: Node): boolean; - function isCallOrNewExpressionTarget(node: Node): boolean; - function climbPastPropertyAccess(node: Node): Node; - function getTargetLabel(referenceNode: Node, labelName: string): Identifier | undefined; - function hasPropertyAccessExpressionWithName(node: CallExpression, funcName: string): boolean; - function isJumpStatementTarget(node: Node): node is Identifier & { - parent: BreakOrContinueStatement; - }; - function isLabelOfLabeledStatement(node: Node): node is Identifier; - function isLabelName(node: Node): boolean; - function isTagName(node: Node): boolean; - function isRightSideOfQualifiedName(node: Node): boolean; - function isRightSideOfPropertyAccess(node: Node): boolean; - function isNameOfModuleDeclaration(node: Node): boolean; - function isNameOfFunctionDeclaration(node: Node): boolean; - function isLiteralNameOfPropertyDeclarationOrIndexAccess(node: StringLiteral | NumericLiteral): boolean; - function isExpressionOfExternalModuleImportEqualsDeclaration(node: Node): boolean; - function getContainerNode(node: Node): Declaration | undefined; - function getNodeKind(node: Node): ScriptElementKind; - function isThis(node: Node): boolean; - interface ListItemInfo { - listItemIndex: number; - list: Node; - } - function getLineStartPositionForPosition(position: number, sourceFile: SourceFileLike): number; - function rangeContainsRange(r1: TextRange, r2: TextRange): boolean; - function rangeContainsRangeExclusive(r1: TextRange, r2: TextRange): boolean; - function rangeContainsPosition(r: TextRange, pos: number): boolean; - function rangeContainsPositionExclusive(r: TextRange, pos: number): boolean; - function startEndContainsRange(start: number, end: number, range: TextRange): boolean; - function rangeContainsStartEnd(range: TextRange, start: number, end: number): boolean; - function rangeOverlapsWithStartEnd(r1: TextRange, start: number, end: number): boolean; - function nodeOverlapsWithStartEnd(node: Node, sourceFile: SourceFile, start: number, end: number): boolean; - function startEndOverlapsWithStartEnd(start1: number, end1: number, start2: number, end2: number): boolean; - /** - * Assumes `candidate.start <= position` holds. - */ - function positionBelongsToNode(candidate: Node, position: number, sourceFile: SourceFile): boolean; - function findListItemInfo(node: Node): ListItemInfo | undefined; - function hasChildOfKind(n: Node, kind: SyntaxKind, sourceFile: SourceFile): boolean; - function findChildOfKind(n: Node, kind: T["kind"], sourceFile: SourceFileLike): T | undefined; - function findContainingList(node: Node): SyntaxList | undefined; - /** - * Gets the token whose text has range [start, end) and - * position >= start and (position < end or (position === end && token is literal or keyword or identifier)) - */ - function getTouchingPropertyName(sourceFile: SourceFile, position: number): Node; - /** - * Returns the token if position is in [start, end). - * If position === end, returns the preceding token if includeItemAtEndPosition(previousToken) === true - */ - function getTouchingToken(sourceFile: SourceFile, position: number, includePrecedingTokenAtEndPosition?: (n: Node) => boolean): Node; - /** Returns a token if position is in [start-of-leading-trivia, end) */ - function getTokenAtPosition(sourceFile: SourceFile, position: number): Node; - /** - * The token on the left of the position is the token that strictly includes the position - * or sits to the left of the cursor if it is on a boundary. For example - * - * fo|o -> will return foo - * foo |bar -> will return foo - * - */ - function findTokenOnLeftOfPosition(file: SourceFile, position: number): Node | undefined; - function findNextToken(previousToken: Node, parent: Node, sourceFile: SourceFile): Node | undefined; - /** - * Finds the rightmost token satisfying `token.end <= position`, - * excluding `JsxText` tokens containing only whitespace. - */ - function findPrecedingToken(position: number, sourceFile: SourceFile, startNode?: Node, excludeJsdoc?: boolean): Node | undefined; - function isInString(sourceFile: SourceFile, position: number, previousToken?: Node | undefined): boolean; - /** - * returns true if the position is in between the open and close elements of an JSX expression. - */ - function isInsideJsxElementOrAttribute(sourceFile: SourceFile, position: number): boolean; - function isInTemplateString(sourceFile: SourceFile, position: number): boolean; - function isInJSXText(sourceFile: SourceFile, position: number): boolean; - function findPrecedingMatchingToken(token: Node, matchingTokenKind: SyntaxKind, sourceFile: SourceFile): Node | undefined; - function isPossiblyTypeArgumentPosition(token: Node, sourceFile: SourceFile, checker: TypeChecker): boolean; - function getPossibleGenericSignatures(called: Expression, typeArgumentCount: number, checker: TypeChecker): ReadonlyArray; - interface PossibleTypeArgumentInfo { - readonly called: Identifier; - readonly nTypeArguments: number; - } - interface PossibleProgramFileInfo { - ProgramFiles?: string[]; - } - function getPossibleTypeArgumentsInfo(tokenIn: Node, sourceFile: SourceFile): PossibleTypeArgumentInfo | undefined; - /** - * Returns true if the cursor at position in sourceFile is within a comment. - * - * @param tokenAtPosition Must equal `getTokenAtPosition(sourceFile, position) - * @param predicate Additional predicate to test on the comment range. - */ - function isInComment(sourceFile: SourceFile, position: number, tokenAtPosition?: Node): CommentRange | undefined; - function hasDocComment(sourceFile: SourceFile, position: number): boolean; - function getNodeModifiers(node: Node): string; - function getTypeArgumentOrTypeParameterList(node: Node): NodeArray | undefined; - function isComment(kind: SyntaxKind): boolean; - function isStringOrRegularExpressionOrTemplateLiteral(kind: SyntaxKind): boolean; - function isPunctuation(kind: SyntaxKind): boolean; - function isInsideTemplateLiteral(node: TemplateLiteralToken, position: number, sourceFile: SourceFile): boolean; - function isAccessibilityModifier(kind: SyntaxKind): boolean; - function cloneCompilerOptions(options: CompilerOptions): CompilerOptions; - function isArrayLiteralOrObjectLiteralDestructuringPattern(node: Node): boolean; - function isInReferenceComment(sourceFile: SourceFile, position: number): boolean; - function isInNonReferenceComment(sourceFile: SourceFile, position: number): boolean; - function createTextSpanFromNode(node: Node, sourceFile?: SourceFile, endNode?: Node): TextSpan; - function createTextRangeFromNode(node: Node, sourceFile: SourceFile): TextRange; - function createTextSpanFromRange(range: TextRange): TextSpan; - function createTextRangeFromSpan(span: TextSpan): TextRange; - function createTextChangeFromStartLength(start: number, length: number, newText: string): TextChange; - function createTextChange(span: TextSpan, newText: string): TextChange; - const typeKeywords: ReadonlyArray; - function isTypeKeyword(kind: SyntaxKind): boolean; - /** True if the symbol is for an external module, as opposed to a namespace. */ - function isExternalModuleSymbol(moduleSymbol: Symbol): boolean; - /** Returns `true` the first time it encounters a node and `false` afterwards. */ - type NodeSeenTracker = (node: T) => boolean; - function nodeSeenTracker(): NodeSeenTracker; - function getSnapshotText(snap: IScriptSnapshot): string; - function repeatString(str: string, count: number): string; - function skipConstraint(type: Type): Type; - function getNameFromPropertyName(name: PropertyName): string | undefined; - function programContainsEs6Modules(program: Program): boolean; - function compilerOptionsIndicateEs6Modules(compilerOptions: CompilerOptions): boolean; - function hostUsesCaseSensitiveFileNames(host: { - useCaseSensitiveFileNames?(): boolean; - }): boolean; - function hostGetCanonicalFileName(host: { - useCaseSensitiveFileNames?(): boolean; - }): GetCanonicalFileName; - function makeImportIfNecessary(defaultImport: Identifier | undefined, namedImports: ReadonlyArray | undefined, moduleSpecifier: string, quotePreference: QuotePreference): ImportDeclaration | undefined; - function makeImport(defaultImport: Identifier | undefined, namedImports: ReadonlyArray | undefined, moduleSpecifier: string | Expression, quotePreference: QuotePreference): ImportDeclaration; - function makeStringLiteral(text: string, quotePreference: QuotePreference): StringLiteral; - enum QuotePreference { - Single = 0, - Double = 1 - } - function quotePreferenceFromString(str: StringLiteral, sourceFile: SourceFile): QuotePreference; - function getQuotePreference(sourceFile: SourceFile, preferences: UserPreferences): QuotePreference; - function getQuoteFromPreference(qp: QuotePreference): string; - function symbolNameNoDefault(symbol: Symbol): string | undefined; - function symbolEscapedNameNoDefault(symbol: Symbol): __String | undefined; - type ObjectBindingElementWithoutPropertyName = BindingElement & { - name: Identifier; - }; - function isObjectBindingElementWithoutPropertyName(bindingElement: Node): bindingElement is ObjectBindingElementWithoutPropertyName; - function getPropertySymbolFromBindingElement(checker: TypeChecker, bindingElement: ObjectBindingElementWithoutPropertyName): Symbol | undefined; - /** - * Find symbol of the given property-name and add the symbol to the given result array - * @param symbol a symbol to start searching for the given propertyName - * @param propertyName a name of property to search for - * @param result an array of symbol of found property symbols - * @param previousIterationSymbolsCache a cache of symbol from previous iterations of calling this function to prevent infinite revisiting of the same symbol. - * The value of previousIterationSymbol is undefined when the function is first called. - */ - function getPropertySymbolsFromBaseTypes(symbol: Symbol, propertyName: string, checker: TypeChecker, cb: (symbol: Symbol) => T | undefined): T | undefined; - function isMemberSymbolInBaseType(memberSymbol: Symbol, checker: TypeChecker): boolean; - function getParentNodeInSpan(node: Node | undefined, file: SourceFile, span: TextSpan): Node | undefined; - function findModifier(node: Node, kind: Modifier["kind"]): Modifier | undefined; - function insertImport(changes: textChanges.ChangeTracker, sourceFile: SourceFile, importDecl: Statement): void; - function textSpansEqual(a: TextSpan | undefined, b: TextSpan | undefined): boolean; - function documentSpansEqual(a: DocumentSpan, b: DocumentSpan): boolean; -} -declare namespace ts { - function isFirstDeclarationOfSymbolParameter(symbol: Symbol): boolean; - function symbolPart(text: string, symbol: Symbol): SymbolDisplayPart; - function displayPart(text: string, kind: SymbolDisplayPartKind): SymbolDisplayPart; - function spacePart(): SymbolDisplayPart; - function keywordPart(kind: SyntaxKind): SymbolDisplayPart; - function punctuationPart(kind: SyntaxKind): SymbolDisplayPart; - function operatorPart(kind: SyntaxKind): SymbolDisplayPart; - function textOrKeywordPart(text: string): SymbolDisplayPart; - function textPart(text: string): SymbolDisplayPart; - /** - * The default is CRLF. - */ - function getNewLineOrDefaultFromHost(host: LanguageServiceHost | LanguageServiceShimHost, formatSettings?: FormatCodeSettings): string; - function lineBreakPart(): SymbolDisplayPart; - function mapToDisplayParts(writeDisplayParts: (writer: DisplayPartsSymbolWriter) => void): SymbolDisplayPart[]; - function typeToDisplayParts(typechecker: TypeChecker, type: Type, enclosingDeclaration?: Node, flags?: TypeFormatFlags): SymbolDisplayPart[]; - function symbolToDisplayParts(typeChecker: TypeChecker, symbol: Symbol, enclosingDeclaration?: Node, meaning?: SymbolFlags, flags?: SymbolFormatFlags): SymbolDisplayPart[]; - function signatureToDisplayParts(typechecker: TypeChecker, signature: Signature, enclosingDeclaration?: Node, flags?: TypeFormatFlags): SymbolDisplayPart[]; - function isImportOrExportSpecifierName(location: Node): location is Identifier; - function scriptKindIs(fileName: string, host: LanguageServiceHost, ...scriptKinds: ScriptKind[]): boolean; - function getScriptKind(fileName: string, host?: LanguageServiceHost): ScriptKind; - function getSymbolTarget(symbol: Symbol, checker: TypeChecker): Symbol; - function getUniqueSymbolId(symbol: Symbol, checker: TypeChecker): number; - function getFirstNonSpaceCharacterPosition(text: string, position: number): number; - function getPrecedingNonSpaceCharacterPosition(text: string, position: number): number; - /** - * Creates a deep, memberwise clone of a node with no source map location. - * - * WARNING: This is an expensive operation and is only intended to be used in refactorings - * and code fixes (because those are triggered by explicit user actions). - */ - function getSynthesizedDeepClone(node: T, includeTrivia?: boolean): T; - function getSynthesizedDeepCloneWithRenames(node: T, includeTrivia?: boolean, renameMap?: Map, checker?: TypeChecker, callback?: (originalNode: Node, clone: Node) => any): T; - function getSynthesizedDeepClones(nodes: NodeArray, includeTrivia?: boolean): NodeArray; - function getSynthesizedDeepClones(nodes: NodeArray | undefined, includeTrivia?: boolean): NodeArray | undefined; - /** - * Sets EmitFlags to suppress leading and trailing trivia on the node. - */ - function suppressLeadingAndTrailingTrivia(node: Node): void; - /** - * Sets EmitFlags to suppress leading trivia on the node. - */ - function suppressLeadingTrivia(node: Node): void; - /** - * Sets EmitFlags to suppress trailing trivia on the node. - */ - function suppressTrailingTrivia(node: Node): void; - function getUniqueName(baseName: string, sourceFile: SourceFile): string; - /** - * @return The index of the (only) reference to the extracted symbol. We want the cursor - * to be on the reference, rather than the declaration, because it's closer to where the - * user was before extracting it. - */ - function getRenameLocation(edits: ReadonlyArray, renameFilename: string, name: string, preferLastLocation: boolean): number; - function copyLeadingComments(sourceNode: Node, targetNode: Node, sourceFile: SourceFile, commentKind?: CommentKind, hasTrailingNewLine?: boolean): void; - function copyTrailingComments(sourceNode: Node, targetNode: Node, sourceFile: SourceFile, commentKind?: CommentKind, hasTrailingNewLine?: boolean): void; - /** - * This function copies the trailing comments for the token that comes before `sourceNode`, as leading comments of `targetNode`. - * This is useful because sometimes a comment that refers to `sourceNode` will be a leading comment for `sourceNode`, according to the - * notion of trivia ownership, and instead will be a trailing comment for the token before `sourceNode`, e.g.: - * `function foo(\* not leading comment for a *\ a: string) {}` - * The comment refers to `a` but belongs to the `(` token, but we might want to copy it. - */ - function copyTrailingAsLeadingComments(sourceNode: Node, targetNode: Node, sourceFile: SourceFile, commentKind?: CommentKind, hasTrailingNewLine?: boolean): void; - function getContextualTypeFromParent(node: Expression, checker: TypeChecker): Type | undefined; - function quote(text: string, preferences: UserPreferences): string; - function isEqualityOperatorKind(kind: SyntaxKind): kind is EqualityOperator; - function isStringLiteralOrTemplate(node: Node): node is StringLiteralLike | TemplateExpression | TaggedTemplateExpression; - function hasIndexSignature(type: Type): boolean; - function getSwitchedType(caseClause: CaseClause, checker: TypeChecker): Type | undefined; - function getTypeNodeIfAccessible(type: Type, enclosingScope: Node, program: Program, host: LanguageServiceHost): TypeNode | undefined; - function syntaxUsuallyHasTrailingSemicolon(kind: SyntaxKind): boolean; - function probablyUsesSemicolons(sourceFile: SourceFile): boolean; -} -declare namespace ts { - /** The classifier is used for syntactic highlighting in editors via the TSServer */ - function createClassifier(): Classifier; - function getSemanticClassifications(typeChecker: TypeChecker, cancellationToken: CancellationToken, sourceFile: SourceFile, classifiableNames: UnderscoreEscapedMap, span: TextSpan): ClassifiedSpan[]; - function getEncodedSemanticClassifications(typeChecker: TypeChecker, cancellationToken: CancellationToken, sourceFile: SourceFile, classifiableNames: UnderscoreEscapedMap, span: TextSpan): Classifications; - function getSyntacticClassifications(cancellationToken: CancellationToken, sourceFile: SourceFile, span: TextSpan): ClassifiedSpan[]; - function getEncodedSyntacticClassifications(cancellationToken: CancellationToken, sourceFile: SourceFile, span: TextSpan): Classifications; -} -declare namespace ts.Completions.StringCompletions { - function getStringLiteralCompletions(sourceFile: SourceFile, position: number, contextToken: Node | undefined, checker: TypeChecker, options: CompilerOptions, host: LanguageServiceHost, log: Log, preferences: UserPreferences): CompletionInfo | undefined; - function getStringLiteralCompletionDetails(name: string, sourceFile: SourceFile, position: number, contextToken: Node | undefined, checker: TypeChecker, options: CompilerOptions, host: LanguageServiceHost, cancellationToken: CancellationToken): CompletionEntryDetails | undefined; -} -declare namespace ts.Completions { - export enum SortText { - LocationPriority = "0", - SuggestedClassMembers = "1", - GlobalsOrKeywords = "2", - AutoImportSuggestions = "3", - JavascriptIdentifiers = "4" - } - export type Log = (message: string) => void; - enum SymbolOriginInfoKind { - ThisType = 0, - SymbolMemberNoExport = 1, - SymbolMemberExport = 2, - Export = 3 - } - type SymbolOriginInfo = { - kind: SymbolOriginInfoKind.ThisType; - } | { - kind: SymbolOriginInfoKind.SymbolMemberNoExport; - } | SymbolOriginInfoExport; - interface SymbolOriginInfoExport { - kind: SymbolOriginInfoKind.SymbolMemberExport | SymbolOriginInfoKind.Export; - moduleSymbol: Symbol; - isDefaultExport: boolean; - } - /** - * Map from symbol id -> SymbolOriginInfo. - * Only populated for symbols that come from other modules. - */ - type SymbolOriginInfoMap = (SymbolOriginInfo | undefined)[]; - type SymbolSortTextMap = (SortText | undefined)[]; - export function getCompletionsAtPosition(host: LanguageServiceHost, program: Program, log: Log, sourceFile: SourceFile, position: number, preferences: UserPreferences, triggerCharacter: CompletionsTriggerCharacter | undefined): CompletionInfo | undefined; - export function getCompletionEntriesFromSymbols(symbols: ReadonlyArray, entries: Push, location: Node | undefined, sourceFile: SourceFile, typeChecker: TypeChecker, target: ScriptTarget, log: Log, kind: CompletionKind, preferences: UserPreferences, propertyAccessToConvert?: PropertyAccessExpression | undefined, isJsxInitializer?: IsJsxInitializer, recommendedCompletion?: Symbol, symbolToOriginInfoMap?: SymbolOriginInfoMap, symbolToSortTextMap?: SymbolSortTextMap): Map; - export interface CompletionEntryIdentifier { - name: string; - source?: string; - } - export function getCompletionEntryDetails(program: Program, log: Log, sourceFile: SourceFile, position: number, entryId: CompletionEntryIdentifier, host: LanguageServiceHost, formatContext: formatting.FormatContext, preferences: UserPreferences, cancellationToken: CancellationToken): CompletionEntryDetails | undefined; - export function createCompletionDetailsForSymbol(symbol: Symbol, checker: TypeChecker, sourceFile: SourceFile, location: Node, cancellationToken: CancellationToken, codeActions?: CodeAction[], sourceDisplay?: SymbolDisplayPart[]): CompletionEntryDetails; - export function createCompletionDetails(name: string, kindModifiers: string, kind: ScriptElementKind, displayParts: SymbolDisplayPart[], documentation?: SymbolDisplayPart[], tags?: JSDocTagInfo[], codeActions?: CodeAction[], source?: SymbolDisplayPart[]): CompletionEntryDetails; - export function getCompletionEntrySymbol(program: Program, log: Log, sourceFile: SourceFile, position: number, entryId: CompletionEntryIdentifier): Symbol | undefined; - /** true: after the `=` sign but no identifier has been typed yet. Else is the Identifier after the initializer. */ - type IsJsxInitializer = boolean | Identifier; - export enum CompletionKind { - ObjectPropertyDeclaration = 0, - Global = 1, - PropertyAccess = 2, - MemberLike = 3, - String = 4, - None = 5 - } - export {}; -} -declare namespace ts.DocumentHighlights { - function getDocumentHighlights(program: Program, cancellationToken: CancellationToken, sourceFile: SourceFile, position: number, sourceFilesToSearch: ReadonlyArray): DocumentHighlights[] | undefined; -} -declare namespace ts { - /** - * The document registry represents a store of SourceFile objects that can be shared between - * multiple LanguageService instances. A LanguageService instance holds on the SourceFile (AST) - * of files in the context. - * SourceFile objects account for most of the memory usage by the language service. Sharing - * the same DocumentRegistry instance between different instances of LanguageService allow - * for more efficient memory utilization since all projects will share at least the library - * file (lib.d.ts). - * - * A more advanced use of the document registry is to serialize sourceFile objects to disk - * and re-hydrate them when needed. - * - * To create a default DocumentRegistry, use createDocumentRegistry to create one, and pass it - * to all subsequent createLanguageService calls. - */ - interface DocumentRegistry { - /** - * Request a stored SourceFile with a given fileName and compilationSettings. - * The first call to acquire will call createLanguageServiceSourceFile to generate - * the SourceFile if was not found in the registry. - * - * @param fileName The name of the file requested - * @param compilationSettings Some compilation settings like target affects the - * shape of a the resulting SourceFile. This allows the DocumentRegistry to store - * multiple copies of the same file for different compilation settings. - * @param scriptSnapshot Text of the file. Only used if the file was not found - * in the registry and a new one was created. - * @param version Current version of the file. Only used if the file was not found - * in the registry and a new one was created. - */ - acquireDocument(fileName: string, compilationSettings: CompilerOptions, scriptSnapshot: IScriptSnapshot, version: string, scriptKind?: ScriptKind): SourceFile; - acquireDocumentWithKey(fileName: string, path: Path, compilationSettings: CompilerOptions, key: DocumentRegistryBucketKey, scriptSnapshot: IScriptSnapshot, version: string, scriptKind?: ScriptKind): SourceFile; - /** - * Request an updated version of an already existing SourceFile with a given fileName - * and compilationSettings. The update will in-turn call updateLanguageServiceSourceFile - * to get an updated SourceFile. - * - * @param fileName The name of the file requested - * @param compilationSettings Some compilation settings like target affects the - * shape of a the resulting SourceFile. This allows the DocumentRegistry to store - * multiple copies of the same file for different compilation settings. - * @param scriptSnapshot Text of the file. - * @param version Current version of the file. - */ - updateDocument(fileName: string, compilationSettings: CompilerOptions, scriptSnapshot: IScriptSnapshot, version: string, scriptKind?: ScriptKind): SourceFile; - updateDocumentWithKey(fileName: string, path: Path, compilationSettings: CompilerOptions, key: DocumentRegistryBucketKey, scriptSnapshot: IScriptSnapshot, version: string, scriptKind?: ScriptKind): SourceFile; - getKeyForCompilationSettings(settings: CompilerOptions): DocumentRegistryBucketKey; - /** - * Informs the DocumentRegistry that a file is not needed any longer. - * - * Note: It is not allowed to call release on a SourceFile that was not acquired from - * this registry originally. - * - * @param fileName The name of the file to be released - * @param compilationSettings The compilation settings used to acquire the file - */ - releaseDocument(fileName: string, compilationSettings: CompilerOptions): void; - releaseDocumentWithKey(path: Path, key: DocumentRegistryBucketKey): void; - getLanguageServiceRefCounts(path: Path): [string, number | undefined][]; - reportStats(): string; - } - interface ExternalDocumentCache { - setDocument(key: DocumentRegistryBucketKey, path: Path, sourceFile: SourceFile): void; - getDocument(key: DocumentRegistryBucketKey, path: Path): SourceFile | undefined; - } - type DocumentRegistryBucketKey = string & { - __bucketKey: any; - }; - function createDocumentRegistry(useCaseSensitiveFileNames?: boolean, currentDirectory?: string): DocumentRegistry; - function createDocumentRegistryInternal(useCaseSensitiveFileNames?: boolean, currentDirectory?: string, externalCache?: ExternalDocumentCache): DocumentRegistry; -} -declare namespace ts.FindAllReferences { - interface ImportsResult { - /** For every import of the symbol, the location and local symbol for the import. */ - importSearches: ReadonlyArray<[Identifier, Symbol]>; - /** For rename imports/exports `{ foo as bar }`, `foo` is not a local, so it may be added as a reference immediately without further searching. */ - singleReferences: ReadonlyArray; - /** List of source files that may (or may not) use the symbol via a namespace. (For UMD modules this is every file.) */ - indirectUsers: ReadonlyArray; - } - type ImportTracker = (exportSymbol: Symbol, exportInfo: ExportInfo, isForRename: boolean) => ImportsResult; - /** Creates the imports map and returns an ImportTracker that uses it. Call this lazily to avoid calling `getDirectImportsMap` unnecessarily. */ - function createImportTracker(sourceFiles: ReadonlyArray, sourceFilesSet: ReadonlyMap, checker: TypeChecker, cancellationToken: CancellationToken | undefined): ImportTracker; - /** Info about an exported symbol to perform recursive search on. */ - interface ExportInfo { - exportingModuleSymbol: Symbol; - exportKind: ExportKind; - } - enum ExportKind { - Named = 0, - Default = 1, - ExportEquals = 2 - } - enum ImportExport { - Import = 0, - Export = 1 - } - type ModuleReference = - /** "import" also includes require() calls. */ - { - kind: "import"; - literal: StringLiteralLike; - } - /** or */ - | { - kind: "reference"; - referencingFile: SourceFile; - ref: FileReference; - }; - function findModuleReferences(program: Program, sourceFiles: ReadonlyArray, searchModuleSymbol: Symbol): ModuleReference[]; - interface ImportedSymbol { - kind: ImportExport.Import; - symbol: Symbol; - } - interface ExportedSymbol { - kind: ImportExport.Export; - symbol: Symbol; - exportInfo: ExportInfo; - } - /** - * Given a local reference, we might notice that it's an import/export and recursively search for references of that. - * If at an import, look locally for the symbol it imports. - * If at an export, look for all imports of it. - * This doesn't handle export specifiers; that is done in `getReferencesAtExportSpecifier`. - * @param comingFromExport If we are doing a search for all exports, don't bother looking backwards for the imported symbol, since that's the reason we're here. - */ - function getImportOrExportSymbol(node: Node, symbol: Symbol, checker: TypeChecker, comingFromExport: boolean): ImportedSymbol | ExportedSymbol | undefined; - function getExportInfo(exportSymbol: Symbol, exportKind: ExportKind, checker: TypeChecker): ExportInfo | undefined; -} -declare namespace ts.FindAllReferences { - interface SymbolAndEntries { - readonly definition: Definition | undefined; - readonly references: ReadonlyArray; - } - enum DefinitionKind { - Symbol = 0, - Label = 1, - Keyword = 2, - This = 3, - String = 4 - } - type Definition = { - readonly type: DefinitionKind.Symbol; - readonly symbol: Symbol; - } | { - readonly type: DefinitionKind.Label; - readonly node: Identifier; - } | { - readonly type: DefinitionKind.Keyword; - readonly node: Node; - } | { - readonly type: DefinitionKind.This; - readonly node: Node; - } | { - readonly type: DefinitionKind.String; - readonly node: StringLiteral; - }; - enum EntryKind { - Span = 0, - Node = 1, - StringLiteral = 2, - SearchedLocalFoundProperty = 3, - SearchedPropertyFoundLocal = 4 - } - type NodeEntryKind = EntryKind.Node | EntryKind.StringLiteral | EntryKind.SearchedLocalFoundProperty | EntryKind.SearchedPropertyFoundLocal; - type Entry = NodeEntry | SpanEntry; - interface ContextWithStartAndEndNode { - start: Node; - end: Node; - } - type ContextNode = Node | ContextWithStartAndEndNode; - interface NodeEntry { - readonly kind: NodeEntryKind; - readonly node: Node; - readonly context?: ContextNode; - } - interface SpanEntry { - readonly kind: EntryKind.Span; - readonly fileName: string; - readonly textSpan: TextSpan; - } - function nodeEntry(node: Node, kind?: NodeEntryKind): NodeEntry; - function isContextWithStartAndEndNode(node: ContextNode): node is ContextWithStartAndEndNode; - function getContextNode(node: NamedDeclaration | BinaryExpression | ForInOrOfStatement | undefined): ContextNode | undefined; - function toContextSpan(textSpan: TextSpan, sourceFile: SourceFile, context?: ContextNode): { - contextSpan: TextSpan; - } | undefined; - interface Options { - readonly findInStrings?: boolean; - readonly findInComments?: boolean; - /** - * True if we are renaming the symbol. - * If so, we will find fewer references -- if it is referenced by several different names, we still only find references for the original name. - */ - readonly isForRename?: boolean; - /** True if we are searching for implementations. We will have a different method of adding references if so. */ - readonly implementations?: boolean; - /** - * True to opt in for enhanced renaming of shorthand properties and import/export specifiers. - * The options controls the behavior for the whole rename operation; it cannot be changed on a per-file basis. - * Default is false for backwards compatibility. - */ - readonly providePrefixAndSuffixTextForRename?: boolean; - } - function findReferencedSymbols(program: Program, cancellationToken: CancellationToken, sourceFiles: ReadonlyArray, sourceFile: SourceFile, position: number): ReferencedSymbol[] | undefined; - function getImplementationsAtPosition(program: Program, cancellationToken: CancellationToken, sourceFiles: ReadonlyArray, sourceFile: SourceFile, position: number): ImplementationLocation[] | undefined; - function findReferenceOrRenameEntries(program: Program, cancellationToken: CancellationToken, sourceFiles: ReadonlyArray, node: Node, position: number, options: Options | undefined, convertEntry: ToReferenceOrRenameEntry): T[] | undefined; - type ToReferenceOrRenameEntry = (entry: Entry, originalNode: Node, checker: TypeChecker) => T; - function getReferenceEntriesForNode(position: number, node: Node, program: Program, sourceFiles: ReadonlyArray, cancellationToken: CancellationToken, options?: Options, sourceFilesSet?: ReadonlyMap): ReadonlyArray | undefined; - function toRenameLocation(entry: Entry, originalNode: Node, checker: TypeChecker, providePrefixAndSuffixText: boolean): RenameLocation; - function toReferenceEntry(entry: Entry): ReferenceEntry; - function toHighlightSpan(entry: Entry): { - fileName: string; - span: HighlightSpan; - }; - function getTextSpanOfEntry(entry: Entry): TextSpan; -} -/** Encapsulates the core find-all-references algorithm. */ -declare namespace ts.FindAllReferences.Core { - /** Core find-all-references algorithm. Handles special cases before delegating to `getReferencedSymbolsForSymbol`. */ - function getReferencedSymbolsForNode(position: number, node: Node, program: Program, sourceFiles: ReadonlyArray, cancellationToken: CancellationToken, options?: Options, sourceFilesSet?: ReadonlyMap): ReadonlyArray | undefined; - function eachExportReference(sourceFiles: ReadonlyArray, checker: TypeChecker, cancellationToken: CancellationToken | undefined, exportSymbol: Symbol, exportingModuleSymbol: Symbol, exportName: string, isDefaultExport: boolean, cb: (ref: Identifier) => void): void; - /** Used as a quick check for whether a symbol is used at all in a file (besides its definition). */ - function isSymbolReferencedInFile(definition: Identifier, checker: TypeChecker, sourceFile: SourceFile): boolean; - function eachSymbolReferenceInFile(definition: Identifier, checker: TypeChecker, sourceFile: SourceFile, cb: (token: Identifier) => T): T | undefined; - function eachSignatureCall(signature: SignatureDeclaration, sourceFiles: ReadonlyArray, checker: TypeChecker, cb: (call: CallExpression) => void): void; - /** - * Given an initial searchMeaning, extracted from a location, widen the search scope based on the declarations - * of the corresponding symbol. e.g. if we are searching for "Foo" in value position, but "Foo" references a class - * then we need to widen the search to include type positions as well. - * On the contrary, if we are searching for "Bar" in type position and we trace bar to an interface, and an uninstantiated - * module, we want to keep the search limited to only types, as the two declarations (interface and uninstantiated module) - * do not intersect in any of the three spaces. - */ - function getIntersectingMeaningFromDeclarations(node: Node, symbol: Symbol): SemanticMeaning; - function getReferenceEntriesForShorthandPropertyAssignment(node: Node, checker: TypeChecker, addReference: (node: Node) => void): void; -} -declare namespace ts { - export function getEditsForFileRename(program: Program, oldFileOrDirPath: string, newFileOrDirPath: string, host: LanguageServiceHost, formatContext: formatting.FormatContext, _preferences: UserPreferences, sourceMapper: SourceMapper): ReadonlyArray; - /** If 'path' refers to an old directory, returns path in the new directory. */ - type PathUpdater = (path: string) => string | undefined; - export function getPathUpdater(oldFileOrDirPath: string, newFileOrDirPath: string, getCanonicalFileName: GetCanonicalFileName, sourceMapper: SourceMapper | undefined): PathUpdater; - export {}; -} -declare namespace ts.GoToDefinition { - function getDefinitionAtPosition(program: Program, sourceFile: SourceFile, position: number): ReadonlyArray | undefined; - function getReferenceAtPosition(sourceFile: SourceFile, position: number, program: Program): { - fileName: string; - file: SourceFile; - } | undefined; - function getTypeDefinitionAtPosition(typeChecker: TypeChecker, sourceFile: SourceFile, position: number): ReadonlyArray | undefined; - function getDefinitionAndBoundSpan(program: Program, sourceFile: SourceFile, position: number): DefinitionInfoAndBoundSpan | undefined; - function findReferenceInPosition(refs: ReadonlyArray, pos: number): FileReference | undefined; -} -declare namespace ts.JsDoc { - function getJsDocCommentsFromDeclarations(declarations: ReadonlyArray): SymbolDisplayPart[]; - function getJsDocTagsFromDeclarations(declarations?: Declaration[]): JSDocTagInfo[]; - function getJSDocTagNameCompletions(): CompletionEntry[]; - const getJSDocTagNameCompletionDetails: typeof getJSDocTagCompletionDetails; - function getJSDocTagCompletions(): CompletionEntry[]; - function getJSDocTagCompletionDetails(name: string): CompletionEntryDetails; - function getJSDocParameterNameCompletions(tag: JSDocParameterTag): CompletionEntry[]; - function getJSDocParameterNameCompletionDetails(name: string): CompletionEntryDetails; - /** - * Checks if position points to a valid position to add JSDoc comments, and if so, - * returns the appropriate template. Otherwise returns an empty string. - * Valid positions are - * - outside of comments, statements, and expressions, and - * - preceding a: - * - function/constructor/method declaration - * - class declarations - * - variable statements - * - namespace declarations - * - interface declarations - * - method signatures - * - type alias declarations - * - * Hosts should ideally check that: - * - The line is all whitespace up to 'position' before performing the insertion. - * - If the keystroke sequence "/\*\*" induced the call, we also check that the next - * non-whitespace character is '*', which (approximately) indicates whether we added - * the second '*' to complete an existing (JSDoc) comment. - * @param fileName The file in which to perform the check. - * @param position The (character-indexed) position in the file where the check should - * be performed. - */ - function getDocCommentTemplateAtPosition(newLine: string, sourceFile: SourceFile, position: number): TextInsertion | undefined; -} -declare namespace ts.NavigateTo { - function getNavigateToItems(sourceFiles: ReadonlyArray, checker: TypeChecker, cancellationToken: CancellationToken, searchValue: string, maxResultCount: number | undefined, excludeDtsFiles: boolean): NavigateToItem[]; -} -declare namespace ts.NavigationBar { - function getNavigationBarItems(sourceFile: SourceFile, cancellationToken: CancellationToken): NavigationBarItem[]; - function getNavigationTree(sourceFile: SourceFile, cancellationToken: CancellationToken): NavigationTree; -} -declare namespace ts.OrganizeImports { - /** - * Organize imports by: - * 1) Removing unused imports - * 2) Coalescing imports from the same module - * 3) Sorting imports - */ - function organizeImports(sourceFile: SourceFile, formatContext: formatting.FormatContext, host: LanguageServiceHost, program: Program, _preferences: UserPreferences): FileTextChanges[]; - /** - * @param importGroup a list of ImportDeclarations, all with the same module name. - */ - function coalesceImports(importGroup: ReadonlyArray): readonly ImportDeclaration[]; - /** - * @param exportGroup a list of ExportDeclarations, all with the same module name. - */ - function coalesceExports(exportGroup: ReadonlyArray): readonly ExportDeclaration[]; - function compareModuleSpecifiers(m1: Expression, m2: Expression): Comparison; -} -declare namespace ts.OutliningElementsCollector { - function collectElements(sourceFile: SourceFile, cancellationToken: CancellationToken): OutliningSpan[]; -} -declare namespace ts { - enum PatternMatchKind { - exact = 0, - prefix = 1, - substring = 2, - camelCase = 3 - } - interface PatternMatch { - kind: PatternMatchKind; - isCaseSensitive: boolean; - } - interface PatternMatcher { - getMatchForLastSegmentOfPattern(candidate: string): PatternMatch | undefined; - getFullMatch(candidateContainers: ReadonlyArray, candidate: string): PatternMatch | undefined; - patternContainsDots: boolean; - } - function createPatternMatcher(pattern: string): PatternMatcher | undefined; - function breakIntoCharacterSpans(identifier: string): TextSpan[]; - function breakIntoWordSpans(identifier: string): TextSpan[]; -} -declare namespace ts { - function preProcessFile(sourceText: string, readImportFiles?: boolean, detectJavaScriptImports?: boolean): PreProcessedFileInfo; -} -declare namespace ts.Rename { - function getRenameInfo(program: Program, sourceFile: SourceFile, position: number, options?: RenameInfoOptions): RenameInfo; -} -declare namespace ts.SmartSelectionRange { - function getSmartSelectionRange(pos: number, sourceFile: SourceFile): SelectionRange; -} -declare namespace ts.SignatureHelp { - function getSignatureHelpItems(program: Program, sourceFile: SourceFile, position: number, triggerReason: SignatureHelpTriggerReason | undefined, cancellationToken: CancellationToken): SignatureHelpItems | undefined; - interface ArgumentInfoForCompletions { - readonly invocation: CallLikeExpression; - readonly argumentIndex: number; - readonly argumentCount: number; - } - function getArgumentInfoForCompletions(node: Node, position: number, sourceFile: SourceFile): ArgumentInfoForCompletions | undefined; -} -declare namespace ts { - interface SourceMapper { - toLineColumnOffset(fileName: string, position: number): LineAndCharacter; - tryGetSourcePosition(info: DocumentPosition): DocumentPosition | undefined; - tryGetGeneratedPosition(info: DocumentPosition): DocumentPosition | undefined; - clearCache(): void; - } - interface SourceMapperHost { - useCaseSensitiveFileNames(): boolean; - getCurrentDirectory(): string; - getProgram(): Program | undefined; - fileExists?(path: string): boolean; - readFile?(path: string, encoding?: string): string | undefined; - getSourceFileLike?(fileName: string): SourceFileLike | undefined; - getDocumentPositionMapper?(generatedFileName: string, sourceFileName?: string): DocumentPositionMapper | undefined; - log(s: string): void; - } - function getSourceMapper(host: SourceMapperHost): SourceMapper; - /** - * string | undefined to contents of map file to create DocumentPositionMapper from it - * DocumentPositionMapper | false to give back cached DocumentPositionMapper - */ - type ReadMapFile = (mapFileName: string, mapFileNameFromDts: string | undefined) => string | undefined | DocumentPositionMapper | false; - function getDocumentPositionMapper(host: DocumentPositionMapperHost, generatedFileName: string, generatedFileLineInfo: LineInfo, readMapFile: ReadMapFile): DocumentPositionMapper | undefined; -} -declare namespace ts { - function computeSuggestionDiagnostics(sourceFile: SourceFile, program: Program, cancellationToken: CancellationToken): DiagnosticWithLocation[]; - function isReturnStatementWithFixablePromiseHandler(node: Node): node is ReturnStatement; - function isFixablePromiseHandler(node: Node): boolean; -} -declare namespace ts.SymbolDisplay { - function getSymbolKind(typeChecker: TypeChecker, symbol: Symbol, location: Node): ScriptElementKind; - function getSymbolModifiers(symbol: Symbol): string; - interface SymbolDisplayPartsDocumentationAndSymbolKind { - displayParts: SymbolDisplayPart[]; - documentation: SymbolDisplayPart[]; - symbolKind: ScriptElementKind; - tags: JSDocTagInfo[] | undefined; - } - function getSymbolDisplayPartsDocumentationAndSymbolKind(typeChecker: TypeChecker, symbol: Symbol, sourceFile: SourceFile, enclosingDeclaration: Node | undefined, location: Node, semanticMeaning?: SemanticMeaning, alias?: Symbol): SymbolDisplayPartsDocumentationAndSymbolKind; -} -declare namespace ts { - interface TranspileOptions { - compilerOptions?: CompilerOptions; - fileName?: string; - reportDiagnostics?: boolean; - moduleName?: string; - renamedDependencies?: MapLike; - transformers?: CustomTransformers; - } - interface TranspileOutput { - outputText: string; - diagnostics?: Diagnostic[]; - sourceMapText?: string; - } - function transpileModule(input: string, transpileOptions: TranspileOptions): TranspileOutput; - function transpile(input: string, compilerOptions?: CompilerOptions, fileName?: string, diagnostics?: Diagnostic[], moduleName?: string): string; - /** JS users may pass in string values for enum compiler options (such as ModuleKind), so convert. */ - function fixupCompilerOptions(options: CompilerOptions, diagnostics: Diagnostic[]): CompilerOptions; -} -declare namespace ts.formatting { - enum FormattingRequestKind { - FormatDocument = 0, - FormatSelection = 1, - FormatOnEnter = 2, - FormatOnSemicolon = 3, - FormatOnOpeningCurlyBrace = 4, - FormatOnClosingCurlyBrace = 5 - } - class FormattingContext { - readonly sourceFile: SourceFileLike; - formattingRequestKind: FormattingRequestKind; - options: FormatCodeSettings; - currentTokenSpan: TextRangeWithKind; - nextTokenSpan: TextRangeWithKind; - contextNode: Node; - currentTokenParent: Node; - nextTokenParent: Node; - private contextNodeAllOnSameLine; - private nextNodeAllOnSameLine; - private tokensAreOnSameLine; - private contextNodeBlockIsOnOneLine; - private nextNodeBlockIsOnOneLine; - constructor(sourceFile: SourceFileLike, formattingRequestKind: FormattingRequestKind, options: FormatCodeSettings); - updateContext(currentRange: TextRangeWithKind, currentTokenParent: Node, nextRange: TextRangeWithKind, nextTokenParent: Node, commonParent: Node): void; - ContextNodeAllOnSameLine(): boolean; - NextNodeAllOnSameLine(): boolean; - TokensAreOnSameLine(): boolean; - ContextNodeBlockIsOnOneLine(): boolean; - NextNodeBlockIsOnOneLine(): boolean; - private NodeIsOnOneLine; - private BlockIsOnOneLine; - } -} -declare namespace ts.formatting { - interface FormattingScanner { - advance(): void; - isOnToken(): boolean; - readTokenInfo(n: Node): TokenInfo; - getCurrentLeadingTrivia(): TextRangeWithKind[] | undefined; - lastTrailingTriviaWasNewLine(): boolean; - skipToEndOf(node: Node): void; - } - function getFormattingScanner(text: string, languageVariant: LanguageVariant, startPos: number, endPos: number, cb: (scanner: FormattingScanner) => T): T; -} -declare namespace ts.formatting { - interface Rule { - readonly debugName: string; - readonly context: ReadonlyArray; - readonly action: RuleAction; - readonly flags: RuleFlags; - } - type ContextPredicate = (context: FormattingContext) => boolean; - const anyContext: ReadonlyArray; - enum RuleAction { - Ignore = 1, - Space = 2, - NewLine = 4, - Delete = 8 - } - enum RuleFlags { - None = 0, - CanDeleteNewLines = 1 - } - interface TokenRange { - readonly tokens: ReadonlyArray; - readonly isSpecific: boolean; - } -} -declare namespace ts.formatting { - interface RuleSpec { - readonly leftTokenRange: TokenRange; - readonly rightTokenRange: TokenRange; - readonly rule: Rule; - } - function getAllRules(): RuleSpec[]; -} -declare namespace ts.formatting { - function getFormatContext(options: FormatCodeSettings): FormatContext; - type RulesMap = (context: FormattingContext) => Rule | undefined; - enum RulesPosition { - IgnoreRulesSpecific = 0, - IgnoreRulesAny, - ContextRulesSpecific, - ContextRulesAny, - NoContextRulesSpecific, - NoContextRulesAny - } -} -declare namespace ts.formatting { - interface FormatContext { - readonly options: FormatCodeSettings; - readonly getRule: RulesMap; - } - interface TextRangeWithKind extends TextRange { - kind: SyntaxKind; - } - interface TextRangeWithTriviaKind extends TextRange { - kind: TriviaKind; - } - interface TokenInfo { - leadingTrivia: TextRangeWithTriviaKind[] | undefined; - token: TextRangeWithKind; - trailingTrivia: TextRangeWithTriviaKind[] | undefined; - } - function formatOnEnter(position: number, sourceFile: SourceFile, formatContext: FormatContext): TextChange[]; - function formatOnSemicolon(position: number, sourceFile: SourceFile, formatContext: FormatContext): TextChange[]; - function formatOnOpeningCurly(position: number, sourceFile: SourceFile, formatContext: FormatContext): TextChange[]; - function formatOnClosingCurly(position: number, sourceFile: SourceFile, formatContext: FormatContext): TextChange[]; - function formatDocument(sourceFile: SourceFile, formatContext: FormatContext): TextChange[]; - function formatSelection(start: number, end: number, sourceFile: SourceFile, formatContext: FormatContext): TextChange[]; - function formatNodeGivenIndentation(node: Node, sourceFileLike: SourceFileLike, languageVariant: LanguageVariant, initialIndentation: number, delta: number, formatContext: FormatContext): TextChange[]; - /** - * @param precedingToken pass `null` if preceding token was already computed and result was `undefined`. - */ - function getRangeOfEnclosingComment(sourceFile: SourceFile, position: number, precedingToken?: Node | null, // tslint:disable-line:no-null-keyword - tokenAtPosition?: Node): CommentRange | undefined; - function getIndentationString(indentation: number, options: EditorSettings): string; -} -declare namespace ts.formatting { - namespace SmartIndenter { - /** - * @param assumeNewLineBeforeCloseBrace - * `false` when called on text from a real source file. - * `true` when we need to assume `position` is on a newline. - * - * This is useful for codefixes. Consider - * ``` - * function f() { - * |} - * ``` - * with `position` at `|`. - * - * When inserting some text after an open brace, we would like to get indentation as if a newline was already there. - * By default indentation at `position` will be 0 so 'assumeNewLineBeforeCloseBrace' overrides this behavior. - */ - function getIndentation(position: number, sourceFile: SourceFile, options: EditorSettings, assumeNewLineBeforeCloseBrace?: boolean): number; - function getIndentationForNode(n: Node, ignoreActualIndentationRange: TextRange, sourceFile: SourceFile, options: EditorSettings): number; - function getBaseIndentation(options: EditorSettings): number; - function isArgumentAndStartLineOverlapsExpressionBeingCalled(parent: Node, child: Node, childStartLine: number, sourceFile: SourceFileLike): boolean; - function childStartsOnTheSameLineWithElseInIfStatement(parent: Node, child: TextRangeWithKind, childStartLine: number, sourceFile: SourceFileLike): boolean; - function argumentStartsOnSameLineAsPreviousArgument(parent: Node, child: TextRangeWithKind, childStartLine: number, sourceFile: SourceFileLike): boolean; - function getContainingList(node: Node, sourceFile: SourceFile): NodeArray | undefined; - /** - * Character is the actual index of the character since the beginning of the line. - * Column - position of the character after expanding tabs to spaces. - * "0\t2$" - * value of 'character' for '$' is 3 - * value of 'column' for '$' is 6 (assuming that tab size is 4) - */ - function findFirstNonWhitespaceCharacterAndColumn(startPos: number, endPos: number, sourceFile: SourceFileLike, options: EditorSettings): { - column: number; - character: number; - }; - function findFirstNonWhitespaceColumn(startPos: number, endPos: number, sourceFile: SourceFileLike, options: EditorSettings): number; - function nodeWillIndentChild(settings: FormatCodeSettings, parent: TextRangeWithKind, child: TextRangeWithKind | undefined, sourceFile: SourceFileLike | undefined, indentByDefault: boolean): boolean; - /** - * True when the parent node should indent the given child by an explicit rule. - * @param isNextChild If true, we are judging indent of a hypothetical child *after* this one, not the current child. - */ - function shouldIndentChildNode(settings: FormatCodeSettings, parent: TextRangeWithKind, child?: Node, sourceFile?: SourceFileLike, isNextChild?: boolean): boolean; - } -} -declare namespace ts.textChanges { - interface ConfigurableStart { - leadingTriviaOption?: LeadingTriviaOption; - } - interface ConfigurableEnd { - trailingTriviaOption?: TrailingTriviaOption; - } - enum LeadingTriviaOption { - /** Exclude all leading trivia (use getStart()) */ - Exclude = 0, - /** Include leading trivia and, - * if there are no line breaks between the node and the previous token, - * include all trivia between the node and the previous token - */ - IncludeAll = 1 - } - enum TrailingTriviaOption { - /** Exclude all trailing trivia (use getEnd()) */ - Exclude = 0, - /** Include trailing trivia */ - Include = 1 - } - /** - * Usually node.pos points to a position immediately after the previous token. - * If this position is used as a beginning of the span to remove - it might lead to removing the trailing trivia of the previous node, i.e: - * const x; // this is x - * ^ - pos for the next variable declaration will point here - * const y; // this is y - * ^ - end for previous variable declaration - * Usually leading trivia of the variable declaration 'y' should not include trailing trivia (whitespace, comment 'this is x' and newline) from the preceding - * variable declaration and trailing trivia for 'y' should include (whitespace, comment 'this is y', newline). - * By default when removing nodes we adjust start and end positions to respect specification of the trivia above. - * If pos\end should be interpreted literally (that is, withouth including leading and trailing trivia), `leadingTriviaOption` should be set to `LeadingTriviaOption.Exclude` - * and `trailingTriviaOption` to `TrailingTriviaOption.Exclude`. - */ - interface ConfigurableStartEnd extends ConfigurableStart, ConfigurableEnd { - } - interface InsertNodeOptions { - /** - * Text to be inserted before the new node - */ - prefix?: string; - /** - * Text to be inserted after the new node - */ - suffix?: string; - /** - * Text of inserted node will be formatted with this indentation, otherwise indentation will be inferred from the old node - */ - indentation?: number; - /** - * Text of inserted node will be formatted with this delta, otherwise delta will be inferred from the new node kind - */ - delta?: number; - /** - * Do not trim leading white spaces in the edit range - */ - preserveLeadingWhitespace?: boolean; - } - interface ReplaceWithMultipleNodesOptions extends InsertNodeOptions { - readonly joiner?: string; - } - interface ChangeNodeOptions extends ConfigurableStartEnd, InsertNodeOptions { - } - interface TextChangesContext { - host: LanguageServiceHost; - formatContext: formatting.FormatContext; - } - type TypeAnnotatable = SignatureDeclaration | VariableDeclaration | ParameterDeclaration | PropertyDeclaration | PropertySignature; - type ThisTypeAnnotatable = FunctionDeclaration | FunctionExpression; - function isThisTypeAnnotatable(containingFunction: FunctionLike): containingFunction is ThisTypeAnnotatable; - class ChangeTracker { - private readonly newLineCharacter; - private readonly formatContext; - private readonly changes; - private readonly newFiles; - private readonly classesWithNodesInsertedAtStart; - private readonly deletedNodes; - static fromContext(context: TextChangesContext): ChangeTracker; - static with(context: TextChangesContext, cb: (tracker: ChangeTracker) => void): FileTextChanges[]; - /** Public for tests only. Other callers should use `ChangeTracker.with`. */ - constructor(newLineCharacter: string, formatContext: formatting.FormatContext); - deleteRange(sourceFile: SourceFile, range: TextRange): void; - delete(sourceFile: SourceFile, node: Node | NodeArray): void; - deleteModifier(sourceFile: SourceFile, modifier: Modifier): void; - deleteNodeRange(sourceFile: SourceFile, startNode: Node, endNode: Node, options?: ConfigurableStartEnd): void; - deleteNodeRangeExcludingEnd(sourceFile: SourceFile, startNode: Node, afterEndNode: Node | undefined, options?: ConfigurableStartEnd): void; - replaceRange(sourceFile: SourceFile, range: TextRange, newNode: Node, options?: InsertNodeOptions): void; - replaceNode(sourceFile: SourceFile, oldNode: Node, newNode: Node, options?: ChangeNodeOptions): void; - replaceNodeRange(sourceFile: SourceFile, startNode: Node, endNode: Node, newNode: Node, options?: ChangeNodeOptions): void; - private replaceRangeWithNodes; - replaceNodeWithNodes(sourceFile: SourceFile, oldNode: Node, newNodes: ReadonlyArray, options?: ChangeNodeOptions): void; - replaceNodeWithText(sourceFile: SourceFile, oldNode: Node, text: string): void; - replaceNodeRangeWithNodes(sourceFile: SourceFile, startNode: Node, endNode: Node, newNodes: ReadonlyArray, options?: ReplaceWithMultipleNodesOptions & ConfigurableStartEnd): void; - private nextCommaToken; - replacePropertyAssignment(sourceFile: SourceFile, oldNode: PropertyAssignment, newNode: PropertyAssignment): void; - insertNodeAt(sourceFile: SourceFile, pos: number, newNode: Node, options?: InsertNodeOptions): void; - private insertNodesAt; - insertNodeAtTopOfFile(sourceFile: SourceFile, newNode: Statement, blankLineBetween: boolean): void; - insertNodeBefore(sourceFile: SourceFile, before: Node, newNode: Node, blankLineBetween?: boolean): void; - insertModifierBefore(sourceFile: SourceFile, modifier: SyntaxKind, before: Node): void; - insertLastModifierBefore(sourceFile: SourceFile, modifier: SyntaxKind, before: Node): void; - insertCommentBeforeLine(sourceFile: SourceFile, lineNumber: number, position: number, commentText: string): void; - insertJsdocCommentBefore(sourceFile: SourceFile, node: HasJSDoc, tag: JSDoc): void; - replaceRangeWithText(sourceFile: SourceFile, range: TextRange, text: string): void; - insertText(sourceFile: SourceFile, pos: number, text: string): void; - /** Prefer this over replacing a node with another that has a type annotation, as it avoids reformatting the other parts of the node. */ - tryInsertTypeAnnotation(sourceFile: SourceFile, node: TypeAnnotatable, type: TypeNode): void; - tryInsertThisTypeAnnotation(sourceFile: SourceFile, node: ThisTypeAnnotatable, type: TypeNode): void; - insertTypeParameters(sourceFile: SourceFile, node: SignatureDeclaration, typeParameters: ReadonlyArray): void; - private getOptionsForInsertNodeBefore; - insertNodeAtConstructorStart(sourceFile: SourceFile, ctr: ConstructorDeclaration, newStatement: Statement): void; - insertNodeAtConstructorEnd(sourceFile: SourceFile, ctr: ConstructorDeclaration, newStatement: Statement): void; - private replaceConstructorBody; - insertNodeAtEndOfScope(sourceFile: SourceFile, scope: Node, newNode: Node): void; - insertNodeAtClassStart(sourceFile: SourceFile, cls: ClassLikeDeclaration | InterfaceDeclaration, newElement: ClassElement): void; - insertNodeAtObjectStart(sourceFile: SourceFile, obj: ObjectLiteralExpression, newElement: ObjectLiteralElementLike): void; - private insertNodeAtStartWorker; - private getInsertNodeAtStartPrefixSuffix; - insertNodeAfterComma(sourceFile: SourceFile, after: Node, newNode: Node): void; - insertNodeAfter(sourceFile: SourceFile, after: Node, newNode: Node): void; - insertNodeAtEndOfList(sourceFile: SourceFile, list: NodeArray, newNode: Node): void; - insertNodesAfter(sourceFile: SourceFile, after: Node, newNodes: ReadonlyArray): void; - private insertNodeAfterWorker; - private getInsertNodeAfterOptions; - private getInsertNodeAfterOptionsWorker; - insertName(sourceFile: SourceFile, node: FunctionExpression | ClassExpression | ArrowFunction, name: string): void; - insertExportModifier(sourceFile: SourceFile, node: DeclarationStatement | VariableStatement): void; - /** - * This function should be used to insert nodes in lists when nodes don't carry separators as the part of the node range, - * i.e. arguments in arguments lists, parameters in parameter lists etc. - * Note that separators are part of the node in statements and class elements. - */ - insertNodeInListAfter(sourceFile: SourceFile, after: Node, newNode: Node, containingList?: NodeArray | undefined): void; - parenthesizeExpression(sourceFile: SourceFile, expression: Expression): void; - private finishClassesWithNodesInsertedAtStart; - private finishDeleteDeclarations; - /** - * Note: after calling this, the TextChanges object must be discarded! - * @param validate only for tests - * The reason we must validate as part of this method is that `getNonFormattedText` changes the node's positions, - * so we can only call this once and can't get the non-formatted text separately. - */ - getChanges(validate?: ValidateNonFormattedText): FileTextChanges[]; - createNewFile(oldFile: SourceFile | undefined, fileName: string, statements: ReadonlyArray): void; - } - type ValidateNonFormattedText = (node: Node, text: string) => void; - function getNewFileText(statements: ReadonlyArray, scriptKind: ScriptKind, newLineCharacter: string, formatContext: formatting.FormatContext): string; - function applyChanges(text: string, changes: ReadonlyArray): string; - function isValidLocationToAddComment(sourceFile: SourceFile, position: number): boolean; - /** Warning: This deletes comments too. See `copyComments` in `convertFunctionToEs6Class`. */ - function deleteNode(changes: ChangeTracker, sourceFile: SourceFile, node: Node, options?: ConfigurableStartEnd): void; -} -declare namespace ts { - interface CodeFixRegistration { - errorCodes: ReadonlyArray; - getCodeActions(context: CodeFixContext): CodeFixAction[] | undefined; - fixIds?: ReadonlyArray; - getAllCodeActions?(context: CodeFixAllContext): CombinedCodeActions; - } - interface CodeFixContextBase extends textChanges.TextChangesContext { - sourceFile: SourceFile; - program: Program; - cancellationToken: CancellationToken; - preferences: UserPreferences; - } - interface CodeFixAllContext extends CodeFixContextBase { - fixId: {}; - } - interface CodeFixContext extends CodeFixContextBase { - errorCode: number; - span: TextSpan; - } - namespace codefix { - type DiagnosticAndArguments = DiagnosticMessage | [DiagnosticMessage, string] | [DiagnosticMessage, string, string]; - function createCodeFixActionNoFixId(fixName: string, changes: FileTextChanges[], description: DiagnosticAndArguments): CodeFixAction; - function createCodeFixAction(fixName: string, changes: FileTextChanges[], description: DiagnosticAndArguments, fixId: {}, fixAllDescription: DiagnosticAndArguments, command?: CodeActionCommand): CodeFixAction; - function registerCodeFix(reg: CodeFixRegistration): void; - function getSupportedErrorCodes(): string[]; - function getFixes(context: CodeFixContext): ReadonlyArray; - function getAllFixes(context: CodeFixAllContext): CombinedCodeActions; - function createCombinedCodeActions(changes: FileTextChanges[], commands?: CodeActionCommand[]): CombinedCodeActions; - function createFileTextChanges(fileName: string, textChanges: TextChange[]): FileTextChanges; - function codeFixAll(context: CodeFixAllContext, errorCodes: number[], use: (changes: textChanges.ChangeTracker, error: DiagnosticWithLocation, commands: Push) => void): CombinedCodeActions; - function eachDiagnostic({ program, sourceFile, cancellationToken }: CodeFixAllContext, errorCodes: ReadonlyArray, cb: (diag: DiagnosticWithLocation) => void): void; - } -} -declare namespace ts { - interface Refactor { - /** Compute the associated code actions */ - getEditsForAction(context: RefactorContext, actionName: string): RefactorEditInfo | undefined; - /** Compute (quickly) which actions are available here */ - getAvailableActions(context: RefactorContext): ReadonlyArray; - } - interface RefactorContext extends textChanges.TextChangesContext { - file: SourceFile; - startPosition: number; - endPosition?: number; - program: Program; - cancellationToken?: CancellationToken; - preferences: UserPreferences; - } - namespace refactor { - /** @param name An unique code associated with each refactor. Does not have to be human-readable. */ - function registerRefactor(name: string, refactor: Refactor): void; - function getApplicableRefactors(context: RefactorContext): ApplicableRefactorInfo[]; - function getEditsForRefactor(context: RefactorContext, refactorName: string, actionName: string): RefactorEditInfo | undefined; - } - function getRefactorContextSpan({ startPosition, endPosition }: RefactorContext): TextSpan; -} -declare namespace ts.codefix { -} -declare namespace ts.codefix { -} -declare namespace ts.codefix { -} -declare namespace ts.codefix { -} -declare namespace ts.codefix { -} -declare namespace ts.codefix { - type DeclarationWithType = FunctionLikeDeclaration | VariableDeclaration | PropertySignature | PropertyDeclaration; - function parameterShouldGetTypeFromJSDoc(node: Node): node is DeclarationWithType; -} -declare namespace ts.codefix { -} -declare namespace ts.codefix { -} -declare namespace ts.codefix { -} -declare namespace ts.codefix { -} -declare namespace ts.codefix { -} -declare namespace ts.codefix { -} -declare namespace ts.codefix { - const importFixId = "fixMissingImport"; - enum ImportKind { - Named = 0, - Default = 1, - Namespace = 2, - Equals = 3, - ConstEquals = 4 - } - function getImportCompletionAction(exportedSymbol: Symbol, moduleSymbol: Symbol, sourceFile: SourceFile, symbolName: string, host: LanguageServiceHost, program: Program, formatContext: formatting.FormatContext, position: number, preferences: UserPreferences): { - readonly moduleSpecifier: string; - readonly codeAction: CodeAction; - }; - function forEachExternalModuleToImportFrom(checker: TypeChecker, from: SourceFile, allSourceFiles: ReadonlyArray, cb: (module: Symbol) => void): void; - function moduleSymbolToValidIdentifier(moduleSymbol: Symbol, target: ScriptTarget): string; - function moduleSpecifierToValidIdentifier(moduleSpecifier: string, target: ScriptTarget): string; -} -declare namespace ts.codefix { -} -declare namespace ts.codefix { -} -declare namespace ts.codefix { -} -declare namespace ts.codefix { -} -declare namespace ts.codefix { -} -declare namespace ts.codefix { -} -declare namespace ts.codefix { -} -declare namespace ts.codefix { -} -declare namespace ts.codefix { -} -declare namespace ts.codefix { -} -declare namespace ts.codefix { -} -declare namespace ts.codefix { -} -declare namespace ts.codefix { -} -declare namespace ts.codefix { -} -declare namespace ts.codefix { -} -declare namespace ts.codefix { -} -declare namespace ts.codefix { -} -declare namespace ts.codefix { - /** - * Finds members of the resolved type that are missing in the class pointed to by class decl - * and generates source code for the missing members. - * @param possiblyMissingSymbols The collection of symbols to filter and then get insertions for. - * @returns Empty string iff there are no member insertions. - */ - function createMissingMemberNodes(classDeclaration: ClassLikeDeclaration, possiblyMissingSymbols: ReadonlyArray, context: TypeConstructionContext, preferences: UserPreferences, out: (node: ClassElement) => void): void; - function getNoopSymbolTrackerWithResolver(context: TypeConstructionContext): SymbolTracker; - interface TypeConstructionContext { - program: Program; - host: ModuleSpecifierResolutionHost; - } - function createMethodFromCallExpression(context: CodeFixContextBase, call: CallExpression, methodName: string, inJs: boolean, makeStatic: boolean, preferences: UserPreferences, contextNode: Node): MethodDeclaration; - function setJsonCompilerOptionValue(changeTracker: textChanges.ChangeTracker, configFile: TsConfigSourceFile, optionName: string, optionValue: Expression): undefined; - function createJsonPropertyAssignment(name: string, initializer: Expression): PropertyAssignment; - function findJsonProperty(obj: ObjectLiteralExpression, name: string): PropertyAssignment | undefined; -} -declare namespace ts.codefix { -} -declare namespace ts.codefix { -} -declare namespace ts.codefix { -} -declare namespace ts.codefix { -} -declare namespace ts.codefix { -} -declare namespace ts.codefix { -} -declare namespace ts.codefix { -} -declare namespace ts.refactor { -} -declare namespace ts.refactor { -} -declare namespace ts.refactor.extractSymbol { - /** - * Compute the associated code actions - * Exported for tests. - */ - function getAvailableActions(context: RefactorContext): ReadonlyArray; - function getEditsForAction(context: RefactorContext, actionName: string): RefactorEditInfo | undefined; - namespace Messages { - const cannotExtractRange: DiagnosticMessage; - const cannotExtractImport: DiagnosticMessage; - const cannotExtractSuper: DiagnosticMessage; - const cannotExtractEmpty: DiagnosticMessage; - const expressionExpected: DiagnosticMessage; - const uselessConstantType: DiagnosticMessage; - const statementOrExpressionExpected: DiagnosticMessage; - const cannotExtractRangeContainingConditionalBreakOrContinueStatements: DiagnosticMessage; - const cannotExtractRangeContainingConditionalReturnStatement: DiagnosticMessage; - const cannotExtractRangeContainingLabeledBreakOrContinueStatementWithTargetOutsideOfTheRange: DiagnosticMessage; - const cannotExtractRangeThatContainsWritesToReferencesLocatedOutsideOfTheTargetRangeInGenerators: DiagnosticMessage; - const typeWillNotBeVisibleInTheNewScope: DiagnosticMessage; - const functionWillNotBeVisibleInTheNewScope: DiagnosticMessage; - const cannotExtractIdentifier: DiagnosticMessage; - const cannotExtractExportedEntity: DiagnosticMessage; - const cannotWriteInExpression: DiagnosticMessage; - const cannotExtractReadonlyPropertyInitializerOutsideConstructor: DiagnosticMessage; - const cannotExtractAmbientBlock: DiagnosticMessage; - const cannotAccessVariablesFromNestedScopes: DiagnosticMessage; - const cannotExtractToOtherFunctionLike: DiagnosticMessage; - const cannotExtractToJSClass: DiagnosticMessage; - const cannotExtractToExpressionArrowFunction: DiagnosticMessage; - } - enum RangeFacts { - None = 0, - HasReturn = 1, - IsGenerator = 2, - IsAsyncFunction = 4, - UsesThis = 8, - /** - * The range is in a function which needs the 'static' modifier in a class - */ - InStaticRegion = 16 - } - /** - * Represents an expression or a list of statements that should be extracted with some extra information - */ - interface TargetRange { - readonly range: Expression | Statement[]; - readonly facts: RangeFacts; - /** - * A list of symbols that are declared in the selected range which are visible in the containing lexical scope - * Used to ensure we don't turn something used outside the range free (or worse, resolve to a different entity). - */ - readonly declarations: Symbol[]; - } - /** - * Result of 'getRangeToExtract' operation: contains either a range or a list of errors - */ - type RangeToExtract = { - readonly targetRange?: never; - readonly errors: ReadonlyArray; - } | { - readonly targetRange: TargetRange; - readonly errors?: never; - }; - /** - * getRangeToExtract takes a span inside a text file and returns either an expression or an array - * of statements representing the minimum set of nodes needed to extract the entire span. This - * process may fail, in which case a set of errors is returned instead (these are currently - * not shown to the user, but can be used by us diagnostically) - */ - function getRangeToExtract(sourceFile: SourceFile, span: TextSpan): RangeToExtract; - enum Usage { - Read = 1, - Write = 2 - } -} -declare namespace ts.refactor { -} -declare namespace ts.refactor.generateGetAccessorAndSetAccessor { -} -declare namespace ts.refactor { -} -declare namespace ts.refactor.addOrRemoveBracesToArrowFunction { -} -declare namespace ts.refactor.convertParamsToDestructuredObject { -} -declare namespace ts { - /** The version of the language service API */ - const servicesVersion = "0.8"; - interface DisplayPartsSymbolWriter extends EmitTextWriter { - displayParts(): SymbolDisplayPart[]; - } - function toEditorSettings(options: FormatCodeOptions | FormatCodeSettings): FormatCodeSettings; - function toEditorSettings(options: EditorOptions | EditorSettings): EditorSettings; - function displayPartsToString(displayParts: SymbolDisplayPart[] | undefined): string; - function getDefaultCompilerOptions(): CompilerOptions; - function getSupportedCodeFixes(): string[]; - function createLanguageServiceSourceFile(fileName: string, scriptSnapshot: IScriptSnapshot, scriptTarget: ScriptTarget, version: string, setNodeParents: boolean, scriptKind?: ScriptKind): SourceFile; - let disableIncrementalParsing: boolean; - function updateLanguageServiceSourceFile(sourceFile: SourceFile, scriptSnapshot: IScriptSnapshot, version: string, textChangeRange: TextChangeRange | undefined, aggressiveChecks?: boolean): SourceFile; - /** A cancellation that throttles calls to the host */ - class ThrottledCancellationToken implements CancellationToken { - private hostCancellationToken; - private readonly throttleWaitMilliseconds; - private lastCancellationCheckTime; - constructor(hostCancellationToken: HostCancellationToken, throttleWaitMilliseconds?: number); - isCancellationRequested(): boolean; - throwIfCancellationRequested(): void; - } - function createLanguageService(host: LanguageServiceHost, documentRegistry?: DocumentRegistry, syntaxOnly?: boolean): LanguageService; - /** Names in the name table are escaped, so an identifier `__foo` will have a name table entry `___foo`. */ - function getNameTable(sourceFile: SourceFile): UnderscoreEscapedMap; - /** - * Returns the containing object literal property declaration given a possible name node, e.g. "a" in x = { "a": 1 } - */ - function getContainingObjectLiteralElement(node: Node): ObjectLiteralElementWithName | undefined; - type ObjectLiteralElementWithName = ObjectLiteralElement & { - name: PropertyName; - parent: ObjectLiteralExpression | JsxAttributes; - }; - /** Gets all symbols for one property. Does not get symbols for every property. */ - function getPropertySymbolsFromContextualType(node: ObjectLiteralElementWithName, checker: TypeChecker, contextualType: Type, unionSymbolOk: boolean): ReadonlyArray; - /** - * Get the path of the default library files (lib.d.ts) as distributed with the typescript - * node package. - * The functionality is not supported if the ts module is consumed outside of a node module. - */ - function getDefaultLibFilePath(options: CompilerOptions): string; -} -declare namespace ts.BreakpointResolver { - /** - * Get the breakpoint span in given sourceFile - */ - function spanInSourceFileAtLocation(sourceFile: SourceFile, position: number): TextSpan | undefined; -} -declare namespace ts { - /** - * Transform one or more nodes using the supplied transformers. - * @param source A single `Node` or an array of `Node` objects. - * @param transformers An array of `TransformerFactory` callbacks used to process the transformation. - * @param compilerOptions Optional compiler options. - */ - function transform(source: T | T[], transformers: TransformerFactory[], compilerOptions?: CompilerOptions): TransformationResult; -} -declare namespace ts { - interface ScriptSnapshotShim { - /** Gets a portion of the script snapshot specified by [start, end). */ - getText(start: number, end: number): string; - /** Gets the length of this script snapshot. */ - getLength(): number; - /** - * Returns a JSON-encoded value of the type: - * { span: { start: number; length: number }; newLength: number } - * - * Or undefined value if there was no change. - */ - getChangeRange(oldSnapshot: ScriptSnapshotShim): string | undefined; - /** Releases all resources held by this script snapshot */ - dispose?(): void; - } - interface Logger { - log(s: string): void; - trace(s: string): void; - error(s: string): void; - } - /** Public interface of the host of a language service shim instance. */ - interface LanguageServiceShimHost extends Logger { - getCompilationSettings(): string; - /** Returns a JSON-encoded value of the type: string[] */ - getScriptFileNames(): string; - getScriptKind?(fileName: string): ScriptKind; - getScriptVersion(fileName: string): string; - getScriptSnapshot(fileName: string): ScriptSnapshotShim; - getLocalizedDiagnosticMessages(): string; - getCancellationToken(): HostCancellationToken; - getCurrentDirectory(): string; - getDirectories(path: string): string; - getDefaultLibFileName(options: string): string; - getNewLine?(): string; - getProjectVersion?(): string; - useCaseSensitiveFileNames?(): boolean; - getTypeRootsVersion?(): number; - readDirectory(rootDir: string, extension: string, basePaths?: string, excludeEx?: string, includeFileEx?: string, includeDirEx?: string, depth?: number): string; - readFile(path: string, encoding?: string): string | undefined; - fileExists(path: string): boolean; - getModuleResolutionsForFile?(fileName: string): string; - getTypeReferenceDirectiveResolutionsForFile?(fileName: string): string; - directoryExists(directoryName: string): boolean; - } - /** Public interface of the core-services host instance used in managed side */ - interface CoreServicesShimHost extends Logger { - directoryExists(directoryName: string): boolean; - fileExists(fileName: string): boolean; - getCurrentDirectory(): string; - getDirectories(path: string): string; - /** - * Returns a JSON-encoded value of the type: string[] - * - * @param exclude A JSON encoded string[] containing the paths to exclude - * when enumerating the directory. - */ - readDirectory(rootDir: string, extension: string, basePaths?: string, excludeEx?: string, includeFileEx?: string, includeDirEx?: string, depth?: number): string; - /** - * Read arbitrary text files on disk, i.e. when resolution procedure needs the content of 'package.json' to determine location of bundled typings for node modules - */ - readFile(fileName: string): string | undefined; - realpath?(path: string): string; - trace(s: string): void; - useCaseSensitiveFileNames?(): boolean; - } - interface ShimsFileReference { - path: string; - position: number; - length: number; - } - /** Public interface of a language service instance shim. */ - interface ShimFactory { - registerShim(shim: Shim): void; - unregisterShim(shim: Shim): void; - } - interface Shim { - dispose(_dummy: {}): void; - } - interface LanguageServiceShim extends Shim { - languageService: LanguageService; - dispose(_dummy: {}): void; - refresh(throwOnError: boolean): void; - cleanupSemanticCache(): void; - getSyntacticDiagnostics(fileName: string): string; - getSemanticDiagnostics(fileName: string): string; - getSuggestionDiagnostics(fileName: string): string; - getCompilerOptionsDiagnostics(): string; - getSyntacticClassifications(fileName: string, start: number, length: number): string; - getSemanticClassifications(fileName: string, start: number, length: number): string; - getEncodedSyntacticClassifications(fileName: string, start: number, length: number): string; - getEncodedSemanticClassifications(fileName: string, start: number, length: number): string; - getCompletionsAtPosition(fileName: string, position: number, preferences: UserPreferences | undefined): string; - getCompletionEntryDetails(fileName: string, position: number, entryName: string, formatOptions: string | undefined, source: string | undefined, preferences: UserPreferences | undefined): string; - getQuickInfoAtPosition(fileName: string, position: number): string; - getNameOrDottedNameSpan(fileName: string, startPos: number, endPos: number): string; - getBreakpointStatementAtPosition(fileName: string, position: number): string; - getSignatureHelpItems(fileName: string, position: number, options: SignatureHelpItemsOptions | undefined): string; - /** - * Returns a JSON-encoded value of the type: - * { canRename: boolean, localizedErrorMessage: string, displayName: string, fullDisplayName: string, kind: string, kindModifiers: string, triggerSpan: { start; length } } - */ - getRenameInfo(fileName: string, position: number, options?: RenameInfoOptions): string; - getSmartSelectionRange(fileName: string, position: number): string; - /** - * Returns a JSON-encoded value of the type: - * { fileName: string, textSpan: { start: number, length: number } }[] - */ - findRenameLocations(fileName: string, position: number, findInStrings: boolean, findInComments: boolean, providePrefixAndSuffixTextForRename?: boolean): string; - /** - * Returns a JSON-encoded value of the type: - * { fileName: string; textSpan: { start: number; length: number}; kind: string; name: string; containerKind: string; containerName: string } - * - * Or undefined value if no definition can be found. - */ - getDefinitionAtPosition(fileName: string, position: number): string; - getDefinitionAndBoundSpan(fileName: string, position: number): string; - /** - * Returns a JSON-encoded value of the type: - * { fileName: string; textSpan: { start: number; length: number}; kind: string; name: string; containerKind: string; containerName: string } - * - * Or undefined value if no definition can be found. - */ - getTypeDefinitionAtPosition(fileName: string, position: number): string; - /** - * Returns a JSON-encoded value of the type: - * { fileName: string; textSpan: { start: number; length: number}; }[] - */ - getImplementationAtPosition(fileName: string, position: number): string; - /** - * Returns a JSON-encoded value of the type: - * { fileName: string; textSpan: { start: number; length: number}; isWriteAccess: boolean, isDefinition?: boolean }[] - */ - getReferencesAtPosition(fileName: string, position: number): string; - /** - * Returns a JSON-encoded value of the type: - * { definition: ; references: [] }[] - */ - findReferences(fileName: string, position: number): string; - /** - * @deprecated - * Returns a JSON-encoded value of the type: - * { fileName: string; textSpan: { start: number; length: number}; isWriteAccess: boolean }[] - */ - getOccurrencesAtPosition(fileName: string, position: number): string; - /** - * Returns a JSON-encoded value of the type: - * { fileName: string; highlights: { start: number; length: number, isDefinition: boolean }[] }[] - * - * @param fileToSearch A JSON encoded string[] containing the file names that should be - * considered when searching. - */ - getDocumentHighlights(fileName: string, position: number, filesToSearch: string): string; - /** - * Returns a JSON-encoded value of the type: - * { name: string; kind: string; kindModifiers: string; containerName: string; containerKind: string; matchKind: string; fileName: string; textSpan: { start: number; length: number}; } [] = []; - */ - getNavigateToItems(searchValue: string, maxResultCount?: number, fileName?: string): string; - /** - * Returns a JSON-encoded value of the type: - * { text: string; kind: string; kindModifiers: string; bolded: boolean; grayed: boolean; indent: number; spans: { start: number; length: number; }[]; childItems: [] } [] = []; - */ - getNavigationBarItems(fileName: string): string; - /** Returns a JSON-encoded value of the type ts.NavigationTree. */ - getNavigationTree(fileName: string): string; - /** - * Returns a JSON-encoded value of the type: - * { textSpan: { start: number, length: number }; hintSpan: { start: number, length: number }; bannerText: string; autoCollapse: boolean } [] = []; - */ - getOutliningSpans(fileName: string): string; - getTodoComments(fileName: string, todoCommentDescriptors: string): string; - getBraceMatchingAtPosition(fileName: string, position: number): string; - getIndentationAtPosition(fileName: string, position: number, options: string): string; - getFormattingEditsForRange(fileName: string, start: number, end: number, options: string): string; - getFormattingEditsForDocument(fileName: string, options: string): string; - getFormattingEditsAfterKeystroke(fileName: string, position: number, key: string, options: string): string; - /** - * Returns JSON-encoded value of the type TextInsertion. - */ - getDocCommentTemplateAtPosition(fileName: string, position: number): string; - /** - * Returns JSON-encoded boolean to indicate whether we should support brace location - * at the current position. - * E.g. we don't want brace completion inside string-literals, comments, etc. - */ - isValidBraceCompletionAtPosition(fileName: string, position: number, openingBrace: number): string; - /** - * Returns a JSON-encoded TextSpan | undefined indicating the range of the enclosing comment, if it exists. - */ - getSpanOfEnclosingComment(fileName: string, position: number, onlyMultiLine: boolean): string; - getEmitOutput(fileName: string): string; - getEmitOutputObject(fileName: string): EmitOutput; - } - interface ClassifierShim extends Shim { - getEncodedLexicalClassifications(text: string, lexState: EndOfLineState, syntacticClassifierAbsent?: boolean): string; - getClassificationsForLine(text: string, lexState: EndOfLineState, syntacticClassifierAbsent?: boolean): string; - } - interface CoreServicesShim extends Shim { - getAutomaticTypeDirectiveNames(compilerOptionsJson: string): string; - getPreProcessedFileInfo(fileName: string, sourceText: IScriptSnapshot): string; - getTSConfigFileInfo(fileName: string, sourceText: IScriptSnapshot): string; - getDefaultCompilationSettings(): string; - discoverTypings(discoverTypingsJson: string): string; - } - class LanguageServiceShimHostAdapter implements LanguageServiceHost { - private shimHost; - private loggingEnabled; - private tracingEnabled; - resolveModuleNames: ((moduleName: string[], containingFile: string) => (ResolvedModuleFull | undefined)[]) | undefined; - resolveTypeReferenceDirectives: ((typeDirectiveNames: string[], containingFile: string) => (ResolvedTypeReferenceDirective | undefined)[]) | undefined; - directoryExists: ((directoryName: string) => boolean) | undefined; - constructor(shimHost: LanguageServiceShimHost); - log(s: string): void; - trace(s: string): void; - error(s: string): void; - getProjectVersion(): string; - getTypeRootsVersion(): number; - useCaseSensitiveFileNames(): boolean; - getCompilationSettings(): CompilerOptions; - getScriptFileNames(): string[]; - getScriptSnapshot(fileName: string): IScriptSnapshot | undefined; - getScriptKind(fileName: string): ScriptKind; - getScriptVersion(fileName: string): string; - getLocalizedDiagnosticMessages(): any; - getCancellationToken(): HostCancellationToken; - getCurrentDirectory(): string; - getDirectories(path: string): string[]; - getDefaultLibFileName(options: CompilerOptions): string; - readDirectory(path: string, extensions?: ReadonlyArray, exclude?: string[], include?: string[], depth?: number): string[]; - readFile(path: string, encoding?: string): string | undefined; - fileExists(path: string): boolean; - } - class CoreServicesShimHostAdapter implements ParseConfigHost, ModuleResolutionHost, JsTyping.TypingResolutionHost { - private shimHost; - directoryExists: (directoryName: string) => boolean; - realpath: (path: string) => string; - useCaseSensitiveFileNames: boolean; - constructor(shimHost: CoreServicesShimHost); - readDirectory(rootDir: string, extensions: ReadonlyArray, exclude: ReadonlyArray, include: ReadonlyArray, depth?: number): string[]; - fileExists(fileName: string): boolean; - readFile(fileName: string): string | undefined; - getDirectories(path: string): string[]; - } - interface RealizedDiagnostic { - message: string; - start: number; - length: number; - category: string; - code: number; - reportsUnnecessary?: {}; - } - function realizeDiagnostics(diagnostics: ReadonlyArray, newLine: string): RealizedDiagnostic[]; - class TypeScriptServicesFactory implements ShimFactory { - private _shims; - private documentRegistry; - getServicesVersion(): string; - createLanguageServiceShim(host: LanguageServiceShimHost): LanguageServiceShim; - createClassifierShim(logger: Logger): ClassifierShim; - createCoreServicesShim(host: CoreServicesShimHost): CoreServicesShim; - close(): void; - registerShim(shim: Shim): void; - unregisterShim(shim: Shim): void; - } -} -declare namespace TypeScript.Services { - const TypeScriptServicesFactory: typeof ts.TypeScriptServicesFactory; -} -declare const toolsVersion = "3.7"; - -export = ts \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index dffb7865..26d86152 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,5 +1,27 @@ -import transformer from "./transformer"; + +/* ****************************************************************************************************************** * + * Transformer + * ****************************************************************************************************************** */ + +import { transformer } from './transform'; export default transformer; -export { TsTransformPathsConfig, TransformerExtras } from "./types"; -export { register } from "./register"; +/* ****************************************************************************************************************** * + * Types + * ****************************************************************************************************************** */ + +export * from "./types"; + +/* ****************************************************************************************************************** * + * Compatibility + * ****************************************************************************************************************** */ + +/** @internal */ +export { nodeRegister } from "./compatibility/node-register"; + +/* ****************************************************************************************************************** * + * Internal + * ****************************************************************************************************************** */ + +/** @internal — Used with compatibility scripts to confirm module is tstp */ +export const isTsTp = true; diff --git a/src/resolve/extensions.ts b/src/resolve/extensions.ts new file mode 100755 index 00000000..0d29e912 --- /dev/null +++ b/src/resolve/extensions.ts @@ -0,0 +1,23 @@ +import { extName } from "../utils"; + +/* ****************************************************************************************************************** * + * Locals + * ****************************************************************************************************************** */ + +const implicitExtensions = [ '.js', '.d.ts', '.ts' ]; + +/* ****************************************************************************************************************** */ +// region: Utils +/* ****************************************************************************************************************** */ + +export function isImplicitExtension(ext: string) { + return implicitExtensions.includes(ext); +} + +export function stripImplicitExtension(fileName: string) { + const ext = extName(fileName); + return isImplicitExtension(ext) ? fileName.slice(0, fileName.length - ext.length) : fileName; +} + +// endregion + diff --git a/src/resolve/index-checker.ts b/src/resolve/index-checker.ts new file mode 100755 index 00000000..71397f0c --- /dev/null +++ b/src/resolve/index-checker.ts @@ -0,0 +1,120 @@ +import type TS from "typescript"; +import fs from "fs"; +import { isImplicitExtension, stripImplicitExtension } from "./extensions"; +import { dirName, normalizePath, relativePath, resolvePath } from "../utils"; + +/* ****************************************************************************************************************** */ +// region: Types +/* ****************************************************************************************************************** */ + +export interface IndexDetail { + flags: IndexFlags + indexPath?: string +} + +export enum IndexFlags { + None, + Implicit = 1 << 0, + Package = 1 << 1, + Node = 1 << 2 +} + +type PackageIndexInfo = { packageIndex: string, packageDir: string } + +// endregion + + +/* ****************************************************************************************************************** * + * IndexChecker (class) + * ****************************************************************************************************************** */ + +/** @internal */ +export class IndexChecker { + private packageMap = new Map(); + + constructor(private _ts: typeof TS) {} + + checkBaseName(baseNameNoExt: string, ext: string | undefined, suppliedBaseNameNoExt: string): IndexDetail { + if (baseNameNoExt === 'index' && isImplicitExtension(ext!)) { + let flags = IndexFlags.Node; + if (suppliedBaseNameNoExt !== baseNameNoExt) flags |= IndexFlags.Implicit; + return { + indexPath: baseNameNoExt + (ext ?? ''), + flags + } + } + + return { flags: IndexFlags.None }; + } + + checkPackageFile( + fileName: string, + pathMatch: string | TS.Pattern | undefined, + moduleName: string, + suppliedPackageName: string | undefined, + suppliedPackagePath: string | undefined + ): IndexDetail { + const idx = this.getPackageIndexInfo(fileName); + + const fileNameStrippedExt = stripImplicitExtension(fileName); + const suppliedPathStrippedExt = suppliedPackagePath && stripImplicitExtension(suppliedPackagePath); + if (idx && stripImplicitExtension(idx.packageIndex) === fileNameStrippedExt) { + const { matchedText } = this._ts; + + let flags = IndexFlags.Package; + if (pathMatch && typeof pathMatch !== 'string' && !pathMatch?.suffix) { + let matchedStar = stripImplicitExtension(matchedText(pathMatch, moduleName)); + if (fileNameStrippedExt.slice(-matchedStar.length) !== matchedStar) flags |= IndexFlags.Implicit; + } else { + if (suppliedPackageName) + if (!suppliedPathStrippedExt || fileNameStrippedExt.slice(-suppliedPathStrippedExt.length) !== suppliedPathStrippedExt) + flags |= IndexFlags.Implicit; + } + + const indexPath = relativePath(idx.packageDir, idx.packageIndex); + return { flags, indexPath }; + } + + return { flags: IndexFlags.None }; + } + + getPackageIndexInfo(fileName: string): undefined | PackageIndexInfo { + fileName = normalizePath(fileName); + + /* Walk up dirs looking for package.json */ + let dir = dirName(fileName); + const pathStack: string[] = []; + while (true) { + pathStack.push(dir); + + if (this.packageMap.has(dir)) return this.packageMap.get(dir); + + const pkgFile = resolvePath(dir, 'package.json'); + if (fs.existsSync(pkgFile)) { + let packageIndex = 'index.js'; + try { + const { main } = JSON.parse(fs.readFileSync(pkgFile, 'utf8')); + if (main) packageIndex = main; + } catch (e) { + debugger; + throw e; + } + + packageIndex = resolvePath(dir, packageIndex); + + const res = { packageDir: dir, packageIndex }; + pathStack.forEach(p => this.packageMap.set(p, res)); + + return res; + } + + try { + const parentDir = resolvePath(dir, '..'); + if (parentDir === dir) break; + dir = parentDir; + } catch { + break; + } + } + } +} diff --git a/src/resolve/index.ts b/src/resolve/index.ts new file mode 100755 index 00000000..73d74a26 --- /dev/null +++ b/src/resolve/index.ts @@ -0,0 +1 @@ +export { resolvePathAndUpdateNode } from './resolve-path-update-node' diff --git a/src/resolve/output-path-detail.ts b/src/resolve/output-path-detail.ts new file mode 100755 index 00000000..94a87973 --- /dev/null +++ b/src/resolve/output-path-detail.ts @@ -0,0 +1,123 @@ +import { Pattern, ResolvedModuleFull } from "typescript"; +import { baseName, extName, joinPaths, normalizeSlashes, removeSuffix } from "../utils"; +import { VisitorContext } from "../types"; +import { IndexDetail } from "./index-checker"; + +/* ****************************************************************************************************************** */ +// region: Types +/* ****************************************************************************************************************** */ + +export interface OutputPathDetail { + isImplicitExtension: boolean; + isExternalLibraryImport: boolean; + resolvedExt: string | undefined; + resolvedPath: string; + suppliedExt: string | undefined; + /** Package name from package.json */ + packageName?: string; + /** Package name as written (could differ due to npm aliasing) */ + suppliedPackageName?: string; + suppliedPackagePath?: string; + packageRoot?: string; + packageFileName?: string; + tsPathsKey?: string; + indexDetail: IndexDetail +} + +// endregion + +/* ****************************************************************************************************************** */ +// region: Helpers +/* ****************************************************************************************************************** */ + +const pkgRegex = /^((?:@[^/]+\/)?[^/@]+)(?:\/([^@]+?))?$/; + +function getSuppliedPackageInfo(moduleName: string | undefined) { + if (!moduleName) return void 0; + const { 1: suppliedPackageName, 2: suppliedPackagePath } = pkgRegex.exec(moduleName)!; + return { suppliedPackageName, suppliedPackagePath }; +} + +function getTsPathMatch(match: string | Pattern): string { + return typeof match === 'string' ? match : [match.prefix, match.suffix].join('*'); +} + +// endregion + +/* ****************************************************************************************************************** */ +// region: Utils +/* ****************************************************************************************************************** */ + +/** @internal — Uses internal TS type */ +export function getOutputPathDetail( + context: VisitorContext, + moduleName: string, + resolvedModule: ResolvedModuleFull, + pathMatch: string | Pattern | undefined +): OutputPathDetail { + const { indexChecker } = context; + + /* Get paths */ + moduleName = normalizeSlashes(moduleName, { removeTrailingSlash: true }); + let suppliedExtName = extName(moduleName); + let suppliedBaseName = baseName(moduleName); + let suppliedBaseNameNoExt = removeSuffix(suppliedBaseName, suppliedExtName); + + const resolvedFileName = resolvedModule.originalPath ?? resolvedModule.resolvedFileName; + const resolvedExtName = extName(resolvedFileName); + const resolvedBaseName = baseName(resolvedFileName); + const resolvedBaseNameNoExt = removeSuffix(resolvedBaseName, resolvedExtName); + + const { isExternalLibraryImport, packageId } = resolvedModule; + const packageName = packageId?.name; + const packageRoot = packageId && indexChecker.getPackageIndexInfo(resolvedFileName)!.packageDir; + const packageFileName = packageId && joinPaths(packageRoot, packageId.subModuleName); + const packageExtName = packageFileName && extName(packageFileName); + const packageBaseName = packageFileName && baseName(packageFileName); + const packageBaseNameNoExt = packageBaseName && removeSuffix(packageBaseName, packageExtName!); + + const effectiveFileName = packageFileName || resolvedFileName; + const effectiveBaseNameNoExt = packageBaseNameNoExt || resolvedBaseNameNoExt; + const effectiveExtName = packageExtName || resolvedExtName; + + // Detect and fix invalid extname due to implicit ext (ie. `file.accounting.ts` could decide `accounting` is the extension) + if (suppliedExtName && effectiveBaseNameNoExt && effectiveBaseNameNoExt === suppliedBaseName) { + suppliedBaseNameNoExt = suppliedBaseName; + suppliedExtName = ''; + } + + /* Get Extras */ + const isImplicitExtension = !suppliedExtName && !!effectiveExtName; + + let suppliedPackageName: string | undefined; + let suppliedPackagePath: string | undefined; + if (packageName) { + const pkgInfo = getSuppliedPackageInfo(moduleName); + suppliedPackageName = pkgInfo?.suppliedPackageName; + suppliedPackagePath = pkgInfo?.suppliedPackagePath; + } + + const tsPathsKey = pathMatch && getTsPathMatch(pathMatch); + + /* Get IndexDetail */ + const indexDetail = packageId + ? indexChecker.checkPackageFile(effectiveFileName, pathMatch, moduleName, suppliedPackageName, suppliedPackagePath) + : indexChecker.checkBaseName(effectiveBaseNameNoExt, effectiveExtName, suppliedBaseNameNoExt); + + return { + isImplicitExtension, + isExternalLibraryImport: !!isExternalLibraryImport, + resolvedExt: effectiveExtName, + suppliedExt: suppliedExtName, + resolvedPath: effectiveFileName, + tsPathsKey, + packageRoot, + packageName, + suppliedPackagePath, + suppliedPackageName, + packageFileName, + indexDetail + }; +} + +// endregion diff --git a/src/resolve/resolve-module-name.ts b/src/resolve/resolve-module-name.ts new file mode 100755 index 00000000..e3ae27c5 --- /dev/null +++ b/src/resolve/resolve-module-name.ts @@ -0,0 +1,234 @@ +import { ResolutionContext, VisitorContext } from "../types"; +import { + baseName, dirName, isBaseDir, isURL, joinPaths, maybeAddRelativeLocalPrefix, normalizeSlashes, relativePath, + removeSuffix +} from "../utils"; +import { getOutputExtension, Node, Pattern, removeFileExtension, ResolvedModuleFull, SourceFile } from "typescript"; +import { getOutputPathForSourceFile } from "../ts"; +import { getOutputPathDetail, OutputPathDetail } from "./output-path-detail"; +import { IndexFlags } from "./index-checker"; + +/* ****************************************************************************************************************** */ +// region: Types +/* ****************************************************************************************************************** */ + +export interface ResolvedModule { + fullResolvedPath?: string; + outputPath: string; +} + +interface GetReturnPathContext { + visitorContext: VisitorContext; + node: Node; + moduleName: string; + pathDetail?: OutputPathDetail; + resolvedModule?: ResolvedModuleFull; + resolvedSourceFile?: SourceFile; + isURL?: boolean; + outputPath: string; +} + +// endregion + +/* ****************************************************************************************************************** */ +// region: Helpers +/* ****************************************************************************************************************** */ + +function getResolvedSourceFile(context: VisitorContext, fileName: string): SourceFile { + let res: SourceFile | undefined; + const { program, tsInstance } = context; + + if (program) { + /* Attempt to directly pull from Program */ + res = program.getSourceFile(fileName) as SourceFile; + if (res) return res; + + /* Attempt to find without extension */ + res = (program.getSourceFiles() as SourceFile[]).find( + (s) => removeFileExtension(s.fileName) === removeFileExtension(fileName) + ); + if (res) return res; + } + + /* + * Create basic synthetic SourceFile for use with compiler API - Applies if SourceFile not found in program due to + * import being added by another transformer + */ + return tsInstance.createSourceFile(fileName, ``, tsInstance.ScriptTarget.ESNext, /* setParentNodes */ false); +} + +function getReturnPath(ctx: GetReturnPathContext) { + const { pathDetail, resolvedSourceFile } = ctx; + const { + resolver, + config: { outputExtensions, outputIndexes }, + compilerOptions, + } = ctx.visitorContext; + const { suppliedExt, resolvedPath, isImplicitExtension, indexDetail, isExternalLibraryImport } = ctx.pathDetail ?? {}; + + let res = ctx.outputPath; + + let outputExt: string | undefined; + if (pathDetail) { + outputExt = + !isImplicitExtension && outputExtensions !== 'never' + ? suppliedExt + : outputExtensions === 'always' + ? getOutputExtension(resolvedSourceFile!, compilerOptions) + : void 0; + + let usesStrippedIndex = false; + if (indexDetail && indexDetail.flags & ~IndexFlags.None) + if ( + (indexDetail.flags & IndexFlags.Implicit && outputIndexes !== 'always') || + (indexDetail.flags & ~IndexFlags.Implicit && outputIndexes === 'never') + ) { + const indexPath = isExternalLibraryImport + ? baseName(indexDetail.indexPath!, true) + : normalizeSlashes(removeFileExtension(indexDetail.indexPath!), { removeTrailingSlash: true }); + res = normalizeSlashes(removeSuffix(res, indexPath), { removeTrailingSlash: true }); + usesStrippedIndex = true; + } + + if (!usesStrippedIndex) res += outputExt ?? ''; + } + + if (resolver) { + const { moduleName, node, visitorContext, isURL, resolvedModule } = ctx; + const { resolvedFileName, originalPath } = resolvedModule ?? {}; + const { packageName, suppliedPackageName, tsPathsKey, packageFileName, isExternalLibraryImport } = ctx.pathDetail ?? {}; + + const resolutionContext: ResolutionContext = { + moduleExtName: suppliedExt, + moduleName, + tsPathsKey, + isURL: !!isURL, + ...(packageName && { + package: { + packageName, + originalPackageName: suppliedPackageName, + isExternalLibrary: isExternalLibraryImport!, + }, + }), + ...(pathDetail && { + target: { + indexDetail: indexDetail!, + packagePath: packageFileName, + resolvedFilePath: resolvedFileName!, + originalPath, + sourceFile: resolvedSourceFile, + }, + }), + outputPath: res, + outputExt, + node, + visitorContext, + }; + + const resolverRes = resolver(resolutionContext); + return !resolverRes ? void 0 : { outputPath: resolverRes }; + } + + return { fullResolvedPath: resolvedPath, outputPath: res }; +} + +// endregion + +/* ****************************************************************************************************************** */ +// region: Utils +/* ****************************************************************************************************************** */ + +/** + * Resolve a module name + * @internal — Uses internal TS type + */ +export function resolveModuleName( + context: VisitorContext, + node: Node, + moduleName: string, + pathMatch: string | Pattern | undefined +): ResolvedModule | undefined { + const { tsInstance, compilerOptions, sourceFile, config, rootDirs } = context; + const { removeFileExtension } = tsInstance; + + // Attempt to resolve with TS Compiler API + const { resolvedModule, failedLookupLocations } = tsInstance.resolveModuleName( + moduleName, + sourceFile.fileName, + compilerOptions, + tsInstance.sys + ); + + // Handle non-resolvable module + if (!resolvedModule) { + const maybeURL = failedLookupLocations[0]; + const pathIsUrl = isURL(maybeURL); + + if (pathIsUrl && !context.resolver) return { outputPath: maybeURL }; + return getReturnPath({ + moduleName, + visitorContext: context, + node, + isURL: pathIsUrl, + outputPath: pathIsUrl ? maybeURL : moduleName, + }); + } + + const resolvedSourceFile = getResolvedSourceFile(context, resolvedModule.resolvedFileName); + const pathDetail = getOutputPathDetail(context, moduleName, resolvedModule, pathMatch); + + const { isExternalLibraryImport, resolvedPath, resolvedExt } = pathDetail; + + // External packages without a paths match should be be relative to package specifier + if (isExternalLibraryImport && !pathMatch) { + const { suppliedPackageName, suppliedPackagePath, indexDetail } = pathDetail; + + let outputPath = joinPaths(suppliedPackageName, suppliedPackagePath && removeFileExtension(suppliedPackagePath)); + if (indexDetail.flags & IndexFlags.Implicit) outputPath = joinPaths(outputPath, baseName(indexDetail.indexPath!, true)); + + return getReturnPath({ + moduleName, + node, + visitorContext: context, + resolvedModule, + resolvedSourceFile, + pathDetail, + outputPath + }); + } + + /* Determine output dirs */ + let srcFileOutputDir = dirName(getOutputPathForSourceFile(context, sourceFile)); + let moduleFileOutputDir = dirName(getOutputPathForSourceFile(context, resolvedSourceFile)); + + // Handle rootDirs remapping + if (config.useRootDirs && rootDirs) { + let fileRootDir = ''; + let moduleRootDir = ''; + for (const rootDir of rootDirs) { + if (isBaseDir(rootDir, moduleFileOutputDir) && rootDir.length > moduleRootDir.length) moduleRootDir = rootDir; + if (isBaseDir(rootDir, srcFileOutputDir) && rootDir.length > fileRootDir.length) fileRootDir = rootDir; + } + + /* Remove base dirs to make relative to root */ + if (fileRootDir && moduleRootDir) { + srcFileOutputDir = relativePath(fileRootDir, srcFileOutputDir); + moduleFileOutputDir = relativePath(moduleRootDir, moduleFileOutputDir); + } + } + + const outputDir = relativePath(srcFileOutputDir, moduleFileOutputDir); + const outputPath = maybeAddRelativeLocalPrefix(joinPaths(outputDir, baseName(resolvedPath, resolvedExt))); + + return getReturnPath({ + moduleName, + node, + visitorContext: context, + resolvedModule, + resolvedSourceFile, + pathDetail, + outputPath, + }); +} + +// endregion diff --git a/src/utils/resolve-path-update-node.ts b/src/resolve/resolve-path-update-node.ts similarity index 62% rename from src/utils/resolve-path-update-node.ts rename to src/resolve/resolve-path-update-node.ts index 81285950..56dcd399 100755 --- a/src/utils/resolve-path-update-node.ts +++ b/src/resolve/resolve-path-update-node.ts @@ -1,24 +1,24 @@ -import ts from "typescript"; +import type TS from "typescript"; import { VisitorContext } from "../types"; -import { isURL, maybeAddRelativeLocalPrefix } from "./general-utils"; -import { getTsPathsMatch } from "./ts-helpers"; +import { isURL, maybeAddRelativeLocalPrefix, normalizePath } from "../utils"; import { resolveModuleName } from "./resolve-module-name"; +import { getTsPathsMatch } from "../ts"; -/* ****************************************************************************************************************** */ -// region: Node Updater Utility -/* ****************************************************************************************************************** */ + +/* ****************************************************************************************************************** * + * Node Updater Util + * ****************************************************************************************************************** */ /** * Gets proper path and calls updaterFn to get the new node if it should be updated */ export function resolvePathAndUpdateNode( context: VisitorContext, - node: ts.Node, + node: TS.Node, moduleName: string, - updaterFn: (newPath: ts.StringLiteral) => ts.Node | undefined -): ts.Node | undefined { - const { sourceFile, tsInstance, factory, outputMode } = context; - const { normalizePath } = tsInstance; + updaterFn: (newPath: TS.StringLiteral) => TS.Node | undefined +): TS.Node | undefined { + const { sourceFile, tsInstance, factory, config: { outputExtensions, outputIndexes, usePaths } } = context; /* Handle JSDoc statement tags */ const tags = getStatementTags(); @@ -31,24 +31,27 @@ export function resolvePathAndUpdateNode( const transformedPath = !isURL(tags.overridePath) ? maybeAddRelativeLocalPrefix(normalizePath(tags.overridePath)) : tags.overridePath; + return updaterFn(factory.createStringLiteral(transformedPath)); } - /* Resolve Module */ - const pathsMatch = getTsPathsMatch(context, moduleName); + // Check for tsconfig paths match + const pathsMatch = usePaths ? getTsPathsMatch(context, moduleName) : undefined; - // Don't process if not necessary - if (!pathsMatch && !context.resolver && outputMode !== "esm") return node; + // Skip if possible + const canSkip = !pathsMatch && !context.resolver && outputIndexes !== "always" && outputExtensions !== "always"; + if (canSkip) return node; + // Resolve const res = resolveModuleName(context, node, moduleName, pathsMatch); if (!res) return node; - const { outputPath, resolvedPath } = res; + const { outputPath, fullResolvedPath } = res; /* Skip if matches exclusion */ - if (resolvedPath && context.excludeMatchers) + if (fullResolvedPath && context.excludeMatchers) for (const matcher of context.excludeMatchers) - if (matcher.match(outputPath) || (resolvedPath && matcher.match(resolvedPath))) return node; + if (matcher.match(outputPath) || (fullResolvedPath && matcher.match(fullResolvedPath))) return node; return updaterFn(factory.createStringLiteral(outputPath)); @@ -62,7 +65,7 @@ export function resolvePathAndUpdateNode( : tsInstance.findAncestor(node, tsInstance.isStatement) ?? node; targetNode = tsInstance.getOriginalNode(targetNode); - let jsDocTags: readonly ts.JSDocTag[] | undefined; + let jsDocTags: readonly TS.JSDocTag[] | undefined; try { jsDocTags = tsInstance.getJSDocTags(targetNode); } catch {} @@ -90,23 +93,7 @@ export function resolvePathAndUpdateNode( for (const tag of jsDocTags) { const tagName = tag.tagName.text.toLowerCase(); if (tagName === expected) return typeof tag.comment === "string" ? tag.comment : true; - - /* The following handles older TS which splits tags at first hyphens */ - if (typeof tag.comment !== "string" || tag.comment[0] !== "-") continue; - - const dashPos = expected.indexOf("-"); - if (dashPos < 0) return void 0; - - if (tagName === expected.slice(0, dashPos)) { - const comment = tag.comment; - const choppedCommentTagName = comment.slice(0, expected.length - dashPos); - return choppedCommentTagName === expected.slice(dashPos) - ? comment.slice(choppedCommentTagName.length + 1).trim() || true - : void 0; - } } } } } - -// endregion diff --git a/src/utils/elide-import-export.ts b/src/transform/elide-import-export.ts similarity index 98% rename from src/utils/elide-import-export.ts rename to src/transform/elide-import-export.ts index e0ac719c..5d38d37b 100755 --- a/src/utils/elide-import-export.ts +++ b/src/transform/elide-import-export.ts @@ -1,5 +1,5 @@ /** - * This file and its contents are due to an issue in TypeScript (affecting *at least* up to 4.1) which causes type + * This file and its contents are due to an issue in TypeScript (affecting *at least* up to 4.5) which causes type * elision to break during emit for nodes which have been transformed. Specifically, if the 'original' property is set, * elision functionality no longer works. * @@ -29,7 +29,7 @@ * export { A } from './b' */ import { ImportOrExportClause, ImportOrExportDeclaration, VisitorContext } from "../types"; -import { +import type { ExportDeclaration, ExportSpecifier, ImportClause, @@ -50,6 +50,7 @@ import { * See notes in get-import-export-clause.ts header for why this is necessary * * @returns import or export clause or undefined if it entire declaration should be elided + * @internal */ export function elideImportOrExportClause( context: VisitorContext, diff --git a/src/transform/index.ts b/src/transform/index.ts new file mode 100755 index 00000000..52d675ea --- /dev/null +++ b/src/transform/index.ts @@ -0,0 +1 @@ +export { transformer } from './transformer' diff --git a/src/transform/transformer.ts b/src/transform/transformer.ts new file mode 100755 index 00000000..b961f1b2 --- /dev/null +++ b/src/transform/transformer.ts @@ -0,0 +1,168 @@ +import path from 'path'; +import type TS from 'typescript'; +import { + ManualTransformOptions, + PathResolver, + TransformerConfig, + TransformerContext, + TransformerExtras, + TransformerOptions, + VisitorContext, +} from '../types'; +import { nodeVisitor } from './visitor'; +import { checkTsSupport, createHarmonyFactory, createSyntheticEmitHost, getTsNodeRegistrationProperties } from "../ts"; +import { Minimatch } from 'minimatch'; +import { IndexChecker } from "../resolve/index-checker"; + +/* ****************************************************************************************************************** */ +// region: Helpers +/* ****************************************************************************************************************** */ + +function getTsDetail(p: { + program: TS.Program | undefined; + extras: TransformerExtras | undefined; + manualTransformOptions: ManualTransformOptions | undefined; + transformationContext: TS.TransformationContext; +}) { + let tsInstance: typeof TS; + let compilerOptions: TS.CompilerOptions; + let fileNames: readonly string[] | undefined; + let isTranspileOnly = false; + let isTsNode = false; + + const { program, extras, manualTransformOptions, transformationContext } = p; + + tsInstance = extras?.ts ?? require('typescript'); + checkTsSupport(tsInstance); + + compilerOptions = manualTransformOptions?.compilerOptions!; + + /* Handle ts-node */ + const tsNodeProps = getTsNodeRegistrationProperties(tsInstance); + if (tsNodeProps) isTsNode = true; + + /* Fixup options based on transform type */ + if (program) { + compilerOptions ??= Object.assign({}, program.getCompilerOptions(), tsNodeProps?.compilerOptions); + } else if (manualTransformOptions) { + fileNames = manualTransformOptions.fileNames; + } else { + if (!tsNodeProps) + throw new Error( + `Cannot transform without a Program, ts-node instance, or manual parameters supplied. ` + + `Make sure you're using ts-patch or ts-node with transpileOnly.` + ); + isTranspileOnly = true; + compilerOptions = tsNodeProps.compilerOptions; + fileNames = tsNodeProps.fileNames; + } + + /* Get EmitHost */ + const getCanonicalFileName = tsInstance.createGetCanonicalFileName(tsInstance.sys.useCaseSensitiveFileNames); + + let emitHost = transformationContext.getEmitHost(); + if (!emitHost || (isTsNode && isTranspileOnly)) { + if (!fileNames) + throw new Error( + `No EmitHost found and could not determine files to be processed. Please file an issue with a reproduction!` + ); + emitHost = createSyntheticEmitHost(compilerOptions, tsInstance, getCanonicalFileName, fileNames as string[]); + } + + const projectReferences = program?.getResolvedProjectReferences()?.map(r => r?.sourceFile); + + return { tsInstance, compilerOptions, fileNames, isTranspileOnly, isTsNode, emitHost, projectReferences }; +} + +function loadResolver(p: string): PathResolver { + const resolver = require(p).default; + if (typeof resolver !== 'function') + throw new Error(`Cannot load resolver! Resolver file must export a resolver function as default`); + + return resolver; +} + +/** @internal - Used by UT */ +export function getTransformerConfig(options?: TransformerOptions): TransformerConfig { + return { + ...options, + outputIndexes: options?.outputIndexes || 'auto', + outputExtensions: options?.outputExtensions || 'auto', + usePaths: options?.usePaths ?? true + }; +} + +// endregion + +/* ****************************************************************************************************************** */ +// region: Transformer +/* ****************************************************************************************************************** */ + +export function transformer( + program?: TS.Program, + options?: TransformerOptions, + extras?: TransformerExtras, + /** + * Supply if manually transforming with compiler API via 'transformNodes' / 'transformModule' + */ + manualTransformOptions?: ManualTransformOptions +) { + return (transformationContext: TS.TransformationContext) => { + const config = getTransformerConfig(options); + const { tsInstance, compilerOptions, isTranspileOnly, isTsNode, emitHost } = getTsDetail( + { + program, + extras, + manualTransformOptions, + transformationContext, + } + ); + + const rootDirs = compilerOptions.rootDirs?.filter(path.isAbsolute); + const { configFile, paths } = compilerOptions; + const resolver = config.resolver ? loadResolver(config.resolver) : void 0; + + // Older TS does not have this, so we type it accordingly to determine path parse method + const tryParsePatterns: typeof TS.tryParsePatterns | undefined = tsInstance.tryParsePatterns; + + const tsTransformPathsContext: TransformerContext = { + compilerOptions, + config, + elisionMap: new Map(), + tsFactory: transformationContext.factory, + program, + rootDirs, + transformationContext: transformationContext, + tsInstance, + emitHost, + resolver, + isTranspileOnly, + isTsNode, + indexChecker: new IndexChecker(tsInstance), + excludeMatchers: config.exclude?.map((globPattern) => new Minimatch(globPattern, { matchBase: true })), + outputFileNamesCache: new Map(), + pathsPatterns: + paths && + (tryParsePatterns + ? configFile?.configFileSpecs?.pathPatterns || tryParsePatterns(paths) + : tsInstance.getOwnKeys(paths)), + }; + + return (sourceFile: TS.SourceFile) => { + const visitorContext: VisitorContext = { + ...tsTransformPathsContext, + sourceFile, + isDeclarationFile: sourceFile.isDeclarationFile, + originalSourceFile: (tsInstance).getOriginalSourceFile(sourceFile), + getVisitor() { + return nodeVisitor.bind(this); + }, + factory: createHarmonyFactory(tsInstance, transformationContext.factory), + }; + + return tsInstance.visitEachChild(sourceFile, visitorContext.getVisitor(), transformationContext); + }; + }; +} + +// endregion diff --git a/src/visitor.ts b/src/transform/visitor.ts similarity index 72% rename from src/visitor.ts rename to src/transform/visitor.ts index 4b56bb2b..a3bdd440 100755 --- a/src/visitor.ts +++ b/src/transform/visitor.ts @@ -1,18 +1,20 @@ -import ts from "typescript"; -import { VisitorContext } from "./types"; -import { elideImportOrExportClause, resolvePathAndUpdateNode } from "./utils"; +import type TS from "typescript"; +import { VisitorContext } from "../types"; +import { elideImportOrExportClause } from "./elide-import-export"; +import { resolvePathAndUpdateNode } from "../resolve"; +import { copyNodeComments } from '../ts'; /* ****************************************************************************************************************** * * Helpers * ****************************************************************************************************************** */ -const isAsyncImport = ({ tsInstance }: VisitorContext, node: ts.Node): node is ts.CallExpression => +const isAsyncImport = ({ tsInstance }: VisitorContext, node: TS.Node): node is TS.CallExpression => tsInstance.isCallExpression(node) && node.expression.kind === tsInstance.SyntaxKind.ImportKeyword && tsInstance.isStringLiteral(node.arguments[0]) && node.arguments.length === 1; -const isRequire = ({ tsInstance }: VisitorContext, node: ts.Node): node is ts.CallExpression => +const isRequire = ({ tsInstance }: VisitorContext, node: TS.Node): node is TS.CallExpression => tsInstance.isCallExpression(node) && tsInstance.isIdentifier(node.expression) && node.expression.text === "require" && @@ -26,8 +28,8 @@ const isRequire = ({ tsInstance }: VisitorContext, node: ts.Node): node is ts.Ca /** * Visit and replace nodes with module specifiers */ -export function nodeVisitor(this: VisitorContext, node: ts.Node): ts.Node | undefined { - const { factory, tsInstance, transformationContext } = this; +export function nodeVisitor(this: VisitorContext, node: TS.Node): TS.Node | undefined { + const { factory, tsInstance, transformationContext, sourceFile } = this; /** * Update require / import functions @@ -36,30 +38,13 @@ export function nodeVisitor(this: VisitorContext, node: ts.Node): ts.Node | unde * import('module') */ if (isRequire(this, node) || isAsyncImport(this, node)) - return resolvePathAndUpdateNode(this, node, (node.arguments[0]).text, (p) => { + return resolvePathAndUpdateNode(this, node, (node.arguments[0]).text, (p) => { const res = factory.updateCallExpression(node, node.expression, node.typeArguments, [p]); - /* Handle comments */ + /* Copy inner comments */ const textNode = node.arguments[0]; - const commentRanges = tsInstance.getLeadingCommentRanges(textNode.getFullText(), 0) || []; - - for (const range of commentRanges) { - const { kind, pos, end, hasTrailingNewLine } = range; - - const caption = textNode - .getFullText() - .substr(pos, end) - .replace( - /* searchValue */ kind === tsInstance.SyntaxKind.MultiLineCommentTrivia - ? // Comment range in a multi-line comment with more than one line erroneously - // includes the node's text in the range. For that reason, we use the greedy - // selector in capture group and dismiss anything after the final comment close tag - /^\/\*(.+)\*\/.*/s - : /^\/\/(.+)/s, - /* replaceValue */ "$1" - ); - tsInstance.addSyntheticLeadingComment(p, kind, caption, hasTrailingNewLine); - } + copyNodeComments(tsInstance, sourceFile, textNode, p); + return res; }); @@ -79,7 +64,7 @@ export function nodeVisitor(this: VisitorContext, node: ts.Node): ts.Node | unde * typeof import("./bar"); */ if (tsInstance.isImportTypeNode(node)) { - const argument = node.argument as ts.LiteralTypeNode; + const argument = node.argument as TS.LiteralTypeNode; if (!tsInstance.isStringLiteral(argument.literal)) return node; const { text } = argument.literal; diff --git a/src/transformer.ts b/src/transformer.ts deleted file mode 100755 index a3d36a3e..00000000 --- a/src/transformer.ts +++ /dev/null @@ -1,139 +0,0 @@ -// noinspection ES6UnusedImports -import {} from "ts-expose-internals"; -import path from "path"; -import ts from "typescript"; -import { TransformerExtras, TsTransformPathsConfig, TsTransformPathsContext, VisitorContext } from "./types"; -import { nodeVisitor } from "./visitor"; -import { createHarmonyFactory } from "./utils/harmony-factory"; -import { Minimatch } from "minimatch"; -import { createSyntheticEmitHost, getTsNodeRegistrationProperties } from "./utils/ts-helpers"; - - -/* ****************************************************************************************************************** */ -// region: Helpers -/* ****************************************************************************************************************** */ - -function getTsProperties(args: Parameters) { - let tsInstance: typeof ts; - let compilerOptions: ts.CompilerOptions; - let fileNames: readonly string[] | undefined; - let isTranspileOnly = false; - let isTsNode = false; - - const [program, pluginConfig, extras, manualTransformOptions] = args; - - tsInstance = extras?.ts ?? ts; - compilerOptions = manualTransformOptions?.compilerOptions!; - const config = { - ...pluginConfig, - outputMode: pluginConfig?.outputMode === "esm" ? "esm" : "commonjs", - }; - - const tsNodeProps = getTsNodeRegistrationProperties(tsInstance); - if (tsNodeProps) isTsNode = true; - - if (program) { - compilerOptions ??= Object.assign({}, program.getCompilerOptions(), tsNodeProps?.compilerOptions); - } else if (manualTransformOptions) { - fileNames = manualTransformOptions.fileNames; - } else { - if (!tsNodeProps) - throw new Error( - `Cannot transform without a Program, ts-node instance, or manual parameters supplied. ` + - `Make sure you're using ts-patch or ts-node with transpileOnly.` - ); - isTranspileOnly = true; - compilerOptions = tsNodeProps.compilerOptions; - fileNames = tsNodeProps.fileNames; - } - - return { tsInstance, compilerOptions, fileNames, isTranspileOnly, config, isTsNode }; -} - -// endregion - -/* ****************************************************************************************************************** */ -// region: Transformer -/* ****************************************************************************************************************** */ - -export default function transformer( - program?: ts.Program, - pluginConfig?: TsTransformPathsConfig, - transformerExtras?: TransformerExtras, - /** - * Supply if manually transforming with compiler API via 'transformNodes' / 'transformModule' - */ - manualTransformOptions?: { - compilerOptions?: ts.CompilerOptions; - fileNames?: string[]; - } -) { - return (transformationContext: ts.TransformationContext) => { - // prettier-ignore - const { - tsInstance, - compilerOptions, - fileNames, - isTranspileOnly, - isTsNode, - config - } = getTsProperties([ program, pluginConfig, transformerExtras, manualTransformOptions ]); - - const rootDirs = compilerOptions.rootDirs?.filter(path.isAbsolute); - const getCanonicalFileName = tsInstance.createGetCanonicalFileName(tsInstance.sys.useCaseSensitiveFileNames); - - let emitHost = transformationContext.getEmitHost(); - if (!emitHost) { - if (!fileNames) - throw new Error( - `No EmitHost found and could not determine files to be processed. Please file an issue with a reproduction!` - ); - emitHost = createSyntheticEmitHost(compilerOptions, tsInstance, getCanonicalFileName, fileNames as string[]); - } else if (isTranspileOnly) { - Object.assign(emitHost, { getCompilerOptions: () => compilerOptions }); - } - - const { configFile, paths } = compilerOptions; - const tryParsePatterns: typeof ts.tryParsePatterns | undefined = tsInstance.tryParsePatterns; - - const tsTransformPathsContext: TsTransformPathsContext = { - compilerOptions, - config, - elisionMap: new Map(), - tsFactory: transformationContext.factory, - program, - rootDirs, - transformationContext, - tsInstance, - emitHost, - isTranspileOnly, - isTsNode, - excludeMatchers: config.exclude?.map((globPattern) => new Minimatch(globPattern, { matchBase: true })), - outputFileNamesCache: new Map(), - // Get paths patterns appropriate for TS compiler version - pathsPatterns: - paths && - (tryParsePatterns - ? configFile?.configFileSpecs?.pathPatterns || tryParsePatterns(paths) - : tsInstance.getOwnKeys(paths)), - }; - - return (sourceFile: ts.SourceFile) => { - const visitorContext: VisitorContext = { - ...tsTransformPathsContext, - sourceFile, - isDeclarationFile: sourceFile.isDeclarationFile, - originalSourceFile: (tsInstance).getOriginalSourceFile(sourceFile), - getVisitor() { - return nodeVisitor.bind(this); - }, - factory: createHarmonyFactory(tsTransformPathsContext), - outputMode: config.outputMode === 'esm' && sourceFile.isDeclarationFile ? 'esm' : 'commonjs' - }; - - return tsInstance.visitEachChild(sourceFile, visitorContext.getVisitor(), transformationContext); - }; - }; -} - -// endregion diff --git a/src/ts/harmony-factory.ts b/src/ts/harmony-factory.ts new file mode 100755 index 00000000..4534d0a6 --- /dev/null +++ b/src/ts/harmony-factory.ts @@ -0,0 +1,98 @@ +import TS from "typescript"; + +/* ****************************************************************************************************************** */ +// region: Types +/* ****************************************************************************************************************** */ + +export interface HarmonyFactory extends TS.NodeFactory {} + +// endregion + +/* ****************************************************************************************************************** */ +// region: Utilities +/* ****************************************************************************************************************** */ + +// Leave this for now, as it serves as an example for when factory diverges again + +// function getTs3Prop(instance: typeof TsThree, prop: string | symbol) { +// switch (prop) { +// case "updateCallExpression": +// return (...args: any) => instance.updateCall.apply(void 0, args); +// case "updateImportClause": +// return function ( +// node: TsThree.ImportClause, +// isTypeOnly: boolean, +// name: TsThree.Identifier | undefined, +// namedBindings: TsThree.NamedImportBindings | undefined +// ) { +// return instance.updateImportClause(node, name, namedBindings); +// }; +// case "createImportClause": +// return function ( +// name: TsThree.Identifier | undefined, +// isTypeOnly: boolean, +// namedBindings: TsThree.NamedImportBindings | undefined +// ) { +// return instance.createImportClause(name, namedBindings); +// }; +// case "updateExportDeclaration": +// return function ( +// node: TsThree.ExportDeclaration, +// decorators: readonly TsThree.Decorator[] | undefined, +// modifiers: readonly TsThree.Modifier[] | undefined, +// isTypeOnly: boolean, +// exportClause: TsThree.NamedExports | undefined, +// moduleSpecifier: TsThree.Expression | undefined +// ) { +// return instance.updateExportDeclaration( +// node, +// node.decorators, +// node.modifiers, +// exportClause, +// moduleSpecifier, +// // @ts-ignore - This was added in later versions of 3.x +// node.isTypeOnly +// ); +// }; +// case "createExportDeclaration": +// return function ( +// decorators: readonly TsThree.Decorator[] | undefined, +// modifiers: readonly TsThree.Modifier[] | undefined, +// isTypeOnly: boolean, +// exportClause: TsThree.NamedExports | undefined, +// moduleSpecifier: TsThree.Expression | undefined +// ) { +// return instance.createExportDeclaration( +// decorators, +// modifiers, +// exportClause, +// moduleSpecifier, +// // @ts-ignore - This was added in later versions of 3.x +// isTypeOnly +// ); +// }; +// default: +// return (...args: any) => (instance)[prop](...args); +// } +// } + +/** + * Creates a factory capable of working with any TS version using modern parameters + */ +export function createHarmonyFactory(tsInstance: typeof TS, factory: TS.NodeFactory | undefined): HarmonyFactory { + const [ majorVer, minorVer ] = tsInstance.versionMajorMinor.split('.'); + + return new Proxy(factory ?? tsInstance, { + get(target, prop) { + // if (!factory) return getTs3Prop(cast(tsInstance), prop); + + // For 4.0 - 4.4 + if (+majorVer < 4 || +minorVer < 5) return (target)[prop]; + + // TODO - Handle 4.5 + return (target)[prop]; + }, + }) as HarmonyFactory; +} + +// endregion diff --git a/src/ts/index.ts b/src/ts/index.ts new file mode 100755 index 00000000..5bc466c9 --- /dev/null +++ b/src/ts/index.ts @@ -0,0 +1,2 @@ +export * from './harmony-factory' +export * from './ts-helpers' diff --git a/src/utils/ts-helpers.ts b/src/ts/ts-helpers.ts similarity index 54% rename from src/utils/ts-helpers.ts rename to src/ts/ts-helpers.ts index daa522bf..4526302a 100755 --- a/src/utils/ts-helpers.ts +++ b/src/ts/ts-helpers.ts @@ -1,4 +1,5 @@ -import ts, { GetCanonicalFileName, SourceFile } from "typescript"; +import TS from "typescript"; +import { GetCanonicalFileName, SourceFile } from "typescript"; import { VisitorContext } from "../types"; import type { REGISTER_INSTANCE } from "ts-node"; @@ -38,22 +39,11 @@ export function getOutputPathForSourceFile(context: VisitorContext, sourceFile: } /** - * Determine if moduleName matches config in paths - */ -export function getTsPathsMatch(context: VisitorContext, moduleName: string): string | ts.Pattern | undefined { - const { - pathsPatterns, - tsInstance: { matchPatternOrExact }, - } = context; - return pathsPatterns && matchPatternOrExact(pathsPatterns, moduleName); -} - -/** - * Create barebones EmitHost (for no-Program transform) + * Create barebones EmitHost (for no-Program / ts-node transform) */ export function createSyntheticEmitHost( - compilerOptions: ts.CompilerOptions, - tsInstance: typeof ts, + compilerOptions: TS.CompilerOptions, + tsInstance: typeof TS, getCanonicalFileName: GetCanonicalFileName, fileNames: string[] ) { @@ -62,17 +52,17 @@ export function createSyntheticEmitHost( getCurrentDirectory: tsInstance.sys.getCurrentDirectory, getCommonSourceDirectory: () => tsInstance.getCommonSourceDirectoryOfConfig( - { options: compilerOptions, fileNames: fileNames } as ts.ParsedCommandLine, + { options: compilerOptions, fileNames: fileNames } as TS.ParsedCommandLine, !tsInstance.sys.useCaseSensitiveFileNames ), getCanonicalFileName, - } as unknown as ts.EmitHost; + } as unknown as TS.EmitHost; } /** * Get ts-node register info */ -export function getTsNodeRegistrationProperties(tsInstance: typeof ts) { +export function getTsNodeRegistrationProperties(tsInstance: typeof TS) { let tsNodeSymbol: typeof REGISTER_INSTANCE; try { tsNodeSymbol = require("ts-node")?.["REGISTER_INSTANCE"]; @@ -92,7 +82,59 @@ export function getTsNodeRegistrationProperties(tsInstance: typeof ts) { const fileNames = pcl?.fileNames || config.fileNames; const compilerOptions = Object.assign(config.options, options.compilerOptions, { outDir: pcl?.options.outDir }); - return { compilerOptions, fileNames }; + return { compilerOptions, fileNames, tsNodeConfig: config }; +} + +/** + * Copies comment range from srcNode to destNode + */ +export function copyNodeComments(tsInstance: typeof TS, srcSourceFile: TS.SourceFile, srcNode: TS.Node, destNode: TS.Node) { + // TS has a bugs which cause getLeadingTriviaWidth & getLeadingCommentRanges to exceed the proper boundaries. + // This tends to happen in scenarios where there are more than one comment. + // - It often causes the final comment to include the full node text as well + // - Single line comments can be combined into single range (ie: `//comment1\n//comment2`) + // + // Otherwise, the proper method would be to use something like the following: + // const commentRanges = tsInstance.getLeadingCommentRanges(srcNode.getFullText(), 0); + // + // NOTE: If TS fixes this, we still cannot change the logic unless we no longer support the older versions with the bugs + // As of now, I have not filed nor was I able to find a bug report for this + + const fullText = srcNode.getFullText(srcSourceFile); + const commendEndPos = fullText.length - srcNode.getText(srcSourceFile).length; + const commentText = fullText.substr(0, commendEndPos); + + const commentRegex = /(?:\/\*([\s\S]*?)\*\/|\/\/([^\r\n]*))(\r?\n?)/gs; + + let match: RegExpExecArray | null; + while (match = commentRegex.exec(commentText)) { + const caption = match[1] || match[2]; + const isMultiLine = !!match[1]; + const hasTrailingNewLine = !!match[3]; + const kind = isMultiLine ? tsInstance.SyntaxKind.MultiLineCommentTrivia : tsInstance.SyntaxKind.SingleLineCommentTrivia; + + tsInstance.addSyntheticLeadingComment(destNode, kind, caption, hasTrailingNewLine); + } +} + +/** + * Determine if moduleName matches config in paths + */ +export function getTsPathsMatch(context: VisitorContext, moduleName: string): string | TS.Pattern | undefined { + const { + pathsPatterns, + tsInstance: { matchPatternOrExact }, + } = context; + return pathsPatterns && matchPatternOrExact(pathsPatterns, moduleName); +} + +/** + * Throw if unsupported version + */ +export function checkTsSupport(tsInstance: typeof TS) { + const [ major, minor ] = tsInstance.versionMajorMinor.split('.'); + if (+major < 4 || (+major === 4 && +minor < 2)) + throw new Error(`The latest version of 'typescript-transform-paths' requires TS version 4.2.2 or higher. Either upgrade TS or use v3 of the plugin.`); } // endregion diff --git a/src/types.ts b/src/types.ts index 39bbe3aa..5beac6c9 100755 --- a/src/types.ts +++ b/src/types.ts @@ -1,69 +1,300 @@ -import ts, { CompilerOptions, EmitHost, Pattern, SourceFile } from "typescript"; -import { HarmonyFactory } from "./utils/harmony-factory"; -import { IMinimatch } from "minimatch"; -import { RequireSome } from "./utils"; +import type TS from "typescript"; +import type { HarmonyFactory } from "./ts"; +import type { IMinimatch } from "minimatch"; +import { IndexChecker, IndexDetail } from "./resolve/index-checker"; /* ****************************************************************************************************************** */ -// region: TS Types +// region: Config /* ****************************************************************************************************************** */ -export type ImportOrExportDeclaration = ts.ImportDeclaration | ts.ExportDeclaration; -export type ImportOrExportClause = ts.ImportDeclaration["importClause"] | ts.ExportDeclaration["exportClause"]; -export type TransformerExtras = { - ts: typeof ts; +export interface TransformerConfig { + /** + * Automatically remap directories according to tsconfig.json -> `rootDirs` + * @default false + */ + readonly useRootDirs?: boolean; + + /** + * Transform using path mapping in tsconfig.json -> `paths` + * @default true + */ + readonly usePaths: boolean; + + /** + * Method for handling implicit indexes + * @example + * // File: './dir/index.ts' + * + * // Output: + * // 'auto': './dir' + * // 'always': './dir/index' + * // 'never': './dir' + * import './dir' + * + * // Output: + * // 'auto': './dir/index' + * // 'always': './dir/index' + * // 'never': './dir' + * import './dir/index' + * + * // Package: 'pkg' + * // Package `main` entry: 'dist/main.js' + * + * // Output: + * // 'auto': 'pkg' + * // 'always': 'pkg/dist/main.js' + * // 'never: 'pkg' + * import 'pkg'; + */ + readonly outputIndexes: 'auto' | 'always' | 'never' + + /** + * Method for handling implicit extensions + * @example + * // File: './dir/index.ts' + * + * // Output: + * // 'auto': './dir/index' + * // 'always': './dir/index.js' + * // 'never': './dir/index' + * import './dir/index' + * + * // Output: + * // 'auto': './dir/index.js' + * // 'always': './dir/index.js' + * // 'never': './dir/index' + * import './dir/index.js' + * + * // Output: + * // 'auto': './dir' + * // 'always': './dir' + * // 'never': './dir' + * import './dir' + */ + readonly outputExtensions: 'auto' | 'always' | 'never' + + /** + * Transform Exclusion patterns — exclude from transform if file path matches pattern + */ + readonly exclude?: string[]; + + /** + * Path to custom resolve middleware + */ + readonly resolver?: string; } // endregion /* ****************************************************************************************************************** */ -// region: Config +// region: Resolver /* ****************************************************************************************************************** */ -export interface TsTransformPathsConfig { - readonly useRootDirs?: boolean; - readonly exclude?: string[]; - readonly outputMode?: "commonjs" | "esm"; +export interface PathResolver { + (ctx: ResolutionContext): string | undefined +} + +export interface ResolutionContext { + /** + * Supplied module name + * + * @example + * // moduleName = 'typescript-transform-paths/dist/index' + * import './src/index'; + */ + moduleName: string + + /** + * Supplied module name's extension (if specified) + * + * @example + * // moduleExtName = undefined + * import './src/index'; + * // moduleExtName = '.ts' + * import './src/index.ts'; + */ + moduleExtName?: string + + /** + * This is the path that will normally be output by the plugin + */ + outputPath: string + + /** + * Extension for output path + */ + outputExt: string | undefined + + /** + * If there is a match from tsconfig.json -> 'compilerOptions' -> 'paths', the matched key name will be here + * @example + * // tsconfig.json + * { + * "compilerOptions": { + * "paths": { + * "#src/*": [ "./src/*" ] + * } + * } + * } + * + * // tsPathsKey = '#src/*' + * import '#src/hello'; + */ + tsPathsKey?: string + + /** + * True if target is a URL + */ + isURL: boolean + + /** + * Info on resolved target (not supplied if module can't be resolved to file) + */ + target?: { + /** + * If the resolved file is a symlink, this will be the initial resolved path (before following link) + */ + originalPath?: string + + /** + * Implicit index detail + */ + indexDetail: IndexDetail + + /** + * Final resolved file path (after following any symlink — for pre-follow, use `originalPath`) + */ + resolvedFilePath: string + + /** + * If module resolves to a sub-package within the current package or an external package, this is the sub-path within the package + * + * Note: This field is especially important with ESM, as it's possible for the import path not to correspond to the actual + * resolved file path. + */ + packagePath?: string + + /** + * Resolved ts.SourceFile + */ + sourceFile?: TS.SourceFile + } + + /** + * If the module resolves to a sub-package or external package, this contains that detail + */ + package?: { + /** + * Name of the package according to its package.json + * + * @example + * // packageName = '@scope/package' + * import '@scope/package/dist/index'; + */ + packageName: string + + /** + * Package name as specified + * Note: In some cases, a package may be aliased so that the name used to import/require it does not match the package.json + * If that is the case, the supplied name is here. + * + * @example + * // package.json + * { + * "dependencies": { + * "aliased-typescript": "npm:typescript@latest" + * } + * } + * + * // packageName = 'typescript' + * // originalPackageName = 'aliased-typescript' + * import 'aliased-typescript'; + */ + originalPackageName?: string + + isExternalLibrary: boolean + } + + /** + * Context for visitor + * @see https://github.com/LeDDGroup/typescript-transform-paths/blob/master/src/types.ts + */ + visitorContext: VisitorContext + + /** + * AST Node being transformed + */ + node: TS.Node } // endregion /* ****************************************************************************************************************** */ -// region: Contexts +// region: Transformer /* ****************************************************************************************************************** */ -export interface TsTransformPathsContext { - readonly tsInstance: typeof ts; - readonly tsFactory?: ts.NodeFactory; - readonly program?: ts.Program; - readonly config: RequireSome; - readonly compilerOptions: CompilerOptions; - readonly transformationContext: ts.TransformationContext; +export type TransformerOptions = Partial; + +export interface ManualTransformOptions { + compilerOptions?: TS.CompilerOptions; + fileNames?: string[]; +} + +export interface TransformerContext { + readonly tsInstance: typeof TS; + readonly tsFactory?: TS.NodeFactory; + readonly program?: TS.Program; + readonly config: TransformerConfig; + readonly compilerOptions: TS.CompilerOptions; + readonly transformationContext: TS.TransformationContext; readonly rootDirs?: string[]; readonly isTsNode: boolean; readonly isTranspileOnly: boolean; + readonly resolver?: PathResolver; /** @internal - Do not remove internal flag — this uses an internal TS type */ - readonly pathsPatterns: readonly (string | Pattern)[] | undefined; + readonly pathsPatterns: readonly (string | TS.Pattern)[] | undefined; /** @internal - Do not remove internal flag — this uses an internal TS type */ - readonly emitHost: EmitHost; + readonly emitHost: TS.EmitHost; /** @internal */ - readonly elisionMap: Map>; + indexChecker: IndexChecker + /** @internal */ + readonly elisionMap: Map>; /** @internal */ readonly excludeMatchers: IMinimatch[] | undefined; /** @internal */ - readonly outputFileNamesCache: Map; + readonly outputFileNamesCache: Map; } -export interface VisitorContext extends TsTransformPathsContext { +export interface VisitorContext extends TransformerContext { readonly factory: HarmonyFactory; - readonly sourceFile: ts.SourceFile; + readonly sourceFile: TS.SourceFile; readonly isDeclarationFile: boolean; - readonly originalSourceFile: ts.SourceFile; - readonly outputMode: 'esm' | 'commonjs'; + readonly originalSourceFile: TS.SourceFile; /** @internal */ - getVisitor(): (node: ts.Node) => ts.VisitResult; + getVisitor(): (node: TS.Node) => TS.VisitResult; } // endregion + +/* ****************************************************************************************************************** */ +// region: Internal / External / Deprecated +/* ****************************************************************************************************************** */ + +/** @deprecated - use TransformerOptions */ +export type TsTransformPathsConfig = TransformerOptions; + +/** Represents Extras type passed by ttypescript or ts-patch */ +export type TransformerExtras = { + ts: typeof TS; +} + +/** @internal */ +export type ImportOrExportDeclaration = TS.ImportDeclaration | TS.ExportDeclaration; + +/** @internal */ +export type ImportOrExportClause = TS.ImportDeclaration["importClause"] | TS.ExportDeclaration["exportClause"]; + +// endregion diff --git a/src/utils.ts b/src/utils.ts new file mode 100755 index 00000000..e15ce9a7 --- /dev/null +++ b/src/utils.ts @@ -0,0 +1,78 @@ +import path from "path"; +import url from 'url'; + +/* ****************************************************************************************************************** * + * TS Exports + * ****************************************************************************************************************** */ + +import { normalizePath } from 'typescript'; +export { removeFileExtension, isAnySupportedFileExtension, removeSuffix } from 'typescript'; +export { normalizePath }; + +/* ****************************************************************************************************************** */ +// region: General Utils +/* ****************************************************************************************************************** */ + +export const isURL = (s: string): boolean => !!s && (!!url.parse(s).host || !!url.parse(s).hostname); +export const cast = (v: any): T => v; +export const isBaseDir = (baseDir: string, testDir: string): boolean => { + const relative = path.relative(baseDir, testDir); + return relative ? !relative.startsWith("..") && !path.isAbsolute(relative) : true; +}; +export const maybeAddRelativeLocalPrefix = (p: string) => (p[0] === "." ? p : `./${p}`); + +// endregion + +/* ****************************************************************************************************************** */ +// region: Path Utils +/* ****************************************************************************************************************** */ + +/** + * Merge and normalize paths (preserves relative prefix – ie. `./my/path`) + */ +export function joinPaths(...paths: (string | undefined)[]): string { + // path.join / ts.normalizePath cannot be used here, because they remove relative prefix + return normalizePath((paths.filter(p => !!p) as string[]).join('/'))!; +} + +/** + * Normalize slashes in path + */ +export function normalizeSlashes(p: T, opt?: { removeLeadingSlash?: boolean, removeTrailingSlash?: boolean }): T { + if (!p) return p; + + let res = p.replace(/\\+|\/+/g, '/'); + + if (opt?.removeLeadingSlash && res[0] === '/') res = res.slice(1); + if (opt?.removeTrailingSlash && res[res.length-1] === '/') res = res.slice(0, res.length - 1); + + return res as T; +} + +/** + * Get extension for path (supports declaration style – ie. `d.ts`) + */ +export function extName(p: string) { + const res = path.extname(p); + const baseName = path.basename(p, res); + return baseName.slice(-2) === '.d' ? `.d${res}` : res; +} + +export function baseName(p: string, stripExtension: boolean | string = false) { + const ext = !stripExtension ? void 0 : (typeof stripExtension === 'string' ? stripExtension : extName(p)); + return path.basename(p, ext); +} + +export function resolvePath(...p: (string | undefined)[]): string { + return normalizePath(path.resolve(joinPaths(...p))) as string; +} + +export function dirName(p: string) { + return normalizePath(path.dirname(p)); +} + +export function relativePath(from: string, to: string) { + return normalizePath(path.relative(from, to)); +} + +// endregion diff --git a/src/utils/general-utils.ts b/src/utils/general-utils.ts deleted file mode 100755 index 73cba2f5..00000000 --- a/src/utils/general-utils.ts +++ /dev/null @@ -1,16 +0,0 @@ -import url from "url"; -import path from "path"; - -/* ****************************************************************************************************************** * - * General Utilities & Helpers - * ****************************************************************************************************************** */ - -export const isURL = (s: string): boolean => !!s && (!!url.parse(s).host || !!url.parse(s).hostname); -export const cast = (v: any): T => v; -export const isBaseDir = (baseDir: string, testDir: string): boolean => { - const relative = path.relative(baseDir, testDir); - return relative ? !relative.startsWith("..") && !path.isAbsolute(relative) : true; -}; -export const maybeAddRelativeLocalPrefix = (p: string) => (p[0] === "." ? p : `./${p}`); - -export type RequireSome = T & Pick, K>; diff --git a/src/utils/harmony-factory.ts b/src/utils/harmony-factory.ts deleted file mode 100755 index b8b5a9f3..00000000 --- a/src/utils/harmony-factory.ts +++ /dev/null @@ -1,78 +0,0 @@ -import TS, { - Decorator, - ExportDeclaration, - Expression, - Identifier, - ImportClause, - Modifier, - NamedExportBindings, - NamedImportBindings, -} from "typescript"; -import { cast } from "./general-utils"; -import * as TsThree from '../declarations/typescript3'; -import { TsTransformPathsContext } from "../types"; -import { downSampleTsTypes } from "./ts-type-conversion"; - -/* ****************************************************************************************************************** */ -// region: Types -/* ****************************************************************************************************************** */ - -export interface HarmonyFactory extends TS.NodeFactory {} - -// endregion - -/* ****************************************************************************************************************** */ -// region: Utilities -/* ****************************************************************************************************************** */ - -/** - * Creates a node factory compatible with TS v3+ - */ -export function createHarmonyFactory(context: TsTransformPathsContext): HarmonyFactory { - const { tsInstance } = context; - const tsThreeInstance = cast(tsInstance); - - return new Proxy(context.tsFactory ?? context.tsInstance, { - get(target, prop) { - if (context.tsFactory) return (target)[prop]; - - switch (prop) { - case "updateCallExpression": - return (...args: any) => tsThreeInstance.updateCall.apply(void 0, args); - case "updateImportClause": - return function ( - node: ImportClause, - isTypeOnly: boolean, - name: Identifier | undefined, - namedBindings: NamedImportBindings | undefined - ) { - return tsThreeInstance.updateImportClause.apply(void 0, downSampleTsTypes(node, name, namedBindings)); - }; - case "updateExportDeclaration": - return function ( - node: ExportDeclaration, - decorators: readonly Decorator[] | undefined, - modifiers: readonly Modifier[] | undefined, - isTypeOnly: boolean, - exportClause: NamedExportBindings | undefined, - moduleSpecifier: Expression | undefined - ) { - const [dsNode, dsModuleSpecifier, dsExportClause] = downSampleTsTypes(node, moduleSpecifier, exportClause); - return tsThreeInstance.updateExportDeclaration( - dsNode, - dsNode.decorators, - dsNode.modifiers, - dsExportClause, - dsModuleSpecifier, - // @ts-ignore - This was added in later versions of 3.x - dsNode.isTypeOnly - ); - }; - default: - return (...args: any) => (tsThreeInstance)[prop](...args); - } - }, - }) as HarmonyFactory; -} - -// endregion diff --git a/src/utils/index.ts b/src/utils/index.ts deleted file mode 100755 index c5ab0a28..00000000 --- a/src/utils/index.ts +++ /dev/null @@ -1,4 +0,0 @@ -export * from "./general-utils"; -export * from "./elide-import-export"; -export * from "./resolve-path-update-node"; -export * from "./ts-type-conversion"; diff --git a/src/utils/path.ts b/src/utils/path.ts deleted file mode 100755 index 7bf74226..00000000 --- a/src/utils/path.ts +++ /dev/null @@ -1,178 +0,0 @@ -// noinspection JSUnusedLocalSymbols,JSUnusedAssignment - -import path from "path"; -import { normalizePath, Pattern, removePrefix, removeSuffix, ResolvedModuleFull } from "typescript"; - -/* ****************************************************************************************************************** */ -// region: Types -/* ****************************************************************************************************************** */ - -export interface OutputPathDetail { - isImplicitExtension: boolean - isExternalLibraryImport: boolean - resolvedExt: string | undefined; - resolvedPath: string; - outputPath: string | undefined; - suppliedExt: string | undefined; - implicitPath?: string; - /** Package name from package.json */ - packageName?: string; - /** Package name as written (could differ due to npm aliasing) */ - suppliedPackageName?: string - suppliedPackagePath?: string - packagePath?: string; - tsPathMatch?: string; -} - -// endregion - -/* ****************************************************************************************************************** */ -// region: Helpers -/* ****************************************************************************************************************** */ - -const pkgRegex = /^((@[^/]+\/[^/@]+)|([^@/]+))(?:\/([^@]+?))?$/; - -/** @internal */ -function getPaths(supplied: string, resolved: string) { - let endMatchPos = 0; - for (let i = 0; i < supplied.length && i < resolved.length; i++) { - if (supplied[i] !== resolved[i]) { - endMatchPos = i; - break; - } - } - - const outputPath = supplied.slice(0, endMatchPos); - const implicitPath = resolved.slice(endMatchPos); - - return { outputPath, implicitPath }; -} - -function getPackagePaths(moduleName: string, suppliedExt: string, subModule: string) { - const { 1: suppliedPackageName, 2: suppliedPackagePath } = pkgRegex.exec(moduleName)!; - - const packagePathNoExt = fixupPartialPath(suppliedPackagePath, suppliedExt); - - if (!subModule) return { outputPath: packagePathNoExt }; - - const subModuleNoExt = fixupPartialPath(subModule, path.extname(subModule)); - - return { - ...getPaths(packagePathNoExt, subModuleNoExt), - suppliedPackageName, - suppliedPackagePath - }; -} - -function getModulePaths( - moduleName: string, - suppliedExt: string, - resolvedFileName: string, - resolvedExt: string, - tsPathMatch: string | Pattern | undefined -) { - // In this case, the file ending is a fixed path, so no further information needs to be determined - if (typeof tsPathMatch === "string" || tsPathMatch?.suffix) return { outputPath: void 0 }; - - const resolvedFileNameNoExt = fixupPartialPath(resolvedFileName, resolvedExt); - const modulePathNoExt = tsPathMatch?.prefix - ? fixupPartialPath(removePrefix(moduleName, tsPathMatch?.prefix), suppliedExt) - : fixupPath(moduleName, suppliedExt); - - return getPaths(modulePathNoExt, resolvedFileNameNoExt); -} - -function getTsPathMatch(match: string | Pattern): string { - return typeof match === "string" ? match : [match.prefix, match.suffix].join("*"); -} - -// endregion - -/* ****************************************************************************************************************** */ -// region: Utils -/* ****************************************************************************************************************** */ - -export function joinPaths(...paths: (string | undefined)[]): string { - return normalizePath(path.join('', ...paths.filter(p => typeof p === 'string') as string[])); -} - -/** - * Remove leading or trailing slashes - * @p path to fix - * @extName extname to remove - */ -export function fixupPartialPath(p: string, extName?: string): string { - p = p.replace(/^[/\\]*(.+?)[/\\]*$/g, "$1"); - if (extName && p.slice(-extName.length) === extName) p = p.slice(0, p.length - extName.length); - return p; -} - -/** - * Remove trailing slashes - * @p path to fix - * @extName extname to remove - */ -export function fixupPath(p: string, extName?: string): string { - p = p.replace(/^(.+?)[/\\]*$/g, "$1"); - if (extName && p.slice(-extName.length) === extName) p = p.slice(0, p.length - extName.length); - return p; -} - -/** @internal — Uses internal TS type */ -export function getOutputPathDetail( - moduleName: string, - resolvedModule: ResolvedModuleFull, - pathMatch: string | Pattern | undefined -): OutputPathDetail { - moduleName = fixupPath(moduleName); - let suppliedExtName = path.extname(moduleName); - const suppliedBaseName = path.basename(moduleName); - let suppliedBaseNameNoExt = path.basename(moduleName, suppliedExtName); - - const resolvedFileName = resolvedModule.originalPath ?? resolvedModule.resolvedFileName; - const resolvedExtName = path.extname(resolvedFileName); - const resolvedFileNameNoExt = removeSuffix(resolvedFileName, resolvedExtName); - const resolvedBaseName = path.basename(resolvedFileName); - const resolvedBaseNameNoExt = path.basename(resolvedFileName, suppliedExtName); - - const tsPathMatch = pathMatch && getTsPathMatch(pathMatch); - - const { isExternalLibraryImport, packageId } = resolvedModule; - const packageName = packageId?.name; - const packageFileName = packageId && fixupPartialPath(packageId.subModuleName); - const packageExtName = packageFileName && path.extname(packageFileName); - const packageFileNameNoExt = packageFileName && removeSuffix(packageFileName, resolvedExtName); - const packageBaseName = packageFileName && path.basename(packageFileName); - const packageBaseNameNoExt = packageFileName && path.basename(packageFileName, packageExtName); - - const effectiveResolvedFileName = packageFileNameNoExt || resolvedFileNameNoExt; - const effectiveResolvedBaseName = packageBaseName || resolvedBaseName; - const effectiveResolvedBaseNameNoExt = packageBaseNameNoExt || resolvedBaseNameNoExt; - const effectiveResolvedExtName = packageExtName || resolvedExtName; - - // Detect and fix invalid extname due to implicit ext (ie. `file.accounting.ts` could decide `accounting` is the extension) - if (suppliedExtName && effectiveResolvedBaseNameNoExt && suppliedBaseName && effectiveResolvedBaseNameNoExt === suppliedBaseName) { - suppliedBaseNameNoExt = suppliedBaseName; - suppliedExtName = ""; - } - - const isImplicitExtension = !suppliedExtName; - - const pathDetail = resolvedModule.isExternalLibraryImport - ? getPackagePaths(moduleName, suppliedExtName, packageId!.subModuleName) - : getModulePaths(moduleName, suppliedExtName, resolvedFileName, resolvedExtName, tsPathMatch); - - return { - isImplicitExtension, - isExternalLibraryImport: !!isExternalLibraryImport, - resolvedExt: effectiveResolvedExtName, - suppliedExt: suppliedExtName, - resolvedPath: effectiveResolvedFileName, - tsPathMatch, - packageName, - packagePath: packageFileName, - ...pathDetail, - }; -} - -// endregion diff --git a/src/utils/resolve-module-name.ts b/src/utils/resolve-module-name.ts deleted file mode 100755 index 5b1765da..00000000 --- a/src/utils/resolve-module-name.ts +++ /dev/null @@ -1,181 +0,0 @@ -import { VisitorContext } from "../types"; -import { isBaseDir, isURL, maybeAddRelativeLocalPrefix } from "./general-utils"; -import { Node, Pattern, removeFileExtension, ResolvedModuleFull, SourceFile } from "typescript"; -import { getOutputPathDetail, joinPaths, OutputPathDetail } from "./path"; -import { getOutputPathForSourceFile } from "./ts-helpers"; -import path from "path"; - -/* ****************************************************************************************************************** */ -// region: Types -/* ****************************************************************************************************************** */ - -export interface ResolvedModule { - resolvedPath?: string; - outputPath: string; -} - -interface GetReturnPathContext { - visitorContext: VisitorContext - node: Node - moduleName: string - pathDetail?: OutputPathDetail - resolvedModule?: ResolvedModuleFull - resolvedSourceFile?: SourceFile - outputPath: string | (string | undefined)[] -} - -// endregion - -/* ****************************************************************************************************************** */ -// region: Helpers -/* ****************************************************************************************************************** */ - -function getResolvedSourceFile(context: VisitorContext, fileName: string): SourceFile { - let res: SourceFile | undefined; - const { program, tsInstance } = context; - - if (program) { - /* Attempt to directly pull from Program */ - res = program.getSourceFile(fileName) as SourceFile; - if (res) return res; - - /* Attempt to find without extension */ - res = (program.getSourceFiles() as SourceFile[]).find( - (s) => removeFileExtension(s.fileName) === removeFileExtension(fileName) - ); - if (res) return res; - } - - /* - * Create basic synthetic SourceFile for use with compiler API - Applies if SourceFile not found in program due to - * import being added by another transformer - */ - return tsInstance.createSourceFile(fileName, ``, tsInstance.ScriptTarget.ESNext, /* setParentNodes */ false); -} - -function getReturnPath(ctx: GetReturnPathContext) { - const { pathDetail, outputPath } = ctx; - const { outputMode } = ctx.visitorContext; - const { - resolvedExt, - suppliedExt, - resolvedPath, - isImplicitExtension, - implicitPath, - } = ctx.pathDetail ?? {}; - - const isEsm = outputMode === "esm"; - const paths = [ outputPath ].flat(); - - let res = joinPaths(...paths); - if (!res) - throw new Error(`Could not resolve path! Please file an issue!\nDetail: ${JSON.stringify(pathDetail, null,2)}`); - - if (pathDetail) { - const ext = isEsm ? resolvedExt : isImplicitExtension ? void 0 : suppliedExt; - const implicit = isEsm ? implicitPath : void 0; - if (ext) res = joinPaths(res, implicit, ext); - } - - return { resolvedPath: resolvedPath, outputPath: res }; -} - -// endregion - -/* ****************************************************************************************************************** */ -// region: Utils -/* ****************************************************************************************************************** */ - -/** - * Resolve a module name - * @internal — Uses internal TS type - */ -export function resolveModuleName( - context: VisitorContext, - node: Node, - moduleName: string, - pathMatch: string | Pattern | undefined -): ResolvedModule | undefined { - const { tsInstance, compilerOptions, sourceFile, config, rootDirs } = context; - - // Attempt to resolve with TS Compiler API - const { resolvedModule, failedLookupLocations } = tsInstance.resolveModuleName( - moduleName, - sourceFile.fileName, - compilerOptions, - tsInstance.sys - ); - - // Handle non-resolvable module - if (!resolvedModule) { - const maybeURL = failedLookupLocations[0]; - const pathIsUrl = isURL(maybeURL); - - if (pathIsUrl && !context.resolver) return void 0; - return getReturnPath({ - moduleName, - visitorContext: context, - node, - outputPath: pathIsUrl ? maybeURL : moduleName - }); - } - - const resolvedSourceFile = getResolvedSourceFile(context, resolvedModule.resolvedFileName); - const pathDetail = getOutputPathDetail(moduleName, resolvedModule, pathMatch); - - const { isExternalLibraryImport } = pathDetail; - - // External packages without a path match hit do not require path relativization - if (isExternalLibraryImport && !pathMatch) { - const { suppliedPackageName, outputPath } = pathDetail; - return getReturnPath({ - moduleName, - node, - visitorContext: context, - resolvedModule, - resolvedSourceFile, - pathDetail, - outputPath: [ suppliedPackageName, outputPath ] - }); - } - - /* Determine output dirs */ - let srcFileOutputDir = path.dirname(getOutputPathForSourceFile(context, sourceFile)); - let moduleFileOutputDir = path.dirname( - resolvedModule.packageId ? pathDetail.outputPath! : getOutputPathForSourceFile(context, resolvedSourceFile) - ); - - // Handle rootDirs remapping - if (config.useRootDirs && rootDirs) { - let fileRootDir = ""; - let moduleRootDir = ""; - for (const rootDir of rootDirs) { - if (isBaseDir(rootDir, moduleFileOutputDir) && rootDir.length > moduleRootDir.length) moduleRootDir = rootDir; - if (isBaseDir(rootDir, srcFileOutputDir) && rootDir.length > fileRootDir.length) fileRootDir = rootDir; - } - - /* Remove base dirs to make relative to root */ - if (fileRootDir && moduleRootDir) { - srcFileOutputDir = path.relative(fileRootDir, srcFileOutputDir); - moduleFileOutputDir = path.relative(moduleRootDir, moduleFileOutputDir); - } - } - - const outputDir = path.relative(srcFileOutputDir, moduleFileOutputDir); - - /* Compose final output path */ - const outputBaseName = pathDetail.implicitPath ? void 0 : path.basename(pathDetail.resolvedPath, pathDetail.resolvedExt); - const outputPath = maybeAddRelativeLocalPrefix(joinPaths(outputDir, outputBaseName)); - - return getReturnPath({ - moduleName, - node, - visitorContext: context, - resolvedModule, - resolvedSourceFile, - pathDetail, - outputPath - }); -} - -// endregion diff --git a/src/utils/ts-type-conversion.ts b/src/utils/ts-type-conversion.ts deleted file mode 100755 index 6ffc2745..00000000 --- a/src/utils/ts-type-conversion.ts +++ /dev/null @@ -1,81 +0,0 @@ -import ts from "typescript"; -import tsThree from "../declarations/typescript3"; - -/* ****************************************************************************************************************** */ -// region: Types -/* ****************************************************************************************************************** */ - -type TypeMapping = [ - [ts.SourceFile, tsThree.SourceFile], - [ts.StringLiteral, tsThree.StringLiteral], - [ts.CompilerOptions, tsThree.CompilerOptions], - [ts.EmitResolver, tsThree.EmitResolver], - [ts.CallExpression, tsThree.CallExpression], - [ts.ExternalModuleReference, tsThree.ExternalModuleReference], - [ts.LiteralTypeNode, tsThree.LiteralTypeNode], - [ts.ExternalModuleReference, tsThree.ExternalModuleReference], - [ts.ImportTypeNode, tsThree.ImportTypeNode], - [ts.LiteralTypeNode, tsThree.LiteralTypeNode], - [ts.ImportDeclaration, tsThree.ImportDeclaration], - [ts.ImportClause, tsThree.ImportClause], - [ts.Identifier, tsThree.Identifier], - [ts.NamedImportBindings, tsThree.NamedImportBindings], - [ts.ImportDeclaration, tsThree.ImportDeclaration], - [ts.ExportDeclaration, tsThree.ExportDeclaration], - [ts.ExportDeclaration["exportClause"], tsThree.ExportDeclaration["exportClause"]] -]; - -type TsType = Exclude; -type TsThreeType = Exclude; - -type TsTypeConversion = { - [i in keyof Tuple]: Tuple[i] extends any[] ? TsTypeConversion : DownSampleTsType; -} & { length: Tuple["length"] }; - -type DownSampleTsType = T extends TsType ? Extract[1] : T; - -type UpSampleTsTypes = { - [i in keyof Tuple]: Tuple[i] extends any[] ? UpSampleTsTypes : UpSampleTsType; -} & { length: Tuple["length"] }; - -type UpSampleTsType = T extends TsThreeType ? Extract[0] : T; - -// endregion - -/* ****************************************************************************************************************** */ -// region: Utilities -/* ****************************************************************************************************************** */ - -/** - * Convert TS4 to TS3 types - * @internal -*/ -export function downSampleTsTypes(...args: T): TsTypeConversion { - return args as TsTypeConversion; -} - -/** - * Convert TS4 to TS3 type - * @internal - */ -export function downSampleTsType(v: T): DownSampleTsType { - return v as DownSampleTsType; -} - -/** - * Convert TS3 to TS4 types - * @internal - */ -export function upSampleTsTypes(...args: T): UpSampleTsTypes { - return args as UpSampleTsTypes; -} - -/** - * Convert TS3 to TS4 type - * @internal - */ -export function upSampleTsType(v: T): UpSampleTsType { - return v as UpSampleTsType; -} - -// endregion diff --git a/test/README.md b/test/README.md new file mode 100755 index 00000000..292890fa --- /dev/null +++ b/test/README.md @@ -0,0 +1,124 @@ +# Test Framework + +This library uses a bespoke testing framework built on top of jest called `Underscore Test` + +## Overview + +- TS projects used for tests are in `test/projects` +- UT source can be found in `test/src` +- Convention is to keep all UT tests for a project in a single, root-level file called `tests.ts` + (ie. `test/projects/my-project/tests.ts`) + +## Debugging +### Environment Variables + +The following env vars can be used to fine-tune / speed up testing during debugging. + +| VAR | Type | Description | +| ------------ | -----| ----------------------------------------------------------------------------- | +| TS_MODULES | Comma separated name fields in `tsModules`* | TS Version to use for testing | +| BUILD_MODES | Comma separated of `buildModes`* | Configure which builders to use (program, ts-node, etc) ¹ | +| TEST_GROUPS | Comma separated string | Only run specific test groups | +| TEST_TARGET | 'src' or 'dist' (default: 'src') | Test against compiled or uncompiled source | + +_\* see: `test/src/config.ts`_ +_¹ Only applies to general project suite — UT suites only test with `Program`_ + +_Note: if `CI` env var is set, custom vars will be ignored_ + +### Example +Only test latest TS, in uncompiled source, using program and ts-node: + +- TS_MODULES = latest; +- BUILD_MODES = program,ts-node; +- TEST_TARGET = src; + +## Writing Tests +### Test Projects + +#### `_test()` + +Defines a test + +- Can conditionally apply test based on test run config via `if` config + +#### `_expect()` + +Attaches an expect to a test + +- All expects are written in-line, preceding the statement they apply to. +- Multiple expects can be attached to single statement + - In a multiple expect-scenario, expects can link to different tests +- Can conditionally apply expect based on: + - run config via `if` config + - output file type via `for` config +- Specifiers are determined automatically, but they can also be manually set via `specifiers` config + +_Note: For more detail see intellisense or JSDoc for signatures in `test/src/ut-global/globals.d.ts`_ + +#### Example + +`tests.ts` +```ts +export const _test_elided = _test(`Elides properly`); +export const _test_transform = _test(`Transforms Path`); +export const _test_ts3_only = _test(`Something for TS3`, { if: (opt) => opt.tsModule[0][0] === '3' }) +``` + +`my-file.ts` +```ts +import { _test_elided, _test_transform, _test_ts3_only } from './tests'; + +_expect(_test_elided, 'new-path', { for: 'js', specifiers: [ 'preserved' ] }); +_expect(_test_transform, 'new-path') +import { elided, preserved } from '#transformable-path'; + +// Not a practical test - simply demonstrates test `if` +_expect(_test_ts3_only, 'path') +import path from 'path'; + +// Second expect linked to `_test_transform` test +_expect(_test_transform, 'new-path-2') +export { b } from '#transformable-path2' +``` + +### Test Suites + +#### `ut.loadProject()` + +Loads project and builds map of tests with expects + +#### `expect().toResolve()` + +Custom UT jest matcher to process expects + +#### Example + +```ts +import { ut } from "../../src"; + +/* ********************************************************************************* * + * Config + * ********************************************************************************* */ + +// Loads from 'test/projects/my-project' +// Returns an array of tsVersions + a method called loadTests() to load a test array +const tsTests = ut.loadProject({ projectName: 'my-project' }); + +/* ********************************************************************************* * + * Tests + * ********************************************************************************* */ + +describe(`[Project: 'my-project'] - Custom Project`, () => { + // Group for each ts version + describe.each(tsTests)(`[TS: $tsVersion]`, ({ loadTests }) => { + const tests = loadTests().loadTests(); + + // Run each test loaded + test.each(tests)(`%s`, (_, detail) => { + detail.expects.forEach(exp => expect(exp).toResolve()); + }) + }) +}); + +``` diff --git a/test/config.ts b/test/config.ts deleted file mode 100755 index 5ebb558f..00000000 --- a/test/config.ts +++ /dev/null @@ -1,29 +0,0 @@ -import ts from "typescript"; -import TypeScriptThree from "typescript-three"; -import path from "path"; - -/* ****************************************************************************************************************** */ -// region: TS Instances -/* ****************************************************************************************************************** */ - -export { ts }; -export const tsThree: typeof TypeScriptThree = require("typescript-three"); - -// endregion - -/* ****************************************************************************************************************** */ -// region: Config -/* ****************************************************************************************************************** */ - -export const tsModules = [ - ["3.6.5", tsThree, "typescript-three"], - ["Latest", ts, "typescript"], -]; - -export const projectsPaths = path.join(__dirname, "./projects"); -export const transformerPath = path.resolve(__dirname, "../src/index.ts"); -export const builtTransformerPath = path.resolve(__dirname, "../dist/index.js"); - -Error.stackTraceLimit = 120; - -// endregion diff --git a/test/package.json b/test/package.json index 88e47c8f..a065f24d 100755 --- a/test/package.json +++ b/test/package.json @@ -5,11 +5,14 @@ "prepare": "node prepare.js" }, "devDependencies": { - "typescript-transform-paths": "link:../", - "ts-expose-internals": "^4.1.2", - "typescript": "npm:typescript@latest", - "typescript-three": "npm:typescript@3.6.5", - "ts-patch": "link:../node_modules/ts-patch" + "@types/underscore-test": "link:src/ut-global", + "chalk": "^4.1.2", + "ts-expose-internals": "latest", + "ts-patch": "link:../node_modules/ts-patch", + "tstp": "link:../", + "typescript-latest": "npm:typescript@latest", + "typescript-42": "npm:typescript@4.2.2", + "typescript-transform-paths": "link:./transformer-wrapper" }, "workspaces": [ "projects/*" diff --git a/test/prepare.js b/test/prepare.js index 2c41f655..6c9d53c0 100755 --- a/test/prepare.js +++ b/test/prepare.js @@ -8,29 +8,13 @@ const tsPatch = require("ts-patch"); * ****************************************************************************************************************** */ const rootDir = __dirname; -const cacheDir = path.resolve(rootDir, ".yarn-cache"); -const tsDirs = ["typescript-three", "typescript"]; +const tsDirs = glob.sync('./node_modules/typescript-*/lib/typescript.js', { cwd: rootDir }) + .map(d => path.resolve(rootDir, d.replace(/\/lib\/typescript.js$/, ''))); /* ****************************************************************************************************************** * * Patch TS Modules * ****************************************************************************************************************** */ -const baseDirs = new Set(); - -for (const tsDirName of tsDirs) { - const mainDir = path.resolve(rootDir, "node_modules", tsDirName); - - /* Find un-patched typescript modules */ - if (!fs.existsSync(path.join(mainDir, "lib-backup"))) { - baseDirs.add(mainDir); - - // Add cached module path - glob - .sync(`**/${tsDirName}/lib/@(typescript|tsc).js`, { cwd: cacheDir }) - .map((f) => path.resolve(cacheDir, path.dirname(f), "..")) - .forEach((d) => baseDirs.add(d)); - } -} - -// Patch discovered modules -for (const dir of baseDirs) tsPatch.patch(["tsc.js", "typescript.js"], { basedir: dir }); +for (const dir of tsDirs) + if (!fs.existsSync(path.join(dir, "lib-backup"))) + tsPatch.patch(["tsc.js", "typescript.js"], { basedir: dir }); diff --git a/test/projects/extras/package.json b/test/projects/extras/package.json index 5968d6db..35cca5ac 100755 --- a/test/projects/extras/package.json +++ b/test/projects/extras/package.json @@ -1,8 +1,5 @@ { "private": true, "name": "@tests/extras", - "version": "0.0.0", - "dependencies": { - "typescript-transform-paths": "*" - } + "version": "0.0.0" } diff --git a/test/projects/extras/tsconfig.json b/test/projects/extras/tsconfig.json index a50c3f97..3c7964ba 100755 --- a/test/projects/extras/tsconfig.json +++ b/test/projects/extras/tsconfig.json @@ -3,7 +3,7 @@ "ts-node": { "transpileOnly": true, - "require": [ "typescript-transform-paths/register" ], + "require": [ "tstp/register" ], }, "compilerOptions": { diff --git a/test/projects/general/core/index.ts b/test/projects/general/core/index.ts index 1150ecdd..a771ac55 100644 --- a/test/projects/general/core/index.ts +++ b/test/projects/general/core/index.ts @@ -1,5 +1,3 @@ -// @ts-ignore -import sum = require("@utils/sum"); export { sum } from "@utils/index"; export { g } from "#utils/hello"; export { sum as sum2 } from "#utils/sum"; @@ -7,10 +5,13 @@ export { NoRuntimecodeHere } from "@utils/types-only"; import { subs, NoRuntimecodeHere } from "@utils/index"; import "@circular/b"; import { A } from "@circular/a"; -import * as path from "path"; import * as b from "circular/a"; import * as c from "../circular/a"; import { myNative } from "@utils/utils.native"; +// @ts-expect-error +import sum = require("@utils/sum"); +// @ts-expect-error +import * as path from "path"; c.A; b.A; diff --git a/test/projects/general/tsconfig.json b/test/projects/general/tsconfig.json index 132e2028..82125291 100644 --- a/test/projects/general/tsconfig.json +++ b/test/projects/general/tsconfig.json @@ -1,8 +1,15 @@ { "compilerOptions": { - "target": "es5", + "skipLibCheck": true, + "skipDefaultLibCheck": true, + "types": [ "@types/underscore-test" ], + "typeRoots": [], + + "target": "ES2015", "module": "ESNext", + "moduleResolution": "node", "outDir": "../__built", + "sourceMap": false, "declaration": true, "baseUrl": "./", @@ -13,11 +20,6 @@ "*": ["*"] }, - "esModuleInterop": true, - - "plugins": [ - { "transform": "../../../src/index.ts" }, - { "transform": "../../../src/index.ts", "afterDeclarations": true } - ] + "esModuleInterop": true } } diff --git a/test/projects/project-ref/a/tsconfig.json b/test/projects/project-ref/a/tsconfig.json index e969bde3..e02404ee 100755 --- a/test/projects/project-ref/a/tsconfig.json +++ b/test/projects/project-ref/a/tsconfig.json @@ -2,6 +2,7 @@ "files": [ "index.ts" ], "extends": "../tsconfig.base.json", "compilerOptions": { + "noEmit": false, "outDir": "../lib/a", "declaration": true } diff --git a/test/projects/project-ref/b/index.ts b/test/projects/project-ref/b/index.ts index 0bc35dfa..b6da5208 100755 --- a/test/projects/project-ref/b/index.ts +++ b/test/projects/project-ref/b/index.ts @@ -1,2 +1,5 @@ +_expect(_test_referenced, { path: "../a/index" }); export { AReffedConst } from "#a/index"; + +_expect(_test_local, { path: "./local/index" }); export { LocalConst } from "#b/local/index"; diff --git a/test/projects/project-ref/b/tests.ts b/test/projects/project-ref/b/tests.ts new file mode 100755 index 00000000..a07ee110 --- /dev/null +++ b/test/projects/project-ref/b/tests.ts @@ -0,0 +1,7 @@ + +/* ****************************************************************************************************************** * + * Tests + * ****************************************************************************************************************** */ + +const _test_referenced = _test(`Specifier for referenced project file resolves`); +const _test_local = _test(`Specifier for local file resolves`); diff --git a/test/projects/project-ref/b/tsconfig.json b/test/projects/project-ref/b/tsconfig.json index 8d73f8ce..9d373e31 100755 --- a/test/projects/project-ref/b/tsconfig.json +++ b/test/projects/project-ref/b/tsconfig.json @@ -1,8 +1,10 @@ { - "files": [ "index.ts", "local/index.ts" ], + "files": [ "index.ts", "local/index.ts", "tests.ts" ], "extends": "../tsconfig.base.json", "compilerOptions": { + "noEmit": false, "outDir": "../lib/b", + "declaration": true }, "references": [ { diff --git a/test/projects/project-ref/tsconfig.base.json b/test/projects/project-ref/tsconfig.base.json index b5bd3845..deb32b17 100755 --- a/test/projects/project-ref/tsconfig.base.json +++ b/test/projects/project-ref/tsconfig.base.json @@ -1,26 +1,21 @@ { "compilerOptions": { + "noEmit": true, + "skipLibCheck": true, + "skipDefaultLibCheck": true, + "types": [ "@types/underscore-test" ], + "typeRoots": [], + "moduleResolution": "Node", "esModuleInterop": true, "module": "ESNext", "target": "ESNext", "composite": true, - "declaration": true, "baseUrl": ".", "paths": { "#a/*": [ "./a/*" ], "#b/*": [ "./b/*" ] - }, - "plugins": [ - // Note - Paths are relative to one level deeper, due to tsp not resolving from base config dir - { - "transform": "../../../../src/index.ts", - }, - { - "transform": "../../../../src/index.ts", - "afterDeclarations": true - } - ] + } } } diff --git a/test/projects/project-ref/tsconfig.json b/test/projects/project-ref/tsconfig.json index 4cdbc7ad..1da7dd65 100755 --- a/test/projects/project-ref/tsconfig.json +++ b/test/projects/project-ref/tsconfig.json @@ -1,4 +1,5 @@ { + "extends": "./tsconfig.base.json", "references": [ { "path": "./a" diff --git a/test/projects/resolution/package.json b/test/projects/resolution/package.json new file mode 100755 index 00000000..2f9c7cc0 --- /dev/null +++ b/test/projects/resolution/package.json @@ -0,0 +1,11 @@ +{ + "private": true, + "name": "@tests/resolution", + "version": "0.0.0", + "dependencies": { + "@external/root-idx": "link:./packages/external/root-idx", + "@external/subdir-idx": "link:./packages/external/subdir-idx", + "@external/root-named-idx": "link:./packages/external/root-named-idx", + "@external/esm": "link:./packages/external/esm" + } +} diff --git a/test/projects/resolution/packages/external/esm/dir/main.d.ts b/test/projects/resolution/packages/external/esm/dir/main.d.ts new file mode 100755 index 00000000..3c8d4b9d --- /dev/null +++ b/test/projects/resolution/packages/external/esm/dir/main.d.ts @@ -0,0 +1 @@ +export declare const exp: null; diff --git a/test/projects/resolution/packages/external/esm/dir/main.js b/test/projects/resolution/packages/external/esm/dir/main.js new file mode 100755 index 00000000..6d83c9d2 --- /dev/null +++ b/test/projects/resolution/packages/external/esm/dir/main.js @@ -0,0 +1,3 @@ +module.exports = { + exp: null, +}; diff --git a/test/projects/resolution/packages/external/esm/dir/mod.d.ts b/test/projects/resolution/packages/external/esm/dir/mod.d.ts new file mode 100755 index 00000000..3c8d4b9d --- /dev/null +++ b/test/projects/resolution/packages/external/esm/dir/mod.d.ts @@ -0,0 +1 @@ +export declare const exp: null; diff --git a/test/projects/resolution/packages/external/esm/dir/mod.mjs b/test/projects/resolution/packages/external/esm/dir/mod.mjs new file mode 100755 index 00000000..092fefc9 --- /dev/null +++ b/test/projects/resolution/packages/external/esm/dir/mod.mjs @@ -0,0 +1 @@ +export const exp = null; diff --git a/test/projects/resolution/packages/external/esm/package.json b/test/projects/resolution/packages/external/esm/package.json new file mode 100755 index 00000000..e164bfc1 --- /dev/null +++ b/test/projects/resolution/packages/external/esm/package.json @@ -0,0 +1,10 @@ +{ + "name": "@external/esm", + "version": "0.0.0", + "private": "true", + "exports": { + ".": "./dir/main.js", + "./synthetic/path/mod": "./dir/mod.mjs", + "./synthetic/path/mod.mjs": "./dir/mod.mjs" + } +} diff --git a/test/projects/specific/src/packages/pkg-a/index.d.ts b/test/projects/resolution/packages/external/root-idx/index.d.ts similarity index 100% rename from test/projects/specific/src/packages/pkg-a/index.d.ts rename to test/projects/resolution/packages/external/root-idx/index.d.ts diff --git a/test/projects/specific/src/packages/pkg-a/index.js b/test/projects/resolution/packages/external/root-idx/index.js similarity index 100% rename from test/projects/specific/src/packages/pkg-a/index.js rename to test/projects/resolution/packages/external/root-idx/index.js diff --git a/test/projects/resolution/packages/external/root-idx/other.d.ts b/test/projects/resolution/packages/external/root-idx/other.d.ts new file mode 100755 index 00000000..a2097d79 --- /dev/null +++ b/test/projects/resolution/packages/external/root-idx/other.d.ts @@ -0,0 +1 @@ +export declare const b: null; diff --git a/test/projects/resolution/packages/external/root-idx/other.js b/test/projects/resolution/packages/external/root-idx/other.js new file mode 100755 index 00000000..9dd9d027 --- /dev/null +++ b/test/projects/resolution/packages/external/root-idx/other.js @@ -0,0 +1 @@ +module.exports = { d: null }; diff --git a/test/projects/specific/src/packages/pkg-a/package.json b/test/projects/resolution/packages/external/root-idx/package.json similarity index 50% rename from test/projects/specific/src/packages/pkg-a/package.json rename to test/projects/resolution/packages/external/root-idx/package.json index b1207ef2..0052c7f2 100755 --- a/test/projects/specific/src/packages/pkg-a/package.json +++ b/test/projects/resolution/packages/external/root-idx/package.json @@ -1,6 +1,6 @@ { - "name": "pkg-a", - "version": "0.0.0-alpha", + "name": "root-idx", + "version": "0.0.0", "private": "true", "main": "./index.js" } diff --git a/test/projects/specific/src/packages/pkg-a/sub-pkg/main.d.ts b/test/projects/resolution/packages/external/root-idx/sub-pkg/main.d.ts similarity index 100% rename from test/projects/specific/src/packages/pkg-a/sub-pkg/main.d.ts rename to test/projects/resolution/packages/external/root-idx/sub-pkg/main.d.ts diff --git a/test/projects/specific/src/packages/pkg-a/sub-pkg/main.js b/test/projects/resolution/packages/external/root-idx/sub-pkg/main.js similarity index 100% rename from test/projects/specific/src/packages/pkg-a/sub-pkg/main.js rename to test/projects/resolution/packages/external/root-idx/sub-pkg/main.js diff --git a/test/projects/specific/src/packages/pkg-a/sub-pkg/package.json b/test/projects/resolution/packages/external/root-idx/sub-pkg/package.json similarity index 100% rename from test/projects/specific/src/packages/pkg-a/sub-pkg/package.json rename to test/projects/resolution/packages/external/root-idx/sub-pkg/package.json diff --git a/test/projects/specific/src/packages/pkg-c/main.d.ts b/test/projects/resolution/packages/external/root-named-idx/main.d.ts similarity index 100% rename from test/projects/specific/src/packages/pkg-c/main.d.ts rename to test/projects/resolution/packages/external/root-named-idx/main.d.ts diff --git a/test/projects/specific/src/packages/pkg-c/main.js b/test/projects/resolution/packages/external/root-named-idx/main.js similarity index 100% rename from test/projects/specific/src/packages/pkg-c/main.js rename to test/projects/resolution/packages/external/root-named-idx/main.js diff --git a/test/projects/resolution/packages/external/root-named-idx/package.json b/test/projects/resolution/packages/external/root-named-idx/package.json new file mode 100755 index 00000000..a2eab78e --- /dev/null +++ b/test/projects/resolution/packages/external/root-named-idx/package.json @@ -0,0 +1,6 @@ +{ + "name": "root-named-idx", + "version": "0.0.0", + "private": "true", + "main": "./main.js" +} diff --git a/test/projects/specific/src/packages/pkg-b/package.json b/test/projects/resolution/packages/external/subdir-idx/package.json similarity index 53% rename from test/projects/specific/src/packages/pkg-b/package.json rename to test/projects/resolution/packages/external/subdir-idx/package.json index 65a449b5..8c2aa837 100755 --- a/test/projects/specific/src/packages/pkg-b/package.json +++ b/test/projects/resolution/packages/external/subdir-idx/package.json @@ -1,6 +1,6 @@ { - "name": "pkg-b", - "version": "0.0.0-alpha", + "name": "subdir-idx", + "version": "0.0.0", "private": "true", "main": "./subdir/main.js" } diff --git a/test/projects/specific/src/packages/pkg-b/subdir/main.d.ts b/test/projects/resolution/packages/external/subdir-idx/subdir/main.d.ts similarity index 100% rename from test/projects/specific/src/packages/pkg-b/subdir/main.d.ts rename to test/projects/resolution/packages/external/subdir-idx/subdir/main.d.ts diff --git a/test/projects/specific/src/packages/pkg-b/subdir/main.js b/test/projects/resolution/packages/external/subdir-idx/subdir/main.js similarity index 100% rename from test/projects/specific/src/packages/pkg-b/subdir/main.js rename to test/projects/resolution/packages/external/subdir-idx/subdir/main.js diff --git a/test/projects/resolution/packages/internal/esm/dir/main.d.ts b/test/projects/resolution/packages/internal/esm/dir/main.d.ts new file mode 100755 index 00000000..3c8d4b9d --- /dev/null +++ b/test/projects/resolution/packages/internal/esm/dir/main.d.ts @@ -0,0 +1 @@ +export declare const exp: null; diff --git a/test/projects/resolution/packages/internal/esm/dir/main.js b/test/projects/resolution/packages/internal/esm/dir/main.js new file mode 100755 index 00000000..6d83c9d2 --- /dev/null +++ b/test/projects/resolution/packages/internal/esm/dir/main.js @@ -0,0 +1,3 @@ +module.exports = { + exp: null, +}; diff --git a/test/projects/resolution/packages/internal/esm/dir/mod.d.ts b/test/projects/resolution/packages/internal/esm/dir/mod.d.ts new file mode 100755 index 00000000..3c8d4b9d --- /dev/null +++ b/test/projects/resolution/packages/internal/esm/dir/mod.d.ts @@ -0,0 +1 @@ +export declare const exp: null; diff --git a/test/projects/resolution/packages/internal/esm/dir/mod.mjs b/test/projects/resolution/packages/internal/esm/dir/mod.mjs new file mode 100755 index 00000000..092fefc9 --- /dev/null +++ b/test/projects/resolution/packages/internal/esm/dir/mod.mjs @@ -0,0 +1 @@ +export const exp = null; diff --git a/test/projects/resolution/packages/internal/esm/package.json b/test/projects/resolution/packages/internal/esm/package.json new file mode 100755 index 00000000..64b3dcef --- /dev/null +++ b/test/projects/resolution/packages/internal/esm/package.json @@ -0,0 +1,10 @@ +{ + "name": "esm", + "version": "0.0.0", + "private": "true", + "exports": { + ".": "./dir/main.js", + "./synthetic/path/mod": "./dir/mod.mjs", + "./synthetic/path/mod.mjs": "./dir/mod.mjs" + } +} diff --git a/test/projects/resolution/packages/internal/root-idx/index.d.ts b/test/projects/resolution/packages/internal/root-idx/index.d.ts new file mode 100755 index 00000000..447639ee --- /dev/null +++ b/test/projects/resolution/packages/internal/root-idx/index.d.ts @@ -0,0 +1,2 @@ +export type PackageAType = null; +export declare const packageAConst: PackageAType; diff --git a/test/projects/resolution/packages/internal/root-idx/index.js b/test/projects/resolution/packages/internal/root-idx/index.js new file mode 100755 index 00000000..08f0c5a5 --- /dev/null +++ b/test/projects/resolution/packages/internal/root-idx/index.js @@ -0,0 +1,3 @@ +module.exports = { + packageAConst: null, +}; diff --git a/test/projects/resolution/packages/internal/root-idx/package.json b/test/projects/resolution/packages/internal/root-idx/package.json new file mode 100755 index 00000000..0052c7f2 --- /dev/null +++ b/test/projects/resolution/packages/internal/root-idx/package.json @@ -0,0 +1,6 @@ +{ + "name": "root-idx", + "version": "0.0.0", + "private": "true", + "main": "./index.js" +} diff --git a/test/projects/resolution/packages/internal/root-idx/sub-pkg/main.d.ts b/test/projects/resolution/packages/internal/root-idx/sub-pkg/main.d.ts new file mode 100755 index 00000000..1849268f --- /dev/null +++ b/test/projects/resolution/packages/internal/root-idx/sub-pkg/main.d.ts @@ -0,0 +1,2 @@ +export type SubPackageType = null; +export declare const subPackageConst: SubPackageType; diff --git a/test/projects/resolution/packages/internal/root-idx/sub-pkg/main.js b/test/projects/resolution/packages/internal/root-idx/sub-pkg/main.js new file mode 100755 index 00000000..18eb020b --- /dev/null +++ b/test/projects/resolution/packages/internal/root-idx/sub-pkg/main.js @@ -0,0 +1,3 @@ +module.exports = { + subPackageConst: null, +}; diff --git a/test/projects/specific/src/packages/pkg-c/package.json b/test/projects/resolution/packages/internal/root-idx/sub-pkg/package.json similarity index 56% rename from test/projects/specific/src/packages/pkg-c/package.json rename to test/projects/resolution/packages/internal/root-idx/sub-pkg/package.json index 18b3a7df..b53f2aed 100755 --- a/test/projects/specific/src/packages/pkg-c/package.json +++ b/test/projects/resolution/packages/internal/root-idx/sub-pkg/package.json @@ -1,6 +1,6 @@ { - "name": "pkg-c", + "name": "sub-pkg", "version": "0.0.0-alpha", "private": "true", - "main": "./main.js" + "main": "main.js" } diff --git a/test/projects/resolution/packages/internal/root-named-idx/main.d.ts b/test/projects/resolution/packages/internal/root-named-idx/main.d.ts new file mode 100755 index 00000000..770bc49f --- /dev/null +++ b/test/projects/resolution/packages/internal/root-named-idx/main.d.ts @@ -0,0 +1,2 @@ +export type PackageCType = null; +export declare const packageCConst: PackageCType; diff --git a/test/projects/resolution/packages/internal/root-named-idx/main.js b/test/projects/resolution/packages/internal/root-named-idx/main.js new file mode 100755 index 00000000..363f8780 --- /dev/null +++ b/test/projects/resolution/packages/internal/root-named-idx/main.js @@ -0,0 +1,3 @@ +module.exports = { + packageCConst: null, +}; diff --git a/test/projects/resolution/packages/internal/root-named-idx/package.json b/test/projects/resolution/packages/internal/root-named-idx/package.json new file mode 100755 index 00000000..a2eab78e --- /dev/null +++ b/test/projects/resolution/packages/internal/root-named-idx/package.json @@ -0,0 +1,6 @@ +{ + "name": "root-named-idx", + "version": "0.0.0", + "private": "true", + "main": "./main.js" +} diff --git a/test/projects/resolution/packages/internal/subdir-idx/package.json b/test/projects/resolution/packages/internal/subdir-idx/package.json new file mode 100755 index 00000000..8c2aa837 --- /dev/null +++ b/test/projects/resolution/packages/internal/subdir-idx/package.json @@ -0,0 +1,6 @@ +{ + "name": "subdir-idx", + "version": "0.0.0", + "private": "true", + "main": "./subdir/main.js" +} diff --git a/test/projects/resolution/packages/internal/subdir-idx/subdir/main.d.ts b/test/projects/resolution/packages/internal/subdir-idx/subdir/main.d.ts new file mode 100755 index 00000000..a7598853 --- /dev/null +++ b/test/projects/resolution/packages/internal/subdir-idx/subdir/main.d.ts @@ -0,0 +1,2 @@ +export type PackageBType = null; +export declare const packageBConst: PackageBType; diff --git a/test/projects/resolution/packages/internal/subdir-idx/subdir/main.js b/test/projects/resolution/packages/internal/subdir-idx/subdir/main.js new file mode 100755 index 00000000..3b89af4b --- /dev/null +++ b/test/projects/resolution/packages/internal/subdir-idx/subdir/main.js @@ -0,0 +1,3 @@ +module.exports = { + packageBConst: null, +}; diff --git a/test/projects/resolution/src/esm.ts b/test/projects/resolution/src/esm.ts new file mode 100755 index 00000000..3ca58755 --- /dev/null +++ b/test/projects/resolution/src/esm.ts @@ -0,0 +1,28 @@ +import { _test_esm_index, _test_esm_reject_unmapped } from "../tests"; + +/* ****************************************************************************************************************** * + * Index + * ****************************************************************************************************************** */ + +_expect(_test_esm_index, _expect.index('@external/esm', 'dir/main')); +import '@external/esm'; + +/* ****************************************************************************************************************** * + * Synthetic Paths + * ****************************************************************************************************************** */ +// Not supported pre 4.5 - maybe supported after? + +// _expect(_test_esm_synthetic_path, _expect.path('../packages/esm/synthetic/path/mod')); +// import '@external/esm/synthetic/path/mod'; +// +// _expect(_test_esm_synthetic_path, _expect.path('../packages/esm/synthetic/path/mod')); +// import '@external/esm/dir/'; + +/* ****************************************************************************************************************** * + * Unmapped Paths + * ****************************************************************************************************************** */ +// The following path exists, but it is not mapped in exports + +_expect(_test_esm_reject_unmapped); +import '@external/esm/dir/main.js'; + diff --git a/test/projects/resolution/src/indexes.ts b/test/projects/resolution/src/indexes.ts new file mode 100755 index 00000000..5b8cf2db --- /dev/null +++ b/test/projects/resolution/src/indexes.ts @@ -0,0 +1,51 @@ +import { _test_internal_package_index, _test_external_package_index, _test_local_index } from "../tests"; + + +/* ****************************************************************************************************************** * + * Local + * ****************************************************************************************************************** */ + +_expect(_test_local_index, _expect.index('./local')); +import '#root/local' + +_expect(_test_local_index, _expect.index('./local')); +import "./local" + +/* ****************************************************************************************************************** * + * Internal + * ****************************************************************************************************************** */ + +_expect(_test_internal_package_index, _expect.index('../packages/internal/root-idx')); +import "../packages/internal/root-idx"; + +_expect(_test_internal_package_index, _expect.index('../packages/internal/root-idx')); +import "#internal/root-idx"; + +_expect(_test_internal_package_index, _expect.index('../packages/internal/root-idx/sub-pkg', 'main')); +import "#internal/root-idx/sub-pkg"; + +_expect(_test_internal_package_index, _expect.index('../packages/internal/root-named-idx', 'main')); +import "#internal/root-named-idx"; + +_expect(_test_internal_package_index, _expect.index('../packages/internal/subdir-idx', 'subdir/main')); +import "#internal/subdir-idx"; + +// TS Does not resolve +_expect(_test_internal_package_index); +import "#internal/esm"; + +/* ****************************************************************************************************************** * + * External + * ****************************************************************************************************************** */ + +_expect(_test_external_package_index, _expect.index('@external/root-idx')); +import "@external/root-idx"; + +_expect(_test_external_package_index, _expect.index('@external/root-idx/sub-pkg', 'main')); +import "@external/root-idx/sub-pkg"; + +_expect(_test_external_package_index, _expect.index('@external/root-named-idx', 'main')); +import "@external/root-named-idx"; + +_expect(_test_external_package_index, _expect.index('@external/subdir-idx', 'subdir/main')); +import "@external/subdir-idx"; diff --git a/test/projects/resolution/src/local/index.ts b/test/projects/resolution/src/local/index.ts new file mode 100755 index 00000000..e69de29b diff --git a/test/projects/resolution/src/tricky.ts b/test/projects/resolution/src/tricky.ts new file mode 100755 index 00000000..8e8cc1d6 --- /dev/null +++ b/test/projects/resolution/src/tricky.ts @@ -0,0 +1,33 @@ +import { _test_tricky } from "../tests"; + + +// Path match to package in node_modules: +// isExternalLibrary = true, package, submodule = index.d.ts +// _expect(_test_tricky) +// import '#ext-root-idx-pkg'; + +// Path match to node_modules, sub-file +// isExternalLibrary = true, package, submodule = other.d.ts +// _expect(_test_tricky, 'ss') +// import '#ext-root-idx-pkg/other'; + +// Path match to ESM package (does not use "index", uses "exports") in node_modules: +// Failed to resolve +// _expect(_test_tricky, 'ss') +// import '#ext-esm'; + +// Path match to ESM node_modules, sub-file +// isExternalLibrary = true, submodule dir/main.d.ts +// _expect(_test_tricky, 'ss') +// import '#ext-esm/dir/main'; + +// Path match to package (does not use "index", uses "main") in node_modules: +// isExternalLibrary = true, package, submodule = main.d.ts +// _expect(_test_tricky) +// import '#ext-root-named-idx-pkg'; + +// Internal ESM package +// Failed to resolve +// import '#internal/esm' + +import 'pkg/external' diff --git a/test/projects/resolution/tests.ts b/test/projects/resolution/tests.ts new file mode 100755 index 00000000..88888146 --- /dev/null +++ b/test/projects/resolution/tests.ts @@ -0,0 +1,37 @@ +/* ****************************************************************************************************************** * + * Tests + * ****************************************************************************************************************** */ + +export const _test_internal_package_index = _test({ + label: `Internal packages resolve properly`, + group: "Package" +}); + +export const _test_external_package_index = _test({ + label: `External packages resolve properly`, + group: "Package" +}); + +export const _test_local_index = _test(`Local index resolves properly`); + +export const _test_esm_index = _test({ + label: `Resolves index`, + group: 'ESM' +}); + +// Not supported pre 4.5 - maybe supported after? + +// export const _test_esm_synthetic_path = _test({ +// label: `Resolves synthetic paths`, +// group: 'ESM' +// }); + +export const _test_esm_reject_unmapped = _test({ + label: `Does not transform unmapped paths`, + group: 'ESM', + if: () => false +}); + +// export const _test_tricky = _test({ +// label: 'Tricky' +// }); diff --git a/test/projects/resolution/tsconfig.json b/test/projects/resolution/tsconfig.json new file mode 100755 index 00000000..bb5d4149 --- /dev/null +++ b/test/projects/resolution/tsconfig.json @@ -0,0 +1,25 @@ +{ + "include": [ "src", "packages/internal", "tests.ts" ], + + "compilerOptions": { + "noEmit": true, + + "rootDir": ".", + "module": "ESNext", + "esModuleInterop": true, + "moduleResolution": "node", + "declaration": true, + + "baseUrl": ".", + "paths": { + "#root/*": [ "./src/*" ], + "#internal/*": [ "./packages/internal/*" ], + "#ext-root-idx-pkg": [ "../../node_modules/@external/root-idx" ], + "#ext-root-idx-pkg/*": [ "../../node_modules/@external/root-idx/*" ], + "#ext-root-named-idx-pkg": [ "../../node_modules/@external/root-named-idx" ], + "#ext-esm": [ "../../node_modules/@external/esm" ], + "#ext-esm/*": [ "../../node_modules/@external/esm/*" ], + "pkg/*": [ "./packages/*/root-idx" ] + } + } +} diff --git a/test/projects/root-dirs/generated/dir/gen-file.ts b/test/projects/root-dirs/generated/dir/gen-file.ts new file mode 100755 index 00000000..b4335ac1 --- /dev/null +++ b/test/projects/root-dirs/generated/dir/gen-file.ts @@ -0,0 +1,7 @@ +import { _test_no_root_dirs, _test_root_dirs } from '../../tests'; + +_expect(_test_root_dirs, { path: "./src-file" }); +_expect(_test_no_root_dirs, { path: "../../src/dir/src-file" }); +import "#root/dir/src-file"; + +export const b = 1; diff --git a/test/projects/root-dirs/package.json b/test/projects/root-dirs/package.json new file mode 100755 index 00000000..63f5f6a1 --- /dev/null +++ b/test/projects/root-dirs/package.json @@ -0,0 +1,5 @@ +{ + "private": true, + "name": "@tests/root-dirs", + "version": "0.0.0" +} diff --git a/test/projects/root-dirs/src/dir/src-file.ts b/test/projects/root-dirs/src/dir/src-file.ts new file mode 100755 index 00000000..2145fc4a --- /dev/null +++ b/test/projects/root-dirs/src/dir/src-file.ts @@ -0,0 +1,7 @@ +import { _test_no_root_dirs, _test_root_dirs } from '../../tests'; + +_expect(_test_root_dirs, { path: "./gen-file" }); +_expect(_test_no_root_dirs, { path: "../../generated/dir/gen-file" }); +import "#root/dir/gen-file"; + +export const a = 2; diff --git a/test/projects/root-dirs/src/index.ts b/test/projects/root-dirs/src/index.ts new file mode 100755 index 00000000..12d5940c --- /dev/null +++ b/test/projects/root-dirs/src/index.ts @@ -0,0 +1,9 @@ +import { _test_no_root_dirs, _test_root_dirs } from '../tests'; + +_expect(_test_root_dirs, { path: "./dir/gen-file" }); +_expect(_test_no_root_dirs, { path: "../generated/dir/gen-file" }); +export { b } from "#root/dir/gen-file"; + +_expect(_test_root_dirs, { path: "./dir/src-file" }); +_expect(_test_no_root_dirs, { path: "./dir/src-file" }); +export { a } from "#root/dir/src-file"; diff --git a/test/projects/root-dirs/tests.ts b/test/projects/root-dirs/tests.ts new file mode 100755 index 00000000..6dbab9eb --- /dev/null +++ b/test/projects/root-dirs/tests.ts @@ -0,0 +1,13 @@ +/* ****************************************************************************************************************** * + * Tests + * ****************************************************************************************************************** */ + +export const _test_root_dirs = _test({ + label: `Re-maps for rootDirs`, + if: ({ pluginOptions }) => pluginOptions.useRootDirs +}); + +export const _test_no_root_dirs = _test({ + label: `Ignores rootDirs`, + if: ({ pluginOptions }) => !pluginOptions.useRootDirs +}); diff --git a/test/projects/root-dirs/tsconfig.json b/test/projects/root-dirs/tsconfig.json new file mode 100755 index 00000000..1d729c7e --- /dev/null +++ b/test/projects/root-dirs/tsconfig.json @@ -0,0 +1,18 @@ +{ + "include": [ "src", "generated", "tests.ts" ], + + "compilerOptions": { + "noEmit": true, + + "rootDir": ".", + "moduleResolution": "node", + "declaration": true, + + "rootDirs": [ "src", "generated" ], + + "baseUrl": ".", + "paths": { + "#root/*": [ "./src/*", "./generated/*" ], + }, + } +} diff --git a/test/projects/specific/generated/dir/gen-file.ts b/test/projects/specific/generated/dir/gen-file.ts deleted file mode 100755 index 72fab4ed..00000000 --- a/test/projects/specific/generated/dir/gen-file.ts +++ /dev/null @@ -1,3 +0,0 @@ -import "#root/dir/src-file"; - -export const b = 1; diff --git a/test/projects/specific/src/dir/src-file.ts b/test/projects/specific/src/dir/src-file.ts deleted file mode 100755 index 9d2e4480..00000000 --- a/test/projects/specific/src/dir/src-file.ts +++ /dev/null @@ -1,4 +0,0 @@ -import "#root/dir/gen-file"; - -export const a = 2; -export type A = string; diff --git a/test/projects/specific/src/index.ts b/test/projects/specific/src/index.ts index f2896acc..97914ccc 100755 --- a/test/projects/specific/src/index.ts +++ b/test/projects/specific/src/index.ts @@ -1,25 +1,46 @@ -export { b } from "#root/dir/gen-file"; -export { a } from "#root/dir/src-file"; +import { _test_async_import_comments, _test_exclude, _test_explicit_extensions, _test_type_only_import } from "../tests"; -import type { A as ATypeOnly } from "#root/dir/src-file"; +/* ********************************************************* * + * TypeOnly + * ********************************************************* */ + +_expect(_test_type_only_import, { path: './general', for: 'dts' }); +_expect(_test_type_only_import, { elided: true, for: 'js' }); +import type { GeneralTypeA as ATypeOnly } from "./general"; export { ATypeOnly }; -import(/* webpackChunkName: "Comment" */ "#root/dir/src-file"); +/* ********************************************************* * + * Async Import Comments + * ********************************************************* */ + +_expect(_test_async_import_comments, { path: './general', extraCheck: (c) => /^import\(\/\* w/.test(c), for: 'js' }) +import(/* webpackChunkName: "Comment" */ "./general"); + +_expect(_test_async_import_comments, { path: './general', extraCheck: (c) => /^import\(\s*\/\/ c/.test(c), for: 'js' }) import( - // comment 1 - /* - comment 2 - */ - "#root/dir/src-file" +// comment 1 +/* +comment 2 +*/ +"./general" ); +/* ********************************************************* * + * Exclusion + * ********************************************************* */ + +_expect(_test_exclude); export { bb } from "#exclusion/ex"; + +_expect(_test_exclude); export { dd } from "#root/excluded-file"; -export { JsonValue } from "#root/data.json"; -export { GeneralConstA } from "#root/general"; -export { GeneralConstB } from "#root/general.js"; +/* ********************************************************* * + * Explicit Extensions + * ********************************************************* */ -export const b1 = 3; +_expect(_test_explicit_extensions, { path: './data.json' }) +export { JsonValue } from "#root/data.json"; -export { ConstB } from "#elision"; +_expect(_test_explicit_extensions, { path: './general.js' }) +export { GeneralConstB } from "#root/general.js"; diff --git a/test/projects/specific/src/module-augment.ts b/test/projects/specific/src/module-augment.ts index 6eab0bfa..d74251e6 100755 --- a/test/projects/specific/src/module-augment.ts +++ b/test/projects/specific/src/module-augment.ts @@ -1,16 +1,18 @@ import { Expandable } from "#root/general"; +import { _test_module_augmentation } from "../tests"; -// Gets transformed +_expect(_test_module_augmentation, { path: './general' }); declare module "#root/general" { interface Expandable { b: number; } } -// Remains untransformed +_expect(_test_module_augmentation); declare module "./excluded-file" { type B = null; } +// Leave this - provides typechecking declare const b: Expandable; b.b && b.a; diff --git a/test/projects/specific/src/sub-packages.ts b/test/projects/specific/src/sub-packages.ts deleted file mode 100755 index 36f16d60..00000000 --- a/test/projects/specific/src/sub-packages.ts +++ /dev/null @@ -1,13 +0,0 @@ -export { packageAConst, PackageAType } from "#packages/pkg-a"; -export { packageBConst, PackageBType } from "#packages/pkg-b"; -export { packageCConst, PackageCType } from "#packages/pkg-c"; -export { SubPackageType, subPackageConst } from "#packages/pkg-a/sub-pkg"; - -// This path should resolve to './packages/pkg-c/main' -export { packageCConst as C2 } from "#packages/pkg-c/main"; -// This path should resolve to './packages/pkg-c/main.js', due to explicit extension -export { packageCConst as C3 } from "#packages/pkg-c/main.js"; -// This path should resolve to './packages/pkg-a/sub-pkg/main' -export { subPackageConst as C4 } from "#packages/pkg-a/sub-pkg/main"; -// This path should resolve to './packages/pkg-a/sub-pkg/main.js', due to explicit extension -export { subPackageConst as C5 } from "#packages/pkg-a/sub-pkg/main.js"; diff --git a/test/projects/specific/src/tags.ts b/test/projects/specific/src/tags.ts index f8f1e2c1..96b1a406 100755 --- a/test/projects/specific/src/tags.ts +++ b/test/projects/specific/src/tags.ts @@ -1,12 +1,16 @@ +import { _test_tag_explicit_transform, _test_tag_no_transform } from "../tests"; + /* ****************************************************************************************************************** * * JSDoc * ****************************************************************************************************************** */ +_expect(_test_tag_no_transform, { path: '#root/index' }); /** * @no-transform-path */ import * as skipTransform1 from "#root/index"; +_expect(_test_tag_no_transform, { path: '#root/index' }); /** * @multi-tag1 * @no-transform-path @@ -14,6 +18,7 @@ import * as skipTransform1 from "#root/index"; */ import * as skipTransform2 from "#root/index"; +_expect(_test_tag_explicit_transform, { path: './dir/src-file' }); /** * @multi-tag1 * @transform-path ./dir/src-file @@ -21,6 +26,7 @@ import * as skipTransform2 from "#root/index"; */ import * as explicitTransform1 from "./index"; +_expect(_test_tag_explicit_transform, { path: "http://www.go.com/react.js" }); /** * @multi-tag1 * @transform-path http://www.go.com/react.js @@ -32,19 +38,23 @@ import * as explicitTransform2 from "./index"; * JS Tag * ****************************************************************************************************************** */ +_expect(_test_tag_no_transform, { path: "#root/index" }); // @no-transform-path import * as skipTransform3 from "#root/index"; +_expect(_test_tag_no_transform, { path: "#root/index" }); // @multi-tag1 // @no-transform-path // @multi-tag2 import * as skipTransform4 from "#root/index"; +_expect(_test_tag_explicit_transform, { path: "./dir/src-file" }); // @multi-tag1 // @transform-path ./dir/src-file // @multi-tag2 import * as explicitTransform3 from "./index"; +_expect(_test_tag_explicit_transform, { path: "http://www.go.com/react.js" }); // @multi-tag1 // @transform-path http://www.go.com/react.js // @multi-tag2 diff --git a/test/projects/specific/src/type-elision/index.ts b/test/projects/specific/src/type-elision/index.ts index 1b2d9353..1846a77b 100755 --- a/test/projects/specific/src/type-elision/index.ts +++ b/test/projects/specific/src/type-elision/index.ts @@ -1,4 +1,18 @@ +import { _test_type_elision } from "../../tests"; + + +_expect(_test_type_elision, { specifiers: [ 'ConstB' ], for: 'js' }); +_expect(_test_type_elision, { specifiers: [ 'ConstB', 'TypeA' ], for: 'dts' }); import { ConstB, TypeA } from "./a"; + +_expect(_test_type_elision, { elided: true, for: 'js' }); +_expect(_test_type_elision, { specifiers: [ 'TypeA2' ], for: 'dts' }); import { TypeA as TypeA2 } from "./a"; + +_expect(_test_type_elision, { specifiers: [ 'ConstB' ], for: 'js' }); +_expect(_test_type_elision, { specifiers: [ 'ConstB', 'TypeA' ], for: 'dts' }); export { ConstB, TypeA }; + +_expect(_test_type_elision, { elided: true, for: 'js' }); +_expect(_test_type_elision, { specifiers: [ 'TypeA2' ], for: 'dts' }); export { TypeA2 }; diff --git a/test/projects/specific/tests.ts b/test/projects/specific/tests.ts new file mode 100755 index 00000000..e382abe4 --- /dev/null +++ b/test/projects/specific/tests.ts @@ -0,0 +1,34 @@ +/* ****************************************************************************************************************** * + * Tests + * ****************************************************************************************************************** */ + +export const _test_tag_no_transform = _test({ + label: `(@no-transform-path) Doesn't transform path`, + group: "Tags", +}); + +export const _test_tag_explicit_transform = _test({ + label: `(@transform-path) Transforms path with explicit value`, + group: "Tags", +}); + +export const _test_exclude = _test({ + label: `(exclude) Doesn't transform for exclusion patterns`, + group: "Options", +}); + +export const _test_type_only_import = _test({ + label: `Type-only import transforms`, + if: (c) => c.tsMajorVersion > 3 || (c.tsMajorVersion == 3 && c.tsMinorVersion >= 8), +}); + +export const _test_module_augmentation = _test({ + label: `Resolves module augmentation`, + for: "dts", +}); + +export const _test_type_elision = _test(`Type elision works properly`); + +export const _test_async_import_comments = _test(`Copies comments in async import`); + +export const _test_explicit_extensions = _test(`Preserves explicit extensions`); diff --git a/test/projects/specific/tsconfig.json b/test/projects/specific/tsconfig.json index 4ea47cbb..7f57916c 100755 --- a/test/projects/specific/tsconfig.json +++ b/test/projects/specific/tsconfig.json @@ -1,5 +1,5 @@ { - "include": [ "src", "generated" ], + "include": [ "src", "tests.ts" ], "compilerOptions": { "noEmit": true, @@ -10,15 +10,12 @@ "moduleResolution": "node", "declaration": true, - "rootDirs": [ "src", "generated" ], - "baseUrl": ".", "paths": { - "#root/*": [ "./src/*", "./generated/*" ], + "#root/*": [ "./src/*" ], "#exclusion/*": [ "./src/excluded/*" ], "#elision": [ "./src/type-elision" ], - "#elision/*": [ "./src/type-elision/*" ], - "#packages/*": [ "./src/packages/*" ] + "#elision/*": [ "./src/type-elision/*" ] }, "resolveJsonModule": true } diff --git a/test/projects/specific/yarn.lock b/test/projects/specific/yarn.lock deleted file mode 100755 index c0770123..00000000 --- a/test/projects/specific/yarn.lock +++ /dev/null @@ -1,8 +0,0 @@ -# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. -# yarn lockfile v1 - - -ts-expose-internals@^4.1.2: - version "4.1.2" - resolved "https://registry.yarnpkg.com/ts-expose-internals/-/ts-expose-internals-4.1.2.tgz#c89a64be5b7ae6634d2f0f25dffa798e2931d136" - integrity sha512-J5xYsQocO5tjP2UMkGlOb5U+joore0AiL1drA5bMPganlQR/9gPmQVO55pQDeHVfy8OATqZaBT5JweyjI6f3eA== diff --git a/test/src/config.ts b/test/src/config.ts new file mode 100755 index 00000000..20639413 --- /dev/null +++ b/test/src/config.ts @@ -0,0 +1,22 @@ +import path from "path"; + +/* ****************************************************************************************************************** */ +// region: Config +/* ****************************************************************************************************************** */ + +export const tsModules = [ + ["Latest", "typescript-latest"], + ["4.2.2", "typescript-42"], +]; + +export const modes = ["program", "manual", "ts-node"] as const; + +export const projectsPath = path.join(__dirname, "../projects"); +export const rootPath = path.resolve(__dirname, "../../"); + +Error.stackTraceLimit = 120; + +export const testCallName = '_test'; +export const expectCallName = '_expect'; + +// endregion diff --git a/test/src/index.ts b/test/src/index.ts new file mode 100755 index 00000000..49f0e731 --- /dev/null +++ b/test/src/index.ts @@ -0,0 +1,2 @@ +export * as ut from "./ut"; +export * from './ts-helpers' diff --git a/test/src/setup.ts b/test/src/setup.ts new file mode 100755 index 00000000..124ad840 --- /dev/null +++ b/test/src/setup.ts @@ -0,0 +1,61 @@ +import { modes, tsModules } from "./config"; +import chalk from "chalk"; +import { toResolve } from "./ut/matchers/to-resolve"; + +/* ****************************************************************************************************************** */ +// region: Types +/* ****************************************************************************************************************** */ + +declare global { + namespace jest { + interface Matchers { + toResolve(): void; + } + } + const envOptions: { + tsModules: typeof tsModules[number][] + buildModes: typeof modes[number][] + testTarget: 'src' | 'dist' + testGroups: string | undefined + } +} + +// endregion + +/* ****************************************************************************************************************** */ +// region: Setup +/* ****************************************************************************************************************** */ + +(function setup() { + let { TS_MODULES, BUILD_MODES, TEST_GROUPS, CI, TEST_TARGET, UT_DEBUG } = process.env; + + /* Get env config */ + const splitStr = (v: string | undefined) => v?.split(',').map(m => m.trim().toLowerCase()); + const opt = { + tsModules: splitStr(TS_MODULES), + buildModes: splitStr(BUILD_MODES), + testGroups: splitStr(TEST_GROUPS), + testTarget: TEST_TARGET === 'dist' ? 'dist' : 'src' + }; + + (global).envOptions = { + tsModules: !opt.tsModules || CI ? tsModules : tsModules.filter((m) => opt.tsModules!.includes(m[0].toLowerCase())), + buildModes: !opt.buildModes || CI ? modes : modes.filter((m) => opt.buildModes!.includes(m.toLowerCase())), + testGroups: CI ? void 0 : opt.testGroups, + testTarget: CI ? 'dist' : opt.testTarget + } + + /* Add Matchers */ + expect.extend({ toResolve }); + + /* Debug Message */ + if (UT_DEBUG) + process.stdout.write( + '\n' + + chalk.yellow(`Started UnderscoreTest Framework ${CI ? chalk.red(`(CI MODE)`) : ''}`) + '\n' + + chalk.grey(`Options: `) + + chalk.grey(JSON.stringify(envOptions, null, 2)) + '\n' + ); +})(); + +// endregion diff --git a/test/src/ts-helpers.ts b/test/src/ts-helpers.ts new file mode 100755 index 00000000..dabb8e96 --- /dev/null +++ b/test/src/ts-helpers.ts @@ -0,0 +1,215 @@ +import { default as tstpTransform, TransformerOptions } from "typescript-transform-paths"; +import fs from "fs"; +import type * as TS from "typescript"; +import type { CompilerOptions, ParsedCommandLine, Program, SourceFile } from "typescript"; +import * as tsNode from "ts-node"; + +/* ****************************************************************************************************************** */ +// region: Types +/* ****************************************************************************************************************** */ + +export type EmittedFiles = { + [fileName: string]: { js: string; dts?: string; js_src?: SourceFile; dts_src?: SourceFile }; +}; + +export interface CreateTsProgramOptions { + tsInstance: typeof TS; + tsConfigFile: string; + disablePlugin?: boolean; + additionalOptions?: CompilerOptions; + pluginOptions?: TransformerOptions; +} + +// endregion + +/* ****************************************************************************************************************** */ +// region: Helpers +/* ****************************************************************************************************************** */ + +function createWriteFile(ts: typeof TS, outputFiles: EmittedFiles) { + return (fileName: string, data: string) => { + let { 1: rootName, 2: ext } = fileName.match(/(.+)\.((d.ts)|(js))$/) ?? []; + if (!ext) return; + rootName = `${rootName}.ts`; + const key = ext.replace('.', '') as 'js' | 'dts'; + if (!outputFiles[rootName]) outputFiles[rootName] = {}; + outputFiles[rootName][key] = data; + (outputFiles[rootName])[key + '_src'] = ts.createSourceFile(fileName, data, ts.ScriptTarget!.ESNext); + }; +} + +function createReadFile(outputFiles: EmittedFiles, originalReadFile: Function) { + return (fileName: string) => { + let { 1: rootName, 2: ext } = fileName.match(/(.+)\.((d.ts)|(js))$/) ?? []; + if (ext) { + rootName = `${rootName}.ts`; + const key = ext.replace('.', '') as keyof EmittedFiles[string]; + const res = outputFiles[rootName]?.[key]; + if (res) return res; + } + return originalReadFile(fileName); + }; +} + +// endregion + +/* ****************************************************************************************************************** */ +// region: Utilities +/* ****************************************************************************************************************** */ + +/** + * Create TS Program with faux files and options + */ +export function createTsProgram(opt: CreateTsProgramOptions): Program { + const { disablePlugin, additionalOptions, pluginOptions } = opt; + const ts: typeof TS = opt.tsInstance; + + const extendOptions = Object.assign({}, additionalOptions, { + outDir: undefined, + noEmit: false, + skipLibCheck: true, + skipDefaultLibCheck: true, + types: ['@types/underscore-test'], + typeRoots: [], + target: ts.ScriptTarget.ESNext, + plugins: disablePlugin + ? [] + : [ + { transform: 'typescript-transform-paths', ...pluginOptions }, + { + transform: 'typescript-transform-paths', + afterDeclarations: true, + ...pluginOptions, + }, + ], + }); + + let compilerOptions: CompilerOptions; + let fileNames: string[]; + + const pcl = ts.getParsedCommandLineOfConfigFile(opt.tsConfigFile, extendOptions, ts.sys)!; + compilerOptions = pcl.options; + fileNames = pcl.fileNames; + + return ts.createProgram({ options: compilerOptions, rootNames: fileNames }); +} + +export function createTsSolutionBuilder( + ts: typeof TS, + projectDir: string, + getTransformers?: (program: TS.Program) => TS.CustomTransformers +) { + // It is annoying to have to do this, but I don't know of any other way to get the program, which is necessary to + // create a TypeChecker instance in the walker + const originalCreateProgram = ts.createProgram as any; + ts.createProgram = function () { + const program = originalCreateProgram(...arguments) as Program; + const transformers = getTransformers?.(program); + + if (transformers) { + const originalEmit = program.emit; + program.emit = ( + targetSourceFile?: TS.SourceFile, + writeFile?: TS.WriteFileCallback, + cancellationToken?: TS.CancellationToken, + emitOnlyDtsFiles?: boolean, + customTransformers?: TS.CustomTransformers + ): TS.EmitResult => { + customTransformers = { + before: [ ...(customTransformers?.before ?? []), ...(transformers.before ?? []) ], + after: [ ...(customTransformers?.after ?? []), ...(transformers.after ?? []) ], + afterDeclarations: [ ...(customTransformers?.afterDeclarations ?? []), ...(transformers.afterDeclarations ?? []) ], + }; + + return originalEmit(targetSourceFile, writeFile, cancellationToken, emitOnlyDtsFiles, customTransformers); + }; + } + + return program; + }; + + const host = ts.createSolutionBuilderHost(); + + host.createDirectory = () => {}; + + const virtualFiles = new Map(); + const originalReadFile = host.readFile; + host.readFile = (p: string, enc: any) => virtualFiles.get(p) ?? originalReadFile(p, enc); + host.writeFile = (p: string, data: string) => virtualFiles.set(p, data); + + return Object.assign(ts.createSolutionBuilder(host, [projectDir], { force: true }), { + restoreTs: () => { ts.createProgram = originalCreateProgram; } + }); +} + +/** + * Get emitted files for program + */ +export function getEmitResultFromProgram(tsInstance: typeof TS, program: Program): EmittedFiles { + const outputFiles: EmittedFiles = {}; + program.emit(undefined, createWriteFile(tsInstance, outputFiles)); + return outputFiles; +} + +export function getManualEmitResult( + pluginConfig: TransformerOptions, + tsInstance: any, + pcl: ParsedCommandLine, + disablePlugin?: boolean +) { + const { options: compilerOptions, fileNames } = pcl; + const transformer = disablePlugin + ? () => (s: TS.SourceFile) => s + : tstpTransform(void 0, pluginConfig, { ts: tsInstance } as any, { compilerOptions, fileNames }); + + const { transformed } = tsInstance.transform( + fileNames.map((f) => + tsInstance.createSourceFile(f, fs.readFileSync(f, 'utf8'), tsInstance.ScriptTarget.ESNext, true) + ), + [transformer], + compilerOptions + ); + + const printer = tsInstance.createPrinter(); + + const res: EmittedFiles = {}; + for (const sourceFile of transformed) res[sourceFile.fileName] = { js: printer.printFile(sourceFile) }; + + return res; +} + +export function getTsNodeEmitResult( + pluginConfig: TransformerOptions, + pcl: ParsedCommandLine, + tsSpecifier: string, + disablePlugin?: boolean +) { + const transformers = disablePlugin + ? void 0 + : { before: [tstpTransform(void 0, pluginConfig, { ts: require(tsSpecifier) })] }; + + const compiler = tsNode.create({ + transpileOnly: true, + transformers, + project: pcl.options.configFilePath, + compiler: tsSpecifier, + logError: true, + ignoreDiagnostics: [1144, 1005], // Issues with old TS and type only imports + }); + + const originalRegister = global.process[tsNode.REGISTER_INSTANCE]; + global.process[tsNode.REGISTER_INSTANCE] = compiler; + try { + const res: EmittedFiles = {}; + for (const fileName of pcl.fileNames.filter((f) => !/\.d\.ts$/.test(f))) + res[fileName] = { + js: compiler.compile(fs.readFileSync(fileName, 'utf8'), fileName).replace(/\/\/# sourceMappingURL.+$/g, '') + }; + + return res; + } finally { + global.process[tsNode.REGISTER_INSTANCE] = originalRegister; + } +} + +// endregion diff --git a/test/src/ut-global/globals.d.ts b/test/src/ut-global/globals.d.ts new file mode 100755 index 00000000..dfeb5276 --- /dev/null +++ b/test/src/ut-global/globals.d.ts @@ -0,0 +1,117 @@ + +/* ****************************************************************************************************************** */ +// region: Project Functions +/* ****************************************************************************************************************** */ + +declare function _test(label: TestConfig['label']): UnderscoreTest; +declare function _test(cfg: TestConfig): UnderscoreTest; + +declare function _expect(test: UnderscoreTest, path?: ExpectConfig['path']): void +declare function _expect(test: UnderscoreTest, cfg?: ExpectConfig): void + +declare namespace _expect { + /** + * Get expected path with implicit index based on run config + * @param path Expected path (without implicits index or extension) + * @param implicitIndex Defaults to 'index' (do not add extension, as this is automatically determined) + */ + export function index(path: string, implicitIndex?: string): string; + + /** + * Get expected path with implicit extension based on run config + * @param path + * @param implicitExtension Defaults to '.js' for js or '.d.ts' for declarations + */ + export function path(path: string, implicitExtension?: string): string; +} + +// endregion + + +/* ****************************************************************************************************************** */ +// region: Project Function Types +/* ****************************************************************************************************************** */ + +declare interface TestConfig { + label: string | ((opt: TestRunConfig) => string) + + /** + * This test will only process if predicate is true + */ + if?: (c: TestRunConfig) => boolean + + /** + * Assign a group name to the test + */ + group?: string + + /** + * Only run test for specific output type + */ + for?: ForKind +} + +declare interface ExpectConfig { + /** + * Only apply expect if predicate is true + */ + if?: (c: TestRunConfig) => boolean + + /** + * Only apply expect to a certain type of output file + * @default 'all' + */ + for?: ForKind + + /** + * Specific Path + * @default same as source + */ + path?: string | undefined | ((c: TestRunConfig) => string) + + /** + * Specific Path if outputMode = 'esm' + * Note: Not all tests use esm mode + */ + esmPath?: string | undefined | ((c: TestRunConfig) => string) + + /** + * If true, the entire node is expected to be elided + */ + elided?: boolean + + /** + * Expected specifiers + * @example + * _expect(_my_test, 'path', { specifiers: [ 'shown' ] }); + * import { shown, elided } from 'path'; + */ + specifiers?: string [] + + /** + * Additional check predicate (test fails if predicate returns false) + */ + extraCheck?: (compiledStatement: string | undefined) => boolean +} + +// endregion + +/* ****************************************************************************************************************** */ +// region: Internal +/* ****************************************************************************************************************** */ + +declare type ForKind = 'dts' | 'js' | 'all'; + +declare const underscoreTestSym: unique symbol; +declare interface UnderscoreTest { + [underscoreTestSym]: boolean +} + +declare interface TestRunConfig { + pluginOptions?: Record + mode: 'program' | 'ts-node' | 'manual' + tsMajorVersion: number + tsMinorVersion: number +} + +// endregion diff --git a/test/src/ut-global/package.json b/test/src/ut-global/package.json new file mode 100755 index 00000000..03652a98 --- /dev/null +++ b/test/src/ut-global/package.json @@ -0,0 +1,6 @@ +{ + "name": "@types/tester", + "version": "0.0.0", + "private": true, + "types": "globals.d.ts" +} diff --git a/test/src/ut-global/tsconfig.json b/test/src/ut-global/tsconfig.json new file mode 100755 index 00000000..3d206364 --- /dev/null +++ b/test/src/ut-global/tsconfig.json @@ -0,0 +1,7 @@ +{ + "include": [ "globals.d.ts" ], + "compilerOptions": { + "types": [], + "typeRoots": [] + } +} diff --git a/test/src/ut/index.ts b/test/src/ut/index.ts new file mode 100755 index 00000000..923497a4 --- /dev/null +++ b/test/src/ut/index.ts @@ -0,0 +1,3 @@ +export { loadProject } from "./project"; +export { createConfigSpread } from "./utils/create-config-spread"; +export * from './types' diff --git a/test/src/ut/matchers/to-resolve.ts b/test/src/ut/matchers/to-resolve.ts new file mode 100755 index 00000000..fd3f74dc --- /dev/null +++ b/test/src/ut/matchers/to-resolve.ts @@ -0,0 +1,47 @@ +import { ExpectDetail } from "../types"; +import chalk from "chalk"; +import path from "path"; +import { projectsPath } from "../../config"; +import { matcherHint } from "jest-matcher-utils"; +import { diff } from "jest-diff"; + + +/* ****************************************************************************************************************** * + * toResolve() (Jest Matcher) + * ****************************************************************************************************************** */ + +export const toResolve: jest.CustomMatcher = function toResolve(detail: ExpectDetail) { + const { expectedOutput, actualOutput, sourceFile, targetNode, config } = detail; + + let failType: 'equality' | 'extraCheck' = 'equality'; + let pass = detail.expectedOutput === detail.actualOutput; + const pos = sourceFile.getLineAndCharacterOfPosition(targetNode.getStart(sourceFile)); + let detailStr = + `File: ${chalk.white(path.relative(projectsPath, detail.sourceFile.fileName))}\n` + + `Line: ${chalk.white(pos.line+1)}\n` + + `Output: ${chalk.white(detail.compiledSourceFile.isDeclarationFile ? 'declarations' : 'js')}\n\n`; + + if (config.extraCheck && !config.extraCheck(actualOutput)) { + failType = 'extraCheck'; + pass = false; + } + + let message: () => string; + if (pass) { + message = () => `${matcherHint(`.not.toResolve`)}\n` + detailStr; + } else { + message = () => + `${matcherHint(`.toResolve`)}\n` + detailStr + + (failType === 'extraCheck' + ? `Failed extraCheck: ${config.extraCheck!.toString()}` + : diff(expectedOutput, actualOutput, { expand: this.expand }) + '\n'); + } + + return { + actual: actualOutput, + expected: expectedOutput, + message: message, + name: "toResolve", + pass, + }; +}; diff --git a/test/src/ut/project/index.ts b/test/src/ut/project/index.ts new file mode 100755 index 00000000..8390f3e1 --- /dev/null +++ b/test/src/ut/project/index.ts @@ -0,0 +1 @@ +export * from './load-project' diff --git a/test/src/ut/project/load-project.ts b/test/src/ut/project/load-project.ts new file mode 100755 index 00000000..bf4c54b4 --- /dev/null +++ b/test/src/ut/project/load-project.ts @@ -0,0 +1,154 @@ +import type * as TS from "typescript"; +import { createTsProgram, createTsSolutionBuilder } from "../../ts-helpers"; +import path from "path"; +import { projectsPath } from "../../config"; +import { ProjectRunGroup, UnderscoreTestContext, UtProjectConfig } from "../types"; +import { TestMap } from "../test-map"; +import { getProjectWalker } from "./project-walker"; +import type { TransformerOptions } from 'tstp/src'; +import { getTransformerConfig } from "tstp/src/transform/transformer"; +import { default as tstpTransform } from "typescript-transform-paths"; + +/* ****************************************************************************************************************** */ +// region: Helpers +/* ****************************************************************************************************************** */ + +/** + * Note: Does not currently support pluginOptions from runConfig + */ +function emitWithSolutionBuilder(context: UnderscoreTestContext) { + const { ts, projectDir, runConfig: { pluginOptions }, projectConfig: { builderTransformerPredicate } } = context; + + const builder = createTsSolutionBuilder(ts, projectDir, (program) => { + if (builderTransformerPredicate && !builderTransformerPredicate(program)) return {}; + + const tstpTransformer = tstpTransform(program, pluginOptions, { ts }); + const utWalker = getProjectWalker(context, program); + return { + before: [ tstpTransformer ], + after: [ utWalker ], + afterDeclarations: [ tstpTransformer, utWalker ] as TS.TransformerFactory[] + } + }); + + builder.build(); + builder.restoreTs(); // Do not remove. Needed to unpatch TS createProgram +} + +function emitWithProgram(context: UnderscoreTestContext) { + const { projectDir, ts } = context; + + const program = createTsProgram({ + tsConfigFile: path.join(projectDir, "tsconfig.json"), + tsInstance: ts, + pluginOptions: context.runConfig.pluginOptions + }); + + const t = getProjectWalker(context, program); + const customTransformers = { after: [t], afterDeclarations: [t as TS.TransformerFactory] }; + program.emit(undefined, () => {}, void 0, false, customTransformers); +} + +function emit(context: UnderscoreTestContext) { + const { projectConfig: { programKind } } = context; + return programKind === 'solutionBuilder' ? emitWithSolutionBuilder(context) : emitWithProgram(context); +} + +function createContext( + projectDir: string, + projectConfig: T, + tsModule: typeof envOptions.tsModules[number], + ts: typeof TS, + runConfig: TestRunConfig +) { + const context: UnderscoreTestContext = { + ts, + projectConfig, + tests: void 0, + printer: ts.createPrinter(), + projectDir, + tsModule, + runConfig, + transformerConfig: getTransformerConfig(runConfig.pluginOptions), + walkLog: { + js: false, + declarations: false + } + }; + context.tests = new TestMap(context); + + return context; +} + +// endregion + +/* ****************************************************************************************************************** * + * loadProject (Utility) + * ****************************************************************************************************************** */ + +export function loadProject(projectConfig: T) { + const { projectName, configs, useGroups } = projectConfig; + + const projectDir = path.resolve(projectsPath, projectName); + + const allowedTs = projectConfig.allowedTs?.map((m) => m.toLowerCase()) as string[]; + const tsModules = !projectConfig.allowedTs + ? envOptions.tsModules + : envOptions.tsModules.filter((m) => allowedTs!.includes(m[0].toLowerCase())); + const tsInstances = new Map(); + + let res: ProjectRunGroup[] = []; + for (const tsModule of tsModules) { + for (const config of [ configs ].flat()) { + const runConfig = createRunConfig(tsModule, config); + const testMap = loadTests(tsModule, runConfig); + const runLabel = `[TS: ${tsModule[0]}` + (config ? ` - ` + getConfigLabel(config) : '') + ']'; + const run = { runLabel } as ProjectRunGroup; + + if (useGroups) { + run.groups = []; + for (const groupName of testMap.getGroups()) + run.groups.push({ groupLabel: `[${groupName}]`, tests: testMap.getTestsForGroup(groupName) }); + } + else run.tests = testMap.getTests(); + + res.push(run); + } + } + + return res; + + function getConfigLabel(config: Record) { + return Object.entries(config).map(([k, v]) => `${k}: ${v?.toString()}`).join(', '); + } + + function loadTests(tsModule: typeof tsModules[number], runConfig: TestRunConfig) { + const ctx = createContext(projectDir, projectConfig, tsModule, getTsInstance(tsModule), runConfig); + + emit(ctx); + + if (!ctx.walkLog.js) throw new Error(`Walker never executed for js files!`); + if (!ctx.walkLog.declarations) throw new Error(`Walker never executed for declarations files!`); + + return ctx.tests.validate(); + } + + function createRunConfig(tsModule: typeof tsModules[number], config?: TransformerOptions): TestRunConfig { + const ts = getTsInstance(tsModule); + const [ majorVer, minorVer ] = ts.versionMajorMinor.split('.'); + return { + mode: 'program', + tsMajorVersion: +majorVer, + tsMinorVersion: +minorVer, + pluginOptions: { + ...projectConfig.pluginOptions, + ...config + } + }; + } + + function getTsInstance(tsModule: typeof tsModules[number]) { + if (!tsInstances.has(tsModule)) tsInstances.set(tsModule, require(tsModule[1])); + return tsInstances.get(tsModule)!; + } +} diff --git a/test/src/ut/project/project-walker.ts b/test/src/ut/project/project-walker.ts new file mode 100755 index 00000000..1f30f6f9 --- /dev/null +++ b/test/src/ut/project/project-walker.ts @@ -0,0 +1,344 @@ +import { TestDetail, UnderscoreTestContext } from "../types"; +import type { Identifier, Node, Program, SourceFile, TransformationContext, TransformerFactory } from "typescript"; +import type TS from "typescript"; +import { expectCallName, testCallName } from "../../config"; +import { + getFirstOriginal, getString, getStringOrFunctionOrObjectLiteral, isAsyncImport, isRequire, +} from "../utils/node-helpers"; +import { createHarmonyFactory, copyNodeComments } from "tstp/src/ts"; +import { assert } from "console"; + + +/* ****************************************************************************************************************** */ +// region: Types +/* ****************************************************************************************************************** */ + +export interface VisitorContext extends UnderscoreTestContext { + checker: TS.TypeChecker + factory: TS.NodeFactory + sourceFile: SourceFile + compiledSourceFile: SourceFile + isDeclarations: boolean +} + +// endregion + +/* ****************************************************************************************************************** */ +// region: Helpers +/* ****************************************************************************************************************** */ + +function getExpectTargetNode(ctx: VisitorContext, expectIndex: number) { + const { ts, sourceFile, compiledSourceFile } = ctx; + + const expectNode = sourceFile.statements[expectIndex]; + const targetNode = findTarget(sourceFile, expectIndex); + if (!targetNode) throw new Error(`No target found for _expect()! Please check your syntax — ` + expectNode.getText()); + + const compiledTargetNode = findStatementByOriginal(targetNode, compiledSourceFile); + + return { targetNode, compiledTargetNode }; + + function findTarget(s: SourceFile, idx: number) { + for (let i = idx + 1; i < s.statements.length; i++) { + const node = s.statements[i]; + if ( + ts.isExpressionStatement(node) && + ts.isCallExpression(node.expression) && + node.expression.expression && + ts.isIdentifier(node.expression.expression) && + node.expression.expression.text === expectCallName + ) + continue; + + if (isValidTarget(node)) return node; + + throw new Error( + `Unexpected target node type! _expect() must follow statement with valid transform target — ` + + expectNode.getText() + ); + } + } + + function isValidTarget(t: Node) { + return ts.isImportDeclaration(t) || ts.isExportDeclaration(t) || ts.isModuleDeclaration(t) || checkChildren(t); + + function checkChildren(n: Node): boolean { + if (isRequire(ts, n) || isAsyncImport(ts, n) || ts.isImportTypeNode(n) || ts.isExternalModuleReference(n)) + return true; + + try { + if (n.getChildCount(sourceFile)) + for (const child of n.getChildren(sourceFile)) if (checkChildren(child)) return true; + } catch {} + return false; + } + } +} + +function getExpectedOutput( + { ts, printer, compiledSourceFile, sourceFile }: VisitorContext, + factory: TS.NodeFactory, + node: Node, + expectedPath: string | undefined, + config: ExpectConfig | undefined +) { + if (!factory) factory = ts as any; + + let moduleSpecifier: TS.StringLiteral | undefined = expectedPath ? factory.createStringLiteral(expectedPath) : void 0; + + if (ts.isImportDeclaration(node)) { + let namedBindings = node.importClause?.namedBindings; + if (namedBindings && ts.isNamedImports(namedBindings) && config?.specifiers) + namedBindings = factory.createNamedImports( + namedBindings.elements.filter((b) => config.specifiers!.includes(b.name.text)) + ); + + return print( + factory.createImportDeclaration( + node.decorators, + node.modifiers, + node.importClause && factory.createImportClause(node.importClause.isTypeOnly, node.importClause.name, namedBindings), + moduleSpecifier || node.moduleSpecifier + ) + ); + } else if (ts.isExportDeclaration(node)) { + let exportClause = node.exportClause; + if (exportClause && ts.isNamedExports(exportClause) && config?.specifiers) + exportClause = factory.createNamedExports( + exportClause.elements.filter((e) => config.specifiers!.includes(e.name.text)) + ); + + moduleSpecifier ||= node.moduleSpecifier as TS.StringLiteral; + + return print( + factory.createExportDeclaration(node.decorators, node.modifiers, node.isTypeOnly, exportClause, moduleSpecifier) + ); + } else if (ts.isExternalModuleReference(node)) { + return print(moduleSpecifier ? factory.createExternalModuleReference(moduleSpecifier) : node); + } + else if (ts.isImportTypeNode(node)) { + const argument = moduleSpecifier ? factory.createLiteralTypeNode(moduleSpecifier as TS.LiteralExpression) : node.argument; + return print(factory.createImportTypeNode(argument, node.qualifier, node.typeArguments, node.isTypeOf)); + } else if (ts.isModuleDeclaration(node)) + return print( + factory.createModuleDeclaration(node.decorators, node.modifiers, moduleSpecifier as TS.ModuleName || node.name, node.body, node.flags) + ); + else { + const res = print(node); + return expectedPath + ? res.replace(/((?:^|\s*)(?:require|import)\(['"])(.+?)(['"]\))/g, `$1${expectedPath}$3`) + : res; + } + + function print(n: Node) { + if (n !== node) copyNodeComments(ts, sourceFile, node, n); + return printer.printNode(ts.EmitHint?.Unspecified, n, compiledSourceFile); + } +} + +function getExpectMethodResult( + ctx: VisitorContext, + rootNode: TS.ExpressionStatement, + node: TS.CallExpression +) { + const { ts, transformerConfig: cfg, compiledSourceFile, sourceFile } = ctx; + if ( + ts.isPropertyAccessExpression(node.expression) && ts.isIdentifier(node.expression.expression) && + node.expression.expression.text === expectCallName && ts.isIdentifier(node.expression.name) + ) { + const fnName = node.expression.name.text; + if (fnName === 'index' || fnName === 'path') { + const getExt = () => compiledSourceFile.isDeclarationFile ? '.d.ts' : '.js'; + const args = node.arguments.map(n => getString(ctx, n, sourceFile)); + + let res: string = args[0]; + if (fnName === 'index' && cfg.outputIndexes === 'always') + res += '/' + (args[1] ?? 'index') + (cfg.outputExtensions !== 'always' ? '' : getExt()); + else if (fnName === 'path' && cfg.outputExtensions === 'always') res += args[1] ?? getExt(); + + return res; + } + } + + throw new Error(`Invalid call expression in expect config: ${rootNode.getText(sourceFile)}`); +} + +function checkForKind(forKind: ForKind | undefined, sourceFile: SourceFile) { + switch (forKind) { + case 'all': + case undefined: + return true; + case 'dts': + return sourceFile.isDeclarationFile + case 'js': + return !sourceFile.isDeclarationFile + } +} + +function findStatementByOriginal(originalNode: Node, sourceFile: SourceFile) { + for (const s of sourceFile.statements) + for (let n: Node | undefined = s; n; n = n.original) + if (n === originalNode) return s; +} + +// endregion + +/* ****************************************************************************************************************** */ +// region: Checkers +/* ****************************************************************************************************************** */ + +/** + * Handle _expect() — ie. _expect(...) + */ +function checkExpect(context: VisitorContext, node: Node, statementIndex: number): void { + const { ts, checker, factory, runConfig, printer, tests, sourceFile, compiledSourceFile } = context; + + if ( + ts.isExpressionStatement(node) && + ts.isCallExpression(node.expression) && + ts.isIdentifier(node.expression.expression) && + node.expression.expression.text === expectCallName + ) { + const [testNameNode, pathOrConfigOrCallNode] = node.expression.arguments as unknown as [Node, Node?]; + assert(ts.isIdentifier(testNameNode)); + + /* Get Test */ + const testName = (testNameNode as Identifier).text; + let test = tests.get(testName); + if (!test) { + let sym = checker.getSymbolAtLocation(testNameNode)!; + let aliasedSym: TS.Symbol | undefined; + try { + aliasedSym = checker.getAliasedSymbol(sym); + } catch {} + + const testNode = ts.getRootDeclaration((aliasedSym ?? sym).valueDeclaration!).parent.parent; + test = checkTest(context, testNode, true)!; + } + + if (!test.enabled) return; + + /* Get Config */ + const pathOrConfig = + !pathOrConfigOrCallNode ? void 0 : + ts.isCallExpression(pathOrConfigOrCallNode) ? getExpectMethodResult(context, node, pathOrConfigOrCallNode) : + getStringOrFunctionOrObjectLiteral(context, pathOrConfigOrCallNode, sourceFile)!; + + const config: ExpectConfig = + !pathOrConfigOrCallNode ? { path: undefined } : + (typeof pathOrConfig === 'string' || typeof pathOrConfigOrCallNode === 'function') + ? { path: pathOrConfig } as ExpectConfig + : pathOrConfig as ExpectConfig; + + const expectedPath = typeof config.path === 'string' ? config.path : + typeof config.path === 'function' ? config.path(runConfig) : + void 0; + + /* Check against expect config if & for */ + if (config.if && !config.if(runConfig)) return; + if (!checkForKind(config.for, compiledSourceFile)) return; + + /* Find target nodes */ + const { targetNode, compiledTargetNode } = getExpectTargetNode(context, statementIndex); + if (!config.elided && !compiledTargetNode) + throw new Error( + `No target found for _expect() in compiled code! Did you mean to set elided: true? — ` + + targetNode.getText() + ); + + /* Create output comparisons */ + let expectedOutput = config.elided ? void 0 : getExpectedOutput(context, factory, targetNode, expectedPath, config); + let actualOutput = compiledTargetNode ? printer.printNode(ts.EmitHint.Unspecified, compiledTargetNode, compiledSourceFile) : void 0; + + if (expectedOutput) expectedOutput = standardizeQuotes(expectedOutput); + if (actualOutput) actualOutput = standardizeQuotes(actualOutput); + + test.expects.push({ + config, + sourceFile, + compiledSourceFile, + testName, + targetNode, + compiledTargetNode, + expectedOutput, + actualOutput, + }); + } + + function standardizeQuotes(s: string) { + return s.replace(/['"]/g, '"'); + } +} + +/** + * Handle _test() — ie. const test_name = _test(...) + */ +function checkTest( + context: VisitorContext, + node: Node, + expectValidTest: boolean = false +): TestDetail | undefined { + const { ts, tests, runConfig, sourceFile, compiledSourceFile } = context; + + if (ts.isVariableStatement(node) && node.declarationList.declarations.length === 1) { + const declarationNode = node.declarationList.declarations[0]; + if (declarationNode.initializer && ts.isIdentifier(declarationNode.name)) { + const init = declarationNode.initializer; + if (ts.isCallExpression(init) && ts.isIdentifier(init.expression) && init.expression.text === testCallName) { + const arg0 = getStringOrFunctionOrObjectLiteral(context, init.arguments[0], sourceFile); + const config = (typeof arg0 === 'string' || typeof arg0 === 'function') ? { label: arg0 } as TestConfig : arg0; + const label = typeof config.label === 'string' ? config.label : config.label(runConfig); + const testName = declarationNode.name.text; + + let detail: TestDetail; + if (!tests.has(testName)) { + const enabled = (!config.if || config.if(context.runConfig)) && checkForKind(config.for, compiledSourceFile); + detail = { sourceFile, expects: [], config, label, testName, enabled }; + tests.set(testName, detail); + } else detail = tests.get(testName)!; + + return detail; + } + } + } + + if (expectValidTest) throw new Error(`Expected valid _test node, but got: ${node.getText(sourceFile)}`); +} + +// endregion + +/* ****************************************************************************************************************** */ +// region: Walker Factory +/* ****************************************************************************************************************** */ + +export function getProjectWalker(context: UnderscoreTestContext, program: Program) { + const { ts } = context; + const checker = program.getTypeChecker(); + + const transformer: TransformerFactory = (tCtx: TransformationContext) => (compiledSourceFile: SourceFile) => { + const factory = createHarmonyFactory(ts, tCtx.factory); + const sourceFile = getFirstOriginal(compiledSourceFile); + const visitorContext: VisitorContext = { + ...context, + checker, + factory, + sourceFile, + compiledSourceFile, + isDeclarations: compiledSourceFile.isDeclarationFile + }; + + context.walkLog.declarations ||= compiledSourceFile.isDeclarationFile; + context.walkLog.js ||= !compiledSourceFile.isDeclarationFile; + + sourceFile.statements.forEach((s, idx) => { + checkTest(visitorContext, s); + checkExpect(visitorContext, s, idx); + }); + + return compiledSourceFile; + }; + + return transformer; +} + +// endregion diff --git a/test/src/ut/test-map.ts b/test/src/ut/test-map.ts new file mode 100755 index 00000000..12833f28 --- /dev/null +++ b/test/src/ut/test-map.ts @@ -0,0 +1,77 @@ +import { TestDetail, UnderscoreTestContext } from "./types"; + +/* ****************************************************************************************************************** * + * Locals + * ****************************************************************************************************************** */ + +const defaultNonGroupedTag = 'General'; + +/* ****************************************************************************************************************** * + * TestMap (class) + * ****************************************************************************************************************** */ + +export class TestMap extends Map { + constructor( + private testContext: UnderscoreTestContext, + private nonGroupedTag: string = defaultNonGroupedTag + ) { + super(); + } + + /* ********************************************************* * + * Methods + * ********************************************************* */ + + getTests() { + return this.getTestsWorker(); + } + + getTestsForGroup(groupName: string | undefined) { + return this.getTestsWorker(groupName); + } + + private getTestsWorker(groupName?: string) { + const res = Array.from(this.values()) + .map((detail) => [ + typeof detail.label === "string" ? detail.label : detail.label(this.testContext.runConfig), + detail, + ]); + + return !groupName + ? res + : res.filter(([_, d]) => d.config.group === groupName || (!d.config.group && groupName === this.nonGroupedTag)); + } + + getGroups(): (string | undefined)[] { + let res = Array.from(new Set([ ...this.values() ].map(t => t.config?.group || this.nonGroupedTag))) + if (envOptions.testGroups) res = res.filter(g => envOptions.testGroups!.includes(g.toLowerCase())); + return res; + } + + + /* ********************************************************* * + * Internal + * ********************************************************* */ + + /** + * Validate tests and returns self + */ + validate(): this { + const tsLabel = this.testContext.tsModule[0]; + + for (const [key, test] of this.entries()) { + if (!test.enabled) this.delete(key); + else if (test.expects.length < 1) + throw new Error( + `No expects found for '${test.testName}' in ${test.sourceFile.fileName} in TS: ${tsLabel}` + ); + } + + if (!this.size) throw new Error( + `No tests enabled for current configuration in TS: ${tsLabel}! \n` + + JSON.stringify(this.testContext.projectConfig, null, 2) + ); + + return this; + } +} diff --git a/test/src/ut/types.ts b/test/src/ut/types.ts new file mode 100755 index 00000000..69ebbc4e --- /dev/null +++ b/test/src/ut/types.ts @@ -0,0 +1,63 @@ +import TS, { Node, SourceFile } from "typescript"; +import { tsModules } from "../config"; +import { TransformerConfig, TransformerOptions } from "tstp/src"; +import { TestMap } from "./test-map"; + + +/* ****************************************************************************************************************** * + * Types + * ****************************************************************************************************************** */ + +export interface ExpectDetail { + sourceFile: SourceFile + compiledSourceFile: SourceFile + testName: string + config: ExpectConfig + targetNode: Node + compiledTargetNode: Node | undefined + expectedOutput: string | undefined + actualOutput: string | undefined +} + +export interface TestDetail { + sourceFile: SourceFile + expects: ExpectDetail[] + config: TestConfig + testName: string + label: string | ((opt: any) => string) + enabled: boolean +} + +export interface UtProjectConfig { + projectName: string; + programKind?: 'program' | 'solutionBuilder' + /** + * Restrict to specific TS version (initializes array with those specified but can be narrowed by env var) + */ + allowedTs?: typeof tsModules[number][0][] + pluginOptions?: TransformerOptions | ((ctx: TestRunConfig) => TransformerOptions) + useGroups?: boolean + configs?: TransformerOptions[] + builderTransformerPredicate?: (program: TS.Program) => boolean +} + +export interface UnderscoreTestContext { + projectConfig: UtProjectConfig + ts: typeof TS + printer: TS.Printer + tests: TestMap + projectDir: string + tsModule: typeof tsModules[number] + runConfig: TestRunConfig + transformerConfig: TransformerConfig + walkLog: { + declarations: boolean + js: boolean + } +} + +export interface ProjectRunGroup { + runLabel: string; + tests: (readonly [ string, TestDetail])[], + groups: { groupLabel: string, tests: (readonly [ string, TestDetail ])[] }[] +} diff --git a/test/src/ut/utils/create-config-spread.ts b/test/src/ut/utils/create-config-spread.ts new file mode 100755 index 00000000..1f607af6 --- /dev/null +++ b/test/src/ut/utils/create-config-spread.ts @@ -0,0 +1,34 @@ +import { TransformerOptions } from 'tstp/src'; + +/* ****************************************************************************************************************** * + * Types + * ****************************************************************************************************************** */ + +type SpreadableConfig = { + [K in keyof TransformerOptions]?: TransformerOptions[K][] | TransformerOptions[K]; +}; + +/* ****************************************************************************************************************** * + * createConfigSpread (Util) + * ****************************************************************************************************************** */ + +export function createConfigSpread(config: SpreadableConfig) { + const staticProps: TransformerOptions = {}; + for (const [k, v] of Object.entries(config)) if (!Array.isArray(v)) (staticProps)[k] = v; + + const res: TransformerOptions[] = []; + for (const [k, v] of Object.entries(config)) { + if (!Array.isArray(v)) continue; + + const configs = v.map((val) => ({ ...staticProps, [k]: val })); + if (!res.length) res.push(...configs); + else { + for (const existing of [ ...res ]) { + res.shift(); + res.push(...configs.map(c => ({ ...existing, ...c }))); + } + } + } + + return res; +} diff --git a/test/src/ut/utils/node-helpers.ts b/test/src/ut/utils/node-helpers.ts new file mode 100755 index 00000000..e007d1aa --- /dev/null +++ b/test/src/ut/utils/node-helpers.ts @@ -0,0 +1,66 @@ +import ts, { Node, SourceFile } from "typescript"; +import { UnderscoreTestContext } from "../types"; + +/* ****************************************************************************************************************** * + * Node Helpers + * ****************************************************************************************************************** */ + +export const isAsyncImport = (tsInstance: typeof ts, node: ts.Node): node is ts.CallExpression => + tsInstance.isCallExpression(node) && + node.expression.kind === tsInstance.SyntaxKind.ImportKeyword && + tsInstance.isStringLiteral(node.arguments[0]) && + node.arguments.length === 1; + +export const isRequire = (tsInstance: typeof ts, node: ts.Node): node is ts.CallExpression => + tsInstance.isCallExpression(node) && node.expression && + tsInstance.isIdentifier(node.expression) && + node.expression.text === "require" && + tsInstance.isStringLiteral(node.arguments[0]) && + node.arguments.length === 1; + +export function getFirstOriginal(node: T): T { + for (let n: any = node; n; n = n.original) + if (!n.original) return n; + + return node; +} + +export function getString({ ts, printer }: UnderscoreTestContext, node: Node, sourceFile: SourceFile): string { + const res: string | undefined = + ts.isStringLiteral(node) || ts.isNoSubstitutionTemplateLiteral(node) ? node.text : + void 0; + + if (!res) throw new Error(`Expression is not a string! Expression: ${getFirstOriginal(node).getText(sourceFile)}`); + return res; +} + +export function getStringOrFunctionOrObjectLiteral(ctx: UnderscoreTestContext, node: Node, sourceFile: SourceFile): T { + try { + return getStringOrFunction(ctx, node, sourceFile) as T; + } catch { + try { + return getObjectLiteral(ctx, node, sourceFile) as T; + } catch { + throw new Error(`Expression is not a valid string, function, or object literal. Expression ${getFirstOriginal(node).getText(sourceFile)}`); + } + } +} + +export function getStringOrFunction({ ts, printer }: UnderscoreTestContext, node: Node, sourceFile: SourceFile): T { + const res: string | Function | undefined = + ts.isStringLiteral(node) || ts.isNoSubstitutionTemplateLiteral(node) ? node.text : + ts.isArrowFunction(node) || ts.isFunctionExpression(node) ? eval(`(${printer.printNode(ts.EmitHint.Expression, node, sourceFile)})`) as Function : + void 0; + + if (!res) throw new Error(`Expression is not a string or function! Expression: ${getFirstOriginal(node).getText(sourceFile)}`); + return res as unknown as T; +} + +export function getObjectLiteral({ ts, printer }: UnderscoreTestContext, node: Node, sourceFile: SourceFile): T { + const res: object | undefined = ts.isObjectLiteralExpression(node) + ? eval(`(${printer.printNode(ts.EmitHint.Expression, node, sourceFile)})`) + : void 0; + + if (!res) throw new Error(`Expression is not an object literal! Expression: ${getFirstOriginal(node).getText(sourceFile)}`); + return res as unknown as T; +} diff --git a/test/tests/register.test.ts b/test/tests/compatibility/node-register.test.ts similarity index 90% rename from test/tests/register.test.ts rename to test/tests/compatibility/node-register.test.ts index 717ef4ec..0904a7b5 100755 --- a/test/tests/register.test.ts +++ b/test/tests/compatibility/node-register.test.ts @@ -1,7 +1,5 @@ -import { register } from "../../src"; -import { PluginConfig } from "ts-patch"; +import { nodeRegister } from "typescript-transform-paths"; import * as tsNode from "ts-node"; -import * as transformerModule from "../../src/transformer"; import { REGISTER_INSTANCE } from "ts-node"; import { CustomTransformers, PluginImport, Program } from "typescript"; @@ -9,8 +7,11 @@ import { CustomTransformers, PluginImport, Program } from "typescript"; * Config * ****************************************************************************************************************** */ +const transformerModule = require(`tstp/${envOptions.testTarget}/transform/transformer`); + const pluginOptions = { opt1: true, opt2: 3 }; const otherTransformer = { transform: "fake-transformer@23904" }; + const configs = { "Implicit before": {}, "Explicit before": { before: true }, @@ -26,7 +27,7 @@ const configMap = Object.entries(configs).map(([label, cfg]) => { .map((c) => { if ((c).before || !(c).afterDeclarations) hasBefore = true; if ((c).afterDeclarations) hasAfterDeclarations = true; - return { transform: "typescript-transform-paths", ...c, ...pluginOptions } as PluginConfig; + return { transform: "typescript-transform-paths", ...c, ...pluginOptions } as any; }) .concat([otherTransformer]); @@ -39,7 +40,7 @@ const instanceSymbol: typeof REGISTER_INSTANCE = tsNode["REGISTER_INSTANCE"]; * Tests * ****************************************************************************************************************** */ -describe(`Register script`, () => { +describe(`[Compatibility: ts-node] Register script`, () => { describe(`Initialize`, () => { test(`Registers initial ts-node if none found`, () => { const originalTsNodeInstance = global.process[instanceSymbol]; @@ -49,7 +50,7 @@ describe(`Register script`, () => { registerSpy = jest.spyOn(tsNode, "register"); expect(global.process[instanceSymbol]).toBeUndefined(); - register.initialize(); + nodeRegister.initialize(); expect(registerSpy).toBeCalledTimes(1); expect(registerSpy.mock.calls[0]).toHaveLength(0); @@ -68,7 +69,7 @@ describe(`Register script`, () => { try { registerSpy = jest.spyOn(tsNode, "register"); - const { tsNodeInstance } = register.initialize(); + const { tsNodeInstance } = nodeRegister.initialize(); expect(registerSpy).not.toBeCalled(); expect(tsNodeInstance).toBe(fakeInstance); @@ -79,7 +80,7 @@ describe(`Register script`, () => { }); test(`Returns instance, tsNode, and symbol`, () => { - const res = register.initialize(); + const res = nodeRegister.initialize(); expect(res.tsNode).toBe(tsNode); expect(res.tsNodeInstance).toBe(global.process[instanceSymbol]); expect(res.instanceSymbol).toBe(instanceSymbol); @@ -95,26 +96,26 @@ describe(`Register script`, () => { }, { virtual: true } ); - expect(() => register()).toThrow(`Cannot resolve ts-node`); + expect(() => nodeRegister()).toThrow(`Cannot resolve ts-node`); jest.dontMock("ts-node"); }); test(`Throws if can't register ts-node`, () => { jest.doMock("ts-node", () => ({ register: () => {} }), { virtual: true }); - expect(() => register()).toThrow(`Could not register ts-node instance!`); + expect(() => nodeRegister()).toThrow(`Could not register ts-node instance!`); jest.dontMock("ts-node"); }); test(`No transformers in tsConfig exits quietly`, () => { - const originalInitialize = register.initialize; - const initializeSpy = jest.spyOn(register, "initialize"); + const originalInitialize = nodeRegister.initialize; + const initializeSpy = jest.spyOn(nodeRegister, "initialize"); try { initializeSpy.mockImplementation(() => { const res = originalInitialize(); delete res.tsNodeInstance.config.options.plugins; return res; }); - expect(register()).toBeUndefined(); + expect(nodeRegister()).toBeUndefined(); } finally { initializeSpy.mockRestore(); } @@ -155,12 +156,12 @@ describe(`Register script`, () => { let mergedTransformers: CustomTransformers; beforeAll(() => { - mockTransformer = jest.spyOn(transformerModule, "default").mockReturnValue(fakeTransformer); + mockTransformer = jest.spyOn(transformerModule, "transformer").mockReturnValue(fakeTransformer); global.process[instanceSymbol] = void 0; - const originalInitialize = register.initialize; - initializeSpy = jest.spyOn(register, "initialize"); + const originalInitialize = nodeRegister.initialize; + initializeSpy = jest.spyOn(nodeRegister, "initialize"); initializeSpy.mockImplementation(() => { const res = originalInitialize(); if (existingTransformers) res.tsNodeInstance.options.transformers = existingTransformers; @@ -171,7 +172,7 @@ describe(`Register script`, () => { }); const originalTsNodeInstance = global.process[instanceSymbol]; - registerResult = register()!; + registerResult = nodeRegister()!; instanceRegistrationResult = global.process[instanceSymbol]!; global.process[instanceSymbol] = originalTsNodeInstance; diff --git a/test/tests/extras.test.ts b/test/tests/extras.test.ts deleted file mode 100755 index 18a5d1bf..00000000 --- a/test/tests/extras.test.ts +++ /dev/null @@ -1,41 +0,0 @@ -import { createTsProgram, getEmitResultFromProgram } from "../utils"; -import { projectsPaths } from "../config"; -import path from "path"; -import ts from "typescript"; -import * as config from "../config"; -import { execSync } from "child_process"; - -/* ****************************************************************************************************************** * - * Tests - * ****************************************************************************************************************** */ - -describe(`Extra Tests`, () => { - const projectRoot = ts.normalizePath(path.join(projectsPaths, "extras")); - const indexFile = ts.normalizePath(path.join(projectRoot, "src/index.ts")); - const tsConfigFile = ts.normalizePath(path.join(projectRoot, "tsconfig.json")); - - describe(`Built Tests`, () => { - // see: https://github.com/LeDDGroup/typescript-transform-paths/issues/130 - test(`Transformer works without ts-node being present`, () => { - jest.doMock( - "ts-node", - () => { - require("sdf0s39rf3333d@fake-module"); - }, - { virtual: true } - ); - try { - const program = createTsProgram({ tsInstance: ts, tsConfigFile }, config.builtTransformerPath); - const res = getEmitResultFromProgram(program); - expect(res[indexFile].js).toMatch(`var _identifier_1 = require("./id")`); - } finally { - jest.dontMock("ts-node"); - } - }); - - test(`Register script transforms with ts-node`, () => { - const res = execSync("ts-node src/index.ts", { cwd: projectRoot }).toString(); - expect(res).toMatch(/^null($|\r?\n)/); - }); - }); -}); diff --git a/test/tests/project-ref.test.ts b/test/tests/project-ref.test.ts deleted file mode 100755 index 68468e93..00000000 --- a/test/tests/project-ref.test.ts +++ /dev/null @@ -1,37 +0,0 @@ -// noinspection ES6UnusedImports -import {} from "ts-expose-internals"; -import * as path from "path"; -import { createTsSolutionBuilder, EmittedFiles } from "../utils"; -import { projectsPaths, ts } from "../config"; - -/* ****************************************************************************************************************** * - * Config - * ****************************************************************************************************************** */ - -/* File Paths */ -const projectDir = ts.normalizePath(path.join(projectsPaths, "project-ref")); -const indexFile = ts.normalizePath(path.join(projectDir, "lib/b/index.ts")); - -/* ****************************************************************************************************************** * - * Tests - * ****************************************************************************************************************** */ - -// see: https://github.com/LeDDGroup/typescript-transform-paths/issues/125 -describe(`Project References`, () => { - let emittedFiles: EmittedFiles; - - beforeAll(() => { - const builder = createTsSolutionBuilder({ tsInstance: ts, projectDir }); - emittedFiles = builder.getEmitFiles(); - }); - - test(`Specifier for referenced project file resolves properly`, () => { - expect(emittedFiles[indexFile].js).toMatch(`export { AReffedConst } from "../a/index"`); - expect(emittedFiles[indexFile].dts).toMatch(`export { AReffedConst } from "../a/index"`); - }); - - test(`Specifier for local file resolves properly`, () => { - expect(emittedFiles[indexFile].js).toMatch(`export { LocalConst } from "./local/index"`); - expect(emittedFiles[indexFile].dts).toMatch(`export { LocalConst } from "./local/index"`); - }); -}); diff --git a/test/tests/projects/extras.test.ts b/test/tests/projects/extras.test.ts new file mode 100755 index 00000000..9758d3c6 --- /dev/null +++ b/test/tests/projects/extras.test.ts @@ -0,0 +1,64 @@ +import { projectsPath, rootPath } from "../../src/config"; +import path from "path"; +import type TS from 'typescript'; +import { normalizePath } from 'typescript' +import { execSync } from "child_process"; +import { createTsProgram, getEmitResultFromProgram } from "../../src"; + + +/* ****************************************************************************************************************** * + * Config + * ****************************************************************************************************************** */ + +const tsNodePath = path.resolve(rootPath, 'node_modules/.bin/ts-node'); + +/* ****************************************************************************************************************** * + * Tests + * ****************************************************************************************************************** */ + +describe(`[Project: 'extras'] Extra Tests`, () => { + const projectRoot = normalizePath(path.join(projectsPath, "extras")); + const indexFile = normalizePath(path.join(projectRoot, "src/index.ts")); + const tsConfigFile = normalizePath(path.join(projectRoot, "tsconfig.json")); + + describe.each(envOptions.tsModules)(`[TS %s]`, (_, tsSpecifier) => { + const ts: typeof TS = require(tsSpecifier); + + // see: https://github.com/LeDDGroup/typescript-transform-paths/issues/130 + test(`Transformer works without ts-node being present`, () => { + jest.doMock( + "ts-node", + () => { + require("sdf0s39rf3333d@fake-module"); + }, + { virtual: true } + ); + try { + const program = createTsProgram({ tsInstance: ts, tsConfigFile }); + const res = getEmitResultFromProgram(ts, program); + expect(res[indexFile].js).toMatch(`const _identifier_1 = require("./id")`); + } finally { + jest.dontMock("ts-node"); + } + }); + }); + + (envOptions.testTarget === 'dist' ? test : test.skip)(`Register script transforms with ts-node`, () => { + const res = execSync(`${tsNodePath} src/index.ts`, { cwd: projectRoot }).toString(); + expect(res).toMatch(/^null($|\r?\n)/); + }); + + test(`Transformer throws with lower version`, () => { + const ts = require('typescript-latest'); + const originalMajorMinor = ts.versionMajorMinor; + (ts).versionMajorMinor = '4.1.0'; + try { + expect(() => { + const program = createTsProgram({ tsInstance: ts, tsConfigFile }); + getEmitResultFromProgram(ts, program); + }).toThrow(`The latest version of 'typescript-transform-paths' requires TS version `); + } finally { + (ts).versionMajorMinor = originalMajorMinor; + } + }); +}); diff --git a/test/tests/projects/general.test.ts b/test/tests/projects/general.test.ts new file mode 100755 index 00000000..39bb350b --- /dev/null +++ b/test/tests/projects/general.test.ts @@ -0,0 +1,92 @@ +/** + * The following test suite does not use the Underscore Test framework. In a some respects, it is less comprehensive, + * however it also affords a secondary approach as well as testing ts-node and manual transformation. For these reasons, + * its current setup provides additional coverage and should therefore be left outside of the UT framework. + */ +import * as path from 'path'; +import { + createTsProgram, + EmittedFiles, + getEmitResultFromProgram, + getManualEmitResult, + getTsNodeEmitResult, +} from '../../src'; +import { projectsPath } from '../../src/config'; +import type TS from 'typescript'; + +/* ****************************************************************************************************************** * + * Helpers + * ****************************************************************************************************************** */ + +const makeRelative = (tsInstance: typeof TS, fileName: string, p: string, rootDir: string) => { + let rel = tsInstance.normalizePath(path.relative(path.dirname(fileName), path.join(rootDir, p))); + if (rel[0] !== '.') rel = `./${rel}`; + return `"${rel}"`; +}; + +const getExpected = (tsInstance: typeof TS, fileName: string, original: string, rootDir: string): string => + original + .replace(/"@(.*)"/g, (_, p) => makeRelative(tsInstance, fileName, p, rootDir)) + .replace(/"#utils\/(.*)"/g, (_, p) => + makeRelative(tsInstance, fileName, path.join(p === 'hello' ? 'secondary' : 'utils', p), rootDir) + ) + .replace('"path"', '"https://external.url/path.js"') + .replace('"circular/a"', '"../circular/a"'); + +/* ****************************************************************************************************************** * + * Tests + * ****************************************************************************************************************** */ + +describe(`[Project: 'general'] - General Tests`, () => { + const projectRoot = path.join(projectsPath, 'general'); + const tsConfigFile = path.join(projectRoot, 'tsconfig.json'); + + describe.each(envOptions.tsModules)(`[TS: %s]`, (s, tsSpecifier) => { + const ts: typeof TS = require(tsSpecifier); + const pcl = ts.getParsedCommandLineOfConfigFile(tsConfigFile, {}, ts.sys)! as TS.ParsedCommandLine; + const fileNames = pcl.fileNames; + + describe.each(envOptions.buildModes)(`Mode: %s`, (mode) => { + let skipDts: boolean = false; + let originalFiles: EmittedFiles = {}; + let transformedFiles: EmittedFiles = {}; + + switch (mode) { + case 'program': + const program = createTsProgram({ tsInstance: ts, tsConfigFile, disablePlugin: true }); + const programWithTransformer = createTsProgram({ tsInstance: ts, tsConfigFile }); + + originalFiles = getEmitResultFromProgram(ts, program); + transformedFiles = getEmitResultFromProgram(ts, programWithTransformer); + break; + case 'manual': { + skipDts = true; + originalFiles = getManualEmitResult({}, ts, pcl, true); + transformedFiles = getManualEmitResult({}, ts, pcl); + break; + } + case 'ts-node': { + skipDts = true; + originalFiles = getTsNodeEmitResult({}, pcl, tsSpecifier, true); + transformedFiles = getTsNodeEmitResult({}, pcl, tsSpecifier); + } + } + + describe.each(fileNames!.map((p) => [p.slice(projectRoot.length), p]))(`%s`, (_, file) => { + let expected: EmittedFiles[string]; + let transformed: EmittedFiles[string]; + + beforeAll(() => { + transformed = transformedFiles[file]; + expected = { + js: getExpected(ts, file, originalFiles[file].js, projectRoot), + ...(!skipDts && { dts: getExpected(ts, file, originalFiles[file].dts!, projectRoot) }) + }; + }); + + test(`js matches`, () => expect(transformed.js).toEqual(expected.js)); + if (!skipDts) test(`dts matches`, () => expect(transformed.dts).toEqual(expected.dts)); + }); + }); + }); +}); diff --git a/test/tests/projects/project-ref.test.ts b/test/tests/projects/project-ref.test.ts new file mode 100755 index 00000000..970f213d --- /dev/null +++ b/test/tests/projects/project-ref.test.ts @@ -0,0 +1,26 @@ +import { joinPaths } from 'tstp/src/utils'; +import { ut } from "../../src"; +import { projectsPath } from "../../src/config"; + +/* ****************************************************************************************************************** * + * Config + * ****************************************************************************************************************** */ + +const testRuns = ut.loadProject({ + projectName: 'project-ref', + programKind: 'solutionBuilder', + builderTransformerPredicate: (program) => + program.getCompilerOptions().configFilePath === joinPaths(projectsPath, 'project-ref/b/tsconfig.json') +}); + +/* ****************************************************************************************************************** * + * Tests + * ****************************************************************************************************************** */ + +describe(`[Project: 'project-ref'] - Project References`, () => { + describe.each(testRuns)(`$runLabel`, ({ tests }) => { + test.each(tests)(`%s`, (_, detail) => { + detail.expects.forEach(exp => expect(exp).toResolve()); + }) + }) +}); diff --git a/test/tests/projects/resolution.test.ts b/test/tests/projects/resolution.test.ts new file mode 100755 index 00000000..ee26b2fc --- /dev/null +++ b/test/tests/projects/resolution.test.ts @@ -0,0 +1,32 @@ +import { ut } from '../../src'; + +/* ****************************************************************************************************************** * + * Config + * ****************************************************************************************************************** */ + +const testRuns = ut.loadProject({ + projectName: 'resolution', + useGroups: true, + // configs: ut.createConfigSpread({ + // outputIndexes: [ 'auto', 'never', 'always' ], + // outputExtensions: [ 'auto', 'never', 'always' ] + // }) + configs: ut.createConfigSpread({ + outputIndexes: 'always', + outputExtensions: [ 'auto', 'never', 'always' ] + }) +}); + +/* ****************************************************************************************************************** * + * Tests + * ****************************************************************************************************************** */ + +describe(`[Project: 'resolution'] - Resolution-related`, () => { + describe.each(testRuns)(`$runLabel`, ({ groups }) => { + describe.each(groups)(`$groupLabel`, ({ tests }) => { + test.each(tests)(`%s`, (_, { expects }) => { + expects.forEach((exp) => expect(exp).toResolve()); + }); + }); + }); +}); diff --git a/test/tests/projects/root-dirs.test.ts b/test/tests/projects/root-dirs.test.ts new file mode 100755 index 00000000..a1b07830 --- /dev/null +++ b/test/tests/projects/root-dirs.test.ts @@ -0,0 +1,23 @@ +import { ut } from "../../src"; + +/* ****************************************************************************************************************** * + * Config + * ****************************************************************************************************************** */ + +const testRuns = ut.loadProject({ + projectName: 'root-dirs', + configs: [ true, false, undefined ].map(v => ({ useRootDirs: v })) +}); + + +/* ****************************************************************************************************************** * + * Tests + * ****************************************************************************************************************** */ + +describe(`[Project: 'root-dirs'] - TS RootDirs`, () => { + describe.each(testRuns)(`$runLabel`, ({ tests }) => { + test.each(tests)(`%s`, (_, { expects }) => { + expects.forEach((exp) => expect(exp).toResolve()); + }); + }) +}); diff --git a/test/tests/projects/specific.test.ts b/test/tests/projects/specific.test.ts new file mode 100755 index 00000000..148f3170 --- /dev/null +++ b/test/tests/projects/specific.test.ts @@ -0,0 +1,25 @@ +import { ut } from '../../src'; + +/* ****************************************************************************************************************** * + * Config + * ****************************************************************************************************************** */ + +const testRuns = ut.loadProject({ + projectName: 'specific', + pluginOptions: { exclude: ['**/excluded/**', 'excluded-file.*'] }, + useGroups: true +}); + +/* ****************************************************************************************************************** * + * Tests + * ****************************************************************************************************************** */ + +describe(`[Project: 'specific'] - Specific Test Cases`, () => { + describe.each(testRuns)(`$runLabel`, ({ groups }) => { + describe.each(groups)(`$groupLabel`, ({ tests }) => { + test.each(tests)(`%s`, (_, { expects }) => { + expects.forEach((exp) => expect(exp).toResolve()); + }); + }) + }); +}); diff --git a/test/tests/transformer/general.test.ts b/test/tests/transformer/general.test.ts deleted file mode 100755 index 98c63b9b..00000000 --- a/test/tests/transformer/general.test.ts +++ /dev/null @@ -1,63 +0,0 @@ -// noinspection ES6UnusedImports -import {} from "ts-expose-internals"; -import * as path from "path"; -import { createTsProgram, EmittedFiles, getEmitResultFromProgram } from "../../utils"; -import { ts, tsModules, projectsPaths } from "../../config"; - -/* ****************************************************************************************************************** * - * Helpers - * ****************************************************************************************************************** */ - -const makeRelative = (tsInstance: typeof ts, fileName: string, p: string, rootDir: string) => { - let rel = tsInstance.normalizePath(path.relative(path.dirname(fileName), path.join(rootDir, p))); - if (rel[0] !== ".") rel = `./${rel}`; - return `"${rel}"`; -}; - -const getExpected = (tsInstance: typeof ts, fileName: string, original: string, rootDir: string): string => - original - .replace(/"@(.*)"/g, (_, p) => makeRelative(tsInstance, fileName, p, rootDir)) - .replace(/"#utils\/(.*)"/g, (_, p) => - makeRelative(tsInstance, fileName, path.join(p === "hello" ? "secondary" : "utils", p), rootDir) - ) - .replace('"path"', '"https://external.url/path.js"') - .replace('"circular/a"', '"../circular/a"'); - -/* ****************************************************************************************************************** * - * Tests - * ****************************************************************************************************************** */ - -describe(`Transformer -> General Tests`, () => { - const projectRoot = path.join(projectsPaths, "general"); - const tsConfigFile = path.join(projectRoot, "tsconfig.json"); - - describe.each(tsModules)(`TypeScript %s`, (s, tsInstance) => { - let originalFiles: EmittedFiles = {}; - let transformedFiles: EmittedFiles = {}; - - const program = createTsProgram({ tsInstance: tsInstance as typeof ts, tsConfigFile, disablePlugin: true }); - const programWithTransformer = createTsProgram({ tsInstance: tsInstance as typeof ts, tsConfigFile }); - const fileNames = program.getRootFileNames() as string[]; - - beforeAll(() => { - originalFiles = getEmitResultFromProgram(program); - transformedFiles = getEmitResultFromProgram(programWithTransformer); - }); - - describe.each(fileNames!.map((p) => [p.slice(projectRoot.length), p]))(`%s`, (_, file) => { - let expected: EmittedFiles[string]; - let transformed: EmittedFiles[string]; - - beforeAll(() => { - transformed = transformedFiles[file]; - expected = { - js: getExpected(tsInstance, file, originalFiles[file].js, projectRoot), - dts: getExpected(tsInstance, file, originalFiles[file].dts, projectRoot), - }; - }); - - test(`js matches`, () => expect(transformed.js).toEqual(expected.js)); - test(`dts matches`, () => expect(transformed.dts).toEqual(expected.dts)); - }); - }); -}); diff --git a/test/tests/transformer/specific.test.ts b/test/tests/transformer/specific.test.ts deleted file mode 100755 index e6521368..00000000 --- a/test/tests/transformer/specific.test.ts +++ /dev/null @@ -1,342 +0,0 @@ -/** - * Note: To make debug testing easier, you can use the following environment variables to control what tests run: - * - * TS_MODULES - comma separated string of name fields in `tsModules` (config.ts) - * MODES - comma separated string of `modes` (see config heading below) - * OUTPUT_MODES - comma separated string of `outputModes` (see config heading below) - * - * Example — only test latest TS, using program and ts-node, with outputMode 'esm': - * TS_MODULES=latest; - * MODES=program,ts-node; - * OUTPUT_MODES=esm; - */ -// noinspection ES6UnusedImports -import {} from "ts-expose-internals"; -import * as path from "path"; -import { - createTsProgram, - EmittedFiles, - getEmitResultFromProgram, - getManualEmitResult, - getTsNodeEmitResult, -} from "../../utils"; -import { projectsPaths, ts, tsModules } from "../../config"; -import { TsTransformPathsConfig } from "../../../src"; -import TS from "typescript"; - -/* ****************************************************************************************************************** * - * Config - * ****************************************************************************************************************** */ - -const baseConfig: TsTransformPathsConfig = { exclude: ["**/excluded/**", "excluded-file.*"] }; - -const modes = ["program", "manual", "ts-node"] as const; -const outputModes = ["[default]", "commonjs", "esm"] as const; - -/* File Paths */ -const projectRoot = ts.normalizePath(path.join(projectsPaths, "specific")); -const tsConfigFile = ts.normalizePath(path.join(projectsPaths, "specific/tsconfig.json")); -const genFile = ts.normalizePath(path.join(projectRoot, "generated/dir/gen-file.ts")); -const srcFile = ts.normalizePath(path.join(projectRoot, "src/dir/src-file.ts")); -const indexFile = ts.normalizePath(path.join(projectRoot, "src/index.ts")); -const tagFile = ts.normalizePath(path.join(projectRoot, "src/tags.ts")); -const typeElisionIndex = ts.normalizePath(path.join(projectRoot, "src/type-elision/index.ts")); -const subPackagesFile = ts.normalizePath(path.join(projectRoot, "src/sub-packages.ts")); -const moduleAugmentFile = ts.normalizePath(path.join(projectRoot, "src/module-augment.ts")); - -/* ****************************************************************************************************************** * - * Setup - * ****************************************************************************************************************** */ - -const testConfigs = (function prepareConfigs() { - let { TS_MODULES, MODES, OUTPUT_MODES } = process.env; - const opt = { - modules: TS_MODULES?.split(",").map((m) => m.trim().toLowerCase()), - modes: MODES?.split(",").map((m) => m.trim().toLowerCase()), - outputModes: OUTPUT_MODES?.split(",").map((m) => m.trim().toLowerCase()), - }; - - const cfgTsModules = !opt.modules ? tsModules : tsModules.filter((m) => opt.modules!.includes(m[0].toLowerCase())); - const cfgModes = !opt.modes ? modes : modes.filter((m) => opt.modes!.includes(m.toLowerCase())); - const cfgOutputModes = !opt.outputModes - ? outputModes - : outputModes.filter((m) => opt.outputModes!.includes(m.toLowerCase())); - - const res: { - label: string; - tsInstance: any; - mode: typeof modes[number]; - tsSpecifier: string; - config: TsTransformPathsConfig; - outputMode: typeof outputModes[number]; - }[] = []; - - cfgTsModules.forEach((cfg) => - cfgOutputModes.forEach((outputMode) => - res.push( - ...cfgModes.map((mode) => ({ - label: cfg[0], - tsInstance: cfg[1], - mode, - tsSpecifier: cfg[2], - config: { - ...baseConfig, - outputMode: outputMode === "[default]" ? void 0 : outputMode, - }, - outputMode, - })) - ) - ) - ); - - return res; -})(); - -/* ****************************************************************************************************************** * - * Types - * ****************************************************************************************************************** */ - -interface TransformedMatchesOpt { - base?: EmittedFiles[]; - kind?: ("dts" | "js")[]; - noEsmFix?: boolean; -} - -declare global { - namespace jest { - interface Matchers { - transformedMatches(expected: RegExp | string, opt?: TransformedMatchesOpt): void; - } - } -} - -/* ****************************************************************************************************************** * - * Tests - * ****************************************************************************************************************** */ - -describe(`Specific Tests`, () => { - describe.each(testConfigs)( - `TypeScript $label - Mode: $mode - OutputMode: $outputMode`, - ({ tsInstance, mode, tsSpecifier, config, outputMode }) => { - const tsVersion = +tsInstance.versionMajorMinor.split(".").slice(0, 2).join(""); - let normalEmit: EmittedFiles; - let rootDirsEmit: EmittedFiles; - let skipDts = false; - - beforeAll(() => { - switch (mode) { - case "program": - const program = createTsProgram({ - tsInstance, - tsConfigFile, - pluginOptions: { - ...config, - useRootDirs: false, - }, - }); - normalEmit = getEmitResultFromProgram(program); - - const rootDirsProgram = createTsProgram({ - tsInstance, - tsConfigFile, - pluginOptions: { - ...config, - useRootDirs: true, - }, - }); - rootDirsEmit = getEmitResultFromProgram(rootDirsProgram); - break; - case "manual": { - skipDts = true; - const pcl = tsInstance.getParsedCommandLineOfConfigFile( - tsConfigFile, - {}, - tsInstance.sys - )! as TS.ParsedCommandLine; - normalEmit = getManualEmitResult({ ...config, useRootDirs: false }, tsInstance, pcl); - rootDirsEmit = getManualEmitResult({ ...config, useRootDirs: true }, tsInstance, pcl); - break; - } - case "ts-node": { - const pcl = tsInstance.getParsedCommandLineOfConfigFile( - tsConfigFile, - {}, - tsInstance.sys - )! as TS.ParsedCommandLine; - skipDts = true; - normalEmit = getTsNodeEmitResult({ ...config, useRootDirs: false }, pcl, tsSpecifier); - rootDirsEmit = getTsNodeEmitResult({ ...config, useRootDirs: true }, pcl, tsSpecifier); - } - } - - expect.extend({ - transformedMatches(fileName: string, expected: RegExp | string, opt?: TransformedMatchesOpt) { - const bases = opt?.base ?? [normalEmit, rootDirsEmit]; - const kinds = (opt?.kind ?? ["dts", "js"]).filter((k) => !skipDts || k !== "dts"); - - let failed: boolean = false; - const messages: string[] = []; - for (const base of bases) { - for (const kind of kinds) { - const content = base[fileName][kind]; - const exp = getExpected(kind); - const isValid = typeof exp === "string" ? content.indexOf(exp) >= 0 : exp.test(content); - if (!isValid) { - failed = true; - messages.push( - `File: ${fileName}\nKind: ${kind}\nrootDirs: ${base === normalEmit}\n\n` + - `Expected: \`${exp}\`\nReceived:\n\t${content.replace(/(\r?\n)+/g, "$1\t")}` - ); - } - } - } - - return { message: () => messages.join("\n\n"), pass: !failed }; - - function getExpected(kind: "dts" | "js") { - if (!(expected instanceof RegExp) && !opt?.noEsmFix && kind === "js" && outputMode === "esm") { - const regEx = /"\.(.+?)"/g; - let res: string = ""; - - let match: RegExpExecArray | null; - let lastIndex = 0; - while ((match = regEx.exec(expected)) !== null) { - let p = match[1]; - if (!path.extname(p)) p += ".js"; - res += expected.slice(lastIndex, match.index) + `".${p}"`; - lastIndex = res.length; - } - - return res; - } - - return expected; - } - }, - }); - }); - - describe(`Options`, () => { - test(`(useRootDirs: true) Re-maps for rootDirs`, () => { - expect(genFile).transformedMatches(`import "./src-file"`, { base: [rootDirsEmit] }); - expect(srcFile).transformedMatches(`import "./gen-file"`, { base: [rootDirsEmit] }); - expect(indexFile).transformedMatches(`export { b } from "./dir/gen-file"`, { base: [rootDirsEmit] }); - expect(indexFile).transformedMatches(`export { a } from "./dir/src-file"`, { base: [rootDirsEmit] }); - }); - - test(`(useRootDirs: false) Ignores rootDirs`, () => { - expect(genFile).transformedMatches(`import "../../src/dir/src-file"`, { base: [normalEmit] }); - expect(srcFile).transformedMatches(`import "../../generated/dir/gen-file"`, { base: [normalEmit] }); - expect(indexFile).transformedMatches(`export { b } from "../generated/dir/gen-file"`, { base: [normalEmit] }); - expect(indexFile).transformedMatches(`export { a } from "./dir/src-file"`, { base: [normalEmit] }); - }); - - test(`(exclude) Doesn't transform for exclusion patterns`, () => { - expect(indexFile).transformedMatches( - /export { bb } from "#exclusion\/ex";\s*export { dd } from "#root\/excluded-file"/ - ); - }); - }); - - describe(`Tags`, () => { - test(`(@no-transform-path) Doesn't transform path`, () => { - for (let i = 1; i <= 4; i++) - expect(tagFile).transformedMatches(`import * as skipTransform${i} from "#root\/index`); - }); - - test(`(@transform-path) Transforms path with explicit value`, () => { - expect(tagFile).transformedMatches(`import * as explicitTransform1 from "./dir/src-file"`, { - noEsmFix: true, - }); - expect(tagFile).transformedMatches(`import * as explicitTransform2 from "http://www.go.com/react.js"`); - expect(tagFile).transformedMatches(`import * as explicitTransform3 from "./dir/src-file"`, { - noEsmFix: true, - }); - expect(tagFile).transformedMatches(`import * as explicitTransform4 from "http://www.go.com/react.js"`); - }); - }); - - (mode === "program" ? test : test.skip)(`Type elision works properly`, () => { - expect(typeElisionIndex).transformedMatches( - outputMode === "esm" - ? /import { ConstB } from "\.\/a\.js";\s*export { ConstB };/ - : /import { ConstB } from "\.\/a";\s*export { ConstB };/, - { kind: ["js"] } - ); - expect(typeElisionIndex).transformedMatches( - /import { ConstB, TypeA } from "\.\/a";\s*import { TypeA as TypeA2 } from "\.\/a";\s*export { ConstB, TypeA };\s*export { TypeA2 };/, - { kind: ["dts"] } - ); - }); - - (!skipDts && tsVersion >= 38 ? test : test.skip)(`Import type-only transforms`, () => { - expect(indexFile).transformedMatches(`import type { A as ATypeOnly } from "./dir/src-file"`, { kind: ["dts"] }); - }); - - test(`Copies comments in async import`, () => { - expect(indexFile).transformedMatches(`import(/* webpackChunkName: "Comment" */ "./dir/src-file");`, { - kind: ["js"], - }); - expect(indexFile).transformedMatches( - /\/\/ comment 1\r?\n\s*\r?\n\/\*\r?\n\s*comment 2\r?\n\s*\*\/\r?\n\s*"\.\/dir\/src-file(\.js)?"/, - { kind: ["js"] } - ); - }); - - test(`Preserves explicit extensions`, () => { - expect(indexFile).transformedMatches(`export { JsonValue } from "./data.json"`); - expect(indexFile).transformedMatches(`export { GeneralConstA } from "./general"`); - expect(indexFile).transformedMatches(`export { GeneralConstB } from "./general.js"`); - }); - - test(`Properly handles implicit index filenames`, () => { - const implicitMatch = `export { ConstB } from "./type-elision"`; - const explicitMatch = `export { ConstB } from "./type-elision/index.js"`; - - expect(indexFile).transformedMatches(outputMode === "esm" ? explicitMatch : implicitMatch, { kind: ["js"] }); - expect(indexFile).transformedMatches(implicitMatch, { kind: ["dts"] }); - }); - - test(`Resolves sub-modules properly`, () => { - const a = { - js: `export { packageAConst } from "./packages/pkg-a"`, - full: `export { packageAConst, PackageAType } from "./packages/pkg-a"`, - }; - const b = { - js: `export { packageBConst } from "./packages/pkg-b"`, - full: `export { packageBConst, PackageBType } from "./packages/pkg-b"`, - }; - const c = { - js: `export { packageCConst } from "./packages/pkg-c"`, - full: `export { packageCConst, PackageCType } from "./packages/pkg-c"`, - }; - const sub = { - js: `export { subPackageConst } from "./packages/pkg-a/sub-pkg"`, - full: `export { SubPackageType, subPackageConst } from "./packages/pkg-a/sub-pkg"`, - }; - - for (const exp of [a, b, c, sub]) { - expect(subPackagesFile).transformedMatches(mode !== "program" ? exp.full : exp.js, { - kind: ["js"], - noEsmFix: true, - }); - if (!skipDts) expect(subPackagesFile).transformedMatches(exp.full, { kind: ["dts"] }); - } - - expect(subPackagesFile).transformedMatches(`export { packageCConst as C2 } from "./packages/pkg-c/main"`); - expect(subPackagesFile).transformedMatches(`export { packageCConst as C3 } from "./packages/pkg-c/main.js"`); - expect(subPackagesFile).transformedMatches( - `export { subPackageConst as C4 } from "./packages/pkg-a/sub-pkg/main"` - ); - expect(subPackagesFile).transformedMatches( - `export { subPackageConst as C5 } from "./packages/pkg-a/sub-pkg/main.js"` - ); - }); - - (!skipDts ? test : test.skip)(`Resolves module augmentation`, () => { - expect(moduleAugmentFile).transformedMatches(`declare module "./general" {`, { kind: ["dts"] }); - expect(moduleAugmentFile).transformedMatches(`declare module "./excluded-file" {`, { kind: ["dts"] }); - }); - } - ); -}); diff --git a/test/transformer-wrapper/index.d.ts b/test/transformer-wrapper/index.d.ts new file mode 100755 index 00000000..49449093 --- /dev/null +++ b/test/transformer-wrapper/index.d.ts @@ -0,0 +1,4 @@ +export * from 'tstp/src' + +import { default as transformer } from 'tstp/src'; +export default transformer; diff --git a/test/transformer-wrapper/index.js b/test/transformer-wrapper/index.js new file mode 100755 index 00000000..c4b42948 --- /dev/null +++ b/test/transformer-wrapper/index.js @@ -0,0 +1,3 @@ +const target = process.env.TEST_TARGET === 'dist' ? 'dist' : 'src'; + +module.exports = require(`tstp/${target}`); diff --git a/test/transformer-wrapper/package.json b/test/transformer-wrapper/package.json new file mode 100755 index 00000000..53223b29 --- /dev/null +++ b/test/transformer-wrapper/package.json @@ -0,0 +1,7 @@ +{ + "name": "@test/transformer-wrapper", + "private": true, + "version": "0.0.0", + "main": "index.js", + "types": "index.d.ts" +} diff --git a/test/tsconfig.json b/test/tsconfig.json index 3453ff74..a5b2b963 100755 --- a/test/tsconfig.json +++ b/test/tsconfig.json @@ -1,10 +1,13 @@ { "extends": "../tsconfig.base", - "include": [ "tests", "utils" ], + "include": [ "tests", "src" ], + "exclude": [ "src/ut-global" ], "compilerOptions": { "noEmit": true, "strict": true, - "esModuleInterop": true + "esModuleInterop": true, + "skipLibCheck": true, + "skipDefaultLibCheck": true } } diff --git a/test/utils/helpers.ts b/test/utils/helpers.ts deleted file mode 100755 index 8153da0f..00000000 --- a/test/utils/helpers.ts +++ /dev/null @@ -1,203 +0,0 @@ -import { default as tstpTransform, TsTransformPathsConfig } from "../../src"; -import fs from "fs"; -import ts from "typescript"; -import * as tsNode from "ts-node"; -import * as config from "../config"; - -/* ****************************************************************************************************************** */ -// region: Types -/* ****************************************************************************************************************** */ - -export type EmittedFiles = { [fileName: string]: { js: string; dts: string } }; - -export interface CreateTsProgramOptions { - tsInstance: typeof ts; - files?: { [fileName: string]: /* data */ string }; - tsConfigFile?: string; - disablePlugin?: boolean; - additionalOptions?: ts.CompilerOptions; - pluginOptions?: TsTransformPathsConfig; -} - -export interface CreateTsSolutionBuilderOptions { - tsInstance: typeof ts; - projectDir: string; -} - -// endregion - -/* ****************************************************************************************************************** */ -// region: Helpers -/* ****************************************************************************************************************** */ - -function createWriteFile(outputFiles: EmittedFiles) { - return (fileName: string, data: string) => { - let { 1: rootName, 2: ext } = fileName.match(/(.+)\.((d.ts)|(js))$/) ?? []; - if (!ext) return; - rootName = `${rootName}.ts`; - const key = ext.replace(".", "") as keyof EmittedFiles[string]; - if (!outputFiles[rootName]) outputFiles[rootName] = {}; - outputFiles[rootName][key] = data; - }; -} - -function createReadFile(outputFiles: EmittedFiles, originalReadFile: Function) { - return (fileName: string) => { - let { 1: rootName, 2: ext } = fileName.match(/(.+)\.((d.ts)|(js))$/) ?? []; - if (ext) { - rootName = `${rootName}.ts`; - const key = ext.replace(".", "") as keyof EmittedFiles[string]; - const res = outputFiles[rootName]?.[key]; - if (res) return res; - } - return originalReadFile(fileName); - }; -} - -// endregion - -/* ****************************************************************************************************************** */ -// region: Utilities -/* ****************************************************************************************************************** */ - -/** - * Create TS Program with faux files and options - */ -export function createTsProgram( - opt: CreateTsProgramOptions, - transformerPath: string = config.transformerPath -): ts.Program { - const { disablePlugin, additionalOptions, pluginOptions } = opt; - const tsInstance: typeof ts = opt.tsInstance; - - if ((!opt.files && !opt.tsConfigFile) || (opt.files && opt.tsConfigFile)) - throw new Error(`Must supply *either* files or tsConfigFile to createProgram`); - - const extendOptions = Object.assign({}, additionalOptions, { - outDir: undefined, - noEmit: false, - plugins: disablePlugin - ? [] - : [ - { transform: transformerPath, ...pluginOptions }, - { - transform: transformerPath, - afterDeclarations: true, - ...pluginOptions, - }, - ], - }); - - let compilerOptions: ts.CompilerOptions = {}; - let fileNames: string[]; - let host: ts.CompilerHost | undefined; - - if (opt.tsConfigFile) { - const pcl = tsInstance.getParsedCommandLineOfConfigFile(opt.tsConfigFile, extendOptions, tsInstance.sys)!; - compilerOptions = pcl.options; - fileNames = pcl.fileNames; - } else { - const files = Object.entries(compilerOptions.files!).reduce((p, [fileName, data]) => { - p[tsInstance.normalizePath(fileName)] = data; - return p; - }, {}); - fileNames = Object.keys(files); - - host = tsInstance.createCompilerHost(compilerOptions); - compilerOptions = extendOptions; - - /* Patch host to feed mock files */ - const originalGetSourceFile: any = host.getSourceFile; - host.getSourceFile = function (fileName: string, scriptTarget: ts.ScriptTarget) { - if (Object.keys(files).includes(fileName)) - return tsInstance.createSourceFile(fileName, files[fileName], scriptTarget); - else originalGetSourceFile.apply(undefined, arguments); - }; - } - - return tsInstance.createProgram({ options: compilerOptions, rootNames: fileNames, host }); -} - -export function createTsSolutionBuilder( - opt: CreateTsSolutionBuilderOptions -): ts.SolutionBuilder & { getEmitFiles(): EmittedFiles } { - const { tsInstance, projectDir } = opt; - - const outputFiles: EmittedFiles = {}; - - const host = tsInstance.createSolutionBuilderHost(); - const originalReadFile = host.readFile; - Object.assign(host, { - readFile: createReadFile(outputFiles, originalReadFile), - writeFile: createWriteFile(outputFiles), - }); - - const builder = tsInstance.createSolutionBuilder(host, [projectDir], { force: true }); - - return Object.assign(builder, { - getEmitFiles() { - builder.build(); - return outputFiles; - }, - }); -} - -/** - * Get emitted files for program - */ -export function getEmitResultFromProgram(program: ts.Program): EmittedFiles { - const outputFiles: EmittedFiles = {}; - program.emit(undefined, createWriteFile(outputFiles)); - return outputFiles; -} - -export function getManualEmitResult(pluginConfig: TsTransformPathsConfig, tsInstance: any, pcl: ts.ParsedCommandLine) { - const { options: compilerOptions, fileNames } = pcl; - const transformer = tstpTransform(void 0, pluginConfig, { ts: tsInstance } as any, { compilerOptions, fileNames }); - - const { transformed } = tsInstance.transform( - fileNames.map((f) => - tsInstance.createSourceFile(f, fs.readFileSync(f, "utf8"), tsInstance.ScriptTarget.ESNext, true) - ), - [transformer], - compilerOptions - ); - - const printer = tsInstance.createPrinter(); - - const res: EmittedFiles = {}; - for (const sourceFile of transformed) res[sourceFile.fileName] = { js: printer.printFile(sourceFile) }; - - return res; -} - -export function getTsNodeEmitResult( - pluginConfig: TsTransformPathsConfig, - pcl: ts.ParsedCommandLine, - tsSpecifier: string -) { - const compiler = tsNode.create({ - transpileOnly: true, - transformers: { - before: [tstpTransform(void 0, pluginConfig, { ts: require(tsSpecifier) })], - }, - project: pcl.options.configFilePath, - compiler: tsSpecifier, - logError: true, - ignoreDiagnostics: [1144, 1005], // Issues with old TS and type only imports - }); - - const originalRegister = global.process[tsNode.REGISTER_INSTANCE]; - global.process[tsNode.REGISTER_INSTANCE] = compiler; - try { - const res: EmittedFiles = {}; - for (const fileName of pcl.fileNames.filter((f) => !/\.d\.ts$/.test(f))) - res[fileName] = { js: compiler.compile(fs.readFileSync(fileName, "utf8"), fileName) }; - - return res; - } finally { - global.process[tsNode.REGISTER_INSTANCE] = originalRegister; - } -} - -// endregion diff --git a/test/utils/index.ts b/test/utils/index.ts deleted file mode 100755 index d4e09d7b..00000000 --- a/test/utils/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from "./helpers"; diff --git a/test/yarn.lock b/test/yarn.lock new file mode 100755 index 00000000..4d43ae11 --- /dev/null +++ b/test/yarn.lock @@ -0,0 +1,269 @@ +# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. +# yarn lockfile v1 + + +"@external/esm@link:./projects/resolution/packages/external/esm": + version "0.0.0" + uid "" + +"@external/root-idx@link:./projects/resolution/packages/external/root-idx": + version "0.0.0" + uid "" + +"@external/root-named-idx@link:./projects/resolution/packages/external/root-named-idx": + version "0.0.0" + uid "" + +"@external/subdir-idx@link:./projects/resolution/packages/external/subdir-idx": + version "0.0.0" + uid "" + +"@types/underscore-test@link:src/ut-global": + version "0.0.0" + uid "" + +ansi-regex@^5.0.1: + version "5.0.1" + resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-5.0.1.tgz#082cb2c89c9fe8659a311a53bd6a4dc5301db304" + integrity sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ== + +ansi-styles@^4.1.0: + version "4.3.0" + resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-4.3.0.tgz#edd803628ae71c04c85ae7a0906edad34b648937" + integrity sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg== + dependencies: + color-convert "^2.0.1" + +balanced-match@^1.0.0: + version "1.0.2" + resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-1.0.2.tgz#e83e3a7e3f300b34cb9d87f615fa0cbf357690ee" + integrity sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw== + +brace-expansion@^1.1.7: + version "1.1.11" + resolved "https://registry.yarnpkg.com/brace-expansion/-/brace-expansion-1.1.11.tgz#3c7fcbf529d87226f3d2f52b966ff5271eb441dd" + integrity sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA== + dependencies: + balanced-match "^1.0.0" + concat-map "0.0.1" + +chalk@^4.1.0, chalk@^4.1.2: + version "4.1.2" + resolved "https://registry.yarnpkg.com/chalk/-/chalk-4.1.2.tgz#aac4e2b7734a740867aeb16bf02aad556a1e7a01" + integrity sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA== + dependencies: + ansi-styles "^4.1.0" + supports-color "^7.1.0" + +color-convert@^2.0.1: + version "2.0.1" + resolved "https://registry.yarnpkg.com/color-convert/-/color-convert-2.0.1.tgz#72d3a68d598c9bdb3af2ad1e84f21d896abd4de3" + integrity sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ== + dependencies: + color-name "~1.1.4" + +color-name@~1.1.4: + version "1.1.4" + resolved "https://registry.yarnpkg.com/color-name/-/color-name-1.1.4.tgz#c2a09a87acbde69543de6f63fa3995c826c536a2" + integrity sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA== + +concat-map@0.0.1: + version "0.0.1" + resolved "https://registry.yarnpkg.com/concat-map/-/concat-map-0.0.1.tgz#d8a96bd77fd68df7793a73036a3ba0d5405d477b" + integrity sha1-2Klr13/Wjfd5OnMDajug1UBdR3s= + +fs.realpath@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/fs.realpath/-/fs.realpath-1.0.0.tgz#1504ad2523158caa40db4a2787cb01411994ea4f" + integrity sha1-FQStJSMVjKpA20onh8sBQRmU6k8= + +function-bind@^1.1.1: + version "1.1.1" + resolved "https://registry.yarnpkg.com/function-bind/-/function-bind-1.1.1.tgz#a56899d3ea3c9bab874bb9773b7c5ede92f4895d" + integrity sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A== + +glob@^7.0.0, glob@^7.1.7: + version "7.2.0" + resolved "https://registry.yarnpkg.com/glob/-/glob-7.2.0.tgz#d15535af7732e02e948f4c41628bd910293f6023" + integrity sha512-lmLf6gtyrPq8tTjSmrO94wBeQbFR3HbLHbuyD69wuyQkImp2hWqMGB47OX65FBkPffO641IP9jWa1z4ivqG26Q== + dependencies: + fs.realpath "^1.0.0" + inflight "^1.0.4" + inherits "2" + minimatch "^3.0.4" + once "^1.3.0" + path-is-absolute "^1.0.0" + +global-prefix@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/global-prefix/-/global-prefix-3.0.0.tgz#fc85f73064df69f50421f47f883fe5b913ba9b97" + integrity sha512-awConJSVCHVGND6x3tmMaKcQvwXLhjdkmomy2W+Goaui8YPgYgXJZewhg3fWC+DlfqqQuWg8AwqjGTD2nAPVWg== + dependencies: + ini "^1.3.5" + kind-of "^6.0.2" + which "^1.3.1" + +has-flag@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/has-flag/-/has-flag-4.0.0.tgz#944771fd9c81c81265c4d6941860da06bb59479b" + integrity sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ== + +has@^1.0.3: + version "1.0.3" + resolved "https://registry.yarnpkg.com/has/-/has-1.0.3.tgz#722d7cbfc1f6aa8241f16dd814e011e1f41e8796" + integrity sha512-f2dvO0VU6Oej7RkWJGrehjbzMAjFp5/VKPp5tTpWIV4JHHZK1/BxbFRtf/siA2SWTe09caDmVtYYzWEIbBS4zw== + dependencies: + function-bind "^1.1.1" + +inflight@^1.0.4: + version "1.0.6" + resolved "https://registry.yarnpkg.com/inflight/-/inflight-1.0.6.tgz#49bd6331d7d02d0c09bc910a1075ba8165b56df9" + integrity sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk= + dependencies: + once "^1.3.0" + wrappy "1" + +inherits@2: + version "2.0.4" + resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.4.tgz#0fa2c64f932917c3433a0ded55363aae37416b7c" + integrity sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ== + +ini@^1.3.5: + version "1.3.8" + resolved "https://registry.yarnpkg.com/ini/-/ini-1.3.8.tgz#a29da425b48806f34767a4efce397269af28432c" + integrity sha512-JV/yugV2uzW5iMRSiZAyDtQd+nxtUnjeLt0acNdw98kKLrvuRVyB80tsREOE7yvGVgalhZ6RNXCmEHkUKBKxew== + +interpret@^1.0.0: + version "1.4.0" + resolved "https://registry.yarnpkg.com/interpret/-/interpret-1.4.0.tgz#665ab8bc4da27a774a40584e812e3e0fa45b1a1e" + integrity sha512-agE4QfB2Lkp9uICn7BAqoscw4SZP9kTE2hxiFI3jBPmXJfdqiahTbUuKGsMoN2GtqL9AxhYioAcVvgsb1HvRbA== + +is-core-module@^2.2.0: + version "2.6.0" + resolved "https://registry.yarnpkg.com/is-core-module/-/is-core-module-2.6.0.tgz#d7553b2526fe59b92ba3e40c8df757ec8a709e19" + integrity sha512-wShG8vs60jKfPWpF2KZRaAtvt3a20OAn7+IJ6hLPECpSABLcKtFKTTI4ZtH5QcBruBHlq+WsdHWyz0BCZW7svQ== + dependencies: + has "^1.0.3" + +isexe@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/isexe/-/isexe-2.0.0.tgz#e8fbf374dc556ff8947a10dcb0572d633f2cfa10" + integrity sha1-6PvzdNxVb/iUehDcsFctYz8s+hA= + +kind-of@^6.0.2: + version "6.0.3" + resolved "https://registry.yarnpkg.com/kind-of/-/kind-of-6.0.3.tgz#07c05034a6c349fa06e24fa35aa76db4580ce4dd" + integrity sha512-dcS1ul+9tmeD95T+x28/ehLgd9mENa3LsvDTtzm3vyBEO7RPptvAD+t44WVXaUjTBRcrpFeFlC8WCruUR456hw== + +minimatch@^3.0.4: + version "3.0.4" + resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-3.0.4.tgz#5166e286457f03306064be5497e8dbb0c3d32083" + integrity sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA== + dependencies: + brace-expansion "^1.1.7" + +minimist@^1.2.5: + version "1.2.5" + resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.5.tgz#67d66014b66a6a8aaa0c083c5fd58df4e4e97602" + integrity sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw== + +once@^1.3.0: + version "1.4.0" + resolved "https://registry.yarnpkg.com/once/-/once-1.4.0.tgz#583b1aa775961d4b113ac17d9c50baef9dd76bd1" + integrity sha1-WDsap3WWHUsROsF9nFC6753Xa9E= + dependencies: + wrappy "1" + +path-is-absolute@^1.0.0: + version "1.0.1" + resolved "https://registry.yarnpkg.com/path-is-absolute/-/path-is-absolute-1.0.1.tgz#174b9268735534ffbc7ace6bf53a5a9e1b5c5f5f" + integrity sha1-F0uSaHNVNP+8es5r9TpanhtcX18= + +path-parse@^1.0.6: + version "1.0.7" + resolved "https://registry.yarnpkg.com/path-parse/-/path-parse-1.0.7.tgz#fbc114b60ca42b30d9daf5858e4bd68bbedb6735" + integrity sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw== + +rechoir@^0.6.2: + version "0.6.2" + resolved "https://registry.yarnpkg.com/rechoir/-/rechoir-0.6.2.tgz#85204b54dba82d5742e28c96756ef43af50e3384" + integrity sha1-hSBLVNuoLVdC4oyWdW70OvUOM4Q= + dependencies: + resolve "^1.1.6" + +resolve@^1.1.6, resolve@^1.20.0: + version "1.20.0" + resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.20.0.tgz#629a013fb3f70755d6f0b7935cc1c2c5378b1975" + integrity sha512-wENBPt4ySzg4ybFQW2TT1zMQucPK95HSh/nq2CFTZVOGut2+pQvSsgtda4d26YrYcr067wjbmzOG8byDPBX63A== + dependencies: + is-core-module "^2.2.0" + path-parse "^1.0.6" + +shelljs@^0.8.4: + version "0.8.4" + resolved "https://registry.yarnpkg.com/shelljs/-/shelljs-0.8.4.tgz#de7684feeb767f8716b326078a8a00875890e3c2" + integrity sha512-7gk3UZ9kOfPLIAbslLzyWeGiEqx9e3rxwZM0KE6EL8GlGwjym9Mrlx5/p33bWTu9YG6vcS4MBxYZDHYr5lr8BQ== + dependencies: + glob "^7.0.0" + interpret "^1.0.0" + rechoir "^0.6.2" + +strip-ansi@^6.0.0: + version "6.0.1" + resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9" + integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A== + dependencies: + ansi-regex "^5.0.1" + +supports-color@^7.1.0: + version "7.2.0" + resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-7.2.0.tgz#1b7dcdcb32b8138801b3e478ba6a51caa89648da" + integrity sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw== + dependencies: + has-flag "^4.0.0" + +ts-expose-internals@latest: + version "4.4.3" + resolved "https://registry.yarnpkg.com/ts-expose-internals/-/ts-expose-internals-4.4.3.tgz#02cd43988403b35d266ac69bf5bee02a885093f4" + integrity sha512-hvdD6g3aOdh6vnTMBpKfy+mfG4uTxN7aq5PYC1/s0MCqEKY3+1QD0o1yEgafIGzp9Bi4k7ciaB/lPWV8s55xTQ== + +"ts-patch@link:../node_modules/ts-patch": + version "0.0.0" + uid "" + +"tstp@link:..": + version "0.0.0" + uid "" + +"typescript-42@npm:typescript@4.2.2": + version "4.2.2" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.2.2.tgz#1450f020618f872db0ea17317d16d8da8ddb8c4c" + integrity sha512-tbb+NVrLfnsJy3M59lsDgrzWIflR4d4TIUjz+heUnHZwdF7YsrMTKoRERiIvI2lvBG95dfpLxB21WZhys1bgaQ== + +"typescript-latest@npm:typescript@latest": + version "4.4.3" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.4.3.tgz#bdc5407caa2b109efd4f82fe130656f977a29324" + integrity sha512-4xfscpisVgqqDfPaJo5vkd+Qd/ItkoagnHpufr+i2QCHBsNYp+G7UAoyFl8aPtx879u38wPV65rZ8qbGZijalA== + +typescript-transform-paths@*: + version "3.3.1" + resolved "https://registry.yarnpkg.com/typescript-transform-paths/-/typescript-transform-paths-3.3.1.tgz#74526bc1b6dc575ffe269cc81833db7bd81763e1" + integrity sha512-c+8Cqd2rsRtTU68rJI0NX/OtqgBDddNs1fIxm1nCNyhn0WpoyqtpUxc1w9Ke5c5kgE4/OT5xYbKf2cf694RYEg== + dependencies: + minimatch "^3.0.4" + +"typescript-transform-paths@link:./transformer-wrapper": + version "0.0.0" + uid "" + +which@^1.3.1: + version "1.3.1" + resolved "https://registry.yarnpkg.com/which/-/which-1.3.1.tgz#a45043d54f5805316da8d62f9f50918d3da70b0a" + integrity sha512-HxJdYWq1MTIQbJ3nw0cqssHoTNU267KlrDuGZ1WYlxDStUtKUhOaJmh112/TZmHxxUfuJqPXSOm7tDyas0OSIQ== + dependencies: + isexe "^2.0.0" + +wrappy@1: + version "1.0.2" + resolved "https://registry.yarnpkg.com/wrappy/-/wrappy-1.0.2.tgz#b5243d8f3ec1aa35f1364605bc0d1036e30ab69f" + integrity sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8= diff --git a/tsconfig.json b/tsconfig.json index 84819c04..14322882 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,7 +1,6 @@ { "extends": "./tsconfig.base", "include": [ "src" ], - "exclude": [ "src/declarations" ], "compilerOptions": { "rootDir": "src", diff --git a/yarn.lock b/yarn.lock index 4b622de8..6f98ae26 100644 --- a/yarn.lock +++ b/yarn.lock @@ -826,6 +826,11 @@ resolved "https://registry.yarnpkg.com/@types/stack-utils/-/stack-utils-2.0.1.tgz#20f18294f797f2209b5f65c8e3b5c8e8261d127c" integrity sha512-Hl219/BT5fLAaz6NDkSuhzasy49dwQS/DSdu4MdggFB8zcXv7vflBI3xp7FEmkmdDkBUI2bPUNeMttp2knYdxw== +"@types/ts-expose-internals@npm:ts-expose-internals@4.4.3": + version "4.4.3" + resolved "https://registry.yarnpkg.com/ts-expose-internals/-/ts-expose-internals-4.4.3.tgz#02cd43988403b35d266ac69bf5bee02a885093f4" + integrity sha512-hvdD6g3aOdh6vnTMBpKfy+mfG4uTxN7aq5PYC1/s0MCqEKY3+1QD0o1yEgafIGzp9Bi4k7ciaB/lPWV8s55xTQ== + "@types/yargs-parser@*": version "15.0.0" resolved "https://registry.yarnpkg.com/@types/yargs-parser/-/yargs-parser-15.0.0.tgz#cb3f9f741869e20cce330ffbeb9271590483882d" @@ -1419,7 +1424,14 @@ create-require@^1.1.0: resolved "https://registry.yarnpkg.com/create-require/-/create-require-1.1.1.tgz#c1d7e8f1e5f6cfc9ff65f9cd352d37348756c333" integrity sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ== -cross-spawn@^7.0.3: +cross-env@^7.0.3: + version "7.0.3" + resolved "https://registry.yarnpkg.com/cross-env/-/cross-env-7.0.3.tgz#865264b29677dc015ba8418918965dd232fc54cf" + integrity sha512-+/HKd6EgcQCJGh2PSjZuUitQBQynKor4wrFbRg4DtAgS1aWO+gU52xpH7M9ScGgXSYmAVS9bIJ8EzuaGw0oNAw== + dependencies: + cross-spawn "^7.0.1" + +cross-spawn@^7.0.1, cross-spawn@^7.0.3: version "7.0.3" resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-7.0.3.tgz#f73a85b9d5d41d045551c177e2882d4ac85728a6" integrity sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w== @@ -3637,11 +3649,6 @@ trim-off-newlines@^1.0.0: resolved "https://registry.yarnpkg.com/trim-off-newlines/-/trim-off-newlines-1.0.1.tgz#9f9ba9d9efa8764c387698bcbfeb2c848f11adb3" integrity sha1-n5up2e+odkw4dpi8v+sshI8RrbM= -ts-expose-internals@^4.4.3: - version "4.4.3" - resolved "https://registry.yarnpkg.com/ts-expose-internals/-/ts-expose-internals-4.4.3.tgz#02cd43988403b35d266ac69bf5bee02a885093f4" - integrity sha512-hvdD6g3aOdh6vnTMBpKfy+mfG4uTxN7aq5PYC1/s0MCqEKY3+1QD0o1yEgafIGzp9Bi4k7ciaB/lPWV8s55xTQ== - ts-jest@^27.0.4: version "27.0.4" resolved "https://registry.yarnpkg.com/ts-jest/-/ts-jest-27.0.4.tgz#df49683535831560ccb58f94c023d831b1b80df0" @@ -3687,6 +3694,16 @@ ts-patch@^1.4.4: shelljs "^0.8.4" strip-ansi "^6.0.0" +"ts3@npm:typescript@3.7.7": + version "3.7.7" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.7.7.tgz#c931733e2ec10dda56b855b379cc488a72a81199" + integrity sha512-MmQdgo/XenfZPvVLtKZOq9jQQvzaUAUpcKW8Z43x9B2fOm4S5g//tPtMweZUIP+SoBqrVPEIm+dJeQ9dfO0QdA== + +"ts45@npm:typescript@4.5.0-beta": + version "4.5.0-beta" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.5.0-beta.tgz#f2e2724d93c35e7a0d0d1e55a22d1e4efb2181c7" + integrity sha512-7PvWhki2lwukaR9osVhFnNzxaE4LM+gC94dlwcvS+Tqz8+U65va7FbKo02bT+/MFlnMPM8bsPUXvHiMD/Mg3Jg== + type-check@~0.3.2: version "0.3.2" resolved "https://registry.yarnpkg.com/type-check/-/type-check-0.3.2.tgz#5884cab512cf1d355e3fb784f30804b2b520db72" @@ -3736,7 +3753,7 @@ typedarray@^0.0.6: resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777" integrity sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c= -typescript@^4.4.3: +typescript@latest: version "4.4.3" resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.4.3.tgz#bdc5407caa2b109efd4f82fe130656f977a29324" integrity sha512-4xfscpisVgqqDfPaJo5vkd+Qd/ItkoagnHpufr+i2QCHBsNYp+G7UAoyFl8aPtx879u38wPV65rZ8qbGZijalA== From 7edfd10c9d8240bad2b15fcde138bad29e28d781 Mon Sep 17 00:00:00 2001 From: Ron S Date: Sat, 30 Oct 2021 21:04:11 -0400 Subject: [PATCH 08/13] refactor: Correct a few minor bugs --- src/resolve/resolve-module-name.ts | 8 +++++--- src/ts/ts-helpers.ts | 9 +++++++++ src/utils.ts | 4 ++-- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/resolve/resolve-module-name.ts b/src/resolve/resolve-module-name.ts index e3ae27c5..6d19a2b9 100755 --- a/src/resolve/resolve-module-name.ts +++ b/src/resolve/resolve-module-name.ts @@ -3,8 +3,8 @@ import { baseName, dirName, isBaseDir, isURL, joinPaths, maybeAddRelativeLocalPrefix, normalizeSlashes, relativePath, removeSuffix } from "../utils"; -import { getOutputExtension, Node, Pattern, removeFileExtension, ResolvedModuleFull, SourceFile } from "typescript"; -import { getOutputPathForSourceFile } from "../ts"; +import { Node, Pattern, removeFileExtension, ResolvedModuleFull, SourceFile } from "typescript"; +import { getOutputPathForSourceFile, getOutputExtension } from "../ts"; import { getOutputPathDetail, OutputPathDetail } from "./output-path-detail"; import { IndexFlags } from "./index-checker"; @@ -63,6 +63,8 @@ function getReturnPath(ctx: GetReturnPathContext) { resolver, config: { outputExtensions, outputIndexes }, compilerOptions, + tsInstance, + isDeclarationFile } = ctx.visitorContext; const { suppliedExt, resolvedPath, isImplicitExtension, indexDetail, isExternalLibraryImport } = ctx.pathDetail ?? {}; @@ -74,7 +76,7 @@ function getReturnPath(ctx: GetReturnPathContext) { !isImplicitExtension && outputExtensions !== 'never' ? suppliedExt : outputExtensions === 'always' - ? getOutputExtension(resolvedSourceFile!, compilerOptions) + ? getOutputExtension(tsInstance, compilerOptions, resolvedSourceFile!, isDeclarationFile) : void 0; let usesStrippedIndex = false; diff --git a/src/ts/ts-helpers.ts b/src/ts/ts-helpers.ts index 4526302a..28e1cba7 100755 --- a/src/ts/ts-helpers.ts +++ b/src/ts/ts-helpers.ts @@ -137,4 +137,13 @@ export function checkTsSupport(tsInstance: typeof TS) { throw new Error(`The latest version of 'typescript-transform-paths' requires TS version 4.2.2 or higher. Either upgrade TS or use v3 of the plugin.`); } +export function getOutputExtension( + tsInstance: typeof TS, + compilerOptions: TS.CompilerOptions, + sourceFile: TS.SourceFile, + isDeclaration: boolean +) { + return isDeclaration ? '.d.ts' : tsInstance.getOutputExtension(sourceFile, compilerOptions); +} + // endregion diff --git a/src/utils.ts b/src/utils.ts index e15ce9a7..c977fe37 100755 --- a/src/utils.ts +++ b/src/utils.ts @@ -31,8 +31,8 @@ export const maybeAddRelativeLocalPrefix = (p: string) => (p[0] === "." ? p : `. * Merge and normalize paths (preserves relative prefix – ie. `./my/path`) */ export function joinPaths(...paths: (string | undefined)[]): string { - // path.join / ts.normalizePath cannot be used here, because they remove relative prefix - return normalizePath((paths.filter(p => !!p) as string[]).join('/'))!; + // path.join / normalizePath cannot be used here, because they remove relative prefix + return normalizeSlashes((paths.filter(p => !!p) as string[]).join('/'))!; } /** From bb97f0130bdd485752d9a257fd11ba54c40d165f Mon Sep 17 00:00:00 2001 From: Ron S Date: Sun, 14 Nov 2021 19:39:55 -0500 Subject: [PATCH 09/13] test: Get all tests passing --- src/resolve/resolve-module-name.ts | 4 ++-- test/projects/resolution/src/esm.ts | 7 ++++--- test/projects/resolution/tests.ts | 12 +++++++----- test/src/ut/utils/create-config-spread.ts | 2 ++ test/tests/projects/resolution.test.ts | 8 ++------ 5 files changed, 17 insertions(+), 16 deletions(-) diff --git a/src/resolve/resolve-module-name.ts b/src/resolve/resolve-module-name.ts index 6d19a2b9..6d809f6e 100755 --- a/src/resolve/resolve-module-name.ts +++ b/src/resolve/resolve-module-name.ts @@ -86,7 +86,7 @@ function getReturnPath(ctx: GetReturnPathContext) { (indexDetail.flags & ~IndexFlags.Implicit && outputIndexes === 'never') ) { const indexPath = isExternalLibraryImport - ? baseName(indexDetail.indexPath!, true) + ? removeFileExtension(indexDetail.indexPath!) : normalizeSlashes(removeFileExtension(indexDetail.indexPath!), { removeTrailingSlash: true }); res = normalizeSlashes(removeSuffix(res, indexPath), { removeTrailingSlash: true }); usesStrippedIndex = true; @@ -186,7 +186,7 @@ export function resolveModuleName( const { suppliedPackageName, suppliedPackagePath, indexDetail } = pathDetail; let outputPath = joinPaths(suppliedPackageName, suppliedPackagePath && removeFileExtension(suppliedPackagePath)); - if (indexDetail.flags & IndexFlags.Implicit) outputPath = joinPaths(outputPath, baseName(indexDetail.indexPath!, true)); + if (indexDetail.flags & IndexFlags.Implicit) outputPath = joinPaths(outputPath, removeFileExtension(indexDetail.indexPath!)); return getReturnPath({ moduleName, diff --git a/test/projects/resolution/src/esm.ts b/test/projects/resolution/src/esm.ts index 3ca58755..32863060 100755 --- a/test/projects/resolution/src/esm.ts +++ b/test/projects/resolution/src/esm.ts @@ -1,11 +1,12 @@ -import { _test_esm_index, _test_esm_reject_unmapped } from "../tests"; +import { _test_esm_reject_unmapped } from "../tests"; /* ****************************************************************************************************************** * * Index * ****************************************************************************************************************** */ +// TODO - Implicit indexes are more tricky with ESM and are not presently supported -_expect(_test_esm_index, _expect.index('@external/esm', 'dir/main')); -import '@external/esm'; +// _expect(_test_esm_index, _expect.index('@external/esm', 'dir/main')); +// import '@external/esm'; /* ****************************************************************************************************************** * * Synthetic Paths diff --git a/test/projects/resolution/tests.ts b/test/projects/resolution/tests.ts index 88888146..166fea8d 100755 --- a/test/projects/resolution/tests.ts +++ b/test/projects/resolution/tests.ts @@ -14,11 +14,6 @@ export const _test_external_package_index = _test({ export const _test_local_index = _test(`Local index resolves properly`); -export const _test_esm_index = _test({ - label: `Resolves index`, - group: 'ESM' -}); - // Not supported pre 4.5 - maybe supported after? // export const _test_esm_synthetic_path = _test({ @@ -32,6 +27,13 @@ export const _test_esm_reject_unmapped = _test({ if: () => false }); +// --- TODO ---- + +// export const _test_esm_index = _test({ +// label: `Resolves index`, +// group: 'ESM' +// }); + // export const _test_tricky = _test({ // label: 'Tricky' // }); diff --git a/test/src/ut/utils/create-config-spread.ts b/test/src/ut/utils/create-config-spread.ts index 1f607af6..2806a872 100755 --- a/test/src/ut/utils/create-config-spread.ts +++ b/test/src/ut/utils/create-config-spread.ts @@ -30,5 +30,7 @@ export function createConfigSpread(config: SpreadableConfig) { } } + if (!res.length) res.push(staticProps); + return res; } diff --git a/test/tests/projects/resolution.test.ts b/test/tests/projects/resolution.test.ts index ee26b2fc..d37879a7 100755 --- a/test/tests/projects/resolution.test.ts +++ b/test/tests/projects/resolution.test.ts @@ -7,14 +7,10 @@ import { ut } from '../../src'; const testRuns = ut.loadProject({ projectName: 'resolution', useGroups: true, - // configs: ut.createConfigSpread({ - // outputIndexes: [ 'auto', 'never', 'always' ], - // outputExtensions: [ 'auto', 'never', 'always' ] - // }) configs: ut.createConfigSpread({ - outputIndexes: 'always', + outputIndexes: [ 'auto', 'never', 'always' ], outputExtensions: [ 'auto', 'never', 'always' ] - }) + }), }); /* ****************************************************************************************************************** * From e915977fe5c7076d268ae443a404d82b441d7450 Mon Sep 17 00:00:00 2001 From: Ron S Date: Sun, 14 Nov 2021 19:43:57 -0500 Subject: [PATCH 10/13] style: Fix formatting (prettier) --- src/compatibility/node-register.ts | 18 +- src/index.ts | 5 +- src/resolve/extensions.ts | 5 +- src/resolve/index-checker.ts | 28 +-- src/resolve/index.ts | 2 +- src/resolve/output-path-detail.ts | 12 +- src/resolve/resolve-module-name.ts | 33 ++-- src/resolve/resolve-path-update-node.ts | 28 +-- src/transform/elide-import-export.ts | 6 +- src/transform/index.ts | 2 +- src/transform/transformer.ts | 22 +-- src/transform/visitor.ts | 10 +- src/ts/harmony-factory.ts | 4 +- src/ts/index.ts | 4 +- src/ts/ts-helpers.ts | 29 ++- src/types.ts | 56 +++--- src/utils.ts | 17 +- test/prepare.js | 16 +- test/projects/extras/src/index.ts | 4 +- test/projects/general/circular/a.ts | 4 +- test/projects/general/circular/b.ts | 2 +- test/projects/general/core/index.ts | 36 ++-- test/projects/general/dynamic/logger.ts | 4 +- test/projects/general/secondary/hello.ts | 2 +- test/projects/general/utils/index.ts | 6 +- test/projects/general/utils/subs.ts | 2 +- test/projects/general/utils/types-only.ts | 4 +- test/projects/project-ref/b/index.ts | 8 +- test/projects/project-ref/b/tests.ts | 1 - test/projects/resolution/src/esm.ts | 3 +- test/projects/resolution/src/indexes.ts | 27 ++- test/projects/resolution/src/tricky.ts | 5 +- test/projects/resolution/tests.ts | 6 +- .../root-dirs/generated/dir/gen-file.ts | 6 +- test/projects/root-dirs/src/dir/src-file.ts | 6 +- test/projects/root-dirs/src/index.ts | 12 +- test/projects/root-dirs/tests.ts | 4 +- test/projects/specific/src/index.ts | 33 ++-- test/projects/specific/src/module-augment.ts | 8 +- test/projects/specific/src/tags.ts | 28 +-- test/projects/specific/src/type-elision/a.ts | 2 +- .../specific/src/type-elision/index.ts | 19 +- test/projects/specific/tests.ts | 8 +- test/src/config.ts | 12 +- test/src/index.ts | 4 +- test/src/setup.ts | 32 ++-- test/src/ts-helpers.ts | 29 +-- test/src/ut-global/globals.d.ts | 38 ++-- test/src/ut/index.ts | 6 +- test/src/ut/matchers/to-resolve.ts | 20 +- test/src/ut/project/index.ts | 2 +- test/src/ut/project/load-project.ts | 60 +++--- test/src/ut/project/project-walker.ts | 178 ++++++++++-------- test/src/ut/test-map.ts | 34 ++-- test/src/ut/types.ts | 75 ++++---- test/src/ut/utils/create-config-spread.ts | 4 +- test/src/ut/utils/node-helpers.ts | 47 +++-- .../tests/compatibility/node-register.test.ts | 62 +++--- test/tests/projects/extras.test.ts | 23 ++- test/tests/projects/general.test.ts | 2 +- test/tests/projects/project-ref.test.ts | 12 +- test/tests/projects/resolution.test.ts | 4 +- test/tests/projects/root-dirs.test.ts | 7 +- test/tests/projects/specific.test.ts | 4 +- test/transformer-wrapper/index.d.ts | 2 +- 65 files changed, 625 insertions(+), 569 deletions(-) diff --git a/src/compatibility/node-register.ts b/src/compatibility/node-register.ts index 242892c3..cba3369e 100755 --- a/src/compatibility/node-register.ts +++ b/src/compatibility/node-register.ts @@ -1,7 +1,7 @@ -import type TSNode from "ts-node"; -import type { REGISTER_INSTANCE } from "ts-node"; -import type TS from "typescript"; -import { transformer } from "../transform"; +import type TSNode from 'ts-node'; +import type { REGISTER_INSTANCE } from 'ts-node'; +import type TS from 'typescript'; +import { transformer } from '../transform'; /* ****************************************************************************************************************** */ // region: Helpers @@ -16,7 +16,7 @@ const checkModuleIsTsTp = (m: string) => { if (!transformerModule) return m === 'typescript-transform-paths'; return transformerModule.isTsTp; -} +}; function getProjectTransformerConfig(pcl: TS.ParsedCommandLine) { const plugins = pcl.options.plugins as Record[] | undefined; @@ -25,7 +25,7 @@ function getProjectTransformerConfig(pcl: TS.ParsedCommandLine) { const res: { afterDeclarations?: Record; before?: Record } = {}; for (const plugin of plugins) { if (plugin.transform && checkModuleIsTsTp(plugin.transform) && !plugin.after) - res[plugin.afterDeclarations ? "afterDeclarations" : "before"] = plugin; + res[plugin.afterDeclarations ? 'afterDeclarations' : 'before'] = plugin; } return res; @@ -78,7 +78,7 @@ export function nodeRegister(): TSNode.RegisterOptions | undefined { const registerOptions: TSNode.RegisterOptions = Object.assign({}, tsNodeInstance.options); if (registerOptions.transformers) { - if (typeof registerOptions.transformers === "function") { + if (typeof registerOptions.transformers === 'function') { let oldTransformersFactory = registerOptions.transformers; registerOptions.transformers = (program) => { const transformers = getTransformers(program, beforeConfig, afterDeclarationsConfig); @@ -108,14 +108,14 @@ export namespace nodeRegister { } { let tsNode: typeof TSNode; try { - tsNode = require("ts-node"); + tsNode = require('ts-node'); } catch { throw new Error( `Cannot resolve ts-node. Make sure ts-node is installed before using typescript-transform-paths/register` ); } - const instanceSymbol: typeof REGISTER_INSTANCE = tsNode["REGISTER_INSTANCE"]; + const instanceSymbol: typeof REGISTER_INSTANCE = tsNode['REGISTER_INSTANCE']; let tsNodeInstance = global.process[instanceSymbol]; if (!tsNodeInstance) { diff --git a/src/index.ts b/src/index.ts index 26d86152..6da3fc7f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,4 +1,3 @@ - /* ****************************************************************************************************************** * * Transformer * ****************************************************************************************************************** */ @@ -10,14 +9,14 @@ export default transformer; * Types * ****************************************************************************************************************** */ -export * from "./types"; +export * from './types'; /* ****************************************************************************************************************** * * Compatibility * ****************************************************************************************************************** */ /** @internal */ -export { nodeRegister } from "./compatibility/node-register"; +export { nodeRegister } from './compatibility/node-register'; /* ****************************************************************************************************************** * * Internal diff --git a/src/resolve/extensions.ts b/src/resolve/extensions.ts index 0d29e912..be8a47c2 100755 --- a/src/resolve/extensions.ts +++ b/src/resolve/extensions.ts @@ -1,10 +1,10 @@ -import { extName } from "../utils"; +import { extName } from '../utils'; /* ****************************************************************************************************************** * * Locals * ****************************************************************************************************************** */ -const implicitExtensions = [ '.js', '.d.ts', '.ts' ]; +const implicitExtensions = ['.js', '.d.ts', '.ts']; /* ****************************************************************************************************************** */ // region: Utils @@ -20,4 +20,3 @@ export function stripImplicitExtension(fileName: string) { } // endregion - diff --git a/src/resolve/index-checker.ts b/src/resolve/index-checker.ts index 71397f0c..e37137d5 100755 --- a/src/resolve/index-checker.ts +++ b/src/resolve/index-checker.ts @@ -1,29 +1,28 @@ -import type TS from "typescript"; -import fs from "fs"; -import { isImplicitExtension, stripImplicitExtension } from "./extensions"; -import { dirName, normalizePath, relativePath, resolvePath } from "../utils"; +import type TS from 'typescript'; +import fs from 'fs'; +import { isImplicitExtension, stripImplicitExtension } from './extensions'; +import { dirName, normalizePath, relativePath, resolvePath } from '../utils'; /* ****************************************************************************************************************** */ // region: Types /* ****************************************************************************************************************** */ export interface IndexDetail { - flags: IndexFlags - indexPath?: string + flags: IndexFlags; + indexPath?: string; } export enum IndexFlags { None, Implicit = 1 << 0, Package = 1 << 1, - Node = 1 << 2 + Node = 1 << 2, } -type PackageIndexInfo = { packageIndex: string, packageDir: string } +type PackageIndexInfo = { packageIndex: string; packageDir: string }; // endregion - /* ****************************************************************************************************************** * * IndexChecker (class) * ****************************************************************************************************************** */ @@ -40,8 +39,8 @@ export class IndexChecker { if (suppliedBaseNameNoExt !== baseNameNoExt) flags |= IndexFlags.Implicit; return { indexPath: baseNameNoExt + (ext ?? ''), - flags - } + flags, + }; } return { flags: IndexFlags.None }; @@ -67,7 +66,10 @@ export class IndexChecker { if (fileNameStrippedExt.slice(-matchedStar.length) !== matchedStar) flags |= IndexFlags.Implicit; } else { if (suppliedPackageName) - if (!suppliedPathStrippedExt || fileNameStrippedExt.slice(-suppliedPathStrippedExt.length) !== suppliedPathStrippedExt) + if ( + !suppliedPathStrippedExt || + fileNameStrippedExt.slice(-suppliedPathStrippedExt.length) !== suppliedPathStrippedExt + ) flags |= IndexFlags.Implicit; } @@ -103,7 +105,7 @@ export class IndexChecker { packageIndex = resolvePath(dir, packageIndex); const res = { packageDir: dir, packageIndex }; - pathStack.forEach(p => this.packageMap.set(p, res)); + pathStack.forEach((p) => this.packageMap.set(p, res)); return res; } diff --git a/src/resolve/index.ts b/src/resolve/index.ts index 73d74a26..e8a0bbb3 100755 --- a/src/resolve/index.ts +++ b/src/resolve/index.ts @@ -1 +1 @@ -export { resolvePathAndUpdateNode } from './resolve-path-update-node' +export { resolvePathAndUpdateNode } from './resolve-path-update-node'; diff --git a/src/resolve/output-path-detail.ts b/src/resolve/output-path-detail.ts index 94a87973..b642f1c5 100755 --- a/src/resolve/output-path-detail.ts +++ b/src/resolve/output-path-detail.ts @@ -1,7 +1,7 @@ -import { Pattern, ResolvedModuleFull } from "typescript"; -import { baseName, extName, joinPaths, normalizeSlashes, removeSuffix } from "../utils"; -import { VisitorContext } from "../types"; -import { IndexDetail } from "./index-checker"; +import { Pattern, ResolvedModuleFull } from 'typescript'; +import { baseName, extName, joinPaths, normalizeSlashes, removeSuffix } from '../utils'; +import { VisitorContext } from '../types'; +import { IndexDetail } from './index-checker'; /* ****************************************************************************************************************** */ // region: Types @@ -21,7 +21,7 @@ export interface OutputPathDetail { packageRoot?: string; packageFileName?: string; tsPathsKey?: string; - indexDetail: IndexDetail + indexDetail: IndexDetail; } // endregion @@ -116,7 +116,7 @@ export function getOutputPathDetail( suppliedPackagePath, suppliedPackageName, packageFileName, - indexDetail + indexDetail, }; } diff --git a/src/resolve/resolve-module-name.ts b/src/resolve/resolve-module-name.ts index 6d809f6e..0b617ccd 100755 --- a/src/resolve/resolve-module-name.ts +++ b/src/resolve/resolve-module-name.ts @@ -1,12 +1,19 @@ -import { ResolutionContext, VisitorContext } from "../types"; +import { ResolutionContext, VisitorContext } from '../types'; import { - baseName, dirName, isBaseDir, isURL, joinPaths, maybeAddRelativeLocalPrefix, normalizeSlashes, relativePath, - removeSuffix -} from "../utils"; -import { Node, Pattern, removeFileExtension, ResolvedModuleFull, SourceFile } from "typescript"; -import { getOutputPathForSourceFile, getOutputExtension } from "../ts"; -import { getOutputPathDetail, OutputPathDetail } from "./output-path-detail"; -import { IndexFlags } from "./index-checker"; + baseName, + dirName, + isBaseDir, + isURL, + joinPaths, + maybeAddRelativeLocalPrefix, + normalizeSlashes, + relativePath, + removeSuffix, +} from '../utils'; +import { Node, Pattern, removeFileExtension, ResolvedModuleFull, SourceFile } from 'typescript'; +import { getOutputPathForSourceFile, getOutputExtension } from '../ts'; +import { getOutputPathDetail, OutputPathDetail } from './output-path-detail'; +import { IndexFlags } from './index-checker'; /* ****************************************************************************************************************** */ // region: Types @@ -64,7 +71,7 @@ function getReturnPath(ctx: GetReturnPathContext) { config: { outputExtensions, outputIndexes }, compilerOptions, tsInstance, - isDeclarationFile + isDeclarationFile, } = ctx.visitorContext; const { suppliedExt, resolvedPath, isImplicitExtension, indexDetail, isExternalLibraryImport } = ctx.pathDetail ?? {}; @@ -98,7 +105,8 @@ function getReturnPath(ctx: GetReturnPathContext) { if (resolver) { const { moduleName, node, visitorContext, isURL, resolvedModule } = ctx; const { resolvedFileName, originalPath } = resolvedModule ?? {}; - const { packageName, suppliedPackageName, tsPathsKey, packageFileName, isExternalLibraryImport } = ctx.pathDetail ?? {}; + const { packageName, suppliedPackageName, tsPathsKey, packageFileName, isExternalLibraryImport } = + ctx.pathDetail ?? {}; const resolutionContext: ResolutionContext = { moduleExtName: suppliedExt, @@ -186,7 +194,8 @@ export function resolveModuleName( const { suppliedPackageName, suppliedPackagePath, indexDetail } = pathDetail; let outputPath = joinPaths(suppliedPackageName, suppliedPackagePath && removeFileExtension(suppliedPackagePath)); - if (indexDetail.flags & IndexFlags.Implicit) outputPath = joinPaths(outputPath, removeFileExtension(indexDetail.indexPath!)); + if (indexDetail.flags & IndexFlags.Implicit) + outputPath = joinPaths(outputPath, removeFileExtension(indexDetail.indexPath!)); return getReturnPath({ moduleName, @@ -195,7 +204,7 @@ export function resolveModuleName( resolvedModule, resolvedSourceFile, pathDetail, - outputPath + outputPath, }); } diff --git a/src/resolve/resolve-path-update-node.ts b/src/resolve/resolve-path-update-node.ts index 56dcd399..c18a4fe1 100755 --- a/src/resolve/resolve-path-update-node.ts +++ b/src/resolve/resolve-path-update-node.ts @@ -1,9 +1,8 @@ -import type TS from "typescript"; -import { VisitorContext } from "../types"; -import { isURL, maybeAddRelativeLocalPrefix, normalizePath } from "../utils"; -import { resolveModuleName } from "./resolve-module-name"; -import { getTsPathsMatch } from "../ts"; - +import type TS from 'typescript'; +import { VisitorContext } from '../types'; +import { isURL, maybeAddRelativeLocalPrefix, normalizePath } from '../utils'; +import { resolveModuleName } from './resolve-module-name'; +import { getTsPathsMatch } from '../ts'; /* ****************************************************************************************************************** * * Node Updater Util @@ -18,7 +17,12 @@ export function resolvePathAndUpdateNode( moduleName: string, updaterFn: (newPath: TS.StringLiteral) => TS.Node | undefined ): TS.Node | undefined { - const { sourceFile, tsInstance, factory, config: { outputExtensions, outputIndexes, usePaths } } = context; + const { + sourceFile, + tsInstance, + factory, + config: { outputExtensions, outputIndexes, usePaths }, + } = context; /* Handle JSDoc statement tags */ const tags = getStatementTags(); @@ -39,7 +43,7 @@ export function resolvePathAndUpdateNode( const pathsMatch = usePaths ? getTsPathsMatch(context, moduleName) : undefined; // Skip if possible - const canSkip = !pathsMatch && !context.resolver && outputIndexes !== "always" && outputExtensions !== "always"; + const canSkip = !pathsMatch && !context.resolver && outputIndexes !== 'always' && outputExtensions !== 'always'; if (canSkip) return node; // Resolve @@ -78,11 +82,11 @@ export function resolvePathAndUpdateNode( for (let match = regex.exec(trivia); match; match = regex.exec(trivia)) commentTags.set(match[1], match[2]); } catch {} - const overridePath = findTag("transform-path"); - const shouldSkip = findTag("no-transform-path"); + const overridePath = findTag('transform-path'); + const shouldSkip = findTag('no-transform-path'); return { - overridePath: typeof overridePath === "string" ? overridePath : void 0, + overridePath: typeof overridePath === 'string' ? overridePath : void 0, shouldSkip: !!shouldSkip, }; @@ -92,7 +96,7 @@ export function resolvePathAndUpdateNode( for (const tag of jsDocTags) { const tagName = tag.tagName.text.toLowerCase(); - if (tagName === expected) return typeof tag.comment === "string" ? tag.comment : true; + if (tagName === expected) return typeof tag.comment === 'string' ? tag.comment : true; } } } diff --git a/src/transform/elide-import-export.ts b/src/transform/elide-import-export.ts index 5d38d37b..a324bc19 100755 --- a/src/transform/elide-import-export.ts +++ b/src/transform/elide-import-export.ts @@ -28,7 +28,7 @@ * import { A, B } from './b' * export { A } from './b' */ -import { ImportOrExportClause, ImportOrExportDeclaration, VisitorContext } from "../types"; +import { ImportOrExportClause, ImportOrExportDeclaration, VisitorContext } from '../types'; import type { ExportDeclaration, ExportSpecifier, @@ -39,7 +39,7 @@ import type { NamedImportBindings, Visitor, VisitResult, -} from "typescript"; +} from 'typescript'; /* ****************************************************************************************************************** */ // region: Utilities @@ -55,7 +55,7 @@ import type { export function elideImportOrExportClause( context: VisitorContext, node: T -): (T extends ImportDeclaration ? ImportDeclaration["importClause"] : ExportDeclaration["exportClause"]) | undefined; +): (T extends ImportDeclaration ? ImportDeclaration['importClause'] : ExportDeclaration['exportClause']) | undefined; export function elideImportOrExportClause( context: VisitorContext, diff --git a/src/transform/index.ts b/src/transform/index.ts index 52d675ea..cf7900f2 100755 --- a/src/transform/index.ts +++ b/src/transform/index.ts @@ -1 +1 @@ -export { transformer } from './transformer' +export { transformer } from './transformer'; diff --git a/src/transform/transformer.ts b/src/transform/transformer.ts index b961f1b2..31791183 100755 --- a/src/transform/transformer.ts +++ b/src/transform/transformer.ts @@ -10,9 +10,9 @@ import { VisitorContext, } from '../types'; import { nodeVisitor } from './visitor'; -import { checkTsSupport, createHarmonyFactory, createSyntheticEmitHost, getTsNodeRegistrationProperties } from "../ts"; +import { checkTsSupport, createHarmonyFactory, createSyntheticEmitHost, getTsNodeRegistrationProperties } from '../ts'; import { Minimatch } from 'minimatch'; -import { IndexChecker } from "../resolve/index-checker"; +import { IndexChecker } from '../resolve/index-checker'; /* ****************************************************************************************************************** */ // region: Helpers @@ -69,7 +69,7 @@ function getTsDetail(p: { emitHost = createSyntheticEmitHost(compilerOptions, tsInstance, getCanonicalFileName, fileNames as string[]); } - const projectReferences = program?.getResolvedProjectReferences()?.map(r => r?.sourceFile); + const projectReferences = program?.getResolvedProjectReferences()?.map((r) => r?.sourceFile); return { tsInstance, compilerOptions, fileNames, isTranspileOnly, isTsNode, emitHost, projectReferences }; } @@ -88,7 +88,7 @@ export function getTransformerConfig(options?: TransformerOptions): TransformerC ...options, outputIndexes: options?.outputIndexes || 'auto', outputExtensions: options?.outputExtensions || 'auto', - usePaths: options?.usePaths ?? true + usePaths: options?.usePaths ?? true, }; } @@ -109,14 +109,12 @@ export function transformer( ) { return (transformationContext: TS.TransformationContext) => { const config = getTransformerConfig(options); - const { tsInstance, compilerOptions, isTranspileOnly, isTsNode, emitHost } = getTsDetail( - { - program, - extras, - manualTransformOptions, - transformationContext, - } - ); + const { tsInstance, compilerOptions, isTranspileOnly, isTsNode, emitHost } = getTsDetail({ + program, + extras, + manualTransformOptions, + transformationContext, + }); const rootDirs = compilerOptions.rootDirs?.filter(path.isAbsolute); const { configFile, paths } = compilerOptions; diff --git a/src/transform/visitor.ts b/src/transform/visitor.ts index a3bdd440..481ba34d 100755 --- a/src/transform/visitor.ts +++ b/src/transform/visitor.ts @@ -1,7 +1,7 @@ -import type TS from "typescript"; -import { VisitorContext } from "../types"; -import { elideImportOrExportClause } from "./elide-import-export"; -import { resolvePathAndUpdateNode } from "../resolve"; +import type TS from 'typescript'; +import { VisitorContext } from '../types'; +import { elideImportOrExportClause } from './elide-import-export'; +import { resolvePathAndUpdateNode } from '../resolve'; import { copyNodeComments } from '../ts'; /* ****************************************************************************************************************** * @@ -17,7 +17,7 @@ const isAsyncImport = ({ tsInstance }: VisitorContext, node: TS.Node): node is T const isRequire = ({ tsInstance }: VisitorContext, node: TS.Node): node is TS.CallExpression => tsInstance.isCallExpression(node) && tsInstance.isIdentifier(node.expression) && - node.expression.text === "require" && + node.expression.text === 'require' && tsInstance.isStringLiteral(node.arguments[0]) && node.arguments.length === 1; diff --git a/src/ts/harmony-factory.ts b/src/ts/harmony-factory.ts index 4534d0a6..f16b028b 100755 --- a/src/ts/harmony-factory.ts +++ b/src/ts/harmony-factory.ts @@ -1,4 +1,4 @@ -import TS from "typescript"; +import TS from 'typescript'; /* ****************************************************************************************************************** */ // region: Types @@ -80,7 +80,7 @@ export interface HarmonyFactory extends TS.NodeFactory {} * Creates a factory capable of working with any TS version using modern parameters */ export function createHarmonyFactory(tsInstance: typeof TS, factory: TS.NodeFactory | undefined): HarmonyFactory { - const [ majorVer, minorVer ] = tsInstance.versionMajorMinor.split('.'); + const [majorVer, minorVer] = tsInstance.versionMajorMinor.split('.'); return new Proxy(factory ?? tsInstance, { get(target, prop) { diff --git a/src/ts/index.ts b/src/ts/index.ts index 5bc466c9..f6a65aed 100755 --- a/src/ts/index.ts +++ b/src/ts/index.ts @@ -1,2 +1,2 @@ -export * from './harmony-factory' -export * from './ts-helpers' +export * from './harmony-factory'; +export * from './ts-helpers'; diff --git a/src/ts/ts-helpers.ts b/src/ts/ts-helpers.ts index 28e1cba7..fa0a5de1 100755 --- a/src/ts/ts-helpers.ts +++ b/src/ts/ts-helpers.ts @@ -1,7 +1,7 @@ -import TS from "typescript"; -import { GetCanonicalFileName, SourceFile } from "typescript"; -import { VisitorContext } from "../types"; -import type { REGISTER_INSTANCE } from "ts-node"; +import TS from 'typescript'; +import { GetCanonicalFileName, SourceFile } from 'typescript'; +import { VisitorContext } from '../types'; +import type { REGISTER_INSTANCE } from 'ts-node'; /* ****************************************************************************************************************** */ // region: TS Helpers @@ -65,7 +65,7 @@ export function createSyntheticEmitHost( export function getTsNodeRegistrationProperties(tsInstance: typeof TS) { let tsNodeSymbol: typeof REGISTER_INSTANCE; try { - tsNodeSymbol = require("ts-node")?.["REGISTER_INSTANCE"]; + tsNodeSymbol = require('ts-node')?.['REGISTER_INSTANCE']; } catch { return undefined; } @@ -88,7 +88,12 @@ export function getTsNodeRegistrationProperties(tsInstance: typeof TS) { /** * Copies comment range from srcNode to destNode */ -export function copyNodeComments(tsInstance: typeof TS, srcSourceFile: TS.SourceFile, srcNode: TS.Node, destNode: TS.Node) { +export function copyNodeComments( + tsInstance: typeof TS, + srcSourceFile: TS.SourceFile, + srcNode: TS.Node, + destNode: TS.Node +) { // TS has a bugs which cause getLeadingTriviaWidth & getLeadingCommentRanges to exceed the proper boundaries. // This tends to happen in scenarios where there are more than one comment. // - It often causes the final comment to include the full node text as well @@ -107,11 +112,13 @@ export function copyNodeComments(tsInstance: typeof TS, srcSourceFile: TS.Source const commentRegex = /(?:\/\*([\s\S]*?)\*\/|\/\/([^\r\n]*))(\r?\n?)/gs; let match: RegExpExecArray | null; - while (match = commentRegex.exec(commentText)) { + while ((match = commentRegex.exec(commentText))) { const caption = match[1] || match[2]; const isMultiLine = !!match[1]; const hasTrailingNewLine = !!match[3]; - const kind = isMultiLine ? tsInstance.SyntaxKind.MultiLineCommentTrivia : tsInstance.SyntaxKind.SingleLineCommentTrivia; + const kind = isMultiLine + ? tsInstance.SyntaxKind.MultiLineCommentTrivia + : tsInstance.SyntaxKind.SingleLineCommentTrivia; tsInstance.addSyntheticLeadingComment(destNode, kind, caption, hasTrailingNewLine); } @@ -132,9 +139,11 @@ export function getTsPathsMatch(context: VisitorContext, moduleName: string): st * Throw if unsupported version */ export function checkTsSupport(tsInstance: typeof TS) { - const [ major, minor ] = tsInstance.versionMajorMinor.split('.'); + const [major, minor] = tsInstance.versionMajorMinor.split('.'); if (+major < 4 || (+major === 4 && +minor < 2)) - throw new Error(`The latest version of 'typescript-transform-paths' requires TS version 4.2.2 or higher. Either upgrade TS or use v3 of the plugin.`); + throw new Error( + `The latest version of 'typescript-transform-paths' requires TS version 4.2.2 or higher. Either upgrade TS or use v3 of the plugin.` + ); } export function getOutputExtension( diff --git a/src/types.ts b/src/types.ts index 5beac6c9..b02bfd37 100755 --- a/src/types.ts +++ b/src/types.ts @@ -1,7 +1,7 @@ -import type TS from "typescript"; -import type { HarmonyFactory } from "./ts"; -import type { IMinimatch } from "minimatch"; -import { IndexChecker, IndexDetail } from "./resolve/index-checker"; +import type TS from 'typescript'; +import type { HarmonyFactory } from './ts'; +import type { IMinimatch } from 'minimatch'; +import { IndexChecker, IndexDetail } from './resolve/index-checker'; /* ****************************************************************************************************************** */ // region: Config @@ -46,7 +46,7 @@ export interface TransformerConfig { * // 'never: 'pkg' * import 'pkg'; */ - readonly outputIndexes: 'auto' | 'always' | 'never' + readonly outputIndexes: 'auto' | 'always' | 'never'; /** * Method for handling implicit extensions @@ -71,7 +71,7 @@ export interface TransformerConfig { * // 'never': './dir' * import './dir' */ - readonly outputExtensions: 'auto' | 'always' | 'never' + readonly outputExtensions: 'auto' | 'always' | 'never'; /** * Transform Exclusion patterns — exclude from transform if file path matches pattern @@ -91,7 +91,7 @@ export interface TransformerConfig { /* ****************************************************************************************************************** */ export interface PathResolver { - (ctx: ResolutionContext): string | undefined + (ctx: ResolutionContext): string | undefined; } export interface ResolutionContext { @@ -102,7 +102,7 @@ export interface ResolutionContext { * // moduleName = 'typescript-transform-paths/dist/index' * import './src/index'; */ - moduleName: string + moduleName: string; /** * Supplied module name's extension (if specified) @@ -113,17 +113,17 @@ export interface ResolutionContext { * // moduleExtName = '.ts' * import './src/index.ts'; */ - moduleExtName?: string + moduleExtName?: string; /** * This is the path that will normally be output by the plugin */ - outputPath: string + outputPath: string; /** * Extension for output path */ - outputExt: string | undefined + outputExt: string | undefined; /** * If there is a match from tsconfig.json -> 'compilerOptions' -> 'paths', the matched key name will be here @@ -140,12 +140,12 @@ export interface ResolutionContext { * // tsPathsKey = '#src/*' * import '#src/hello'; */ - tsPathsKey?: string + tsPathsKey?: string; /** * True if target is a URL */ - isURL: boolean + isURL: boolean; /** * Info on resolved target (not supplied if module can't be resolved to file) @@ -154,17 +154,17 @@ export interface ResolutionContext { /** * If the resolved file is a symlink, this will be the initial resolved path (before following link) */ - originalPath?: string + originalPath?: string; /** * Implicit index detail */ - indexDetail: IndexDetail + indexDetail: IndexDetail; /** * Final resolved file path (after following any symlink — for pre-follow, use `originalPath`) */ - resolvedFilePath: string + resolvedFilePath: string; /** * If module resolves to a sub-package within the current package or an external package, this is the sub-path within the package @@ -172,13 +172,13 @@ export interface ResolutionContext { * Note: This field is especially important with ESM, as it's possible for the import path not to correspond to the actual * resolved file path. */ - packagePath?: string + packagePath?: string; /** * Resolved ts.SourceFile */ - sourceFile?: TS.SourceFile - } + sourceFile?: TS.SourceFile; + }; /** * If the module resolves to a sub-package or external package, this contains that detail @@ -191,7 +191,7 @@ export interface ResolutionContext { * // packageName = '@scope/package' * import '@scope/package/dist/index'; */ - packageName: string + packageName: string; /** * Package name as specified @@ -210,21 +210,21 @@ export interface ResolutionContext { * // originalPackageName = 'aliased-typescript' * import 'aliased-typescript'; */ - originalPackageName?: string + originalPackageName?: string; - isExternalLibrary: boolean - } + isExternalLibrary: boolean; + }; /** * Context for visitor * @see https://github.com/LeDDGroup/typescript-transform-paths/blob/master/src/types.ts */ - visitorContext: VisitorContext + visitorContext: VisitorContext; /** * AST Node being transformed */ - node: TS.Node + node: TS.Node; } // endregion @@ -258,7 +258,7 @@ export interface TransformerContext { readonly emitHost: TS.EmitHost; /** @internal */ - indexChecker: IndexChecker + indexChecker: IndexChecker; /** @internal */ readonly elisionMap: Map>; /** @internal */ @@ -289,12 +289,12 @@ export type TsTransformPathsConfig = TransformerOptions; /** Represents Extras type passed by ttypescript or ts-patch */ export type TransformerExtras = { ts: typeof TS; -} +}; /** @internal */ export type ImportOrExportDeclaration = TS.ImportDeclaration | TS.ExportDeclaration; /** @internal */ -export type ImportOrExportClause = TS.ImportDeclaration["importClause"] | TS.ExportDeclaration["exportClause"]; +export type ImportOrExportClause = TS.ImportDeclaration['importClause'] | TS.ExportDeclaration['exportClause']; // endregion diff --git a/src/utils.ts b/src/utils.ts index c977fe37..97014978 100755 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,4 +1,4 @@ -import path from "path"; +import path from 'path'; import url from 'url'; /* ****************************************************************************************************************** * @@ -17,9 +17,9 @@ export const isURL = (s: string): boolean => !!s && (!!url.parse(s).host || !!ur export const cast = (v: any): T => v; export const isBaseDir = (baseDir: string, testDir: string): boolean => { const relative = path.relative(baseDir, testDir); - return relative ? !relative.startsWith("..") && !path.isAbsolute(relative) : true; + return relative ? !relative.startsWith('..') && !path.isAbsolute(relative) : true; }; -export const maybeAddRelativeLocalPrefix = (p: string) => (p[0] === "." ? p : `./${p}`); +export const maybeAddRelativeLocalPrefix = (p: string) => (p[0] === '.' ? p : `./${p}`); // endregion @@ -32,19 +32,22 @@ export const maybeAddRelativeLocalPrefix = (p: string) => (p[0] === "." ? p : `. */ export function joinPaths(...paths: (string | undefined)[]): string { // path.join / normalizePath cannot be used here, because they remove relative prefix - return normalizeSlashes((paths.filter(p => !!p) as string[]).join('/'))!; + return normalizeSlashes((paths.filter((p) => !!p) as string[]).join('/'))!; } /** * Normalize slashes in path */ -export function normalizeSlashes(p: T, opt?: { removeLeadingSlash?: boolean, removeTrailingSlash?: boolean }): T { +export function normalizeSlashes( + p: T, + opt?: { removeLeadingSlash?: boolean; removeTrailingSlash?: boolean } +): T { if (!p) return p; let res = p.replace(/\\+|\/+/g, '/'); if (opt?.removeLeadingSlash && res[0] === '/') res = res.slice(1); - if (opt?.removeTrailingSlash && res[res.length-1] === '/') res = res.slice(0, res.length - 1); + if (opt?.removeTrailingSlash && res[res.length - 1] === '/') res = res.slice(0, res.length - 1); return res as T; } @@ -59,7 +62,7 @@ export function extName(p: string) { } export function baseName(p: string, stripExtension: boolean | string = false) { - const ext = !stripExtension ? void 0 : (typeof stripExtension === 'string' ? stripExtension : extName(p)); + const ext = !stripExtension ? void 0 : typeof stripExtension === 'string' ? stripExtension : extName(p); return path.basename(p, ext); } diff --git a/test/prepare.js b/test/prepare.js index 6c9d53c0..3c488bb0 100755 --- a/test/prepare.js +++ b/test/prepare.js @@ -1,20 +1,20 @@ -const fs = require("fs"); -const path = require("path"); -const glob = require("glob"); -const tsPatch = require("ts-patch"); +const fs = require('fs'); +const path = require('path'); +const glob = require('glob'); +const tsPatch = require('ts-patch'); /* ****************************************************************************************************************** * * Config * ****************************************************************************************************************** */ const rootDir = __dirname; -const tsDirs = glob.sync('./node_modules/typescript-*/lib/typescript.js', { cwd: rootDir }) - .map(d => path.resolve(rootDir, d.replace(/\/lib\/typescript.js$/, ''))); +const tsDirs = glob + .sync('./node_modules/typescript-*/lib/typescript.js', { cwd: rootDir }) + .map((d) => path.resolve(rootDir, d.replace(/\/lib\/typescript.js$/, ''))); /* ****************************************************************************************************************** * * Patch TS Modules * ****************************************************************************************************************** */ for (const dir of tsDirs) - if (!fs.existsSync(path.join(dir, "lib-backup"))) - tsPatch.patch(["tsc.js", "typescript.js"], { basedir: dir }); + if (!fs.existsSync(path.join(dir, 'lib-backup'))) tsPatch.patch(['tsc.js', 'typescript.js'], { basedir: dir }); diff --git a/test/projects/extras/src/index.ts b/test/projects/extras/src/index.ts index c0bb14c0..27578225 100755 --- a/test/projects/extras/src/index.ts +++ b/test/projects/extras/src/index.ts @@ -1,4 +1,4 @@ -export * from "#identifier"; -import { b } from "#identifier"; +export * from '#identifier'; +import { b } from '#identifier'; console.log(b); diff --git a/test/projects/general/circular/a.ts b/test/projects/general/circular/a.ts index 15adcb34..1a13ab3f 100644 --- a/test/projects/general/circular/a.ts +++ b/test/projects/general/circular/a.ts @@ -1,8 +1,8 @@ -import { B } from "@circular/b"; +import { B } from '@circular/b'; export class A { constructor(public name: string) {} } export const b = new B(); -b.print(new A("This is a random name")); +b.print(new A('This is a random name')); diff --git a/test/projects/general/circular/b.ts b/test/projects/general/circular/b.ts index 841381bb..3379c86e 100644 --- a/test/projects/general/circular/b.ts +++ b/test/projects/general/circular/b.ts @@ -1,4 +1,4 @@ -import { A } from "@circular/a"; +import { A } from '@circular/a'; export class B { print(a: A) { diff --git a/test/projects/general/core/index.ts b/test/projects/general/core/index.ts index a771ac55..d59b3f9e 100644 --- a/test/projects/general/core/index.ts +++ b/test/projects/general/core/index.ts @@ -1,17 +1,17 @@ -export { sum } from "@utils/index"; -export { g } from "#utils/hello"; -export { sum as sum2 } from "#utils/sum"; -export { NoRuntimecodeHere } from "@utils/types-only"; -import { subs, NoRuntimecodeHere } from "@utils/index"; -import "@circular/b"; -import { A } from "@circular/a"; -import * as b from "circular/a"; -import * as c from "../circular/a"; -import { myNative } from "@utils/utils.native"; +export { sum } from '@utils/index'; +export { g } from '#utils/hello'; +export { sum as sum2 } from '#utils/sum'; +export { NoRuntimecodeHere } from '@utils/types-only'; +import { subs, NoRuntimecodeHere } from '@utils/index'; +import '@circular/b'; +import { A } from '@circular/a'; +import * as b from 'circular/a'; +import * as c from '../circular/a'; +import { myNative } from '@utils/utils.native'; // @ts-expect-error -import sum = require("@utils/sum"); +import sum = require('@utils/sum'); // @ts-expect-error -import * as path from "path"; +import * as path from 'path'; c.A; b.A; @@ -23,21 +23,21 @@ sum.sum(2, 3); const n: NoRuntimecodeHere = null as any; subs(2, 3); -const a = new A(""); +const a = new A(''); (async function () { - const Logger = await (await import("@dynamic/logger")).Logger; + const Logger = await (await import('@dynamic/logger')).Logger; const logger = new Logger(); - logger.log("hi"); + logger.log('hi'); })(); (async function () { - const Tester = (await import("@dynamic/tester")).Tester; + const Tester = (await import('@dynamic/tester')).Tester; - const testerConst = (await import("@dynamic/tester")).tester; + const testerConst = (await import('@dynamic/tester')).tester; const testerClass = new Tester(); testerClass.test(12); - testerConst.test("12"); + testerConst.test('12'); })(); diff --git a/test/projects/general/dynamic/logger.ts b/test/projects/general/dynamic/logger.ts index e0308785..9b4d9190 100644 --- a/test/projects/general/dynamic/logger.ts +++ b/test/projects/general/dynamic/logger.ts @@ -1,7 +1,7 @@ -type Tester = import("@dynamic/tester").Tester; +type Tester = import('@dynamic/tester').Tester; export class Logger { - level: string = "hi"; + level: string = 'hi'; tester: Tester; public log(x: string): void { diff --git a/test/projects/general/secondary/hello.ts b/test/projects/general/secondary/hello.ts index 01a52b07..f6ba14c8 100755 --- a/test/projects/general/secondary/hello.ts +++ b/test/projects/general/secondary/hello.ts @@ -1 +1 @@ -export const g = "hello"; +export const g = 'hello'; diff --git a/test/projects/general/utils/index.ts b/test/projects/general/utils/index.ts index 55190fa1..4cbd28d9 100644 --- a/test/projects/general/utils/index.ts +++ b/test/projects/general/utils/index.ts @@ -1,3 +1,3 @@ -export * from "@utils/sum"; -export * from "@utils/subs"; -export { NoRuntimecodeHere } from "@utils/types-only"; +export * from '@utils/sum'; +export * from '@utils/subs'; +export { NoRuntimecodeHere } from '@utils/types-only'; diff --git a/test/projects/general/utils/subs.ts b/test/projects/general/utils/subs.ts index 3646e51b..b50041ce 100644 --- a/test/projects/general/utils/subs.ts +++ b/test/projects/general/utils/subs.ts @@ -1,4 +1,4 @@ -import { sum } from "@utils/sum"; +import { sum } from '@utils/sum'; export function subs(a: number, b: number) { return sum(a, -b); diff --git a/test/projects/general/utils/types-only.ts b/test/projects/general/utils/types-only.ts index 59af7621..ebc36096 100644 --- a/test/projects/general/utils/types-only.ts +++ b/test/projects/general/utils/types-only.ts @@ -1,3 +1,3 @@ -export type NoRuntimecodeHere = "never gonna give you up!"; +export type NoRuntimecodeHere = 'never gonna give you up!'; -throw new Error("Not supposed to be!"); +throw new Error('Not supposed to be!'); diff --git a/test/projects/project-ref/b/index.ts b/test/projects/project-ref/b/index.ts index b6da5208..dddf1c4c 100755 --- a/test/projects/project-ref/b/index.ts +++ b/test/projects/project-ref/b/index.ts @@ -1,5 +1,5 @@ -_expect(_test_referenced, { path: "../a/index" }); -export { AReffedConst } from "#a/index"; +_expect(_test_referenced, { path: '../a/index' }); +export { AReffedConst } from '#a/index'; -_expect(_test_local, { path: "./local/index" }); -export { LocalConst } from "#b/local/index"; +_expect(_test_local, { path: './local/index' }); +export { LocalConst } from '#b/local/index'; diff --git a/test/projects/project-ref/b/tests.ts b/test/projects/project-ref/b/tests.ts index a07ee110..e30d0ab9 100755 --- a/test/projects/project-ref/b/tests.ts +++ b/test/projects/project-ref/b/tests.ts @@ -1,4 +1,3 @@ - /* ****************************************************************************************************************** * * Tests * ****************************************************************************************************************** */ diff --git a/test/projects/resolution/src/esm.ts b/test/projects/resolution/src/esm.ts index 32863060..b030874a 100755 --- a/test/projects/resolution/src/esm.ts +++ b/test/projects/resolution/src/esm.ts @@ -1,4 +1,4 @@ -import { _test_esm_reject_unmapped } from "../tests"; +import { _test_esm_reject_unmapped } from '../tests'; /* ****************************************************************************************************************** * * Index @@ -26,4 +26,3 @@ import { _test_esm_reject_unmapped } from "../tests"; _expect(_test_esm_reject_unmapped); import '@external/esm/dir/main.js'; - diff --git a/test/projects/resolution/src/indexes.ts b/test/projects/resolution/src/indexes.ts index 5b8cf2db..d3faa9bf 100755 --- a/test/projects/resolution/src/indexes.ts +++ b/test/projects/resolution/src/indexes.ts @@ -1,51 +1,50 @@ -import { _test_internal_package_index, _test_external_package_index, _test_local_index } from "../tests"; - +import { _test_internal_package_index, _test_external_package_index, _test_local_index } from '../tests'; /* ****************************************************************************************************************** * * Local * ****************************************************************************************************************** */ _expect(_test_local_index, _expect.index('./local')); -import '#root/local' +import '#root/local'; _expect(_test_local_index, _expect.index('./local')); -import "./local" +import './local'; /* ****************************************************************************************************************** * * Internal * ****************************************************************************************************************** */ _expect(_test_internal_package_index, _expect.index('../packages/internal/root-idx')); -import "../packages/internal/root-idx"; +import '../packages/internal/root-idx'; _expect(_test_internal_package_index, _expect.index('../packages/internal/root-idx')); -import "#internal/root-idx"; +import '#internal/root-idx'; _expect(_test_internal_package_index, _expect.index('../packages/internal/root-idx/sub-pkg', 'main')); -import "#internal/root-idx/sub-pkg"; +import '#internal/root-idx/sub-pkg'; _expect(_test_internal_package_index, _expect.index('../packages/internal/root-named-idx', 'main')); -import "#internal/root-named-idx"; +import '#internal/root-named-idx'; _expect(_test_internal_package_index, _expect.index('../packages/internal/subdir-idx', 'subdir/main')); -import "#internal/subdir-idx"; +import '#internal/subdir-idx'; // TS Does not resolve _expect(_test_internal_package_index); -import "#internal/esm"; +import '#internal/esm'; /* ****************************************************************************************************************** * * External * ****************************************************************************************************************** */ _expect(_test_external_package_index, _expect.index('@external/root-idx')); -import "@external/root-idx"; +import '@external/root-idx'; _expect(_test_external_package_index, _expect.index('@external/root-idx/sub-pkg', 'main')); -import "@external/root-idx/sub-pkg"; +import '@external/root-idx/sub-pkg'; _expect(_test_external_package_index, _expect.index('@external/root-named-idx', 'main')); -import "@external/root-named-idx"; +import '@external/root-named-idx'; _expect(_test_external_package_index, _expect.index('@external/subdir-idx', 'subdir/main')); -import "@external/subdir-idx"; +import '@external/subdir-idx'; diff --git a/test/projects/resolution/src/tricky.ts b/test/projects/resolution/src/tricky.ts index 8e8cc1d6..bc0fae2b 100755 --- a/test/projects/resolution/src/tricky.ts +++ b/test/projects/resolution/src/tricky.ts @@ -1,5 +1,4 @@ -import { _test_tricky } from "../tests"; - +import { _test_tricky } from '../tests'; // Path match to package in node_modules: // isExternalLibrary = true, package, submodule = index.d.ts @@ -30,4 +29,4 @@ import { _test_tricky } from "../tests"; // Failed to resolve // import '#internal/esm' -import 'pkg/external' +import 'pkg/external'; diff --git a/test/projects/resolution/tests.ts b/test/projects/resolution/tests.ts index 166fea8d..1f328425 100755 --- a/test/projects/resolution/tests.ts +++ b/test/projects/resolution/tests.ts @@ -4,12 +4,12 @@ export const _test_internal_package_index = _test({ label: `Internal packages resolve properly`, - group: "Package" + group: 'Package', }); export const _test_external_package_index = _test({ label: `External packages resolve properly`, - group: "Package" + group: 'Package', }); export const _test_local_index = _test(`Local index resolves properly`); @@ -24,7 +24,7 @@ export const _test_local_index = _test(`Local index resolves properly`); export const _test_esm_reject_unmapped = _test({ label: `Does not transform unmapped paths`, group: 'ESM', - if: () => false + if: () => false, }); // --- TODO ---- diff --git a/test/projects/root-dirs/generated/dir/gen-file.ts b/test/projects/root-dirs/generated/dir/gen-file.ts index b4335ac1..07d0ffd4 100755 --- a/test/projects/root-dirs/generated/dir/gen-file.ts +++ b/test/projects/root-dirs/generated/dir/gen-file.ts @@ -1,7 +1,7 @@ import { _test_no_root_dirs, _test_root_dirs } from '../../tests'; -_expect(_test_root_dirs, { path: "./src-file" }); -_expect(_test_no_root_dirs, { path: "../../src/dir/src-file" }); -import "#root/dir/src-file"; +_expect(_test_root_dirs, { path: './src-file' }); +_expect(_test_no_root_dirs, { path: '../../src/dir/src-file' }); +import '#root/dir/src-file'; export const b = 1; diff --git a/test/projects/root-dirs/src/dir/src-file.ts b/test/projects/root-dirs/src/dir/src-file.ts index 2145fc4a..dacca80f 100755 --- a/test/projects/root-dirs/src/dir/src-file.ts +++ b/test/projects/root-dirs/src/dir/src-file.ts @@ -1,7 +1,7 @@ import { _test_no_root_dirs, _test_root_dirs } from '../../tests'; -_expect(_test_root_dirs, { path: "./gen-file" }); -_expect(_test_no_root_dirs, { path: "../../generated/dir/gen-file" }); -import "#root/dir/gen-file"; +_expect(_test_root_dirs, { path: './gen-file' }); +_expect(_test_no_root_dirs, { path: '../../generated/dir/gen-file' }); +import '#root/dir/gen-file'; export const a = 2; diff --git a/test/projects/root-dirs/src/index.ts b/test/projects/root-dirs/src/index.ts index 12d5940c..7bf83263 100755 --- a/test/projects/root-dirs/src/index.ts +++ b/test/projects/root-dirs/src/index.ts @@ -1,9 +1,9 @@ import { _test_no_root_dirs, _test_root_dirs } from '../tests'; -_expect(_test_root_dirs, { path: "./dir/gen-file" }); -_expect(_test_no_root_dirs, { path: "../generated/dir/gen-file" }); -export { b } from "#root/dir/gen-file"; +_expect(_test_root_dirs, { path: './dir/gen-file' }); +_expect(_test_no_root_dirs, { path: '../generated/dir/gen-file' }); +export { b } from '#root/dir/gen-file'; -_expect(_test_root_dirs, { path: "./dir/src-file" }); -_expect(_test_no_root_dirs, { path: "./dir/src-file" }); -export { a } from "#root/dir/src-file"; +_expect(_test_root_dirs, { path: './dir/src-file' }); +_expect(_test_no_root_dirs, { path: './dir/src-file' }); +export { a } from '#root/dir/src-file'; diff --git a/test/projects/root-dirs/tests.ts b/test/projects/root-dirs/tests.ts index 6dbab9eb..a0400f53 100755 --- a/test/projects/root-dirs/tests.ts +++ b/test/projects/root-dirs/tests.ts @@ -4,10 +4,10 @@ export const _test_root_dirs = _test({ label: `Re-maps for rootDirs`, - if: ({ pluginOptions }) => pluginOptions.useRootDirs + if: ({ pluginOptions }) => pluginOptions.useRootDirs, }); export const _test_no_root_dirs = _test({ label: `Ignores rootDirs`, - if: ({ pluginOptions }) => !pluginOptions.useRootDirs + if: ({ pluginOptions }) => !pluginOptions.useRootDirs, }); diff --git a/test/projects/specific/src/index.ts b/test/projects/specific/src/index.ts index 97914ccc..5b41f99d 100755 --- a/test/projects/specific/src/index.ts +++ b/test/projects/specific/src/index.ts @@ -1,4 +1,9 @@ -import { _test_async_import_comments, _test_exclude, _test_explicit_extensions, _test_type_only_import } from "../tests"; +import { + _test_async_import_comments, + _test_exclude, + _test_explicit_extensions, + _test_type_only_import, +} from '../tests'; /* ********************************************************* * * TypeOnly @@ -6,23 +11,23 @@ import { _test_async_import_comments, _test_exclude, _test_explicit_extensions, _expect(_test_type_only_import, { path: './general', for: 'dts' }); _expect(_test_type_only_import, { elided: true, for: 'js' }); -import type { GeneralTypeA as ATypeOnly } from "./general"; +import type { GeneralTypeA as ATypeOnly } from './general'; export { ATypeOnly }; /* ********************************************************* * * Async Import Comments * ********************************************************* */ -_expect(_test_async_import_comments, { path: './general', extraCheck: (c) => /^import\(\/\* w/.test(c), for: 'js' }) -import(/* webpackChunkName: "Comment" */ "./general"); +_expect(_test_async_import_comments, { path: './general', extraCheck: (c) => /^import\(\/\* w/.test(c), for: 'js' }); +import(/* webpackChunkName: "Comment" */ './general'); -_expect(_test_async_import_comments, { path: './general', extraCheck: (c) => /^import\(\s*\/\/ c/.test(c), for: 'js' }) +_expect(_test_async_import_comments, { path: './general', extraCheck: (c) => /^import\(\s*\/\/ c/.test(c), for: 'js' }); import( -// comment 1 -/* + // comment 1 + /* comment 2 */ -"./general" + './general' ); /* ********************************************************* * @@ -30,17 +35,17 @@ comment 2 * ********************************************************* */ _expect(_test_exclude); -export { bb } from "#exclusion/ex"; +export { bb } from '#exclusion/ex'; _expect(_test_exclude); -export { dd } from "#root/excluded-file"; +export { dd } from '#root/excluded-file'; /* ********************************************************* * * Explicit Extensions * ********************************************************* */ -_expect(_test_explicit_extensions, { path: './data.json' }) -export { JsonValue } from "#root/data.json"; +_expect(_test_explicit_extensions, { path: './data.json' }); +export { JsonValue } from '#root/data.json'; -_expect(_test_explicit_extensions, { path: './general.js' }) -export { GeneralConstB } from "#root/general.js"; +_expect(_test_explicit_extensions, { path: './general.js' }); +export { GeneralConstB } from '#root/general.js'; diff --git a/test/projects/specific/src/module-augment.ts b/test/projects/specific/src/module-augment.ts index d74251e6..aa871198 100755 --- a/test/projects/specific/src/module-augment.ts +++ b/test/projects/specific/src/module-augment.ts @@ -1,15 +1,15 @@ -import { Expandable } from "#root/general"; -import { _test_module_augmentation } from "../tests"; +import { Expandable } from '#root/general'; +import { _test_module_augmentation } from '../tests'; _expect(_test_module_augmentation, { path: './general' }); -declare module "#root/general" { +declare module '#root/general' { interface Expandable { b: number; } } _expect(_test_module_augmentation); -declare module "./excluded-file" { +declare module './excluded-file' { type B = null; } diff --git a/test/projects/specific/src/tags.ts b/test/projects/specific/src/tags.ts index 96b1a406..952be76e 100755 --- a/test/projects/specific/src/tags.ts +++ b/test/projects/specific/src/tags.ts @@ -1,4 +1,4 @@ -import { _test_tag_explicit_transform, _test_tag_no_transform } from "../tests"; +import { _test_tag_explicit_transform, _test_tag_no_transform } from '../tests'; /* ****************************************************************************************************************** * * JSDoc @@ -8,7 +8,7 @@ _expect(_test_tag_no_transform, { path: '#root/index' }); /** * @no-transform-path */ -import * as skipTransform1 from "#root/index"; +import * as skipTransform1 from '#root/index'; _expect(_test_tag_no_transform, { path: '#root/index' }); /** @@ -16,7 +16,7 @@ _expect(_test_tag_no_transform, { path: '#root/index' }); * @no-transform-path * @multi-tag2 */ -import * as skipTransform2 from "#root/index"; +import * as skipTransform2 from '#root/index'; _expect(_test_tag_explicit_transform, { path: './dir/src-file' }); /** @@ -24,41 +24,41 @@ _expect(_test_tag_explicit_transform, { path: './dir/src-file' }); * @transform-path ./dir/src-file * @multi-tag2 */ -import * as explicitTransform1 from "./index"; +import * as explicitTransform1 from './index'; -_expect(_test_tag_explicit_transform, { path: "http://www.go.com/react.js" }); +_expect(_test_tag_explicit_transform, { path: 'http://www.go.com/react.js' }); /** * @multi-tag1 * @transform-path http://www.go.com/react.js * @multi-tag2 */ -import * as explicitTransform2 from "./index"; +import * as explicitTransform2 from './index'; /* ****************************************************************************************************************** * * JS Tag * ****************************************************************************************************************** */ -_expect(_test_tag_no_transform, { path: "#root/index" }); +_expect(_test_tag_no_transform, { path: '#root/index' }); // @no-transform-path -import * as skipTransform3 from "#root/index"; +import * as skipTransform3 from '#root/index'; -_expect(_test_tag_no_transform, { path: "#root/index" }); +_expect(_test_tag_no_transform, { path: '#root/index' }); // @multi-tag1 // @no-transform-path // @multi-tag2 -import * as skipTransform4 from "#root/index"; +import * as skipTransform4 from '#root/index'; -_expect(_test_tag_explicit_transform, { path: "./dir/src-file" }); +_expect(_test_tag_explicit_transform, { path: './dir/src-file' }); // @multi-tag1 // @transform-path ./dir/src-file // @multi-tag2 -import * as explicitTransform3 from "./index"; +import * as explicitTransform3 from './index'; -_expect(_test_tag_explicit_transform, { path: "http://www.go.com/react.js" }); +_expect(_test_tag_explicit_transform, { path: 'http://www.go.com/react.js' }); // @multi-tag1 // @transform-path http://www.go.com/react.js // @multi-tag2 -import * as explicitTransform4 from "./index"; +import * as explicitTransform4 from './index'; export { skipTransform1, diff --git a/test/projects/specific/src/type-elision/a.ts b/test/projects/specific/src/type-elision/a.ts index eb088979..b4ae7ec7 100755 --- a/test/projects/specific/src/type-elision/a.ts +++ b/test/projects/specific/src/type-elision/a.ts @@ -1,2 +1,2 @@ export type TypeA = string; -export const ConstB = "hello"; +export const ConstB = 'hello'; diff --git a/test/projects/specific/src/type-elision/index.ts b/test/projects/specific/src/type-elision/index.ts index 1846a77b..a44575ee 100755 --- a/test/projects/specific/src/type-elision/index.ts +++ b/test/projects/specific/src/type-elision/index.ts @@ -1,18 +1,17 @@ -import { _test_type_elision } from "../../tests"; +import { _test_type_elision } from '../../tests'; - -_expect(_test_type_elision, { specifiers: [ 'ConstB' ], for: 'js' }); -_expect(_test_type_elision, { specifiers: [ 'ConstB', 'TypeA' ], for: 'dts' }); -import { ConstB, TypeA } from "./a"; +_expect(_test_type_elision, { specifiers: ['ConstB'], for: 'js' }); +_expect(_test_type_elision, { specifiers: ['ConstB', 'TypeA'], for: 'dts' }); +import { ConstB, TypeA } from './a'; _expect(_test_type_elision, { elided: true, for: 'js' }); -_expect(_test_type_elision, { specifiers: [ 'TypeA2' ], for: 'dts' }); -import { TypeA as TypeA2 } from "./a"; +_expect(_test_type_elision, { specifiers: ['TypeA2'], for: 'dts' }); +import { TypeA as TypeA2 } from './a'; -_expect(_test_type_elision, { specifiers: [ 'ConstB' ], for: 'js' }); -_expect(_test_type_elision, { specifiers: [ 'ConstB', 'TypeA' ], for: 'dts' }); +_expect(_test_type_elision, { specifiers: ['ConstB'], for: 'js' }); +_expect(_test_type_elision, { specifiers: ['ConstB', 'TypeA'], for: 'dts' }); export { ConstB, TypeA }; _expect(_test_type_elision, { elided: true, for: 'js' }); -_expect(_test_type_elision, { specifiers: [ 'TypeA2' ], for: 'dts' }); +_expect(_test_type_elision, { specifiers: ['TypeA2'], for: 'dts' }); export { TypeA2 }; diff --git a/test/projects/specific/tests.ts b/test/projects/specific/tests.ts index e382abe4..6bd9d26a 100755 --- a/test/projects/specific/tests.ts +++ b/test/projects/specific/tests.ts @@ -4,17 +4,17 @@ export const _test_tag_no_transform = _test({ label: `(@no-transform-path) Doesn't transform path`, - group: "Tags", + group: 'Tags', }); export const _test_tag_explicit_transform = _test({ label: `(@transform-path) Transforms path with explicit value`, - group: "Tags", + group: 'Tags', }); export const _test_exclude = _test({ label: `(exclude) Doesn't transform for exclusion patterns`, - group: "Options", + group: 'Options', }); export const _test_type_only_import = _test({ @@ -24,7 +24,7 @@ export const _test_type_only_import = _test({ export const _test_module_augmentation = _test({ label: `Resolves module augmentation`, - for: "dts", + for: 'dts', }); export const _test_type_elision = _test(`Type elision works properly`); diff --git a/test/src/config.ts b/test/src/config.ts index 20639413..bae06f14 100755 --- a/test/src/config.ts +++ b/test/src/config.ts @@ -1,18 +1,18 @@ -import path from "path"; +import path from 'path'; /* ****************************************************************************************************************** */ // region: Config /* ****************************************************************************************************************** */ export const tsModules = [ - ["Latest", "typescript-latest"], - ["4.2.2", "typescript-42"], + ['Latest', 'typescript-latest'], + ['4.2.2', 'typescript-42'], ]; -export const modes = ["program", "manual", "ts-node"] as const; +export const modes = ['program', 'manual', 'ts-node'] as const; -export const projectsPath = path.join(__dirname, "../projects"); -export const rootPath = path.resolve(__dirname, "../../"); +export const projectsPath = path.join(__dirname, '../projects'); +export const rootPath = path.resolve(__dirname, '../../'); Error.stackTraceLimit = 120; diff --git a/test/src/index.ts b/test/src/index.ts index 49f0e731..f9bb6580 100755 --- a/test/src/index.ts +++ b/test/src/index.ts @@ -1,2 +1,2 @@ -export * as ut from "./ut"; -export * from './ts-helpers' +export * as ut from './ut'; +export * from './ts-helpers'; diff --git a/test/src/setup.ts b/test/src/setup.ts index 124ad840..a816a5fb 100755 --- a/test/src/setup.ts +++ b/test/src/setup.ts @@ -1,6 +1,6 @@ -import { modes, tsModules } from "./config"; -import chalk from "chalk"; -import { toResolve } from "./ut/matchers/to-resolve"; +import { modes, tsModules } from './config'; +import chalk from 'chalk'; +import { toResolve } from './ut/matchers/to-resolve'; /* ****************************************************************************************************************** */ // region: Types @@ -13,11 +13,11 @@ declare global { } } const envOptions: { - tsModules: typeof tsModules[number][] - buildModes: typeof modes[number][] - testTarget: 'src' | 'dist' - testGroups: string | undefined - } + tsModules: typeof tsModules[number][]; + buildModes: typeof modes[number][]; + testTarget: 'src' | 'dist'; + testGroups: string | undefined; + }; } // endregion @@ -30,20 +30,20 @@ declare global { let { TS_MODULES, BUILD_MODES, TEST_GROUPS, CI, TEST_TARGET, UT_DEBUG } = process.env; /* Get env config */ - const splitStr = (v: string | undefined) => v?.split(',').map(m => m.trim().toLowerCase()); + const splitStr = (v: string | undefined) => v?.split(',').map((m) => m.trim().toLowerCase()); const opt = { tsModules: splitStr(TS_MODULES), buildModes: splitStr(BUILD_MODES), testGroups: splitStr(TEST_GROUPS), - testTarget: TEST_TARGET === 'dist' ? 'dist' : 'src' + testTarget: TEST_TARGET === 'dist' ? 'dist' : 'src', }; (global).envOptions = { tsModules: !opt.tsModules || CI ? tsModules : tsModules.filter((m) => opt.tsModules!.includes(m[0].toLowerCase())), buildModes: !opt.buildModes || CI ? modes : modes.filter((m) => opt.buildModes!.includes(m.toLowerCase())), testGroups: CI ? void 0 : opt.testGroups, - testTarget: CI ? 'dist' : opt.testTarget - } + testTarget: CI ? 'dist' : opt.testTarget, + }; /* Add Matchers */ expect.extend({ toResolve }); @@ -52,9 +52,11 @@ declare global { if (UT_DEBUG) process.stdout.write( '\n' + - chalk.yellow(`Started UnderscoreTest Framework ${CI ? chalk.red(`(CI MODE)`) : ''}`) + '\n' + - chalk.grey(`Options: `) + - chalk.grey(JSON.stringify(envOptions, null, 2)) + '\n' + chalk.yellow(`Started UnderscoreTest Framework ${CI ? chalk.red(`(CI MODE)`) : ''}`) + + '\n' + + chalk.grey(`Options: `) + + chalk.grey(JSON.stringify(envOptions, null, 2)) + + '\n' ); })(); diff --git a/test/src/ts-helpers.ts b/test/src/ts-helpers.ts index dabb8e96..a97b1b5e 100755 --- a/test/src/ts-helpers.ts +++ b/test/src/ts-helpers.ts @@ -1,8 +1,8 @@ -import { default as tstpTransform, TransformerOptions } from "typescript-transform-paths"; -import fs from "fs"; -import type * as TS from "typescript"; -import type { CompilerOptions, ParsedCommandLine, Program, SourceFile } from "typescript"; -import * as tsNode from "ts-node"; +import { default as tstpTransform, TransformerOptions } from 'typescript-transform-paths'; +import fs from 'fs'; +import type * as TS from 'typescript'; +import type { CompilerOptions, ParsedCommandLine, Program, SourceFile } from 'typescript'; +import * as tsNode from 'ts-node'; /* ****************************************************************************************************************** */ // region: Types @@ -116,9 +116,12 @@ export function createTsSolutionBuilder( customTransformers?: TS.CustomTransformers ): TS.EmitResult => { customTransformers = { - before: [ ...(customTransformers?.before ?? []), ...(transformers.before ?? []) ], - after: [ ...(customTransformers?.after ?? []), ...(transformers.after ?? []) ], - afterDeclarations: [ ...(customTransformers?.afterDeclarations ?? []), ...(transformers.afterDeclarations ?? []) ], + before: [...(customTransformers?.before ?? []), ...(transformers.before ?? [])], + after: [...(customTransformers?.after ?? []), ...(transformers.after ?? [])], + afterDeclarations: [ + ...(customTransformers?.afterDeclarations ?? []), + ...(transformers.afterDeclarations ?? []), + ], }; return originalEmit(targetSourceFile, writeFile, cancellationToken, emitOnlyDtsFiles, customTransformers); @@ -137,9 +140,11 @@ export function createTsSolutionBuilder( host.readFile = (p: string, enc: any) => virtualFiles.get(p) ?? originalReadFile(p, enc); host.writeFile = (p: string, data: string) => virtualFiles.set(p, data); - return Object.assign(ts.createSolutionBuilder(host, [projectDir], { force: true }), { - restoreTs: () => { ts.createProgram = originalCreateProgram; } - }); + return Object.assign(ts.createSolutionBuilder(host, [projectDir], { force: true }), { + restoreTs: () => { + ts.createProgram = originalCreateProgram; + }, + }); } /** @@ -203,7 +208,7 @@ export function getTsNodeEmitResult( const res: EmittedFiles = {}; for (const fileName of pcl.fileNames.filter((f) => !/\.d\.ts$/.test(f))) res[fileName] = { - js: compiler.compile(fs.readFileSync(fileName, 'utf8'), fileName).replace(/\/\/# sourceMappingURL.+$/g, '') + js: compiler.compile(fs.readFileSync(fileName, 'utf8'), fileName).replace(/\/\/# sourceMappingURL.+$/g, ''), }; return res; diff --git a/test/src/ut-global/globals.d.ts b/test/src/ut-global/globals.d.ts index dfeb5276..4a333ce8 100755 --- a/test/src/ut-global/globals.d.ts +++ b/test/src/ut-global/globals.d.ts @@ -1,4 +1,3 @@ - /* ****************************************************************************************************************** */ // region: Project Functions /* ****************************************************************************************************************** */ @@ -6,8 +5,8 @@ declare function _test(label: TestConfig['label']): UnderscoreTest; declare function _test(cfg: TestConfig): UnderscoreTest; -declare function _expect(test: UnderscoreTest, path?: ExpectConfig['path']): void -declare function _expect(test: UnderscoreTest, cfg?: ExpectConfig): void +declare function _expect(test: UnderscoreTest, path?: ExpectConfig['path']): void; +declare function _expect(test: UnderscoreTest, cfg?: ExpectConfig): void; declare namespace _expect { /** @@ -27,58 +26,57 @@ declare namespace _expect { // endregion - /* ****************************************************************************************************************** */ // region: Project Function Types /* ****************************************************************************************************************** */ declare interface TestConfig { - label: string | ((opt: TestRunConfig) => string) + label: string | ((opt: TestRunConfig) => string); /** * This test will only process if predicate is true */ - if?: (c: TestRunConfig) => boolean + if?: (c: TestRunConfig) => boolean; /** * Assign a group name to the test */ - group?: string + group?: string; /** * Only run test for specific output type */ - for?: ForKind + for?: ForKind; } declare interface ExpectConfig { /** * Only apply expect if predicate is true */ - if?: (c: TestRunConfig) => boolean + if?: (c: TestRunConfig) => boolean; /** * Only apply expect to a certain type of output file * @default 'all' */ - for?: ForKind + for?: ForKind; /** * Specific Path * @default same as source */ - path?: string | undefined | ((c: TestRunConfig) => string) + path?: string | undefined | ((c: TestRunConfig) => string); /** * Specific Path if outputMode = 'esm' * Note: Not all tests use esm mode */ - esmPath?: string | undefined | ((c: TestRunConfig) => string) + esmPath?: string | undefined | ((c: TestRunConfig) => string); /** * If true, the entire node is expected to be elided */ - elided?: boolean + elided?: boolean; /** * Expected specifiers @@ -86,12 +84,12 @@ declare interface ExpectConfig { * _expect(_my_test, 'path', { specifiers: [ 'shown' ] }); * import { shown, elided } from 'path'; */ - specifiers?: string [] + specifiers?: string[]; /** * Additional check predicate (test fails if predicate returns false) */ - extraCheck?: (compiledStatement: string | undefined) => boolean + extraCheck?: (compiledStatement: string | undefined) => boolean; } // endregion @@ -104,14 +102,14 @@ declare type ForKind = 'dts' | 'js' | 'all'; declare const underscoreTestSym: unique symbol; declare interface UnderscoreTest { - [underscoreTestSym]: boolean + [underscoreTestSym]: boolean; } declare interface TestRunConfig { - pluginOptions?: Record - mode: 'program' | 'ts-node' | 'manual' - tsMajorVersion: number - tsMinorVersion: number + pluginOptions?: Record; + mode: 'program' | 'ts-node' | 'manual'; + tsMajorVersion: number; + tsMinorVersion: number; } // endregion diff --git a/test/src/ut/index.ts b/test/src/ut/index.ts index 923497a4..676cdfbc 100755 --- a/test/src/ut/index.ts +++ b/test/src/ut/index.ts @@ -1,3 +1,3 @@ -export { loadProject } from "./project"; -export { createConfigSpread } from "./utils/create-config-spread"; -export * from './types' +export { loadProject } from './project'; +export { createConfigSpread } from './utils/create-config-spread'; +export * from './types'; diff --git a/test/src/ut/matchers/to-resolve.ts b/test/src/ut/matchers/to-resolve.ts index fd3f74dc..70be9944 100755 --- a/test/src/ut/matchers/to-resolve.ts +++ b/test/src/ut/matchers/to-resolve.ts @@ -1,10 +1,9 @@ -import { ExpectDetail } from "../types"; -import chalk from "chalk"; -import path from "path"; -import { projectsPath } from "../../config"; -import { matcherHint } from "jest-matcher-utils"; -import { diff } from "jest-diff"; - +import { ExpectDetail } from '../types'; +import chalk from 'chalk'; +import path from 'path'; +import { projectsPath } from '../../config'; +import { matcherHint } from 'jest-matcher-utils'; +import { diff } from 'jest-diff'; /* ****************************************************************************************************************** * * toResolve() (Jest Matcher) @@ -18,7 +17,7 @@ export const toResolve: jest.CustomMatcher = function toResolve(detail: ExpectDe const pos = sourceFile.getLineAndCharacterOfPosition(targetNode.getStart(sourceFile)); let detailStr = `File: ${chalk.white(path.relative(projectsPath, detail.sourceFile.fileName))}\n` + - `Line: ${chalk.white(pos.line+1)}\n` + + `Line: ${chalk.white(pos.line + 1)}\n` + `Output: ${chalk.white(detail.compiledSourceFile.isDeclarationFile ? 'declarations' : 'js')}\n\n`; if (config.extraCheck && !config.extraCheck(actualOutput)) { @@ -31,7 +30,8 @@ export const toResolve: jest.CustomMatcher = function toResolve(detail: ExpectDe message = () => `${matcherHint(`.not.toResolve`)}\n` + detailStr; } else { message = () => - `${matcherHint(`.toResolve`)}\n` + detailStr + + `${matcherHint(`.toResolve`)}\n` + + detailStr + (failType === 'extraCheck' ? `Failed extraCheck: ${config.extraCheck!.toString()}` : diff(expectedOutput, actualOutput, { expand: this.expand }) + '\n'); @@ -41,7 +41,7 @@ export const toResolve: jest.CustomMatcher = function toResolve(detail: ExpectDe actual: actualOutput, expected: expectedOutput, message: message, - name: "toResolve", + name: 'toResolve', pass, }; }; diff --git a/test/src/ut/project/index.ts b/test/src/ut/project/index.ts index 8390f3e1..502dc445 100755 --- a/test/src/ut/project/index.ts +++ b/test/src/ut/project/index.ts @@ -1 +1 @@ -export * from './load-project' +export * from './load-project'; diff --git a/test/src/ut/project/load-project.ts b/test/src/ut/project/load-project.ts index bf4c54b4..4abcdcfb 100755 --- a/test/src/ut/project/load-project.ts +++ b/test/src/ut/project/load-project.ts @@ -1,13 +1,13 @@ -import type * as TS from "typescript"; -import { createTsProgram, createTsSolutionBuilder } from "../../ts-helpers"; -import path from "path"; -import { projectsPath } from "../../config"; -import { ProjectRunGroup, UnderscoreTestContext, UtProjectConfig } from "../types"; -import { TestMap } from "../test-map"; -import { getProjectWalker } from "./project-walker"; +import type * as TS from 'typescript'; +import { createTsProgram, createTsSolutionBuilder } from '../../ts-helpers'; +import path from 'path'; +import { projectsPath } from '../../config'; +import { ProjectRunGroup, UnderscoreTestContext, UtProjectConfig } from '../types'; +import { TestMap } from '../test-map'; +import { getProjectWalker } from './project-walker'; import type { TransformerOptions } from 'tstp/src'; -import { getTransformerConfig } from "tstp/src/transform/transformer"; -import { default as tstpTransform } from "typescript-transform-paths"; +import { getTransformerConfig } from 'tstp/src/transform/transformer'; +import { default as tstpTransform } from 'typescript-transform-paths'; /* ****************************************************************************************************************** */ // region: Helpers @@ -17,7 +17,12 @@ import { default as tstpTransform } from "typescript-transform-paths"; * Note: Does not currently support pluginOptions from runConfig */ function emitWithSolutionBuilder(context: UnderscoreTestContext) { - const { ts, projectDir, runConfig: { pluginOptions }, projectConfig: { builderTransformerPredicate } } = context; + const { + ts, + projectDir, + runConfig: { pluginOptions }, + projectConfig: { builderTransformerPredicate }, + } = context; const builder = createTsSolutionBuilder(ts, projectDir, (program) => { if (builderTransformerPredicate && !builderTransformerPredicate(program)) return {}; @@ -25,10 +30,10 @@ function emitWithSolutionBuilder(context: UnderscoreTestContext) { const tstpTransformer = tstpTransform(program, pluginOptions, { ts }); const utWalker = getProjectWalker(context, program); return { - before: [ tstpTransformer ], - after: [ utWalker ], - afterDeclarations: [ tstpTransformer, utWalker ] as TS.TransformerFactory[] - } + before: [tstpTransformer], + after: [utWalker], + afterDeclarations: [tstpTransformer, utWalker] as TS.TransformerFactory[], + }; }); builder.build(); @@ -39,9 +44,9 @@ function emitWithProgram(context: UnderscoreTestContext) { const { projectDir, ts } = context; const program = createTsProgram({ - tsConfigFile: path.join(projectDir, "tsconfig.json"), + tsConfigFile: path.join(projectDir, 'tsconfig.json'), tsInstance: ts, - pluginOptions: context.runConfig.pluginOptions + pluginOptions: context.runConfig.pluginOptions, }); const t = getProjectWalker(context, program); @@ -50,7 +55,9 @@ function emitWithProgram(context: UnderscoreTestContext) { } function emit(context: UnderscoreTestContext) { - const { projectConfig: { programKind } } = context; + const { + projectConfig: { programKind }, + } = context; return programKind === 'solutionBuilder' ? emitWithSolutionBuilder(context) : emitWithProgram(context); } @@ -72,8 +79,8 @@ function createContext( transformerConfig: getTransformerConfig(runConfig.pluginOptions), walkLog: { js: false, - declarations: false - } + declarations: false, + }, }; context.tests = new TestMap(context); @@ -99,7 +106,7 @@ export function loadProject(projectConfig: T) { let res: ProjectRunGroup[] = []; for (const tsModule of tsModules) { - for (const config of [ configs ].flat()) { + for (const config of [configs].flat()) { const runConfig = createRunConfig(tsModule, config); const testMap = loadTests(tsModule, runConfig); const runLabel = `[TS: ${tsModule[0]}` + (config ? ` - ` + getConfigLabel(config) : '') + ']'; @@ -109,8 +116,7 @@ export function loadProject(projectConfig: T) { run.groups = []; for (const groupName of testMap.getGroups()) run.groups.push({ groupLabel: `[${groupName}]`, tests: testMap.getTestsForGroup(groupName) }); - } - else run.tests = testMap.getTests(); + } else run.tests = testMap.getTests(); res.push(run); } @@ -119,7 +125,9 @@ export function loadProject(projectConfig: T) { return res; function getConfigLabel(config: Record) { - return Object.entries(config).map(([k, v]) => `${k}: ${v?.toString()}`).join(', '); + return Object.entries(config) + .map(([k, v]) => `${k}: ${v?.toString()}`) + .join(', '); } function loadTests(tsModule: typeof tsModules[number], runConfig: TestRunConfig) { @@ -135,15 +143,15 @@ export function loadProject(projectConfig: T) { function createRunConfig(tsModule: typeof tsModules[number], config?: TransformerOptions): TestRunConfig { const ts = getTsInstance(tsModule); - const [ majorVer, minorVer ] = ts.versionMajorMinor.split('.'); + const [majorVer, minorVer] = ts.versionMajorMinor.split('.'); return { mode: 'program', tsMajorVersion: +majorVer, tsMinorVersion: +minorVer, pluginOptions: { ...projectConfig.pluginOptions, - ...config - } + ...config, + }, }; } diff --git a/test/src/ut/project/project-walker.ts b/test/src/ut/project/project-walker.ts index 1f30f6f9..7254eca3 100755 --- a/test/src/ut/project/project-walker.ts +++ b/test/src/ut/project/project-walker.ts @@ -1,24 +1,27 @@ -import { TestDetail, UnderscoreTestContext } from "../types"; -import type { Identifier, Node, Program, SourceFile, TransformationContext, TransformerFactory } from "typescript"; -import type TS from "typescript"; -import { expectCallName, testCallName } from "../../config"; +import { TestDetail, UnderscoreTestContext } from '../types'; +import type { Identifier, Node, Program, SourceFile, TransformationContext, TransformerFactory } from 'typescript'; +import type TS from 'typescript'; +import { expectCallName, testCallName } from '../../config'; import { - getFirstOriginal, getString, getStringOrFunctionOrObjectLiteral, isAsyncImport, isRequire, -} from "../utils/node-helpers"; -import { createHarmonyFactory, copyNodeComments } from "tstp/src/ts"; -import { assert } from "console"; - + getFirstOriginal, + getString, + getStringOrFunctionOrObjectLiteral, + isAsyncImport, + isRequire, +} from '../utils/node-helpers'; +import { createHarmonyFactory, copyNodeComments } from 'tstp/src/ts'; +import { assert } from 'console'; /* ****************************************************************************************************************** */ // region: Types /* ****************************************************************************************************************** */ export interface VisitorContext extends UnderscoreTestContext { - checker: TS.TypeChecker - factory: TS.NodeFactory - sourceFile: SourceFile - compiledSourceFile: SourceFile - isDeclarations: boolean + checker: TS.TypeChecker; + factory: TS.NodeFactory; + sourceFile: SourceFile; + compiledSourceFile: SourceFile; + isDeclarations: boolean; } // endregion @@ -54,7 +57,7 @@ function getExpectTargetNode(ctx: VisitorContext, expectIndex: number) { throw new Error( `Unexpected target node type! _expect() must follow statement with valid transform target — ` + - expectNode.getText() + expectNode.getText() ); } } @@ -97,7 +100,8 @@ function getExpectedOutput( factory.createImportDeclaration( node.decorators, node.modifiers, - node.importClause && factory.createImportClause(node.importClause.isTypeOnly, node.importClause.name, namedBindings), + node.importClause && + factory.createImportClause(node.importClause.isTypeOnly, node.importClause.name, namedBindings), moduleSpecifier || node.moduleSpecifier ) ); @@ -115,19 +119,24 @@ function getExpectedOutput( ); } else if (ts.isExternalModuleReference(node)) { return print(moduleSpecifier ? factory.createExternalModuleReference(moduleSpecifier) : node); - } - else if (ts.isImportTypeNode(node)) { - const argument = moduleSpecifier ? factory.createLiteralTypeNode(moduleSpecifier as TS.LiteralExpression) : node.argument; + } else if (ts.isImportTypeNode(node)) { + const argument = moduleSpecifier + ? factory.createLiteralTypeNode(moduleSpecifier as TS.LiteralExpression) + : node.argument; return print(factory.createImportTypeNode(argument, node.qualifier, node.typeArguments, node.isTypeOf)); } else if (ts.isModuleDeclaration(node)) return print( - factory.createModuleDeclaration(node.decorators, node.modifiers, moduleSpecifier as TS.ModuleName || node.name, node.body, node.flags) + factory.createModuleDeclaration( + node.decorators, + node.modifiers, + (moduleSpecifier as TS.ModuleName) || node.name, + node.body, + node.flags + ) ); else { const res = print(node); - return expectedPath - ? res.replace(/((?:^|\s*)(?:require|import)\(['"])(.+?)(['"]\))/g, `$1${expectedPath}$3`) - : res; + return expectedPath ? res.replace(/((?:^|\s*)(?:require|import)\(['"])(.+?)(['"]\))/g, `$1${expectedPath}$3`) : res; } function print(n: Node) { @@ -136,20 +145,18 @@ function getExpectedOutput( } } -function getExpectMethodResult( - ctx: VisitorContext, - rootNode: TS.ExpressionStatement, - node: TS.CallExpression -) { +function getExpectMethodResult(ctx: VisitorContext, rootNode: TS.ExpressionStatement, node: TS.CallExpression) { const { ts, transformerConfig: cfg, compiledSourceFile, sourceFile } = ctx; if ( - ts.isPropertyAccessExpression(node.expression) && ts.isIdentifier(node.expression.expression) && - node.expression.expression.text === expectCallName && ts.isIdentifier(node.expression.name) + ts.isPropertyAccessExpression(node.expression) && + ts.isIdentifier(node.expression.expression) && + node.expression.expression.text === expectCallName && + ts.isIdentifier(node.expression.name) ) { const fnName = node.expression.name.text; if (fnName === 'index' || fnName === 'path') { - const getExt = () => compiledSourceFile.isDeclarationFile ? '.d.ts' : '.js'; - const args = node.arguments.map(n => getString(ctx, n, sourceFile)); + const getExt = () => (compiledSourceFile.isDeclarationFile ? '.d.ts' : '.js'); + const args = node.arguments.map((n) => getString(ctx, n, sourceFile)); let res: string = args[0]; if (fnName === 'index' && cfg.outputIndexes === 'always') @@ -169,16 +176,15 @@ function checkForKind(forKind: ForKind | undefined, sourceFile: SourceFile) { case undefined: return true; case 'dts': - return sourceFile.isDeclarationFile + return sourceFile.isDeclarationFile; case 'js': - return !sourceFile.isDeclarationFile + return !sourceFile.isDeclarationFile; } } function findStatementByOriginal(originalNode: Node, sourceFile: SourceFile) { for (const s of sourceFile.statements) - for (let n: Node | undefined = s; n; n = n.original) - if (n === originalNode) return s; + for (let n: Node | undefined = s; n; n = n.original) if (n === originalNode) return s; } // endregion @@ -219,20 +225,28 @@ function checkExpect(context: VisitorContext, node: Node, statementIndex: number if (!test.enabled) return; /* Get Config */ - const pathOrConfig = - !pathOrConfigOrCallNode ? void 0 : - ts.isCallExpression(pathOrConfigOrCallNode) ? getExpectMethodResult(context, node, pathOrConfigOrCallNode) : - getStringOrFunctionOrObjectLiteral(context, pathOrConfigOrCallNode, sourceFile)!; - - const config: ExpectConfig = - !pathOrConfigOrCallNode ? { path: undefined } : - (typeof pathOrConfig === 'string' || typeof pathOrConfigOrCallNode === 'function') - ? { path: pathOrConfig } as ExpectConfig - : pathOrConfig as ExpectConfig; - - const expectedPath = typeof config.path === 'string' ? config.path : - typeof config.path === 'function' ? config.path(runConfig) : - void 0; + const pathOrConfig = !pathOrConfigOrCallNode + ? void 0 + : ts.isCallExpression(pathOrConfigOrCallNode) + ? getExpectMethodResult(context, node, pathOrConfigOrCallNode) + : getStringOrFunctionOrObjectLiteral( + context, + pathOrConfigOrCallNode, + sourceFile + )!; + + const config: ExpectConfig = !pathOrConfigOrCallNode + ? { path: undefined } + : typeof pathOrConfig === 'string' || typeof pathOrConfigOrCallNode === 'function' + ? ({ path: pathOrConfig } as ExpectConfig) + : (pathOrConfig as ExpectConfig); + + const expectedPath = + typeof config.path === 'string' + ? config.path + : typeof config.path === 'function' + ? config.path(runConfig) + : void 0; /* Check against expect config if & for */ if (config.if && !config.if(runConfig)) return; @@ -242,13 +256,14 @@ function checkExpect(context: VisitorContext, node: Node, statementIndex: number const { targetNode, compiledTargetNode } = getExpectTargetNode(context, statementIndex); if (!config.elided && !compiledTargetNode) throw new Error( - `No target found for _expect() in compiled code! Did you mean to set elided: true? — ` + - targetNode.getText() + `No target found for _expect() in compiled code! Did you mean to set elided: true? — ` + targetNode.getText() ); /* Create output comparisons */ let expectedOutput = config.elided ? void 0 : getExpectedOutput(context, factory, targetNode, expectedPath, config); - let actualOutput = compiledTargetNode ? printer.printNode(ts.EmitHint.Unspecified, compiledTargetNode, compiledSourceFile) : void 0; + let actualOutput = compiledTargetNode + ? printer.printNode(ts.EmitHint.Unspecified, compiledTargetNode, compiledSourceFile) + : void 0; if (expectedOutput) expectedOutput = standardizeQuotes(expectedOutput); if (actualOutput) actualOutput = standardizeQuotes(actualOutput); @@ -273,11 +288,7 @@ function checkExpect(context: VisitorContext, node: Node, statementIndex: number /** * Handle _test() — ie. const test_name = _test(...) */ -function checkTest( - context: VisitorContext, - node: Node, - expectValidTest: boolean = false -): TestDetail | undefined { +function checkTest(context: VisitorContext, node: Node, expectValidTest: boolean = false): TestDetail | undefined { const { ts, tests, runConfig, sourceFile, compiledSourceFile } = context; if (ts.isVariableStatement(node) && node.declarationList.declarations.length === 1) { @@ -285,8 +296,12 @@ function checkTest( if (declarationNode.initializer && ts.isIdentifier(declarationNode.name)) { const init = declarationNode.initializer; if (ts.isCallExpression(init) && ts.isIdentifier(init.expression) && init.expression.text === testCallName) { - const arg0 = getStringOrFunctionOrObjectLiteral(context, init.arguments[0], sourceFile); - const config = (typeof arg0 === 'string' || typeof arg0 === 'function') ? { label: arg0 } as TestConfig : arg0; + const arg0 = getStringOrFunctionOrObjectLiteral( + context, + init.arguments[0], + sourceFile + ); + const config = typeof arg0 === 'string' || typeof arg0 === 'function' ? ({ label: arg0 } as TestConfig) : arg0; const label = typeof config.label === 'string' ? config.label : config.label(runConfig); const testName = declarationNode.name.text; @@ -315,29 +330,30 @@ export function getProjectWalker(context: UnderscoreTestContext, program: Progra const { ts } = context; const checker = program.getTypeChecker(); - const transformer: TransformerFactory = (tCtx: TransformationContext) => (compiledSourceFile: SourceFile) => { - const factory = createHarmonyFactory(ts, tCtx.factory); - const sourceFile = getFirstOriginal(compiledSourceFile); - const visitorContext: VisitorContext = { - ...context, - checker, - factory, - sourceFile, - compiledSourceFile, - isDeclarations: compiledSourceFile.isDeclarationFile + const transformer: TransformerFactory = + (tCtx: TransformationContext) => (compiledSourceFile: SourceFile) => { + const factory = createHarmonyFactory(ts, tCtx.factory); + const sourceFile = getFirstOriginal(compiledSourceFile); + const visitorContext: VisitorContext = { + ...context, + checker, + factory, + sourceFile, + compiledSourceFile, + isDeclarations: compiledSourceFile.isDeclarationFile, + }; + + context.walkLog.declarations ||= compiledSourceFile.isDeclarationFile; + context.walkLog.js ||= !compiledSourceFile.isDeclarationFile; + + sourceFile.statements.forEach((s, idx) => { + checkTest(visitorContext, s); + checkExpect(visitorContext, s, idx); + }); + + return compiledSourceFile; }; - context.walkLog.declarations ||= compiledSourceFile.isDeclarationFile; - context.walkLog.js ||= !compiledSourceFile.isDeclarationFile; - - sourceFile.statements.forEach((s, idx) => { - checkTest(visitorContext, s); - checkExpect(visitorContext, s, idx); - }); - - return compiledSourceFile; - }; - return transformer; } diff --git a/test/src/ut/test-map.ts b/test/src/ut/test-map.ts index 12833f28..b1c9ecdc 100755 --- a/test/src/ut/test-map.ts +++ b/test/src/ut/test-map.ts @@ -1,4 +1,4 @@ -import { TestDetail, UnderscoreTestContext } from "./types"; +import { TestDetail, UnderscoreTestContext } from './types'; /* ****************************************************************************************************************** * * Locals @@ -11,10 +11,7 @@ const defaultNonGroupedTag = 'General'; * ****************************************************************************************************************** */ export class TestMap extends Map { - constructor( - private testContext: UnderscoreTestContext, - private nonGroupedTag: string = defaultNonGroupedTag - ) { + constructor(private testContext: UnderscoreTestContext, private nonGroupedTag: string = defaultNonGroupedTag) { super(); } @@ -31,11 +28,10 @@ export class TestMap extends Map { } private getTestsWorker(groupName?: string) { - const res = Array.from(this.values()) - .map((detail) => [ - typeof detail.label === "string" ? detail.label : detail.label(this.testContext.runConfig), - detail, - ]); + const res = Array.from(this.values()).map( + (detail) => + [typeof detail.label === 'string' ? detail.label : detail.label(this.testContext.runConfig), detail] + ); return !groupName ? res @@ -43,12 +39,11 @@ export class TestMap extends Map { } getGroups(): (string | undefined)[] { - let res = Array.from(new Set([ ...this.values() ].map(t => t.config?.group || this.nonGroupedTag))) - if (envOptions.testGroups) res = res.filter(g => envOptions.testGroups!.includes(g.toLowerCase())); + let res = Array.from(new Set([...this.values()].map((t) => t.config?.group || this.nonGroupedTag))); + if (envOptions.testGroups) res = res.filter((g) => envOptions.testGroups!.includes(g.toLowerCase())); return res; } - /* ********************************************************* * * Internal * ********************************************************* */ @@ -62,15 +57,14 @@ export class TestMap extends Map { for (const [key, test] of this.entries()) { if (!test.enabled) this.delete(key); else if (test.expects.length < 1) - throw new Error( - `No expects found for '${test.testName}' in ${test.sourceFile.fileName} in TS: ${tsLabel}` - ); + throw new Error(`No expects found for '${test.testName}' in ${test.sourceFile.fileName} in TS: ${tsLabel}`); } - if (!this.size) throw new Error( - `No tests enabled for current configuration in TS: ${tsLabel}! \n` + - JSON.stringify(this.testContext.projectConfig, null, 2) - ); + if (!this.size) + throw new Error( + `No tests enabled for current configuration in TS: ${tsLabel}! \n` + + JSON.stringify(this.testContext.projectConfig, null, 2) + ); return this; } diff --git a/test/src/ut/types.ts b/test/src/ut/types.ts index 69ebbc4e..86bec6c6 100755 --- a/test/src/ut/types.ts +++ b/test/src/ut/types.ts @@ -1,63 +1,62 @@ -import TS, { Node, SourceFile } from "typescript"; -import { tsModules } from "../config"; -import { TransformerConfig, TransformerOptions } from "tstp/src"; -import { TestMap } from "./test-map"; - +import TS, { Node, SourceFile } from 'typescript'; +import { tsModules } from '../config'; +import { TransformerConfig, TransformerOptions } from 'tstp/src'; +import { TestMap } from './test-map'; /* ****************************************************************************************************************** * * Types * ****************************************************************************************************************** */ export interface ExpectDetail { - sourceFile: SourceFile - compiledSourceFile: SourceFile - testName: string - config: ExpectConfig - targetNode: Node - compiledTargetNode: Node | undefined - expectedOutput: string | undefined - actualOutput: string | undefined + sourceFile: SourceFile; + compiledSourceFile: SourceFile; + testName: string; + config: ExpectConfig; + targetNode: Node; + compiledTargetNode: Node | undefined; + expectedOutput: string | undefined; + actualOutput: string | undefined; } export interface TestDetail { - sourceFile: SourceFile - expects: ExpectDetail[] - config: TestConfig - testName: string - label: string | ((opt: any) => string) - enabled: boolean + sourceFile: SourceFile; + expects: ExpectDetail[]; + config: TestConfig; + testName: string; + label: string | ((opt: any) => string); + enabled: boolean; } export interface UtProjectConfig { projectName: string; - programKind?: 'program' | 'solutionBuilder' + programKind?: 'program' | 'solutionBuilder'; /** * Restrict to specific TS version (initializes array with those specified but can be narrowed by env var) */ - allowedTs?: typeof tsModules[number][0][] - pluginOptions?: TransformerOptions | ((ctx: TestRunConfig) => TransformerOptions) - useGroups?: boolean - configs?: TransformerOptions[] - builderTransformerPredicate?: (program: TS.Program) => boolean + allowedTs?: typeof tsModules[number][0][]; + pluginOptions?: TransformerOptions | ((ctx: TestRunConfig) => TransformerOptions); + useGroups?: boolean; + configs?: TransformerOptions[]; + builderTransformerPredicate?: (program: TS.Program) => boolean; } export interface UnderscoreTestContext { - projectConfig: UtProjectConfig - ts: typeof TS - printer: TS.Printer - tests: TestMap - projectDir: string - tsModule: typeof tsModules[number] - runConfig: TestRunConfig - transformerConfig: TransformerConfig + projectConfig: UtProjectConfig; + ts: typeof TS; + printer: TS.Printer; + tests: TestMap; + projectDir: string; + tsModule: typeof tsModules[number]; + runConfig: TestRunConfig; + transformerConfig: TransformerConfig; walkLog: { - declarations: boolean - js: boolean - } + declarations: boolean; + js: boolean; + }; } export interface ProjectRunGroup { runLabel: string; - tests: (readonly [ string, TestDetail])[], - groups: { groupLabel: string, tests: (readonly [ string, TestDetail ])[] }[] + tests: (readonly [string, TestDetail])[]; + groups: { groupLabel: string; tests: (readonly [string, TestDetail])[] }[]; } diff --git a/test/src/ut/utils/create-config-spread.ts b/test/src/ut/utils/create-config-spread.ts index 2806a872..c7834f81 100755 --- a/test/src/ut/utils/create-config-spread.ts +++ b/test/src/ut/utils/create-config-spread.ts @@ -23,9 +23,9 @@ export function createConfigSpread(config: SpreadableConfig) { const configs = v.map((val) => ({ ...staticProps, [k]: val })); if (!res.length) res.push(...configs); else { - for (const existing of [ ...res ]) { + for (const existing of [...res]) { res.shift(); - res.push(...configs.map(c => ({ ...existing, ...c }))); + res.push(...configs.map((c) => ({ ...existing, ...c }))); } } } diff --git a/test/src/ut/utils/node-helpers.ts b/test/src/ut/utils/node-helpers.ts index e007d1aa..78eebed9 100755 --- a/test/src/ut/utils/node-helpers.ts +++ b/test/src/ut/utils/node-helpers.ts @@ -1,5 +1,5 @@ -import ts, { Node, SourceFile } from "typescript"; -import { UnderscoreTestContext } from "../types"; +import ts, { Node, SourceFile } from 'typescript'; +import { UnderscoreTestContext } from '../types'; /* ****************************************************************************************************************** * * Node Helpers @@ -12,55 +12,68 @@ export const isAsyncImport = (tsInstance: typeof ts, node: ts.Node): node is ts. node.arguments.length === 1; export const isRequire = (tsInstance: typeof ts, node: ts.Node): node is ts.CallExpression => - tsInstance.isCallExpression(node) && node.expression && + tsInstance.isCallExpression(node) && + node.expression && tsInstance.isIdentifier(node.expression) && - node.expression.text === "require" && + node.expression.text === 'require' && tsInstance.isStringLiteral(node.arguments[0]) && node.arguments.length === 1; export function getFirstOriginal(node: T): T { - for (let n: any = node; n; n = n.original) - if (!n.original) return n; + for (let n: any = node; n; n = n.original) if (!n.original) return n; return node; } export function getString({ ts, printer }: UnderscoreTestContext, node: Node, sourceFile: SourceFile): string { const res: string | undefined = - ts.isStringLiteral(node) || ts.isNoSubstitutionTemplateLiteral(node) ? node.text : - void 0; + ts.isStringLiteral(node) || ts.isNoSubstitutionTemplateLiteral(node) ? node.text : void 0; if (!res) throw new Error(`Expression is not a string! Expression: ${getFirstOriginal(node).getText(sourceFile)}`); return res; } -export function getStringOrFunctionOrObjectLiteral(ctx: UnderscoreTestContext, node: Node, sourceFile: SourceFile): T { +export function getStringOrFunctionOrObjectLiteral( + ctx: UnderscoreTestContext, + node: Node, + sourceFile: SourceFile +): T { try { return getStringOrFunction(ctx, node, sourceFile) as T; } catch { try { return getObjectLiteral(ctx, node, sourceFile) as T; } catch { - throw new Error(`Expression is not a valid string, function, or object literal. Expression ${getFirstOriginal(node).getText(sourceFile)}`); + throw new Error( + `Expression is not a valid string, function, or object literal. Expression ${getFirstOriginal(node).getText( + sourceFile + )}` + ); } } } export function getStringOrFunction({ ts, printer }: UnderscoreTestContext, node: Node, sourceFile: SourceFile): T { const res: string | Function | undefined = - ts.isStringLiteral(node) || ts.isNoSubstitutionTemplateLiteral(node) ? node.text : - ts.isArrowFunction(node) || ts.isFunctionExpression(node) ? eval(`(${printer.printNode(ts.EmitHint.Expression, node, sourceFile)})`) as Function : - void 0; + ts.isStringLiteral(node) || ts.isNoSubstitutionTemplateLiteral(node) + ? node.text + : ts.isArrowFunction(node) || ts.isFunctionExpression(node) + ? (eval(`(${printer.printNode(ts.EmitHint.Expression, node, sourceFile)})`) as Function) + : void 0; - if (!res) throw new Error(`Expression is not a string or function! Expression: ${getFirstOriginal(node).getText(sourceFile)}`); + if (!res) + throw new Error( + `Expression is not a string or function! Expression: ${getFirstOriginal(node).getText(sourceFile)}` + ); return res as unknown as T; } export function getObjectLiteral({ ts, printer }: UnderscoreTestContext, node: Node, sourceFile: SourceFile): T { const res: object | undefined = ts.isObjectLiteralExpression(node) - ? eval(`(${printer.printNode(ts.EmitHint.Expression, node, sourceFile)})`) - : void 0; + ? eval(`(${printer.printNode(ts.EmitHint.Expression, node, sourceFile)})`) + : void 0; - if (!res) throw new Error(`Expression is not an object literal! Expression: ${getFirstOriginal(node).getText(sourceFile)}`); + if (!res) + throw new Error(`Expression is not an object literal! Expression: ${getFirstOriginal(node).getText(sourceFile)}`); return res as unknown as T; } diff --git a/test/tests/compatibility/node-register.test.ts b/test/tests/compatibility/node-register.test.ts index 0904a7b5..59dd17b5 100755 --- a/test/tests/compatibility/node-register.test.ts +++ b/test/tests/compatibility/node-register.test.ts @@ -1,7 +1,7 @@ -import { nodeRegister } from "typescript-transform-paths"; -import * as tsNode from "ts-node"; -import { REGISTER_INSTANCE } from "ts-node"; -import { CustomTransformers, PluginImport, Program } from "typescript"; +import { nodeRegister } from 'typescript-transform-paths'; +import * as tsNode from 'ts-node'; +import { REGISTER_INSTANCE } from 'ts-node'; +import { CustomTransformers, PluginImport, Program } from 'typescript'; /* ****************************************************************************************************************** * * Config @@ -10,14 +10,14 @@ import { CustomTransformers, PluginImport, Program } from "typescript"; const transformerModule = require(`tstp/${envOptions.testTarget}/transform/transformer`); const pluginOptions = { opt1: true, opt2: 3 }; -const otherTransformer = { transform: "fake-transformer@23904" }; +const otherTransformer = { transform: 'fake-transformer@23904' }; const configs = { - "Implicit before": {}, - "Explicit before": { before: true }, + 'Implicit before': {}, + 'Explicit before': { before: true }, afterDeclarations: { afterDeclarations: true }, - "Implicit before + afterDeclarations": [{}, { afterDeclarations: true }], - "Explicit before + afterDeclarations": [{ before: true }, { afterDeclarations: true }], + 'Implicit before + afterDeclarations': [{}, { afterDeclarations: true }], + 'Explicit before + afterDeclarations': [{ before: true }, { afterDeclarations: true }], } as const; const configMap = Object.entries(configs).map(([label, cfg]) => { let hasBefore: boolean = false; @@ -27,14 +27,14 @@ const configMap = Object.entries(configs).map(([label, cfg]) => { .map((c) => { if ((c).before || !(c).afterDeclarations) hasBefore = true; if ((c).afterDeclarations) hasAfterDeclarations = true; - return { transform: "typescript-transform-paths", ...c, ...pluginOptions } as any; + return { transform: 'typescript-transform-paths', ...c, ...pluginOptions } as any; }) .concat([otherTransformer]); return { label, transformers, hasBefore, hasAfterDeclarations }; }); -const instanceSymbol: typeof REGISTER_INSTANCE = tsNode["REGISTER_INSTANCE"]; +const instanceSymbol: typeof REGISTER_INSTANCE = tsNode['REGISTER_INSTANCE']; /* ****************************************************************************************************************** * * Tests @@ -47,7 +47,7 @@ describe(`[Compatibility: ts-node] Register script`, () => { global.process[instanceSymbol] = void 0; let registerSpy: jest.SpyInstance | undefined; try { - registerSpy = jest.spyOn(tsNode, "register"); + registerSpy = jest.spyOn(tsNode, 'register'); expect(global.process[instanceSymbol]).toBeUndefined(); nodeRegister.initialize(); @@ -67,7 +67,7 @@ describe(`[Compatibility: ts-node] Register script`, () => { global.process[instanceSymbol] = fakeInstance; let registerSpy: jest.SpyInstance | undefined; try { - registerSpy = jest.spyOn(tsNode, "register"); + registerSpy = jest.spyOn(tsNode, 'register'); const { tsNodeInstance } = nodeRegister.initialize(); @@ -90,25 +90,25 @@ describe(`[Compatibility: ts-node] Register script`, () => { describe(`Register`, () => { test(`Throws without ts-node`, () => { jest.doMock( - "ts-node", + 'ts-node', () => { - require("sdf0s39rf3333d@fake-module"); + require('sdf0s39rf3333d@fake-module'); }, { virtual: true } ); expect(() => nodeRegister()).toThrow(`Cannot resolve ts-node`); - jest.dontMock("ts-node"); + jest.dontMock('ts-node'); }); test(`Throws if can't register ts-node`, () => { - jest.doMock("ts-node", () => ({ register: () => {} }), { virtual: true }); + jest.doMock('ts-node', () => ({ register: () => {} }), { virtual: true }); expect(() => nodeRegister()).toThrow(`Could not register ts-node instance!`); - jest.dontMock("ts-node"); + jest.dontMock('ts-node'); }); test(`No transformers in tsConfig exits quietly`, () => { const originalInitialize = nodeRegister.initialize; - const initializeSpy = jest.spyOn(nodeRegister, "initialize"); + const initializeSpy = jest.spyOn(nodeRegister, 'initialize'); try { initializeSpy.mockImplementation(() => { const res = originalInitialize(); @@ -122,9 +122,9 @@ describe(`[Compatibility: ts-node] Register script`, () => { }); describe.each([ - "Existing Transformer Config", - "Existing Transformer Config Factory", - "No Existing Transformers", + 'Existing Transformer Config', + 'Existing Transformer Config Factory', + 'No Existing Transformers', ] as const)(`%s`, (configKind) => { const fakeExistingTransformer = function fakeExistingTransformer(): any {}; const fakeTransformer = function fakeTransformer(): any {}; @@ -138,13 +138,13 @@ describe(`[Compatibility: ts-node] Register script`, () => { let existingTransformers: CustomTransformers | ((p: Program) => CustomTransformers) | undefined; switch (configKind) { - case "Existing Transformer Config Factory": + case 'Existing Transformer Config Factory': existingTransformers = transformerFactoryFn; break; - case "Existing Transformer Config": + case 'Existing Transformer Config': existingTransformers = { ...fakeTransformerConfig }; break; - case "No Existing Transformers": + case 'No Existing Transformers': existingTransformers = void 0; } @@ -156,12 +156,12 @@ describe(`[Compatibility: ts-node] Register script`, () => { let mergedTransformers: CustomTransformers; beforeAll(() => { - mockTransformer = jest.spyOn(transformerModule, "transformer").mockReturnValue(fakeTransformer); + mockTransformer = jest.spyOn(transformerModule, 'transformer').mockReturnValue(fakeTransformer); global.process[instanceSymbol] = void 0; const originalInitialize = nodeRegister.initialize; - initializeSpy = jest.spyOn(nodeRegister, "initialize"); + initializeSpy = jest.spyOn(nodeRegister, 'initialize'); initializeSpy.mockImplementation(() => { const res = originalInitialize(); if (existingTransformers) res.tsNodeInstance.options.transformers = existingTransformers; @@ -177,7 +177,7 @@ describe(`[Compatibility: ts-node] Register script`, () => { global.process[instanceSymbol] = originalTsNodeInstance; mergedTransformers = - typeof registerResult.transformers === "function" + typeof registerResult.transformers === 'function' ? registerResult.transformers(fakeProgram) : registerResult.transformers!; }); @@ -219,16 +219,16 @@ describe(`[Compatibility: ts-node] Register script`, () => { }); test(`Transformer instantiated w/ proper config${ - existingTransformers === transformerFactoryFn ? " & Program" : "" + existingTransformers === transformerFactoryFn ? ' & Program' : '' }`, () => { const callTimes = +hasBefore + +hasAfterDeclarations; expect(mockTransformer).toBeCalledTimes(callTimes); const afterDeclarationsConfig = transformers.find( - (t) => t.transform === "typescript-transform-paths" && t.afterDeclarations + (t) => t.transform === 'typescript-transform-paths' && t.afterDeclarations ); const beforeConfig = transformers.find( - (t) => t.transform === "typescript-transform-paths" && !t.afterDeclarations + (t) => t.transform === 'typescript-transform-paths' && !t.afterDeclarations ); if (hasBefore) expect(beforeConfig).not.toBeUndefined(); diff --git a/test/tests/projects/extras.test.ts b/test/tests/projects/extras.test.ts index 9758d3c6..691ba792 100755 --- a/test/tests/projects/extras.test.ts +++ b/test/tests/projects/extras.test.ts @@ -1,10 +1,9 @@ -import { projectsPath, rootPath } from "../../src/config"; -import path from "path"; +import { projectsPath, rootPath } from '../../src/config'; +import path from 'path'; import type TS from 'typescript'; -import { normalizePath } from 'typescript' -import { execSync } from "child_process"; -import { createTsProgram, getEmitResultFromProgram } from "../../src"; - +import { normalizePath } from 'typescript'; +import { execSync } from 'child_process'; +import { createTsProgram, getEmitResultFromProgram } from '../../src'; /* ****************************************************************************************************************** * * Config @@ -17,9 +16,9 @@ const tsNodePath = path.resolve(rootPath, 'node_modules/.bin/ts-node'); * ****************************************************************************************************************** */ describe(`[Project: 'extras'] Extra Tests`, () => { - const projectRoot = normalizePath(path.join(projectsPath, "extras")); - const indexFile = normalizePath(path.join(projectRoot, "src/index.ts")); - const tsConfigFile = normalizePath(path.join(projectRoot, "tsconfig.json")); + const projectRoot = normalizePath(path.join(projectsPath, 'extras')); + const indexFile = normalizePath(path.join(projectRoot, 'src/index.ts')); + const tsConfigFile = normalizePath(path.join(projectRoot, 'tsconfig.json')); describe.each(envOptions.tsModules)(`[TS %s]`, (_, tsSpecifier) => { const ts: typeof TS = require(tsSpecifier); @@ -27,9 +26,9 @@ describe(`[Project: 'extras'] Extra Tests`, () => { // see: https://github.com/LeDDGroup/typescript-transform-paths/issues/130 test(`Transformer works without ts-node being present`, () => { jest.doMock( - "ts-node", + 'ts-node', () => { - require("sdf0s39rf3333d@fake-module"); + require('sdf0s39rf3333d@fake-module'); }, { virtual: true } ); @@ -38,7 +37,7 @@ describe(`[Project: 'extras'] Extra Tests`, () => { const res = getEmitResultFromProgram(ts, program); expect(res[indexFile].js).toMatch(`const _identifier_1 = require("./id")`); } finally { - jest.dontMock("ts-node"); + jest.dontMock('ts-node'); } }); }); diff --git a/test/tests/projects/general.test.ts b/test/tests/projects/general.test.ts index 39bb350b..92b0f019 100755 --- a/test/tests/projects/general.test.ts +++ b/test/tests/projects/general.test.ts @@ -80,7 +80,7 @@ describe(`[Project: 'general'] - General Tests`, () => { transformed = transformedFiles[file]; expected = { js: getExpected(ts, file, originalFiles[file].js, projectRoot), - ...(!skipDts && { dts: getExpected(ts, file, originalFiles[file].dts!, projectRoot) }) + ...(!skipDts && { dts: getExpected(ts, file, originalFiles[file].dts!, projectRoot) }), }; }); diff --git a/test/tests/projects/project-ref.test.ts b/test/tests/projects/project-ref.test.ts index 970f213d..541ce17a 100755 --- a/test/tests/projects/project-ref.test.ts +++ b/test/tests/projects/project-ref.test.ts @@ -1,6 +1,6 @@ import { joinPaths } from 'tstp/src/utils'; -import { ut } from "../../src"; -import { projectsPath } from "../../src/config"; +import { ut } from '../../src'; +import { projectsPath } from '../../src/config'; /* ****************************************************************************************************************** * * Config @@ -10,7 +10,7 @@ const testRuns = ut.loadProject({ projectName: 'project-ref', programKind: 'solutionBuilder', builderTransformerPredicate: (program) => - program.getCompilerOptions().configFilePath === joinPaths(projectsPath, 'project-ref/b/tsconfig.json') + program.getCompilerOptions().configFilePath === joinPaths(projectsPath, 'project-ref/b/tsconfig.json'), }); /* ****************************************************************************************************************** * @@ -20,7 +20,7 @@ const testRuns = ut.loadProject({ describe(`[Project: 'project-ref'] - Project References`, () => { describe.each(testRuns)(`$runLabel`, ({ tests }) => { test.each(tests)(`%s`, (_, detail) => { - detail.expects.forEach(exp => expect(exp).toResolve()); - }) - }) + detail.expects.forEach((exp) => expect(exp).toResolve()); + }); + }); }); diff --git a/test/tests/projects/resolution.test.ts b/test/tests/projects/resolution.test.ts index d37879a7..ba40afd9 100755 --- a/test/tests/projects/resolution.test.ts +++ b/test/tests/projects/resolution.test.ts @@ -8,8 +8,8 @@ const testRuns = ut.loadProject({ projectName: 'resolution', useGroups: true, configs: ut.createConfigSpread({ - outputIndexes: [ 'auto', 'never', 'always' ], - outputExtensions: [ 'auto', 'never', 'always' ] + outputIndexes: ['auto', 'never', 'always'], + outputExtensions: ['auto', 'never', 'always'], }), }); diff --git a/test/tests/projects/root-dirs.test.ts b/test/tests/projects/root-dirs.test.ts index a1b07830..2f3dde01 100755 --- a/test/tests/projects/root-dirs.test.ts +++ b/test/tests/projects/root-dirs.test.ts @@ -1,4 +1,4 @@ -import { ut } from "../../src"; +import { ut } from '../../src'; /* ****************************************************************************************************************** * * Config @@ -6,10 +6,9 @@ import { ut } from "../../src"; const testRuns = ut.loadProject({ projectName: 'root-dirs', - configs: [ true, false, undefined ].map(v => ({ useRootDirs: v })) + configs: [true, false, undefined].map((v) => ({ useRootDirs: v })), }); - /* ****************************************************************************************************************** * * Tests * ****************************************************************************************************************** */ @@ -19,5 +18,5 @@ describe(`[Project: 'root-dirs'] - TS RootDirs`, () => { test.each(tests)(`%s`, (_, { expects }) => { expects.forEach((exp) => expect(exp).toResolve()); }); - }) + }); }); diff --git a/test/tests/projects/specific.test.ts b/test/tests/projects/specific.test.ts index 148f3170..9dec6508 100755 --- a/test/tests/projects/specific.test.ts +++ b/test/tests/projects/specific.test.ts @@ -7,7 +7,7 @@ import { ut } from '../../src'; const testRuns = ut.loadProject({ projectName: 'specific', pluginOptions: { exclude: ['**/excluded/**', 'excluded-file.*'] }, - useGroups: true + useGroups: true, }); /* ****************************************************************************************************************** * @@ -20,6 +20,6 @@ describe(`[Project: 'specific'] - Specific Test Cases`, () => { test.each(tests)(`%s`, (_, { expects }) => { expects.forEach((exp) => expect(exp).toResolve()); }); - }) + }); }); }); diff --git a/test/transformer-wrapper/index.d.ts b/test/transformer-wrapper/index.d.ts index 49449093..72000fcc 100755 --- a/test/transformer-wrapper/index.d.ts +++ b/test/transformer-wrapper/index.d.ts @@ -1,4 +1,4 @@ -export * from 'tstp/src' +export * from 'tstp/src'; import { default as transformer } from 'tstp/src'; export default transformer; From dbc9bdcf6b850e0ffdf3eee697c71527a58e0459 Mon Sep 17 00:00:00 2001 From: Ron S Date: Sun, 14 Nov 2021 21:04:00 -0500 Subject: [PATCH 11/13] test: Updated General test for single quote --- test/tests/projects/general.test.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/test/tests/projects/general.test.ts b/test/tests/projects/general.test.ts index 92b0f019..1fcf01cc 100755 --- a/test/tests/projects/general.test.ts +++ b/test/tests/projects/general.test.ts @@ -26,6 +26,7 @@ const makeRelative = (tsInstance: typeof TS, fileName: string, p: string, rootDi const getExpected = (tsInstance: typeof TS, fileName: string, original: string, rootDir: string): string => original + .replace(/'/g, '"') .replace(/"@(.*)"/g, (_, p) => makeRelative(tsInstance, fileName, p, rootDir)) .replace(/"#utils\/(.*)"/g, (_, p) => makeRelative(tsInstance, fileName, path.join(p === 'hello' ? 'secondary' : 'utils', p), rootDir) @@ -77,7 +78,9 @@ describe(`[Project: 'general'] - General Tests`, () => { let transformed: EmittedFiles[string]; beforeAll(() => { - transformed = transformedFiles[file]; + transformed = transformedFiles[file] + transformed.js = transformed.js.replace(/'/g, '"'); + transformed.dts = transformed.dts?.replace(/'/g, '"'); expected = { js: getExpected(ts, file, originalFiles[file].js, projectRoot), ...(!skipDts && { dts: getExpected(ts, file, originalFiles[file].dts!, projectRoot) }), From b62dd49856e53351d70599b4e2e116e96fcd3176 Mon Sep 17 00:00:00 2001 From: Ron S Date: Sun, 14 Nov 2021 21:05:28 -0500 Subject: [PATCH 12/13] feat: Added esm loader --- esm.mjs | 13 ++++++ package.json | 2 +- register.js | 1 - src/compatibility/node-register.ts | 5 +-- test/projects/esm-loader/package.json | 6 +++ test/projects/esm-loader/src/id.ts | 1 + test/projects/esm-loader/src/index.ts | 4 ++ test/projects/esm-loader/tsconfig.json | 29 ++++++++++++++ test/tests/compatibility/esm-loader.test.ts | 22 ++++++++++ .../tests/compatibility/node-register.test.ts | 3 +- yarn.lock | 40 +++++++++++++++---- 11 files changed, 112 insertions(+), 14 deletions(-) create mode 100755 esm.mjs create mode 100755 test/projects/esm-loader/package.json create mode 100755 test/projects/esm-loader/src/id.ts create mode 100755 test/projects/esm-loader/src/index.ts create mode 100755 test/projects/esm-loader/tsconfig.json create mode 100755 test/tests/compatibility/esm-loader.test.ts diff --git a/esm.mjs b/esm.mjs new file mode 100755 index 00000000..29f4af0f --- /dev/null +++ b/esm.mjs @@ -0,0 +1,13 @@ +import { fileURLToPath } from 'url'; +import { createRequire } from 'module'; +const require = createRequire(fileURLToPath(import.meta.url)); + +/** @type {import('./src/compatibility/node-register')} */ +const { nodeRegister } = require('./dist/compatibility/node-register'); + +/** @type {import('ts-node')} */ +import tsNode from 'ts-node'; + +const tsNodeInstance = nodeRegister(); + +export const { resolve, getFormat, transformSource } = tsNode.createEsmHooks(tsNodeInstance); diff --git a/package.json b/package.json index bb2ced5d..d68228a9 100755 --- a/package.json +++ b/package.json @@ -64,7 +64,7 @@ "rimraf": "^3.0.2", "standard-version": "^9.3.1", "ts-jest": "^27.0.4", - "ts-node": "^10.1.0", + "ts-node": "^10.4.0", "ts-patch": "^1.4.4", "ts3": "npm:typescript@3.7.7", "ts45": "npm:typescript@4.5.0-beta", diff --git a/register.js b/register.js index c6f41b0e..7d681960 100755 --- a/register.js +++ b/register.js @@ -7,5 +7,4 @@ try { ); } -tsNode.register(); require('./').nodeRegister(); diff --git a/src/compatibility/node-register.ts b/src/compatibility/node-register.ts index cba3369e..74799c84 100755 --- a/src/compatibility/node-register.ts +++ b/src/compatibility/node-register.ts @@ -68,7 +68,7 @@ export function mergeTransformers( // region: TsNode Registration Utility /* ****************************************************************************************************************** */ -export function nodeRegister(): TSNode.RegisterOptions | undefined { +export function nodeRegister(): TSNode.Service | undefined { const { tsNodeInstance, tsNode } = nodeRegister.initialize(); const transformerConfig = getProjectTransformerConfig(tsNodeInstance.config); @@ -96,8 +96,7 @@ export function nodeRegister(): TSNode.RegisterOptions | undefined { } // Re-register with new transformers - tsNode.register(registerOptions); - return registerOptions; + return tsNode.register(registerOptions); } export namespace nodeRegister { diff --git a/test/projects/esm-loader/package.json b/test/projects/esm-loader/package.json new file mode 100755 index 00000000..cc8fd44c --- /dev/null +++ b/test/projects/esm-loader/package.json @@ -0,0 +1,6 @@ +{ + "private": true, + "name": "@tests/esm-loader", + "version": "0.0.0", + "type": "module" +} diff --git a/test/projects/esm-loader/src/id.ts b/test/projects/esm-loader/src/id.ts new file mode 100755 index 00000000..01b2dc8e --- /dev/null +++ b/test/projects/esm-loader/src/id.ts @@ -0,0 +1 @@ +export const b = null; diff --git a/test/projects/esm-loader/src/index.ts b/test/projects/esm-loader/src/index.ts new file mode 100755 index 00000000..c0bb14c0 --- /dev/null +++ b/test/projects/esm-loader/src/index.ts @@ -0,0 +1,4 @@ +export * from "#identifier"; +import { b } from "#identifier"; + +console.log(b); diff --git a/test/projects/esm-loader/tsconfig.json b/test/projects/esm-loader/tsconfig.json new file mode 100755 index 00000000..49a3c232 --- /dev/null +++ b/test/projects/esm-loader/tsconfig.json @@ -0,0 +1,29 @@ +{ + "include": [ "src" ], + + "compilerOptions": { + "noEmit": true, + + "rootDir": ".", + "module": "ESNext", + "target": "ESNext", + "esModuleInterop": true, + "moduleResolution": "node", + "declaration": true, + + "baseUrl": "./src", + "paths": { + "#identifier": [ "./id.ts" ] + }, + + "plugins": [ + { + "transform": "typescript-transform-paths" + }, + { + "transform": "typescript-transform-paths", + "afterDeclarations": true + } + ] + } +} diff --git a/test/tests/compatibility/esm-loader.test.ts b/test/tests/compatibility/esm-loader.test.ts new file mode 100755 index 00000000..4abce72f --- /dev/null +++ b/test/tests/compatibility/esm-loader.test.ts @@ -0,0 +1,22 @@ +import { execSync } from "child_process"; +import path from "path"; +import ts from 'typescript' +import { projectsPath } from "../../src/config"; + +/* ****************************************************************************************************************** * + * Tests + * ****************************************************************************************************************** */ + +describe(`ESM Loader`, () => { + const esmProjectRoot = ts.normalizePath(path.join(projectsPath, "esm-loader")); + + // See: https://github.com/LeDDGroup/typescript-transform-paths/issues/134 + test(`Transforms ESM project`, () => { + const res = execSync( + `node --no-warnings --loader tstp/esm --es-module-specifier-resolution=node ./src/index.ts`, + { cwd: esmProjectRoot } + ).toString(); + + expect(res).toMatch(/^null($|\r?\n)/); + }); +}); diff --git a/test/tests/compatibility/node-register.test.ts b/test/tests/compatibility/node-register.test.ts index 59dd17b5..7f3d7cf5 100755 --- a/test/tests/compatibility/node-register.test.ts +++ b/test/tests/compatibility/node-register.test.ts @@ -60,6 +60,7 @@ describe(`[Compatibility: ts-node] Register script`, () => { registerSpy?.mockRestore(); } }); + test(`Uses existing ts-node if found`, () => { const fakeInstance: any = {}; @@ -172,7 +173,7 @@ describe(`[Compatibility: ts-node] Register script`, () => { }); const originalTsNodeInstance = global.process[instanceSymbol]; - registerResult = nodeRegister()!; + registerResult = nodeRegister()!.options; instanceRegistrationResult = global.process[instanceSymbol]!; global.process[instanceSymbol] = originalTsNodeInstance; diff --git a/yarn.lock b/yarn.lock index 6f98ae26..06dfd1d7 100644 --- a/yarn.lock +++ b/yarn.lock @@ -482,6 +482,18 @@ resolved "https://registry.yarnpkg.com/@bcoe/v8-coverage/-/v8-coverage-0.2.3.tgz#75a2e8b51cb758a7553d6804a5932d7aace75c39" integrity sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw== +"@cspotcode/source-map-consumer@0.8.0": + version "0.8.0" + resolved "https://registry.yarnpkg.com/@cspotcode/source-map-consumer/-/source-map-consumer-0.8.0.tgz#33bf4b7b39c178821606f669bbc447a6a629786b" + integrity sha512-41qniHzTU8yAGbCp04ohlmSrZf8bkf/iJsl3V0dRGsQN/5GFfx+LbCSsCpp2gqrqjTVg/K6O8ycoV35JIwAzAg== + +"@cspotcode/source-map-support@0.7.0": + version "0.7.0" + resolved "https://registry.yarnpkg.com/@cspotcode/source-map-support/-/source-map-support-0.7.0.tgz#4789840aa859e46d2f3173727ab707c66bf344f5" + integrity sha512-X4xqRHqN8ACt2aHVe51OxeA2HjbcL4MqFqXkrmQszJ1NOUuUu5u6Vqx/0lZSVNku7velL5FC/s5uEAj1lsBMhA== + dependencies: + "@cspotcode/source-map-consumer" "0.8.0" + "@hutson/parse-repository-url@^3.0.0": version "3.0.2" resolved "https://registry.yarnpkg.com/@hutson/parse-repository-url/-/parse-repository-url-3.0.2.tgz#98c23c950a3d9b6c8f0daed06da6c3af06981340" @@ -717,7 +729,7 @@ resolved "https://registry.yarnpkg.com/@tsconfig/node14/-/node14-1.0.1.tgz#95f2d167ffb9b8d2068b0b235302fafd4df711f2" integrity sha512-509r2+yARFfHHE7T6Puu2jjkoycftovhXRqW328PDXTVGKihlb1P8Z9mMZH04ebyajfRY7dedfGynlrFHJUQCg== -"@tsconfig/node16@^1.0.1": +"@tsconfig/node16@^1.0.2": version "1.0.2" resolved "https://registry.yarnpkg.com/@tsconfig/node16/-/node16-1.0.2.tgz#423c77877d0569db20e1fc80885ac4118314010e" integrity sha512-eZxlbI8GZscaGS7kkc/trHTT5xgrjH3/1n2JDwusC9iahPKWMRvRjJSAN5mCXviuTGQ/lHnhvv8Q1YTpnfz9gA== @@ -876,6 +888,11 @@ acorn-walk@^7.1.1: resolved "https://registry.yarnpkg.com/acorn-walk/-/acorn-walk-7.2.0.tgz#0de889a601203909b0fbe07b8938dc21d2e967bc" integrity sha512-OPdCF6GsMIP+Az+aWfAAOEt2/+iVDKE7oy6lJ098aoe59oAmK76qV6Gw60SbZ8jHuG2wH058GF4pLFbYamYrVA== +acorn-walk@^8.1.1: + version "8.2.0" + resolved "https://registry.yarnpkg.com/acorn-walk/-/acorn-walk-8.2.0.tgz#741210f2e2426454508853a2f44d0ab83b7f69c1" + integrity sha512-k+iyHEuPgSw6SbuDpGQM+06HQUa04DZ3o+F6CSzXMvvI5KMvnaEqXe+YVe555R9nn6GPt404fos4wcgpw12SDA== + acorn@^7.1.1: version "7.4.1" resolved "https://registry.yarnpkg.com/acorn/-/acorn-7.4.1.tgz#feaed255973d2e77555b83dbc08851a6c63520fa" @@ -886,6 +903,11 @@ acorn@^8.2.4: resolved "https://registry.yarnpkg.com/acorn/-/acorn-8.4.1.tgz#56c36251fc7cabc7096adc18f05afe814321a28c" integrity sha512-asabaBSkEKosYKMITunzX177CXxQ4Q8BSSzMTKD+FefUhipQC70gfW5SiUDhYQ3vk8G+81HqQk7Fv9OXwwn9KA== +acorn@^8.4.1: + version "8.5.0" + resolved "https://registry.yarnpkg.com/acorn/-/acorn-8.5.0.tgz#4512ccb99b3698c752591e9bb4472e38ad43cee2" + integrity sha512-yXbYeFy+jUuYd3/CDcg2NkIYE991XYX/bje7LmjJigUciaeO1JR4XxXgCIV1/Zc/dRuFEyw1L0pbA+qynJkW5Q== + add-stream@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/add-stream/-/add-stream-1.0.0.tgz#6a7990437ca736d5e1288db92bd3266d5f5cb2aa" @@ -3357,7 +3379,7 @@ slash@^3.0.0: resolved "https://registry.yarnpkg.com/slash/-/slash-3.0.0.tgz#6539be870c165adbd5240220dbe361f1bc4d4634" integrity sha512-g9Q1haeby36OSStwb4ntCGGGaKsaVSjQ68fBxoQcutl5fS1vuY18H3wSt3jFyFtrkx+Kz0V1G85A4MyAdDMi2Q== -source-map-support@^0.5.17, source-map-support@^0.5.6: +source-map-support@^0.5.6: version "0.5.19" resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.5.19.tgz#a98b62f86dcaf4f67399648c085291ab9e8fed61" integrity sha512-Wonm7zOCIJzBGQdB+thsPar0kYuCIzYvxZwlBa87yi/Mdjv7Tip2cyVbLj5o0cFPN4EVkuTwb3GDDyUx2DGnGw== @@ -3665,20 +3687,22 @@ ts-jest@^27.0.4: semver "7.x" yargs-parser "20.x" -ts-node@^10.1.0: - version "10.1.0" - resolved "https://registry.yarnpkg.com/ts-node/-/ts-node-10.1.0.tgz#e656d8ad3b61106938a867f69c39a8ba6efc966e" - integrity sha512-6szn3+J9WyG2hE+5W8e0ruZrzyk1uFLYye6IGMBadnOzDh8aP7t8CbFpsfCiEx2+wMixAhjFt7lOZC4+l+WbEA== +ts-node@^10.4.0: + version "10.4.0" + resolved "https://registry.yarnpkg.com/ts-node/-/ts-node-10.4.0.tgz#680f88945885f4e6cf450e7f0d6223dd404895f7" + integrity sha512-g0FlPvvCXSIO1JDF6S232P5jPYqBkRL9qly81ZgAOSU7rwI0stphCgd2kLiCrU9DjQCrJMWEqcNSjQL02s6d8A== dependencies: + "@cspotcode/source-map-support" "0.7.0" "@tsconfig/node10" "^1.0.7" "@tsconfig/node12" "^1.0.7" "@tsconfig/node14" "^1.0.0" - "@tsconfig/node16" "^1.0.1" + "@tsconfig/node16" "^1.0.2" + acorn "^8.4.1" + acorn-walk "^8.1.1" arg "^4.1.0" create-require "^1.1.0" diff "^4.0.1" make-error "^1.1.1" - source-map-support "^0.5.17" yn "3.1.1" ts-patch@^1.4.4: From 9a4aa5322e9bab183a39b967abebcdbbfafb7b7a Mon Sep 17 00:00:00 2001 From: Ron S Date: Sun, 14 Nov 2021 21:18:50 -0500 Subject: [PATCH 13/13] test: Fix jest-haste-map collisions --- .../projects/resolution/packages/external/root-idx/package.json | 2 +- .../resolution/packages/external/root-idx/sub-pkg/package.json | 2 +- .../resolution/packages/external/root-named-idx/package.json | 2 +- .../resolution/packages/external/subdir-idx/package.json | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/test/projects/resolution/packages/external/root-idx/package.json b/test/projects/resolution/packages/external/root-idx/package.json index 0052c7f2..4ae2a4bc 100755 --- a/test/projects/resolution/packages/external/root-idx/package.json +++ b/test/projects/resolution/packages/external/root-idx/package.json @@ -1,5 +1,5 @@ { - "name": "root-idx", + "name": "@external/root-idx", "version": "0.0.0", "private": "true", "main": "./index.js" diff --git a/test/projects/resolution/packages/external/root-idx/sub-pkg/package.json b/test/projects/resolution/packages/external/root-idx/sub-pkg/package.json index b53f2aed..24a9b5e5 100755 --- a/test/projects/resolution/packages/external/root-idx/sub-pkg/package.json +++ b/test/projects/resolution/packages/external/root-idx/sub-pkg/package.json @@ -1,5 +1,5 @@ { - "name": "sub-pkg", + "name": "@external/sub-pkg", "version": "0.0.0-alpha", "private": "true", "main": "main.js" diff --git a/test/projects/resolution/packages/external/root-named-idx/package.json b/test/projects/resolution/packages/external/root-named-idx/package.json index a2eab78e..456bf942 100755 --- a/test/projects/resolution/packages/external/root-named-idx/package.json +++ b/test/projects/resolution/packages/external/root-named-idx/package.json @@ -1,5 +1,5 @@ { - "name": "root-named-idx", + "name": "@external/root-named-idx", "version": "0.0.0", "private": "true", "main": "./main.js" diff --git a/test/projects/resolution/packages/external/subdir-idx/package.json b/test/projects/resolution/packages/external/subdir-idx/package.json index 8c2aa837..0c78f8fb 100755 --- a/test/projects/resolution/packages/external/subdir-idx/package.json +++ b/test/projects/resolution/packages/external/subdir-idx/package.json @@ -1,5 +1,5 @@ { - "name": "subdir-idx", + "name": "@external/subdir-idx", "version": "0.0.0", "private": "true", "main": "./subdir/main.js"