File tree Expand file tree Collapse file tree 3 files changed +74
-0
lines changed Expand file tree Collapse file tree 3 files changed +74
-0
lines changed Original file line number Diff line number Diff line change @@ -855,6 +855,7 @@ namespace ts.Completions {
855
855
host : LanguageServiceHost
856
856
) : CompletionData | Request | undefined {
857
857
const typeChecker = program . getTypeChecker ( ) ;
858
+ const compilerOptions = program . getCompilerOptions ( ) ;
858
859
859
860
let start = timestamp ( ) ;
860
861
let currentToken = getTokenAtPosition ( sourceFile , position ) ; // TODO: GH#15853
@@ -1519,7 +1520,16 @@ namespace ts.Completions {
1519
1520
return false ;
1520
1521
}
1521
1522
1523
+ // External modules can have global export declarations
1524
+ // the global declrations are available in all scopes but if the module
1525
+ // already has an explicit export then the global declrations should be
1526
+ // shadowed/filtered out by the module exports to be available as an import suggestion
1522
1527
symbol = skipAlias ( symbol , typeChecker ) ;
1528
+ const origin = symbol . id ? symbolToOriginInfoMap [ symbol . id ] : undefined ;
1529
+ if ( originIsExport ( origin )
1530
+ && origin . moduleSymbol . globalExports && origin . moduleSymbol . exports && ! compilerOptions . allowUmdGlobalAccess ) {
1531
+ return false ;
1532
+ }
1523
1533
1524
1534
// import m = /**/ <-- It can only access namespace (if typing import = x. this would get member symbols and not namespace)
1525
1535
if ( isInRightSideOfInternalImportEqualsDeclaration ( location ) ) {
Original file line number Diff line number Diff line change
1
+ /// <reference path="./fourslash.ts" />
2
+
3
+ // @filename : /package.json
4
+ //// { "dependencies": { "@types/classnames": "*" } }
5
+
6
+ // @filename : /tsconfig.json
7
+ //// { "compilerOptions": { "allowUmdGlobalAccess": true } }
8
+
9
+ // @filename : /node_modules/@types/classnames/package.json
10
+ //// { "name": "@types/classnames", "types": "index.d.ts" }
11
+
12
+ // @filename : /node_modules/@types/classnames/index.d.ts
13
+ //// declare const classNames: () => string;
14
+ //// export = classNames;
15
+ //// export as namespace classNames;
16
+
17
+ // @filename : /SomeReactComponent.tsx
18
+ //// import * as React from 'react';
19
+ ////
20
+ //// const el1 = <div className={class/*1*/}>foo</div>;
21
+
22
+ goTo . marker ( "1" ) ;
23
+
24
+ verify . completions ( {
25
+ includes : [ {
26
+ name : "classNames" ,
27
+ hasAction : undefined , // Asserts to have no actions
28
+ sortText : completion . SortText . GlobalsOrKeywords ,
29
+ } ] ,
30
+ } ) ;
Original file line number Diff line number Diff line change
1
+ /// <reference path="./fourslash.ts" />
2
+
3
+ // @filename : /package.json
4
+ //// { "dependencies": { "@types/classnames": "*" } }
5
+
6
+ // @filename : /tsconfig.json
7
+ //// {}
8
+
9
+ // @filename : /node_modules/@types/classnames/package.json
10
+ //// { "name": "@types/classnames", "types": "index.d.ts" }
11
+
12
+ // @filename : /node_modules/@types/classnames/index.d.ts
13
+ //// declare const classNames: () => string;
14
+ //// export = classNames;
15
+ //// export as namespace classNames;
16
+
17
+ // @filename : /SomeReactComponent.tsx
18
+ //// import * as React from 'react';
19
+ ////
20
+ //// const el1 = <div className={class/*1*/}>foo</div>;
21
+
22
+ goTo . marker ( "1" ) ;
23
+
24
+ verify . completions ( {
25
+ includes : [ {
26
+ name : "classNames" ,
27
+ hasAction : true ,
28
+ source : "/node_modules/@types/classnames/index" ,
29
+ sortText : completion . SortText . AutoImportSuggestions ,
30
+ } ] ,
31
+ preferences : {
32
+ includeCompletionsForModuleExports : true ,
33
+ }
34
+ } ) ;
You can’t perform that action at this time.
0 commit comments