Skip to content

Commit c48b52f

Browse files
committed
Merge branch 'master' into release-2.8
2 parents 67c7b36 + 3dc754a commit c48b52f

14 files changed

+211
-33
lines changed

.travis.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,8 @@ matrix:
1616
branches:
1717
only:
1818
- master
19-
- release-2.5
20-
- release-2.6
2119
- release-2.7
20+
- release-2.8
2221

2322
install:
2423
- npm uninstall typescript --no-save

src/compiler/program.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2201,7 +2201,7 @@ namespace ts {
22012201

22022202
if (options.emitDeclarationOnly) {
22032203
if (!options.declaration) {
2204-
createDiagnosticForOptionName(Diagnostics.Option_0_cannot_be_specified_without_specifying_option_1, "emitDeclarationOnly", "declarations");
2204+
createDiagnosticForOptionName(Diagnostics.Option_0_cannot_be_specified_without_specifying_option_1, "emitDeclarationOnly", "declaration");
22052205
}
22062206

22072207
if (options.noEmit) {

src/harness/fourslash.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ namespace FourSlash {
435435
}
436436
}
437437

438-
private markerName(m: Marker): string {
438+
public markerName(m: Marker): string {
439439
return ts.forEachEntry(this.testData.markerPositions, (marker, name) => {
440440
if (marker === m) {
441441
return name;
@@ -3768,6 +3768,10 @@ namespace FourSlashInterface {
37683768
return this.state.getMarkerByName(name);
37693769
}
37703770

3771+
public markerName(m: FourSlash.Marker) {
3772+
return this.state.markerName(m);
3773+
}
3774+
37713775
public ranges(): FourSlash.Range[] {
37723776
return this.state.getRanges();
37733777
}
@@ -3810,6 +3814,7 @@ namespace FourSlashInterface {
38103814
this.state.goToEachMarker(markers, typeof a === "function" ? a : b);
38113815
}
38123816

3817+
38133818
public rangeStart(range: FourSlash.Range) {
38143819
this.state.goToRangeStart(range);
38153820
}

src/harness/unittests/tscWatchMode.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2333,9 +2333,9 @@ declare module "fs" {
23332333
verifyRenamingFileInSubFolder(TestFSWithWatch.Tsc_WatchDirectory.NonRecursiveWatchDirectory);
23342334
});
23352335

2336-
it("uses non recursive dynamic polling when renaming file in subfolder", () => {
2337-
verifyRenamingFileInSubFolder(TestFSWithWatch.Tsc_WatchDirectory.DynamicPolling);
2338-
});
2336+
// it("uses non recursive dynamic polling when renaming file in subfolder", () => {
2337+
// verifyRenamingFileInSubFolder(TestFSWithWatch.Tsc_WatchDirectory.DynamicPolling);
2338+
// });
23392339
});
23402340
});
23412341
}

src/lib/dom.generated.d.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3654,7 +3654,7 @@ interface Document extends Node, GlobalEventHandlers, ParentNode, DocumentEvent
36543654
/**
36553655
* Contains information about the current URL.
36563656
*/
3657-
location: Location | string;
3657+
location: Location;
36583658
msCSSOMElementFloatMetrics: boolean;
36593659
msCapsLockWarningOff: boolean;
36603660
/**
@@ -14909,7 +14909,7 @@ interface Window extends EventTarget, WindowTimers, WindowSessionStorage, Window
1490914909
readonly innerWidth: number;
1491014910
readonly isSecureContext: boolean;
1491114911
readonly length: number;
14912-
location: Location | string;
14912+
location: Location;
1491314913
readonly locationbar: BarProp;
1491414914
readonly menubar: BarProp;
1491514915
readonly msContentScript: ExtensionScriptApis;
@@ -15718,7 +15718,7 @@ declare var innerHeight: number;
1571815718
declare var innerWidth: number;
1571915719
declare var isSecureContext: boolean;
1572015720
declare var length: number;
15721-
declare var location: Location | string;
15721+
declare var location: Location;
1572215722
declare var locationbar: BarProp;
1572315723
declare var menubar: BarProp;
1572415724
declare var msContentScript: ExtensionScriptApis;

src/services/completions.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -994,6 +994,7 @@ namespace ts.Completions {
994994
// Since this is qualified name check its a type node location
995995
const isTypeLocation = insideJsDocTagTypeExpression || isPartOfTypeNode(node.parent);
996996
const isRhsOfImportDeclaration = isInRightSideOfInternalImportEqualsDeclaration(node);
997+
const allowTypeOrValue = isRhsOfImportDeclaration || (!isTypeLocation && isPossiblyTypeArgumentPosition(contextToken, sourceFile));
997998
if (isEntityName(node)) {
998999
let symbol = typeChecker.getSymbolAtLocation(node);
9991000
if (symbol) {
@@ -1004,7 +1005,7 @@ namespace ts.Completions {
10041005
const exportedSymbols = Debug.assertEachDefined(typeChecker.getExportsOfModule(symbol), "getExportsOfModule() should all be defined");
10051006
const isValidValueAccess = (symbol: Symbol) => typeChecker.isValidPropertyAccess(<PropertyAccessExpression>(node.parent), symbol.name);
10061007
const isValidTypeAccess = (symbol: Symbol) => symbolCanBeReferencedAtTypeLocation(symbol);
1007-
const isValidAccess = isRhsOfImportDeclaration ?
1008+
const isValidAccess = allowTypeOrValue ?
10081009
// Any kind is allowed when dotting off namespace in internal import equals declaration
10091010
(symbol: Symbol) => isValidTypeAccess(symbol) || isValidValueAccess(symbol) :
10101011
isTypeLocation ? isValidTypeAccess : isValidValueAccess;
@@ -1173,8 +1174,9 @@ namespace ts.Completions {
11731174
}
11741175

11751176
function filterGlobalCompletion(symbols: Symbol[]): void {
1176-
const isTypeCompletion = insideJsDocTagTypeExpression || !isContextTokenValueLocation(contextToken) && (isPartOfTypeNode(location) || isContextTokenTypeLocation(contextToken));
1177-
if (isTypeCompletion) keywordFilters = KeywordCompletionFilters.TypeKeywords;
1177+
const isTypeOnlyCompletion = insideJsDocTagTypeExpression || !isContextTokenValueLocation(contextToken) && (isPartOfTypeNode(location) || isContextTokenTypeLocation(contextToken));
1178+
const allowTypes = isTypeOnlyCompletion || !isContextTokenValueLocation(contextToken) && isPossiblyTypeArgumentPosition(contextToken, sourceFile);
1179+
if (isTypeOnlyCompletion) keywordFilters = KeywordCompletionFilters.TypeKeywords;
11781180

11791181
filterMutate(symbols, symbol => {
11801182
if (!isSourceFile(location)) {
@@ -1190,9 +1192,12 @@ namespace ts.Completions {
11901192
return !!(symbol.flags & SymbolFlags.Namespace);
11911193
}
11921194

1193-
if (isTypeCompletion) {
1195+
if (allowTypes) {
11941196
// Its a type, but you can reach it by namespace.type as well
1195-
return symbolCanBeReferencedAtTypeLocation(symbol);
1197+
const symbolAllowedAsType = symbolCanBeReferencedAtTypeLocation(symbol);
1198+
if (symbolAllowedAsType || isTypeOnlyCompletion) {
1199+
return symbolAllowedAsType;
1200+
}
11961201
}
11971202
}
11981203

@@ -1204,7 +1209,7 @@ namespace ts.Completions {
12041209
function isContextTokenValueLocation(contextToken: Node) {
12051210
return contextToken &&
12061211
contextToken.kind === SyntaxKind.TypeOfKeyword &&
1207-
contextToken.parent.kind === SyntaxKind.TypeQuery;
1212+
(contextToken.parent.kind === SyntaxKind.TypeQuery || isTypeOfExpression(contextToken.parent));
12081213
}
12091214

12101215
function isContextTokenTypeLocation(contextToken: Node): boolean {

src/services/symbolDisplay.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,25 @@
22
namespace ts.SymbolDisplay {
33
// TODO(drosen): use contextual SemanticMeaning.
44
export function getSymbolKind(typeChecker: TypeChecker, symbol: Symbol, location: Node): ScriptElementKind {
5-
const flags = getCombinedLocalAndExportSymbolFlags(symbol);
5+
const result = getSymbolKindOfConstructorPropertyMethodAccessorFunctionOrVar(typeChecker, symbol, location);
6+
if (result !== ScriptElementKind.unknown) {
7+
return result;
8+
}
69

10+
const flags = getCombinedLocalAndExportSymbolFlags(symbol);
711
if (flags & SymbolFlags.Class) {
812
return getDeclarationOfKind(symbol, SyntaxKind.ClassExpression) ?
9-
ScriptElementKind.localClassElement : ScriptElementKind.classElement;
13+
ScriptElementKind.localClassElement : ScriptElementKind.classElement;
1014
}
1115
if (flags & SymbolFlags.Enum) return ScriptElementKind.enumElement;
1216
if (flags & SymbolFlags.TypeAlias) return ScriptElementKind.typeElement;
1317
if (flags & SymbolFlags.Interface) return ScriptElementKind.interfaceElement;
1418
if (flags & SymbolFlags.TypeParameter) return ScriptElementKind.typeParameterElement;
1519

16-
const result = getSymbolKindOfConstructorPropertyMethodAccessorFunctionOrVar(typeChecker, symbol, location);
17-
if (result === ScriptElementKind.unknown) {
18-
if (flags & SymbolFlags.TypeParameter) return ScriptElementKind.typeParameterElement;
19-
if (flags & SymbolFlags.EnumMember) return ScriptElementKind.enumMemberElement;
20-
if (flags & SymbolFlags.Alias) return ScriptElementKind.alias;
21-
if (flags & SymbolFlags.Module) return ScriptElementKind.moduleElement;
22-
}
20+
if (flags & SymbolFlags.TypeParameter) return ScriptElementKind.typeParameterElement;
21+
if (flags & SymbolFlags.EnumMember) return ScriptElementKind.enumMemberElement;
22+
if (flags & SymbolFlags.Alias) return ScriptElementKind.alias;
23+
if (flags & SymbolFlags.Module) return ScriptElementKind.moduleElement;
2324

2425
return result;
2526
}

src/services/utilities.ts

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -890,6 +890,114 @@ namespace ts {
890890
return isTemplateLiteralKind(token.kind) && position > token.getStart(sourceFile);
891891
}
892892

893+
export function findPrecedingMatchingToken(token: Node, matchingTokenKind: SyntaxKind, sourceFile: SourceFile) {
894+
const tokenKind = token.kind;
895+
let remainingMatchingTokens = 0;
896+
while (true) {
897+
token = findPrecedingToken(token.getFullStart(), sourceFile);
898+
if (!token) {
899+
return undefined;
900+
}
901+
902+
if (token.kind === matchingTokenKind) {
903+
if (remainingMatchingTokens === 0) {
904+
return token;
905+
}
906+
907+
remainingMatchingTokens--;
908+
}
909+
else if (token.kind === tokenKind) {
910+
remainingMatchingTokens++;
911+
}
912+
}
913+
}
914+
915+
export function isPossiblyTypeArgumentPosition(token: Node, sourceFile: SourceFile) {
916+
// This function determines if the node could be type argument position
917+
// Since during editing, when type argument list is not complete,
918+
// the tree could be of any shape depending on the tokens parsed before current node,
919+
// scanning of the previous identifier followed by "<" before current node would give us better result
920+
// Note that we also balance out the already provided type arguments, arrays, object literals while doing so
921+
let remainingLessThanTokens = 0;
922+
while (token) {
923+
switch (token.kind) {
924+
case SyntaxKind.LessThanToken:
925+
// Found the beginning of the generic argument expression
926+
token = findPrecedingToken(token.getFullStart(), sourceFile);
927+
const tokenIsIdentifier = token && isIdentifier(token);
928+
if (!remainingLessThanTokens || !tokenIsIdentifier) {
929+
return tokenIsIdentifier;
930+
}
931+
remainingLessThanTokens--;
932+
break;
933+
934+
case SyntaxKind.GreaterThanGreaterThanGreaterThanToken:
935+
remainingLessThanTokens = + 3;
936+
break;
937+
938+
case SyntaxKind.GreaterThanGreaterThanToken:
939+
remainingLessThanTokens = + 2;
940+
break;
941+
942+
case SyntaxKind.GreaterThanToken:
943+
remainingLessThanTokens++;
944+
break;
945+
946+
case SyntaxKind.CloseBraceToken:
947+
// This can be object type, skip untill we find the matching open brace token
948+
// Skip untill the matching open brace token
949+
token = findPrecedingMatchingToken(token, SyntaxKind.OpenBraceToken, sourceFile);
950+
if (!token) return false;
951+
break;
952+
953+
case SyntaxKind.CloseParenToken:
954+
// This can be object type, skip untill we find the matching open brace token
955+
// Skip untill the matching open brace token
956+
token = findPrecedingMatchingToken(token, SyntaxKind.OpenParenToken, sourceFile);
957+
if (!token) return false;
958+
break;
959+
960+
case SyntaxKind.CloseBracketToken:
961+
// This can be object type, skip untill we find the matching open brace token
962+
// Skip untill the matching open brace token
963+
token = findPrecedingMatchingToken(token, SyntaxKind.OpenBracketToken, sourceFile);
964+
if (!token) return false;
965+
break;
966+
967+
// Valid tokens in a type name. Skip.
968+
case SyntaxKind.CommaToken:
969+
case SyntaxKind.EqualsGreaterThanToken:
970+
971+
case SyntaxKind.Identifier:
972+
case SyntaxKind.StringLiteral:
973+
case SyntaxKind.NumericLiteral:
974+
case SyntaxKind.TrueKeyword:
975+
case SyntaxKind.FalseKeyword:
976+
977+
case SyntaxKind.TypeOfKeyword:
978+
case SyntaxKind.ExtendsKeyword:
979+
case SyntaxKind.KeyOfKeyword:
980+
case SyntaxKind.DotToken:
981+
case SyntaxKind.BarToken:
982+
case SyntaxKind.QuestionToken:
983+
case SyntaxKind.ColonToken:
984+
break;
985+
986+
default:
987+
if (isTypeNode(token)) {
988+
break;
989+
}
990+
991+
// Invalid token in type
992+
return false;
993+
}
994+
995+
token = findPrecedingToken(token.getFullStart(), sourceFile);
996+
}
997+
998+
return false;
999+
}
1000+
8931001
/**
8941002
* Returns true if the cursor at position in sourceFile is within a comment.
8951003
*
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
error TS5052: Option 'emitDeclarationOnly' cannot be specified without specifying option 'declarations'.
1+
error TS5052: Option 'emitDeclarationOnly' cannot be specified without specifying option 'declaration'.
22

33

4-
!!! error TS5052: Option 'emitDeclarationOnly' cannot be specified without specifying option 'declarations'.
4+
!!! error TS5052: Option 'emitDeclarationOnly' cannot be specified without specifying option 'declaration'.
55
==== tests/cases/compiler/hello.ts (0 errors) ====
66
var hello = "yo!";
77

tests/baselines/reference/declFileEmitDeclarationOnlyError2.errors.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
error TS5052: Option 'emitDeclarationOnly' cannot be specified without specifying option 'declarations'.
1+
error TS5052: Option 'emitDeclarationOnly' cannot be specified without specifying option 'declaration'.
22
error TS5053: Option 'emitDeclarationOnly' cannot be specified with option 'noEmit'.
33

44

5-
!!! error TS5052: Option 'emitDeclarationOnly' cannot be specified without specifying option 'declarations'.
5+
!!! error TS5052: Option 'emitDeclarationOnly' cannot be specified without specifying option 'declaration'.
66
!!! error TS5053: Option 'emitDeclarationOnly' cannot be specified with option 'noEmit'.
77
==== tests/cases/compiler/hello.ts (0 errors) ====
88
var hello = "yo!";

0 commit comments

Comments
 (0)