Skip to content

Commit 96e8fbc

Browse files
sheonhansheetalkamat
authored andcommitted
Fix for issue #32528: Prevent meta property from appearing twice (#35844)
* fix meta property from appearing twice * handle case where ImportMeta has props defined * rename file * use exclude instead of exact * undo comment * this file should have no change * change file name back * add more test cases * remove comment and text validation * fix formatting
1 parent 1a10e71 commit 96e8fbc

File tree

4 files changed

+72
-5
lines changed

4 files changed

+72
-5
lines changed

src/services/completions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1143,7 +1143,7 @@ namespace ts.Completions {
11431143
}
11441144
}
11451145

1146-
if (isMetaProperty(node) && (node.keywordToken === SyntaxKind.NewKeyword || node.keywordToken === SyntaxKind.ImportKeyword)) {
1146+
if (isMetaProperty(node) && (node.keywordToken === SyntaxKind.NewKeyword || node.keywordToken === SyntaxKind.ImportKeyword) && contextToken === node.getChildAt(1)) {
11471147
const completion = (node.keywordToken === SyntaxKind.NewKeyword) ? "target" : "meta";
11481148
symbols.push(typeChecker.createSymbol(SymbolFlags.Property, escapeLeadingUnderscores(completion)));
11491149
return;
Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,25 @@
11
/// <reference path='fourslash.ts' />
22

3-
////import./**/
3+
// @Filename: a.ts
4+
////import./*1*/
45

5-
verify.completions({ marker: "", exact: "meta" });
6+
// @Filename: b.ts
7+
////import.meta./*2*/
8+
9+
// @Filename: c.ts
10+
////import./*3*/meta
11+
12+
verify.completions(
13+
{
14+
marker: "1",
15+
exact: "meta"
16+
},
17+
{
18+
marker: "2",
19+
exact: undefined
20+
},
21+
{
22+
marker: "3",
23+
exact: "meta"
24+
}
25+
);
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
// Module: esnext
4+
5+
// @Filename: a.ts
6+
////import./*1*/
7+
8+
// @Filename: b.ts
9+
////declare global {
10+
//// interface ImportMeta {
11+
//// url: string;
12+
//// }
13+
////}
14+
////import.meta./*2*/
15+
16+
// @Filename: c.ts
17+
////import.meta./*3*/url
18+
19+
// @Filename: d.ts
20+
////import./*4*/meta
21+
22+
verify.completions(
23+
{
24+
marker: "1",
25+
exact: "meta"
26+
},
27+
{
28+
marker: "2",
29+
includes: ["url"],
30+
excludes: ["meta"]
31+
},
32+
{
33+
marker: "3",
34+
includes: ["url"],
35+
excludes: ["meta"]
36+
},
37+
{
38+
marker: "4",
39+
exact: "meta"
40+
}
41+
);

tests/cases/fourslash/completionsNewTarget.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,14 @@
22

33
////class C {
44
//// constructor() {
5-
//// if (C === new./**/)
5+
//// if (C === new./*1*/)
6+
//// }
7+
////}
8+
////class D {
9+
//// constructor() {
10+
//// if (D === new.target./*2*/)
611
//// }
712
////}
813

9-
verify.completions({ marker: "", exact: "target" });
14+
verify.completions({ marker: "1", exact: "target" });
15+
verify.completions({ marker: "2", excludes: ["target"] });

0 commit comments

Comments
 (0)