Skip to content

Commit a4f8303

Browse files
committed
fix(52543): escape module specifiers
1 parent 9ee3315 commit a4f8303

File tree

3 files changed

+121
-1
lines changed

3 files changed

+121
-1
lines changed

src/services/completions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2045,7 +2045,7 @@ function completionEntryDataToSymbolOriginInfo(data: CompletionEntryData, comple
20452045

20462046
function getInsertTextAndReplacementSpanForImportCompletion(name: string, importStatementCompletion: ImportStatementCompletionInfo, origin: SymbolOriginInfoResolvedExport, useSemicolons: boolean, sourceFile: SourceFile, options: CompilerOptions, preferences: UserPreferences) {
20472047
const replacementSpan = importStatementCompletion.replacementSpan;
2048-
const quotedModuleSpecifier = quote(sourceFile, preferences, origin.moduleSpecifier);
2048+
const quotedModuleSpecifier = quote(sourceFile, preferences, escapeSnippetText(origin.moduleSpecifier));
20492049
const exportKind =
20502050
origin.isDefaultExport ? ExportKind.Default :
20512051
origin.exportName === InternalSymbolName.ExportEquals ? ExportKind.ExportEquals :
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
=== /tests/cases/fourslash/./bar.ts ===
2+
// import f
3+
// ^
4+
// | ----------------------------------------------------------------------
5+
// | function foo(): void
6+
// | type
7+
// | ----------------------------------------------------------------------
8+
9+
[
10+
{
11+
"marker": {
12+
"fileName": "/tests/cases/fourslash/./bar.ts",
13+
"position": 8,
14+
"name": ""
15+
},
16+
"item": {
17+
"flags": 11,
18+
"isGlobalCompletion": false,
19+
"isMemberCompletion": false,
20+
"isNewIdentifierLocation": true,
21+
"optionalReplacementSpan": {
22+
"start": 7,
23+
"length": 1
24+
},
25+
"entries": [
26+
{
27+
"name": "foo",
28+
"kind": "function",
29+
"kindModifiers": "export",
30+
"sortText": "11",
31+
"source": [
32+
{
33+
"text": "./$foo",
34+
"kind": "text"
35+
}
36+
],
37+
"insertText": "import { foo$1 } from \"./\\\\$foo\";",
38+
"replacementSpan": {
39+
"start": 0,
40+
"length": 8
41+
},
42+
"sourceDisplay": [
43+
{
44+
"text": "./$foo",
45+
"kind": "text"
46+
}
47+
],
48+
"isSnippet": true,
49+
"isImportStatementCompletion": true,
50+
"data": {
51+
"exportName": "foo",
52+
"moduleSpecifier": "./$foo",
53+
"fileName": "/tests/cases/fourslash/$foo.ts"
54+
},
55+
"displayParts": [
56+
{
57+
"text": "function",
58+
"kind": "keyword"
59+
},
60+
{
61+
"text": " ",
62+
"kind": "space"
63+
},
64+
{
65+
"text": "foo",
66+
"kind": "functionName"
67+
},
68+
{
69+
"text": "(",
70+
"kind": "punctuation"
71+
},
72+
{
73+
"text": ")",
74+
"kind": "punctuation"
75+
},
76+
{
77+
"text": ":",
78+
"kind": "punctuation"
79+
},
80+
{
81+
"text": " ",
82+
"kind": "space"
83+
},
84+
{
85+
"text": "void",
86+
"kind": "keyword"
87+
}
88+
],
89+
"documentation": []
90+
},
91+
{
92+
"name": "type",
93+
"kind": "keyword",
94+
"kindModifiers": "",
95+
"sortText": "15",
96+
"displayParts": [
97+
{
98+
"text": "type",
99+
"kind": "keyword"
100+
}
101+
]
102+
}
103+
]
104+
}
105+
}
106+
]
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
// @Filename: ./$foo.ts
4+
////export function foo() {}
5+
6+
// @Filename: ./bar.ts
7+
////import f/**/
8+
9+
verify.baselineCompletions({
10+
includeCompletionsForImportStatements: true,
11+
includeCompletionsForModuleExports: true,
12+
includeCompletionsWithSnippetText: true,
13+
includeCompletionsWithInsertText: true,
14+
});

0 commit comments

Comments
 (0)