Don't add external module completions in a pure commonjs file (#22583) (#22880)

This commit is contained in:
Andy 2018-03-26 16:30:29 -07:00 committed by GitHub
parent 0a1d427f63
commit c63b206d4f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 15 deletions

View File

@ -1153,7 +1153,8 @@ namespace ts.Completions {
}
}
if (options.includeExternalModuleExports) {
// Don't suggest import completions for a commonjs-only module
if (options.includeExternalModuleExports && !(sourceFile.commonJsModuleIndicator && !sourceFile.externalModuleIndicator)) {
getSymbolsFromOtherSourceFileExports(symbols, previousToken && isIdentifier(previousToken) ? previousToken.text : "", target);
}
filterGlobalCompletion(symbols);

View File

@ -14,20 +14,8 @@
////fo/*c*/
goTo.marker("b");
verify.completionListContains({ name: "foo", source: "/a" }, "const foo: 0", "", "const", /*spanIndex*/ undefined, /*hasAction*/ true, {
includeExternalModuleExports: true,
sourceDisplay: "./a",
});
verify.applyCodeActionFromCompletion("b", {
name: "foo",
source: "/a",
description: `Import 'foo' from module "./a"`,
newFileContent: `import { foo } from "./a";
const a = require("./a");
fo`,
});
// Doesn't activate for commonjs-only module
verify.not.completionListContains({ name: "foo", source: "/a" });
goTo.marker("c");
verify.completionListContains({ name: "foo", source: "/a" }, "const foo: 0", "", "const", /*spanIndex*/ undefined, /*hasAction*/ true, {