File tree Expand file tree Collapse file tree 2 files changed +37
-2
lines changed
Expand file tree Collapse file tree 2 files changed +37
-2
lines changed Original file line number Diff line number Diff line change @@ -184,14 +184,14 @@ namespace ts.Completions.StringCompletions {
184184
185185 case SyntaxKind . CallExpression :
186186 case SyntaxKind . NewExpression :
187- if ( ! isRequireCall ( parent , /*checkArgumentIsStringLiteralLike*/ false ) && ! isImportCall ( parent ) ) {
187+ if ( ! isRequireCallArgument ( node ) && ! isImportCall ( parent ) ) {
188188 const argumentInfo = SignatureHelp . getArgumentInfoForCompletions ( node , position , sourceFile ) ;
189189 // Get string literal completions from specialized signatures of the target
190190 // i.e. declare function f(a: 'A');
191191 // f("/*completion position*/")
192192 return argumentInfo ? getStringLiteralCompletionsFromSignature ( argumentInfo , typeChecker ) : fromContextualType ( ) ;
193193 }
194- // falls through (is `require("")` or `import("")`)
194+ // falls through (is `require("")` or `require(""` or ` import("")`)
195195
196196 case SyntaxKind . ImportDeclaration :
197197 case SyntaxKind . ExportDeclaration :
@@ -759,4 +759,14 @@ namespace ts.Completions.StringCompletions {
759759 function containsSlash ( fragment : string ) {
760760 return stringContains ( fragment , directorySeparator ) ;
761761 }
762+
763+ /**
764+ * Matches
765+ * require(""
766+ * require("")
767+ */
768+ function isRequireCallArgument ( node : Node ) {
769+ return isCallExpression ( node . parent ) && firstOrUndefined ( node . parent . arguments ) === node
770+ && isIdentifier ( node . parent . expression ) && node . parent . expression . escapedText === "require" ;
771+ }
762772}
Original file line number Diff line number Diff line change 1+ /// <reference path='fourslash.ts' />
2+
3+ // @allowJs : true
4+ // @Filename : foo.js
5+ ////var foo = require("/**/"
6+ ////
7+ ////foo();
8+ ////
9+ /////**
10+ //// * @return {void }
11+ //// */
12+ ////function foo() {
13+ //// }
14+
15+ // @Filename : package.json
16+ //// { "dependencies": { "fake-module": "latest" } }
17+
18+ // @Filename : node_modules/fake-module/index.js
19+ /////* fake-module */
20+
21+ verify . completions ( {
22+ marker : "" ,
23+ exact : [ "fake-module" ] ,
24+ isNewIdentifierLocation : true
25+ } )
You can’t perform that action at this time.
0 commit comments