Merge branch 'master' into release-2.8

This commit is contained in:
Mohamed Hegazy 2018-03-09 14:43:30 -08:00
commit c48b52f676
14 changed files with 211 additions and 33 deletions

View File

@ -16,9 +16,8 @@ matrix:
branches:
only:
- master
- release-2.5
- release-2.6
- release-2.7
- release-2.8
install:
- npm uninstall typescript --no-save

View File

@ -2201,7 +2201,7 @@ namespace ts {
if (options.emitDeclarationOnly) {
if (!options.declaration) {
createDiagnosticForOptionName(Diagnostics.Option_0_cannot_be_specified_without_specifying_option_1, "emitDeclarationOnly", "declarations");
createDiagnosticForOptionName(Diagnostics.Option_0_cannot_be_specified_without_specifying_option_1, "emitDeclarationOnly", "declaration");
}
if (options.noEmit) {

View File

@ -435,7 +435,7 @@ namespace FourSlash {
}
}
private markerName(m: Marker): string {
public markerName(m: Marker): string {
return ts.forEachEntry(this.testData.markerPositions, (marker, name) => {
if (marker === m) {
return name;
@ -3768,6 +3768,10 @@ namespace FourSlashInterface {
return this.state.getMarkerByName(name);
}
public markerName(m: FourSlash.Marker) {
return this.state.markerName(m);
}
public ranges(): FourSlash.Range[] {
return this.state.getRanges();
}
@ -3810,6 +3814,7 @@ namespace FourSlashInterface {
this.state.goToEachMarker(markers, typeof a === "function" ? a : b);
}
public rangeStart(range: FourSlash.Range) {
this.state.goToRangeStart(range);
}

View File

@ -2333,9 +2333,9 @@ declare module "fs" {
verifyRenamingFileInSubFolder(TestFSWithWatch.Tsc_WatchDirectory.NonRecursiveWatchDirectory);
});
it("uses non recursive dynamic polling when renaming file in subfolder", () => {
verifyRenamingFileInSubFolder(TestFSWithWatch.Tsc_WatchDirectory.DynamicPolling);
});
// it("uses non recursive dynamic polling when renaming file in subfolder", () => {
// verifyRenamingFileInSubFolder(TestFSWithWatch.Tsc_WatchDirectory.DynamicPolling);
// });
});
});
}

View File

@ -3654,7 +3654,7 @@ interface Document extends Node, GlobalEventHandlers, ParentNode, DocumentEvent
/**
* Contains information about the current URL.
*/
location: Location | string;
location: Location;
msCSSOMElementFloatMetrics: boolean;
msCapsLockWarningOff: boolean;
/**
@ -14909,7 +14909,7 @@ interface Window extends EventTarget, WindowTimers, WindowSessionStorage, Window
readonly innerWidth: number;
readonly isSecureContext: boolean;
readonly length: number;
location: Location | string;
location: Location;
readonly locationbar: BarProp;
readonly menubar: BarProp;
readonly msContentScript: ExtensionScriptApis;
@ -15718,7 +15718,7 @@ declare var innerHeight: number;
declare var innerWidth: number;
declare var isSecureContext: boolean;
declare var length: number;
declare var location: Location | string;
declare var location: Location;
declare var locationbar: BarProp;
declare var menubar: BarProp;
declare var msContentScript: ExtensionScriptApis;

View File

@ -994,6 +994,7 @@ namespace ts.Completions {
// Since this is qualified name check its a type node location
const isTypeLocation = insideJsDocTagTypeExpression || isPartOfTypeNode(node.parent);
const isRhsOfImportDeclaration = isInRightSideOfInternalImportEqualsDeclaration(node);
const allowTypeOrValue = isRhsOfImportDeclaration || (!isTypeLocation && isPossiblyTypeArgumentPosition(contextToken, sourceFile));
if (isEntityName(node)) {
let symbol = typeChecker.getSymbolAtLocation(node);
if (symbol) {
@ -1004,7 +1005,7 @@ namespace ts.Completions {
const exportedSymbols = Debug.assertEachDefined(typeChecker.getExportsOfModule(symbol), "getExportsOfModule() should all be defined");
const isValidValueAccess = (symbol: Symbol) => typeChecker.isValidPropertyAccess(<PropertyAccessExpression>(node.parent), symbol.name);
const isValidTypeAccess = (symbol: Symbol) => symbolCanBeReferencedAtTypeLocation(symbol);
const isValidAccess = isRhsOfImportDeclaration ?
const isValidAccess = allowTypeOrValue ?
// Any kind is allowed when dotting off namespace in internal import equals declaration
(symbol: Symbol) => isValidTypeAccess(symbol) || isValidValueAccess(symbol) :
isTypeLocation ? isValidTypeAccess : isValidValueAccess;
@ -1173,8 +1174,9 @@ namespace ts.Completions {
}
function filterGlobalCompletion(symbols: Symbol[]): void {
const isTypeCompletion = insideJsDocTagTypeExpression || !isContextTokenValueLocation(contextToken) && (isPartOfTypeNode(location) || isContextTokenTypeLocation(contextToken));
if (isTypeCompletion) keywordFilters = KeywordCompletionFilters.TypeKeywords;
const isTypeOnlyCompletion = insideJsDocTagTypeExpression || !isContextTokenValueLocation(contextToken) && (isPartOfTypeNode(location) || isContextTokenTypeLocation(contextToken));
const allowTypes = isTypeOnlyCompletion || !isContextTokenValueLocation(contextToken) && isPossiblyTypeArgumentPosition(contextToken, sourceFile);
if (isTypeOnlyCompletion) keywordFilters = KeywordCompletionFilters.TypeKeywords;
filterMutate(symbols, symbol => {
if (!isSourceFile(location)) {
@ -1190,9 +1192,12 @@ namespace ts.Completions {
return !!(symbol.flags & SymbolFlags.Namespace);
}
if (isTypeCompletion) {
if (allowTypes) {
// Its a type, but you can reach it by namespace.type as well
return symbolCanBeReferencedAtTypeLocation(symbol);
const symbolAllowedAsType = symbolCanBeReferencedAtTypeLocation(symbol);
if (symbolAllowedAsType || isTypeOnlyCompletion) {
return symbolAllowedAsType;
}
}
}
@ -1204,7 +1209,7 @@ namespace ts.Completions {
function isContextTokenValueLocation(contextToken: Node) {
return contextToken &&
contextToken.kind === SyntaxKind.TypeOfKeyword &&
contextToken.parent.kind === SyntaxKind.TypeQuery;
(contextToken.parent.kind === SyntaxKind.TypeQuery || isTypeOfExpression(contextToken.parent));
}
function isContextTokenTypeLocation(contextToken: Node): boolean {

View File

@ -2,24 +2,25 @@
namespace ts.SymbolDisplay {
// TODO(drosen): use contextual SemanticMeaning.
export function getSymbolKind(typeChecker: TypeChecker, symbol: Symbol, location: Node): ScriptElementKind {
const flags = getCombinedLocalAndExportSymbolFlags(symbol);
const result = getSymbolKindOfConstructorPropertyMethodAccessorFunctionOrVar(typeChecker, symbol, location);
if (result !== ScriptElementKind.unknown) {
return result;
}
const flags = getCombinedLocalAndExportSymbolFlags(symbol);
if (flags & SymbolFlags.Class) {
return getDeclarationOfKind(symbol, SyntaxKind.ClassExpression) ?
ScriptElementKind.localClassElement : ScriptElementKind.classElement;
ScriptElementKind.localClassElement : ScriptElementKind.classElement;
}
if (flags & SymbolFlags.Enum) return ScriptElementKind.enumElement;
if (flags & SymbolFlags.TypeAlias) return ScriptElementKind.typeElement;
if (flags & SymbolFlags.Interface) return ScriptElementKind.interfaceElement;
if (flags & SymbolFlags.TypeParameter) return ScriptElementKind.typeParameterElement;
const result = getSymbolKindOfConstructorPropertyMethodAccessorFunctionOrVar(typeChecker, symbol, location);
if (result === ScriptElementKind.unknown) {
if (flags & SymbolFlags.TypeParameter) return ScriptElementKind.typeParameterElement;
if (flags & SymbolFlags.EnumMember) return ScriptElementKind.enumMemberElement;
if (flags & SymbolFlags.Alias) return ScriptElementKind.alias;
if (flags & SymbolFlags.Module) return ScriptElementKind.moduleElement;
}
if (flags & SymbolFlags.TypeParameter) return ScriptElementKind.typeParameterElement;
if (flags & SymbolFlags.EnumMember) return ScriptElementKind.enumMemberElement;
if (flags & SymbolFlags.Alias) return ScriptElementKind.alias;
if (flags & SymbolFlags.Module) return ScriptElementKind.moduleElement;
return result;
}

View File

@ -890,6 +890,114 @@ namespace ts {
return isTemplateLiteralKind(token.kind) && position > token.getStart(sourceFile);
}
export function findPrecedingMatchingToken(token: Node, matchingTokenKind: SyntaxKind, sourceFile: SourceFile) {
const tokenKind = token.kind;
let remainingMatchingTokens = 0;
while (true) {
token = findPrecedingToken(token.getFullStart(), sourceFile);
if (!token) {
return undefined;
}
if (token.kind === matchingTokenKind) {
if (remainingMatchingTokens === 0) {
return token;
}
remainingMatchingTokens--;
}
else if (token.kind === tokenKind) {
remainingMatchingTokens++;
}
}
}
export function isPossiblyTypeArgumentPosition(token: Node, sourceFile: SourceFile) {
// This function determines if the node could be type argument position
// Since during editing, when type argument list is not complete,
// the tree could be of any shape depending on the tokens parsed before current node,
// scanning of the previous identifier followed by "<" before current node would give us better result
// Note that we also balance out the already provided type arguments, arrays, object literals while doing so
let remainingLessThanTokens = 0;
while (token) {
switch (token.kind) {
case SyntaxKind.LessThanToken:
// Found the beginning of the generic argument expression
token = findPrecedingToken(token.getFullStart(), sourceFile);
const tokenIsIdentifier = token && isIdentifier(token);
if (!remainingLessThanTokens || !tokenIsIdentifier) {
return tokenIsIdentifier;
}
remainingLessThanTokens--;
break;
case SyntaxKind.GreaterThanGreaterThanGreaterThanToken:
remainingLessThanTokens = + 3;
break;
case SyntaxKind.GreaterThanGreaterThanToken:
remainingLessThanTokens = + 2;
break;
case SyntaxKind.GreaterThanToken:
remainingLessThanTokens++;
break;
case SyntaxKind.CloseBraceToken:
// This can be object type, skip untill we find the matching open brace token
// Skip untill the matching open brace token
token = findPrecedingMatchingToken(token, SyntaxKind.OpenBraceToken, sourceFile);
if (!token) return false;
break;
case SyntaxKind.CloseParenToken:
// This can be object type, skip untill we find the matching open brace token
// Skip untill the matching open brace token
token = findPrecedingMatchingToken(token, SyntaxKind.OpenParenToken, sourceFile);
if (!token) return false;
break;
case SyntaxKind.CloseBracketToken:
// This can be object type, skip untill we find the matching open brace token
// Skip untill the matching open brace token
token = findPrecedingMatchingToken(token, SyntaxKind.OpenBracketToken, sourceFile);
if (!token) return false;
break;
// Valid tokens in a type name. Skip.
case SyntaxKind.CommaToken:
case SyntaxKind.EqualsGreaterThanToken:
case SyntaxKind.Identifier:
case SyntaxKind.StringLiteral:
case SyntaxKind.NumericLiteral:
case SyntaxKind.TrueKeyword:
case SyntaxKind.FalseKeyword:
case SyntaxKind.TypeOfKeyword:
case SyntaxKind.ExtendsKeyword:
case SyntaxKind.KeyOfKeyword:
case SyntaxKind.DotToken:
case SyntaxKind.BarToken:
case SyntaxKind.QuestionToken:
case SyntaxKind.ColonToken:
break;
default:
if (isTypeNode(token)) {
break;
}
// Invalid token in type
return false;
}
token = findPrecedingToken(token.getFullStart(), sourceFile);
}
return false;
}
/**
* Returns true if the cursor at position in sourceFile is within a comment.
*

View File

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

View File

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

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,42 @@
/// <reference path='fourslash.ts'/>
////let x = 10;
////type Type = void;
////declare function f<T>(): void;
////declare function f2<T, U>(): void;
////f</*1a*/T/*2a*/y/*3a*/
////f</*1b*/T/*2b*/y/*3b*/;
////f</*1c*/T/*2c*/y/*3c*/>
////f</*1d*/T/*2d*/y/*3d*/>
////f</*1eTypeOnly*/T/*2eTypeOnly*/y/*3eTypeOnly*/>();
////
////f2</*1k*/T/*2k*/y/*3k*/,
////f2</*1l*/T/*2l*/y/*3l*/,/*4l*/T/*5l*/y/*6l*/
////f2</*1m*/T/*2m*/y/*3m*/,/*4m*/T/*5m*/y/*6m*/;
////f2</*1n*/T/*2n*/y/*3n*/,/*4n*/T/*5n*/y/*6n*/>
////f2</*1o*/T/*2o*/y/*3o*/,/*4o*/T/*5o*/y/*6o*/>
////f2</*1pTypeOnly*/T/*2pTypeOnly*/y/*3pTypeOnly*/,/*4pTypeOnly*/T/*5pTypeOnly*/y/*6pTypeOnly*/>();
////
////f2<typeof /*1uValueOnly*/x, /*4u*/T/*5u*/y/*6u*/
////
////f2</*1x*/T/*2x*/y/*3x*/, () =>/*4x*/T/*5x*/y/*6x*/
////f2<() =>/*1y*/T/*2y*/y/*3y*/, () =>/*4y*/T/*5y*/y/*6y*/
////f2<any, () =>/*1z*/T/*2z*/y/*3z*/
goTo.eachMarker((marker) => {
const markerName = test.markerName(marker);
if (markerName.endsWith("TypeOnly")) {
verify.not.completionListContains("x");
}
else {
verify.completionListContains("x");
}
if (markerName.endsWith("ValueOnly")) {
verify.not.completionListContains("Type");
}
else {
verify.completionListContains("Type");
}
});

View File

@ -0,0 +1,17 @@
/// <reference path='fourslash.ts'/>
////interface AnalyserNode {
////}
////declare var AnalyserNode: {
//// prototype: AnalyserNode;
//// new(): AnalyserNode;
////};
/////**/
goTo.marker();
verify.completionListContains("AnalyserNode", /*text*/ undefined, /*documentation*/ undefined, "var");
verify.completionEntryDetailIs("AnalyserNode", `interface AnalyserNode
var AnalyserNode: {
new (): AnalyserNode;
prototype: AnalyserNode;
}`, /*documentation*/ undefined, "var")

View File

@ -113,6 +113,7 @@ declare namespace FourSlashInterface {
class test_ {
markers(): Marker[];
markerNames(): string[];
markerName(m: Marker): string;
marker(name?: string): Marker;
ranges(): Range[];
spans(): Array<{ start: number, length: number }>;