From b745ea059e9b36aa23983184faebeb5fbdf52a4f Mon Sep 17 00:00:00 2001 From: Elizabeth Dinella Date: Thu, 24 May 2018 14:12:33 -0700 Subject: [PATCH] Fix to issue 23326 for completions on new.target (#24342) * Fix to issue 23326 for completions on new.target * Fixed linting issues - whitespace in if statements * Removed debug statement in test case and consolidated and cleaned up code in switch statement for completions * Added support for import.meta completion --- src/services/completions.ts | 7 +++++++ tests/cases/fourslash/completionImportMeta.ts | 6 ++++++ tests/cases/fourslash/completionsNewTarget.ts | 10 ++++++++++ 3 files changed, 23 insertions(+) create mode 100644 tests/cases/fourslash/completionImportMeta.ts create mode 100644 tests/cases/fourslash/completionsNewTarget.ts diff --git a/src/services/completions.ts b/src/services/completions.ts index 56833298a64..45317be065e 100644 --- a/src/services/completions.ts +++ b/src/services/completions.ts @@ -895,6 +895,7 @@ namespace ts.Completions { node = (parent as QualifiedName).left; break; case SyntaxKind.ImportType: + case SyntaxKind.MetaProperty: node = parent; break; default: @@ -1061,6 +1062,12 @@ namespace ts.Completions { } } + if (isMetaProperty(node) && (node.keywordToken === SyntaxKind.NewKeyword || node.keywordToken === SyntaxKind.ImportKeyword)) { + const completion = (node.keywordToken === SyntaxKind.NewKeyword) ? "target" : "meta"; + symbols.push(typeChecker.createSymbol(SymbolFlags.Property, escapeLeadingUnderscores(completion))); + return; + } + if (!isTypeLocation) { addTypeProperties(typeChecker.getTypeAtLocation(node)!); } diff --git a/tests/cases/fourslash/completionImportMeta.ts b/tests/cases/fourslash/completionImportMeta.ts new file mode 100644 index 00000000000..cac84c2c82f --- /dev/null +++ b/tests/cases/fourslash/completionImportMeta.ts @@ -0,0 +1,6 @@ +/// + +////import./**/ + +goTo.marker(""); +verify.completionListContains("meta"); \ No newline at end of file diff --git a/tests/cases/fourslash/completionsNewTarget.ts b/tests/cases/fourslash/completionsNewTarget.ts new file mode 100644 index 00000000000..3f8a4d689cc --- /dev/null +++ b/tests/cases/fourslash/completionsNewTarget.ts @@ -0,0 +1,10 @@ +/// + +////class C { +//// constructor() { +//// if (C === new./**/) +//// } +////} + +goTo.marker(""); +verify.completionListContains("target"); \ No newline at end of file