Merge branch 'master' into asyncAwaitFidelity

This commit is contained in:
Cyrus Najmabadi
2014-11-25 21:34:46 -08:00
89 changed files with 702 additions and 526 deletions
+1 -1
View File
@@ -81,11 +81,11 @@ module ts {
getTypeCount: () => typeCount,
isUndefinedSymbol: symbol => symbol === undefinedSymbol,
isArgumentsSymbol: symbol => symbol === argumentsSymbol,
emitFiles: invokeEmitter,
getDiagnostics,
getDeclarationDiagnostics,
getGlobalDiagnostics,
checkProgram,
invokeEmitter,
getParentOfSymbol,
getNarrowedTypeOfSymbol,
getDeclaredTypeOfSymbol,
@@ -414,5 +414,7 @@ module ts {
_0_implicitly_has_return_type_any_because_it_does_not_have_a_return_type_annotation_and_is_referenced_directly_or_indirectly_in_one_of_its_return_expressions: { code: 7023, category: DiagnosticCategory.Error, key: "'{0}' implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions." },
Function_implicitly_has_return_type_any_because_it_does_not_have_a_return_type_annotation_and_is_referenced_directly_or_indirectly_in_one_of_its_return_expressions: { code: 7024, category: DiagnosticCategory.Error, key: "Function implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions." },
You_cannot_rename_this_element: { code: 8000, category: DiagnosticCategory.Error, key: "You cannot rename this element." },
yield_expressions_are_not_currently_supported: { code: 9000, category: DiagnosticCategory.Error, key: "'yield' expressions are not currently supported." },
generators_are_not_currently_supported: { code: 9001, category: DiagnosticCategory.Error, key: "'generators' are not currently supported." },
};
}
+8
View File
@@ -1654,5 +1654,13 @@
"You cannot rename this element.": {
"category": "Error",
"code": 8000
},
"'yield' expressions are not currently supported.": {
"category": "Error",
"code": 9000
},
"'generators' are not currently supported.": {
"category": "Error",
"code": 9001
}
}
+45 -42
View File
@@ -1155,6 +1155,15 @@ module ts {
return false;
}
function parseOptionalToken(t: SyntaxKind): Node {
if (token === t) {
var node = createNode(t);
nextToken();
return finishNode(node);
}
return undefined;
}
function canParseSemicolon() {
// If there's a real semicolon, then we can always parse it out.
if (token === SyntaxKind.SemicolonToken) {
@@ -2202,10 +2211,7 @@ module ts {
if (!scanner.hasPrecedingLineBreak() &&
(token === SyntaxKind.AsteriskToken || isStartOfExpression())) {
if (parseOptional(SyntaxKind.AsteriskToken)) {
node.flags = NodeFlags.YieldStar;
}
node.asteriskToken = parseOptionalToken(SyntaxKind.AsteriskToken);
node.expression = parseAssignmentExpression();
return finishNode(node);
}
@@ -2255,7 +2261,7 @@ module ts {
}
else {
// If not, we're probably better off bailing out and returning a bogus function expression.
return makeFunctionExpression(SyntaxKind.ArrowFunction, pos, /* name */ undefined, sig, createMissingNode());
return makeFunctionExpression(SyntaxKind.ArrowFunction, pos, /*asteriskToken:*/ undefined, /*name:*/ undefined, sig, createMissingNode());
}
}
@@ -2395,7 +2401,7 @@ module ts {
body = parseAssignmentExpression();
}
return makeFunctionExpression(SyntaxKind.ArrowFunction, pos, /* name */ undefined, sig, body);
return makeFunctionExpression(SyntaxKind.ArrowFunction, pos, /*asteriskToken:*/ undefined, /*name:*/ undefined, sig, body);
}
function parseConditionalExpression(): Expression {
@@ -2731,26 +2737,23 @@ module ts {
function parsePropertyAssignment(): Declaration {
var nodePos = scanner.getStartPos();
var isGenerator = parseOptional(SyntaxKind.AsteriskToken);
var asteriskToken = parseOptionalToken(SyntaxKind.AsteriskToken);
var tokenIsIdentifier = isIdentifier();
var nameToken = token;
var propertyName = parsePropertyName();
var node: Declaration;
if (isGenerator || token === SyntaxKind.OpenParenToken || token === SyntaxKind.LessThanToken) {
if (asteriskToken || token === SyntaxKind.OpenParenToken || token === SyntaxKind.LessThanToken) {
node = <PropertyDeclaration>createNode(SyntaxKind.PropertyAssignment, nodePos);
node.name = propertyName;
if (isGenerator) {
node.flags |= NodeFlags.Generator;
}
var sig = parseSignature(SyntaxKind.CallSignature, SyntaxKind.ColonToken, /* returnTokenRequired */ false, /*yieldAndGeneratorParameterContext:*/ isGenerator);
var sig = parseSignature(SyntaxKind.CallSignature, SyntaxKind.ColonToken, /* returnTokenRequired */ false, /*yieldAndGeneratorParameterContext:*/ !!asteriskToken);
var body = parseFunctionBlock(isGenerator, /* ignoreMissingOpenBrace */ false);
var body = parseFunctionBlock(!!asteriskToken, /* ignoreMissingOpenBrace */ false);
// do not propagate property name as name for function expression
// for scenarios like
// var x = 1;
// var y = { x() { } }
// otherwise this will bring y.x into the scope of x which is incorrect
(<PropertyDeclaration>node).initializer = makeFunctionExpression(SyntaxKind.FunctionExpression, node.pos, undefined, sig, body);
(<PropertyDeclaration>node).initializer = makeFunctionExpression(SyntaxKind.FunctionExpression, node.pos, asteriskToken, undefined, sig, body);
return finishNode(node);
}
@@ -2808,24 +2811,21 @@ module ts {
var pos = getNodePos();
parseExpected(SyntaxKind.FunctionKeyword);
var isGenerator = parseOptional(SyntaxKind.AsteriskToken);
var name = isGenerator ? doInYieldContext(parseOptionalIdentifier) : parseOptionalIdentifier();
var sig = parseSignature(SyntaxKind.CallSignature, SyntaxKind.ColonToken, /* returnTokenRequired */ false, /*yieldAndGeneratorParameterContext:*/ isGenerator);
var asteriskToken = parseOptionalToken(SyntaxKind.AsteriskToken);
var name = asteriskToken ? doInYieldContext(parseOptionalIdentifier) : parseOptionalIdentifier();
var sig = parseSignature(SyntaxKind.CallSignature, SyntaxKind.ColonToken, /* returnTokenRequired */ false, /*yieldAndGeneratorParameterContext:*/ !!asteriskToken);
var body = parseFunctionBlock(/*allowYield:*/ isGenerator, /* ignoreMissingOpenBrace */ false);
return makeFunctionExpression(SyntaxKind.FunctionExpression, pos, name, sig, body, isGenerator ? NodeFlags.Generator : undefined);
var body = parseFunctionBlock(/*allowYield:*/ !!asteriskToken, /* ignoreMissingOpenBrace */ false);
return makeFunctionExpression(SyntaxKind.FunctionExpression, pos, asteriskToken, name, sig, body);
}
function parseOptionalIdentifier() {
return isIdentifier() ? parseIdentifier() : undefined;
}
function makeFunctionExpression(kind: SyntaxKind, pos: number, name: Identifier, sig: ParsedSignature, body: Node, flags?: NodeFlags): FunctionExpression {
function makeFunctionExpression(kind: SyntaxKind, pos: number, asteriskToken: Node, name: Identifier, sig: ParsedSignature, body: Node): FunctionExpression {
var node = <FunctionExpression>createNode(kind, pos);
if (flags) {
node.flags = flags;
}
node.asteriskToken = asteriskToken;
node.name = name;
node.typeParameters = sig.typeParameters;
node.parameters = sig.parameters;
@@ -3292,14 +3292,10 @@ module ts {
var node = <FunctionLikeDeclaration>createNode(SyntaxKind.FunctionDeclaration, fullStart);
setModifiers(node, modifiers);
parseExpected(SyntaxKind.FunctionKeyword);
var isGenerator = parseOptional(SyntaxKind.AsteriskToken);
if (isGenerator) {
node.flags |= NodeFlags.Generator;
}
node.asteriskToken = parseOptionalToken(SyntaxKind.AsteriskToken);
node.name = parseIdentifier();
fillSignature(SyntaxKind.CallSignature, SyntaxKind.ColonToken, /* returnTokenRequired */ false, /*yieldAndGeneratorParameterContext:*/ isGenerator, node);
node.body = parseFunctionBlockOrSemicolon(isGenerator);
fillSignature(SyntaxKind.CallSignature, SyntaxKind.ColonToken, /* returnTokenRequired */ false, /*yieldAndGeneratorParameterContext:*/ !!node.asteriskToken, node);
node.body = parseFunctionBlockOrSemicolon(!!node.asteriskToken);
return finishNode(node);
}
@@ -3314,11 +3310,7 @@ module ts {
function parsePropertyMemberDeclaration(fullStart: number, modifiers: ModifiersArray): Declaration {
var flags = modifiers ? modifiers.flags : 0;
var isGenerator = parseOptional(SyntaxKind.AsteriskToken);
if (isGenerator) {
flags |= NodeFlags.Generator;
}
var asteriskToken = parseOptionalToken(SyntaxKind.AsteriskToken);
var name = parsePropertyName();
if (parseOptional(SyntaxKind.QuestionToken)) {
// Note: this is not legal as per the grammar. But we allow it in the parser and
@@ -3326,15 +3318,16 @@ module ts {
flags |= NodeFlags.QuestionMark;
}
if (isGenerator || token === SyntaxKind.OpenParenToken || token === SyntaxKind.LessThanToken) {
if (asteriskToken || token === SyntaxKind.OpenParenToken || token === SyntaxKind.LessThanToken) {
var method = <MethodDeclaration>createNode(SyntaxKind.Method, fullStart);
setModifiers(method, modifiers);
if (flags) {
method.flags = flags;
}
method.asteriskToken = asteriskToken;
method.name = name;
fillSignature(SyntaxKind.CallSignature, SyntaxKind.ColonToken, /* returnTokenRequired */ false, /*yieldAndGeneratorParameterContext:*/ isGenerator, method);
method.body = parseFunctionBlockOrSemicolon(isGenerator);
fillSignature(SyntaxKind.CallSignature, SyntaxKind.ColonToken, /* returnTokenRequired */ false, /*yieldAndGeneratorParameterContext:*/ !!asteriskToken, method);
method.body = parseFunctionBlockOrSemicolon(!!asteriskToken);
return finishNode(method);
}
else {
@@ -4302,12 +4295,20 @@ module ts {
function checkFunctionDeclaration(node: FunctionLikeDeclaration) {
return checkAnyParsedSignature(node) ||
checkFunctionName(node.name) ||
checkForBodyInAmbientContext(node.body, /*isConstructor:*/ false);
checkForBodyInAmbientContext(node.body, /*isConstructor:*/ false) ||
checkForGenerator(node);
}
function checkForGenerator(node: FunctionLikeDeclaration) {
if (node.asteriskToken) {
return grammarErrorOnNode(node.asteriskToken, Diagnostics.generators_are_not_currently_supported);
}
}
function checkFunctionExpression(node: FunctionExpression) {
return checkAnyParsedSignature(node) ||
checkFunctionName(node.name);
checkFunctionName(node.name) ||
checkForGenerator(node);
}
function checkFunctionName(name: Node) {
@@ -4386,7 +4387,8 @@ module ts {
function checkMethod(node: MethodDeclaration) {
return checkAnyParsedSignature(node) ||
checkForBodyInAmbientContext(node.body, /*isConstructor:*/ false) ||
(node.parent.kind === SyntaxKind.ClassDeclaration && checkForInvalidQuestionMark(node, Diagnostics.A_class_member_cannot_be_declared_optional));
(node.parent.kind === SyntaxKind.ClassDeclaration && checkForInvalidQuestionMark(node, Diagnostics.A_class_member_cannot_be_declared_optional)) ||
checkForGenerator(node);
}
function checkForBodyInAmbientContext(body: Block | Expression, isConstructor: boolean): boolean {
@@ -4963,6 +4965,7 @@ module ts {
if (!(node.parserContextFlags & ParserContextFlags.Yield)) {
return grammarErrorOnFirstToken(node, Diagnostics.yield_expression_must_be_contained_within_a_generator_declaration);
}
return grammarErrorOnFirstToken(node, Diagnostics.yield_expressions_are_not_currently_supported);
}
}
+1 -1
View File
@@ -367,7 +367,7 @@ module ts {
}
else {
var emitStart = new Date().getTime();
var emitOutput = checker.invokeEmitter();
var emitOutput = checker.emitFiles();
var emitErrors = emitOutput.diagnostics;
exitStatus = emitOutput.emitResultStatus;
var reportStart = new Date().getTime();
+3 -3
View File
@@ -271,8 +271,6 @@ module ts {
Let = 0x00000800, // Variable declaration
Const = 0x00001000, // Variable declaration
OctalLiteral = 0x00002000,
Generator = 0x00004000,
YieldStar = 0x00008000,
Modifier = Export | Ambient | Public | Private | Protected | Static,
AccessibilityModifier = Public | Private | Protected,
@@ -377,6 +375,7 @@ module ts {
* FunctionExpression
*/
export interface FunctionLikeDeclaration extends Declaration, ParsedSignature {
asteriskToken?: Node;
body?: Block | Expression;
}
@@ -442,6 +441,7 @@ module ts {
}
export interface YieldExpression extends Expression {
asteriskToken?: Node;
expression: Expression;
}
@@ -753,7 +753,7 @@ module ts {
getSymbolCount(): number;
getTypeCount(): number;
checkProgram(): void;
invokeEmitter(targetSourceFile?: SourceFile): EmitResult;
emitFiles(targetSourceFile?: SourceFile): EmitResult;
getParentOfSymbol(symbol: Symbol): Symbol;
getNarrowedTypeOfSymbol(symbol: Symbol, node: Node): Type;
getDeclaredTypeOfSymbol(symbol: Symbol): Type;
+1 -1
View File
@@ -2223,7 +2223,7 @@ module FourSlash {
if (errs.length > 0) {
throw new Error('Error compiling ' + fileName + ': ' + errs.map(e => e.messageText).join('\r\n'));
}
checker.invokeEmitter();
checker.emitFiles();
result = result || ''; // Might have an empty fourslash file
// Compile and execute the test
+1 -1
View File
@@ -806,7 +806,7 @@ module Harness {
// only emit if there weren't parse errors
var emitResult: ts.EmitResult;
if (!isEmitBlocked) {
emitResult = checker.invokeEmitter();
emitResult = checker.emitFiles();
}
var errors: HarnessDiagnostic[] = [];
+1 -1
View File
@@ -132,7 +132,7 @@ class ProjectRunner extends RunnerBase {
if (!errors.length) {
var checker = program.getTypeChecker(/*fullTypeCheck*/ true);
errors = checker.getDiagnostics();
var emitResult = checker.invokeEmitter();
var emitResult = checker.emitFiles();
errors = ts.concatenate(errors, emitResult.diagnostics);
sourceMapData = emitResult.sourceMaps;
+1 -1
View File
@@ -4642,7 +4642,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 = getFullTypeCheckChecker().invokeEmitter(targetSourceFile);
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