Skip to content

Commit 1c41b56

Browse files
committed
Revert "fixed errors on specifier-less imports"
This reverts commit ca9be69.
1 parent 60a95d8 commit 1c41b56

File tree

44 files changed

+88
-367
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+88
-367
lines changed

src/compiler/checker.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4568,9 +4568,9 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
45684568
}
45694569

45704570
if (resolvedModule.resolvedUsingTsExtension && isDeclarationFileName(moduleReference)) {
4571-
const importOrExport = findAncestor(location, isImportDeclaration) ||
4571+
const importOrExport = findAncestor(location, isImportDeclaration)?.importClause ||
45724572
findAncestor(location, or(isImportEqualsDeclaration, isExportDeclaration));
4573-
if (errorNode && importOrExport && !(isImportDeclaration(importOrExport) ? importOrExport.importClause : importOrExport)?.isTypeOnly || findAncestor(location, isImportCall)) {
4573+
if (errorNode && importOrExport && !importOrExport.isTypeOnly || findAncestor(location, isImportCall)) {
45744574
error(
45754575
errorNode,
45764576
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 {
45794579
}
45804580
}
45814581
else if (resolvedModule.resolvedUsingTsExtension && !shouldAllowImportingTsExtension(compilerOptions, currentSourceFile.fileName)) {
4582-
const importOrExport = findAncestor(location, isImportDeclaration) ||
4582+
const importOrExport = findAncestor(location, isImportDeclaration)?.importClause ||
45834583
findAncestor(location, or(isImportEqualsDeclaration, isExportDeclaration));
4584-
if (errorNode && !(importOrExport && (isImportDeclaration(importOrExport) ? importOrExport.importClause : importOrExport)?.isTypeOnly || findAncestor(location, isImportTypeNode))) {
4584+
if (errorNode && !(importOrExport?.isTypeOnly || findAncestor(location, isImportTypeNode))) {
45854585
const tsExtension = Debug.checkDefined(tryExtractTSExtension(moduleReference));
45864586
error(errorNode, Diagnostics.An_import_path_can_only_end_with_a_0_extension_when_allowImportingTsExtensions_is_enabled, tsExtension);
45874587
}

src/testRunner/unittests/programApi.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -216,17 +216,14 @@ describe("unittests:: programApi:: Program.getTypeChecker / Program.getSemanticD
216216
const sourceFile = program.getSourceFile("main.ts")!;
217217
const typeChecker = program.getTypeChecker();
218218
typeChecker.getSymbolAtLocation((sourceFile.statements[0] as ts.ImportDeclaration).moduleSpecifier);
219-
const diagnostics = program.getSemanticDiagnostics()
220-
assert.equal(diagnostics.length, 1);
221-
assert.equal(diagnostics[0].code, ts.Diagnostics.File_0_is_not_a_module.code);
222-
assert.equal(diagnostics[0].messageText, "File '/module.d.ts' is not a module.");
219+
assert.isEmpty(program.getSemanticDiagnostics());
223220
});
224221
});
225222

226223
describe("unittests:: programApi:: CompilerOptions relative paths", () => {
227224
it("resolves relative paths by getCurrentDirectory", () => {
228225
const main = new documents.TextDocument("/main.ts", 'import "module";');
229-
const mod = new documents.TextDocument("/lib/module.ts", "export declare const foo: any;");
226+
const mod = new documents.TextDocument("/lib/module.ts", "declare const foo: any;");
230227

231228
const fs = vfs.createFromFileSystem(Harness.IO, /*ignoreCase*/ false, { documents: [main, mod], cwd: "/" });
232229
const program = ts.createProgram(["./main.ts"], {

src/testRunner/unittests/tscWatch/programUpdates.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2129,7 +2129,7 @@ import { x } from "../b";`,
21292129
sys: () => {
21302130
const module1: File = {
21312131
path: `/user/username/projects/myproject/a.ts`,
2132-
content: `export {};`,
2132+
content: ``,
21332133
};
21342134
const module2: File = {
21352135
path: `/user/username/projects/myproject/b.ts`,

tests/baselines/reference/allowsImportingTsExtension.errors.txt

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
b.ts(2,16): error TS5097: An import path can only end with a '.ts' extension when 'allowImportingTsExtensions' is enabled.
2-
b.ts(3,8): error TS5097: An import path can only end with a '.ts' extension when 'allowImportingTsExtensions' is enabled.
3-
b.ts(4,30): error TS5097: An import path can only end with a '.ts' extension when 'allowImportingTsExtensions' is enabled.
4-
b.ts(6,25): error TS5097: An import path can only end with a '.ts' extension when 'allowImportingTsExtensions' is enabled.
2+
b.ts(3,30): error TS5097: An import path can only end with a '.ts' extension when 'allowImportingTsExtensions' is enabled.
3+
b.ts(5,25): error TS5097: An import path can only end with a '.ts' extension when 'allowImportingTsExtensions' is enabled.
54
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?
6-
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?
7-
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?
8-
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?
5+
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?
6+
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?
97

108

119
==== a.ts (0 errors) ====
@@ -14,13 +12,10 @@ c.ts(6,25): error TS2846: A declaration file cannot be imported without 'import
1412
==== a.d.ts (0 errors) ====
1513
export class A {}
1614

17-
==== b.ts (4 errors) ====
15+
==== b.ts (3 errors) ====
1816
import type { A } from "./a.ts"; // ok
1917
import {} from "./a.ts"; // error
2018
~~~~~~~~
21-
!!! error TS5097: An import path can only end with a '.ts' extension when 'allowImportingTsExtensions' is enabled.
22-
import "./a.ts"; // error
23-
~~~~~~~~
2419
!!! error TS5097: An import path can only end with a '.ts' extension when 'allowImportingTsExtensions' is enabled.
2520
import { type A as _A } from "./a.ts"; // error
2621
~~~~~~~~
@@ -30,13 +25,10 @@ c.ts(6,25): error TS2846: A declaration file cannot be imported without 'import
3025
~~~~~~~~
3126
!!! error TS5097: An import path can only end with a '.ts' extension when 'allowImportingTsExtensions' is enabled.
3227

33-
==== c.ts (4 errors) ====
28+
==== c.ts (3 errors) ====
3429
import type { A } from "./a.d.ts"; // ok
3530
import {} from "./a.d.ts"; // error
3631
~~~~~~~~~~
37-
!!! error TS2846: A declaration file cannot be imported without 'import type'. Did you mean to import an implementation file './a.js' instead?
38-
import "./a.d.ts"; // error
39-
~~~~~~~~~~
4032
!!! error TS2846: A declaration file cannot be imported without 'import type'. Did you mean to import an implementation file './a.js' instead?
4133
import { type A as _A } from "./a.d.ts"; // error
4234
~~~~~~~~~~

tests/baselines/reference/allowsImportingTsExtension.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,13 @@ export class A {}
99
//// [b.ts]
1010
import type { A } from "./a.ts"; // ok
1111
import {} from "./a.ts"; // error
12-
import "./a.ts"; // error
1312
import { type A as _A } from "./a.ts"; // error
1413
type __A = import("./a.ts").A; // ok
1514
const aPromise = import("./a.ts"); // error
1615

1716
//// [c.ts]
1817
import type { A } from "./a.d.ts"; // ok
1918
import {} from "./a.d.ts"; // error
20-
import "./a.d.ts"; // error
2119
import { type A as _A } from "./a.d.ts"; // error
2220
type __A = import("./a.d.ts").A; // ok
2321
const aPromise = import("./a.d.ts"); // error
@@ -27,8 +25,8 @@ const aPromise = import("./a.d.ts"); // error
2725
export class A {
2826
}
2927
//// [b.js]
30-
import "./a.ts"; // error
3128
const aPromise = import("./a.ts"); // error
29+
export {};
3230
//// [c.js]
33-
import "./a.d.ts"; // error
3431
const aPromise = import("./a.d.ts"); // error
32+
export {};

tests/baselines/reference/allowsImportingTsExtension.symbols

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,34 +13,32 @@ import type { A } from "./a.ts"; // ok
1313
>A : Symbol(A, Decl(b.ts, 0, 13))
1414

1515
import {} from "./a.ts"; // error
16-
import "./a.ts"; // error
1716
import { type A as _A } from "./a.ts"; // error
1817
>A : Symbol(A, Decl(a.ts, 0, 0))
19-
>_A : Symbol(_A, Decl(b.ts, 3, 8))
18+
>_A : Symbol(_A, Decl(b.ts, 2, 8))
2019

2120
type __A = import("./a.ts").A; // ok
22-
>__A : Symbol(__A, Decl(b.ts, 3, 38))
21+
>__A : Symbol(__A, Decl(b.ts, 2, 38))
2322
>A : Symbol(A, Decl(a.ts, 0, 0))
2423

2524
const aPromise = import("./a.ts"); // error
26-
>aPromise : Symbol(aPromise, Decl(b.ts, 5, 5))
25+
>aPromise : Symbol(aPromise, Decl(b.ts, 4, 5))
2726
>"./a.ts" : Symbol("a", Decl(a.ts, 0, 0))
2827

2928
=== c.ts ===
3029
import type { A } from "./a.d.ts"; // ok
3130
>A : Symbol(A, Decl(c.ts, 0, 13))
3231

3332
import {} from "./a.d.ts"; // error
34-
import "./a.d.ts"; // error
3533
import { type A as _A } from "./a.d.ts"; // error
3634
>A : Symbol(A, Decl(a.ts, 0, 0))
37-
>_A : Symbol(_A, Decl(c.ts, 3, 8))
35+
>_A : Symbol(_A, Decl(c.ts, 2, 8))
3836

3937
type __A = import("./a.d.ts").A; // ok
40-
>__A : Symbol(__A, Decl(c.ts, 3, 40))
38+
>__A : Symbol(__A, Decl(c.ts, 2, 40))
4139
>A : Symbol(A, Decl(a.ts, 0, 0))
4240

4341
const aPromise = import("./a.d.ts"); // error
44-
>aPromise : Symbol(aPromise, Decl(c.ts, 5, 5))
42+
>aPromise : Symbol(aPromise, Decl(c.ts, 4, 5))
4543
>"./a.d.ts" : Symbol("a", Decl(a.ts, 0, 0))
4644

tests/baselines/reference/allowsImportingTsExtension.types

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import type { A } from "./a.ts"; // ok
1616
> : ^
1717

1818
import {} from "./a.ts"; // error
19-
import "./a.ts"; // error
2019
import { type A as _A } from "./a.ts"; // error
2120
>A : typeof A
2221
> : ^^^^^^^^
@@ -41,7 +40,6 @@ import type { A } from "./a.d.ts"; // ok
4140
> : ^
4241

4342
import {} from "./a.d.ts"; // error
44-
import "./a.d.ts"; // error
4543
import { type A as _A } from "./a.d.ts"; // error
4644
>A : typeof A
4745
> : ^^^^^^^^

tests/baselines/reference/ambientExportDefaultErrors.errors.txt

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,16 @@
1-
consumer.ts(4,8): error TS2307: Cannot find module 'foo' or its corresponding type declarations.
2-
consumer.ts(6,8): error TS2307: Cannot find module 'foo2' or its corresponding type declarations.
31
foo.d.ts(1,16): error TS2714: The expression of an export assignment must be an identifier or qualified name in an ambient context.
42
foo2.d.ts(1,10): error TS2714: The expression of an export assignment must be an identifier or qualified name in an ambient context.
53
indirection.d.ts(3,20): error TS2714: The expression of an export assignment must be an identifier or qualified name in an ambient context.
64
indirection2.d.ts(3,14): error TS2714: The expression of an export assignment must be an identifier or qualified name in an ambient context.
75

86

9-
==== consumer.ts (2 errors) ====
7+
==== consumer.ts (0 errors) ====
108
/// <reference path="./indirection.d.ts" />
119
/// <reference path="./indirection2.d.ts" />
1210
import "indirect";
1311
import "foo";
14-
~~~~~
15-
!!! error TS2307: Cannot find module 'foo' or its corresponding type declarations.
1612
import "indirect2";
1713
import "foo2";
18-
~~~~~~
19-
!!! error TS2307: Cannot find module 'foo2' or its corresponding type declarations.
2014
==== foo.d.ts (1 errors) ====
2115
export default 2 + 2;
2216
~~~~~

tests/baselines/reference/amdDependencyCommentName4.errors.txt

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,16 @@
1-
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?
21
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?
32
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?
43
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?
54
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?
6-
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?
75

86

9-
==== amdDependencyCommentName4.ts (6 errors) ====
7+
==== amdDependencyCommentName4.ts (4 errors) ====
108
///<amd-dependency path='aliasedModule5' name='n1'/>
119
///<amd-dependency path='unaliasedModule3'/>
1210
///<amd-dependency path='aliasedModule6' name='n2'/>
1311
///<amd-dependency path='unaliasedModule4'/>
1412

1513
import "unaliasedModule1";
16-
~~~~~~~~~~~~~~~~~~
17-
!!! error TS2792: Cannot find module 'unaliasedModule1'. Did you mean to set the 'moduleResolution' option to 'nodenext', or to add aliases to the 'paths' option?
1814

1915
import r1 = require("aliasedModule1");
2016
~~~~~~~~~~~~~~~~
@@ -36,6 +32,4 @@ amdDependencyCommentName4.ts(20,8): error TS2792: Cannot find module 'unaliasedM
3632
!!! error TS2792: Cannot find module 'aliasedModule4'. Did you mean to set the 'moduleResolution' option to 'nodenext', or to add aliases to the 'paths' option?
3733
ns;
3834

39-
import "unaliasedModule2";
40-
~~~~~~~~~~~~~~~~~~
41-
!!! error TS2792: Cannot find module 'unaliasedModule2'. Did you mean to set the 'moduleResolution' option to 'nodenext', or to add aliases to the 'paths' option?
35+
import "unaliasedModule2";

tests/baselines/reference/autoAccessorDisallowedModifiers.errors.txt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,14 @@ autoAccessorDisallowedModifiers.ts(31,1): error TS1275: 'accessor' modifier can
2323
autoAccessorDisallowedModifiers.ts(32,1): error TS1275: 'accessor' modifier can only appear on a property declaration.
2424
autoAccessorDisallowedModifiers.ts(33,1): error TS1275: 'accessor' modifier can only appear on a property declaration.
2525
autoAccessorDisallowedModifiers.ts(34,1): error TS1275: 'accessor' modifier can only appear on a property declaration.
26-
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?
2726
autoAccessorDisallowedModifiers.ts(35,1): error TS1275: 'accessor' modifier can only appear on a property declaration.
2827
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?
2928
autoAccessorDisallowedModifiers.ts(36,1): error TS1275: 'accessor' modifier can only appear on a property declaration.
3029
autoAccessorDisallowedModifiers.ts(37,1): error TS1275: 'accessor' modifier can only appear on a property declaration.
3130
autoAccessorDisallowedModifiers.ts(38,1): error TS1275: 'accessor' modifier can only appear on a property declaration.
3231

3332

34-
==== autoAccessorDisallowedModifiers.ts (31 errors) ====
33+
==== autoAccessorDisallowedModifiers.ts (30 errors) ====
3534
abstract class C1 {
3635
accessor accessor a: any;
3736
~~~~~~~~
@@ -116,8 +115,6 @@ autoAccessorDisallowedModifiers.ts(38,1): error TS1275: 'accessor' modifier can
116115
accessor import "x";
117116
~~~~~~~~
118117
!!! error TS1275: 'accessor' modifier can only appear on a property declaration.
119-
~~~
120-
!!! error TS2792: Cannot find module 'x'. Did you mean to set the 'moduleResolution' option to 'nodenext', or to add aliases to the 'paths' option?
121118
accessor import {} from "x";
122119
~~~~~~~~
123120
!!! error TS1275: 'accessor' modifier can only appear on a property declaration.

0 commit comments

Comments
 (0)