From 697df6ff41a53ea9572d41eb334a4586569de7c1 Mon Sep 17 00:00:00 2001 From: TypeScript Bot Date: Wed, 25 May 2022 15:27:54 -0700 Subject: [PATCH 01/12] Cherry-pick PR #49233 into release-4.7 (#49244) Component commits: 1ab6396efe Fix extensions for noDtsResolution in node16/nodenext Co-authored-by: Andrew Branch --- src/compiler/moduleNameResolver.ts | 14 +++++--- .../fourslash/server/goToSource13_nodenext.ts | 35 +++++++++++++++++++ 2 files changed, 44 insertions(+), 5 deletions(-) create mode 100644 tests/cases/fourslash/server/goToSource13_nodenext.ts diff --git a/src/compiler/moduleNameResolver.ts b/src/compiler/moduleNameResolver.ts index 8f466c0495aee..d2b0db1041b4e 100644 --- a/src/compiler/moduleNameResolver.ts +++ b/src/compiler/moduleNameResolver.ts @@ -1288,18 +1288,22 @@ namespace ts { ); } + const jsOnlyExtensions = [Extensions.JavaScript]; + const tsExtensions = [Extensions.TypeScript, Extensions.JavaScript]; + const tsPlusJsonExtensions = [...tsExtensions, Extensions.Json]; + const tsconfigExtensions = [Extensions.TSConfig]; function nodeNextModuleNameResolverWorker(features: NodeResolutionFeatures, moduleName: string, containingFile: string, compilerOptions: CompilerOptions, host: ModuleResolutionHost, cache?: ModuleResolutionCache, redirectedReference?: ResolvedProjectReference, resolutionMode?: ModuleKind.CommonJS | ModuleKind.ESNext): ResolvedModuleWithFailedLookupLocations { const containingDirectory = getDirectoryPath(containingFile); // es module file or cjs-like input file, use a variant of the legacy cjs resolver that supports the selected modern features const esmMode = resolutionMode === ModuleKind.ESNext ? NodeResolutionFeatures.EsmMode : 0; - return nodeModuleNameResolverWorker(features | esmMode, moduleName, containingDirectory, compilerOptions, host, cache, compilerOptions.resolveJsonModule ? tsPlusJsonExtensions : tsExtensions, redirectedReference); + let extensions = compilerOptions.noDtsResolution ? [Extensions.TsOnly, Extensions.JavaScript] : tsExtensions; + if (compilerOptions.resolveJsonModule) { + extensions = [...extensions, Extensions.Json]; + } + return nodeModuleNameResolverWorker(features | esmMode, moduleName, containingDirectory, compilerOptions, host, cache, extensions, redirectedReference); } - const jsOnlyExtensions = [Extensions.JavaScript]; - const tsExtensions = [Extensions.TypeScript, Extensions.JavaScript]; - const tsPlusJsonExtensions = [...tsExtensions, Extensions.Json]; - const tsconfigExtensions = [Extensions.TSConfig]; function tryResolveJSModuleWorker(moduleName: string, initialDir: string, host: ModuleResolutionHost): ResolvedModuleWithFailedLookupLocations { return nodeModuleNameResolverWorker(NodeResolutionFeatures.None, moduleName, initialDir, { moduleResolution: ModuleResolutionKind.NodeJs, allowJs: true }, host, /*cache*/ undefined, jsOnlyExtensions, /*redirectedReferences*/ undefined); } diff --git a/tests/cases/fourslash/server/goToSource13_nodenext.ts b/tests/cases/fourslash/server/goToSource13_nodenext.ts new file mode 100644 index 0000000000000..99a3a29ef2ec9 --- /dev/null +++ b/tests/cases/fourslash/server/goToSource13_nodenext.ts @@ -0,0 +1,35 @@ +/// + +// @Filename: /node_modules/left-pad/package.json +//// { +//// "name": "left-pad", +//// "version": "1.3.0", +//// "description": "String left pad", +//// "main": "index.js", +//// "types": "index.d.ts" +//// } + +// @Filename: /node_modules/left-pad/index.d.ts +//// declare function leftPad(str: string|number, len: number, ch?: string|number): string; +//// declare namespace leftPad { } +//// export = leftPad; + +// @Filename: /node_modules/left-pad/index.js +//// module.exports = leftPad; +//// function /*end*/leftPad(str, len, ch) {} + +// @Filename: /tsconfig.json +//// { +//// "compilerOptions": { +//// "module": "node16", +//// "strict": true, +//// "outDir": "./out", +//// +//// } +//// } + +// @Filename: /index.mts +//// import leftPad = require("left-pad"); +//// /*start*/leftPad("", 4); + +verify.goToSourceDefinition("start", "end"); From 6e0328af6aef8ae85778d142336296e4ae02e9ee Mon Sep 17 00:00:00 2001 From: TypeScript Bot Date: Thu, 26 May 2022 16:43:37 -0700 Subject: [PATCH 02/12] Cherry-pick PR #49252 into release-4.7 (#49272) Component commits: 94cf1272e5 Fix `isVariableDeclarationInitializedToBareOrAccessedRequire` returning true on binding elements fae1bbedc1 Undo auto format change Co-authored-by: Andrew Branch --- src/compiler/binder.ts | 7 ++++++- src/compiler/checker.ts | 9 +++++---- src/compiler/utilities.ts | 3 --- src/services/findAllReferences.ts | 2 +- src/services/importTracker.ts | 2 +- .../goToSource14_unresolvedRequireDestructuring.ts | 8 ++++++++ 6 files changed, 21 insertions(+), 10 deletions(-) create mode 100644 tests/cases/fourslash/server/goToSource14_unresolvedRequireDestructuring.ts diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index 66a9f6393dc75..10e40cf4cecbd 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -3291,7 +3291,12 @@ namespace ts { } if (!isBindingPattern(node.name)) { - if (isInJSFile(node) && isVariableDeclarationInitializedToBareOrAccessedRequire(node) && !getJSDocTypeTag(node) && !(getCombinedModifierFlags(node) & ModifierFlags.Export)) { + const possibleVariableDecl = node.kind === SyntaxKind.VariableDeclaration ? node : node.parent.parent; + if (isInJSFile(node) && + isVariableDeclarationInitializedToBareOrAccessedRequire(possibleVariableDecl) && + !getJSDocTypeTag(node) && + !(getCombinedModifierFlags(node) & ModifierFlags.Export) + ) { declareSymbolAndAddToSymbolTable(node as Declaration, SymbolFlags.Alias, SymbolFlags.AliasExcludes); } else if (isBlockOrCatchScoped(node)) { diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index ae18d03694253..650373f3dc097 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -2641,7 +2641,8 @@ namespace ts { && isAliasableOrJsExpression(node.parent.right) || node.kind === SyntaxKind.ShorthandPropertyAssignment || node.kind === SyntaxKind.PropertyAssignment && isAliasableOrJsExpression((node as PropertyAssignment).initializer) - || isVariableDeclarationInitializedToBareOrAccessedRequire(node); + || node.kind === SyntaxKind.VariableDeclaration && isVariableDeclarationInitializedToBareOrAccessedRequire(node) + || node.kind === SyntaxKind.BindingElement && isVariableDeclarationInitializedToBareOrAccessedRequire(node.parent.parent); } function isAliasableOrJsExpression(e: Expression) { @@ -37725,8 +37726,8 @@ namespace ts { } // For a commonjs `const x = require`, validate the alias and exit const symbol = getSymbolOfNode(node); - if (symbol.flags & SymbolFlags.Alias && isVariableDeclarationInitializedToBareOrAccessedRequire(node)) { - checkAliasSymbol(node); + if (symbol.flags & SymbolFlags.Alias && isVariableDeclarationInitializedToBareOrAccessedRequire(node.kind === SyntaxKind.BindingElement ? node.parent.parent : node)) { + checkAliasSymbol(node as BindingElement | VariableDeclaration); return; } @@ -40590,7 +40591,7 @@ namespace ts { return true; } - function checkAliasSymbol(node: ImportEqualsDeclaration | VariableDeclaration | ImportClause | NamespaceImport | ImportSpecifier | ExportSpecifier | NamespaceExport) { + function checkAliasSymbol(node: ImportEqualsDeclaration | VariableDeclaration | ImportClause | NamespaceImport | ImportSpecifier | ExportSpecifier | NamespaceExport | BindingElement) { let symbol = getSymbolOfNode(node); const target = resolveAlias(symbol); diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 6036f516bb025..5850d36971828 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -2197,9 +2197,6 @@ namespace ts { } function isVariableDeclarationInitializedWithRequireHelper(node: Node, allowAccessedRequire: boolean) { - if (node.kind === SyntaxKind.BindingElement) { - node = node.parent.parent; - } return isVariableDeclaration(node) && !!node.initializer && isRequireCall(allowAccessedRequire ? getLeftmostAccessExpression(node.initializer) : node.initializer, /*requireStringLiteralLikeArgument*/ true); diff --git a/src/services/findAllReferences.ts b/src/services/findAllReferences.ts index ba46b5d311f46..2b0ad8bc71d6c 100644 --- a/src/services/findAllReferences.ts +++ b/src/services/findAllReferences.ts @@ -1601,7 +1601,7 @@ namespace ts.FindAllReferences { // Use the parent symbol if the location is commonjs require syntax on javascript files only. if (isInJSFile(referenceLocation) && referenceLocation.parent.kind === SyntaxKind.BindingElement - && isVariableDeclarationInitializedToBareOrAccessedRequire(referenceLocation.parent)) { + && isVariableDeclarationInitializedToBareOrAccessedRequire(referenceLocation.parent.parent.parent)) { referenceSymbol = referenceLocation.parent.symbol; // The parent will not have a symbol if it's an ObjectBindingPattern (when destructuring is used). In // this case, just skip it, since the bound identifiers are not an alias of the import. diff --git a/src/services/importTracker.ts b/src/services/importTracker.ts index a3fcfb76680de..6ea4de1e9520a 100644 --- a/src/services/importTracker.ts +++ b/src/services/importTracker.ts @@ -621,7 +621,7 @@ namespace ts.FindAllReferences { Debug.assert((parent as ImportClause | NamespaceImport).name === node); return true; case SyntaxKind.BindingElement: - return isInJSFile(node) && isVariableDeclarationInitializedToBareOrAccessedRequire(parent); + return isInJSFile(node) && isVariableDeclarationInitializedToBareOrAccessedRequire(parent.parent.parent); default: return false; } diff --git a/tests/cases/fourslash/server/goToSource14_unresolvedRequireDestructuring.ts b/tests/cases/fourslash/server/goToSource14_unresolvedRequireDestructuring.ts new file mode 100644 index 0000000000000..426dc11107488 --- /dev/null +++ b/tests/cases/fourslash/server/goToSource14_unresolvedRequireDestructuring.ts @@ -0,0 +1,8 @@ +/// + +// @allowJs: true + +// @Filename: /index.js +//// const { blah/**/ } = require("unresolved"); + +verify.goToSourceDefinition("", []); From b24b05b5af693b3872143533f60755acf2a57db0 Mon Sep 17 00:00:00 2001 From: TypeScript Bot Date: Wed, 1 Jun 2022 10:43:06 -0700 Subject: [PATCH 03/12] Cherry-pick PR #49327 into release-4.7 (#49329) Component commits: 79957c179e Fix index fallback of CJS package from ESM-mode import when `main` is present but does not resolve Co-authored-by: Andrew Branch --- src/compiler/moduleNameResolver.ts | 4 +- ...ortModeImplicitIndexResolution2.errors.txt | 44 +++++++++++++++++++ ...eNextImportModeImplicitIndexResolution2.js | 44 +++++++++++++++++++ ...ImportModeImplicitIndexResolution2.symbols | 38 ++++++++++++++++ ...xtImportModeImplicitIndexResolution2.types | 38 ++++++++++++++++ ...eNextImportModeImplicitIndexResolution2.ts | 37 ++++++++++++++++ 6 files changed, 203 insertions(+), 2 deletions(-) create mode 100644 tests/baselines/reference/nodeNextImportModeImplicitIndexResolution2.errors.txt create mode 100644 tests/baselines/reference/nodeNextImportModeImplicitIndexResolution2.js create mode 100644 tests/baselines/reference/nodeNextImportModeImplicitIndexResolution2.symbols create mode 100644 tests/baselines/reference/nodeNextImportModeImplicitIndexResolution2.types create mode 100644 tests/cases/compiler/nodeNextImportModeImplicitIndexResolution2.ts diff --git a/src/compiler/moduleNameResolver.ts b/src/compiler/moduleNameResolver.ts index d2b0db1041b4e..fc62e3ee01bd7 100644 --- a/src/compiler/moduleNameResolver.ts +++ b/src/compiler/moduleNameResolver.ts @@ -2413,8 +2413,8 @@ namespace ts { ); if ( !pathAndExtension && packageInfo - && packageInfo.packageJsonContent.exports === undefined - && packageInfo.packageJsonContent.main === undefined + // eslint-disable-next-line no-null/no-null + && (packageInfo.packageJsonContent.exports === undefined || packageInfo.packageJsonContent.exports === null) && state.features & NodeResolutionFeatures.EsmMode ) { // EsmMode disables index lookup in `loadNodeModuleFromDirectoryWorker` generally, however non-relative package resolutions still assume diff --git a/tests/baselines/reference/nodeNextImportModeImplicitIndexResolution2.errors.txt b/tests/baselines/reference/nodeNextImportModeImplicitIndexResolution2.errors.txt new file mode 100644 index 0000000000000..914722e2f4d65 --- /dev/null +++ b/tests/baselines/reference/nodeNextImportModeImplicitIndexResolution2.errors.txt @@ -0,0 +1,44 @@ +/index.cts(4,21): error TS2307: Cannot find module 'dedent4' or its corresponding type declarations. +/index.mts(4,21): error TS2307: Cannot find module 'dedent4' or its corresponding type declarations. + + +==== /node_modules/@types/dedent/package.json (0 errors) ==== + { "name": "@types/dedent", "version": "1.0.0", "main": "" } + +==== /node_modules/@types/dedent2/package.json (0 errors) ==== + { "name": "@types/dedent2", "version": "1.0.0", "main": "asdfasdfasdf" } + +==== /node_modules/@types/dedent3/package.json (0 errors) ==== + { "name": "@types/dedent3", "version": "1.0.0", "main": "asdfasdfasdf", "exports": null } + +==== /node_modules/@types/dedent4/package.json (0 errors) ==== + { "name": "@types/dedent4", "version": "1.0.0", "main": "asdfasdfasdf", "exports": "./asdfasdfasdf" } + +==== /node_modules/@types/dedent/index.d.ts (0 errors) ==== + export {}; + +==== /node_modules/@types/dedent2/index.d.ts (0 errors) ==== + export {}; + +==== /node_modules/@types/dedent3/index.d.ts (0 errors) ==== + export {}; + +==== /node_modules/@types/dedent4/index.d.ts (0 errors) ==== + export {}; + +==== /index.mts (1 errors) ==== + import dedent from "dedent"; + import dedent2 from "dedent2"; + import dedent3 from "dedent3"; + import dedent4 from "dedent4"; // Error + ~~~~~~~~~ +!!! error TS2307: Cannot find module 'dedent4' or its corresponding type declarations. + +==== /index.cts (1 errors) ==== + import dedent from "dedent"; + import dedent2 from "dedent2"; + import dedent3 from "dedent3"; + import dedent4 from "dedent4"; // Error + ~~~~~~~~~ +!!! error TS2307: Cannot find module 'dedent4' or its corresponding type declarations. + \ No newline at end of file diff --git a/tests/baselines/reference/nodeNextImportModeImplicitIndexResolution2.js b/tests/baselines/reference/nodeNextImportModeImplicitIndexResolution2.js new file mode 100644 index 0000000000000..3125a73f6e76e --- /dev/null +++ b/tests/baselines/reference/nodeNextImportModeImplicitIndexResolution2.js @@ -0,0 +1,44 @@ +//// [tests/cases/compiler/nodeNextImportModeImplicitIndexResolution2.ts] //// + +//// [package.json] +{ "name": "@types/dedent", "version": "1.0.0", "main": "" } + +//// [package.json] +{ "name": "@types/dedent2", "version": "1.0.0", "main": "asdfasdfasdf" } + +//// [package.json] +{ "name": "@types/dedent3", "version": "1.0.0", "main": "asdfasdfasdf", "exports": null } + +//// [package.json] +{ "name": "@types/dedent4", "version": "1.0.0", "main": "asdfasdfasdf", "exports": "./asdfasdfasdf" } + +//// [index.d.ts] +export {}; + +//// [index.d.ts] +export {}; + +//// [index.d.ts] +export {}; + +//// [index.d.ts] +export {}; + +//// [index.mts] +import dedent from "dedent"; +import dedent2 from "dedent2"; +import dedent3 from "dedent3"; +import dedent4 from "dedent4"; // Error + +//// [index.cts] +import dedent from "dedent"; +import dedent2 from "dedent2"; +import dedent3 from "dedent3"; +import dedent4 from "dedent4"; // Error + + +//// [index.mjs] +export {}; +//// [index.cjs] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/tests/baselines/reference/nodeNextImportModeImplicitIndexResolution2.symbols b/tests/baselines/reference/nodeNextImportModeImplicitIndexResolution2.symbols new file mode 100644 index 0000000000000..5685121775b0c --- /dev/null +++ b/tests/baselines/reference/nodeNextImportModeImplicitIndexResolution2.symbols @@ -0,0 +1,38 @@ +=== /node_modules/@types/dedent/index.d.ts === +export {}; +No type information for this code. +No type information for this code.=== /node_modules/@types/dedent2/index.d.ts === +export {}; +No type information for this code. +No type information for this code.=== /node_modules/@types/dedent3/index.d.ts === +export {}; +No type information for this code. +No type information for this code.=== /node_modules/@types/dedent4/index.d.ts === +export {}; +No type information for this code. +No type information for this code.=== /index.mts === +import dedent from "dedent"; +>dedent : Symbol(dedent, Decl(index.mts, 0, 6)) + +import dedent2 from "dedent2"; +>dedent2 : Symbol(dedent2, Decl(index.mts, 1, 6)) + +import dedent3 from "dedent3"; +>dedent3 : Symbol(dedent3, Decl(index.mts, 2, 6)) + +import dedent4 from "dedent4"; // Error +>dedent4 : Symbol(dedent4, Decl(index.mts, 3, 6)) + +=== /index.cts === +import dedent from "dedent"; +>dedent : Symbol(dedent, Decl(index.cts, 0, 6)) + +import dedent2 from "dedent2"; +>dedent2 : Symbol(dedent2, Decl(index.cts, 1, 6)) + +import dedent3 from "dedent3"; +>dedent3 : Symbol(dedent3, Decl(index.cts, 2, 6)) + +import dedent4 from "dedent4"; // Error +>dedent4 : Symbol(dedent4, Decl(index.cts, 3, 6)) + diff --git a/tests/baselines/reference/nodeNextImportModeImplicitIndexResolution2.types b/tests/baselines/reference/nodeNextImportModeImplicitIndexResolution2.types new file mode 100644 index 0000000000000..a2a37da0ecdca --- /dev/null +++ b/tests/baselines/reference/nodeNextImportModeImplicitIndexResolution2.types @@ -0,0 +1,38 @@ +=== /node_modules/@types/dedent/index.d.ts === +export {}; +No type information for this code. +No type information for this code.=== /node_modules/@types/dedent2/index.d.ts === +export {}; +No type information for this code. +No type information for this code.=== /node_modules/@types/dedent3/index.d.ts === +export {}; +No type information for this code. +No type information for this code.=== /node_modules/@types/dedent4/index.d.ts === +export {}; +No type information for this code. +No type information for this code.=== /index.mts === +import dedent from "dedent"; +>dedent : typeof dedent + +import dedent2 from "dedent2"; +>dedent2 : typeof dedent2 + +import dedent3 from "dedent3"; +>dedent3 : typeof dedent3 + +import dedent4 from "dedent4"; // Error +>dedent4 : any + +=== /index.cts === +import dedent from "dedent"; +>dedent : typeof dedent + +import dedent2 from "dedent2"; +>dedent2 : typeof dedent2 + +import dedent3 from "dedent3"; +>dedent3 : typeof dedent3 + +import dedent4 from "dedent4"; // Error +>dedent4 : any + diff --git a/tests/cases/compiler/nodeNextImportModeImplicitIndexResolution2.ts b/tests/cases/compiler/nodeNextImportModeImplicitIndexResolution2.ts new file mode 100644 index 0000000000000..12b7844c22b50 --- /dev/null +++ b/tests/cases/compiler/nodeNextImportModeImplicitIndexResolution2.ts @@ -0,0 +1,37 @@ +// @module: nodenext + +// @Filename: /node_modules/@types/dedent/package.json +{ "name": "@types/dedent", "version": "1.0.0", "main": "" } + +// @Filename: /node_modules/@types/dedent2/package.json +{ "name": "@types/dedent2", "version": "1.0.0", "main": "asdfasdfasdf" } + +// @Filename: /node_modules/@types/dedent3/package.json +{ "name": "@types/dedent3", "version": "1.0.0", "main": "asdfasdfasdf", "exports": null } + +// @Filename: /node_modules/@types/dedent4/package.json +{ "name": "@types/dedent4", "version": "1.0.0", "main": "asdfasdfasdf", "exports": "./asdfasdfasdf" } + +// @Filename: /node_modules/@types/dedent/index.d.ts +export {}; + +// @Filename: /node_modules/@types/dedent2/index.d.ts +export {}; + +// @Filename: /node_modules/@types/dedent3/index.d.ts +export {}; + +// @Filename: /node_modules/@types/dedent4/index.d.ts +export {}; + +// @Filename: /index.mts +import dedent from "dedent"; +import dedent2 from "dedent2"; +import dedent3 from "dedent3"; +import dedent4 from "dedent4"; // Error + +// @Filename: /index.cts +import dedent from "dedent"; +import dedent2 from "dedent2"; +import dedent3 from "dedent3"; +import dedent4 from "dedent4"; // Error From 4e91c6cb08b45e6424e4a6b434595a068cd55c76 Mon Sep 17 00:00:00 2001 From: TypeScript Bot Date: Wed, 1 Jun 2022 15:20:13 -0700 Subject: [PATCH 04/12] =?UTF-8?q?=F0=9F=A4=96=20Pick=20PR=20#49341=20(Fix?= =?UTF-8?q?=20check=20in=20isMappedTypeGenericInd...)=20into=20release-4.7?= =?UTF-8?q?=20(#49342)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Cherry-pick PR #49341 into release-4.7 Component commits: d347d87782 Fix check in isMappedTypeGenericIndexedAccess e24c6f61b7 Add regression tests * Update baselines. Co-authored-by: Anders Hejlsberg Co-authored-by: Daniel Rosenwasser --- src/compiler/checker.ts | 2 +- .../mappedTypeGenericIndexedAccess.js | 105 ++++++++++++ .../mappedTypeGenericIndexedAccess.symbols | 150 ++++++++++++++++++ .../mappedTypeGenericIndexedAccess.types | 147 +++++++++++++++++ .../mappedTypeGenericIndexedAccess.ts | 46 ++++++ 5 files changed, 449 insertions(+), 1 deletion(-) create mode 100644 tests/baselines/reference/mappedTypeGenericIndexedAccess.js create mode 100644 tests/baselines/reference/mappedTypeGenericIndexedAccess.symbols create mode 100644 tests/baselines/reference/mappedTypeGenericIndexedAccess.types create mode 100644 tests/cases/compiler/mappedTypeGenericIndexedAccess.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 650373f3dc097..b16ef4991a9f6 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -12283,7 +12283,7 @@ namespace ts { let objectType; return !!(type.flags & TypeFlags.IndexedAccess && getObjectFlags(objectType = (type as IndexedAccessType).objectType) & ObjectFlags.Mapped && !isGenericMappedType(objectType) && isGenericIndexType((type as IndexedAccessType).indexType) && - !(objectType as MappedType).declaration.questionToken && !(objectType as MappedType).declaration.nameType); + !(getMappedTypeModifiers(objectType as MappedType) & MappedTypeModifiers.ExcludeOptional) && !(objectType as MappedType).declaration.nameType); } /** diff --git a/tests/baselines/reference/mappedTypeGenericIndexedAccess.js b/tests/baselines/reference/mappedTypeGenericIndexedAccess.js new file mode 100644 index 0000000000000..a06d9b27218a6 --- /dev/null +++ b/tests/baselines/reference/mappedTypeGenericIndexedAccess.js @@ -0,0 +1,105 @@ +//// [mappedTypeGenericIndexedAccess.ts] +// Repro from #49242 + +type Types = { + first: { a1: true }; + second: { a2: true }; + third: { a3: true }; +} + +class Test { + entries: { [T in keyof Types]?: Types[T][] }; + + constructor() { + this.entries = {}; + } + + addEntry(name: T, entry: Types[T]) { + if (!this.entries[name]) { + this.entries[name] = []; + } + this.entries[name]?.push(entry); + } +} + +// Repro from #49338 + +type TypesMap = { + [0]: { foo: 'bar'; }; + [1]: { a: 'b'; }; +}; + +type P = { t: T; } & TypesMap[T]; + +type TypeHandlers = { + [T in keyof TypesMap]?: (p: P) => void; +}; + +const typeHandlers: TypeHandlers = { + [0]: (p) => console.log(p.foo), + [1]: (p) => console.log(p.a), +}; + +const onSomeEvent = (p: P) => + typeHandlers[p.t]?.(p); + + +//// [mappedTypeGenericIndexedAccess.js] +"use strict"; +// Repro from #49242 +var _a; +var Test = /** @class */ (function () { + function Test() { + this.entries = {}; + } + Test.prototype.addEntry = function (name, entry) { + var _a; + if (!this.entries[name]) { + this.entries[name] = []; + } + (_a = this.entries[name]) === null || _a === void 0 ? void 0 : _a.push(entry); + }; + return Test; +}()); +var typeHandlers = (_a = {}, + _a[0] = function (p) { return console.log(p.foo); }, + _a[1] = function (p) { return console.log(p.a); }, + _a); +var onSomeEvent = function (p) { var _a; return (_a = typeHandlers[p.t]) === null || _a === void 0 ? void 0 : _a.call(typeHandlers, p); }; + + +//// [mappedTypeGenericIndexedAccess.d.ts] +declare type Types = { + first: { + a1: true; + }; + second: { + a2: true; + }; + third: { + a3: true; + }; +}; +declare class Test { + entries: { + [T in keyof Types]?: Types[T][]; + }; + constructor(); + addEntry(name: T, entry: Types[T]): void; +} +declare type TypesMap = { + [0]: { + foo: 'bar'; + }; + [1]: { + a: 'b'; + }; +}; +declare type P = { + t: T; +} & TypesMap[T]; +declare type TypeHandlers = { + [T in keyof TypesMap]?: (p: P) => void; +}; +declare const typeHandlers: TypeHandlers; +declare const onSomeEvent: (p: P) => void | undefined; diff --git a/tests/baselines/reference/mappedTypeGenericIndexedAccess.symbols b/tests/baselines/reference/mappedTypeGenericIndexedAccess.symbols new file mode 100644 index 0000000000000..329932a9afdbf --- /dev/null +++ b/tests/baselines/reference/mappedTypeGenericIndexedAccess.symbols @@ -0,0 +1,150 @@ +=== tests/cases/compiler/mappedTypeGenericIndexedAccess.ts === +// Repro from #49242 + +type Types = { +>Types : Symbol(Types, Decl(mappedTypeGenericIndexedAccess.ts, 0, 0)) + + first: { a1: true }; +>first : Symbol(first, Decl(mappedTypeGenericIndexedAccess.ts, 2, 14)) +>a1 : Symbol(a1, Decl(mappedTypeGenericIndexedAccess.ts, 3, 12)) + + second: { a2: true }; +>second : Symbol(second, Decl(mappedTypeGenericIndexedAccess.ts, 3, 24)) +>a2 : Symbol(a2, Decl(mappedTypeGenericIndexedAccess.ts, 4, 13)) + + third: { a3: true }; +>third : Symbol(third, Decl(mappedTypeGenericIndexedAccess.ts, 4, 25)) +>a3 : Symbol(a3, Decl(mappedTypeGenericIndexedAccess.ts, 5, 12)) +} + +class Test { +>Test : Symbol(Test, Decl(mappedTypeGenericIndexedAccess.ts, 6, 1)) + + entries: { [T in keyof Types]?: Types[T][] }; +>entries : Symbol(Test.entries, Decl(mappedTypeGenericIndexedAccess.ts, 8, 12)) +>T : Symbol(T, Decl(mappedTypeGenericIndexedAccess.ts, 9, 16)) +>Types : Symbol(Types, Decl(mappedTypeGenericIndexedAccess.ts, 0, 0)) +>Types : Symbol(Types, Decl(mappedTypeGenericIndexedAccess.ts, 0, 0)) +>T : Symbol(T, Decl(mappedTypeGenericIndexedAccess.ts, 9, 16)) + + constructor() { + this.entries = {}; +>this.entries : Symbol(Test.entries, Decl(mappedTypeGenericIndexedAccess.ts, 8, 12)) +>this : Symbol(Test, Decl(mappedTypeGenericIndexedAccess.ts, 6, 1)) +>entries : Symbol(Test.entries, Decl(mappedTypeGenericIndexedAccess.ts, 8, 12)) + } + + addEntry(name: T, entry: Types[T]) { +>addEntry : Symbol(Test.addEntry, Decl(mappedTypeGenericIndexedAccess.ts, 13, 5)) +>T : Symbol(T, Decl(mappedTypeGenericIndexedAccess.ts, 15, 13)) +>Types : Symbol(Types, Decl(mappedTypeGenericIndexedAccess.ts, 0, 0)) +>name : Symbol(name, Decl(mappedTypeGenericIndexedAccess.ts, 15, 36)) +>T : Symbol(T, Decl(mappedTypeGenericIndexedAccess.ts, 15, 13)) +>entry : Symbol(entry, Decl(mappedTypeGenericIndexedAccess.ts, 15, 44)) +>Types : Symbol(Types, Decl(mappedTypeGenericIndexedAccess.ts, 0, 0)) +>T : Symbol(T, Decl(mappedTypeGenericIndexedAccess.ts, 15, 13)) + + if (!this.entries[name]) { +>this.entries : Symbol(Test.entries, Decl(mappedTypeGenericIndexedAccess.ts, 8, 12)) +>this : Symbol(Test, Decl(mappedTypeGenericIndexedAccess.ts, 6, 1)) +>entries : Symbol(Test.entries, Decl(mappedTypeGenericIndexedAccess.ts, 8, 12)) +>name : Symbol(name, Decl(mappedTypeGenericIndexedAccess.ts, 15, 36)) + + this.entries[name] = []; +>this.entries : Symbol(Test.entries, Decl(mappedTypeGenericIndexedAccess.ts, 8, 12)) +>this : Symbol(Test, Decl(mappedTypeGenericIndexedAccess.ts, 6, 1)) +>entries : Symbol(Test.entries, Decl(mappedTypeGenericIndexedAccess.ts, 8, 12)) +>name : Symbol(name, Decl(mappedTypeGenericIndexedAccess.ts, 15, 36)) + } + this.entries[name]?.push(entry); +>this.entries[name]?.push : Symbol(Array.push, Decl(lib.es5.d.ts, --, --)) +>this.entries : Symbol(Test.entries, Decl(mappedTypeGenericIndexedAccess.ts, 8, 12)) +>this : Symbol(Test, Decl(mappedTypeGenericIndexedAccess.ts, 6, 1)) +>entries : Symbol(Test.entries, Decl(mappedTypeGenericIndexedAccess.ts, 8, 12)) +>name : Symbol(name, Decl(mappedTypeGenericIndexedAccess.ts, 15, 36)) +>push : Symbol(Array.push, Decl(lib.es5.d.ts, --, --)) +>entry : Symbol(entry, Decl(mappedTypeGenericIndexedAccess.ts, 15, 44)) + } +} + +// Repro from #49338 + +type TypesMap = { +>TypesMap : Symbol(TypesMap, Decl(mappedTypeGenericIndexedAccess.ts, 21, 1)) + + [0]: { foo: 'bar'; }; +>[0] : Symbol([0], Decl(mappedTypeGenericIndexedAccess.ts, 25, 17)) +>0 : Symbol([0], Decl(mappedTypeGenericIndexedAccess.ts, 25, 17)) +>foo : Symbol(foo, Decl(mappedTypeGenericIndexedAccess.ts, 26, 10)) + + [1]: { a: 'b'; }; +>[1] : Symbol([1], Decl(mappedTypeGenericIndexedAccess.ts, 26, 25)) +>1 : Symbol([1], Decl(mappedTypeGenericIndexedAccess.ts, 26, 25)) +>a : Symbol(a, Decl(mappedTypeGenericIndexedAccess.ts, 27, 10)) + +}; + +type P = { t: T; } & TypesMap[T]; +>P : Symbol(P, Decl(mappedTypeGenericIndexedAccess.ts, 28, 2)) +>T : Symbol(T, Decl(mappedTypeGenericIndexedAccess.ts, 30, 7)) +>TypesMap : Symbol(TypesMap, Decl(mappedTypeGenericIndexedAccess.ts, 21, 1)) +>t : Symbol(t, Decl(mappedTypeGenericIndexedAccess.ts, 30, 36)) +>T : Symbol(T, Decl(mappedTypeGenericIndexedAccess.ts, 30, 7)) +>TypesMap : Symbol(TypesMap, Decl(mappedTypeGenericIndexedAccess.ts, 21, 1)) +>T : Symbol(T, Decl(mappedTypeGenericIndexedAccess.ts, 30, 7)) + +type TypeHandlers = { +>TypeHandlers : Symbol(TypeHandlers, Decl(mappedTypeGenericIndexedAccess.ts, 30, 59)) + + [T in keyof TypesMap]?: (p: P) => void; +>T : Symbol(T, Decl(mappedTypeGenericIndexedAccess.ts, 33, 5)) +>TypesMap : Symbol(TypesMap, Decl(mappedTypeGenericIndexedAccess.ts, 21, 1)) +>p : Symbol(p, Decl(mappedTypeGenericIndexedAccess.ts, 33, 29)) +>P : Symbol(P, Decl(mappedTypeGenericIndexedAccess.ts, 28, 2)) +>T : Symbol(T, Decl(mappedTypeGenericIndexedAccess.ts, 33, 5)) + +}; + +const typeHandlers: TypeHandlers = { +>typeHandlers : Symbol(typeHandlers, Decl(mappedTypeGenericIndexedAccess.ts, 36, 5)) +>TypeHandlers : Symbol(TypeHandlers, Decl(mappedTypeGenericIndexedAccess.ts, 30, 59)) + + [0]: (p) => console.log(p.foo), +>[0] : Symbol([0], Decl(mappedTypeGenericIndexedAccess.ts, 36, 36)) +>0 : Symbol([0], Decl(mappedTypeGenericIndexedAccess.ts, 36, 36)) +>p : Symbol(p, Decl(mappedTypeGenericIndexedAccess.ts, 37, 10)) +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>p.foo : Symbol(foo, Decl(mappedTypeGenericIndexedAccess.ts, 26, 10)) +>p : Symbol(p, Decl(mappedTypeGenericIndexedAccess.ts, 37, 10)) +>foo : Symbol(foo, Decl(mappedTypeGenericIndexedAccess.ts, 26, 10)) + + [1]: (p) => console.log(p.a), +>[1] : Symbol([1], Decl(mappedTypeGenericIndexedAccess.ts, 37, 35)) +>1 : Symbol([1], Decl(mappedTypeGenericIndexedAccess.ts, 37, 35)) +>p : Symbol(p, Decl(mappedTypeGenericIndexedAccess.ts, 38, 10)) +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>p.a : Symbol(a, Decl(mappedTypeGenericIndexedAccess.ts, 27, 10)) +>p : Symbol(p, Decl(mappedTypeGenericIndexedAccess.ts, 38, 10)) +>a : Symbol(a, Decl(mappedTypeGenericIndexedAccess.ts, 27, 10)) + +}; + +const onSomeEvent = (p: P) => +>onSomeEvent : Symbol(onSomeEvent, Decl(mappedTypeGenericIndexedAccess.ts, 41, 5)) +>T : Symbol(T, Decl(mappedTypeGenericIndexedAccess.ts, 41, 21)) +>TypesMap : Symbol(TypesMap, Decl(mappedTypeGenericIndexedAccess.ts, 21, 1)) +>p : Symbol(p, Decl(mappedTypeGenericIndexedAccess.ts, 41, 47)) +>P : Symbol(P, Decl(mappedTypeGenericIndexedAccess.ts, 28, 2)) +>T : Symbol(T, Decl(mappedTypeGenericIndexedAccess.ts, 41, 21)) + + typeHandlers[p.t]?.(p); +>typeHandlers : Symbol(typeHandlers, Decl(mappedTypeGenericIndexedAccess.ts, 36, 5)) +>p.t : Symbol(t, Decl(mappedTypeGenericIndexedAccess.ts, 30, 36)) +>p : Symbol(p, Decl(mappedTypeGenericIndexedAccess.ts, 41, 47)) +>t : Symbol(t, Decl(mappedTypeGenericIndexedAccess.ts, 30, 36)) +>p : Symbol(p, Decl(mappedTypeGenericIndexedAccess.ts, 41, 47)) + diff --git a/tests/baselines/reference/mappedTypeGenericIndexedAccess.types b/tests/baselines/reference/mappedTypeGenericIndexedAccess.types new file mode 100644 index 0000000000000..1833e8c547d49 --- /dev/null +++ b/tests/baselines/reference/mappedTypeGenericIndexedAccess.types @@ -0,0 +1,147 @@ +=== tests/cases/compiler/mappedTypeGenericIndexedAccess.ts === +// Repro from #49242 + +type Types = { +>Types : { first: { a1: true;}; second: { a2: true;}; third: { a3: true;}; } + + first: { a1: true }; +>first : { a1: true; } +>a1 : true +>true : true + + second: { a2: true }; +>second : { a2: true; } +>a2 : true +>true : true + + third: { a3: true }; +>third : { a3: true; } +>a3 : true +>true : true +} + +class Test { +>Test : Test + + entries: { [T in keyof Types]?: Types[T][] }; +>entries : { first?: { a1: true; }[] | undefined; second?: { a2: true; }[] | undefined; third?: { a3: true; }[] | undefined; } + + constructor() { + this.entries = {}; +>this.entries = {} : {} +>this.entries : { first?: { a1: true; }[] | undefined; second?: { a2: true; }[] | undefined; third?: { a3: true; }[] | undefined; } +>this : this +>entries : { first?: { a1: true; }[] | undefined; second?: { a2: true; }[] | undefined; third?: { a3: true; }[] | undefined; } +>{} : {} + } + + addEntry(name: T, entry: Types[T]) { +>addEntry : (name: T, entry: Types[T]) => void +>name : T +>entry : Types[T] + + if (!this.entries[name]) { +>!this.entries[name] : boolean +>this.entries[name] : { first?: { a1: true; }[] | undefined; second?: { a2: true; }[] | undefined; third?: { a3: true; }[] | undefined; }[T] +>this.entries : { first?: { a1: true; }[] | undefined; second?: { a2: true; }[] | undefined; third?: { a3: true; }[] | undefined; } +>this : this +>entries : { first?: { a1: true; }[] | undefined; second?: { a2: true; }[] | undefined; third?: { a3: true; }[] | undefined; } +>name : T + + this.entries[name] = []; +>this.entries[name] = [] : never[] +>this.entries[name] : { first?: { a1: true; }[] | undefined; second?: { a2: true; }[] | undefined; third?: { a3: true; }[] | undefined; }[T] +>this.entries : { first?: { a1: true; }[] | undefined; second?: { a2: true; }[] | undefined; third?: { a3: true; }[] | undefined; } +>this : this +>entries : { first?: { a1: true; }[] | undefined; second?: { a2: true; }[] | undefined; third?: { a3: true; }[] | undefined; } +>name : T +>[] : never[] + } + this.entries[name]?.push(entry); +>this.entries[name]?.push(entry) : number | undefined +>this.entries[name]?.push : ((...items: Types[T][]) => number) | undefined +>this.entries[name] : Types[T][] | undefined +>this.entries : { first?: { a1: true; }[] | undefined; second?: { a2: true; }[] | undefined; third?: { a3: true; }[] | undefined; } +>this : this +>entries : { first?: { a1: true; }[] | undefined; second?: { a2: true; }[] | undefined; third?: { a3: true; }[] | undefined; } +>name : T +>push : ((...items: Types[T][]) => number) | undefined +>entry : Types[T] + } +} + +// Repro from #49338 + +type TypesMap = { +>TypesMap : { 0: { foo: 'bar';}; 1: { a: 'b';}; } + + [0]: { foo: 'bar'; }; +>[0] : { foo: 'bar'; } +>0 : 0 +>foo : "bar" + + [1]: { a: 'b'; }; +>[1] : { a: 'b'; } +>1 : 1 +>a : "b" + +}; + +type P = { t: T; } & TypesMap[T]; +>P : P +>t : T + +type TypeHandlers = { +>TypeHandlers : { 0?: ((p: P<0>) => void) | undefined; 1?: ((p: P<1>) => void) | undefined; } + + [T in keyof TypesMap]?: (p: P) => void; +>p : P + +}; + +const typeHandlers: TypeHandlers = { +>typeHandlers : TypeHandlers +>{ [0]: (p) => console.log(p.foo), [1]: (p) => console.log(p.a),} : { 0: (p: P<0>) => void; 1: (p: P<1>) => void; } + + [0]: (p) => console.log(p.foo), +>[0] : (p: P<0>) => void +>0 : 0 +>(p) => console.log(p.foo) : (p: P<0>) => void +>p : P<0> +>console.log(p.foo) : void +>console.log : (...data: any[]) => void +>console : Console +>log : (...data: any[]) => void +>p.foo : "bar" +>p : P<0> +>foo : "bar" + + [1]: (p) => console.log(p.a), +>[1] : (p: P<1>) => void +>1 : 1 +>(p) => console.log(p.a) : (p: P<1>) => void +>p : P<1> +>console.log(p.a) : void +>console.log : (...data: any[]) => void +>console : Console +>log : (...data: any[]) => void +>p.a : "b" +>p : P<1> +>a : "b" + +}; + +const onSomeEvent = (p: P) => +>onSomeEvent : (p: P) => void | undefined +>(p: P) => typeHandlers[p.t]?.(p) : (p: P) => void | undefined +>p : P + + typeHandlers[p.t]?.(p); +>typeHandlers[p.t]?.(p) : void | undefined +>typeHandlers[p.t] : ((p: P) => void) | undefined +>typeHandlers : TypeHandlers +>p.t : T +>p : P +>t : T +>p : P + diff --git a/tests/cases/compiler/mappedTypeGenericIndexedAccess.ts b/tests/cases/compiler/mappedTypeGenericIndexedAccess.ts new file mode 100644 index 0000000000000..68240b8bc87fb --- /dev/null +++ b/tests/cases/compiler/mappedTypeGenericIndexedAccess.ts @@ -0,0 +1,46 @@ +// @strict: true +// @declaration: true + +// Repro from #49242 + +type Types = { + first: { a1: true }; + second: { a2: true }; + third: { a3: true }; +} + +class Test { + entries: { [T in keyof Types]?: Types[T][] }; + + constructor() { + this.entries = {}; + } + + addEntry(name: T, entry: Types[T]) { + if (!this.entries[name]) { + this.entries[name] = []; + } + this.entries[name]?.push(entry); + } +} + +// Repro from #49338 + +type TypesMap = { + [0]: { foo: 'bar'; }; + [1]: { a: 'b'; }; +}; + +type P = { t: T; } & TypesMap[T]; + +type TypeHandlers = { + [T in keyof TypesMap]?: (p: P) => void; +}; + +const typeHandlers: TypeHandlers = { + [0]: (p) => console.log(p.foo), + [1]: (p) => console.log(p.a), +}; + +const onSomeEvent = (p: P) => + typeHandlers[p.t]?.(p); From 35519356ede14b7d87b37e3612937e475b5db86d Mon Sep 17 00:00:00 2001 From: TypeScript Bot Date: Wed, 1 Jun 2022 15:20:33 -0700 Subject: [PATCH 05/12] Cherry-pick PR #49268 into release-4.7 (#49276) Component commits: 5d13ab280d moduleDetection: auto makes cjs files parse as modules, module: node sets moduleDetection: force Co-authored-by: Wesley Wigham --- src/compiler/binder.ts | 6 ++++-- src/compiler/checker.ts | 2 +- src/compiler/utilities.ts | 10 ++++++---- .../reference/moduleResolutionWithoutExtension8.js | 2 ++ ...ModulesAllowJsExportAssignment(module=node16).js | 2 ++ ...dulesAllowJsExportAssignment(module=nodenext).js | 2 ++ ...xportlessJsModuleDetectionAuto(module=node16).js | 13 +++++++++++++ ...lessJsModuleDetectionAuto(module=node16).symbols | 5 +++++ ...rtlessJsModuleDetectionAuto(module=node16).types | 5 +++++ ...ortlessJsModuleDetectionAuto(module=nodenext).js | 13 +++++++++++++ ...ssJsModuleDetectionAuto(module=nodenext).symbols | 5 +++++ ...lessJsModuleDetectionAuto(module=nodenext).types | 5 +++++ ...pesReferenceWithMissingExports(module=node16).js | 2 ++ ...sReferenceWithMissingExports(module=nodenext).js | 2 ++ ...ModulesAllowJsExportlessJsModuleDetectionAuto.ts | 8 ++++++++ 15 files changed, 75 insertions(+), 7 deletions(-) create mode 100644 tests/baselines/reference/nodeModulesAllowJsExportlessJsModuleDetectionAuto(module=node16).js create mode 100644 tests/baselines/reference/nodeModulesAllowJsExportlessJsModuleDetectionAuto(module=node16).symbols create mode 100644 tests/baselines/reference/nodeModulesAllowJsExportlessJsModuleDetectionAuto(module=node16).types create mode 100644 tests/baselines/reference/nodeModulesAllowJsExportlessJsModuleDetectionAuto(module=nodenext).js create mode 100644 tests/baselines/reference/nodeModulesAllowJsExportlessJsModuleDetectionAuto(module=nodenext).symbols create mode 100644 tests/baselines/reference/nodeModulesAllowJsExportlessJsModuleDetectionAuto(module=nodenext).types create mode 100644 tests/cases/conformance/node/allowJs/nodeModulesAllowJsExportlessJsModuleDetectionAuto.ts diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index 10e40cf4cecbd..3cefcf33bf2a8 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -2834,12 +2834,14 @@ namespace ts { } function setCommonJsModuleIndicator(node: Node) { - if (file.externalModuleIndicator) { + if (file.externalModuleIndicator && file.externalModuleIndicator !== true) { return false; } if (!file.commonJsModuleIndicator) { file.commonJsModuleIndicator = node; - bindSourceFileAsExternalModule(); + if (!file.externalModuleIndicator) { + bindSourceFileAsExternalModule(); + } } return true; } diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index b16ef4991a9f6..413600e0dcede 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -2747,7 +2747,7 @@ namespace ts { return hasExportAssignmentSymbol(moduleSymbol); } // JS files have a synthetic default if they do not contain ES2015+ module syntax (export = is not valid in js) _and_ do not have an __esModule marker - return !file.externalModuleIndicator && !resolveExportByName(moduleSymbol, escapeLeadingUnderscores("__esModule"), /*sourceNode*/ undefined, dontResolveAlias); + return typeof file.externalModuleIndicator !== "object" && !resolveExportByName(moduleSymbol, escapeLeadingUnderscores("__esModule"), /*sourceNode*/ undefined, dontResolveAlias); } function getTargetOfImportClause(node: ImportClause, dontResolveAlias: boolean): Symbol | undefined { diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 5850d36971828..a4cb8f9d8a5ee 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -6312,8 +6312,9 @@ namespace ts { */ function isFileForcedToBeModuleByFormat(file: SourceFile): true | undefined { // Excludes declaration files - they still require an explicit `export {}` or the like - // for back compat purposes. - return file.impliedNodeFormat === ModuleKind.ESNext && !file.isDeclarationFile ? true : undefined; + // for back compat purposes. The only non-declaration files _not_ forced to be a module are `.js` files + // that aren't esm-mode (meaning not in a `type: module` scope). + return (file.impliedNodeFormat === ModuleKind.ESNext || (fileExtensionIsOneOf(file.fileName, [Extension.Cjs, Extension.Cts]))) && !file.isDeclarationFile ? true : undefined; } export function getSetExternalModuleIndicator(options: CompilerOptions): (file: SourceFile) => void { @@ -6322,7 +6323,7 @@ namespace ts { case ModuleDetectionKind.Force: // All non-declaration files are modules, declaration files still do the usual isFileProbablyExternalModule return (file: SourceFile) => { - file.externalModuleIndicator = !file.isDeclarationFile || isFileProbablyExternalModule(file); + file.externalModuleIndicator = isFileProbablyExternalModule(file) || !file.isDeclarationFile || undefined; }; case ModuleDetectionKind.Legacy: // Files are modules if they have imports, exports, or import.meta @@ -6382,7 +6383,8 @@ namespace ts { } export function getEmitModuleDetectionKind(options: CompilerOptions) { - return options.moduleDetection || ModuleDetectionKind.Auto; + return options.moduleDetection || + (getEmitModuleKind(options) === ModuleKind.Node16 || getEmitModuleKind(options) === ModuleKind.NodeNext ? ModuleDetectionKind.Force : ModuleDetectionKind.Auto); } export function hasJsonModuleEmitEnabled(options: CompilerOptions) { diff --git a/tests/baselines/reference/moduleResolutionWithoutExtension8.js b/tests/baselines/reference/moduleResolutionWithoutExtension8.js index 593f3668b3c73..7410092fdbcbb 100644 --- a/tests/baselines/reference/moduleResolutionWithoutExtension8.js +++ b/tests/baselines/reference/moduleResolutionWithoutExtension8.js @@ -3,5 +3,7 @@ import("./foo").then(x => x); // should error, ask for extension //// [bar.cjs] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); // Extensionless relative path dynamic import in a cjs module import("./foo").then(x => x); // should error, ask for extension diff --git a/tests/baselines/reference/nodeModulesAllowJsExportAssignment(module=node16).js b/tests/baselines/reference/nodeModulesAllowJsExportAssignment(module=node16).js index 10d6da622e9a4..7eb839f9e4697 100644 --- a/tests/baselines/reference/nodeModulesAllowJsExportAssignment(module=node16).js +++ b/tests/baselines/reference/nodeModulesAllowJsExportAssignment(module=node16).js @@ -34,6 +34,8 @@ module.exports = a; const a = {}; module.exports = a; //// [file.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); // cjs format file const a = {}; module.exports = a; diff --git a/tests/baselines/reference/nodeModulesAllowJsExportAssignment(module=nodenext).js b/tests/baselines/reference/nodeModulesAllowJsExportAssignment(module=nodenext).js index 10d6da622e9a4..7eb839f9e4697 100644 --- a/tests/baselines/reference/nodeModulesAllowJsExportAssignment(module=nodenext).js +++ b/tests/baselines/reference/nodeModulesAllowJsExportAssignment(module=nodenext).js @@ -34,6 +34,8 @@ module.exports = a; const a = {}; module.exports = a; //// [file.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); // cjs format file const a = {}; module.exports = a; diff --git a/tests/baselines/reference/nodeModulesAllowJsExportlessJsModuleDetectionAuto(module=node16).js b/tests/baselines/reference/nodeModulesAllowJsExportlessJsModuleDetectionAuto(module=node16).js new file mode 100644 index 0000000000000..e3ca6368e77fb --- /dev/null +++ b/tests/baselines/reference/nodeModulesAllowJsExportlessJsModuleDetectionAuto(module=node16).js @@ -0,0 +1,13 @@ +//// [tests/cases/conformance/node/allowJs/nodeModulesAllowJsExportlessJsModuleDetectionAuto.ts] //// + +//// [foo.cjs] +// this file is a module despite having no imports +//// [bar.js] +// however this file is _not_ a module + +//// [foo.cjs] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +// this file is a module despite having no imports +//// [bar.js] +// however this file is _not_ a module diff --git a/tests/baselines/reference/nodeModulesAllowJsExportlessJsModuleDetectionAuto(module=node16).symbols b/tests/baselines/reference/nodeModulesAllowJsExportlessJsModuleDetectionAuto(module=node16).symbols new file mode 100644 index 0000000000000..e4e9a53aa590d --- /dev/null +++ b/tests/baselines/reference/nodeModulesAllowJsExportlessJsModuleDetectionAuto(module=node16).symbols @@ -0,0 +1,5 @@ +=== tests/cases/conformance/node/allowJs/foo.cjs === +// this file is a module despite having no imports +No type information for this code.=== tests/cases/conformance/node/allowJs/bar.js === +// however this file is _not_ a module +No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/nodeModulesAllowJsExportlessJsModuleDetectionAuto(module=node16).types b/tests/baselines/reference/nodeModulesAllowJsExportlessJsModuleDetectionAuto(module=node16).types new file mode 100644 index 0000000000000..e4e9a53aa590d --- /dev/null +++ b/tests/baselines/reference/nodeModulesAllowJsExportlessJsModuleDetectionAuto(module=node16).types @@ -0,0 +1,5 @@ +=== tests/cases/conformance/node/allowJs/foo.cjs === +// this file is a module despite having no imports +No type information for this code.=== tests/cases/conformance/node/allowJs/bar.js === +// however this file is _not_ a module +No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/nodeModulesAllowJsExportlessJsModuleDetectionAuto(module=nodenext).js b/tests/baselines/reference/nodeModulesAllowJsExportlessJsModuleDetectionAuto(module=nodenext).js new file mode 100644 index 0000000000000..e3ca6368e77fb --- /dev/null +++ b/tests/baselines/reference/nodeModulesAllowJsExportlessJsModuleDetectionAuto(module=nodenext).js @@ -0,0 +1,13 @@ +//// [tests/cases/conformance/node/allowJs/nodeModulesAllowJsExportlessJsModuleDetectionAuto.ts] //// + +//// [foo.cjs] +// this file is a module despite having no imports +//// [bar.js] +// however this file is _not_ a module + +//// [foo.cjs] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +// this file is a module despite having no imports +//// [bar.js] +// however this file is _not_ a module diff --git a/tests/baselines/reference/nodeModulesAllowJsExportlessJsModuleDetectionAuto(module=nodenext).symbols b/tests/baselines/reference/nodeModulesAllowJsExportlessJsModuleDetectionAuto(module=nodenext).symbols new file mode 100644 index 0000000000000..e4e9a53aa590d --- /dev/null +++ b/tests/baselines/reference/nodeModulesAllowJsExportlessJsModuleDetectionAuto(module=nodenext).symbols @@ -0,0 +1,5 @@ +=== tests/cases/conformance/node/allowJs/foo.cjs === +// this file is a module despite having no imports +No type information for this code.=== tests/cases/conformance/node/allowJs/bar.js === +// however this file is _not_ a module +No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/nodeModulesAllowJsExportlessJsModuleDetectionAuto(module=nodenext).types b/tests/baselines/reference/nodeModulesAllowJsExportlessJsModuleDetectionAuto(module=nodenext).types new file mode 100644 index 0000000000000..e4e9a53aa590d --- /dev/null +++ b/tests/baselines/reference/nodeModulesAllowJsExportlessJsModuleDetectionAuto(module=nodenext).types @@ -0,0 +1,5 @@ +=== tests/cases/conformance/node/allowJs/foo.cjs === +// this file is a module despite having no imports +No type information for this code.=== tests/cases/conformance/node/allowJs/bar.js === +// however this file is _not_ a module +No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/tripleSlashTypesReferenceWithMissingExports(module=node16).js b/tests/baselines/reference/tripleSlashTypesReferenceWithMissingExports(module=node16).js index 89dd2c7541a29..7c518b3b9d9cc 100644 --- a/tests/baselines/reference/tripleSlashTypesReferenceWithMissingExports(module=node16).js +++ b/tests/baselines/reference/tripleSlashTypesReferenceWithMissingExports(module=node16).js @@ -14,5 +14,7 @@ interface GlobalThing { a: number } const a: GlobalThing = { a: 0 }; //// [usage.js] +"use strict"; /// +Object.defineProperty(exports, "__esModule", { value: true }); const a = { a: 0 }; diff --git a/tests/baselines/reference/tripleSlashTypesReferenceWithMissingExports(module=nodenext).js b/tests/baselines/reference/tripleSlashTypesReferenceWithMissingExports(module=nodenext).js index 89dd2c7541a29..7c518b3b9d9cc 100644 --- a/tests/baselines/reference/tripleSlashTypesReferenceWithMissingExports(module=nodenext).js +++ b/tests/baselines/reference/tripleSlashTypesReferenceWithMissingExports(module=nodenext).js @@ -14,5 +14,7 @@ interface GlobalThing { a: number } const a: GlobalThing = { a: 0 }; //// [usage.js] +"use strict"; /// +Object.defineProperty(exports, "__esModule", { value: true }); const a = { a: 0 }; diff --git a/tests/cases/conformance/node/allowJs/nodeModulesAllowJsExportlessJsModuleDetectionAuto.ts b/tests/cases/conformance/node/allowJs/nodeModulesAllowJsExportlessJsModuleDetectionAuto.ts new file mode 100644 index 0000000000000..24037e466bafa --- /dev/null +++ b/tests/cases/conformance/node/allowJs/nodeModulesAllowJsExportlessJsModuleDetectionAuto.ts @@ -0,0 +1,8 @@ +// @module: node16,nodenext +// @allowJs: true +// @outDir: ./out +// @moduleDetection: auto +// @filename: foo.cjs +// this file is a module despite having no imports +// @filename: bar.js +// however this file is _not_ a module \ No newline at end of file From 197aaef55fe79b9a0218a6fdea79348274ee34bc Mon Sep 17 00:00:00 2001 From: TypeScript Bot Date: Wed, 1 Jun 2022 15:21:09 -0700 Subject: [PATCH 06/12] Cherry-pick PR #49246 into release-4.7 (#49250) Component commits: b846905041 Add failing test 66d51e5114 Fix the implicit glob key so that recursive keys are not differing just by directory seperator Fixes #49078 f93951f4b8 Reset the reload level once program is loaded Co-authored-by: Sheetal Nandi --- src/compiler/commandLineParser.ts | 2 +- src/compiler/watchPublic.ts | 1 + .../unittests/config/tsconfigParsing.ts | 9 + .../unittests/tscWatch/programUpdates.ts | 33 ++ ...keys-differ-only-in-directory-seperator.js | 388 ++++++++++++++++++ 5 files changed, 432 insertions(+), 1 deletion(-) create mode 100644 tests/baselines/reference/tscWatch/programUpdates/correctly-parses-wild-card-directories-from-implicit-glob-when-two-keys-differ-only-in-directory-seperator.js diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index b257d7aed4c7a..1f830f06a4005 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -3542,7 +3542,7 @@ namespace ts { } if (isImplicitGlob(spec.substring(spec.lastIndexOf(directorySeparator) + 1))) { return { - key: useCaseSensitiveFileNames ? spec : toFileNameLowerCase(spec), + key: removeTrailingDirectorySeparator(useCaseSensitiveFileNames ? spec : toFileNameLowerCase(spec)), flags: WatchDirectoryFlags.Recursive }; } diff --git a/src/compiler/watchPublic.ts b/src/compiler/watchPublic.ts index 8af1397e19cff..53e3666041415 100644 --- a/src/compiler/watchPublic.ts +++ b/src/compiler/watchPublic.ts @@ -700,6 +700,7 @@ namespace ts { function reloadFileNamesFromConfigFile() { writeLog("Reloading new file names and options"); + reloadLevel = ConfigFileProgramReloadLevel.None; rootFileNames = getFileNamesFromConfigSpecs(compilerOptions.configFile!.configFileSpecs!, getNormalizedAbsolutePath(getDirectoryPath(configFileName), currentDirectory), compilerOptions, parseConfigFileHost, extraFileExtensions); if (updateErrorForNoInputFiles(rootFileNames, getNormalizedAbsolutePath(configFileName, currentDirectory), compilerOptions.configFile!.configFileSpecs!, configFileParsingDiagnostics!, canConfigFileJsonReportNoInputFiles)) { hasChangedConfigFileParsingErrors = true; diff --git a/src/testRunner/unittests/config/tsconfigParsing.ts b/src/testRunner/unittests/config/tsconfigParsing.ts index de793bffa4e05..9a5e46322e44d 100644 --- a/src/testRunner/unittests/config/tsconfigParsing.ts +++ b/src/testRunner/unittests/config/tsconfigParsing.ts @@ -421,5 +421,14 @@ namespace ts { const parsedCommand = parseJsonConfigFileContent(parsed.config, sys, "/foo.bar"); assert.deepEqual(parsedCommand.wildcardDirectories, { "/foo.bar/src": WatchDirectoryFlags.Recursive }); }); + + it("correctly parses wild card directories from implicit glob when two keys differ only in directory seperator", () => { + const parsed = parseConfigFileTextToJson("/foo.bar/tsconfig.json", JSON.stringify({ + include: ["./", "./**/*.json"] + })); + + const parsedCommand = parseJsonConfigFileContent(parsed.config, sys, "/foo"); + assert.deepEqual(parsedCommand.wildcardDirectories, { "/foo": WatchDirectoryFlags.Recursive }); + }); }); } diff --git a/src/testRunner/unittests/tscWatch/programUpdates.ts b/src/testRunner/unittests/tscWatch/programUpdates.ts index 68f03f0d20cc4..a17f857024f11 100644 --- a/src/testRunner/unittests/tscWatch/programUpdates.ts +++ b/src/testRunner/unittests/tscWatch/programUpdates.ts @@ -616,6 +616,39 @@ export class A { ] }); + verifyTscWatch({ + scenario, + subScenario: "correctly parses wild card directories from implicit glob when two keys differ only in directory seperator", + commandLineArgs: ["-w", "--extendedDiagnostics"], + sys: () => { + const file1 = { + path: `${projectRoot}/f1.ts`, + content: "export const x = 1" + }; + const file2 = { + path: `${projectRoot}/f2.ts`, + content: "export const y = 1" + }; + const configFile = { + path: `${projectRoot}/tsconfig.json`, + content: JSON.stringify({ compilerOptions: { composite: true }, include: ["./", "./**/*.json"] }) + }; + return createWatchedSystem([file1, file2, libFile, configFile], { currentDirectory: projectRoot }); + }, + changes: [ + { + caption: "Add new file", + change: sys => sys.writeFile(`${projectRoot}/new-file.ts`, "export const z = 1;"), + timeouts: sys => sys.checkTimeoutQueueLengthAndRun(1), + }, + { + caption: "Import new file", + change: sys => sys.prependFile(`${projectRoot}/f1.ts`, `import { z } from "./new-file";`), + timeouts: sys => sys.checkTimeoutQueueLengthAndRun(1), + } + ] + }); + verifyTscWatch({ scenario, subScenario: "can correctly update configured project when set of root files has changed through include", diff --git a/tests/baselines/reference/tscWatch/programUpdates/correctly-parses-wild-card-directories-from-implicit-glob-when-two-keys-differ-only-in-directory-seperator.js b/tests/baselines/reference/tscWatch/programUpdates/correctly-parses-wild-card-directories-from-implicit-glob-when-two-keys-differ-only-in-directory-seperator.js new file mode 100644 index 0000000000000..2fded49fea8e0 --- /dev/null +++ b/tests/baselines/reference/tscWatch/programUpdates/correctly-parses-wild-card-directories-from-implicit-glob-when-two-keys-differ-only-in-directory-seperator.js @@ -0,0 +1,388 @@ +Input:: +//// [/user/username/projects/myproject/f1.ts] +export const x = 1 + +//// [/user/username/projects/myproject/f2.ts] +export const y = 1 + +//// [/a/lib/lib.d.ts] +/// +interface Boolean {} +interface Function {} +interface CallableFunction {} +interface NewableFunction {} +interface IArguments {} +interface Number { toExponential: any; } +interface Object {} +interface RegExp {} +interface String { charAt: any; } +interface Array { length: number; [n: number]: T; } + +//// [/user/username/projects/myproject/tsconfig.json] +{"compilerOptions":{"composite":true},"include":["./","./**/*.json"]} + + +/a/lib/tsc.js -w --extendedDiagnostics +Output:: +[12:00:23 AM] Starting compilation in watch mode... + +Current directory: /user/username/projects/myproject CaseSensitiveFileNames: false +FileWatcher:: Added:: WatchInfo: /user/username/projects/myproject/tsconfig.json 2000 undefined Config file +Synchronizing program +CreatingProgramWith:: + roots: ["/user/username/projects/myproject/f1.ts","/user/username/projects/myproject/f2.ts"] + options: {"composite":true,"watch":true,"extendedDiagnostics":true,"configFilePath":"/user/username/projects/myproject/tsconfig.json"} +FileWatcher:: Added:: WatchInfo: /user/username/projects/myproject/f1.ts 250 undefined Source file +FileWatcher:: Added:: WatchInfo: /user/username/projects/myproject/f2.ts 250 undefined Source file +FileWatcher:: Added:: WatchInfo: /a/lib/lib.d.ts 250 undefined Source file +DirectoryWatcher:: Added:: WatchInfo: /user/username/projects/myproject/node_modules/@types 1 undefined Type roots +Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /user/username/projects/myproject/node_modules/@types 1 undefined Type roots +[12:00:34 AM] Found 0 errors. Watching for file changes. + +DirectoryWatcher:: Added:: WatchInfo: /user/username/projects/myproject 1 undefined Wild card directory +Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /user/username/projects/myproject 1 undefined Wild card directory + + +Program root files: ["/user/username/projects/myproject/f1.ts","/user/username/projects/myproject/f2.ts"] +Program options: {"composite":true,"watch":true,"extendedDiagnostics":true,"configFilePath":"/user/username/projects/myproject/tsconfig.json"} +Program structureReused: Not +Program files:: +/a/lib/lib.d.ts +/user/username/projects/myproject/f1.ts +/user/username/projects/myproject/f2.ts + +Semantic diagnostics in builder refreshed for:: +/a/lib/lib.d.ts +/user/username/projects/myproject/f1.ts +/user/username/projects/myproject/f2.ts + +Shape signatures in builder refreshed for:: +/a/lib/lib.d.ts (used version) +/user/username/projects/myproject/f1.ts (computed .d.ts during emit) +/user/username/projects/myproject/f2.ts (computed .d.ts during emit) + +WatchedFiles:: +/user/username/projects/myproject/tsconfig.json: + {"fileName":"/user/username/projects/myproject/tsconfig.json","pollingInterval":250} +/user/username/projects/myproject/f1.ts: + {"fileName":"/user/username/projects/myproject/f1.ts","pollingInterval":250} +/user/username/projects/myproject/f2.ts: + {"fileName":"/user/username/projects/myproject/f2.ts","pollingInterval":250} +/a/lib/lib.d.ts: + {"fileName":"/a/lib/lib.d.ts","pollingInterval":250} + +FsWatches:: + +FsWatchesRecursive:: +/user/username/projects/myproject/node_modules/@types: + {"directoryName":"/user/username/projects/myproject/node_modules/@types","fallbackPollingInterval":500,"fallbackOptions":{"watchFile":"PriorityPollingInterval"}} +/user/username/projects/myproject: + {"directoryName":"/user/username/projects/myproject","fallbackPollingInterval":500,"fallbackOptions":{"watchFile":"PriorityPollingInterval"}} + +exitCode:: ExitStatus.undefined + +//// [/user/username/projects/myproject/f1.js] +"use strict"; +exports.__esModule = true; +exports.x = void 0; +exports.x = 1; + + +//// [/user/username/projects/myproject/f1.d.ts] +export declare const x = 1; + + +//// [/user/username/projects/myproject/f2.js] +"use strict"; +exports.__esModule = true; +exports.y = void 0; +exports.y = 1; + + +//// [/user/username/projects/myproject/f2.d.ts] +export declare const y = 1; + + +//// [/user/username/projects/myproject/tsconfig.tsbuildinfo] +{"program":{"fileNames":["../../../../a/lib/lib.d.ts","./f1.ts","./f2.ts"],"fileInfos":[{"version":"-7698705165-/// \ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array { length: number; [n: number]: T; }","affectsGlobalScope":true},{"version":"-10906998252-export const x = 1","signature":"-7495133367-export declare const x = 1;\n"},{"version":"-10905812331-export const y = 1","signature":"-6203665398-export declare const y = 1;\n"}],"options":{"composite":true},"referencedMap":[],"exportedModulesMap":[],"semanticDiagnosticsPerFile":[1,2,3]},"version":"FakeTSVersion"} + +//// [/user/username/projects/myproject/tsconfig.tsbuildinfo.readable.baseline.txt] +{ + "program": { + "fileNames": [ + "../../../../a/lib/lib.d.ts", + "./f1.ts", + "./f2.ts" + ], + "fileInfos": { + "../../../../a/lib/lib.d.ts": { + "version": "-7698705165-/// \ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array { length: number; [n: number]: T; }", + "signature": "-7698705165-/// \ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array { length: number; [n: number]: T; }", + "affectsGlobalScope": true + }, + "./f1.ts": { + "version": "-10906998252-export const x = 1", + "signature": "-7495133367-export declare const x = 1;\n" + }, + "./f2.ts": { + "version": "-10905812331-export const y = 1", + "signature": "-6203665398-export declare const y = 1;\n" + } + }, + "options": { + "composite": true + }, + "referencedMap": {}, + "exportedModulesMap": {}, + "semanticDiagnosticsPerFile": [ + "../../../../a/lib/lib.d.ts", + "./f1.ts", + "./f2.ts" + ] + }, + "version": "FakeTSVersion", + "size": 828 +} + + +Change:: Add new file + +Input:: +//// [/user/username/projects/myproject/new-file.ts] +export const z = 1; + + +Output:: +DirectoryWatcher:: Triggered with /user/username/projects/myproject/new-file.ts :: WatchInfo: /user/username/projects/myproject 1 undefined Wild card directory +Scheduling update +Elapsed:: *ms DirectoryWatcher:: Triggered with /user/username/projects/myproject/new-file.ts :: WatchInfo: /user/username/projects/myproject 1 undefined Wild card directory +Reloading new file names and options +Synchronizing program +[12:00:39 AM] File change detected. Starting incremental compilation... + +CreatingProgramWith:: + roots: ["/user/username/projects/myproject/f1.ts","/user/username/projects/myproject/f2.ts","/user/username/projects/myproject/new-file.ts"] + options: {"composite":true,"watch":true,"extendedDiagnostics":true,"configFilePath":"/user/username/projects/myproject/tsconfig.json"} +FileWatcher:: Added:: WatchInfo: /user/username/projects/myproject/new-file.ts 250 undefined Source file +DirectoryWatcher:: Triggered with /user/username/projects/myproject/new-file.js :: WatchInfo: /user/username/projects/myproject 1 undefined Wild card directory +Project: /user/username/projects/myproject/tsconfig.json Detected file add/remove of non supported extension: /user/username/projects/myproject/new-file.js +Elapsed:: *ms DirectoryWatcher:: Triggered with /user/username/projects/myproject/new-file.js :: WatchInfo: /user/username/projects/myproject 1 undefined Wild card directory +DirectoryWatcher:: Triggered with /user/username/projects/myproject/new-file.d.ts :: WatchInfo: /user/username/projects/myproject 1 undefined Wild card directory +Project: /user/username/projects/myproject/tsconfig.json Detected output file: /user/username/projects/myproject/new-file.d.ts +Elapsed:: *ms DirectoryWatcher:: Triggered with /user/username/projects/myproject/new-file.d.ts :: WatchInfo: /user/username/projects/myproject 1 undefined Wild card directory +[12:00:47 AM] Found 0 errors. Watching for file changes. + + + +Program root files: ["/user/username/projects/myproject/f1.ts","/user/username/projects/myproject/f2.ts","/user/username/projects/myproject/new-file.ts"] +Program options: {"composite":true,"watch":true,"extendedDiagnostics":true,"configFilePath":"/user/username/projects/myproject/tsconfig.json"} +Program structureReused: Not +Program files:: +/a/lib/lib.d.ts +/user/username/projects/myproject/f1.ts +/user/username/projects/myproject/f2.ts +/user/username/projects/myproject/new-file.ts + +Semantic diagnostics in builder refreshed for:: +/user/username/projects/myproject/new-file.ts + +Shape signatures in builder refreshed for:: +/user/username/projects/myproject/new-file.ts (computed .d.ts) + +WatchedFiles:: +/user/username/projects/myproject/tsconfig.json: + {"fileName":"/user/username/projects/myproject/tsconfig.json","pollingInterval":250} +/user/username/projects/myproject/f1.ts: + {"fileName":"/user/username/projects/myproject/f1.ts","pollingInterval":250} +/user/username/projects/myproject/f2.ts: + {"fileName":"/user/username/projects/myproject/f2.ts","pollingInterval":250} +/a/lib/lib.d.ts: + {"fileName":"/a/lib/lib.d.ts","pollingInterval":250} +/user/username/projects/myproject/new-file.ts: + {"fileName":"/user/username/projects/myproject/new-file.ts","pollingInterval":250} + +FsWatches:: + +FsWatchesRecursive:: +/user/username/projects/myproject/node_modules/@types: + {"directoryName":"/user/username/projects/myproject/node_modules/@types","fallbackPollingInterval":500,"fallbackOptions":{"watchFile":"PriorityPollingInterval"}} +/user/username/projects/myproject: + {"directoryName":"/user/username/projects/myproject","fallbackPollingInterval":500,"fallbackOptions":{"watchFile":"PriorityPollingInterval"}} + +exitCode:: ExitStatus.undefined + +//// [/user/username/projects/myproject/tsconfig.tsbuildinfo] +{"program":{"fileNames":["../../../../a/lib/lib.d.ts","./f1.ts","./f2.ts","./new-file.ts"],"fileInfos":[{"version":"-7698705165-/// \ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array { length: number; [n: number]: T; }","affectsGlobalScope":true},{"version":"-10906998252-export const x = 1","signature":"-7495133367-export declare const x = 1;\n"},{"version":"-10905812331-export const y = 1","signature":"-6203665398-export declare const y = 1;\n"},{"version":"-11960320495-export const z = 1;","signature":"-9207164725-export declare const z = 1;\n"}],"options":{"composite":true},"referencedMap":[],"exportedModulesMap":[],"semanticDiagnosticsPerFile":[1,2,3,4]},"version":"FakeTSVersion"} + +//// [/user/username/projects/myproject/tsconfig.tsbuildinfo.readable.baseline.txt] +{ + "program": { + "fileNames": [ + "../../../../a/lib/lib.d.ts", + "./f1.ts", + "./f2.ts", + "./new-file.ts" + ], + "fileInfos": { + "../../../../a/lib/lib.d.ts": { + "version": "-7698705165-/// \ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array { length: number; [n: number]: T; }", + "signature": "-7698705165-/// \ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array { length: number; [n: number]: T; }", + "affectsGlobalScope": true + }, + "./f1.ts": { + "version": "-10906998252-export const x = 1", + "signature": "-7495133367-export declare const x = 1;\n" + }, + "./f2.ts": { + "version": "-10905812331-export const y = 1", + "signature": "-6203665398-export declare const y = 1;\n" + }, + "./new-file.ts": { + "version": "-11960320495-export const z = 1;", + "signature": "-9207164725-export declare const z = 1;\n" + } + }, + "options": { + "composite": true + }, + "referencedMap": {}, + "exportedModulesMap": {}, + "semanticDiagnosticsPerFile": [ + "../../../../a/lib/lib.d.ts", + "./f1.ts", + "./f2.ts", + "./new-file.ts" + ] + }, + "version": "FakeTSVersion", + "size": 949 +} + +//// [/user/username/projects/myproject/new-file.js] +"use strict"; +exports.__esModule = true; +exports.z = void 0; +exports.z = 1; + + +//// [/user/username/projects/myproject/new-file.d.ts] +export declare const z = 1; + + + +Change:: Import new file + +Input:: +//// [/user/username/projects/myproject/f1.ts] +import { z } from "./new-file";export const x = 1 + + +Output:: +FileWatcher:: Triggered with /user/username/projects/myproject/f1.ts 1:: WatchInfo: /user/username/projects/myproject/f1.ts 250 undefined Source file +Scheduling update +Elapsed:: *ms FileWatcher:: Triggered with /user/username/projects/myproject/f1.ts 1:: WatchInfo: /user/username/projects/myproject/f1.ts 250 undefined Source file +Synchronizing program +[12:00:53 AM] File change detected. Starting incremental compilation... + +CreatingProgramWith:: + roots: ["/user/username/projects/myproject/f1.ts","/user/username/projects/myproject/f2.ts","/user/username/projects/myproject/new-file.ts"] + options: {"composite":true,"watch":true,"extendedDiagnostics":true,"configFilePath":"/user/username/projects/myproject/tsconfig.json"} +[12:01:03 AM] Found 0 errors. Watching for file changes. + + + +Program root files: ["/user/username/projects/myproject/f1.ts","/user/username/projects/myproject/f2.ts","/user/username/projects/myproject/new-file.ts"] +Program options: {"composite":true,"watch":true,"extendedDiagnostics":true,"configFilePath":"/user/username/projects/myproject/tsconfig.json"} +Program structureReused: SafeModules +Program files:: +/a/lib/lib.d.ts +/user/username/projects/myproject/new-file.ts +/user/username/projects/myproject/f1.ts +/user/username/projects/myproject/f2.ts + +Semantic diagnostics in builder refreshed for:: +/user/username/projects/myproject/f1.ts + +Shape signatures in builder refreshed for:: +/user/username/projects/myproject/f1.ts (computed .d.ts) + +WatchedFiles:: +/user/username/projects/myproject/tsconfig.json: + {"fileName":"/user/username/projects/myproject/tsconfig.json","pollingInterval":250} +/user/username/projects/myproject/f1.ts: + {"fileName":"/user/username/projects/myproject/f1.ts","pollingInterval":250} +/user/username/projects/myproject/f2.ts: + {"fileName":"/user/username/projects/myproject/f2.ts","pollingInterval":250} +/a/lib/lib.d.ts: + {"fileName":"/a/lib/lib.d.ts","pollingInterval":250} +/user/username/projects/myproject/new-file.ts: + {"fileName":"/user/username/projects/myproject/new-file.ts","pollingInterval":250} + +FsWatches:: + +FsWatchesRecursive:: +/user/username/projects/myproject/node_modules/@types: + {"directoryName":"/user/username/projects/myproject/node_modules/@types","fallbackPollingInterval":500,"fallbackOptions":{"watchFile":"PriorityPollingInterval"}} +/user/username/projects/myproject: + {"directoryName":"/user/username/projects/myproject","fallbackPollingInterval":500,"fallbackOptions":{"watchFile":"PriorityPollingInterval"}} + +exitCode:: ExitStatus.undefined + +//// [/user/username/projects/myproject/f1.js] file written with same contents +//// [/user/username/projects/myproject/f1.d.ts] file written with same contents +//// [/user/username/projects/myproject/tsconfig.tsbuildinfo] +{"program":{"fileNames":["../../../../a/lib/lib.d.ts","./new-file.ts","./f1.ts","./f2.ts"],"fileInfos":[{"version":"-7698705165-/// \ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array { length: number; [n: number]: T; }","affectsGlobalScope":true},{"version":"-11960320495-export const z = 1;","signature":"-9207164725-export declare const z = 1;\n"},{"version":"1363236232-import { z } from \"./new-file\";export const x = 1","signature":"-7495133367-export declare const x = 1;\n"},{"version":"-10905812331-export const y = 1","signature":"-6203665398-export declare const y = 1;\n"}],"options":{"composite":true},"fileIdsList":[[2]],"referencedMap":[[3,1]],"exportedModulesMap":[],"semanticDiagnosticsPerFile":[1,3,4,2]},"version":"FakeTSVersion"} + +//// [/user/username/projects/myproject/tsconfig.tsbuildinfo.readable.baseline.txt] +{ + "program": { + "fileNames": [ + "../../../../a/lib/lib.d.ts", + "./new-file.ts", + "./f1.ts", + "./f2.ts" + ], + "fileNamesList": [ + [ + "./new-file.ts" + ] + ], + "fileInfos": { + "../../../../a/lib/lib.d.ts": { + "version": "-7698705165-/// \ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array { length: number; [n: number]: T; }", + "signature": "-7698705165-/// \ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array { length: number; [n: number]: T; }", + "affectsGlobalScope": true + }, + "./new-file.ts": { + "version": "-11960320495-export const z = 1;", + "signature": "-9207164725-export declare const z = 1;\n" + }, + "./f1.ts": { + "version": "1363236232-import { z } from \"./new-file\";export const x = 1", + "signature": "-7495133367-export declare const x = 1;\n" + }, + "./f2.ts": { + "version": "-10905812331-export const y = 1", + "signature": "-6203665398-export declare const y = 1;\n" + } + }, + "options": { + "composite": true + }, + "referencedMap": { + "./f1.ts": [ + "./new-file.ts" + ] + }, + "exportedModulesMap": {}, + "semanticDiagnosticsPerFile": [ + "../../../../a/lib/lib.d.ts", + "./f1.ts", + "./f2.ts", + "./new-file.ts" + ] + }, + "version": "FakeTSVersion", + "size": 1005 +} + From c07d883428845a321c7379c7d326e13f7aad8974 Mon Sep 17 00:00:00 2001 From: TypeScript Bot Date: Thu, 2 Jun 2022 15:42:13 -0700 Subject: [PATCH 07/12] Cherry-pick PR #49313 into release-4.7 (#49359) Component commits: 00b7574003 fix(49306): add isImportTypeAssertionContainer helper Co-authored-by: Oleksandr T --- src/compiler/factory/nodeTests.ts | 4 ++++ tests/baselines/reference/api/tsserverlibrary.d.ts | 1 + tests/baselines/reference/api/typescript.d.ts | 1 + 3 files changed, 6 insertions(+) diff --git a/src/compiler/factory/nodeTests.ts b/src/compiler/factory/nodeTests.ts index cf473caf65bf7..d4ae3767cf096 100644 --- a/src/compiler/factory/nodeTests.ts +++ b/src/compiler/factory/nodeTests.ts @@ -597,6 +597,10 @@ namespace ts { return node.kind === SyntaxKind.ImportClause; } + export function isImportTypeAssertionContainer(node: Node): node is ImportTypeAssertionContainer { + return node.kind === SyntaxKind.ImportTypeAssertionContainer; + } + export function isAssertClause(node: Node): node is AssertClause { return node.kind === SyntaxKind.AssertClause; } diff --git a/tests/baselines/reference/api/tsserverlibrary.d.ts b/tests/baselines/reference/api/tsserverlibrary.d.ts index f7e45674ac056..3c0a87593c61e 100644 --- a/tests/baselines/reference/api/tsserverlibrary.d.ts +++ b/tests/baselines/reference/api/tsserverlibrary.d.ts @@ -4720,6 +4720,7 @@ declare namespace ts { function isImportEqualsDeclaration(node: Node): node is ImportEqualsDeclaration; function isImportDeclaration(node: Node): node is ImportDeclaration; function isImportClause(node: Node): node is ImportClause; + function isImportTypeAssertionContainer(node: Node): node is ImportTypeAssertionContainer; function isAssertClause(node: Node): node is AssertClause; function isAssertEntry(node: Node): node is AssertEntry; function isNamespaceImport(node: Node): node is NamespaceImport; diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index fb0a5a0c1e756..2e19019614600 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -4720,6 +4720,7 @@ declare namespace ts { function isImportEqualsDeclaration(node: Node): node is ImportEqualsDeclaration; function isImportDeclaration(node: Node): node is ImportDeclaration; function isImportClause(node: Node): node is ImportClause; + function isImportTypeAssertionContainer(node: Node): node is ImportTypeAssertionContainer; function isAssertClause(node: Node): node is AssertClause; function isAssertEntry(node: Node): node is AssertEntry; function isNamespaceImport(node: Node): node is NamespaceImport; From 5f7f0b1d57fdbc166c3969a3dd3f19f15ba0388e Mon Sep 17 00:00:00 2001 From: TypeScript Bot Date: Thu, 2 Jun 2022 16:25:30 -0700 Subject: [PATCH 08/12] Cherry-pick PR #49361 into release-4.7 (#49364) Component commits: fce91155fc Use node's algorithm for calculating the longest matching export/import pattern Co-authored-by: Wesley Wigham --- src/compiler/moduleNameResolver.ts | 20 +- ...rnExportsExclude(module=node16).errors.txt | 123 +++++++++ ...agePatternExportsExclude(module=node16).js | 127 ++++++++++ ...tternExportsExclude(module=node16).symbols | 120 +++++++++ ...PatternExportsExclude(module=node16).types | 120 +++++++++ ...ExportsExclude(module=nodenext).errors.txt | 123 +++++++++ ...ePatternExportsExclude(module=nodenext).js | 127 ++++++++++ ...ernExportsExclude(module=nodenext).symbols | 120 +++++++++ ...tternExportsExclude(module=nodenext).types | 120 +++++++++ ...rnExportsExclude(module=node16).errors.txt | 177 +++++++++++++ ...agePatternExportsExclude(module=node16).js | 187 ++++++++++++++ ...tternExportsExclude(module=node16).symbols | 234 ++++++++++++++++++ ...PatternExportsExclude(module=node16).types | 234 ++++++++++++++++++ ...ExportsExclude(module=nodenext).errors.txt | 177 +++++++++++++ ...ePatternExportsExclude(module=nodenext).js | 187 ++++++++++++++ ...ernExportsExclude(module=nodenext).symbols | 234 ++++++++++++++++++ ...tternExportsExclude(module=nodenext).types | 234 ++++++++++++++++++ ...ulesAllowJsPackagePatternExportsExclude.ts | 72 ++++++ ...nodeModulesPackagePatternExportsExclude.ts | 112 +++++++++ 19 files changed, 2847 insertions(+), 1 deletion(-) create mode 100644 tests/baselines/reference/nodeModulesAllowJsPackagePatternExportsExclude(module=node16).errors.txt create mode 100644 tests/baselines/reference/nodeModulesAllowJsPackagePatternExportsExclude(module=node16).js create mode 100644 tests/baselines/reference/nodeModulesAllowJsPackagePatternExportsExclude(module=node16).symbols create mode 100644 tests/baselines/reference/nodeModulesAllowJsPackagePatternExportsExclude(module=node16).types create mode 100644 tests/baselines/reference/nodeModulesAllowJsPackagePatternExportsExclude(module=nodenext).errors.txt create mode 100644 tests/baselines/reference/nodeModulesAllowJsPackagePatternExportsExclude(module=nodenext).js create mode 100644 tests/baselines/reference/nodeModulesAllowJsPackagePatternExportsExclude(module=nodenext).symbols create mode 100644 tests/baselines/reference/nodeModulesAllowJsPackagePatternExportsExclude(module=nodenext).types create mode 100644 tests/baselines/reference/nodeModulesPackagePatternExportsExclude(module=node16).errors.txt create mode 100644 tests/baselines/reference/nodeModulesPackagePatternExportsExclude(module=node16).js create mode 100644 tests/baselines/reference/nodeModulesPackagePatternExportsExclude(module=node16).symbols create mode 100644 tests/baselines/reference/nodeModulesPackagePatternExportsExclude(module=node16).types create mode 100644 tests/baselines/reference/nodeModulesPackagePatternExportsExclude(module=nodenext).errors.txt create mode 100644 tests/baselines/reference/nodeModulesPackagePatternExportsExclude(module=nodenext).js create mode 100644 tests/baselines/reference/nodeModulesPackagePatternExportsExclude(module=nodenext).symbols create mode 100644 tests/baselines/reference/nodeModulesPackagePatternExportsExclude(module=nodenext).types create mode 100644 tests/cases/conformance/node/allowJs/nodeModulesAllowJsPackagePatternExportsExclude.ts create mode 100644 tests/cases/conformance/node/nodeModulesPackagePatternExportsExclude.ts diff --git a/src/compiler/moduleNameResolver.ts b/src/compiler/moduleNameResolver.ts index fc62e3ee01bd7..63aadea575a16 100644 --- a/src/compiler/moduleNameResolver.ts +++ b/src/compiler/moduleNameResolver.ts @@ -2064,6 +2064,24 @@ namespace ts { return toSearchResult(/*value*/ undefined); } + /** + * From https://github.com/nodejs/node/blob/8f39f51cbbd3b2de14b9ee896e26421cc5b20121/lib/internal/modules/esm/resolve.js#L722 - + * "longest" has some nuance as to what "longest" means in the presence of pattern trailers + */ + function comparePatternKeys(a: string, b: string) { + const aPatternIndex = a.indexOf("*"); + const bPatternIndex = b.indexOf("*"); + const baseLenA = aPatternIndex === -1 ? a.length : aPatternIndex + 1; + const baseLenB = bPatternIndex === -1 ? b.length : bPatternIndex + 1; + if (baseLenA > baseLenB) return -1; + if (baseLenB > baseLenA) return 1; + if (aPatternIndex === -1) return 1; + if (bPatternIndex === -1) return -1; + if (a.length > b.length) return -1; + if (b.length > a.length) return 1; + return 0; + } + function loadModuleFromImportsOrExports(extensions: Extensions, state: ModuleResolutionState, cache: ModuleResolutionCache | undefined, redirectedReference: ResolvedProjectReference | undefined, moduleName: string, lookupTable: object, scope: PackageJsonInfo, isImports: boolean): SearchResult | undefined { const loadModuleFromTargetImportOrExport = getLoadModuleFromTargetImportOrExport(extensions, state, cache, redirectedReference, moduleName, scope, isImports); @@ -2071,7 +2089,7 @@ namespace ts { const target = (lookupTable as {[idx: string]: unknown})[moduleName]; return loadModuleFromTargetImportOrExport(target, /*subpath*/ "", /*pattern*/ false); } - const expandingKeys = sort(filter(getOwnKeys(lookupTable as MapLike), k => k.indexOf("*") !== -1 || endsWith(k, "/")), (a, b) => a.length - b.length); + const expandingKeys = sort(filter(getOwnKeys(lookupTable as MapLike), k => k.indexOf("*") !== -1 || endsWith(k, "/")), comparePatternKeys); for (const potentialTarget of expandingKeys) { if (state.features & NodeResolutionFeatures.ExportsPatternTrailers && matchesPatternWithTrailer(potentialTarget, moduleName)) { const target = (lookupTable as {[idx: string]: unknown})[potentialTarget]; diff --git a/tests/baselines/reference/nodeModulesAllowJsPackagePatternExportsExclude(module=node16).errors.txt b/tests/baselines/reference/nodeModulesAllowJsPackagePatternExportsExclude(module=node16).errors.txt new file mode 100644 index 0000000000000..d47318a006c10 --- /dev/null +++ b/tests/baselines/reference/nodeModulesAllowJsPackagePatternExportsExclude(module=node16).errors.txt @@ -0,0 +1,123 @@ +tests/cases/conformance/node/allowJs/index.cjs(2,23): error TS2307: Cannot find module 'inner/cjs/exclude/index' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/index.cjs(3,23): error TS2307: Cannot find module 'inner/mjs/exclude/index' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/index.cjs(4,24): error TS2307: Cannot find module 'inner/js/exclude/index' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/index.js(2,23): error TS2307: Cannot find module 'inner/cjs/exclude/index' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/index.js(3,23): error TS2307: Cannot find module 'inner/mjs/exclude/index' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/index.js(4,24): error TS2307: Cannot find module 'inner/js/exclude/index' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/index.mjs(2,23): error TS2307: Cannot find module 'inner/cjs/exclude/index' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/index.mjs(3,23): error TS2307: Cannot find module 'inner/mjs/exclude/index' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/index.mjs(4,24): error TS2307: Cannot find module 'inner/js/exclude/index' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/node_modules/inner/exclude/index.d.cts(2,22): error TS2307: Cannot find module 'inner/cjs/exclude/index' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/node_modules/inner/exclude/index.d.cts(3,22): error TS2307: Cannot find module 'inner/mjs/exclude/index' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/node_modules/inner/exclude/index.d.cts(4,23): error TS2307: Cannot find module 'inner/js/exclude/index' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/node_modules/inner/exclude/index.d.mts(2,22): error TS2307: Cannot find module 'inner/cjs/exclude/index' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/node_modules/inner/exclude/index.d.mts(3,22): error TS2307: Cannot find module 'inner/mjs/exclude/index' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/node_modules/inner/exclude/index.d.mts(4,23): error TS2307: Cannot find module 'inner/js/exclude/index' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/node_modules/inner/exclude/index.d.ts(2,22): error TS2307: Cannot find module 'inner/cjs/exclude/index' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/node_modules/inner/exclude/index.d.ts(3,22): error TS2307: Cannot find module 'inner/mjs/exclude/index' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/node_modules/inner/exclude/index.d.ts(4,23): error TS2307: Cannot find module 'inner/js/exclude/index' or its corresponding type declarations. + + +==== tests/cases/conformance/node/allowJs/index.js (3 errors) ==== + // esm format file + import * as cjsi from "inner/cjs/exclude/index"; + ~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'inner/cjs/exclude/index' or its corresponding type declarations. + import * as mjsi from "inner/mjs/exclude/index"; + ~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'inner/mjs/exclude/index' or its corresponding type declarations. + import * as typei from "inner/js/exclude/index"; + ~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'inner/js/exclude/index' or its corresponding type declarations. + cjsi; + mjsi; + typei; +==== tests/cases/conformance/node/allowJs/index.mjs (3 errors) ==== + // esm format file + import * as cjsi from "inner/cjs/exclude/index"; + ~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'inner/cjs/exclude/index' or its corresponding type declarations. + import * as mjsi from "inner/mjs/exclude/index"; + ~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'inner/mjs/exclude/index' or its corresponding type declarations. + import * as typei from "inner/js/exclude/index"; + ~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'inner/js/exclude/index' or its corresponding type declarations. + cjsi; + mjsi; + typei; +==== tests/cases/conformance/node/allowJs/index.cjs (3 errors) ==== + // cjs format file + import * as cjsi from "inner/cjs/exclude/index"; + ~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'inner/cjs/exclude/index' or its corresponding type declarations. + import * as mjsi from "inner/mjs/exclude/index"; + ~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'inner/mjs/exclude/index' or its corresponding type declarations. + import * as typei from "inner/js/exclude/index"; + ~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'inner/js/exclude/index' or its corresponding type declarations. + cjsi; + mjsi; + typei; +==== tests/cases/conformance/node/allowJs/node_modules/inner/exclude/index.d.ts (3 errors) ==== + // cjs format file + import * as cjs from "inner/cjs/exclude/index"; + ~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'inner/cjs/exclude/index' or its corresponding type declarations. + import * as mjs from "inner/mjs/exclude/index"; + ~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'inner/mjs/exclude/index' or its corresponding type declarations. + import * as type from "inner/js/exclude/index"; + ~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'inner/js/exclude/index' or its corresponding type declarations. + export { cjs }; + export { mjs }; + export { type }; +==== tests/cases/conformance/node/allowJs/node_modules/inner/exclude/index.d.mts (3 errors) ==== + // esm format file + import * as cjs from "inner/cjs/exclude/index"; + ~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'inner/cjs/exclude/index' or its corresponding type declarations. + import * as mjs from "inner/mjs/exclude/index"; + ~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'inner/mjs/exclude/index' or its corresponding type declarations. + import * as type from "inner/js/exclude/index"; + ~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'inner/js/exclude/index' or its corresponding type declarations. + export { cjs }; + export { mjs }; + export { type }; +==== tests/cases/conformance/node/allowJs/node_modules/inner/exclude/index.d.cts (3 errors) ==== + // cjs format file + import * as cjs from "inner/cjs/exclude/index"; + ~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'inner/cjs/exclude/index' or its corresponding type declarations. + import * as mjs from "inner/mjs/exclude/index"; + ~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'inner/mjs/exclude/index' or its corresponding type declarations. + import * as type from "inner/js/exclude/index"; + ~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'inner/js/exclude/index' or its corresponding type declarations. + export { cjs }; + export { mjs }; + export { type }; +==== tests/cases/conformance/node/allowJs/package.json (0 errors) ==== + { + "name": "package", + "private": true, + "type": "module" + } +==== tests/cases/conformance/node/allowJs/node_modules/inner/package.json (0 errors) ==== + { + "name": "inner", + "private": true, + "exports": { + "./cjs/*": "./*.cjs", + "./cjs/exclude/*": null, + "./mjs/*": "./*.mjs", + "./mjs/exclude/*": null, + "./js/*": "./*.js", + "./js/exclude/*": null + } + } \ No newline at end of file diff --git a/tests/baselines/reference/nodeModulesAllowJsPackagePatternExportsExclude(module=node16).js b/tests/baselines/reference/nodeModulesAllowJsPackagePatternExportsExclude(module=node16).js new file mode 100644 index 0000000000000..7ede2700377a9 --- /dev/null +++ b/tests/baselines/reference/nodeModulesAllowJsPackagePatternExportsExclude(module=node16).js @@ -0,0 +1,127 @@ +//// [tests/cases/conformance/node/allowJs/nodeModulesAllowJsPackagePatternExportsExclude.ts] //// + +//// [index.js] +// esm format file +import * as cjsi from "inner/cjs/exclude/index"; +import * as mjsi from "inner/mjs/exclude/index"; +import * as typei from "inner/js/exclude/index"; +cjsi; +mjsi; +typei; +//// [index.mjs] +// esm format file +import * as cjsi from "inner/cjs/exclude/index"; +import * as mjsi from "inner/mjs/exclude/index"; +import * as typei from "inner/js/exclude/index"; +cjsi; +mjsi; +typei; +//// [index.cjs] +// cjs format file +import * as cjsi from "inner/cjs/exclude/index"; +import * as mjsi from "inner/mjs/exclude/index"; +import * as typei from "inner/js/exclude/index"; +cjsi; +mjsi; +typei; +//// [index.d.ts] +// cjs format file +import * as cjs from "inner/cjs/exclude/index"; +import * as mjs from "inner/mjs/exclude/index"; +import * as type from "inner/js/exclude/index"; +export { cjs }; +export { mjs }; +export { type }; +//// [index.d.mts] +// esm format file +import * as cjs from "inner/cjs/exclude/index"; +import * as mjs from "inner/mjs/exclude/index"; +import * as type from "inner/js/exclude/index"; +export { cjs }; +export { mjs }; +export { type }; +//// [index.d.cts] +// cjs format file +import * as cjs from "inner/cjs/exclude/index"; +import * as mjs from "inner/mjs/exclude/index"; +import * as type from "inner/js/exclude/index"; +export { cjs }; +export { mjs }; +export { type }; +//// [package.json] +{ + "name": "package", + "private": true, + "type": "module" +} +//// [package.json] +{ + "name": "inner", + "private": true, + "exports": { + "./cjs/*": "./*.cjs", + "./cjs/exclude/*": null, + "./mjs/*": "./*.mjs", + "./mjs/exclude/*": null, + "./js/*": "./*.js", + "./js/exclude/*": null + } +} + +//// [index.js] +// esm format file +import * as cjsi from "inner/cjs/exclude/index"; +import * as mjsi from "inner/mjs/exclude/index"; +import * as typei from "inner/js/exclude/index"; +cjsi; +mjsi; +typei; +//// [index.mjs] +// esm format file +import * as cjsi from "inner/cjs/exclude/index"; +import * as mjsi from "inner/mjs/exclude/index"; +import * as typei from "inner/js/exclude/index"; +cjsi; +mjsi; +typei; +//// [index.cjs] +"use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { + desc = { enumerable: true, get: function() { return m[k]; } }; + } + Object.defineProperty(o, k2, desc); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +// cjs format file +const cjsi = __importStar(require("inner/cjs/exclude/index")); +const mjsi = __importStar(require("inner/mjs/exclude/index")); +const typei = __importStar(require("inner/js/exclude/index")); +cjsi; +mjsi; +typei; + + +//// [index.d.ts] +export {}; +//// [index.d.mts] +export {}; +//// [index.d.cts] +export {}; diff --git a/tests/baselines/reference/nodeModulesAllowJsPackagePatternExportsExclude(module=node16).symbols b/tests/baselines/reference/nodeModulesAllowJsPackagePatternExportsExclude(module=node16).symbols new file mode 100644 index 0000000000000..ba8ceb18ddfba --- /dev/null +++ b/tests/baselines/reference/nodeModulesAllowJsPackagePatternExportsExclude(module=node16).symbols @@ -0,0 +1,120 @@ +=== tests/cases/conformance/node/allowJs/index.js === +// esm format file +import * as cjsi from "inner/cjs/exclude/index"; +>cjsi : Symbol(cjsi, Decl(index.js, 1, 6)) + +import * as mjsi from "inner/mjs/exclude/index"; +>mjsi : Symbol(mjsi, Decl(index.js, 2, 6)) + +import * as typei from "inner/js/exclude/index"; +>typei : Symbol(typei, Decl(index.js, 3, 6)) + +cjsi; +>cjsi : Symbol(cjsi, Decl(index.js, 1, 6)) + +mjsi; +>mjsi : Symbol(mjsi, Decl(index.js, 2, 6)) + +typei; +>typei : Symbol(typei, Decl(index.js, 3, 6)) + +=== tests/cases/conformance/node/allowJs/index.mjs === +// esm format file +import * as cjsi from "inner/cjs/exclude/index"; +>cjsi : Symbol(cjsi, Decl(index.mjs, 1, 6)) + +import * as mjsi from "inner/mjs/exclude/index"; +>mjsi : Symbol(mjsi, Decl(index.mjs, 2, 6)) + +import * as typei from "inner/js/exclude/index"; +>typei : Symbol(typei, Decl(index.mjs, 3, 6)) + +cjsi; +>cjsi : Symbol(cjsi, Decl(index.mjs, 1, 6)) + +mjsi; +>mjsi : Symbol(mjsi, Decl(index.mjs, 2, 6)) + +typei; +>typei : Symbol(typei, Decl(index.mjs, 3, 6)) + +=== tests/cases/conformance/node/allowJs/index.cjs === +// cjs format file +import * as cjsi from "inner/cjs/exclude/index"; +>cjsi : Symbol(cjsi, Decl(index.cjs, 1, 6)) + +import * as mjsi from "inner/mjs/exclude/index"; +>mjsi : Symbol(mjsi, Decl(index.cjs, 2, 6)) + +import * as typei from "inner/js/exclude/index"; +>typei : Symbol(typei, Decl(index.cjs, 3, 6)) + +cjsi; +>cjsi : Symbol(cjsi, Decl(index.cjs, 1, 6)) + +mjsi; +>mjsi : Symbol(mjsi, Decl(index.cjs, 2, 6)) + +typei; +>typei : Symbol(typei, Decl(index.cjs, 3, 6)) + +=== tests/cases/conformance/node/allowJs/node_modules/inner/exclude/index.d.ts === +// cjs format file +import * as cjs from "inner/cjs/exclude/index"; +>cjs : Symbol(cjs, Decl(index.d.ts, 1, 6)) + +import * as mjs from "inner/mjs/exclude/index"; +>mjs : Symbol(mjs, Decl(index.d.ts, 2, 6)) + +import * as type from "inner/js/exclude/index"; +>type : Symbol(type, Decl(index.d.ts, 3, 6)) + +export { cjs }; +>cjs : Symbol(cjs, Decl(index.d.ts, 4, 8)) + +export { mjs }; +>mjs : Symbol(mjs, Decl(index.d.ts, 5, 8)) + +export { type }; +>type : Symbol(type, Decl(index.d.ts, 6, 8)) + +=== tests/cases/conformance/node/allowJs/node_modules/inner/exclude/index.d.mts === +// esm format file +import * as cjs from "inner/cjs/exclude/index"; +>cjs : Symbol(cjs, Decl(index.d.mts, 1, 6)) + +import * as mjs from "inner/mjs/exclude/index"; +>mjs : Symbol(mjs, Decl(index.d.mts, 2, 6)) + +import * as type from "inner/js/exclude/index"; +>type : Symbol(type, Decl(index.d.mts, 3, 6)) + +export { cjs }; +>cjs : Symbol(cjs, Decl(index.d.mts, 4, 8)) + +export { mjs }; +>mjs : Symbol(mjs, Decl(index.d.mts, 5, 8)) + +export { type }; +>type : Symbol(type, Decl(index.d.mts, 6, 8)) + +=== tests/cases/conformance/node/allowJs/node_modules/inner/exclude/index.d.cts === +// cjs format file +import * as cjs from "inner/cjs/exclude/index"; +>cjs : Symbol(cjs, Decl(index.d.cts, 1, 6)) + +import * as mjs from "inner/mjs/exclude/index"; +>mjs : Symbol(mjs, Decl(index.d.cts, 2, 6)) + +import * as type from "inner/js/exclude/index"; +>type : Symbol(type, Decl(index.d.cts, 3, 6)) + +export { cjs }; +>cjs : Symbol(cjs, Decl(index.d.cts, 4, 8)) + +export { mjs }; +>mjs : Symbol(mjs, Decl(index.d.cts, 5, 8)) + +export { type }; +>type : Symbol(type, Decl(index.d.cts, 6, 8)) + diff --git a/tests/baselines/reference/nodeModulesAllowJsPackagePatternExportsExclude(module=node16).types b/tests/baselines/reference/nodeModulesAllowJsPackagePatternExportsExclude(module=node16).types new file mode 100644 index 0000000000000..85c53a5460da2 --- /dev/null +++ b/tests/baselines/reference/nodeModulesAllowJsPackagePatternExportsExclude(module=node16).types @@ -0,0 +1,120 @@ +=== tests/cases/conformance/node/allowJs/index.js === +// esm format file +import * as cjsi from "inner/cjs/exclude/index"; +>cjsi : any + +import * as mjsi from "inner/mjs/exclude/index"; +>mjsi : any + +import * as typei from "inner/js/exclude/index"; +>typei : any + +cjsi; +>cjsi : any + +mjsi; +>mjsi : any + +typei; +>typei : any + +=== tests/cases/conformance/node/allowJs/index.mjs === +// esm format file +import * as cjsi from "inner/cjs/exclude/index"; +>cjsi : any + +import * as mjsi from "inner/mjs/exclude/index"; +>mjsi : any + +import * as typei from "inner/js/exclude/index"; +>typei : any + +cjsi; +>cjsi : any + +mjsi; +>mjsi : any + +typei; +>typei : any + +=== tests/cases/conformance/node/allowJs/index.cjs === +// cjs format file +import * as cjsi from "inner/cjs/exclude/index"; +>cjsi : any + +import * as mjsi from "inner/mjs/exclude/index"; +>mjsi : any + +import * as typei from "inner/js/exclude/index"; +>typei : any + +cjsi; +>cjsi : any + +mjsi; +>mjsi : any + +typei; +>typei : any + +=== tests/cases/conformance/node/allowJs/node_modules/inner/exclude/index.d.ts === +// cjs format file +import * as cjs from "inner/cjs/exclude/index"; +>cjs : any + +import * as mjs from "inner/mjs/exclude/index"; +>mjs : any + +import * as type from "inner/js/exclude/index"; +>type : any + +export { cjs }; +>cjs : any + +export { mjs }; +>mjs : any + +export { type }; +>type : any + +=== tests/cases/conformance/node/allowJs/node_modules/inner/exclude/index.d.mts === +// esm format file +import * as cjs from "inner/cjs/exclude/index"; +>cjs : any + +import * as mjs from "inner/mjs/exclude/index"; +>mjs : any + +import * as type from "inner/js/exclude/index"; +>type : any + +export { cjs }; +>cjs : any + +export { mjs }; +>mjs : any + +export { type }; +>type : any + +=== tests/cases/conformance/node/allowJs/node_modules/inner/exclude/index.d.cts === +// cjs format file +import * as cjs from "inner/cjs/exclude/index"; +>cjs : any + +import * as mjs from "inner/mjs/exclude/index"; +>mjs : any + +import * as type from "inner/js/exclude/index"; +>type : any + +export { cjs }; +>cjs : any + +export { mjs }; +>mjs : any + +export { type }; +>type : any + diff --git a/tests/baselines/reference/nodeModulesAllowJsPackagePatternExportsExclude(module=nodenext).errors.txt b/tests/baselines/reference/nodeModulesAllowJsPackagePatternExportsExclude(module=nodenext).errors.txt new file mode 100644 index 0000000000000..d47318a006c10 --- /dev/null +++ b/tests/baselines/reference/nodeModulesAllowJsPackagePatternExportsExclude(module=nodenext).errors.txt @@ -0,0 +1,123 @@ +tests/cases/conformance/node/allowJs/index.cjs(2,23): error TS2307: Cannot find module 'inner/cjs/exclude/index' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/index.cjs(3,23): error TS2307: Cannot find module 'inner/mjs/exclude/index' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/index.cjs(4,24): error TS2307: Cannot find module 'inner/js/exclude/index' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/index.js(2,23): error TS2307: Cannot find module 'inner/cjs/exclude/index' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/index.js(3,23): error TS2307: Cannot find module 'inner/mjs/exclude/index' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/index.js(4,24): error TS2307: Cannot find module 'inner/js/exclude/index' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/index.mjs(2,23): error TS2307: Cannot find module 'inner/cjs/exclude/index' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/index.mjs(3,23): error TS2307: Cannot find module 'inner/mjs/exclude/index' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/index.mjs(4,24): error TS2307: Cannot find module 'inner/js/exclude/index' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/node_modules/inner/exclude/index.d.cts(2,22): error TS2307: Cannot find module 'inner/cjs/exclude/index' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/node_modules/inner/exclude/index.d.cts(3,22): error TS2307: Cannot find module 'inner/mjs/exclude/index' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/node_modules/inner/exclude/index.d.cts(4,23): error TS2307: Cannot find module 'inner/js/exclude/index' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/node_modules/inner/exclude/index.d.mts(2,22): error TS2307: Cannot find module 'inner/cjs/exclude/index' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/node_modules/inner/exclude/index.d.mts(3,22): error TS2307: Cannot find module 'inner/mjs/exclude/index' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/node_modules/inner/exclude/index.d.mts(4,23): error TS2307: Cannot find module 'inner/js/exclude/index' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/node_modules/inner/exclude/index.d.ts(2,22): error TS2307: Cannot find module 'inner/cjs/exclude/index' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/node_modules/inner/exclude/index.d.ts(3,22): error TS2307: Cannot find module 'inner/mjs/exclude/index' or its corresponding type declarations. +tests/cases/conformance/node/allowJs/node_modules/inner/exclude/index.d.ts(4,23): error TS2307: Cannot find module 'inner/js/exclude/index' or its corresponding type declarations. + + +==== tests/cases/conformance/node/allowJs/index.js (3 errors) ==== + // esm format file + import * as cjsi from "inner/cjs/exclude/index"; + ~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'inner/cjs/exclude/index' or its corresponding type declarations. + import * as mjsi from "inner/mjs/exclude/index"; + ~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'inner/mjs/exclude/index' or its corresponding type declarations. + import * as typei from "inner/js/exclude/index"; + ~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'inner/js/exclude/index' or its corresponding type declarations. + cjsi; + mjsi; + typei; +==== tests/cases/conformance/node/allowJs/index.mjs (3 errors) ==== + // esm format file + import * as cjsi from "inner/cjs/exclude/index"; + ~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'inner/cjs/exclude/index' or its corresponding type declarations. + import * as mjsi from "inner/mjs/exclude/index"; + ~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'inner/mjs/exclude/index' or its corresponding type declarations. + import * as typei from "inner/js/exclude/index"; + ~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'inner/js/exclude/index' or its corresponding type declarations. + cjsi; + mjsi; + typei; +==== tests/cases/conformance/node/allowJs/index.cjs (3 errors) ==== + // cjs format file + import * as cjsi from "inner/cjs/exclude/index"; + ~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'inner/cjs/exclude/index' or its corresponding type declarations. + import * as mjsi from "inner/mjs/exclude/index"; + ~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'inner/mjs/exclude/index' or its corresponding type declarations. + import * as typei from "inner/js/exclude/index"; + ~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'inner/js/exclude/index' or its corresponding type declarations. + cjsi; + mjsi; + typei; +==== tests/cases/conformance/node/allowJs/node_modules/inner/exclude/index.d.ts (3 errors) ==== + // cjs format file + import * as cjs from "inner/cjs/exclude/index"; + ~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'inner/cjs/exclude/index' or its corresponding type declarations. + import * as mjs from "inner/mjs/exclude/index"; + ~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'inner/mjs/exclude/index' or its corresponding type declarations. + import * as type from "inner/js/exclude/index"; + ~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'inner/js/exclude/index' or its corresponding type declarations. + export { cjs }; + export { mjs }; + export { type }; +==== tests/cases/conformance/node/allowJs/node_modules/inner/exclude/index.d.mts (3 errors) ==== + // esm format file + import * as cjs from "inner/cjs/exclude/index"; + ~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'inner/cjs/exclude/index' or its corresponding type declarations. + import * as mjs from "inner/mjs/exclude/index"; + ~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'inner/mjs/exclude/index' or its corresponding type declarations. + import * as type from "inner/js/exclude/index"; + ~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'inner/js/exclude/index' or its corresponding type declarations. + export { cjs }; + export { mjs }; + export { type }; +==== tests/cases/conformance/node/allowJs/node_modules/inner/exclude/index.d.cts (3 errors) ==== + // cjs format file + import * as cjs from "inner/cjs/exclude/index"; + ~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'inner/cjs/exclude/index' or its corresponding type declarations. + import * as mjs from "inner/mjs/exclude/index"; + ~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'inner/mjs/exclude/index' or its corresponding type declarations. + import * as type from "inner/js/exclude/index"; + ~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'inner/js/exclude/index' or its corresponding type declarations. + export { cjs }; + export { mjs }; + export { type }; +==== tests/cases/conformance/node/allowJs/package.json (0 errors) ==== + { + "name": "package", + "private": true, + "type": "module" + } +==== tests/cases/conformance/node/allowJs/node_modules/inner/package.json (0 errors) ==== + { + "name": "inner", + "private": true, + "exports": { + "./cjs/*": "./*.cjs", + "./cjs/exclude/*": null, + "./mjs/*": "./*.mjs", + "./mjs/exclude/*": null, + "./js/*": "./*.js", + "./js/exclude/*": null + } + } \ No newline at end of file diff --git a/tests/baselines/reference/nodeModulesAllowJsPackagePatternExportsExclude(module=nodenext).js b/tests/baselines/reference/nodeModulesAllowJsPackagePatternExportsExclude(module=nodenext).js new file mode 100644 index 0000000000000..7ede2700377a9 --- /dev/null +++ b/tests/baselines/reference/nodeModulesAllowJsPackagePatternExportsExclude(module=nodenext).js @@ -0,0 +1,127 @@ +//// [tests/cases/conformance/node/allowJs/nodeModulesAllowJsPackagePatternExportsExclude.ts] //// + +//// [index.js] +// esm format file +import * as cjsi from "inner/cjs/exclude/index"; +import * as mjsi from "inner/mjs/exclude/index"; +import * as typei from "inner/js/exclude/index"; +cjsi; +mjsi; +typei; +//// [index.mjs] +// esm format file +import * as cjsi from "inner/cjs/exclude/index"; +import * as mjsi from "inner/mjs/exclude/index"; +import * as typei from "inner/js/exclude/index"; +cjsi; +mjsi; +typei; +//// [index.cjs] +// cjs format file +import * as cjsi from "inner/cjs/exclude/index"; +import * as mjsi from "inner/mjs/exclude/index"; +import * as typei from "inner/js/exclude/index"; +cjsi; +mjsi; +typei; +//// [index.d.ts] +// cjs format file +import * as cjs from "inner/cjs/exclude/index"; +import * as mjs from "inner/mjs/exclude/index"; +import * as type from "inner/js/exclude/index"; +export { cjs }; +export { mjs }; +export { type }; +//// [index.d.mts] +// esm format file +import * as cjs from "inner/cjs/exclude/index"; +import * as mjs from "inner/mjs/exclude/index"; +import * as type from "inner/js/exclude/index"; +export { cjs }; +export { mjs }; +export { type }; +//// [index.d.cts] +// cjs format file +import * as cjs from "inner/cjs/exclude/index"; +import * as mjs from "inner/mjs/exclude/index"; +import * as type from "inner/js/exclude/index"; +export { cjs }; +export { mjs }; +export { type }; +//// [package.json] +{ + "name": "package", + "private": true, + "type": "module" +} +//// [package.json] +{ + "name": "inner", + "private": true, + "exports": { + "./cjs/*": "./*.cjs", + "./cjs/exclude/*": null, + "./mjs/*": "./*.mjs", + "./mjs/exclude/*": null, + "./js/*": "./*.js", + "./js/exclude/*": null + } +} + +//// [index.js] +// esm format file +import * as cjsi from "inner/cjs/exclude/index"; +import * as mjsi from "inner/mjs/exclude/index"; +import * as typei from "inner/js/exclude/index"; +cjsi; +mjsi; +typei; +//// [index.mjs] +// esm format file +import * as cjsi from "inner/cjs/exclude/index"; +import * as mjsi from "inner/mjs/exclude/index"; +import * as typei from "inner/js/exclude/index"; +cjsi; +mjsi; +typei; +//// [index.cjs] +"use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { + desc = { enumerable: true, get: function() { return m[k]; } }; + } + Object.defineProperty(o, k2, desc); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +// cjs format file +const cjsi = __importStar(require("inner/cjs/exclude/index")); +const mjsi = __importStar(require("inner/mjs/exclude/index")); +const typei = __importStar(require("inner/js/exclude/index")); +cjsi; +mjsi; +typei; + + +//// [index.d.ts] +export {}; +//// [index.d.mts] +export {}; +//// [index.d.cts] +export {}; diff --git a/tests/baselines/reference/nodeModulesAllowJsPackagePatternExportsExclude(module=nodenext).symbols b/tests/baselines/reference/nodeModulesAllowJsPackagePatternExportsExclude(module=nodenext).symbols new file mode 100644 index 0000000000000..ba8ceb18ddfba --- /dev/null +++ b/tests/baselines/reference/nodeModulesAllowJsPackagePatternExportsExclude(module=nodenext).symbols @@ -0,0 +1,120 @@ +=== tests/cases/conformance/node/allowJs/index.js === +// esm format file +import * as cjsi from "inner/cjs/exclude/index"; +>cjsi : Symbol(cjsi, Decl(index.js, 1, 6)) + +import * as mjsi from "inner/mjs/exclude/index"; +>mjsi : Symbol(mjsi, Decl(index.js, 2, 6)) + +import * as typei from "inner/js/exclude/index"; +>typei : Symbol(typei, Decl(index.js, 3, 6)) + +cjsi; +>cjsi : Symbol(cjsi, Decl(index.js, 1, 6)) + +mjsi; +>mjsi : Symbol(mjsi, Decl(index.js, 2, 6)) + +typei; +>typei : Symbol(typei, Decl(index.js, 3, 6)) + +=== tests/cases/conformance/node/allowJs/index.mjs === +// esm format file +import * as cjsi from "inner/cjs/exclude/index"; +>cjsi : Symbol(cjsi, Decl(index.mjs, 1, 6)) + +import * as mjsi from "inner/mjs/exclude/index"; +>mjsi : Symbol(mjsi, Decl(index.mjs, 2, 6)) + +import * as typei from "inner/js/exclude/index"; +>typei : Symbol(typei, Decl(index.mjs, 3, 6)) + +cjsi; +>cjsi : Symbol(cjsi, Decl(index.mjs, 1, 6)) + +mjsi; +>mjsi : Symbol(mjsi, Decl(index.mjs, 2, 6)) + +typei; +>typei : Symbol(typei, Decl(index.mjs, 3, 6)) + +=== tests/cases/conformance/node/allowJs/index.cjs === +// cjs format file +import * as cjsi from "inner/cjs/exclude/index"; +>cjsi : Symbol(cjsi, Decl(index.cjs, 1, 6)) + +import * as mjsi from "inner/mjs/exclude/index"; +>mjsi : Symbol(mjsi, Decl(index.cjs, 2, 6)) + +import * as typei from "inner/js/exclude/index"; +>typei : Symbol(typei, Decl(index.cjs, 3, 6)) + +cjsi; +>cjsi : Symbol(cjsi, Decl(index.cjs, 1, 6)) + +mjsi; +>mjsi : Symbol(mjsi, Decl(index.cjs, 2, 6)) + +typei; +>typei : Symbol(typei, Decl(index.cjs, 3, 6)) + +=== tests/cases/conformance/node/allowJs/node_modules/inner/exclude/index.d.ts === +// cjs format file +import * as cjs from "inner/cjs/exclude/index"; +>cjs : Symbol(cjs, Decl(index.d.ts, 1, 6)) + +import * as mjs from "inner/mjs/exclude/index"; +>mjs : Symbol(mjs, Decl(index.d.ts, 2, 6)) + +import * as type from "inner/js/exclude/index"; +>type : Symbol(type, Decl(index.d.ts, 3, 6)) + +export { cjs }; +>cjs : Symbol(cjs, Decl(index.d.ts, 4, 8)) + +export { mjs }; +>mjs : Symbol(mjs, Decl(index.d.ts, 5, 8)) + +export { type }; +>type : Symbol(type, Decl(index.d.ts, 6, 8)) + +=== tests/cases/conformance/node/allowJs/node_modules/inner/exclude/index.d.mts === +// esm format file +import * as cjs from "inner/cjs/exclude/index"; +>cjs : Symbol(cjs, Decl(index.d.mts, 1, 6)) + +import * as mjs from "inner/mjs/exclude/index"; +>mjs : Symbol(mjs, Decl(index.d.mts, 2, 6)) + +import * as type from "inner/js/exclude/index"; +>type : Symbol(type, Decl(index.d.mts, 3, 6)) + +export { cjs }; +>cjs : Symbol(cjs, Decl(index.d.mts, 4, 8)) + +export { mjs }; +>mjs : Symbol(mjs, Decl(index.d.mts, 5, 8)) + +export { type }; +>type : Symbol(type, Decl(index.d.mts, 6, 8)) + +=== tests/cases/conformance/node/allowJs/node_modules/inner/exclude/index.d.cts === +// cjs format file +import * as cjs from "inner/cjs/exclude/index"; +>cjs : Symbol(cjs, Decl(index.d.cts, 1, 6)) + +import * as mjs from "inner/mjs/exclude/index"; +>mjs : Symbol(mjs, Decl(index.d.cts, 2, 6)) + +import * as type from "inner/js/exclude/index"; +>type : Symbol(type, Decl(index.d.cts, 3, 6)) + +export { cjs }; +>cjs : Symbol(cjs, Decl(index.d.cts, 4, 8)) + +export { mjs }; +>mjs : Symbol(mjs, Decl(index.d.cts, 5, 8)) + +export { type }; +>type : Symbol(type, Decl(index.d.cts, 6, 8)) + diff --git a/tests/baselines/reference/nodeModulesAllowJsPackagePatternExportsExclude(module=nodenext).types b/tests/baselines/reference/nodeModulesAllowJsPackagePatternExportsExclude(module=nodenext).types new file mode 100644 index 0000000000000..85c53a5460da2 --- /dev/null +++ b/tests/baselines/reference/nodeModulesAllowJsPackagePatternExportsExclude(module=nodenext).types @@ -0,0 +1,120 @@ +=== tests/cases/conformance/node/allowJs/index.js === +// esm format file +import * as cjsi from "inner/cjs/exclude/index"; +>cjsi : any + +import * as mjsi from "inner/mjs/exclude/index"; +>mjsi : any + +import * as typei from "inner/js/exclude/index"; +>typei : any + +cjsi; +>cjsi : any + +mjsi; +>mjsi : any + +typei; +>typei : any + +=== tests/cases/conformance/node/allowJs/index.mjs === +// esm format file +import * as cjsi from "inner/cjs/exclude/index"; +>cjsi : any + +import * as mjsi from "inner/mjs/exclude/index"; +>mjsi : any + +import * as typei from "inner/js/exclude/index"; +>typei : any + +cjsi; +>cjsi : any + +mjsi; +>mjsi : any + +typei; +>typei : any + +=== tests/cases/conformance/node/allowJs/index.cjs === +// cjs format file +import * as cjsi from "inner/cjs/exclude/index"; +>cjsi : any + +import * as mjsi from "inner/mjs/exclude/index"; +>mjsi : any + +import * as typei from "inner/js/exclude/index"; +>typei : any + +cjsi; +>cjsi : any + +mjsi; +>mjsi : any + +typei; +>typei : any + +=== tests/cases/conformance/node/allowJs/node_modules/inner/exclude/index.d.ts === +// cjs format file +import * as cjs from "inner/cjs/exclude/index"; +>cjs : any + +import * as mjs from "inner/mjs/exclude/index"; +>mjs : any + +import * as type from "inner/js/exclude/index"; +>type : any + +export { cjs }; +>cjs : any + +export { mjs }; +>mjs : any + +export { type }; +>type : any + +=== tests/cases/conformance/node/allowJs/node_modules/inner/exclude/index.d.mts === +// esm format file +import * as cjs from "inner/cjs/exclude/index"; +>cjs : any + +import * as mjs from "inner/mjs/exclude/index"; +>mjs : any + +import * as type from "inner/js/exclude/index"; +>type : any + +export { cjs }; +>cjs : any + +export { mjs }; +>mjs : any + +export { type }; +>type : any + +=== tests/cases/conformance/node/allowJs/node_modules/inner/exclude/index.d.cts === +// cjs format file +import * as cjs from "inner/cjs/exclude/index"; +>cjs : any + +import * as mjs from "inner/mjs/exclude/index"; +>mjs : any + +import * as type from "inner/js/exclude/index"; +>type : any + +export { cjs }; +>cjs : any + +export { mjs }; +>mjs : any + +export { type }; +>type : any + diff --git a/tests/baselines/reference/nodeModulesPackagePatternExportsExclude(module=node16).errors.txt b/tests/baselines/reference/nodeModulesPackagePatternExportsExclude(module=node16).errors.txt new file mode 100644 index 0000000000000..863b455cf4796 --- /dev/null +++ b/tests/baselines/reference/nodeModulesPackagePatternExportsExclude(module=node16).errors.txt @@ -0,0 +1,177 @@ +tests/cases/conformance/node/index.cts(2,23): error TS2307: Cannot find module 'inner/cjs/exclude/index' or its corresponding type declarations. +tests/cases/conformance/node/index.cts(3,23): error TS2307: Cannot find module 'inner/mjs/exclude/index' or its corresponding type declarations. +tests/cases/conformance/node/index.cts(4,24): error TS2307: Cannot find module 'inner/js/exclude/index' or its corresponding type declarations. +tests/cases/conformance/node/index.cts(9,24): error TS1471: Module 'inner/mjs/index' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/index.mts(2,23): error TS2307: Cannot find module 'inner/cjs/exclude/index' or its corresponding type declarations. +tests/cases/conformance/node/index.mts(3,23): error TS2307: Cannot find module 'inner/mjs/exclude/index' or its corresponding type declarations. +tests/cases/conformance/node/index.mts(4,24): error TS2307: Cannot find module 'inner/js/exclude/index' or its corresponding type declarations. +tests/cases/conformance/node/index.ts(2,23): error TS2307: Cannot find module 'inner/cjs/exclude/index' or its corresponding type declarations. +tests/cases/conformance/node/index.ts(3,23): error TS2307: Cannot find module 'inner/mjs/exclude/index' or its corresponding type declarations. +tests/cases/conformance/node/index.ts(4,24): error TS2307: Cannot find module 'inner/js/exclude/index' or its corresponding type declarations. +tests/cases/conformance/node/node_modules/inner/exclude/index.d.cts(2,22): error TS2307: Cannot find module 'inner/cjs/exclude/index' or its corresponding type declarations. +tests/cases/conformance/node/node_modules/inner/exclude/index.d.cts(3,22): error TS2307: Cannot find module 'inner/mjs/exclude/index' or its corresponding type declarations. +tests/cases/conformance/node/node_modules/inner/exclude/index.d.cts(4,23): error TS2307: Cannot find module 'inner/js/exclude/index' or its corresponding type declarations. +tests/cases/conformance/node/node_modules/inner/exclude/index.d.mts(2,22): error TS2307: Cannot find module 'inner/cjs/exclude/index' or its corresponding type declarations. +tests/cases/conformance/node/node_modules/inner/exclude/index.d.mts(3,22): error TS2307: Cannot find module 'inner/mjs/exclude/index' or its corresponding type declarations. +tests/cases/conformance/node/node_modules/inner/exclude/index.d.mts(4,23): error TS2307: Cannot find module 'inner/js/exclude/index' or its corresponding type declarations. +tests/cases/conformance/node/node_modules/inner/exclude/index.d.ts(2,22): error TS2307: Cannot find module 'inner/cjs/exclude/index' or its corresponding type declarations. +tests/cases/conformance/node/node_modules/inner/exclude/index.d.ts(3,22): error TS2307: Cannot find module 'inner/mjs/exclude/index' or its corresponding type declarations. +tests/cases/conformance/node/node_modules/inner/exclude/index.d.ts(4,23): error TS2307: Cannot find module 'inner/js/exclude/index' or its corresponding type declarations. +tests/cases/conformance/node/node_modules/inner/index.d.cts(3,22): error TS1471: Module 'inner/mjs/index' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/node_modules/inner/index.d.ts(2,13): error TS2303: Circular definition of import alias 'cjs'. +tests/cases/conformance/node/node_modules/inner/index.d.ts(3,22): error TS1471: Module 'inner/mjs/index' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. + + +==== tests/cases/conformance/node/index.ts (3 errors) ==== + // esm format file + import * as cjsi from "inner/cjs/exclude/index"; + ~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'inner/cjs/exclude/index' or its corresponding type declarations. + import * as mjsi from "inner/mjs/exclude/index"; + ~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'inner/mjs/exclude/index' or its corresponding type declarations. + import * as typei from "inner/js/exclude/index"; + ~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'inner/js/exclude/index' or its corresponding type declarations. + cjsi; + mjsi; + typei; + import * as cjsi2 from "inner/cjs/index"; + import * as mjsi2 from "inner/mjs/index"; + import * as typei2 from "inner/js/index"; + cjsi2; + mjsi2; + typei2; +==== tests/cases/conformance/node/index.mts (3 errors) ==== + // esm format file + import * as cjsi from "inner/cjs/exclude/index"; + ~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'inner/cjs/exclude/index' or its corresponding type declarations. + import * as mjsi from "inner/mjs/exclude/index"; + ~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'inner/mjs/exclude/index' or its corresponding type declarations. + import * as typei from "inner/js/exclude/index"; + ~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'inner/js/exclude/index' or its corresponding type declarations. + cjsi; + mjsi; + typei; + import * as cjsi2 from "inner/cjs/index"; + import * as mjsi2 from "inner/mjs/index"; + import * as typei2 from "inner/js/index"; + cjsi2; + mjsi2; + typei2; +==== tests/cases/conformance/node/index.cts (4 errors) ==== + // cjs format file + import * as cjsi from "inner/cjs/exclude/index"; + ~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'inner/cjs/exclude/index' or its corresponding type declarations. + import * as mjsi from "inner/mjs/exclude/index"; + ~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'inner/mjs/exclude/index' or its corresponding type declarations. + import * as typei from "inner/js/exclude/index"; + ~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'inner/js/exclude/index' or its corresponding type declarations. + cjsi; + mjsi; + typei; + import * as cjsi2 from "inner/cjs/index"; + import * as mjsi2 from "inner/mjs/index"; + ~~~~~~~~~~~~~~~~~ +!!! error TS1471: Module 'inner/mjs/index' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. + import * as typei2 from "inner/js/index"; + cjsi2; + mjsi2; + typei2; +==== tests/cases/conformance/node/node_modules/inner/exclude/index.d.ts (3 errors) ==== + // cjs format file + import * as cjs from "inner/cjs/exclude/index"; + ~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'inner/cjs/exclude/index' or its corresponding type declarations. + import * as mjs from "inner/mjs/exclude/index"; + ~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'inner/mjs/exclude/index' or its corresponding type declarations. + import * as type from "inner/js/exclude/index"; + ~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'inner/js/exclude/index' or its corresponding type declarations. + export { cjs }; + export { mjs }; + export { type }; +==== tests/cases/conformance/node/node_modules/inner/exclude/index.d.mts (3 errors) ==== + // esm format file + import * as cjs from "inner/cjs/exclude/index"; + ~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'inner/cjs/exclude/index' or its corresponding type declarations. + import * as mjs from "inner/mjs/exclude/index"; + ~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'inner/mjs/exclude/index' or its corresponding type declarations. + import * as type from "inner/js/exclude/index"; + ~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'inner/js/exclude/index' or its corresponding type declarations. + export { cjs }; + export { mjs }; + export { type }; +==== tests/cases/conformance/node/node_modules/inner/exclude/index.d.cts (3 errors) ==== + // cjs format file + import * as cjs from "inner/cjs/exclude/index"; + ~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'inner/cjs/exclude/index' or its corresponding type declarations. + import * as mjs from "inner/mjs/exclude/index"; + ~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'inner/mjs/exclude/index' or its corresponding type declarations. + import * as type from "inner/js/exclude/index"; + ~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'inner/js/exclude/index' or its corresponding type declarations. + export { cjs }; + export { mjs }; + export { type }; +==== tests/cases/conformance/node/node_modules/inner/index.d.ts (2 errors) ==== + // cjs format file + import * as cjs from "inner/cjs/index"; + ~~~ +!!! error TS2303: Circular definition of import alias 'cjs'. + import * as mjs from "inner/mjs/index"; + ~~~~~~~~~~~~~~~~~ +!!! error TS1471: Module 'inner/mjs/index' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. + import * as type from "inner/js/index"; + export { cjs }; + export { mjs }; + export { type }; +==== tests/cases/conformance/node/node_modules/inner/index.d.mts (0 errors) ==== + // esm format file + import * as cjs from "inner/cjs/index"; + import * as mjs from "inner/mjs/index"; + import * as type from "inner/js/index"; + export { cjs }; + export { mjs }; + export { type }; +==== tests/cases/conformance/node/node_modules/inner/index.d.cts (1 errors) ==== + // cjs format file + import * as cjs from "inner/cjs/index"; + import * as mjs from "inner/mjs/index"; + ~~~~~~~~~~~~~~~~~ +!!! error TS1471: Module 'inner/mjs/index' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. + import * as type from "inner/js/index"; + export { cjs }; + export { mjs }; + export { type }; +==== tests/cases/conformance/node/package.json (0 errors) ==== + { + "name": "package", + "private": true, + "type": "module" + } +==== tests/cases/conformance/node/node_modules/inner/package.json (0 errors) ==== + { + "name": "inner", + "private": true, + "exports": { + "./cjs/*": "./*.cjs", + "./cjs/exclude/*": null, + "./mjs/*": "./*.mjs", + "./mjs/exclude/*": null, + "./js/*": "./*.js", + "./js/exclude/*": null + } + } \ No newline at end of file diff --git a/tests/baselines/reference/nodeModulesPackagePatternExportsExclude(module=node16).js b/tests/baselines/reference/nodeModulesPackagePatternExportsExclude(module=node16).js new file mode 100644 index 0000000000000..5c3a1fea21903 --- /dev/null +++ b/tests/baselines/reference/nodeModulesPackagePatternExportsExclude(module=node16).js @@ -0,0 +1,187 @@ +//// [tests/cases/conformance/node/nodeModulesPackagePatternExportsExclude.ts] //// + +//// [index.ts] +// esm format file +import * as cjsi from "inner/cjs/exclude/index"; +import * as mjsi from "inner/mjs/exclude/index"; +import * as typei from "inner/js/exclude/index"; +cjsi; +mjsi; +typei; +import * as cjsi2 from "inner/cjs/index"; +import * as mjsi2 from "inner/mjs/index"; +import * as typei2 from "inner/js/index"; +cjsi2; +mjsi2; +typei2; +//// [index.mts] +// esm format file +import * as cjsi from "inner/cjs/exclude/index"; +import * as mjsi from "inner/mjs/exclude/index"; +import * as typei from "inner/js/exclude/index"; +cjsi; +mjsi; +typei; +import * as cjsi2 from "inner/cjs/index"; +import * as mjsi2 from "inner/mjs/index"; +import * as typei2 from "inner/js/index"; +cjsi2; +mjsi2; +typei2; +//// [index.cts] +// cjs format file +import * as cjsi from "inner/cjs/exclude/index"; +import * as mjsi from "inner/mjs/exclude/index"; +import * as typei from "inner/js/exclude/index"; +cjsi; +mjsi; +typei; +import * as cjsi2 from "inner/cjs/index"; +import * as mjsi2 from "inner/mjs/index"; +import * as typei2 from "inner/js/index"; +cjsi2; +mjsi2; +typei2; +//// [index.d.ts] +// cjs format file +import * as cjs from "inner/cjs/exclude/index"; +import * as mjs from "inner/mjs/exclude/index"; +import * as type from "inner/js/exclude/index"; +export { cjs }; +export { mjs }; +export { type }; +//// [index.d.mts] +// esm format file +import * as cjs from "inner/cjs/exclude/index"; +import * as mjs from "inner/mjs/exclude/index"; +import * as type from "inner/js/exclude/index"; +export { cjs }; +export { mjs }; +export { type }; +//// [index.d.cts] +// cjs format file +import * as cjs from "inner/cjs/exclude/index"; +import * as mjs from "inner/mjs/exclude/index"; +import * as type from "inner/js/exclude/index"; +export { cjs }; +export { mjs }; +export { type }; +//// [index.d.ts] +// cjs format file +import * as cjs from "inner/cjs/index"; +import * as mjs from "inner/mjs/index"; +import * as type from "inner/js/index"; +export { cjs }; +export { mjs }; +export { type }; +//// [index.d.mts] +// esm format file +import * as cjs from "inner/cjs/index"; +import * as mjs from "inner/mjs/index"; +import * as type from "inner/js/index"; +export { cjs }; +export { mjs }; +export { type }; +//// [index.d.cts] +// cjs format file +import * as cjs from "inner/cjs/index"; +import * as mjs from "inner/mjs/index"; +import * as type from "inner/js/index"; +export { cjs }; +export { mjs }; +export { type }; +//// [package.json] +{ + "name": "package", + "private": true, + "type": "module" +} +//// [package.json] +{ + "name": "inner", + "private": true, + "exports": { + "./cjs/*": "./*.cjs", + "./cjs/exclude/*": null, + "./mjs/*": "./*.mjs", + "./mjs/exclude/*": null, + "./js/*": "./*.js", + "./js/exclude/*": null + } +} + +//// [index.js] +// esm format file +import * as cjsi from "inner/cjs/exclude/index"; +import * as mjsi from "inner/mjs/exclude/index"; +import * as typei from "inner/js/exclude/index"; +cjsi; +mjsi; +typei; +import * as cjsi2 from "inner/cjs/index"; +import * as mjsi2 from "inner/mjs/index"; +import * as typei2 from "inner/js/index"; +cjsi2; +mjsi2; +typei2; +//// [index.mjs] +// esm format file +import * as cjsi from "inner/cjs/exclude/index"; +import * as mjsi from "inner/mjs/exclude/index"; +import * as typei from "inner/js/exclude/index"; +cjsi; +mjsi; +typei; +import * as cjsi2 from "inner/cjs/index"; +import * as mjsi2 from "inner/mjs/index"; +import * as typei2 from "inner/js/index"; +cjsi2; +mjsi2; +typei2; +//// [index.cjs] +"use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { + desc = { enumerable: true, get: function() { return m[k]; } }; + } + Object.defineProperty(o, k2, desc); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +// cjs format file +const cjsi = __importStar(require("inner/cjs/exclude/index")); +const mjsi = __importStar(require("inner/mjs/exclude/index")); +const typei = __importStar(require("inner/js/exclude/index")); +cjsi; +mjsi; +typei; +const cjsi2 = __importStar(require("inner/cjs/index")); +const mjsi2 = __importStar(require("inner/mjs/index")); +const typei2 = __importStar(require("inner/js/index")); +cjsi2; +mjsi2; +typei2; + + +//// [index.d.ts] +export {}; +//// [index.d.mts] +export {}; +//// [index.d.cts] +export {}; diff --git a/tests/baselines/reference/nodeModulesPackagePatternExportsExclude(module=node16).symbols b/tests/baselines/reference/nodeModulesPackagePatternExportsExclude(module=node16).symbols new file mode 100644 index 0000000000000..6114f146f235f --- /dev/null +++ b/tests/baselines/reference/nodeModulesPackagePatternExportsExclude(module=node16).symbols @@ -0,0 +1,234 @@ +=== tests/cases/conformance/node/index.ts === +// esm format file +import * as cjsi from "inner/cjs/exclude/index"; +>cjsi : Symbol(cjsi, Decl(index.ts, 1, 6)) + +import * as mjsi from "inner/mjs/exclude/index"; +>mjsi : Symbol(mjsi, Decl(index.ts, 2, 6)) + +import * as typei from "inner/js/exclude/index"; +>typei : Symbol(typei, Decl(index.ts, 3, 6)) + +cjsi; +>cjsi : Symbol(cjsi, Decl(index.ts, 1, 6)) + +mjsi; +>mjsi : Symbol(mjsi, Decl(index.ts, 2, 6)) + +typei; +>typei : Symbol(typei, Decl(index.ts, 3, 6)) + +import * as cjsi2 from "inner/cjs/index"; +>cjsi2 : Symbol(cjsi2, Decl(index.ts, 7, 6)) + +import * as mjsi2 from "inner/mjs/index"; +>mjsi2 : Symbol(mjsi2, Decl(index.ts, 8, 6)) + +import * as typei2 from "inner/js/index"; +>typei2 : Symbol(typei2, Decl(index.ts, 9, 6)) + +cjsi2; +>cjsi2 : Symbol(cjsi2, Decl(index.ts, 7, 6)) + +mjsi2; +>mjsi2 : Symbol(mjsi2, Decl(index.ts, 8, 6)) + +typei2; +>typei2 : Symbol(typei2, Decl(index.ts, 9, 6)) + +=== tests/cases/conformance/node/index.mts === +// esm format file +import * as cjsi from "inner/cjs/exclude/index"; +>cjsi : Symbol(cjsi, Decl(index.mts, 1, 6)) + +import * as mjsi from "inner/mjs/exclude/index"; +>mjsi : Symbol(mjsi, Decl(index.mts, 2, 6)) + +import * as typei from "inner/js/exclude/index"; +>typei : Symbol(typei, Decl(index.mts, 3, 6)) + +cjsi; +>cjsi : Symbol(cjsi, Decl(index.mts, 1, 6)) + +mjsi; +>mjsi : Symbol(mjsi, Decl(index.mts, 2, 6)) + +typei; +>typei : Symbol(typei, Decl(index.mts, 3, 6)) + +import * as cjsi2 from "inner/cjs/index"; +>cjsi2 : Symbol(cjsi2, Decl(index.mts, 7, 6)) + +import * as mjsi2 from "inner/mjs/index"; +>mjsi2 : Symbol(mjsi2, Decl(index.mts, 8, 6)) + +import * as typei2 from "inner/js/index"; +>typei2 : Symbol(typei2, Decl(index.mts, 9, 6)) + +cjsi2; +>cjsi2 : Symbol(cjsi2, Decl(index.mts, 7, 6)) + +mjsi2; +>mjsi2 : Symbol(mjsi2, Decl(index.mts, 8, 6)) + +typei2; +>typei2 : Symbol(typei2, Decl(index.mts, 9, 6)) + +=== tests/cases/conformance/node/index.cts === +// cjs format file +import * as cjsi from "inner/cjs/exclude/index"; +>cjsi : Symbol(cjsi, Decl(index.cts, 1, 6)) + +import * as mjsi from "inner/mjs/exclude/index"; +>mjsi : Symbol(mjsi, Decl(index.cts, 2, 6)) + +import * as typei from "inner/js/exclude/index"; +>typei : Symbol(typei, Decl(index.cts, 3, 6)) + +cjsi; +>cjsi : Symbol(cjsi, Decl(index.cts, 1, 6)) + +mjsi; +>mjsi : Symbol(mjsi, Decl(index.cts, 2, 6)) + +typei; +>typei : Symbol(typei, Decl(index.cts, 3, 6)) + +import * as cjsi2 from "inner/cjs/index"; +>cjsi2 : Symbol(cjsi2, Decl(index.cts, 7, 6)) + +import * as mjsi2 from "inner/mjs/index"; +>mjsi2 : Symbol(mjsi2, Decl(index.cts, 8, 6)) + +import * as typei2 from "inner/js/index"; +>typei2 : Symbol(typei2, Decl(index.cts, 9, 6)) + +cjsi2; +>cjsi2 : Symbol(cjsi2, Decl(index.cts, 7, 6)) + +mjsi2; +>mjsi2 : Symbol(mjsi2, Decl(index.cts, 8, 6)) + +typei2; +>typei2 : Symbol(typei2, Decl(index.cts, 9, 6)) + +=== tests/cases/conformance/node/node_modules/inner/exclude/index.d.ts === +// cjs format file +import * as cjs from "inner/cjs/exclude/index"; +>cjs : Symbol(cjs, Decl(index.d.ts, 1, 6)) + +import * as mjs from "inner/mjs/exclude/index"; +>mjs : Symbol(mjs, Decl(index.d.ts, 2, 6)) + +import * as type from "inner/js/exclude/index"; +>type : Symbol(type, Decl(index.d.ts, 3, 6)) + +export { cjs }; +>cjs : Symbol(cjs, Decl(index.d.ts, 4, 8)) + +export { mjs }; +>mjs : Symbol(mjs, Decl(index.d.ts, 5, 8)) + +export { type }; +>type : Symbol(type, Decl(index.d.ts, 6, 8)) + +=== tests/cases/conformance/node/node_modules/inner/exclude/index.d.mts === +// esm format file +import * as cjs from "inner/cjs/exclude/index"; +>cjs : Symbol(cjs, Decl(index.d.mts, 1, 6)) + +import * as mjs from "inner/mjs/exclude/index"; +>mjs : Symbol(mjs, Decl(index.d.mts, 2, 6)) + +import * as type from "inner/js/exclude/index"; +>type : Symbol(type, Decl(index.d.mts, 3, 6)) + +export { cjs }; +>cjs : Symbol(cjs, Decl(index.d.mts, 4, 8)) + +export { mjs }; +>mjs : Symbol(mjs, Decl(index.d.mts, 5, 8)) + +export { type }; +>type : Symbol(type, Decl(index.d.mts, 6, 8)) + +=== tests/cases/conformance/node/node_modules/inner/exclude/index.d.cts === +// cjs format file +import * as cjs from "inner/cjs/exclude/index"; +>cjs : Symbol(cjs, Decl(index.d.cts, 1, 6)) + +import * as mjs from "inner/mjs/exclude/index"; +>mjs : Symbol(mjs, Decl(index.d.cts, 2, 6)) + +import * as type from "inner/js/exclude/index"; +>type : Symbol(type, Decl(index.d.cts, 3, 6)) + +export { cjs }; +>cjs : Symbol(cjs, Decl(index.d.cts, 4, 8)) + +export { mjs }; +>mjs : Symbol(mjs, Decl(index.d.cts, 5, 8)) + +export { type }; +>type : Symbol(type, Decl(index.d.cts, 6, 8)) + +=== tests/cases/conformance/node/node_modules/inner/index.d.ts === +// cjs format file +import * as cjs from "inner/cjs/index"; +>cjs : Symbol(cjs, Decl(index.d.ts, 1, 6)) + +import * as mjs from "inner/mjs/index"; +>mjs : Symbol(mjs, Decl(index.d.ts, 2, 6)) + +import * as type from "inner/js/index"; +>type : Symbol(type, Decl(index.d.ts, 3, 6)) + +export { cjs }; +>cjs : Symbol(mjs.cjs.cjs.type.cjs, Decl(index.d.ts, 4, 8)) + +export { mjs }; +>mjs : Symbol(mjs.cjs.cjs.type.mjs, Decl(index.d.ts, 5, 8)) + +export { type }; +>type : Symbol(mjs.cjs.cjs.type.type, Decl(index.d.ts, 6, 8)) + +=== tests/cases/conformance/node/node_modules/inner/index.d.mts === +// esm format file +import * as cjs from "inner/cjs/index"; +>cjs : Symbol(cjs, Decl(index.d.mts, 1, 6)) + +import * as mjs from "inner/mjs/index"; +>mjs : Symbol(mjs, Decl(index.d.mts, 2, 6)) + +import * as type from "inner/js/index"; +>type : Symbol(type, Decl(index.d.mts, 3, 6)) + +export { cjs }; +>cjs : Symbol(cjs.cjs.mjs.cjs, Decl(index.d.mts, 4, 8)) + +export { mjs }; +>mjs : Symbol(cjs.cjs.mjs.mjs, Decl(index.d.mts, 5, 8)) + +export { type }; +>type : Symbol(cjs.cjs.mjs.type, Decl(index.d.mts, 6, 8)) + +=== tests/cases/conformance/node/node_modules/inner/index.d.cts === +// cjs format file +import * as cjs from "inner/cjs/index"; +>cjs : Symbol(cjs, Decl(index.d.cts, 1, 6)) + +import * as mjs from "inner/mjs/index"; +>mjs : Symbol(mjs, Decl(index.d.cts, 2, 6)) + +import * as type from "inner/js/index"; +>type : Symbol(type, Decl(index.d.cts, 3, 6)) + +export { cjs }; +>cjs : Symbol(cjs.cjs, Decl(index.d.cts, 4, 8)) + +export { mjs }; +>mjs : Symbol(cjs.mjs, Decl(index.d.cts, 5, 8)) + +export { type }; +>type : Symbol(cjs.type, Decl(index.d.cts, 6, 8)) + diff --git a/tests/baselines/reference/nodeModulesPackagePatternExportsExclude(module=node16).types b/tests/baselines/reference/nodeModulesPackagePatternExportsExclude(module=node16).types new file mode 100644 index 0000000000000..517f6dfa99bd6 --- /dev/null +++ b/tests/baselines/reference/nodeModulesPackagePatternExportsExclude(module=node16).types @@ -0,0 +1,234 @@ +=== tests/cases/conformance/node/index.ts === +// esm format file +import * as cjsi from "inner/cjs/exclude/index"; +>cjsi : any + +import * as mjsi from "inner/mjs/exclude/index"; +>mjsi : any + +import * as typei from "inner/js/exclude/index"; +>typei : any + +cjsi; +>cjsi : any + +mjsi; +>mjsi : any + +typei; +>typei : any + +import * as cjsi2 from "inner/cjs/index"; +>cjsi2 : typeof cjsi2 + +import * as mjsi2 from "inner/mjs/index"; +>mjsi2 : typeof cjsi2.cjs.mjs + +import * as typei2 from "inner/js/index"; +>typei2 : typeof typei2 + +cjsi2; +>cjsi2 : typeof cjsi2 + +mjsi2; +>mjsi2 : typeof cjsi2.cjs.mjs + +typei2; +>typei2 : typeof typei2 + +=== tests/cases/conformance/node/index.mts === +// esm format file +import * as cjsi from "inner/cjs/exclude/index"; +>cjsi : any + +import * as mjsi from "inner/mjs/exclude/index"; +>mjsi : any + +import * as typei from "inner/js/exclude/index"; +>typei : any + +cjsi; +>cjsi : any + +mjsi; +>mjsi : any + +typei; +>typei : any + +import * as cjsi2 from "inner/cjs/index"; +>cjsi2 : typeof cjsi2 + +import * as mjsi2 from "inner/mjs/index"; +>mjsi2 : typeof cjsi2.cjs.mjs + +import * as typei2 from "inner/js/index"; +>typei2 : typeof typei2 + +cjsi2; +>cjsi2 : typeof cjsi2 + +mjsi2; +>mjsi2 : typeof cjsi2.cjs.mjs + +typei2; +>typei2 : typeof typei2 + +=== tests/cases/conformance/node/index.cts === +// cjs format file +import * as cjsi from "inner/cjs/exclude/index"; +>cjsi : any + +import * as mjsi from "inner/mjs/exclude/index"; +>mjsi : any + +import * as typei from "inner/js/exclude/index"; +>typei : any + +cjsi; +>cjsi : any + +mjsi; +>mjsi : any + +typei; +>typei : any + +import * as cjsi2 from "inner/cjs/index"; +>cjsi2 : typeof cjsi2 + +import * as mjsi2 from "inner/mjs/index"; +>mjsi2 : typeof cjsi2.mjs + +import * as typei2 from "inner/js/index"; +>typei2 : typeof cjsi2.mjs.cjs.type + +cjsi2; +>cjsi2 : typeof cjsi2 + +mjsi2; +>mjsi2 : typeof cjsi2.mjs + +typei2; +>typei2 : typeof cjsi2.mjs.cjs.type + +=== tests/cases/conformance/node/node_modules/inner/exclude/index.d.ts === +// cjs format file +import * as cjs from "inner/cjs/exclude/index"; +>cjs : any + +import * as mjs from "inner/mjs/exclude/index"; +>mjs : any + +import * as type from "inner/js/exclude/index"; +>type : any + +export { cjs }; +>cjs : any + +export { mjs }; +>mjs : any + +export { type }; +>type : any + +=== tests/cases/conformance/node/node_modules/inner/exclude/index.d.mts === +// esm format file +import * as cjs from "inner/cjs/exclude/index"; +>cjs : any + +import * as mjs from "inner/mjs/exclude/index"; +>mjs : any + +import * as type from "inner/js/exclude/index"; +>type : any + +export { cjs }; +>cjs : any + +export { mjs }; +>mjs : any + +export { type }; +>type : any + +=== tests/cases/conformance/node/node_modules/inner/exclude/index.d.cts === +// cjs format file +import * as cjs from "inner/cjs/exclude/index"; +>cjs : any + +import * as mjs from "inner/mjs/exclude/index"; +>mjs : any + +import * as type from "inner/js/exclude/index"; +>type : any + +export { cjs }; +>cjs : any + +export { mjs }; +>mjs : any + +export { type }; +>type : any + +=== tests/cases/conformance/node/node_modules/inner/index.d.ts === +// cjs format file +import * as cjs from "inner/cjs/index"; +>cjs : any + +import * as mjs from "inner/mjs/index"; +>mjs : typeof mjs + +import * as type from "inner/js/index"; +>type : typeof mjs.cjs.cjs.type + +export { cjs }; +>cjs : any + +export { mjs }; +>mjs : typeof mjs + +export { type }; +>type : typeof mjs.cjs.cjs.type + +=== tests/cases/conformance/node/node_modules/inner/index.d.mts === +// esm format file +import * as cjs from "inner/cjs/index"; +>cjs : typeof cjs + +import * as mjs from "inner/mjs/index"; +>mjs : typeof cjs.cjs.mjs + +import * as type from "inner/js/index"; +>type : typeof cjs.cjs.mjs.type + +export { cjs }; +>cjs : typeof cjs + +export { mjs }; +>mjs : typeof cjs.cjs.mjs + +export { type }; +>type : typeof cjs.cjs.mjs.type + +=== tests/cases/conformance/node/node_modules/inner/index.d.cts === +// cjs format file +import * as cjs from "inner/cjs/index"; +>cjs : typeof cjs + +import * as mjs from "inner/mjs/index"; +>mjs : typeof cjs.mjs + +import * as type from "inner/js/index"; +>type : typeof cjs.mjs.cjs.type + +export { cjs }; +>cjs : typeof cjs + +export { mjs }; +>mjs : typeof cjs.mjs + +export { type }; +>type : typeof cjs.mjs.cjs.type + diff --git a/tests/baselines/reference/nodeModulesPackagePatternExportsExclude(module=nodenext).errors.txt b/tests/baselines/reference/nodeModulesPackagePatternExportsExclude(module=nodenext).errors.txt new file mode 100644 index 0000000000000..863b455cf4796 --- /dev/null +++ b/tests/baselines/reference/nodeModulesPackagePatternExportsExclude(module=nodenext).errors.txt @@ -0,0 +1,177 @@ +tests/cases/conformance/node/index.cts(2,23): error TS2307: Cannot find module 'inner/cjs/exclude/index' or its corresponding type declarations. +tests/cases/conformance/node/index.cts(3,23): error TS2307: Cannot find module 'inner/mjs/exclude/index' or its corresponding type declarations. +tests/cases/conformance/node/index.cts(4,24): error TS2307: Cannot find module 'inner/js/exclude/index' or its corresponding type declarations. +tests/cases/conformance/node/index.cts(9,24): error TS1471: Module 'inner/mjs/index' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/index.mts(2,23): error TS2307: Cannot find module 'inner/cjs/exclude/index' or its corresponding type declarations. +tests/cases/conformance/node/index.mts(3,23): error TS2307: Cannot find module 'inner/mjs/exclude/index' or its corresponding type declarations. +tests/cases/conformance/node/index.mts(4,24): error TS2307: Cannot find module 'inner/js/exclude/index' or its corresponding type declarations. +tests/cases/conformance/node/index.ts(2,23): error TS2307: Cannot find module 'inner/cjs/exclude/index' or its corresponding type declarations. +tests/cases/conformance/node/index.ts(3,23): error TS2307: Cannot find module 'inner/mjs/exclude/index' or its corresponding type declarations. +tests/cases/conformance/node/index.ts(4,24): error TS2307: Cannot find module 'inner/js/exclude/index' or its corresponding type declarations. +tests/cases/conformance/node/node_modules/inner/exclude/index.d.cts(2,22): error TS2307: Cannot find module 'inner/cjs/exclude/index' or its corresponding type declarations. +tests/cases/conformance/node/node_modules/inner/exclude/index.d.cts(3,22): error TS2307: Cannot find module 'inner/mjs/exclude/index' or its corresponding type declarations. +tests/cases/conformance/node/node_modules/inner/exclude/index.d.cts(4,23): error TS2307: Cannot find module 'inner/js/exclude/index' or its corresponding type declarations. +tests/cases/conformance/node/node_modules/inner/exclude/index.d.mts(2,22): error TS2307: Cannot find module 'inner/cjs/exclude/index' or its corresponding type declarations. +tests/cases/conformance/node/node_modules/inner/exclude/index.d.mts(3,22): error TS2307: Cannot find module 'inner/mjs/exclude/index' or its corresponding type declarations. +tests/cases/conformance/node/node_modules/inner/exclude/index.d.mts(4,23): error TS2307: Cannot find module 'inner/js/exclude/index' or its corresponding type declarations. +tests/cases/conformance/node/node_modules/inner/exclude/index.d.ts(2,22): error TS2307: Cannot find module 'inner/cjs/exclude/index' or its corresponding type declarations. +tests/cases/conformance/node/node_modules/inner/exclude/index.d.ts(3,22): error TS2307: Cannot find module 'inner/mjs/exclude/index' or its corresponding type declarations. +tests/cases/conformance/node/node_modules/inner/exclude/index.d.ts(4,23): error TS2307: Cannot find module 'inner/js/exclude/index' or its corresponding type declarations. +tests/cases/conformance/node/node_modules/inner/index.d.cts(3,22): error TS1471: Module 'inner/mjs/index' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. +tests/cases/conformance/node/node_modules/inner/index.d.ts(2,13): error TS2303: Circular definition of import alias 'cjs'. +tests/cases/conformance/node/node_modules/inner/index.d.ts(3,22): error TS1471: Module 'inner/mjs/index' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. + + +==== tests/cases/conformance/node/index.ts (3 errors) ==== + // esm format file + import * as cjsi from "inner/cjs/exclude/index"; + ~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'inner/cjs/exclude/index' or its corresponding type declarations. + import * as mjsi from "inner/mjs/exclude/index"; + ~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'inner/mjs/exclude/index' or its corresponding type declarations. + import * as typei from "inner/js/exclude/index"; + ~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'inner/js/exclude/index' or its corresponding type declarations. + cjsi; + mjsi; + typei; + import * as cjsi2 from "inner/cjs/index"; + import * as mjsi2 from "inner/mjs/index"; + import * as typei2 from "inner/js/index"; + cjsi2; + mjsi2; + typei2; +==== tests/cases/conformance/node/index.mts (3 errors) ==== + // esm format file + import * as cjsi from "inner/cjs/exclude/index"; + ~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'inner/cjs/exclude/index' or its corresponding type declarations. + import * as mjsi from "inner/mjs/exclude/index"; + ~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'inner/mjs/exclude/index' or its corresponding type declarations. + import * as typei from "inner/js/exclude/index"; + ~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'inner/js/exclude/index' or its corresponding type declarations. + cjsi; + mjsi; + typei; + import * as cjsi2 from "inner/cjs/index"; + import * as mjsi2 from "inner/mjs/index"; + import * as typei2 from "inner/js/index"; + cjsi2; + mjsi2; + typei2; +==== tests/cases/conformance/node/index.cts (4 errors) ==== + // cjs format file + import * as cjsi from "inner/cjs/exclude/index"; + ~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'inner/cjs/exclude/index' or its corresponding type declarations. + import * as mjsi from "inner/mjs/exclude/index"; + ~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'inner/mjs/exclude/index' or its corresponding type declarations. + import * as typei from "inner/js/exclude/index"; + ~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'inner/js/exclude/index' or its corresponding type declarations. + cjsi; + mjsi; + typei; + import * as cjsi2 from "inner/cjs/index"; + import * as mjsi2 from "inner/mjs/index"; + ~~~~~~~~~~~~~~~~~ +!!! error TS1471: Module 'inner/mjs/index' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. + import * as typei2 from "inner/js/index"; + cjsi2; + mjsi2; + typei2; +==== tests/cases/conformance/node/node_modules/inner/exclude/index.d.ts (3 errors) ==== + // cjs format file + import * as cjs from "inner/cjs/exclude/index"; + ~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'inner/cjs/exclude/index' or its corresponding type declarations. + import * as mjs from "inner/mjs/exclude/index"; + ~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'inner/mjs/exclude/index' or its corresponding type declarations. + import * as type from "inner/js/exclude/index"; + ~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'inner/js/exclude/index' or its corresponding type declarations. + export { cjs }; + export { mjs }; + export { type }; +==== tests/cases/conformance/node/node_modules/inner/exclude/index.d.mts (3 errors) ==== + // esm format file + import * as cjs from "inner/cjs/exclude/index"; + ~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'inner/cjs/exclude/index' or its corresponding type declarations. + import * as mjs from "inner/mjs/exclude/index"; + ~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'inner/mjs/exclude/index' or its corresponding type declarations. + import * as type from "inner/js/exclude/index"; + ~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'inner/js/exclude/index' or its corresponding type declarations. + export { cjs }; + export { mjs }; + export { type }; +==== tests/cases/conformance/node/node_modules/inner/exclude/index.d.cts (3 errors) ==== + // cjs format file + import * as cjs from "inner/cjs/exclude/index"; + ~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'inner/cjs/exclude/index' or its corresponding type declarations. + import * as mjs from "inner/mjs/exclude/index"; + ~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'inner/mjs/exclude/index' or its corresponding type declarations. + import * as type from "inner/js/exclude/index"; + ~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'inner/js/exclude/index' or its corresponding type declarations. + export { cjs }; + export { mjs }; + export { type }; +==== tests/cases/conformance/node/node_modules/inner/index.d.ts (2 errors) ==== + // cjs format file + import * as cjs from "inner/cjs/index"; + ~~~ +!!! error TS2303: Circular definition of import alias 'cjs'. + import * as mjs from "inner/mjs/index"; + ~~~~~~~~~~~~~~~~~ +!!! error TS1471: Module 'inner/mjs/index' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. + import * as type from "inner/js/index"; + export { cjs }; + export { mjs }; + export { type }; +==== tests/cases/conformance/node/node_modules/inner/index.d.mts (0 errors) ==== + // esm format file + import * as cjs from "inner/cjs/index"; + import * as mjs from "inner/mjs/index"; + import * as type from "inner/js/index"; + export { cjs }; + export { mjs }; + export { type }; +==== tests/cases/conformance/node/node_modules/inner/index.d.cts (1 errors) ==== + // cjs format file + import * as cjs from "inner/cjs/index"; + import * as mjs from "inner/mjs/index"; + ~~~~~~~~~~~~~~~~~ +!!! error TS1471: Module 'inner/mjs/index' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead. + import * as type from "inner/js/index"; + export { cjs }; + export { mjs }; + export { type }; +==== tests/cases/conformance/node/package.json (0 errors) ==== + { + "name": "package", + "private": true, + "type": "module" + } +==== tests/cases/conformance/node/node_modules/inner/package.json (0 errors) ==== + { + "name": "inner", + "private": true, + "exports": { + "./cjs/*": "./*.cjs", + "./cjs/exclude/*": null, + "./mjs/*": "./*.mjs", + "./mjs/exclude/*": null, + "./js/*": "./*.js", + "./js/exclude/*": null + } + } \ No newline at end of file diff --git a/tests/baselines/reference/nodeModulesPackagePatternExportsExclude(module=nodenext).js b/tests/baselines/reference/nodeModulesPackagePatternExportsExclude(module=nodenext).js new file mode 100644 index 0000000000000..5c3a1fea21903 --- /dev/null +++ b/tests/baselines/reference/nodeModulesPackagePatternExportsExclude(module=nodenext).js @@ -0,0 +1,187 @@ +//// [tests/cases/conformance/node/nodeModulesPackagePatternExportsExclude.ts] //// + +//// [index.ts] +// esm format file +import * as cjsi from "inner/cjs/exclude/index"; +import * as mjsi from "inner/mjs/exclude/index"; +import * as typei from "inner/js/exclude/index"; +cjsi; +mjsi; +typei; +import * as cjsi2 from "inner/cjs/index"; +import * as mjsi2 from "inner/mjs/index"; +import * as typei2 from "inner/js/index"; +cjsi2; +mjsi2; +typei2; +//// [index.mts] +// esm format file +import * as cjsi from "inner/cjs/exclude/index"; +import * as mjsi from "inner/mjs/exclude/index"; +import * as typei from "inner/js/exclude/index"; +cjsi; +mjsi; +typei; +import * as cjsi2 from "inner/cjs/index"; +import * as mjsi2 from "inner/mjs/index"; +import * as typei2 from "inner/js/index"; +cjsi2; +mjsi2; +typei2; +//// [index.cts] +// cjs format file +import * as cjsi from "inner/cjs/exclude/index"; +import * as mjsi from "inner/mjs/exclude/index"; +import * as typei from "inner/js/exclude/index"; +cjsi; +mjsi; +typei; +import * as cjsi2 from "inner/cjs/index"; +import * as mjsi2 from "inner/mjs/index"; +import * as typei2 from "inner/js/index"; +cjsi2; +mjsi2; +typei2; +//// [index.d.ts] +// cjs format file +import * as cjs from "inner/cjs/exclude/index"; +import * as mjs from "inner/mjs/exclude/index"; +import * as type from "inner/js/exclude/index"; +export { cjs }; +export { mjs }; +export { type }; +//// [index.d.mts] +// esm format file +import * as cjs from "inner/cjs/exclude/index"; +import * as mjs from "inner/mjs/exclude/index"; +import * as type from "inner/js/exclude/index"; +export { cjs }; +export { mjs }; +export { type }; +//// [index.d.cts] +// cjs format file +import * as cjs from "inner/cjs/exclude/index"; +import * as mjs from "inner/mjs/exclude/index"; +import * as type from "inner/js/exclude/index"; +export { cjs }; +export { mjs }; +export { type }; +//// [index.d.ts] +// cjs format file +import * as cjs from "inner/cjs/index"; +import * as mjs from "inner/mjs/index"; +import * as type from "inner/js/index"; +export { cjs }; +export { mjs }; +export { type }; +//// [index.d.mts] +// esm format file +import * as cjs from "inner/cjs/index"; +import * as mjs from "inner/mjs/index"; +import * as type from "inner/js/index"; +export { cjs }; +export { mjs }; +export { type }; +//// [index.d.cts] +// cjs format file +import * as cjs from "inner/cjs/index"; +import * as mjs from "inner/mjs/index"; +import * as type from "inner/js/index"; +export { cjs }; +export { mjs }; +export { type }; +//// [package.json] +{ + "name": "package", + "private": true, + "type": "module" +} +//// [package.json] +{ + "name": "inner", + "private": true, + "exports": { + "./cjs/*": "./*.cjs", + "./cjs/exclude/*": null, + "./mjs/*": "./*.mjs", + "./mjs/exclude/*": null, + "./js/*": "./*.js", + "./js/exclude/*": null + } +} + +//// [index.js] +// esm format file +import * as cjsi from "inner/cjs/exclude/index"; +import * as mjsi from "inner/mjs/exclude/index"; +import * as typei from "inner/js/exclude/index"; +cjsi; +mjsi; +typei; +import * as cjsi2 from "inner/cjs/index"; +import * as mjsi2 from "inner/mjs/index"; +import * as typei2 from "inner/js/index"; +cjsi2; +mjsi2; +typei2; +//// [index.mjs] +// esm format file +import * as cjsi from "inner/cjs/exclude/index"; +import * as mjsi from "inner/mjs/exclude/index"; +import * as typei from "inner/js/exclude/index"; +cjsi; +mjsi; +typei; +import * as cjsi2 from "inner/cjs/index"; +import * as mjsi2 from "inner/mjs/index"; +import * as typei2 from "inner/js/index"; +cjsi2; +mjsi2; +typei2; +//// [index.cjs] +"use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { + desc = { enumerable: true, get: function() { return m[k]; } }; + } + Object.defineProperty(o, k2, desc); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +// cjs format file +const cjsi = __importStar(require("inner/cjs/exclude/index")); +const mjsi = __importStar(require("inner/mjs/exclude/index")); +const typei = __importStar(require("inner/js/exclude/index")); +cjsi; +mjsi; +typei; +const cjsi2 = __importStar(require("inner/cjs/index")); +const mjsi2 = __importStar(require("inner/mjs/index")); +const typei2 = __importStar(require("inner/js/index")); +cjsi2; +mjsi2; +typei2; + + +//// [index.d.ts] +export {}; +//// [index.d.mts] +export {}; +//// [index.d.cts] +export {}; diff --git a/tests/baselines/reference/nodeModulesPackagePatternExportsExclude(module=nodenext).symbols b/tests/baselines/reference/nodeModulesPackagePatternExportsExclude(module=nodenext).symbols new file mode 100644 index 0000000000000..6114f146f235f --- /dev/null +++ b/tests/baselines/reference/nodeModulesPackagePatternExportsExclude(module=nodenext).symbols @@ -0,0 +1,234 @@ +=== tests/cases/conformance/node/index.ts === +// esm format file +import * as cjsi from "inner/cjs/exclude/index"; +>cjsi : Symbol(cjsi, Decl(index.ts, 1, 6)) + +import * as mjsi from "inner/mjs/exclude/index"; +>mjsi : Symbol(mjsi, Decl(index.ts, 2, 6)) + +import * as typei from "inner/js/exclude/index"; +>typei : Symbol(typei, Decl(index.ts, 3, 6)) + +cjsi; +>cjsi : Symbol(cjsi, Decl(index.ts, 1, 6)) + +mjsi; +>mjsi : Symbol(mjsi, Decl(index.ts, 2, 6)) + +typei; +>typei : Symbol(typei, Decl(index.ts, 3, 6)) + +import * as cjsi2 from "inner/cjs/index"; +>cjsi2 : Symbol(cjsi2, Decl(index.ts, 7, 6)) + +import * as mjsi2 from "inner/mjs/index"; +>mjsi2 : Symbol(mjsi2, Decl(index.ts, 8, 6)) + +import * as typei2 from "inner/js/index"; +>typei2 : Symbol(typei2, Decl(index.ts, 9, 6)) + +cjsi2; +>cjsi2 : Symbol(cjsi2, Decl(index.ts, 7, 6)) + +mjsi2; +>mjsi2 : Symbol(mjsi2, Decl(index.ts, 8, 6)) + +typei2; +>typei2 : Symbol(typei2, Decl(index.ts, 9, 6)) + +=== tests/cases/conformance/node/index.mts === +// esm format file +import * as cjsi from "inner/cjs/exclude/index"; +>cjsi : Symbol(cjsi, Decl(index.mts, 1, 6)) + +import * as mjsi from "inner/mjs/exclude/index"; +>mjsi : Symbol(mjsi, Decl(index.mts, 2, 6)) + +import * as typei from "inner/js/exclude/index"; +>typei : Symbol(typei, Decl(index.mts, 3, 6)) + +cjsi; +>cjsi : Symbol(cjsi, Decl(index.mts, 1, 6)) + +mjsi; +>mjsi : Symbol(mjsi, Decl(index.mts, 2, 6)) + +typei; +>typei : Symbol(typei, Decl(index.mts, 3, 6)) + +import * as cjsi2 from "inner/cjs/index"; +>cjsi2 : Symbol(cjsi2, Decl(index.mts, 7, 6)) + +import * as mjsi2 from "inner/mjs/index"; +>mjsi2 : Symbol(mjsi2, Decl(index.mts, 8, 6)) + +import * as typei2 from "inner/js/index"; +>typei2 : Symbol(typei2, Decl(index.mts, 9, 6)) + +cjsi2; +>cjsi2 : Symbol(cjsi2, Decl(index.mts, 7, 6)) + +mjsi2; +>mjsi2 : Symbol(mjsi2, Decl(index.mts, 8, 6)) + +typei2; +>typei2 : Symbol(typei2, Decl(index.mts, 9, 6)) + +=== tests/cases/conformance/node/index.cts === +// cjs format file +import * as cjsi from "inner/cjs/exclude/index"; +>cjsi : Symbol(cjsi, Decl(index.cts, 1, 6)) + +import * as mjsi from "inner/mjs/exclude/index"; +>mjsi : Symbol(mjsi, Decl(index.cts, 2, 6)) + +import * as typei from "inner/js/exclude/index"; +>typei : Symbol(typei, Decl(index.cts, 3, 6)) + +cjsi; +>cjsi : Symbol(cjsi, Decl(index.cts, 1, 6)) + +mjsi; +>mjsi : Symbol(mjsi, Decl(index.cts, 2, 6)) + +typei; +>typei : Symbol(typei, Decl(index.cts, 3, 6)) + +import * as cjsi2 from "inner/cjs/index"; +>cjsi2 : Symbol(cjsi2, Decl(index.cts, 7, 6)) + +import * as mjsi2 from "inner/mjs/index"; +>mjsi2 : Symbol(mjsi2, Decl(index.cts, 8, 6)) + +import * as typei2 from "inner/js/index"; +>typei2 : Symbol(typei2, Decl(index.cts, 9, 6)) + +cjsi2; +>cjsi2 : Symbol(cjsi2, Decl(index.cts, 7, 6)) + +mjsi2; +>mjsi2 : Symbol(mjsi2, Decl(index.cts, 8, 6)) + +typei2; +>typei2 : Symbol(typei2, Decl(index.cts, 9, 6)) + +=== tests/cases/conformance/node/node_modules/inner/exclude/index.d.ts === +// cjs format file +import * as cjs from "inner/cjs/exclude/index"; +>cjs : Symbol(cjs, Decl(index.d.ts, 1, 6)) + +import * as mjs from "inner/mjs/exclude/index"; +>mjs : Symbol(mjs, Decl(index.d.ts, 2, 6)) + +import * as type from "inner/js/exclude/index"; +>type : Symbol(type, Decl(index.d.ts, 3, 6)) + +export { cjs }; +>cjs : Symbol(cjs, Decl(index.d.ts, 4, 8)) + +export { mjs }; +>mjs : Symbol(mjs, Decl(index.d.ts, 5, 8)) + +export { type }; +>type : Symbol(type, Decl(index.d.ts, 6, 8)) + +=== tests/cases/conformance/node/node_modules/inner/exclude/index.d.mts === +// esm format file +import * as cjs from "inner/cjs/exclude/index"; +>cjs : Symbol(cjs, Decl(index.d.mts, 1, 6)) + +import * as mjs from "inner/mjs/exclude/index"; +>mjs : Symbol(mjs, Decl(index.d.mts, 2, 6)) + +import * as type from "inner/js/exclude/index"; +>type : Symbol(type, Decl(index.d.mts, 3, 6)) + +export { cjs }; +>cjs : Symbol(cjs, Decl(index.d.mts, 4, 8)) + +export { mjs }; +>mjs : Symbol(mjs, Decl(index.d.mts, 5, 8)) + +export { type }; +>type : Symbol(type, Decl(index.d.mts, 6, 8)) + +=== tests/cases/conformance/node/node_modules/inner/exclude/index.d.cts === +// cjs format file +import * as cjs from "inner/cjs/exclude/index"; +>cjs : Symbol(cjs, Decl(index.d.cts, 1, 6)) + +import * as mjs from "inner/mjs/exclude/index"; +>mjs : Symbol(mjs, Decl(index.d.cts, 2, 6)) + +import * as type from "inner/js/exclude/index"; +>type : Symbol(type, Decl(index.d.cts, 3, 6)) + +export { cjs }; +>cjs : Symbol(cjs, Decl(index.d.cts, 4, 8)) + +export { mjs }; +>mjs : Symbol(mjs, Decl(index.d.cts, 5, 8)) + +export { type }; +>type : Symbol(type, Decl(index.d.cts, 6, 8)) + +=== tests/cases/conformance/node/node_modules/inner/index.d.ts === +// cjs format file +import * as cjs from "inner/cjs/index"; +>cjs : Symbol(cjs, Decl(index.d.ts, 1, 6)) + +import * as mjs from "inner/mjs/index"; +>mjs : Symbol(mjs, Decl(index.d.ts, 2, 6)) + +import * as type from "inner/js/index"; +>type : Symbol(type, Decl(index.d.ts, 3, 6)) + +export { cjs }; +>cjs : Symbol(mjs.cjs.cjs.type.cjs, Decl(index.d.ts, 4, 8)) + +export { mjs }; +>mjs : Symbol(mjs.cjs.cjs.type.mjs, Decl(index.d.ts, 5, 8)) + +export { type }; +>type : Symbol(mjs.cjs.cjs.type.type, Decl(index.d.ts, 6, 8)) + +=== tests/cases/conformance/node/node_modules/inner/index.d.mts === +// esm format file +import * as cjs from "inner/cjs/index"; +>cjs : Symbol(cjs, Decl(index.d.mts, 1, 6)) + +import * as mjs from "inner/mjs/index"; +>mjs : Symbol(mjs, Decl(index.d.mts, 2, 6)) + +import * as type from "inner/js/index"; +>type : Symbol(type, Decl(index.d.mts, 3, 6)) + +export { cjs }; +>cjs : Symbol(cjs.cjs.mjs.cjs, Decl(index.d.mts, 4, 8)) + +export { mjs }; +>mjs : Symbol(cjs.cjs.mjs.mjs, Decl(index.d.mts, 5, 8)) + +export { type }; +>type : Symbol(cjs.cjs.mjs.type, Decl(index.d.mts, 6, 8)) + +=== tests/cases/conformance/node/node_modules/inner/index.d.cts === +// cjs format file +import * as cjs from "inner/cjs/index"; +>cjs : Symbol(cjs, Decl(index.d.cts, 1, 6)) + +import * as mjs from "inner/mjs/index"; +>mjs : Symbol(mjs, Decl(index.d.cts, 2, 6)) + +import * as type from "inner/js/index"; +>type : Symbol(type, Decl(index.d.cts, 3, 6)) + +export { cjs }; +>cjs : Symbol(cjs.cjs, Decl(index.d.cts, 4, 8)) + +export { mjs }; +>mjs : Symbol(cjs.mjs, Decl(index.d.cts, 5, 8)) + +export { type }; +>type : Symbol(cjs.type, Decl(index.d.cts, 6, 8)) + diff --git a/tests/baselines/reference/nodeModulesPackagePatternExportsExclude(module=nodenext).types b/tests/baselines/reference/nodeModulesPackagePatternExportsExclude(module=nodenext).types new file mode 100644 index 0000000000000..517f6dfa99bd6 --- /dev/null +++ b/tests/baselines/reference/nodeModulesPackagePatternExportsExclude(module=nodenext).types @@ -0,0 +1,234 @@ +=== tests/cases/conformance/node/index.ts === +// esm format file +import * as cjsi from "inner/cjs/exclude/index"; +>cjsi : any + +import * as mjsi from "inner/mjs/exclude/index"; +>mjsi : any + +import * as typei from "inner/js/exclude/index"; +>typei : any + +cjsi; +>cjsi : any + +mjsi; +>mjsi : any + +typei; +>typei : any + +import * as cjsi2 from "inner/cjs/index"; +>cjsi2 : typeof cjsi2 + +import * as mjsi2 from "inner/mjs/index"; +>mjsi2 : typeof cjsi2.cjs.mjs + +import * as typei2 from "inner/js/index"; +>typei2 : typeof typei2 + +cjsi2; +>cjsi2 : typeof cjsi2 + +mjsi2; +>mjsi2 : typeof cjsi2.cjs.mjs + +typei2; +>typei2 : typeof typei2 + +=== tests/cases/conformance/node/index.mts === +// esm format file +import * as cjsi from "inner/cjs/exclude/index"; +>cjsi : any + +import * as mjsi from "inner/mjs/exclude/index"; +>mjsi : any + +import * as typei from "inner/js/exclude/index"; +>typei : any + +cjsi; +>cjsi : any + +mjsi; +>mjsi : any + +typei; +>typei : any + +import * as cjsi2 from "inner/cjs/index"; +>cjsi2 : typeof cjsi2 + +import * as mjsi2 from "inner/mjs/index"; +>mjsi2 : typeof cjsi2.cjs.mjs + +import * as typei2 from "inner/js/index"; +>typei2 : typeof typei2 + +cjsi2; +>cjsi2 : typeof cjsi2 + +mjsi2; +>mjsi2 : typeof cjsi2.cjs.mjs + +typei2; +>typei2 : typeof typei2 + +=== tests/cases/conformance/node/index.cts === +// cjs format file +import * as cjsi from "inner/cjs/exclude/index"; +>cjsi : any + +import * as mjsi from "inner/mjs/exclude/index"; +>mjsi : any + +import * as typei from "inner/js/exclude/index"; +>typei : any + +cjsi; +>cjsi : any + +mjsi; +>mjsi : any + +typei; +>typei : any + +import * as cjsi2 from "inner/cjs/index"; +>cjsi2 : typeof cjsi2 + +import * as mjsi2 from "inner/mjs/index"; +>mjsi2 : typeof cjsi2.mjs + +import * as typei2 from "inner/js/index"; +>typei2 : typeof cjsi2.mjs.cjs.type + +cjsi2; +>cjsi2 : typeof cjsi2 + +mjsi2; +>mjsi2 : typeof cjsi2.mjs + +typei2; +>typei2 : typeof cjsi2.mjs.cjs.type + +=== tests/cases/conformance/node/node_modules/inner/exclude/index.d.ts === +// cjs format file +import * as cjs from "inner/cjs/exclude/index"; +>cjs : any + +import * as mjs from "inner/mjs/exclude/index"; +>mjs : any + +import * as type from "inner/js/exclude/index"; +>type : any + +export { cjs }; +>cjs : any + +export { mjs }; +>mjs : any + +export { type }; +>type : any + +=== tests/cases/conformance/node/node_modules/inner/exclude/index.d.mts === +// esm format file +import * as cjs from "inner/cjs/exclude/index"; +>cjs : any + +import * as mjs from "inner/mjs/exclude/index"; +>mjs : any + +import * as type from "inner/js/exclude/index"; +>type : any + +export { cjs }; +>cjs : any + +export { mjs }; +>mjs : any + +export { type }; +>type : any + +=== tests/cases/conformance/node/node_modules/inner/exclude/index.d.cts === +// cjs format file +import * as cjs from "inner/cjs/exclude/index"; +>cjs : any + +import * as mjs from "inner/mjs/exclude/index"; +>mjs : any + +import * as type from "inner/js/exclude/index"; +>type : any + +export { cjs }; +>cjs : any + +export { mjs }; +>mjs : any + +export { type }; +>type : any + +=== tests/cases/conformance/node/node_modules/inner/index.d.ts === +// cjs format file +import * as cjs from "inner/cjs/index"; +>cjs : any + +import * as mjs from "inner/mjs/index"; +>mjs : typeof mjs + +import * as type from "inner/js/index"; +>type : typeof mjs.cjs.cjs.type + +export { cjs }; +>cjs : any + +export { mjs }; +>mjs : typeof mjs + +export { type }; +>type : typeof mjs.cjs.cjs.type + +=== tests/cases/conformance/node/node_modules/inner/index.d.mts === +// esm format file +import * as cjs from "inner/cjs/index"; +>cjs : typeof cjs + +import * as mjs from "inner/mjs/index"; +>mjs : typeof cjs.cjs.mjs + +import * as type from "inner/js/index"; +>type : typeof cjs.cjs.mjs.type + +export { cjs }; +>cjs : typeof cjs + +export { mjs }; +>mjs : typeof cjs.cjs.mjs + +export { type }; +>type : typeof cjs.cjs.mjs.type + +=== tests/cases/conformance/node/node_modules/inner/index.d.cts === +// cjs format file +import * as cjs from "inner/cjs/index"; +>cjs : typeof cjs + +import * as mjs from "inner/mjs/index"; +>mjs : typeof cjs.mjs + +import * as type from "inner/js/index"; +>type : typeof cjs.mjs.cjs.type + +export { cjs }; +>cjs : typeof cjs + +export { mjs }; +>mjs : typeof cjs.mjs + +export { type }; +>type : typeof cjs.mjs.cjs.type + diff --git a/tests/cases/conformance/node/allowJs/nodeModulesAllowJsPackagePatternExportsExclude.ts b/tests/cases/conformance/node/allowJs/nodeModulesAllowJsPackagePatternExportsExclude.ts new file mode 100644 index 0000000000000..f402a08f65144 --- /dev/null +++ b/tests/cases/conformance/node/allowJs/nodeModulesAllowJsPackagePatternExportsExclude.ts @@ -0,0 +1,72 @@ +// @module: node16,nodenext +// @declaration: true +// @allowJs: true +// @checkJs: true +// @outDir: out +// @filename: index.js +// esm format file +import * as cjsi from "inner/cjs/exclude/index"; +import * as mjsi from "inner/mjs/exclude/index"; +import * as typei from "inner/js/exclude/index"; +cjsi; +mjsi; +typei; +// @filename: index.mjs +// esm format file +import * as cjsi from "inner/cjs/exclude/index"; +import * as mjsi from "inner/mjs/exclude/index"; +import * as typei from "inner/js/exclude/index"; +cjsi; +mjsi; +typei; +// @filename: index.cjs +// cjs format file +import * as cjsi from "inner/cjs/exclude/index"; +import * as mjsi from "inner/mjs/exclude/index"; +import * as typei from "inner/js/exclude/index"; +cjsi; +mjsi; +typei; +// @filename: node_modules/inner/exclude/index.d.ts +// cjs format file +import * as cjs from "inner/cjs/exclude/index"; +import * as mjs from "inner/mjs/exclude/index"; +import * as type from "inner/js/exclude/index"; +export { cjs }; +export { mjs }; +export { type }; +// @filename: node_modules/inner/exclude/index.d.mts +// esm format file +import * as cjs from "inner/cjs/exclude/index"; +import * as mjs from "inner/mjs/exclude/index"; +import * as type from "inner/js/exclude/index"; +export { cjs }; +export { mjs }; +export { type }; +// @filename: node_modules/inner/exclude/index.d.cts +// cjs format file +import * as cjs from "inner/cjs/exclude/index"; +import * as mjs from "inner/mjs/exclude/index"; +import * as type from "inner/js/exclude/index"; +export { cjs }; +export { mjs }; +export { type }; +// @filename: package.json +{ + "name": "package", + "private": true, + "type": "module" +} +// @filename: node_modules/inner/package.json +{ + "name": "inner", + "private": true, + "exports": { + "./cjs/*": "./*.cjs", + "./cjs/exclude/*": null, + "./mjs/*": "./*.mjs", + "./mjs/exclude/*": null, + "./js/*": "./*.js", + "./js/exclude/*": null + } +} \ No newline at end of file diff --git a/tests/cases/conformance/node/nodeModulesPackagePatternExportsExclude.ts b/tests/cases/conformance/node/nodeModulesPackagePatternExportsExclude.ts new file mode 100644 index 0000000000000..a12b1dab20dc0 --- /dev/null +++ b/tests/cases/conformance/node/nodeModulesPackagePatternExportsExclude.ts @@ -0,0 +1,112 @@ +// @module: node16,nodenext +// @declaration: true +// @outDir: out +// @filename: index.ts +// esm format file +import * as cjsi from "inner/cjs/exclude/index"; +import * as mjsi from "inner/mjs/exclude/index"; +import * as typei from "inner/js/exclude/index"; +cjsi; +mjsi; +typei; +import * as cjsi2 from "inner/cjs/index"; +import * as mjsi2 from "inner/mjs/index"; +import * as typei2 from "inner/js/index"; +cjsi2; +mjsi2; +typei2; +// @filename: index.mts +// esm format file +import * as cjsi from "inner/cjs/exclude/index"; +import * as mjsi from "inner/mjs/exclude/index"; +import * as typei from "inner/js/exclude/index"; +cjsi; +mjsi; +typei; +import * as cjsi2 from "inner/cjs/index"; +import * as mjsi2 from "inner/mjs/index"; +import * as typei2 from "inner/js/index"; +cjsi2; +mjsi2; +typei2; +// @filename: index.cts +// cjs format file +import * as cjsi from "inner/cjs/exclude/index"; +import * as mjsi from "inner/mjs/exclude/index"; +import * as typei from "inner/js/exclude/index"; +cjsi; +mjsi; +typei; +import * as cjsi2 from "inner/cjs/index"; +import * as mjsi2 from "inner/mjs/index"; +import * as typei2 from "inner/js/index"; +cjsi2; +mjsi2; +typei2; +// @filename: node_modules/inner/exclude/index.d.ts +// cjs format file +import * as cjs from "inner/cjs/exclude/index"; +import * as mjs from "inner/mjs/exclude/index"; +import * as type from "inner/js/exclude/index"; +export { cjs }; +export { mjs }; +export { type }; +// @filename: node_modules/inner/exclude/index.d.mts +// esm format file +import * as cjs from "inner/cjs/exclude/index"; +import * as mjs from "inner/mjs/exclude/index"; +import * as type from "inner/js/exclude/index"; +export { cjs }; +export { mjs }; +export { type }; +// @filename: node_modules/inner/exclude/index.d.cts +// cjs format file +import * as cjs from "inner/cjs/exclude/index"; +import * as mjs from "inner/mjs/exclude/index"; +import * as type from "inner/js/exclude/index"; +export { cjs }; +export { mjs }; +export { type }; +// @filename: node_modules/inner/index.d.ts +// cjs format file +import * as cjs from "inner/cjs/index"; +import * as mjs from "inner/mjs/index"; +import * as type from "inner/js/index"; +export { cjs }; +export { mjs }; +export { type }; +// @filename: node_modules/inner/index.d.mts +// esm format file +import * as cjs from "inner/cjs/index"; +import * as mjs from "inner/mjs/index"; +import * as type from "inner/js/index"; +export { cjs }; +export { mjs }; +export { type }; +// @filename: node_modules/inner/index.d.cts +// cjs format file +import * as cjs from "inner/cjs/index"; +import * as mjs from "inner/mjs/index"; +import * as type from "inner/js/index"; +export { cjs }; +export { mjs }; +export { type }; +// @filename: package.json +{ + "name": "package", + "private": true, + "type": "module" +} +// @filename: node_modules/inner/package.json +{ + "name": "inner", + "private": true, + "exports": { + "./cjs/*": "./*.cjs", + "./cjs/exclude/*": null, + "./mjs/*": "./*.mjs", + "./mjs/exclude/*": null, + "./js/*": "./*.js", + "./js/exclude/*": null + } +} \ No newline at end of file From 3bf0d30686e81c8f91c954eb0bd18a19b0a544b2 Mon Sep 17 00:00:00 2001 From: Andrew Branch Date: Thu, 2 Jun 2022 16:25:52 -0700 Subject: [PATCH 09/12] Pick PR #49356 (Add nightly-only error on ImportType resolution mode assertion) into release-4.7 (#49365) * Add nightly-only error on ImportType resolution mode assertion (#49356) * Add nightly-only error on ImportType resolution mode assertion * Temporarily change version to demonstrate errors * Revert "Temporarily change version to demonstrate errors" This reverts commit 40c2469647f129ea088a16d60f3f070f9f5beeb2. * "Resolution mode" -> "resolution-mode" * Update baselines --- src/compiler/checker.ts | 11 ++- src/compiler/diagnosticMessages.json | 8 +- src/compiler/program.ts | 2 +- src/compiler/transformers/declarations.ts | 11 ++- src/compiler/types.ts | 1 + ...DynamicImportWithPackageExports.errors.txt | 80 +++++++++++++++++++ ...tionEmitDynamicImportWithPackageExports.js | 16 ---- ...DeclarationEmit1(module=node16).errors.txt | 24 +++--- ...clarationEmit1(module=nodenext).errors.txt | 24 +++--- ...DeclarationEmit2(module=node16).errors.txt | 24 +++--- ...clarationEmit2(module=nodenext).errors.txt | 24 +++--- ...ationEmitErrors1(module=node16).errors.txt | 4 +- ...ionEmitErrors1(module=nodenext).errors.txt | 4 +- ...DeclarationEmit1(module=node16).errors.txt | 38 +++++++++ ...TypeModeDeclarationEmit1(module=node16).js | 6 -- ...clarationEmit1(module=nodenext).errors.txt | 38 +++++++++ ...peModeDeclarationEmit1(module=nodenext).js | 6 -- ...ationEmitErrors1(module=node16).errors.txt | 11 ++- ...deDeclarationEmitErrors1(module=node16).js | 4 - ...ionEmitErrors1(module=nodenext).errors.txt | 11 ++- ...DeclarationEmitErrors1(module=nodenext).js | 4 - ...eModeOverrideOldResolutionError.errors.txt | 8 +- 22 files changed, 257 insertions(+), 102 deletions(-) create mode 100644 tests/baselines/reference/nodeModulesDeclarationEmitDynamicImportWithPackageExports.errors.txt create mode 100644 tests/baselines/reference/nodeModulesImportTypeModeDeclarationEmit1(module=node16).errors.txt create mode 100644 tests/baselines/reference/nodeModulesImportTypeModeDeclarationEmit1(module=nodenext).errors.txt diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 413600e0dcede..056d9377b986c 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -6199,6 +6199,7 @@ namespace ts { factory.createStringLiteral("import") ) ]))); + context.tracker.reportImportTypeNodeResolutionModeOverride?.(); } } if (!specifier) { @@ -6222,6 +6223,7 @@ namespace ts { factory.createStringLiteral(swappedMode === ModuleKind.ESNext ? "import" : "require") ) ]))); + context.tracker.reportImportTypeNodeResolutionModeOverride?.(); } } @@ -35825,8 +35827,11 @@ namespace ts { if (node.assertions) { const override = getResolutionModeOverrideForClause(node.assertions.assertClause, grammarErrorOnNode); if (override) { + if (!isNightly()) { + grammarErrorOnNode(node.assertions.assertClause, Diagnostics.resolution_mode_assertions_are_unstable_Use_nightly_TypeScript_to_silence_this_error_Try_updating_with_npm_install_D_typescript_next); + } if (getEmitModuleResolutionKind(compilerOptions) !== ModuleResolutionKind.Node16 && getEmitModuleResolutionKind(compilerOptions) !== ModuleResolutionKind.NodeNext) { - grammarErrorOnNode(node.assertions.assertClause, Diagnostics.Resolution_modes_are_only_supported_when_moduleResolution_is_node16_or_nodenext); + grammarErrorOnNode(node.assertions.assertClause, Diagnostics.resolution_mode_assertions_are_only_supported_when_moduleResolution_is_node16_or_nodenext); } } } @@ -40720,11 +40725,11 @@ namespace ts { const override = getResolutionModeOverrideForClause(declaration.assertClause, validForTypeAssertions ? grammarErrorOnNode : undefined); if (validForTypeAssertions && override) { if (!isNightly()) { - grammarErrorOnNode(declaration.assertClause, Diagnostics.Resolution_mode_assertions_are_unstable_Use_nightly_TypeScript_to_silence_this_error_Try_updating_with_npm_install_D_typescript_next); + grammarErrorOnNode(declaration.assertClause, Diagnostics.resolution_mode_assertions_are_unstable_Use_nightly_TypeScript_to_silence_this_error_Try_updating_with_npm_install_D_typescript_next); } if (getEmitModuleResolutionKind(compilerOptions) !== ModuleResolutionKind.Node16 && getEmitModuleResolutionKind(compilerOptions) !== ModuleResolutionKind.NodeNext) { - return grammarErrorOnNode(declaration.assertClause, Diagnostics.Resolution_modes_are_only_supported_when_moduleResolution_is_node16_or_nodenext); + return grammarErrorOnNode(declaration.assertClause, Diagnostics.resolution_mode_assertions_are_only_supported_when_moduleResolution_is_node16_or_nodenext); } return; // Other grammar checks do not apply to type-only imports with resolution mode assertions } diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index bae97eb537518..42edfb82af6ce 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -1424,7 +1424,7 @@ "category": "Error", "code": 1451 }, - "Resolution modes are only supported when `moduleResolution` is `node16` or `nodenext`.": { + "'resolution-mode' assertions are only supported when `moduleResolution` is `node16` or `nodenext`.": { "category": "Error", "code": 1452 }, @@ -3451,6 +3451,10 @@ "category": "Error", "code": 2838 }, + "The type of this expression cannot be named without a 'resolution-mode' assertion, which is an unstable feature. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'.": { + "category": "Error", + "code": 2841 + }, "Import declaration '{0}' is using private name '{1}'.": { "category": "Error", @@ -3880,7 +3884,7 @@ "category": "Error", "code": 4124 }, - "Resolution mode assertions are unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'.": { + "'resolution-mode' assertions are unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'.": { "category": "Error", "code": 4125 }, diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 7044953fee6be..2f47acb8d095e 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -3116,7 +3116,7 @@ namespace ts { setResolvedTypeReferenceDirective(file, fileName, resolvedTypeReferenceDirective); const mode = ref.resolutionMode || file.impliedNodeFormat; if (mode && getEmitModuleResolutionKind(options) !== ModuleResolutionKind.Node16 && getEmitModuleResolutionKind(options) !== ModuleResolutionKind.NodeNext) { - programDiagnostics.add(createDiagnosticForRange(file, ref, Diagnostics.Resolution_modes_are_only_supported_when_moduleResolution_is_node16_or_nodenext)); + programDiagnostics.add(createDiagnosticForRange(file, ref, Diagnostics.resolution_mode_assertions_are_only_supported_when_moduleResolution_is_node16_or_nodenext)); } processTypeReferenceDirective(fileName, mode, resolvedTypeReferenceDirective, { kind: FileIncludeKind.TypeReferenceDirective, file: file.path, index, }); } diff --git a/src/compiler/transformers/declarations.ts b/src/compiler/transformers/declarations.ts index b855fd4b8dab5..76db95b260377 100644 --- a/src/compiler/transformers/declarations.ts +++ b/src/compiler/transformers/declarations.ts @@ -78,7 +78,8 @@ namespace ts { trackReferencedAmbientModule, trackExternalModuleSymbolOfImportTypeNode, reportNonlocalAugmentation, - reportNonSerializableProperty + reportNonSerializableProperty, + reportImportTypeNodeResolutionModeOverride, }; let errorNameNode: DeclarationName | undefined; let errorFallbackNode: Declaration | undefined; @@ -235,6 +236,12 @@ namespace ts { } } + function reportImportTypeNodeResolutionModeOverride() { + if (!isNightly() && (errorNameNode || errorFallbackNode)) { + context.addDiagnostic(createDiagnosticForNode((errorNameNode || errorFallbackNode)!, Diagnostics.The_type_of_this_expression_cannot_be_named_without_a_resolution_mode_assertion_which_is_an_unstable_feature_Use_nightly_TypeScript_to_silence_this_error_Try_updating_with_npm_install_D_typescript_next)); + } + } + function transformDeclarationsForJS(sourceFile: SourceFile, bundled?: boolean) { const oldDiag = getSymbolAccessibilityDiagnostic; getSymbolAccessibilityDiagnostic = (s) => (s.errorNode && canProduceDiagnostics(s.errorNode) ? createGetSymbolAccessibilityDiagnosticForNode(s.errorNode)(s) : ({ @@ -792,7 +799,7 @@ namespace ts { const mode = getResolutionModeOverrideForClause(assertClause); if (mode !== undefined) { if (!isNightly()) { - context.addDiagnostic(createDiagnosticForNode(assertClause!, Diagnostics.Resolution_mode_assertions_are_unstable_Use_nightly_TypeScript_to_silence_this_error_Try_updating_with_npm_install_D_typescript_next)); + context.addDiagnostic(createDiagnosticForNode(assertClause!, Diagnostics.resolution_mode_assertions_are_unstable_Use_nightly_TypeScript_to_silence_this_error_Try_updating_with_npm_install_D_typescript_next)); } return assertClause; } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 6becb6813eac6..459eee018fd65 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -8511,6 +8511,7 @@ namespace ts { trackExternalModuleSymbolOfImportTypeNode?(symbol: Symbol): void; reportNonlocalAugmentation?(containingFile: SourceFile, parentSymbol: Symbol, augmentingSymbol: Symbol): void; reportNonSerializableProperty?(propertyName: string): void; + reportImportTypeNodeResolutionModeOverride?(): void; } export interface TextSpan { diff --git a/tests/baselines/reference/nodeModulesDeclarationEmitDynamicImportWithPackageExports.errors.txt b/tests/baselines/reference/nodeModulesDeclarationEmitDynamicImportWithPackageExports.errors.txt new file mode 100644 index 0000000000000..65b88328267c9 --- /dev/null +++ b/tests/baselines/reference/nodeModulesDeclarationEmitDynamicImportWithPackageExports.errors.txt @@ -0,0 +1,80 @@ +tests/cases/conformance/node/other.cts(3,14): error TS2841: The type of this expression cannot be named without a 'resolution-mode' assertion, which is an unstable feature. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'. +tests/cases/conformance/node/other.cts(4,14): error TS2841: The type of this expression cannot be named without a 'resolution-mode' assertion, which is an unstable feature. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'. +tests/cases/conformance/node/other2.cts(3,14): error TS2841: The type of this expression cannot be named without a 'resolution-mode' assertion, which is an unstable feature. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'. + + +==== tests/cases/conformance/node/index.ts (0 errors) ==== + // esm format file + export {}; +==== tests/cases/conformance/node/index.mts (0 errors) ==== + // esm format file + export {}; +==== tests/cases/conformance/node/index.cts (0 errors) ==== + // cjs format file + export {}; +==== tests/cases/conformance/node/other.ts (0 errors) ==== + // esm format file + export const a = await import("package/cjs"); + export const b = await import("package/mjs"); + export const c = await import("package"); + export const f = await import("inner"); +==== tests/cases/conformance/node/other2.ts (0 errors) ==== + // esm format file + export const d = await import("inner/cjs"); + export const e = await import("inner/mjs"); +==== tests/cases/conformance/node/other.mts (0 errors) ==== + // esm format file + export const a = await import("package/cjs"); + export const b = await import("package/mjs"); + export const c = await import("package"); + export const f = await import("inner"); +==== tests/cases/conformance/node/other2.mts (0 errors) ==== + // esm format file + export const d = await import("inner/cjs"); + export const e = await import("inner/mjs"); +==== tests/cases/conformance/node/other.cts (2 errors) ==== + // cjs format file, no TLA + export const a = import("package/cjs"); + export const b = import("package/mjs"); + ~ +!!! error TS2841: The type of this expression cannot be named without a 'resolution-mode' assertion, which is an unstable feature. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'. + export const c = import("package"); + ~ +!!! error TS2841: The type of this expression cannot be named without a 'resolution-mode' assertion, which is an unstable feature. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'. + export const f = import("inner"); +==== tests/cases/conformance/node/other2.cts (1 errors) ==== + // cjs format file, no TLA + export const d = import("inner/cjs"); + export const e = import("inner/mjs"); + ~ +!!! error TS2841: The type of this expression cannot be named without a 'resolution-mode' assertion, which is an unstable feature. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'. +==== tests/cases/conformance/node/node_modules/inner/index.d.ts (0 errors) ==== + // cjs format file + export const cjsMain = true; +==== tests/cases/conformance/node/node_modules/inner/index.d.mts (0 errors) ==== + // esm format file + export const esm = true; +==== tests/cases/conformance/node/node_modules/inner/index.d.cts (0 errors) ==== + // cjs format file + export const cjsNonmain = true; +==== tests/cases/conformance/node/package.json (0 errors) ==== + { + "name": "package", + "private": true, + "type": "module", + "exports": { + "./cjs": "./index.cjs", + "./mjs": "./index.mjs", + ".": "./index.js" + } + } +==== tests/cases/conformance/node/node_modules/inner/package.json (0 errors) ==== + { + "name": "inner", + "private": true, + "exports": { + "./cjs": "./index.cjs", + "./mjs": "./index.mjs", + ".": "./index.js" + } + } \ No newline at end of file diff --git a/tests/baselines/reference/nodeModulesDeclarationEmitDynamicImportWithPackageExports.js b/tests/baselines/reference/nodeModulesDeclarationEmitDynamicImportWithPackageExports.js index 9bc4bb789c561..beb51a1f5e5d5 100644 --- a/tests/baselines/reference/nodeModulesDeclarationEmitDynamicImportWithPackageExports.js +++ b/tests/baselines/reference/nodeModulesDeclarationEmitDynamicImportWithPackageExports.js @@ -153,19 +153,3 @@ export declare const d: { cjsNonmain: true; }; export declare const e: typeof import("inner/mjs"); -//// [other.d.cts] -export declare const a: Promise<{ - default: typeof import("./index.cjs"); -}>; -export declare const b: Promise; -export declare const c: Promise; -export declare const f: Promise<{ - default: typeof import("inner"); - cjsMain: true; -}>; -//// [other2.d.cts] -export declare const d: Promise<{ - default: typeof import("inner/cjs"); - cjsNonmain: true; -}>; -export declare const e: Promise; diff --git a/tests/baselines/reference/nodeModulesImportModeDeclarationEmit1(module=node16).errors.txt b/tests/baselines/reference/nodeModulesImportModeDeclarationEmit1(module=node16).errors.txt index f8e0dd250c64a..1216d8820077d 100644 --- a/tests/baselines/reference/nodeModulesImportModeDeclarationEmit1(module=node16).errors.txt +++ b/tests/baselines/reference/nodeModulesImportModeDeclarationEmit1(module=node16).errors.txt @@ -1,21 +1,21 @@ -/index.ts(1,45): error TS4125: Resolution mode assertions are unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'. -/index.ts(2,44): error TS4125: Resolution mode assertions are unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'. +/index.ts(1,45): error TS4125: 'resolution-mode' assertions are unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'. +/index.ts(2,44): error TS4125: 'resolution-mode' assertions are unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'. /index.ts(6,50): error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext' or 'nodenext'. -/index.ts(6,50): error TS4125: Resolution mode assertions are unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'. +/index.ts(6,50): error TS4125: 'resolution-mode' assertions are unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'. /index.ts(7,14): error TS2305: Module '"pkg"' has no exported member 'ImportInterface'. /index.ts(7,49): error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext' or 'nodenext'. -/index.ts(7,49): error TS4125: Resolution mode assertions are unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'. -/index.ts(10,45): error TS4125: Resolution mode assertions are unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'. -/index.ts(11,44): error TS4125: Resolution mode assertions are unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'. +/index.ts(7,49): error TS4125: 'resolution-mode' assertions are unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'. +/index.ts(10,45): error TS4125: 'resolution-mode' assertions are unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'. +/index.ts(11,44): error TS4125: 'resolution-mode' assertions are unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'. ==== /index.ts (9 errors) ==== import type { RequireInterface } from "pkg" assert { "resolution-mode": "require" }; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS4125: Resolution mode assertions are unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'. +!!! error TS4125: 'resolution-mode' assertions are unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'. import type { ImportInterface } from "pkg" assert { "resolution-mode": "import" }; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS4125: Resolution mode assertions are unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'. +!!! error TS4125: 'resolution-mode' assertions are unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'. export interface LocalInterface extends RequireInterface, ImportInterface {} @@ -23,22 +23,22 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext' or 'nodenext'. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS4125: Resolution mode assertions are unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'. +!!! error TS4125: 'resolution-mode' assertions are unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'. import {type ImportInterface as Imp} from "pkg" assert { "resolution-mode": "import" }; ~~~~~~~~~~~~~~~ !!! error TS2305: Module '"pkg"' has no exported member 'ImportInterface'. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext' or 'nodenext'. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS4125: Resolution mode assertions are unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'. +!!! error TS4125: 'resolution-mode' assertions are unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'. export interface Loc extends Req, Imp {} export type { RequireInterface } from "pkg" assert { "resolution-mode": "require" }; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS4125: Resolution mode assertions are unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'. +!!! error TS4125: 'resolution-mode' assertions are unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'. export type { ImportInterface } from "pkg" assert { "resolution-mode": "import" }; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS4125: Resolution mode assertions are unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'. +!!! error TS4125: 'resolution-mode' assertions are unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'. ==== /node_modules/pkg/package.json (0 errors) ==== { diff --git a/tests/baselines/reference/nodeModulesImportModeDeclarationEmit1(module=nodenext).errors.txt b/tests/baselines/reference/nodeModulesImportModeDeclarationEmit1(module=nodenext).errors.txt index 7efa411b51e2a..097bebc6d34a8 100644 --- a/tests/baselines/reference/nodeModulesImportModeDeclarationEmit1(module=nodenext).errors.txt +++ b/tests/baselines/reference/nodeModulesImportModeDeclarationEmit1(module=nodenext).errors.txt @@ -1,21 +1,21 @@ -/index.ts(1,45): error TS4125: Resolution mode assertions are unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'. -/index.ts(2,44): error TS4125: Resolution mode assertions are unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'. +/index.ts(1,45): error TS4125: 'resolution-mode' assertions are unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'. +/index.ts(2,44): error TS4125: 'resolution-mode' assertions are unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'. /index.ts(6,50): error TS2836: Import assertions are not allowed on statements that transpile to commonjs 'require' calls. -/index.ts(6,50): error TS4125: Resolution mode assertions are unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'. +/index.ts(6,50): error TS4125: 'resolution-mode' assertions are unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'. /index.ts(7,14): error TS2305: Module '"pkg"' has no exported member 'ImportInterface'. /index.ts(7,49): error TS2836: Import assertions are not allowed on statements that transpile to commonjs 'require' calls. -/index.ts(7,49): error TS4125: Resolution mode assertions are unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'. -/index.ts(10,45): error TS4125: Resolution mode assertions are unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'. -/index.ts(11,44): error TS4125: Resolution mode assertions are unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'. +/index.ts(7,49): error TS4125: 'resolution-mode' assertions are unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'. +/index.ts(10,45): error TS4125: 'resolution-mode' assertions are unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'. +/index.ts(11,44): error TS4125: 'resolution-mode' assertions are unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'. ==== /index.ts (9 errors) ==== import type { RequireInterface } from "pkg" assert { "resolution-mode": "require" }; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS4125: Resolution mode assertions are unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'. +!!! error TS4125: 'resolution-mode' assertions are unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'. import type { ImportInterface } from "pkg" assert { "resolution-mode": "import" }; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS4125: Resolution mode assertions are unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'. +!!! error TS4125: 'resolution-mode' assertions are unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'. export interface LocalInterface extends RequireInterface, ImportInterface {} @@ -23,22 +23,22 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2836: Import assertions are not allowed on statements that transpile to commonjs 'require' calls. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS4125: Resolution mode assertions are unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'. +!!! error TS4125: 'resolution-mode' assertions are unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'. import {type ImportInterface as Imp} from "pkg" assert { "resolution-mode": "import" }; ~~~~~~~~~~~~~~~ !!! error TS2305: Module '"pkg"' has no exported member 'ImportInterface'. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2836: Import assertions are not allowed on statements that transpile to commonjs 'require' calls. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS4125: Resolution mode assertions are unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'. +!!! error TS4125: 'resolution-mode' assertions are unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'. export interface Loc extends Req, Imp {} export type { RequireInterface } from "pkg" assert { "resolution-mode": "require" }; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS4125: Resolution mode assertions are unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'. +!!! error TS4125: 'resolution-mode' assertions are unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'. export type { ImportInterface } from "pkg" assert { "resolution-mode": "import" }; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS4125: Resolution mode assertions are unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'. +!!! error TS4125: 'resolution-mode' assertions are unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'. ==== /node_modules/pkg/package.json (0 errors) ==== { diff --git a/tests/baselines/reference/nodeModulesImportModeDeclarationEmit2(module=node16).errors.txt b/tests/baselines/reference/nodeModulesImportModeDeclarationEmit2(module=node16).errors.txt index 60b828aa1b010..299c92f3b0d53 100644 --- a/tests/baselines/reference/nodeModulesImportModeDeclarationEmit2(module=node16).errors.txt +++ b/tests/baselines/reference/nodeModulesImportModeDeclarationEmit2(module=node16).errors.txt @@ -1,21 +1,21 @@ -/index.ts(1,45): error TS4125: Resolution mode assertions are unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'. -/index.ts(2,44): error TS4125: Resolution mode assertions are unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'. +/index.ts(1,45): error TS4125: 'resolution-mode' assertions are unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'. +/index.ts(2,44): error TS4125: 'resolution-mode' assertions are unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'. /index.ts(6,14): error TS2305: Module '"pkg"' has no exported member 'RequireInterface'. /index.ts(6,50): error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext' or 'nodenext'. -/index.ts(6,50): error TS4125: Resolution mode assertions are unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'. +/index.ts(6,50): error TS4125: 'resolution-mode' assertions are unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'. /index.ts(7,49): error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext' or 'nodenext'. -/index.ts(7,49): error TS4125: Resolution mode assertions are unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'. -/index.ts(10,45): error TS4125: Resolution mode assertions are unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'. -/index.ts(11,44): error TS4125: Resolution mode assertions are unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'. +/index.ts(7,49): error TS4125: 'resolution-mode' assertions are unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'. +/index.ts(10,45): error TS4125: 'resolution-mode' assertions are unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'. +/index.ts(11,44): error TS4125: 'resolution-mode' assertions are unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'. ==== /index.ts (9 errors) ==== import type { RequireInterface } from "pkg" assert { "resolution-mode": "require" }; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS4125: Resolution mode assertions are unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'. +!!! error TS4125: 'resolution-mode' assertions are unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'. import type { ImportInterface } from "pkg" assert { "resolution-mode": "import" }; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS4125: Resolution mode assertions are unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'. +!!! error TS4125: 'resolution-mode' assertions are unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'. export interface LocalInterface extends RequireInterface, ImportInterface {} @@ -25,20 +25,20 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext' or 'nodenext'. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS4125: Resolution mode assertions are unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'. +!!! error TS4125: 'resolution-mode' assertions are unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'. import {type ImportInterface as Imp} from "pkg" assert { "resolution-mode": "import" }; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext' or 'nodenext'. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS4125: Resolution mode assertions are unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'. +!!! error TS4125: 'resolution-mode' assertions are unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'. export interface Loc extends Req, Imp {} export type { RequireInterface } from "pkg" assert { "resolution-mode": "require" }; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS4125: Resolution mode assertions are unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'. +!!! error TS4125: 'resolution-mode' assertions are unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'. export type { ImportInterface } from "pkg" assert { "resolution-mode": "import" }; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS4125: Resolution mode assertions are unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'. +!!! error TS4125: 'resolution-mode' assertions are unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'. ==== /node_modules/pkg/package.json (0 errors) ==== { diff --git a/tests/baselines/reference/nodeModulesImportModeDeclarationEmit2(module=nodenext).errors.txt b/tests/baselines/reference/nodeModulesImportModeDeclarationEmit2(module=nodenext).errors.txt index 2667d16176820..d0ae4f1ef1aa6 100644 --- a/tests/baselines/reference/nodeModulesImportModeDeclarationEmit2(module=nodenext).errors.txt +++ b/tests/baselines/reference/nodeModulesImportModeDeclarationEmit2(module=nodenext).errors.txt @@ -1,21 +1,21 @@ -/index.ts(1,45): error TS4125: Resolution mode assertions are unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'. -/index.ts(2,44): error TS4125: Resolution mode assertions are unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'. +/index.ts(1,45): error TS4125: 'resolution-mode' assertions are unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'. +/index.ts(2,44): error TS4125: 'resolution-mode' assertions are unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'. /index.ts(6,14): error TS2305: Module '"pkg"' has no exported member 'RequireInterface'. /index.ts(6,50): error TS1454: `resolution-mode` can only be set for type-only imports. -/index.ts(6,50): error TS4125: Resolution mode assertions are unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'. +/index.ts(6,50): error TS4125: 'resolution-mode' assertions are unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'. /index.ts(7,49): error TS1454: `resolution-mode` can only be set for type-only imports. -/index.ts(7,49): error TS4125: Resolution mode assertions are unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'. -/index.ts(10,45): error TS4125: Resolution mode assertions are unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'. -/index.ts(11,44): error TS4125: Resolution mode assertions are unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'. +/index.ts(7,49): error TS4125: 'resolution-mode' assertions are unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'. +/index.ts(10,45): error TS4125: 'resolution-mode' assertions are unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'. +/index.ts(11,44): error TS4125: 'resolution-mode' assertions are unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'. ==== /index.ts (9 errors) ==== import type { RequireInterface } from "pkg" assert { "resolution-mode": "require" }; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS4125: Resolution mode assertions are unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'. +!!! error TS4125: 'resolution-mode' assertions are unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'. import type { ImportInterface } from "pkg" assert { "resolution-mode": "import" }; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS4125: Resolution mode assertions are unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'. +!!! error TS4125: 'resolution-mode' assertions are unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'. export interface LocalInterface extends RequireInterface, ImportInterface {} @@ -25,20 +25,20 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS1454: `resolution-mode` can only be set for type-only imports. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS4125: Resolution mode assertions are unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'. +!!! error TS4125: 'resolution-mode' assertions are unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'. import {type ImportInterface as Imp} from "pkg" assert { "resolution-mode": "import" }; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS1454: `resolution-mode` can only be set for type-only imports. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS4125: Resolution mode assertions are unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'. +!!! error TS4125: 'resolution-mode' assertions are unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'. export interface Loc extends Req, Imp {} export type { RequireInterface } from "pkg" assert { "resolution-mode": "require" }; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS4125: Resolution mode assertions are unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'. +!!! error TS4125: 'resolution-mode' assertions are unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'. export type { ImportInterface } from "pkg" assert { "resolution-mode": "import" }; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS4125: Resolution mode assertions are unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'. +!!! error TS4125: 'resolution-mode' assertions are unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'. ==== /node_modules/pkg/package.json (0 errors) ==== { diff --git a/tests/baselines/reference/nodeModulesImportModeDeclarationEmitErrors1(module=node16).errors.txt b/tests/baselines/reference/nodeModulesImportModeDeclarationEmitErrors1(module=node16).errors.txt index fa726c1dc13d7..4934625b136e9 100644 --- a/tests/baselines/reference/nodeModulesImportModeDeclarationEmitErrors1(module=node16).errors.txt +++ b/tests/baselines/reference/nodeModulesImportModeDeclarationEmitErrors1(module=node16).errors.txt @@ -2,7 +2,7 @@ /index.ts(2,73): error TS1453: `resolution-mode` should be either `require` or `import`. /index.ts(4,10): error TS2305: Module '"pkg"' has no exported member 'ImportInterface'. /index.ts(4,39): error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext' or 'nodenext'. -/index.ts(4,39): error TS4125: Resolution mode assertions are unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'. +/index.ts(4,39): error TS4125: 'resolution-mode' assertions are unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'. /index.ts(6,76): error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext' or 'nodenext'. @@ -20,7 +20,7 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext' or 'nodenext'. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS4125: Resolution mode assertions are unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'. +!!! error TS4125: 'resolution-mode' assertions are unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'. // not exclusively type-only import {type RequireInterface as Req, RequireInterface as Req2} from "pkg" assert { "resolution-mode": "require" }; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/tests/baselines/reference/nodeModulesImportModeDeclarationEmitErrors1(module=nodenext).errors.txt b/tests/baselines/reference/nodeModulesImportModeDeclarationEmitErrors1(module=nodenext).errors.txt index 0fd8ca6399ebc..4d564793b0c59 100644 --- a/tests/baselines/reference/nodeModulesImportModeDeclarationEmitErrors1(module=nodenext).errors.txt +++ b/tests/baselines/reference/nodeModulesImportModeDeclarationEmitErrors1(module=nodenext).errors.txt @@ -2,7 +2,7 @@ /index.ts(2,73): error TS1453: `resolution-mode` should be either `require` or `import`. /index.ts(4,10): error TS2305: Module '"pkg"' has no exported member 'ImportInterface'. /index.ts(4,39): error TS2836: Import assertions are not allowed on statements that transpile to commonjs 'require' calls. -/index.ts(4,39): error TS4125: Resolution mode assertions are unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'. +/index.ts(4,39): error TS4125: 'resolution-mode' assertions are unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'. /index.ts(6,76): error TS2836: Import assertions are not allowed on statements that transpile to commonjs 'require' calls. @@ -20,7 +20,7 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2836: Import assertions are not allowed on statements that transpile to commonjs 'require' calls. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS4125: Resolution mode assertions are unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'. +!!! error TS4125: 'resolution-mode' assertions are unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'. // not exclusively type-only import {type RequireInterface as Req, RequireInterface as Req2} from "pkg" assert { "resolution-mode": "require" }; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/tests/baselines/reference/nodeModulesImportTypeModeDeclarationEmit1(module=node16).errors.txt b/tests/baselines/reference/nodeModulesImportTypeModeDeclarationEmit1(module=node16).errors.txt new file mode 100644 index 0000000000000..224e7b20e2dad --- /dev/null +++ b/tests/baselines/reference/nodeModulesImportTypeModeDeclarationEmit1(module=node16).errors.txt @@ -0,0 +1,38 @@ +/index.ts(2,31): error TS4125: 'resolution-mode' assertions are unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'. +/index.ts(3,31): error TS4125: 'resolution-mode' assertions are unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'. +/index.ts(5,58): error TS4125: 'resolution-mode' assertions are unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'. +/index.ts(6,14): error TS2841: The type of this expression cannot be named without a 'resolution-mode' assertion, which is an unstable feature. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'. +/index.ts(6,58): error TS4125: 'resolution-mode' assertions are unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'. + + +==== /index.ts (5 errors) ==== + export type LocalInterface = + & import("pkg", { assert: {"resolution-mode": "require"} }).RequireInterface + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS4125: 'resolution-mode' assertions are unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'. + & import("pkg", { assert: {"resolution-mode": "import"} }).ImportInterface; + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS4125: 'resolution-mode' assertions are unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'. + + export const a = (null as any as import("pkg", { assert: {"resolution-mode": "require"} }).RequireInterface); + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS4125: 'resolution-mode' assertions are unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'. + export const b = (null as any as import("pkg", { assert: {"resolution-mode": "import"} }).ImportInterface); + ~ +!!! error TS2841: The type of this expression cannot be named without a 'resolution-mode' assertion, which is an unstable feature. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'. + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS4125: 'resolution-mode' assertions are unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'. + +==== /node_modules/pkg/package.json (0 errors) ==== + { + "name": "pkg", + "version": "0.0.1", + "exports": { + "import": "./import.js", + "require": "./require.js" + } + } +==== /node_modules/pkg/import.d.ts (0 errors) ==== + export interface ImportInterface {} +==== /node_modules/pkg/require.d.ts (0 errors) ==== + export interface RequireInterface {} \ No newline at end of file diff --git a/tests/baselines/reference/nodeModulesImportTypeModeDeclarationEmit1(module=node16).js b/tests/baselines/reference/nodeModulesImportTypeModeDeclarationEmit1(module=node16).js index 4a65e05cdd90e..ac1cb24c8b3a7 100644 --- a/tests/baselines/reference/nodeModulesImportTypeModeDeclarationEmit1(module=node16).js +++ b/tests/baselines/reference/nodeModulesImportTypeModeDeclarationEmit1(module=node16).js @@ -28,9 +28,3 @@ Object.defineProperty(exports, "__esModule", { value: true }); exports.b = exports.a = void 0; exports.a = null; exports.b = null; - - -//// [index.d.ts] -export declare type LocalInterface = import("pkg", { assert: { "resolution-mode": "require" } }).RequireInterface & import("pkg", { assert: { "resolution-mode": "import" } }).ImportInterface; -export declare const a: import("pkg").RequireInterface; -export declare const b: import("pkg", { assert: { "resolution-mode": "import" } }).ImportInterface; diff --git a/tests/baselines/reference/nodeModulesImportTypeModeDeclarationEmit1(module=nodenext).errors.txt b/tests/baselines/reference/nodeModulesImportTypeModeDeclarationEmit1(module=nodenext).errors.txt new file mode 100644 index 0000000000000..224e7b20e2dad --- /dev/null +++ b/tests/baselines/reference/nodeModulesImportTypeModeDeclarationEmit1(module=nodenext).errors.txt @@ -0,0 +1,38 @@ +/index.ts(2,31): error TS4125: 'resolution-mode' assertions are unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'. +/index.ts(3,31): error TS4125: 'resolution-mode' assertions are unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'. +/index.ts(5,58): error TS4125: 'resolution-mode' assertions are unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'. +/index.ts(6,14): error TS2841: The type of this expression cannot be named without a 'resolution-mode' assertion, which is an unstable feature. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'. +/index.ts(6,58): error TS4125: 'resolution-mode' assertions are unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'. + + +==== /index.ts (5 errors) ==== + export type LocalInterface = + & import("pkg", { assert: {"resolution-mode": "require"} }).RequireInterface + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS4125: 'resolution-mode' assertions are unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'. + & import("pkg", { assert: {"resolution-mode": "import"} }).ImportInterface; + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS4125: 'resolution-mode' assertions are unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'. + + export const a = (null as any as import("pkg", { assert: {"resolution-mode": "require"} }).RequireInterface); + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS4125: 'resolution-mode' assertions are unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'. + export const b = (null as any as import("pkg", { assert: {"resolution-mode": "import"} }).ImportInterface); + ~ +!!! error TS2841: The type of this expression cannot be named without a 'resolution-mode' assertion, which is an unstable feature. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'. + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS4125: 'resolution-mode' assertions are unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'. + +==== /node_modules/pkg/package.json (0 errors) ==== + { + "name": "pkg", + "version": "0.0.1", + "exports": { + "import": "./import.js", + "require": "./require.js" + } + } +==== /node_modules/pkg/import.d.ts (0 errors) ==== + export interface ImportInterface {} +==== /node_modules/pkg/require.d.ts (0 errors) ==== + export interface RequireInterface {} \ No newline at end of file diff --git a/tests/baselines/reference/nodeModulesImportTypeModeDeclarationEmit1(module=nodenext).js b/tests/baselines/reference/nodeModulesImportTypeModeDeclarationEmit1(module=nodenext).js index 4a65e05cdd90e..ac1cb24c8b3a7 100644 --- a/tests/baselines/reference/nodeModulesImportTypeModeDeclarationEmit1(module=nodenext).js +++ b/tests/baselines/reference/nodeModulesImportTypeModeDeclarationEmit1(module=nodenext).js @@ -28,9 +28,3 @@ Object.defineProperty(exports, "__esModule", { value: true }); exports.b = exports.a = void 0; exports.a = null; exports.b = null; - - -//// [index.d.ts] -export declare type LocalInterface = import("pkg", { assert: { "resolution-mode": "require" } }).RequireInterface & import("pkg", { assert: { "resolution-mode": "import" } }).ImportInterface; -export declare const a: import("pkg").RequireInterface; -export declare const b: import("pkg", { assert: { "resolution-mode": "import" } }).ImportInterface; diff --git a/tests/baselines/reference/nodeModulesImportTypeModeDeclarationEmitErrors1(module=node16).errors.txt b/tests/baselines/reference/nodeModulesImportTypeModeDeclarationEmitErrors1(module=node16).errors.txt index b8b88af5ded82..f95d9176a3f8b 100644 --- a/tests/baselines/reference/nodeModulesImportTypeModeDeclarationEmitErrors1(module=node16).errors.txt +++ b/tests/baselines/reference/nodeModulesImportTypeModeDeclarationEmitErrors1(module=node16).errors.txt @@ -1,5 +1,8 @@ /index.ts(2,51): error TS1453: `resolution-mode` should be either `require` or `import`. +/index.ts(3,31): error TS4125: 'resolution-mode' assertions are unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'. /index.ts(5,78): error TS1453: `resolution-mode` should be either `require` or `import`. +/index.ts(6,14): error TS2841: The type of this expression cannot be named without a 'resolution-mode' assertion, which is an unstable feature. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'. +/index.ts(6,58): error TS4125: 'resolution-mode' assertions are unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'. /other.ts(3,7): error TS1340: Module 'pkg' does not refer to a type, but is used as a type here. Did you mean 'typeof import('pkg')'? /other.ts(3,22): error TS1005: 'assert' expected. /other.ts(3,39): error TS1005: ';' expected. @@ -89,17 +92,23 @@ export interface ImportInterface {} ==== /node_modules/pkg/require.d.ts (0 errors) ==== export interface RequireInterface {} -==== /index.ts (2 errors) ==== +==== /index.ts (5 errors) ==== export type LocalInterface = & import("pkg", { assert: {"resolution-mode": "foobar"} }).RequireInterface ~~~~~~~~ !!! error TS1453: `resolution-mode` should be either `require` or `import`. & import("pkg", { assert: {"resolution-mode": "import"} }).ImportInterface; + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS4125: 'resolution-mode' assertions are unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'. export const a = (null as any as import("pkg", { assert: {"resolution-mode": "foobar"} }).RequireInterface); ~~~~~~~~ !!! error TS1453: `resolution-mode` should be either `require` or `import`. export const b = (null as any as import("pkg", { assert: {"resolution-mode": "import"} }).ImportInterface); + ~ +!!! error TS2841: The type of this expression cannot be named without a 'resolution-mode' assertion, which is an unstable feature. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'. + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS4125: 'resolution-mode' assertions are unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'. ==== /other.ts (27 errors) ==== // missing assert: export type LocalInterface = diff --git a/tests/baselines/reference/nodeModulesImportTypeModeDeclarationEmitErrors1(module=node16).js b/tests/baselines/reference/nodeModulesImportTypeModeDeclarationEmitErrors1(module=node16).js index 7fd0aff8e8f6e..a514fca1cc011 100644 --- a/tests/baselines/reference/nodeModulesImportTypeModeDeclarationEmitErrors1(module=node16).js +++ b/tests/baselines/reference/nodeModulesImportTypeModeDeclarationEmitErrors1(module=node16).js @@ -119,10 +119,6 @@ exports.a = null; exports.b = null; -//// [index.d.ts] -export declare type LocalInterface = import("pkg", { assert: { "resolution-mode": "foobar" } }).RequireInterface & import("pkg", { assert: { "resolution-mode": "import" } }).ImportInterface; -export declare const a: import("pkg").RequireInterface; -export declare const b: import("pkg", { assert: { "resolution-mode": "import" } }).ImportInterface; //// [other.d.ts] export declare type LocalInterface = import("pkg", { assert: {} }); export declare const a: any; diff --git a/tests/baselines/reference/nodeModulesImportTypeModeDeclarationEmitErrors1(module=nodenext).errors.txt b/tests/baselines/reference/nodeModulesImportTypeModeDeclarationEmitErrors1(module=nodenext).errors.txt index b8b88af5ded82..f95d9176a3f8b 100644 --- a/tests/baselines/reference/nodeModulesImportTypeModeDeclarationEmitErrors1(module=nodenext).errors.txt +++ b/tests/baselines/reference/nodeModulesImportTypeModeDeclarationEmitErrors1(module=nodenext).errors.txt @@ -1,5 +1,8 @@ /index.ts(2,51): error TS1453: `resolution-mode` should be either `require` or `import`. +/index.ts(3,31): error TS4125: 'resolution-mode' assertions are unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'. /index.ts(5,78): error TS1453: `resolution-mode` should be either `require` or `import`. +/index.ts(6,14): error TS2841: The type of this expression cannot be named without a 'resolution-mode' assertion, which is an unstable feature. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'. +/index.ts(6,58): error TS4125: 'resolution-mode' assertions are unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'. /other.ts(3,7): error TS1340: Module 'pkg' does not refer to a type, but is used as a type here. Did you mean 'typeof import('pkg')'? /other.ts(3,22): error TS1005: 'assert' expected. /other.ts(3,39): error TS1005: ';' expected. @@ -89,17 +92,23 @@ export interface ImportInterface {} ==== /node_modules/pkg/require.d.ts (0 errors) ==== export interface RequireInterface {} -==== /index.ts (2 errors) ==== +==== /index.ts (5 errors) ==== export type LocalInterface = & import("pkg", { assert: {"resolution-mode": "foobar"} }).RequireInterface ~~~~~~~~ !!! error TS1453: `resolution-mode` should be either `require` or `import`. & import("pkg", { assert: {"resolution-mode": "import"} }).ImportInterface; + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS4125: 'resolution-mode' assertions are unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'. export const a = (null as any as import("pkg", { assert: {"resolution-mode": "foobar"} }).RequireInterface); ~~~~~~~~ !!! error TS1453: `resolution-mode` should be either `require` or `import`. export const b = (null as any as import("pkg", { assert: {"resolution-mode": "import"} }).ImportInterface); + ~ +!!! error TS2841: The type of this expression cannot be named without a 'resolution-mode' assertion, which is an unstable feature. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'. + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS4125: 'resolution-mode' assertions are unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'. ==== /other.ts (27 errors) ==== // missing assert: export type LocalInterface = diff --git a/tests/baselines/reference/nodeModulesImportTypeModeDeclarationEmitErrors1(module=nodenext).js b/tests/baselines/reference/nodeModulesImportTypeModeDeclarationEmitErrors1(module=nodenext).js index 7fd0aff8e8f6e..a514fca1cc011 100644 --- a/tests/baselines/reference/nodeModulesImportTypeModeDeclarationEmitErrors1(module=nodenext).js +++ b/tests/baselines/reference/nodeModulesImportTypeModeDeclarationEmitErrors1(module=nodenext).js @@ -119,10 +119,6 @@ exports.a = null; exports.b = null; -//// [index.d.ts] -export declare type LocalInterface = import("pkg", { assert: { "resolution-mode": "foobar" } }).RequireInterface & import("pkg", { assert: { "resolution-mode": "import" } }).ImportInterface; -export declare const a: import("pkg").RequireInterface; -export declare const b: import("pkg", { assert: { "resolution-mode": "import" } }).ImportInterface; //// [other.d.ts] export declare type LocalInterface = import("pkg", { assert: {} }); export declare const a: any; diff --git a/tests/baselines/reference/nodeModulesTripleSlashReferenceModeOverrideOldResolutionError.errors.txt b/tests/baselines/reference/nodeModulesTripleSlashReferenceModeOverrideOldResolutionError.errors.txt index 05f937c37aded..fcec678778db4 100644 --- a/tests/baselines/reference/nodeModulesTripleSlashReferenceModeOverrideOldResolutionError.errors.txt +++ b/tests/baselines/reference/nodeModulesTripleSlashReferenceModeOverrideOldResolutionError.errors.txt @@ -1,6 +1,6 @@ -/index.ts(1,23): error TS1452: Resolution modes are only supported when `moduleResolution` is `node16` or `nodenext`. +/index.ts(1,23): error TS1452: 'resolution-mode' assertions are only supported when `moduleResolution` is `node16` or `nodenext`. /index.ts(1,23): error TS2688: Cannot find type definition file for 'pkg'. -/index.ts(2,23): error TS1452: Resolution modes are only supported when `moduleResolution` is `node16` or `nodenext`. +/index.ts(2,23): error TS1452: 'resolution-mode' assertions are only supported when `moduleResolution` is `node16` or `nodenext`. /index.ts(2,23): error TS2688: Cannot find type definition file for 'pkg'. /index.ts(3,1): error TS2304: Cannot find name 'foo'. /index.ts(4,1): error TS2304: Cannot find name 'bar'. @@ -9,12 +9,12 @@ ==== /index.ts (6 errors) ==== /// ~~~ -!!! error TS1452: Resolution modes are only supported when `moduleResolution` is `node16` or `nodenext`. +!!! error TS1452: 'resolution-mode' assertions are only supported when `moduleResolution` is `node16` or `nodenext`. ~~~ !!! error TS2688: Cannot find type definition file for 'pkg'. /// ~~~ -!!! error TS1452: Resolution modes are only supported when `moduleResolution` is `node16` or `nodenext`. +!!! error TS1452: 'resolution-mode' assertions are only supported when `moduleResolution` is `node16` or `nodenext`. ~~~ !!! error TS2688: Cannot find type definition file for 'pkg'. foo; // `resolution-mode` is an error in old resolution settings, which resolves is arbitrary From 3ce08c6ba14eb6f9062f29462bd0ac2d5bada5c5 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Thu, 2 Jun 2022 17:46:48 -0700 Subject: [PATCH 10/12] fix(49223): checker.getTypeAtLocation for ExpressionWithTypeArguments returns an error any type (#49284) (#49369) * fix(49223): handle ExpressionWithTypeArguments nodes in isExpressionNode * Update src/compiler/utilities.ts * Just use `!isHeritageClause(node.parent)`. Co-authored-by: Daniel Rosenwasser Co-authored-by: Oleksandr T --- src/compiler/utilities.ts | 2 ++ src/testRunner/unittests/publicApi.ts | 24 +++++++++++++ .../reference/genericCallWithoutArgs.types | 1 + .../reference/importWithTypeArguments.types | 3 ++ .../instantiationExpressionErrors.types | 13 +++++++ .../reference/instantiationExpressions.types | 34 +++++++++++++++++++ .../parserMemberAccessExpression1.types | 2 ++ .../parserMemberAccessOffOfGenericType1.types | 1 + 8 files changed, 80 insertions(+) diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index a4cb8f9d8a5ee..dfb7ec0512883 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -2016,6 +2016,8 @@ namespace ts { case SyntaxKind.AwaitExpression: case SyntaxKind.MetaProperty: return true; + case SyntaxKind.ExpressionWithTypeArguments: + return !isHeritageClause(node.parent); case SyntaxKind.QualifiedName: while (node.parent.kind === SyntaxKind.QualifiedName) { node = node.parent; diff --git a/src/testRunner/unittests/publicApi.ts b/src/testRunner/unittests/publicApi.ts index 4bfce8288f500..00d8994520f54 100644 --- a/src/testRunner/unittests/publicApi.ts +++ b/src/testRunner/unittests/publicApi.ts @@ -131,6 +131,30 @@ describe("unittests:: Public APIs:: getTypeAtLocation", () => { assert.equal(type.flags, ts.TypeFlags.Any); }); + it("works on ExpressionWithTypeArguments", () => { + const content = ` + function fn(value: T) { + return { value }; + } + const foo = fn; + `; + const host = new fakes.CompilerHost(vfs.createFromFileSystem( + Harness.IO, + /*ignoreCase*/ true, + { documents: [new documents.TextDocument("/file.ts", content)], cwd: "/" })); + + const program = ts.createProgram({ + host, + rootNames: ["/file.ts"], + options: { noLib: true } + }); + + const checker = program.getTypeChecker(); + const file = program.getSourceFile("/file.ts")!; + const [declaration] = (ts.findLast(file.statements, ts.isVariableStatement) as ts.VariableStatement).declarationList.declarations; + assert.equal(checker.getTypeAtLocation(declaration.initializer!).flags, ts.TypeFlags.Object); + }); + it("returns an errorType for VariableDeclaration with BindingPattern name", () => { const content = "const foo = [1];\n" + "const [a] = foo;"; diff --git a/tests/baselines/reference/genericCallWithoutArgs.types b/tests/baselines/reference/genericCallWithoutArgs.types index 82c32a2ad0444..6d4969a83ee7e 100644 --- a/tests/baselines/reference/genericCallWithoutArgs.types +++ b/tests/baselines/reference/genericCallWithoutArgs.types @@ -7,6 +7,7 @@ function f(x: X, y: Y) { f. >f. : any +>f : (x: number, y: string) => void >f : (x: X, y: Y) => void > : any diff --git a/tests/baselines/reference/importWithTypeArguments.types b/tests/baselines/reference/importWithTypeArguments.types index 442b3cc9ed993..2998bd6f20e3b 100644 --- a/tests/baselines/reference/importWithTypeArguments.types +++ b/tests/baselines/reference/importWithTypeArguments.types @@ -1,5 +1,8 @@ === tests/cases/conformance/types/import/importWithTypeArguments.ts === import +>import : any + const a = import >a : any +>import : any diff --git a/tests/baselines/reference/instantiationExpressionErrors.types b/tests/baselines/reference/instantiationExpressionErrors.types index 334cb69865e01..c2de6b5720ec1 100644 --- a/tests/baselines/reference/instantiationExpressionErrors.types +++ b/tests/baselines/reference/instantiationExpressionErrors.types @@ -7,10 +7,12 @@ declare let f: { (): T, g(): U }; const a1 = f; // { (): number; g(): U; } >a1 : { (): number; g(): U; } +>f : { (): number; g(): U; } >f : { (): T; g(): U; } const a2 = f.g; // () => number >a2 : () => number +>f.g : () => number >f.g : () => U >f : { (): T; g(): U; } >g : () => U @@ -18,17 +20,21 @@ const a2 = f.g; // () => number const a3 = f.g; // () => U >a3 : () => U >f.g : () => U +>f : { (): number; g(): U; } >f : { (): T; g(): U; } >g : () => U const a4 = f.g; // () => number >a4 : () => number +>f.g : () => number >f.g : () => U +>f : { (): number; g(): U; } >f : { (): T; g(): U; } >g : () => U const a5 = f['g']; // () => number >a5 : () => number +>f['g'] : () => number >f['g'] : () => U >f : { (): T; g(): U; } >'g' : "g" @@ -48,6 +54,7 @@ const a7 = (f)['g']; >a7 : () => U >(f)['g'] : () => U >(f) : { (): number; g(): U; } +>f : { (): number; g(): U; } >f : { (): T; g(): U; } >'g' : "g" @@ -64,7 +71,9 @@ const a8 = f; // Relational operator error const a9 = (f); // Error, no applicable signatures >a9 : { g(): U; } +>(f) : { g(): U; } >(f) : { (): number; g(): U; } +>f : { (): number; g(): U; } >f : { (): T; g(): U; } // Type arguments with `?.` token @@ -82,11 +91,13 @@ const b2 = f?.(); const b3 = f?.(); >b3 : number >f?.() : number +>f : { (): number; g(): U; } >f : { (): T; g(): U; } const b4 = f?.(); // Error, expected no type arguments >b4 : number >f?.() : number +>f : { (): number; g(): U; } >f : { (): T; g(): U; } // Parsed as function call, even though this differs from JavaScript @@ -116,6 +127,7 @@ true; const x3 = f; >x3 : { (): true; g(): U; } +>f : { (): true; g(): U; } >f : { (): T; g(): U; } >true : true @@ -126,6 +138,7 @@ true; const x4 = f >x4 : { (): true; g(): U; } +>f : { (): true; g(): U; } >f : { (): T; g(): U; } >true : true diff --git a/tests/baselines/reference/instantiationExpressions.types b/tests/baselines/reference/instantiationExpressions.types index bb35bc036a14a..75fe72fc441bc 100644 --- a/tests/baselines/reference/instantiationExpressions.types +++ b/tests/baselines/reference/instantiationExpressions.types @@ -17,18 +17,22 @@ function f1() { let f0 = fx<>; // Error >f0 : { (x: T): T; (x: T, n: number): T; (t: [T, U]): [T, U]; } +>fx<> : { (x: T): T; (x: T, n: number): T; (t: [T, U]): [T, U]; } >fx : { (x: T): T; (x: T, n: number): T; (t: [T, U]): [T, U]; } let f1 = fx; // { (x: string): string; (x: string, n: number): string; } >f1 : { (x: string): string; (x: string, n: number): string; } +>fx : { (x: string): string; (x: string, n: number): string; } >fx : { (x: T): T; (x: T, n: number): T; (t: [T, U]): [T, U]; } let f2 = fx; // (t: [string, number]) => [string, number] >f2 : (t: [string, number]) => [string, number] +>fx : (t: [string, number]) => [string, number] >fx : { (x: T): T; (x: T, n: number): T; (t: [T, U]): [T, U]; } let f3 = fx; // Error >f3 : {} +>fx : {} >fx : { (x: T): T; (x: T, n: number): T; (t: [T, U]): [T, U]; } } @@ -53,14 +57,17 @@ function f2() { const A0 = Array<>; // Error >A0 : ArrayConstructor +>Array<> : ArrayConstructor >Array : ArrayConstructor const A1 = Array; // new (...) => string[] >A1 : { (arrayLength: number): string[]; (...items: string[]): string[]; new (arrayLength: number): string[]; new (...items: string[]): string[]; isArray(arg: any): arg is any[]; readonly prototype: any[]; } +>Array : { (arrayLength: number): string[]; (...items: string[]): string[]; new (arrayLength: number): string[]; new (...items: string[]): string[]; isArray(arg: any): arg is any[]; readonly prototype: any[]; } >Array : ArrayConstructor const A2 = Array; // Error >A2 : { isArray(arg: any): arg is any[]; readonly prototype: any[]; } +>Array : { isArray(arg: any): arg is any[]; readonly prototype: any[]; } >Array : ArrayConstructor } @@ -92,10 +99,12 @@ function f3() { let c1 = C; // { new (x: string): C; f(x: U): T[]; prototype: C; } >c1 : { new (x: string): C; prototype: C; f(x: U): U[]; } +>C : { new (x: string): C; prototype: C; f(x: U): U[]; } >C : typeof C let f1 = C.f; // (x: string) => string[] >f1 : (x: string) => string[] +>C.f : (x: string) => string[] >C.f : (x: U) => U[] >C : typeof C >f : (x: U) => U[] @@ -110,6 +119,7 @@ function f10(f: { (a: T): T, (a: U, b: number): U[] }) { let fs = f; // { (a: string): string; (a: string, b: number): string[]; } >fs : { (a: string): string; (a: string, b: number): string[]; } +>f : { (a: string): string; (a: string, b: number): string[]; } >f : { (a: T): T; (a: U, b: number): U[]; } } @@ -122,6 +132,7 @@ function f11(f: { (a: T): T, (a: string, b: number): string[] }) { let fs = f; // (a: string) => string >fs : (a: string) => string +>f : (a: string) => string >f : { (a: T): T; (a: string, b: number): string[]; } } @@ -133,6 +144,7 @@ function f12(f: { (a: T): T, x: string }) { let fs = f; // { (a: string): string; x: string; } >fs : { (a: string): string; x: string; } +>f : { (a: string): string; x: string; } >f : { (a: T): T; x: string; } } @@ -144,6 +156,7 @@ function f13(f: { x: string, y: string }) { let fs = f; // Error, no applicable signatures >fs : { x: string; y: string; } +>f : { x: string; y: string; } >f : { x: string; y: string; } } @@ -156,6 +169,7 @@ function f14(f: { new (a: T): T, new (a: U, b: number): U[] }) { let fs = f; // { new (a: string): string; new (a: string, b: number): string[]; } >fs : { new (a: string): string; new (a: string, b: number): string[]; } +>f : { new (a: string): string; new (a: string, b: number): string[]; } >f : { new (a: T): T; new (a: U, b: number): U[]; } } @@ -168,6 +182,7 @@ function f15(f: { new (a: T): T, (a: U, b: number): U[] }) { let fs = f; // { new (a: string): string; (a: string, b: number): string[]; } >fs : { (a: string, b: number): string[]; new (a: string): string; } +>f : { (a: string, b: number): string[]; new (a: string): string; } >f : { (a: U, b: number): U[]; new (a: T): T; } } @@ -180,6 +195,7 @@ function f16(f: { new (a: T): T, (a: string, b: number): string[] }) { let fs = f; // new (a: string) => string >fs : new (a: string) => string +>f : new (a: string) => string >f : { (a: string, b: number): string[]; new (a: T): T; } } @@ -192,6 +208,7 @@ function f17(f: { (a: T): T, new (a: string, b: number): string[] }) { let fs = f; // (a: string) => string >fs : (a: string) => string +>f : (a: string) => string >f : { (a: T): T; new (a: string, b: number): string[]; } } @@ -204,6 +221,7 @@ function f20(f: ((a: T) => T) & ((a: U, b: number) => U[])) { let fs = f; // ((a: string) => string) & ((a: string, b: number) => string[]]) >fs : ((a: string) => string) & ((a: string, b: number) => string[]) +>f : ((a: string) => string) & ((a: string, b: number) => string[]) >f : ((a: T) => T) & ((a: U, b: number) => U[]) } @@ -216,6 +234,7 @@ function f21(f: ((a: T) => T) & ((a: string, b: number) => string[])) { let fs = f; // (a: string) => string >fs : (a: string) => string +>f : (a: string) => string >f : ((a: T) => T) & ((a: string, b: number) => string[]) } @@ -227,6 +246,7 @@ function f22(f: ((a: T) => T) & { x: string }) { let fs = f; // ((a: string) => string) & { x: string } >fs : ((a: string) => string) & { x: string; } +>f : ((a: string) => string) & { x: string; } >f : ((a: T) => T) & { x: string; } } @@ -238,6 +258,7 @@ function f23(f: { x: string } & { y: string }) { let fs = f; // Error, no applicable signatures >fs : { x: string; } & { y: string; } +>f : { x: string; } & { y: string; } >f : { x: string; } & { y: string; } } @@ -250,6 +271,7 @@ function f24(f: (new (a: T) => T) & (new (a: U, b: number) => U[])) { let fs = f; // (new (a: string) => string) & ((a: string, b: number) => string[]]) >fs : (new (a: string) => string) & (new (a: string, b: number) => string[]) +>f : (new (a: string) => string) & (new (a: string, b: number) => string[]) >f : (new (a: T) => T) & (new (a: U, b: number) => U[]) } @@ -262,6 +284,7 @@ function f25(f: (new (a: T) => T) & ((a: U, b: number) => U[])) { let fs = f; // (new (a: string) => string) & ((a: string, b: number) => string[]]) >fs : (new (a: string) => string) & ((a: string, b: number) => string[]) +>f : (new (a: string) => string) & ((a: string, b: number) => string[]) >f : (new (a: T) => T) & ((a: U, b: number) => U[]) } @@ -274,6 +297,7 @@ function f26(f: (new (a: T) => T) & ((a: string, b: number) => string[])) { let fs = f; // new (a: string) => string >fs : new (a: string) => string +>f : new (a: string) => string >f : (new (a: T) => T) & ((a: string, b: number) => string[]) } @@ -286,6 +310,7 @@ function f27(f: ((a: T) => T) & (new (a: string, b: number) => string[])) { let fs = f; // (a: string) => string >fs : (a: string) => string +>f : (a: string) => string >f : ((a: T) => T) & (new (a: string, b: number) => string[]) } @@ -298,6 +323,7 @@ function f30(f: ((a: T) => T) | ((a: U, b: number) => U[])) { let fs = f; // ((a: string) => string) | ((a: string, b: number) => string[]]) >fs : ((a: string) => string) | ((a: string, b: number) => string[]) +>f : ((a: string) => string) | ((a: string, b: number) => string[]) >f : ((a: T) => T) | ((a: U, b: number) => U[]) } @@ -310,6 +336,7 @@ function f31(f: ((a: T) => T) | ((a: string, b: number) => string[])) { let fs = f; // Error, '(a: string, b: number) => string[]' has no applicable signatures >fs : ((a: string) => string) | {} +>f : ((a: string) => string) | {} >f : ((a: T) => T) | ((a: string, b: number) => string[]) } @@ -321,6 +348,7 @@ function f32(f: ((a: T) => T) | { x: string }) { let fs = f; // ((a: string) => string) | { x: string } >fs : { x: string; } | ((a: string) => string) +>f : { x: string; } | ((a: string) => string) >f : { x: string; } | ((a: T) => T) } @@ -332,6 +360,7 @@ function f33(f: { x: string } | { y: string }) { let fs = f; // Error, no applicable signatures >fs : { x: string; } | { y: string; } +>f : { x: string; } | { y: string; } >f : { x: string; } | { y: string; } } @@ -344,6 +373,7 @@ function f34(f: (new (a: T) => T) | (new (a: U, b: number) => U[])) { let fs = f; // (new (a: string) => string) | ((a: string, b: number) => string[]]) >fs : (new (a: string) => string) | (new (a: string, b: number) => string[]) +>f : (new (a: string) => string) | (new (a: string, b: number) => string[]) >f : (new (a: T) => T) | (new (a: U, b: number) => U[]) } @@ -356,6 +386,7 @@ function f35(f: (new (a: T) => T) | ((a: U, b: number) => U[])) { let fs = f; // (new (a: string) => string) | ((a: string, b: number) => string[]]) >fs : (new (a: string) => string) | ((a: string, b: number) => string[]) +>f : (new (a: string) => string) | ((a: string, b: number) => string[]) >f : (new (a: T) => T) | ((a: U, b: number) => U[]) } @@ -368,6 +399,7 @@ function f36(f: (new (a: T) => T) | ((a: string, b: number) => string[])) { let fs = f; // Error, '(a: string, b: number) => string[]' has no applicable signatures >fs : (new (a: string) => string) | {} +>f : (new (a: string) => string) | {} >f : (new (a: T) => T) | ((a: string, b: number) => string[]) } @@ -380,6 +412,7 @@ function f37(f: ((a: T) => T) | (new (a: string, b: number) => string[])) { let fs = f; // Error, 'new (a: string, b: number) => string[]' has no applicable signatures >fs : ((a: string) => string) | {} +>f : ((a: string) => string) | {} >f : ((a: T) => T) | (new (a: string, b: number) => string[]) } @@ -392,6 +425,7 @@ function f38(x: A) => A) | ((x: B) => B[]), U>(f: T | U | ( let fs = f; // U | ((x: string) => string) | ((x: string) => string[]) | ((x: string) => string[][]) >fs : U | ((x: string) => string) | ((x: string) => string[]) | ((x: string) => string[][]) +>f : U | ((x: string) => string) | ((x: string) => string[]) | ((x: string) => string[][]) >f : T | U | ((x: C) => C[][]) } diff --git a/tests/baselines/reference/parserMemberAccessExpression1.types b/tests/baselines/reference/parserMemberAccessExpression1.types index 08299f7dfd75f..395f91b2450f3 100644 --- a/tests/baselines/reference/parserMemberAccessExpression1.types +++ b/tests/baselines/reference/parserMemberAccessExpression1.types @@ -12,12 +12,14 @@ Foo.Bar(); Foo.Bar(); >Foo.Bar() : any >Foo.Bar : any +>Foo : any >Foo : any >Bar : any Foo.Bar(); >Foo.Bar() : any >Foo.Bar : any +>Foo : any >Foo : any >Bar : any diff --git a/tests/baselines/reference/parserMemberAccessOffOfGenericType1.types b/tests/baselines/reference/parserMemberAccessOffOfGenericType1.types index 2bd59381f8765..b89005fb0ca62 100644 --- a/tests/baselines/reference/parserMemberAccessOffOfGenericType1.types +++ b/tests/baselines/reference/parserMemberAccessOffOfGenericType1.types @@ -3,6 +3,7 @@ var v = List.makeChild(); >v : any >List.makeChild() : any >List.makeChild : any +>List : any >List : any >makeChild : any From 4c4c80322a1512391d2708a9008e910401c16ca1 Mon Sep 17 00:00:00 2001 From: TypeScript Bot Date: Thu, 2 Jun 2022 17:47:14 -0700 Subject: [PATCH 11/12] =?UTF-8?q?=F0=9F=A4=96=20Pick=20PR=20#49360=20(Expo?= =?UTF-8?q?se=20import=20mode=20calculation=20func...)=20into=20release-4.?= =?UTF-8?q?7=20(#49370)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Cherry-pick PR #49360 into release-4.7 Component commits: 5eb6425569 Expose import mode calculation functions 1f907ae640 Make `SourceFileImportsList` internal again. 4e40185fe8 Accepted API baselines. * Fix lints. Co-authored-by: Daniel Rosenwasser Co-authored-by: Daniel Rosenwasser --- src/compiler/program.ts | 43 +++++++++++++++---- .../reference/api/tsserverlibrary.d.ts | 25 +++++++++++ tests/baselines/reference/api/typescript.d.ts | 25 +++++++++++ 3 files changed, 85 insertions(+), 8 deletions(-) diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 2f47acb8d095e..76cb5086cbd0f 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -533,20 +533,39 @@ namespace ts { return resolutions; } - /* @internal */ - interface SourceFileImportsList { - imports: SourceFile["imports"]; - moduleAugmentations: SourceFile["moduleAugmentations"]; + /** + * Subset of a SourceFile used to calculate index-based resolutions + * This includes some internal fields, so unless you have very good reason, + * (and are willing to use some less stable internals) you should probably just pass a SourceFile. + * + * @internal + */ + export interface SourceFileImportsList { + /* @internal */ imports: SourceFile["imports"]; + /* @internal */ moduleAugmentations: SourceFile["moduleAugmentations"]; impliedNodeFormat?: SourceFile["impliedNodeFormat"]; }; - /* @internal */ + /** + * Calculates the resulting resolution mode for some reference in some file - this is generally the explicitly + * provided resolution mode in the reference, unless one is not present, in which case it is the mode of the containing file. + */ export function getModeForFileReference(ref: FileReference | string, containingFileMode: SourceFile["impliedNodeFormat"]) { return (isString(ref) ? containingFileMode : ref.resolutionMode) || containingFileMode; } - /* @internal */ - export function getModeForResolutionAtIndex(file: SourceFileImportsList, index: number) { + /** + * Calculates the final resolution mode for an import at some index within a file's imports list. This is generally the explicitly + * defined mode of the import if provided, or, if not, the mode of the containing file (with some exceptions: import=require is always commonjs, dynamic import is always esm). + * If you have an actual import node, prefer using getModeForUsageLocation on the reference string node. + * @param file File to fetch the resolution mode within + * @param index Index into the file's complete resolution list to get the resolution of - this is a concatenation of the file's imports and module augmentations + */ + export function getModeForResolutionAtIndex(file: SourceFile, index: number): ModuleKind.CommonJS | ModuleKind.ESNext | undefined; + /** @internal */ + // eslint-disable-next-line @typescript-eslint/unified-signatures + export function getModeForResolutionAtIndex(file: SourceFileImportsList, index: number): ModuleKind.CommonJS | ModuleKind.ESNext | undefined; + export function getModeForResolutionAtIndex(file: SourceFileImportsList, index: number): ModuleKind.CommonJS | ModuleKind.ESNext | undefined { if (file.impliedNodeFormat === undefined) return undefined; // we ensure all elements of file.imports and file.moduleAugmentations have the relevant parent pointers set during program setup, // so it's safe to use them even pre-bind @@ -564,7 +583,15 @@ namespace ts { return false; } - /* @internal */ + /** + * Calculates the final resolution mode for a given module reference node. This is generally the explicitly provided resolution mode, if + * one exists, or the mode of the containing source file. (Excepting import=require, which is always commonjs, and dynamic import, which is always esm). + * Notably, this function always returns `undefined` if the containing file has an `undefined` `impliedNodeFormat` - this field is only set when + * `moduleResolution` is `node16`+. + * @param file The file the import or import-like reference is contained within + * @param usage The module reference string + * @returns The final resolution mode of the import + */ export function getModeForUsageLocation(file: {impliedNodeFormat?: SourceFile["impliedNodeFormat"]}, usage: StringLiteralLike) { if (file.impliedNodeFormat === undefined) return undefined; if ((isImportDeclaration(usage.parent) || isExportDeclaration(usage.parent))) { diff --git a/tests/baselines/reference/api/tsserverlibrary.d.ts b/tests/baselines/reference/api/tsserverlibrary.d.ts index 3c0a87593c61e..ffa14ce6b4f79 100644 --- a/tests/baselines/reference/api/tsserverlibrary.d.ts +++ b/tests/baselines/reference/api/tsserverlibrary.d.ts @@ -5099,6 +5099,31 @@ declare namespace ts { export function formatDiagnostic(diagnostic: Diagnostic, host: FormatDiagnosticsHost): string; export function formatDiagnosticsWithColorAndContext(diagnostics: readonly Diagnostic[], host: FormatDiagnosticsHost): string; export function flattenDiagnosticMessageText(diag: string | DiagnosticMessageChain | undefined, newLine: string, indent?: number): string; + /** + * Calculates the resulting resolution mode for some reference in some file - this is generally the explicitly + * provided resolution mode in the reference, unless one is not present, in which case it is the mode of the containing file. + */ + export function getModeForFileReference(ref: FileReference | string, containingFileMode: SourceFile["impliedNodeFormat"]): ModuleKind.CommonJS | ModuleKind.ESNext | undefined; + /** + * Calculates the final resolution mode for an import at some index within a file's imports list. This is generally the explicitly + * defined mode of the import if provided, or, if not, the mode of the containing file (with some exceptions: import=require is always commonjs, dynamic import is always esm). + * If you have an actual import node, prefer using getModeForUsageLocation on the reference string node. + * @param file File to fetch the resolution mode within + * @param index Index into the file's complete resolution list to get the resolution of - this is a concatenation of the file's imports and module augmentations + */ + export function getModeForResolutionAtIndex(file: SourceFile, index: number): ModuleKind.CommonJS | ModuleKind.ESNext | undefined; + /** + * Calculates the final resolution mode for a given module reference node. This is generally the explicitly provided resolution mode, if + * one exists, or the mode of the containing source file. (Excepting import=require, which is always commonjs, and dynamic import, which is always esm). + * Notably, this function always returns `undefined` if the containing file has an `undefined` `impliedNodeFormat` - this field is only set when + * `moduleResolution` is `node16`+. + * @param file The file the import or import-like reference is contained within + * @param usage The module reference string + * @returns The final resolution mode of the import + */ + export function getModeForUsageLocation(file: { + impliedNodeFormat?: SourceFile["impliedNodeFormat"]; + }, usage: StringLiteralLike): ModuleKind.CommonJS | ModuleKind.ESNext | undefined; export 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 diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index 2e19019614600..66dc7a05a49f3 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -5099,6 +5099,31 @@ declare namespace ts { export function formatDiagnostic(diagnostic: Diagnostic, host: FormatDiagnosticsHost): string; export function formatDiagnosticsWithColorAndContext(diagnostics: readonly Diagnostic[], host: FormatDiagnosticsHost): string; export function flattenDiagnosticMessageText(diag: string | DiagnosticMessageChain | undefined, newLine: string, indent?: number): string; + /** + * Calculates the resulting resolution mode for some reference in some file - this is generally the explicitly + * provided resolution mode in the reference, unless one is not present, in which case it is the mode of the containing file. + */ + export function getModeForFileReference(ref: FileReference | string, containingFileMode: SourceFile["impliedNodeFormat"]): ModuleKind.CommonJS | ModuleKind.ESNext | undefined; + /** + * Calculates the final resolution mode for an import at some index within a file's imports list. This is generally the explicitly + * defined mode of the import if provided, or, if not, the mode of the containing file (with some exceptions: import=require is always commonjs, dynamic import is always esm). + * If you have an actual import node, prefer using getModeForUsageLocation on the reference string node. + * @param file File to fetch the resolution mode within + * @param index Index into the file's complete resolution list to get the resolution of - this is a concatenation of the file's imports and module augmentations + */ + export function getModeForResolutionAtIndex(file: SourceFile, index: number): ModuleKind.CommonJS | ModuleKind.ESNext | undefined; + /** + * Calculates the final resolution mode for a given module reference node. This is generally the explicitly provided resolution mode, if + * one exists, or the mode of the containing source file. (Excepting import=require, which is always commonjs, and dynamic import, which is always esm). + * Notably, this function always returns `undefined` if the containing file has an `undefined` `impliedNodeFormat` - this field is only set when + * `moduleResolution` is `node16`+. + * @param file The file the import or import-like reference is contained within + * @param usage The module reference string + * @returns The final resolution mode of the import + */ + export function getModeForUsageLocation(file: { + impliedNodeFormat?: SourceFile["impliedNodeFormat"]; + }, usage: StringLiteralLike): ModuleKind.CommonJS | ModuleKind.ESNext | undefined; export 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 From e5050bb405548a127b0a48a264bade6fd662ce06 Mon Sep 17 00:00:00 2001 From: TypeScript Bot Date: Fri, 3 Jun 2022 01:02:45 +0000 Subject: [PATCH 12/12] Bump version to 4.7.3 and LKG --- lib/tsc.js | 109 ++++++++++++++++++++-------- lib/tsserver.js | 137 ++++++++++++++++++++++++++---------- lib/tsserverlibrary.d.ts | 26 +++++++ lib/tsserverlibrary.js | 137 ++++++++++++++++++++++++++---------- lib/typescript.d.ts | 26 +++++++ lib/typescript.js | 137 ++++++++++++++++++++++++++---------- lib/typescriptServices.d.ts | 26 +++++++ lib/typescriptServices.js | 137 ++++++++++++++++++++++++++---------- lib/typingsInstaller.js | 133 +++++++++++++++++++++++++--------- package.json | 2 +- src/compiler/corePublic.ts | 2 +- 11 files changed, 656 insertions(+), 216 deletions(-) diff --git a/lib/tsc.js b/lib/tsc.js index 781b84ae4daff..7dd72bc6432c5 100644 --- a/lib/tsc.js +++ b/lib/tsc.js @@ -69,7 +69,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) { var ts; (function (ts) { ts.versionMajorMinor = "4.7"; - ts.version = "4.7.2"; + ts.version = "4.7.3"; var NativeCollections; (function (NativeCollections) { var globals = typeof globalThis !== "undefined" ? globalThis : @@ -5573,7 +5573,7 @@ var ts; Preserve_unused_imported_values_in_the_JavaScript_output_that_would_otherwise_be_removed: diag(1449, ts.DiagnosticCategory.Message, "Preserve_unused_imported_values_in_the_JavaScript_output_that_would_otherwise_be_removed_1449", "Preserve unused imported values in the JavaScript output that would otherwise be removed."), Dynamic_imports_can_only_accept_a_module_specifier_and_an_optional_assertion_as_arguments: diag(1450, ts.DiagnosticCategory.Message, "Dynamic_imports_can_only_accept_a_module_specifier_and_an_optional_assertion_as_arguments_1450", "Dynamic imports can only accept a module specifier and an optional assertion as arguments"), Private_identifiers_are_only_allowed_in_class_bodies_and_may_only_be_used_as_part_of_a_class_member_declaration_property_access_or_on_the_left_hand_side_of_an_in_expression: diag(1451, ts.DiagnosticCategory.Error, "Private_identifiers_are_only_allowed_in_class_bodies_and_may_only_be_used_as_part_of_a_class_member__1451", "Private identifiers are only allowed in class bodies and may only be used as part of a class member declaration, property access, or on the left-hand-side of an 'in' expression"), - Resolution_modes_are_only_supported_when_moduleResolution_is_node16_or_nodenext: diag(1452, ts.DiagnosticCategory.Error, "Resolution_modes_are_only_supported_when_moduleResolution_is_node16_or_nodenext_1452", "Resolution modes are only supported when `moduleResolution` is `node16` or `nodenext`."), + resolution_mode_assertions_are_only_supported_when_moduleResolution_is_node16_or_nodenext: diag(1452, ts.DiagnosticCategory.Error, "resolution_mode_assertions_are_only_supported_when_moduleResolution_is_node16_or_nodenext_1452", "'resolution-mode' assertions are only supported when `moduleResolution` is `node16` or `nodenext`."), resolution_mode_should_be_either_require_or_import: diag(1453, ts.DiagnosticCategory.Error, "resolution_mode_should_be_either_require_or_import_1453", "`resolution-mode` should be either `require` or `import`."), resolution_mode_can_only_be_set_for_type_only_imports: diag(1454, ts.DiagnosticCategory.Error, "resolution_mode_can_only_be_set_for_type_only_imports_1454", "`resolution-mode` can only be set for type-only imports."), resolution_mode_is_the_only_valid_key_for_type_import_assertions: diag(1455, ts.DiagnosticCategory.Error, "resolution_mode_is_the_only_valid_key_for_type_import_assertions_1455", "`resolution-mode` is the only valid key for type import assertions."), @@ -6077,6 +6077,7 @@ var ts; Import_assertions_are_not_allowed_on_statements_that_transpile_to_commonjs_require_calls: diag(2836, ts.DiagnosticCategory.Error, "Import_assertions_are_not_allowed_on_statements_that_transpile_to_commonjs_require_calls_2836", "Import assertions are not allowed on statements that transpile to commonjs 'require' calls."), Import_assertion_values_must_be_string_literal_expressions: diag(2837, ts.DiagnosticCategory.Error, "Import_assertion_values_must_be_string_literal_expressions_2837", "Import assertion values must be string literal expressions."), All_declarations_of_0_must_have_identical_constraints: diag(2838, ts.DiagnosticCategory.Error, "All_declarations_of_0_must_have_identical_constraints_2838", "All declarations of '{0}' must have identical constraints."), + The_type_of_this_expression_cannot_be_named_without_a_resolution_mode_assertion_which_is_an_unstable_feature_Use_nightly_TypeScript_to_silence_this_error_Try_updating_with_npm_install_D_typescript_next: diag(2841, ts.DiagnosticCategory.Error, "The_type_of_this_expression_cannot_be_named_without_a_resolution_mode_assertion_which_is_an_unstable_2841", "The type of this expression cannot be named without a 'resolution-mode' assertion, which is an unstable feature. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'."), Import_declaration_0_is_using_private_name_1: diag(4000, ts.DiagnosticCategory.Error, "Import_declaration_0_is_using_private_name_1_4000", "Import declaration '{0}' is using private name '{1}'."), Type_parameter_0_of_exported_class_has_or_is_using_private_name_1: diag(4002, ts.DiagnosticCategory.Error, "Type_parameter_0_of_exported_class_has_or_is_using_private_name_1_4002", "Type parameter '{0}' of exported class has or is using private name '{1}'."), Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1: diag(4004, ts.DiagnosticCategory.Error, "Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1_4004", "Type parameter '{0}' of exported interface has or is using private name '{1}'."), @@ -6184,7 +6185,7 @@ var ts; This_member_cannot_have_a_JSDoc_comment_with_an_override_tag_because_it_is_not_declared_in_the_base_class_0: diag(4122, ts.DiagnosticCategory.Error, "This_member_cannot_have_a_JSDoc_comment_with_an_override_tag_because_it_is_not_declared_in_the_base__4122", "This member cannot have a JSDoc comment with an '@override' tag because it is not declared in the base class '{0}'."), This_member_cannot_have_a_JSDoc_comment_with_an_override_tag_because_it_is_not_declared_in_the_base_class_0_Did_you_mean_1: diag(4123, ts.DiagnosticCategory.Error, "This_member_cannot_have_a_JSDoc_comment_with_an_override_tag_because_it_is_not_declared_in_the_base__4123", "This member cannot have a JSDoc comment with an 'override' tag because it is not declared in the base class '{0}'. Did you mean '{1}'?"), Compiler_option_0_of_value_1_is_unstable_Use_nightly_TypeScript_to_silence_this_error_Try_updating_with_npm_install_D_typescript_next: diag(4124, ts.DiagnosticCategory.Error, "Compiler_option_0_of_value_1_is_unstable_Use_nightly_TypeScript_to_silence_this_error_Try_updating_w_4124", "Compiler option '{0}' of value '{1}' is unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'."), - Resolution_mode_assertions_are_unstable_Use_nightly_TypeScript_to_silence_this_error_Try_updating_with_npm_install_D_typescript_next: diag(4125, ts.DiagnosticCategory.Error, "Resolution_mode_assertions_are_unstable_Use_nightly_TypeScript_to_silence_this_error_Try_updating_wi_4125", "Resolution mode assertions are unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'."), + resolution_mode_assertions_are_unstable_Use_nightly_TypeScript_to_silence_this_error_Try_updating_with_npm_install_D_typescript_next: diag(4125, ts.DiagnosticCategory.Error, "resolution_mode_assertions_are_unstable_Use_nightly_TypeScript_to_silence_this_error_Try_updating_wi_4125", "'resolution-mode' assertions are unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'."), The_current_host_does_not_support_the_0_option: diag(5001, ts.DiagnosticCategory.Error, "The_current_host_does_not_support_the_0_option_5001", "The current host does not support the '{0}' option."), Cannot_find_the_common_subdirectory_path_for_the_input_files: diag(5009, ts.DiagnosticCategory.Error, "Cannot_find_the_common_subdirectory_path_for_the_input_files_5009", "Cannot find the common subdirectory path for the input files."), File_specification_cannot_end_in_a_recursive_directory_wildcard_Asterisk_Asterisk_Colon_0: diag(5010, ts.DiagnosticCategory.Error, "File_specification_cannot_end_in_a_recursive_directory_wildcard_Asterisk_Asterisk_Colon_0_5010", "File specification cannot end in a recursive directory wildcard ('**'): '{0}'."), @@ -12408,6 +12409,8 @@ var ts; case 218: case 231: return true; + case 228: + return !ts.isHeritageClause(node.parent); case 161: while (node.parent.kind === 161) { node = node.parent; @@ -12571,9 +12574,6 @@ var ts; } ts.isVariableDeclarationInitializedToBareOrAccessedRequire = isVariableDeclarationInitializedToBareOrAccessedRequire; function isVariableDeclarationInitializedWithRequireHelper(node, allowAccessedRequire) { - if (node.kind === 203) { - node = node.parent.parent; - } return ts.isVariableDeclaration(node) && !!node.initializer && isRequireCall(allowAccessedRequire ? getLeftmostAccessExpression(node.initializer) : node.initializer, true); @@ -15843,13 +15843,13 @@ var ts; return !file.isDeclarationFile ? walkTreeForJSXTags(file) : undefined; } function isFileForcedToBeModuleByFormat(file) { - return file.impliedNodeFormat === ts.ModuleKind.ESNext && !file.isDeclarationFile ? true : undefined; + return (file.impliedNodeFormat === ts.ModuleKind.ESNext || (ts.fileExtensionIsOneOf(file.fileName, [".cjs", ".cts"]))) && !file.isDeclarationFile ? true : undefined; } function getSetExternalModuleIndicator(options) { switch (getEmitModuleDetectionKind(options)) { case ts.ModuleDetectionKind.Force: return function (file) { - file.externalModuleIndicator = !file.isDeclarationFile || ts.isFileProbablyExternalModule(file); + file.externalModuleIndicator = ts.isFileProbablyExternalModule(file) || !file.isDeclarationFile || undefined; }; case ts.ModuleDetectionKind.Legacy: return function (file) { @@ -15905,7 +15905,8 @@ var ts; } ts.getEmitModuleResolutionKind = getEmitModuleResolutionKind; function getEmitModuleDetectionKind(options) { - return options.moduleDetection || ts.ModuleDetectionKind.Auto; + return options.moduleDetection || + (getEmitModuleKind(options) === ts.ModuleKind.Node16 || getEmitModuleKind(options) === ts.ModuleKind.NodeNext ? ts.ModuleDetectionKind.Force : ts.ModuleDetectionKind.Auto); } ts.getEmitModuleDetectionKind = getEmitModuleDetectionKind; function hasJsonModuleEmitEnabled(options) { @@ -23341,6 +23342,10 @@ var ts; return node.kind === 267; } ts.isImportClause = isImportClause; + function isImportTypeAssertionContainer(node) { + return node.kind === 295; + } + ts.isImportTypeAssertionContainer = isImportTypeAssertionContainer; function isAssertClause(node) { return node.kind === 293; } @@ -34231,7 +34236,7 @@ var ts; } if (ts.isImplicitGlob(spec.substring(spec.lastIndexOf(ts.directorySeparator) + 1))) { return { - key: useCaseSensitiveFileNames ? spec : ts.toFileNameLowerCase(spec), + key: ts.removeTrailingDirectorySeparator(useCaseSensitiveFileNames ? spec : ts.toFileNameLowerCase(spec)), flags: 1 }; } @@ -35164,15 +35169,19 @@ var ts; function nodeNextModuleNameResolver(moduleName, containingFile, compilerOptions, host, cache, redirectedReference, resolutionMode) { return nodeNextModuleNameResolverWorker(NodeResolutionFeatures.NodeNextDefault, moduleName, containingFile, compilerOptions, host, cache, redirectedReference, resolutionMode); } - function nodeNextModuleNameResolverWorker(features, moduleName, containingFile, compilerOptions, host, cache, redirectedReference, resolutionMode) { - var containingDirectory = ts.getDirectoryPath(containingFile); - var esmMode = resolutionMode === ts.ModuleKind.ESNext ? NodeResolutionFeatures.EsmMode : 0; - return nodeModuleNameResolverWorker(features | esmMode, moduleName, containingDirectory, compilerOptions, host, cache, compilerOptions.resolveJsonModule ? tsPlusJsonExtensions : tsExtensions, redirectedReference); - } var jsOnlyExtensions = [Extensions.JavaScript]; var tsExtensions = [Extensions.TypeScript, Extensions.JavaScript]; var tsPlusJsonExtensions = __spreadArray(__spreadArray([], tsExtensions, true), [Extensions.Json], false); var tsconfigExtensions = [Extensions.TSConfig]; + function nodeNextModuleNameResolverWorker(features, moduleName, containingFile, compilerOptions, host, cache, redirectedReference, resolutionMode) { + var containingDirectory = ts.getDirectoryPath(containingFile); + var esmMode = resolutionMode === ts.ModuleKind.ESNext ? NodeResolutionFeatures.EsmMode : 0; + var extensions = compilerOptions.noDtsResolution ? [Extensions.TsOnly, Extensions.JavaScript] : tsExtensions; + if (compilerOptions.resolveJsonModule) { + extensions = __spreadArray(__spreadArray([], extensions, true), [Extensions.Json], false); + } + return nodeModuleNameResolverWorker(features | esmMode, moduleName, containingDirectory, compilerOptions, host, cache, extensions, redirectedReference); + } function tryResolveJSModuleWorker(moduleName, initialDir, host) { return nodeModuleNameResolverWorker(NodeResolutionFeatures.None, moduleName, initialDir, { moduleResolution: ts.ModuleResolutionKind.NodeJs, allowJs: true }, host, undefined, jsOnlyExtensions, undefined); } @@ -35795,13 +35804,32 @@ var ts; } return toSearchResult(undefined); } + function comparePatternKeys(a, b) { + var aPatternIndex = a.indexOf("*"); + var bPatternIndex = b.indexOf("*"); + var baseLenA = aPatternIndex === -1 ? a.length : aPatternIndex + 1; + var baseLenB = bPatternIndex === -1 ? b.length : bPatternIndex + 1; + if (baseLenA > baseLenB) + return -1; + if (baseLenB > baseLenA) + return 1; + if (aPatternIndex === -1) + return 1; + if (bPatternIndex === -1) + return -1; + if (a.length > b.length) + return -1; + if (b.length > a.length) + return 1; + return 0; + } function loadModuleFromImportsOrExports(extensions, state, cache, redirectedReference, moduleName, lookupTable, scope, isImports) { var loadModuleFromTargetImportOrExport = getLoadModuleFromTargetImportOrExport(extensions, state, cache, redirectedReference, moduleName, scope, isImports); if (!ts.endsWith(moduleName, ts.directorySeparator) && moduleName.indexOf("*") === -1 && ts.hasProperty(lookupTable, moduleName)) { var target = lookupTable[moduleName]; return loadModuleFromTargetImportOrExport(target, "", false); } - var expandingKeys = ts.sort(ts.filter(ts.getOwnKeys(lookupTable), function (k) { return k.indexOf("*") !== -1 || ts.endsWith(k, "/"); }), function (a, b) { return a.length - b.length; }); + var expandingKeys = ts.sort(ts.filter(ts.getOwnKeys(lookupTable), function (k) { return k.indexOf("*") !== -1 || ts.endsWith(k, "/"); }), comparePatternKeys); for (var _i = 0, expandingKeys_1 = expandingKeys; _i < expandingKeys_1.length; _i++) { var potentialTarget = expandingKeys_1[_i]; if (state.features & NodeResolutionFeatures.ExportsPatternTrailers && matchesPatternWithTrailer(potentialTarget, moduleName)) { @@ -36076,8 +36104,7 @@ var ts; var pathAndExtension = loadModuleFromFile(extensions, candidate, onlyRecordFailures, state) || loadNodeModuleFromDirectoryWorker(extensions, candidate, onlyRecordFailures, state, packageInfo && packageInfo.packageJsonContent, packageInfo && packageInfo.versionPaths); if (!pathAndExtension && packageInfo - && packageInfo.packageJsonContent.exports === undefined - && packageInfo.packageJsonContent.main === undefined + && (packageInfo.packageJsonContent.exports === undefined || packageInfo.packageJsonContent.exports === null) && state.features & NodeResolutionFeatures.EsmMode) { pathAndExtension = loadModuleFromFile(extensions, ts.combinePaths(candidate, "index.js"), onlyRecordFailures, state); } @@ -38452,12 +38479,14 @@ var ts; } } function setCommonJsModuleIndicator(node) { - if (file.externalModuleIndicator) { + if (file.externalModuleIndicator && file.externalModuleIndicator !== true) { return false; } if (!file.commonJsModuleIndicator) { file.commonJsModuleIndicator = node; - bindSourceFileAsExternalModule(); + if (!file.externalModuleIndicator) { + bindSourceFileAsExternalModule(); + } } return true; } @@ -38810,7 +38839,11 @@ var ts; checkStrictModeEvalOrArguments(node, node.name); } if (!ts.isBindingPattern(node.name)) { - if (ts.isInJSFile(node) && ts.isVariableDeclarationInitializedToBareOrAccessedRequire(node) && !ts.getJSDocTypeTag(node) && !(ts.getCombinedModifierFlags(node) & 1)) { + var possibleVariableDecl = node.kind === 254 ? node : node.parent.parent; + if (ts.isInJSFile(node) && + ts.isVariableDeclarationInitializedToBareOrAccessedRequire(possibleVariableDecl) && + !ts.getJSDocTypeTag(node) && + !(ts.getCombinedModifierFlags(node) & 1)) { declareSymbolAndAddToSymbolTable(node, 2097152, 2097152); } else if (ts.isBlockOrCatchScoped(node)) { @@ -41123,7 +41156,8 @@ var ts; && isAliasableOrJsExpression(node.parent.right) || node.kind === 297 || node.kind === 296 && isAliasableOrJsExpression(node.initializer) - || ts.isVariableDeclarationInitializedToBareOrAccessedRequire(node); + || node.kind === 254 && ts.isVariableDeclarationInitializedToBareOrAccessedRequire(node) + || node.kind === 203 && ts.isVariableDeclarationInitializedToBareOrAccessedRequire(node.parent.parent); } function isAliasableOrJsExpression(e) { return ts.isAliasableExpression(e) || ts.isFunctionExpression(e) && isJSConstructor(e); @@ -41204,7 +41238,7 @@ var ts; if (!ts.isSourceFileJS(file)) { return hasExportAssignmentSymbol(moduleSymbol); } - return !file.externalModuleIndicator && !resolveExportByName(moduleSymbol, ts.escapeLeadingUnderscores("__esModule"), undefined, dontResolveAlias); + return typeof file.externalModuleIndicator !== "object" && !resolveExportByName(moduleSymbol, ts.escapeLeadingUnderscores("__esModule"), undefined, dontResolveAlias); } function getTargetOfImportClause(node, dontResolveAlias) { var _a; @@ -43994,6 +44028,7 @@ var ts; return symbol.parent ? ts.factory.createQualifiedName(symbolToEntityNameNode(symbol.parent), identifier) : identifier; } function symbolToTypeNode(symbol, context, meaning, overrideTypeArguments) { + var _a, _b, _c, _d; var chain = lookupSymbolChain(symbol, context, meaning, !(context.flags & 16384)); var isTypeOf = meaning === 111551; if (ts.some(chain[0].declarations, hasNonGlobalAugmentationExternalModuleSymbol)) { @@ -44009,6 +44044,7 @@ var ts; assertion = ts.factory.createImportTypeAssertionContainer(ts.factory.createAssertClause(ts.factory.createNodeArray([ ts.factory.createAssertEntry(ts.factory.createStringLiteral("resolution-mode"), ts.factory.createStringLiteral("import")) ]))); + (_b = (_a = context.tracker).reportImportTypeNodeResolutionModeOverride) === null || _b === void 0 ? void 0 : _b.call(_a); } } if (!specifier) { @@ -44026,6 +44062,7 @@ var ts; assertion = ts.factory.createImportTypeAssertionContainer(ts.factory.createAssertClause(ts.factory.createNodeArray([ ts.factory.createAssertEntry(ts.factory.createStringLiteral("resolution-mode"), ts.factory.createStringLiteral(swappedMode === ts.ModuleKind.ESNext ? "import" : "require")) ]))); + (_d = (_c = context.tracker).reportImportTypeNodeResolutionModeOverride) === null || _d === void 0 ? void 0 : _d.call(_c); } } if (!assertion) { @@ -48695,7 +48732,7 @@ var ts; var objectType; return !!(type.flags & 8388608 && ts.getObjectFlags(objectType = type.objectType) & 32 && !isGenericMappedType(objectType) && isGenericIndexType(type.indexType) && - !objectType.declaration.questionToken && !objectType.declaration.nameType); + !(getMappedTypeModifiers(objectType) & 8) && !objectType.declaration.nameType); } function getApparentType(type) { var t = !(type.flags & 465829888) ? type : getBaseConstraintOfType(type) || unknownType; @@ -67596,8 +67633,11 @@ var ts; if (node.assertions) { var override = ts.getResolutionModeOverrideForClause(node.assertions.assertClause, grammarErrorOnNode); if (override) { + if (!ts.isNightly()) { + grammarErrorOnNode(node.assertions.assertClause, ts.Diagnostics.resolution_mode_assertions_are_unstable_Use_nightly_TypeScript_to_silence_this_error_Try_updating_with_npm_install_D_typescript_next); + } if (ts.getEmitModuleResolutionKind(compilerOptions) !== ts.ModuleResolutionKind.Node16 && ts.getEmitModuleResolutionKind(compilerOptions) !== ts.ModuleResolutionKind.NodeNext) { - grammarErrorOnNode(node.assertions.assertClause, ts.Diagnostics.Resolution_modes_are_only_supported_when_moduleResolution_is_node16_or_nodenext); + grammarErrorOnNode(node.assertions.assertClause, ts.Diagnostics.resolution_mode_assertions_are_only_supported_when_moduleResolution_is_node16_or_nodenext); } } } @@ -68965,7 +69005,7 @@ var ts; return; } var symbol = getSymbolOfNode(node); - if (symbol.flags & 2097152 && ts.isVariableDeclarationInitializedToBareOrAccessedRequire(node)) { + if (symbol.flags & 2097152 && ts.isVariableDeclarationInitializedToBareOrAccessedRequire(node.kind === 203 ? node.parent.parent : node)) { checkAliasSymbol(node); return; } @@ -71217,10 +71257,10 @@ var ts; var override = ts.getResolutionModeOverrideForClause(declaration.assertClause, validForTypeAssertions ? grammarErrorOnNode : undefined); if (validForTypeAssertions && override) { if (!ts.isNightly()) { - grammarErrorOnNode(declaration.assertClause, ts.Diagnostics.Resolution_mode_assertions_are_unstable_Use_nightly_TypeScript_to_silence_this_error_Try_updating_with_npm_install_D_typescript_next); + grammarErrorOnNode(declaration.assertClause, ts.Diagnostics.resolution_mode_assertions_are_unstable_Use_nightly_TypeScript_to_silence_this_error_Try_updating_with_npm_install_D_typescript_next); } if (ts.getEmitModuleResolutionKind(compilerOptions) !== ts.ModuleResolutionKind.Node16 && ts.getEmitModuleResolutionKind(compilerOptions) !== ts.ModuleResolutionKind.NodeNext) { - return grammarErrorOnNode(declaration.assertClause, ts.Diagnostics.Resolution_modes_are_only_supported_when_moduleResolution_is_node16_or_nodenext); + return grammarErrorOnNode(declaration.assertClause, ts.Diagnostics.resolution_mode_assertions_are_only_supported_when_moduleResolution_is_node16_or_nodenext); } return; } @@ -88352,7 +88392,8 @@ var ts; trackReferencedAmbientModule: trackReferencedAmbientModule, trackExternalModuleSymbolOfImportTypeNode: trackExternalModuleSymbolOfImportTypeNode, reportNonlocalAugmentation: reportNonlocalAugmentation, - reportNonSerializableProperty: reportNonSerializableProperty + reportNonSerializableProperty: reportNonSerializableProperty, + reportImportTypeNodeResolutionModeOverride: reportImportTypeNodeResolutionModeOverride, }; var errorNameNode; var errorFallbackNode; @@ -88474,6 +88515,11 @@ var ts; context.addDiagnostic(ts.createDiagnosticForNode((errorNameNode || errorFallbackNode), ts.Diagnostics.The_type_of_this_node_cannot_be_serialized_because_its_property_0_cannot_be_serialized, propertyName)); } } + function reportImportTypeNodeResolutionModeOverride() { + if (!ts.isNightly() && (errorNameNode || errorFallbackNode)) { + context.addDiagnostic(ts.createDiagnosticForNode((errorNameNode || errorFallbackNode), ts.Diagnostics.The_type_of_this_expression_cannot_be_named_without_a_resolution_mode_assertion_which_is_an_unstable_feature_Use_nightly_TypeScript_to_silence_this_error_Try_updating_with_npm_install_D_typescript_next)); + } + } function transformDeclarationsForJS(sourceFile, bundled) { var oldDiag = getSymbolAccessibilityDiagnostic; getSymbolAccessibilityDiagnostic = function (s) { return (s.errorNode && ts.canProduceDiagnostics(s.errorNode) ? ts.createGetSymbolAccessibilityDiagnosticForNode(s.errorNode)(s) : ({ @@ -88890,7 +88936,7 @@ var ts; var mode = ts.getResolutionModeOverrideForClause(assertClause); if (mode !== undefined) { if (!ts.isNightly()) { - context.addDiagnostic(ts.createDiagnosticForNode(assertClause, ts.Diagnostics.Resolution_mode_assertions_are_unstable_Use_nightly_TypeScript_to_silence_this_error_Try_updating_with_npm_install_D_typescript_next)); + context.addDiagnostic(ts.createDiagnosticForNode(assertClause, ts.Diagnostics.resolution_mode_assertions_are_unstable_Use_nightly_TypeScript_to_silence_this_error_Try_updating_with_npm_install_D_typescript_next)); } return assertClause; } @@ -97594,7 +97640,7 @@ var ts; ts.setResolvedTypeReferenceDirective(file, fileName, resolvedTypeReferenceDirective); var mode = ref.resolutionMode || file.impliedNodeFormat; if (mode && ts.getEmitModuleResolutionKind(options) !== ts.ModuleResolutionKind.Node16 && ts.getEmitModuleResolutionKind(options) !== ts.ModuleResolutionKind.NodeNext) { - programDiagnostics.add(ts.createDiagnosticForRange(file, ref, ts.Diagnostics.Resolution_modes_are_only_supported_when_moduleResolution_is_node16_or_nodenext)); + programDiagnostics.add(ts.createDiagnosticForRange(file, ref, ts.Diagnostics.resolution_mode_assertions_are_only_supported_when_moduleResolution_is_node16_or_nodenext)); } processTypeReferenceDirective(fileName, mode, resolvedTypeReferenceDirective, { kind: ts.FileIncludeKind.TypeReferenceDirective, file: file.path, index: index, }); } @@ -102211,6 +102257,7 @@ var ts; } function reloadFileNamesFromConfigFile() { writeLog("Reloading new file names and options"); + reloadLevel = ts.ConfigFileProgramReloadLevel.None; rootFileNames = ts.getFileNamesFromConfigSpecs(compilerOptions.configFile.configFileSpecs, ts.getNormalizedAbsolutePath(ts.getDirectoryPath(configFileName), currentDirectory), compilerOptions, parseConfigFileHost, extraFileExtensions); if (ts.updateErrorForNoInputFiles(rootFileNames, ts.getNormalizedAbsolutePath(configFileName, currentDirectory), compilerOptions.configFile.configFileSpecs, configFileParsingDiagnostics, canConfigFileJsonReportNoInputFiles)) { hasChangedConfigFileParsingErrors = true; diff --git a/lib/tsserver.js b/lib/tsserver.js index 2cd21081a3706..cccf548a539e8 100644 --- a/lib/tsserver.js +++ b/lib/tsserver.js @@ -100,7 +100,7 @@ var ts; // The following is baselined as a literal template type without intervention /** The version of the TypeScript compiler release */ // eslint-disable-next-line @typescript-eslint/no-inferrable-types - ts.version = "4.7.2"; + ts.version = "4.7.3"; /* @internal */ var Comparison; (function (Comparison) { @@ -8389,7 +8389,7 @@ var ts; Preserve_unused_imported_values_in_the_JavaScript_output_that_would_otherwise_be_removed: diag(1449, ts.DiagnosticCategory.Message, "Preserve_unused_imported_values_in_the_JavaScript_output_that_would_otherwise_be_removed_1449", "Preserve unused imported values in the JavaScript output that would otherwise be removed."), Dynamic_imports_can_only_accept_a_module_specifier_and_an_optional_assertion_as_arguments: diag(1450, ts.DiagnosticCategory.Message, "Dynamic_imports_can_only_accept_a_module_specifier_and_an_optional_assertion_as_arguments_1450", "Dynamic imports can only accept a module specifier and an optional assertion as arguments"), Private_identifiers_are_only_allowed_in_class_bodies_and_may_only_be_used_as_part_of_a_class_member_declaration_property_access_or_on_the_left_hand_side_of_an_in_expression: diag(1451, ts.DiagnosticCategory.Error, "Private_identifiers_are_only_allowed_in_class_bodies_and_may_only_be_used_as_part_of_a_class_member__1451", "Private identifiers are only allowed in class bodies and may only be used as part of a class member declaration, property access, or on the left-hand-side of an 'in' expression"), - Resolution_modes_are_only_supported_when_moduleResolution_is_node16_or_nodenext: diag(1452, ts.DiagnosticCategory.Error, "Resolution_modes_are_only_supported_when_moduleResolution_is_node16_or_nodenext_1452", "Resolution modes are only supported when `moduleResolution` is `node16` or `nodenext`."), + resolution_mode_assertions_are_only_supported_when_moduleResolution_is_node16_or_nodenext: diag(1452, ts.DiagnosticCategory.Error, "resolution_mode_assertions_are_only_supported_when_moduleResolution_is_node16_or_nodenext_1452", "'resolution-mode' assertions are only supported when `moduleResolution` is `node16` or `nodenext`."), resolution_mode_should_be_either_require_or_import: diag(1453, ts.DiagnosticCategory.Error, "resolution_mode_should_be_either_require_or_import_1453", "`resolution-mode` should be either `require` or `import`."), resolution_mode_can_only_be_set_for_type_only_imports: diag(1454, ts.DiagnosticCategory.Error, "resolution_mode_can_only_be_set_for_type_only_imports_1454", "`resolution-mode` can only be set for type-only imports."), resolution_mode_is_the_only_valid_key_for_type_import_assertions: diag(1455, ts.DiagnosticCategory.Error, "resolution_mode_is_the_only_valid_key_for_type_import_assertions_1455", "`resolution-mode` is the only valid key for type import assertions."), @@ -8893,6 +8893,7 @@ var ts; Import_assertions_are_not_allowed_on_statements_that_transpile_to_commonjs_require_calls: diag(2836, ts.DiagnosticCategory.Error, "Import_assertions_are_not_allowed_on_statements_that_transpile_to_commonjs_require_calls_2836", "Import assertions are not allowed on statements that transpile to commonjs 'require' calls."), Import_assertion_values_must_be_string_literal_expressions: diag(2837, ts.DiagnosticCategory.Error, "Import_assertion_values_must_be_string_literal_expressions_2837", "Import assertion values must be string literal expressions."), All_declarations_of_0_must_have_identical_constraints: diag(2838, ts.DiagnosticCategory.Error, "All_declarations_of_0_must_have_identical_constraints_2838", "All declarations of '{0}' must have identical constraints."), + The_type_of_this_expression_cannot_be_named_without_a_resolution_mode_assertion_which_is_an_unstable_feature_Use_nightly_TypeScript_to_silence_this_error_Try_updating_with_npm_install_D_typescript_next: diag(2841, ts.DiagnosticCategory.Error, "The_type_of_this_expression_cannot_be_named_without_a_resolution_mode_assertion_which_is_an_unstable_2841", "The type of this expression cannot be named without a 'resolution-mode' assertion, which is an unstable feature. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'."), Import_declaration_0_is_using_private_name_1: diag(4000, ts.DiagnosticCategory.Error, "Import_declaration_0_is_using_private_name_1_4000", "Import declaration '{0}' is using private name '{1}'."), Type_parameter_0_of_exported_class_has_or_is_using_private_name_1: diag(4002, ts.DiagnosticCategory.Error, "Type_parameter_0_of_exported_class_has_or_is_using_private_name_1_4002", "Type parameter '{0}' of exported class has or is using private name '{1}'."), Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1: diag(4004, ts.DiagnosticCategory.Error, "Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1_4004", "Type parameter '{0}' of exported interface has or is using private name '{1}'."), @@ -9000,7 +9001,7 @@ var ts; This_member_cannot_have_a_JSDoc_comment_with_an_override_tag_because_it_is_not_declared_in_the_base_class_0: diag(4122, ts.DiagnosticCategory.Error, "This_member_cannot_have_a_JSDoc_comment_with_an_override_tag_because_it_is_not_declared_in_the_base__4122", "This member cannot have a JSDoc comment with an '@override' tag because it is not declared in the base class '{0}'."), This_member_cannot_have_a_JSDoc_comment_with_an_override_tag_because_it_is_not_declared_in_the_base_class_0_Did_you_mean_1: diag(4123, ts.DiagnosticCategory.Error, "This_member_cannot_have_a_JSDoc_comment_with_an_override_tag_because_it_is_not_declared_in_the_base__4123", "This member cannot have a JSDoc comment with an 'override' tag because it is not declared in the base class '{0}'. Did you mean '{1}'?"), Compiler_option_0_of_value_1_is_unstable_Use_nightly_TypeScript_to_silence_this_error_Try_updating_with_npm_install_D_typescript_next: diag(4124, ts.DiagnosticCategory.Error, "Compiler_option_0_of_value_1_is_unstable_Use_nightly_TypeScript_to_silence_this_error_Try_updating_w_4124", "Compiler option '{0}' of value '{1}' is unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'."), - Resolution_mode_assertions_are_unstable_Use_nightly_TypeScript_to_silence_this_error_Try_updating_with_npm_install_D_typescript_next: diag(4125, ts.DiagnosticCategory.Error, "Resolution_mode_assertions_are_unstable_Use_nightly_TypeScript_to_silence_this_error_Try_updating_wi_4125", "Resolution mode assertions are unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'."), + resolution_mode_assertions_are_unstable_Use_nightly_TypeScript_to_silence_this_error_Try_updating_with_npm_install_D_typescript_next: diag(4125, ts.DiagnosticCategory.Error, "resolution_mode_assertions_are_unstable_Use_nightly_TypeScript_to_silence_this_error_Try_updating_wi_4125", "'resolution-mode' assertions are unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'."), The_current_host_does_not_support_the_0_option: diag(5001, ts.DiagnosticCategory.Error, "The_current_host_does_not_support_the_0_option_5001", "The current host does not support the '{0}' option."), Cannot_find_the_common_subdirectory_path_for_the_input_files: diag(5009, ts.DiagnosticCategory.Error, "Cannot_find_the_common_subdirectory_path_for_the_input_files_5009", "Cannot find the common subdirectory path for the input files."), File_specification_cannot_end_in_a_recursive_directory_wildcard_Asterisk_Asterisk_Colon_0: diag(5010, ts.DiagnosticCategory.Error, "File_specification_cannot_end_in_a_recursive_directory_wildcard_Asterisk_Asterisk_Colon_0_5010", "File specification cannot end in a recursive directory wildcard ('**'): '{0}'."), @@ -16018,6 +16019,8 @@ var ts; case 218 /* SyntaxKind.AwaitExpression */: case 231 /* SyntaxKind.MetaProperty */: return true; + case 228 /* SyntaxKind.ExpressionWithTypeArguments */: + return !ts.isHeritageClause(node.parent); case 161 /* SyntaxKind.QualifiedName */: while (node.parent.kind === 161 /* SyntaxKind.QualifiedName */) { node = node.parent; @@ -16189,9 +16192,6 @@ var ts; } ts.isVariableDeclarationInitializedToBareOrAccessedRequire = isVariableDeclarationInitializedToBareOrAccessedRequire; function isVariableDeclarationInitializedWithRequireHelper(node, allowAccessedRequire) { - if (node.kind === 203 /* SyntaxKind.BindingElement */) { - node = node.parent.parent; - } return ts.isVariableDeclaration(node) && !!node.initializer && isRequireCall(allowAccessedRequire ? getLeftmostAccessExpression(node.initializer) : node.initializer, /*requireStringLiteralLikeArgument*/ true); @@ -20013,8 +20013,9 @@ var ts; */ function isFileForcedToBeModuleByFormat(file) { // Excludes declaration files - they still require an explicit `export {}` or the like - // for back compat purposes. - return file.impliedNodeFormat === ts.ModuleKind.ESNext && !file.isDeclarationFile ? true : undefined; + // for back compat purposes. The only non-declaration files _not_ forced to be a module are `.js` files + // that aren't esm-mode (meaning not in a `type: module` scope). + return (file.impliedNodeFormat === ts.ModuleKind.ESNext || (ts.fileExtensionIsOneOf(file.fileName, [".cjs" /* Extension.Cjs */, ".cts" /* Extension.Cts */]))) && !file.isDeclarationFile ? true : undefined; } function getSetExternalModuleIndicator(options) { // TODO: Should this callback be cached? @@ -20022,7 +20023,7 @@ var ts; case ts.ModuleDetectionKind.Force: // All non-declaration files are modules, declaration files still do the usual isFileProbablyExternalModule return function (file) { - file.externalModuleIndicator = !file.isDeclarationFile || ts.isFileProbablyExternalModule(file); + file.externalModuleIndicator = ts.isFileProbablyExternalModule(file) || !file.isDeclarationFile || undefined; }; case ts.ModuleDetectionKind.Legacy: // Files are modules if they have imports, exports, or import.meta @@ -20082,7 +20083,8 @@ var ts; } ts.getEmitModuleResolutionKind = getEmitModuleResolutionKind; function getEmitModuleDetectionKind(options) { - return options.moduleDetection || ts.ModuleDetectionKind.Auto; + return options.moduleDetection || + (getEmitModuleKind(options) === ts.ModuleKind.Node16 || getEmitModuleKind(options) === ts.ModuleKind.NodeNext ? ts.ModuleDetectionKind.Force : ts.ModuleDetectionKind.Auto); } ts.getEmitModuleDetectionKind = getEmitModuleDetectionKind; function hasJsonModuleEmitEnabled(options) { @@ -29062,6 +29064,10 @@ var ts; return node.kind === 267 /* SyntaxKind.ImportClause */; } ts.isImportClause = isImportClause; + function isImportTypeAssertionContainer(node) { + return node.kind === 295 /* SyntaxKind.ImportTypeAssertionContainer */; + } + ts.isImportTypeAssertionContainer = isImportTypeAssertionContainer; function isAssertClause(node) { return node.kind === 293 /* SyntaxKind.AssertClause */; } @@ -42006,7 +42012,7 @@ var ts; } if (ts.isImplicitGlob(spec.substring(spec.lastIndexOf(ts.directorySeparator) + 1))) { return { - key: useCaseSensitiveFileNames ? spec : ts.toFileNameLowerCase(spec), + key: ts.removeTrailingDirectorySeparator(useCaseSensitiveFileNames ? spec : ts.toFileNameLowerCase(spec)), flags: 1 /* WatchDirectoryFlags.Recursive */ }; } @@ -43111,16 +43117,20 @@ var ts; function nodeNextModuleNameResolver(moduleName, containingFile, compilerOptions, host, cache, redirectedReference, resolutionMode) { return nodeNextModuleNameResolverWorker(NodeResolutionFeatures.NodeNextDefault, moduleName, containingFile, compilerOptions, host, cache, redirectedReference, resolutionMode); } + var jsOnlyExtensions = [Extensions.JavaScript]; + var tsExtensions = [Extensions.TypeScript, Extensions.JavaScript]; + var tsPlusJsonExtensions = __spreadArray(__spreadArray([], tsExtensions, true), [Extensions.Json], false); + var tsconfigExtensions = [Extensions.TSConfig]; function nodeNextModuleNameResolverWorker(features, moduleName, containingFile, compilerOptions, host, cache, redirectedReference, resolutionMode) { var containingDirectory = ts.getDirectoryPath(containingFile); // es module file or cjs-like input file, use a variant of the legacy cjs resolver that supports the selected modern features var esmMode = resolutionMode === ts.ModuleKind.ESNext ? NodeResolutionFeatures.EsmMode : 0; - return nodeModuleNameResolverWorker(features | esmMode, moduleName, containingDirectory, compilerOptions, host, cache, compilerOptions.resolveJsonModule ? tsPlusJsonExtensions : tsExtensions, redirectedReference); + var extensions = compilerOptions.noDtsResolution ? [Extensions.TsOnly, Extensions.JavaScript] : tsExtensions; + if (compilerOptions.resolveJsonModule) { + extensions = __spreadArray(__spreadArray([], extensions, true), [Extensions.Json], false); + } + return nodeModuleNameResolverWorker(features | esmMode, moduleName, containingDirectory, compilerOptions, host, cache, extensions, redirectedReference); } - var jsOnlyExtensions = [Extensions.JavaScript]; - var tsExtensions = [Extensions.TypeScript, Extensions.JavaScript]; - var tsPlusJsonExtensions = __spreadArray(__spreadArray([], tsExtensions, true), [Extensions.Json], false); - var tsconfigExtensions = [Extensions.TSConfig]; function tryResolveJSModuleWorker(moduleName, initialDir, host) { return nodeModuleNameResolverWorker(NodeResolutionFeatures.None, moduleName, initialDir, { moduleResolution: ts.ModuleResolutionKind.NodeJs, allowJs: true }, host, /*cache*/ undefined, jsOnlyExtensions, /*redirectedReferences*/ undefined); } @@ -43803,13 +43813,36 @@ var ts; } return toSearchResult(/*value*/ undefined); } + /** + * From https://github.com/nodejs/node/blob/8f39f51cbbd3b2de14b9ee896e26421cc5b20121/lib/internal/modules/esm/resolve.js#L722 - + * "longest" has some nuance as to what "longest" means in the presence of pattern trailers + */ + function comparePatternKeys(a, b) { + var aPatternIndex = a.indexOf("*"); + var bPatternIndex = b.indexOf("*"); + var baseLenA = aPatternIndex === -1 ? a.length : aPatternIndex + 1; + var baseLenB = bPatternIndex === -1 ? b.length : bPatternIndex + 1; + if (baseLenA > baseLenB) + return -1; + if (baseLenB > baseLenA) + return 1; + if (aPatternIndex === -1) + return 1; + if (bPatternIndex === -1) + return -1; + if (a.length > b.length) + return -1; + if (b.length > a.length) + return 1; + return 0; + } function loadModuleFromImportsOrExports(extensions, state, cache, redirectedReference, moduleName, lookupTable, scope, isImports) { var loadModuleFromTargetImportOrExport = getLoadModuleFromTargetImportOrExport(extensions, state, cache, redirectedReference, moduleName, scope, isImports); if (!ts.endsWith(moduleName, ts.directorySeparator) && moduleName.indexOf("*") === -1 && ts.hasProperty(lookupTable, moduleName)) { var target = lookupTable[moduleName]; return loadModuleFromTargetImportOrExport(target, /*subpath*/ "", /*pattern*/ false); } - var expandingKeys = ts.sort(ts.filter(ts.getOwnKeys(lookupTable), function (k) { return k.indexOf("*") !== -1 || ts.endsWith(k, "/"); }), function (a, b) { return a.length - b.length; }); + var expandingKeys = ts.sort(ts.filter(ts.getOwnKeys(lookupTable), function (k) { return k.indexOf("*") !== -1 || ts.endsWith(k, "/"); }), comparePatternKeys); for (var _i = 0, expandingKeys_1 = expandingKeys; _i < expandingKeys_1.length; _i++) { var potentialTarget = expandingKeys_1[_i]; if (state.features & NodeResolutionFeatures.ExportsPatternTrailers && matchesPatternWithTrailer(potentialTarget, moduleName)) { @@ -44128,8 +44161,8 @@ var ts; var pathAndExtension = loadModuleFromFile(extensions, candidate, onlyRecordFailures, state) || loadNodeModuleFromDirectoryWorker(extensions, candidate, onlyRecordFailures, state, packageInfo && packageInfo.packageJsonContent, packageInfo && packageInfo.versionPaths); if (!pathAndExtension && packageInfo - && packageInfo.packageJsonContent.exports === undefined - && packageInfo.packageJsonContent.main === undefined + // eslint-disable-next-line no-null/no-null + && (packageInfo.packageJsonContent.exports === undefined || packageInfo.packageJsonContent.exports === null) && state.features & NodeResolutionFeatures.EsmMode) { // EsmMode disables index lookup in `loadNodeModuleFromDirectoryWorker` generally, however non-relative package resolutions still assume // a default `index.js` entrypoint if no `main` or `exports` are present @@ -46905,12 +46938,14 @@ var ts; } } function setCommonJsModuleIndicator(node) { - if (file.externalModuleIndicator) { + if (file.externalModuleIndicator && file.externalModuleIndicator !== true) { return false; } if (!file.commonJsModuleIndicator) { file.commonJsModuleIndicator = node; - bindSourceFileAsExternalModule(); + if (!file.externalModuleIndicator) { + bindSourceFileAsExternalModule(); + } } return true; } @@ -47324,7 +47359,11 @@ var ts; checkStrictModeEvalOrArguments(node, node.name); } if (!ts.isBindingPattern(node.name)) { - if (ts.isInJSFile(node) && ts.isVariableDeclarationInitializedToBareOrAccessedRequire(node) && !ts.getJSDocTypeTag(node) && !(ts.getCombinedModifierFlags(node) & 1 /* ModifierFlags.Export */)) { + var possibleVariableDecl = node.kind === 254 /* SyntaxKind.VariableDeclaration */ ? node : node.parent.parent; + if (ts.isInJSFile(node) && + ts.isVariableDeclarationInitializedToBareOrAccessedRequire(possibleVariableDecl) && + !ts.getJSDocTypeTag(node) && + !(ts.getCombinedModifierFlags(node) & 1 /* ModifierFlags.Export */)) { declareSymbolAndAddToSymbolTable(node, 2097152 /* SymbolFlags.Alias */, 2097152 /* SymbolFlags.AliasExcludes */); } else if (ts.isBlockOrCatchScoped(node)) { @@ -50151,7 +50190,8 @@ var ts; && isAliasableOrJsExpression(node.parent.right) || node.kind === 297 /* SyntaxKind.ShorthandPropertyAssignment */ || node.kind === 296 /* SyntaxKind.PropertyAssignment */ && isAliasableOrJsExpression(node.initializer) - || ts.isVariableDeclarationInitializedToBareOrAccessedRequire(node); + || node.kind === 254 /* SyntaxKind.VariableDeclaration */ && ts.isVariableDeclarationInitializedToBareOrAccessedRequire(node) + || node.kind === 203 /* SyntaxKind.BindingElement */ && ts.isVariableDeclarationInitializedToBareOrAccessedRequire(node.parent.parent); } function isAliasableOrJsExpression(e) { return ts.isAliasableExpression(e) || ts.isFunctionExpression(e) && isJSConstructor(e); @@ -50244,7 +50284,7 @@ var ts; return hasExportAssignmentSymbol(moduleSymbol); } // JS files have a synthetic default if they do not contain ES2015+ module syntax (export = is not valid in js) _and_ do not have an __esModule marker - return !file.externalModuleIndicator && !resolveExportByName(moduleSymbol, ts.escapeLeadingUnderscores("__esModule"), /*sourceNode*/ undefined, dontResolveAlias); + return typeof file.externalModuleIndicator !== "object" && !resolveExportByName(moduleSymbol, ts.escapeLeadingUnderscores("__esModule"), /*sourceNode*/ undefined, dontResolveAlias); } function getTargetOfImportClause(node, dontResolveAlias) { var _a; @@ -53359,6 +53399,7 @@ var ts; return symbol.parent ? ts.factory.createQualifiedName(symbolToEntityNameNode(symbol.parent), identifier) : identifier; } function symbolToTypeNode(symbol, context, meaning, overrideTypeArguments) { + var _a, _b, _c, _d; var chain = lookupSymbolChain(symbol, context, meaning, !(context.flags & 16384 /* NodeBuilderFlags.UseAliasDefinedOutsideCurrentScope */)); // If we're using aliases outside the current scope, dont bother with the module var isTypeOf = meaning === 111551 /* SymbolFlags.Value */; if (ts.some(chain[0].declarations, hasNonGlobalAugmentationExternalModuleSymbol)) { @@ -53376,6 +53417,7 @@ var ts; assertion = ts.factory.createImportTypeAssertionContainer(ts.factory.createAssertClause(ts.factory.createNodeArray([ ts.factory.createAssertEntry(ts.factory.createStringLiteral("resolution-mode"), ts.factory.createStringLiteral("import")) ]))); + (_b = (_a = context.tracker).reportImportTypeNodeResolutionModeOverride) === null || _b === void 0 ? void 0 : _b.call(_a); } } if (!specifier) { @@ -53395,6 +53437,7 @@ var ts; assertion = ts.factory.createImportTypeAssertionContainer(ts.factory.createAssertClause(ts.factory.createNodeArray([ ts.factory.createAssertEntry(ts.factory.createStringLiteral("resolution-mode"), ts.factory.createStringLiteral(swappedMode === ts.ModuleKind.ESNext ? "import" : "require")) ]))); + (_d = (_c = context.tracker).reportImportTypeNodeResolutionModeOverride) === null || _d === void 0 ? void 0 : _d.call(_c); } } if (!assertion) { @@ -58883,7 +58926,7 @@ var ts; var objectType; return !!(type.flags & 8388608 /* TypeFlags.IndexedAccess */ && ts.getObjectFlags(objectType = type.objectType) & 32 /* ObjectFlags.Mapped */ && !isGenericMappedType(objectType) && isGenericIndexType(type.indexType) && - !objectType.declaration.questionToken && !objectType.declaration.nameType); + !(getMappedTypeModifiers(objectType) & 8 /* MappedTypeModifiers.ExcludeOptional */) && !objectType.declaration.nameType); } /** * For a type parameter, return the base constraint of the type parameter. For the string, number, @@ -80634,8 +80677,11 @@ var ts; if (node.assertions) { var override = ts.getResolutionModeOverrideForClause(node.assertions.assertClause, grammarErrorOnNode); if (override) { + if (!ts.isNightly()) { + grammarErrorOnNode(node.assertions.assertClause, ts.Diagnostics.resolution_mode_assertions_are_unstable_Use_nightly_TypeScript_to_silence_this_error_Try_updating_with_npm_install_D_typescript_next); + } if (ts.getEmitModuleResolutionKind(compilerOptions) !== ts.ModuleResolutionKind.Node16 && ts.getEmitModuleResolutionKind(compilerOptions) !== ts.ModuleResolutionKind.NodeNext) { - grammarErrorOnNode(node.assertions.assertClause, ts.Diagnostics.Resolution_modes_are_only_supported_when_moduleResolution_is_node16_or_nodenext); + grammarErrorOnNode(node.assertions.assertClause, ts.Diagnostics.resolution_mode_assertions_are_only_supported_when_moduleResolution_is_node16_or_nodenext); } } } @@ -82338,7 +82384,7 @@ var ts; } // For a commonjs `const x = require`, validate the alias and exit var symbol = getSymbolOfNode(node); - if (symbol.flags & 2097152 /* SymbolFlags.Alias */ && ts.isVariableDeclarationInitializedToBareOrAccessedRequire(node)) { + if (symbol.flags & 2097152 /* SymbolFlags.Alias */ && ts.isVariableDeclarationInitializedToBareOrAccessedRequire(node.kind === 203 /* SyntaxKind.BindingElement */ ? node.parent.parent : node)) { checkAliasSymbol(node); return; } @@ -85006,10 +85052,10 @@ var ts; var override = ts.getResolutionModeOverrideForClause(declaration.assertClause, validForTypeAssertions ? grammarErrorOnNode : undefined); if (validForTypeAssertions && override) { if (!ts.isNightly()) { - grammarErrorOnNode(declaration.assertClause, ts.Diagnostics.Resolution_mode_assertions_are_unstable_Use_nightly_TypeScript_to_silence_this_error_Try_updating_with_npm_install_D_typescript_next); + grammarErrorOnNode(declaration.assertClause, ts.Diagnostics.resolution_mode_assertions_are_unstable_Use_nightly_TypeScript_to_silence_this_error_Try_updating_with_npm_install_D_typescript_next); } if (ts.getEmitModuleResolutionKind(compilerOptions) !== ts.ModuleResolutionKind.Node16 && ts.getEmitModuleResolutionKind(compilerOptions) !== ts.ModuleResolutionKind.NodeNext) { - return grammarErrorOnNode(declaration.assertClause, ts.Diagnostics.Resolution_modes_are_only_supported_when_moduleResolution_is_node16_or_nodenext); + return grammarErrorOnNode(declaration.assertClause, ts.Diagnostics.resolution_mode_assertions_are_only_supported_when_moduleResolution_is_node16_or_nodenext); } return; // Other grammar checks do not apply to type-only imports with resolution mode assertions } @@ -107861,7 +107907,8 @@ var ts; trackReferencedAmbientModule: trackReferencedAmbientModule, trackExternalModuleSymbolOfImportTypeNode: trackExternalModuleSymbolOfImportTypeNode, reportNonlocalAugmentation: reportNonlocalAugmentation, - reportNonSerializableProperty: reportNonSerializableProperty + reportNonSerializableProperty: reportNonSerializableProperty, + reportImportTypeNodeResolutionModeOverride: reportImportTypeNodeResolutionModeOverride, }; var errorNameNode; var errorFallbackNode; @@ -107988,6 +108035,11 @@ var ts; context.addDiagnostic(ts.createDiagnosticForNode((errorNameNode || errorFallbackNode), ts.Diagnostics.The_type_of_this_node_cannot_be_serialized_because_its_property_0_cannot_be_serialized, propertyName)); } } + function reportImportTypeNodeResolutionModeOverride() { + if (!ts.isNightly() && (errorNameNode || errorFallbackNode)) { + context.addDiagnostic(ts.createDiagnosticForNode((errorNameNode || errorFallbackNode), ts.Diagnostics.The_type_of_this_expression_cannot_be_named_without_a_resolution_mode_assertion_which_is_an_unstable_feature_Use_nightly_TypeScript_to_silence_this_error_Try_updating_with_npm_install_D_typescript_next)); + } + } function transformDeclarationsForJS(sourceFile, bundled) { var oldDiag = getSymbolAccessibilityDiagnostic; getSymbolAccessibilityDiagnostic = function (s) { return (s.errorNode && ts.canProduceDiagnostics(s.errorNode) ? ts.createGetSymbolAccessibilityDiagnosticForNode(s.errorNode)(s) : ({ @@ -108438,7 +108490,7 @@ var ts; var mode = ts.getResolutionModeOverrideForClause(assertClause); if (mode !== undefined) { if (!ts.isNightly()) { - context.addDiagnostic(ts.createDiagnosticForNode(assertClause, ts.Diagnostics.Resolution_mode_assertions_are_unstable_Use_nightly_TypeScript_to_silence_this_error_Try_updating_with_npm_install_D_typescript_next)); + context.addDiagnostic(ts.createDiagnosticForNode(assertClause, ts.Diagnostics.resolution_mode_assertions_are_unstable_Use_nightly_TypeScript_to_silence_this_error_Try_updating_with_npm_install_D_typescript_next)); } return assertClause; } @@ -115945,12 +115997,14 @@ var ts; } ts.loadWithTypeDirectiveCache = loadWithTypeDirectiveCache; ; - /* @internal */ + /** + * Calculates the resulting resolution mode for some reference in some file - this is generally the explicitly + * provided resolution mode in the reference, unless one is not present, in which case it is the mode of the containing file. + */ function getModeForFileReference(ref, containingFileMode) { return (ts.isString(ref) ? containingFileMode : ref.resolutionMode) || containingFileMode; } ts.getModeForFileReference = getModeForFileReference; - /* @internal */ function getModeForResolutionAtIndex(file, index) { if (file.impliedNodeFormat === undefined) return undefined; @@ -115971,7 +116025,15 @@ var ts; return false; } ts.isExclusivelyTypeOnlyImportOrExport = isExclusivelyTypeOnlyImportOrExport; - /* @internal */ + /** + * Calculates the final resolution mode for a given module reference node. This is generally the explicitly provided resolution mode, if + * one exists, or the mode of the containing source file. (Excepting import=require, which is always commonjs, and dynamic import, which is always esm). + * Notably, this function always returns `undefined` if the containing file has an `undefined` `impliedNodeFormat` - this field is only set when + * `moduleResolution` is `node16`+. + * @param file The file the import or import-like reference is contained within + * @param usage The module reference string + * @returns The final resolution mode of the import + */ function getModeForUsageLocation(file, usage) { var _a, _b; if (file.impliedNodeFormat === undefined) @@ -118205,7 +118267,7 @@ var ts; ts.setResolvedTypeReferenceDirective(file, fileName, resolvedTypeReferenceDirective); var mode = ref.resolutionMode || file.impliedNodeFormat; if (mode && ts.getEmitModuleResolutionKind(options) !== ts.ModuleResolutionKind.Node16 && ts.getEmitModuleResolutionKind(options) !== ts.ModuleResolutionKind.NodeNext) { - programDiagnostics.add(ts.createDiagnosticForRange(file, ref, ts.Diagnostics.Resolution_modes_are_only_supported_when_moduleResolution_is_node16_or_nodenext)); + programDiagnostics.add(ts.createDiagnosticForRange(file, ref, ts.Diagnostics.resolution_mode_assertions_are_only_supported_when_moduleResolution_is_node16_or_nodenext)); } processTypeReferenceDirective(fileName, mode, resolvedTypeReferenceDirective, { kind: ts.FileIncludeKind.TypeReferenceDirective, file: file.path, index: index, }); } @@ -123498,6 +123560,7 @@ var ts; } function reloadFileNamesFromConfigFile() { writeLog("Reloading new file names and options"); + reloadLevel = ts.ConfigFileProgramReloadLevel.None; rootFileNames = ts.getFileNamesFromConfigSpecs(compilerOptions.configFile.configFileSpecs, ts.getNormalizedAbsolutePath(ts.getDirectoryPath(configFileName), currentDirectory), compilerOptions, parseConfigFileHost, extraFileExtensions); if (ts.updateErrorForNoInputFiles(rootFileNames, ts.getNormalizedAbsolutePath(configFileName, currentDirectory), compilerOptions.configFile.configFileSpecs, configFileParsingDiagnostics, canConfigFileJsonReportNoInputFiles)) { hasChangedConfigFileParsingErrors = true; @@ -136072,7 +136135,7 @@ var ts; ts.Debug.assert(parent.name === node); return true; case 203 /* SyntaxKind.BindingElement */: - return ts.isInJSFile(node) && ts.isVariableDeclarationInitializedToBareOrAccessedRequire(parent); + return ts.isInJSFile(node) && ts.isVariableDeclarationInitializedToBareOrAccessedRequire(parent.parent.parent); default: return false; } @@ -137537,7 +137600,7 @@ var ts; // Use the parent symbol if the location is commonjs require syntax on javascript files only. if (ts.isInJSFile(referenceLocation) && referenceLocation.parent.kind === 203 /* SyntaxKind.BindingElement */ - && ts.isVariableDeclarationInitializedToBareOrAccessedRequire(referenceLocation.parent)) { + && ts.isVariableDeclarationInitializedToBareOrAccessedRequire(referenceLocation.parent.parent.parent)) { referenceSymbol = referenceLocation.parent.symbol; // The parent will not have a symbol if it's an ObjectBindingPattern (when destructuring is used). In // this case, just skip it, since the bound identifiers are not an alias of the import. diff --git a/lib/tsserverlibrary.d.ts b/lib/tsserverlibrary.d.ts index f7e45674ac056..ffa14ce6b4f79 100644 --- a/lib/tsserverlibrary.d.ts +++ b/lib/tsserverlibrary.d.ts @@ -4720,6 +4720,7 @@ declare namespace ts { function isImportEqualsDeclaration(node: Node): node is ImportEqualsDeclaration; function isImportDeclaration(node: Node): node is ImportDeclaration; function isImportClause(node: Node): node is ImportClause; + function isImportTypeAssertionContainer(node: Node): node is ImportTypeAssertionContainer; function isAssertClause(node: Node): node is AssertClause; function isAssertEntry(node: Node): node is AssertEntry; function isNamespaceImport(node: Node): node is NamespaceImport; @@ -5098,6 +5099,31 @@ declare namespace ts { export function formatDiagnostic(diagnostic: Diagnostic, host: FormatDiagnosticsHost): string; export function formatDiagnosticsWithColorAndContext(diagnostics: readonly Diagnostic[], host: FormatDiagnosticsHost): string; export function flattenDiagnosticMessageText(diag: string | DiagnosticMessageChain | undefined, newLine: string, indent?: number): string; + /** + * Calculates the resulting resolution mode for some reference in some file - this is generally the explicitly + * provided resolution mode in the reference, unless one is not present, in which case it is the mode of the containing file. + */ + export function getModeForFileReference(ref: FileReference | string, containingFileMode: SourceFile["impliedNodeFormat"]): ModuleKind.CommonJS | ModuleKind.ESNext | undefined; + /** + * Calculates the final resolution mode for an import at some index within a file's imports list. This is generally the explicitly + * defined mode of the import if provided, or, if not, the mode of the containing file (with some exceptions: import=require is always commonjs, dynamic import is always esm). + * If you have an actual import node, prefer using getModeForUsageLocation on the reference string node. + * @param file File to fetch the resolution mode within + * @param index Index into the file's complete resolution list to get the resolution of - this is a concatenation of the file's imports and module augmentations + */ + export function getModeForResolutionAtIndex(file: SourceFile, index: number): ModuleKind.CommonJS | ModuleKind.ESNext | undefined; + /** + * Calculates the final resolution mode for a given module reference node. This is generally the explicitly provided resolution mode, if + * one exists, or the mode of the containing source file. (Excepting import=require, which is always commonjs, and dynamic import, which is always esm). + * Notably, this function always returns `undefined` if the containing file has an `undefined` `impliedNodeFormat` - this field is only set when + * `moduleResolution` is `node16`+. + * @param file The file the import or import-like reference is contained within + * @param usage The module reference string + * @returns The final resolution mode of the import + */ + export function getModeForUsageLocation(file: { + impliedNodeFormat?: SourceFile["impliedNodeFormat"]; + }, usage: StringLiteralLike): ModuleKind.CommonJS | ModuleKind.ESNext | undefined; export 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 diff --git a/lib/tsserverlibrary.js b/lib/tsserverlibrary.js index 54c7b5294982c..a32ed4a819d26 100644 --- a/lib/tsserverlibrary.js +++ b/lib/tsserverlibrary.js @@ -294,7 +294,7 @@ var ts; // The following is baselined as a literal template type without intervention /** The version of the TypeScript compiler release */ // eslint-disable-next-line @typescript-eslint/no-inferrable-types - ts.version = "4.7.2"; + ts.version = "4.7.3"; /* @internal */ var Comparison; (function (Comparison) { @@ -8583,7 +8583,7 @@ var ts; Preserve_unused_imported_values_in_the_JavaScript_output_that_would_otherwise_be_removed: diag(1449, ts.DiagnosticCategory.Message, "Preserve_unused_imported_values_in_the_JavaScript_output_that_would_otherwise_be_removed_1449", "Preserve unused imported values in the JavaScript output that would otherwise be removed."), Dynamic_imports_can_only_accept_a_module_specifier_and_an_optional_assertion_as_arguments: diag(1450, ts.DiagnosticCategory.Message, "Dynamic_imports_can_only_accept_a_module_specifier_and_an_optional_assertion_as_arguments_1450", "Dynamic imports can only accept a module specifier and an optional assertion as arguments"), Private_identifiers_are_only_allowed_in_class_bodies_and_may_only_be_used_as_part_of_a_class_member_declaration_property_access_or_on_the_left_hand_side_of_an_in_expression: diag(1451, ts.DiagnosticCategory.Error, "Private_identifiers_are_only_allowed_in_class_bodies_and_may_only_be_used_as_part_of_a_class_member__1451", "Private identifiers are only allowed in class bodies and may only be used as part of a class member declaration, property access, or on the left-hand-side of an 'in' expression"), - Resolution_modes_are_only_supported_when_moduleResolution_is_node16_or_nodenext: diag(1452, ts.DiagnosticCategory.Error, "Resolution_modes_are_only_supported_when_moduleResolution_is_node16_or_nodenext_1452", "Resolution modes are only supported when `moduleResolution` is `node16` or `nodenext`."), + resolution_mode_assertions_are_only_supported_when_moduleResolution_is_node16_or_nodenext: diag(1452, ts.DiagnosticCategory.Error, "resolution_mode_assertions_are_only_supported_when_moduleResolution_is_node16_or_nodenext_1452", "'resolution-mode' assertions are only supported when `moduleResolution` is `node16` or `nodenext`."), resolution_mode_should_be_either_require_or_import: diag(1453, ts.DiagnosticCategory.Error, "resolution_mode_should_be_either_require_or_import_1453", "`resolution-mode` should be either `require` or `import`."), resolution_mode_can_only_be_set_for_type_only_imports: diag(1454, ts.DiagnosticCategory.Error, "resolution_mode_can_only_be_set_for_type_only_imports_1454", "`resolution-mode` can only be set for type-only imports."), resolution_mode_is_the_only_valid_key_for_type_import_assertions: diag(1455, ts.DiagnosticCategory.Error, "resolution_mode_is_the_only_valid_key_for_type_import_assertions_1455", "`resolution-mode` is the only valid key for type import assertions."), @@ -9087,6 +9087,7 @@ var ts; Import_assertions_are_not_allowed_on_statements_that_transpile_to_commonjs_require_calls: diag(2836, ts.DiagnosticCategory.Error, "Import_assertions_are_not_allowed_on_statements_that_transpile_to_commonjs_require_calls_2836", "Import assertions are not allowed on statements that transpile to commonjs 'require' calls."), Import_assertion_values_must_be_string_literal_expressions: diag(2837, ts.DiagnosticCategory.Error, "Import_assertion_values_must_be_string_literal_expressions_2837", "Import assertion values must be string literal expressions."), All_declarations_of_0_must_have_identical_constraints: diag(2838, ts.DiagnosticCategory.Error, "All_declarations_of_0_must_have_identical_constraints_2838", "All declarations of '{0}' must have identical constraints."), + The_type_of_this_expression_cannot_be_named_without_a_resolution_mode_assertion_which_is_an_unstable_feature_Use_nightly_TypeScript_to_silence_this_error_Try_updating_with_npm_install_D_typescript_next: diag(2841, ts.DiagnosticCategory.Error, "The_type_of_this_expression_cannot_be_named_without_a_resolution_mode_assertion_which_is_an_unstable_2841", "The type of this expression cannot be named without a 'resolution-mode' assertion, which is an unstable feature. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'."), Import_declaration_0_is_using_private_name_1: diag(4000, ts.DiagnosticCategory.Error, "Import_declaration_0_is_using_private_name_1_4000", "Import declaration '{0}' is using private name '{1}'."), Type_parameter_0_of_exported_class_has_or_is_using_private_name_1: diag(4002, ts.DiagnosticCategory.Error, "Type_parameter_0_of_exported_class_has_or_is_using_private_name_1_4002", "Type parameter '{0}' of exported class has or is using private name '{1}'."), Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1: diag(4004, ts.DiagnosticCategory.Error, "Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1_4004", "Type parameter '{0}' of exported interface has or is using private name '{1}'."), @@ -9194,7 +9195,7 @@ var ts; This_member_cannot_have_a_JSDoc_comment_with_an_override_tag_because_it_is_not_declared_in_the_base_class_0: diag(4122, ts.DiagnosticCategory.Error, "This_member_cannot_have_a_JSDoc_comment_with_an_override_tag_because_it_is_not_declared_in_the_base__4122", "This member cannot have a JSDoc comment with an '@override' tag because it is not declared in the base class '{0}'."), This_member_cannot_have_a_JSDoc_comment_with_an_override_tag_because_it_is_not_declared_in_the_base_class_0_Did_you_mean_1: diag(4123, ts.DiagnosticCategory.Error, "This_member_cannot_have_a_JSDoc_comment_with_an_override_tag_because_it_is_not_declared_in_the_base__4123", "This member cannot have a JSDoc comment with an 'override' tag because it is not declared in the base class '{0}'. Did you mean '{1}'?"), Compiler_option_0_of_value_1_is_unstable_Use_nightly_TypeScript_to_silence_this_error_Try_updating_with_npm_install_D_typescript_next: diag(4124, ts.DiagnosticCategory.Error, "Compiler_option_0_of_value_1_is_unstable_Use_nightly_TypeScript_to_silence_this_error_Try_updating_w_4124", "Compiler option '{0}' of value '{1}' is unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'."), - Resolution_mode_assertions_are_unstable_Use_nightly_TypeScript_to_silence_this_error_Try_updating_with_npm_install_D_typescript_next: diag(4125, ts.DiagnosticCategory.Error, "Resolution_mode_assertions_are_unstable_Use_nightly_TypeScript_to_silence_this_error_Try_updating_wi_4125", "Resolution mode assertions are unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'."), + resolution_mode_assertions_are_unstable_Use_nightly_TypeScript_to_silence_this_error_Try_updating_with_npm_install_D_typescript_next: diag(4125, ts.DiagnosticCategory.Error, "resolution_mode_assertions_are_unstable_Use_nightly_TypeScript_to_silence_this_error_Try_updating_wi_4125", "'resolution-mode' assertions are unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'."), The_current_host_does_not_support_the_0_option: diag(5001, ts.DiagnosticCategory.Error, "The_current_host_does_not_support_the_0_option_5001", "The current host does not support the '{0}' option."), Cannot_find_the_common_subdirectory_path_for_the_input_files: diag(5009, ts.DiagnosticCategory.Error, "Cannot_find_the_common_subdirectory_path_for_the_input_files_5009", "Cannot find the common subdirectory path for the input files."), File_specification_cannot_end_in_a_recursive_directory_wildcard_Asterisk_Asterisk_Colon_0: diag(5010, ts.DiagnosticCategory.Error, "File_specification_cannot_end_in_a_recursive_directory_wildcard_Asterisk_Asterisk_Colon_0_5010", "File specification cannot end in a recursive directory wildcard ('**'): '{0}'."), @@ -16212,6 +16213,8 @@ var ts; case 218 /* SyntaxKind.AwaitExpression */: case 231 /* SyntaxKind.MetaProperty */: return true; + case 228 /* SyntaxKind.ExpressionWithTypeArguments */: + return !ts.isHeritageClause(node.parent); case 161 /* SyntaxKind.QualifiedName */: while (node.parent.kind === 161 /* SyntaxKind.QualifiedName */) { node = node.parent; @@ -16383,9 +16386,6 @@ var ts; } ts.isVariableDeclarationInitializedToBareOrAccessedRequire = isVariableDeclarationInitializedToBareOrAccessedRequire; function isVariableDeclarationInitializedWithRequireHelper(node, allowAccessedRequire) { - if (node.kind === 203 /* SyntaxKind.BindingElement */) { - node = node.parent.parent; - } return ts.isVariableDeclaration(node) && !!node.initializer && isRequireCall(allowAccessedRequire ? getLeftmostAccessExpression(node.initializer) : node.initializer, /*requireStringLiteralLikeArgument*/ true); @@ -20207,8 +20207,9 @@ var ts; */ function isFileForcedToBeModuleByFormat(file) { // Excludes declaration files - they still require an explicit `export {}` or the like - // for back compat purposes. - return file.impliedNodeFormat === ts.ModuleKind.ESNext && !file.isDeclarationFile ? true : undefined; + // for back compat purposes. The only non-declaration files _not_ forced to be a module are `.js` files + // that aren't esm-mode (meaning not in a `type: module` scope). + return (file.impliedNodeFormat === ts.ModuleKind.ESNext || (ts.fileExtensionIsOneOf(file.fileName, [".cjs" /* Extension.Cjs */, ".cts" /* Extension.Cts */]))) && !file.isDeclarationFile ? true : undefined; } function getSetExternalModuleIndicator(options) { // TODO: Should this callback be cached? @@ -20216,7 +20217,7 @@ var ts; case ts.ModuleDetectionKind.Force: // All non-declaration files are modules, declaration files still do the usual isFileProbablyExternalModule return function (file) { - file.externalModuleIndicator = !file.isDeclarationFile || ts.isFileProbablyExternalModule(file); + file.externalModuleIndicator = ts.isFileProbablyExternalModule(file) || !file.isDeclarationFile || undefined; }; case ts.ModuleDetectionKind.Legacy: // Files are modules if they have imports, exports, or import.meta @@ -20276,7 +20277,8 @@ var ts; } ts.getEmitModuleResolutionKind = getEmitModuleResolutionKind; function getEmitModuleDetectionKind(options) { - return options.moduleDetection || ts.ModuleDetectionKind.Auto; + return options.moduleDetection || + (getEmitModuleKind(options) === ts.ModuleKind.Node16 || getEmitModuleKind(options) === ts.ModuleKind.NodeNext ? ts.ModuleDetectionKind.Force : ts.ModuleDetectionKind.Auto); } ts.getEmitModuleDetectionKind = getEmitModuleDetectionKind; function hasJsonModuleEmitEnabled(options) { @@ -29256,6 +29258,10 @@ var ts; return node.kind === 267 /* SyntaxKind.ImportClause */; } ts.isImportClause = isImportClause; + function isImportTypeAssertionContainer(node) { + return node.kind === 295 /* SyntaxKind.ImportTypeAssertionContainer */; + } + ts.isImportTypeAssertionContainer = isImportTypeAssertionContainer; function isAssertClause(node) { return node.kind === 293 /* SyntaxKind.AssertClause */; } @@ -42200,7 +42206,7 @@ var ts; } if (ts.isImplicitGlob(spec.substring(spec.lastIndexOf(ts.directorySeparator) + 1))) { return { - key: useCaseSensitiveFileNames ? spec : ts.toFileNameLowerCase(spec), + key: ts.removeTrailingDirectorySeparator(useCaseSensitiveFileNames ? spec : ts.toFileNameLowerCase(spec)), flags: 1 /* WatchDirectoryFlags.Recursive */ }; } @@ -43305,16 +43311,20 @@ var ts; function nodeNextModuleNameResolver(moduleName, containingFile, compilerOptions, host, cache, redirectedReference, resolutionMode) { return nodeNextModuleNameResolverWorker(NodeResolutionFeatures.NodeNextDefault, moduleName, containingFile, compilerOptions, host, cache, redirectedReference, resolutionMode); } + var jsOnlyExtensions = [Extensions.JavaScript]; + var tsExtensions = [Extensions.TypeScript, Extensions.JavaScript]; + var tsPlusJsonExtensions = __spreadArray(__spreadArray([], tsExtensions, true), [Extensions.Json], false); + var tsconfigExtensions = [Extensions.TSConfig]; function nodeNextModuleNameResolverWorker(features, moduleName, containingFile, compilerOptions, host, cache, redirectedReference, resolutionMode) { var containingDirectory = ts.getDirectoryPath(containingFile); // es module file or cjs-like input file, use a variant of the legacy cjs resolver that supports the selected modern features var esmMode = resolutionMode === ts.ModuleKind.ESNext ? NodeResolutionFeatures.EsmMode : 0; - return nodeModuleNameResolverWorker(features | esmMode, moduleName, containingDirectory, compilerOptions, host, cache, compilerOptions.resolveJsonModule ? tsPlusJsonExtensions : tsExtensions, redirectedReference); + var extensions = compilerOptions.noDtsResolution ? [Extensions.TsOnly, Extensions.JavaScript] : tsExtensions; + if (compilerOptions.resolveJsonModule) { + extensions = __spreadArray(__spreadArray([], extensions, true), [Extensions.Json], false); + } + return nodeModuleNameResolverWorker(features | esmMode, moduleName, containingDirectory, compilerOptions, host, cache, extensions, redirectedReference); } - var jsOnlyExtensions = [Extensions.JavaScript]; - var tsExtensions = [Extensions.TypeScript, Extensions.JavaScript]; - var tsPlusJsonExtensions = __spreadArray(__spreadArray([], tsExtensions, true), [Extensions.Json], false); - var tsconfigExtensions = [Extensions.TSConfig]; function tryResolveJSModuleWorker(moduleName, initialDir, host) { return nodeModuleNameResolverWorker(NodeResolutionFeatures.None, moduleName, initialDir, { moduleResolution: ts.ModuleResolutionKind.NodeJs, allowJs: true }, host, /*cache*/ undefined, jsOnlyExtensions, /*redirectedReferences*/ undefined); } @@ -43997,13 +44007,36 @@ var ts; } return toSearchResult(/*value*/ undefined); } + /** + * From https://github.com/nodejs/node/blob/8f39f51cbbd3b2de14b9ee896e26421cc5b20121/lib/internal/modules/esm/resolve.js#L722 - + * "longest" has some nuance as to what "longest" means in the presence of pattern trailers + */ + function comparePatternKeys(a, b) { + var aPatternIndex = a.indexOf("*"); + var bPatternIndex = b.indexOf("*"); + var baseLenA = aPatternIndex === -1 ? a.length : aPatternIndex + 1; + var baseLenB = bPatternIndex === -1 ? b.length : bPatternIndex + 1; + if (baseLenA > baseLenB) + return -1; + if (baseLenB > baseLenA) + return 1; + if (aPatternIndex === -1) + return 1; + if (bPatternIndex === -1) + return -1; + if (a.length > b.length) + return -1; + if (b.length > a.length) + return 1; + return 0; + } function loadModuleFromImportsOrExports(extensions, state, cache, redirectedReference, moduleName, lookupTable, scope, isImports) { var loadModuleFromTargetImportOrExport = getLoadModuleFromTargetImportOrExport(extensions, state, cache, redirectedReference, moduleName, scope, isImports); if (!ts.endsWith(moduleName, ts.directorySeparator) && moduleName.indexOf("*") === -1 && ts.hasProperty(lookupTable, moduleName)) { var target = lookupTable[moduleName]; return loadModuleFromTargetImportOrExport(target, /*subpath*/ "", /*pattern*/ false); } - var expandingKeys = ts.sort(ts.filter(ts.getOwnKeys(lookupTable), function (k) { return k.indexOf("*") !== -1 || ts.endsWith(k, "/"); }), function (a, b) { return a.length - b.length; }); + var expandingKeys = ts.sort(ts.filter(ts.getOwnKeys(lookupTable), function (k) { return k.indexOf("*") !== -1 || ts.endsWith(k, "/"); }), comparePatternKeys); for (var _i = 0, expandingKeys_1 = expandingKeys; _i < expandingKeys_1.length; _i++) { var potentialTarget = expandingKeys_1[_i]; if (state.features & NodeResolutionFeatures.ExportsPatternTrailers && matchesPatternWithTrailer(potentialTarget, moduleName)) { @@ -44322,8 +44355,8 @@ var ts; var pathAndExtension = loadModuleFromFile(extensions, candidate, onlyRecordFailures, state) || loadNodeModuleFromDirectoryWorker(extensions, candidate, onlyRecordFailures, state, packageInfo && packageInfo.packageJsonContent, packageInfo && packageInfo.versionPaths); if (!pathAndExtension && packageInfo - && packageInfo.packageJsonContent.exports === undefined - && packageInfo.packageJsonContent.main === undefined + // eslint-disable-next-line no-null/no-null + && (packageInfo.packageJsonContent.exports === undefined || packageInfo.packageJsonContent.exports === null) && state.features & NodeResolutionFeatures.EsmMode) { // EsmMode disables index lookup in `loadNodeModuleFromDirectoryWorker` generally, however non-relative package resolutions still assume // a default `index.js` entrypoint if no `main` or `exports` are present @@ -47099,12 +47132,14 @@ var ts; } } function setCommonJsModuleIndicator(node) { - if (file.externalModuleIndicator) { + if (file.externalModuleIndicator && file.externalModuleIndicator !== true) { return false; } if (!file.commonJsModuleIndicator) { file.commonJsModuleIndicator = node; - bindSourceFileAsExternalModule(); + if (!file.externalModuleIndicator) { + bindSourceFileAsExternalModule(); + } } return true; } @@ -47518,7 +47553,11 @@ var ts; checkStrictModeEvalOrArguments(node, node.name); } if (!ts.isBindingPattern(node.name)) { - if (ts.isInJSFile(node) && ts.isVariableDeclarationInitializedToBareOrAccessedRequire(node) && !ts.getJSDocTypeTag(node) && !(ts.getCombinedModifierFlags(node) & 1 /* ModifierFlags.Export */)) { + var possibleVariableDecl = node.kind === 254 /* SyntaxKind.VariableDeclaration */ ? node : node.parent.parent; + if (ts.isInJSFile(node) && + ts.isVariableDeclarationInitializedToBareOrAccessedRequire(possibleVariableDecl) && + !ts.getJSDocTypeTag(node) && + !(ts.getCombinedModifierFlags(node) & 1 /* ModifierFlags.Export */)) { declareSymbolAndAddToSymbolTable(node, 2097152 /* SymbolFlags.Alias */, 2097152 /* SymbolFlags.AliasExcludes */); } else if (ts.isBlockOrCatchScoped(node)) { @@ -50345,7 +50384,8 @@ var ts; && isAliasableOrJsExpression(node.parent.right) || node.kind === 297 /* SyntaxKind.ShorthandPropertyAssignment */ || node.kind === 296 /* SyntaxKind.PropertyAssignment */ && isAliasableOrJsExpression(node.initializer) - || ts.isVariableDeclarationInitializedToBareOrAccessedRequire(node); + || node.kind === 254 /* SyntaxKind.VariableDeclaration */ && ts.isVariableDeclarationInitializedToBareOrAccessedRequire(node) + || node.kind === 203 /* SyntaxKind.BindingElement */ && ts.isVariableDeclarationInitializedToBareOrAccessedRequire(node.parent.parent); } function isAliasableOrJsExpression(e) { return ts.isAliasableExpression(e) || ts.isFunctionExpression(e) && isJSConstructor(e); @@ -50438,7 +50478,7 @@ var ts; return hasExportAssignmentSymbol(moduleSymbol); } // JS files have a synthetic default if they do not contain ES2015+ module syntax (export = is not valid in js) _and_ do not have an __esModule marker - return !file.externalModuleIndicator && !resolveExportByName(moduleSymbol, ts.escapeLeadingUnderscores("__esModule"), /*sourceNode*/ undefined, dontResolveAlias); + return typeof file.externalModuleIndicator !== "object" && !resolveExportByName(moduleSymbol, ts.escapeLeadingUnderscores("__esModule"), /*sourceNode*/ undefined, dontResolveAlias); } function getTargetOfImportClause(node, dontResolveAlias) { var _a; @@ -53553,6 +53593,7 @@ var ts; return symbol.parent ? ts.factory.createQualifiedName(symbolToEntityNameNode(symbol.parent), identifier) : identifier; } function symbolToTypeNode(symbol, context, meaning, overrideTypeArguments) { + var _a, _b, _c, _d; var chain = lookupSymbolChain(symbol, context, meaning, !(context.flags & 16384 /* NodeBuilderFlags.UseAliasDefinedOutsideCurrentScope */)); // If we're using aliases outside the current scope, dont bother with the module var isTypeOf = meaning === 111551 /* SymbolFlags.Value */; if (ts.some(chain[0].declarations, hasNonGlobalAugmentationExternalModuleSymbol)) { @@ -53570,6 +53611,7 @@ var ts; assertion = ts.factory.createImportTypeAssertionContainer(ts.factory.createAssertClause(ts.factory.createNodeArray([ ts.factory.createAssertEntry(ts.factory.createStringLiteral("resolution-mode"), ts.factory.createStringLiteral("import")) ]))); + (_b = (_a = context.tracker).reportImportTypeNodeResolutionModeOverride) === null || _b === void 0 ? void 0 : _b.call(_a); } } if (!specifier) { @@ -53589,6 +53631,7 @@ var ts; assertion = ts.factory.createImportTypeAssertionContainer(ts.factory.createAssertClause(ts.factory.createNodeArray([ ts.factory.createAssertEntry(ts.factory.createStringLiteral("resolution-mode"), ts.factory.createStringLiteral(swappedMode === ts.ModuleKind.ESNext ? "import" : "require")) ]))); + (_d = (_c = context.tracker).reportImportTypeNodeResolutionModeOverride) === null || _d === void 0 ? void 0 : _d.call(_c); } } if (!assertion) { @@ -59077,7 +59120,7 @@ var ts; var objectType; return !!(type.flags & 8388608 /* TypeFlags.IndexedAccess */ && ts.getObjectFlags(objectType = type.objectType) & 32 /* ObjectFlags.Mapped */ && !isGenericMappedType(objectType) && isGenericIndexType(type.indexType) && - !objectType.declaration.questionToken && !objectType.declaration.nameType); + !(getMappedTypeModifiers(objectType) & 8 /* MappedTypeModifiers.ExcludeOptional */) && !objectType.declaration.nameType); } /** * For a type parameter, return the base constraint of the type parameter. For the string, number, @@ -80828,8 +80871,11 @@ var ts; if (node.assertions) { var override = ts.getResolutionModeOverrideForClause(node.assertions.assertClause, grammarErrorOnNode); if (override) { + if (!ts.isNightly()) { + grammarErrorOnNode(node.assertions.assertClause, ts.Diagnostics.resolution_mode_assertions_are_unstable_Use_nightly_TypeScript_to_silence_this_error_Try_updating_with_npm_install_D_typescript_next); + } if (ts.getEmitModuleResolutionKind(compilerOptions) !== ts.ModuleResolutionKind.Node16 && ts.getEmitModuleResolutionKind(compilerOptions) !== ts.ModuleResolutionKind.NodeNext) { - grammarErrorOnNode(node.assertions.assertClause, ts.Diagnostics.Resolution_modes_are_only_supported_when_moduleResolution_is_node16_or_nodenext); + grammarErrorOnNode(node.assertions.assertClause, ts.Diagnostics.resolution_mode_assertions_are_only_supported_when_moduleResolution_is_node16_or_nodenext); } } } @@ -82532,7 +82578,7 @@ var ts; } // For a commonjs `const x = require`, validate the alias and exit var symbol = getSymbolOfNode(node); - if (symbol.flags & 2097152 /* SymbolFlags.Alias */ && ts.isVariableDeclarationInitializedToBareOrAccessedRequire(node)) { + if (symbol.flags & 2097152 /* SymbolFlags.Alias */ && ts.isVariableDeclarationInitializedToBareOrAccessedRequire(node.kind === 203 /* SyntaxKind.BindingElement */ ? node.parent.parent : node)) { checkAliasSymbol(node); return; } @@ -85200,10 +85246,10 @@ var ts; var override = ts.getResolutionModeOverrideForClause(declaration.assertClause, validForTypeAssertions ? grammarErrorOnNode : undefined); if (validForTypeAssertions && override) { if (!ts.isNightly()) { - grammarErrorOnNode(declaration.assertClause, ts.Diagnostics.Resolution_mode_assertions_are_unstable_Use_nightly_TypeScript_to_silence_this_error_Try_updating_with_npm_install_D_typescript_next); + grammarErrorOnNode(declaration.assertClause, ts.Diagnostics.resolution_mode_assertions_are_unstable_Use_nightly_TypeScript_to_silence_this_error_Try_updating_with_npm_install_D_typescript_next); } if (ts.getEmitModuleResolutionKind(compilerOptions) !== ts.ModuleResolutionKind.Node16 && ts.getEmitModuleResolutionKind(compilerOptions) !== ts.ModuleResolutionKind.NodeNext) { - return grammarErrorOnNode(declaration.assertClause, ts.Diagnostics.Resolution_modes_are_only_supported_when_moduleResolution_is_node16_or_nodenext); + return grammarErrorOnNode(declaration.assertClause, ts.Diagnostics.resolution_mode_assertions_are_only_supported_when_moduleResolution_is_node16_or_nodenext); } return; // Other grammar checks do not apply to type-only imports with resolution mode assertions } @@ -108055,7 +108101,8 @@ var ts; trackReferencedAmbientModule: trackReferencedAmbientModule, trackExternalModuleSymbolOfImportTypeNode: trackExternalModuleSymbolOfImportTypeNode, reportNonlocalAugmentation: reportNonlocalAugmentation, - reportNonSerializableProperty: reportNonSerializableProperty + reportNonSerializableProperty: reportNonSerializableProperty, + reportImportTypeNodeResolutionModeOverride: reportImportTypeNodeResolutionModeOverride, }; var errorNameNode; var errorFallbackNode; @@ -108182,6 +108229,11 @@ var ts; context.addDiagnostic(ts.createDiagnosticForNode((errorNameNode || errorFallbackNode), ts.Diagnostics.The_type_of_this_node_cannot_be_serialized_because_its_property_0_cannot_be_serialized, propertyName)); } } + function reportImportTypeNodeResolutionModeOverride() { + if (!ts.isNightly() && (errorNameNode || errorFallbackNode)) { + context.addDiagnostic(ts.createDiagnosticForNode((errorNameNode || errorFallbackNode), ts.Diagnostics.The_type_of_this_expression_cannot_be_named_without_a_resolution_mode_assertion_which_is_an_unstable_feature_Use_nightly_TypeScript_to_silence_this_error_Try_updating_with_npm_install_D_typescript_next)); + } + } function transformDeclarationsForJS(sourceFile, bundled) { var oldDiag = getSymbolAccessibilityDiagnostic; getSymbolAccessibilityDiagnostic = function (s) { return (s.errorNode && ts.canProduceDiagnostics(s.errorNode) ? ts.createGetSymbolAccessibilityDiagnosticForNode(s.errorNode)(s) : ({ @@ -108632,7 +108684,7 @@ var ts; var mode = ts.getResolutionModeOverrideForClause(assertClause); if (mode !== undefined) { if (!ts.isNightly()) { - context.addDiagnostic(ts.createDiagnosticForNode(assertClause, ts.Diagnostics.Resolution_mode_assertions_are_unstable_Use_nightly_TypeScript_to_silence_this_error_Try_updating_with_npm_install_D_typescript_next)); + context.addDiagnostic(ts.createDiagnosticForNode(assertClause, ts.Diagnostics.resolution_mode_assertions_are_unstable_Use_nightly_TypeScript_to_silence_this_error_Try_updating_with_npm_install_D_typescript_next)); } return assertClause; } @@ -116139,12 +116191,14 @@ var ts; } ts.loadWithTypeDirectiveCache = loadWithTypeDirectiveCache; ; - /* @internal */ + /** + * Calculates the resulting resolution mode for some reference in some file - this is generally the explicitly + * provided resolution mode in the reference, unless one is not present, in which case it is the mode of the containing file. + */ function getModeForFileReference(ref, containingFileMode) { return (ts.isString(ref) ? containingFileMode : ref.resolutionMode) || containingFileMode; } ts.getModeForFileReference = getModeForFileReference; - /* @internal */ function getModeForResolutionAtIndex(file, index) { if (file.impliedNodeFormat === undefined) return undefined; @@ -116165,7 +116219,15 @@ var ts; return false; } ts.isExclusivelyTypeOnlyImportOrExport = isExclusivelyTypeOnlyImportOrExport; - /* @internal */ + /** + * Calculates the final resolution mode for a given module reference node. This is generally the explicitly provided resolution mode, if + * one exists, or the mode of the containing source file. (Excepting import=require, which is always commonjs, and dynamic import, which is always esm). + * Notably, this function always returns `undefined` if the containing file has an `undefined` `impliedNodeFormat` - this field is only set when + * `moduleResolution` is `node16`+. + * @param file The file the import or import-like reference is contained within + * @param usage The module reference string + * @returns The final resolution mode of the import + */ function getModeForUsageLocation(file, usage) { var _a, _b; if (file.impliedNodeFormat === undefined) @@ -118399,7 +118461,7 @@ var ts; ts.setResolvedTypeReferenceDirective(file, fileName, resolvedTypeReferenceDirective); var mode = ref.resolutionMode || file.impliedNodeFormat; if (mode && ts.getEmitModuleResolutionKind(options) !== ts.ModuleResolutionKind.Node16 && ts.getEmitModuleResolutionKind(options) !== ts.ModuleResolutionKind.NodeNext) { - programDiagnostics.add(ts.createDiagnosticForRange(file, ref, ts.Diagnostics.Resolution_modes_are_only_supported_when_moduleResolution_is_node16_or_nodenext)); + programDiagnostics.add(ts.createDiagnosticForRange(file, ref, ts.Diagnostics.resolution_mode_assertions_are_only_supported_when_moduleResolution_is_node16_or_nodenext)); } processTypeReferenceDirective(fileName, mode, resolvedTypeReferenceDirective, { kind: ts.FileIncludeKind.TypeReferenceDirective, file: file.path, index: index, }); } @@ -123692,6 +123754,7 @@ var ts; } function reloadFileNamesFromConfigFile() { writeLog("Reloading new file names and options"); + reloadLevel = ts.ConfigFileProgramReloadLevel.None; rootFileNames = ts.getFileNamesFromConfigSpecs(compilerOptions.configFile.configFileSpecs, ts.getNormalizedAbsolutePath(ts.getDirectoryPath(configFileName), currentDirectory), compilerOptions, parseConfigFileHost, extraFileExtensions); if (ts.updateErrorForNoInputFiles(rootFileNames, ts.getNormalizedAbsolutePath(configFileName, currentDirectory), compilerOptions.configFile.configFileSpecs, configFileParsingDiagnostics, canConfigFileJsonReportNoInputFiles)) { hasChangedConfigFileParsingErrors = true; @@ -136683,7 +136746,7 @@ var ts; ts.Debug.assert(parent.name === node); return true; case 203 /* SyntaxKind.BindingElement */: - return ts.isInJSFile(node) && ts.isVariableDeclarationInitializedToBareOrAccessedRequire(parent); + return ts.isInJSFile(node) && ts.isVariableDeclarationInitializedToBareOrAccessedRequire(parent.parent.parent); default: return false; } @@ -138148,7 +138211,7 @@ var ts; // Use the parent symbol if the location is commonjs require syntax on javascript files only. if (ts.isInJSFile(referenceLocation) && referenceLocation.parent.kind === 203 /* SyntaxKind.BindingElement */ - && ts.isVariableDeclarationInitializedToBareOrAccessedRequire(referenceLocation.parent)) { + && ts.isVariableDeclarationInitializedToBareOrAccessedRequire(referenceLocation.parent.parent.parent)) { referenceSymbol = referenceLocation.parent.symbol; // The parent will not have a symbol if it's an ObjectBindingPattern (when destructuring is used). In // this case, just skip it, since the bound identifiers are not an alias of the import. diff --git a/lib/typescript.d.ts b/lib/typescript.d.ts index fb0a5a0c1e756..66dc7a05a49f3 100644 --- a/lib/typescript.d.ts +++ b/lib/typescript.d.ts @@ -4720,6 +4720,7 @@ declare namespace ts { function isImportEqualsDeclaration(node: Node): node is ImportEqualsDeclaration; function isImportDeclaration(node: Node): node is ImportDeclaration; function isImportClause(node: Node): node is ImportClause; + function isImportTypeAssertionContainer(node: Node): node is ImportTypeAssertionContainer; function isAssertClause(node: Node): node is AssertClause; function isAssertEntry(node: Node): node is AssertEntry; function isNamespaceImport(node: Node): node is NamespaceImport; @@ -5098,6 +5099,31 @@ declare namespace ts { export function formatDiagnostic(diagnostic: Diagnostic, host: FormatDiagnosticsHost): string; export function formatDiagnosticsWithColorAndContext(diagnostics: readonly Diagnostic[], host: FormatDiagnosticsHost): string; export function flattenDiagnosticMessageText(diag: string | DiagnosticMessageChain | undefined, newLine: string, indent?: number): string; + /** + * Calculates the resulting resolution mode for some reference in some file - this is generally the explicitly + * provided resolution mode in the reference, unless one is not present, in which case it is the mode of the containing file. + */ + export function getModeForFileReference(ref: FileReference | string, containingFileMode: SourceFile["impliedNodeFormat"]): ModuleKind.CommonJS | ModuleKind.ESNext | undefined; + /** + * Calculates the final resolution mode for an import at some index within a file's imports list. This is generally the explicitly + * defined mode of the import if provided, or, if not, the mode of the containing file (with some exceptions: import=require is always commonjs, dynamic import is always esm). + * If you have an actual import node, prefer using getModeForUsageLocation on the reference string node. + * @param file File to fetch the resolution mode within + * @param index Index into the file's complete resolution list to get the resolution of - this is a concatenation of the file's imports and module augmentations + */ + export function getModeForResolutionAtIndex(file: SourceFile, index: number): ModuleKind.CommonJS | ModuleKind.ESNext | undefined; + /** + * Calculates the final resolution mode for a given module reference node. This is generally the explicitly provided resolution mode, if + * one exists, or the mode of the containing source file. (Excepting import=require, which is always commonjs, and dynamic import, which is always esm). + * Notably, this function always returns `undefined` if the containing file has an `undefined` `impliedNodeFormat` - this field is only set when + * `moduleResolution` is `node16`+. + * @param file The file the import or import-like reference is contained within + * @param usage The module reference string + * @returns The final resolution mode of the import + */ + export function getModeForUsageLocation(file: { + impliedNodeFormat?: SourceFile["impliedNodeFormat"]; + }, usage: StringLiteralLike): ModuleKind.CommonJS | ModuleKind.ESNext | undefined; export 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 diff --git a/lib/typescript.js b/lib/typescript.js index 8f41c15ff8d89..67c644c042c7d 100644 --- a/lib/typescript.js +++ b/lib/typescript.js @@ -294,7 +294,7 @@ var ts; // The following is baselined as a literal template type without intervention /** The version of the TypeScript compiler release */ // eslint-disable-next-line @typescript-eslint/no-inferrable-types - ts.version = "4.7.2"; + ts.version = "4.7.3"; /* @internal */ var Comparison; (function (Comparison) { @@ -8583,7 +8583,7 @@ var ts; Preserve_unused_imported_values_in_the_JavaScript_output_that_would_otherwise_be_removed: diag(1449, ts.DiagnosticCategory.Message, "Preserve_unused_imported_values_in_the_JavaScript_output_that_would_otherwise_be_removed_1449", "Preserve unused imported values in the JavaScript output that would otherwise be removed."), Dynamic_imports_can_only_accept_a_module_specifier_and_an_optional_assertion_as_arguments: diag(1450, ts.DiagnosticCategory.Message, "Dynamic_imports_can_only_accept_a_module_specifier_and_an_optional_assertion_as_arguments_1450", "Dynamic imports can only accept a module specifier and an optional assertion as arguments"), Private_identifiers_are_only_allowed_in_class_bodies_and_may_only_be_used_as_part_of_a_class_member_declaration_property_access_or_on_the_left_hand_side_of_an_in_expression: diag(1451, ts.DiagnosticCategory.Error, "Private_identifiers_are_only_allowed_in_class_bodies_and_may_only_be_used_as_part_of_a_class_member__1451", "Private identifiers are only allowed in class bodies and may only be used as part of a class member declaration, property access, or on the left-hand-side of an 'in' expression"), - Resolution_modes_are_only_supported_when_moduleResolution_is_node16_or_nodenext: diag(1452, ts.DiagnosticCategory.Error, "Resolution_modes_are_only_supported_when_moduleResolution_is_node16_or_nodenext_1452", "Resolution modes are only supported when `moduleResolution` is `node16` or `nodenext`."), + resolution_mode_assertions_are_only_supported_when_moduleResolution_is_node16_or_nodenext: diag(1452, ts.DiagnosticCategory.Error, "resolution_mode_assertions_are_only_supported_when_moduleResolution_is_node16_or_nodenext_1452", "'resolution-mode' assertions are only supported when `moduleResolution` is `node16` or `nodenext`."), resolution_mode_should_be_either_require_or_import: diag(1453, ts.DiagnosticCategory.Error, "resolution_mode_should_be_either_require_or_import_1453", "`resolution-mode` should be either `require` or `import`."), resolution_mode_can_only_be_set_for_type_only_imports: diag(1454, ts.DiagnosticCategory.Error, "resolution_mode_can_only_be_set_for_type_only_imports_1454", "`resolution-mode` can only be set for type-only imports."), resolution_mode_is_the_only_valid_key_for_type_import_assertions: diag(1455, ts.DiagnosticCategory.Error, "resolution_mode_is_the_only_valid_key_for_type_import_assertions_1455", "`resolution-mode` is the only valid key for type import assertions."), @@ -9087,6 +9087,7 @@ var ts; Import_assertions_are_not_allowed_on_statements_that_transpile_to_commonjs_require_calls: diag(2836, ts.DiagnosticCategory.Error, "Import_assertions_are_not_allowed_on_statements_that_transpile_to_commonjs_require_calls_2836", "Import assertions are not allowed on statements that transpile to commonjs 'require' calls."), Import_assertion_values_must_be_string_literal_expressions: diag(2837, ts.DiagnosticCategory.Error, "Import_assertion_values_must_be_string_literal_expressions_2837", "Import assertion values must be string literal expressions."), All_declarations_of_0_must_have_identical_constraints: diag(2838, ts.DiagnosticCategory.Error, "All_declarations_of_0_must_have_identical_constraints_2838", "All declarations of '{0}' must have identical constraints."), + The_type_of_this_expression_cannot_be_named_without_a_resolution_mode_assertion_which_is_an_unstable_feature_Use_nightly_TypeScript_to_silence_this_error_Try_updating_with_npm_install_D_typescript_next: diag(2841, ts.DiagnosticCategory.Error, "The_type_of_this_expression_cannot_be_named_without_a_resolution_mode_assertion_which_is_an_unstable_2841", "The type of this expression cannot be named without a 'resolution-mode' assertion, which is an unstable feature. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'."), Import_declaration_0_is_using_private_name_1: diag(4000, ts.DiagnosticCategory.Error, "Import_declaration_0_is_using_private_name_1_4000", "Import declaration '{0}' is using private name '{1}'."), Type_parameter_0_of_exported_class_has_or_is_using_private_name_1: diag(4002, ts.DiagnosticCategory.Error, "Type_parameter_0_of_exported_class_has_or_is_using_private_name_1_4002", "Type parameter '{0}' of exported class has or is using private name '{1}'."), Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1: diag(4004, ts.DiagnosticCategory.Error, "Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1_4004", "Type parameter '{0}' of exported interface has or is using private name '{1}'."), @@ -9194,7 +9195,7 @@ var ts; This_member_cannot_have_a_JSDoc_comment_with_an_override_tag_because_it_is_not_declared_in_the_base_class_0: diag(4122, ts.DiagnosticCategory.Error, "This_member_cannot_have_a_JSDoc_comment_with_an_override_tag_because_it_is_not_declared_in_the_base__4122", "This member cannot have a JSDoc comment with an '@override' tag because it is not declared in the base class '{0}'."), This_member_cannot_have_a_JSDoc_comment_with_an_override_tag_because_it_is_not_declared_in_the_base_class_0_Did_you_mean_1: diag(4123, ts.DiagnosticCategory.Error, "This_member_cannot_have_a_JSDoc_comment_with_an_override_tag_because_it_is_not_declared_in_the_base__4123", "This member cannot have a JSDoc comment with an 'override' tag because it is not declared in the base class '{0}'. Did you mean '{1}'?"), Compiler_option_0_of_value_1_is_unstable_Use_nightly_TypeScript_to_silence_this_error_Try_updating_with_npm_install_D_typescript_next: diag(4124, ts.DiagnosticCategory.Error, "Compiler_option_0_of_value_1_is_unstable_Use_nightly_TypeScript_to_silence_this_error_Try_updating_w_4124", "Compiler option '{0}' of value '{1}' is unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'."), - Resolution_mode_assertions_are_unstable_Use_nightly_TypeScript_to_silence_this_error_Try_updating_with_npm_install_D_typescript_next: diag(4125, ts.DiagnosticCategory.Error, "Resolution_mode_assertions_are_unstable_Use_nightly_TypeScript_to_silence_this_error_Try_updating_wi_4125", "Resolution mode assertions are unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'."), + resolution_mode_assertions_are_unstable_Use_nightly_TypeScript_to_silence_this_error_Try_updating_with_npm_install_D_typescript_next: diag(4125, ts.DiagnosticCategory.Error, "resolution_mode_assertions_are_unstable_Use_nightly_TypeScript_to_silence_this_error_Try_updating_wi_4125", "'resolution-mode' assertions are unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'."), The_current_host_does_not_support_the_0_option: diag(5001, ts.DiagnosticCategory.Error, "The_current_host_does_not_support_the_0_option_5001", "The current host does not support the '{0}' option."), Cannot_find_the_common_subdirectory_path_for_the_input_files: diag(5009, ts.DiagnosticCategory.Error, "Cannot_find_the_common_subdirectory_path_for_the_input_files_5009", "Cannot find the common subdirectory path for the input files."), File_specification_cannot_end_in_a_recursive_directory_wildcard_Asterisk_Asterisk_Colon_0: diag(5010, ts.DiagnosticCategory.Error, "File_specification_cannot_end_in_a_recursive_directory_wildcard_Asterisk_Asterisk_Colon_0_5010", "File specification cannot end in a recursive directory wildcard ('**'): '{0}'."), @@ -16212,6 +16213,8 @@ var ts; case 218 /* SyntaxKind.AwaitExpression */: case 231 /* SyntaxKind.MetaProperty */: return true; + case 228 /* SyntaxKind.ExpressionWithTypeArguments */: + return !ts.isHeritageClause(node.parent); case 161 /* SyntaxKind.QualifiedName */: while (node.parent.kind === 161 /* SyntaxKind.QualifiedName */) { node = node.parent; @@ -16383,9 +16386,6 @@ var ts; } ts.isVariableDeclarationInitializedToBareOrAccessedRequire = isVariableDeclarationInitializedToBareOrAccessedRequire; function isVariableDeclarationInitializedWithRequireHelper(node, allowAccessedRequire) { - if (node.kind === 203 /* SyntaxKind.BindingElement */) { - node = node.parent.parent; - } return ts.isVariableDeclaration(node) && !!node.initializer && isRequireCall(allowAccessedRequire ? getLeftmostAccessExpression(node.initializer) : node.initializer, /*requireStringLiteralLikeArgument*/ true); @@ -20207,8 +20207,9 @@ var ts; */ function isFileForcedToBeModuleByFormat(file) { // Excludes declaration files - they still require an explicit `export {}` or the like - // for back compat purposes. - return file.impliedNodeFormat === ts.ModuleKind.ESNext && !file.isDeclarationFile ? true : undefined; + // for back compat purposes. The only non-declaration files _not_ forced to be a module are `.js` files + // that aren't esm-mode (meaning not in a `type: module` scope). + return (file.impliedNodeFormat === ts.ModuleKind.ESNext || (ts.fileExtensionIsOneOf(file.fileName, [".cjs" /* Extension.Cjs */, ".cts" /* Extension.Cts */]))) && !file.isDeclarationFile ? true : undefined; } function getSetExternalModuleIndicator(options) { // TODO: Should this callback be cached? @@ -20216,7 +20217,7 @@ var ts; case ts.ModuleDetectionKind.Force: // All non-declaration files are modules, declaration files still do the usual isFileProbablyExternalModule return function (file) { - file.externalModuleIndicator = !file.isDeclarationFile || ts.isFileProbablyExternalModule(file); + file.externalModuleIndicator = ts.isFileProbablyExternalModule(file) || !file.isDeclarationFile || undefined; }; case ts.ModuleDetectionKind.Legacy: // Files are modules if they have imports, exports, or import.meta @@ -20276,7 +20277,8 @@ var ts; } ts.getEmitModuleResolutionKind = getEmitModuleResolutionKind; function getEmitModuleDetectionKind(options) { - return options.moduleDetection || ts.ModuleDetectionKind.Auto; + return options.moduleDetection || + (getEmitModuleKind(options) === ts.ModuleKind.Node16 || getEmitModuleKind(options) === ts.ModuleKind.NodeNext ? ts.ModuleDetectionKind.Force : ts.ModuleDetectionKind.Auto); } ts.getEmitModuleDetectionKind = getEmitModuleDetectionKind; function hasJsonModuleEmitEnabled(options) { @@ -29256,6 +29258,10 @@ var ts; return node.kind === 267 /* SyntaxKind.ImportClause */; } ts.isImportClause = isImportClause; + function isImportTypeAssertionContainer(node) { + return node.kind === 295 /* SyntaxKind.ImportTypeAssertionContainer */; + } + ts.isImportTypeAssertionContainer = isImportTypeAssertionContainer; function isAssertClause(node) { return node.kind === 293 /* SyntaxKind.AssertClause */; } @@ -42200,7 +42206,7 @@ var ts; } if (ts.isImplicitGlob(spec.substring(spec.lastIndexOf(ts.directorySeparator) + 1))) { return { - key: useCaseSensitiveFileNames ? spec : ts.toFileNameLowerCase(spec), + key: ts.removeTrailingDirectorySeparator(useCaseSensitiveFileNames ? spec : ts.toFileNameLowerCase(spec)), flags: 1 /* WatchDirectoryFlags.Recursive */ }; } @@ -43305,16 +43311,20 @@ var ts; function nodeNextModuleNameResolver(moduleName, containingFile, compilerOptions, host, cache, redirectedReference, resolutionMode) { return nodeNextModuleNameResolverWorker(NodeResolutionFeatures.NodeNextDefault, moduleName, containingFile, compilerOptions, host, cache, redirectedReference, resolutionMode); } + var jsOnlyExtensions = [Extensions.JavaScript]; + var tsExtensions = [Extensions.TypeScript, Extensions.JavaScript]; + var tsPlusJsonExtensions = __spreadArray(__spreadArray([], tsExtensions, true), [Extensions.Json], false); + var tsconfigExtensions = [Extensions.TSConfig]; function nodeNextModuleNameResolverWorker(features, moduleName, containingFile, compilerOptions, host, cache, redirectedReference, resolutionMode) { var containingDirectory = ts.getDirectoryPath(containingFile); // es module file or cjs-like input file, use a variant of the legacy cjs resolver that supports the selected modern features var esmMode = resolutionMode === ts.ModuleKind.ESNext ? NodeResolutionFeatures.EsmMode : 0; - return nodeModuleNameResolverWorker(features | esmMode, moduleName, containingDirectory, compilerOptions, host, cache, compilerOptions.resolveJsonModule ? tsPlusJsonExtensions : tsExtensions, redirectedReference); + var extensions = compilerOptions.noDtsResolution ? [Extensions.TsOnly, Extensions.JavaScript] : tsExtensions; + if (compilerOptions.resolveJsonModule) { + extensions = __spreadArray(__spreadArray([], extensions, true), [Extensions.Json], false); + } + return nodeModuleNameResolverWorker(features | esmMode, moduleName, containingDirectory, compilerOptions, host, cache, extensions, redirectedReference); } - var jsOnlyExtensions = [Extensions.JavaScript]; - var tsExtensions = [Extensions.TypeScript, Extensions.JavaScript]; - var tsPlusJsonExtensions = __spreadArray(__spreadArray([], tsExtensions, true), [Extensions.Json], false); - var tsconfigExtensions = [Extensions.TSConfig]; function tryResolveJSModuleWorker(moduleName, initialDir, host) { return nodeModuleNameResolverWorker(NodeResolutionFeatures.None, moduleName, initialDir, { moduleResolution: ts.ModuleResolutionKind.NodeJs, allowJs: true }, host, /*cache*/ undefined, jsOnlyExtensions, /*redirectedReferences*/ undefined); } @@ -43997,13 +44007,36 @@ var ts; } return toSearchResult(/*value*/ undefined); } + /** + * From https://github.com/nodejs/node/blob/8f39f51cbbd3b2de14b9ee896e26421cc5b20121/lib/internal/modules/esm/resolve.js#L722 - + * "longest" has some nuance as to what "longest" means in the presence of pattern trailers + */ + function comparePatternKeys(a, b) { + var aPatternIndex = a.indexOf("*"); + var bPatternIndex = b.indexOf("*"); + var baseLenA = aPatternIndex === -1 ? a.length : aPatternIndex + 1; + var baseLenB = bPatternIndex === -1 ? b.length : bPatternIndex + 1; + if (baseLenA > baseLenB) + return -1; + if (baseLenB > baseLenA) + return 1; + if (aPatternIndex === -1) + return 1; + if (bPatternIndex === -1) + return -1; + if (a.length > b.length) + return -1; + if (b.length > a.length) + return 1; + return 0; + } function loadModuleFromImportsOrExports(extensions, state, cache, redirectedReference, moduleName, lookupTable, scope, isImports) { var loadModuleFromTargetImportOrExport = getLoadModuleFromTargetImportOrExport(extensions, state, cache, redirectedReference, moduleName, scope, isImports); if (!ts.endsWith(moduleName, ts.directorySeparator) && moduleName.indexOf("*") === -1 && ts.hasProperty(lookupTable, moduleName)) { var target = lookupTable[moduleName]; return loadModuleFromTargetImportOrExport(target, /*subpath*/ "", /*pattern*/ false); } - var expandingKeys = ts.sort(ts.filter(ts.getOwnKeys(lookupTable), function (k) { return k.indexOf("*") !== -1 || ts.endsWith(k, "/"); }), function (a, b) { return a.length - b.length; }); + var expandingKeys = ts.sort(ts.filter(ts.getOwnKeys(lookupTable), function (k) { return k.indexOf("*") !== -1 || ts.endsWith(k, "/"); }), comparePatternKeys); for (var _i = 0, expandingKeys_1 = expandingKeys; _i < expandingKeys_1.length; _i++) { var potentialTarget = expandingKeys_1[_i]; if (state.features & NodeResolutionFeatures.ExportsPatternTrailers && matchesPatternWithTrailer(potentialTarget, moduleName)) { @@ -44322,8 +44355,8 @@ var ts; var pathAndExtension = loadModuleFromFile(extensions, candidate, onlyRecordFailures, state) || loadNodeModuleFromDirectoryWorker(extensions, candidate, onlyRecordFailures, state, packageInfo && packageInfo.packageJsonContent, packageInfo && packageInfo.versionPaths); if (!pathAndExtension && packageInfo - && packageInfo.packageJsonContent.exports === undefined - && packageInfo.packageJsonContent.main === undefined + // eslint-disable-next-line no-null/no-null + && (packageInfo.packageJsonContent.exports === undefined || packageInfo.packageJsonContent.exports === null) && state.features & NodeResolutionFeatures.EsmMode) { // EsmMode disables index lookup in `loadNodeModuleFromDirectoryWorker` generally, however non-relative package resolutions still assume // a default `index.js` entrypoint if no `main` or `exports` are present @@ -47099,12 +47132,14 @@ var ts; } } function setCommonJsModuleIndicator(node) { - if (file.externalModuleIndicator) { + if (file.externalModuleIndicator && file.externalModuleIndicator !== true) { return false; } if (!file.commonJsModuleIndicator) { file.commonJsModuleIndicator = node; - bindSourceFileAsExternalModule(); + if (!file.externalModuleIndicator) { + bindSourceFileAsExternalModule(); + } } return true; } @@ -47518,7 +47553,11 @@ var ts; checkStrictModeEvalOrArguments(node, node.name); } if (!ts.isBindingPattern(node.name)) { - if (ts.isInJSFile(node) && ts.isVariableDeclarationInitializedToBareOrAccessedRequire(node) && !ts.getJSDocTypeTag(node) && !(ts.getCombinedModifierFlags(node) & 1 /* ModifierFlags.Export */)) { + var possibleVariableDecl = node.kind === 254 /* SyntaxKind.VariableDeclaration */ ? node : node.parent.parent; + if (ts.isInJSFile(node) && + ts.isVariableDeclarationInitializedToBareOrAccessedRequire(possibleVariableDecl) && + !ts.getJSDocTypeTag(node) && + !(ts.getCombinedModifierFlags(node) & 1 /* ModifierFlags.Export */)) { declareSymbolAndAddToSymbolTable(node, 2097152 /* SymbolFlags.Alias */, 2097152 /* SymbolFlags.AliasExcludes */); } else if (ts.isBlockOrCatchScoped(node)) { @@ -50345,7 +50384,8 @@ var ts; && isAliasableOrJsExpression(node.parent.right) || node.kind === 297 /* SyntaxKind.ShorthandPropertyAssignment */ || node.kind === 296 /* SyntaxKind.PropertyAssignment */ && isAliasableOrJsExpression(node.initializer) - || ts.isVariableDeclarationInitializedToBareOrAccessedRequire(node); + || node.kind === 254 /* SyntaxKind.VariableDeclaration */ && ts.isVariableDeclarationInitializedToBareOrAccessedRequire(node) + || node.kind === 203 /* SyntaxKind.BindingElement */ && ts.isVariableDeclarationInitializedToBareOrAccessedRequire(node.parent.parent); } function isAliasableOrJsExpression(e) { return ts.isAliasableExpression(e) || ts.isFunctionExpression(e) && isJSConstructor(e); @@ -50438,7 +50478,7 @@ var ts; return hasExportAssignmentSymbol(moduleSymbol); } // JS files have a synthetic default if they do not contain ES2015+ module syntax (export = is not valid in js) _and_ do not have an __esModule marker - return !file.externalModuleIndicator && !resolveExportByName(moduleSymbol, ts.escapeLeadingUnderscores("__esModule"), /*sourceNode*/ undefined, dontResolveAlias); + return typeof file.externalModuleIndicator !== "object" && !resolveExportByName(moduleSymbol, ts.escapeLeadingUnderscores("__esModule"), /*sourceNode*/ undefined, dontResolveAlias); } function getTargetOfImportClause(node, dontResolveAlias) { var _a; @@ -53553,6 +53593,7 @@ var ts; return symbol.parent ? ts.factory.createQualifiedName(symbolToEntityNameNode(symbol.parent), identifier) : identifier; } function symbolToTypeNode(symbol, context, meaning, overrideTypeArguments) { + var _a, _b, _c, _d; var chain = lookupSymbolChain(symbol, context, meaning, !(context.flags & 16384 /* NodeBuilderFlags.UseAliasDefinedOutsideCurrentScope */)); // If we're using aliases outside the current scope, dont bother with the module var isTypeOf = meaning === 111551 /* SymbolFlags.Value */; if (ts.some(chain[0].declarations, hasNonGlobalAugmentationExternalModuleSymbol)) { @@ -53570,6 +53611,7 @@ var ts; assertion = ts.factory.createImportTypeAssertionContainer(ts.factory.createAssertClause(ts.factory.createNodeArray([ ts.factory.createAssertEntry(ts.factory.createStringLiteral("resolution-mode"), ts.factory.createStringLiteral("import")) ]))); + (_b = (_a = context.tracker).reportImportTypeNodeResolutionModeOverride) === null || _b === void 0 ? void 0 : _b.call(_a); } } if (!specifier) { @@ -53589,6 +53631,7 @@ var ts; assertion = ts.factory.createImportTypeAssertionContainer(ts.factory.createAssertClause(ts.factory.createNodeArray([ ts.factory.createAssertEntry(ts.factory.createStringLiteral("resolution-mode"), ts.factory.createStringLiteral(swappedMode === ts.ModuleKind.ESNext ? "import" : "require")) ]))); + (_d = (_c = context.tracker).reportImportTypeNodeResolutionModeOverride) === null || _d === void 0 ? void 0 : _d.call(_c); } } if (!assertion) { @@ -59077,7 +59120,7 @@ var ts; var objectType; return !!(type.flags & 8388608 /* TypeFlags.IndexedAccess */ && ts.getObjectFlags(objectType = type.objectType) & 32 /* ObjectFlags.Mapped */ && !isGenericMappedType(objectType) && isGenericIndexType(type.indexType) && - !objectType.declaration.questionToken && !objectType.declaration.nameType); + !(getMappedTypeModifiers(objectType) & 8 /* MappedTypeModifiers.ExcludeOptional */) && !objectType.declaration.nameType); } /** * For a type parameter, return the base constraint of the type parameter. For the string, number, @@ -80828,8 +80871,11 @@ var ts; if (node.assertions) { var override = ts.getResolutionModeOverrideForClause(node.assertions.assertClause, grammarErrorOnNode); if (override) { + if (!ts.isNightly()) { + grammarErrorOnNode(node.assertions.assertClause, ts.Diagnostics.resolution_mode_assertions_are_unstable_Use_nightly_TypeScript_to_silence_this_error_Try_updating_with_npm_install_D_typescript_next); + } if (ts.getEmitModuleResolutionKind(compilerOptions) !== ts.ModuleResolutionKind.Node16 && ts.getEmitModuleResolutionKind(compilerOptions) !== ts.ModuleResolutionKind.NodeNext) { - grammarErrorOnNode(node.assertions.assertClause, ts.Diagnostics.Resolution_modes_are_only_supported_when_moduleResolution_is_node16_or_nodenext); + grammarErrorOnNode(node.assertions.assertClause, ts.Diagnostics.resolution_mode_assertions_are_only_supported_when_moduleResolution_is_node16_or_nodenext); } } } @@ -82532,7 +82578,7 @@ var ts; } // For a commonjs `const x = require`, validate the alias and exit var symbol = getSymbolOfNode(node); - if (symbol.flags & 2097152 /* SymbolFlags.Alias */ && ts.isVariableDeclarationInitializedToBareOrAccessedRequire(node)) { + if (symbol.flags & 2097152 /* SymbolFlags.Alias */ && ts.isVariableDeclarationInitializedToBareOrAccessedRequire(node.kind === 203 /* SyntaxKind.BindingElement */ ? node.parent.parent : node)) { checkAliasSymbol(node); return; } @@ -85200,10 +85246,10 @@ var ts; var override = ts.getResolutionModeOverrideForClause(declaration.assertClause, validForTypeAssertions ? grammarErrorOnNode : undefined); if (validForTypeAssertions && override) { if (!ts.isNightly()) { - grammarErrorOnNode(declaration.assertClause, ts.Diagnostics.Resolution_mode_assertions_are_unstable_Use_nightly_TypeScript_to_silence_this_error_Try_updating_with_npm_install_D_typescript_next); + grammarErrorOnNode(declaration.assertClause, ts.Diagnostics.resolution_mode_assertions_are_unstable_Use_nightly_TypeScript_to_silence_this_error_Try_updating_with_npm_install_D_typescript_next); } if (ts.getEmitModuleResolutionKind(compilerOptions) !== ts.ModuleResolutionKind.Node16 && ts.getEmitModuleResolutionKind(compilerOptions) !== ts.ModuleResolutionKind.NodeNext) { - return grammarErrorOnNode(declaration.assertClause, ts.Diagnostics.Resolution_modes_are_only_supported_when_moduleResolution_is_node16_or_nodenext); + return grammarErrorOnNode(declaration.assertClause, ts.Diagnostics.resolution_mode_assertions_are_only_supported_when_moduleResolution_is_node16_or_nodenext); } return; // Other grammar checks do not apply to type-only imports with resolution mode assertions } @@ -108055,7 +108101,8 @@ var ts; trackReferencedAmbientModule: trackReferencedAmbientModule, trackExternalModuleSymbolOfImportTypeNode: trackExternalModuleSymbolOfImportTypeNode, reportNonlocalAugmentation: reportNonlocalAugmentation, - reportNonSerializableProperty: reportNonSerializableProperty + reportNonSerializableProperty: reportNonSerializableProperty, + reportImportTypeNodeResolutionModeOverride: reportImportTypeNodeResolutionModeOverride, }; var errorNameNode; var errorFallbackNode; @@ -108182,6 +108229,11 @@ var ts; context.addDiagnostic(ts.createDiagnosticForNode((errorNameNode || errorFallbackNode), ts.Diagnostics.The_type_of_this_node_cannot_be_serialized_because_its_property_0_cannot_be_serialized, propertyName)); } } + function reportImportTypeNodeResolutionModeOverride() { + if (!ts.isNightly() && (errorNameNode || errorFallbackNode)) { + context.addDiagnostic(ts.createDiagnosticForNode((errorNameNode || errorFallbackNode), ts.Diagnostics.The_type_of_this_expression_cannot_be_named_without_a_resolution_mode_assertion_which_is_an_unstable_feature_Use_nightly_TypeScript_to_silence_this_error_Try_updating_with_npm_install_D_typescript_next)); + } + } function transformDeclarationsForJS(sourceFile, bundled) { var oldDiag = getSymbolAccessibilityDiagnostic; getSymbolAccessibilityDiagnostic = function (s) { return (s.errorNode && ts.canProduceDiagnostics(s.errorNode) ? ts.createGetSymbolAccessibilityDiagnosticForNode(s.errorNode)(s) : ({ @@ -108632,7 +108684,7 @@ var ts; var mode = ts.getResolutionModeOverrideForClause(assertClause); if (mode !== undefined) { if (!ts.isNightly()) { - context.addDiagnostic(ts.createDiagnosticForNode(assertClause, ts.Diagnostics.Resolution_mode_assertions_are_unstable_Use_nightly_TypeScript_to_silence_this_error_Try_updating_with_npm_install_D_typescript_next)); + context.addDiagnostic(ts.createDiagnosticForNode(assertClause, ts.Diagnostics.resolution_mode_assertions_are_unstable_Use_nightly_TypeScript_to_silence_this_error_Try_updating_with_npm_install_D_typescript_next)); } return assertClause; } @@ -116139,12 +116191,14 @@ var ts; } ts.loadWithTypeDirectiveCache = loadWithTypeDirectiveCache; ; - /* @internal */ + /** + * Calculates the resulting resolution mode for some reference in some file - this is generally the explicitly + * provided resolution mode in the reference, unless one is not present, in which case it is the mode of the containing file. + */ function getModeForFileReference(ref, containingFileMode) { return (ts.isString(ref) ? containingFileMode : ref.resolutionMode) || containingFileMode; } ts.getModeForFileReference = getModeForFileReference; - /* @internal */ function getModeForResolutionAtIndex(file, index) { if (file.impliedNodeFormat === undefined) return undefined; @@ -116165,7 +116219,15 @@ var ts; return false; } ts.isExclusivelyTypeOnlyImportOrExport = isExclusivelyTypeOnlyImportOrExport; - /* @internal */ + /** + * Calculates the final resolution mode for a given module reference node. This is generally the explicitly provided resolution mode, if + * one exists, or the mode of the containing source file. (Excepting import=require, which is always commonjs, and dynamic import, which is always esm). + * Notably, this function always returns `undefined` if the containing file has an `undefined` `impliedNodeFormat` - this field is only set when + * `moduleResolution` is `node16`+. + * @param file The file the import or import-like reference is contained within + * @param usage The module reference string + * @returns The final resolution mode of the import + */ function getModeForUsageLocation(file, usage) { var _a, _b; if (file.impliedNodeFormat === undefined) @@ -118399,7 +118461,7 @@ var ts; ts.setResolvedTypeReferenceDirective(file, fileName, resolvedTypeReferenceDirective); var mode = ref.resolutionMode || file.impliedNodeFormat; if (mode && ts.getEmitModuleResolutionKind(options) !== ts.ModuleResolutionKind.Node16 && ts.getEmitModuleResolutionKind(options) !== ts.ModuleResolutionKind.NodeNext) { - programDiagnostics.add(ts.createDiagnosticForRange(file, ref, ts.Diagnostics.Resolution_modes_are_only_supported_when_moduleResolution_is_node16_or_nodenext)); + programDiagnostics.add(ts.createDiagnosticForRange(file, ref, ts.Diagnostics.resolution_mode_assertions_are_only_supported_when_moduleResolution_is_node16_or_nodenext)); } processTypeReferenceDirective(fileName, mode, resolvedTypeReferenceDirective, { kind: ts.FileIncludeKind.TypeReferenceDirective, file: file.path, index: index, }); } @@ -123692,6 +123754,7 @@ var ts; } function reloadFileNamesFromConfigFile() { writeLog("Reloading new file names and options"); + reloadLevel = ts.ConfigFileProgramReloadLevel.None; rootFileNames = ts.getFileNamesFromConfigSpecs(compilerOptions.configFile.configFileSpecs, ts.getNormalizedAbsolutePath(ts.getDirectoryPath(configFileName), currentDirectory), compilerOptions, parseConfigFileHost, extraFileExtensions); if (ts.updateErrorForNoInputFiles(rootFileNames, ts.getNormalizedAbsolutePath(configFileName, currentDirectory), compilerOptions.configFile.configFileSpecs, configFileParsingDiagnostics, canConfigFileJsonReportNoInputFiles)) { hasChangedConfigFileParsingErrors = true; @@ -136683,7 +136746,7 @@ var ts; ts.Debug.assert(parent.name === node); return true; case 203 /* SyntaxKind.BindingElement */: - return ts.isInJSFile(node) && ts.isVariableDeclarationInitializedToBareOrAccessedRequire(parent); + return ts.isInJSFile(node) && ts.isVariableDeclarationInitializedToBareOrAccessedRequire(parent.parent.parent); default: return false; } @@ -138148,7 +138211,7 @@ var ts; // Use the parent symbol if the location is commonjs require syntax on javascript files only. if (ts.isInJSFile(referenceLocation) && referenceLocation.parent.kind === 203 /* SyntaxKind.BindingElement */ - && ts.isVariableDeclarationInitializedToBareOrAccessedRequire(referenceLocation.parent)) { + && ts.isVariableDeclarationInitializedToBareOrAccessedRequire(referenceLocation.parent.parent.parent)) { referenceSymbol = referenceLocation.parent.symbol; // The parent will not have a symbol if it's an ObjectBindingPattern (when destructuring is used). In // this case, just skip it, since the bound identifiers are not an alias of the import. diff --git a/lib/typescriptServices.d.ts b/lib/typescriptServices.d.ts index 75f7eaab2308a..447913ebfb539 100644 --- a/lib/typescriptServices.d.ts +++ b/lib/typescriptServices.d.ts @@ -4720,6 +4720,7 @@ declare namespace ts { function isImportEqualsDeclaration(node: Node): node is ImportEqualsDeclaration; function isImportDeclaration(node: Node): node is ImportDeclaration; function isImportClause(node: Node): node is ImportClause; + function isImportTypeAssertionContainer(node: Node): node is ImportTypeAssertionContainer; function isAssertClause(node: Node): node is AssertClause; function isAssertEntry(node: Node): node is AssertEntry; function isNamespaceImport(node: Node): node is NamespaceImport; @@ -5098,6 +5099,31 @@ declare namespace ts { export function formatDiagnostic(diagnostic: Diagnostic, host: FormatDiagnosticsHost): string; export function formatDiagnosticsWithColorAndContext(diagnostics: readonly Diagnostic[], host: FormatDiagnosticsHost): string; export function flattenDiagnosticMessageText(diag: string | DiagnosticMessageChain | undefined, newLine: string, indent?: number): string; + /** + * Calculates the resulting resolution mode for some reference in some file - this is generally the explicitly + * provided resolution mode in the reference, unless one is not present, in which case it is the mode of the containing file. + */ + export function getModeForFileReference(ref: FileReference | string, containingFileMode: SourceFile["impliedNodeFormat"]): ModuleKind.CommonJS | ModuleKind.ESNext | undefined; + /** + * Calculates the final resolution mode for an import at some index within a file's imports list. This is generally the explicitly + * defined mode of the import if provided, or, if not, the mode of the containing file (with some exceptions: import=require is always commonjs, dynamic import is always esm). + * If you have an actual import node, prefer using getModeForUsageLocation on the reference string node. + * @param file File to fetch the resolution mode within + * @param index Index into the file's complete resolution list to get the resolution of - this is a concatenation of the file's imports and module augmentations + */ + export function getModeForResolutionAtIndex(file: SourceFile, index: number): ModuleKind.CommonJS | ModuleKind.ESNext | undefined; + /** + * Calculates the final resolution mode for a given module reference node. This is generally the explicitly provided resolution mode, if + * one exists, or the mode of the containing source file. (Excepting import=require, which is always commonjs, and dynamic import, which is always esm). + * Notably, this function always returns `undefined` if the containing file has an `undefined` `impliedNodeFormat` - this field is only set when + * `moduleResolution` is `node16`+. + * @param file The file the import or import-like reference is contained within + * @param usage The module reference string + * @returns The final resolution mode of the import + */ + export function getModeForUsageLocation(file: { + impliedNodeFormat?: SourceFile["impliedNodeFormat"]; + }, usage: StringLiteralLike): ModuleKind.CommonJS | ModuleKind.ESNext | undefined; export 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 diff --git a/lib/typescriptServices.js b/lib/typescriptServices.js index 0d8b6b5f33a19..b29e783239371 100644 --- a/lib/typescriptServices.js +++ b/lib/typescriptServices.js @@ -294,7 +294,7 @@ var ts; // The following is baselined as a literal template type without intervention /** The version of the TypeScript compiler release */ // eslint-disable-next-line @typescript-eslint/no-inferrable-types - ts.version = "4.7.2"; + ts.version = "4.7.3"; /* @internal */ var Comparison; (function (Comparison) { @@ -8583,7 +8583,7 @@ var ts; Preserve_unused_imported_values_in_the_JavaScript_output_that_would_otherwise_be_removed: diag(1449, ts.DiagnosticCategory.Message, "Preserve_unused_imported_values_in_the_JavaScript_output_that_would_otherwise_be_removed_1449", "Preserve unused imported values in the JavaScript output that would otherwise be removed."), Dynamic_imports_can_only_accept_a_module_specifier_and_an_optional_assertion_as_arguments: diag(1450, ts.DiagnosticCategory.Message, "Dynamic_imports_can_only_accept_a_module_specifier_and_an_optional_assertion_as_arguments_1450", "Dynamic imports can only accept a module specifier and an optional assertion as arguments"), Private_identifiers_are_only_allowed_in_class_bodies_and_may_only_be_used_as_part_of_a_class_member_declaration_property_access_or_on_the_left_hand_side_of_an_in_expression: diag(1451, ts.DiagnosticCategory.Error, "Private_identifiers_are_only_allowed_in_class_bodies_and_may_only_be_used_as_part_of_a_class_member__1451", "Private identifiers are only allowed in class bodies and may only be used as part of a class member declaration, property access, or on the left-hand-side of an 'in' expression"), - Resolution_modes_are_only_supported_when_moduleResolution_is_node16_or_nodenext: diag(1452, ts.DiagnosticCategory.Error, "Resolution_modes_are_only_supported_when_moduleResolution_is_node16_or_nodenext_1452", "Resolution modes are only supported when `moduleResolution` is `node16` or `nodenext`."), + resolution_mode_assertions_are_only_supported_when_moduleResolution_is_node16_or_nodenext: diag(1452, ts.DiagnosticCategory.Error, "resolution_mode_assertions_are_only_supported_when_moduleResolution_is_node16_or_nodenext_1452", "'resolution-mode' assertions are only supported when `moduleResolution` is `node16` or `nodenext`."), resolution_mode_should_be_either_require_or_import: diag(1453, ts.DiagnosticCategory.Error, "resolution_mode_should_be_either_require_or_import_1453", "`resolution-mode` should be either `require` or `import`."), resolution_mode_can_only_be_set_for_type_only_imports: diag(1454, ts.DiagnosticCategory.Error, "resolution_mode_can_only_be_set_for_type_only_imports_1454", "`resolution-mode` can only be set for type-only imports."), resolution_mode_is_the_only_valid_key_for_type_import_assertions: diag(1455, ts.DiagnosticCategory.Error, "resolution_mode_is_the_only_valid_key_for_type_import_assertions_1455", "`resolution-mode` is the only valid key for type import assertions."), @@ -9087,6 +9087,7 @@ var ts; Import_assertions_are_not_allowed_on_statements_that_transpile_to_commonjs_require_calls: diag(2836, ts.DiagnosticCategory.Error, "Import_assertions_are_not_allowed_on_statements_that_transpile_to_commonjs_require_calls_2836", "Import assertions are not allowed on statements that transpile to commonjs 'require' calls."), Import_assertion_values_must_be_string_literal_expressions: diag(2837, ts.DiagnosticCategory.Error, "Import_assertion_values_must_be_string_literal_expressions_2837", "Import assertion values must be string literal expressions."), All_declarations_of_0_must_have_identical_constraints: diag(2838, ts.DiagnosticCategory.Error, "All_declarations_of_0_must_have_identical_constraints_2838", "All declarations of '{0}' must have identical constraints."), + The_type_of_this_expression_cannot_be_named_without_a_resolution_mode_assertion_which_is_an_unstable_feature_Use_nightly_TypeScript_to_silence_this_error_Try_updating_with_npm_install_D_typescript_next: diag(2841, ts.DiagnosticCategory.Error, "The_type_of_this_expression_cannot_be_named_without_a_resolution_mode_assertion_which_is_an_unstable_2841", "The type of this expression cannot be named without a 'resolution-mode' assertion, which is an unstable feature. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'."), Import_declaration_0_is_using_private_name_1: diag(4000, ts.DiagnosticCategory.Error, "Import_declaration_0_is_using_private_name_1_4000", "Import declaration '{0}' is using private name '{1}'."), Type_parameter_0_of_exported_class_has_or_is_using_private_name_1: diag(4002, ts.DiagnosticCategory.Error, "Type_parameter_0_of_exported_class_has_or_is_using_private_name_1_4002", "Type parameter '{0}' of exported class has or is using private name '{1}'."), Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1: diag(4004, ts.DiagnosticCategory.Error, "Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1_4004", "Type parameter '{0}' of exported interface has or is using private name '{1}'."), @@ -9194,7 +9195,7 @@ var ts; This_member_cannot_have_a_JSDoc_comment_with_an_override_tag_because_it_is_not_declared_in_the_base_class_0: diag(4122, ts.DiagnosticCategory.Error, "This_member_cannot_have_a_JSDoc_comment_with_an_override_tag_because_it_is_not_declared_in_the_base__4122", "This member cannot have a JSDoc comment with an '@override' tag because it is not declared in the base class '{0}'."), This_member_cannot_have_a_JSDoc_comment_with_an_override_tag_because_it_is_not_declared_in_the_base_class_0_Did_you_mean_1: diag(4123, ts.DiagnosticCategory.Error, "This_member_cannot_have_a_JSDoc_comment_with_an_override_tag_because_it_is_not_declared_in_the_base__4123", "This member cannot have a JSDoc comment with an 'override' tag because it is not declared in the base class '{0}'. Did you mean '{1}'?"), Compiler_option_0_of_value_1_is_unstable_Use_nightly_TypeScript_to_silence_this_error_Try_updating_with_npm_install_D_typescript_next: diag(4124, ts.DiagnosticCategory.Error, "Compiler_option_0_of_value_1_is_unstable_Use_nightly_TypeScript_to_silence_this_error_Try_updating_w_4124", "Compiler option '{0}' of value '{1}' is unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'."), - Resolution_mode_assertions_are_unstable_Use_nightly_TypeScript_to_silence_this_error_Try_updating_with_npm_install_D_typescript_next: diag(4125, ts.DiagnosticCategory.Error, "Resolution_mode_assertions_are_unstable_Use_nightly_TypeScript_to_silence_this_error_Try_updating_wi_4125", "Resolution mode assertions are unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'."), + resolution_mode_assertions_are_unstable_Use_nightly_TypeScript_to_silence_this_error_Try_updating_with_npm_install_D_typescript_next: diag(4125, ts.DiagnosticCategory.Error, "resolution_mode_assertions_are_unstable_Use_nightly_TypeScript_to_silence_this_error_Try_updating_wi_4125", "'resolution-mode' assertions are unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'."), The_current_host_does_not_support_the_0_option: diag(5001, ts.DiagnosticCategory.Error, "The_current_host_does_not_support_the_0_option_5001", "The current host does not support the '{0}' option."), Cannot_find_the_common_subdirectory_path_for_the_input_files: diag(5009, ts.DiagnosticCategory.Error, "Cannot_find_the_common_subdirectory_path_for_the_input_files_5009", "Cannot find the common subdirectory path for the input files."), File_specification_cannot_end_in_a_recursive_directory_wildcard_Asterisk_Asterisk_Colon_0: diag(5010, ts.DiagnosticCategory.Error, "File_specification_cannot_end_in_a_recursive_directory_wildcard_Asterisk_Asterisk_Colon_0_5010", "File specification cannot end in a recursive directory wildcard ('**'): '{0}'."), @@ -16212,6 +16213,8 @@ var ts; case 218 /* SyntaxKind.AwaitExpression */: case 231 /* SyntaxKind.MetaProperty */: return true; + case 228 /* SyntaxKind.ExpressionWithTypeArguments */: + return !ts.isHeritageClause(node.parent); case 161 /* SyntaxKind.QualifiedName */: while (node.parent.kind === 161 /* SyntaxKind.QualifiedName */) { node = node.parent; @@ -16383,9 +16386,6 @@ var ts; } ts.isVariableDeclarationInitializedToBareOrAccessedRequire = isVariableDeclarationInitializedToBareOrAccessedRequire; function isVariableDeclarationInitializedWithRequireHelper(node, allowAccessedRequire) { - if (node.kind === 203 /* SyntaxKind.BindingElement */) { - node = node.parent.parent; - } return ts.isVariableDeclaration(node) && !!node.initializer && isRequireCall(allowAccessedRequire ? getLeftmostAccessExpression(node.initializer) : node.initializer, /*requireStringLiteralLikeArgument*/ true); @@ -20207,8 +20207,9 @@ var ts; */ function isFileForcedToBeModuleByFormat(file) { // Excludes declaration files - they still require an explicit `export {}` or the like - // for back compat purposes. - return file.impliedNodeFormat === ts.ModuleKind.ESNext && !file.isDeclarationFile ? true : undefined; + // for back compat purposes. The only non-declaration files _not_ forced to be a module are `.js` files + // that aren't esm-mode (meaning not in a `type: module` scope). + return (file.impliedNodeFormat === ts.ModuleKind.ESNext || (ts.fileExtensionIsOneOf(file.fileName, [".cjs" /* Extension.Cjs */, ".cts" /* Extension.Cts */]))) && !file.isDeclarationFile ? true : undefined; } function getSetExternalModuleIndicator(options) { // TODO: Should this callback be cached? @@ -20216,7 +20217,7 @@ var ts; case ts.ModuleDetectionKind.Force: // All non-declaration files are modules, declaration files still do the usual isFileProbablyExternalModule return function (file) { - file.externalModuleIndicator = !file.isDeclarationFile || ts.isFileProbablyExternalModule(file); + file.externalModuleIndicator = ts.isFileProbablyExternalModule(file) || !file.isDeclarationFile || undefined; }; case ts.ModuleDetectionKind.Legacy: // Files are modules if they have imports, exports, or import.meta @@ -20276,7 +20277,8 @@ var ts; } ts.getEmitModuleResolutionKind = getEmitModuleResolutionKind; function getEmitModuleDetectionKind(options) { - return options.moduleDetection || ts.ModuleDetectionKind.Auto; + return options.moduleDetection || + (getEmitModuleKind(options) === ts.ModuleKind.Node16 || getEmitModuleKind(options) === ts.ModuleKind.NodeNext ? ts.ModuleDetectionKind.Force : ts.ModuleDetectionKind.Auto); } ts.getEmitModuleDetectionKind = getEmitModuleDetectionKind; function hasJsonModuleEmitEnabled(options) { @@ -29256,6 +29258,10 @@ var ts; return node.kind === 267 /* SyntaxKind.ImportClause */; } ts.isImportClause = isImportClause; + function isImportTypeAssertionContainer(node) { + return node.kind === 295 /* SyntaxKind.ImportTypeAssertionContainer */; + } + ts.isImportTypeAssertionContainer = isImportTypeAssertionContainer; function isAssertClause(node) { return node.kind === 293 /* SyntaxKind.AssertClause */; } @@ -42200,7 +42206,7 @@ var ts; } if (ts.isImplicitGlob(spec.substring(spec.lastIndexOf(ts.directorySeparator) + 1))) { return { - key: useCaseSensitiveFileNames ? spec : ts.toFileNameLowerCase(spec), + key: ts.removeTrailingDirectorySeparator(useCaseSensitiveFileNames ? spec : ts.toFileNameLowerCase(spec)), flags: 1 /* WatchDirectoryFlags.Recursive */ }; } @@ -43305,16 +43311,20 @@ var ts; function nodeNextModuleNameResolver(moduleName, containingFile, compilerOptions, host, cache, redirectedReference, resolutionMode) { return nodeNextModuleNameResolverWorker(NodeResolutionFeatures.NodeNextDefault, moduleName, containingFile, compilerOptions, host, cache, redirectedReference, resolutionMode); } + var jsOnlyExtensions = [Extensions.JavaScript]; + var tsExtensions = [Extensions.TypeScript, Extensions.JavaScript]; + var tsPlusJsonExtensions = __spreadArray(__spreadArray([], tsExtensions, true), [Extensions.Json], false); + var tsconfigExtensions = [Extensions.TSConfig]; function nodeNextModuleNameResolverWorker(features, moduleName, containingFile, compilerOptions, host, cache, redirectedReference, resolutionMode) { var containingDirectory = ts.getDirectoryPath(containingFile); // es module file or cjs-like input file, use a variant of the legacy cjs resolver that supports the selected modern features var esmMode = resolutionMode === ts.ModuleKind.ESNext ? NodeResolutionFeatures.EsmMode : 0; - return nodeModuleNameResolverWorker(features | esmMode, moduleName, containingDirectory, compilerOptions, host, cache, compilerOptions.resolveJsonModule ? tsPlusJsonExtensions : tsExtensions, redirectedReference); + var extensions = compilerOptions.noDtsResolution ? [Extensions.TsOnly, Extensions.JavaScript] : tsExtensions; + if (compilerOptions.resolveJsonModule) { + extensions = __spreadArray(__spreadArray([], extensions, true), [Extensions.Json], false); + } + return nodeModuleNameResolverWorker(features | esmMode, moduleName, containingDirectory, compilerOptions, host, cache, extensions, redirectedReference); } - var jsOnlyExtensions = [Extensions.JavaScript]; - var tsExtensions = [Extensions.TypeScript, Extensions.JavaScript]; - var tsPlusJsonExtensions = __spreadArray(__spreadArray([], tsExtensions, true), [Extensions.Json], false); - var tsconfigExtensions = [Extensions.TSConfig]; function tryResolveJSModuleWorker(moduleName, initialDir, host) { return nodeModuleNameResolverWorker(NodeResolutionFeatures.None, moduleName, initialDir, { moduleResolution: ts.ModuleResolutionKind.NodeJs, allowJs: true }, host, /*cache*/ undefined, jsOnlyExtensions, /*redirectedReferences*/ undefined); } @@ -43997,13 +44007,36 @@ var ts; } return toSearchResult(/*value*/ undefined); } + /** + * From https://github.com/nodejs/node/blob/8f39f51cbbd3b2de14b9ee896e26421cc5b20121/lib/internal/modules/esm/resolve.js#L722 - + * "longest" has some nuance as to what "longest" means in the presence of pattern trailers + */ + function comparePatternKeys(a, b) { + var aPatternIndex = a.indexOf("*"); + var bPatternIndex = b.indexOf("*"); + var baseLenA = aPatternIndex === -1 ? a.length : aPatternIndex + 1; + var baseLenB = bPatternIndex === -1 ? b.length : bPatternIndex + 1; + if (baseLenA > baseLenB) + return -1; + if (baseLenB > baseLenA) + return 1; + if (aPatternIndex === -1) + return 1; + if (bPatternIndex === -1) + return -1; + if (a.length > b.length) + return -1; + if (b.length > a.length) + return 1; + return 0; + } function loadModuleFromImportsOrExports(extensions, state, cache, redirectedReference, moduleName, lookupTable, scope, isImports) { var loadModuleFromTargetImportOrExport = getLoadModuleFromTargetImportOrExport(extensions, state, cache, redirectedReference, moduleName, scope, isImports); if (!ts.endsWith(moduleName, ts.directorySeparator) && moduleName.indexOf("*") === -1 && ts.hasProperty(lookupTable, moduleName)) { var target = lookupTable[moduleName]; return loadModuleFromTargetImportOrExport(target, /*subpath*/ "", /*pattern*/ false); } - var expandingKeys = ts.sort(ts.filter(ts.getOwnKeys(lookupTable), function (k) { return k.indexOf("*") !== -1 || ts.endsWith(k, "/"); }), function (a, b) { return a.length - b.length; }); + var expandingKeys = ts.sort(ts.filter(ts.getOwnKeys(lookupTable), function (k) { return k.indexOf("*") !== -1 || ts.endsWith(k, "/"); }), comparePatternKeys); for (var _i = 0, expandingKeys_1 = expandingKeys; _i < expandingKeys_1.length; _i++) { var potentialTarget = expandingKeys_1[_i]; if (state.features & NodeResolutionFeatures.ExportsPatternTrailers && matchesPatternWithTrailer(potentialTarget, moduleName)) { @@ -44322,8 +44355,8 @@ var ts; var pathAndExtension = loadModuleFromFile(extensions, candidate, onlyRecordFailures, state) || loadNodeModuleFromDirectoryWorker(extensions, candidate, onlyRecordFailures, state, packageInfo && packageInfo.packageJsonContent, packageInfo && packageInfo.versionPaths); if (!pathAndExtension && packageInfo - && packageInfo.packageJsonContent.exports === undefined - && packageInfo.packageJsonContent.main === undefined + // eslint-disable-next-line no-null/no-null + && (packageInfo.packageJsonContent.exports === undefined || packageInfo.packageJsonContent.exports === null) && state.features & NodeResolutionFeatures.EsmMode) { // EsmMode disables index lookup in `loadNodeModuleFromDirectoryWorker` generally, however non-relative package resolutions still assume // a default `index.js` entrypoint if no `main` or `exports` are present @@ -47099,12 +47132,14 @@ var ts; } } function setCommonJsModuleIndicator(node) { - if (file.externalModuleIndicator) { + if (file.externalModuleIndicator && file.externalModuleIndicator !== true) { return false; } if (!file.commonJsModuleIndicator) { file.commonJsModuleIndicator = node; - bindSourceFileAsExternalModule(); + if (!file.externalModuleIndicator) { + bindSourceFileAsExternalModule(); + } } return true; } @@ -47518,7 +47553,11 @@ var ts; checkStrictModeEvalOrArguments(node, node.name); } if (!ts.isBindingPattern(node.name)) { - if (ts.isInJSFile(node) && ts.isVariableDeclarationInitializedToBareOrAccessedRequire(node) && !ts.getJSDocTypeTag(node) && !(ts.getCombinedModifierFlags(node) & 1 /* ModifierFlags.Export */)) { + var possibleVariableDecl = node.kind === 254 /* SyntaxKind.VariableDeclaration */ ? node : node.parent.parent; + if (ts.isInJSFile(node) && + ts.isVariableDeclarationInitializedToBareOrAccessedRequire(possibleVariableDecl) && + !ts.getJSDocTypeTag(node) && + !(ts.getCombinedModifierFlags(node) & 1 /* ModifierFlags.Export */)) { declareSymbolAndAddToSymbolTable(node, 2097152 /* SymbolFlags.Alias */, 2097152 /* SymbolFlags.AliasExcludes */); } else if (ts.isBlockOrCatchScoped(node)) { @@ -50345,7 +50384,8 @@ var ts; && isAliasableOrJsExpression(node.parent.right) || node.kind === 297 /* SyntaxKind.ShorthandPropertyAssignment */ || node.kind === 296 /* SyntaxKind.PropertyAssignment */ && isAliasableOrJsExpression(node.initializer) - || ts.isVariableDeclarationInitializedToBareOrAccessedRequire(node); + || node.kind === 254 /* SyntaxKind.VariableDeclaration */ && ts.isVariableDeclarationInitializedToBareOrAccessedRequire(node) + || node.kind === 203 /* SyntaxKind.BindingElement */ && ts.isVariableDeclarationInitializedToBareOrAccessedRequire(node.parent.parent); } function isAliasableOrJsExpression(e) { return ts.isAliasableExpression(e) || ts.isFunctionExpression(e) && isJSConstructor(e); @@ -50438,7 +50478,7 @@ var ts; return hasExportAssignmentSymbol(moduleSymbol); } // JS files have a synthetic default if they do not contain ES2015+ module syntax (export = is not valid in js) _and_ do not have an __esModule marker - return !file.externalModuleIndicator && !resolveExportByName(moduleSymbol, ts.escapeLeadingUnderscores("__esModule"), /*sourceNode*/ undefined, dontResolveAlias); + return typeof file.externalModuleIndicator !== "object" && !resolveExportByName(moduleSymbol, ts.escapeLeadingUnderscores("__esModule"), /*sourceNode*/ undefined, dontResolveAlias); } function getTargetOfImportClause(node, dontResolveAlias) { var _a; @@ -53553,6 +53593,7 @@ var ts; return symbol.parent ? ts.factory.createQualifiedName(symbolToEntityNameNode(symbol.parent), identifier) : identifier; } function symbolToTypeNode(symbol, context, meaning, overrideTypeArguments) { + var _a, _b, _c, _d; var chain = lookupSymbolChain(symbol, context, meaning, !(context.flags & 16384 /* NodeBuilderFlags.UseAliasDefinedOutsideCurrentScope */)); // If we're using aliases outside the current scope, dont bother with the module var isTypeOf = meaning === 111551 /* SymbolFlags.Value */; if (ts.some(chain[0].declarations, hasNonGlobalAugmentationExternalModuleSymbol)) { @@ -53570,6 +53611,7 @@ var ts; assertion = ts.factory.createImportTypeAssertionContainer(ts.factory.createAssertClause(ts.factory.createNodeArray([ ts.factory.createAssertEntry(ts.factory.createStringLiteral("resolution-mode"), ts.factory.createStringLiteral("import")) ]))); + (_b = (_a = context.tracker).reportImportTypeNodeResolutionModeOverride) === null || _b === void 0 ? void 0 : _b.call(_a); } } if (!specifier) { @@ -53589,6 +53631,7 @@ var ts; assertion = ts.factory.createImportTypeAssertionContainer(ts.factory.createAssertClause(ts.factory.createNodeArray([ ts.factory.createAssertEntry(ts.factory.createStringLiteral("resolution-mode"), ts.factory.createStringLiteral(swappedMode === ts.ModuleKind.ESNext ? "import" : "require")) ]))); + (_d = (_c = context.tracker).reportImportTypeNodeResolutionModeOverride) === null || _d === void 0 ? void 0 : _d.call(_c); } } if (!assertion) { @@ -59077,7 +59120,7 @@ var ts; var objectType; return !!(type.flags & 8388608 /* TypeFlags.IndexedAccess */ && ts.getObjectFlags(objectType = type.objectType) & 32 /* ObjectFlags.Mapped */ && !isGenericMappedType(objectType) && isGenericIndexType(type.indexType) && - !objectType.declaration.questionToken && !objectType.declaration.nameType); + !(getMappedTypeModifiers(objectType) & 8 /* MappedTypeModifiers.ExcludeOptional */) && !objectType.declaration.nameType); } /** * For a type parameter, return the base constraint of the type parameter. For the string, number, @@ -80828,8 +80871,11 @@ var ts; if (node.assertions) { var override = ts.getResolutionModeOverrideForClause(node.assertions.assertClause, grammarErrorOnNode); if (override) { + if (!ts.isNightly()) { + grammarErrorOnNode(node.assertions.assertClause, ts.Diagnostics.resolution_mode_assertions_are_unstable_Use_nightly_TypeScript_to_silence_this_error_Try_updating_with_npm_install_D_typescript_next); + } if (ts.getEmitModuleResolutionKind(compilerOptions) !== ts.ModuleResolutionKind.Node16 && ts.getEmitModuleResolutionKind(compilerOptions) !== ts.ModuleResolutionKind.NodeNext) { - grammarErrorOnNode(node.assertions.assertClause, ts.Diagnostics.Resolution_modes_are_only_supported_when_moduleResolution_is_node16_or_nodenext); + grammarErrorOnNode(node.assertions.assertClause, ts.Diagnostics.resolution_mode_assertions_are_only_supported_when_moduleResolution_is_node16_or_nodenext); } } } @@ -82532,7 +82578,7 @@ var ts; } // For a commonjs `const x = require`, validate the alias and exit var symbol = getSymbolOfNode(node); - if (symbol.flags & 2097152 /* SymbolFlags.Alias */ && ts.isVariableDeclarationInitializedToBareOrAccessedRequire(node)) { + if (symbol.flags & 2097152 /* SymbolFlags.Alias */ && ts.isVariableDeclarationInitializedToBareOrAccessedRequire(node.kind === 203 /* SyntaxKind.BindingElement */ ? node.parent.parent : node)) { checkAliasSymbol(node); return; } @@ -85200,10 +85246,10 @@ var ts; var override = ts.getResolutionModeOverrideForClause(declaration.assertClause, validForTypeAssertions ? grammarErrorOnNode : undefined); if (validForTypeAssertions && override) { if (!ts.isNightly()) { - grammarErrorOnNode(declaration.assertClause, ts.Diagnostics.Resolution_mode_assertions_are_unstable_Use_nightly_TypeScript_to_silence_this_error_Try_updating_with_npm_install_D_typescript_next); + grammarErrorOnNode(declaration.assertClause, ts.Diagnostics.resolution_mode_assertions_are_unstable_Use_nightly_TypeScript_to_silence_this_error_Try_updating_with_npm_install_D_typescript_next); } if (ts.getEmitModuleResolutionKind(compilerOptions) !== ts.ModuleResolutionKind.Node16 && ts.getEmitModuleResolutionKind(compilerOptions) !== ts.ModuleResolutionKind.NodeNext) { - return grammarErrorOnNode(declaration.assertClause, ts.Diagnostics.Resolution_modes_are_only_supported_when_moduleResolution_is_node16_or_nodenext); + return grammarErrorOnNode(declaration.assertClause, ts.Diagnostics.resolution_mode_assertions_are_only_supported_when_moduleResolution_is_node16_or_nodenext); } return; // Other grammar checks do not apply to type-only imports with resolution mode assertions } @@ -108055,7 +108101,8 @@ var ts; trackReferencedAmbientModule: trackReferencedAmbientModule, trackExternalModuleSymbolOfImportTypeNode: trackExternalModuleSymbolOfImportTypeNode, reportNonlocalAugmentation: reportNonlocalAugmentation, - reportNonSerializableProperty: reportNonSerializableProperty + reportNonSerializableProperty: reportNonSerializableProperty, + reportImportTypeNodeResolutionModeOverride: reportImportTypeNodeResolutionModeOverride, }; var errorNameNode; var errorFallbackNode; @@ -108182,6 +108229,11 @@ var ts; context.addDiagnostic(ts.createDiagnosticForNode((errorNameNode || errorFallbackNode), ts.Diagnostics.The_type_of_this_node_cannot_be_serialized_because_its_property_0_cannot_be_serialized, propertyName)); } } + function reportImportTypeNodeResolutionModeOverride() { + if (!ts.isNightly() && (errorNameNode || errorFallbackNode)) { + context.addDiagnostic(ts.createDiagnosticForNode((errorNameNode || errorFallbackNode), ts.Diagnostics.The_type_of_this_expression_cannot_be_named_without_a_resolution_mode_assertion_which_is_an_unstable_feature_Use_nightly_TypeScript_to_silence_this_error_Try_updating_with_npm_install_D_typescript_next)); + } + } function transformDeclarationsForJS(sourceFile, bundled) { var oldDiag = getSymbolAccessibilityDiagnostic; getSymbolAccessibilityDiagnostic = function (s) { return (s.errorNode && ts.canProduceDiagnostics(s.errorNode) ? ts.createGetSymbolAccessibilityDiagnosticForNode(s.errorNode)(s) : ({ @@ -108632,7 +108684,7 @@ var ts; var mode = ts.getResolutionModeOverrideForClause(assertClause); if (mode !== undefined) { if (!ts.isNightly()) { - context.addDiagnostic(ts.createDiagnosticForNode(assertClause, ts.Diagnostics.Resolution_mode_assertions_are_unstable_Use_nightly_TypeScript_to_silence_this_error_Try_updating_with_npm_install_D_typescript_next)); + context.addDiagnostic(ts.createDiagnosticForNode(assertClause, ts.Diagnostics.resolution_mode_assertions_are_unstable_Use_nightly_TypeScript_to_silence_this_error_Try_updating_with_npm_install_D_typescript_next)); } return assertClause; } @@ -116139,12 +116191,14 @@ var ts; } ts.loadWithTypeDirectiveCache = loadWithTypeDirectiveCache; ; - /* @internal */ + /** + * Calculates the resulting resolution mode for some reference in some file - this is generally the explicitly + * provided resolution mode in the reference, unless one is not present, in which case it is the mode of the containing file. + */ function getModeForFileReference(ref, containingFileMode) { return (ts.isString(ref) ? containingFileMode : ref.resolutionMode) || containingFileMode; } ts.getModeForFileReference = getModeForFileReference; - /* @internal */ function getModeForResolutionAtIndex(file, index) { if (file.impliedNodeFormat === undefined) return undefined; @@ -116165,7 +116219,15 @@ var ts; return false; } ts.isExclusivelyTypeOnlyImportOrExport = isExclusivelyTypeOnlyImportOrExport; - /* @internal */ + /** + * Calculates the final resolution mode for a given module reference node. This is generally the explicitly provided resolution mode, if + * one exists, or the mode of the containing source file. (Excepting import=require, which is always commonjs, and dynamic import, which is always esm). + * Notably, this function always returns `undefined` if the containing file has an `undefined` `impliedNodeFormat` - this field is only set when + * `moduleResolution` is `node16`+. + * @param file The file the import or import-like reference is contained within + * @param usage The module reference string + * @returns The final resolution mode of the import + */ function getModeForUsageLocation(file, usage) { var _a, _b; if (file.impliedNodeFormat === undefined) @@ -118399,7 +118461,7 @@ var ts; ts.setResolvedTypeReferenceDirective(file, fileName, resolvedTypeReferenceDirective); var mode = ref.resolutionMode || file.impliedNodeFormat; if (mode && ts.getEmitModuleResolutionKind(options) !== ts.ModuleResolutionKind.Node16 && ts.getEmitModuleResolutionKind(options) !== ts.ModuleResolutionKind.NodeNext) { - programDiagnostics.add(ts.createDiagnosticForRange(file, ref, ts.Diagnostics.Resolution_modes_are_only_supported_when_moduleResolution_is_node16_or_nodenext)); + programDiagnostics.add(ts.createDiagnosticForRange(file, ref, ts.Diagnostics.resolution_mode_assertions_are_only_supported_when_moduleResolution_is_node16_or_nodenext)); } processTypeReferenceDirective(fileName, mode, resolvedTypeReferenceDirective, { kind: ts.FileIncludeKind.TypeReferenceDirective, file: file.path, index: index, }); } @@ -123692,6 +123754,7 @@ var ts; } function reloadFileNamesFromConfigFile() { writeLog("Reloading new file names and options"); + reloadLevel = ts.ConfigFileProgramReloadLevel.None; rootFileNames = ts.getFileNamesFromConfigSpecs(compilerOptions.configFile.configFileSpecs, ts.getNormalizedAbsolutePath(ts.getDirectoryPath(configFileName), currentDirectory), compilerOptions, parseConfigFileHost, extraFileExtensions); if (ts.updateErrorForNoInputFiles(rootFileNames, ts.getNormalizedAbsolutePath(configFileName, currentDirectory), compilerOptions.configFile.configFileSpecs, configFileParsingDiagnostics, canConfigFileJsonReportNoInputFiles)) { hasChangedConfigFileParsingErrors = true; @@ -136683,7 +136746,7 @@ var ts; ts.Debug.assert(parent.name === node); return true; case 203 /* SyntaxKind.BindingElement */: - return ts.isInJSFile(node) && ts.isVariableDeclarationInitializedToBareOrAccessedRequire(parent); + return ts.isInJSFile(node) && ts.isVariableDeclarationInitializedToBareOrAccessedRequire(parent.parent.parent); default: return false; } @@ -138148,7 +138211,7 @@ var ts; // Use the parent symbol if the location is commonjs require syntax on javascript files only. if (ts.isInJSFile(referenceLocation) && referenceLocation.parent.kind === 203 /* SyntaxKind.BindingElement */ - && ts.isVariableDeclarationInitializedToBareOrAccessedRequire(referenceLocation.parent)) { + && ts.isVariableDeclarationInitializedToBareOrAccessedRequire(referenceLocation.parent.parent.parent)) { referenceSymbol = referenceLocation.parent.symbol; // The parent will not have a symbol if it's an ObjectBindingPattern (when destructuring is used). In // this case, just skip it, since the bound identifiers are not an alias of the import. diff --git a/lib/typingsInstaller.js b/lib/typingsInstaller.js index 38ae0d01eafc5..05870bdae2a13 100644 --- a/lib/typingsInstaller.js +++ b/lib/typingsInstaller.js @@ -89,7 +89,7 @@ var ts; // The following is baselined as a literal template type without intervention /** The version of the TypeScript compiler release */ // eslint-disable-next-line @typescript-eslint/no-inferrable-types - ts.version = "4.7.2"; + ts.version = "4.7.3"; /* @internal */ var Comparison; (function (Comparison) { @@ -8378,7 +8378,7 @@ var ts; Preserve_unused_imported_values_in_the_JavaScript_output_that_would_otherwise_be_removed: diag(1449, ts.DiagnosticCategory.Message, "Preserve_unused_imported_values_in_the_JavaScript_output_that_would_otherwise_be_removed_1449", "Preserve unused imported values in the JavaScript output that would otherwise be removed."), Dynamic_imports_can_only_accept_a_module_specifier_and_an_optional_assertion_as_arguments: diag(1450, ts.DiagnosticCategory.Message, "Dynamic_imports_can_only_accept_a_module_specifier_and_an_optional_assertion_as_arguments_1450", "Dynamic imports can only accept a module specifier and an optional assertion as arguments"), Private_identifiers_are_only_allowed_in_class_bodies_and_may_only_be_used_as_part_of_a_class_member_declaration_property_access_or_on_the_left_hand_side_of_an_in_expression: diag(1451, ts.DiagnosticCategory.Error, "Private_identifiers_are_only_allowed_in_class_bodies_and_may_only_be_used_as_part_of_a_class_member__1451", "Private identifiers are only allowed in class bodies and may only be used as part of a class member declaration, property access, or on the left-hand-side of an 'in' expression"), - Resolution_modes_are_only_supported_when_moduleResolution_is_node16_or_nodenext: diag(1452, ts.DiagnosticCategory.Error, "Resolution_modes_are_only_supported_when_moduleResolution_is_node16_or_nodenext_1452", "Resolution modes are only supported when `moduleResolution` is `node16` or `nodenext`."), + resolution_mode_assertions_are_only_supported_when_moduleResolution_is_node16_or_nodenext: diag(1452, ts.DiagnosticCategory.Error, "resolution_mode_assertions_are_only_supported_when_moduleResolution_is_node16_or_nodenext_1452", "'resolution-mode' assertions are only supported when `moduleResolution` is `node16` or `nodenext`."), resolution_mode_should_be_either_require_or_import: diag(1453, ts.DiagnosticCategory.Error, "resolution_mode_should_be_either_require_or_import_1453", "`resolution-mode` should be either `require` or `import`."), resolution_mode_can_only_be_set_for_type_only_imports: diag(1454, ts.DiagnosticCategory.Error, "resolution_mode_can_only_be_set_for_type_only_imports_1454", "`resolution-mode` can only be set for type-only imports."), resolution_mode_is_the_only_valid_key_for_type_import_assertions: diag(1455, ts.DiagnosticCategory.Error, "resolution_mode_is_the_only_valid_key_for_type_import_assertions_1455", "`resolution-mode` is the only valid key for type import assertions."), @@ -8882,6 +8882,7 @@ var ts; Import_assertions_are_not_allowed_on_statements_that_transpile_to_commonjs_require_calls: diag(2836, ts.DiagnosticCategory.Error, "Import_assertions_are_not_allowed_on_statements_that_transpile_to_commonjs_require_calls_2836", "Import assertions are not allowed on statements that transpile to commonjs 'require' calls."), Import_assertion_values_must_be_string_literal_expressions: diag(2837, ts.DiagnosticCategory.Error, "Import_assertion_values_must_be_string_literal_expressions_2837", "Import assertion values must be string literal expressions."), All_declarations_of_0_must_have_identical_constraints: diag(2838, ts.DiagnosticCategory.Error, "All_declarations_of_0_must_have_identical_constraints_2838", "All declarations of '{0}' must have identical constraints."), + The_type_of_this_expression_cannot_be_named_without_a_resolution_mode_assertion_which_is_an_unstable_feature_Use_nightly_TypeScript_to_silence_this_error_Try_updating_with_npm_install_D_typescript_next: diag(2841, ts.DiagnosticCategory.Error, "The_type_of_this_expression_cannot_be_named_without_a_resolution_mode_assertion_which_is_an_unstable_2841", "The type of this expression cannot be named without a 'resolution-mode' assertion, which is an unstable feature. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'."), Import_declaration_0_is_using_private_name_1: diag(4000, ts.DiagnosticCategory.Error, "Import_declaration_0_is_using_private_name_1_4000", "Import declaration '{0}' is using private name '{1}'."), Type_parameter_0_of_exported_class_has_or_is_using_private_name_1: diag(4002, ts.DiagnosticCategory.Error, "Type_parameter_0_of_exported_class_has_or_is_using_private_name_1_4002", "Type parameter '{0}' of exported class has or is using private name '{1}'."), Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1: diag(4004, ts.DiagnosticCategory.Error, "Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1_4004", "Type parameter '{0}' of exported interface has or is using private name '{1}'."), @@ -8989,7 +8990,7 @@ var ts; This_member_cannot_have_a_JSDoc_comment_with_an_override_tag_because_it_is_not_declared_in_the_base_class_0: diag(4122, ts.DiagnosticCategory.Error, "This_member_cannot_have_a_JSDoc_comment_with_an_override_tag_because_it_is_not_declared_in_the_base__4122", "This member cannot have a JSDoc comment with an '@override' tag because it is not declared in the base class '{0}'."), This_member_cannot_have_a_JSDoc_comment_with_an_override_tag_because_it_is_not_declared_in_the_base_class_0_Did_you_mean_1: diag(4123, ts.DiagnosticCategory.Error, "This_member_cannot_have_a_JSDoc_comment_with_an_override_tag_because_it_is_not_declared_in_the_base__4123", "This member cannot have a JSDoc comment with an 'override' tag because it is not declared in the base class '{0}'. Did you mean '{1}'?"), Compiler_option_0_of_value_1_is_unstable_Use_nightly_TypeScript_to_silence_this_error_Try_updating_with_npm_install_D_typescript_next: diag(4124, ts.DiagnosticCategory.Error, "Compiler_option_0_of_value_1_is_unstable_Use_nightly_TypeScript_to_silence_this_error_Try_updating_w_4124", "Compiler option '{0}' of value '{1}' is unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'."), - Resolution_mode_assertions_are_unstable_Use_nightly_TypeScript_to_silence_this_error_Try_updating_with_npm_install_D_typescript_next: diag(4125, ts.DiagnosticCategory.Error, "Resolution_mode_assertions_are_unstable_Use_nightly_TypeScript_to_silence_this_error_Try_updating_wi_4125", "Resolution mode assertions are unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'."), + resolution_mode_assertions_are_unstable_Use_nightly_TypeScript_to_silence_this_error_Try_updating_with_npm_install_D_typescript_next: diag(4125, ts.DiagnosticCategory.Error, "resolution_mode_assertions_are_unstable_Use_nightly_TypeScript_to_silence_this_error_Try_updating_wi_4125", "'resolution-mode' assertions are unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'."), The_current_host_does_not_support_the_0_option: diag(5001, ts.DiagnosticCategory.Error, "The_current_host_does_not_support_the_0_option_5001", "The current host does not support the '{0}' option."), Cannot_find_the_common_subdirectory_path_for_the_input_files: diag(5009, ts.DiagnosticCategory.Error, "Cannot_find_the_common_subdirectory_path_for_the_input_files_5009", "Cannot find the common subdirectory path for the input files."), File_specification_cannot_end_in_a_recursive_directory_wildcard_Asterisk_Asterisk_Colon_0: diag(5010, ts.DiagnosticCategory.Error, "File_specification_cannot_end_in_a_recursive_directory_wildcard_Asterisk_Asterisk_Colon_0_5010", "File specification cannot end in a recursive directory wildcard ('**'): '{0}'."), @@ -16007,6 +16008,8 @@ var ts; case 218 /* SyntaxKind.AwaitExpression */: case 231 /* SyntaxKind.MetaProperty */: return true; + case 228 /* SyntaxKind.ExpressionWithTypeArguments */: + return !ts.isHeritageClause(node.parent); case 161 /* SyntaxKind.QualifiedName */: while (node.parent.kind === 161 /* SyntaxKind.QualifiedName */) { node = node.parent; @@ -16178,9 +16181,6 @@ var ts; } ts.isVariableDeclarationInitializedToBareOrAccessedRequire = isVariableDeclarationInitializedToBareOrAccessedRequire; function isVariableDeclarationInitializedWithRequireHelper(node, allowAccessedRequire) { - if (node.kind === 203 /* SyntaxKind.BindingElement */) { - node = node.parent.parent; - } return ts.isVariableDeclaration(node) && !!node.initializer && isRequireCall(allowAccessedRequire ? getLeftmostAccessExpression(node.initializer) : node.initializer, /*requireStringLiteralLikeArgument*/ true); @@ -20002,8 +20002,9 @@ var ts; */ function isFileForcedToBeModuleByFormat(file) { // Excludes declaration files - they still require an explicit `export {}` or the like - // for back compat purposes. - return file.impliedNodeFormat === ts.ModuleKind.ESNext && !file.isDeclarationFile ? true : undefined; + // for back compat purposes. The only non-declaration files _not_ forced to be a module are `.js` files + // that aren't esm-mode (meaning not in a `type: module` scope). + return (file.impliedNodeFormat === ts.ModuleKind.ESNext || (ts.fileExtensionIsOneOf(file.fileName, [".cjs" /* Extension.Cjs */, ".cts" /* Extension.Cts */]))) && !file.isDeclarationFile ? true : undefined; } function getSetExternalModuleIndicator(options) { // TODO: Should this callback be cached? @@ -20011,7 +20012,7 @@ var ts; case ts.ModuleDetectionKind.Force: // All non-declaration files are modules, declaration files still do the usual isFileProbablyExternalModule return function (file) { - file.externalModuleIndicator = !file.isDeclarationFile || ts.isFileProbablyExternalModule(file); + file.externalModuleIndicator = ts.isFileProbablyExternalModule(file) || !file.isDeclarationFile || undefined; }; case ts.ModuleDetectionKind.Legacy: // Files are modules if they have imports, exports, or import.meta @@ -20071,7 +20072,8 @@ var ts; } ts.getEmitModuleResolutionKind = getEmitModuleResolutionKind; function getEmitModuleDetectionKind(options) { - return options.moduleDetection || ts.ModuleDetectionKind.Auto; + return options.moduleDetection || + (getEmitModuleKind(options) === ts.ModuleKind.Node16 || getEmitModuleKind(options) === ts.ModuleKind.NodeNext ? ts.ModuleDetectionKind.Force : ts.ModuleDetectionKind.Auto); } ts.getEmitModuleDetectionKind = getEmitModuleDetectionKind; function hasJsonModuleEmitEnabled(options) { @@ -29051,6 +29053,10 @@ var ts; return node.kind === 267 /* SyntaxKind.ImportClause */; } ts.isImportClause = isImportClause; + function isImportTypeAssertionContainer(node) { + return node.kind === 295 /* SyntaxKind.ImportTypeAssertionContainer */; + } + ts.isImportTypeAssertionContainer = isImportTypeAssertionContainer; function isAssertClause(node) { return node.kind === 293 /* SyntaxKind.AssertClause */; } @@ -41995,7 +42001,7 @@ var ts; } if (ts.isImplicitGlob(spec.substring(spec.lastIndexOf(ts.directorySeparator) + 1))) { return { - key: useCaseSensitiveFileNames ? spec : ts.toFileNameLowerCase(spec), + key: ts.removeTrailingDirectorySeparator(useCaseSensitiveFileNames ? spec : ts.toFileNameLowerCase(spec)), flags: 1 /* WatchDirectoryFlags.Recursive */ }; } @@ -43100,16 +43106,20 @@ var ts; function nodeNextModuleNameResolver(moduleName, containingFile, compilerOptions, host, cache, redirectedReference, resolutionMode) { return nodeNextModuleNameResolverWorker(NodeResolutionFeatures.NodeNextDefault, moduleName, containingFile, compilerOptions, host, cache, redirectedReference, resolutionMode); } + var jsOnlyExtensions = [Extensions.JavaScript]; + var tsExtensions = [Extensions.TypeScript, Extensions.JavaScript]; + var tsPlusJsonExtensions = __spreadArray(__spreadArray([], tsExtensions, true), [Extensions.Json], false); + var tsconfigExtensions = [Extensions.TSConfig]; function nodeNextModuleNameResolverWorker(features, moduleName, containingFile, compilerOptions, host, cache, redirectedReference, resolutionMode) { var containingDirectory = ts.getDirectoryPath(containingFile); // es module file or cjs-like input file, use a variant of the legacy cjs resolver that supports the selected modern features var esmMode = resolutionMode === ts.ModuleKind.ESNext ? NodeResolutionFeatures.EsmMode : 0; - return nodeModuleNameResolverWorker(features | esmMode, moduleName, containingDirectory, compilerOptions, host, cache, compilerOptions.resolveJsonModule ? tsPlusJsonExtensions : tsExtensions, redirectedReference); + var extensions = compilerOptions.noDtsResolution ? [Extensions.TsOnly, Extensions.JavaScript] : tsExtensions; + if (compilerOptions.resolveJsonModule) { + extensions = __spreadArray(__spreadArray([], extensions, true), [Extensions.Json], false); + } + return nodeModuleNameResolverWorker(features | esmMode, moduleName, containingDirectory, compilerOptions, host, cache, extensions, redirectedReference); } - var jsOnlyExtensions = [Extensions.JavaScript]; - var tsExtensions = [Extensions.TypeScript, Extensions.JavaScript]; - var tsPlusJsonExtensions = __spreadArray(__spreadArray([], tsExtensions, true), [Extensions.Json], false); - var tsconfigExtensions = [Extensions.TSConfig]; function tryResolveJSModuleWorker(moduleName, initialDir, host) { return nodeModuleNameResolverWorker(NodeResolutionFeatures.None, moduleName, initialDir, { moduleResolution: ts.ModuleResolutionKind.NodeJs, allowJs: true }, host, /*cache*/ undefined, jsOnlyExtensions, /*redirectedReferences*/ undefined); } @@ -43792,13 +43802,36 @@ var ts; } return toSearchResult(/*value*/ undefined); } + /** + * From https://github.com/nodejs/node/blob/8f39f51cbbd3b2de14b9ee896e26421cc5b20121/lib/internal/modules/esm/resolve.js#L722 - + * "longest" has some nuance as to what "longest" means in the presence of pattern trailers + */ + function comparePatternKeys(a, b) { + var aPatternIndex = a.indexOf("*"); + var bPatternIndex = b.indexOf("*"); + var baseLenA = aPatternIndex === -1 ? a.length : aPatternIndex + 1; + var baseLenB = bPatternIndex === -1 ? b.length : bPatternIndex + 1; + if (baseLenA > baseLenB) + return -1; + if (baseLenB > baseLenA) + return 1; + if (aPatternIndex === -1) + return 1; + if (bPatternIndex === -1) + return -1; + if (a.length > b.length) + return -1; + if (b.length > a.length) + return 1; + return 0; + } function loadModuleFromImportsOrExports(extensions, state, cache, redirectedReference, moduleName, lookupTable, scope, isImports) { var loadModuleFromTargetImportOrExport = getLoadModuleFromTargetImportOrExport(extensions, state, cache, redirectedReference, moduleName, scope, isImports); if (!ts.endsWith(moduleName, ts.directorySeparator) && moduleName.indexOf("*") === -1 && ts.hasProperty(lookupTable, moduleName)) { var target = lookupTable[moduleName]; return loadModuleFromTargetImportOrExport(target, /*subpath*/ "", /*pattern*/ false); } - var expandingKeys = ts.sort(ts.filter(ts.getOwnKeys(lookupTable), function (k) { return k.indexOf("*") !== -1 || ts.endsWith(k, "/"); }), function (a, b) { return a.length - b.length; }); + var expandingKeys = ts.sort(ts.filter(ts.getOwnKeys(lookupTable), function (k) { return k.indexOf("*") !== -1 || ts.endsWith(k, "/"); }), comparePatternKeys); for (var _i = 0, expandingKeys_1 = expandingKeys; _i < expandingKeys_1.length; _i++) { var potentialTarget = expandingKeys_1[_i]; if (state.features & NodeResolutionFeatures.ExportsPatternTrailers && matchesPatternWithTrailer(potentialTarget, moduleName)) { @@ -44117,8 +44150,8 @@ var ts; var pathAndExtension = loadModuleFromFile(extensions, candidate, onlyRecordFailures, state) || loadNodeModuleFromDirectoryWorker(extensions, candidate, onlyRecordFailures, state, packageInfo && packageInfo.packageJsonContent, packageInfo && packageInfo.versionPaths); if (!pathAndExtension && packageInfo - && packageInfo.packageJsonContent.exports === undefined - && packageInfo.packageJsonContent.main === undefined + // eslint-disable-next-line no-null/no-null + && (packageInfo.packageJsonContent.exports === undefined || packageInfo.packageJsonContent.exports === null) && state.features & NodeResolutionFeatures.EsmMode) { // EsmMode disables index lookup in `loadNodeModuleFromDirectoryWorker` generally, however non-relative package resolutions still assume // a default `index.js` entrypoint if no `main` or `exports` are present @@ -46894,12 +46927,14 @@ var ts; } } function setCommonJsModuleIndicator(node) { - if (file.externalModuleIndicator) { + if (file.externalModuleIndicator && file.externalModuleIndicator !== true) { return false; } if (!file.commonJsModuleIndicator) { file.commonJsModuleIndicator = node; - bindSourceFileAsExternalModule(); + if (!file.externalModuleIndicator) { + bindSourceFileAsExternalModule(); + } } return true; } @@ -47313,7 +47348,11 @@ var ts; checkStrictModeEvalOrArguments(node, node.name); } if (!ts.isBindingPattern(node.name)) { - if (ts.isInJSFile(node) && ts.isVariableDeclarationInitializedToBareOrAccessedRequire(node) && !ts.getJSDocTypeTag(node) && !(ts.getCombinedModifierFlags(node) & 1 /* ModifierFlags.Export */)) { + var possibleVariableDecl = node.kind === 254 /* SyntaxKind.VariableDeclaration */ ? node : node.parent.parent; + if (ts.isInJSFile(node) && + ts.isVariableDeclarationInitializedToBareOrAccessedRequire(possibleVariableDecl) && + !ts.getJSDocTypeTag(node) && + !(ts.getCombinedModifierFlags(node) & 1 /* ModifierFlags.Export */)) { declareSymbolAndAddToSymbolTable(node, 2097152 /* SymbolFlags.Alias */, 2097152 /* SymbolFlags.AliasExcludes */); } else if (ts.isBlockOrCatchScoped(node)) { @@ -50140,7 +50179,8 @@ var ts; && isAliasableOrJsExpression(node.parent.right) || node.kind === 297 /* SyntaxKind.ShorthandPropertyAssignment */ || node.kind === 296 /* SyntaxKind.PropertyAssignment */ && isAliasableOrJsExpression(node.initializer) - || ts.isVariableDeclarationInitializedToBareOrAccessedRequire(node); + || node.kind === 254 /* SyntaxKind.VariableDeclaration */ && ts.isVariableDeclarationInitializedToBareOrAccessedRequire(node) + || node.kind === 203 /* SyntaxKind.BindingElement */ && ts.isVariableDeclarationInitializedToBareOrAccessedRequire(node.parent.parent); } function isAliasableOrJsExpression(e) { return ts.isAliasableExpression(e) || ts.isFunctionExpression(e) && isJSConstructor(e); @@ -50233,7 +50273,7 @@ var ts; return hasExportAssignmentSymbol(moduleSymbol); } // JS files have a synthetic default if they do not contain ES2015+ module syntax (export = is not valid in js) _and_ do not have an __esModule marker - return !file.externalModuleIndicator && !resolveExportByName(moduleSymbol, ts.escapeLeadingUnderscores("__esModule"), /*sourceNode*/ undefined, dontResolveAlias); + return typeof file.externalModuleIndicator !== "object" && !resolveExportByName(moduleSymbol, ts.escapeLeadingUnderscores("__esModule"), /*sourceNode*/ undefined, dontResolveAlias); } function getTargetOfImportClause(node, dontResolveAlias) { var _a; @@ -53348,6 +53388,7 @@ var ts; return symbol.parent ? ts.factory.createQualifiedName(symbolToEntityNameNode(symbol.parent), identifier) : identifier; } function symbolToTypeNode(symbol, context, meaning, overrideTypeArguments) { + var _a, _b, _c, _d; var chain = lookupSymbolChain(symbol, context, meaning, !(context.flags & 16384 /* NodeBuilderFlags.UseAliasDefinedOutsideCurrentScope */)); // If we're using aliases outside the current scope, dont bother with the module var isTypeOf = meaning === 111551 /* SymbolFlags.Value */; if (ts.some(chain[0].declarations, hasNonGlobalAugmentationExternalModuleSymbol)) { @@ -53365,6 +53406,7 @@ var ts; assertion = ts.factory.createImportTypeAssertionContainer(ts.factory.createAssertClause(ts.factory.createNodeArray([ ts.factory.createAssertEntry(ts.factory.createStringLiteral("resolution-mode"), ts.factory.createStringLiteral("import")) ]))); + (_b = (_a = context.tracker).reportImportTypeNodeResolutionModeOverride) === null || _b === void 0 ? void 0 : _b.call(_a); } } if (!specifier) { @@ -53384,6 +53426,7 @@ var ts; assertion = ts.factory.createImportTypeAssertionContainer(ts.factory.createAssertClause(ts.factory.createNodeArray([ ts.factory.createAssertEntry(ts.factory.createStringLiteral("resolution-mode"), ts.factory.createStringLiteral(swappedMode === ts.ModuleKind.ESNext ? "import" : "require")) ]))); + (_d = (_c = context.tracker).reportImportTypeNodeResolutionModeOverride) === null || _d === void 0 ? void 0 : _d.call(_c); } } if (!assertion) { @@ -58872,7 +58915,7 @@ var ts; var objectType; return !!(type.flags & 8388608 /* TypeFlags.IndexedAccess */ && ts.getObjectFlags(objectType = type.objectType) & 32 /* ObjectFlags.Mapped */ && !isGenericMappedType(objectType) && isGenericIndexType(type.indexType) && - !objectType.declaration.questionToken && !objectType.declaration.nameType); + !(getMappedTypeModifiers(objectType) & 8 /* MappedTypeModifiers.ExcludeOptional */) && !objectType.declaration.nameType); } /** * For a type parameter, return the base constraint of the type parameter. For the string, number, @@ -80623,8 +80666,11 @@ var ts; if (node.assertions) { var override = ts.getResolutionModeOverrideForClause(node.assertions.assertClause, grammarErrorOnNode); if (override) { + if (!ts.isNightly()) { + grammarErrorOnNode(node.assertions.assertClause, ts.Diagnostics.resolution_mode_assertions_are_unstable_Use_nightly_TypeScript_to_silence_this_error_Try_updating_with_npm_install_D_typescript_next); + } if (ts.getEmitModuleResolutionKind(compilerOptions) !== ts.ModuleResolutionKind.Node16 && ts.getEmitModuleResolutionKind(compilerOptions) !== ts.ModuleResolutionKind.NodeNext) { - grammarErrorOnNode(node.assertions.assertClause, ts.Diagnostics.Resolution_modes_are_only_supported_when_moduleResolution_is_node16_or_nodenext); + grammarErrorOnNode(node.assertions.assertClause, ts.Diagnostics.resolution_mode_assertions_are_only_supported_when_moduleResolution_is_node16_or_nodenext); } } } @@ -82327,7 +82373,7 @@ var ts; } // For a commonjs `const x = require`, validate the alias and exit var symbol = getSymbolOfNode(node); - if (symbol.flags & 2097152 /* SymbolFlags.Alias */ && ts.isVariableDeclarationInitializedToBareOrAccessedRequire(node)) { + if (symbol.flags & 2097152 /* SymbolFlags.Alias */ && ts.isVariableDeclarationInitializedToBareOrAccessedRequire(node.kind === 203 /* SyntaxKind.BindingElement */ ? node.parent.parent : node)) { checkAliasSymbol(node); return; } @@ -84995,10 +85041,10 @@ var ts; var override = ts.getResolutionModeOverrideForClause(declaration.assertClause, validForTypeAssertions ? grammarErrorOnNode : undefined); if (validForTypeAssertions && override) { if (!ts.isNightly()) { - grammarErrorOnNode(declaration.assertClause, ts.Diagnostics.Resolution_mode_assertions_are_unstable_Use_nightly_TypeScript_to_silence_this_error_Try_updating_with_npm_install_D_typescript_next); + grammarErrorOnNode(declaration.assertClause, ts.Diagnostics.resolution_mode_assertions_are_unstable_Use_nightly_TypeScript_to_silence_this_error_Try_updating_with_npm_install_D_typescript_next); } if (ts.getEmitModuleResolutionKind(compilerOptions) !== ts.ModuleResolutionKind.Node16 && ts.getEmitModuleResolutionKind(compilerOptions) !== ts.ModuleResolutionKind.NodeNext) { - return grammarErrorOnNode(declaration.assertClause, ts.Diagnostics.Resolution_modes_are_only_supported_when_moduleResolution_is_node16_or_nodenext); + return grammarErrorOnNode(declaration.assertClause, ts.Diagnostics.resolution_mode_assertions_are_only_supported_when_moduleResolution_is_node16_or_nodenext); } return; // Other grammar checks do not apply to type-only imports with resolution mode assertions } @@ -107850,7 +107896,8 @@ var ts; trackReferencedAmbientModule: trackReferencedAmbientModule, trackExternalModuleSymbolOfImportTypeNode: trackExternalModuleSymbolOfImportTypeNode, reportNonlocalAugmentation: reportNonlocalAugmentation, - reportNonSerializableProperty: reportNonSerializableProperty + reportNonSerializableProperty: reportNonSerializableProperty, + reportImportTypeNodeResolutionModeOverride: reportImportTypeNodeResolutionModeOverride, }; var errorNameNode; var errorFallbackNode; @@ -107977,6 +108024,11 @@ var ts; context.addDiagnostic(ts.createDiagnosticForNode((errorNameNode || errorFallbackNode), ts.Diagnostics.The_type_of_this_node_cannot_be_serialized_because_its_property_0_cannot_be_serialized, propertyName)); } } + function reportImportTypeNodeResolutionModeOverride() { + if (!ts.isNightly() && (errorNameNode || errorFallbackNode)) { + context.addDiagnostic(ts.createDiagnosticForNode((errorNameNode || errorFallbackNode), ts.Diagnostics.The_type_of_this_expression_cannot_be_named_without_a_resolution_mode_assertion_which_is_an_unstable_feature_Use_nightly_TypeScript_to_silence_this_error_Try_updating_with_npm_install_D_typescript_next)); + } + } function transformDeclarationsForJS(sourceFile, bundled) { var oldDiag = getSymbolAccessibilityDiagnostic; getSymbolAccessibilityDiagnostic = function (s) { return (s.errorNode && ts.canProduceDiagnostics(s.errorNode) ? ts.createGetSymbolAccessibilityDiagnosticForNode(s.errorNode)(s) : ({ @@ -108427,7 +108479,7 @@ var ts; var mode = ts.getResolutionModeOverrideForClause(assertClause); if (mode !== undefined) { if (!ts.isNightly()) { - context.addDiagnostic(ts.createDiagnosticForNode(assertClause, ts.Diagnostics.Resolution_mode_assertions_are_unstable_Use_nightly_TypeScript_to_silence_this_error_Try_updating_with_npm_install_D_typescript_next)); + context.addDiagnostic(ts.createDiagnosticForNode(assertClause, ts.Diagnostics.resolution_mode_assertions_are_unstable_Use_nightly_TypeScript_to_silence_this_error_Try_updating_with_npm_install_D_typescript_next)); } return assertClause; } @@ -115934,12 +115986,14 @@ var ts; } ts.loadWithTypeDirectiveCache = loadWithTypeDirectiveCache; ; - /* @internal */ + /** + * Calculates the resulting resolution mode for some reference in some file - this is generally the explicitly + * provided resolution mode in the reference, unless one is not present, in which case it is the mode of the containing file. + */ function getModeForFileReference(ref, containingFileMode) { return (ts.isString(ref) ? containingFileMode : ref.resolutionMode) || containingFileMode; } ts.getModeForFileReference = getModeForFileReference; - /* @internal */ function getModeForResolutionAtIndex(file, index) { if (file.impliedNodeFormat === undefined) return undefined; @@ -115960,7 +116014,15 @@ var ts; return false; } ts.isExclusivelyTypeOnlyImportOrExport = isExclusivelyTypeOnlyImportOrExport; - /* @internal */ + /** + * Calculates the final resolution mode for a given module reference node. This is generally the explicitly provided resolution mode, if + * one exists, or the mode of the containing source file. (Excepting import=require, which is always commonjs, and dynamic import, which is always esm). + * Notably, this function always returns `undefined` if the containing file has an `undefined` `impliedNodeFormat` - this field is only set when + * `moduleResolution` is `node16`+. + * @param file The file the import or import-like reference is contained within + * @param usage The module reference string + * @returns The final resolution mode of the import + */ function getModeForUsageLocation(file, usage) { var _a, _b; if (file.impliedNodeFormat === undefined) @@ -118194,7 +118256,7 @@ var ts; ts.setResolvedTypeReferenceDirective(file, fileName, resolvedTypeReferenceDirective); var mode = ref.resolutionMode || file.impliedNodeFormat; if (mode && ts.getEmitModuleResolutionKind(options) !== ts.ModuleResolutionKind.Node16 && ts.getEmitModuleResolutionKind(options) !== ts.ModuleResolutionKind.NodeNext) { - programDiagnostics.add(ts.createDiagnosticForRange(file, ref, ts.Diagnostics.Resolution_modes_are_only_supported_when_moduleResolution_is_node16_or_nodenext)); + programDiagnostics.add(ts.createDiagnosticForRange(file, ref, ts.Diagnostics.resolution_mode_assertions_are_only_supported_when_moduleResolution_is_node16_or_nodenext)); } processTypeReferenceDirective(fileName, mode, resolvedTypeReferenceDirective, { kind: ts.FileIncludeKind.TypeReferenceDirective, file: file.path, index: index, }); } @@ -123487,6 +123549,7 @@ var ts; } function reloadFileNamesFromConfigFile() { writeLog("Reloading new file names and options"); + reloadLevel = ts.ConfigFileProgramReloadLevel.None; rootFileNames = ts.getFileNamesFromConfigSpecs(compilerOptions.configFile.configFileSpecs, ts.getNormalizedAbsolutePath(ts.getDirectoryPath(configFileName), currentDirectory), compilerOptions, parseConfigFileHost, extraFileExtensions); if (ts.updateErrorForNoInputFiles(rootFileNames, ts.getNormalizedAbsolutePath(configFileName, currentDirectory), compilerOptions.configFile.configFileSpecs, configFileParsingDiagnostics, canConfigFileJsonReportNoInputFiles)) { hasChangedConfigFileParsingErrors = true; diff --git a/package.json b/package.json index dea95f6f6676a..9723e5d2e7ac3 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "typescript", "author": "Microsoft Corp.", "homepage": "https://www.typescriptlang.org/", - "version": "4.7.2", + "version": "4.7.3", "license": "Apache-2.0", "description": "TypeScript is a language for application scale JavaScript development", "keywords": [ diff --git a/src/compiler/corePublic.ts b/src/compiler/corePublic.ts index f15552f526ff9..6678bc8204c2b 100644 --- a/src/compiler/corePublic.ts +++ b/src/compiler/corePublic.ts @@ -5,7 +5,7 @@ namespace ts { // The following is baselined as a literal template type without intervention /** The version of the TypeScript compiler release */ // eslint-disable-next-line @typescript-eslint/no-inferrable-types - export const version = "4.7.2" as string; + export const version = "4.7.3" as string; /** * Type of objects whose values are all of the same type.