mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-04-12 23:36:28 -05:00
Only add suggestion for modules
This commit is contained in:
@@ -32,7 +32,7 @@ namespace ts {
|
||||
}
|
||||
check(sourceFile);
|
||||
|
||||
if (!isJsFile) {
|
||||
if (!isJsFile && sourceFile.externalModuleIndicator) {
|
||||
for (const statement of sourceFile.statements) {
|
||||
if (isVariableStatement(statement) &&
|
||||
statement.declarationList.flags & NodeFlags.Const &&
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @Filename: /a.ts
|
||||
////export {};
|
||||
////const a = [|require("a")|];
|
||||
////a;
|
||||
|
||||
verify.getSuggestionDiagnostics([{
|
||||
message: "'require' call may be converted to an import.",
|
||||
@@ -11,5 +12,8 @@ verify.getSuggestionDiagnostics([{
|
||||
verify.codeFix({
|
||||
description: "Convert 'require' to 'import'",
|
||||
newFileContent:
|
||||
`import a = require("a");`,
|
||||
// TODO: GH#23781
|
||||
`export {};
|
||||
import a = require("a");
|
||||
a;`,
|
||||
});
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @Filename: /a.ts
|
||||
////export {};
|
||||
////const a = [|require("a")|];
|
||||
////const b = [|require("b")|];
|
||||
|
||||
@@ -8,6 +8,8 @@ verify.codeFixAll({
|
||||
fixId: "requireInTs",
|
||||
fixAllDescription: "Convert all 'require' to 'import'",
|
||||
newFileContent:
|
||||
`import a = require("a");
|
||||
// TODO: GH#23781
|
||||
`export {};
|
||||
import a = require("a");
|
||||
import b = require("b");`,
|
||||
});
|
||||
|
||||
@@ -2,10 +2,15 @@
|
||||
|
||||
// @allowSyntheticDefaultImports: true
|
||||
|
||||
// @Filename: /a.ts
|
||||
////export {};
|
||||
////const a = [|require("a")|];
|
||||
////a;
|
||||
|
||||
verify.codeFix({
|
||||
description: "Convert 'require' to 'import'",
|
||||
newFileContent: `import a from "a";`,
|
||||
newFileContent:
|
||||
// TODO: GH#23781
|
||||
`export {};
|
||||
import a from "a";
|
||||
a;`,
|
||||
});
|
||||
|
||||
5
tests/cases/fourslash/codeFixRequireInTs_onlyIfModule.ts
Normal file
5
tests/cases/fourslash/codeFixRequireInTs_onlyIfModule.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
////const a = [|require("a")|];
|
||||
|
||||
verify.getSuggestionDiagnostics([]);
|
||||
Reference in New Issue
Block a user