From ffe07e7e7128c78ba3ea64b37feaa167ff053a0c Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Wed, 5 Oct 2016 14:19:38 -0700 Subject: [PATCH 1/3] Fix incorrect returning of completion entries when in string literal of property assignment expression Fixes #11232 --- src/services/services.ts | 4 +++- ...letionListInObjectLiteralPropertyAssignment.ts | 15 +++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 tests/cases/fourslash/completionListInObjectLiteralPropertyAssignment.ts diff --git a/src/services/services.ts b/src/services/services.ts index c59fb53282e..b82a26c8039 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -4497,7 +4497,9 @@ namespace ts { return undefined; } - if (node.parent.kind === SyntaxKind.PropertyAssignment && node.parent.parent.kind === SyntaxKind.ObjectLiteralExpression) { + if (node.parent.kind === SyntaxKind.PropertyAssignment && + node.parent.parent.kind === SyntaxKind.ObjectLiteralExpression && + (node.parent).name === node) { // Get quoted name of properties of the object literal expression // i.e. interface ConfigFiles { // 'jspm:dev': string diff --git a/tests/cases/fourslash/completionListInObjectLiteralPropertyAssignment.ts b/tests/cases/fourslash/completionListInObjectLiteralPropertyAssignment.ts new file mode 100644 index 00000000000..14ccd985577 --- /dev/null +++ b/tests/cases/fourslash/completionListInObjectLiteralPropertyAssignment.ts @@ -0,0 +1,15 @@ +/// + +////var foo; +////interface I { +//// metadata: string; +//// wat: string; +////} +////var x: I = { +//// metadata: "/*1*/ +////} + +goTo.marker('1'); + +verify.not.completionListContains("metadata"); +verify.not.completionListContains("wat"); \ No newline at end of file From f30874763f2b1830114bb7b80219fcf574caa018 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Wed, 5 Oct 2016 13:46:47 -0700 Subject: [PATCH 2/3] Even in javascript files when creating completion entry from symbols we need to perform identifier check Fixes #11217 --- src/services/services.ts | 2 +- .../completionListInvalidMemberNames3.ts | 71 +++++++++++++++++++ 2 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 tests/cases/fourslash/completionListInvalidMemberNames3.ts diff --git a/src/services/services.ts b/src/services/services.ts index b82a26c8039..bcd2f3d5c9b 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -4371,7 +4371,7 @@ namespace ts { const entries: CompletionEntry[] = []; if (isSourceFileJavaScript(sourceFile)) { - const uniqueNames = getCompletionEntriesFromSymbols(symbols, entries, location, /*performCharacterChecks*/ false); + const uniqueNames = getCompletionEntriesFromSymbols(symbols, entries, location, /*performCharacterChecks*/ true); addRange(entries, getJavaScriptCompletionEntries(sourceFile, location.pos, uniqueNames)); } else { diff --git a/tests/cases/fourslash/completionListInvalidMemberNames3.ts b/tests/cases/fourslash/completionListInvalidMemberNames3.ts new file mode 100644 index 00000000000..cf1141b4094 --- /dev/null +++ b/tests/cases/fourslash/completionListInvalidMemberNames3.ts @@ -0,0 +1,71 @@ +/// + +// @allowjs: true + +// @Filename: test.js +////interface Symbol { +//// /** Returns a string representation of an object. */ +//// toString(): string; + +//// /** Returns the primitive value of the specified object. */ +//// valueOf(): Object; +////} + +////interface SymbolConstructor { +//// /** +//// * A reference to the prototype. +//// */ +//// readonly prototype: Symbol; + +//// /** +//// * Returns a new unique Symbol value. +//// * @param description Description of the new Symbol object. +//// */ +//// (description?: string | number): symbol; + +//// /** +//// * Returns a Symbol object from the global symbol registry matching the given key if found. +//// * Otherwise, returns a new symbol with this key. +//// * @param key key to search for. +//// */ +//// for(key: string): symbol; + +//// /** +//// * Returns a key from the global symbol registry matching the given Symbol if found. +//// * Otherwise, returns a undefined. +//// * @param sym Symbol to find the key for. +//// */ +//// keyFor(sym: symbol): string | undefined; +////} + +////declare var Symbol: SymbolConstructor;/// + +////interface SymbolConstructor { +//// /** +//// * A method that determines if a constructor object recognizes an object as one of the +//// * constructor’s instances. Called by the semantics of the instanceof operator. +//// */ +//// readonly hasInstance: symbol; +////} + +////interface Function { +//// /** +//// * Determines whether the given value inherits from this function if this function was used +//// * as a constructor function. +//// * +//// * A constructor function can control which objects are recognized as its instances by +//// * 'instanceof' by overriding this method. +//// */ +//// [Symbol.hasInstance](value: any): boolean; +////} + +////interface SomeInterface { +//// (value: number): any; +////} + +////var _ : SomeInterface; +////_./**/ + +goTo.marker(); + +verify.not.completionListContains("[Symbol.hasInstance]"); \ No newline at end of file From d8280d88072f2694df39f112eb8b60f1a6be1c0f Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Wed, 5 Oct 2016 17:19:38 -0700 Subject: [PATCH 3/3] Handle the require call in javascript file for getSymbolAtLocation This helps in getting the alias symbol so that it can go to the definition of external module Fixes #9251 --- src/compiler/checker.ts | 3 +++ tests/cases/fourslash/goToDefinitionJsModuleName.ts | 12 ++++++++++++ 2 files changed, 15 insertions(+) create mode 100644 tests/cases/fourslash/goToDefinitionJsModuleName.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 0ba65d6e61a..03d8259bcfc 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -18167,6 +18167,9 @@ namespace ts { (node.parent).moduleSpecifier === node)) { return resolveExternalModuleName(node, node); } + if (isInJavaScriptFile(node) && isRequireCall(node.parent, /*checkArgumentIsStringLiteral*/ false)) { + return resolveExternalModuleName(node, node); + } // Fall through case SyntaxKind.NumericLiteral: diff --git a/tests/cases/fourslash/goToDefinitionJsModuleName.ts b/tests/cases/fourslash/goToDefinitionJsModuleName.ts new file mode 100644 index 00000000000..eac4bc8053d --- /dev/null +++ b/tests/cases/fourslash/goToDefinitionJsModuleName.ts @@ -0,0 +1,12 @@ +/// + +// @allowJs: true +// @Filename: foo.js +/////*2*/module.exports = {}; + +// @Filename: bar.js +////var x = require(/*1*/"./foo"); + +goTo.marker("1"); +goTo.definition(); +verify.caretAtMarker("2"); \ No newline at end of file