typescript 4.7.0-dev.20220311 → 4.7.0-dev.20220314

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.
@@ -2888,6 +2888,20 @@ declare namespace ts {
2888
2888
  Node12 = 3,
2889
2889
  NodeNext = 99
2890
2890
  }
2891
+ export enum ModuleDetectionKind {
2892
+ /**
2893
+ * Files with imports, exports and/or import.meta are considered modules
2894
+ */
2895
+ Legacy = 1,
2896
+ /**
2897
+ * Legacy, but also files with jsx under react-jsx or react-jsxdev and esm mode files under moduleResolution: node12+
2898
+ */
2899
+ Auto = 2,
2900
+ /**
2901
+ * Consider all non-declaration files modules, regardless of present syntax
2902
+ */
2903
+ Force = 3
2904
+ }
2891
2905
  export interface PluginImport {
2892
2906
  name: string;
2893
2907
  }
@@ -2959,6 +2973,7 @@ declare namespace ts {
2959
2973
  maxNodeModuleJsDepth?: number;
2960
2974
  module?: ModuleKind;
2961
2975
  moduleResolution?: ModuleResolutionKind;
2976
+ moduleDetection?: ModuleDetectionKind;
2962
2977
  newLine?: NewLineKind;
2963
2978
  noEmit?: boolean;
2964
2979
  noEmitHelpers?: boolean;
@@ -3146,6 +3161,13 @@ declare namespace ts {
3146
3161
  getDirectories?(path: string): string[];
3147
3162
  useCaseSensitiveFileNames?: boolean | (() => boolean);
3148
3163
  }
3164
+ /**
3165
+ * Used by services to specify the minimum host area required to set up source files under any compilation settings
3166
+ */
3167
+ export interface MinimalResolutionCacheHost extends ModuleResolutionHost {
3168
+ getCompilationSettings(): CompilerOptions;
3169
+ getCompilerHost?(): CompilerHost | undefined;
3170
+ }
3149
3171
  /**
3150
3172
  * Represents the result of module resolution.
3151
3173
  * Module resolution will pick up tsx/jsx/js files even if '--jsx' and '--allowJs' are turned off.
@@ -3221,8 +3243,8 @@ declare namespace ts {
3221
3243
  readonly failedLookupLocations: string[];
3222
3244
  }
3223
3245
  export interface CompilerHost extends ModuleResolutionHost {
3224
- getSourceFile(fileName: string, languageVersion: ScriptTarget, onError?: (message: string) => void, shouldCreateNewSourceFile?: boolean): SourceFile | undefined;
3225
- getSourceFileByPath?(fileName: string, path: Path, languageVersion: ScriptTarget, onError?: (message: string) => void, shouldCreateNewSourceFile?: boolean): SourceFile | undefined;
3246
+ getSourceFile(fileName: string, languageVersionOrOptions: ScriptTarget | CreateSourceFileOptions, onError?: (message: string) => void, shouldCreateNewSourceFile?: boolean): SourceFile | undefined;
3247
+ getSourceFileByPath?(fileName: string, path: Path, languageVersionOrOptions: ScriptTarget | CreateSourceFileOptions, onError?: (message: string) => void, shouldCreateNewSourceFile?: boolean): SourceFile | undefined;
3226
3248
  getCancellationToken?(): CancellationToken;
3227
3249
  getDefaultLibFileName(options: CompilerOptions): string;
3228
3250
  getDefaultLibLocation?(): string;
@@ -4776,7 +4798,22 @@ declare namespace ts {
4776
4798
  * that they appear in the source code. The language service depends on this property to locate nodes by position.
4777
4799
  */
4778
4800
  export function forEachChild<T>(node: Node, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray<Node>) => T | undefined): T | undefined;
4779
- export function createSourceFile(fileName: string, sourceText: string, languageVersion: ScriptTarget, setParentNodes?: boolean, scriptKind?: ScriptKind): SourceFile;
4801
+ export interface CreateSourceFileOptions {
4802
+ languageVersion: ScriptTarget;
4803
+ /**
4804
+ * Controls the format the file is detected as - this can be derived from only the path
4805
+ * and files on disk, but needs to be done with a module resolution cache in scope to be performant.
4806
+ * This is usually `undefined` for compilations that do not have `moduleResolution` values of `node12` or `nodenext`.
4807
+ */
4808
+ impliedNodeFormat?: ModuleKind.ESNext | ModuleKind.CommonJS;
4809
+ /**
4810
+ * Controls how module-y-ness is set for the given file. Usually the result of calling
4811
+ * `getSetExternalModuleIndicator` on a valid `CompilerOptions` object. If not present, the default
4812
+ * check specified by `isFileProbablyExternalModule` will be used to set the field.
4813
+ */
4814
+ setExternalModuleIndicator?: (file: SourceFile) => void;
4815
+ }
4816
+ export function createSourceFile(fileName: string, sourceText: string, languageVersionOrOptions: ScriptTarget | CreateSourceFileOptions, setParentNodes?: boolean, scriptKind?: ScriptKind): SourceFile;
4780
4817
  export function parseIsolatedEntityName(text: string, languageVersion: ScriptTarget): EntityName | undefined;
4781
4818
  /**
4782
4819
  * Parse json text into SyntaxTree and return node and parse errors if any
@@ -5676,7 +5713,7 @@ declare namespace ts {
5676
5713
  set(response: CompletionInfo): void;
5677
5714
  clear(): void;
5678
5715
  }
5679
- interface LanguageServiceHost extends GetEffectiveTypeRootsHost {
5716
+ interface LanguageServiceHost extends GetEffectiveTypeRootsHost, MinimalResolutionCacheHost {
5680
5717
  getCompilationSettings(): CompilerOptions;
5681
5718
  getNewLine?(): string;
5682
5719
  getProjectVersion?(): string;
@@ -5694,9 +5731,9 @@ declare namespace ts {
5694
5731
  error?(s: string): void;
5695
5732
  useCaseSensitiveFileNames?(): boolean;
5696
5733
  readDirectory?(path: string, extensions?: readonly string[], exclude?: readonly string[], include?: readonly string[], depth?: number): string[];
5697
- readFile?(path: string, encoding?: string): string | undefined;
5698
5734
  realpath?(path: string): string;
5699
- fileExists?(path: string): boolean;
5735
+ readFile(path: string, encoding?: string): string | undefined;
5736
+ fileExists(path: string): boolean;
5700
5737
  getTypeRootsVersion?(): number;
5701
5738
  resolveModuleNames?(moduleNames: string[], containingFile: string, reusedNames: string[] | undefined, redirectedReference: ResolvedProjectReference | undefined, options: CompilerOptions, containingSourceFile?: SourceFile): (ResolvedModule | undefined)[];
5702
5739
  getResolvedModuleWithFailedLookupLocationsFromCache?(modulename: string, containingFile: string, resolutionMode?: ModuleKind.CommonJS | ModuleKind.ESNext): ResolvedModuleWithFailedLookupLocations | undefined;
@@ -6748,30 +6785,36 @@ declare namespace ts {
6748
6785
  * the SourceFile if was not found in the registry.
6749
6786
  *
6750
6787
  * @param fileName The name of the file requested
6751
- * @param compilationSettings Some compilation settings like target affects the
6788
+ * @param compilationSettingsOrHost Some compilation settings like target affects the
6752
6789
  * shape of a the resulting SourceFile. This allows the DocumentRegistry to store
6753
- * multiple copies of the same file for different compilation settings.
6790
+ * multiple copies of the same file for different compilation settings. A minimal
6791
+ * resolution cache is needed to fully define a source file's shape when
6792
+ * the compilation settings include `module: node12`+, so providing a cache host
6793
+ * object should be preferred. A common host is a language service `ConfiguredProject`.
6754
6794
  * @param scriptSnapshot Text of the file. Only used if the file was not found
6755
6795
  * in the registry and a new one was created.
6756
6796
  * @param version Current version of the file. Only used if the file was not found
6757
6797
  * in the registry and a new one was created.
6758
6798
  */
6759
- acquireDocument(fileName: string, compilationSettings: CompilerOptions, scriptSnapshot: IScriptSnapshot, version: string, scriptKind?: ScriptKind): SourceFile;
6760
- acquireDocumentWithKey(fileName: string, path: Path, compilationSettings: CompilerOptions, key: DocumentRegistryBucketKey, scriptSnapshot: IScriptSnapshot, version: string, scriptKind?: ScriptKind): SourceFile;
6799
+ acquireDocument(fileName: string, compilationSettingsOrHost: CompilerOptions | MinimalResolutionCacheHost, scriptSnapshot: IScriptSnapshot, version: string, scriptKind?: ScriptKind): SourceFile;
6800
+ acquireDocumentWithKey(fileName: string, path: Path, compilationSettingsOrHost: CompilerOptions | MinimalResolutionCacheHost, key: DocumentRegistryBucketKey, scriptSnapshot: IScriptSnapshot, version: string, scriptKind?: ScriptKind): SourceFile;
6761
6801
  /**
6762
6802
  * Request an updated version of an already existing SourceFile with a given fileName
6763
6803
  * and compilationSettings. The update will in-turn call updateLanguageServiceSourceFile
6764
6804
  * to get an updated SourceFile.
6765
6805
  *
6766
6806
  * @param fileName The name of the file requested
6767
- * @param compilationSettings Some compilation settings like target affects the
6807
+ * @param compilationSettingsOrHost Some compilation settings like target affects the
6768
6808
  * shape of a the resulting SourceFile. This allows the DocumentRegistry to store
6769
- * multiple copies of the same file for different compilation settings.
6809
+ * multiple copies of the same file for different compilation settings. A minimal
6810
+ * resolution cache is needed to fully define a source file's shape when
6811
+ * the compilation settings include `module: node12`+, so providing a cache host
6812
+ * object should be preferred. A common host is a language service `ConfiguredProject`.
6770
6813
  * @param scriptSnapshot Text of the file.
6771
6814
  * @param version Current version of the file.
6772
6815
  */
6773
- updateDocument(fileName: string, compilationSettings: CompilerOptions, scriptSnapshot: IScriptSnapshot, version: string, scriptKind?: ScriptKind): SourceFile;
6774
- updateDocumentWithKey(fileName: string, path: Path, compilationSettings: CompilerOptions, key: DocumentRegistryBucketKey, scriptSnapshot: IScriptSnapshot, version: string, scriptKind?: ScriptKind): SourceFile;
6816
+ updateDocument(fileName: string, compilationSettingsOrHost: CompilerOptions | MinimalResolutionCacheHost, scriptSnapshot: IScriptSnapshot, version: string, scriptKind?: ScriptKind): SourceFile;
6817
+ updateDocumentWithKey(fileName: string, path: Path, compilationSettingsOrHost: CompilerOptions | MinimalResolutionCacheHost, key: DocumentRegistryBucketKey, scriptSnapshot: IScriptSnapshot, version: string, scriptKind?: ScriptKind): SourceFile;
6775
6818
  getKeyForCompilationSettings(settings: CompilerOptions): DocumentRegistryBucketKey;
6776
6819
  /**
6777
6820
  * Informs the DocumentRegistry that a file is not needed any longer.
@@ -6833,7 +6876,7 @@ declare namespace ts {
6833
6876
  function displayPartsToString(displayParts: SymbolDisplayPart[] | undefined): string;
6834
6877
  function getDefaultCompilerOptions(): CompilerOptions;
6835
6878
  function getSupportedCodeFixes(): string[];
6836
- function createLanguageServiceSourceFile(fileName: string, scriptSnapshot: IScriptSnapshot, scriptTarget: ScriptTarget, version: string, setNodeParents: boolean, scriptKind?: ScriptKind): SourceFile;
6879
+ function createLanguageServiceSourceFile(fileName: string, scriptSnapshot: IScriptSnapshot, scriptTargetOrOptions: ScriptTarget | CreateSourceFileOptions, version: string, setNodeParents: boolean, scriptKind?: ScriptKind): SourceFile;
6837
6880
  function updateLanguageServiceSourceFile(sourceFile: SourceFile, scriptSnapshot: IScriptSnapshot, version: string, textChangeRange: TextChangeRange | undefined, aggressiveChecks?: boolean): SourceFile;
6838
6881
  function createLanguageService(host: LanguageServiceHost, documentRegistry?: DocumentRegistry, syntaxOnlyOrLanguageServiceMode?: boolean | LanguageServiceMode): LanguageService;
6839
6882
  /**