Skip to content

Commit 506afe5

Browse files
committed
Merge branch 'master' into metaDataWithStringLiteral
2 parents 8e4efb6 + 3008520 commit 506afe5

10 files changed

+132
-4
lines changed

src/compiler/checker.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18456,6 +18456,9 @@ namespace ts {
1845618456
(<ImportDeclaration>node.parent).moduleSpecifier === node)) {
1845718457
return resolveExternalModuleName(node, <LiteralExpression>node);
1845818458
}
18459+
if (isInJavaScriptFile(node) && isRequireCall(node.parent, /*checkArgumentIsStringLiteral*/ false)) {
18460+
return resolveExternalModuleName(node, <LiteralExpression>node);
18461+
}
1845918462
// Fall through
1846018463

1846118464
case SyntaxKind.NumericLiteral:

src/server/session.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1109,7 +1109,7 @@ namespace ts.server {
11091109

11101110
private getNavigationBarItems(args: protocol.FileRequestArgs, simplifiedResult: boolean): protocol.NavigationBarItem[] | NavigationBarItem[] {
11111111
const { file, project } = this.getFileAndProject(args);
1112-
const items = project.getLanguageService().getNavigationBarItems(file);
1112+
const items = project.getLanguageService(/*ensureSynchronized*/ false).getNavigationBarItems(file);
11131113
if (!items) {
11141114
return undefined;
11151115
}

src/services/completions.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ namespace ts.Completions {
2424
const entries: CompletionEntry[] = [];
2525

2626
if (isSourceFileJavaScript(sourceFile)) {
27-
const uniqueNames = getCompletionEntriesFromSymbols(symbols, entries, location, /*performCharacterChecks*/ false);
27+
const uniqueNames = getCompletionEntriesFromSymbols(symbols, entries, location, /*performCharacterChecks*/ true);
2828
addRange(entries, getJavaScriptCompletionEntries(sourceFile, location.pos, uniqueNames));
2929
}
3030
else {
@@ -138,7 +138,9 @@ namespace ts.Completions {
138138
return undefined;
139139
}
140140

141-
if (node.parent.kind === SyntaxKind.PropertyAssignment && node.parent.parent.kind === SyntaxKind.ObjectLiteralExpression) {
141+
if (node.parent.kind === SyntaxKind.PropertyAssignment &&
142+
node.parent.parent.kind === SyntaxKind.ObjectLiteralExpression &&
143+
(<PropertyAssignment>node.parent).name === node) {
142144
// Get quoted name of properties of the object literal expression
143145
// i.e. interface ConfigFiles {
144146
// 'jspm:dev': string
@@ -1001,6 +1003,7 @@ namespace ts.Completions {
10011003
if ((jsxContainer.kind === SyntaxKind.JsxSelfClosingElement) || (jsxContainer.kind === SyntaxKind.JsxOpeningElement)) {
10021004
// Cursor is inside a JSX self-closing element or opening element
10031005
attrsType = typeChecker.getJsxElementAttributesType(<JsxOpeningLikeElement>jsxContainer);
1006+
isGlobalCompletion = false;
10041007

10051008
if (attrsType) {
10061009
symbols = filterJsxAttributes(typeChecker.getPropertiesOfType(attrsType), (<JsxOpeningLikeElement>jsxContainer).attributes);

src/services/services.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1512,12 +1512,25 @@ namespace ts {
15121512
return NavigationBar.getNavigationBarItems(sourceFile);
15131513
}
15141514

1515+
function isTsOrTsxFile(fileName: string): boolean {
1516+
const kind = getScriptKind(fileName, host);
1517+
return kind === ScriptKind.TS || kind === ScriptKind.TSX;
1518+
}
1519+
15151520
function getSemanticClassifications(fileName: string, span: TextSpan): ClassifiedSpan[] {
1521+
if (!isTsOrTsxFile(fileName)) {
1522+
// do not run semantic classification on non-ts-or-tsx files
1523+
return [];
1524+
}
15161525
synchronizeHostData();
15171526
return ts.getSemanticClassifications(program.getTypeChecker(), cancellationToken, getValidSourceFile(fileName), program.getClassifiableNames(), span);
15181527
}
15191528

15201529
function getEncodedSemanticClassifications(fileName: string, span: TextSpan): Classifications {
1530+
if (!isTsOrTsxFile(fileName)) {
1531+
// do not run semantic classification on non-ts-or-tsx files
1532+
return { spans: [], endOfLineState: EndOfLineState.None };
1533+
}
15211534
synchronizeHostData();
15221535
return ts.getEncodedSemanticClassifications(program.getTypeChecker(), cancellationToken, getValidSourceFile(fileName), program.getClassifiableNames(), span);
15231536
}

tests/baselines/reference/tsxCorrectlyParseLessThanComparison1.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ var __extends = (this && this.__extends) || function (d, b) {
2929
var ShortDetails = (function (_super) {
3030
__extends(ShortDetails, _super);
3131
function ShortDetails() {
32-
_super.apply(this, arguments);
32+
return _super.apply(this, arguments) || this;
3333
}
3434
ShortDetails.prototype.render = function () {
3535
if (this.props.id < 1) {
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
////var foo;
4+
////interface I {
5+
//// metadata: string;
6+
//// wat: string;
7+
////}
8+
////var x: I = {
9+
//// metadata: "/*1*/
10+
////}
11+
12+
goTo.marker('1');
13+
14+
verify.not.completionListContains("metadata");
15+
verify.not.completionListContains("wat");
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
// @allowjs: true
4+
5+
// @Filename: test.js
6+
////interface Symbol {
7+
//// /** Returns a string representation of an object. */
8+
//// toString(): string;
9+
10+
//// /** Returns the primitive value of the specified object. */
11+
//// valueOf(): Object;
12+
////}
13+
14+
////interface SymbolConstructor {
15+
//// /**
16+
//// * A reference to the prototype.
17+
//// */
18+
//// readonly prototype: Symbol;
19+
20+
//// /**
21+
//// * Returns a new unique Symbol value.
22+
//// * @param description Description of the new Symbol object.
23+
//// */
24+
//// (description?: string | number): symbol;
25+
26+
//// /**
27+
//// * Returns a Symbol object from the global symbol registry matching the given key if found.
28+
//// * Otherwise, returns a new symbol with this key.
29+
//// * @param key key to search for.
30+
//// */
31+
//// for(key: string): symbol;
32+
33+
//// /**
34+
//// * Returns a key from the global symbol registry matching the given Symbol if found.
35+
//// * Otherwise, returns a undefined.
36+
//// * @param sym Symbol to find the key for.
37+
//// */
38+
//// keyFor(sym: symbol): string | undefined;
39+
////}
40+
41+
////declare var Symbol: SymbolConstructor;/// <reference path="lib.es2015.symbol.d.ts" />
42+
43+
////interface SymbolConstructor {
44+
//// /**
45+
//// * A method that determines if a constructor object recognizes an object as one of the
46+
//// * constructor’s instances. Called by the semantics of the instanceof operator.
47+
//// */
48+
//// readonly hasInstance: symbol;
49+
////}
50+
51+
////interface Function {
52+
//// /**
53+
//// * Determines whether the given value inherits from this function if this function was used
54+
//// * as a constructor function.
55+
//// *
56+
//// * A constructor function can control which objects are recognized as its instances by
57+
//// * 'instanceof' by overriding this method.
58+
//// */
59+
//// [Symbol.hasInstance](value: any): boolean;
60+
////}
61+
62+
////interface SomeInterface {
63+
//// (value: number): any;
64+
////}
65+
66+
////var _ : SomeInterface;
67+
////_./**/
68+
69+
goTo.marker();
70+
71+
verify.not.completionListContains("[Symbol.hasInstance]");

tests/cases/fourslash/completionListIsGlobalCompletion.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/// <reference path='fourslash.ts'/>
22

3+
//@Filename: file.tsx
34
/////// <reference path="/*1*/..\services\services.ts" /> // no globals in reference paths
45
////import { /*2*/ } from "./file.ts"; // no globals in imports
56
////var test = "/*3*/"; // no globals in strings
@@ -20,6 +21,7 @@
2021
//// /*9*/ // insert globals
2122
////}
2223
/////*10*/ // insert globals
24+
////const y = <div /*11*/ />;
2325
goTo.marker("1");
2426
verify.completionListIsGlobal(false);
2527
goTo.marker("2");
@@ -40,3 +42,5 @@ goTo.marker("9");
4042
verify.completionListIsGlobal(true);
4143
goTo.marker("10");
4244
verify.completionListIsGlobal(true);
45+
goTo.marker("11");
46+
verify.completionListIsGlobal(false);
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/// <reference path='fourslash.ts'/>
2+
3+
// @allowJs: true
4+
// @Filename: foo.js
5+
/////*2*/module.exports = {};
6+
7+
// @Filename: bar.js
8+
////var x = require(/*1*/"./foo");
9+
10+
verify.goToDefinition("1", "2");
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/// <reference path="fourslash.ts"/>
2+
3+
// @Filename: app.js
4+
//// function foo() {
5+
//// }
6+
//// let x = 1;
7+
8+
// no semantic classification in js file
9+
verify.semanticClassificationsAre();

0 commit comments

Comments
 (0)