Skip to content

Commit f9f46fd

Browse files
committed
Update existing tests
1 parent 11e5727 commit f9f46fd

26 files changed

+183
-151
lines changed

tests/baselines/reference/api/typescript.d.ts

Lines changed: 89 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6006,19 +6006,67 @@ declare namespace ts {
60066006
isSourceFileFromExternalLibrary(file: SourceFile): boolean;
60076007
isSourceFileDefaultLibrary(file: SourceFile): boolean;
60086008
/**
6009-
* Calculates the final resolution mode for a given module reference node. This is the resolution mode explicitly provided via import
6010-
* attributes, if present, or the syntax the usage would have if emitted to JavaScript. In `--module node16` or `nodenext`, this may
6011-
* depend on the file's `impliedNodeFormat`. In `--module preserve`, it depends only on the input syntax of the reference. In other
6012-
* `module` modes, when overriding import attributes are not provided, this function returns `undefined`, as the result would have no
6013-
* impact on module resolution, emit, or type checking.
6009+
* Calculates the final resolution mode for a given module reference node. This function only returns a result when module resolution
6010+
* settings allow differing resolution between ESM imports and CJS requires, or when a mode is explicitly provided via import attributes,
6011+
* which cause an `import` or `require` condition to be used during resolution regardless of module resolution settings. In absence of
6012+
* overriding attributes, and in modes that support differing resolution, the result indicates the syntax the usage would emit to JavaScript.
6013+
* Some examples:
6014+
*
6015+
* ```ts
6016+
* // tsc foo.mts --module nodenext
6017+
* import {} from "mod";
6018+
* // Result: ESNext - the import emits as ESM due to `impliedNodeFormat` set by .mts file extension
6019+
*
6020+
* // tsc foo.cts --module nodenext
6021+
* import {} from "mod";
6022+
* // Result: CommonJS - the import emits as CJS due to `impliedNodeFormat` set by .cts file extension
6023+
*
6024+
* // tsc foo.ts --module preserve --moduleResolution bundler
6025+
* import {} from "mod";
6026+
* // Result: ESNext - the import emits as ESM due to `--module preserve` and `--moduleResolution bundler`
6027+
* // supports conditional imports/exports
6028+
*
6029+
* // tsc foo.ts --module preserve --moduleResolution node10
6030+
* import {} from "mod";
6031+
* // Result: undefined - the import emits as ESM due to `--module preserve`, but `--moduleResolution node10`
6032+
* // does not support conditional imports/exports
6033+
*
6034+
* // tsc foo.ts --module commonjs --moduleResolution node10
6035+
* import type {} from "mod" with { "resolution-mode": "import" };
6036+
* // Result: ESNext - conditional imports/exports always supported with "resolution-mode" attribute
6037+
* ```
60146038
*/
60156039
getModeForUsageLocation(file: SourceFile, usage: StringLiteralLike): ResolutionMode;
60166040
/**
6017-
* Calculates the final resolution mode for an import at some index within a file's `imports` list. This is the resolution mode
6018-
* explicitly provided via import attributes, if present, or the syntax the usage would have if emitted to JavaScript. In
6019-
* `--module node16` or `nodenext`, this may depend on the file's `impliedNodeFormat`. In `--module preserve`, it depends only on the
6020-
* input syntax of the reference. In other `module` modes, when overriding import attributes are not provided, this function returns
6021-
* `undefined`, as the result would have no impact on module resolution, emit, or type checking.
6041+
* Calculates the final resolution mode for an import at some index within a file's `imports` list. This function only returns a result
6042+
* when module resolution settings allow differing resolution between ESM imports and CJS requires, or when a mode is explicitly provided
6043+
* via import attributes, which cause an `import` or `require` condition to be used during resolution regardless of module resolution
6044+
* settings. In absence of overriding attributes, and in modes that support differing resolution, the result indicates the syntax the
6045+
* usage would emit to JavaScript. Some examples:
6046+
*
6047+
* ```ts
6048+
* // tsc foo.mts --module nodenext
6049+
* import {} from "mod";
6050+
* // Result: ESNext - the import emits as ESM due to `impliedNodeFormat` set by .mts file extension
6051+
*
6052+
* // tsc foo.cts --module nodenext
6053+
* import {} from "mod";
6054+
* // Result: CommonJS - the import emits as CJS due to `impliedNodeFormat` set by .cts file extension
6055+
*
6056+
* // tsc foo.ts --module preserve --moduleResolution bundler
6057+
* import {} from "mod";
6058+
* // Result: ESNext - the import emits as ESM due to `--module preserve` and `--moduleResolution bundler`
6059+
* // supports conditional imports/exports
6060+
*
6061+
* // tsc foo.ts --module preserve --moduleResolution node10
6062+
* import {} from "mod";
6063+
* // Result: undefined - the import emits as ESM due to `--module preserve`, but `--moduleResolution node10`
6064+
* // does not support conditional imports/exports
6065+
*
6066+
* // tsc foo.ts --module commonjs --moduleResolution node10
6067+
* import type {} from "mod" with { "resolution-mode": "import" };
6068+
* // Result: ESNext - conditional imports/exports always supported with "resolution-mode" attribute
6069+
* ```
60226070
*/
60236071
getModeForResolutionAtIndex(file: SourceFile, index: number): ResolutionMode;
60246072
getProjectReferences(): readonly ProjectReference[] | undefined;
@@ -9366,24 +9414,43 @@ declare namespace ts {
93669414
function getModeForResolutionAtIndex(file: SourceFile, index: number, compilerOptions: CompilerOptions): ResolutionMode;
93679415
/**
93689416
* Use `program.getModeForUsageLocation`, which retrieves the correct `compilerOptions`, instead of this function whenever possible.
9369-
* Calculates the final resolution mode for a given module reference node. This is the resolution mode explicitly provided via import
9370-
* attributes, if present, or the syntax the usage would have if emitted to JavaScript. In `--module node16` or `nodenext`, this may
9371-
* depend on the file's `impliedNodeFormat`. In `--module preserve`, it depends only on the input syntax of the reference. In other
9372-
* `module` modes, when overriding import attributes are not provided, this function returns `undefined`, as the result would have no
9373-
* impact on module resolution, emit, or type checking.
9417+
* Calculates the final resolution mode for a given module reference node. This function only returns a result when module resolution
9418+
* settings allow differing resolution between ESM imports and CJS requires, or when a mode is explicitly provided via import attributes,
9419+
* which cause an `import` or `require` condition to be used during resolution regardless of module resolution settings. In absence of
9420+
* overriding attributes, and in modes that support differing resolution, the result indicates the syntax the usage would emit to JavaScript.
9421+
* Some examples:
9422+
*
9423+
* ```ts
9424+
* // tsc foo.mts --module nodenext
9425+
* import {} from "mod";
9426+
* // Result: ESNext - the import emits as ESM due to `impliedNodeFormat` set by .mts file extension
9427+
*
9428+
* // tsc foo.cts --module nodenext
9429+
* import {} from "mod";
9430+
* // Result: CommonJS - the import emits as CJS due to `impliedNodeFormat` set by .cts file extension
9431+
*
9432+
* // tsc foo.ts --module preserve --moduleResolution bundler
9433+
* import {} from "mod";
9434+
* // Result: ESNext - the import emits as ESM due to `--module preserve` and `--moduleResolution bundler`
9435+
* // supports conditional imports/exports
9436+
*
9437+
* // tsc foo.ts --module preserve --moduleResolution node10
9438+
* import {} from "mod";
9439+
* // Result: undefined - the import emits as ESM due to `--module preserve`, but `--moduleResolution node10`
9440+
* // does not support conditional imports/exports
9441+
*
9442+
* // tsc foo.ts --module commonjs --moduleResolution node10
9443+
* import type {} from "mod" with { "resolution-mode": "import" };
9444+
* // Result: ESNext - conditional imports/exports always supported with "resolution-mode" attribute
9445+
* ```
9446+
*
93749447
* @param file The file the import or import-like reference is contained within
93759448
* @param usage The module reference string
93769449
* @param compilerOptions The compiler options for the program that owns the file. If the file belongs to a referenced project, the compiler options
93779450
* should be the options of the referenced project, not the referencing project.
93789451
* @returns The final resolution mode of the import
93799452
*/
9380-
function getModeForUsageLocation(
9381-
file: {
9382-
impliedNodeFormat?: ResolutionMode;
9383-
},
9384-
usage: StringLiteralLike,
9385-
compilerOptions: CompilerOptions,
9386-
): ModuleKind.CommonJS | ModuleKind.ESNext | undefined;
9453+
function getModeForUsageLocation(file: SourceFile, usage: StringLiteralLike, compilerOptions: CompilerOptions): ResolutionMode;
93879454
function getConfigFileParsingDiagnostics(configFileParseResult: ParsedCommandLine): readonly Diagnostic[];
93889455
/**
93899456
* A function for determining if a given file is esm or cjs format, assuming modern node module resolution rules, as configured by the

tests/baselines/reference/bundlerImportESM(module=esnext).js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ import { esm } from "./esm.mjs";
1616
//// [esm.mjs]
1717
export var esm = 0;
1818
//// [not-actually-cjs.cjs]
19-
export {};
19+
"use strict";
20+
Object.defineProperty(exports, "__esModule", { value: true });
2021
//// [still-not-cjs.js]
21-
export {};
22+
"use strict";
23+
Object.defineProperty(exports, "__esModule", { value: true });

tests/baselines/reference/bundlerNodeModules1(module=esnext).errors.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error TS6504: File '/node_modules/dual/index.cjs' is a JavaScript file. Did you
44
error TS6504: File '/node_modules/dual/index.js' is a JavaScript file. Did you mean to enable the 'allowJs' option?
55
The file is in the program because:
66
Root file specified for compilation
7-
/main.cts(1,15): error TS2305: Module '"dual"' has no exported member 'cjs'.
7+
/main.cts(1,10): error TS2305: Module '"dual"' has no exported member 'esm'.
88
/main.mts(1,15): error TS2305: Module '"dual"' has no exported member 'cjs'.
99
/main.ts(1,15): error TS2305: Module '"dual"' has no exported member 'cjs'.
1010

@@ -54,6 +54,6 @@ error TS6504: File '/node_modules/dual/index.js' is a JavaScript file. Did you m
5454

5555
==== /main.cts (1 errors) ====
5656
import { esm, cjs } from "dual";
57-
~~~
58-
!!! error TS2305: Module '"dual"' has no exported member 'cjs'.
57+
~~~
58+
!!! error TS2305: Module '"dual"' has no exported member 'esm'.
5959

tests/baselines/reference/bundlerNodeModules1(module=esnext).js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,5 @@ export {};
4242
//// [main.mjs]
4343
export {};
4444
//// [main.cjs]
45-
export {};
45+
"use strict";
46+
Object.defineProperty(exports, "__esModule", { value: true });

tests/baselines/reference/bundlerNodeModules1(module=esnext).types

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@ import { esm, cjs } from "dual";
2020

2121
=== /main.cts ===
2222
import { esm, cjs } from "dual";
23-
>esm : number
24-
>cjs : any
23+
>esm : any
24+
>cjs : number
2525

tests/baselines/reference/bundlerNodeModules1(module=preserve).errors.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error TS6504: File '/node_modules/dual/index.cjs' is a JavaScript file. Did you
44
error TS6504: File '/node_modules/dual/index.js' is a JavaScript file. Did you mean to enable the 'allowJs' option?
55
The file is in the program because:
66
Root file specified for compilation
7-
/main.cts(1,15): error TS2305: Module '"dual"' has no exported member 'cjs'.
7+
/main.cts(1,10): error TS2305: Module '"dual"' has no exported member 'esm'.
88
/main.mts(1,15): error TS2305: Module '"dual"' has no exported member 'cjs'.
99
/main.ts(1,15): error TS2305: Module '"dual"' has no exported member 'cjs'.
1010

@@ -54,6 +54,6 @@ error TS6504: File '/node_modules/dual/index.js' is a JavaScript file. Did you m
5454

5555
==== /main.cts (1 errors) ====
5656
import { esm, cjs } from "dual";
57-
~~~
58-
!!! error TS2305: Module '"dual"' has no exported member 'cjs'.
57+
~~~
58+
!!! error TS2305: Module '"dual"' has no exported member 'esm'.
5959

tests/baselines/reference/bundlerNodeModules1(module=preserve).types

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@ import { esm, cjs } from "dual";
2020

2121
=== /main.cts ===
2222
import { esm, cjs } from "dual";
23-
>esm : number
24-
>cjs : any
23+
>esm : any
24+
>cjs : number
2525

tests/baselines/reference/conditionalExportsResolutionFallback(moduleresolution=bundler).errors.txt

Lines changed: 0 additions & 29 deletions
This file was deleted.

tests/baselines/reference/customConditions(resolvepackagejsonexports=false).errors.txt

Lines changed: 0 additions & 31 deletions
This file was deleted.

tests/baselines/reference/customConditions(resolvepackagejsonexports=false).js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,3 @@ import _ from "lodash";
2929

3030

3131
//// [index.js]
32-
"use strict";
33-
Object.defineProperty(exports, "__esModule", { value: true });

tests/baselines/reference/customConditions(resolvepackagejsonexports=true).errors.txt

Lines changed: 0 additions & 31 deletions
This file was deleted.

tests/baselines/reference/customConditions(resolvepackagejsonexports=true).js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,3 @@ import _ from "lodash";
2929

3030

3131
//// [index.js]
32-
"use strict";
33-
Object.defineProperty(exports, "__esModule", { value: true });

tests/baselines/reference/legacyNodeModulesExportsSpecifierGenerationConditions.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ export interface Thing {} // not exported in export map, inaccessible under new
3232
}
3333

3434
//// [index.js]
35-
"use strict";
3635
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3736
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3837
return new (P || (P = Promise))(function (resolve, reject) {
@@ -69,15 +68,12 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
6968
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
7069
}
7170
};
72-
Object.defineProperty(exports, "__esModule", { value: true });
73-
exports.a = void 0;
74-
var a = function () { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
71+
export var a = function () { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
7572
switch (_a.label) {
76-
case 0: return [4 /*yield*/, Promise.resolve().then(function () { return require("inner"); })];
73+
case 0: return [4 /*yield*/, import("inner")];
7774
case 1: return [2 /*return*/, (_a.sent()).x()];
7875
}
7976
}); }); };
80-
exports.a = a;
8177

8278

8379
//// [index.d.ts]

tests/baselines/reference/moduleDetectionIsolatedModulesCjsFileScope.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ const a = 2;
66
const a = 2;
77

88
//// [filename.cjs]
9+
"use strict";
10+
Object.defineProperty(exports, "__esModule", { value: true });
911
const a = 2;
10-
export {};
1112
//// [filename.mjs]
1213
const a = 2;
1314
export {};

0 commit comments

Comments
 (0)