8000 `moduleResolution: node12` support by weswigham · Pull Request #45884 · microsoft/TypeScript · GitHub
[go: up one dir, main page]

Skip to content

moduleResolution: node12 support #45884

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

Merged
merged 31 commits into from
Sep 24, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
c416aa9
Initial support for module: node12
weswigham Jun 8, 2021
34812f0
Add allowJs and declaration emit enabled tests
weswigham Jun 8, 2021
b447ed7
Fix typos
weswigham Jul 12, 2021
9b83a2e
cts, mts, cjs, mjs, etc extension support
weswigham Jul 6, 2021
44675c9
Merge branch 'main' into module-node
weswigham Aug 26, 2021
55d0728
Merge branch 'module-node' into mjscjs-support
weswigham Aug 26, 2021
e6a386c
Fix watch of files whose intepretation changes due to a package.json …
weswigham Aug 26, 2021
fd2190f
Merge branch 'main' into module-node
weswigham Sep 1, 2021
13e76d7
Merge branch 'module-node' into mjscjs-support
weswigham Sep 1, 2021
b12315f
Minor PR feedback
weswigham Sep 1, 2021
15e1904
Adjust error message
weswigham Sep 1, 2021
093002c
Initial import/export/self-name support
weswigham Sep 14, 2021
4ab3f7e
Merge branch 'main' into module-node
weswigham Sep 15, 2021
a092fd3
Merge branch 'module-node' into mjscjs-support
weswigham Sep 15, 2021
5bf44ac
Accept new error codes
weswigham Sep 15, 2021
859abb6
Merge branch 'mjscjs-support' into imports-exports-selfs
weswigham Sep 15, 2021
c21cb48
TypesVersions support in export/import map conditions
weswigham Sep 15, 2021
9294633
Fix import suggestion and autoimport default extensions under new res…
weswigham Sep 20, 2021
c776453
Add tests for import maps non-relative name lookup feature
weswigham Sep 20, 2021
ae83938
Fix isDeclarationFileName for .d.mts and .d.cts
weswigham Sep 20, 2021
8ab7517
Preserve new extensions when generating module specifiers
weswigham Sep 20, 2021
222ba00
Fix spurious implict any suggestion caused by file ordering bug and o…
weswigham Sep 21, 2021
408ef20
Fix a bunch of incremental bugs that dont repro under fourslash for s…
weswigham Sep 21, 2021
6aaa681
Merge branch 'main' into module-node
weswigham Sep 21, 2021
21b73e8
Accept updated baseline
weswigham Sep 21, 2021
c160805
Merge branch 'module-node' into mjscjs-support
weswigham Sep 21, 2021
44b81b2
Merge branch 'mjscjs-support' into imports-exports-selfs
weswigham Sep 21, 2021
4a33975
Always include extensions on completions for cjs/mjs style imports
weswigham Sep 21, 2021
76afb79
String completion relative import suggestions respect the mode of the…
weswigham Sep 21, 2021
0891db4
Style feedback
weswigham Sep 23, 2021
a2e799a
Change diagnostic case
weswigham Sep 24, 2021
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 allowJs and declaration emit enabled tests
  • Loading branch information
weswigham committed Jul 12, 2021
commit 34812f09ba623ed1ee14a779f6da697de2d19e69
26 changes: 25 additions & 1 deletion src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7142,6 +7142,28 @@ namespace ts {
), symbol.declarations && filter(symbol.declarations, d => isClassDeclaration(d) || isClassExpression(d))[0]), modifierFlags);
}

function getSomeTargetNameFromDeclarations(declarations: Declaration[] | undefined) {
return firstDefined(declarations, d => {
if (isImportSpecifier(d) || isExportSpecifier(d)) {
return idText(d.propertyName || d.name);
}
if (isBinaryExpression(d) || isExportAssignment(d)) {
const expression = isExportAssignment(d) ? d.expression : d.right;
if (isPropertyAccessExpression(expression)) {
return idText(expression.name);
}
}
if (isAliasSymbolDeclaration(d)) {
// This is... heuristic, at best. But it's probably better than always printing the name of the shorthand ambient module.
const name = getNameOfDeclaration(d);
if (name && isIdentifier(name)) {
return idText(name);
}
}
return undefined;
});
}

function serializeAsAlias(symbol: Symbol, localName: string, modifierFlags: ModifierFlags) {
// synthesize an alias, eg `export { symbolName as Name }`
// need to mark the alias `symbol` points at
Expand All @@ -7152,7 +7174,9 @@ namespace ts {
if (!target) {
return;
}
let verbatimTargetName = unescapeLeadingUnderscores(target.escapedName);
// If `target` refers to a shorthand module symbol, the name we're trying to pull out isn;t recoverable from the target symbol
// In such a scenario, we must fall back to looking for an alias declaration on `symbol` and pulling the target name from that
let verbatimTargetName = isShorthandAmbientModuleSymbol(target) && getSomeTargetNameFromDeclarations(symbol.declarations) || unescapeLeadingUnderscores(target.escapedName);
if (verbatimTargetName === InternalSymbolName.ExportEquals && (getESModuleInterop(compilerOptions) || compilerOptions.allowSyntheticDefaultImports)) {
// target refers to an `export=` symbol that was hoisted into a synthetic default - rename here to match
verbatimTargetName = InternalSymbolName.Default;
Expand Down
14 changes: 14 additions & 0 deletions tests/baselines/reference/nodeModules1(module=node12).js
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,17 @@ export { x };
// esm format file
const x = 1;
export { x };


//// [index.d.ts]
declare const x = 1;
export { x };
//// [index.d.ts]
declare const x = 1;
export { x };
//// [index.d.ts]
declare const x = 1;
export { x };
//// [index.d.ts]
declare const x = 1;
export { x };
14 changes: 14 additions & 0 deletions tests/baselines/reference/nodeModules1(module=nodenext).js
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,17 @@ export { x };
// esm format file
const x = 1;
export { x };


//// [index.d.ts]
declare const x = 1;
export { x };
//// [index.d.ts]
declare const x = 1;
export { x };
//// [index.d.ts]
declare const x = 1;
export { x };
//// [index.d.ts]
declare const x = 1;
export { x };
68 changes: 68 additions & 0 deletions tests/baselines/reference/nodeModulesAllowJs1(module=node12).js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
//// [tests/cases/conformance/node/allowJs/nodeModulesAllowJs1.ts] ////

//// [index.js]
// cjs format file
const x = 1;
export {x};
//// [index.js]
// cjs format file
const x = 1;
export {x};
//// [index.js]
// esm format file
const x = 1;
export {x};
//// [index.js]
// esm format file
const x = 1;
export {x};
//// [package.json]
{
"name": "package",
"private": true,
"type": "module"
}
//// [package.json]
{
"type": "commonjs"
}
//// [package.json]
{
}
//// [package.json]
{
"type": "module"
}

//// [index.js]
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.x = void 0;
// cjs format file
const x = 1;
exports.x = x;
//// [index.js]
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.x = void 0;
// cjs format file
const x = 1;
exports.x = x;
//// [index.js]
// esm format file
const x = 1;
export { x };
//// [index.js]
// esm format file
const x = 1;
export { x };


//// [index.d.ts]
export const x: 1;
//// [index.d.ts]
export const x: 1;
//// [index.d.ts]
export const x: 1;
//// [index.d.ts]
export const x: 1;
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
=== tests/cases/conformance/node/allowJs/subfolder/index.js ===
// cjs format file
const x = 1;
>x : Symbol(x, Decl(index.js, 1, 5))

export {x};
>x : Symbol(x, Decl(index.js, 2, 8))

=== tests/cases/conformance/node/allowJs/subfolder2/index.js ===
// cjs format file
const x = 1;
>x : Symbol(x, Decl(index.js, 1, 5))

export {x};
>x : Symbol(x, Decl(index.js, 2, 8))

=== tests/cases/conformance/node/allowJs/subfolder2/another/index.js ===
// esm format file
const x = 1;
>x : Symbol(x, Decl(index.js, 1, 5))

export {x};
>x : Symbol(x, Decl(index.js, 2, 8))

=== tests/cases/conformance/node/allowJs/index.js ===
// esm format file
const x = 1;
>x : Symbol(x, Decl(index.js, 1, 5))

export {x};
>x : Symbol(x, Decl(index.js, 2, 8))

36 changes: 36 additions & 0 deletions tests/baselines/reference/nodeModulesAllowJs1(module=node12).types
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
=== tests/cases/conformance/node/allowJs/subfolder/index.js ===
// cjs format file
const x = 1;
>x : 1
>1 : 1

export {x};
>x : 1

=== tests/cases/conformance/node/allowJs/subfolder2/index.js ===
// cjs format file
const x = 1;
>x : 1
>1 : 1

export {x};
>x : 1

=== tests/cases/conformance/node/allowJs/subfolder2/another/index.js ===
// esm format file
const x = 1;
>x : 1
>1 : 1

export {x};
>x : 1

=== tests/cases/conformance/node/allowJs/index.js ===
// esm format file
const x = 1;
>x : 1
>1 : 1

export {x};
>x : 1

68 changes: 68 additions & 0 deletions tests/baselines/reference/nodeModulesAllowJs1(module=nodenext).js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
//// [tests/cases/conformance/node/allowJs/nodeModulesAllowJs1.ts] ////

//// [index.js]
// cjs format file
const x = 1;
export {x};
//// [index.js]
// cjs format file
const x = 1;
export {x};
//// [index.js]
// esm format file
const x = 1;
export {x};
//// [index.js]
// esm format file
const x = 1;
export {x};
//// [package.json]
{
"name": "package",
"private": true,
"type": "module"
}
//// [package.json]
{
"type": "commonjs"
}
//// [package.json]
{
}
//// [package.json]
{
"type": "module"
}

//// [index.js]
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.x = void 0;
// cjs format file
const x = 1;
exports.x = x;
//// [index.js]
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.x = void 0;
// cjs format file
const x = 1;
exports.x = x;
//// [index.js]
// esm format file
const x = 1;
export { x };
//// [index.js]
// esm format file
const x = 1;
export { x };


//// [index.d.ts]
export const x: 1;
//// [index.d.ts]
export const x: 1;
//// [index.d.ts]
export const x: 1;
//// [index.d.ts]
export const x: 1;
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
=== tests/cases/conformance/node/allowJs/subfolder/index.js ===
// cjs format file
const x = 1;
>x : Symbol(x, Decl(index.js, 1, 5))

export {x};
>x : Symbol(x, Decl(index.js, 2, 8))

=== tests/cases/conformance/node/allowJs/subfolder2/index.js ===
// cjs format file
const x = 1;
>x : Symbol(x, Decl(index.js, 1, 5))

export {x};
>x : Symbol(x, Decl(index.js, 2, 8))

=== tests/cases/conformance/node/allowJs/subfolder2/another/index.js ===
// esm format file
const x = 1;
>x : Symbol(x, Decl(index.js, 1, 5))

export {x};
>x : Symbol(x, Decl(index.js, 2, 8))

=== tests/cases/conformance/node/allowJs/index.js ===
// esm format file
const x = 1;
>x : Symbol(x, Decl(index.js, 1, 5))

export {x};
>x : Symbol(x, Decl(index.js, 2, 8))

Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
=== tests/cases/conformance/node/allowJs/subfolder/index.js ===
// cjs format file
const x = 1;
>x : 1
>1 : 1

export {x};
>x : 1

=== tests/cases/conformance/node/allowJs/subfolder2/index.js ===
// cjs format file
const x = 1;
>x : 1
>1 : 1

export {x};
>x : 1

=== tests/cases/conformance/node/allowJs/subfolder2/another/index.js ===
// esm format file
const x = 1;
>x : 1
>1 : 1

export {x};
>x : 1

=== tests/cases/conformance/node/allowJs/index.js ===
// esm format file
const x = 1;
>x : 1
>1 : 1

export {x};
>x : 1

Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
//// [tests/cases/conformance/node/allowJs/nodeModulesAllowJsDynamicImport.ts] ////

//// [index.js]
// cjs format file
export async function main() {
const { readFile } = await import("fs");
}
//// [index.js]
// esm format file
export async function main() {
const { readFile } = await import("fs");
}
//// [package.json]
{
"name": "package",
"private": true,
"type": "module"
}
//// [package.json]
{
"type": "commonjs"
}
//// [types.d.ts]
declare module "fs";

//// [index.js]
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.main = void 0;
// cjs format file
async function main() {
const { readFile } = await import("fs");
}
exports.main = main;
//// [index.js]
// esm format file
export async function main() {
const { readFile } = await import("fs");
}


//// [index.d.ts]
export function main(): Promise<void>;
//// [index.d.ts]
export function main(): Promise<void>;
Loading
0