Skip to content

Commit

Permalink
Update existing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewbranch committed Mar 21, 2024
1 parent 11e5727 commit f9f46fd
Show file tree
Hide file tree
Showing 26 changed files with 183 additions and 151 deletions.
111 changes: 89 additions & 22 deletions tests/baselines/reference/api/typescript.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6006,19 +6006,67 @@ declare namespace ts {
isSourceFileFromExternalLibrary(file: SourceFile): boolean;
isSourceFileDefaultLibrary(file: SourceFile): boolean;
/**
* Calculates the final resolution mode for a given module reference node. This is the resolution mode explicitly provided via import
* attributes, if present, or the syntax the usage would have if emitted to JavaScript. In `--module node16` or `nodenext`, this may
* depend on the file's `impliedNodeFormat`. In `--module preserve`, it depends only on the input syntax of the reference. In other
* `module` modes, when overriding import attributes are not provided, this function returns `undefined`, as the result would have no
* impact on module resolution, emit, or type checking.
* Calculates the final resolution mode for a given module reference node. This function only returns a result when module resolution
* settings allow differing resolution between ESM imports and CJS requires, or when a mode is explicitly provided via import attributes,
* which cause an `import` or `require` condition to be used during resolution regardless of module resolution settings. In absence of
* overriding attributes, and in modes that support differing resolution, the result indicates the syntax the usage would emit to JavaScript.
* Some examples:
*
* ```ts
* // tsc foo.mts --module nodenext
* import {} from "mod";
* // Result: ESNext - the import emits as ESM due to `impliedNodeFormat` set by .mts file extension
*
* // tsc foo.cts --module nodenext
* import {} from "mod";
* // Result: CommonJS - the import emits as CJS due to `impliedNodeFormat` set by .cts file extension
*
* // tsc foo.ts --module preserve --moduleResolution bundler
* import {} from "mod";
* // Result: ESNext - the import emits as ESM due to `--module preserve` and `--moduleResolution bundler`
* // supports conditional imports/exports
*
* // tsc foo.ts --module preserve --moduleResolution node10
* import {} from "mod";
* // Result: undefined - the import emits as ESM due to `--module preserve`, but `--moduleResolution node10`
* // does not support conditional imports/exports
*
* // tsc foo.ts --module commonjs --moduleResolution node10
* import type {} from "mod" with { "resolution-mode": "import" };
* // Result: ESNext - conditional imports/exports always supported with "resolution-mode" attribute
* ```
*/
getModeForUsageLocation(file: SourceFile, usage: StringLiteralLike): ResolutionMode;
/**
* Calculates the final resolution mode for an import at some index within a file's `imports` list. This is the resolution mode
* explicitly provided via import attributes, if present, or the syntax the usage would have if emitted to JavaScript. In
* `--module node16` or `nodenext`, this may depend on the file's `impliedNodeFormat`. In `--module preserve`, it depends only on the
* input syntax of the reference. In other `module` modes, when overriding import attributes are not provided, this function returns
* `undefined`, as the result would have no impact on module resolution, emit, or type checking.
* Calculates the final resolution mode for an import at some index within a file's `imports` list. This function only returns a result
* when module resolution settings allow differing resolution between ESM imports and CJS requires, or when a mode is explicitly provided
* via import attributes, which cause an `import` or `require` condition to be used during resolution regardless of module resolution
* settings. In absence of overriding attributes, and in modes that support differing resolution, the result indicates the syntax the
* usage would emit to JavaScript. Some examples:
*
* ```ts
* // tsc foo.mts --module nodenext
* import {} from "mod";
* // Result: ESNext - the import emits as ESM due to `impliedNodeFormat` set by .mts file extension
*
* // tsc foo.cts --module nodenext
* import {} from "mod";
* // Result: CommonJS - the import emits as CJS due to `impliedNodeFormat` set by .cts file extension
*
* // tsc foo.ts --module preserve --moduleResolution bundler
* import {} from "mod";
* // Result: ESNext - the import emits as ESM due to `--module preserve` and `--moduleResolution bundler`
* // supports conditional imports/exports
*
* // tsc foo.ts --module preserve --moduleResolution node10
* import {} from "mod";
* // Result: undefined - the import emits as ESM due to `--module preserve`, but `--moduleResolution node10`
* // does not support conditional imports/exports
*
* // tsc foo.ts --module commonjs --moduleResolution node10
* import type {} from "mod" with { "resolution-mode": "import" };
* // Result: ESNext - conditional imports/exports always supported with "resolution-mode" attribute
* ```
*/
getModeForResolutionAtIndex(file: SourceFile, index: number): ResolutionMode;
getProjectReferences(): readonly ProjectReference[] | undefined;
Expand Down Expand Up @@ -9366,24 +9414,43 @@ declare namespace ts {
function getModeForResolutionAtIndex(file: SourceFile, index: number, compilerOptions: CompilerOptions): ResolutionMode;
/**
* Use `program.getModeForUsageLocation`, which retrieves the correct `compilerOptions`, instead of this function whenever possible.
* Calculates the final resolution mode for a given module reference node. This is the resolution mode explicitly provided via import
* attributes, if present, or the syntax the usage would have if emitted to JavaScript. In `--module node16` or `nodenext`, this may
* depend on the file's `impliedNodeFormat`. In `--module preserve`, it depends only on the input syntax of the reference. In other
* `module` modes, when overriding import attributes are not provided, this function returns `undefined`, as the result would have no
* impact on module resolution, emit, or type checking.
* Calculates the final resolution mode for a given module reference node. This function only returns a result when module resolution
* settings allow differing resolution between ESM imports and CJS requires, or when a mode is explicitly provided via import attributes,
* which cause an `import` or `require` condition to be used during resolution regardless of module resolution settings. In absence of
* overriding attributes, and in modes that support differing resolution, the result indicates the syntax the usage would emit to JavaScript.
* Some examples:
*
* ```ts
* // tsc foo.mts --module nodenext
* import {} from "mod";
* // Result: ESNext - the import emits as ESM due to `impliedNodeFormat` set by .mts file extension
*
* // tsc foo.cts --module nodenext
* import {} from "mod";
* // Result: CommonJS - the import emits as CJS due to `impliedNodeFormat` set by .cts file extension
*
* // tsc foo.ts --module preserve --moduleResolution bundler
* import {} from "mod";
* // Result: ESNext - the import emits as ESM due to `--module preserve` and `--moduleResolution bundler`
* // supports conditional imports/exports
*
* // tsc foo.ts --module preserve --moduleResolution node10
* import {} from "mod";
* // Result: undefined - the import emits as ESM due to `--module preserve`, but `--moduleResolution node10`
* // does not support conditional imports/exports
*
* // tsc foo.ts --module commonjs --moduleResolution node10
* import type {} from "mod" with { "resolution-mode": "import" };
* // Result: ESNext - conditional imports/exports always supported with "resolution-mode" attribute
* ```
*
* @param file The file the import or import-like reference is contained within
* @param usage The module reference string
* @param compilerOptions The compiler options for the program that owns the file. If the file belongs to a referenced project, the compiler options
* should be the options of the referenced project, not the referencing project.
* @returns The final resolution mode of the import
*/
function getModeForUsageLocation(
file: {
impliedNodeFormat?: ResolutionMode;
},
usage: StringLiteralLike,
compilerOptions: CompilerOptions,
): ModuleKind.CommonJS | ModuleKind.ESNext | undefined;
function getModeForUsageLocation(file: SourceFile, usage: StringLiteralLike, compilerOptions: CompilerOptions): ResolutionMode;
function getConfigFileParsingDiagnostics(configFileParseResult: ParsedCommandLine): readonly Diagnostic[];
/**
* A function for determining if a given file is esm or cjs format, assuming modern node module resolution rules, as configured by the
Expand Down
6 changes: 4 additions & 2 deletions tests/baselines/reference/bundlerImportESM(module=esnext).js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import { esm } from "./esm.mjs";
//// [esm.mjs]
export var esm = 0;
//// [not-actually-cjs.cjs]
export {};
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//// [still-not-cjs.js]
export {};
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ error TS6504: File '/node_modules/dual/index.cjs' is a JavaScript file. Did you
error TS6504: File '/node_modules/dual/index.js' is a JavaScript file. Did you mean to enable the 'allowJs' option?
The file is in the program because:
Root file specified for compilation
/main.cts(1,15): error TS2305: Module '"dual"' has no exported member 'cjs'.
/main.cts(1,10): error TS2305: Module '"dual"' has no exported member 'esm'.
/main.mts(1,15): error TS2305: Module '"dual"' has no exported member 'cjs'.
/main.ts(1,15): error TS2305: Module '"dual"' has no exported member 'cjs'.

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

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

Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,5 @@ export {};
//// [main.mjs]
export {};
//// [main.cjs]
export {};
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ import { esm, cjs } from "dual";

=== /main.cts ===
import { esm, cjs } from "dual";
>esm : number
>cjs : any
>esm : any
>cjs : number

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ error TS6504: File '/node_modules/dual/index.cjs' is a JavaScript file. Did you
error TS6504: File '/node_modules/dual/index.js' is a JavaScript file. Did you mean to enable the 'allowJs' option?
The file is in the program because:
Root file specified for compilation
/main.cts(1,15): error TS2305: Module '"dual"' has no exported member 'cjs'.
/main.cts(1,10): error TS2305: Module '"dual"' has no exported member 'esm'.
/main.mts(1,15): error TS2305: Module '"dual"' has no exported member 'cjs'.
/main.ts(1,15): error TS2305: Module '"dual"' has no exported member 'cjs'.

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

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

Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ import { esm, cjs } from "dual";

=== /main.cts ===
import { esm, cjs } from "dual";
>esm : number
>cjs : any
>esm : any
>cjs : number

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,3 @@ import _ from "lodash";


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

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,3 @@ import _ from "lodash";


//// [index.js]
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ export interface Thing {} // not exported in export map, inaccessible under new
}

//// [index.js]
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
Expand Down Expand Up @@ -69,15 +68,12 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.a = void 0;
var a = function () { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
export var a = function () { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, Promise.resolve().then(function () { return require("inner"); })];
case 0: return [4 /*yield*/, import("inner")];
case 1: return [2 /*return*/, (_a.sent()).x()];
}
}); }); };
exports.a = a;


//// [index.d.ts]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ const a = 2;
const a = 2;

//// [filename.cjs]
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const a = 2;
export {};
//// [filename.mjs]
const a = 2;
export {};
Expand Down
Loading

0 comments on commit f9f46fd

Please sign in to comment.