Merge branch 'master' into objectLiteralCompletion

This commit is contained in:
Mohamed Hegazy
2014-10-08 17:29:47 -07:00
18 changed files with 279 additions and 66 deletions
+14 -8
View File
@@ -3231,21 +3231,27 @@ module ts {
}
if (targetSourceFile === undefined) {
// No targetSourceFile is specified (e.g. calling emitter from batch compiler)
forEach(program.getSourceFiles(), sourceFile => {
if (shouldEmitToOwnFile(sourceFile, compilerOptions)) {
var jsFilePath = getOwnEmitOutputFilePath(sourceFile, ".js");
emitFile(jsFilePath, sourceFile);
}
});
}
else {
// Emit only one file specified in targetFilename. This is mainly used in compilerOnSave feature
var jsFilePath = getOwnEmitOutputFilePath(targetSourceFile, ".js");
emitFile(jsFilePath, targetSourceFile);
}
if (compilerOptions.out) {
emitFile(compilerOptions.out);
if (compilerOptions.out) {
emitFile(compilerOptions.out);
}
} else {
// targetSourceFile is specified (e.g calling emitter from language service)
if (shouldEmitToOwnFile(targetSourceFile, compilerOptions)) {
// If shouldEmitToOwnFile is true or targetSourceFile is an external module file, then emit targetSourceFile in its own output file
var jsFilePath = getOwnEmitOutputFilePath(targetSourceFile, ".js");
emitFile(jsFilePath, targetSourceFile);
} else {
// If shouldEmitToOwnFile is false, then emit all, non-external-module file, into one single output file
emitFile(compilerOptions.out);
}
}
// Sort and make the unique list of diagnostics
-6
View File
@@ -2397,9 +2397,6 @@ module ts {
else {
parseExpected(SyntaxKind.OpenParenToken);
}
// It is an error to have a trailing comma in an argument list. However, the checker
// needs evidence of a trailing comma in order to give good results for signature help.
// That is why we do not allow a trailing comma, but we "preserve" a trailing comma.
callExpr.arguments = parseDelimitedList(ParsingContext.ArgumentExpressions,
parseArgumentExpression, /*allowTrailingComma*/ false);
parseExpected(SyntaxKind.CloseParenToken);
@@ -2627,9 +2624,6 @@ module ts {
parseExpected(SyntaxKind.NewKeyword);
node.func = parseCallAndAccess(parsePrimaryExpression(), /* inNewExpression */ true);
if (parseOptional(SyntaxKind.OpenParenToken) || token === SyntaxKind.LessThanToken && (node.typeArguments = tryParse(parseTypeArgumentsAndOpenParen))) {
// It is an error to have a trailing comma in an argument list. However, the checker
// needs evidence of a trailing comma in order to give good results for signature help.
// That is why we do not allow a trailing comma, but we "preserve" a trailing comma.
node.arguments = parseDelimitedList(ParsingContext.ArgumentExpressions,
parseArgumentExpression, /*allowTrailingComma*/ false);
parseExpected(SyntaxKind.CloseParenToken);
+1 -1
View File
@@ -148,7 +148,7 @@ module ts.NavigationBar {
var item = createItem(child);
if (item !== undefined) {
if (item.text.length > 0) {
var key = item.text + "-" + item.kind;
var key = item.text + "-" + item.kind + "-" + item.indent;
var itemWithSameName = keyToItem[key];
if (itemWithSameName) {
+32 -2
View File
@@ -33,13 +33,14 @@ module ts {
export module OutliningElementsCollector {
export function collectElements(sourceFile: SourceFile): OutliningSpan[] {
var elements: OutliningSpan[] = [];
var collapseText = "...";
function addOutliningSpan(hintSpanNode: Node, startElement: Node, endElement: Node, autoCollapse: boolean) {
if (hintSpanNode && startElement && endElement) {
var span: OutliningSpan = {
textSpan: TypeScript.TextSpan.fromBounds(startElement.pos, endElement.end),
hintSpan: TypeScript.TextSpan.fromBounds(hintSpanNode.getStart(), hintSpanNode.end),
bannerText: "...",
bannerText: collapseText,
autoCollapse: autoCollapse
};
elements.push(span);
@@ -66,10 +67,39 @@ module ts {
}
switch (n.kind) {
case SyntaxKind.Block:
var parent = n.parent;
var openBrace = findChildOfKind(n, SyntaxKind.OpenBraceToken, sourceFile);
var closeBrace = findChildOfKind(n, SyntaxKind.CloseBraceToken, sourceFile);
// Check if the block is standalone, or 'attached' to some parent statement.
// If the latter, we want to collaps the block, but consider its hint span
// to be the entire span of the parent.
if (parent.kind === SyntaxKind.DoStatement ||
parent.kind === SyntaxKind.ForInStatement ||
parent.kind === SyntaxKind.ForStatement ||
parent.kind === SyntaxKind.IfStatement ||
parent.kind === SyntaxKind.WhileStatement ||
parent.kind === SyntaxKind.WithStatement) {
addOutliningSpan(parent, openBrace, closeBrace, autoCollapse(n));
}
else {
// Block was a standalone block. In this case we want to only collapse
// the span of the block, independent of any parent span.
var span = TypeScript.TextSpan.fromBounds(n.getStart(), n.end);
elements.push({
textSpan: span,
hintSpan: span,
bannerText: collapseText,
autoCollapse: autoCollapse(n)
});
}
break;
case SyntaxKind.FunctionBlock:
case SyntaxKind.ModuleBlock:
case SyntaxKind.TryBlock:
case SyntaxKind.TryBlock:
case SyntaxKind.CatchBlock:
case SyntaxKind.FinallyBlock:
var openBrace = findChildOfKind(n, SyntaxKind.OpenBraceToken, sourceFile);
+34 -15
View File
@@ -504,27 +504,47 @@ module ts {
if (!this.namedDeclarations) {
var sourceFile = this;
var namedDeclarations: Declaration[] = [];
var isExternalModule = ts.isExternalModule(sourceFile);
forEachChild(sourceFile, function visit(node: Node): boolean {
forEachChild(sourceFile, function visit(node: Node): void {
switch (node.kind) {
case SyntaxKind.FunctionDeclaration:
case SyntaxKind.Method:
var functionDeclaration = <FunctionDeclaration>node;
if (functionDeclaration.name && functionDeclaration.name.kind !== SyntaxKind.Missing) {
var lastDeclaration = namedDeclarations.length > 0 ?
namedDeclarations[namedDeclarations.length - 1] :
undefined;
// Check whether this declaration belongs to an "overload group".
if (lastDeclaration && functionDeclaration.symbol === lastDeclaration.symbol) {
// Overwrite the last declaration if it was an overload
// and this one is an implementation.
if (functionDeclaration.body && !(<FunctionDeclaration>lastDeclaration).body) {
namedDeclarations[namedDeclarations.length - 1] = functionDeclaration;
}
}
else {
namedDeclarations.push(node);
}
forEachChild(node, visit);
}
break;
case SyntaxKind.ClassDeclaration:
case SyntaxKind.InterfaceDeclaration:
case SyntaxKind.EnumDeclaration:
case SyntaxKind.ModuleDeclaration:
case SyntaxKind.ImportDeclaration:
case SyntaxKind.Method:
case SyntaxKind.FunctionDeclaration:
case SyntaxKind.Constructor:
case SyntaxKind.GetAccessor:
case SyntaxKind.SetAccessor:
case SyntaxKind.TypeLiteral:
if ((<Declaration>node).name) {
namedDeclarations.push(<Declaration>node);
}
forEachChild(node, visit);
break;
// fall through
case SyntaxKind.Constructor:
case SyntaxKind.VariableStatement:
case SyntaxKind.ModuleBlock:
case SyntaxKind.FunctionBlock:
@@ -532,19 +552,17 @@ module ts {
break;
case SyntaxKind.Parameter:
// Only consider properties defined as constructor parameters
if (!(node.flags & NodeFlags.AccessibilityModifier)) {
// Only consider properties defined as constructor parameters
break;
}
// fall through
case SyntaxKind.VariableDeclaration:
case SyntaxKind.EnumMember:
case SyntaxKind.Property:
namedDeclarations.push(<Declaration>node);
break;
}
// do not go any deeper
return undefined;
});
this.namedDeclarations = namedDeclarations;
@@ -3889,7 +3907,8 @@ module ts {
filename = TypeScript.switchToForwardSlashes(filename);
var compilerOptions = program.getCompilerOptions();
var targetSourceFile = program.getSourceFile(filename); // Current selected file to be output
var emitToSingleFile = ts.shouldEmitToOwnFile(targetSourceFile, compilerOptions);
// If --out flag is not specified, shouldEmitToOwnFile is true. Otherwise shouldEmitToOwnFile is false.
var shouldEmitToOwnFile = ts.shouldEmitToOwnFile(targetSourceFile, compilerOptions);
var emitDeclaration = compilerOptions.declaration;
var emitOutput: EmitOutput = {
outputFiles: [],
@@ -3910,7 +3929,7 @@ module ts {
var syntacticDiagnostics: Diagnostic[] = [];
var containSyntacticErrors = false;
if (emitToSingleFile) {
if (shouldEmitToOwnFile) {
// Check only the file we want to emit
containSyntacticErrors = containErrors(program.getDiagnostics(targetSourceFile));
} else {
@@ -3937,7 +3956,7 @@ module ts {
// Perform semantic and force a type check before emit to ensure that all symbols are updated
// EmitFiles will report if there is an error from TypeChecker and Emitter
// Depend whether we will have to emit into a single file or not either emit only selected file in the project, emit all files into a single file
var emitFilesResult = emitToSingleFile ? getFullTypeCheckChecker().emitFiles(targetSourceFile) : getFullTypeCheckChecker().emitFiles();
var emitFilesResult = getFullTypeCheckChecker().emitFiles(targetSourceFile);
emitOutput.emitOutputStatus = emitFilesResult.emitResultStatus;
// Reset writer back to undefined to make sure that we produce an error message if CompilerHost.writeFile method is called when we are not in getEmitOutput
+3 -2
View File
@@ -174,7 +174,7 @@ module ts {
}
/// TODO: delete this, it is only needed until the VS interface is updated
enum LanguageVersion {
export enum LanguageVersion {
EcmaScript3 = 0,
EcmaScript5 = 1,
}
@@ -502,7 +502,8 @@ module ts {
start: diagnostic.start,
length: diagnostic.length,
/// TODO: no need for the tolowerCase call
category: DiagnosticCategory[diagnostic.category].toLowerCase()
category: DiagnosticCategory[diagnostic.category].toLowerCase(),
code: diagnostic.code
};
}
+6
View File
@@ -241,6 +241,12 @@ module ts.SignatureHelp {
return undefined;
}
// If the node is not a subspan of its parent, this is a big problem.
// There have been crashes that might be caused by this violation.
if (n.pos < n.parent.pos || n.end > n.parent.end) {
Debug.fail("Node of kind " + SyntaxKind[n.kind] + " is not a subspan of its parent of kind " + SyntaxKind[n.parent.kind]);
}
var argumentInfo = getImmediatelyContainingArgumentInfo(n);
if (argumentInfo) {
return argumentInfo;
+8 -1
View File
@@ -27,11 +27,18 @@ module ts {
// for the position of the relevant node (or comma).
var syntaxList = forEach(node.parent.getChildren(), c => {
// find syntax list that covers the span of the node
if (c.kind == SyntaxKind.SyntaxList && c.pos <= node.pos && c.end >= node.end) {
if (c.kind === SyntaxKind.SyntaxList && c.pos <= node.pos && c.end >= node.end) {
return c;
}
});
// syntaxList should not be undefined here. If it is, there is a problem. Find out if
// there at least is a child that is a list.
if (!syntaxList) {
Debug.assert(findChildOfKind(node.parent, SyntaxKind.SyntaxList),
"Node of kind " + SyntaxKind[node.parent.kind] + " has no list children");
}
return syntaxList;
}