typescript 4.5.0-dev.20210924 → 4.5.0-dev.20210928

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -670,7 +670,7 @@ declare namespace ts {
670
670
  readonly parent: Declaration;
671
671
  readonly expression: Expression;
672
672
  }
673
- export interface PrivateIdentifier extends Node {
673
+ export interface PrivateIdentifier extends PrimaryExpression {
674
674
  readonly kind: SyntaxKind.PrivateIdentifier;
675
675
  readonly escapedText: __String;
676
676
  }
@@ -1698,10 +1698,12 @@ declare namespace ts {
1698
1698
  readonly parent: NamedImports;
1699
1699
  readonly propertyName?: Identifier;
1700
1700
  readonly name: Identifier;
1701
+ readonly isTypeOnly: boolean;
1701
1702
  }
1702
1703
  export interface ExportSpecifier extends NamedDeclaration {
1703
1704
  readonly kind: SyntaxKind.ExportSpecifier;
1704
1705
  readonly parent: NamedExports;
1706
+ readonly isTypeOnly: boolean;
1705
1707
  readonly propertyName?: Identifier;
1706
1708
  readonly name: Identifier;
1707
1709
  }
@@ -2030,6 +2032,18 @@ declare namespace ts {
2030
2032
  */
2031
2033
  hasNoDefaultLib: boolean;
2032
2034
  languageVersion: ScriptTarget;
2035
+ /**
2036
+ * When `module` is `Node12` or `NodeNext`, this field controls whether the
2037
+ * source file in question is an ESNext-output-format file, or a CommonJS-output-format
2038
+ * module. This is derived by the module resolver as it looks up the file, since
2039
+ * it is derived from either the file extension of the module, or the containing
2040
+ * `package.json` context, and affects both checking and emit.
2041
+ *
2042
+ * It is _public_ so that (pre)transformers can set this field,
2043
+ * since it switches the builtin `node` module transform. Generally speaking, if unset,
2044
+ * the field is treated as though it is `ModuleKind.CommonJS`.
2045
+ */
2046
+ impliedNodeFormat?: ModuleKind.ESNext | ModuleKind.CommonJS;
2033
2047
  }
2034
2048
  export interface Bundle extends Node {
2035
2049
  readonly kind: SyntaxKind.Bundle;
@@ -2847,7 +2861,9 @@ declare namespace ts {
2847
2861
  }
2848
2862
  export enum ModuleResolutionKind {
2849
2863
  Classic = 1,
2850
- NodeJs = 2
2864
+ NodeJs = 2,
2865
+ Node12 = 3,
2866
+ NodeNext = 99
2851
2867
  }
2852
2868
  export interface PluginImport {
2853
2869
  name: string;
@@ -3009,7 +3025,9 @@ declare namespace ts {
3009
3025
  System = 4,
3010
3026
  ES2015 = 5,
3011
3027
  ES2020 = 6,
3012
- ESNext = 99
3028
+ ESNext = 99,
3029
+ Node12 = 100,
3030
+ NodeNext = 199
3013
3031
  }
3014
3032
  export enum JsxEmit {
3015
3033
  None = 0,
@@ -3155,7 +3173,13 @@ declare namespace ts {
3155
3173
  Js = ".js",
3156
3174
  Jsx = ".jsx",
3157
3175
  Json = ".json",
3158
- TsBuildInfo = ".tsbuildinfo"
3176
+ TsBuildInfo = ".tsbuildinfo",
3177
+ Mjs = ".mjs",
3178
+ Mts = ".mts",
3179
+ Dmts = ".d.mts",
3180
+ Cjs = ".cjs",
3181
+ Cts = ".cts",
3182
+ Dcts = ".d.cts"
3159
3183
  }
3160
3184
  export interface ResolvedModuleWithFailedLookupLocations {
3161
3185
  readonly resolvedModule: ResolvedModuleFull | undefined;
@@ -3183,7 +3207,11 @@ declare namespace ts {
3183
3207
  useCaseSensitiveFileNames(): boolean;
3184
3208
  getNewLine(): string;
3185
3209
  readDirectory?(rootDir: string, extensions: readonly string[], excludes: readonly string[] | undefined, includes: readonly string[], depth?: number): string[];
3186
- resolveModuleNames?(moduleNames: string[], containingFile: string, reusedNames: string[] | undefined, redirectedReference: ResolvedProjectReference | undefined, options: CompilerOptions): (ResolvedModule | undefined)[];
3210
+ resolveModuleNames?(moduleNames: string[], containingFile: string, reusedNames: string[] | undefined, redirectedReference: ResolvedProjectReference | undefined, options: CompilerOptions, containingSourceFile?: SourceFile): (ResolvedModule | undefined)[];
3211
+ /**
3212
+ * Returns the module resolution cache used by a provided `resolveModuleNames` implementation so that any non-name module resolution operations (eg, package.json lookup) can reuse it
3213
+ */
3214
+ getModuleResolutionCache?(): ModuleResolutionCache | undefined;
3187
3215
  /**
3188
3216
  * This method is a companion for 'resolveModuleNames' and is used to resolve 'types' references to actual type declaration files
3189
3217
  */
@@ -3552,16 +3580,16 @@ declare namespace ts {
3552
3580
  updateNamespaceExport(node: NamespaceExport, name: Identifier): NamespaceExport;
3553
3581
  createNamedImports(elements: readonly ImportSpecifier[]): NamedImports;
3554
3582
  updateNamedImports(node: NamedImports, elements: readonly ImportSpecifier[]): NamedImports;
3555
- createImportSpecifier(propertyName: Identifier | undefined, name: Identifier): ImportSpecifier;
3556
- updateImportSpecifier(node: ImportSpecifier, propertyName: Identifier | undefined, name: Identifier): ImportSpecifier;
3583
+ createImportSpecifier(isTypeOnly: boolean, propertyName: Identifier | undefined, name: Identifier): ImportSpecifier;
3584
+ updateImportSpecifier(node: ImportSpecifier, isTypeOnly: boolean, propertyName: Identifier | undefined, name: Identifier): ImportSpecifier;
3557
3585
  createExportAssignment(decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, isExportEquals: boolean | undefined, expression: Expression): ExportAssignment;
3558
3586
  updateExportAssignment(node: ExportAssignment, decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, expression: Expression): ExportAssignment;
3559
3587
  createExportDeclaration(decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, isTypeOnly: boolean, exportClause: NamedExportBindings | undefined, moduleSpecifier?: Expression, assertClause?: AssertClause): ExportDeclaration;
3560
3588
  updateExportDeclaration(node: ExportDeclaration, decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, isTypeOnly: boolean, exportClause: NamedExportBindings | undefined, moduleSpecifier: Expression | undefined, assertClause: AssertClause | undefined): ExportDeclaration;
3561
3589
  createNamedExports(elements: readonly ExportSpecifier[]): NamedExports;
3562
3590
  updateNamedExports(node: NamedExports, elements: readonly ExportSpecifier[]): NamedExports;
3563
- createExportSpecifier(propertyName: string | Identifier | undefined, name: string | Identifier): ExportSpecifier;
3564
- updateExportSpecifier(node: ExportSpecifier, propertyName: Identifier | undefined, name: Identifier): ExportSpecifier;
3591
+ createExportSpecifier(isTypeOnly: boolean, propertyName: string | Identifier | undefined, name: string | Identifier): ExportSpecifier;
3592
+ updateExportSpecifier(node: ExportSpecifier, isTypeOnly: boolean, propertyName: Identifier | undefined, name: Identifier): ExportSpecifier;
3565
3593
  createExternalModuleReference(expression: Expression): ExternalModuleReference;
3566
3594
  updateExternalModuleReference(node: ExternalModuleReference, expression: Expression): ExternalModuleReference;
3567
3595
  createJSDocAllType(): JSDocAllType;
@@ -4830,12 +4858,20 @@ declare namespace ts {
4830
4858
  export function getAutomaticTypeDirectiveNames(options: CompilerOptions, host: ModuleResolutionHost): string[];
4831
4859
  export interface TypeReferenceDirectiveResolutionCache extends PerDirectoryResolutionCache<ResolvedTypeReferenceDirectiveWithFailedLookupLocations>, PackageJsonInfoCache {
4832
4860
  }
4861
+ export interface ModeAwareCache<T> {
4862
+ get(key: string, mode: ModuleKind.CommonJS | ModuleKind.ESNext | undefined): T | undefined;
4863
+ set(key: string, mode: ModuleKind.CommonJS | ModuleKind.ESNext | undefined, value: T): this;
4864
+ delete(key: string, mode: ModuleKind.CommonJS | ModuleKind.ESNext | undefined): this;
4865
+ has(key: string, mode: ModuleKind.CommonJS | ModuleKind.ESNext | undefined): boolean;
4866
+ forEach(cb: (elem: T, key: string, mode: ModuleKind.CommonJS | ModuleKind.ESNext | undefined) => void): void;
4867
+ size(): number;
4868
+ }
4833
4869
  /**
4834
4870
  * Cached resolutions per containing directory.
4835
4871
  * This assumes that any module id will have the same resolution for sibling files located in the same folder.
4836
4872
  */
4837
4873
  export interface PerDirectoryResolutionCache<T> {
4838
- getOrCreateCacheForDirectory(directoryName: string, redirectedReference?: ResolvedProjectReference): Map<T>;
4874
+ getOrCreateCacheForDirectory(directoryName: string, redirectedReference?: ResolvedProjectReference): ModeAwareCache<T>;
4839
4875
  clear(): void;
4840
4876
  /**
4841
4877
  * Updates with the current compilerOptions the cache will operate with.
@@ -4851,7 +4887,7 @@ declare namespace ts {
4851
4887
  * We support only non-relative module names because resolution of relative module names is usually more deterministic and thus less expensive.
4852
4888
  */
4853
4889
  export interface NonRelativeModuleNameResolutionCache extends PackageJsonInfoCache {
4854
- getOrCreateCacheForModuleName(nonRelativeModuleName: string, redirectedReference?: ResolvedProjectReference): PerModuleNameCache;
4890
+ getOrCreateCacheForModuleName(nonRelativeModuleName: string, mode: ModuleKind.CommonJS | ModuleKind.ESNext | undefined, redirectedReference?: ResolvedProjectReference): PerModuleNameCache;
4855
4891
  }
4856
4892
  export interface PackageJsonInfoCache {
4857
4893
  clear(): void;
@@ -4862,8 +4898,8 @@ declare namespace ts {
4862
4898
  }
4863
4899
  export function createModuleResolutionCache(currentDirectory: string, getCanonicalFileName: (s: string) => string, options?: CompilerOptions): ModuleResolutionCache;
4864
4900
  export function createTypeReferenceDirectiveResolutionCache(currentDirectory: string, getCanonicalFileName: (s: string) => string, options?: CompilerOptions, packageJsonInfoCache?: PackageJsonInfoCache): TypeReferenceDirectiveResolutionCache;
4865
- export function resolveModuleNameFromCache(moduleName: string, containingFile: string, cache: ModuleResolutionCache): ResolvedModuleWithFailedLookupLocations | undefined;
4866
- export function resolveModuleName(moduleName: string, containingFile: string, compilerOptions: CompilerOptions, host: ModuleResolutionHost, cache?: ModuleResolutionCache, redirectedReference?: ResolvedProjectReference): ResolvedModuleWithFailedLookupLocations;
4901
+ export function resolveModuleNameFromCache(moduleName: string, containingFile: string, cache: ModuleResolutionCache, mode?: ModuleKind.CommonJS | ModuleKind.ESNext): ResolvedModuleWithFailedLookupLocations | undefined;
4902
+ export function resolveModuleName(moduleName: string, containingFile: string, compilerOptions: CompilerOptions, host: ModuleResolutionHost, cache?: ModuleResolutionCache, redirectedReference?: ResolvedProjectReference, resolutionMode?: ModuleKind.CommonJS | ModuleKind.ESNext): ResolvedModuleWithFailedLookupLocations;
4867
4903
  export function nodeModuleNameResolver(moduleName: string, containingFile: string, compilerOptions: CompilerOptions, host: ModuleResolutionHost, cache?: ModuleResolutionCache, redirectedReference?: ResolvedProjectReference): ResolvedModuleWithFailedLookupLocations;
4868
4904
  export function classicNameResolver(moduleName: string, containingFile: string, compilerOptions: CompilerOptions, host: ModuleResolutionHost, cache?: NonRelativeModuleNameResolutionCache, redirectedReference?: ResolvedProjectReference): ResolvedModuleWithFailedLookupLocations;
4869
4905
  export {};
@@ -4974,6 +5010,17 @@ declare namespace ts {
4974
5010
  export function formatDiagnosticsWithColorAndContext(diagnostics: readonly Diagnostic[], host: FormatDiagnosticsHost): string;
4975
5011
  export function flattenDiagnosticMessageText(diag: string | DiagnosticMessageChain | undefined, newLine: string, indent?: number): string;
4976
5012
  export function getConfigFileParsingDiagnostics(configFileParseResult: ParsedCommandLine): readonly Diagnostic[];
5013
+ /**
5014
+ * A function for determining if a given file is esm or cjs format, assuming modern node module resolution rules, as configured by the
5015
+ * `options` parameter.
5016
+ *
5017
+ * @param fileName The normalized absolute path to check the format of (it need not exist on disk)
5018
+ * @param [packageJsonInfoCache] A cache for package file lookups - it's best to have a cache when this function is called often
5019
+ * @param host The ModuleResolutionHost which can perform the filesystem lookups for package json data
5020
+ * @param options The compiler options to perform the analysis under - relevant options are `moduleResolution` and `traceResolution`
5021
+ * @returns `undefined` if the path has no relevant implied format, `ModuleKind.ESNext` for esm format, and `ModuleKind.CommonJS` for cjs format
5022
+ */
5023
+ export function getImpliedNodeFormatForFile(fileName: Path, packageJsonInfoCache: PackageJsonInfoCache | undefined, host: ModuleResolutionHost, options: CompilerOptions): ModuleKind.ESNext | ModuleKind.CommonJS | undefined;
4977
5024
  /**
4978
5025
  * Create a new 'Program' instance. A Program is an immutable collection of 'SourceFile's and a 'CompilerOptions'
4979
5026
  * that represent a compilation unit.
@@ -5218,7 +5265,7 @@ declare namespace ts {
5218
5265
  /** If provided is used to get the environment variable */
5219
5266
  getEnvironmentVariable?(name: string): string | undefined;
5220
5267
  /** If provided, used to resolve the module names, otherwise typescript's default module resolution */
5221
- resolveModuleNames?(moduleNames: string[], containingFile: string, reusedNames: string[] | undefined, redirectedReference: ResolvedProjectReference | undefined, options: CompilerOptions): (ResolvedModule | undefined)[];
5268
+ resolveModuleNames?(moduleNames: string[], containingFile: string, reusedNames: string[] | undefined, redirectedReference: ResolvedProjectReference | undefined, options: CompilerOptions, containingSourceFile?: SourceFile): (ResolvedModule | undefined)[];
5222
5269
  /** If provided, used to resolve type reference directives, otherwise typescript's default resolution */
5223
5270
  resolveTypeReferenceDirectives?(typeReferenceDirectiveNames: string[], containingFile: string, redirectedReference: ResolvedProjectReference | undefined, options: CompilerOptions): (ResolvedTypeReferenceDirective | undefined)[];
5224
5271
  }
@@ -5608,8 +5655,8 @@ declare namespace ts {
5608
5655
  realpath?(path: string): string;
5609
5656
  fileExists?(path: string): boolean;
5610
5657
  getTypeRootsVersion?(): number;
5611
- resolveModuleNames?(moduleNames: string[], containingFile: string, reusedNames: string[] | undefined, redirectedReference: ResolvedProjectReference | undefined, options: CompilerOptions): (ResolvedModule | undefined)[];
5612
- getResolvedModuleWithFailedLookupLocationsFromCache?(modulename: string, containingFile: string): ResolvedModuleWithFailedLookupLocations | undefined;
5658
+ resolveModuleNames?(moduleNames: string[], containingFile: string, reusedNames: string[] | undefined, redirectedReference: ResolvedProjectReference | undefined, options: CompilerOptions, containingSourceFile?: SourceFile): (ResolvedModule | undefined)[];
5659
+ getResolvedModuleWithFailedLookupLocationsFromCache?(modulename: string, containingFile: string, resolutionMode?: ModuleKind.CommonJS | ModuleKind.ESNext): ResolvedModuleWithFailedLookupLocations | undefined;
5613
5660
  resolveTypeReferenceDirectives?(typeDirectiveNames: string[], containingFile: string, redirectedReference: ResolvedProjectReference | undefined, options: CompilerOptions): (ResolvedTypeReferenceDirective | undefined)[];
5614
5661
  getDirectories?(directoryName: string): string[];
5615
5662
  /**
@@ -6557,7 +6604,13 @@ declare namespace ts {
6557
6604
  tsxModifier = ".tsx",
6558
6605
  jsModifier = ".js",
6559
6606
  jsxModifier = ".jsx",
6560
- jsonModifier = ".json"
6607
+ jsonModifier = ".json",
6608
+ dmtsModifier = ".d.mts",
6609
+ mtsModifier = ".mts",
6610
+ mjsModifier = ".mjs",
6611
+ dctsModifier = ".d.cts",
6612
+ ctsModifier = ".cts",
6613
+ cjsModifier = ".cjs"
6561
6614
  }
6562
6615
  enum ClassificationTypeNames {
6563
6616
  comment = "comment",
@@ -7201,9 +7254,9 @@ declare namespace ts {
7201
7254
  /** @deprecated Use `factory.updateNamedImports` or the factory supplied by your transformation context instead. */
7202
7255
  const updateNamedImports: (node: NamedImports, elements: readonly ImportSpecifier[]) => NamedImports;
7203
7256
  /** @deprecated Use `factory.createImportSpecifier` or the factory supplied by your transformation context instead. */
7204
- const createImportSpecifier: (propertyName: Identifier | undefined, name: Identifier) => ImportSpecifier;
7257
+ const createImportSpecifier: (isTypeOnly: boolean, propertyName: Identifier | undefined, name: Identifier) => ImportSpecifier;
7205
7258
  /** @deprecated Use `factory.updateImportSpecifier` or the factory supplied by your transformation context instead. */
7206
- const updateImportSpecifier: (node: ImportSpecifier, propertyName: Identifier | undefined, name: Identifier) => ImportSpecifier;
7259
+ const updateImportSpecifier: (node: ImportSpecifier, isTypeOnly: boolean, propertyName: Identifier | undefined, name: Identifier) => ImportSpecifier;
7207
7260
  /** @deprecated Use `factory.createExportAssignment` or the factory supplied by your transformation context instead. */
7208
7261
  const createExportAssignment: (decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, isExportEquals: boolean | undefined, expression: Expression) => ExportAssignment;
7209
7262
  /** @deprecated Use `factory.updateExportAssignment` or the factory supplied by your transformation context instead. */
@@ -7213,9 +7266,9 @@ declare namespace ts {
7213
7266
  /** @deprecated Use `factory.updateNamedExports` or the factory supplied by your transformation context instead. */
7214
7267
  const updateNamedExports: (node: NamedExports, elements: readonly ExportSpecifier[]) => NamedExports;
7215
7268
  /** @deprecated Use `factory.createExportSpecifier` or the factory supplied by your transformation context instead. */
7216
- const createExportSpecifier: (propertyName: string | Identifier | undefined, name: string | Identifier) => ExportSpecifier;
7269
+ const createExportSpecifier: (isTypeOnly: boolean, propertyName: string | Identifier | undefined, name: string | Identifier) => ExportSpecifier;
7217
7270
  /** @deprecated Use `factory.updateExportSpecifier` or the factory supplied by your transformation context instead. */
7218
- const updateExportSpecifier: (node: ExportSpecifier, propertyName: Identifier | undefined, name: Identifier) => ExportSpecifier;
7271
+ const updateExportSpecifier: (node: ExportSpecifier, isTypeOnly: boolean, propertyName: Identifier | undefined, name: Identifier) => ExportSpecifier;
7219
7272
  /** @deprecated Use `factory.createExternalModuleReference` or the factory supplied by your transformation context instead. */
7220
7273
  const createExternalModuleReference: (expression: Expression) => ExternalModuleReference;
7221
7274
  /** @deprecated Use `factory.updateExternalModuleReference` or the factory supplied by your transformation context instead. */