Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Respect package.json "type" and module-format-specific file extensions in more module modes #57896

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add new tests
  • Loading branch information
andrewbranch committed Mar 21, 2024
commit 09330b8d4c663035a1a5ceb350f4dc7a43548b43
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/index.ts(1,8): error TS1192: Module '"/node_modules/mdast-util-to-string/index"' has no default export.
/index.ts(7,8): error TS2339: Property 'default' does not exist on type 'typeof import("/node_modules/mdast-util-to-string/index")'.


==== /node_modules/mdast-util-to-string/package.json (0 errors) ====
{ "type": "module" }

==== /node_modules/mdast-util-to-string/index.d.ts (0 errors) ====
export function toString(): string;

==== /index.ts (2 errors) ====
import mdast, { toString } from 'mdast-util-to-string';
~~~~~
!!! error TS1192: Module '"/node_modules/mdast-util-to-string/index"' has no default export.
mdast;
mdast.toString();

const mdast2 = await import('mdast-util-to-string');
mdast2.toString();
mdast2.default;
~~~~~~~
!!! error TS2339: Property 'default' does not exist on type 'typeof import("/node_modules/mdast-util-to-string/index")'.

Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//// [tests/cases/compiler/esmNoSynthesizedDefault.ts] ////

//// [package.json]
{ "type": "module" }

//// [index.d.ts]
export function toString(): string;

//// [index.ts]
import mdast, { toString } from 'mdast-util-to-string';
mdast;
mdast.toString();

const mdast2 = await import('mdast-util-to-string');
mdast2.toString();
mdast2.default;


//// [index.js]
import mdast from 'mdast-util-to-string';
mdast;
mdast.toString();
const mdast2 = await import('mdast-util-to-string');
mdast2.toString();
mdast2.default;
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//// [tests/cases/compiler/esmNoSynthesizedDefault.ts] ////

=== /node_modules/mdast-util-to-string/index.d.ts ===
export function toString(): string;
>toString : Symbol(toString, Decl(index.d.ts, 0, 0))

=== /index.ts ===
import mdast, { toString } from 'mdast-util-to-string';
>mdast : Symbol(mdast, Decl(index.ts, 0, 6))
>toString : Symbol(toString, Decl(index.ts, 0, 15))

mdast;
>mdast : Symbol(mdast, Decl(index.ts, 0, 6))

mdast.toString();
>mdast : Symbol(mdast, Decl(index.ts, 0, 6))

const mdast2 = await import('mdast-util-to-string');
>mdast2 : Symbol(mdast2, Decl(index.ts, 4, 5))
>'mdast-util-to-string' : Symbol("/node_modules/mdast-util-to-string/index", Decl(index.d.ts, 0, 0))

mdast2.toString();
>mdast2.toString : Symbol(toString, Decl(index.d.ts, 0, 0))
>mdast2 : Symbol(mdast2, Decl(index.ts, 4, 5))
>toString : Symbol(toString, Decl(index.d.ts, 0, 0))

mdast2.default;
>mdast2 : Symbol(mdast2, Decl(index.ts, 4, 5))

Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//// [tests/cases/compiler/esmNoSynthesizedDefault.ts] ////

=== /node_modules/mdast-util-to-string/index.d.ts ===
export function toString(): string;
>toString : () => string

=== /index.ts ===
import mdast, { toString } from 'mdast-util-to-string';
>mdast : any
>toString : () => string

mdast;
>mdast : any

mdast.toString();
>mdast.toString() : any
>mdast.toString : any
>mdast : any
>toString : any

const mdast2 = await import('mdast-util-to-string');
>mdast2 : typeof import("/node_modules/mdast-util-to-string/index")
>await import('mdast-util-to-string') : typeof import("/node_modules/mdast-util-to-string/index")
>import('mdast-util-to-string') : Promise<typeof import("/node_modules/mdast-util-to-string/index")>
>'mdast-util-to-string' : "mdast-util-to-string"

mdast2.toString();
>mdast2.toString() : string
>mdast2.toString : () => string
>mdast2 : typeof import("/node_modules/mdast-util-to-string/index")
>toString : () => string

mdast2.default;
>mdast2.default : any
>mdast2 : typeof import("/node_modules/mdast-util-to-string/index")
>default : any

Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/index.ts(1,8): error TS1192: Module '"/node_modules/mdast-util-to-string/index"' has no default export.
/index.ts(7,8): error TS2339: Property 'default' does not exist on type 'typeof import("/node_modules/mdast-util-to-string/index")'.


==== /node_modules/mdast-util-to-string/package.json (0 errors) ====
{ "type": "module" }

==== /node_modules/mdast-util-to-string/index.d.ts (0 errors) ====
export function toString(): string;

==== /index.ts (2 errors) ====
import mdast, { toString } from 'mdast-util-to-string';
~~~~~
!!! error TS1192: Module '"/node_modules/mdast-util-to-string/index"' has no default export.
mdast;
mdast.toString();

const mdast2 = await import('mdast-util-to-string');
mdast2.toString();
mdast2.default;
~~~~~~~
!!! error TS2339: Property 'default' does not exist on type 'typeof import("/node_modules/mdast-util-to-string/index")'.

Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//// [tests/cases/compiler/esmNoSynthesizedDefault.ts] ////

//// [package.json]
{ "type": "module" }

//// [index.d.ts]
export function toString(): string;

//// [index.ts]
import mdast, { toString } from 'mdast-util-to-string';
mdast;
mdast.toString();

const mdast2 = await import('mdast-util-to-string');
mdast2.toString();
mdast2.default;


//// [index.js]
import mdast from 'mdast-util-to-string';
mdast;
mdast.toString();
const mdast2 = await import('mdast-util-to-string');
mdast2.toString();
mdast2.default;
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//// [tests/cases/compiler/esmNoSynthesizedDefault.ts] ////

=== /node_modules/mdast-util-to-string/index.d.ts ===
export function toString(): string;
>toString : Symbol(toString, Decl(index.d.ts, 0, 0))

=== /index.ts ===
import mdast, { toString } from 'mdast-util-to-string';
>mdast : Symbol(mdast, Decl(index.ts, 0, 6))
>toString : Symbol(toString, Decl(index.ts, 0, 15))

mdast;
>mdast : Symbol(mdast, Decl(index.ts, 0, 6))

mdast.toString();
>mdast : Symbol(mdast, Decl(index.ts, 0, 6))

const mdast2 = await import('mdast-util-to-string');
>mdast2 : Symbol(mdast2, Decl(index.ts, 4, 5))
>'mdast-util-to-string' : Symbol("/node_modules/mdast-util-to-string/index", Decl(index.d.ts, 0, 0))

mdast2.toString();
>mdast2.toString : Symbol(toString, Decl(index.d.ts, 0, 0))
>mdast2 : Symbol(mdast2, Decl(index.ts, 4, 5))
>toString : Symbol(toString, Decl(index.d.ts, 0, 0))

mdast2.default;
>mdast2 : Symbol(mdast2, Decl(index.ts, 4, 5))

Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//// [tests/cases/compiler/esmNoSynthesizedDefault.ts] ////

=== /node_modules/mdast-util-to-string/index.d.ts ===
export function toString(): string;
>toString : () => string

=== /index.ts ===
import mdast, { toString } from 'mdast-util-to-string';
>mdast : any
>toString : () => string

mdast;
>mdast : any

mdast.toString();
>mdast.toString() : any
>mdast.toString : any
>mdast : any
>toString : any

const mdast2 = await import('mdast-util-to-string');
>mdast2 : typeof import("/node_modules/mdast-util-to-string/index")
>await import('mdast-util-to-string') : typeof import("/node_modules/mdast-util-to-string/index")
>import('mdast-util-to-string') : Promise<typeof import("/node_modules/mdast-util-to-string/index")>
>'mdast-util-to-string' : "mdast-util-to-string"

mdast2.toString();
>mdast2.toString() : string
>mdast2.toString : () => string
>mdast2 : typeof import("/node_modules/mdast-util-to-string/index")
>toString : () => string

mdast2.default;
>mdast2.default : any
>mdast2 : typeof import("/node_modules/mdast-util-to-string/index")
>default : any

Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
error TS5095: Option 'bundler' can only be used when 'module' is set to 'preserve' or to 'es2015' or later.


!!! error TS5095: Option 'bundler' can only be used when 'module' is set to 'preserve' or to 'es2015' or later.
==== /a.ts (0 errors) ====
export const _ = 0;

==== /b.mts (0 errors) ====
export const _ = 0;

==== /c.cts (0 errors) ====
export const _ = 0;

==== /d.js (0 errors) ====
export const _ = 0;

==== /e.mjs (0 errors) ====
export const _ = 0;

==== /f.mjs (0 errors) ====
export const _ = 0;

==== /g.ts (0 errors) ====
import {} from "./a";
import a = require("./a");

==== /h.mts (0 errors) ====
import {} from "./a";
import a = require("./a");

==== /i.cts (0 errors) ====
import {} from "./a";
import a = require("./a");

==== /dummy.ts (0 errors) ====
export {};

98 changes: 98 additions & 0 deletions tests/baselines/reference/impliedNodeFormatEmit1(module=amd).js
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
//// [tests/cases/compiler/impliedNodeFormatEmit1.ts] ////

//// [a.ts]
export const _ = 0;

//// [b.mts]
export const _ = 0;

//// [c.cts]
export const _ = 0;

//// [d.js]
export const _ = 0;

//// [e.mjs]
export const _ = 0;

//// [f.mjs]
export const _ = 0;

//// [g.ts]
import {} from "./a";
import a = require("./a");

//// [h.mts]
import {} from "./a";
import a = require("./a");

//// [i.cts]
import {} from "./a";
import a = require("./a");

//// [dummy.ts]
export {};


//// [a.js]
define(["require", "exports"], function (require, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports._ = void 0;
exports._ = 0;
});
//// [b.mjs]
define(["require", "exports"], function (require, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports._ = void 0;
exports._ = 0;
});
//// [c.cjs]
define(["require", "exports"], function (require, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports._ = void 0;
exports._ = 0;
});
//// [d.js]
define(["require", "exports"], function (require, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports._ = void 0;
exports._ = 0;
});
//// [e.mjs]
define(["require", "exports"], function (require, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports._ = void 0;
exports._ = 0;
});
//// [f.mjs]
define(["require", "exports"], function (require, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports._ = void 0;
exports._ = 0;
});
//// [g.js]
define(["require", "exports"], function (require, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
});
//// [h.mjs]
define(["require", "exports"], function (require, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
});
//// [i.cjs]
define(["require", "exports"], function (require, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
});
//// [dummy.js]
define(["require", "exports"], function (require, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
});
Loading