typescript 5.6.0-dev.20240717 → 5.6.0-dev.20240718

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.
@@ -5991,19 +5991,67 @@ declare namespace ts {
5991
5991
  isSourceFileFromExternalLibrary(file: SourceFile): boolean;
5992
5992
  isSourceFileDefaultLibrary(file: SourceFile): boolean;
5993
5993
  /**
5994
- * Calculates the final resolution mode for a given module reference node. This is the resolution mode explicitly provided via import
5995
- * attributes, if present, or the syntax the usage would have if emitted to JavaScript. In `--module node16` or `nodenext`, this may
5996
- * depend on the file's `impliedNodeFormat`. In `--module preserve`, it depends only on the input syntax of the reference. In other
5997
- * `module` modes, when overriding import attributes are not provided, this function returns `undefined`, as the result would have no
5998
- * impact on module resolution, emit, or type checking.
5994
+ * Calculates the final resolution mode for a given module reference node. This function only returns a result when module resolution
5995
+ * settings allow differing resolution between ESM imports and CJS requires, or when a mode is explicitly provided via import attributes,
5996
+ * which cause an `import` or `require` condition to be used during resolution regardless of module resolution settings. In absence of
5997
+ * overriding attributes, and in modes that support differing resolution, the result indicates the syntax the usage would emit to JavaScript.
5998
+ * Some examples:
5999
+ *
6000
+ * ```ts
6001
+ * // tsc foo.mts --module nodenext
6002
+ * import {} from "mod";
6003
+ * // Result: ESNext - the import emits as ESM due to `impliedNodeFormat` set by .mts file extension
6004
+ *
6005
+ * // tsc foo.cts --module nodenext
6006
+ * import {} from "mod";
6007
+ * // Result: CommonJS - the import emits as CJS due to `impliedNodeFormat` set by .cts file extension
6008
+ *
6009
+ * // tsc foo.ts --module preserve --moduleResolution bundler
6010
+ * import {} from "mod";
6011
+ * // Result: ESNext - the import emits as ESM due to `--module preserve` and `--moduleResolution bundler`
6012
+ * // supports conditional imports/exports
6013
+ *
6014
+ * // tsc foo.ts --module preserve --moduleResolution node10
6015
+ * import {} from "mod";
6016
+ * // Result: undefined - the import emits as ESM due to `--module preserve`, but `--moduleResolution node10`
6017
+ * // does not support conditional imports/exports
6018
+ *
6019
+ * // tsc foo.ts --module commonjs --moduleResolution node10
6020
+ * import type {} from "mod" with { "resolution-mode": "import" };
6021
+ * // Result: ESNext - conditional imports/exports always supported with "resolution-mode" attribute
6022
+ * ```
5999
6023
  */
6000
6024
  getModeForUsageLocation(file: SourceFile, usage: StringLiteralLike): ResolutionMode;
6001
6025
  /**
6002
- * Calculates the final resolution mode for an import at some index within a file's `imports` list. This is the resolution mode
6003
- * explicitly provided via import attributes, if present, or the syntax the usage would have if emitted to JavaScript. In
6004
- * `--module node16` or `nodenext`, this may depend on the file's `impliedNodeFormat`. In `--module preserve`, it depends only on the
6005
- * input syntax of the reference. In other `module` modes, when overriding import attributes are not provided, this function returns
6006
- * `undefined`, as the result would have no impact on module resolution, emit, or type checking.
6026
+ * Calculates the final resolution mode for an import at some index within a file's `imports` list. This function only returns a result
6027
+ * when module resolution settings allow differing resolution between ESM imports and CJS requires, or when a mode is explicitly provided
6028
+ * via import attributes, which cause an `import` or `require` condition to be used during resolution regardless of module resolution
6029
+ * settings. In absence of overriding attributes, and in modes that support differing resolution, the result indicates the syntax the
6030
+ * usage would emit to JavaScript. Some examples:
6031
+ *
6032
+ * ```ts
6033
+ * // tsc foo.mts --module nodenext
6034
+ * import {} from "mod";
6035
+ * // Result: ESNext - the import emits as ESM due to `impliedNodeFormat` set by .mts file extension
6036
+ *
6037
+ * // tsc foo.cts --module nodenext
6038
+ * import {} from "mod";
6039
+ * // Result: CommonJS - the import emits as CJS due to `impliedNodeFormat` set by .cts file extension
6040
+ *
6041
+ * // tsc foo.ts --module preserve --moduleResolution bundler
6042
+ * import {} from "mod";
6043
+ * // Result: ESNext - the import emits as ESM due to `--module preserve` and `--moduleResolution bundler`
6044
+ * // supports conditional imports/exports
6045
+ *
6046
+ * // tsc foo.ts --module preserve --moduleResolution node10
6047
+ * import {} from "mod";
6048
+ * // Result: undefined - the import emits as ESM due to `--module preserve`, but `--moduleResolution node10`
6049
+ * // does not support conditional imports/exports
6050
+ *
6051
+ * // tsc foo.ts --module commonjs --moduleResolution node10
6052
+ * import type {} from "mod" with { "resolution-mode": "import" };
6053
+ * // Result: ESNext - conditional imports/exports always supported with "resolution-mode" attribute
6054
+ * ```
6007
6055
  */
6008
6056
  getModeForResolutionAtIndex(file: SourceFile, index: number): ResolutionMode;
6009
6057
  getProjectReferences(): readonly ProjectReference[] | undefined;
@@ -9362,24 +9410,43 @@ declare namespace ts {
9362
9410
  function getModeForResolutionAtIndex(file: SourceFile, index: number, compilerOptions: CompilerOptions): ResolutionMode;
9363
9411
  /**
9364
9412
  * Use `program.getModeForUsageLocation`, which retrieves the correct `compilerOptions`, instead of this function whenever possible.
9365
- * Calculates the final resolution mode for a given module reference node. This is the resolution mode explicitly provided via import
9366
- * attributes, if present, or the syntax the usage would have if emitted to JavaScript. In `--module node16` or `nodenext`, this may
9367
- * depend on the file's `impliedNodeFormat`. In `--module preserve`, it depends only on the input syntax of the reference. In other
9368
- * `module` modes, when overriding import attributes are not provided, this function returns `undefined`, as the result would have no
9369
- * impact on module resolution, emit, or type checking.
9413
+ * Calculates the final resolution mode for a given module reference node. This function only returns a result when module resolution
9414
+ * settings allow differing resolution between ESM imports and CJS requires, or when a mode is explicitly provided via import attributes,
9415
+ * which cause an `import` or `require` condition to be used during resolution regardless of module resolution settings. In absence of
9416
+ * overriding attributes, and in modes that support differing resolution, the result indicates the syntax the usage would emit to JavaScript.
9417
+ * Some examples:
9418
+ *
9419
+ * ```ts
9420
+ * // tsc foo.mts --module nodenext
9421
+ * import {} from "mod";
9422
+ * // Result: ESNext - the import emits as ESM due to `impliedNodeFormat` set by .mts file extension
9423
+ *
9424
+ * // tsc foo.cts --module nodenext
9425
+ * import {} from "mod";
9426
+ * // Result: CommonJS - the import emits as CJS due to `impliedNodeFormat` set by .cts file extension
9427
+ *
9428
+ * // tsc foo.ts --module preserve --moduleResolution bundler
9429
+ * import {} from "mod";
9430
+ * // Result: ESNext - the import emits as ESM due to `--module preserve` and `--moduleResolution bundler`
9431
+ * // supports conditional imports/exports
9432
+ *
9433
+ * // tsc foo.ts --module preserve --moduleResolution node10
9434
+ * import {} from "mod";
9435
+ * // Result: undefined - the import emits as ESM due to `--module preserve`, but `--moduleResolution node10`
9436
+ * // does not support conditional imports/exports
9437
+ *
9438
+ * // tsc foo.ts --module commonjs --moduleResolution node10
9439
+ * import type {} from "mod" with { "resolution-mode": "import" };
9440
+ * // Result: ESNext - conditional imports/exports always supported with "resolution-mode" attribute
9441
+ * ```
9442
+ *
9370
9443
  * @param file The file the import or import-like reference is contained within
9371
9444
  * @param usage The module reference string
9372
9445
  * @param compilerOptions The compiler options for the program that owns the file. If the file belongs to a referenced project, the compiler options
9373
9446
  * should be the options of the referenced project, not the referencing project.
9374
9447
  * @returns The final resolution mode of the import
9375
9448
  */
9376
- function getModeForUsageLocation(
9377
- file: {
9378
- impliedNodeFormat?: ResolutionMode;
9379
- },
9380
- usage: StringLiteralLike,
9381
- compilerOptions: CompilerOptions,
9382
- ): ModuleKind.CommonJS | ModuleKind.ESNext | undefined;
9449
+ function getModeForUsageLocation(file: SourceFile, usage: StringLiteralLike, compilerOptions: CompilerOptions): ResolutionMode;
9383
9450
  function getConfigFileParsingDiagnostics(configFileParseResult: ParsedCommandLine): readonly Diagnostic[];
9384
9451
  /**
9385
9452
  * A function for determining if a given file is esm or cjs format, assuming modern node module resolution rules, as configured by the