Merge branch 'master' into formatting_scanner

This commit is contained in:
Vladimir Matveev
2014-11-14 11:01:17 -08:00
176 changed files with 12826 additions and 719 deletions
+227 -75
View File
@@ -6,7 +6,6 @@
/// <reference path="emitter.ts"/>
module ts {
var nextSymbolId = 1;
var nextNodeId = 1;
var nextMergeId = 1;
@@ -147,6 +146,7 @@ module ts {
var globalNumberType: ObjectType;
var globalBooleanType: ObjectType;
var globalRegExpType: ObjectType;
var globalTemplateStringsArrayType: ObjectType;
var tupleTypes: Map<TupleType> = {};
var unionTypes: Map<UnionType> = {};
@@ -4474,7 +4474,7 @@ module ts {
if (symbol.flags & SymbolFlags.Import) {
// Mark the import as referenced so that we emit it in the final .js file.
// exception: identifiers that appear in type queries, const enums, modules that contain only const enums
getSymbolLinks(symbol).referenced = !isInTypeQuery(node) && !isConstEnumOrConstEnumOnlyModule(resolveImport(symbol));
getSymbolLinks(symbol).referenced = getSymbolLinks(symbol).referenced || (!isInTypeQuery(node) && !isConstEnumOrConstEnumOnlyModule(resolveImport(symbol)));
}
checkCollisionWithCapturedSuperVariable(node, node);
@@ -5206,45 +5206,103 @@ module ts {
return unknownType;
}
function resolveUntypedCall(node: CallExpression): Signature {
forEach(node.arguments, argument => {
checkExpression(argument);
});
function resolveUntypedCall(node: CallLikeExpression): Signature {
if (node.kind === SyntaxKind.TaggedTemplateExpression) {
checkExpression((<TaggedTemplateExpression>node).template);
}
else {
forEach((<CallExpression>node).arguments, argument => {
checkExpression(argument);
});
}
return anySignature;
}
function resolveErrorCall(node: CallExpression): Signature {
function resolveErrorCall(node: CallLikeExpression): Signature {
resolveUntypedCall(node);
return unknownSignature;
}
function signatureHasCorrectArity(node: CallExpression, signature: Signature): boolean {
if (!node.arguments) {
// This only happens when we have something of the form:
// new C
//
return signature.minArgumentCount === 0;
function hasCorrectArity(node: CallLikeExpression, args: Expression[], signature: Signature) {
var adjustedArgCount: number;
var typeArguments: NodeArray<TypeNode>;
var callIsIncomplete: boolean;
if (node.kind === SyntaxKind.TaggedTemplateExpression) {
var tagExpression = <TaggedTemplateExpression>node;
// Even if the call is incomplete, we'll have a missing expression as our last argument,
// so we can say the count is just the arg list length
adjustedArgCount = args.length;
typeArguments = undefined;
if (tagExpression.template.kind === SyntaxKind.TemplateExpression) {
// If a tagged template expression lacks a tail literal, the call is incomplete.
// Specifically, a template only can end in a TemplateTail or a Missing literal.
var templateExpression = <TemplateExpression>tagExpression.template;
var lastSpan = lastOrUndefined(templateExpression.templateSpans);
Debug.assert(lastSpan !== undefined); // we should always have at least one span.
callIsIncomplete = lastSpan.literal.kind === SyntaxKind.Missing || isUnterminatedTemplateEnd(lastSpan.literal);
}
else {
// If the template didn't end in a backtick, or its beginning occurred right prior to EOF,
// then this might actually turn out to be a TemplateHead in the future;
// so we consider the call to be incomplete.
var templateLiteral = <LiteralExpression>tagExpression.template;
Debug.assert(templateLiteral.kind === SyntaxKind.NoSubstitutionTemplateLiteral);
callIsIncomplete = isUnterminatedTemplateEnd(templateLiteral);
}
}
else {
var callExpression = <CallExpression>node;
if (!callExpression.arguments) {
// This only happens when we have something of the form: 'new C'
Debug.assert(callExpression.kind === SyntaxKind.NewExpression);
return signature.minArgumentCount === 0;
}
// For IDE scenarios we may have an incomplete call, so a trailing comma is tantamount to adding another argument.
adjustedArgCount = callExpression.arguments.hasTrailingComma ? args.length + 1 : args.length;
// If we are missing the close paren, the call is incomplete.
callIsIncomplete = (<CallExpression>callExpression).arguments.end === callExpression.end;
typeArguments = callExpression.typeArguments;
}
// For IDE scenarios, since we may have an incomplete call, we make two modifications
// to arity checking.
// 1. A trailing comma is tantamount to adding another argument
// 2. If the call is incomplete (no closing paren) allow fewer arguments than expected
var args = node.arguments;
var numberOfArgs = args.hasTrailingComma ? args.length + 1 : args.length;
var hasTooManyArguments = !signature.hasRestParameter && numberOfArgs > signature.parameters.length;
var hasRightNumberOfTypeArguments = !node.typeArguments ||
(signature.typeParameters && node.typeArguments.length === signature.typeParameters.length);
Debug.assert(adjustedArgCount !== undefined, "'adjustedArgCount' undefined");
Debug.assert(callIsIncomplete !== undefined, "'callIsIncomplete' undefined");
if (hasTooManyArguments || !hasRightNumberOfTypeArguments) {
return false;
return checkArity(adjustedArgCount, typeArguments, callIsIncomplete, signature);
/**
* @param adjustedArgCount The "apparent" number of arguments that we will have in this call.
* @param typeArguments Type arguments node of the call if it exists; undefined otherwise.
* @param callIsIncomplete Whether or not a call is unfinished, and we should be "lenient" when we have too few arguments.
* @param signature The signature whose arity we are comparing.
*/
function checkArity(adjustedArgCount: number,
typeArguments: NodeArray<TypeNode>,
callIsIncomplete: boolean,
signature: Signature): boolean {
// Too many arguments implies incorrect arity.
if (!signature.hasRestParameter && adjustedArgCount > signature.parameters.length) {
return false;
}
// If the user supplied type arguments, but the number of type arguments does not match
// the declared number of type parameters, the call has an incorrect arity.
var hasRightNumberOfTypeArgs = !typeArguments ||
(signature.typeParameters && typeArguments.length === signature.typeParameters.length);
if (!hasRightNumberOfTypeArgs) {
return false;
}
// If the call is incomplete, we should skip the lower bound check.
var hasEnoughArguments = adjustedArgCount >= signature.minArgumentCount;
return callIsIncomplete || hasEnoughArguments;
}
// If we are missing the close paren, the call is incomplete, and we should skip
// the lower bound check.
var callIsIncomplete = args.end === node.end;
var hasEnoughArguments = numberOfArgs >= signature.minArgumentCount;
return callIsIncomplete || hasEnoughArguments;
}
// If type has a single call signature and no other members, return that signature. Otherwise, return undefined.
@@ -5280,15 +5338,23 @@ module ts {
}
if (!excludeArgument || excludeArgument[i] === undefined) {
var parameterType = getTypeAtPosition(signature, i);
if (i === 0 && args[i].parent.kind === SyntaxKind.TaggedTemplateExpression) {
inferTypes(context, globalTemplateStringsArrayType, parameterType);
continue;
}
inferTypes(context, checkExpressionWithContextualType(args[i], parameterType, mapper), parameterType);
}
}
// Next, infer from those context sensitive arguments that are no longer excluded
if (excludeArgument) {
for (var i = 0; i < args.length; i++) {
if (args[i].kind === SyntaxKind.OmittedExpression) {
continue;
}
// No need to special-case tagged templates; their excludeArgument value will be 'undefined'.
if (excludeArgument[i] === false) {
var parameterType = getTypeAtPosition(signature, i);
inferTypes(context, checkExpressionWithContextualType(args[i], parameterType, mapper), parameterType);
@@ -5328,31 +5394,72 @@ module ts {
return typeArgumentsAreAssignable;
}
function checkApplicableSignature(node: CallExpression, signature: Signature, relation: Map<Ternary>, excludeArgument: boolean[], reportErrors: boolean) {
if (node.arguments) {
for (var i = 0; i < node.arguments.length; i++) {
var arg = node.arguments[i];
if (arg.kind === SyntaxKind.OmittedExpression) {
continue;
}
var paramType = getTypeAtPosition(signature, i);
function checkApplicableSignature(node: CallLikeExpression, args: Node[], signature: Signature, relation: Map<Ternary>, excludeArgument: boolean[], reportErrors: boolean) {
for (var i = 0; i < args.length; i++) {
var arg = args[i];
var argType: Type;
if (arg.kind === SyntaxKind.OmittedExpression) {
continue;
}
var paramType = getTypeAtPosition(signature, i);
if (i === 0 && node.kind === SyntaxKind.TaggedTemplateExpression) {
// A tagged template expression has something of a
// "virtual" parameter with the "cooked" strings array type.
argType = globalTemplateStringsArrayType;
}
else {
// String literals get string literal types unless we're reporting errors
var argType = arg.kind === SyntaxKind.StringLiteral && !reportErrors ?
getStringLiteralType(<LiteralExpression>arg) :
checkExpressionWithContextualType(arg, paramType, excludeArgument && excludeArgument[i] ? identityMapper : undefined);
// Use argument expression as error location when reporting errors
var isValidArgument = checkTypeRelatedTo(argType, paramType, relation, reportErrors ? arg : undefined,
Diagnostics.Argument_of_type_0_is_not_assignable_to_parameter_of_type_1);
if (!isValidArgument) {
return false;
}
argType = arg.kind === SyntaxKind.StringLiteral && !reportErrors
? getStringLiteralType(<LiteralExpression>arg)
: checkExpressionWithContextualType(arg, paramType, excludeArgument && excludeArgument[i] ? identityMapper : undefined);
}
// Use argument expression as error location when reporting errors
var isValidArgument = checkTypeRelatedTo(argType, paramType, relation, reportErrors ? arg : undefined,
Diagnostics.Argument_of_type_0_is_not_assignable_to_parameter_of_type_1);
if (!isValidArgument) {
return false;
}
}
return true;
}
function resolveCall(node: CallExpression, signatures: Signature[], candidatesOutArray: Signature[]): Signature {
forEach(node.typeArguments, checkSourceElement);
/**
* Returns the effective arguments for an expression that works like a function invokation.
*
* If 'node' is a CallExpression or a NewExpression, then its argument list is returned.
* If 'node' is a TaggedTemplateExpression, a new argument list is constructed from the substitution
* expressions, where the first element of the list is the template for error reporting purposes.
*/
function getEffectiveCallArguments(node: CallLikeExpression): Expression[] {
var args: Expression[];
if (node.kind === SyntaxKind.TaggedTemplateExpression) {
var template = (<TaggedTemplateExpression>node).template;
args = [template];
if (template.kind === SyntaxKind.TemplateExpression) {
forEach((<TemplateExpression>template).templateSpans, span => {
args.push(span.expression);
});
}
}
else {
args = (<CallExpression>node).arguments || emptyArray;
}
return args;
}
function resolveCall(node: CallLikeExpression, signatures: Signature[], candidatesOutArray: Signature[]): Signature {
var isTaggedTemplate = node.kind === SyntaxKind.TaggedTemplateExpression;
var typeArguments = isTaggedTemplate ? undefined : (<CallExpression>node).typeArguments;
forEach(typeArguments, checkSourceElement);
var candidates = candidatesOutArray || [];
// collectCandidates fills up the candidates array directly
collectCandidates();
@@ -5360,11 +5467,26 @@ module ts {
error(node, Diagnostics.Supplied_parameters_do_not_match_any_signature_of_call_target);
return resolveErrorCall(node);
}
var args = node.arguments || emptyArray;
var args = getEffectiveCallArguments(node);
// The following applies to any value of 'excludeArgument[i]':
// - true: the argument at 'i' is susceptible to a one-time permanent contextual typing.
// - undefined: the argument at 'i' is *not* susceptible to permanent contextual typing.
// - false: the argument at 'i' *was* and *has been* permanently contextually typed.
//
// The idea is that we will perform type argument inference & assignability checking once
// without using the susceptible parameters that are functions, and once more for each of those
// parameters, contextually typing each as we go along.
//
// For a tagged template, then the first argument be 'undefined' if necessary
// because it represents a TemplateStringsArray.
var excludeArgument: boolean[];
for (var i = 0; i < args.length; i++) {
for (var i = isTaggedTemplate ? 1 : 0; i < args.length; i++) {
if (isContextSensitiveExpression(args[i])) {
if (!excludeArgument) excludeArgument = new Array(args.length);
if (!excludeArgument) {
excludeArgument = new Array(args.length);
}
excludeArgument[i] = true;
}
}
@@ -5406,14 +5528,14 @@ module ts {
// is just important for choosing the best signature. So in the case where there is only one
// signature, the subtype pass is useless. So skipping it is an optimization.
if (candidates.length > 1) {
result = chooseOverload(candidates, subtypeRelation, excludeArgument);
result = chooseOverload(candidates, subtypeRelation);
}
if (!result) {
// Reinitialize these pointers for round two
candidateForArgumentError = undefined;
candidateForTypeArgumentError = undefined;
resultOfFailedInference = undefined;
result = chooseOverload(candidates, assignableRelation, excludeArgument);
result = chooseOverload(candidates, assignableRelation);
}
if (result) {
return result;
@@ -5429,11 +5551,11 @@ module ts {
// in arguments too early. If possible, we'd like to only type them once we know the correct
// overload. However, this matters for the case where the call is correct. When the call is
// an error, we don't need to exclude any arguments, although it would cause no harm to do so.
checkApplicableSignature(node, candidateForArgumentError, assignableRelation, /*excludeArgument*/ undefined, /*reportErrors*/ true);
checkApplicableSignature(node, args, candidateForArgumentError, assignableRelation, /*excludeArgument*/ undefined, /*reportErrors*/ true);
}
else if (candidateForTypeArgumentError) {
if (node.typeArguments) {
checkTypeArguments(candidateForTypeArgumentError, node.typeArguments, [], /*reportErrors*/ true)
if (!isTaggedTemplate && (<CallExpression>node).typeArguments) {
checkTypeArguments(candidateForTypeArgumentError, (<CallExpression>node).typeArguments, [], /*reportErrors*/ true)
}
else {
Debug.assert(resultOfFailedInference.failedTypeParameterIndex >= 0);
@@ -5444,7 +5566,7 @@ module ts {
Diagnostics.The_type_argument_for_type_parameter_0_cannot_be_inferred_from_the_usage_Consider_specifying_the_type_arguments_explicitly,
typeToString(failedTypeParameter));
reportNoCommonSupertypeError(inferenceCandidates, node.func, diagnosticChainHead);
reportNoCommonSupertypeError(inferenceCandidates, (<CallExpression>node).func || (<TaggedTemplateExpression>node).tag, diagnosticChainHead);
}
}
else {
@@ -5458,7 +5580,7 @@ module ts {
// f({ |
if (!fullTypeCheck) {
for (var i = 0, n = candidates.length; i < n; i++) {
if (signatureHasCorrectArity(node, candidates[i])) {
if (hasCorrectArity(node, args, candidates[i])) {
return candidates[i];
}
}
@@ -5466,9 +5588,9 @@ module ts {
return resolveErrorCall(node);
function chooseOverload(candidates: Signature[], relation: Map<Ternary>, excludeArgument: boolean[]) {
function chooseOverload(candidates: Signature[], relation: Map<Ternary>) {
for (var i = 0; i < candidates.length; i++) {
if (!signatureHasCorrectArity(node, candidates[i])) {
if (!hasCorrectArity(node, args, candidates[i])) {
continue;
}
@@ -5480,9 +5602,9 @@ module ts {
if (candidate.typeParameters) {
var typeArgumentTypes: Type[];
var typeArgumentsAreValid: boolean;
if (node.typeArguments) {
if (typeArguments) {
typeArgumentTypes = new Array<Type>(candidate.typeParameters.length);
typeArgumentsAreValid = checkTypeArguments(candidate, node.typeArguments, typeArgumentTypes, /*reportErrors*/ false)
typeArgumentsAreValid = checkTypeArguments(candidate, typeArguments, typeArgumentTypes, /*reportErrors*/ false)
}
else {
inferenceResult = inferTypeArguments(candidate, args, excludeArgument);
@@ -5494,7 +5616,7 @@ module ts {
}
candidate = getSignatureInstantiation(candidate, typeArgumentTypes);
}
if (!checkApplicableSignature(node, candidate, relation, excludeArgument, /*reportErrors*/ false)) {
if (!checkApplicableSignature(node, args, candidate, relation, excludeArgument, /*reportErrors*/ false)) {
break;
}
var index = excludeArgument ? indexOf(excludeArgument, true) : -1;
@@ -5516,7 +5638,7 @@ module ts {
}
else {
candidateForTypeArgumentError = originalCandidate;
if (!node.typeArguments) {
if (!typeArguments) {
resultOfFailedInference = inferenceResult;
}
}
@@ -5627,7 +5749,6 @@ module ts {
function resolveNewExpression(node: NewExpression, candidatesOutArray: Signature[]): Signature {
var expressionType = checkExpression(node.func);
// TS 1.0 spec: 4.11
// If ConstructExpr is of type Any, Args can be any argument
// list and the result of the operation is of type Any.
@@ -5675,9 +5796,32 @@ module ts {
return resolveErrorCall(node);
}
function resolveTaggedTemplateExpression(node: TaggedTemplateExpression, candidatesOutArray: Signature[]): Signature {
var tagType = checkExpression(node.tag);
var apparentType = getApparentType(tagType);
if (apparentType === unknownType) {
// Another error has already been reported
return resolveErrorCall(node);
}
var callSignatures = getSignaturesOfType(apparentType, SignatureKind.Call);
if (tagType === anyType || (!callSignatures.length && !(tagType.flags & TypeFlags.Union) && isTypeAssignableTo(tagType, globalFunctionType))) {
return resolveUntypedCall(node);
}
if (!callSignatures.length) {
error(node, Diagnostics.Cannot_invoke_an_expression_whose_type_lacks_a_call_signature);
return resolveErrorCall(node);
}
return resolveCall(node, callSignatures, candidatesOutArray);
}
// candidatesOutArray is passed by signature help in the language service, and collectCandidates
// must fill it up with the appropriate candidate signatures
function getResolvedSignature(node: CallExpression, candidatesOutArray?: Signature[]): Signature {
function getResolvedSignature(node: CallLikeExpression, candidatesOutArray?: Signature[]): Signature {
var links = getNodeLinks(node);
// If getResolvedSignature has already been called, we will have cached the resolvedSignature.
// However, it is possible that either candidatesOutArray was not passed in the first time,
@@ -5685,9 +5829,19 @@ module ts {
// to correctly fill the candidatesOutArray.
if (!links.resolvedSignature || candidatesOutArray) {
links.resolvedSignature = anySignature;
links.resolvedSignature = node.kind === SyntaxKind.CallExpression
? resolveCallExpression(node, candidatesOutArray)
: resolveNewExpression(node, candidatesOutArray);
if (node.kind === SyntaxKind.CallExpression) {
links.resolvedSignature = resolveCallExpression(<CallExpression>node, candidatesOutArray);
}
else if (node.kind === SyntaxKind.NewExpression) {
links.resolvedSignature = resolveNewExpression(<NewExpression>node, candidatesOutArray);
}
else if (node.kind === SyntaxKind.TaggedTemplateExpression) {
links.resolvedSignature = resolveTaggedTemplateExpression(<TaggedTemplateExpression>node, candidatesOutArray);
}
else {
Debug.fail("Branch in 'getResolvedSignature' should be unreachable.");
}
}
return links.resolvedSignature;
}
@@ -5711,10 +5865,7 @@ module ts {
}
function checkTaggedTemplateExpression(node: TaggedTemplateExpression): Type {
// TODO (drosen): Make sure substitutions are assignable to the tag's arguments.
checkExpression(node.tag);
checkExpression(node.template);
return anyType;
return getReturnTypeOfSignature(getResolvedSignature(node));
}
function checkTypeAssertion(node: TypeAssertion): Type {
@@ -8467,7 +8618,7 @@ module ts {
// above them to find the lowest container
case SyntaxKind.Identifier:
// If the identifier is the RHS of a qualified name, then it's a type iff its parent is.
if (node.parent.kind === SyntaxKind.QualifiedName) {
if (node.parent.kind === SyntaxKind.QualifiedName && (<QualifiedName>node.parent).right === node) {
node = node.parent;
}
// fall through
@@ -8951,6 +9102,7 @@ module ts {
globalNumberType = getGlobalType("Number");
globalBooleanType = getGlobalType("Boolean");
globalRegExpType = getGlobalType("RegExp");
globalTemplateStringsArrayType = getGlobalType("TemplateStringsArray");
}
initializeTypeChecker();
+11
View File
@@ -122,6 +122,17 @@ module ts {
return result;
}
/**
* Returns the last element of an array if non-empty, undefined otherwise.
*/
export function lastOrUndefined<T>(array: T[]): T {
if (array.length === 0) {
return undefined;
}
return array[array.length - 1];
}
export function binarySearch(array: number[], value: number): number {
var low = 0;
var high = array.length - 1;
+22 -5
View File
@@ -34,12 +34,16 @@ module ts {
return file.filename + "(" + loc.line + "," + loc.character + ")";
}
export function getStartPosOfNode(node: Node): number {
return node.pos;
}
export function getTokenPosOfNode(node: Node, sourceFile?: SourceFile): number {
// With nodes that have no width (i.e. 'Missing' nodes), we actually *don't*
// want to skip trivia because this will launch us forward to the next token.
if (node.pos === node.end) {
return node.pos;
}
return skipTrivia((sourceFile || getSourceFileOfNode(node)).text, node.pos);
}
@@ -567,7 +571,6 @@ module ts {
return false;
}
export function isDeclaration(node: Node): boolean {
switch (node.kind) {
case SyntaxKind.TypeParameter:
@@ -747,7 +750,7 @@ module ts {
nodeIsNestedInLabel(label: Identifier, requireIterationStatement: boolean, stopAtFunctionBoundary: boolean): ControlBlockContext;
}
interface ReferencePathMatchResult {
export interface ReferencePathMatchResult {
fileReference?: FileReference
diagnostic?: DiagnosticMessage
isNoDefaultLib?: boolean
@@ -796,6 +799,20 @@ module ts {
return SyntaxKind.FirstTriviaToken <= token && token <= SyntaxKind.LastTriviaToken;
}
export function isUnterminatedTemplateEnd(node: LiteralExpression) {
Debug.assert(node.kind === SyntaxKind.NoSubstitutionTemplateLiteral || node.kind === SyntaxKind.TemplateTail);
var sourceText = getSourceFileOfNode(node).text;
// If we're not at the EOF, we know we must be terminated.
if (node.end !== sourceText.length) {
return false;
}
// If we didn't end in a backtick, we must still be in the middle of a template.
// If we did, make sure that it's not the *initial* backtick.
return sourceText.charCodeAt(node.end - 1) !== CharacterCodes.backtick || node.text.length === 0;
}
export function isModifier(token: SyntaxKind): boolean {
switch (token) {
case SyntaxKind.PublicKeyword:
@@ -1145,6 +1162,7 @@ module ts {
}
function internIdentifier(text: string): string {
text = escapeIdentifier(text);
return hasProperty(identifiers, text) ? identifiers[text] : (identifiers[text] = text);
}
@@ -1155,8 +1173,7 @@ module ts {
identifierCount++;
if (isIdentifier) {
var node = <Identifier>createNode(SyntaxKind.Identifier);
var text = escapeIdentifier(scanner.getTokenValue());
node.text = internIdentifier(text);
node.text = internIdentifier(scanner.getTokenValue());
nextToken();
return finishNode(node);
}
+2
View File
@@ -481,6 +481,8 @@ module ts {
template: LiteralExpression | TemplateExpression;
}
export type CallLikeExpression = CallExpression | NewExpression | TaggedTemplateExpression;
export interface TypeAssertion extends Expression {
type: TypeNode;
operand: Expression;
+4
View File
@@ -484,6 +484,10 @@ declare var Number: {
POSITIVE_INFINITY: number;
}
interface TemplateStringsArray extends Array<string> {
raw: string[];
}
interface Math {
/** The mathematical constant e. This is Euler's number, the base of natural logarithms. */
E: number;
@@ -96,6 +96,7 @@ module TypeScript {
Type_expected: "Type expected.",
Template_literal_cannot_be_used_as_an_element_name: "Template literal cannot be used as an element name.",
Computed_property_names_cannot_be_used_here: "Computed property names cannot be used here.",
yield_expression_must_be_contained_within_a_generator_declaration: "'yield' expression must be contained within a generator declaration.",
Duplicate_identifier_0: "Duplicate identifier '{0}'.",
The_name_0_does_not_exist_in_the_current_scope: "The name '{0}' does not exist in the current scope.",
The_name_0_does_not_refer_to_a_value: "The name '{0}' does not refer to a value.",
@@ -98,6 +98,7 @@ module TypeScript {
"Type expected.": { "code": 1110, "category": DiagnosticCategory.Error },
"Template literal cannot be used as an element name.": { "code": 1111, "category": DiagnosticCategory.Error },
"Computed property names cannot be used here.": { "code": 1112, "category": DiagnosticCategory.Error },
"'yield' expression must be contained within a generator declaration.": { "code": 1113, "category": DiagnosticCategory.Error },
"Duplicate identifier '{0}'.": { "code": 2000, "category": DiagnosticCategory.Error },
"The name '{0}' does not exist in the current scope.": { "code": 2001, "category": DiagnosticCategory.Error },
"The name '{0}' does not refer to a value.": { "code": 2002, "category": DiagnosticCategory.Error },
@@ -379,6 +379,10 @@
"category": "Error",
"code": 1112
},
"'yield' expression must be contained within a generator declaration.": {
"category": "Error",
"code": 1113
},
"Duplicate identifier '{0}'.": {
"category": "Error",
"code": 2000
+8 -5
View File
@@ -2395,7 +2395,7 @@ module ts {
if (isValid) {
return displayName;
return unescapeIdentifier(displayName);
}
}
@@ -2571,9 +2571,12 @@ module ts {
var start = new Date().getTime();
forEach(symbols, symbol => {
var entry = createCompletionEntry(symbol, session.typeChecker, location);
if (entry && !lookUp(session.symbols, entry.name)) {
session.entries.push(entry);
session.symbols[entry.name] = symbol;
if (entry) {
var id = escapeIdentifier(entry.name);
if (!lookUp(session.symbols, id)) {
session.entries.push(entry);
session.symbols[id] = symbol;
}
}
});
host.log("getCompletionsAtPosition: getCompletionEntriesFromSymbols: " + (new Date().getTime() - start));
@@ -2781,7 +2784,7 @@ module ts {
return undefined;
}
var symbol = lookUp(activeCompletionSession.symbols, entryName);
var symbol = lookUp(activeCompletionSession.symbols, escapeIdentifier(entryName));
if (symbol) {
var location = getTouchingPropertyName(sourceFile, position);
var completionEntry = createCompletionEntry(symbol, session.typeChecker, location);
+58 -43
View File
@@ -599,30 +599,31 @@ var TypeScript;
SyntaxKind[SyntaxKind["OmittedExpression"] = 187] = "OmittedExpression";
SyntaxKind[SyntaxKind["TemplateExpression"] = 188] = "TemplateExpression";
SyntaxKind[SyntaxKind["TemplateAccessExpression"] = 189] = "TemplateAccessExpression";
SyntaxKind[SyntaxKind["VariableDeclaration"] = 190] = "VariableDeclaration";
SyntaxKind[SyntaxKind["VariableDeclarator"] = 191] = "VariableDeclarator";
SyntaxKind[SyntaxKind["ArgumentList"] = 192] = "ArgumentList";
SyntaxKind[SyntaxKind["ParameterList"] = 193] = "ParameterList";
SyntaxKind[SyntaxKind["TypeArgumentList"] = 194] = "TypeArgumentList";
SyntaxKind[SyntaxKind["TypeParameterList"] = 195] = "TypeParameterList";
SyntaxKind[SyntaxKind["HeritageClause"] = 196] = "HeritageClause";
SyntaxKind[SyntaxKind["EqualsValueClause"] = 197] = "EqualsValueClause";
SyntaxKind[SyntaxKind["CaseSwitchClause"] = 198] = "CaseSwitchClause";
SyntaxKind[SyntaxKind["DefaultSwitchClause"] = 199] = "DefaultSwitchClause";
SyntaxKind[SyntaxKind["ElseClause"] = 200] = "ElseClause";
SyntaxKind[SyntaxKind["CatchClause"] = 201] = "CatchClause";
SyntaxKind[SyntaxKind["FinallyClause"] = 202] = "FinallyClause";
SyntaxKind[SyntaxKind["TemplateClause"] = 203] = "TemplateClause";
SyntaxKind[SyntaxKind["TypeParameter"] = 204] = "TypeParameter";
SyntaxKind[SyntaxKind["Constraint"] = 205] = "Constraint";
SyntaxKind[SyntaxKind["SimplePropertyAssignment"] = 206] = "SimplePropertyAssignment";
SyntaxKind[SyntaxKind["FunctionPropertyAssignment"] = 207] = "FunctionPropertyAssignment";
SyntaxKind[SyntaxKind["Parameter"] = 208] = "Parameter";
SyntaxKind[SyntaxKind["EnumElement"] = 209] = "EnumElement";
SyntaxKind[SyntaxKind["TypeAnnotation"] = 210] = "TypeAnnotation";
SyntaxKind[SyntaxKind["ComputedPropertyName"] = 211] = "ComputedPropertyName";
SyntaxKind[SyntaxKind["ExternalModuleReference"] = 212] = "ExternalModuleReference";
SyntaxKind[SyntaxKind["ModuleNameModuleReference"] = 213] = "ModuleNameModuleReference";
SyntaxKind[SyntaxKind["YieldExpression"] = 190] = "YieldExpression";
SyntaxKind[SyntaxKind["VariableDeclaration"] = 191] = "VariableDeclaration";
SyntaxKind[SyntaxKind["VariableDeclarator"] = 192] = "VariableDeclarator";
SyntaxKind[SyntaxKind["ArgumentList"] = 193] = "ArgumentList";
SyntaxKind[SyntaxKind["ParameterList"] = 194] = "ParameterList";
SyntaxKind[SyntaxKind["TypeArgumentList"] = 195] = "TypeArgumentList";
SyntaxKind[SyntaxKind["TypeParameterList"] = 196] = "TypeParameterList";
SyntaxKind[SyntaxKind["HeritageClause"] = 197] = "HeritageClause";
SyntaxKind[SyntaxKind["EqualsValueClause"] = 198] = "EqualsValueClause";
SyntaxKind[SyntaxKind["CaseSwitchClause"] = 199] = "CaseSwitchClause";
SyntaxKind[SyntaxKind["DefaultSwitchClause"] = 200] = "DefaultSwitchClause";
SyntaxKind[SyntaxKind["ElseClause"] = 201] = "ElseClause";
SyntaxKind[SyntaxKind["CatchClause"] = 202] = "CatchClause";
SyntaxKind[SyntaxKind["FinallyClause"] = 203] = "FinallyClause";
SyntaxKind[SyntaxKind["TemplateClause"] = 204] = "TemplateClause";
SyntaxKind[SyntaxKind["TypeParameter"] = 205] = "TypeParameter";
SyntaxKind[SyntaxKind["Constraint"] = 206] = "Constraint";
SyntaxKind[SyntaxKind["SimplePropertyAssignment"] = 207] = "SimplePropertyAssignment";
SyntaxKind[SyntaxKind["FunctionPropertyAssignment"] = 208] = "FunctionPropertyAssignment";
SyntaxKind[SyntaxKind["Parameter"] = 209] = "Parameter";
SyntaxKind[SyntaxKind["EnumElement"] = 210] = "EnumElement";
SyntaxKind[SyntaxKind["TypeAnnotation"] = 211] = "TypeAnnotation";
SyntaxKind[SyntaxKind["ComputedPropertyName"] = 212] = "ComputedPropertyName";
SyntaxKind[SyntaxKind["ExternalModuleReference"] = 213] = "ExternalModuleReference";
SyntaxKind[SyntaxKind["ModuleNameModuleReference"] = 214] = "ModuleNameModuleReference";
SyntaxKind[SyntaxKind["FirstStandardKeyword"] = SyntaxKind.BreakKeyword] = "FirstStandardKeyword";
SyntaxKind[SyntaxKind["LastStandardKeyword"] = SyntaxKind.WithKeyword] = "LastStandardKeyword";
SyntaxKind[SyntaxKind["FirstFutureReservedKeyword"] = SyntaxKind.ClassKeyword] = "FirstFutureReservedKeyword";
@@ -910,9 +911,9 @@ var definitions = [
baseType: 'ISyntaxNode',
interfaces: ['IModuleReferenceSyntax'],
children: [
{ name: 'requireKeyword', isToken: true, tokenKinds: ['RequireKeyword'], excludeFromAST: true },
{ name: 'requireKeyword', isToken: true, excludeFromAST: true },
{ name: 'openParenToken', isToken: true, excludeFromAST: true },
{ name: 'stringLiteral', isToken: true, tokenKinds: ['StringLiteral'] },
{ name: 'stringLiteral', isToken: true },
{ name: 'closeParenToken', isToken: true, excludeFromAST: true }
],
isTypeScriptSpecific: true
@@ -933,7 +934,7 @@ var definitions = [
children: [
{ name: 'modifiers', isList: true, elementType: 'ISyntaxToken' },
{ name: 'importKeyword', isToken: true, excludeFromAST: true },
{ name: 'identifier', isToken: true, tokenKinds: ['IdentifierName'] },
{ name: 'identifier', isToken: true },
{ name: 'equalsToken', isToken: true, excludeFromAST: true },
{ name: 'moduleReference', type: 'IModuleReferenceSyntax' },
{ name: 'semicolonToken', isToken: true, isOptional: true, excludeFromAST: true }
@@ -947,7 +948,7 @@ var definitions = [
children: [
{ name: 'exportKeyword', isToken: true, excludeFromAST: true },
{ name: 'equalsToken', isToken: true, excludeFromAST: true },
{ name: 'identifier', isToken: true, tokenKinds: ['IdentifierName'] },
{ name: 'identifier', isToken: true },
{ name: 'semicolonToken', isToken: true, isOptional: true, excludeFromAST: true }
],
isTypeScriptSpecific: true
@@ -959,7 +960,7 @@ var definitions = [
children: [
{ name: 'modifiers', isList: true, elementType: 'ISyntaxToken' },
{ name: 'classKeyword', isToken: true, excludeFromAST: true },
{ name: 'identifier', isToken: true, tokenKinds: ['IdentifierName'] },
{ name: 'identifier', isToken: true },
{ name: 'typeParameterList', type: 'TypeParameterListSyntax', isOptional: true },
{ name: 'heritageClauses', isList: true, elementType: 'HeritageClauseSyntax' },
{ name: 'openBraceToken', isToken: true, excludeFromAST: true },
@@ -975,7 +976,7 @@ var definitions = [
children: [
{ name: 'modifiers', isList: true, elementType: 'ISyntaxToken' },
{ name: 'interfaceKeyword', isToken: true, excludeFromAST: true },
{ name: 'identifier', isToken: true, tokenKinds: ['IdentifierName'] },
{ name: 'identifier', isToken: true },
{ name: 'typeParameterList', type: 'TypeParameterListSyntax', isOptional: true },
{ name: 'heritageClauses', isList: true, elementType: 'HeritageClauseSyntax' },
{ name: 'body', type: 'ObjectTypeSyntax' }
@@ -1012,7 +1013,8 @@ var definitions = [
children: [
{ name: 'modifiers', isList: true, elementType: 'ISyntaxToken', isTypeScriptSpecific: true },
{ name: 'functionKeyword', isToken: true, excludeFromAST: true },
{ name: 'identifier', isToken: true, tokenKinds: ['IdentifierName'] },
{ name: 'asterixToken', isToken: true, isOptional: true },
{ name: 'identifier', isToken: true },
{ name: 'callSignature', type: 'CallSignatureSyntax' },
{ name: 'body', type: 'BlockSyntax | ISyntaxToken', isOptional: true }
]
@@ -1116,7 +1118,7 @@ var definitions = [
children: [
{ name: 'left', type: 'INameSyntax' },
{ name: 'dotToken', isToken: true, excludeFromAST: true },
{ name: 'right', isToken: true, tokenKinds: ['IdentifierName'] }
{ name: 'right', isToken: true }
],
isTypeScriptSpecific: true
},
@@ -1255,7 +1257,7 @@ var definitions = [
children: [
{ name: 'dotDotDotToken', isToken: true, isOptional: true, isTypeScriptSpecific: true },
{ name: 'modifiers', isList: true, elementType: 'ISyntaxToken' },
{ name: 'identifier', isToken: true, tokenKinds: ['IdentifierName'] },
{ name: 'identifier', isToken: true },
{ name: 'questionToken', isToken: true, isOptional: true, isTypeScriptSpecific: true },
{ name: 'typeAnnotation', type: 'TypeAnnotationSyntax', isOptional: true, isTypeScriptSpecific: true },
{ name: 'equalsValueClause', type: 'EqualsValueClauseSyntax', isOptional: true, isTypeScriptSpecific: true }
@@ -1268,7 +1270,7 @@ var definitions = [
children: [
{ name: 'expression', type: 'ILeftHandSideExpressionSyntax' },
{ name: 'dotToken', isToken: true, excludeFromAST: true },
{ name: 'name', isToken: true, tokenKinds: ['IdentifierName'] }
{ name: 'name', isToken: true }
]
},
{
@@ -1434,7 +1436,7 @@ var definitions = [
name: 'TypeParameterSyntax',
baseType: 'ISyntaxNode',
children: [
{ name: 'identifier', isToken: true, tokenKinds: ['IdentifierName'] },
{ name: 'identifier', isToken: true },
{ name: 'constraint', type: 'ConstraintSyntax', isOptional: true }
],
isTypeScriptSpecific: true
@@ -1496,6 +1498,7 @@ var definitions = [
interfaces: ['IMemberDeclarationSyntax'],
children: [
{ name: 'modifiers', isList: true, elementType: 'ISyntaxToken' },
{ name: 'asterixToken', isToken: true, isOptional: true },
{ name: 'propertyName', type: 'IPropertyNameSyntax' },
{ name: 'callSignature', type: 'CallSignatureSyntax' },
{ name: 'body', type: 'BlockSyntax | ISyntaxToken', isOptional: true }
@@ -1620,7 +1623,7 @@ var definitions = [
interfaces: ['IStatementSyntax'],
children: [
{ name: 'breakKeyword', isToken: true },
{ name: 'identifier', isToken: true, isOptional: true, tokenKinds: ['IdentifierName'] },
{ name: 'identifier', isToken: true, isOptional: true },
{ name: 'semicolonToken', isToken: true, isOptional: true, excludeFromAST: true }
]
},
@@ -1630,7 +1633,7 @@ var definitions = [
interfaces: ['IStatementSyntax'],
children: [
{ name: 'continueKeyword', isToken: true },
{ name: 'identifier', isToken: true, isOptional: true, tokenKinds: ['IdentifierName'] },
{ name: 'identifier', isToken: true, isOptional: true },
{ name: 'semicolonToken', isToken: true, isOptional: true, excludeFromAST: true }
]
},
@@ -1642,9 +1645,9 @@ var definitions = [
{ name: 'forKeyword', isToken: true, excludeFromAST: true },
{ name: 'openParenToken', isToken: true, excludeFromAST: true },
{ name: 'initializer', type: 'VariableDeclarationSyntax | IExpressionSyntax', isOptional: true },
{ name: 'firstSemicolonToken', isToken: true, tokenKinds: ['SemicolonToken'], excludeFromAST: true },
{ name: 'firstSemicolonToken', isToken: true, excludeFromAST: true },
{ name: 'condition', type: 'IExpressionSyntax', isOptional: true },
{ name: 'secondSemicolonToken', isToken: true, tokenKinds: ['SemicolonToken'], excludeFromAST: true },
{ name: 'secondSemicolonToken', isToken: true, excludeFromAST: true },
{ name: 'incrementor', type: 'IExpressionSyntax', isOptional: true },
{ name: 'closeParenToken', isToken: true, excludeFromAST: true },
{ name: 'statement', type: 'IStatementSyntax' }
@@ -1695,7 +1698,7 @@ var definitions = [
children: [
{ name: 'modifiers', isList: true, elementType: 'ISyntaxToken' },
{ name: 'enumKeyword', isToken: true, excludeFromAST: true },
{ name: 'identifier', isToken: true, tokenKinds: ['IdentifierName'] },
{ name: 'identifier', isToken: true },
{ name: 'openBraceToken', isToken: true, excludeFromAST: true },
{ name: 'enumElements', isSeparatedList: true, elementType: 'EnumElementSyntax' },
{ name: 'closeBraceToken', isToken: true, excludeFromAST: true }
@@ -1757,6 +1760,7 @@ var definitions = [
baseType: 'ISyntaxNode',
interfaces: ['IPropertyAssignmentSyntax'],
children: [
{ name: 'asterixToken', isToken: true, isOptional: true },
{ name: 'propertyName', type: 'IPropertyNameSyntax' },
{ name: 'callSignature', type: 'CallSignatureSyntax' },
{ name: 'block', type: 'BlockSyntax' }
@@ -1768,7 +1772,8 @@ var definitions = [
interfaces: ['IPrimaryExpressionSyntax'],
children: [
{ name: 'functionKeyword', isToken: true, excludeFromAST: true },
{ name: 'identifier', isToken: true, isOptional: true, tokenKinds: ['IdentifierName'] },
{ name: 'asterixToken', isToken: true, isOptional: true },
{ name: 'identifier', isToken: true, isOptional: true },
{ name: 'callSignature', type: 'CallSignatureSyntax' },
{ name: 'block', type: 'BlockSyntax' }
]
@@ -1798,7 +1803,7 @@ var definitions = [
children: [
{ name: 'catchKeyword', isToken: true, excludeFromAST: true },
{ name: 'openParenToken', isToken: true, excludeFromAST: true },
{ name: 'identifier', isToken: true, tokenKinds: ['IdentifierName'] },
{ name: 'identifier', isToken: true },
{ name: 'typeAnnotation', type: 'TypeAnnotationSyntax', isOptional: true, isTypeScriptSpecified: true },
{ name: 'closeParenToken', isToken: true, excludeFromAST: true },
{ name: 'block', type: 'BlockSyntax' }
@@ -1817,7 +1822,7 @@ var definitions = [
baseType: 'ISyntaxNode',
interfaces: ['IStatementSyntax'],
children: [
{ name: 'identifier', isToken: true, tokenKinds: ['IdentifierName'] },
{ name: 'identifier', isToken: true },
{ name: 'colonToken', isToken: true, excludeFromAST: true },
{ name: 'statement', type: 'IStatementSyntax' }
]
@@ -1863,6 +1868,16 @@ var definitions = [
{ name: 'expression', type: 'IUnaryExpressionSyntax' }
]
},
{
name: 'YieldExpressionSyntax',
baseType: 'ISyntaxNode',
interfaces: ['IExpressionSyntax'],
children: [
{ name: 'yieldKeyword', isToken: true },
{ name: 'asterixToken', isToken: true, isOptional: true },
{ name: 'expression', type: 'IExpressionSyntax', isOptional: true }
]
},
{
name: 'DebuggerStatementSyntax',
baseType: 'ISyntaxNode',
File diff suppressed because one or more lines are too long
+10 -7
View File
@@ -1,7 +1,7 @@
///<reference path='references.ts' />
module TypeScript {
export enum SyntaxConstants {
export enum SyntaxNodeConstants {
None = 0,
// Masks that we use to place information about a node into a single int. The first bit tells
@@ -15,12 +15,15 @@ module TypeScript {
// only be used by the incremental parser if it is parsed in the same strict context as before.
// last masks off the part of the int
//
// The width of the node is stored in the remainder of the int. This allows us up to 512MB
// for a node by using all 29 bits. However, in the common case, we'll use less than 29 bits
// The width of the node is stored in the remainder of the int. This allows us up to 128MB
// for a node by using all 27 bits. However, in the common case, we'll use less than 27 bits
// for the width. Thus, the info will be stored in a single int in chakra.
NodeDataComputed = 0x00000001, // 0000 0000 0000 0000 0000 0000 0000 0001
NodeIncrementallyUnusableMask = 0x00000002, // 0000 0000 0000 0000 0000 0000 0000 0010
NodeParsedInStrictModeMask = 0x00000004, // 0000 0000 0000 0000 0000 0000 0000 0100
NodeFullWidthShift = 3, // 1111 1111 1111 1111 1111 1111 1111 1000
DataComputed = 0x00000001, // 0000 0000 0000 0000 0000 0000 0000 0001
IncrementallyUnusableMask = 0x00000002, // 0000 0000 0000 0000 0000 0000 0000 0010
ParsedInStrictModeContext = 0x00000004, // 0000 0000 0000 0000 0000 0000 0000 0100
ParsedInDisallowInContext = 0x00000008, // 0000 0000 0000 0000 0000 0000 0000 1000
ParsedInYieldContext = 0x00000010, // 0000 0000 0000 0000 0000 0000 0001 0000
ParsedInGeneratorParameterContext = 0x00000020, // 0000 0000 0000 0000 0000 0000 0010 0000
FullWidthShift = 1 << 6, // 1111 1111 1111 1111 1111 1111 1100 0000
}
}
File diff suppressed because it is too large Load Diff
+6
View File
@@ -1018,6 +1018,12 @@ module TypeScript.PrettyPrinter {
visitNodeOrToken(this, node.expression);
}
public visitYieldExpression(node: YieldExpressionSyntax): void {
this.appendToken(node.yieldKeyword);
this.ensureSpace();
visitNodeOrToken(this, node.expression);
}
public visitDebuggerStatement(node: DebuggerStatementSyntax): void {
this.appendToken(node.debuggerKeyword);
this.appendToken(node.semicolonToken);
+35 -8
View File
@@ -17,13 +17,40 @@ module TypeScript {
return undefined;
}
export function parsedInStrictMode(node: ISyntaxNode): boolean {
export function parsedInStrictModeContext(node: ISyntaxNode): boolean {
var info = node.__data;
if (info === undefined) {
return false;
}
return (info & SyntaxConstants.NodeParsedInStrictModeMask) !== 0;
return (info & SyntaxNodeConstants.ParsedInStrictModeContext) !== 0;
}
export function parsedInDisallowInContext(node: ISyntaxNode): boolean {
var info = node.__data;
if (info === undefined) {
return false;
}
return (info & SyntaxNodeConstants.ParsedInDisallowInContext) !== 0;
}
export function parsedInYieldContext(node: ISyntaxNode): boolean {
var info = node.__data;
if (info === undefined) {
return false;
}
return (info & SyntaxNodeConstants.ParsedInYieldContext) !== 0;
}
export function parsedInGeneratorParameterContext(node: ISyntaxNode): boolean {
var info = node.__data;
if (info === undefined) {
return false;
}
return (info & SyntaxNodeConstants.ParsedInGeneratorParameterContext) !== 0;
}
export function previousToken(token: ISyntaxToken): ISyntaxToken {
@@ -257,7 +284,7 @@ module TypeScript {
}
var info = data(element);
return info >>> SyntaxConstants.NodeFullWidthShift;
return (info / SyntaxNodeConstants.FullWidthShift) | 0;
}
export function isIncrementallyUnusable(element: ISyntaxElement): boolean {
@@ -265,7 +292,7 @@ module TypeScript {
return (<ISyntaxToken>element).isIncrementallyUnusable();
}
return (data(element) & SyntaxConstants.NodeIncrementallyUnusableMask) !== 0;
return (data(element) & SyntaxNodeConstants.IncrementallyUnusableMask) !== 0;
}
function data(element: ISyntaxElement): number {
@@ -279,7 +306,7 @@ module TypeScript {
info = 0;
}
if ((info & SyntaxConstants.NodeDataComputed) === 0) {
if ((info & SyntaxNodeConstants.DataComputed) === 0) {
info |= computeData(element);
dataElement.__data = info;
}
@@ -288,9 +315,9 @@ module TypeScript {
}
function combineData(fullWidth: number, isIncrementallyUnusable: boolean) {
return (fullWidth << SyntaxConstants.NodeFullWidthShift)
| (isIncrementallyUnusable ? SyntaxConstants.NodeIncrementallyUnusableMask : 0)
| SyntaxConstants.NodeDataComputed;
return (fullWidth * SyntaxNodeConstants.FullWidthShift) +
(isIncrementallyUnusable ? SyntaxNodeConstants.IncrementallyUnusableMask : 0) +
SyntaxNodeConstants.DataComputed;
}
function listComputeData(list: ISyntaxNodeOrToken[]): number {
+32 -20
View File
@@ -23,7 +23,6 @@ interface IMemberDefinition {
isSeparatedList?: boolean;
requiresAtLeastOneItem?: boolean;
isOptional?: boolean;
tokenKinds?: string[];
isTypeScriptSpecific: boolean;
elementType?: string;
}
@@ -56,9 +55,9 @@ var definitions:ITypeDefinition[] = [
baseType: 'ISyntaxNode',
interfaces: ['IModuleReferenceSyntax'],
children: [
<any>{ name: 'requireKeyword', isToken: true, tokenKinds: ['RequireKeyword'], excludeFromAST: true },
<any>{ name: 'requireKeyword', isToken: true, excludeFromAST: true },
<any>{ name: 'openParenToken', isToken: true, excludeFromAST: true },
<any>{ name: 'stringLiteral', isToken: true, tokenKinds: ['StringLiteral'] },
<any>{ name: 'stringLiteral', isToken: true },
<any>{ name: 'closeParenToken', isToken: true, excludeFromAST: true }
],
isTypeScriptSpecific: true
@@ -79,7 +78,7 @@ var definitions:ITypeDefinition[] = [
children: [
<any>{ name: 'modifiers', isList: true, elementType: 'ISyntaxToken' },
<any>{ name: 'importKeyword', isToken: true, excludeFromAST: true },
<any>{ name: 'identifier', isToken: true, tokenKinds: ['IdentifierName'] },
<any>{ name: 'identifier', isToken: true },
<any>{ name: 'equalsToken', isToken: true, excludeFromAST: true },
<any>{ name: 'moduleReference', type: 'IModuleReferenceSyntax' },
<any>{ name: 'semicolonToken', isToken: true, isOptional: true, excludeFromAST: true }
@@ -93,7 +92,7 @@ var definitions:ITypeDefinition[] = [
children: [
<any>{ name: 'exportKeyword', isToken: true, excludeFromAST: true },
<any>{ name: 'equalsToken', isToken: true, excludeFromAST: true },
<any>{ name: 'identifier', isToken: true, tokenKinds: ['IdentifierName'] },
<any>{ name: 'identifier', isToken: true },
<any>{ name: 'semicolonToken', isToken: true, isOptional: true, excludeFromAST: true }
],
isTypeScriptSpecific: true
@@ -105,7 +104,7 @@ var definitions:ITypeDefinition[] = [
children: [
<any>{ name: 'modifiers', isList: true, elementType: 'ISyntaxToken' },
<any>{ name: 'classKeyword', isToken: true, excludeFromAST: true },
<any>{ name: 'identifier', isToken: true, tokenKinds: ['IdentifierName'] },
<any>{ name: 'identifier', isToken: true },
<any>{ name: 'typeParameterList', type: 'TypeParameterListSyntax', isOptional: true },
<any>{ name: 'heritageClauses', isList: true, elementType: 'HeritageClauseSyntax' },
<any>{ name: 'openBraceToken', isToken: true, excludeFromAST: true },
@@ -121,7 +120,7 @@ var definitions:ITypeDefinition[] = [
children: [
<any>{ name: 'modifiers', isList: true, elementType: 'ISyntaxToken' },
<any>{ name: 'interfaceKeyword', isToken: true, excludeFromAST: true },
<any>{ name: 'identifier', isToken: true, tokenKinds: ['IdentifierName'] },
<any>{ name: 'identifier', isToken: true },
<any>{ name: 'typeParameterList', type: 'TypeParameterListSyntax', isOptional: true },
<any>{ name: 'heritageClauses', isList: true, elementType: 'HeritageClauseSyntax' },
<any>{ name: 'body', type: 'ObjectTypeSyntax' }
@@ -158,7 +157,8 @@ var definitions:ITypeDefinition[] = [
children: [
<any>{ name: 'modifiers', isList: true, elementType: 'ISyntaxToken', isTypeScriptSpecific: true },
<any>{ name: 'functionKeyword', isToken: true, excludeFromAST: true },
<any>{ name: 'identifier', isToken: true, tokenKinds: ['IdentifierName'] },
<any>{ name: 'asterixToken', isToken: true, isOptional: true },
<any>{ name: 'identifier', isToken: true },
<any>{ name: 'callSignature', type: 'CallSignatureSyntax' },
<any>{ name: 'body', type: 'BlockSyntax | ISyntaxToken', isOptional: true }
]
@@ -262,7 +262,7 @@ var definitions:ITypeDefinition[] = [
children: [
<any>{ name: 'left', type: 'INameSyntax' },
<any>{ name: 'dotToken', isToken: true, excludeFromAST: true },
<any>{ name: 'right', isToken: true, tokenKinds:['IdentifierName'] }
<any>{ name: 'right', isToken: true }
],
// Qualified names only show up in Types, which are TypeScript specific. Note that a dotted
// expression (like A.B.Foo()) is a MemberAccessExpression, not a QualifiedName.
@@ -403,7 +403,7 @@ var definitions:ITypeDefinition[] = [
children: [
<any>{ name: 'dotDotDotToken', isToken: true, isOptional: true, isTypeScriptSpecific: true },
<any>{ name: 'modifiers', isList: true, elementType: 'ISyntaxToken' },
<any>{ name: 'identifier', isToken: true, tokenKinds: ['IdentifierName'] },
<any>{ name: 'identifier', isToken: true },
<any>{ name: 'questionToken', isToken: true, isOptional: true, isTypeScriptSpecific: true },
<any>{ name: 'typeAnnotation', type: 'TypeAnnotationSyntax', isOptional: true, isTypeScriptSpecific: true },
<any>{ name: 'equalsValueClause', type: 'EqualsValueClauseSyntax', isOptional: true, isTypeScriptSpecific: true }
@@ -416,7 +416,7 @@ var definitions:ITypeDefinition[] = [
children: [
<any>{ name: 'expression', type: 'ILeftHandSideExpressionSyntax' },
<any>{ name: 'dotToken', isToken: true, excludeFromAST: true },
<any>{ name: 'name', isToken: true, tokenKinds: ['IdentifierName'] }
<any>{ name: 'name', isToken: true }
]
},
<any>{
@@ -582,7 +582,7 @@ var definitions:ITypeDefinition[] = [
name: 'TypeParameterSyntax',
baseType: 'ISyntaxNode',
children: [
<any>{ name: 'identifier', isToken: true, tokenKinds: ['IdentifierName'] },
<any>{ name: 'identifier', isToken: true },
<any>{ name: 'constraint', type: 'ConstraintSyntax', isOptional: true }
],
isTypeScriptSpecific: true
@@ -645,6 +645,7 @@ var definitions:ITypeDefinition[] = [
interfaces: ['IMemberDeclarationSyntax'],
children: [
<any>{ name: 'modifiers', isList: true, elementType: 'ISyntaxToken' },
<any>{ name: 'asterixToken', isToken: true, isOptional: true },
<any>{ name: 'propertyName', type: 'IPropertyNameSyntax' },
<any>{ name: 'callSignature', type: 'CallSignatureSyntax' },
<any>{ name: 'body', type: 'BlockSyntax | ISyntaxToken', isOptional: true }
@@ -769,7 +770,7 @@ var definitions:ITypeDefinition[] = [
interfaces: ['IStatementSyntax'],
children: [
<any>{ name: 'breakKeyword', isToken: true },
<any>{ name: 'identifier', isToken: true, isOptional: true, tokenKinds: ['IdentifierName'] },
<any>{ name: 'identifier', isToken: true, isOptional: true },
<any>{ name: 'semicolonToken', isToken: true, isOptional: true, excludeFromAST: true }
]
},
@@ -779,7 +780,7 @@ var definitions:ITypeDefinition[] = [
interfaces: ['IStatementSyntax'],
children: [
<any>{ name: 'continueKeyword', isToken: true },
<any>{ name: 'identifier', isToken: true, isOptional: true, tokenKinds: ['IdentifierName'] },
<any>{ name: 'identifier', isToken: true, isOptional: true },
<any>{ name: 'semicolonToken', isToken: true, isOptional: true, excludeFromAST: true }
]
},
@@ -791,9 +792,9 @@ var definitions:ITypeDefinition[] = [
<any>{ name: 'forKeyword', isToken: true, excludeFromAST: true },
<any>{ name: 'openParenToken', isToken: true, excludeFromAST: true },
<any>{ name: 'initializer', type: 'VariableDeclarationSyntax | IExpressionSyntax', isOptional: true },
<any>{ name: 'firstSemicolonToken', isToken: true, tokenKinds: ['SemicolonToken'], excludeFromAST: true },
<any>{ name: 'firstSemicolonToken', isToken: true, excludeFromAST: true },
<any>{ name: 'condition', type: 'IExpressionSyntax', isOptional: true },
<any>{ name: 'secondSemicolonToken', isToken: true, tokenKinds: ['SemicolonToken'], excludeFromAST: true },
<any>{ name: 'secondSemicolonToken', isToken: true, excludeFromAST: true },
<any>{ name: 'incrementor', type: 'IExpressionSyntax', isOptional: true },
<any>{ name: 'closeParenToken', isToken: true, excludeFromAST: true },
<any>{ name: 'statement', type: 'IStatementSyntax' }
@@ -844,7 +845,7 @@ var definitions:ITypeDefinition[] = [
children: [
<any>{ name: 'modifiers', isList: true, elementType: 'ISyntaxToken' },
<any>{ name: 'enumKeyword', isToken: true, excludeFromAST: true },
<any>{ name: 'identifier', isToken: true, tokenKinds: ['IdentifierName'] },
<any>{ name: 'identifier', isToken: true },
<any>{ name: 'openBraceToken', isToken: true, excludeFromAST: true },
<any>{ name: 'enumElements', isSeparatedList: true, elementType: 'EnumElementSyntax' },
<any>{ name: 'closeBraceToken', isToken: true, excludeFromAST: true }
@@ -906,6 +907,7 @@ var definitions:ITypeDefinition[] = [
baseType: 'ISyntaxNode',
interfaces: ['IPropertyAssignmentSyntax'],
children: [
<any>{ name: 'asterixToken', isToken: true, isOptional: true },
<any>{ name: 'propertyName', type: 'IPropertyNameSyntax' },
<any>{ name: 'callSignature', type: 'CallSignatureSyntax' },
<any>{ name: 'block', type: 'BlockSyntax' }
@@ -917,7 +919,8 @@ var definitions:ITypeDefinition[] = [
interfaces: ['IPrimaryExpressionSyntax'],
children: [
<any>{ name: 'functionKeyword', isToken: true, excludeFromAST: true },
<any>{ name: 'identifier', isToken: true, isOptional: true, tokenKinds: ['IdentifierName'] },
<any>{ name: 'asterixToken', isToken: true, isOptional: true },
<any>{ name: 'identifier', isToken: true, isOptional: true },
<any>{ name: 'callSignature', type: 'CallSignatureSyntax' },
<any>{ name: 'block', type: 'BlockSyntax' }]
},
@@ -944,7 +947,7 @@ var definitions:ITypeDefinition[] = [
children: [
<any>{ name: 'catchKeyword', isToken: true, excludeFromAST: true },
<any>{ name: 'openParenToken', isToken: true, excludeFromAST: true },
<any>{ name: 'identifier', isToken: true, tokenKinds: ['IdentifierName'] },
<any>{ name: 'identifier', isToken: true },
<any>{ name: 'typeAnnotation', type: 'TypeAnnotationSyntax', isOptional: true, isTypeScriptSpecified: true },
<any>{ name: 'closeParenToken', isToken: true, excludeFromAST: true },
<any>{ name: 'block', type: 'BlockSyntax' }]
@@ -961,7 +964,7 @@ var definitions:ITypeDefinition[] = [
baseType: 'ISyntaxNode',
interfaces: ['IStatementSyntax'],
children: [
<any>{ name: 'identifier', isToken: true, tokenKinds: ['IdentifierName'] },
<any>{ name: 'identifier', isToken: true },
<any>{ name: 'colonToken', isToken: true, excludeFromAST: true },
<any>{ name: 'statement', type: 'IStatementSyntax' }]
},
@@ -1002,6 +1005,15 @@ var definitions:ITypeDefinition[] = [
<any>{ name: 'voidKeyword', isToken: true, excludeFromAST: true },
<any>{ name: 'expression', type: 'IUnaryExpressionSyntax' }]
},
<any>{
name: 'YieldExpressionSyntax',
baseType: 'ISyntaxNode',
interfaces: ['IExpressionSyntax'],
children: [
<any>{ name: 'yieldKeyword', isToken: true },
<any>{ name: 'asterixToken', isToken: true, isOptional: true },
<any>{ name: 'expression', type: 'IExpressionSyntax', isOptional: true }]
},
<any>{
name: 'DebuggerStatementSyntax',
baseType: 'ISyntaxNode',
@@ -92,11 +92,12 @@ module TypeScript {
export interface FunctionDeclarationSyntax extends ISyntaxNode, IStatementSyntax {
modifiers: ISyntaxToken[];
functionKeyword: ISyntaxToken;
asterixToken: ISyntaxToken;
identifier: ISyntaxToken;
callSignature: CallSignatureSyntax;
body: BlockSyntax | ISyntaxToken;
}
export interface FunctionDeclarationConstructor { new (data: number, modifiers: ISyntaxToken[], functionKeyword: ISyntaxToken, identifier: ISyntaxToken, callSignature: CallSignatureSyntax, body: BlockSyntax | ISyntaxToken): FunctionDeclarationSyntax }
export interface FunctionDeclarationConstructor { new (data: number, modifiers: ISyntaxToken[], functionKeyword: ISyntaxToken, asterixToken: ISyntaxToken, identifier: ISyntaxToken, callSignature: CallSignatureSyntax, body: BlockSyntax | ISyntaxToken): FunctionDeclarationSyntax }
export interface ModuleDeclarationSyntax extends ISyntaxNode, IModuleElementSyntax {
modifiers: ISyntaxToken[];
@@ -150,11 +151,12 @@ module TypeScript {
export interface MemberFunctionDeclarationSyntax extends ISyntaxNode, IMemberDeclarationSyntax {
modifiers: ISyntaxToken[];
asterixToken: ISyntaxToken;
propertyName: IPropertyNameSyntax;
callSignature: CallSignatureSyntax;
body: BlockSyntax | ISyntaxToken;
}
export interface MemberFunctionDeclarationConstructor { new (data: number, modifiers: ISyntaxToken[], propertyName: IPropertyNameSyntax, callSignature: CallSignatureSyntax, body: BlockSyntax | ISyntaxToken): MemberFunctionDeclarationSyntax }
export interface MemberFunctionDeclarationConstructor { new (data: number, modifiers: ISyntaxToken[], asterixToken: ISyntaxToken, propertyName: IPropertyNameSyntax, callSignature: CallSignatureSyntax, body: BlockSyntax | ISyntaxToken): MemberFunctionDeclarationSyntax }
export interface MemberVariableDeclarationSyntax extends ISyntaxNode, IMemberDeclarationSyntax {
modifiers: ISyntaxToken[];
@@ -498,11 +500,12 @@ module TypeScript {
export interface FunctionExpressionSyntax extends ISyntaxNode, IPrimaryExpressionSyntax {
functionKeyword: ISyntaxToken;
asterixToken: ISyntaxToken;
identifier: ISyntaxToken;
callSignature: CallSignatureSyntax;
block: BlockSyntax;
}
export interface FunctionExpressionConstructor { new (data: number, functionKeyword: ISyntaxToken, identifier: ISyntaxToken, callSignature: CallSignatureSyntax, block: BlockSyntax): FunctionExpressionSyntax }
export interface FunctionExpressionConstructor { new (data: number, functionKeyword: ISyntaxToken, asterixToken: ISyntaxToken, identifier: ISyntaxToken, callSignature: CallSignatureSyntax, block: BlockSyntax): FunctionExpressionSyntax }
export interface OmittedExpressionSyntax extends ISyntaxNode, IExpressionSyntax {
}
@@ -520,6 +523,13 @@ module TypeScript {
}
export interface TemplateAccessExpressionConstructor { new (data: number, expression: ILeftHandSideExpressionSyntax, templateExpression: IPrimaryExpressionSyntax): TemplateAccessExpressionSyntax }
export interface YieldExpressionSyntax extends ISyntaxNode, IExpressionSyntax {
yieldKeyword: ISyntaxToken;
asterixToken: ISyntaxToken;
expression: IExpressionSyntax;
}
export interface YieldExpressionConstructor { new (data: number, yieldKeyword: ISyntaxToken, asterixToken: ISyntaxToken, expression: IExpressionSyntax): YieldExpressionSyntax }
export interface VariableDeclarationSyntax extends ISyntaxNode {
varKeyword: ISyntaxToken;
variableDeclarators: ISeparatedSyntaxList<VariableDeclaratorSyntax>;
@@ -637,11 +647,12 @@ module TypeScript {
export interface SimplePropertyAssignmentConstructor { new (data: number, propertyName: IPropertyNameSyntax, colonToken: ISyntaxToken, expression: IExpressionSyntax): SimplePropertyAssignmentSyntax }
export interface FunctionPropertyAssignmentSyntax extends ISyntaxNode, IPropertyAssignmentSyntax {
asterixToken: ISyntaxToken;
propertyName: IPropertyNameSyntax;
callSignature: CallSignatureSyntax;
block: BlockSyntax;
}
export interface FunctionPropertyAssignmentConstructor { new (data: number, propertyName: IPropertyNameSyntax, callSignature: CallSignatureSyntax, block: BlockSyntax): FunctionPropertyAssignmentSyntax }
export interface FunctionPropertyAssignmentConstructor { new (data: number, asterixToken: ISyntaxToken, propertyName: IPropertyNameSyntax, callSignature: CallSignatureSyntax, block: BlockSyntax): FunctionPropertyAssignmentSyntax }
export interface ParameterSyntax extends ISyntaxNode {
dotDotDotToken: ISyntaxToken;
+1
View File
@@ -234,6 +234,7 @@ module TypeScript {
OmittedExpression,
TemplateExpression,
TemplateAccessExpression,
YieldExpression,
// Variable declarations
VariableDeclaration,
@@ -238,28 +238,31 @@ module TypeScript {
}
}
export var FunctionDeclarationSyntax: FunctionDeclarationConstructor = <any>function(data: number, modifiers: ISyntaxToken[], functionKeyword: ISyntaxToken, identifier: ISyntaxToken, callSignature: CallSignatureSyntax, body: BlockSyntax | ISyntaxToken) {
export var FunctionDeclarationSyntax: FunctionDeclarationConstructor = <any>function(data: number, modifiers: ISyntaxToken[], functionKeyword: ISyntaxToken, asterixToken: ISyntaxToken, identifier: ISyntaxToken, callSignature: CallSignatureSyntax, body: BlockSyntax | ISyntaxToken) {
if (data) { this.__data = data; }
this.modifiers = modifiers,
this.functionKeyword = functionKeyword,
this.asterixToken = asterixToken,
this.identifier = identifier,
this.callSignature = callSignature,
this.body = body,
modifiers.parent = this,
functionKeyword.parent = this,
asterixToken && (asterixToken.parent = this),
identifier.parent = this,
callSignature.parent = this,
body && (body.parent = this);
};
FunctionDeclarationSyntax.prototype.kind = SyntaxKind.FunctionDeclaration;
FunctionDeclarationSyntax.prototype.childCount = 5;
FunctionDeclarationSyntax.prototype.childCount = 6;
FunctionDeclarationSyntax.prototype.childAt = function(index: number): ISyntaxElement {
switch (index) {
case 0: return this.modifiers;
case 1: return this.functionKeyword;
case 2: return this.identifier;
case 3: return this.callSignature;
case 4: return this.body;
case 2: return this.asterixToken;
case 3: return this.identifier;
case 4: return this.callSignature;
case 5: return this.body;
}
}
@@ -403,25 +406,28 @@ module TypeScript {
}
}
export var MemberFunctionDeclarationSyntax: MemberFunctionDeclarationConstructor = <any>function(data: number, modifiers: ISyntaxToken[], propertyName: IPropertyNameSyntax, callSignature: CallSignatureSyntax, body: BlockSyntax | ISyntaxToken) {
export var MemberFunctionDeclarationSyntax: MemberFunctionDeclarationConstructor = <any>function(data: number, modifiers: ISyntaxToken[], asterixToken: ISyntaxToken, propertyName: IPropertyNameSyntax, callSignature: CallSignatureSyntax, body: BlockSyntax | ISyntaxToken) {
if (data) { this.__data = data; }
this.modifiers = modifiers,
this.asterixToken = asterixToken,
this.propertyName = propertyName,
this.callSignature = callSignature,
this.body = body,
modifiers.parent = this,
asterixToken && (asterixToken.parent = this),
propertyName.parent = this,
callSignature.parent = this,
body && (body.parent = this);
};
MemberFunctionDeclarationSyntax.prototype.kind = SyntaxKind.MemberFunctionDeclaration;
MemberFunctionDeclarationSyntax.prototype.childCount = 4;
MemberFunctionDeclarationSyntax.prototype.childCount = 5;
MemberFunctionDeclarationSyntax.prototype.childAt = function(index: number): ISyntaxElement {
switch (index) {
case 0: return this.modifiers;
case 1: return this.propertyName;
case 2: return this.callSignature;
case 3: return this.body;
case 1: return this.asterixToken;
case 2: return this.propertyName;
case 3: return this.callSignature;
case 4: return this.body;
}
}
@@ -1355,25 +1361,28 @@ module TypeScript {
}
}
export var FunctionExpressionSyntax: FunctionExpressionConstructor = <any>function(data: number, functionKeyword: ISyntaxToken, identifier: ISyntaxToken, callSignature: CallSignatureSyntax, block: BlockSyntax) {
export var FunctionExpressionSyntax: FunctionExpressionConstructor = <any>function(data: number, functionKeyword: ISyntaxToken, asterixToken: ISyntaxToken, identifier: ISyntaxToken, callSignature: CallSignatureSyntax, block: BlockSyntax) {
if (data) { this.__data = data; }
this.functionKeyword = functionKeyword,
this.asterixToken = asterixToken,
this.identifier = identifier,
this.callSignature = callSignature,
this.block = block,
functionKeyword.parent = this,
asterixToken && (asterixToken.parent = this),
identifier && (identifier.parent = this),
callSignature.parent = this,
block.parent = this;
};
FunctionExpressionSyntax.prototype.kind = SyntaxKind.FunctionExpression;
FunctionExpressionSyntax.prototype.childCount = 4;
FunctionExpressionSyntax.prototype.childCount = 5;
FunctionExpressionSyntax.prototype.childAt = function(index: number): ISyntaxElement {
switch (index) {
case 0: return this.functionKeyword;
case 1: return this.identifier;
case 2: return this.callSignature;
case 3: return this.block;
case 1: return this.asterixToken;
case 2: return this.identifier;
case 3: return this.callSignature;
case 4: return this.block;
}
}
@@ -1418,6 +1427,25 @@ module TypeScript {
}
}
export var YieldExpressionSyntax: YieldExpressionConstructor = <any>function(data: number, yieldKeyword: ISyntaxToken, asterixToken: ISyntaxToken, expression: IExpressionSyntax) {
if (data) { this.__data = data; }
this.yieldKeyword = yieldKeyword,
this.asterixToken = asterixToken,
this.expression = expression,
yieldKeyword.parent = this,
asterixToken && (asterixToken.parent = this),
expression && (expression.parent = this);
};
YieldExpressionSyntax.prototype.kind = SyntaxKind.YieldExpression;
YieldExpressionSyntax.prototype.childCount = 3;
YieldExpressionSyntax.prototype.childAt = function(index: number): ISyntaxElement {
switch (index) {
case 0: return this.yieldKeyword;
case 1: return this.asterixToken;
case 2: return this.expression;
}
}
export var VariableDeclarationSyntax: VariableDeclarationConstructor = <any>function(data: number, varKeyword: ISyntaxToken, variableDeclarators: ISeparatedSyntaxList<VariableDeclaratorSyntax>) {
if (data) { this.__data = data; }
this.varKeyword = varKeyword,
@@ -1732,22 +1760,25 @@ module TypeScript {
}
}
export var FunctionPropertyAssignmentSyntax: FunctionPropertyAssignmentConstructor = <any>function(data: number, propertyName: IPropertyNameSyntax, callSignature: CallSignatureSyntax, block: BlockSyntax) {
export var FunctionPropertyAssignmentSyntax: FunctionPropertyAssignmentConstructor = <any>function(data: number, asterixToken: ISyntaxToken, propertyName: IPropertyNameSyntax, callSignature: CallSignatureSyntax, block: BlockSyntax) {
if (data) { this.__data = data; }
this.asterixToken = asterixToken,
this.propertyName = propertyName,
this.callSignature = callSignature,
this.block = block,
asterixToken && (asterixToken.parent = this),
propertyName.parent = this,
callSignature.parent = this,
block.parent = this;
};
FunctionPropertyAssignmentSyntax.prototype.kind = SyntaxKind.FunctionPropertyAssignment;
FunctionPropertyAssignmentSyntax.prototype.childCount = 3;
FunctionPropertyAssignmentSyntax.prototype.childCount = 4;
FunctionPropertyAssignmentSyntax.prototype.childAt = function(index: number): ISyntaxElement {
switch (index) {
case 0: return this.propertyName;
case 1: return this.callSignature;
case 2: return this.block;
case 0: return this.asterixToken;
case 1: return this.propertyName;
case 2: return this.callSignature;
case 3: return this.block;
}
}
+16 -7
View File
@@ -1297,7 +1297,7 @@ module TypeScript {
}
private checkForWithInStrictMode(node: WithStatementSyntax): boolean {
if (parsedInStrictMode(node)) {
if (parsedInStrictModeContext(node)) {
this.pushDiagnostic(firstToken(node), DiagnosticCode.with_statements_are_not_allowed_in_strict_mode);
return true;
}
@@ -1509,7 +1509,7 @@ module TypeScript {
}
public visitPrefixUnaryExpression(node: PrefixUnaryExpressionSyntax): void {
if (parsedInStrictMode(node) && this.isPreIncrementOrDecrementExpression(node) && this.isEvalOrArguments(node.operand)) {
if (parsedInStrictModeContext(node) && this.isPreIncrementOrDecrementExpression(node) && this.isEvalOrArguments(node.operand)) {
this.pushDiagnostic(node.operatorToken, DiagnosticCode.Invalid_use_of_0_in_strict_mode, [this.getEvalOrArguments(node.operand)]);
}
@@ -1517,7 +1517,7 @@ module TypeScript {
}
public visitPostfixUnaryExpression(node: PostfixUnaryExpressionSyntax): void {
if (parsedInStrictMode(node) && this.isEvalOrArguments(node.operand)) {
if (parsedInStrictModeContext(node) && this.isEvalOrArguments(node.operand)) {
this.pushDiagnostic(node.operatorToken, DiagnosticCode.Invalid_use_of_0_in_strict_mode, [this.getEvalOrArguments(node.operand)]);
}
@@ -1534,7 +1534,7 @@ module TypeScript {
private checkForDisallowedEvalOrArguments(node: ISyntaxNode, token: ISyntaxToken): boolean {
if (token) {
if (parsedInStrictMode(node) && this.isEvalOrArguments(token)) {
if (parsedInStrictModeContext(node) && this.isEvalOrArguments(token)) {
this.pushDiagnostic(token, DiagnosticCode.Invalid_use_of_0_in_strict_mode, [this.getEvalOrArguments(token)]);
return true;
}
@@ -1554,16 +1554,25 @@ module TypeScript {
}
public visitDeleteExpression(node: DeleteExpressionSyntax): void {
if (parsedInStrictMode(node) && node.expression.kind === SyntaxKind.IdentifierName) {
this.pushDiagnostic(firstToken(node), DiagnosticCode.delete_cannot_be_called_on_an_identifier_in_strict_mode);
if (parsedInStrictModeContext(node) && node.expression.kind === SyntaxKind.IdentifierName) {
this.pushDiagnostic(node.deleteKeyword, DiagnosticCode.delete_cannot_be_called_on_an_identifier_in_strict_mode);
return;
}
super.visitDeleteExpression(node);
}
public visitYieldExpression(node: YieldExpressionSyntax): void {
if (!parsedInYieldContext(node)) {
this.pushDiagnostic(node.yieldKeyword, DiagnosticCode.yield_expression_must_be_contained_within_a_generator_declaration);
return;
}
super.visitYieldExpression(node);
}
private checkIllegalAssignment(node: BinaryExpressionSyntax): boolean {
if (parsedInStrictMode(node) && SyntaxFacts.isAssignmentOperatorToken(node.operatorToken.kind) && this.isEvalOrArguments(node.left)) {
if (parsedInStrictModeContext(node) && SyntaxFacts.isAssignmentOperatorToken(node.operatorToken.kind) && this.isEvalOrArguments(node.left)) {
this.pushDiagnostic(node.operatorToken, DiagnosticCode.Invalid_use_of_0_in_strict_mode, [this.getEvalOrArguments(node.left)]);
return true;
}
@@ -72,6 +72,7 @@ module TypeScript {
case SyntaxKind.OmittedExpression: return visitor.visitOmittedExpression(<OmittedExpressionSyntax>element);
case SyntaxKind.TemplateExpression: return visitor.visitTemplateExpression(<TemplateExpressionSyntax>element);
case SyntaxKind.TemplateAccessExpression: return visitor.visitTemplateAccessExpression(<TemplateAccessExpressionSyntax>element);
case SyntaxKind.YieldExpression: return visitor.visitYieldExpression(<YieldExpressionSyntax>element);
case SyntaxKind.VariableDeclaration: return visitor.visitVariableDeclaration(<VariableDeclarationSyntax>element);
case SyntaxKind.VariableDeclarator: return visitor.visitVariableDeclarator(<VariableDeclaratorSyntax>element);
case SyntaxKind.ArgumentList: return visitor.visitArgumentList(<ArgumentListSyntax>element);
@@ -170,6 +171,7 @@ module TypeScript {
visitOmittedExpression(node: OmittedExpressionSyntax): any;
visitTemplateExpression(node: TemplateExpressionSyntax): any;
visitTemplateAccessExpression(node: TemplateAccessExpressionSyntax): any;
visitYieldExpression(node: YieldExpressionSyntax): any;
visitVariableDeclaration(node: VariableDeclarationSyntax): any;
visitVariableDeclarator(node: VariableDeclaratorSyntax): any;
visitArgumentList(node: ArgumentListSyntax): any;
@@ -97,6 +97,7 @@ module TypeScript {
public visitFunctionDeclaration(node: FunctionDeclarationSyntax): void {
this.visitList(node.modifiers);
this.visitToken(node.functionKeyword);
this.visitOptionalToken(node.asterixToken);
this.visitToken(node.identifier);
visitNodeOrToken(this, node.callSignature);
visitNodeOrToken(this, node.body);
@@ -149,6 +150,7 @@ module TypeScript {
public visitMemberFunctionDeclaration(node: MemberFunctionDeclarationSyntax): void {
this.visitList(node.modifiers);
this.visitOptionalToken(node.asterixToken);
visitNodeOrToken(this, node.propertyName);
visitNodeOrToken(this, node.callSignature);
visitNodeOrToken(this, node.body);
@@ -451,6 +453,7 @@ module TypeScript {
public visitFunctionExpression(node: FunctionExpressionSyntax): void {
this.visitToken(node.functionKeyword);
this.visitOptionalToken(node.asterixToken);
this.visitOptionalToken(node.identifier);
visitNodeOrToken(this, node.callSignature);
visitNodeOrToken(this, node.block);
@@ -469,6 +472,12 @@ module TypeScript {
visitNodeOrToken(this, node.templateExpression);
}
public visitYieldExpression(node: YieldExpressionSyntax): void {
this.visitToken(node.yieldKeyword);
this.visitOptionalToken(node.asterixToken);
visitNodeOrToken(this, node.expression);
}
public visitVariableDeclaration(node: VariableDeclarationSyntax): void {
this.visitToken(node.varKeyword);
this.visitList(node.variableDeclarators);
@@ -569,6 +578,7 @@ module TypeScript {
}
public visitFunctionPropertyAssignment(node: FunctionPropertyAssignmentSyntax): void {
this.visitOptionalToken(node.asterixToken);
visitNodeOrToken(this, node.propertyName);
visitNodeOrToken(this, node.callSignature);
visitNodeOrToken(this, node.block);
+4 -10
View File
@@ -280,19 +280,13 @@ module ts {
}
function nodeHasTokens(n: Node): boolean {
if (n.kind === SyntaxKind.ExpressionStatement) {
return nodeHasTokens((<ExpressionStatement>n).expression);
}
if (n.kind === SyntaxKind.EndOfFileToken ||
n.kind === SyntaxKind.OmittedExpression ||
n.kind === SyntaxKind.Missing ||
n.kind === SyntaxKind.Unknown) {
if (n.kind === SyntaxKind.Unknown) {
return false;
}
// SyntaxList is already realized so getChildCount should be fast and non-expensive
return n.kind !== SyntaxKind.SyntaxList || n.getChildCount() !== 0;
// If we have a token or node that has a non-zero width, it must have tokens.
// Note, that getWidth() does not take trivia into account.
return n.getWidth() !== 0;
}
export function getTypeArgumentOrTypeParameterList(node: Node): NodeArray<Node> {