Merge branch 'master' into unionPropertyAccess

This commit is contained in:
Anders Hejlsberg
2015-04-17 17:19:21 -07:00
238 changed files with 15868 additions and 13097 deletions
+149 -108
View File
@@ -349,7 +349,8 @@ module ts {
}
result = undefined;
}
else if (location.kind === SyntaxKind.SourceFile) {
else if (location.kind === SyntaxKind.SourceFile ||
(location.kind === SyntaxKind.ModuleDeclaration && (<ModuleDeclaration>location).name.kind === SyntaxKind.StringLiteral)) {
result = getSymbol(getSymbolOfNode(location).exports, "default", meaning & SymbolFlags.ModuleMember);
let localSymbol = getLocalSymbolForExportDefault(result);
if (result && (result.flags & meaning) && localSymbol && localSymbol.name === name) {
@@ -597,7 +598,7 @@ module ts {
if (moduleSymbol.flags & SymbolFlags.Variable) {
let typeAnnotation = (<VariableDeclaration>moduleSymbol.valueDeclaration).type;
if (typeAnnotation) {
return getPropertyOfType(getTypeFromTypeNodeOrHeritageClauseElement(typeAnnotation), name);
return getPropertyOfType(getTypeFromTypeNode(typeAnnotation), name);
}
}
}
@@ -646,7 +647,7 @@ module ts {
if (symbol.flags & SymbolFlags.Variable) {
var typeAnnotation = (<VariableDeclaration>symbol.valueDeclaration).type;
if (typeAnnotation) {
return resolveSymbol(getPropertyOfType(getTypeFromTypeNodeOrHeritageClauseElement(typeAnnotation), name));
return resolveSymbol(getPropertyOfType(getTypeFromTypeNode(typeAnnotation), name));
}
}
}
@@ -2127,7 +2128,7 @@ module ts {
}
// Use type from type annotation if one is present
if (declaration.type) {
return getTypeFromTypeNodeOrHeritageClauseElement(declaration.type);
return getTypeFromTypeNode(declaration.type);
}
if (declaration.kind === SyntaxKind.Parameter) {
let func = <FunctionLikeDeclaration>declaration.parent;
@@ -2289,18 +2290,18 @@ module ts {
return links.type;
}
function getSetAccessorTypeAnnotationNode(accessor: AccessorDeclaration): TypeNode | LiteralExpression {
function getSetAccessorTypeAnnotationNode(accessor: AccessorDeclaration): TypeNode {
return accessor && accessor.parameters.length > 0 && accessor.parameters[0].type;
}
function getAnnotatedAccessorType(accessor: AccessorDeclaration): Type {
if (accessor) {
if (accessor.kind === SyntaxKind.GetAccessor) {
return accessor.type && getTypeFromTypeNodeOrHeritageClauseElement(accessor.type);
return accessor.type && getTypeFromTypeNode(accessor.type);
}
else {
let setterTypeAnnotation = getSetAccessorTypeAnnotationNode(accessor);
return setterTypeAnnotation && getTypeFromTypeNodeOrHeritageClauseElement(setterTypeAnnotation);
return setterTypeAnnotation && getTypeFromTypeNode(setterTypeAnnotation);
}
}
return undefined;
@@ -2423,7 +2424,7 @@ module ts {
return check(type);
function check(type: InterfaceType): boolean {
let target = <InterfaceType>getTargetType(type);
return target === checkBase || forEach(target.baseTypes, check);
return target === checkBase || forEach(getBaseTypes(target), check);
}
}
@@ -2451,6 +2452,70 @@ module ts {
return result;
}
function getBaseTypes(type: InterfaceType): ObjectType[]{
let typeWithBaseTypes = <InterfaceTypeWithBaseTypes>type;
if (!typeWithBaseTypes.baseTypes) {
if (type.symbol.flags & SymbolFlags.Class) {
resolveBaseTypesOfClass(typeWithBaseTypes);
}
else if (type.symbol.flags & SymbolFlags.Interface) {
resolveBaseTypesOfInterface(typeWithBaseTypes);
}
else {
Debug.fail("type must be class or interface");
}
}
return typeWithBaseTypes.baseTypes;
}
function resolveBaseTypesOfClass(type: InterfaceTypeWithBaseTypes): void {
type.baseTypes = [];
let declaration = <ClassDeclaration>getDeclarationOfKind(type.symbol, SyntaxKind.ClassDeclaration);
let baseTypeNode = getClassExtendsHeritageClauseElement(declaration);
if (baseTypeNode) {
let baseType = getTypeFromHeritageClauseElement(baseTypeNode);
if (baseType !== unknownType) {
if (getTargetType(baseType).flags & TypeFlags.Class) {
if (type !== baseType && !hasBaseType(<InterfaceType>baseType, type)) {
type.baseTypes.push(baseType);
}
else {
error(declaration, Diagnostics.Type_0_recursively_references_itself_as_a_base_type, typeToString(type, /*enclosingDeclaration*/ undefined, TypeFormatFlags.WriteArrayAsGenericType));
}
}
else {
error(baseTypeNode, Diagnostics.A_class_may_only_extend_another_class);
}
}
}
}
function resolveBaseTypesOfInterface(type: InterfaceTypeWithBaseTypes): void {
type.baseTypes = [];
for (let declaration of type.symbol.declarations) {
if (declaration.kind === SyntaxKind.InterfaceDeclaration && getInterfaceBaseTypeNodes(<InterfaceDeclaration>declaration)) {
for (let node of getInterfaceBaseTypeNodes(<InterfaceDeclaration>declaration)) {
let baseType = getTypeFromHeritageClauseElement(node);
if (baseType !== unknownType) {
if (getTargetType(baseType).flags & (TypeFlags.Class | TypeFlags.Interface)) {
if (type !== baseType && !hasBaseType(<InterfaceType>baseType, type)) {
type.baseTypes.push(baseType);
}
else {
error(declaration, Diagnostics.Type_0_recursively_references_itself_as_a_base_type, typeToString(type, /*enclosingDeclaration*/ undefined, TypeFormatFlags.WriteArrayAsGenericType));
}
}
else {
error(node, Diagnostics.An_interface_may_only_extend_a_class_or_another_interface);
}
}
}
}
}
}
function getDeclaredTypeOfClass(symbol: Symbol): InterfaceType {
let links = getSymbolLinks(symbol);
if (!links.declaredType) {
@@ -2464,25 +2529,7 @@ module ts {
(<GenericType>type).target = <GenericType>type;
(<GenericType>type).typeArguments = type.typeParameters;
}
type.baseTypes = [];
let declaration = <ClassDeclaration>getDeclarationOfKind(symbol, SyntaxKind.ClassDeclaration);
let baseTypeNode = getClassExtendsHeritageClauseElement(declaration);
if (baseTypeNode) {
let baseType = getTypeFromHeritageClauseElement(baseTypeNode);
if (baseType !== unknownType) {
if (getTargetType(baseType).flags & TypeFlags.Class) {
if (type !== baseType && !hasBaseType(<InterfaceType>baseType, type)) {
type.baseTypes.push(baseType);
}
else {
error(declaration, Diagnostics.Type_0_recursively_references_itself_as_a_base_type, typeToString(type, /*enclosingDeclaration*/ undefined, TypeFormatFlags.WriteArrayAsGenericType));
}
}
else {
error(baseTypeNode, Diagnostics.A_class_may_only_extend_another_class);
}
}
}
type.declaredProperties = getNamedMembers(symbol.members);
type.declaredCallSignatures = emptyArray;
type.declaredConstructSignatures = emptyArray;
@@ -2505,28 +2552,7 @@ module ts {
(<GenericType>type).target = <GenericType>type;
(<GenericType>type).typeArguments = type.typeParameters;
}
type.baseTypes = [];
forEach(symbol.declarations, declaration => {
if (declaration.kind === SyntaxKind.InterfaceDeclaration && getInterfaceBaseTypeNodes(<InterfaceDeclaration>declaration)) {
forEach(getInterfaceBaseTypeNodes(<InterfaceDeclaration>declaration), node => {
let baseType = getTypeFromHeritageClauseElement(node);
if (baseType !== unknownType) {
if (getTargetType(baseType).flags & (TypeFlags.Class | TypeFlags.Interface)) {
if (type !== baseType && !hasBaseType(<InterfaceType>baseType, type)) {
type.baseTypes.push(baseType);
}
else {
error(declaration, Diagnostics.Type_0_recursively_references_itself_as_a_base_type, typeToString(type, /*enclosingDeclaration*/ undefined, TypeFormatFlags.WriteArrayAsGenericType));
}
}
else {
error(node, Diagnostics.An_interface_may_only_extend_a_class_or_another_interface);
}
}
});
}
});
type.declaredProperties = getNamedMembers(symbol.members);
type.declaredCallSignatures = getSignaturesOfSymbol(symbol.members["__call"]);
type.declaredConstructSignatures = getSignaturesOfSymbol(symbol.members["__new"]);
@@ -2541,7 +2567,7 @@ module ts {
if (!links.declaredType) {
links.declaredType = resolvingType;
let declaration = <TypeAliasDeclaration>getDeclarationOfKind(symbol, SyntaxKind.TypeAliasDeclaration);
let type = getTypeFromTypeNodeOrHeritageClauseElement(declaration.type);
let type = getTypeFromTypeNode(declaration.type);
if (links.declaredType === resolvingType) {
links.declaredType = type;
}
@@ -2646,15 +2672,16 @@ module ts {
let constructSignatures = type.declaredConstructSignatures;
let stringIndexType = type.declaredStringIndexType;
let numberIndexType = type.declaredNumberIndexType;
if (type.baseTypes.length) {
let baseTypes = getBaseTypes(type);
if (baseTypes.length) {
members = createSymbolTable(type.declaredProperties);
forEach(type.baseTypes, baseType => {
for (let baseType of baseTypes) {
addInheritedMembers(members, getPropertiesOfObjectType(baseType));
callSignatures = concatenate(callSignatures, getSignaturesOfType(baseType, SignatureKind.Call));
constructSignatures = concatenate(constructSignatures, getSignaturesOfType(baseType, SignatureKind.Construct));
stringIndexType = stringIndexType || getIndexTypeOfType(baseType, IndexKind.String);
numberIndexType = numberIndexType || getIndexTypeOfType(baseType, IndexKind.Number);
});
}
}
setObjectTypeMembers(type, members, callSignatures, constructSignatures, stringIndexType, numberIndexType);
}
@@ -2667,7 +2694,7 @@ module ts {
let constructSignatures = instantiateList(target.declaredConstructSignatures, mapper, instantiateSignature);
let stringIndexType = target.declaredStringIndexType ? instantiateType(target.declaredStringIndexType, mapper) : undefined;
let numberIndexType = target.declaredNumberIndexType ? instantiateType(target.declaredNumberIndexType, mapper) : undefined;
forEach(target.baseTypes, baseType => {
forEach(getBaseTypes(target), baseType => {
let instantiatedBaseType = instantiateType(baseType, mapper);
addInheritedMembers(members, getPropertiesOfObjectType(instantiatedBaseType));
callSignatures = concatenate(callSignatures, getSignaturesOfType(instantiatedBaseType, SignatureKind.Call));
@@ -2696,9 +2723,10 @@ module ts {
sig.minArgumentCount, sig.hasRestParameter, sig.hasStringLiterals);
}
function getDefaultConstructSignatures(classType: InterfaceType): Signature[] {
if (classType.baseTypes.length) {
let baseType = classType.baseTypes[0];
function getDefaultConstructSignatures(classType: InterfaceType): Signature[]{
let baseTypes = getBaseTypes(classType);
if (baseTypes.length) {
let baseType = baseTypes[0];
let baseSignatures = getSignaturesOfType(getTypeOfSymbol(baseType.symbol), SignatureKind.Construct);
return map(baseSignatures, baseSignature => {
let signature = baseType.flags & TypeFlags.Reference ?
@@ -2820,9 +2848,10 @@ module ts {
if (!constructSignatures.length) {
constructSignatures = getDefaultConstructSignatures(classType);
}
if (classType.baseTypes.length) {
let baseTypes = getBaseTypes(classType);
if (baseTypes.length) {
members = createSymbolTable(getNamedMembers(members));
addInheritedMembers(members, getPropertiesOfObjectType(getTypeOfSymbol(classType.baseTypes[0].symbol)));
addInheritedMembers(members, getPropertiesOfObjectType(getTypeOfSymbol(baseTypes[0].symbol)));
}
}
stringIndexType = undefined;
@@ -3083,7 +3112,7 @@ module ts {
returnType = classType;
}
else if (declaration.type) {
returnType = getTypeFromTypeNodeOrHeritageClauseElement(declaration.type);
returnType = getTypeFromTypeNode(declaration.type);
}
else {
// TypeScript 1.0 spec (April 2014):
@@ -3241,7 +3270,7 @@ module ts {
function getIndexTypeOfSymbol(symbol: Symbol, kind: IndexKind): Type {
let declaration = getIndexDeclarationOfSymbol(symbol, kind);
return declaration
? declaration.type ? getTypeFromTypeNodeOrHeritageClauseElement(declaration.type) : anyType
? declaration.type ? getTypeFromTypeNode(declaration.type) : anyType
: undefined;
}
@@ -3252,7 +3281,7 @@ module ts {
type.constraint = targetConstraint ? instantiateType(targetConstraint, type.mapper) : noConstraintType;
}
else {
type.constraint = getTypeFromTypeNodeOrHeritageClauseElement((<TypeParameterDeclaration>getDeclarationOfKind(type.symbol, SyntaxKind.TypeParameter)).constraint);
type.constraint = getTypeFromTypeNode((<TypeParameterDeclaration>getDeclarationOfKind(type.symbol, SyntaxKind.TypeParameter)).constraint);
}
}
return type.constraint === noConstraintType ? undefined : type.constraint;
@@ -3383,7 +3412,7 @@ module ts {
if (type.flags & (TypeFlags.Class | TypeFlags.Interface) && type.flags & TypeFlags.Reference) {
let typeParameters = (<InterfaceType>type).typeParameters;
if (node.typeArguments && node.typeArguments.length === typeParameters.length) {
type = createTypeReference(<GenericType>type, map(node.typeArguments, getTypeFromTypeNodeOrHeritageClauseElement));
type = createTypeReference(<GenericType>type, map(node.typeArguments, getTypeFromTypeNode));
}
else {
error(node, Diagnostics.Generic_type_0_requires_1_type_argument_s, typeToString(type, /*enclosingDeclaration*/ undefined, TypeFormatFlags.WriteArrayAsGenericType), typeParameters.length);
@@ -3481,7 +3510,7 @@ module ts {
function getTypeFromArrayTypeNode(node: ArrayTypeNode): Type {
let links = getNodeLinks(node);
if (!links.resolvedType) {
links.resolvedType = createArrayType(getTypeFromTypeNodeOrHeritageClauseElement(node.elementType));
links.resolvedType = createArrayType(getTypeFromTypeNode(node.elementType));
}
return links.resolvedType;
}
@@ -3499,7 +3528,7 @@ module ts {
function getTypeFromTupleTypeNode(node: TupleTypeNode): Type {
let links = getNodeLinks(node);
if (!links.resolvedType) {
links.resolvedType = createTupleType(map(node.elementTypes, getTypeFromTypeNodeOrHeritageClauseElement));
links.resolvedType = createTupleType(map(node.elementTypes, getTypeFromTypeNode));
}
return links.resolvedType;
}
@@ -3608,7 +3637,7 @@ module ts {
function getTypeFromUnionTypeNode(node: UnionTypeNode): Type {
let links = getNodeLinks(node);
if (!links.resolvedType) {
links.resolvedType = getUnionType(map(node.types, getTypeFromTypeNodeOrHeritageClauseElement), /*noSubtypeReduction*/ true);
links.resolvedType = getUnionType(map(node.types, getTypeFromTypeNode), /*noSubtypeReduction*/ true);
}
return links.resolvedType;
}
@@ -3622,7 +3651,7 @@ module ts {
return links.resolvedType;
}
function getStringLiteralType(node: LiteralExpression): StringLiteralType {
function getStringLiteralType(node: StringLiteral): StringLiteralType {
if (hasProperty(stringLiteralTypes, node.text)) {
return stringLiteralTypes[node.text];
}
@@ -3632,7 +3661,7 @@ module ts {
return type;
}
function getTypeFromStringLiteral(node: LiteralExpression): Type {
function getTypeFromStringLiteral(node: StringLiteral): Type {
let links = getNodeLinks(node);
if (!links.resolvedType) {
links.resolvedType = getStringLiteralType(node);
@@ -3640,7 +3669,7 @@ module ts {
return links.resolvedType;
}
function getTypeFromTypeNodeOrHeritageClauseElement(node: TypeNode | LiteralExpression | HeritageClauseElement): Type {
function getTypeFromTypeNode(node: TypeNode): Type {
switch (node.kind) {
case SyntaxKind.AnyKeyword:
return anyType;
@@ -3655,7 +3684,7 @@ module ts {
case SyntaxKind.VoidKeyword:
return voidType;
case SyntaxKind.StringLiteral:
return getTypeFromStringLiteral(<LiteralExpression>node);
return getTypeFromStringLiteral(<StringLiteral>node);
case SyntaxKind.TypeReference:
return getTypeFromTypeReference(<TypeReferenceNode>node);
case SyntaxKind.HeritageClauseElement:
@@ -3669,7 +3698,7 @@ module ts {
case SyntaxKind.UnionType:
return getTypeFromUnionTypeNode(<UnionTypeNode>node);
case SyntaxKind.ParenthesizedType:
return getTypeFromTypeNodeOrHeritageClauseElement((<ParenthesizedTypeNode>node).type);
return getTypeFromTypeNode((<ParenthesizedTypeNode>node).type);
case SyntaxKind.FunctionType:
case SyntaxKind.ConstructorType:
case SyntaxKind.TypeLiteral:
@@ -5550,7 +5579,8 @@ module ts {
let baseClass: Type;
if (enclosingClass && getClassExtendsHeritageClauseElement(enclosingClass)) {
let classType = <InterfaceType>getDeclaredTypeOfSymbol(getSymbolOfNode(enclosingClass));
baseClass = classType.baseTypes.length && classType.baseTypes[0];
let baseTypes = getBaseTypes(classType);
baseClass = baseTypes.length && baseTypes[0];
}
if (!baseClass) {
@@ -5680,7 +5710,7 @@ module ts {
let declaration = <VariableLikeDeclaration>node.parent;
if (node === declaration.initializer) {
if (declaration.type) {
return getTypeFromTypeNodeOrHeritageClauseElement(declaration.type);
return getTypeFromTypeNode(declaration.type);
}
if (declaration.kind === SyntaxKind.Parameter) {
let type = getContextuallyTypedParameterType(<ParameterDeclaration>declaration);
@@ -5883,7 +5913,7 @@ module ts {
case SyntaxKind.NewExpression:
return getContextualTypeForArgument(<CallExpression>parent, node);
case SyntaxKind.TypeAssertionExpression:
return getTypeFromTypeNodeOrHeritageClauseElement((<TypeAssertion>parent).type);
return getTypeFromTypeNode((<TypeAssertion>parent).type);
case SyntaxKind.BinaryExpression:
return getContextualTypeForBinaryOperand(node);
case SyntaxKind.PropertyAssignment:
@@ -6131,9 +6161,7 @@ module ts {
}
else {
Debug.assert(memberDecl.kind === SyntaxKind.ShorthandPropertyAssignment);
type = memberDecl.name.kind === SyntaxKind.ComputedPropertyName
? unknownType
: checkExpression(<Identifier>memberDecl.name, contextualMapper);
type = checkExpression((<ShorthandPropertyAssignment>memberDecl).name, contextualMapper);
}
typeFlags |= type.flags;
let prop = <TransientSymbol>createSymbol(SymbolFlags.Property | SymbolFlags.Transient | member.flags, member.name);
@@ -6705,7 +6733,7 @@ module ts {
let typeArgumentsAreAssignable = true;
for (let i = 0; i < typeParameters.length; i++) {
let typeArgNode = typeArguments[i];
let typeArgument = getTypeFromTypeNodeOrHeritageClauseElement(typeArgNode);
let typeArgument = getTypeFromTypeNode(typeArgNode);
// Do not push on this array! It has a preallocated length
typeArgumentResultTypes[i] = typeArgument;
if (typeArgumentsAreAssignable /* so far */) {
@@ -6727,9 +6755,12 @@ module ts {
let paramType = getTypeAtPosition(signature, i);
// A tagged template expression provides a special first argument, and string literals get string literal types
// unless we're reporting errors
let argType = i === 0 && node.kind === SyntaxKind.TaggedTemplateExpression ? globalTemplateStringsArrayType :
arg.kind === SyntaxKind.StringLiteral && !reportErrors ? getStringLiteralType(<LiteralExpression>arg) :
checkExpressionWithContextualType(arg, paramType, excludeArgument && excludeArgument[i] ? identityMapper : undefined);
let argType = i === 0 && node.kind === SyntaxKind.TaggedTemplateExpression
? globalTemplateStringsArrayType
: arg.kind === SyntaxKind.StringLiteral && !reportErrors
? getStringLiteralType(<StringLiteral>arg)
: checkExpressionWithContextualType(arg, paramType, excludeArgument && excludeArgument[i] ? identityMapper : undefined);
// Use argument expression as error location when reporting errors
if (!checkTypeRelatedTo(argType, paramType, relation, reportErrors ? arg : undefined,
Diagnostics.Argument_of_type_0_is_not_assignable_to_parameter_of_type_1)) {
@@ -7187,7 +7218,7 @@ module ts {
function checkTypeAssertion(node: TypeAssertion): Type {
let exprType = checkExpression(node.expression);
let targetType = getTypeFromTypeNodeOrHeritageClauseElement(node.type);
let targetType = getTypeFromTypeNode(node.type);
if (produceDiagnostics && targetType !== unknownType) {
let widenedType = getWidenedType(exprType);
if (!(isTypeAssignableTo(targetType, widenedType))) {
@@ -7361,7 +7392,7 @@ module ts {
function checkFunctionExpressionOrObjectLiteralMethodBody(node: FunctionExpression | MethodDeclaration) {
Debug.assert(node.kind !== SyntaxKind.MethodDeclaration || isObjectLiteralMethod(node));
if (node.type && !node.asteriskToken) {
checkIfNonVoidFunctionHasReturnExpressionsOrSingleThrowStatment(node, getTypeFromTypeNodeOrHeritageClauseElement(node.type));
checkIfNonVoidFunctionHasReturnExpressionsOrSingleThrowStatment(node, getTypeFromTypeNode(node.type));
}
if (node.body) {
@@ -7371,7 +7402,7 @@ module ts {
else {
let exprType = checkExpression(<Expression>node.body);
if (node.type) {
checkTypeAssignableTo(exprType, getTypeFromTypeNodeOrHeritageClauseElement(node.type), node.body, /*headMessage*/ undefined);
checkTypeAssignableTo(exprType, getTypeFromTypeNode(node.type), node.body, /*headMessage*/ undefined);
}
checkFunctionExpressionBodies(node.body);
}
@@ -8020,7 +8051,7 @@ module ts {
function checkNumericLiteral(node: LiteralExpression): Type {
// Grammar checking
checkGrammarNumbericLiteral(node);
checkGrammarNumericLiteral(node);
return numberType;
}
@@ -8800,12 +8831,12 @@ module ts {
}
/** Checks a type reference node as an expression. */
function checkTypeNodeAsExpression(node: TypeNode | LiteralExpression) {
function checkTypeNodeAsExpression(node: TypeNode) {
// When we are emitting type metadata for decorators, we need to try to check the type
// as if it were an expression so that we can emit the type in a value position when we
// serialize the type metadata.
if (node && node.kind === SyntaxKind.TypeReference) {
let type = getTypeFromTypeNodeOrHeritageClauseElement(node);
let type = getTypeFromTypeNode(node);
let shouldCheckIfUnknownType = type === unknownType && compilerOptions.separateCompilation;
if (!type || (!shouldCheckIfUnknownType && type.flags & (TypeFlags.Intrinsic | TypeFlags.NumberLike | TypeFlags.StringLike))) {
return;
@@ -8825,7 +8856,8 @@ module ts {
case SyntaxKind.PropertyDeclaration:
checkTypeNodeAsExpression((<PropertyDeclaration>node).type);
break;
case SyntaxKind.Parameter: checkTypeNodeAsExpression((<ParameterDeclaration>node).type);
case SyntaxKind.Parameter:
checkTypeNodeAsExpression((<ParameterDeclaration>node).type);
break;
case SyntaxKind.MethodDeclaration:
checkTypeNodeAsExpression((<MethodDeclaration>node).type);
@@ -8941,7 +8973,7 @@ module ts {
checkSourceElement(node.body);
if (node.type && !isAccessor(node.kind) && !node.asteriskToken) {
checkIfNonVoidFunctionHasReturnExpressionsOrSingleThrowStatment(node, getTypeFromTypeNodeOrHeritageClauseElement(node.type));
checkIfNonVoidFunctionHasReturnExpressionsOrSingleThrowStatment(node, getTypeFromTypeNode(node.type));
}
// Report an implicit any error if there is no body, no explicit return type, and node is not a private method
@@ -9829,7 +9861,7 @@ module ts {
errorNode = declaredNumberIndexer || declaredStringIndexer;
// condition 'errorNode === undefined' may appear if types does not declare nor string neither number indexer
if (!errorNode && (type.flags & TypeFlags.Interface)) {
let someBaseTypeHasBothIndexers = forEach((<InterfaceType>type).baseTypes, base => getIndexTypeOfType(base, IndexKind.String) && getIndexTypeOfType(base, IndexKind.Number));
let someBaseTypeHasBothIndexers = forEach(getBaseTypes(<InterfaceType>type), base => getIndexTypeOfType(base, IndexKind.String) && getIndexTypeOfType(base, IndexKind.Number));
errorNode = someBaseTypeHasBothIndexers ? undefined : type.symbol.declarations[0];
}
}
@@ -9869,7 +9901,7 @@ module ts {
// for interfaces property and indexer might be inherited from different bases
// check if any base class already has both property and indexer.
// check should be performed only if 'type' is the first type that brings property\indexer together
let someBaseClassHasBothPropertyAndIndexer = forEach((<InterfaceType>containingType).baseTypes, base => getPropertyOfObjectType(base, prop.name) && getIndexTypeOfType(base, indexKind));
let someBaseClassHasBothPropertyAndIndexer = forEach(getBaseTypes(<InterfaceType>containingType), base => getPropertyOfObjectType(base, prop.name) && getIndexTypeOfType(base, indexKind));
errorNode = someBaseClassHasBothPropertyAndIndexer ? undefined : containingType.symbol.declarations[0];
}
@@ -9953,9 +9985,10 @@ module ts {
emitExtends = emitExtends || !isInAmbientContext(node);
checkHeritageClauseElement(baseTypeNode);
}
if (type.baseTypes.length) {
let baseTypes = getBaseTypes(type);
if (baseTypes.length) {
if (produceDiagnostics) {
let baseType = type.baseTypes[0];
let baseType = baseTypes[0];
checkTypeAssignableTo(type, baseType, node.name || node, Diagnostics.Class_0_incorrectly_extends_base_class_1);
let staticBaseType = getTypeOfSymbol(baseType.symbol);
checkTypeAssignableTo(staticType, getTypeWithoutConstructors(staticBaseType), node.name || node,
@@ -9969,7 +10002,7 @@ module ts {
}
}
if (type.baseTypes.length || (baseTypeNode && compilerOptions.separateCompilation)) {
if (baseTypes.length || (baseTypeNode && compilerOptions.separateCompilation)) {
// Check that base type can be evaluated as expression
checkExpressionOrQualifiedName(baseTypeNode.expression);
}
@@ -10105,7 +10138,7 @@ module ts {
if (!tp1.constraint || !tp2.constraint) {
return false;
}
if (!isTypeIdenticalTo(getTypeFromTypeNodeOrHeritageClauseElement(tp1.constraint), getTypeFromTypeNodeOrHeritageClauseElement(tp2.constraint))) {
if (!isTypeIdenticalTo(getTypeFromTypeNode(tp1.constraint), getTypeFromTypeNode(tp2.constraint))) {
return false;
}
}
@@ -10113,7 +10146,8 @@ module ts {
}
function checkInheritedPropertiesAreIdentical(type: InterfaceType, typeNode: Node): boolean {
if (!type.baseTypes.length || type.baseTypes.length === 1) {
let baseTypes = getBaseTypes(type);
if (baseTypes.length < 2) {
return true;
}
@@ -10121,7 +10155,7 @@ module ts {
forEach(type.declaredProperties, p => { seen[p.name] = { prop: p, containingType: type }; });
let ok = true;
for (let base of type.baseTypes) {
for (let base of baseTypes) {
let properties = getPropertiesOfObjectType(base);
for (let prop of properties) {
if (!hasProperty(seen, prop.name)) {
@@ -10169,7 +10203,7 @@ module ts {
let type = <InterfaceType>getDeclaredTypeOfSymbol(symbol);
// run subsequent checks only if first set succeeded
if (checkInheritedPropertiesAreIdentical(type, node.name)) {
forEach(type.baseTypes, baseType => {
forEach(getBaseTypes(type), baseType => {
checkTypeAssignableTo(type, baseType, node.name, Diagnostics.Interface_0_incorrectly_extends_interface_1);
});
checkIndexConstraints(type);
@@ -11136,7 +11170,7 @@ module ts {
return node.parent && node.parent.kind === SyntaxKind.HeritageClauseElement;
}
function isTypeNodeOrHeritageClauseElement(node: Node): boolean {
function isTypeNode(node: Node): boolean {
if (SyntaxKind.FirstTypeNode <= node.kind && node.kind <= SyntaxKind.LastTypeNode) {
return true;
}
@@ -11385,8 +11419,8 @@ module ts {
return unknownType;
}
if (isTypeNodeOrHeritageClauseElement(node)) {
return getTypeFromTypeNodeOrHeritageClauseElement(<TypeNode | HeritageClauseElement>node);
if (isTypeNode(node)) {
return getTypeFromTypeNode(<TypeNode>node);
}
if (isExpression(node)) {
@@ -11480,7 +11514,14 @@ module ts {
let node = getDeclarationOfAliasSymbol(symbol);
if (node) {
if (node.kind === SyntaxKind.ImportClause) {
return getGeneratedNameForNode(<ImportDeclaration>node.parent) + ".default";
let defaultKeyword: string;
if (languageVersion === ScriptTarget.ES3) {
defaultKeyword = "[\"default\"]";
} else {
defaultKeyword = ".default";
}
return getGeneratedNameForNode(<ImportDeclaration>node.parent) + defaultKeyword;
}
if (node.kind === SyntaxKind.ImportSpecifier) {
let moduleName = getGeneratedNameForNode(<ImportDeclaration>node.parent.parent.parent);
@@ -11974,8 +12015,8 @@ module ts {
}
// GRAMMAR CHECKING
function isReservedwordInStrictMode(node: Identifier): boolean {
// Check that originalKeywordKind is less than LastFurtureReservedWord to see if an Identifier is a strict-mode reserved word
function isReservedWordInStrictMode(node: Identifier): boolean {
// Check that originalKeywordKind is less than LastFutureReservedWord to see if an Identifier is a strict-mode reserved word
return (node.parserContextFlags & ParserContextFlags.StrictMode) &&
(node.originalKeywordKind >= SyntaxKind.FirstFutureReservedWord && node.originalKeywordKind <= SyntaxKind.LastFutureReservedWord);
}
@@ -12020,7 +12061,7 @@ module ts {
function checkGrammarDeclarationNameInStrictMode(node: Declaration): boolean {
let name = node.name;
if (name && name.kind === SyntaxKind.Identifier && isReservedwordInStrictMode(<Identifier>name)) {
if (name && name.kind === SyntaxKind.Identifier && isReservedWordInStrictMode(<Identifier>name)) {
let nameText = declarationNameToString(name);
switch (node.kind) {
case SyntaxKind.Parameter:
@@ -12096,7 +12137,7 @@ module ts {
// The function takes an identifier itself or an expression which has SyntaxKind.Identifier.
function checkGrammarIdentifierInStrictMode(node: Expression | Identifier, nameText?: string): boolean {
if (node && node.kind === SyntaxKind.Identifier && isReservedwordInStrictMode(<Identifier>node)) {
if (node && node.kind === SyntaxKind.Identifier && isReservedWordInStrictMode(<Identifier>node)) {
if (!nameText) {
nameText = declarationNameToString(<Identifier>node);
}
@@ -12111,7 +12152,7 @@ module ts {
// The function takes an identifier when uses as a typeName in TypeReferenceNode
function checkGrammarTypeNameInStrictMode(node: Identifier): boolean {
if (node && node.kind === SyntaxKind.Identifier && isReservedwordInStrictMode(<Identifier>node)) {
if (node && node.kind === SyntaxKind.Identifier && isReservedWordInStrictMode(<Identifier>node)) {
let nameText = declarationNameToString(<Identifier>node);
// TODO (yuisu): Fix when module is a strict mode
@@ -12563,7 +12604,7 @@ module ts {
// Grammar checking for computedPropertName and shorthandPropertyAssignment
checkGrammarForInvalidQuestionMark(prop,(<PropertyAssignment>prop).questionToken, Diagnostics.An_object_member_cannot_be_declared_optional);
if (name.kind === SyntaxKind.NumericLiteral) {
checkGrammarNumbericLiteral(<Identifier>name);
checkGrammarNumericLiteral(<Identifier>name);
}
currentKind = Property;
}
@@ -13115,7 +13156,7 @@ module ts {
}
}
function checkGrammarNumbericLiteral(node: Identifier): boolean {
function checkGrammarNumericLiteral(node: Identifier): boolean {
// Grammar checking
if (node.flags & NodeFlags.OctalLiteral) {
if (node.parserContextFlags & ParserContextFlags.StrictMode) {
+4 -4
View File
@@ -258,7 +258,7 @@ module ts {
handleSymbolAccessibilityError(resolver.isSymbolAccessible(symbol, enclosingDeclaration, meaning));
}
function writeTypeOfDeclaration(declaration: AccessorDeclaration | VariableLikeDeclaration, type: TypeNode | StringLiteralExpression, getSymbolAccessibilityDiagnostic: GetSymbolAccessibilityDiagnostic) {
function writeTypeOfDeclaration(declaration: AccessorDeclaration | VariableLikeDeclaration, type: TypeNode, getSymbolAccessibilityDiagnostic: GetSymbolAccessibilityDiagnostic) {
writer.getSymbolAccessibilityDiagnostic = getSymbolAccessibilityDiagnostic;
write(": ");
if (type) {
@@ -314,12 +314,12 @@ module ts {
}
}
function emitTypeWithNewGetSymbolAccessibilityDiagnostic(type: TypeNode | EntityName | HeritageClauseElement, getSymbolAccessibilityDiagnostic: GetSymbolAccessibilityDiagnostic) {
function emitTypeWithNewGetSymbolAccessibilityDiagnostic(type: TypeNode | EntityName, getSymbolAccessibilityDiagnostic: GetSymbolAccessibilityDiagnostic) {
writer.getSymbolAccessibilityDiagnostic = getSymbolAccessibilityDiagnostic;
emitType(type);
}
function emitType(type: TypeNode | StringLiteralExpression | Identifier | QualifiedName | HeritageClauseElement) {
function emitType(type: TypeNode | Identifier | QualifiedName) {
switch (type.kind) {
case SyntaxKind.AnyKeyword:
case SyntaxKind.StringKeyword:
@@ -1126,7 +1126,7 @@ module ts {
writeLine();
}
function getTypeAnnotationFromAccessor(accessor: AccessorDeclaration): TypeNode | StringLiteralExpression {
function getTypeAnnotationFromAccessor(accessor: AccessorDeclaration): TypeNode {
if (accessor) {
return accessor.kind === SyntaxKind.GetAccessor
? accessor.type // Getter - return type
+75 -41
View File
@@ -2469,7 +2469,11 @@ var __param = this.__param || function(index, decorator) { return function (targ
writeLine();
emitStart(node);
if (node.flags & NodeFlags.Default) {
write("exports.default");
if (languageVersion === ScriptTarget.ES3) {
write("exports[\"default\"]");
} else {
write("exports.default");
}
}
else {
emitModuleMemberName(node);
@@ -4560,7 +4564,11 @@ var __param = this.__param || function(index, decorator) { return function (targ
writeLine();
emitStart(node);
emitContainingModuleName(node);
write(".default = ");
if (languageVersion === ScriptTarget.ES3) {
write("[\"default\"] = ");
} else {
write(".default = ");
}
emit(node.expression);
write(";");
emitEnd(node);
@@ -4621,19 +4629,6 @@ var __param = this.__param || function(index, decorator) { return function (targ
}
}
function sortAMDModules(amdModules: {name: string; path: string}[]) {
// AMD modules with declared variable names go first
return amdModules.sort((moduleA, moduleB) => {
if (moduleA.name === moduleB.name) {
return 0;
} else if (!moduleA.name) {
return 1;
} else {
return -1;
}
});
}
function emitExportStarHelper() {
if (hasExportStars) {
writeLine();
@@ -4649,44 +4644,83 @@ var __param = this.__param || function(index, decorator) { return function (targ
function emitAMDModule(node: SourceFile, startIndex: number) {
collectExternalModuleInfo(node);
// An AMD define function has the following shape:
// define(id?, dependencies?, factory);
//
// This has the shape of
// define(name, ["module1", "module2"], function (module1Alias) {
// The location of the alias in the parameter list in the factory function needs to
// match the position of the module name in the dependency list.
//
// To ensure this is true in cases of modules with no aliases, e.g.:
// `import "module"` or `<amd-dependency path= "a.css" />`
// we need to add modules without alias names to the end of the dependencies list
let aliasedModuleNames: string[] = []; // names of modules with corresponding parameter in the
// factory function.
let unaliasedModuleNames: string[] = []; // names of modules with no corresponding parameters in
// factory function.
let importAliasNames: string[] = []; // names of the parameters in the factory function; these
// paramters need to match the indexes of the corresponding
// module names in aliasedModuleNames.
// Fill in amd-dependency tags
for (let amdDependency of node.amdDependencies) {
if (amdDependency.name) {
aliasedModuleNames.push("\"" + amdDependency.path + "\"");
importAliasNames.push(amdDependency.name);
}
else {
unaliasedModuleNames.push("\"" + amdDependency.path + "\"");
}
}
for (let importNode of externalImports) {
// Find the name of the external module
let externalModuleName = "";
let moduleName = getExternalModuleName(importNode);
if (moduleName.kind === SyntaxKind.StringLiteral) {
externalModuleName = getLiteralText(<LiteralExpression>moduleName);
}
// Find the name of the module alais, if there is one
let importAliasName: string;
let namespaceDeclaration = getNamespaceDeclarationNode(importNode);
if (namespaceDeclaration && !isDefaultImport(importNode)) {
importAliasName = getSourceTextOfNodeFromSourceFile(currentSourceFile, namespaceDeclaration.name);
}
else {
importAliasName = getGeneratedNameForNode(<ImportDeclaration | ExportDeclaration>importNode);
}
if (importAliasName) {
aliasedModuleNames.push(externalModuleName);
importAliasNames.push(importAliasName);
}
else {
unaliasedModuleNames.push(externalModuleName);
}
}
writeLine();
write("define(");
sortAMDModules(node.amdDependencies);
if (node.amdModuleName) {
write("\"" + node.amdModuleName + "\", ");
}
write("[\"require\", \"exports\"");
for (let importNode of externalImports) {
if (aliasedModuleNames.length) {
write(", ");
let moduleName = getExternalModuleName(importNode);
if (moduleName.kind === SyntaxKind.StringLiteral) {
emitLiteral(<LiteralExpression>moduleName);
}
else {
write("\"\"");
}
write(aliasedModuleNames.join(", "));
}
for (let amdDependency of node.amdDependencies) {
let text = "\"" + amdDependency.path + "\"";
if (unaliasedModuleNames.length) {
write(", ");
write(text);
write(unaliasedModuleNames.join(", "));
}
write("], function (require, exports");
for (let importNode of externalImports) {
if (importAliasNames.length) {
write(", ");
let namespaceDeclaration = getNamespaceDeclarationNode(importNode);
if (namespaceDeclaration && !isDefaultImport(importNode)) {
emit(namespaceDeclaration.name);
}
else {
write(getGeneratedNameForNode(<ImportDeclaration | ExportDeclaration>importNode));
}
}
for (let amdDependency of node.amdDependencies) {
if (amdDependency.name) {
write(", ");
write(amdDependency.name);
}
write(importAliasNames.join(", "));
}
write(") {");
increaseIndent();
+7 -6
View File
@@ -1803,7 +1803,7 @@ module ts {
function parseParameterType(): TypeNode {
if (parseOptional(SyntaxKind.ColonToken)) {
return token === SyntaxKind.StringLiteral
? <StringLiteralTypeNode>parseLiteralNode(/*internName:*/ true)
? <StringLiteral>parseLiteralNode(/*internName:*/ true)
: parseType();
}
@@ -3859,13 +3859,14 @@ module ts {
function parseObjectBindingElement(): BindingElement {
let node = <BindingElement>createNode(SyntaxKind.BindingElement);
// TODO(andersh): Handle computed properties
let id = parsePropertyName();
if (id.kind === SyntaxKind.Identifier && token !== SyntaxKind.ColonToken) {
node.name = <Identifier>id;
let tokenIsIdentifier = isIdentifier();
let propertyName = parsePropertyName();
if (tokenIsIdentifier && token !== SyntaxKind.ColonToken) {
node.name = <Identifier>propertyName;
}
else {
parseExpected(SyntaxKind.ColonToken);
node.propertyName = <Identifier>id;
node.propertyName = <Identifier>propertyName;
node.name = parseIdentifierOrPattern();
}
node.initializer = parseInitializer(/*inParameter*/ false);
@@ -5416,4 +5417,4 @@ module ts {
Value = -1
}
}
}
}
+34 -31
View File
@@ -24,7 +24,9 @@ module ts {
reScanSlashToken(): SyntaxKind;
reScanTemplateToken(): SyntaxKind;
scan(): SyntaxKind;
setText(text: string): void;
// Sets the text for the scanner to scan. An optional subrange starting point and length
// can be provided to have the scanner only scan a portion of the text.
setText(text: string, start?: number, length?: number): void;
setOnError(onError: ErrorCallback): void;
setScriptTarget(scriptTarget: ScriptTarget): void;
setTextPos(textPos: number): void;
@@ -597,11 +599,11 @@ module ts {
ch > CharacterCodes.maxAsciiCharacter && isUnicodeIdentifierPart(ch, languageVersion);
}
/* @internal */
export function createScanner(languageVersion: ScriptTarget, skipTrivia: boolean, text?: string, onError?: ErrorCallback): Scanner {
// Creates a scanner over a (possibly unspecified) range of a piece of text.
/* @internal */
export function createScanner(languageVersion: ScriptTarget, skipTrivia: boolean, text?: string, onError?: ErrorCallback, start?: number, length?: number): Scanner {
let pos: number; // Current position (end position of text of current token)
let len: number; // Length of text
let end: number; // end of text
let startPos: number; // Start position of whitespace before current token
let tokenPos: number; // Start position of text of current token
let token: SyntaxKind;
@@ -610,7 +612,7 @@ module ts {
let hasExtendedUnicodeEscape: boolean;
let tokenIsUnterminated: boolean;
setText(text);
setText(text, start, length);
return {
getStartPos: () => startPos,
@@ -732,7 +734,7 @@ module ts {
let result = "";
let start = pos;
while (true) {
if (pos >= len) {
if (pos >= end) {
result += text.substring(start, pos);
tokenIsUnterminated = true;
error(Diagnostics.Unterminated_string_literal);
@@ -774,7 +776,7 @@ module ts {
let resultingToken: SyntaxKind;
while (true) {
if (pos >= len) {
if (pos >= end) {
contents += text.substring(start, pos);
tokenIsUnterminated = true;
error(Diagnostics.Unterminated_template_literal);
@@ -793,7 +795,7 @@ module ts {
}
// '${'
if (currChar === CharacterCodes.$ && pos + 1 < len && text.charCodeAt(pos + 1) === CharacterCodes.openBrace) {
if (currChar === CharacterCodes.$ && pos + 1 < end && text.charCodeAt(pos + 1) === CharacterCodes.openBrace) {
contents += text.substring(start, pos);
pos += 2;
resultingToken = startedWithBacktick ? SyntaxKind.TemplateHead : SyntaxKind.TemplateMiddle;
@@ -814,7 +816,7 @@ module ts {
contents += text.substring(start, pos);
pos++;
if (pos < len && text.charCodeAt(pos) === CharacterCodes.lineFeed) {
if (pos < end && text.charCodeAt(pos) === CharacterCodes.lineFeed) {
pos++;
}
@@ -834,7 +836,7 @@ module ts {
function scanEscapeSequence(): string {
pos++;
if (pos >= len) {
if (pos >= end) {
error(Diagnostics.Unexpected_end_of_text);
return "";
}
@@ -860,7 +862,7 @@ module ts {
return "\"";
case CharacterCodes.u:
// '\u{DDDDDDDD}'
if (pos < len && text.charCodeAt(pos) === CharacterCodes.openBrace) {
if (pos < end && text.charCodeAt(pos) === CharacterCodes.openBrace) {
hasExtendedUnicodeEscape = true;
pos++;
return scanExtendedUnicodeEscape();
@@ -876,7 +878,7 @@ module ts {
// when encountering a LineContinuation (i.e. a backslash and a line terminator sequence),
// the line terminator is interpreted to be "the empty code unit sequence".
case CharacterCodes.carriageReturn:
if (pos < len && text.charCodeAt(pos) === CharacterCodes.lineFeed) {
if (pos < end && text.charCodeAt(pos) === CharacterCodes.lineFeed) {
pos++;
}
// fall through
@@ -915,7 +917,7 @@ module ts {
isInvalidExtendedEscape = true;
}
if (pos >= len) {
if (pos >= end) {
error(Diagnostics.Unexpected_end_of_text);
isInvalidExtendedEscape = true;
}
@@ -952,7 +954,7 @@ module ts {
// Current character is known to be a backslash. Check for Unicode escape of the form '\uXXXX'
// and return code point value if valid Unicode escape is found. Otherwise return -1.
function peekUnicodeEscape(): number {
if (pos + 5 < len && text.charCodeAt(pos + 1) === CharacterCodes.u) {
if (pos + 5 < end && text.charCodeAt(pos + 1) === CharacterCodes.u) {
let start = pos;
pos += 2;
let value = scanExactNumberOfHexDigits(4);
@@ -965,7 +967,7 @@ module ts {
function scanIdentifierParts(): string {
let result = "";
let start = pos;
while (pos < len) {
while (pos < end) {
let ch = text.charCodeAt(pos);
if (isIdentifierPart(ch)) {
pos++;
@@ -1032,7 +1034,7 @@ module ts {
tokenIsUnterminated = false;
while (true) {
tokenPos = pos;
if (pos >= len) {
if (pos >= end) {
return token = SyntaxKind.EndOfFileToken;
}
let ch = text.charCodeAt(pos);
@@ -1045,7 +1047,7 @@ module ts {
continue;
}
else {
if (ch === CharacterCodes.carriageReturn && pos + 1 < len && text.charCodeAt(pos + 1) === CharacterCodes.lineFeed) {
if (ch === CharacterCodes.carriageReturn && pos + 1 < end && text.charCodeAt(pos + 1) === CharacterCodes.lineFeed) {
// consume both CR and LF
pos += 2;
}
@@ -1063,7 +1065,7 @@ module ts {
continue;
}
else {
while (pos < len && isWhiteSpace(text.charCodeAt(pos))) {
while (pos < end && isWhiteSpace(text.charCodeAt(pos))) {
pos++;
}
return token = SyntaxKind.WhitespaceTrivia;
@@ -1136,7 +1138,7 @@ module ts {
if (text.charCodeAt(pos + 1) === CharacterCodes.slash) {
pos += 2;
while (pos < len) {
while (pos < end) {
if (isLineBreak(text.charCodeAt(pos))) {
break;
}
@@ -1156,7 +1158,7 @@ module ts {
pos += 2;
let commentClosed = false;
while (pos < len) {
while (pos < end) {
let ch = text.charCodeAt(pos);
if (ch === CharacterCodes.asterisk && text.charCodeAt(pos + 1) === CharacterCodes.slash) {
@@ -1191,7 +1193,7 @@ module ts {
return pos++, token = SyntaxKind.SlashToken;
case CharacterCodes._0:
if (pos + 2 < len && (text.charCodeAt(pos + 1) === CharacterCodes.X || text.charCodeAt(pos + 1) === CharacterCodes.x)) {
if (pos + 2 < end && (text.charCodeAt(pos + 1) === CharacterCodes.X || text.charCodeAt(pos + 1) === CharacterCodes.x)) {
pos += 2;
let value = scanMinimumNumberOfHexDigits(1);
if (value < 0) {
@@ -1201,7 +1203,7 @@ module ts {
tokenValue = "" + value;
return token = SyntaxKind.NumericLiteral;
}
else if (pos + 2 < len && (text.charCodeAt(pos + 1) === CharacterCodes.B || text.charCodeAt(pos + 1) === CharacterCodes.b)) {
else if (pos + 2 < end && (text.charCodeAt(pos + 1) === CharacterCodes.B || text.charCodeAt(pos + 1) === CharacterCodes.b)) {
pos += 2;
let value = scanBinaryOrOctalDigits(/* base */ 2);
if (value < 0) {
@@ -1211,7 +1213,7 @@ module ts {
tokenValue = "" + value;
return token = SyntaxKind.NumericLiteral;
}
else if (pos + 2 < len && (text.charCodeAt(pos + 1) === CharacterCodes.O || text.charCodeAt(pos + 1) === CharacterCodes.o)) {
else if (pos + 2 < end && (text.charCodeAt(pos + 1) === CharacterCodes.O || text.charCodeAt(pos + 1) === CharacterCodes.o)) {
pos += 2;
let value = scanBinaryOrOctalDigits(/* base */ 8);
if (value < 0) {
@@ -1222,7 +1224,7 @@ module ts {
return token = SyntaxKind.NumericLiteral;
}
// Try to parse as an octal
if (pos + 1 < len && isOctalDigit(text.charCodeAt(pos + 1))) {
if (pos + 1 < end && isOctalDigit(text.charCodeAt(pos + 1))) {
tokenValue = "" + scanOctalDigits();
return token = SyntaxKind.NumericLiteral;
}
@@ -1337,7 +1339,7 @@ module ts {
default:
if (isIdentifierStart(ch)) {
pos++;
while (pos < len && isIdentifierPart(ch = text.charCodeAt(pos))) pos++;
while (pos < end && isIdentifierPart(ch = text.charCodeAt(pos))) pos++;
tokenValue = text.substring(tokenPos, pos);
if (ch === CharacterCodes.backslash) {
tokenValue += scanIdentifierParts();
@@ -1388,7 +1390,7 @@ module ts {
while (true) {
// If we reach the end of a file, or hit a newline, then this is an unterminated
// regex. Report error and return what we have so far.
if (p >= len) {
if (p >= end) {
tokenIsUnterminated = true;
error(Diagnostics.Unterminated_regular_expression_literal)
break;
@@ -1424,7 +1426,7 @@ module ts {
p++;
}
while (p < len && isIdentifierPart(text.charCodeAt(p))) {
while (p < end && isIdentifierPart(text.charCodeAt(p))) {
p++;
}
pos = p;
@@ -1473,10 +1475,10 @@ module ts {
return speculationHelper(callback, /*isLookahead:*/ false);
}
function setText(newText: string) {
function setText(newText: string, start: number, length: number) {
text = newText || "";
len = text.length;
setTextPos(0);
end = length === undefined ? text.length : start + length;
setTextPos(start || 0);
}
function setOnError(errorCallback: ErrorCallback) {
@@ -1488,6 +1490,7 @@ module ts {
}
function setTextPos(textPos: number) {
Debug.assert(textPos >= 0);
pos = textPos;
startPos = textPos;
tokenPos = textPos;
+11 -8
View File
@@ -389,7 +389,7 @@ module ts {
export interface Identifier extends PrimaryExpression {
text: string; // Text of identifier (with escapes converted to characters)
originalKeywordKind?: SyntaxKind; // Original syntaxKind which get set so that we can report an error later
originalKeywordKind?: SyntaxKind; // Original syntaxKind which get set so that we can report an error later
}
export interface QualifiedName extends Node {
@@ -596,7 +596,11 @@ module ts {
type: TypeNode;
}
export interface StringLiteralTypeNode extends LiteralExpression, TypeNode { }
// Note that a StringLiteral AST node is both an Expression and a TypeNode. The latter is
// because string literals can appear in the type annotation of a parameter node.
export interface StringLiteral extends LiteralExpression, TypeNode {
_stringLiteralBrand: any;
}
// Note: 'brands' in our syntax nodes serve to give us a small amount of nominal typing.
// Consider 'Expression'. Without the brand, 'Expression' is actually no different
@@ -689,10 +693,6 @@ module ts {
hasExtendedUnicodeEscape?: boolean;
}
export interface StringLiteralExpression extends LiteralExpression {
_stringLiteralExpressionBrand: any;
}
export interface TemplateExpression extends PrimaryExpression {
head: LiteralExpression;
templateSpans: NodeArray<TemplateSpan>;
@@ -739,7 +739,7 @@ module ts {
arguments: NodeArray<Expression>;
}
export interface HeritageClauseElement extends Node {
export interface HeritageClauseElement extends TypeNode {
expression: LeftHandSideExpression;
typeArguments?: NodeArray<TypeNode>;
}
@@ -1485,7 +1485,6 @@ module ts {
// Class and interface types (TypeFlags.Class and TypeFlags.Interface)
export interface InterfaceType extends ObjectType {
typeParameters: TypeParameter[]; // Type parameters (undefined if non-generic)
baseTypes: ObjectType[]; // Base types
declaredProperties: Symbol[]; // Declared members
declaredCallSignatures: Signature[]; // Declared call signatures
declaredConstructSignatures: Signature[]; // Declared construct signatures
@@ -1493,6 +1492,10 @@ module ts {
declaredNumberIndexType: Type; // Declared numeric index type
}
export interface InterfaceTypeWithBaseTypes extends InterfaceType {
baseTypes: ObjectType[];
}
// Type references (TypeFlags.Reference)
export interface TypeReference extends ObjectType {
target: GenericType; // Type reference target
+2 -3
View File
@@ -274,8 +274,7 @@ module ts {
}
export function getSpanOfTokenAtPosition(sourceFile: SourceFile, pos: number): TextSpan {
let scanner = createScanner(sourceFile.languageVersion, /*skipTrivia*/ true, sourceFile.text);
scanner.setTextPos(pos);
let scanner = createScanner(sourceFile.languageVersion, /*skipTrivia*/ true, sourceFile.text, /*onError:*/ undefined, pos);
scanner.scan();
let start = scanner.getTokenPos();
return createTextSpanFromBounds(start, scanner.getTextPos());
@@ -1913,4 +1912,4 @@ module ts {
return createTextChangeRange(createTextSpanFromBounds(oldStartN, oldEndN), /*newLength:*/ newEndN - oldStartN);
}
}
}
+11835 -11071
View File
File diff suppressed because it is too large Load Diff
+1808 -296
View File
File diff suppressed because it is too large Load Diff
+765 -707
View File
File diff suppressed because it is too large Load Diff