From a821a2ba1936409ecc82cbb1a45c4af25c7a42e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Burzy=C5=84ski?= Date: Sun, 26 May 2024 17:42:36 +0200 Subject: [PATCH 1/8] Consistently avoid module reoslution errors when using `getSymbolAtLocation` --- src/compiler/checker.ts | 30 ++-- src/testRunner/unittests/tsc/composite.ts | 54 ++++++ ...le-from-CJS-module-error-on-jsx-element.js | 170 ++++++++++++++++++ ...from-CJS-module-no-crash-no-jsx-element.js | 135 ++++++++++++++ ...owImportingTsExtensions`-of-config-file.js | 7 +- ...-prefers-declaration-file-over-document.js | 14 +- 6 files changed, 389 insertions(+), 21 deletions(-) create mode 100644 tests/baselines/reference/tsc/composite/synthetic-jsx-import-of-ESM-module-from-CJS-module-error-on-jsx-element.js create mode 100644 tests/baselines/reference/tsc/composite/synthetic-jsx-import-of-ESM-module-from-CJS-module-no-crash-no-jsx-element.js diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index a9830b1264457..0db4facf7f9bd 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -2763,7 +2763,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { const moduleNotFoundError = !(moduleName.parent.parent.flags & NodeFlags.Ambient) ? Diagnostics.Invalid_module_name_in_augmentation_module_0_cannot_be_found : undefined; - let mainModule = resolveExternalModuleNameWorker(moduleName, moduleName, moduleNotFoundError, /*isForAugmentation*/ true); + let mainModule = resolveExternalModuleNameWorker(moduleName, moduleName, moduleNotFoundError, /*ignoreErrors*/ false, /*isForAugmentation*/ true); if (!mainModule) { return; } @@ -4521,17 +4521,17 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { const errorMessage = isClassic ? Diagnostics.Cannot_find_module_0_Did_you_mean_to_set_the_moduleResolution_option_to_nodenext_or_to_add_aliases_to_the_paths_option : Diagnostics.Cannot_find_module_0_or_its_corresponding_type_declarations; - return resolveExternalModuleNameWorker(location, moduleReferenceExpression, ignoreErrors ? undefined : errorMessage); + return resolveExternalModuleNameWorker(location, moduleReferenceExpression, ignoreErrors ? undefined : errorMessage, ignoreErrors); } - function resolveExternalModuleNameWorker(location: Node, moduleReferenceExpression: Expression, moduleNotFoundError: DiagnosticMessage | undefined, isForAugmentation = false): Symbol | undefined { + function resolveExternalModuleNameWorker(location: Node, moduleReferenceExpression: Expression, moduleNotFoundError: DiagnosticMessage | undefined, ignoreErrors = false, isForAugmentation = false): Symbol | undefined { return isStringLiteralLike(moduleReferenceExpression) - ? resolveExternalModule(location, moduleReferenceExpression.text, moduleNotFoundError, moduleReferenceExpression, isForAugmentation) + ? resolveExternalModule(location, moduleReferenceExpression.text, moduleNotFoundError, !ignoreErrors ? moduleReferenceExpression : undefined, isForAugmentation) : undefined; } - function resolveExternalModule(location: Node, moduleReference: string, moduleNotFoundError: DiagnosticMessage | undefined, errorNode: Node, isForAugmentation = false): Symbol | undefined { - if (startsWith(moduleReference, "@types/")) { + function resolveExternalModule(location: Node, moduleReference: string, moduleNotFoundError: DiagnosticMessage | undefined, errorNode: Node | undefined, isForAugmentation = false): Symbol | undefined { + if (errorNode && startsWith(moduleReference, "@types/")) { const diag = Diagnostics.Cannot_import_type_declaration_files_Consider_importing_0_instead_of_1; const withoutAtTypePrefix = removePrefix(moduleReference, "@types/"); error(errorNode, diag, withoutAtTypePrefix, moduleReference); @@ -4557,7 +4557,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { : host.getDefaultResolutionModeForFile(currentSourceFile); const moduleResolutionKind = getEmitModuleResolutionKind(compilerOptions); const resolvedModule = host.getResolvedModule(currentSourceFile, moduleReference, mode)?.resolvedModule; - const resolutionDiagnostic = resolvedModule && getResolutionDiagnostic(compilerOptions, resolvedModule, currentSourceFile); + const resolutionDiagnostic = errorNode && resolvedModule && getResolutionDiagnostic(compilerOptions, resolvedModule, currentSourceFile); const sourceFile = resolvedModule && (!resolutionDiagnostic || resolutionDiagnostic === Diagnostics.Module_0_was_resolved_to_1_but_jsx_is_not_set) && host.getSourceFile(resolvedModule.resolvedFileName); @@ -4570,7 +4570,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { if (resolvedModule.resolvedUsingTsExtension && isDeclarationFileName(moduleReference)) { const importOrExport = findAncestor(location, isImportDeclaration)?.importClause || findAncestor(location, or(isImportEqualsDeclaration, isExportDeclaration)); - if (importOrExport && !importOrExport.isTypeOnly || findAncestor(location, isImportCall)) { + if (errorNode && importOrExport && !importOrExport.isTypeOnly || findAncestor(location, isImportCall)) { error( errorNode, Diagnostics.A_declaration_file_cannot_be_imported_without_import_type_Did_you_mean_to_import_an_implementation_file_0_instead, @@ -4581,17 +4581,17 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { else if (resolvedModule.resolvedUsingTsExtension && !shouldAllowImportingTsExtension(compilerOptions, currentSourceFile.fileName)) { const importOrExport = findAncestor(location, isImportDeclaration)?.importClause || findAncestor(location, or(isImportEqualsDeclaration, isExportDeclaration)); - if (!(importOrExport?.isTypeOnly || findAncestor(location, isImportTypeNode))) { + if (errorNode && !(importOrExport?.isTypeOnly || findAncestor(location, isImportTypeNode))) { const tsExtension = Debug.checkDefined(tryExtractTSExtension(moduleReference)); error(errorNode, Diagnostics.An_import_path_can_only_end_with_a_0_extension_when_allowImportingTsExtensions_is_enabled, tsExtension); } } if (sourceFile.symbol) { - if (resolvedModule.isExternalLibraryImport && !resolutionExtensionIsTSOrJson(resolvedModule.extension)) { + if (errorNode && resolvedModule.isExternalLibraryImport && !resolutionExtensionIsTSOrJson(resolvedModule.extension)) { errorOnImplicitAnyModule(/*isError*/ false, errorNode, currentSourceFile, mode, resolvedModule, moduleReference); } - if (moduleResolutionKind === ModuleResolutionKind.Node16 || moduleResolutionKind === ModuleResolutionKind.NodeNext) { + if (errorNode && (moduleResolutionKind === ModuleResolutionKind.Node16 || moduleResolutionKind === ModuleResolutionKind.NodeNext)) { const isSyncImport = (currentSourceFile.impliedNodeFormat === ModuleKind.CommonJS && !findAncestor(location, isImportCall)) || !!findAncestor(location, isImportEqualsDeclaration); const overrideHost = findAncestor(location, l => isImportTypeNode(l) || isExportDeclaration(l) || isImportDeclaration(l)) as ImportTypeNode | ImportDeclaration | ExportDeclaration | undefined; // An override clause will take effect for type-only imports and import types, and allows importing the types across formats, regardless of @@ -4656,7 +4656,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { // merged symbol is module declaration symbol combined with all augmentations return getMergedSymbol(sourceFile.symbol); } - if (moduleNotFoundError) { + if (errorNode && moduleNotFoundError) { // report errors only if it was requested error(errorNode, Diagnostics.File_0_is_not_a_module, sourceFile.fileName); } @@ -4678,6 +4678,10 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { } } + if (!errorNode) { + return undefined; + } + // May be an untyped module. If so, ignore resolutionDiagnostic. if (resolvedModule && !resolutionExtensionIsTSOrJson(resolvedModule.extension) && resolutionDiagnostic === undefined || resolutionDiagnostic === Diagnostics.Could_not_find_a_declaration_file_for_module_0_1_implicitly_has_an_any_type) { if (isForAugmentation) { @@ -32781,7 +32785,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { ? Diagnostics.Cannot_find_module_0_Did_you_mean_to_set_the_moduleResolution_option_to_nodenext_or_to_add_aliases_to_the_paths_option : Diagnostics.Cannot_find_module_0_or_its_corresponding_type_declarations; const specifier = getJSXRuntimeImportSpecifier(file, runtimeImportSpecifier); - const mod = resolveExternalModule(specifier || location!, runtimeImportSpecifier, errorMessage, location!); + const mod = resolveExternalModule(specifier || location!, runtimeImportSpecifier, errorMessage, location); const result = mod && mod !== unknownSymbol ? getMergedSymbol(resolveSymbol(mod)) : undefined; if (links) { links.jsxImplicitImportContainer = result || false; diff --git a/src/testRunner/unittests/tsc/composite.ts b/src/testRunner/unittests/tsc/composite.ts index 0a9dbfb7de6ff..b2d29ef5fbbea 100644 --- a/src/testRunner/unittests/tsc/composite.ts +++ b/src/testRunner/unittests/tsc/composite.ts @@ -114,4 +114,58 @@ describe("unittests:: tsc:: composite::", () => { }, ], }); + + verifyTsc({ + scenario: "composite", + subScenario: "synthetic jsx import of ESM module from CJS module no crash no jsx element", + fs: () => + loadProjectFromFiles({ + "/src/main.ts": "export default 42;", + "/tsconfig.json": jsonToReadableText({ + compilerOptions: { + composite: true, + module: "Node16", + jsx: "react-jsx", + jsxImportSource: "solid-js", + }, + }), + "/node_modules/solid-js/package.json": jsonToReadableText({ + name: "solid-js", + type: "module", + }), + "/node_modules/solid-js/jsx-runtime.d.ts": Utils.dedent` + export namespace JSX { + type IntrinsicElements = { div: {}; }; + } + `, + }), + commandLineArgs: [], + }); + + verifyTsc({ + scenario: "composite", + subScenario: "synthetic jsx import of ESM module from CJS module error on jsx element", + fs: () => + loadProjectFromFiles({ + "/src/main.tsx": "export default
;", + "/tsconfig.json": jsonToReadableText({ + compilerOptions: { + composite: true, + module: "Node16", + jsx: "react-jsx", + jsxImportSource: "solid-js", + }, + }), + "/node_modules/solid-js/package.json": jsonToReadableText({ + name: "solid-js", + type: "module", + }), + "/node_modules/solid-js/jsx-runtime.d.ts": Utils.dedent` + export namespace JSX { + type IntrinsicElements = { div: {}; }; + } + `, + }), + commandLineArgs: [], + }); }); diff --git a/tests/baselines/reference/tsc/composite/synthetic-jsx-import-of-ESM-module-from-CJS-module-error-on-jsx-element.js b/tests/baselines/reference/tsc/composite/synthetic-jsx-import-of-ESM-module-from-CJS-module-error-on-jsx-element.js new file mode 100644 index 0000000000000..4e0e39d7bd646 --- /dev/null +++ b/tests/baselines/reference/tsc/composite/synthetic-jsx-import-of-ESM-module-from-CJS-module-error-on-jsx-element.js @@ -0,0 +1,170 @@ +currentDirectory:: / useCaseSensitiveFileNames: false +Input:: +//// [/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; } +interface ReadonlyArray {} +declare const console: { log(msg: any): void; }; + +//// [/node_modules/solid-js/jsx-runtime.d.ts] +export namespace JSX { + type IntrinsicElements = { div: {}; }; +} + + +//// [/node_modules/solid-js/package.json] +{ + "name": "solid-js", + "type": "module" +} + +//// [/src/main.tsx] +export default
; + +//// [/tsconfig.json] +{ + "compilerOptions": { + "composite": true, + "module": "Node16", + "jsx": "react-jsx", + "jsxImportSource": "solid-js" + } +} + + + +Output:: +/lib/tsc +src/main.tsx:1:16 - error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("solid-js/jsx-runtime")' call instead. + To convert this file to an ECMAScript module, create a local package.json file with `{ "type": "module" }`. + +1 export default
; +   ~~~~~~ + + +Found 1 error in src/main.tsx:1 + +exitCode:: ExitStatus.DiagnosticsPresent_OutputsGenerated + + +//// [/src/main.d.ts] +declare const _default: any; +export default _default; + + +//// [/src/main.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const jsx_runtime_1 = require("solid-js/jsx-runtime"); +exports.default = (0, jsx_runtime_1.jsx)("div", {}); + + +//// [/tsconfig.tsbuildinfo] +{"program":{"fileNames":["./lib/lib.d.ts","./node_modules/solid-js/jsx-runtime.d.ts","./src/main.tsx"],"fileInfos":[{"version":"3858781397-/// \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; }\ninterface ReadonlyArray {}\ndeclare const console: { log(msg: any): void; };","affectsGlobalScope":true,"impliedFormat":1},{"version":"-3511680495-export namespace JSX {\n type IntrinsicElements = { div: {}; };\n}\n","impliedFormat":99},{"version":"-359851309-export default
;","signature":"2119670487-declare const _default: any;\nexport default _default;\n","impliedFormat":1}],"root":[1,3],"options":{"composite":true,"jsx":4,"jsxImportSource":"solid-js","module":100},"fileIdsList":[[2]],"referencedMap":[[3,1]],"semanticDiagnosticsPerFile":[[3,[{"start":15,"length":6,"code":1479,"category":1,"messageText":{"messageText":"The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import(\"solid-js/jsx-runtime\")' call instead.","category":1,"code":1479,"next":[{"messageText":"To convert this file to an ECMAScript module, create a local package.json file with `{ \"type\": \"module\" }`.","category":3,"code":1483}]}}]]],"latestChangedDtsFile":"./src/main.d.ts"},"version":"FakeTSVersion"} + +//// [/tsconfig.tsbuildinfo.readable.baseline.txt] +{ + "program": { + "fileNames": [ + "./lib/lib.d.ts", + "./node_modules/solid-js/jsx-runtime.d.ts", + "./src/main.tsx" + ], + "fileNamesList": [ + [ + "./node_modules/solid-js/jsx-runtime.d.ts" + ] + ], + "fileInfos": { + "./lib/lib.d.ts": { + "original": { + "version": "3858781397-/// \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; }\ninterface ReadonlyArray {}\ndeclare const console: { log(msg: any): void; };", + "affectsGlobalScope": true, + "impliedFormat": 1 + }, + "version": "3858781397-/// \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; }\ninterface ReadonlyArray {}\ndeclare const console: { log(msg: any): void; };", + "signature": "3858781397-/// \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; }\ninterface ReadonlyArray {}\ndeclare const console: { log(msg: any): void; };", + "affectsGlobalScope": true, + "impliedFormat": "commonjs" + }, + "./node_modules/solid-js/jsx-runtime.d.ts": { + "original": { + "version": "-3511680495-export namespace JSX {\n type IntrinsicElements = { div: {}; };\n}\n", + "impliedFormat": 99 + }, + "version": "-3511680495-export namespace JSX {\n type IntrinsicElements = { div: {}; };\n}\n", + "signature": "-3511680495-export namespace JSX {\n type IntrinsicElements = { div: {}; };\n}\n", + "impliedFormat": "esnext" + }, + "./src/main.tsx": { + "original": { + "version": "-359851309-export default
;", + "signature": "2119670487-declare const _default: any;\nexport default _default;\n", + "impliedFormat": 1 + }, + "version": "-359851309-export default
;", + "signature": "2119670487-declare const _default: any;\nexport default _default;\n", + "impliedFormat": "commonjs" + } + }, + "root": [ + [ + 1, + "./lib/lib.d.ts" + ], + [ + 3, + "./src/main.tsx" + ] + ], + "options": { + "composite": true, + "jsx": 4, + "jsxImportSource": "solid-js", + "module": 100 + }, + "referencedMap": { + "./src/main.tsx": [ + "./node_modules/solid-js/jsx-runtime.d.ts" + ] + }, + "semanticDiagnosticsPerFile": [ + [ + "./src/main.tsx", + [ + { + "start": 15, + "length": 6, + "code": 1479, + "category": 1, + "messageText": { + "messageText": "The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import(\"solid-js/jsx-runtime\")' call instead.", + "category": 1, + "code": 1479, + "next": [ + { + "messageText": "To convert this file to an ECMAScript module, create a local package.json file with `{ \"type\": \"module\" }`.", + "category": 3, + "code": 1483 + } + ] + } + } + ] + ] + ], + "latestChangedDtsFile": "./src/main.d.ts" + }, + "version": "FakeTSVersion", + "size": 1640 +} + diff --git a/tests/baselines/reference/tsc/composite/synthetic-jsx-import-of-ESM-module-from-CJS-module-no-crash-no-jsx-element.js b/tests/baselines/reference/tsc/composite/synthetic-jsx-import-of-ESM-module-from-CJS-module-no-crash-no-jsx-element.js new file mode 100644 index 0000000000000..06c331f0bb70b --- /dev/null +++ b/tests/baselines/reference/tsc/composite/synthetic-jsx-import-of-ESM-module-from-CJS-module-no-crash-no-jsx-element.js @@ -0,0 +1,135 @@ +currentDirectory:: / useCaseSensitiveFileNames: false +Input:: +//// [/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; } +interface ReadonlyArray {} +declare const console: { log(msg: any): void; }; + +//// [/node_modules/solid-js/jsx-runtime.d.ts] +export namespace JSX { + type IntrinsicElements = { div: {}; }; +} + + +//// [/node_modules/solid-js/package.json] +{ + "name": "solid-js", + "type": "module" +} + +//// [/src/main.ts] +export default 42; + +//// [/tsconfig.json] +{ + "compilerOptions": { + "composite": true, + "module": "Node16", + "jsx": "react-jsx", + "jsxImportSource": "solid-js" + } +} + + + +Output:: +/lib/tsc +exitCode:: ExitStatus.Success + + +//// [/src/main.d.ts] +declare const _default: 42; +export default _default; + + +//// [/src/main.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.default = 42; + + +//// [/tsconfig.tsbuildinfo] +{"program":{"fileNames":["./lib/lib.d.ts","./node_modules/solid-js/jsx-runtime.d.ts","./src/main.ts"],"fileInfos":[{"version":"3858781397-/// \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; }\ninterface ReadonlyArray {}\ndeclare const console: { log(msg: any): void; };","affectsGlobalScope":true,"impliedFormat":1},{"version":"-3511680495-export namespace JSX {\n type IntrinsicElements = { div: {}; };\n}\n","impliedFormat":99},{"version":"-1874019635-export default 42;","signature":"-5660511115-declare const _default: 42;\nexport default _default;\n","impliedFormat":1}],"root":[1,3],"options":{"composite":true,"jsx":4,"jsxImportSource":"solid-js","module":100},"fileIdsList":[[2]],"referencedMap":[[3,1]],"latestChangedDtsFile":"./src/main.d.ts"},"version":"FakeTSVersion"} + +//// [/tsconfig.tsbuildinfo.readable.baseline.txt] +{ + "program": { + "fileNames": [ + "./lib/lib.d.ts", + "./node_modules/solid-js/jsx-runtime.d.ts", + "./src/main.ts" + ], + "fileNamesList": [ + [ + "./node_modules/solid-js/jsx-runtime.d.ts" + ] + ], + "fileInfos": { + "./lib/lib.d.ts": { + "original": { + "version": "3858781397-/// \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; }\ninterface ReadonlyArray {}\ndeclare const console: { log(msg: any): void; };", + "affectsGlobalScope": true, + "impliedFormat": 1 + }, + "version": "3858781397-/// \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; }\ninterface ReadonlyArray {}\ndeclare const console: { log(msg: any): void; };", + "signature": "3858781397-/// \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; }\ninterface ReadonlyArray {}\ndeclare const console: { log(msg: any): void; };", + "affectsGlobalScope": true, + "impliedFormat": "commonjs" + }, + "./node_modules/solid-js/jsx-runtime.d.ts": { + "original": { + "version": "-3511680495-export namespace JSX {\n type IntrinsicElements = { div: {}; };\n}\n", + "impliedFormat": 99 + }, + "version": "-3511680495-export namespace JSX {\n type IntrinsicElements = { div: {}; };\n}\n", + "signature": "-3511680495-export namespace JSX {\n type IntrinsicElements = { div: {}; };\n}\n", + "impliedFormat": "esnext" + }, + "./src/main.ts": { + "original": { + "version": "-1874019635-export default 42;", + "signature": "-5660511115-declare const _default: 42;\nexport default _default;\n", + "impliedFormat": 1 + }, + "version": "-1874019635-export default 42;", + "signature": "-5660511115-declare const _default: 42;\nexport default _default;\n", + "impliedFormat": "commonjs" + } + }, + "root": [ + [ + 1, + "./lib/lib.d.ts" + ], + [ + 3, + "./src/main.ts" + ] + ], + "options": { + "composite": true, + "jsx": 4, + "jsxImportSource": "solid-js", + "module": 100 + }, + "referencedMap": { + "./src/main.ts": [ + "./node_modules/solid-js/jsx-runtime.d.ts" + ] + }, + "latestChangedDtsFile": "./src/main.d.ts" + }, + "version": "FakeTSVersion", + "size": 1079 +} + diff --git a/tests/baselines/reference/tscWatch/programUpdates/when-changing-`allowImportingTsExtensions`-of-config-file.js b/tests/baselines/reference/tscWatch/programUpdates/when-changing-`allowImportingTsExtensions`-of-config-file.js index cb72c9580b96d..518015404b4c9 100644 --- a/tests/baselines/reference/tscWatch/programUpdates/when-changing-`allowImportingTsExtensions`-of-config-file.js +++ b/tests/baselines/reference/tscWatch/programUpdates/when-changing-`allowImportingTsExtensions`-of-config-file.js @@ -47,12 +47,7 @@ DirectoryWatcher:: Added:: WatchInfo: /user/username/projects/myproject/node_mod Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /user/username/projects/myproject/node_modules/@types 1 undefined Type roots DirectoryWatcher:: Added:: WatchInfo: /user/username/projects/node_modules/@types 1 undefined Type roots Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /user/username/projects/node_modules/@types 1 undefined Type roots -b.ts:1:8 - error TS5097: An import path can only end with a '.ts' extension when 'allowImportingTsExtensions' is enabled. - -1 import "./a.ts"; -   ~~~~~~~~ - -[HH:MM:SS AM] Found 1 error. Watching for file changes. +[HH:MM:SS 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 diff --git a/tests/baselines/reference/tscWatch/resolveJsonModule/incremental-always-prefers-declaration-file-over-document.js b/tests/baselines/reference/tscWatch/resolveJsonModule/incremental-always-prefers-declaration-file-over-document.js index 09431de6cdf3d..52bd29bcd2017 100644 --- a/tests/baselines/reference/tscWatch/resolveJsonModule/incremental-always-prefers-declaration-file-over-document.js +++ b/tests/baselines/reference/tscWatch/resolveJsonModule/incremental-always-prefers-declaration-file-over-document.js @@ -52,7 +52,7 @@ var x = data_json_1.default; //// [/src/project/tsconfig.tsbuildinfo] -{"program":{"fileNames":["../../a/lib/lib.d.ts","./data.d.json.ts","./main.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,"impliedFormat":1},{"version":"2718060498-declare var val: string; export default val;","impliedFormat":1},{"version":"6961905452-import data from \"./data.json\"; let x: string = data;","impliedFormat":1}],"root":[2,3],"semanticDiagnosticsPerFile":[[3,[{"start":17,"length":13,"messageText":"Module './data.json' was resolved to '/src/project/data.d.json.ts', but '--allowArbitraryExtensions' is not set.","category":1,"code":6263}]]]},"version":"FakeTSVersion"} +{"program":{"fileNames":["../../a/lib/lib.d.ts","./data.d.json.ts","./main.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,"impliedFormat":1},{"version":"2718060498-declare var val: string; export default val;","impliedFormat":1},{"version":"6961905452-import data from \"./data.json\"; let x: string = data;","impliedFormat":1}],"root":[2,3],"fileIdsList":[[2]],"referencedMap":[[3,1]],"semanticDiagnosticsPerFile":[[3,[{"start":17,"length":13,"messageText":"Module './data.json' was resolved to '/src/project/data.d.json.ts', but '--allowArbitraryExtensions' is not set.","category":1,"code":6263}]]]},"version":"FakeTSVersion"} //// [/src/project/tsconfig.tsbuildinfo.readable.baseline.txt] { @@ -62,6 +62,11 @@ var x = data_json_1.default; "./data.d.json.ts", "./main.ts" ], + "fileNamesList": [ + [ + "./data.d.json.ts" + ] + ], "fileInfos": { "../../a/lib/lib.d.ts": { "original": { @@ -103,6 +108,11 @@ var x = data_json_1.default; "./main.ts" ] ], + "referencedMap": { + "./main.ts": [ + "./data.d.json.ts" + ] + }, "semanticDiagnosticsPerFile": [ [ "./main.ts", @@ -119,7 +129,7 @@ var x = data_json_1.default; ] }, "version": "FakeTSVersion", - "size": 954 + "size": 998 } From 908ddd029d32c00e982f65e2a85aae5b0b914136 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Burzy=C5=84ski?= Date: Sun, 26 May 2024 21:16:41 +0200 Subject: [PATCH 2/8] fixed missing module resolution errors --- src/compiler/checker.ts | 8 +++----- ...anging-`allowImportingTsExtensions`-of-config-file.js | 9 +++++++-- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 0db4facf7f9bd..56ced9ad94944 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -46812,6 +46812,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { } if (checkExternalImportOrExportDeclaration(node)) { const importClause = node.importClause; + const moduleExisted = resolveExternalModuleName(node, node.moduleSpecifier); if (importClause && !checkGrammarImportClause(importClause)) { if (importClause.name) { checkImportBinding(importClause); @@ -46824,11 +46825,8 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { checkExternalEmitHelpers(node, ExternalEmitHelpers.ImportStar); } } - else { - const moduleExisted = resolveExternalModuleName(node, node.moduleSpecifier); - if (moduleExisted) { - forEach(importClause.namedBindings.elements, checkImportBinding); - } + else if (moduleExisted) { + forEach(importClause.namedBindings.elements, checkImportBinding); } } } diff --git a/tests/baselines/reference/tscWatch/programUpdates/when-changing-`allowImportingTsExtensions`-of-config-file.js b/tests/baselines/reference/tscWatch/programUpdates/when-changing-`allowImportingTsExtensions`-of-config-file.js index 518015404b4c9..4385efd405643 100644 --- a/tests/baselines/reference/tscWatch/programUpdates/when-changing-`allowImportingTsExtensions`-of-config-file.js +++ b/tests/baselines/reference/tscWatch/programUpdates/when-changing-`allowImportingTsExtensions`-of-config-file.js @@ -1,7 +1,7 @@ currentDirectory:: /user/username/projects/myproject useCaseSensitiveFileNames: false Input:: //// [/user/username/projects/myproject/a.ts] - +export {}; //// [/user/username/projects/myproject/b.ts] import "./a.ts"; @@ -47,7 +47,12 @@ DirectoryWatcher:: Added:: WatchInfo: /user/username/projects/myproject/node_mod Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /user/username/projects/myproject/node_modules/@types 1 undefined Type roots DirectoryWatcher:: Added:: WatchInfo: /user/username/projects/node_modules/@types 1 undefined Type roots Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /user/username/projects/node_modules/@types 1 undefined Type roots -[HH:MM:SS AM] Found 0 errors. Watching for file changes. +b.ts:1:8 - error TS5097: An import path can only end with a '.ts' extension when 'allowImportingTsExtensions' is enabled. + +1 import "./a.ts"; +   ~~~~~~~~ + +[HH:MM:SS AM] Found 1 error. 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 From ca9be693eed7e84cf77947924f89f2afd9468aac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Burzy=C5=84ski?= Date: Mon, 27 May 2024 11:07:29 +0200 Subject: [PATCH 3/8] fixed errors on specifier-less imports --- src/compiler/checker.ts | 8 +-- src/testRunner/unittests/programApi.ts | 7 ++- .../unittests/tscWatch/programUpdates.ts | 2 +- .../allowsImportingTsExtension.errors.txt | 20 +++++-- .../reference/allowsImportingTsExtension.js | 6 +- .../allowsImportingTsExtension.symbols | 14 +++-- .../allowsImportingTsExtension.types | 2 + .../ambientExportDefaultErrors.errors.txt | 8 ++- .../amdDependencyCommentName4.errors.txt | 10 +++- ...autoAccessorDisallowedModifiers.errors.txt | 5 +- ...tsObjectAssignPrototypeProperty.errors.txt | 5 +- ...es6ImportWithoutFromClauseInEs5.errors.txt | 10 ++++ ...portWithoutFromClauseWithExport.errors.txt | 7 ++- .../reference/extendGlobalThis.errors.txt | 20 +++++++ .../reference/extendGlobalThis.types | 1 + .../jsxClassAttributeResolution.errors.txt | 28 --------- .../reference/jsxClassAttributeResolution.js | 2 +- .../jsxClassAttributeResolution.symbols | 4 +- .../jsxClassAttributeResolution.types | 8 +-- .../jsxFactoryQualifiedNameWithEs5.errors.txt | 16 ++++++ .../jsxFactoryQualifiedNameWithEs5.types | 6 +- ...tForSideEffectsNonExtantNoError.errors.txt | 13 +++++ .../reference/moduleAugmentationGlobal5.js | 29 ++++++++++ .../moduleAugmentationInAmbientModule5.js | 27 +++++++++ .../reference/moduleAugmentationsImports3.js | 50 ++++++++++++++++ .../reference/moduleAugmentationsImports4.js | 57 +++++++++++++++++++ ...lutionWithExtensions_unexpected.errors.txt | 14 +++++ ...utionWithExtensions_unexpected2.errors.txt | 14 +++++ ...ExportAssignment(module=node16).errors.txt | 5 +- ...portAssignment(module=nodenext).errors.txt | 5 +- .../reference/nodeModulesCJSEmit1.errors.txt | 5 +- .../reference/pathsValidation4.errors.txt | 7 ++- .../reference/pathsValidation5.errors.txt | 7 ++- .../reactJsxReactResolvedNodeNext.js | 2 +- .../reactJsxReactResolvedNodeNext.symbols | 6 +- .../reactJsxReactResolvedNodeNext.types | 2 +- .../reactJsxReactResolvedNodeNextEsm.js | 2 +- .../reactJsxReactResolvedNodeNextEsm.symbols | 6 +- .../reactJsxReactResolvedNodeNextEsm.types | 2 +- .../reference/systemModule9.errors.txt | 5 +- .../compiler/jsxClassAttributeResolution.tsx | 2 +- .../reactJsxReactResolvedNodeNext.tsx | 2 +- .../reactJsxReactResolvedNodeNextEsm.tsx | 2 +- .../typeOnly/allowsImportingTsExtension.ts | 2 + 44 files changed, 367 insertions(+), 88 deletions(-) create mode 100644 tests/baselines/reference/es6ImportWithoutFromClauseInEs5.errors.txt create mode 100644 tests/baselines/reference/extendGlobalThis.errors.txt delete mode 100644 tests/baselines/reference/jsxClassAttributeResolution.errors.txt create mode 100644 tests/baselines/reference/jsxFactoryQualifiedNameWithEs5.errors.txt create mode 100644 tests/baselines/reference/jsxImportForSideEffectsNonExtantNoError.errors.txt create mode 100644 tests/baselines/reference/moduleResolutionWithExtensions_unexpected.errors.txt create mode 100644 tests/baselines/reference/moduleResolutionWithExtensions_unexpected2.errors.txt diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 56ced9ad94944..13693e3660dbf 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -4568,9 +4568,9 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { } if (resolvedModule.resolvedUsingTsExtension && isDeclarationFileName(moduleReference)) { - const importOrExport = findAncestor(location, isImportDeclaration)?.importClause || + const importOrExport = findAncestor(location, isImportDeclaration) || findAncestor(location, or(isImportEqualsDeclaration, isExportDeclaration)); - if (errorNode && importOrExport && !importOrExport.isTypeOnly || findAncestor(location, isImportCall)) { + if (errorNode && importOrExport && !(isImportDeclaration(importOrExport) ? importOrExport.importClause : importOrExport)?.isTypeOnly || findAncestor(location, isImportCall)) { error( errorNode, Diagnostics.A_declaration_file_cannot_be_imported_without_import_type_Did_you_mean_to_import_an_implementation_file_0_instead, @@ -4579,9 +4579,9 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { } } else if (resolvedModule.resolvedUsingTsExtension && !shouldAllowImportingTsExtension(compilerOptions, currentSourceFile.fileName)) { - const importOrExport = findAncestor(location, isImportDeclaration)?.importClause || + const importOrExport = findAncestor(location, isImportDeclaration) || findAncestor(location, or(isImportEqualsDeclaration, isExportDeclaration)); - if (errorNode && !(importOrExport?.isTypeOnly || findAncestor(location, isImportTypeNode))) { + if (errorNode && !(importOrExport && (isImportDeclaration(importOrExport) ? importOrExport.importClause : importOrExport)?.isTypeOnly || findAncestor(location, isImportTypeNode))) { const tsExtension = Debug.checkDefined(tryExtractTSExtension(moduleReference)); error(errorNode, Diagnostics.An_import_path_can_only_end_with_a_0_extension_when_allowImportingTsExtensions_is_enabled, tsExtension); } diff --git a/src/testRunner/unittests/programApi.ts b/src/testRunner/unittests/programApi.ts index 44f391b869002..b7de742ba6a89 100644 --- a/src/testRunner/unittests/programApi.ts +++ b/src/testRunner/unittests/programApi.ts @@ -216,14 +216,17 @@ describe("unittests:: programApi:: Program.getTypeChecker / Program.getSemanticD const sourceFile = program.getSourceFile("main.ts")!; const typeChecker = program.getTypeChecker(); typeChecker.getSymbolAtLocation((sourceFile.statements[0] as ts.ImportDeclaration).moduleSpecifier); - assert.isEmpty(program.getSemanticDiagnostics()); + const diagnostics = program.getSemanticDiagnostics() + assert.equal(diagnostics.length, 1); + assert.equal(diagnostics[0].code, ts.Diagnostics.File_0_is_not_a_module.code); + assert.equal(diagnostics[0].messageText, "File '/module.d.ts' is not a module."); }); }); describe("unittests:: programApi:: CompilerOptions relative paths", () => { it("resolves relative paths by getCurrentDirectory", () => { const main = new documents.TextDocument("/main.ts", 'import "module";'); - const mod = new documents.TextDocument("/lib/module.ts", "declare const foo: any;"); + const mod = new documents.TextDocument("/lib/module.ts", "export declare const foo: any;"); const fs = vfs.createFromFileSystem(Harness.IO, /*ignoreCase*/ false, { documents: [main, mod], cwd: "/" }); const program = ts.createProgram(["./main.ts"], { diff --git a/src/testRunner/unittests/tscWatch/programUpdates.ts b/src/testRunner/unittests/tscWatch/programUpdates.ts index 600a45563b4a8..1c191f84644af 100644 --- a/src/testRunner/unittests/tscWatch/programUpdates.ts +++ b/src/testRunner/unittests/tscWatch/programUpdates.ts @@ -2129,7 +2129,7 @@ import { x } from "../b";`, sys: () => { const module1: File = { path: `/user/username/projects/myproject/a.ts`, - content: ``, + content: `export {};`, }; const module2: File = { path: `/user/username/projects/myproject/b.ts`, diff --git a/tests/baselines/reference/allowsImportingTsExtension.errors.txt b/tests/baselines/reference/allowsImportingTsExtension.errors.txt index d66055353d5da..45954b42e863e 100644 --- a/tests/baselines/reference/allowsImportingTsExtension.errors.txt +++ b/tests/baselines/reference/allowsImportingTsExtension.errors.txt @@ -1,9 +1,11 @@ b.ts(2,16): error TS5097: An import path can only end with a '.ts' extension when 'allowImportingTsExtensions' is enabled. -b.ts(3,30): error TS5097: An import path can only end with a '.ts' extension when 'allowImportingTsExtensions' is enabled. -b.ts(5,25): error TS5097: An import path can only end with a '.ts' extension when 'allowImportingTsExtensions' is enabled. +b.ts(3,8): error TS5097: An import path can only end with a '.ts' extension when 'allowImportingTsExtensions' is enabled. +b.ts(4,30): error TS5097: An import path can only end with a '.ts' extension when 'allowImportingTsExtensions' is enabled. +b.ts(6,25): error TS5097: An import path can only end with a '.ts' extension when 'allowImportingTsExtensions' is enabled. c.ts(2,16): error TS2846: A declaration file cannot be imported without 'import type'. Did you mean to import an implementation file './a.js' instead? -c.ts(3,30): error TS2846: A declaration file cannot be imported without 'import type'. Did you mean to import an implementation file './a.js' instead? -c.ts(5,25): error TS2846: A declaration file cannot be imported without 'import type'. Did you mean to import an implementation file './a.js' instead? +c.ts(3,8): error TS2846: A declaration file cannot be imported without 'import type'. Did you mean to import an implementation file './a.js' instead? +c.ts(4,30): error TS2846: A declaration file cannot be imported without 'import type'. Did you mean to import an implementation file './a.js' instead? +c.ts(6,25): error TS2846: A declaration file cannot be imported without 'import type'. Did you mean to import an implementation file './a.js' instead? ==== a.ts (0 errors) ==== @@ -12,10 +14,13 @@ c.ts(5,25): error TS2846: A declaration file cannot be imported without 'import ==== a.d.ts (0 errors) ==== export class A {} -==== b.ts (3 errors) ==== +==== b.ts (4 errors) ==== import type { A } from "./a.ts"; // ok import {} from "./a.ts"; // error ~~~~~~~~ +!!! error TS5097: An import path can only end with a '.ts' extension when 'allowImportingTsExtensions' is enabled. + import "./a.ts"; // error + ~~~~~~~~ !!! error TS5097: An import path can only end with a '.ts' extension when 'allowImportingTsExtensions' is enabled. import { type A as _A } from "./a.ts"; // error ~~~~~~~~ @@ -25,10 +30,13 @@ c.ts(5,25): error TS2846: A declaration file cannot be imported without 'import ~~~~~~~~ !!! error TS5097: An import path can only end with a '.ts' extension when 'allowImportingTsExtensions' is enabled. -==== c.ts (3 errors) ==== +==== c.ts (4 errors) ==== import type { A } from "./a.d.ts"; // ok import {} from "./a.d.ts"; // error ~~~~~~~~~~ +!!! error TS2846: A declaration file cannot be imported without 'import type'. Did you mean to import an implementation file './a.js' instead? + import "./a.d.ts"; // error + ~~~~~~~~~~ !!! error TS2846: A declaration file cannot be imported without 'import type'. Did you mean to import an implementation file './a.js' instead? import { type A as _A } from "./a.d.ts"; // error ~~~~~~~~~~ diff --git a/tests/baselines/reference/allowsImportingTsExtension.js b/tests/baselines/reference/allowsImportingTsExtension.js index 1eab22395c687..2141ec4434ff6 100644 --- a/tests/baselines/reference/allowsImportingTsExtension.js +++ b/tests/baselines/reference/allowsImportingTsExtension.js @@ -9,6 +9,7 @@ export class A {} //// [b.ts] import type { A } from "./a.ts"; // ok import {} from "./a.ts"; // error +import "./a.ts"; // error import { type A as _A } from "./a.ts"; // error type __A = import("./a.ts").A; // ok const aPromise = import("./a.ts"); // error @@ -16,6 +17,7 @@ const aPromise = import("./a.ts"); // error //// [c.ts] import type { A } from "./a.d.ts"; // ok import {} from "./a.d.ts"; // error +import "./a.d.ts"; // error import { type A as _A } from "./a.d.ts"; // error type __A = import("./a.d.ts").A; // ok const aPromise = import("./a.d.ts"); // error @@ -25,8 +27,8 @@ const aPromise = import("./a.d.ts"); // error export class A { } //// [b.js] +import "./a.ts"; // error const aPromise = import("./a.ts"); // error -export {}; //// [c.js] +import "./a.d.ts"; // error const aPromise = import("./a.d.ts"); // error -export {}; diff --git a/tests/baselines/reference/allowsImportingTsExtension.symbols b/tests/baselines/reference/allowsImportingTsExtension.symbols index a08e00fcf5407..caca7d76b6adb 100644 --- a/tests/baselines/reference/allowsImportingTsExtension.symbols +++ b/tests/baselines/reference/allowsImportingTsExtension.symbols @@ -13,16 +13,17 @@ import type { A } from "./a.ts"; // ok >A : Symbol(A, Decl(b.ts, 0, 13)) import {} from "./a.ts"; // error +import "./a.ts"; // error import { type A as _A } from "./a.ts"; // error >A : Symbol(A, Decl(a.ts, 0, 0)) ->_A : Symbol(_A, Decl(b.ts, 2, 8)) +>_A : Symbol(_A, Decl(b.ts, 3, 8)) type __A = import("./a.ts").A; // ok ->__A : Symbol(__A, Decl(b.ts, 2, 38)) +>__A : Symbol(__A, Decl(b.ts, 3, 38)) >A : Symbol(A, Decl(a.ts, 0, 0)) const aPromise = import("./a.ts"); // error ->aPromise : Symbol(aPromise, Decl(b.ts, 4, 5)) +>aPromise : Symbol(aPromise, Decl(b.ts, 5, 5)) >"./a.ts" : Symbol("a", Decl(a.ts, 0, 0)) === c.ts === @@ -30,15 +31,16 @@ import type { A } from "./a.d.ts"; // ok >A : Symbol(A, Decl(c.ts, 0, 13)) import {} from "./a.d.ts"; // error +import "./a.d.ts"; // error import { type A as _A } from "./a.d.ts"; // error >A : Symbol(A, Decl(a.ts, 0, 0)) ->_A : Symbol(_A, Decl(c.ts, 2, 8)) +>_A : Symbol(_A, Decl(c.ts, 3, 8)) type __A = import("./a.d.ts").A; // ok ->__A : Symbol(__A, Decl(c.ts, 2, 40)) +>__A : Symbol(__A, Decl(c.ts, 3, 40)) >A : Symbol(A, Decl(a.ts, 0, 0)) const aPromise = import("./a.d.ts"); // error ->aPromise : Symbol(aPromise, Decl(c.ts, 4, 5)) +>aPromise : Symbol(aPromise, Decl(c.ts, 5, 5)) >"./a.d.ts" : Symbol("a", Decl(a.ts, 0, 0)) diff --git a/tests/baselines/reference/allowsImportingTsExtension.types b/tests/baselines/reference/allowsImportingTsExtension.types index c1fe54623e545..c8ca0133a1267 100644 --- a/tests/baselines/reference/allowsImportingTsExtension.types +++ b/tests/baselines/reference/allowsImportingTsExtension.types @@ -16,6 +16,7 @@ import type { A } from "./a.ts"; // ok > : ^ import {} from "./a.ts"; // error +import "./a.ts"; // error import { type A as _A } from "./a.ts"; // error >A : typeof A > : ^^^^^^^^ @@ -40,6 +41,7 @@ import type { A } from "./a.d.ts"; // ok > : ^ import {} from "./a.d.ts"; // error +import "./a.d.ts"; // error import { type A as _A } from "./a.d.ts"; // error >A : typeof A > : ^^^^^^^^ diff --git a/tests/baselines/reference/ambientExportDefaultErrors.errors.txt b/tests/baselines/reference/ambientExportDefaultErrors.errors.txt index 4b31677c11549..c4d3781b9e4c7 100644 --- a/tests/baselines/reference/ambientExportDefaultErrors.errors.txt +++ b/tests/baselines/reference/ambientExportDefaultErrors.errors.txt @@ -1,16 +1,22 @@ +consumer.ts(4,8): error TS2307: Cannot find module 'foo' or its corresponding type declarations. +consumer.ts(6,8): error TS2307: Cannot find module 'foo2' or its corresponding type declarations. foo.d.ts(1,16): error TS2714: The expression of an export assignment must be an identifier or qualified name in an ambient context. foo2.d.ts(1,10): error TS2714: The expression of an export assignment must be an identifier or qualified name in an ambient context. indirection.d.ts(3,20): error TS2714: The expression of an export assignment must be an identifier or qualified name in an ambient context. indirection2.d.ts(3,14): error TS2714: The expression of an export assignment must be an identifier or qualified name in an ambient context. -==== consumer.ts (0 errors) ==== +==== consumer.ts (2 errors) ==== /// /// import "indirect"; import "foo"; + ~~~~~ +!!! error TS2307: Cannot find module 'foo' or its corresponding type declarations. import "indirect2"; import "foo2"; + ~~~~~~ +!!! error TS2307: Cannot find module 'foo2' or its corresponding type declarations. ==== foo.d.ts (1 errors) ==== export default 2 + 2; ~~~~~ diff --git a/tests/baselines/reference/amdDependencyCommentName4.errors.txt b/tests/baselines/reference/amdDependencyCommentName4.errors.txt index 6788d6c3b3286..ead5e629fa4a8 100644 --- a/tests/baselines/reference/amdDependencyCommentName4.errors.txt +++ b/tests/baselines/reference/amdDependencyCommentName4.errors.txt @@ -1,16 +1,20 @@ +amdDependencyCommentName4.ts(6,8): error TS2792: Cannot find module 'unaliasedModule1'. Did you mean to set the 'moduleResolution' option to 'nodenext', or to add aliases to the 'paths' option? amdDependencyCommentName4.ts(8,21): error TS2792: Cannot find module 'aliasedModule1'. Did you mean to set the 'moduleResolution' option to 'nodenext', or to add aliases to the 'paths' option? amdDependencyCommentName4.ts(11,26): error TS2792: Cannot find module 'aliasedModule2'. Did you mean to set the 'moduleResolution' option to 'nodenext', or to add aliases to the 'paths' option? amdDependencyCommentName4.ts(14,15): error TS2792: Cannot find module 'aliasedModule3'. Did you mean to set the 'moduleResolution' option to 'nodenext', or to add aliases to the 'paths' option? amdDependencyCommentName4.ts(17,21): error TS2792: Cannot find module 'aliasedModule4'. Did you mean to set the 'moduleResolution' option to 'nodenext', or to add aliases to the 'paths' option? +amdDependencyCommentName4.ts(20,8): error TS2792: Cannot find module 'unaliasedModule2'. Did you mean to set the 'moduleResolution' option to 'nodenext', or to add aliases to the 'paths' option? -==== amdDependencyCommentName4.ts (4 errors) ==== +==== amdDependencyCommentName4.ts (6 errors) ==== /// /// /// /// import "unaliasedModule1"; + ~~~~~~~~~~~~~~~~~~ +!!! error TS2792: Cannot find module 'unaliasedModule1'. Did you mean to set the 'moduleResolution' option to 'nodenext', or to add aliases to the 'paths' option? import r1 = require("aliasedModule1"); ~~~~~~~~~~~~~~~~ @@ -32,4 +36,6 @@ amdDependencyCommentName4.ts(17,21): error TS2792: Cannot find module 'aliasedMo !!! error TS2792: Cannot find module 'aliasedModule4'. Did you mean to set the 'moduleResolution' option to 'nodenext', or to add aliases to the 'paths' option? ns; - import "unaliasedModule2"; \ No newline at end of file + import "unaliasedModule2"; + ~~~~~~~~~~~~~~~~~~ +!!! error TS2792: Cannot find module 'unaliasedModule2'. Did you mean to set the 'moduleResolution' option to 'nodenext', or to add aliases to the 'paths' option? \ No newline at end of file diff --git a/tests/baselines/reference/autoAccessorDisallowedModifiers.errors.txt b/tests/baselines/reference/autoAccessorDisallowedModifiers.errors.txt index d9b841ee69892..4ab0938a6a6b6 100644 --- a/tests/baselines/reference/autoAccessorDisallowedModifiers.errors.txt +++ b/tests/baselines/reference/autoAccessorDisallowedModifiers.errors.txt @@ -23,6 +23,7 @@ autoAccessorDisallowedModifiers.ts(31,1): error TS1275: 'accessor' modifier can autoAccessorDisallowedModifiers.ts(32,1): error TS1275: 'accessor' modifier can only appear on a property declaration. autoAccessorDisallowedModifiers.ts(33,1): error TS1275: 'accessor' modifier can only appear on a property declaration. autoAccessorDisallowedModifiers.ts(34,1): error TS1275: 'accessor' modifier can only appear on a property declaration. +autoAccessorDisallowedModifiers.ts(34,17): error TS2792: Cannot find module 'x'. Did you mean to set the 'moduleResolution' option to 'nodenext', or to add aliases to the 'paths' option? autoAccessorDisallowedModifiers.ts(35,1): error TS1275: 'accessor' modifier can only appear on a property declaration. autoAccessorDisallowedModifiers.ts(35,25): error TS2792: Cannot find module 'x'. Did you mean to set the 'moduleResolution' option to 'nodenext', or to add aliases to the 'paths' option? autoAccessorDisallowedModifiers.ts(36,1): error TS1275: 'accessor' modifier can only appear on a property declaration. @@ -30,7 +31,7 @@ autoAccessorDisallowedModifiers.ts(37,1): error TS1275: 'accessor' modifier can autoAccessorDisallowedModifiers.ts(38,1): error TS1275: 'accessor' modifier can only appear on a property declaration. -==== autoAccessorDisallowedModifiers.ts (30 errors) ==== +==== autoAccessorDisallowedModifiers.ts (31 errors) ==== abstract class C1 { accessor accessor a: any; ~~~~~~~~ @@ -115,6 +116,8 @@ autoAccessorDisallowedModifiers.ts(38,1): error TS1275: 'accessor' modifier can accessor import "x"; ~~~~~~~~ !!! error TS1275: 'accessor' modifier can only appear on a property declaration. + ~~~ +!!! error TS2792: Cannot find module 'x'. Did you mean to set the 'moduleResolution' option to 'nodenext', or to add aliases to the 'paths' option? accessor import {} from "x"; ~~~~~~~~ !!! error TS1275: 'accessor' modifier can only appear on a property declaration. diff --git a/tests/baselines/reference/checkExportsObjectAssignPrototypeProperty.errors.txt b/tests/baselines/reference/checkExportsObjectAssignPrototypeProperty.errors.txt index 805191bcca68f..0ef83f725cd47 100644 --- a/tests/baselines/reference/checkExportsObjectAssignPrototypeProperty.errors.txt +++ b/tests/baselines/reference/checkExportsObjectAssignPrototypeProperty.errors.txt @@ -1,3 +1,4 @@ +validator.ts(1,8): error TS2307: Cannot find module './' or its corresponding type declarations. validator.ts(19,4): error TS2540: Cannot assign to 'readonlyProp' because it is a read-only property. validator.ts(20,4): error TS2540: Cannot assign to 'readonlyAccessor' because it is a read-only property. validator.ts(21,1): error TS2322: Type 'string' is not assignable to type 'number'. @@ -5,8 +6,10 @@ validator.ts(22,1): error TS2322: Type 'string' is not assignable to type 'numbe validator.ts(23,1): error TS2322: Type 'number' is not assignable to type 'string'. -==== validator.ts (5 errors) ==== +==== validator.ts (6 errors) ==== import "./"; + ~~~~ +!!! error TS2307: Cannot find module './' or its corresponding type declarations. import Person = require("./mod1"); diff --git a/tests/baselines/reference/es6ImportWithoutFromClauseInEs5.errors.txt b/tests/baselines/reference/es6ImportWithoutFromClauseInEs5.errors.txt new file mode 100644 index 0000000000000..cff1519cb0c69 --- /dev/null +++ b/tests/baselines/reference/es6ImportWithoutFromClauseInEs5.errors.txt @@ -0,0 +1,10 @@ +es6ImportWithoutFromClauseInEs5_1.ts(1,8): error TS2307: Cannot find module 'es6ImportWithoutFromClauseInEs5_0' or its corresponding type declarations. + + +==== es6ImportWithoutFromClauseInEs5_0.ts (0 errors) ==== + export var a = 10; + +==== es6ImportWithoutFromClauseInEs5_1.ts (1 errors) ==== + import "es6ImportWithoutFromClauseInEs5_0"; + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'es6ImportWithoutFromClauseInEs5_0' or its corresponding type declarations. \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportWithoutFromClauseWithExport.errors.txt b/tests/baselines/reference/es6ImportWithoutFromClauseWithExport.errors.txt index d40a9dee7f283..3eb75fd0443bc 100644 --- a/tests/baselines/reference/es6ImportWithoutFromClauseWithExport.errors.txt +++ b/tests/baselines/reference/es6ImportWithoutFromClauseWithExport.errors.txt @@ -1,10 +1,13 @@ client.ts(1,1): error TS1191: An import declaration cannot have modifiers. +client.ts(1,15): error TS2307: Cannot find module 'server' or its corresponding type declarations. ==== server.ts (0 errors) ==== export var a = 10; -==== client.ts (1 errors) ==== +==== client.ts (2 errors) ==== export import "server"; ~~~~~~ -!!! error TS1191: An import declaration cannot have modifiers. \ No newline at end of file +!!! error TS1191: An import declaration cannot have modifiers. + ~~~~~~~~ +!!! error TS2307: Cannot find module 'server' or its corresponding type declarations. \ No newline at end of file diff --git a/tests/baselines/reference/extendGlobalThis.errors.txt b/tests/baselines/reference/extendGlobalThis.errors.txt new file mode 100644 index 0000000000000..093beeb459cac --- /dev/null +++ b/tests/baselines/reference/extendGlobalThis.errors.txt @@ -0,0 +1,20 @@ +index.ts(1,8): error TS2307: Cannot find module './extention' or its corresponding type declarations. + + +==== extension.d.ts (0 errors) ==== + declare global { + namespace globalThis { + var test: string; + } + } + + export {} + +==== index.ts (1 errors) ==== + import "./extention"; + ~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './extention' or its corresponding type declarations. + + globalThis.tests = "a-b"; + console.log(globalThis.test.split("-")); + \ No newline at end of file diff --git a/tests/baselines/reference/extendGlobalThis.types b/tests/baselines/reference/extendGlobalThis.types index 499b561819e53..a3b91ff95e015 100644 --- a/tests/baselines/reference/extendGlobalThis.types +++ b/tests/baselines/reference/extendGlobalThis.types @@ -24,6 +24,7 @@ globalThis.tests = "a-b"; >globalThis.tests = "a-b" : "a-b" > : ^^^^^ >globalThis.tests : any +> : ^^^ >globalThis : typeof globalThis > : ^^^^^^^^^^^^^^^^^ >tests : any diff --git a/tests/baselines/reference/jsxClassAttributeResolution.errors.txt b/tests/baselines/reference/jsxClassAttributeResolution.errors.txt deleted file mode 100644 index 354df1ee641a2..0000000000000 --- a/tests/baselines/reference/jsxClassAttributeResolution.errors.txt +++ /dev/null @@ -1,28 +0,0 @@ -file.tsx(2,19): error TS2741: Property 'ref' is missing in type '{}' but required in type 'IntrinsicClassAttributesAlias'. - - -==== file.tsx (1 errors) ==== - class App {} - export const a = ; - ~~~ -!!! error TS2741: Property 'ref' is missing in type '{}' but required in type 'IntrinsicClassAttributesAlias'. -!!! related TS2728 node_modules/@types/react/index.d.ts:2:5: 'ref' is declared here. -==== node_modules/@types/react/package.json (0 errors) ==== - { - "name": "@types/react", - "version": "0.0.1", - "main": "", - "types": "index.d.ts", - } -==== node_modules/@types/react/index.d.ts (0 errors) ==== - interface IntrinsicClassAttributesAlias { - ref: T - } - declare namespace JSX { - type IntrinsicClassAttributes = IntrinsicClassAttributesAlias - } -==== node_modules/@types/react/jsx-runtime.d.ts (0 errors) ==== - import './'; -==== node_modules/@types/react/jsx-dev-runtime.d.ts (0 errors) ==== - import './'; - \ No newline at end of file diff --git a/tests/baselines/reference/jsxClassAttributeResolution.js b/tests/baselines/reference/jsxClassAttributeResolution.js index 7fa77a36324a3..5a22fb2a6e12b 100644 --- a/tests/baselines/reference/jsxClassAttributeResolution.js +++ b/tests/baselines/reference/jsxClassAttributeResolution.js @@ -14,7 +14,7 @@ export const a = ; interface IntrinsicClassAttributesAlias { ref: T } -declare namespace JSX { +export declare namespace JSX { type IntrinsicClassAttributes = IntrinsicClassAttributesAlias } //// [jsx-runtime.d.ts] diff --git a/tests/baselines/reference/jsxClassAttributeResolution.symbols b/tests/baselines/reference/jsxClassAttributeResolution.symbols index de0ed218a0b6c..673dce6ce3896 100644 --- a/tests/baselines/reference/jsxClassAttributeResolution.symbols +++ b/tests/baselines/reference/jsxClassAttributeResolution.symbols @@ -18,11 +18,11 @@ interface IntrinsicClassAttributesAlias { >ref : Symbol(IntrinsicClassAttributesAlias.ref, Decl(index.d.ts, 0, 44)) >T : Symbol(T, Decl(index.d.ts, 0, 40)) } -declare namespace JSX { +export declare namespace JSX { >JSX : Symbol(JSX, Decl(index.d.ts, 2, 1)) type IntrinsicClassAttributes = IntrinsicClassAttributesAlias ->IntrinsicClassAttributes : Symbol(IntrinsicClassAttributes, Decl(index.d.ts, 3, 23)) +>IntrinsicClassAttributes : Symbol(IntrinsicClassAttributes, Decl(index.d.ts, 3, 30)) >T : Symbol(T, Decl(index.d.ts, 4, 34)) >IntrinsicClassAttributesAlias : Symbol(IntrinsicClassAttributesAlias, Decl(index.d.ts, 0, 0)) >T : Symbol(T, Decl(index.d.ts, 4, 34)) diff --git a/tests/baselines/reference/jsxClassAttributeResolution.types b/tests/baselines/reference/jsxClassAttributeResolution.types index d8b384531b466..c440d9679c2d2 100644 --- a/tests/baselines/reference/jsxClassAttributeResolution.types +++ b/tests/baselines/reference/jsxClassAttributeResolution.types @@ -6,10 +6,8 @@ class App {} > : ^^^ export const a = ; ->a : any -> : ^^^ -> : any -> : ^^^ +>a : error +> : error >App : typeof App > : ^^^^^^^^^^ >App : typeof App @@ -21,7 +19,7 @@ interface IntrinsicClassAttributesAlias { >ref : T > : ^ } -declare namespace JSX { +export declare namespace JSX { type IntrinsicClassAttributes = IntrinsicClassAttributesAlias >IntrinsicClassAttributes : IntrinsicClassAttributes > : ^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/baselines/reference/jsxFactoryQualifiedNameWithEs5.errors.txt b/tests/baselines/reference/jsxFactoryQualifiedNameWithEs5.errors.txt new file mode 100644 index 0000000000000..13eb01d3431ca --- /dev/null +++ b/tests/baselines/reference/jsxFactoryQualifiedNameWithEs5.errors.txt @@ -0,0 +1,16 @@ +index.tsx(1,8): error TS2307: Cannot find module './jsx' or its corresponding type declarations. + + +==== index.tsx (1 errors) ==== + import "./jsx"; + ~~~~~~~ +!!! error TS2307: Cannot find module './jsx' or its corresponding type declarations. + + var skate: any; + const React = { createElement: skate.h }; + + class Component { + renderCallback() { + return
test
; + } + }; \ No newline at end of file diff --git a/tests/baselines/reference/jsxFactoryQualifiedNameWithEs5.types b/tests/baselines/reference/jsxFactoryQualifiedNameWithEs5.types index c9a019263fe47..dbb1eed353c38 100644 --- a/tests/baselines/reference/jsxFactoryQualifiedNameWithEs5.types +++ b/tests/baselines/reference/jsxFactoryQualifiedNameWithEs5.types @@ -5,6 +5,7 @@ import "./jsx"; var skate: any; >skate : any +> : ^^^ const React = { createElement: skate.h }; >React : { createElement: any; } @@ -12,7 +13,9 @@ const React = { createElement: skate.h }; >{ createElement: skate.h } : { createElement: any; } > : ^^^^^^^^^^^^^^^^^^^^^^^ >createElement : any +> : ^^^ >skate.h : any +> : ^^^ >skate : any > : ^^^ >h : any @@ -27,7 +30,8 @@ class Component { > : ^^^^^^^^^ return
test
; ->
test
: error +>
test
: any +> : ^^^ >div : any > : ^^^ >div : any diff --git a/tests/baselines/reference/jsxImportForSideEffectsNonExtantNoError.errors.txt b/tests/baselines/reference/jsxImportForSideEffectsNonExtantNoError.errors.txt new file mode 100644 index 0000000000000..34182361b1ba1 --- /dev/null +++ b/tests/baselines/reference/jsxImportForSideEffectsNonExtantNoError.errors.txt @@ -0,0 +1,13 @@ +jsxImportForSideEffectsNonExtantNoError.tsx(4,8): error TS2307: Cannot find module './App.css' or its corresponding type declarations. + + +==== jsxImportForSideEffectsNonExtantNoError.tsx (1 errors) ==== + /// + import * as React from "react"; + + import "./App.css"; // doesn't actually exist + ~~~~~~~~~~~ +!!! error TS2307: Cannot find module './App.css' or its corresponding type declarations. + + const tag =
; + \ No newline at end of file diff --git a/tests/baselines/reference/moduleAugmentationGlobal5.js b/tests/baselines/reference/moduleAugmentationGlobal5.js index 5886a438f9da5..88ce41cbe2b6f 100644 --- a/tests/baselines/reference/moduleAugmentationGlobal5.js +++ b/tests/baselines/reference/moduleAugmentationGlobal5.js @@ -32,3 +32,32 @@ require("B"); //// [f3.d.ts] import "A"; import "B"; + + +//// [DtsFileErrors] + + +f3.d.ts(1,8): error TS2307: Cannot find module 'A' or its corresponding type declarations. +f3.d.ts(2,8): error TS2307: Cannot find module 'B' or its corresponding type declarations. + + +==== f3.d.ts (2 errors) ==== + import "A"; + ~~~ +!!! error TS2307: Cannot find module 'A' or its corresponding type declarations. + import "B"; + ~~~ +!!! error TS2307: Cannot find module 'B' or its corresponding type declarations. + +==== f1.d.ts (0 errors) ==== + declare module "A" { + global { + interface Something {x} + } + } +==== f2.d.ts (0 errors) ==== + declare module "B" { + global { + interface Something {y} + } + } \ No newline at end of file diff --git a/tests/baselines/reference/moduleAugmentationInAmbientModule5.js b/tests/baselines/reference/moduleAugmentationInAmbientModule5.js index 923100c74d22b..347fdc1977b2b 100644 --- a/tests/baselines/reference/moduleAugmentationInAmbientModule5.js +++ b/tests/baselines/reference/moduleAugmentationInAmbientModule5.js @@ -33,3 +33,30 @@ var y = x.getA().x; //// [f.d.ts] import "array"; + + +//// [DtsFileErrors] + + +f.d.ts(1,8): error TS2307: Cannot find module 'array' or its corresponding type declarations. + + +==== f.d.ts (1 errors) ==== + import "array"; + ~~~~~~~ +!!! error TS2307: Cannot find module 'array' or its corresponding type declarations. + +==== array.d.ts (0 errors) ==== + declare module "A" { + class A { x: number; } + } + + declare module "array" { + import {A} from "A"; + global { + interface Array { + getA(): A; + } + } + } + \ No newline at end of file diff --git a/tests/baselines/reference/moduleAugmentationsImports3.js b/tests/baselines/reference/moduleAugmentationsImports3.js index 14ae0f65f2ffa..100254136314d 100644 --- a/tests/baselines/reference/moduleAugmentationsImports3.js +++ b/tests/baselines/reference/moduleAugmentationsImports3.js @@ -106,3 +106,53 @@ declare module "main" { import "D"; import "e"; } + + +//// [DtsFileErrors] + + +f.d.ts(20,12): error TS2792: Cannot find module 'D'. Did you mean to set the 'moduleResolution' option to 'nodenext', or to add aliases to the 'paths' option? + + +==== f.d.ts (1 errors) ==== + /// + declare module "a" { + export class A { + } + } + declare module "b" { + export class B { + x: number; + } + } + declare module "e" { + import { Cls } from "C"; + module "a" { + interface A { + getCls(): Cls; + } + } + } + declare module "main" { + import "D"; + ~~~ +!!! error TS2792: Cannot find module 'D'. Did you mean to set the 'moduleResolution' option to 'nodenext', or to add aliases to the 'paths' option? + import "e"; + } + +==== c.d.ts (0 errors) ==== + declare module "C" { + class Cls {y: string; } + } + +==== d.d.ts (0 errors) ==== + declare module "D" { + import {A} from "a"; + import {B} from "b"; + module "a" { + interface A { + getB(): B; + } + } + } + \ No newline at end of file diff --git a/tests/baselines/reference/moduleAugmentationsImports4.js b/tests/baselines/reference/moduleAugmentationsImports4.js index d009f154ad0fd..9bc575724e16c 100644 --- a/tests/baselines/reference/moduleAugmentationsImports4.js +++ b/tests/baselines/reference/moduleAugmentationsImports4.js @@ -93,3 +93,60 @@ declare module "main" { import "D"; import "E"; } + + +//// [DtsFileErrors] + + +f.d.ts(11,12): error TS2792: Cannot find module 'D'. Did you mean to set the 'moduleResolution' option to 'nodenext', or to add aliases to the 'paths' option? +f.d.ts(12,12): error TS2792: Cannot find module 'E'. Did you mean to set the 'moduleResolution' option to 'nodenext', or to add aliases to the 'paths' option? + + +==== f.d.ts (2 errors) ==== + declare module "a" { + export class A { + } + } + declare module "b" { + export class B { + x: number; + } + } + declare module "main" { + import "D"; + ~~~ +!!! error TS2792: Cannot find module 'D'. Did you mean to set the 'moduleResolution' option to 'nodenext', or to add aliases to the 'paths' option? + import "E"; + ~~~ +!!! error TS2792: Cannot find module 'E'. Did you mean to set the 'moduleResolution' option to 'nodenext', or to add aliases to the 'paths' option? + } + +==== c.d.ts (0 errors) ==== + declare module "C" { + class Cls {y: string; } + } + +==== d.d.ts (0 errors) ==== + declare module "D" { + import {A} from "a"; + import {B} from "b"; + module "a" { + interface A { + getB(): B; + } + } + } + +==== e.d.ts (0 errors) ==== + /// + declare module "E" { + import {A} from "a"; + import {Cls} from "C"; + + module "a" { + interface A { + getCls(): Cls; + } + } + } + \ No newline at end of file diff --git a/tests/baselines/reference/moduleResolutionWithExtensions_unexpected.errors.txt b/tests/baselines/reference/moduleResolutionWithExtensions_unexpected.errors.txt new file mode 100644 index 0000000000000..f677838225b10 --- /dev/null +++ b/tests/baselines/reference/moduleResolutionWithExtensions_unexpected.errors.txt @@ -0,0 +1,14 @@ +/a.ts(1,8): error TS2307: Cannot find module 'normalize.css' or its corresponding type declarations. + + +==== /a.ts (1 errors) ==== + import "normalize.css"; + ~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'normalize.css' or its corresponding type declarations. + +==== /node_modules/normalize.css/normalize.css (0 errors) ==== + This file is not read. + +==== /node_modules/normalize.css/package.json (0 errors) ==== + { "main": "normalize.css" } + \ No newline at end of file diff --git a/tests/baselines/reference/moduleResolutionWithExtensions_unexpected2.errors.txt b/tests/baselines/reference/moduleResolutionWithExtensions_unexpected2.errors.txt new file mode 100644 index 0000000000000..0171f5e0b0c6e --- /dev/null +++ b/tests/baselines/reference/moduleResolutionWithExtensions_unexpected2.errors.txt @@ -0,0 +1,14 @@ +/a.ts(1,8): error TS2307: Cannot find module 'foo' or its corresponding type declarations. + + +==== /a.ts (1 errors) ==== + import "foo"; + ~~~~~ +!!! error TS2307: Cannot find module 'foo' or its corresponding type declarations. + +==== /node_modules/foo/foo.js (0 errors) ==== + This file is not read. + +==== /node_modules/foo/package.json (0 errors) ==== + { "types": "foo.js" } + \ No newline at end of file diff --git a/tests/baselines/reference/nodeModulesAllowJsExportAssignment(module=node16).errors.txt b/tests/baselines/reference/nodeModulesAllowJsExportAssignment(module=node16).errors.txt index 15bd70e4c2e9d..92187a7e27b92 100644 --- a/tests/baselines/reference/nodeModulesAllowJsExportAssignment(module=node16).errors.txt +++ b/tests/baselines/reference/nodeModulesAllowJsExportAssignment(module=node16).errors.txt @@ -1,3 +1,4 @@ +file.js(2,8): error TS2307: Cannot find module 'fs' or its corresponding type declarations. file.js(4,1): error TS2580: Cannot find name 'module'. Do you need to install type definitions for node? Try `npm i --save-dev @types/node`. index.js(3,1): error TS1203: Export assignment cannot be used when targeting ECMAScript modules. Consider using 'export default' or another module format instead. index.js(3,1): error TS8003: 'export =' can only be used in TypeScript files. @@ -22,9 +23,11 @@ subfolder/index.js(3,1): error TS8003: 'export =' can only be used in TypeScript !!! error TS1203: Export assignment cannot be used when targeting ECMAScript modules. Consider using 'export default' or another module format instead. ~~~~~~~~~~~ !!! error TS8003: 'export =' can only be used in TypeScript files. -==== file.js (1 errors) ==== +==== file.js (2 errors) ==== // esm format file import "fs"; + ~~~~ +!!! error TS2307: Cannot find module 'fs' or its corresponding type declarations. const a = {}; module.exports = a; ~~~~~~ diff --git a/tests/baselines/reference/nodeModulesAllowJsExportAssignment(module=nodenext).errors.txt b/tests/baselines/reference/nodeModulesAllowJsExportAssignment(module=nodenext).errors.txt index 15bd70e4c2e9d..92187a7e27b92 100644 --- a/tests/baselines/reference/nodeModulesAllowJsExportAssignment(module=nodenext).errors.txt +++ b/tests/baselines/reference/nodeModulesAllowJsExportAssignment(module=nodenext).errors.txt @@ -1,3 +1,4 @@ +file.js(2,8): error TS2307: Cannot find module 'fs' or its corresponding type declarations. file.js(4,1): error TS2580: Cannot find name 'module'. Do you need to install type definitions for node? Try `npm i --save-dev @types/node`. index.js(3,1): error TS1203: Export assignment cannot be used when targeting ECMAScript modules. Consider using 'export default' or another module format instead. index.js(3,1): error TS8003: 'export =' can only be used in TypeScript files. @@ -22,9 +23,11 @@ subfolder/index.js(3,1): error TS8003: 'export =' can only be used in TypeScript !!! error TS1203: Export assignment cannot be used when targeting ECMAScript modules. Consider using 'export default' or another module format instead. ~~~~~~~~~~~ !!! error TS8003: 'export =' can only be used in TypeScript files. -==== file.js (1 errors) ==== +==== file.js (2 errors) ==== // esm format file import "fs"; + ~~~~ +!!! error TS2307: Cannot find module 'fs' or its corresponding type declarations. const a = {}; module.exports = a; ~~~~~~ diff --git a/tests/baselines/reference/nodeModulesCJSEmit1.errors.txt b/tests/baselines/reference/nodeModulesCJSEmit1.errors.txt index 5e3604d311b92..8d9a1b4e1264a 100644 --- a/tests/baselines/reference/nodeModulesCJSEmit1.errors.txt +++ b/tests/baselines/reference/nodeModulesCJSEmit1.errors.txt @@ -1,3 +1,4 @@ +/3.cjs(1,8): error TS2307: Cannot find module 'foo' or its corresponding type declarations. /3.cjs(2,1): error TS2304: Cannot find name 'exports'. /5.cjs(2,8): error TS1192: Module '"/3"' has no default export. @@ -8,8 +9,10 @@ ==== /2.cjs (0 errors) ==== exports.foo = 0; -==== /3.cjs (1 errors) ==== +==== /3.cjs (2 errors) ==== import "foo"; + ~~~~~ +!!! error TS2307: Cannot find module 'foo' or its corresponding type declarations. exports.foo = {}; ~~~~~~~ !!! error TS2304: Cannot find name 'exports'. diff --git a/tests/baselines/reference/pathsValidation4.errors.txt b/tests/baselines/reference/pathsValidation4.errors.txt index 386079a29503b..6a449b9cdf14e 100644 --- a/tests/baselines/reference/pathsValidation4.errors.txt +++ b/tests/baselines/reference/pathsValidation4.errors.txt @@ -1,6 +1,7 @@ tsconfig.json(6,11): error TS5061: Pattern '@interface/**/*' can have at most one '*' character. tsconfig.json(7,11): error TS5061: Pattern '@service/**/*' can have at most one '*' character. tsconfig.json(7,29): error TS5062: Substitution './src/service/**/*' in pattern '@service/**/*' can have at most one '*' character. +src/main.ts(1,8): error TS2307: Cannot find module 'someModule' or its corresponding type declarations. ==== tsconfig.json (3 errors) ==== @@ -22,5 +23,7 @@ tsconfig.json(7,29): error TS5062: Substitution './src/service/**/*' in pattern } } -==== src/main.ts (0 errors) ==== - import 'someModule'; \ No newline at end of file +==== src/main.ts (1 errors) ==== + import 'someModule'; + ~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'someModule' or its corresponding type declarations. \ No newline at end of file diff --git a/tests/baselines/reference/pathsValidation5.errors.txt b/tests/baselines/reference/pathsValidation5.errors.txt index 80eaf2d68f6cb..c61e736a2b871 100644 --- a/tests/baselines/reference/pathsValidation5.errors.txt +++ b/tests/baselines/reference/pathsValidation5.errors.txt @@ -1,6 +1,7 @@ tsconfig.json(5,26): error TS5090: Non-relative paths are not allowed when 'baseUrl' is not set. Did you forget a leading './'? tsconfig.json(6,19): error TS5090: Non-relative paths are not allowed when 'baseUrl' is not set. Did you forget a leading './'? tsconfig.json(7,23): error TS5090: Non-relative paths are not allowed when 'baseUrl' is not set. Did you forget a leading './'? +src/main.ts(1,8): error TS2307: Cannot find module 'someModule' or its corresponding type declarations. ==== tsconfig.json (3 errors) ==== @@ -21,5 +22,7 @@ tsconfig.json(7,23): error TS5090: Non-relative paths are not allowed when 'base } } -==== src/main.ts (0 errors) ==== - import 'someModule'; \ No newline at end of file +==== src/main.ts (1 errors) ==== + import 'someModule'; + ~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'someModule' or its corresponding type declarations. \ No newline at end of file diff --git a/tests/baselines/reference/reactJsxReactResolvedNodeNext.js b/tests/baselines/reference/reactJsxReactResolvedNodeNext.js index f36fdc66c2a5b..c87ced322e9ef 100644 --- a/tests/baselines/reference/reactJsxReactResolvedNodeNext.js +++ b/tests/baselines/reference/reactJsxReactResolvedNodeNext.js @@ -10,7 +10,7 @@ export const a =
; "types": "index.d.ts", } //// [index.d.ts] -declare namespace JSX { +export declare namespace JSX { interface IntrinsicElements { [x: string]: any; } } //// [jsx-runtime.d.ts] diff --git a/tests/baselines/reference/reactJsxReactResolvedNodeNext.symbols b/tests/baselines/reference/reactJsxReactResolvedNodeNext.symbols index e2ddca8d016e8..0923e46c6a196 100644 --- a/tests/baselines/reference/reactJsxReactResolvedNodeNext.symbols +++ b/tests/baselines/reference/reactJsxReactResolvedNodeNext.symbols @@ -3,15 +3,13 @@ === file.tsx === export const a =
; >a : Symbol(a, Decl(file.tsx, 0, 12)) ->div : Symbol(JSX.IntrinsicElements.__index, Decl(index.d.ts, 1, 33)) ->div : Symbol(JSX.IntrinsicElements.__index, Decl(index.d.ts, 1, 33)) === node_modules/@types/react/index.d.ts === -declare namespace JSX { +export declare namespace JSX { >JSX : Symbol(JSX, Decl(index.d.ts, 0, 0)) interface IntrinsicElements { [x: string]: any; } ->IntrinsicElements : Symbol(IntrinsicElements, Decl(index.d.ts, 0, 23)) +>IntrinsicElements : Symbol(IntrinsicElements, Decl(index.d.ts, 0, 30)) >x : Symbol(x, Decl(index.d.ts, 1, 35)) } === node_modules/@types/react/jsx-runtime.d.ts === diff --git a/tests/baselines/reference/reactJsxReactResolvedNodeNext.types b/tests/baselines/reference/reactJsxReactResolvedNodeNext.types index 0e14708fd9eff..48971205e1ae4 100644 --- a/tests/baselines/reference/reactJsxReactResolvedNodeNext.types +++ b/tests/baselines/reference/reactJsxReactResolvedNodeNext.types @@ -10,7 +10,7 @@ export const a =
; > : ^^^ === node_modules/@types/react/index.d.ts === -declare namespace JSX { +export declare namespace JSX { interface IntrinsicElements { [x: string]: any; } >x : string > : ^^^^^^ diff --git a/tests/baselines/reference/reactJsxReactResolvedNodeNextEsm.js b/tests/baselines/reference/reactJsxReactResolvedNodeNextEsm.js index 834a8fa145c4e..cd40b8e423c8f 100644 --- a/tests/baselines/reference/reactJsxReactResolvedNodeNextEsm.js +++ b/tests/baselines/reference/reactJsxReactResolvedNodeNextEsm.js @@ -18,7 +18,7 @@ export const a =
; } } //// [index.d.ts] -declare namespace JSX { +export declare namespace JSX { interface IntrinsicElements { [x: string]: any; } } //// [jsx-runtime.d.ts] diff --git a/tests/baselines/reference/reactJsxReactResolvedNodeNextEsm.symbols b/tests/baselines/reference/reactJsxReactResolvedNodeNextEsm.symbols index 5c5343253c544..6ac83a0ce6b27 100644 --- a/tests/baselines/reference/reactJsxReactResolvedNodeNextEsm.symbols +++ b/tests/baselines/reference/reactJsxReactResolvedNodeNextEsm.symbols @@ -3,15 +3,13 @@ === file.tsx === export const a =
; >a : Symbol(a, Decl(file.tsx, 0, 12)) ->div : Symbol(JSX.IntrinsicElements.__index, Decl(index.d.ts, 1, 33)) ->div : Symbol(JSX.IntrinsicElements.__index, Decl(index.d.ts, 1, 33)) === node_modules/@types/react/index.d.ts === -declare namespace JSX { +export declare namespace JSX { >JSX : Symbol(JSX, Decl(index.d.ts, 0, 0)) interface IntrinsicElements { [x: string]: any; } ->IntrinsicElements : Symbol(IntrinsicElements, Decl(index.d.ts, 0, 23)) +>IntrinsicElements : Symbol(IntrinsicElements, Decl(index.d.ts, 0, 30)) >x : Symbol(x, Decl(index.d.ts, 1, 35)) } === node_modules/@types/react/jsx-runtime.d.ts === diff --git a/tests/baselines/reference/reactJsxReactResolvedNodeNextEsm.types b/tests/baselines/reference/reactJsxReactResolvedNodeNextEsm.types index 5220535071b8b..bb074d664595d 100644 --- a/tests/baselines/reference/reactJsxReactResolvedNodeNextEsm.types +++ b/tests/baselines/reference/reactJsxReactResolvedNodeNextEsm.types @@ -10,7 +10,7 @@ export const a =
; > : ^^^ === node_modules/@types/react/index.d.ts === -declare namespace JSX { +export declare namespace JSX { interface IntrinsicElements { [x: string]: any; } >x : string > : ^^^^^^ diff --git a/tests/baselines/reference/systemModule9.errors.txt b/tests/baselines/reference/systemModule9.errors.txt index be5991350e5de..7dd2738dd6738 100644 --- a/tests/baselines/reference/systemModule9.errors.txt +++ b/tests/baselines/reference/systemModule9.errors.txt @@ -1,12 +1,13 @@ systemModule9.ts(1,21): error TS2792: Cannot find module 'file1'. Did you mean to set the 'moduleResolution' option to 'nodenext', or to add aliases to the 'paths' option? systemModule9.ts(2,25): error TS2792: Cannot find module 'file2'. Did you mean to set the 'moduleResolution' option to 'nodenext', or to add aliases to the 'paths' option? systemModule9.ts(3,15): error TS2792: Cannot find module 'file3'. Did you mean to set the 'moduleResolution' option to 'nodenext', or to add aliases to the 'paths' option? +systemModule9.ts(4,8): error TS2792: Cannot find module 'file4'. Did you mean to set the 'moduleResolution' option to 'nodenext', or to add aliases to the 'paths' option? systemModule9.ts(5,25): error TS2792: Cannot find module 'file5'. Did you mean to set the 'moduleResolution' option to 'nodenext', or to add aliases to the 'paths' option? systemModule9.ts(6,22): error TS2792: Cannot find module 'file6'. Did you mean to set the 'moduleResolution' option to 'nodenext', or to add aliases to the 'paths' option? systemModule9.ts(16,15): error TS2792: Cannot find module 'file7'. Did you mean to set the 'moduleResolution' option to 'nodenext', or to add aliases to the 'paths' option? -==== systemModule9.ts (6 errors) ==== +==== systemModule9.ts (7 errors) ==== import * as ns from 'file1'; ~~~~~~~ !!! error TS2792: Cannot find module 'file1'. Did you mean to set the 'moduleResolution' option to 'nodenext', or to add aliases to the 'paths' option? @@ -17,6 +18,8 @@ systemModule9.ts(16,15): error TS2792: Cannot find module 'file7'. Did you mean ~~~~~~~ !!! error TS2792: Cannot find module 'file3'. Did you mean to set the 'moduleResolution' option to 'nodenext', or to add aliases to the 'paths' option? import 'file4' + ~~~~~~~ +!!! error TS2792: Cannot find module 'file4'. Did you mean to set the 'moduleResolution' option to 'nodenext', or to add aliases to the 'paths' option? import e, * as ns2 from 'file5'; ~~~~~~~ !!! error TS2792: Cannot find module 'file5'. Did you mean to set the 'moduleResolution' option to 'nodenext', or to add aliases to the 'paths' option? diff --git a/tests/cases/compiler/jsxClassAttributeResolution.tsx b/tests/cases/compiler/jsxClassAttributeResolution.tsx index 32263ecd794ee..f18ae3d3d5d84 100644 --- a/tests/cases/compiler/jsxClassAttributeResolution.tsx +++ b/tests/cases/compiler/jsxClassAttributeResolution.tsx @@ -14,7 +14,7 @@ export const a = ; interface IntrinsicClassAttributesAlias { ref: T } -declare namespace JSX { +export declare namespace JSX { type IntrinsicClassAttributes = IntrinsicClassAttributesAlias } // @filename: node_modules/@types/react/jsx-runtime.d.ts diff --git a/tests/cases/compiler/reactJsxReactResolvedNodeNext.tsx b/tests/cases/compiler/reactJsxReactResolvedNodeNext.tsx index 0cc64eda70a14..9744c28f945cd 100644 --- a/tests/cases/compiler/reactJsxReactResolvedNodeNext.tsx +++ b/tests/cases/compiler/reactJsxReactResolvedNodeNext.tsx @@ -11,7 +11,7 @@ export const a =
; "types": "index.d.ts", } // @filename: node_modules/@types/react/index.d.ts -declare namespace JSX { +export declare namespace JSX { interface IntrinsicElements { [x: string]: any; } } // @filename: node_modules/@types/react/jsx-runtime.d.ts diff --git a/tests/cases/compiler/reactJsxReactResolvedNodeNextEsm.tsx b/tests/cases/compiler/reactJsxReactResolvedNodeNextEsm.tsx index 6d2fc006f15db..d9a28c0fe4858 100644 --- a/tests/cases/compiler/reactJsxReactResolvedNodeNextEsm.tsx +++ b/tests/cases/compiler/reactJsxReactResolvedNodeNextEsm.tsx @@ -19,7 +19,7 @@ export const a =
; } } // @filename: node_modules/@types/react/index.d.ts -declare namespace JSX { +export declare namespace JSX { interface IntrinsicElements { [x: string]: any; } } // @filename: node_modules/@types/react/jsx-runtime.d.ts diff --git a/tests/cases/conformance/externalModules/typeOnly/allowsImportingTsExtension.ts b/tests/cases/conformance/externalModules/typeOnly/allowsImportingTsExtension.ts index 706a2f27b554b..be61a7b96f0a4 100644 --- a/tests/cases/conformance/externalModules/typeOnly/allowsImportingTsExtension.ts +++ b/tests/cases/conformance/externalModules/typeOnly/allowsImportingTsExtension.ts @@ -11,6 +11,7 @@ export class A {} // @Filename: b.ts import type { A } from "./a.ts"; // ok import {} from "./a.ts"; // error +import "./a.ts"; // error import { type A as _A } from "./a.ts"; // error type __A = import("./a.ts").A; // ok const aPromise = import("./a.ts"); // error @@ -18,6 +19,7 @@ const aPromise = import("./a.ts"); // error // @Filename: c.ts import type { A } from "./a.d.ts"; // ok import {} from "./a.d.ts"; // error +import "./a.d.ts"; // error import { type A as _A } from "./a.d.ts"; // error type __A = import("./a.d.ts").A; // ok const aPromise = import("./a.d.ts"); // error From c69d9cc7c78b6dae18f65f500295e0d9eef4bd81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Burzy=C5=84ski?= Date: Mon, 27 May 2024 11:23:18 +0200 Subject: [PATCH 4/8] fmt --- src/testRunner/unittests/programApi.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/testRunner/unittests/programApi.ts b/src/testRunner/unittests/programApi.ts index b7de742ba6a89..b5d63cce6080b 100644 --- a/src/testRunner/unittests/programApi.ts +++ b/src/testRunner/unittests/programApi.ts @@ -216,7 +216,7 @@ describe("unittests:: programApi:: Program.getTypeChecker / Program.getSemanticD const sourceFile = program.getSourceFile("main.ts")!; const typeChecker = program.getTypeChecker(); typeChecker.getSymbolAtLocation((sourceFile.statements[0] as ts.ImportDeclaration).moduleSpecifier); - const diagnostics = program.getSemanticDiagnostics() + const diagnostics = program.getSemanticDiagnostics(); assert.equal(diagnostics.length, 1); assert.equal(diagnostics[0].code, ts.Diagnostics.File_0_is_not_a_module.code); assert.equal(diagnostics[0].messageText, "File '/module.d.ts' is not a module."); From 60a95d89e3b7c986e7c22d51640ff26eb25a58ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Burzy=C5=84ski?= Date: Thu, 30 May 2024 21:42:10 +0200 Subject: [PATCH 5/8] Revert "fmt" This reverts commit c69d9cc7c78b6dae18f65f500295e0d9eef4bd81. --- src/testRunner/unittests/programApi.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/testRunner/unittests/programApi.ts b/src/testRunner/unittests/programApi.ts index b5d63cce6080b..b7de742ba6a89 100644 --- a/src/testRunner/unittests/programApi.ts +++ b/src/testRunner/unittests/programApi.ts @@ -216,7 +216,7 @@ describe("unittests:: programApi:: Program.getTypeChecker / Program.getSemanticD const sourceFile = program.getSourceFile("main.ts")!; const typeChecker = program.getTypeChecker(); typeChecker.getSymbolAtLocation((sourceFile.statements[0] as ts.ImportDeclaration).moduleSpecifier); - const diagnostics = program.getSemanticDiagnostics(); + const diagnostics = program.getSemanticDiagnostics() assert.equal(diagnostics.length, 1); assert.equal(diagnostics[0].code, ts.Diagnostics.File_0_is_not_a_module.code); assert.equal(diagnostics[0].messageText, "File '/module.d.ts' is not a module."); From 1c41b56913f6059d72dc5bc09d5d969b18985e06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Burzy=C5=84ski?= Date: Thu, 30 May 2024 21:42:14 +0200 Subject: [PATCH 6/8] Revert "fixed errors on specifier-less imports" This reverts commit ca9be693eed7e84cf77947924f89f2afd9468aac. --- src/compiler/checker.ts | 8 +-- src/testRunner/unittests/programApi.ts | 7 +-- .../unittests/tscWatch/programUpdates.ts | 2 +- .../allowsImportingTsExtension.errors.txt | 20 ++----- .../reference/allowsImportingTsExtension.js | 6 +- .../allowsImportingTsExtension.symbols | 14 ++--- .../allowsImportingTsExtension.types | 2 - .../ambientExportDefaultErrors.errors.txt | 8 +-- .../amdDependencyCommentName4.errors.txt | 10 +--- ...autoAccessorDisallowedModifiers.errors.txt | 5 +- ...tsObjectAssignPrototypeProperty.errors.txt | 5 +- ...es6ImportWithoutFromClauseInEs5.errors.txt | 10 ---- ...portWithoutFromClauseWithExport.errors.txt | 7 +-- .../reference/extendGlobalThis.errors.txt | 20 ------- .../reference/extendGlobalThis.types | 1 - .../jsxClassAttributeResolution.errors.txt | 28 +++++++++ .../reference/jsxClassAttributeResolution.js | 2 +- .../jsxClassAttributeResolution.symbols | 4 +- .../jsxClassAttributeResolution.types | 8 ++- .../jsxFactoryQualifiedNameWithEs5.errors.txt | 16 ------ .../jsxFactoryQualifiedNameWithEs5.types | 6 +- ...tForSideEffectsNonExtantNoError.errors.txt | 13 ----- .../reference/moduleAugmentationGlobal5.js | 29 ---------- .../moduleAugmentationInAmbientModule5.js | 27 --------- .../reference/moduleAugmentationsImports3.js | 50 ---------------- .../reference/moduleAugmentationsImports4.js | 57 ------------------- ...lutionWithExtensions_unexpected.errors.txt | 14 ----- ...utionWithExtensions_unexpected2.errors.txt | 14 ----- ...ExportAssignment(module=node16).errors.txt | 5 +- ...portAssignment(module=nodenext).errors.txt | 5 +- .../reference/nodeModulesCJSEmit1.errors.txt | 5 +- .../reference/pathsValidation4.errors.txt | 7 +-- .../reference/pathsValidation5.errors.txt | 7 +-- .../reactJsxReactResolvedNodeNext.js | 2 +- .../reactJsxReactResolvedNodeNext.symbols | 6 +- .../reactJsxReactResolvedNodeNext.types | 2 +- .../reactJsxReactResolvedNodeNextEsm.js | 2 +- .../reactJsxReactResolvedNodeNextEsm.symbols | 6 +- .../reactJsxReactResolvedNodeNextEsm.types | 2 +- .../reference/systemModule9.errors.txt | 5 +- .../compiler/jsxClassAttributeResolution.tsx | 2 +- .../reactJsxReactResolvedNodeNext.tsx | 2 +- .../reactJsxReactResolvedNodeNextEsm.tsx | 2 +- .../typeOnly/allowsImportingTsExtension.ts | 2 - 44 files changed, 88 insertions(+), 367 deletions(-) delete mode 100644 tests/baselines/reference/es6ImportWithoutFromClauseInEs5.errors.txt delete mode 100644 tests/baselines/reference/extendGlobalThis.errors.txt create mode 100644 tests/baselines/reference/jsxClassAttributeResolution.errors.txt delete mode 100644 tests/baselines/reference/jsxFactoryQualifiedNameWithEs5.errors.txt delete mode 100644 tests/baselines/reference/jsxImportForSideEffectsNonExtantNoError.errors.txt delete mode 100644 tests/baselines/reference/moduleResolutionWithExtensions_unexpected.errors.txt delete mode 100644 tests/baselines/reference/moduleResolutionWithExtensions_unexpected2.errors.txt diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 13693e3660dbf..56ced9ad94944 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -4568,9 +4568,9 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { } if (resolvedModule.resolvedUsingTsExtension && isDeclarationFileName(moduleReference)) { - const importOrExport = findAncestor(location, isImportDeclaration) || + const importOrExport = findAncestor(location, isImportDeclaration)?.importClause || findAncestor(location, or(isImportEqualsDeclaration, isExportDeclaration)); - if (errorNode && importOrExport && !(isImportDeclaration(importOrExport) ? importOrExport.importClause : importOrExport)?.isTypeOnly || findAncestor(location, isImportCall)) { + if (errorNode && importOrExport && !importOrExport.isTypeOnly || findAncestor(location, isImportCall)) { error( errorNode, Diagnostics.A_declaration_file_cannot_be_imported_without_import_type_Did_you_mean_to_import_an_implementation_file_0_instead, @@ -4579,9 +4579,9 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { } } else if (resolvedModule.resolvedUsingTsExtension && !shouldAllowImportingTsExtension(compilerOptions, currentSourceFile.fileName)) { - const importOrExport = findAncestor(location, isImportDeclaration) || + const importOrExport = findAncestor(location, isImportDeclaration)?.importClause || findAncestor(location, or(isImportEqualsDeclaration, isExportDeclaration)); - if (errorNode && !(importOrExport && (isImportDeclaration(importOrExport) ? importOrExport.importClause : importOrExport)?.isTypeOnly || findAncestor(location, isImportTypeNode))) { + if (errorNode && !(importOrExport?.isTypeOnly || findAncestor(location, isImportTypeNode))) { const tsExtension = Debug.checkDefined(tryExtractTSExtension(moduleReference)); error(errorNode, Diagnostics.An_import_path_can_only_end_with_a_0_extension_when_allowImportingTsExtensions_is_enabled, tsExtension); } diff --git a/src/testRunner/unittests/programApi.ts b/src/testRunner/unittests/programApi.ts index b7de742ba6a89..44f391b869002 100644 --- a/src/testRunner/unittests/programApi.ts +++ b/src/testRunner/unittests/programApi.ts @@ -216,17 +216,14 @@ describe("unittests:: programApi:: Program.getTypeChecker / Program.getSemanticD const sourceFile = program.getSourceFile("main.ts")!; const typeChecker = program.getTypeChecker(); typeChecker.getSymbolAtLocation((sourceFile.statements[0] as ts.ImportDeclaration).moduleSpecifier); - const diagnostics = program.getSemanticDiagnostics() - assert.equal(diagnostics.length, 1); - assert.equal(diagnostics[0].code, ts.Diagnostics.File_0_is_not_a_module.code); - assert.equal(diagnostics[0].messageText, "File '/module.d.ts' is not a module."); + assert.isEmpty(program.getSemanticDiagnostics()); }); }); describe("unittests:: programApi:: CompilerOptions relative paths", () => { it("resolves relative paths by getCurrentDirectory", () => { const main = new documents.TextDocument("/main.ts", 'import "module";'); - const mod = new documents.TextDocument("/lib/module.ts", "export declare const foo: any;"); + const mod = new documents.TextDocument("/lib/module.ts", "declare const foo: any;"); const fs = vfs.createFromFileSystem(Harness.IO, /*ignoreCase*/ false, { documents: [main, mod], cwd: "/" }); const program = ts.createProgram(["./main.ts"], { diff --git a/src/testRunner/unittests/tscWatch/programUpdates.ts b/src/testRunner/unittests/tscWatch/programUpdates.ts index 1c191f84644af..600a45563b4a8 100644 --- a/src/testRunner/unittests/tscWatch/programUpdates.ts +++ b/src/testRunner/unittests/tscWatch/programUpdates.ts @@ -2129,7 +2129,7 @@ import { x } from "../b";`, sys: () => { const module1: File = { path: `/user/username/projects/myproject/a.ts`, - content: `export {};`, + content: ``, }; const module2: File = { path: `/user/username/projects/myproject/b.ts`, diff --git a/tests/baselines/reference/allowsImportingTsExtension.errors.txt b/tests/baselines/reference/allowsImportingTsExtension.errors.txt index 45954b42e863e..d66055353d5da 100644 --- a/tests/baselines/reference/allowsImportingTsExtension.errors.txt +++ b/tests/baselines/reference/allowsImportingTsExtension.errors.txt @@ -1,11 +1,9 @@ b.ts(2,16): error TS5097: An import path can only end with a '.ts' extension when 'allowImportingTsExtensions' is enabled. -b.ts(3,8): error TS5097: An import path can only end with a '.ts' extension when 'allowImportingTsExtensions' is enabled. -b.ts(4,30): error TS5097: An import path can only end with a '.ts' extension when 'allowImportingTsExtensions' is enabled. -b.ts(6,25): error TS5097: An import path can only end with a '.ts' extension when 'allowImportingTsExtensions' is enabled. +b.ts(3,30): error TS5097: An import path can only end with a '.ts' extension when 'allowImportingTsExtensions' is enabled. +b.ts(5,25): error TS5097: An import path can only end with a '.ts' extension when 'allowImportingTsExtensions' is enabled. c.ts(2,16): error TS2846: A declaration file cannot be imported without 'import type'. Did you mean to import an implementation file './a.js' instead? -c.ts(3,8): error TS2846: A declaration file cannot be imported without 'import type'. Did you mean to import an implementation file './a.js' instead? -c.ts(4,30): error TS2846: A declaration file cannot be imported without 'import type'. Did you mean to import an implementation file './a.js' instead? -c.ts(6,25): error TS2846: A declaration file cannot be imported without 'import type'. Did you mean to import an implementation file './a.js' instead? +c.ts(3,30): error TS2846: A declaration file cannot be imported without 'import type'. Did you mean to import an implementation file './a.js' instead? +c.ts(5,25): error TS2846: A declaration file cannot be imported without 'import type'. Did you mean to import an implementation file './a.js' instead? ==== a.ts (0 errors) ==== @@ -14,13 +12,10 @@ c.ts(6,25): error TS2846: A declaration file cannot be imported without 'import ==== a.d.ts (0 errors) ==== export class A {} -==== b.ts (4 errors) ==== +==== b.ts (3 errors) ==== import type { A } from "./a.ts"; // ok import {} from "./a.ts"; // error ~~~~~~~~ -!!! error TS5097: An import path can only end with a '.ts' extension when 'allowImportingTsExtensions' is enabled. - import "./a.ts"; // error - ~~~~~~~~ !!! error TS5097: An import path can only end with a '.ts' extension when 'allowImportingTsExtensions' is enabled. import { type A as _A } from "./a.ts"; // error ~~~~~~~~ @@ -30,13 +25,10 @@ c.ts(6,25): error TS2846: A declaration file cannot be imported without 'import ~~~~~~~~ !!! error TS5097: An import path can only end with a '.ts' extension when 'allowImportingTsExtensions' is enabled. -==== c.ts (4 errors) ==== +==== c.ts (3 errors) ==== import type { A } from "./a.d.ts"; // ok import {} from "./a.d.ts"; // error ~~~~~~~~~~ -!!! error TS2846: A declaration file cannot be imported without 'import type'. Did you mean to import an implementation file './a.js' instead? - import "./a.d.ts"; // error - ~~~~~~~~~~ !!! error TS2846: A declaration file cannot be imported without 'import type'. Did you mean to import an implementation file './a.js' instead? import { type A as _A } from "./a.d.ts"; // error ~~~~~~~~~~ diff --git a/tests/baselines/reference/allowsImportingTsExtension.js b/tests/baselines/reference/allowsImportingTsExtension.js index 2141ec4434ff6..1eab22395c687 100644 --- a/tests/baselines/reference/allowsImportingTsExtension.js +++ b/tests/baselines/reference/allowsImportingTsExtension.js @@ -9,7 +9,6 @@ export class A {} //// [b.ts] import type { A } from "./a.ts"; // ok import {} from "./a.ts"; // error -import "./a.ts"; // error import { type A as _A } from "./a.ts"; // error type __A = import("./a.ts").A; // ok const aPromise = import("./a.ts"); // error @@ -17,7 +16,6 @@ const aPromise = import("./a.ts"); // error //// [c.ts] import type { A } from "./a.d.ts"; // ok import {} from "./a.d.ts"; // error -import "./a.d.ts"; // error import { type A as _A } from "./a.d.ts"; // error type __A = import("./a.d.ts").A; // ok const aPromise = import("./a.d.ts"); // error @@ -27,8 +25,8 @@ const aPromise = import("./a.d.ts"); // error export class A { } //// [b.js] -import "./a.ts"; // error const aPromise = import("./a.ts"); // error +export {}; //// [c.js] -import "./a.d.ts"; // error const aPromise = import("./a.d.ts"); // error +export {}; diff --git a/tests/baselines/reference/allowsImportingTsExtension.symbols b/tests/baselines/reference/allowsImportingTsExtension.symbols index caca7d76b6adb..a08e00fcf5407 100644 --- a/tests/baselines/reference/allowsImportingTsExtension.symbols +++ b/tests/baselines/reference/allowsImportingTsExtension.symbols @@ -13,17 +13,16 @@ import type { A } from "./a.ts"; // ok >A : Symbol(A, Decl(b.ts, 0, 13)) import {} from "./a.ts"; // error -import "./a.ts"; // error import { type A as _A } from "./a.ts"; // error >A : Symbol(A, Decl(a.ts, 0, 0)) ->_A : Symbol(_A, Decl(b.ts, 3, 8)) +>_A : Symbol(_A, Decl(b.ts, 2, 8)) type __A = import("./a.ts").A; // ok ->__A : Symbol(__A, Decl(b.ts, 3, 38)) +>__A : Symbol(__A, Decl(b.ts, 2, 38)) >A : Symbol(A, Decl(a.ts, 0, 0)) const aPromise = import("./a.ts"); // error ->aPromise : Symbol(aPromise, Decl(b.ts, 5, 5)) +>aPromise : Symbol(aPromise, Decl(b.ts, 4, 5)) >"./a.ts" : Symbol("a", Decl(a.ts, 0, 0)) === c.ts === @@ -31,16 +30,15 @@ import type { A } from "./a.d.ts"; // ok >A : Symbol(A, Decl(c.ts, 0, 13)) import {} from "./a.d.ts"; // error -import "./a.d.ts"; // error import { type A as _A } from "./a.d.ts"; // error >A : Symbol(A, Decl(a.ts, 0, 0)) ->_A : Symbol(_A, Decl(c.ts, 3, 8)) +>_A : Symbol(_A, Decl(c.ts, 2, 8)) type __A = import("./a.d.ts").A; // ok ->__A : Symbol(__A, Decl(c.ts, 3, 40)) +>__A : Symbol(__A, Decl(c.ts, 2, 40)) >A : Symbol(A, Decl(a.ts, 0, 0)) const aPromise = import("./a.d.ts"); // error ->aPromise : Symbol(aPromise, Decl(c.ts, 5, 5)) +>aPromise : Symbol(aPromise, Decl(c.ts, 4, 5)) >"./a.d.ts" : Symbol("a", Decl(a.ts, 0, 0)) diff --git a/tests/baselines/reference/allowsImportingTsExtension.types b/tests/baselines/reference/allowsImportingTsExtension.types index c8ca0133a1267..c1fe54623e545 100644 --- a/tests/baselines/reference/allowsImportingTsExtension.types +++ b/tests/baselines/reference/allowsImportingTsExtension.types @@ -16,7 +16,6 @@ import type { A } from "./a.ts"; // ok > : ^ import {} from "./a.ts"; // error -import "./a.ts"; // error import { type A as _A } from "./a.ts"; // error >A : typeof A > : ^^^^^^^^ @@ -41,7 +40,6 @@ import type { A } from "./a.d.ts"; // ok > : ^ import {} from "./a.d.ts"; // error -import "./a.d.ts"; // error import { type A as _A } from "./a.d.ts"; // error >A : typeof A > : ^^^^^^^^ diff --git a/tests/baselines/reference/ambientExportDefaultErrors.errors.txt b/tests/baselines/reference/ambientExportDefaultErrors.errors.txt index c4d3781b9e4c7..4b31677c11549 100644 --- a/tests/baselines/reference/ambientExportDefaultErrors.errors.txt +++ b/tests/baselines/reference/ambientExportDefaultErrors.errors.txt @@ -1,22 +1,16 @@ -consumer.ts(4,8): error TS2307: Cannot find module 'foo' or its corresponding type declarations. -consumer.ts(6,8): error TS2307: Cannot find module 'foo2' or its corresponding type declarations. foo.d.ts(1,16): error TS2714: The expression of an export assignment must be an identifier or qualified name in an ambient context. foo2.d.ts(1,10): error TS2714: The expression of an export assignment must be an identifier or qualified name in an ambient context. indirection.d.ts(3,20): error TS2714: The expression of an export assignment must be an identifier or qualified name in an ambient context. indirection2.d.ts(3,14): error TS2714: The expression of an export assignment must be an identifier or qualified name in an ambient context. -==== consumer.ts (2 errors) ==== +==== consumer.ts (0 errors) ==== /// /// import "indirect"; import "foo"; - ~~~~~ -!!! error TS2307: Cannot find module 'foo' or its corresponding type declarations. import "indirect2"; import "foo2"; - ~~~~~~ -!!! error TS2307: Cannot find module 'foo2' or its corresponding type declarations. ==== foo.d.ts (1 errors) ==== export default 2 + 2; ~~~~~ diff --git a/tests/baselines/reference/amdDependencyCommentName4.errors.txt b/tests/baselines/reference/amdDependencyCommentName4.errors.txt index ead5e629fa4a8..6788d6c3b3286 100644 --- a/tests/baselines/reference/amdDependencyCommentName4.errors.txt +++ b/tests/baselines/reference/amdDependencyCommentName4.errors.txt @@ -1,20 +1,16 @@ -amdDependencyCommentName4.ts(6,8): error TS2792: Cannot find module 'unaliasedModule1'. Did you mean to set the 'moduleResolution' option to 'nodenext', or to add aliases to the 'paths' option? amdDependencyCommentName4.ts(8,21): error TS2792: Cannot find module 'aliasedModule1'. Did you mean to set the 'moduleResolution' option to 'nodenext', or to add aliases to the 'paths' option? amdDependencyCommentName4.ts(11,26): error TS2792: Cannot find module 'aliasedModule2'. Did you mean to set the 'moduleResolution' option to 'nodenext', or to add aliases to the 'paths' option? amdDependencyCommentName4.ts(14,15): error TS2792: Cannot find module 'aliasedModule3'. Did you mean to set the 'moduleResolution' option to 'nodenext', or to add aliases to the 'paths' option? amdDependencyCommentName4.ts(17,21): error TS2792: Cannot find module 'aliasedModule4'. Did you mean to set the 'moduleResolution' option to 'nodenext', or to add aliases to the 'paths' option? -amdDependencyCommentName4.ts(20,8): error TS2792: Cannot find module 'unaliasedModule2'. Did you mean to set the 'moduleResolution' option to 'nodenext', or to add aliases to the 'paths' option? -==== amdDependencyCommentName4.ts (6 errors) ==== +==== amdDependencyCommentName4.ts (4 errors) ==== /// /// /// /// import "unaliasedModule1"; - ~~~~~~~~~~~~~~~~~~ -!!! error TS2792: Cannot find module 'unaliasedModule1'. Did you mean to set the 'moduleResolution' option to 'nodenext', or to add aliases to the 'paths' option? import r1 = require("aliasedModule1"); ~~~~~~~~~~~~~~~~ @@ -36,6 +32,4 @@ amdDependencyCommentName4.ts(20,8): error TS2792: Cannot find module 'unaliasedM !!! error TS2792: Cannot find module 'aliasedModule4'. Did you mean to set the 'moduleResolution' option to 'nodenext', or to add aliases to the 'paths' option? ns; - import "unaliasedModule2"; - ~~~~~~~~~~~~~~~~~~ -!!! error TS2792: Cannot find module 'unaliasedModule2'. Did you mean to set the 'moduleResolution' option to 'nodenext', or to add aliases to the 'paths' option? \ No newline at end of file + import "unaliasedModule2"; \ No newline at end of file diff --git a/tests/baselines/reference/autoAccessorDisallowedModifiers.errors.txt b/tests/baselines/reference/autoAccessorDisallowedModifiers.errors.txt index 4ab0938a6a6b6..d9b841ee69892 100644 --- a/tests/baselines/reference/autoAccessorDisallowedModifiers.errors.txt +++ b/tests/baselines/reference/autoAccessorDisallowedModifiers.errors.txt @@ -23,7 +23,6 @@ autoAccessorDisallowedModifiers.ts(31,1): error TS1275: 'accessor' modifier can autoAccessorDisallowedModifiers.ts(32,1): error TS1275: 'accessor' modifier can only appear on a property declaration. autoAccessorDisallowedModifiers.ts(33,1): error TS1275: 'accessor' modifier can only appear on a property declaration. autoAccessorDisallowedModifiers.ts(34,1): error TS1275: 'accessor' modifier can only appear on a property declaration. -autoAccessorDisallowedModifiers.ts(34,17): error TS2792: Cannot find module 'x'. Did you mean to set the 'moduleResolution' option to 'nodenext', or to add aliases to the 'paths' option? autoAccessorDisallowedModifiers.ts(35,1): error TS1275: 'accessor' modifier can only appear on a property declaration. autoAccessorDisallowedModifiers.ts(35,25): error TS2792: Cannot find module 'x'. Did you mean to set the 'moduleResolution' option to 'nodenext', or to add aliases to the 'paths' option? autoAccessorDisallowedModifiers.ts(36,1): error TS1275: 'accessor' modifier can only appear on a property declaration. @@ -31,7 +30,7 @@ autoAccessorDisallowedModifiers.ts(37,1): error TS1275: 'accessor' modifier can autoAccessorDisallowedModifiers.ts(38,1): error TS1275: 'accessor' modifier can only appear on a property declaration. -==== autoAccessorDisallowedModifiers.ts (31 errors) ==== +==== autoAccessorDisallowedModifiers.ts (30 errors) ==== abstract class C1 { accessor accessor a: any; ~~~~~~~~ @@ -116,8 +115,6 @@ autoAccessorDisallowedModifiers.ts(38,1): error TS1275: 'accessor' modifier can accessor import "x"; ~~~~~~~~ !!! error TS1275: 'accessor' modifier can only appear on a property declaration. - ~~~ -!!! error TS2792: Cannot find module 'x'. Did you mean to set the 'moduleResolution' option to 'nodenext', or to add aliases to the 'paths' option? accessor import {} from "x"; ~~~~~~~~ !!! error TS1275: 'accessor' modifier can only appear on a property declaration. diff --git a/tests/baselines/reference/checkExportsObjectAssignPrototypeProperty.errors.txt b/tests/baselines/reference/checkExportsObjectAssignPrototypeProperty.errors.txt index 0ef83f725cd47..805191bcca68f 100644 --- a/tests/baselines/reference/checkExportsObjectAssignPrototypeProperty.errors.txt +++ b/tests/baselines/reference/checkExportsObjectAssignPrototypeProperty.errors.txt @@ -1,4 +1,3 @@ -validator.ts(1,8): error TS2307: Cannot find module './' or its corresponding type declarations. validator.ts(19,4): error TS2540: Cannot assign to 'readonlyProp' because it is a read-only property. validator.ts(20,4): error TS2540: Cannot assign to 'readonlyAccessor' because it is a read-only property. validator.ts(21,1): error TS2322: Type 'string' is not assignable to type 'number'. @@ -6,10 +5,8 @@ validator.ts(22,1): error TS2322: Type 'string' is not assignable to type 'numbe validator.ts(23,1): error TS2322: Type 'number' is not assignable to type 'string'. -==== validator.ts (6 errors) ==== +==== validator.ts (5 errors) ==== import "./"; - ~~~~ -!!! error TS2307: Cannot find module './' or its corresponding type declarations. import Person = require("./mod1"); diff --git a/tests/baselines/reference/es6ImportWithoutFromClauseInEs5.errors.txt b/tests/baselines/reference/es6ImportWithoutFromClauseInEs5.errors.txt deleted file mode 100644 index cff1519cb0c69..0000000000000 --- a/tests/baselines/reference/es6ImportWithoutFromClauseInEs5.errors.txt +++ /dev/null @@ -1,10 +0,0 @@ -es6ImportWithoutFromClauseInEs5_1.ts(1,8): error TS2307: Cannot find module 'es6ImportWithoutFromClauseInEs5_0' or its corresponding type declarations. - - -==== es6ImportWithoutFromClauseInEs5_0.ts (0 errors) ==== - export var a = 10; - -==== es6ImportWithoutFromClauseInEs5_1.ts (1 errors) ==== - import "es6ImportWithoutFromClauseInEs5_0"; - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2307: Cannot find module 'es6ImportWithoutFromClauseInEs5_0' or its corresponding type declarations. \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportWithoutFromClauseWithExport.errors.txt b/tests/baselines/reference/es6ImportWithoutFromClauseWithExport.errors.txt index 3eb75fd0443bc..d40a9dee7f283 100644 --- a/tests/baselines/reference/es6ImportWithoutFromClauseWithExport.errors.txt +++ b/tests/baselines/reference/es6ImportWithoutFromClauseWithExport.errors.txt @@ -1,13 +1,10 @@ client.ts(1,1): error TS1191: An import declaration cannot have modifiers. -client.ts(1,15): error TS2307: Cannot find module 'server' or its corresponding type declarations. ==== server.ts (0 errors) ==== export var a = 10; -==== client.ts (2 errors) ==== +==== client.ts (1 errors) ==== export import "server"; ~~~~~~ -!!! error TS1191: An import declaration cannot have modifiers. - ~~~~~~~~ -!!! error TS2307: Cannot find module 'server' or its corresponding type declarations. \ No newline at end of file +!!! error TS1191: An import declaration cannot have modifiers. \ No newline at end of file diff --git a/tests/baselines/reference/extendGlobalThis.errors.txt b/tests/baselines/reference/extendGlobalThis.errors.txt deleted file mode 100644 index 093beeb459cac..0000000000000 --- a/tests/baselines/reference/extendGlobalThis.errors.txt +++ /dev/null @@ -1,20 +0,0 @@ -index.ts(1,8): error TS2307: Cannot find module './extention' or its corresponding type declarations. - - -==== extension.d.ts (0 errors) ==== - declare global { - namespace globalThis { - var test: string; - } - } - - export {} - -==== index.ts (1 errors) ==== - import "./extention"; - ~~~~~~~~~~~~~ -!!! error TS2307: Cannot find module './extention' or its corresponding type declarations. - - globalThis.tests = "a-b"; - console.log(globalThis.test.split("-")); - \ No newline at end of file diff --git a/tests/baselines/reference/extendGlobalThis.types b/tests/baselines/reference/extendGlobalThis.types index a3b91ff95e015..499b561819e53 100644 --- a/tests/baselines/reference/extendGlobalThis.types +++ b/tests/baselines/reference/extendGlobalThis.types @@ -24,7 +24,6 @@ globalThis.tests = "a-b"; >globalThis.tests = "a-b" : "a-b" > : ^^^^^ >globalThis.tests : any -> : ^^^ >globalThis : typeof globalThis > : ^^^^^^^^^^^^^^^^^ >tests : any diff --git a/tests/baselines/reference/jsxClassAttributeResolution.errors.txt b/tests/baselines/reference/jsxClassAttributeResolution.errors.txt new file mode 100644 index 0000000000000..354df1ee641a2 --- /dev/null +++ b/tests/baselines/reference/jsxClassAttributeResolution.errors.txt @@ -0,0 +1,28 @@ +file.tsx(2,19): error TS2741: Property 'ref' is missing in type '{}' but required in type 'IntrinsicClassAttributesAlias'. + + +==== file.tsx (1 errors) ==== + class App {} + export const a = ; + ~~~ +!!! error TS2741: Property 'ref' is missing in type '{}' but required in type 'IntrinsicClassAttributesAlias'. +!!! related TS2728 node_modules/@types/react/index.d.ts:2:5: 'ref' is declared here. +==== node_modules/@types/react/package.json (0 errors) ==== + { + "name": "@types/react", + "version": "0.0.1", + "main": "", + "types": "index.d.ts", + } +==== node_modules/@types/react/index.d.ts (0 errors) ==== + interface IntrinsicClassAttributesAlias { + ref: T + } + declare namespace JSX { + type IntrinsicClassAttributes = IntrinsicClassAttributesAlias + } +==== node_modules/@types/react/jsx-runtime.d.ts (0 errors) ==== + import './'; +==== node_modules/@types/react/jsx-dev-runtime.d.ts (0 errors) ==== + import './'; + \ No newline at end of file diff --git a/tests/baselines/reference/jsxClassAttributeResolution.js b/tests/baselines/reference/jsxClassAttributeResolution.js index 5a22fb2a6e12b..7fa77a36324a3 100644 --- a/tests/baselines/reference/jsxClassAttributeResolution.js +++ b/tests/baselines/reference/jsxClassAttributeResolution.js @@ -14,7 +14,7 @@ export const a = ; interface IntrinsicClassAttributesAlias { ref: T } -export declare namespace JSX { +declare namespace JSX { type IntrinsicClassAttributes = IntrinsicClassAttributesAlias } //// [jsx-runtime.d.ts] diff --git a/tests/baselines/reference/jsxClassAttributeResolution.symbols b/tests/baselines/reference/jsxClassAttributeResolution.symbols index 673dce6ce3896..de0ed218a0b6c 100644 --- a/tests/baselines/reference/jsxClassAttributeResolution.symbols +++ b/tests/baselines/reference/jsxClassAttributeResolution.symbols @@ -18,11 +18,11 @@ interface IntrinsicClassAttributesAlias { >ref : Symbol(IntrinsicClassAttributesAlias.ref, Decl(index.d.ts, 0, 44)) >T : Symbol(T, Decl(index.d.ts, 0, 40)) } -export declare namespace JSX { +declare namespace JSX { >JSX : Symbol(JSX, Decl(index.d.ts, 2, 1)) type IntrinsicClassAttributes = IntrinsicClassAttributesAlias ->IntrinsicClassAttributes : Symbol(IntrinsicClassAttributes, Decl(index.d.ts, 3, 30)) +>IntrinsicClassAttributes : Symbol(IntrinsicClassAttributes, Decl(index.d.ts, 3, 23)) >T : Symbol(T, Decl(index.d.ts, 4, 34)) >IntrinsicClassAttributesAlias : Symbol(IntrinsicClassAttributesAlias, Decl(index.d.ts, 0, 0)) >T : Symbol(T, Decl(index.d.ts, 4, 34)) diff --git a/tests/baselines/reference/jsxClassAttributeResolution.types b/tests/baselines/reference/jsxClassAttributeResolution.types index c440d9679c2d2..d8b384531b466 100644 --- a/tests/baselines/reference/jsxClassAttributeResolution.types +++ b/tests/baselines/reference/jsxClassAttributeResolution.types @@ -6,8 +6,10 @@ class App {} > : ^^^ export const a = ; ->a : error -> : error +>a : any +> : ^^^ +> : any +> : ^^^ >App : typeof App > : ^^^^^^^^^^ >App : typeof App @@ -19,7 +21,7 @@ interface IntrinsicClassAttributesAlias { >ref : T > : ^ } -export declare namespace JSX { +declare namespace JSX { type IntrinsicClassAttributes = IntrinsicClassAttributesAlias >IntrinsicClassAttributes : IntrinsicClassAttributes > : ^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/baselines/reference/jsxFactoryQualifiedNameWithEs5.errors.txt b/tests/baselines/reference/jsxFactoryQualifiedNameWithEs5.errors.txt deleted file mode 100644 index 13eb01d3431ca..0000000000000 --- a/tests/baselines/reference/jsxFactoryQualifiedNameWithEs5.errors.txt +++ /dev/null @@ -1,16 +0,0 @@ -index.tsx(1,8): error TS2307: Cannot find module './jsx' or its corresponding type declarations. - - -==== index.tsx (1 errors) ==== - import "./jsx"; - ~~~~~~~ -!!! error TS2307: Cannot find module './jsx' or its corresponding type declarations. - - var skate: any; - const React = { createElement: skate.h }; - - class Component { - renderCallback() { - return
test
; - } - }; \ No newline at end of file diff --git a/tests/baselines/reference/jsxFactoryQualifiedNameWithEs5.types b/tests/baselines/reference/jsxFactoryQualifiedNameWithEs5.types index dbb1eed353c38..c9a019263fe47 100644 --- a/tests/baselines/reference/jsxFactoryQualifiedNameWithEs5.types +++ b/tests/baselines/reference/jsxFactoryQualifiedNameWithEs5.types @@ -5,7 +5,6 @@ import "./jsx"; var skate: any; >skate : any -> : ^^^ const React = { createElement: skate.h }; >React : { createElement: any; } @@ -13,9 +12,7 @@ const React = { createElement: skate.h }; >{ createElement: skate.h } : { createElement: any; } > : ^^^^^^^^^^^^^^^^^^^^^^^ >createElement : any -> : ^^^ >skate.h : any -> : ^^^ >skate : any > : ^^^ >h : any @@ -30,8 +27,7 @@ class Component { > : ^^^^^^^^^ return
test
; ->
test
: any -> : ^^^ +>
test
: error >div : any > : ^^^ >div : any diff --git a/tests/baselines/reference/jsxImportForSideEffectsNonExtantNoError.errors.txt b/tests/baselines/reference/jsxImportForSideEffectsNonExtantNoError.errors.txt deleted file mode 100644 index 34182361b1ba1..0000000000000 --- a/tests/baselines/reference/jsxImportForSideEffectsNonExtantNoError.errors.txt +++ /dev/null @@ -1,13 +0,0 @@ -jsxImportForSideEffectsNonExtantNoError.tsx(4,8): error TS2307: Cannot find module './App.css' or its corresponding type declarations. - - -==== jsxImportForSideEffectsNonExtantNoError.tsx (1 errors) ==== - /// - import * as React from "react"; - - import "./App.css"; // doesn't actually exist - ~~~~~~~~~~~ -!!! error TS2307: Cannot find module './App.css' or its corresponding type declarations. - - const tag =
; - \ No newline at end of file diff --git a/tests/baselines/reference/moduleAugmentationGlobal5.js b/tests/baselines/reference/moduleAugmentationGlobal5.js index 88ce41cbe2b6f..5886a438f9da5 100644 --- a/tests/baselines/reference/moduleAugmentationGlobal5.js +++ b/tests/baselines/reference/moduleAugmentationGlobal5.js @@ -32,32 +32,3 @@ require("B"); //// [f3.d.ts] import "A"; import "B"; - - -//// [DtsFileErrors] - - -f3.d.ts(1,8): error TS2307: Cannot find module 'A' or its corresponding type declarations. -f3.d.ts(2,8): error TS2307: Cannot find module 'B' or its corresponding type declarations. - - -==== f3.d.ts (2 errors) ==== - import "A"; - ~~~ -!!! error TS2307: Cannot find module 'A' or its corresponding type declarations. - import "B"; - ~~~ -!!! error TS2307: Cannot find module 'B' or its corresponding type declarations. - -==== f1.d.ts (0 errors) ==== - declare module "A" { - global { - interface Something {x} - } - } -==== f2.d.ts (0 errors) ==== - declare module "B" { - global { - interface Something {y} - } - } \ No newline at end of file diff --git a/tests/baselines/reference/moduleAugmentationInAmbientModule5.js b/tests/baselines/reference/moduleAugmentationInAmbientModule5.js index 347fdc1977b2b..923100c74d22b 100644 --- a/tests/baselines/reference/moduleAugmentationInAmbientModule5.js +++ b/tests/baselines/reference/moduleAugmentationInAmbientModule5.js @@ -33,30 +33,3 @@ var y = x.getA().x; //// [f.d.ts] import "array"; - - -//// [DtsFileErrors] - - -f.d.ts(1,8): error TS2307: Cannot find module 'array' or its corresponding type declarations. - - -==== f.d.ts (1 errors) ==== - import "array"; - ~~~~~~~ -!!! error TS2307: Cannot find module 'array' or its corresponding type declarations. - -==== array.d.ts (0 errors) ==== - declare module "A" { - class A { x: number; } - } - - declare module "array" { - import {A} from "A"; - global { - interface Array { - getA(): A; - } - } - } - \ No newline at end of file diff --git a/tests/baselines/reference/moduleAugmentationsImports3.js b/tests/baselines/reference/moduleAugmentationsImports3.js index 100254136314d..14ae0f65f2ffa 100644 --- a/tests/baselines/reference/moduleAugmentationsImports3.js +++ b/tests/baselines/reference/moduleAugmentationsImports3.js @@ -106,53 +106,3 @@ declare module "main" { import "D"; import "e"; } - - -//// [DtsFileErrors] - - -f.d.ts(20,12): error TS2792: Cannot find module 'D'. Did you mean to set the 'moduleResolution' option to 'nodenext', or to add aliases to the 'paths' option? - - -==== f.d.ts (1 errors) ==== - /// - declare module "a" { - export class A { - } - } - declare module "b" { - export class B { - x: number; - } - } - declare module "e" { - import { Cls } from "C"; - module "a" { - interface A { - getCls(): Cls; - } - } - } - declare module "main" { - import "D"; - ~~~ -!!! error TS2792: Cannot find module 'D'. Did you mean to set the 'moduleResolution' option to 'nodenext', or to add aliases to the 'paths' option? - import "e"; - } - -==== c.d.ts (0 errors) ==== - declare module "C" { - class Cls {y: string; } - } - -==== d.d.ts (0 errors) ==== - declare module "D" { - import {A} from "a"; - import {B} from "b"; - module "a" { - interface A { - getB(): B; - } - } - } - \ No newline at end of file diff --git a/tests/baselines/reference/moduleAugmentationsImports4.js b/tests/baselines/reference/moduleAugmentationsImports4.js index 9bc575724e16c..d009f154ad0fd 100644 --- a/tests/baselines/reference/moduleAugmentationsImports4.js +++ b/tests/baselines/reference/moduleAugmentationsImports4.js @@ -93,60 +93,3 @@ declare module "main" { import "D"; import "E"; } - - -//// [DtsFileErrors] - - -f.d.ts(11,12): error TS2792: Cannot find module 'D'. Did you mean to set the 'moduleResolution' option to 'nodenext', or to add aliases to the 'paths' option? -f.d.ts(12,12): error TS2792: Cannot find module 'E'. Did you mean to set the 'moduleResolution' option to 'nodenext', or to add aliases to the 'paths' option? - - -==== f.d.ts (2 errors) ==== - declare module "a" { - export class A { - } - } - declare module "b" { - export class B { - x: number; - } - } - declare module "main" { - import "D"; - ~~~ -!!! error TS2792: Cannot find module 'D'. Did you mean to set the 'moduleResolution' option to 'nodenext', or to add aliases to the 'paths' option? - import "E"; - ~~~ -!!! error TS2792: Cannot find module 'E'. Did you mean to set the 'moduleResolution' option to 'nodenext', or to add aliases to the 'paths' option? - } - -==== c.d.ts (0 errors) ==== - declare module "C" { - class Cls {y: string; } - } - -==== d.d.ts (0 errors) ==== - declare module "D" { - import {A} from "a"; - import {B} from "b"; - module "a" { - interface A { - getB(): B; - } - } - } - -==== e.d.ts (0 errors) ==== - /// - declare module "E" { - import {A} from "a"; - import {Cls} from "C"; - - module "a" { - interface A { - getCls(): Cls; - } - } - } - \ No newline at end of file diff --git a/tests/baselines/reference/moduleResolutionWithExtensions_unexpected.errors.txt b/tests/baselines/reference/moduleResolutionWithExtensions_unexpected.errors.txt deleted file mode 100644 index f677838225b10..0000000000000 --- a/tests/baselines/reference/moduleResolutionWithExtensions_unexpected.errors.txt +++ /dev/null @@ -1,14 +0,0 @@ -/a.ts(1,8): error TS2307: Cannot find module 'normalize.css' or its corresponding type declarations. - - -==== /a.ts (1 errors) ==== - import "normalize.css"; - ~~~~~~~~~~~~~~~ -!!! error TS2307: Cannot find module 'normalize.css' or its corresponding type declarations. - -==== /node_modules/normalize.css/normalize.css (0 errors) ==== - This file is not read. - -==== /node_modules/normalize.css/package.json (0 errors) ==== - { "main": "normalize.css" } - \ No newline at end of file diff --git a/tests/baselines/reference/moduleResolutionWithExtensions_unexpected2.errors.txt b/tests/baselines/reference/moduleResolutionWithExtensions_unexpected2.errors.txt deleted file mode 100644 index 0171f5e0b0c6e..0000000000000 --- a/tests/baselines/reference/moduleResolutionWithExtensions_unexpected2.errors.txt +++ /dev/null @@ -1,14 +0,0 @@ -/a.ts(1,8): error TS2307: Cannot find module 'foo' or its corresponding type declarations. - - -==== /a.ts (1 errors) ==== - import "foo"; - ~~~~~ -!!! error TS2307: Cannot find module 'foo' or its corresponding type declarations. - -==== /node_modules/foo/foo.js (0 errors) ==== - This file is not read. - -==== /node_modules/foo/package.json (0 errors) ==== - { "types": "foo.js" } - \ No newline at end of file diff --git a/tests/baselines/reference/nodeModulesAllowJsExportAssignment(module=node16).errors.txt b/tests/baselines/reference/nodeModulesAllowJsExportAssignment(module=node16).errors.txt index 92187a7e27b92..15bd70e4c2e9d 100644 --- a/tests/baselines/reference/nodeModulesAllowJsExportAssignment(module=node16).errors.txt +++ b/tests/baselines/reference/nodeModulesAllowJsExportAssignment(module=node16).errors.txt @@ -1,4 +1,3 @@ -file.js(2,8): error TS2307: Cannot find module 'fs' or its corresponding type declarations. file.js(4,1): error TS2580: Cannot find name 'module'. Do you need to install type definitions for node? Try `npm i --save-dev @types/node`. index.js(3,1): error TS1203: Export assignment cannot be used when targeting ECMAScript modules. Consider using 'export default' or another module format instead. index.js(3,1): error TS8003: 'export =' can only be used in TypeScript files. @@ -23,11 +22,9 @@ subfolder/index.js(3,1): error TS8003: 'export =' can only be used in TypeScript !!! error TS1203: Export assignment cannot be used when targeting ECMAScript modules. Consider using 'export default' or another module format instead. ~~~~~~~~~~~ !!! error TS8003: 'export =' can only be used in TypeScript files. -==== file.js (2 errors) ==== +==== file.js (1 errors) ==== // esm format file import "fs"; - ~~~~ -!!! error TS2307: Cannot find module 'fs' or its corresponding type declarations. const a = {}; module.exports = a; ~~~~~~ diff --git a/tests/baselines/reference/nodeModulesAllowJsExportAssignment(module=nodenext).errors.txt b/tests/baselines/reference/nodeModulesAllowJsExportAssignment(module=nodenext).errors.txt index 92187a7e27b92..15bd70e4c2e9d 100644 --- a/tests/baselines/reference/nodeModulesAllowJsExportAssignment(module=nodenext).errors.txt +++ b/tests/baselines/reference/nodeModulesAllowJsExportAssignment(module=nodenext).errors.txt @@ -1,4 +1,3 @@ -file.js(2,8): error TS2307: Cannot find module 'fs' or its corresponding type declarations. file.js(4,1): error TS2580: Cannot find name 'module'. Do you need to install type definitions for node? Try `npm i --save-dev @types/node`. index.js(3,1): error TS1203: Export assignment cannot be used when targeting ECMAScript modules. Consider using 'export default' or another module format instead. index.js(3,1): error TS8003: 'export =' can only be used in TypeScript files. @@ -23,11 +22,9 @@ subfolder/index.js(3,1): error TS8003: 'export =' can only be used in TypeScript !!! error TS1203: Export assignment cannot be used when targeting ECMAScript modules. Consider using 'export default' or another module format instead. ~~~~~~~~~~~ !!! error TS8003: 'export =' can only be used in TypeScript files. -==== file.js (2 errors) ==== +==== file.js (1 errors) ==== // esm format file import "fs"; - ~~~~ -!!! error TS2307: Cannot find module 'fs' or its corresponding type declarations. const a = {}; module.exports = a; ~~~~~~ diff --git a/tests/baselines/reference/nodeModulesCJSEmit1.errors.txt b/tests/baselines/reference/nodeModulesCJSEmit1.errors.txt index 8d9a1b4e1264a..5e3604d311b92 100644 --- a/tests/baselines/reference/nodeModulesCJSEmit1.errors.txt +++ b/tests/baselines/reference/nodeModulesCJSEmit1.errors.txt @@ -1,4 +1,3 @@ -/3.cjs(1,8): error TS2307: Cannot find module 'foo' or its corresponding type declarations. /3.cjs(2,1): error TS2304: Cannot find name 'exports'. /5.cjs(2,8): error TS1192: Module '"/3"' has no default export. @@ -9,10 +8,8 @@ ==== /2.cjs (0 errors) ==== exports.foo = 0; -==== /3.cjs (2 errors) ==== +==== /3.cjs (1 errors) ==== import "foo"; - ~~~~~ -!!! error TS2307: Cannot find module 'foo' or its corresponding type declarations. exports.foo = {}; ~~~~~~~ !!! error TS2304: Cannot find name 'exports'. diff --git a/tests/baselines/reference/pathsValidation4.errors.txt b/tests/baselines/reference/pathsValidation4.errors.txt index 6a449b9cdf14e..386079a29503b 100644 --- a/tests/baselines/reference/pathsValidation4.errors.txt +++ b/tests/baselines/reference/pathsValidation4.errors.txt @@ -1,7 +1,6 @@ tsconfig.json(6,11): error TS5061: Pattern '@interface/**/*' can have at most one '*' character. tsconfig.json(7,11): error TS5061: Pattern '@service/**/*' can have at most one '*' character. tsconfig.json(7,29): error TS5062: Substitution './src/service/**/*' in pattern '@service/**/*' can have at most one '*' character. -src/main.ts(1,8): error TS2307: Cannot find module 'someModule' or its corresponding type declarations. ==== tsconfig.json (3 errors) ==== @@ -23,7 +22,5 @@ src/main.ts(1,8): error TS2307: Cannot find module 'someModule' or its correspon } } -==== src/main.ts (1 errors) ==== - import 'someModule'; - ~~~~~~~~~~~~ -!!! error TS2307: Cannot find module 'someModule' or its corresponding type declarations. \ No newline at end of file +==== src/main.ts (0 errors) ==== + import 'someModule'; \ No newline at end of file diff --git a/tests/baselines/reference/pathsValidation5.errors.txt b/tests/baselines/reference/pathsValidation5.errors.txt index c61e736a2b871..80eaf2d68f6cb 100644 --- a/tests/baselines/reference/pathsValidation5.errors.txt +++ b/tests/baselines/reference/pathsValidation5.errors.txt @@ -1,7 +1,6 @@ tsconfig.json(5,26): error TS5090: Non-relative paths are not allowed when 'baseUrl' is not set. Did you forget a leading './'? tsconfig.json(6,19): error TS5090: Non-relative paths are not allowed when 'baseUrl' is not set. Did you forget a leading './'? tsconfig.json(7,23): error TS5090: Non-relative paths are not allowed when 'baseUrl' is not set. Did you forget a leading './'? -src/main.ts(1,8): error TS2307: Cannot find module 'someModule' or its corresponding type declarations. ==== tsconfig.json (3 errors) ==== @@ -22,7 +21,5 @@ src/main.ts(1,8): error TS2307: Cannot find module 'someModule' or its correspon } } -==== src/main.ts (1 errors) ==== - import 'someModule'; - ~~~~~~~~~~~~ -!!! error TS2307: Cannot find module 'someModule' or its corresponding type declarations. \ No newline at end of file +==== src/main.ts (0 errors) ==== + import 'someModule'; \ No newline at end of file diff --git a/tests/baselines/reference/reactJsxReactResolvedNodeNext.js b/tests/baselines/reference/reactJsxReactResolvedNodeNext.js index c87ced322e9ef..f36fdc66c2a5b 100644 --- a/tests/baselines/reference/reactJsxReactResolvedNodeNext.js +++ b/tests/baselines/reference/reactJsxReactResolvedNodeNext.js @@ -10,7 +10,7 @@ export const a =
; "types": "index.d.ts", } //// [index.d.ts] -export declare namespace JSX { +declare namespace JSX { interface IntrinsicElements { [x: string]: any; } } //// [jsx-runtime.d.ts] diff --git a/tests/baselines/reference/reactJsxReactResolvedNodeNext.symbols b/tests/baselines/reference/reactJsxReactResolvedNodeNext.symbols index 0923e46c6a196..e2ddca8d016e8 100644 --- a/tests/baselines/reference/reactJsxReactResolvedNodeNext.symbols +++ b/tests/baselines/reference/reactJsxReactResolvedNodeNext.symbols @@ -3,13 +3,15 @@ === file.tsx === export const a =
; >a : Symbol(a, Decl(file.tsx, 0, 12)) +>div : Symbol(JSX.IntrinsicElements.__index, Decl(index.d.ts, 1, 33)) +>div : Symbol(JSX.IntrinsicElements.__index, Decl(index.d.ts, 1, 33)) === node_modules/@types/react/index.d.ts === -export declare namespace JSX { +declare namespace JSX { >JSX : Symbol(JSX, Decl(index.d.ts, 0, 0)) interface IntrinsicElements { [x: string]: any; } ->IntrinsicElements : Symbol(IntrinsicElements, Decl(index.d.ts, 0, 30)) +>IntrinsicElements : Symbol(IntrinsicElements, Decl(index.d.ts, 0, 23)) >x : Symbol(x, Decl(index.d.ts, 1, 35)) } === node_modules/@types/react/jsx-runtime.d.ts === diff --git a/tests/baselines/reference/reactJsxReactResolvedNodeNext.types b/tests/baselines/reference/reactJsxReactResolvedNodeNext.types index 48971205e1ae4..0e14708fd9eff 100644 --- a/tests/baselines/reference/reactJsxReactResolvedNodeNext.types +++ b/tests/baselines/reference/reactJsxReactResolvedNodeNext.types @@ -10,7 +10,7 @@ export const a =
; > : ^^^ === node_modules/@types/react/index.d.ts === -export declare namespace JSX { +declare namespace JSX { interface IntrinsicElements { [x: string]: any; } >x : string > : ^^^^^^ diff --git a/tests/baselines/reference/reactJsxReactResolvedNodeNextEsm.js b/tests/baselines/reference/reactJsxReactResolvedNodeNextEsm.js index cd40b8e423c8f..834a8fa145c4e 100644 --- a/tests/baselines/reference/reactJsxReactResolvedNodeNextEsm.js +++ b/tests/baselines/reference/reactJsxReactResolvedNodeNextEsm.js @@ -18,7 +18,7 @@ export const a =
; } } //// [index.d.ts] -export declare namespace JSX { +declare namespace JSX { interface IntrinsicElements { [x: string]: any; } } //// [jsx-runtime.d.ts] diff --git a/tests/baselines/reference/reactJsxReactResolvedNodeNextEsm.symbols b/tests/baselines/reference/reactJsxReactResolvedNodeNextEsm.symbols index 6ac83a0ce6b27..5c5343253c544 100644 --- a/tests/baselines/reference/reactJsxReactResolvedNodeNextEsm.symbols +++ b/tests/baselines/reference/reactJsxReactResolvedNodeNextEsm.symbols @@ -3,13 +3,15 @@ === file.tsx === export const a =
; >a : Symbol(a, Decl(file.tsx, 0, 12)) +>div : Symbol(JSX.IntrinsicElements.__index, Decl(index.d.ts, 1, 33)) +>div : Symbol(JSX.IntrinsicElements.__index, Decl(index.d.ts, 1, 33)) === node_modules/@types/react/index.d.ts === -export declare namespace JSX { +declare namespace JSX { >JSX : Symbol(JSX, Decl(index.d.ts, 0, 0)) interface IntrinsicElements { [x: string]: any; } ->IntrinsicElements : Symbol(IntrinsicElements, Decl(index.d.ts, 0, 30)) +>IntrinsicElements : Symbol(IntrinsicElements, Decl(index.d.ts, 0, 23)) >x : Symbol(x, Decl(index.d.ts, 1, 35)) } === node_modules/@types/react/jsx-runtime.d.ts === diff --git a/tests/baselines/reference/reactJsxReactResolvedNodeNextEsm.types b/tests/baselines/reference/reactJsxReactResolvedNodeNextEsm.types index bb074d664595d..5220535071b8b 100644 --- a/tests/baselines/reference/reactJsxReactResolvedNodeNextEsm.types +++ b/tests/baselines/reference/reactJsxReactResolvedNodeNextEsm.types @@ -10,7 +10,7 @@ export const a =
; > : ^^^ === node_modules/@types/react/index.d.ts === -export declare namespace JSX { +declare namespace JSX { interface IntrinsicElements { [x: string]: any; } >x : string > : ^^^^^^ diff --git a/tests/baselines/reference/systemModule9.errors.txt b/tests/baselines/reference/systemModule9.errors.txt index 7dd2738dd6738..be5991350e5de 100644 --- a/tests/baselines/reference/systemModule9.errors.txt +++ b/tests/baselines/reference/systemModule9.errors.txt @@ -1,13 +1,12 @@ systemModule9.ts(1,21): error TS2792: Cannot find module 'file1'. Did you mean to set the 'moduleResolution' option to 'nodenext', or to add aliases to the 'paths' option? systemModule9.ts(2,25): error TS2792: Cannot find module 'file2'. Did you mean to set the 'moduleResolution' option to 'nodenext', or to add aliases to the 'paths' option? systemModule9.ts(3,15): error TS2792: Cannot find module 'file3'. Did you mean to set the 'moduleResolution' option to 'nodenext', or to add aliases to the 'paths' option? -systemModule9.ts(4,8): error TS2792: Cannot find module 'file4'. Did you mean to set the 'moduleResolution' option to 'nodenext', or to add aliases to the 'paths' option? systemModule9.ts(5,25): error TS2792: Cannot find module 'file5'. Did you mean to set the 'moduleResolution' option to 'nodenext', or to add aliases to the 'paths' option? systemModule9.ts(6,22): error TS2792: Cannot find module 'file6'. Did you mean to set the 'moduleResolution' option to 'nodenext', or to add aliases to the 'paths' option? systemModule9.ts(16,15): error TS2792: Cannot find module 'file7'. Did you mean to set the 'moduleResolution' option to 'nodenext', or to add aliases to the 'paths' option? -==== systemModule9.ts (7 errors) ==== +==== systemModule9.ts (6 errors) ==== import * as ns from 'file1'; ~~~~~~~ !!! error TS2792: Cannot find module 'file1'. Did you mean to set the 'moduleResolution' option to 'nodenext', or to add aliases to the 'paths' option? @@ -18,8 +17,6 @@ systemModule9.ts(16,15): error TS2792: Cannot find module 'file7'. Did you mean ~~~~~~~ !!! error TS2792: Cannot find module 'file3'. Did you mean to set the 'moduleResolution' option to 'nodenext', or to add aliases to the 'paths' option? import 'file4' - ~~~~~~~ -!!! error TS2792: Cannot find module 'file4'. Did you mean to set the 'moduleResolution' option to 'nodenext', or to add aliases to the 'paths' option? import e, * as ns2 from 'file5'; ~~~~~~~ !!! error TS2792: Cannot find module 'file5'. Did you mean to set the 'moduleResolution' option to 'nodenext', or to add aliases to the 'paths' option? diff --git a/tests/cases/compiler/jsxClassAttributeResolution.tsx b/tests/cases/compiler/jsxClassAttributeResolution.tsx index f18ae3d3d5d84..32263ecd794ee 100644 --- a/tests/cases/compiler/jsxClassAttributeResolution.tsx +++ b/tests/cases/compiler/jsxClassAttributeResolution.tsx @@ -14,7 +14,7 @@ export const a = ; interface IntrinsicClassAttributesAlias { ref: T } -export declare namespace JSX { +declare namespace JSX { type IntrinsicClassAttributes = IntrinsicClassAttributesAlias } // @filename: node_modules/@types/react/jsx-runtime.d.ts diff --git a/tests/cases/compiler/reactJsxReactResolvedNodeNext.tsx b/tests/cases/compiler/reactJsxReactResolvedNodeNext.tsx index 9744c28f945cd..0cc64eda70a14 100644 --- a/tests/cases/compiler/reactJsxReactResolvedNodeNext.tsx +++ b/tests/cases/compiler/reactJsxReactResolvedNodeNext.tsx @@ -11,7 +11,7 @@ export const a =
; "types": "index.d.ts", } // @filename: node_modules/@types/react/index.d.ts -export declare namespace JSX { +declare namespace JSX { interface IntrinsicElements { [x: string]: any; } } // @filename: node_modules/@types/react/jsx-runtime.d.ts diff --git a/tests/cases/compiler/reactJsxReactResolvedNodeNextEsm.tsx b/tests/cases/compiler/reactJsxReactResolvedNodeNextEsm.tsx index d9a28c0fe4858..6d2fc006f15db 100644 --- a/tests/cases/compiler/reactJsxReactResolvedNodeNextEsm.tsx +++ b/tests/cases/compiler/reactJsxReactResolvedNodeNextEsm.tsx @@ -19,7 +19,7 @@ export const a =
; } } // @filename: node_modules/@types/react/index.d.ts -export declare namespace JSX { +declare namespace JSX { interface IntrinsicElements { [x: string]: any; } } // @filename: node_modules/@types/react/jsx-runtime.d.ts diff --git a/tests/cases/conformance/externalModules/typeOnly/allowsImportingTsExtension.ts b/tests/cases/conformance/externalModules/typeOnly/allowsImportingTsExtension.ts index be61a7b96f0a4..706a2f27b554b 100644 --- a/tests/cases/conformance/externalModules/typeOnly/allowsImportingTsExtension.ts +++ b/tests/cases/conformance/externalModules/typeOnly/allowsImportingTsExtension.ts @@ -11,7 +11,6 @@ export class A {} // @Filename: b.ts import type { A } from "./a.ts"; // ok import {} from "./a.ts"; // error -import "./a.ts"; // error import { type A as _A } from "./a.ts"; // error type __A = import("./a.ts").A; // ok const aPromise = import("./a.ts"); // error @@ -19,7 +18,6 @@ const aPromise = import("./a.ts"); // error // @Filename: c.ts import type { A } from "./a.d.ts"; // ok import {} from "./a.d.ts"; // error -import "./a.d.ts"; // error import { type A as _A } from "./a.d.ts"; // error type __A = import("./a.d.ts").A; // ok const aPromise = import("./a.d.ts"); // error From a68b4ccd28720f1cc3634c55c8ab839193517aeb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Burzy=C5=84ski?= Date: Thu, 30 May 2024 21:46:21 +0200 Subject: [PATCH 7/8] Revert "fixed missing module resolution errors" This reverts commit 908ddd029d32c00e982f65e2a85aae5b0b914136. --- src/compiler/checker.ts | 8 +++++--- ...anging-`allowImportingTsExtensions`-of-config-file.js | 9 ++------- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 56ced9ad94944..0db4facf7f9bd 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -46812,7 +46812,6 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { } if (checkExternalImportOrExportDeclaration(node)) { const importClause = node.importClause; - const moduleExisted = resolveExternalModuleName(node, node.moduleSpecifier); if (importClause && !checkGrammarImportClause(importClause)) { if (importClause.name) { checkImportBinding(importClause); @@ -46825,8 +46824,11 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { checkExternalEmitHelpers(node, ExternalEmitHelpers.ImportStar); } } - else if (moduleExisted) { - forEach(importClause.namedBindings.elements, checkImportBinding); + else { + const moduleExisted = resolveExternalModuleName(node, node.moduleSpecifier); + if (moduleExisted) { + forEach(importClause.namedBindings.elements, checkImportBinding); + } } } } diff --git a/tests/baselines/reference/tscWatch/programUpdates/when-changing-`allowImportingTsExtensions`-of-config-file.js b/tests/baselines/reference/tscWatch/programUpdates/when-changing-`allowImportingTsExtensions`-of-config-file.js index 4385efd405643..518015404b4c9 100644 --- a/tests/baselines/reference/tscWatch/programUpdates/when-changing-`allowImportingTsExtensions`-of-config-file.js +++ b/tests/baselines/reference/tscWatch/programUpdates/when-changing-`allowImportingTsExtensions`-of-config-file.js @@ -1,7 +1,7 @@ currentDirectory:: /user/username/projects/myproject useCaseSensitiveFileNames: false Input:: //// [/user/username/projects/myproject/a.ts] -export {}; + //// [/user/username/projects/myproject/b.ts] import "./a.ts"; @@ -47,12 +47,7 @@ DirectoryWatcher:: Added:: WatchInfo: /user/username/projects/myproject/node_mod Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /user/username/projects/myproject/node_modules/@types 1 undefined Type roots DirectoryWatcher:: Added:: WatchInfo: /user/username/projects/node_modules/@types 1 undefined Type roots Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /user/username/projects/node_modules/@types 1 undefined Type roots -b.ts:1:8 - error TS5097: An import path can only end with a '.ts' extension when 'allowImportingTsExtensions' is enabled. - -1 import "./a.ts"; -   ~~~~~~~~ - -[HH:MM:SS AM] Found 1 error. Watching for file changes. +[HH:MM:SS 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 From 88dba918ff3d50d879e0dc33c40b9878a5a7c0bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Burzy=C5=84ski?= Date: Sat, 22 Jun 2024 14:08:31 +0200 Subject: [PATCH 8/8] add an extra test case --- .../unittests/tscWatch/programUpdates.ts | 42 +++++ ...ImportingTsExtensions`-of-config-file-2.js | 175 ++++++++++++++++++ 2 files changed, 217 insertions(+) create mode 100644 tests/baselines/reference/tscWatch/programUpdates/when-changing-`allowImportingTsExtensions`-of-config-file-2.js diff --git a/src/testRunner/unittests/tscWatch/programUpdates.ts b/src/testRunner/unittests/tscWatch/programUpdates.ts index 600a45563b4a8..626367c7f3084 100644 --- a/src/testRunner/unittests/tscWatch/programUpdates.ts +++ b/src/testRunner/unittests/tscWatch/programUpdates.ts @@ -2164,6 +2164,48 @@ import { x } from "../b";`, ], }); + verifyTscWatch({ + scenario, + subScenario: "when changing `allowImportingTsExtensions` of config file 2", + commandLineArgs: ["-w", "-p", ".", "--extendedDiagnostics"], + sys: () => { + const module1: File = { + path: `/user/username/projects/myproject/a.ts`, + content: `export const foo = 10;`, + }; + const module2: File = { + path: `/user/username/projects/myproject/b.ts`, + content: `export * as a from "./a.ts";`, + }; + const config: File = { + path: `/user/username/projects/myproject/tsconfig.json`, + content: jsonToReadableText({ + compilerOptions: { + noEmit: true, + allowImportingTsExtensions: false, + }, + }), + }; + return createWatchedSystem([module1, module2, config, libFile], { currentDirectory: "/user/username/projects/myproject" }); + }, + edits: [ + { + caption: "Change allowImportingTsExtensions to true", + edit: sys => + sys.writeFile( + `/user/username/projects/myproject/tsconfig.json`, + jsonToReadableText({ + compilerOptions: { + noEmit: true, + allowImportingTsExtensions: true, + }, + }), + ), + timeouts: sys => sys.runQueuedTimeoutCallbacks(), + }, + ], + }); + verifyTscWatch({ scenario, subScenario: "when changing checkJs of config file", diff --git a/tests/baselines/reference/tscWatch/programUpdates/when-changing-`allowImportingTsExtensions`-of-config-file-2.js b/tests/baselines/reference/tscWatch/programUpdates/when-changing-`allowImportingTsExtensions`-of-config-file-2.js new file mode 100644 index 0000000000000..0e29888a74f3b --- /dev/null +++ b/tests/baselines/reference/tscWatch/programUpdates/when-changing-`allowImportingTsExtensions`-of-config-file-2.js @@ -0,0 +1,175 @@ +currentDirectory:: /user/username/projects/myproject useCaseSensitiveFileNames: false +Input:: +//// [/user/username/projects/myproject/a.ts] +export const foo = 10; + +//// [/user/username/projects/myproject/b.ts] +export * as a from "./a.ts"; + +//// [/user/username/projects/myproject/tsconfig.json] +{ + "compilerOptions": { + "noEmit": true, + "allowImportingTsExtensions": false + } +} + +//// [/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; } + + +/a/lib/tsc.js -w -p . --extendedDiagnostics +Output:: +[HH:MM:SS 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/a.ts","/user/username/projects/myproject/b.ts"] + options: {"noEmit":true,"allowImportingTsExtensions":false,"watch":true,"project":"/user/username/projects/myproject","extendedDiagnostics":true,"configFilePath":"/user/username/projects/myproject/tsconfig.json"} +FileWatcher:: Added:: WatchInfo: /user/username/projects/myproject/a.ts 250 undefined Source file +FileWatcher:: Added:: WatchInfo: /user/username/projects/myproject/b.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 +DirectoryWatcher:: Added:: WatchInfo: /user/username/projects/node_modules/@types 1 undefined Type roots +Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /user/username/projects/node_modules/@types 1 undefined Type roots +b.ts:1:20 - error TS5097: An import path can only end with a '.ts' extension when 'allowImportingTsExtensions' is enabled. + +1 export * as a from "./a.ts"; +   ~~~~~~~~ + +[HH:MM:SS AM] Found 1 error. 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 + + + +PolledWatches:: +/user/username/projects/myproject/node_modules/@types: *new* + {"pollingInterval":500} +/user/username/projects/node_modules/@types: *new* + {"pollingInterval":500} + +FsWatches:: +/a/lib/lib.d.ts: *new* + {} +/user/username/projects/myproject/a.ts: *new* + {} +/user/username/projects/myproject/b.ts: *new* + {} +/user/username/projects/myproject/tsconfig.json: *new* + {} + +FsWatchesRecursive:: +/user/username/projects/myproject: *new* + {} + +Program root files: [ + "/user/username/projects/myproject/a.ts", + "/user/username/projects/myproject/b.ts" +] +Program options: { + "noEmit": true, + "allowImportingTsExtensions": false, + "watch": true, + "project": "/user/username/projects/myproject", + "extendedDiagnostics": true, + "configFilePath": "/user/username/projects/myproject/tsconfig.json" +} +Program structureReused: Not +Program files:: +/a/lib/lib.d.ts +/user/username/projects/myproject/a.ts +/user/username/projects/myproject/b.ts + +Semantic diagnostics in builder refreshed for:: +/a/lib/lib.d.ts +/user/username/projects/myproject/a.ts +/user/username/projects/myproject/b.ts + +Shape signatures in builder refreshed for:: +/a/lib/lib.d.ts (used version) +/user/username/projects/myproject/a.ts (used version) +/user/username/projects/myproject/b.ts (used version) + +exitCode:: ExitStatus.undefined + +Change:: Change allowImportingTsExtensions to true + +Input:: +//// [/user/username/projects/myproject/tsconfig.json] +{ + "compilerOptions": { + "noEmit": true, + "allowImportingTsExtensions": true + } +} + + +Output:: +FileWatcher:: Triggered with /user/username/projects/myproject/tsconfig.json 1:: WatchInfo: /user/username/projects/myproject/tsconfig.json 2000 undefined Config file +Scheduling update +Elapsed:: *ms FileWatcher:: Triggered with /user/username/projects/myproject/tsconfig.json 1:: WatchInfo: /user/username/projects/myproject/tsconfig.json 2000 undefined Config file + + +Timeout callback:: count: 1 +1: timerToUpdateProgram *new* + +Before running Timeout callback:: count: 1 +1: timerToUpdateProgram + +Host is moving to new time +After running Timeout callback:: count: 0 +Output:: +Reloading config file: /user/username/projects/myproject/tsconfig.json +Synchronizing program +[HH:MM:SS AM] File change detected. Starting incremental compilation... + +CreatingProgramWith:: + roots: ["/user/username/projects/myproject/a.ts","/user/username/projects/myproject/b.ts"] + options: {"noEmit":true,"allowImportingTsExtensions":true,"watch":true,"project":"/user/username/projects/myproject","extendedDiagnostics":true,"configFilePath":"/user/username/projects/myproject/tsconfig.json"} +[HH:MM:SS AM] Found 0 errors. Watching for file changes. + + + + + +Program root files: [ + "/user/username/projects/myproject/a.ts", + "/user/username/projects/myproject/b.ts" +] +Program options: { + "noEmit": true, + "allowImportingTsExtensions": true, + "watch": true, + "project": "/user/username/projects/myproject", + "extendedDiagnostics": true, + "configFilePath": "/user/username/projects/myproject/tsconfig.json" +} +Program structureReused: Completely +Program files:: +/a/lib/lib.d.ts +/user/username/projects/myproject/a.ts +/user/username/projects/myproject/b.ts + +Semantic diagnostics in builder refreshed for:: +/a/lib/lib.d.ts +/user/username/projects/myproject/a.ts +/user/username/projects/myproject/b.ts + +No shapes updated in the builder:: + +exitCode:: ExitStatus.undefined