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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃 Pick PR #47007 (Use features for selected module re...) into release-4.5 #47016

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 11 additions & 3 deletions src/compiler/moduleNameResolver.ts
Expand Up @@ -340,7 +340,11 @@ namespace ts {
}

const failedLookupLocations: string[] = [];
const moduleResolutionState: ModuleResolutionState = { compilerOptions: options, host, traceEnabled, failedLookupLocations, packageJsonInfoCache: cache, features: NodeResolutionFeatures.AllFeatures, conditions: ["node", "require", "types"] };
const features =
getEmitModuleResolutionKind(options) === ModuleResolutionKind.Node12 ? NodeResolutionFeatures.Node12Default :
getEmitModuleResolutionKind(options) === ModuleResolutionKind.NodeNext ? NodeResolutionFeatures.NodeNextDefault :
NodeResolutionFeatures.None;
const moduleResolutionState: ModuleResolutionState = { compilerOptions: options, host, traceEnabled, failedLookupLocations, packageJsonInfoCache: cache, features, conditions: ["node", "require", "types"] };
let resolved = primaryLookup();
let primary = true;
if (!resolved) {
Expand Down Expand Up @@ -1186,14 +1190,18 @@ namespace ts {
ExportsPatternTrailers = 1 << 4,
AllFeatures = Imports | SelfName | Exports | ExportsPatternTrailers,

Node12Default = Imports | SelfName | Exports,

NodeNextDefault = AllFeatures,

EsmMode = 1 << 5,
}

function node12ModuleNameResolver(moduleName: string, containingFile: string, compilerOptions: CompilerOptions,
host: ModuleResolutionHost, cache?: ModuleResolutionCache, redirectedReference?: ResolvedProjectReference,
resolutionMode?: ModuleKind.CommonJS | ModuleKind.ESNext): ResolvedModuleWithFailedLookupLocations {
return nodeNextModuleNameResolverWorker(
NodeResolutionFeatures.Imports | NodeResolutionFeatures.SelfName | NodeResolutionFeatures.Exports,
NodeResolutionFeatures.Node12Default,
moduleName,
containingFile,
compilerOptions,
Expand All @@ -1208,7 +1216,7 @@ namespace ts {
host: ModuleResolutionHost, cache?: ModuleResolutionCache, redirectedReference?: ResolvedProjectReference,
resolutionMode?: ModuleKind.CommonJS | ModuleKind.ESNext): ResolvedModuleWithFailedLookupLocations {
return nodeNextModuleNameResolverWorker(
NodeResolutionFeatures.AllFeatures,
NodeResolutionFeatures.NodeNextDefault,
moduleName,
containingFile,
compilerOptions,
Expand Down
@@ -0,0 +1,18 @@
//// [tests/cases/compiler/tripleSlashTypesReferenceWithMissingExports.ts] ////

//// [index.d.ts]
interface GlobalThing { a: number }
//// [package.json]
{
"name": "pkg",
"types": "index.d.ts",
"exports": "some-other-thing.js"
}
//// [usage.ts]
/// <reference types="pkg" />

const a: GlobalThing = { a: 0 };

//// [usage.js]
/// <reference types="pkg" />
var a = { a: 0 };
@@ -0,0 +1,13 @@
=== tests/cases/compiler/node_modules/pkg/index.d.ts ===
interface GlobalThing { a: number }
>GlobalThing : Symbol(GlobalThing, Decl(index.d.ts, 0, 0))
>a : Symbol(GlobalThing.a, Decl(index.d.ts, 0, 23))

=== tests/cases/compiler/usage.ts ===
/// <reference types="pkg" />

const a: GlobalThing = { a: 0 };
>a : Symbol(a, Decl(usage.ts, 2, 5))
>GlobalThing : Symbol(GlobalThing, Decl(index.d.ts, 0, 0))
>a : Symbol(a, Decl(usage.ts, 2, 24))

@@ -0,0 +1,13 @@
=== tests/cases/compiler/node_modules/pkg/index.d.ts ===
interface GlobalThing { a: number }
>a : number

=== tests/cases/compiler/usage.ts ===
/// <reference types="pkg" />

const a: GlobalThing = { a: 0 };
>a : GlobalThing
>{ a: 0 } : { a: number; }
>a : number
>0 : 0

@@ -0,0 +1,19 @@
error TS4124: Compiler option 'module' of value 'node12' is unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'.
tests/cases/compiler/usage.ts(1,23): error TS2688: Cannot find type definition file for 'pkg'.


!!! error TS4124: Compiler option 'module' of value 'node12' is unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'.
==== tests/cases/compiler/node_modules/pkg/index.d.ts (0 errors) ====
interface GlobalThing { a: number }
==== tests/cases/compiler/node_modules/pkg/package.json (0 errors) ====
{
"name": "pkg",
"types": "index.d.ts",
"exports": "some-other-thing.js"
}
==== tests/cases/compiler/usage.ts (1 errors) ====
/// <reference types="pkg" />
~~~
!!! error TS2688: Cannot find type definition file for 'pkg'.

const a: GlobalThing = { a: 0 };
@@ -0,0 +1,18 @@
//// [tests/cases/compiler/tripleSlashTypesReferenceWithMissingExports.ts] ////

//// [index.d.ts]
interface GlobalThing { a: number }
//// [package.json]
{
"name": "pkg",
"types": "index.d.ts",
"exports": "some-other-thing.js"
}
//// [usage.ts]
/// <reference types="pkg" />

const a: GlobalThing = { a: 0 };

//// [usage.js]
/// <reference types="pkg" />
const a = { a: 0 };
@@ -0,0 +1,13 @@
=== tests/cases/compiler/node_modules/pkg/index.d.ts ===
interface GlobalThing { a: number }
>GlobalThing : Symbol(GlobalThing, Decl(index.d.ts, 0, 0))
>a : Symbol(GlobalThing.a, Decl(index.d.ts, 0, 23))

=== tests/cases/compiler/usage.ts ===
/// <reference types="pkg" />

const a: GlobalThing = { a: 0 };
>a : Symbol(a, Decl(usage.ts, 2, 5))
>GlobalThing : Symbol(GlobalThing, Decl(index.d.ts, 0, 0))
>a : Symbol(a, Decl(usage.ts, 2, 24))

@@ -0,0 +1,13 @@
=== tests/cases/compiler/node_modules/pkg/index.d.ts ===
interface GlobalThing { a: number }
>a : number

=== tests/cases/compiler/usage.ts ===
/// <reference types="pkg" />

const a: GlobalThing = { a: 0 };
>a : GlobalThing
>{ a: 0 } : { a: number; }
>a : number
>0 : 0

@@ -0,0 +1,19 @@
error TS4124: Compiler option 'module' of value 'nodenext' is unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'.
tests/cases/compiler/usage.ts(1,23): error TS2688: Cannot find type definition file for 'pkg'.


!!! error TS4124: Compiler option 'module' of value 'nodenext' is unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'.
==== tests/cases/compiler/node_modules/pkg/index.d.ts (0 errors) ====
interface GlobalThing { a: number }
==== tests/cases/compiler/node_modules/pkg/package.json (0 errors) ====
{
"name": "pkg",
"types": "index.d.ts",
"exports": "some-other-thing.js"
}
==== tests/cases/compiler/usage.ts (1 errors) ====
/// <reference types="pkg" />
~~~
!!! error TS2688: Cannot find type definition file for 'pkg'.

const a: GlobalThing = { a: 0 };
@@ -0,0 +1,18 @@
//// [tests/cases/compiler/tripleSlashTypesReferenceWithMissingExports.ts] ////

//// [index.d.ts]
interface GlobalThing { a: number }
//// [package.json]
{
"name": "pkg",
"types": "index.d.ts",
"exports": "some-other-thing.js"
}
//// [usage.ts]
/// <reference types="pkg" />

const a: GlobalThing = { a: 0 };

//// [usage.js]
/// <reference types="pkg" />
const a = { a: 0 };
@@ -0,0 +1,13 @@
=== tests/cases/compiler/node_modules/pkg/index.d.ts ===
interface GlobalThing { a: number }
>GlobalThing : Symbol(GlobalThing, Decl(index.d.ts, 0, 0))
>a : Symbol(GlobalThing.a, Decl(index.d.ts, 0, 23))

=== tests/cases/compiler/usage.ts ===
/// <reference types="pkg" />

const a: GlobalThing = { a: 0 };
>a : Symbol(a, Decl(usage.ts, 2, 5))
>GlobalThing : Symbol(GlobalThing, Decl(index.d.ts, 0, 0))
>a : Symbol(a, Decl(usage.ts, 2, 24))

@@ -0,0 +1,13 @@
=== tests/cases/compiler/node_modules/pkg/index.d.ts ===
interface GlobalThing { a: number }
>a : number

=== tests/cases/compiler/usage.ts ===
/// <reference types="pkg" />

const a: GlobalThing = { a: 0 };
>a : GlobalThing
>{ a: 0 } : { a: number; }
>a : number
>0 : 0

@@ -0,0 +1,13 @@
// @module: commonjs,node12,nodenext
// @filename: node_modules/pkg/index.d.ts
interface GlobalThing { a: number }
// @filename: node_modules/pkg/package.json
{
"name": "pkg",
"types": "index.d.ts",
"exports": "some-other-thing.js"
}
// @filename: usage.ts
/// <reference types="pkg" />

const a: GlobalThing = { a: 0 };