mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
merge with extendsExpressions
This commit is contained in:
+247
-6
@@ -88,6 +88,12 @@ namespace ts {
|
||||
let container: Node;
|
||||
let blockScopeContainer: Node;
|
||||
let lastContainer: Node;
|
||||
|
||||
// If this file is an external module, then it is automatically in strict-mode according to
|
||||
// ES6. If it is not an external module, then we'll determine if it is in strict mode or
|
||||
// not depending on if we see "use strict" in certain places (or if we hit a class/namespace).
|
||||
let inStrictMode = !!file.externalModuleIndicator;
|
||||
|
||||
let symbolCount = 0;
|
||||
let Symbol = objectAllocator.getSymbolConstructor();
|
||||
let classifiableNames: Map<string> = {};
|
||||
@@ -531,6 +537,51 @@ namespace ts {
|
||||
typeLiteralSymbol.members = { [symbol.name]: symbol };
|
||||
}
|
||||
|
||||
function bindObjectLiteralExpression(node: ObjectLiteralExpression) {
|
||||
const enum ElementKind {
|
||||
Property = 1,
|
||||
Accessor = 2
|
||||
}
|
||||
|
||||
if (inStrictMode) {
|
||||
let seen: Map<ElementKind> = {};
|
||||
|
||||
for (let prop of node.properties) {
|
||||
if (prop.name.kind !== SyntaxKind.Identifier) {
|
||||
continue;
|
||||
}
|
||||
|
||||
let identifier = <Identifier>prop.name;
|
||||
|
||||
// ECMA-262 11.1.5 Object Initialiser
|
||||
// If previous is not undefined then throw a SyntaxError exception if any of the following conditions are true
|
||||
// a.This production is contained in strict code and IsDataDescriptor(previous) is true and
|
||||
// IsDataDescriptor(propId.descriptor) is true.
|
||||
// b.IsDataDescriptor(previous) is true and IsAccessorDescriptor(propId.descriptor) is true.
|
||||
// c.IsAccessorDescriptor(previous) is true and IsDataDescriptor(propId.descriptor) is true.
|
||||
// d.IsAccessorDescriptor(previous) is true and IsAccessorDescriptor(propId.descriptor) is true
|
||||
// and either both previous and propId.descriptor have[[Get]] fields or both previous and propId.descriptor have[[Set]] fields
|
||||
let currentKind = prop.kind === SyntaxKind.PropertyAssignment || prop.kind === SyntaxKind.ShorthandPropertyAssignment || prop.kind === SyntaxKind.MethodDeclaration
|
||||
? ElementKind.Property
|
||||
: ElementKind.Accessor;
|
||||
|
||||
let existingKind = seen[identifier.text];
|
||||
if (!existingKind) {
|
||||
seen[identifier.text] = currentKind;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (currentKind === ElementKind.Property && existingKind === ElementKind.Property) {
|
||||
let span = getErrorSpanForNode(file, identifier);
|
||||
file.bindDiagnostics.push(createFileDiagnostic(file, span.start, span.length,
|
||||
Diagnostics.An_object_literal_cannot_have_multiple_properties_with_the_same_name_in_strict_mode));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return bindAnonymousDeclaration(node, SymbolFlags.ObjectLiteral, "__object");
|
||||
}
|
||||
|
||||
function bindAnonymousDeclaration(node: Declaration, symbolFlags: SymbolFlags, name: string) {
|
||||
let symbol = createSymbol(symbolFlags, name);
|
||||
addDeclarationToSymbol(symbol, node, symbolFlags);
|
||||
@@ -563,20 +614,135 @@ namespace ts {
|
||||
// The binder visits every node in the syntax tree so it is a convenient place to perform a single localized
|
||||
// check for reserved words used as identifiers in strict mode code.
|
||||
function checkStrictModeIdentifier(node: Identifier) {
|
||||
if (node.parserContextFlags & ParserContextFlags.StrictMode &&
|
||||
if (inStrictMode &&
|
||||
node.originalKeywordKind >= SyntaxKind.FirstFutureReservedWord &&
|
||||
node.originalKeywordKind <= SyntaxKind.LastFutureReservedWord &&
|
||||
!isIdentifierName(node)) {
|
||||
|
||||
// Report error only if there are no parse errors in file
|
||||
if (!file.parseDiagnostics.length) {
|
||||
let message = getAncestor(node, SyntaxKind.ClassDeclaration) || getAncestor(node, SyntaxKind.ClassExpression) ?
|
||||
Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode_Class_definitions_are_automatically_in_strict_mode :
|
||||
Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode;
|
||||
file.bindDiagnostics.push(createDiagnosticForNode(node, message, declarationNameToString(node)));
|
||||
file.bindDiagnostics.push(createDiagnosticForNode(node,
|
||||
getStrictModeIdentifierMessage(node), declarationNameToString(node)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function getStrictModeIdentifierMessage(node: Node) {
|
||||
// Provide specialized messages to help the user understand why we think they're in
|
||||
// strict mode.
|
||||
if (getAncestor(node, SyntaxKind.ClassDeclaration) || getAncestor(node, SyntaxKind.ClassExpression)) {
|
||||
return Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode_Class_definitions_are_automatically_in_strict_mode;
|
||||
}
|
||||
|
||||
if (file.externalModuleIndicator) {
|
||||
return Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode_Modules_are_automatically_in_strict_mode;
|
||||
}
|
||||
|
||||
return Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode;
|
||||
}
|
||||
|
||||
function checkStrictModeBinaryExpression(node: BinaryExpression) {
|
||||
if (inStrictMode && isLeftHandSideExpression(node.left) && isAssignmentOperator(node.operatorToken.kind)) {
|
||||
// ECMA 262 (Annex C) The identifier eval or arguments may not appear as the LeftHandSideExpression of an
|
||||
// Assignment operator(11.13) or of a PostfixExpression(11.3)
|
||||
checkStrictModeEvalOrArguments(node, <Identifier>node.left);
|
||||
}
|
||||
}
|
||||
|
||||
function checkStrictModeCatchClause(node: CatchClause) {
|
||||
// It is a SyntaxError if a TryStatement with a Catch occurs within strict code and the Identifier of the
|
||||
// Catch production is eval or arguments
|
||||
if (inStrictMode && node.variableDeclaration) {
|
||||
checkStrictModeEvalOrArguments(node, node.variableDeclaration.name);
|
||||
}
|
||||
}
|
||||
|
||||
function checkStrictModeDeleteExpression(node: DeleteExpression) {
|
||||
// Grammar checking
|
||||
if (inStrictMode && node.expression.kind === SyntaxKind.Identifier) {
|
||||
// When a delete operator occurs within strict mode code, a SyntaxError is thrown if its
|
||||
// UnaryExpression is a direct reference to a variable, function argument, or function name
|
||||
let span = getErrorSpanForNode(file, node.expression);
|
||||
file.bindDiagnostics.push(createFileDiagnostic(file, span.start, span.length, Diagnostics.delete_cannot_be_called_on_an_identifier_in_strict_mode));
|
||||
}
|
||||
}
|
||||
|
||||
function isEvalOrArgumentsIdentifier(node: Node): boolean {
|
||||
return node.kind === SyntaxKind.Identifier &&
|
||||
((<Identifier>node).text === "eval" || (<Identifier>node).text === "arguments");
|
||||
}
|
||||
|
||||
function checkStrictModeEvalOrArguments(contextNode: Node, name: Node) {
|
||||
if (name && name.kind === SyntaxKind.Identifier) {
|
||||
let identifier = <Identifier>name;
|
||||
if (isEvalOrArgumentsIdentifier(identifier)) {
|
||||
// We check first if the name is inside class declaration or class expression; if so give explicit message
|
||||
// otherwise report generic error message.
|
||||
let span = getErrorSpanForNode(file, name);
|
||||
file.bindDiagnostics.push(createFileDiagnostic(file, span.start, span.length,
|
||||
getStrictModeEvalOrArgumentsMessage(contextNode), identifier.text));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function getStrictModeEvalOrArgumentsMessage(node: Node) {
|
||||
// Provide specialized messages to help the user understand why we think they're in
|
||||
// strict mode.
|
||||
if (getAncestor(node, SyntaxKind.ClassDeclaration) || getAncestor(node, SyntaxKind.ClassExpression)) {
|
||||
return Diagnostics.Invalid_use_of_0_Class_definitions_are_automatically_in_strict_mode;
|
||||
}
|
||||
|
||||
if (file.externalModuleIndicator) {
|
||||
return Diagnostics.Invalid_use_of_0_Modules_are_automatically_in_strict_mode;
|
||||
}
|
||||
|
||||
return Diagnostics.Invalid_use_of_0_in_strict_mode;
|
||||
}
|
||||
|
||||
function checkStrictModeFunctionName(node: FunctionLikeDeclaration) {
|
||||
if (inStrictMode) {
|
||||
// It is a SyntaxError if the identifier eval or arguments appears within a FormalParameterList of a strict mode FunctionDeclaration or FunctionExpression (13.1))
|
||||
checkStrictModeEvalOrArguments(node, node.name);
|
||||
}
|
||||
}
|
||||
|
||||
function checkStrictModeNumericLiteral(node: LiteralExpression) {
|
||||
if (inStrictMode && node.flags & NodeFlags.OctalLiteral) {
|
||||
file.bindDiagnostics.push(createDiagnosticForNode(node, Diagnostics.Octal_literals_are_not_allowed_in_strict_mode));
|
||||
}
|
||||
}
|
||||
|
||||
function checkStrictModePostfixUnaryExpression(node: PostfixUnaryExpression) {
|
||||
// Grammar checking
|
||||
// The identifier eval or arguments may not appear as the LeftHandSideExpression of an
|
||||
// Assignment operator(11.13) or of a PostfixExpression(11.3) or as the UnaryExpression
|
||||
// operated upon by a Prefix Increment(11.4.4) or a Prefix Decrement(11.4.5) operator.
|
||||
if (inStrictMode) {
|
||||
checkStrictModeEvalOrArguments(node, <Identifier>node.operand);
|
||||
}
|
||||
}
|
||||
|
||||
function checkStrictModePrefixUnaryExpression(node: PrefixUnaryExpression) {
|
||||
// Grammar checking
|
||||
if (inStrictMode) {
|
||||
if (node.operator === SyntaxKind.PlusPlusToken || node.operator === SyntaxKind.MinusMinusToken) {
|
||||
checkStrictModeEvalOrArguments(node, <Identifier>node.operand);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function checkStrictModeWithStatement(node: WithStatement) {
|
||||
// Grammar checking for withStatement
|
||||
if (inStrictMode) {
|
||||
grammarErrorOnFirstToken(node, Diagnostics.with_statements_are_not_allowed_in_strict_mode);
|
||||
}
|
||||
}
|
||||
|
||||
function grammarErrorOnFirstToken(node: Node, message: DiagnosticMessage, arg0?: any, arg1?: any, arg2?: any) {
|
||||
let span = getSpanOfTokenAtPosition(file, node.pos);
|
||||
file.bindDiagnostics.push(createFileDiagnostic(file, span.start, span.length, message, arg0, arg1, arg2));
|
||||
}
|
||||
|
||||
function getDestructuringParameterName(node: Declaration) {
|
||||
return "__" + indexOf((<SignatureDeclaration>node.parent).parameters, node);
|
||||
}
|
||||
@@ -584,6 +750,11 @@ namespace ts {
|
||||
function bind(node: Node) {
|
||||
node.parent = parent;
|
||||
|
||||
var savedInStrictMode = inStrictMode;
|
||||
if (!savedInStrictMode) {
|
||||
updateStrictMode(node);
|
||||
}
|
||||
|
||||
// First we bind declaration nodes to a symbol if possible. We'll both create a symbol
|
||||
// and then potentially add the symbol to an appropriate symbol table. Possible
|
||||
// destination symbol tables are:
|
||||
@@ -601,12 +772,70 @@ namespace ts {
|
||||
// the current 'container' node when it changes. This helps us know which symbol table
|
||||
// a local should go into for example.
|
||||
bindChildren(node);
|
||||
|
||||
inStrictMode = savedInStrictMode;
|
||||
}
|
||||
|
||||
function updateStrictMode(node: Node) {
|
||||
switch (node.kind) {
|
||||
case SyntaxKind.SourceFile:
|
||||
case SyntaxKind.ModuleBlock:
|
||||
updateStrictModeStatementList((<SourceFile | ModuleBlock>node).statements);
|
||||
return;
|
||||
case SyntaxKind.Block:
|
||||
if (isFunctionLike(node.parent)) {
|
||||
updateStrictModeStatementList((<Block>node).statements);
|
||||
}
|
||||
return;
|
||||
case SyntaxKind.ClassDeclaration:
|
||||
case SyntaxKind.ClassExpression:
|
||||
// All classes are automatically in strict mode in ES6.
|
||||
inStrictMode = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
function updateStrictModeStatementList(statements: NodeArray<Statement>) {
|
||||
for (let statement of statements) {
|
||||
if (!isPrologueDirective(statement)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (isUseStrictPrologueDirective(<ExpressionStatement>statement)) {
|
||||
inStrictMode = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Should be called only on prologue directives (isPrologueDirective(node) should be true)
|
||||
function isUseStrictPrologueDirective(node: ExpressionStatement): boolean {
|
||||
let nodeText = getTextOfNodeFromSourceText(file.text, node.expression);
|
||||
|
||||
// Note: the node text must be exactly "use strict" or 'use strict'. It is not ok for the
|
||||
// string to contain unicode escapes (as per ES5).
|
||||
return nodeText === '"use strict"' || nodeText === "'use strict'";
|
||||
}
|
||||
|
||||
function bindWorker(node: Node) {
|
||||
switch (node.kind) {
|
||||
case SyntaxKind.Identifier:
|
||||
return checkStrictModeIdentifier(<Identifier>node);
|
||||
case SyntaxKind.BinaryExpression:
|
||||
return checkStrictModeBinaryExpression(<BinaryExpression>node);
|
||||
case SyntaxKind.CatchClause:
|
||||
return checkStrictModeCatchClause(<CatchClause>node);
|
||||
case SyntaxKind.DeleteExpression:
|
||||
return checkStrictModeDeleteExpression(<DeleteExpression>node);
|
||||
case SyntaxKind.NumericLiteral:
|
||||
return checkStrictModeNumericLiteral(<LiteralExpression>node);
|
||||
case SyntaxKind.PostfixUnaryExpression:
|
||||
return checkStrictModePostfixUnaryExpression(<PostfixUnaryExpression>node);
|
||||
case SyntaxKind.PrefixUnaryExpression:
|
||||
return checkStrictModePrefixUnaryExpression(<PrefixUnaryExpression>node);
|
||||
case SyntaxKind.WithStatement:
|
||||
return checkStrictModeWithStatement(<WithStatement>node);
|
||||
|
||||
case SyntaxKind.TypeParameter:
|
||||
return declareSymbolAndAddToSymbolTable(<Declaration>node, SymbolFlags.TypeParameter, SymbolFlags.TypeParameterExcludes);
|
||||
case SyntaxKind.Parameter:
|
||||
@@ -635,6 +864,7 @@ namespace ts {
|
||||
return bindPropertyOrMethodOrAccessor(<Declaration>node, SymbolFlags.Method | ((<MethodDeclaration>node).questionToken ? SymbolFlags.Optional : SymbolFlags.None),
|
||||
isObjectLiteralMethod(node) ? SymbolFlags.PropertyExcludes : SymbolFlags.MethodExcludes);
|
||||
case SyntaxKind.FunctionDeclaration:
|
||||
checkStrictModeFunctionName(<FunctionDeclaration>node);
|
||||
return declareSymbolAndAddToSymbolTable(<Declaration>node, SymbolFlags.Function, SymbolFlags.FunctionExcludes);
|
||||
case SyntaxKind.Constructor:
|
||||
return declareSymbolAndAddToSymbolTable(<Declaration>node, SymbolFlags.Constructor, /*symbolExcludes:*/ SymbolFlags.None);
|
||||
@@ -648,9 +878,10 @@ namespace ts {
|
||||
case SyntaxKind.TypeLiteral:
|
||||
return bindAnonymousDeclaration(<TypeLiteralNode>node, SymbolFlags.TypeLiteral, "__type");
|
||||
case SyntaxKind.ObjectLiteralExpression:
|
||||
return bindAnonymousDeclaration(<ObjectLiteralExpression>node, SymbolFlags.ObjectLiteral, "__object");
|
||||
return bindObjectLiteralExpression(<ObjectLiteralExpression>node);
|
||||
case SyntaxKind.FunctionExpression:
|
||||
case SyntaxKind.ArrowFunction:
|
||||
checkStrictModeFunctionName(<FunctionExpression>node);
|
||||
return bindAnonymousDeclaration(<FunctionExpression>node, SymbolFlags.Function, "__function");
|
||||
case SyntaxKind.ClassExpression:
|
||||
case SyntaxKind.ClassDeclaration:
|
||||
@@ -756,6 +987,10 @@ namespace ts {
|
||||
}
|
||||
|
||||
function bindVariableDeclarationOrBindingElement(node: VariableDeclaration | BindingElement) {
|
||||
if (inStrictMode) {
|
||||
checkStrictModeEvalOrArguments(node, node.name)
|
||||
}
|
||||
|
||||
if (!isBindingPattern(node.name)) {
|
||||
if (isBlockOrCatchScoped(node)) {
|
||||
bindBlockScopedVariableDeclaration(node);
|
||||
@@ -779,6 +1014,12 @@ namespace ts {
|
||||
}
|
||||
|
||||
function bindParameter(node: ParameterDeclaration) {
|
||||
if (inStrictMode) {
|
||||
// It is a SyntaxError if the identifier eval or arguments appears within a FormalParameterList of a
|
||||
// strict mode FunctionLikeDeclaration or FunctionExpression(13.1)
|
||||
checkStrictModeEvalOrArguments(node, node.name);
|
||||
}
|
||||
|
||||
if (isBindingPattern(node.name)) {
|
||||
bindAnonymousDeclaration(node, SymbolFlags.FunctionScopedVariable, getDestructuringParameterName(node));
|
||||
}
|
||||
|
||||
+178
-209
@@ -2600,56 +2600,126 @@ namespace ts {
|
||||
return concatenate(getOuterTypeParametersOfClassOrInterface(symbol), getLocalTypeParametersOfClassOrInterfaceOrTypeAlias(symbol));
|
||||
}
|
||||
|
||||
function isConstructorType(type: Type): boolean {
|
||||
return type.flags & TypeFlags.ObjectType && getSignaturesOfType(type, SignatureKind.Construct).length > 0;
|
||||
}
|
||||
|
||||
function getBaseTypeNodeOfClass(type: InterfaceType): ExpressionWithTypeArguments {
|
||||
return getClassExtendsHeritageClauseElement(<ClassLikeDeclaration>type.symbol.valueDeclaration);
|
||||
}
|
||||
|
||||
function getConstructorsForTypeArguments(type: ObjectType, typeArgumentNodes: TypeNode[]): Signature[] {
|
||||
let typeArgCount = typeArgumentNodes ? typeArgumentNodes.length : 0;
|
||||
return filter(getSignaturesOfType(type, SignatureKind.Construct),
|
||||
sig => (sig.typeParameters ? sig.typeParameters.length : 0) === typeArgCount);
|
||||
}
|
||||
|
||||
function getInstantiatedConstructorsForTypeArguments(type: ObjectType, typeArgumentNodes: TypeNode[]): Signature[] {
|
||||
let signatures = getConstructorsForTypeArguments(type, typeArgumentNodes);
|
||||
if (typeArgumentNodes) {
|
||||
let typeArguments = map(typeArgumentNodes, getTypeFromTypeNode);
|
||||
signatures = map(signatures, sig => getSignatureInstantiation(sig, typeArguments));
|
||||
}
|
||||
return signatures;
|
||||
}
|
||||
|
||||
// The base constructor of a class can resolve to
|
||||
// undefinedType if the class has no extends clause,
|
||||
// unknownType if an error occurred during resolution of the extends expression,
|
||||
// nullType if the extends expression is the null value, or
|
||||
// an object type with at least one construct signature.
|
||||
function getBaseConstructorTypeOfClass(type: InterfaceType): ObjectType {
|
||||
if (!type.resolvedBaseConstructorType) {
|
||||
let baseTypeNode = getBaseTypeNodeOfClass(type);
|
||||
if (!baseTypeNode) {
|
||||
return type.resolvedBaseConstructorType = undefinedType;
|
||||
}
|
||||
if (!pushTypeResolution(type)) {
|
||||
return unknownType;
|
||||
}
|
||||
let baseConstructorType = checkExpression(baseTypeNode.expression);
|
||||
if (baseConstructorType.flags & TypeFlags.ObjectType) {
|
||||
// Force resolution of members such that we catch circularities
|
||||
resolveObjectOrUnionTypeMembers(baseConstructorType);
|
||||
}
|
||||
if (!popTypeResolution()) {
|
||||
error(type.symbol.valueDeclaration, Diagnostics._0_is_referenced_directly_or_indirectly_in_its_own_base_expression, symbolToString(type.symbol));
|
||||
return type.resolvedBaseConstructorType = unknownType;
|
||||
}
|
||||
if (baseConstructorType !== unknownType && baseConstructorType !== nullType && !isConstructorType(baseConstructorType)) {
|
||||
error(baseTypeNode.expression, Diagnostics.Base_expression_is_not_of_a_constructor_function_type);
|
||||
return type.resolvedBaseConstructorType = unknownType;
|
||||
}
|
||||
type.resolvedBaseConstructorType = baseConstructorType;
|
||||
}
|
||||
return type.resolvedBaseConstructorType;
|
||||
}
|
||||
|
||||
function getBaseTypes(type: InterfaceType): ObjectType[] {
|
||||
let typeWithBaseTypes = <InterfaceTypeWithBaseTypes>type;
|
||||
if (!typeWithBaseTypes.baseTypes) {
|
||||
if (!type.resolvedBaseTypes) {
|
||||
if (type.symbol.flags & SymbolFlags.Class) {
|
||||
resolveBaseTypesOfClass(typeWithBaseTypes);
|
||||
resolveBaseTypesOfClass(type);
|
||||
}
|
||||
else if (type.symbol.flags & SymbolFlags.Interface) {
|
||||
resolveBaseTypesOfInterface(typeWithBaseTypes);
|
||||
resolveBaseTypesOfInterface(type);
|
||||
}
|
||||
else {
|
||||
Debug.fail("type must be class or interface");
|
||||
}
|
||||
}
|
||||
|
||||
return typeWithBaseTypes.baseTypes;
|
||||
return type.resolvedBaseTypes;
|
||||
}
|
||||
|
||||
function resolveBaseTypesOfClass(type: InterfaceTypeWithBaseTypes): void {
|
||||
type.baseTypes = [];
|
||||
let declaration = <ClassDeclaration>getDeclarationOfKind(type.symbol, SyntaxKind.ClassDeclaration);
|
||||
let baseTypeNode = getClassExtendsHeritageClauseElement(declaration);
|
||||
if (baseTypeNode) {
|
||||
let baseType = getTypeFromTypeNode(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 resolveBaseTypesOfClass(type: InterfaceType): void {
|
||||
type.resolvedBaseTypes = emptyArray;
|
||||
let baseContructorType = getBaseConstructorTypeOfClass(type);
|
||||
if (!(baseContructorType.flags & TypeFlags.ObjectType)) {
|
||||
return;
|
||||
}
|
||||
let baseTypeNode = getBaseTypeNodeOfClass(type);
|
||||
let baseType: Type;
|
||||
if (baseContructorType.symbol && baseContructorType.symbol.flags & SymbolFlags.Class) {
|
||||
// When base constructor type is a class we know that the constructors all have the same type parameters as the
|
||||
// class and all return the instance type of the class. There is no need for further checks and we can apply the
|
||||
// type arguments in the same manner as a type reference to get the same error reporting experience.
|
||||
baseType = getTypeFromClassOrInterfaceReference(baseTypeNode, baseContructorType.symbol);
|
||||
}
|
||||
else {
|
||||
// The class derives from a "class-like" constructor function, check that we have at least one construct signature
|
||||
// with a matching number of type parameters and use the return type of the first instantiated signature. Elsewhere
|
||||
// we check that all instantiated signatures return the same type.
|
||||
let constructors = getInstantiatedConstructorsForTypeArguments(baseContructorType, baseTypeNode.typeArguments);
|
||||
if (!constructors.length) {
|
||||
error(baseTypeNode.expression, Diagnostics.No_base_constructor_has_the_specified_number_of_type_arguments);
|
||||
return;
|
||||
}
|
||||
baseType = getReturnTypeOfSignature(constructors[0]);
|
||||
}
|
||||
if (baseType === unknownType) {
|
||||
return;
|
||||
}
|
||||
if (!(getTargetType(baseType).flags & (TypeFlags.Class | TypeFlags.Interface))) {
|
||||
error(baseTypeNode.expression, Diagnostics.Base_constructor_does_not_return_a_class_or_interface_type);
|
||||
return;
|
||||
}
|
||||
if (type === baseType || hasBaseType(<InterfaceType>baseType, type)) {
|
||||
error(type.symbol.valueDeclaration, Diagnostics.Type_0_recursively_references_itself_as_a_base_type,
|
||||
typeToString(type, /*enclosingDeclaration*/ undefined, TypeFormatFlags.WriteArrayAsGenericType));
|
||||
return;
|
||||
}
|
||||
type.resolvedBaseTypes = [baseType];
|
||||
}
|
||||
|
||||
function resolveBaseTypesOfInterface(type: InterfaceTypeWithBaseTypes): void {
|
||||
type.baseTypes = [];
|
||||
function resolveBaseTypesOfInterface(type: InterfaceType): void {
|
||||
type.resolvedBaseTypes = [];
|
||||
for (let declaration of type.symbol.declarations) {
|
||||
if (declaration.kind === SyntaxKind.InterfaceDeclaration && getInterfaceBaseTypeNodes(<InterfaceDeclaration>declaration)) {
|
||||
for (let node of getInterfaceBaseTypeNodes(<InterfaceDeclaration>declaration)) {
|
||||
let baseType = getTypeFromTypeNode(node);
|
||||
|
||||
if (baseType !== unknownType) {
|
||||
if (getTargetType(baseType).flags & (TypeFlags.Class | TypeFlags.Interface)) {
|
||||
if (type !== baseType && !hasBaseType(<InterfaceType>baseType, type)) {
|
||||
type.baseTypes.push(baseType);
|
||||
type.resolvedBaseTypes.push(baseType);
|
||||
}
|
||||
else {
|
||||
error(declaration, Diagnostics.Type_0_recursively_references_itself_as_a_base_type, typeToString(type, /*enclosingDeclaration*/ undefined, TypeFormatFlags.WriteArrayAsGenericType));
|
||||
@@ -2868,19 +2938,25 @@ namespace ts {
|
||||
}
|
||||
|
||||
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 ?
|
||||
getSignatureInstantiation(baseSignature, (<TypeReference>baseType).typeArguments) : cloneSignature(baseSignature);
|
||||
signature.typeParameters = classType.localTypeParameters;
|
||||
signature.resolvedReturnType = classType;
|
||||
return signature;
|
||||
});
|
||||
if (!getBaseTypes(classType).length) {
|
||||
return [createSignature(undefined, classType.localTypeParameters, emptyArray, classType, undefined, 0, false, false)];
|
||||
}
|
||||
return [createSignature(undefined, classType.localTypeParameters, emptyArray, classType, undefined, 0, false, false)];
|
||||
let baseConstructorType = getBaseConstructorTypeOfClass(classType);
|
||||
let baseSignatures = getSignaturesOfType(baseConstructorType, SignatureKind.Construct);
|
||||
let baseTypeNode = getBaseTypeNodeOfClass(classType);
|
||||
let typeArguments = map(baseTypeNode.typeArguments, getTypeFromTypeNode);
|
||||
let typeArgCount = typeArguments ? typeArguments.length : 0;
|
||||
let result: Signature[] = [];
|
||||
for (let baseSig of baseSignatures) {
|
||||
let typeParamCount = baseSig.typeParameters ? baseSig.typeParameters.length : 0;
|
||||
if (typeParamCount === typeArgCount) {
|
||||
let sig = typeParamCount ? getSignatureInstantiation(baseSig, typeArguments) : cloneSignature(baseSig);
|
||||
sig.typeParameters = classType.localTypeParameters;
|
||||
sig.resolvedReturnType = classType;
|
||||
result.push(sig);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
function createTupleTypeMemberSymbols(memberTypes: Type[]): SymbolTable {
|
||||
@@ -2992,10 +3068,10 @@ namespace ts {
|
||||
if (!constructSignatures.length) {
|
||||
constructSignatures = getDefaultConstructSignatures(classType);
|
||||
}
|
||||
let baseTypes = getBaseTypes(classType);
|
||||
if (baseTypes.length) {
|
||||
let baseConstructorType = getBaseConstructorTypeOfClass(classType);
|
||||
if (baseConstructorType.flags & TypeFlags.ObjectType) {
|
||||
members = createSymbolTable(getNamedMembers(members));
|
||||
addInheritedMembers(members, getPropertiesOfObjectType(getTypeOfSymbol(baseTypes[0].symbol)));
|
||||
addInheritedMembers(members, getPropertiesOfObjectType(baseConstructorType));
|
||||
}
|
||||
}
|
||||
stringIndexType = undefined;
|
||||
@@ -4127,14 +4203,14 @@ namespace ts {
|
||||
return !node.typeParameters && node.parameters.length && !forEach(node.parameters, p => p.type);
|
||||
}
|
||||
|
||||
function getTypeWithoutConstructors(type: Type): Type {
|
||||
function getTypeWithoutSignatures(type: Type): Type {
|
||||
if (type.flags & TypeFlags.ObjectType) {
|
||||
let resolved = resolveObjectOrUnionTypeMembers(<ObjectType>type);
|
||||
if (resolved.constructSignatures.length) {
|
||||
let result = <ResolvedType>createObjectType(TypeFlags.Anonymous, type.symbol);
|
||||
result.members = resolved.members;
|
||||
result.properties = resolved.properties;
|
||||
result.callSignatures = resolved.callSignatures;
|
||||
result.callSignatures = emptyArray;
|
||||
result.constructSignatures = emptyArray;
|
||||
type = result;
|
||||
}
|
||||
@@ -5881,15 +5957,11 @@ namespace ts {
|
||||
|
||||
function checkSuperExpression(node: Node): Type {
|
||||
let isCallExpression = node.parent.kind === SyntaxKind.CallExpression && (<CallExpression>node.parent).expression === node;
|
||||
let enclosingClass = <ClassDeclaration>getAncestor(node, SyntaxKind.ClassDeclaration);
|
||||
let baseClass: Type;
|
||||
if (enclosingClass && getClassExtendsHeritageClauseElement(enclosingClass)) {
|
||||
let classType = <InterfaceType>getDeclaredTypeOfSymbol(getSymbolOfNode(enclosingClass));
|
||||
let baseTypes = getBaseTypes(classType);
|
||||
baseClass = baseTypes.length && baseTypes[0];
|
||||
}
|
||||
let classDeclaration = <ClassDeclaration>getAncestor(node, SyntaxKind.ClassDeclaration);
|
||||
let classType = classDeclaration && <InterfaceType>getDeclaredTypeOfSymbol(getSymbolOfNode(classDeclaration));
|
||||
let baseClassType = classType && getBaseTypes(classType)[0];
|
||||
|
||||
if (!baseClass) {
|
||||
if (!baseClassType) {
|
||||
error(node, Diagnostics.super_can_only_be_referenced_in_a_derived_class);
|
||||
return unknownType;
|
||||
}
|
||||
@@ -5944,11 +6016,11 @@ namespace ts {
|
||||
|
||||
if ((container.flags & NodeFlags.Static) || isCallExpression) {
|
||||
getNodeLinks(node).flags |= NodeCheckFlags.SuperStatic;
|
||||
returnType = getTypeOfSymbol(baseClass.symbol);
|
||||
returnType = getBaseConstructorTypeOfClass(classType);
|
||||
}
|
||||
else {
|
||||
getNodeLinks(node).flags |= NodeCheckFlags.SuperInstance;
|
||||
returnType = baseClass;
|
||||
returnType = baseClassType;
|
||||
}
|
||||
|
||||
if (container.kind === SyntaxKind.Constructor && isInConstructorArgumentInitializer(node, container)) {
|
||||
@@ -7135,35 +7207,13 @@ namespace ts {
|
||||
return args;
|
||||
}
|
||||
|
||||
/**
|
||||
* In a 'super' call, type arguments are not provided within the CallExpression node itself.
|
||||
* Instead, they must be fetched from the class declaration's base type node.
|
||||
*
|
||||
* If 'node' is a 'super' call (e.g. super(...), new super(...)), then we attempt to fetch
|
||||
* the type arguments off the containing class's first heritage clause (if one exists). Note that if
|
||||
* type arguments are supplied on the 'super' call, they are ignored (though this is syntactically incorrect).
|
||||
*
|
||||
* In all other cases, the call's explicit type arguments are returned.
|
||||
*/
|
||||
function getEffectiveTypeArguments(callExpression: CallExpression): TypeNode[] {
|
||||
if (callExpression.expression.kind === SyntaxKind.SuperKeyword) {
|
||||
let containingClass = <ClassDeclaration>getAncestor(callExpression, SyntaxKind.ClassDeclaration);
|
||||
let baseClassTypeNode = containingClass && getClassExtendsHeritageClauseElement(containingClass);
|
||||
return baseClassTypeNode && baseClassTypeNode.typeArguments;
|
||||
}
|
||||
else {
|
||||
// Ordinary case - simple function invocation.
|
||||
return callExpression.typeArguments;
|
||||
}
|
||||
}
|
||||
|
||||
function resolveCall(node: CallLikeExpression, signatures: Signature[], candidatesOutArray: Signature[]): Signature {
|
||||
let isTaggedTemplate = node.kind === SyntaxKind.TaggedTemplateExpression;
|
||||
|
||||
let typeArguments: TypeNode[];
|
||||
|
||||
if (!isTaggedTemplate) {
|
||||
typeArguments = getEffectiveTypeArguments(<CallExpression>node);
|
||||
typeArguments = (<CallExpression>node).typeArguments;
|
||||
|
||||
// We already perform checking on the type arguments on the class declaration itself.
|
||||
if ((<CallExpression>node).expression.kind !== SyntaxKind.SuperKeyword) {
|
||||
@@ -7371,7 +7421,11 @@ namespace ts {
|
||||
if (node.expression.kind === SyntaxKind.SuperKeyword) {
|
||||
let superType = checkSuperExpression(node.expression);
|
||||
if (superType !== unknownType) {
|
||||
return resolveCall(node, getSignaturesOfType(superType, SignatureKind.Construct), candidatesOutArray);
|
||||
// In super call, the candidate signatures are the matching arity signatures of the base constructor function instantiated
|
||||
// with the type arguments specified in the extends clause.
|
||||
let baseTypeNode = getClassExtendsHeritageClauseElement(<ClassDeclaration>getAncestor(node, SyntaxKind.ClassDeclaration));
|
||||
let baseConstructors = getInstantiatedConstructorsForTypeArguments(superType, baseTypeNode.typeArguments);
|
||||
return resolveCall(node, baseConstructors, candidatesOutArray);
|
||||
}
|
||||
return resolveUntypedCall(node);
|
||||
}
|
||||
@@ -7746,7 +7800,7 @@ namespace ts {
|
||||
// Grammar checking
|
||||
let hasGrammarError = checkGrammarFunctionLikeDeclaration(node);
|
||||
if (!hasGrammarError && node.kind === SyntaxKind.FunctionExpression) {
|
||||
checkGrammarFunctionName(node.name) || checkGrammarForGenerator(node);
|
||||
checkGrammarForGenerator(node);
|
||||
}
|
||||
|
||||
// The identityMapper object is used to indicate that function expressions are wildcards
|
||||
@@ -7903,14 +7957,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
function checkDeleteExpression(node: DeleteExpression): Type {
|
||||
// Grammar checking
|
||||
if (node.parserContextFlags & ParserContextFlags.StrictMode && node.expression.kind === SyntaxKind.Identifier) {
|
||||
// When a delete operator occurs within strict mode code, a SyntaxError is thrown if its
|
||||
// UnaryExpression is a direct reference to a variable, function argument, or function name
|
||||
grammarErrorOnNode(node.expression, Diagnostics.delete_cannot_be_called_on_an_identifier_in_strict_mode);
|
||||
}
|
||||
|
||||
let operandType = checkExpression(node.expression);
|
||||
checkExpression(node.expression);
|
||||
return booleanType;
|
||||
}
|
||||
|
||||
@@ -7925,14 +7972,6 @@ namespace ts {
|
||||
}
|
||||
|
||||
function checkPrefixUnaryExpression(node: PrefixUnaryExpression): Type {
|
||||
// Grammar checking
|
||||
// The identifier eval or arguments may not appear as the LeftHandSideExpression of an
|
||||
// Assignment operator(11.13) or of a PostfixExpression(11.3) or as the UnaryExpression
|
||||
// operated upon by a Prefix Increment(11.4.4) or a Prefix Decrement(11.4.5) operator
|
||||
if ((node.operator === SyntaxKind.PlusPlusToken || node.operator === SyntaxKind.MinusMinusToken)) {
|
||||
checkGrammarEvalOrArgumentsInStrictMode(node, <Identifier>node.operand);
|
||||
}
|
||||
|
||||
let operandType = checkExpression(node.operand);
|
||||
switch (node.operator) {
|
||||
case SyntaxKind.PlusToken:
|
||||
@@ -7959,12 +7998,6 @@ namespace ts {
|
||||
}
|
||||
|
||||
function checkPostfixUnaryExpression(node: PostfixUnaryExpression): Type {
|
||||
// Grammar checking
|
||||
// The identifier eval or arguments may not appear as the LeftHandSideExpression of an
|
||||
// Assignment operator(11.13) or of a PostfixExpression(11.3) or as the UnaryExpression
|
||||
// operated upon by a Prefix Increment(11.4.4) or a Prefix Decrement(11.4.5) operator.
|
||||
checkGrammarEvalOrArgumentsInStrictMode(node, <Identifier>node.operand);
|
||||
|
||||
let operandType = checkExpression(node.operand);
|
||||
let ok = checkArithmeticOperandType(node.operand, operandType, Diagnostics.An_arithmetic_operand_must_be_of_type_any_number_or_an_enum_type);
|
||||
if (ok) {
|
||||
@@ -8144,13 +8177,6 @@ namespace ts {
|
||||
}
|
||||
|
||||
function checkBinaryExpression(node: BinaryExpression, contextualMapper?: TypeMapper) {
|
||||
// Grammar checking
|
||||
if (isLeftHandSideExpression(node.left) && isAssignmentOperator(node.operatorToken.kind)) {
|
||||
// ECMA 262 (Annex C) The identifier eval or arguments may not appear as the LeftHandSideExpression of an
|
||||
// Assignment operator(11.13) or of a PostfixExpression(11.3)
|
||||
checkGrammarEvalOrArgumentsInStrictMode(node, <Identifier>node.left);
|
||||
}
|
||||
|
||||
let operator = node.operatorToken.kind;
|
||||
if (operator === SyntaxKind.EqualsToken && (node.left.kind === SyntaxKind.ObjectLiteralExpression || node.left.kind === SyntaxKind.ArrayLiteralExpression)) {
|
||||
return checkDestructuringAssignment(node.left, checkExpression(node.right, contextualMapper), contextualMapper);
|
||||
@@ -8592,11 +8618,9 @@ namespace ts {
|
||||
// It is a SyntaxError if the Identifier "eval" or the Identifier "arguments" occurs as the
|
||||
// Identifier in a PropertySetParameterList of a PropertyAssignment that is contained in strict code
|
||||
// or if its FunctionBody is strict code(11.1.5).
|
||||
// It is a SyntaxError if the identifier eval or arguments appears within a FormalParameterList of a
|
||||
// strict mode FunctionLikeDeclaration or FunctionExpression(13.1)
|
||||
|
||||
// Grammar checking
|
||||
checkGrammarDecorators(node) || checkGrammarModifiers(node) || checkGrammarEvalOrArgumentsInStrictMode(node, <Identifier>node.name);
|
||||
checkGrammarDecorators(node) || checkGrammarModifiers(node);
|
||||
|
||||
checkVariableLikeDeclaration(node);
|
||||
let func = getContainingFunction(node);
|
||||
@@ -8958,32 +8982,25 @@ namespace ts {
|
||||
checkDecorators(node);
|
||||
}
|
||||
|
||||
function checkTypeReferenceNode(node: TypeReferenceNode) {
|
||||
return checkTypeReferenceOrExpressionWithTypeArguments(node);
|
||||
function checkTypeArgumentsAndConstraints(typeParameters: TypeParameter[], typeArguments: TypeNode[]) {
|
||||
for (let i = 0; i < typeArguments.length; i++) {
|
||||
let typeArgument = typeArguments[i];
|
||||
checkSourceElement(typeArgument);
|
||||
let constraint = getConstraintOfTypeParameter(typeParameters[i]);
|
||||
if (produceDiagnostics && constraint) {
|
||||
checkTypeAssignableTo(getTypeFromTypeNode(typeArgument), constraint, typeArgument, Diagnostics.Type_0_does_not_satisfy_the_constraint_1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function checkExpressionWithTypeArguments(node: ExpressionWithTypeArguments) {
|
||||
return checkTypeReferenceOrExpressionWithTypeArguments(node);
|
||||
}
|
||||
|
||||
function checkTypeReferenceOrExpressionWithTypeArguments(node: TypeReferenceNode | ExpressionWithTypeArguments) {
|
||||
// Grammar checking
|
||||
function checkTypeReferenceNode(node: TypeReferenceNode | ExpressionWithTypeArguments) {
|
||||
checkGrammarTypeArguments(node, node.typeArguments);
|
||||
|
||||
let type = getTypeFromTypeReference(node);
|
||||
if (type !== unknownType && node.typeArguments) {
|
||||
// Do type argument local checks only if referenced type is successfully resolved
|
||||
let symbol = getNodeLinks(node).resolvedSymbol;
|
||||
let typeParameters = symbol.flags & SymbolFlags.TypeAlias ? getSymbolLinks(symbol).typeParameters : (<TypeReference>type).target.localTypeParameters;
|
||||
let len = node.typeArguments.length;
|
||||
for (let i = 0; i < len; i++) {
|
||||
checkSourceElement(node.typeArguments[i]);
|
||||
let constraint = getConstraintOfTypeParameter(typeParameters[i]);
|
||||
if (produceDiagnostics && constraint) {
|
||||
let typeArgument = (<TypeReference>type).typeArguments[i];
|
||||
checkTypeAssignableTo(typeArgument, constraint, node, Diagnostics.Type_0_does_not_satisfy_the_constraint_1);
|
||||
}
|
||||
}
|
||||
checkTypeArgumentsAndConstraints(typeParameters, node.typeArguments);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9499,9 +9516,7 @@ namespace ts {
|
||||
|
||||
function checkFunctionDeclaration(node: FunctionDeclaration): void {
|
||||
if (produceDiagnostics) {
|
||||
checkFunctionLikeDeclaration(node) ||
|
||||
checkGrammarFunctionName(node.name) ||
|
||||
checkGrammarForGenerator(node);
|
||||
checkFunctionLikeDeclaration(node) || checkGrammarForGenerator(node);
|
||||
|
||||
checkCollisionWithCapturedSuperVariable(node, node.name);
|
||||
checkCollisionWithCapturedThisVariable(node, node.name);
|
||||
@@ -10328,12 +10343,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
function checkWithStatement(node: WithStatement) {
|
||||
// Grammar checking for withStatement
|
||||
if (!checkGrammarStatementInAmbientContext(node)) {
|
||||
if (node.parserContextFlags & ParserContextFlags.StrictMode) {
|
||||
grammarErrorOnFirstToken(node, Diagnostics.with_statements_are_not_allowed_in_strict_mode);
|
||||
}
|
||||
}
|
||||
checkGrammarStatementInAmbientContext(node);
|
||||
|
||||
checkExpression(node.expression);
|
||||
error(node.expression, Diagnostics.All_symbols_within_a_with_block_will_be_resolved_to_any);
|
||||
@@ -10437,10 +10447,6 @@ namespace ts {
|
||||
grammarErrorOnNode(localSymbol.valueDeclaration, Diagnostics.Cannot_redeclare_identifier_0_in_catch_clause, identifierName);
|
||||
}
|
||||
}
|
||||
|
||||
// It is a SyntaxError if a TryStatement with a Catch occurs within strict code and the Identifier of the
|
||||
// Catch production is eval or arguments
|
||||
checkGrammarEvalOrArgumentsInStrictMode(node, <Identifier>catchClause.variableDeclaration.name);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10596,45 +10602,40 @@ namespace ts {
|
||||
let symbol = getSymbolOfNode(node);
|
||||
let type = <InterfaceType>getDeclaredTypeOfSymbol(symbol);
|
||||
let staticType = <ObjectType>getTypeOfSymbol(symbol);
|
||||
|
||||
let baseTypeNode = getClassExtendsHeritageClauseElement(node);
|
||||
if (baseTypeNode) {
|
||||
if (!isSupportedExpressionWithTypeArguments(baseTypeNode)) {
|
||||
error(baseTypeNode.expression, Diagnostics.Only_identifiers_Slashqualified_names_with_optional_type_arguments_are_currently_supported_in_a_class_extends_clauses);
|
||||
}
|
||||
|
||||
emitExtends = emitExtends || !isInAmbientContext(node);
|
||||
checkExpressionWithTypeArguments(baseTypeNode);
|
||||
}
|
||||
let baseTypes = getBaseTypes(type);
|
||||
if (baseTypes.length) {
|
||||
if (produceDiagnostics) {
|
||||
let baseTypes = getBaseTypes(type);
|
||||
if (baseTypes.length && produceDiagnostics) {
|
||||
let baseType = baseTypes[0];
|
||||
let staticBaseType = getBaseConstructorTypeOfClass(type);
|
||||
if (baseTypeNode.typeArguments) {
|
||||
let constructors = getConstructorsForTypeArguments(staticBaseType, baseTypeNode.typeArguments);
|
||||
checkTypeArgumentsAndConstraints(constructors[0].typeParameters, baseTypeNode.typeArguments);
|
||||
}
|
||||
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,
|
||||
checkTypeAssignableTo(staticType, getTypeWithoutSignatures(staticBaseType), node.name || node,
|
||||
Diagnostics.Class_static_side_0_incorrectly_extends_base_class_static_side_1);
|
||||
|
||||
if (baseType.symbol !== resolveEntityName(baseTypeNode.expression, SymbolFlags.Value)) {
|
||||
error(baseTypeNode, Diagnostics.Type_name_0_in_extends_clause_does_not_reference_constructor_function_for_0, typeToString(baseType));
|
||||
if (!(staticBaseType.symbol && staticBaseType.symbol.flags & SymbolFlags.Class)) {
|
||||
// When the static base type is a "class-like" constructor function (but not actually a class), we verify
|
||||
// that all instantiated base constructor signatures return the same type.
|
||||
let constructors = getInstantiatedConstructorsForTypeArguments(staticBaseType, baseTypeNode.typeArguments);
|
||||
if (forEach(constructors, sig => getReturnTypeOfSignature(sig) !== baseType)) {
|
||||
error(baseTypeNode.expression, Diagnostics.Base_constructors_must_all_have_the_same_return_type);
|
||||
}
|
||||
}
|
||||
|
||||
checkKindsOfPropertyMemberOverrides(type, baseType);
|
||||
}
|
||||
}
|
||||
|
||||
if (baseTypes.length || (baseTypeNode && compilerOptions.isolatedModules)) {
|
||||
// Check that base type can be evaluated as expression
|
||||
checkExpression(baseTypeNode.expression);
|
||||
}
|
||||
|
||||
let implementedTypeNodes = getClassImplementsHeritageClauseElements(node);
|
||||
if (implementedTypeNodes) {
|
||||
forEach(implementedTypeNodes, typeRefNode => {
|
||||
if (!isSupportedExpressionWithTypeArguments(typeRefNode)) {
|
||||
error(typeRefNode.expression, Diagnostics.A_class_can_only_implement_an_identifier_Slashqualified_name_with_optional_type_arguments);
|
||||
}
|
||||
|
||||
checkExpressionWithTypeArguments(typeRefNode);
|
||||
checkTypeReferenceNode(typeRefNode);
|
||||
if (produceDiagnostics) {
|
||||
let t = getTypeFromTypeNode(typeRefNode);
|
||||
if (t !== unknownType) {
|
||||
@@ -10834,8 +10835,7 @@ namespace ts {
|
||||
if (!isSupportedExpressionWithTypeArguments(heritageElement)) {
|
||||
error(heritageElement.expression, Diagnostics.An_interface_can_only_extend_an_identifier_Slashqualified_name_with_optional_type_arguments);
|
||||
}
|
||||
|
||||
checkExpressionWithTypeArguments(heritageElement);
|
||||
checkTypeReferenceNode(heritageElement);
|
||||
});
|
||||
forEach(node.members, checkSourceElement);
|
||||
|
||||
@@ -12020,6 +12020,12 @@ namespace ts {
|
||||
return getTypeOfExpression(<Expression>node);
|
||||
}
|
||||
|
||||
if (isClassExtendsExpressionWithTypeArguments(node)) {
|
||||
// A SyntaxKind.ExpressionWithTypeArguments is considered a type node, except when it occurs in the
|
||||
// extends clause of a class. We handle that case here.
|
||||
return getBaseTypes(<InterfaceType>getDeclaredTypeOfSymbol(getSymbolOfNode(node.parent.parent)))[0];
|
||||
}
|
||||
|
||||
if (isTypeDeclaration(node)) {
|
||||
// In this case, we call getSymbolOfNode instead of getSymbolInfo because it is a declaration
|
||||
let symbol = getSymbolOfNode(node);
|
||||
@@ -13075,11 +13081,6 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
|
||||
function checkGrammarFunctionName(name: Node) {
|
||||
// It is a SyntaxError if the identifier eval or arguments appears within a FormalParameterList of a strict mode FunctionDeclaration or FunctionExpression (13.1))
|
||||
return checkGrammarEvalOrArgumentsInStrictMode(name, <Identifier>name);
|
||||
}
|
||||
|
||||
function checkGrammarForInvalidQuestionMark(node: Declaration, questionToken: Node, message: DiagnosticMessage): boolean {
|
||||
if (questionToken) {
|
||||
return grammarErrorOnNode(questionToken, message);
|
||||
@@ -13092,7 +13093,6 @@ namespace ts {
|
||||
let GetAccessor = 2;
|
||||
let SetAccesor = 4;
|
||||
let GetOrSetAccessor = GetAccessor | SetAccesor;
|
||||
let inStrictMode = (node.parserContextFlags & ParserContextFlags.StrictMode) !== 0;
|
||||
|
||||
for (let prop of node.properties) {
|
||||
let name = prop.name;
|
||||
@@ -13139,9 +13139,7 @@ namespace ts {
|
||||
else {
|
||||
let existingKind = seen[(<Identifier>name).text];
|
||||
if (currentKind === Property && existingKind === Property) {
|
||||
if (inStrictMode) {
|
||||
grammarErrorOnNode(name, Diagnostics.An_object_literal_cannot_have_multiple_properties_with_the_same_name_in_strict_mode);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
else if ((currentKind & GetOrSetAccessor) && (existingKind & GetOrSetAccessor)) {
|
||||
if (existingKind !== GetOrSetAccessor && currentKind !== existingKind) {
|
||||
@@ -13364,9 +13362,6 @@ namespace ts {
|
||||
return grammarErrorAtPos(getSourceFileOfNode(node), node.initializer.pos - 1, 1, Diagnostics.A_rest_element_cannot_have_an_initializer);
|
||||
}
|
||||
}
|
||||
// It is a SyntaxError if a VariableDeclaration or VariableDeclarationNoIn occurs within strict code
|
||||
// and its Identifier is eval or arguments
|
||||
return checkGrammarEvalOrArgumentsInStrictMode(node, <Identifier>node.name);
|
||||
}
|
||||
|
||||
function checkGrammarVariableDeclaration(node: VariableDeclaration) {
|
||||
@@ -13398,8 +13393,7 @@ namespace ts {
|
||||
|
||||
// It is a SyntaxError if a VariableDeclaration or VariableDeclarationNoIn occurs within strict code
|
||||
// and its Identifier is eval or arguments
|
||||
return (checkLetConstNames && checkGrammarNameInLetOrConstDeclarations(node.name)) ||
|
||||
checkGrammarEvalOrArgumentsInStrictMode(node, <Identifier>node.name);
|
||||
return checkLetConstNames && checkGrammarNameInLetOrConstDeclarations(node.name);
|
||||
}
|
||||
|
||||
function checkGrammarNameInLetOrConstDeclarations(name: Identifier | BindingPattern): boolean {
|
||||
@@ -13538,26 +13532,6 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
|
||||
function checkGrammarEvalOrArgumentsInStrictMode(contextNode: Node, name: Node): boolean {
|
||||
if (name && name.kind === SyntaxKind.Identifier) {
|
||||
let identifier = <Identifier>name;
|
||||
if (contextNode && (contextNode.parserContextFlags & ParserContextFlags.StrictMode) && isEvalOrArgumentsIdentifier(identifier)) {
|
||||
// We check first if the name is inside class declaration or class expression; if so give explicit message
|
||||
// otherwise report generic error message.
|
||||
|
||||
let message = getAncestor(identifier, SyntaxKind.ClassDeclaration) || getAncestor(identifier, SyntaxKind.ClassExpression) ?
|
||||
Diagnostics.Invalid_use_of_0_Class_definitions_are_automatically_in_strict_mode :
|
||||
Diagnostics.Invalid_use_of_0_in_strict_mode;
|
||||
return grammarErrorOnNode(identifier, message, declarationNameToString(identifier));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function isEvalOrArgumentsIdentifier(node: Node): boolean {
|
||||
return node.kind === SyntaxKind.Identifier &&
|
||||
((<Identifier>node).text === "eval" || (<Identifier>node).text === "arguments");
|
||||
}
|
||||
|
||||
function checkGrammarConstructorTypeParameters(node: ConstructorDeclaration) {
|
||||
if (node.typeParameters) {
|
||||
return grammarErrorAtPos(getSourceFileOfNode(node), node.typeParameters.pos, node.typeParameters.end - node.typeParameters.pos, Diagnostics.Type_parameters_cannot_appear_on_a_constructor_declaration);
|
||||
@@ -13667,13 +13641,8 @@ namespace ts {
|
||||
|
||||
function checkGrammarNumericLiteral(node: Identifier): boolean {
|
||||
// Grammar checking
|
||||
if (node.flags & NodeFlags.OctalLiteral) {
|
||||
if (node.parserContextFlags & ParserContextFlags.StrictMode) {
|
||||
return grammarErrorOnNode(node, Diagnostics.Octal_literals_are_not_allowed_in_strict_mode);
|
||||
}
|
||||
else if (languageVersion >= ScriptTarget.ES5) {
|
||||
return grammarErrorOnNode(node, Diagnostics.Octal_literals_are_not_available_when_targeting_ECMAScript_5_and_higher);
|
||||
}
|
||||
if (node.flags & NodeFlags.OctalLiteral && languageVersion >= ScriptTarget.ES5) {
|
||||
return grammarErrorOnNode(node, Diagnostics.Octal_literals_are_not_available_when_targeting_ECMAScript_5_and_higher);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -171,6 +171,8 @@ namespace ts {
|
||||
A_class_declaration_without_the_default_modifier_must_have_a_name: { code: 1211, category: DiagnosticCategory.Error, key: "A class declaration without the 'default' modifier must have a name" },
|
||||
Identifier_expected_0_is_a_reserved_word_in_strict_mode: { code: 1212, category: DiagnosticCategory.Error, key: "Identifier expected. '{0}' is a reserved word in strict mode" },
|
||||
Identifier_expected_0_is_a_reserved_word_in_strict_mode_Class_definitions_are_automatically_in_strict_mode: { code: 1213, category: DiagnosticCategory.Error, key: "Identifier expected. '{0}' is a reserved word in strict mode. Class definitions are automatically in strict mode." },
|
||||
Identifier_expected_0_is_a_reserved_word_in_strict_mode_Modules_are_automatically_in_strict_mode: { code: 1214, category: DiagnosticCategory.Error, key: "Identifier expected. '{0}' is a reserved word in strict mode. Modules are automatically in strict mode." },
|
||||
Invalid_use_of_0_Modules_are_automatically_in_strict_mode: { code: 1215, category: DiagnosticCategory.Error, key: "Invalid use of '{0}'. Modules are automatically in strict mode." },
|
||||
Export_assignment_is_not_supported_when_module_flag_is_system: { code: 1218, category: DiagnosticCategory.Error, key: "Export assignment is not supported when '--module' flag is 'system'." },
|
||||
Experimental_support_for_decorators_is_a_feature_that_is_subject_to_change_in_a_future_release_Specify_experimentalDecorators_to_remove_this_warning: { code: 1219, category: DiagnosticCategory.Error, key: "Experimental support for decorators is a feature that is subject to change in a future release. Specify '--experimentalDecorators' to remove this warning." },
|
||||
Generators_are_only_available_when_targeting_ECMAScript_6_or_higher: { code: 1220, category: DiagnosticCategory.Error, key: "Generators are only available when targeting ECMAScript 6 or higher." },
|
||||
@@ -386,8 +388,13 @@ namespace ts {
|
||||
Cannot_find_namespace_0: { code: 2503, category: DiagnosticCategory.Error, key: "Cannot find namespace '{0}'." },
|
||||
No_best_common_type_exists_among_yield_expressions: { code: 2504, category: DiagnosticCategory.Error, key: "No best common type exists among yield expressions." },
|
||||
A_generator_cannot_have_a_void_type_annotation: { code: 2505, category: DiagnosticCategory.Error, key: "A generator cannot have a 'void' type annotation." },
|
||||
Cannot_create_an_instance_of_the_abstract_class_0: { code: 2506, category: DiagnosticCategory.Error, key: "Cannot create an instance of the abstract class '{0}'" },
|
||||
All_overload_signatures_must_match_with_respect_to_modifier_0: { code: 2507, category: DiagnosticCategory.Error, key: "All overload signatures must match with respect to modifier '{0}'." },
|
||||
_0_is_referenced_directly_or_indirectly_in_its_own_base_expression: { code: 2506, category: DiagnosticCategory.Error, key: "'{0}' is referenced directly or indirectly in its own base expression." },
|
||||
Base_expression_is_not_of_a_constructor_function_type: { code: 2507, category: DiagnosticCategory.Error, key: "Base expression is not of a constructor function type." },
|
||||
No_base_constructor_has_the_specified_number_of_type_arguments: { code: 2508, category: DiagnosticCategory.Error, key: "No base constructor has the specified number of type arguments." },
|
||||
Base_constructor_does_not_return_a_class_or_interface_type: { code: 2509, category: DiagnosticCategory.Error, key: "Base constructor does not return a class or interface type." },
|
||||
Base_constructors_must_all_have_the_same_return_type: { code: 2510, category: DiagnosticCategory.Error, key: "Base constructors must all have the same return type." },
|
||||
Cannot_create_an_instance_of_the_abstract_class_0: { code: 2511, category: DiagnosticCategory.Error, key: "Cannot create an instance of the abstract class '{0}'" },
|
||||
All_overload_signatures_must_match_with_respect_to_modifier_0: { code: 2512, category: DiagnosticCategory.Error, key: "All overload signatures must match with respect to modifier '{0}'." },
|
||||
Import_declaration_0_is_using_private_name_1: { code: 4000, category: DiagnosticCategory.Error, key: "Import declaration '{0}' is using private name '{1}'." },
|
||||
Type_parameter_0_of_exported_class_has_or_is_using_private_name_1: { code: 4002, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of exported class has or is using private name '{1}'." },
|
||||
Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1: { code: 4004, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of exported interface has or is using private name '{1}'." },
|
||||
|
||||
@@ -671,6 +671,14 @@
|
||||
"category": "Error",
|
||||
"code": 1213
|
||||
},
|
||||
"Identifier expected. '{0}' is a reserved word in strict mode. Modules are automatically in strict mode.": {
|
||||
"category": "Error",
|
||||
"code": 1214
|
||||
},
|
||||
"Invalid use of '{0}'. Modules are automatically in strict mode.": {
|
||||
"category": "Error",
|
||||
"code": 1215
|
||||
},
|
||||
"Export assignment is not supported when '--module' flag is 'system'.": {
|
||||
"category": "Error",
|
||||
"code": 1218
|
||||
@@ -1531,14 +1539,34 @@
|
||||
"category": "Error",
|
||||
"code": 2505
|
||||
},
|
||||
"Cannot create an instance of the abstract class '{0}'": {
|
||||
"'{0}' is referenced directly or indirectly in its own base expression.": {
|
||||
"category": "Error",
|
||||
"code": 2506
|
||||
},
|
||||
"All overload signatures must match with respect to modifier '{0}'.": {
|
||||
"Base expression is not of a constructor function type.": {
|
||||
"category": "Error",
|
||||
"code": 2507
|
||||
},
|
||||
"No base constructor has the specified number of type arguments.": {
|
||||
"category": "Error",
|
||||
"code": 2508
|
||||
},
|
||||
"Base constructor does not return a class or interface type.": {
|
||||
"category": "Error",
|
||||
"code": 2509
|
||||
},
|
||||
"Base constructors must all have the same return type.": {
|
||||
"category": "Error",
|
||||
"code": 2510
|
||||
},
|
||||
"Cannot create an instance of the abstract class '{0}'": {
|
||||
"category": "Error",
|
||||
"code": 2511
|
||||
},
|
||||
"All overload signatures must match with respect to modifier '{0}'.": {
|
||||
"category": "Error",
|
||||
"code": 2512
|
||||
},
|
||||
"Import declaration '{0}' is using private name '{1}'.": {
|
||||
"category": "Error",
|
||||
"code": 4000
|
||||
|
||||
+28
-69
@@ -544,7 +544,7 @@ namespace ts {
|
||||
token = nextToken();
|
||||
processReferenceComments(sourceFile);
|
||||
|
||||
sourceFile.statements = parseList(ParsingContext.SourceElements, /*checkForStrictMode*/ true, parseStatement);
|
||||
sourceFile.statements = parseList(ParsingContext.SourceElements, parseStatement);
|
||||
Debug.assert(token === SyntaxKind.EndOfFileToken);
|
||||
sourceFile.endOfFileToken = parseTokenNode();
|
||||
|
||||
@@ -647,10 +647,6 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
|
||||
function setStrictModeContext(val: boolean) {
|
||||
setContextFlag(val, ParserContextFlags.StrictMode);
|
||||
}
|
||||
|
||||
function setDisallowInContext(val: boolean) {
|
||||
setContextFlag(val, ParserContextFlags.DisallowIn);
|
||||
}
|
||||
@@ -744,10 +740,6 @@ namespace ts {
|
||||
return (contextFlags & ParserContextFlags.Yield) !== 0;
|
||||
}
|
||||
|
||||
function inStrictModeContext() {
|
||||
return (contextFlags & ParserContextFlags.StrictMode) !== 0;
|
||||
}
|
||||
|
||||
function inGeneratorParameterContext() {
|
||||
return (contextFlags & ParserContextFlags.GeneratorParameter) !== 0;
|
||||
}
|
||||
@@ -1328,31 +1320,17 @@ namespace ts {
|
||||
}
|
||||
|
||||
// Parses a list of elements
|
||||
function parseList<T extends Node>(kind: ParsingContext, checkForStrictMode: boolean, parseElement: () => T): NodeArray<T> {
|
||||
function parseList<T extends Node>(kind: ParsingContext, parseElement: () => T): NodeArray<T> {
|
||||
let saveParsingContext = parsingContext;
|
||||
parsingContext |= 1 << kind;
|
||||
let result = <NodeArray<T>>[];
|
||||
result.pos = getNodePos();
|
||||
let savedStrictModeContext = inStrictModeContext();
|
||||
|
||||
while (!isListTerminator(kind)) {
|
||||
if (isListElement(kind, /* inErrorRecovery */ false)) {
|
||||
let element = parseListElement(kind, parseElement);
|
||||
result.push(element);
|
||||
|
||||
// test elements only if we are not already in strict mode
|
||||
if (checkForStrictMode && !inStrictModeContext()) {
|
||||
if (isPrologueDirective(element)) {
|
||||
if (isUseStrictPrologueDirective(element)) {
|
||||
setStrictModeContext(true);
|
||||
checkForStrictMode = false;
|
||||
}
|
||||
}
|
||||
else {
|
||||
checkForStrictMode = false;
|
||||
}
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -1361,22 +1339,11 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
|
||||
setStrictModeContext(savedStrictModeContext);
|
||||
result.end = getNodeEnd();
|
||||
parsingContext = saveParsingContext;
|
||||
return result;
|
||||
}
|
||||
|
||||
/// Should be called only on prologue directives (isPrologueDirective(node) should be true)
|
||||
function isUseStrictPrologueDirective(node: Node): boolean {
|
||||
Debug.assert(isPrologueDirective(node));
|
||||
let nodeText = getTextOfNodeFromSourceText(sourceText, (<ExpressionStatement>node).expression);
|
||||
|
||||
// Note: the node text must be exactly "use strict" or 'use strict'. It is not ok for the
|
||||
// string to contain unicode escapes (as per ES5).
|
||||
return nodeText === '"use strict"' || nodeText === "'use strict'";
|
||||
}
|
||||
|
||||
function parseListElement<T extends Node>(parsingContext: ParsingContext, parseElement: () => T): T {
|
||||
let node = currentNode(parsingContext);
|
||||
if (node) {
|
||||
@@ -2281,7 +2248,7 @@ namespace ts {
|
||||
function parseObjectTypeMembers(): NodeArray<Declaration> {
|
||||
let members: NodeArray<Declaration>;
|
||||
if (parseExpected(SyntaxKind.OpenBraceToken)) {
|
||||
members = parseList(ParsingContext.TypeMembers, /*checkForStrictMode*/ false, parseTypeMember);
|
||||
members = parseList(ParsingContext.TypeMembers, parseTypeMember);
|
||||
parseExpected(SyntaxKind.CloseBraceToken);
|
||||
}
|
||||
else {
|
||||
@@ -2650,12 +2617,6 @@ namespace ts {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (inStrictModeContext()) {
|
||||
// If we're in strict mode, then 'yield' is a keyword, could only ever start
|
||||
// a yield expression.
|
||||
return true;
|
||||
}
|
||||
|
||||
// We're in a context where 'yield expr' is not allowed. However, if we can
|
||||
// definitely tell that the user was trying to parse a 'yield expr' and not
|
||||
// just a normal expr that start with a 'yield' identifier, then parse out
|
||||
@@ -2670,7 +2631,7 @@ namespace ts {
|
||||
// for now we just check if the next token is an identifier. More heuristics
|
||||
// can be added here later as necessary. We just need to make sure that we
|
||||
// don't accidently consume something legal.
|
||||
return lookAhead(nextTokenIsIdentifierOnSameLine);
|
||||
return lookAhead(nextTokenIsIdentifierOrKeywordOrNumberOnSameLine);
|
||||
}
|
||||
|
||||
return false;
|
||||
@@ -3513,10 +3474,10 @@ namespace ts {
|
||||
}
|
||||
|
||||
// STATEMENTS
|
||||
function parseBlock(ignoreMissingOpenBrace: boolean, checkForStrictMode: boolean, diagnosticMessage?: DiagnosticMessage): Block {
|
||||
function parseBlock(ignoreMissingOpenBrace: boolean, diagnosticMessage?: DiagnosticMessage): Block {
|
||||
let node = <Block>createNode(SyntaxKind.Block);
|
||||
if (parseExpected(SyntaxKind.OpenBraceToken, diagnosticMessage) || ignoreMissingOpenBrace) {
|
||||
node.statements = parseList(ParsingContext.BlockStatements, checkForStrictMode, parseStatement);
|
||||
node.statements = parseList(ParsingContext.BlockStatements, parseStatement);
|
||||
parseExpected(SyntaxKind.CloseBraceToken);
|
||||
}
|
||||
else {
|
||||
@@ -3536,7 +3497,7 @@ namespace ts {
|
||||
setDecoratorContext(false);
|
||||
}
|
||||
|
||||
let block = parseBlock(ignoreMissingOpenBrace, /*checkForStrictMode*/ true, diagnosticMessage);
|
||||
let block = parseBlock(ignoreMissingOpenBrace, diagnosticMessage);
|
||||
|
||||
if (saveDecoratorContext) {
|
||||
setDecoratorContext(true);
|
||||
@@ -3678,7 +3639,7 @@ namespace ts {
|
||||
parseExpected(SyntaxKind.CaseKeyword);
|
||||
node.expression = allowInAnd(parseExpression);
|
||||
parseExpected(SyntaxKind.ColonToken);
|
||||
node.statements = parseList(ParsingContext.SwitchClauseStatements, /*checkForStrictMode*/ false, parseStatement);
|
||||
node.statements = parseList(ParsingContext.SwitchClauseStatements, parseStatement);
|
||||
return finishNode(node);
|
||||
}
|
||||
|
||||
@@ -3686,7 +3647,7 @@ namespace ts {
|
||||
let node = <DefaultClause>createNode(SyntaxKind.DefaultClause);
|
||||
parseExpected(SyntaxKind.DefaultKeyword);
|
||||
parseExpected(SyntaxKind.ColonToken);
|
||||
node.statements = parseList(ParsingContext.SwitchClauseStatements, /*checkForStrictMode*/ false, parseStatement);
|
||||
node.statements = parseList(ParsingContext.SwitchClauseStatements, parseStatement);
|
||||
return finishNode(node);
|
||||
}
|
||||
|
||||
@@ -3702,7 +3663,7 @@ namespace ts {
|
||||
parseExpected(SyntaxKind.CloseParenToken);
|
||||
let caseBlock = <CaseBlock>createNode(SyntaxKind.CaseBlock, scanner.getStartPos());
|
||||
parseExpected(SyntaxKind.OpenBraceToken);
|
||||
caseBlock.clauses = parseList(ParsingContext.SwitchClauses, /*checkForStrictMode*/ false, parseCaseOrDefaultClause);
|
||||
caseBlock.clauses = parseList(ParsingContext.SwitchClauses, parseCaseOrDefaultClause);
|
||||
parseExpected(SyntaxKind.CloseBraceToken);
|
||||
node.caseBlock = finishNode(caseBlock);
|
||||
return finishNode(node);
|
||||
@@ -3729,14 +3690,14 @@ namespace ts {
|
||||
let node = <TryStatement>createNode(SyntaxKind.TryStatement);
|
||||
|
||||
parseExpected(SyntaxKind.TryKeyword);
|
||||
node.tryBlock = parseBlock(/*ignoreMissingOpenBrace*/ false, /*checkForStrictMode*/ false);
|
||||
node.tryBlock = parseBlock(/*ignoreMissingOpenBrace*/ false);
|
||||
node.catchClause = token === SyntaxKind.CatchKeyword ? parseCatchClause() : undefined;
|
||||
|
||||
// If we don't have a catch clause, then we must have a finally clause. Try to parse
|
||||
// one out no matter what.
|
||||
if (!node.catchClause || token === SyntaxKind.FinallyKeyword) {
|
||||
parseExpected(SyntaxKind.FinallyKeyword);
|
||||
node.finallyBlock = parseBlock(/*ignoreMissingOpenBrace*/ false, /*checkForStrictMode*/ false);
|
||||
node.finallyBlock = parseBlock(/*ignoreMissingOpenBrace*/ false);
|
||||
}
|
||||
|
||||
return finishNode(node);
|
||||
@@ -3750,7 +3711,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
parseExpected(SyntaxKind.CloseParenToken);
|
||||
result.block = parseBlock(/*ignoreMissingOpenBrace*/ false, /*checkForStrictMode*/ false);
|
||||
result.block = parseBlock(/*ignoreMissingOpenBrace*/ false);
|
||||
return finishNode(result);
|
||||
}
|
||||
|
||||
@@ -3791,6 +3752,11 @@ namespace ts {
|
||||
return isIdentifierOrKeyword() && !scanner.hasPrecedingLineBreak();
|
||||
}
|
||||
|
||||
function nextTokenIsIdentifierOrKeywordOrNumberOnSameLine() {
|
||||
nextToken();
|
||||
return (isIdentifierOrKeyword() || token === SyntaxKind.NumericLiteral) && !scanner.hasPrecedingLineBreak();
|
||||
}
|
||||
|
||||
function isDeclaration(): boolean {
|
||||
while (true) {
|
||||
switch (token) {
|
||||
@@ -3919,16 +3885,15 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
|
||||
function nextTokenIsIdentifierOrStartOfDestructuringOnTheSameLine() {
|
||||
function nextTokenIsIdentifierOrStartOfDestructuring() {
|
||||
nextToken();
|
||||
return !scanner.hasPrecedingLineBreak() &&
|
||||
(isIdentifier() || token === SyntaxKind.OpenBraceToken || token === SyntaxKind.OpenBracketToken);
|
||||
return isIdentifier() || token === SyntaxKind.OpenBraceToken || token === SyntaxKind.OpenBracketToken;
|
||||
}
|
||||
|
||||
function isLetDeclaration() {
|
||||
// It is let declaration if in strict mode or next token is identifier\open bracket\open curly on same line.
|
||||
// otherwise it needs to be treated like identifier
|
||||
return inStrictModeContext() || lookAhead(nextTokenIsIdentifierOrStartOfDestructuringOnTheSameLine);
|
||||
// In ES6 'let' always starts a lexical declaration if followed by an identifier or {
|
||||
// or [.
|
||||
return lookAhead(nextTokenIsIdentifierOrStartOfDestructuring);
|
||||
}
|
||||
|
||||
function parseStatement(): Statement {
|
||||
@@ -3936,7 +3901,7 @@ namespace ts {
|
||||
case SyntaxKind.SemicolonToken:
|
||||
return parseEmptyStatement();
|
||||
case SyntaxKind.OpenBraceToken:
|
||||
return parseBlock(/*ignoreMissingOpenBrace*/ false, /*checkForStrictMode*/ false);
|
||||
return parseBlock(/*ignoreMissingOpenBrace*/ false);
|
||||
case SyntaxKind.VarKeyword:
|
||||
return parseVariableStatement(scanner.getStartPos(), /*decorators*/ undefined, /*modifiers*/ undefined);
|
||||
case SyntaxKind.LetKeyword:
|
||||
@@ -4455,10 +4420,6 @@ namespace ts {
|
||||
}
|
||||
|
||||
function parseClassDeclarationOrExpression(fullStart: number, decorators: NodeArray<Decorator>, modifiers: ModifiersArray, kind: SyntaxKind): ClassLikeDeclaration {
|
||||
// In ES6 specification, All parts of a ClassDeclaration or a ClassExpression are strict mode code
|
||||
let savedStrictModeContext = inStrictModeContext();
|
||||
setStrictModeContext(true);
|
||||
|
||||
var node = <ClassLikeDeclaration>createNode(kind, fullStart);
|
||||
node.decorators = decorators;
|
||||
setModifiers(node, modifiers);
|
||||
@@ -4481,9 +4442,7 @@ namespace ts {
|
||||
node.members = createMissingList<ClassElement>();
|
||||
}
|
||||
|
||||
var finishedNode = finishNode(node);
|
||||
setStrictModeContext(savedStrictModeContext);
|
||||
return finishedNode;
|
||||
return finishNode(node);
|
||||
}
|
||||
|
||||
function parseHeritageClauses(isClassHeritageClause: boolean): NodeArray<HeritageClause> {
|
||||
@@ -4501,7 +4460,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
function parseHeritageClausesWorker() {
|
||||
return parseList(ParsingContext.HeritageClauses, /*checkForStrictMode*/ false, parseHeritageClause);
|
||||
return parseList(ParsingContext.HeritageClauses, parseHeritageClause);
|
||||
}
|
||||
|
||||
function parseHeritageClause() {
|
||||
@@ -4531,7 +4490,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
function parseClassMembers() {
|
||||
return parseList(ParsingContext.ClassMembers, /*checkForStrictMode*/ false, parseClassElement);
|
||||
return parseList(ParsingContext.ClassMembers, parseClassElement);
|
||||
}
|
||||
|
||||
function parseInterfaceDeclaration(fullStart: number, decorators: NodeArray<Decorator>, modifiers: ModifiersArray): InterfaceDeclaration {
|
||||
@@ -4589,7 +4548,7 @@ namespace ts {
|
||||
function parseModuleBlock(): ModuleBlock {
|
||||
let node = <ModuleBlock>createNode(SyntaxKind.ModuleBlock, scanner.getStartPos());
|
||||
if (parseExpected(SyntaxKind.OpenBraceToken)) {
|
||||
node.statements = parseList(ParsingContext.BlockStatements, /*checkForStrictMode*/ false, parseStatement);
|
||||
node.statements = parseList(ParsingContext.BlockStatements, parseStatement);
|
||||
parseExpected(SyntaxKind.CloseBraceToken);
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -364,10 +364,6 @@ namespace ts {
|
||||
export const enum ParserContextFlags {
|
||||
None = 0,
|
||||
|
||||
// Set if this node was parsed in strict mode. Used for grammar error checks, as well as
|
||||
// checking if the node can be reused in incremental settings.
|
||||
StrictMode = 1 << 0,
|
||||
|
||||
// If this node was parsed in a context where 'in-expressions' are not allowed.
|
||||
DisallowIn = 1 << 1,
|
||||
|
||||
@@ -390,7 +386,7 @@ namespace ts {
|
||||
JavaScriptFile = 1 << 6,
|
||||
|
||||
// Context flags set directly by the parser.
|
||||
ParserGeneratedFlags = StrictMode | DisallowIn | Yield | GeneratorParameter | Decorator | ThisNodeHasError,
|
||||
ParserGeneratedFlags = DisallowIn | Yield | GeneratorParameter | Decorator | ThisNodeHasError,
|
||||
|
||||
// Context flags computed by aggregating child flags upwards.
|
||||
|
||||
@@ -1675,10 +1671,8 @@ namespace ts {
|
||||
typeParameters: TypeParameter[]; // Type parameters (undefined if non-generic)
|
||||
outerTypeParameters: TypeParameter[]; // Outer type parameters (undefined if none)
|
||||
localTypeParameters: TypeParameter[]; // Local type parameters (undefined if none)
|
||||
}
|
||||
|
||||
export interface InterfaceTypeWithBaseTypes extends InterfaceType {
|
||||
baseTypes: ObjectType[];
|
||||
resolvedBaseConstructorType?: Type; // Resolved base constructor type of class
|
||||
resolvedBaseTypes: ObjectType[]; // Resolved base types
|
||||
}
|
||||
|
||||
export interface InterfaceTypeWithDeclaredMembers extends InterfaceType {
|
||||
|
||||
@@ -426,7 +426,7 @@ namespace ts {
|
||||
// Specialized signatures can have string literals as their parameters' type names
|
||||
return node.parent.kind === SyntaxKind.Parameter;
|
||||
case SyntaxKind.ExpressionWithTypeArguments:
|
||||
return true;
|
||||
return !isClassExtendsExpressionWithTypeArguments(node);
|
||||
|
||||
// Identifiers and qualified names may be type nodes, depending on their context. Climb
|
||||
// above them to find the lowest container
|
||||
@@ -460,7 +460,7 @@ namespace ts {
|
||||
}
|
||||
switch (parent.kind) {
|
||||
case SyntaxKind.ExpressionWithTypeArguments:
|
||||
return true;
|
||||
return !isClassExtendsExpressionWithTypeArguments(parent);
|
||||
case SyntaxKind.TypeParameter:
|
||||
return node === (<TypeParameterDeclaration>parent).constraint;
|
||||
case SyntaxKind.PropertyDeclaration:
|
||||
@@ -872,7 +872,6 @@ namespace ts {
|
||||
while (node.parent.kind === SyntaxKind.QualifiedName) {
|
||||
node = node.parent;
|
||||
}
|
||||
|
||||
return node.parent.kind === SyntaxKind.TypeQuery;
|
||||
case SyntaxKind.Identifier:
|
||||
if (node.parent.kind === SyntaxKind.TypeQuery) {
|
||||
@@ -920,6 +919,8 @@ namespace ts {
|
||||
return node === (<ComputedPropertyName>parent).expression;
|
||||
case SyntaxKind.Decorator:
|
||||
return true;
|
||||
case SyntaxKind.ExpressionWithTypeArguments:
|
||||
return isClassExtendsExpressionWithTypeArguments(parent);
|
||||
default:
|
||||
if (isExpression(parent)) {
|
||||
return true;
|
||||
@@ -1915,6 +1916,12 @@ namespace ts {
|
||||
return token >= SyntaxKind.FirstAssignment && token <= SyntaxKind.LastAssignment;
|
||||
}
|
||||
|
||||
export function isClassExtendsExpressionWithTypeArguments(node: Node): boolean {
|
||||
return node.kind === SyntaxKind.ExpressionWithTypeArguments &&
|
||||
(<HeritageClause>node.parent).token === SyntaxKind.ExtendsKeyword &&
|
||||
node.parent.parent.kind === SyntaxKind.ClassDeclaration;
|
||||
}
|
||||
|
||||
// Returns false if this heritage clause element's expression contains something unsupported
|
||||
// (i.e. not a name or dotted name).
|
||||
export function isSupportedExpressionWithTypeArguments(node: ExpressionWithTypeArguments): boolean {
|
||||
|
||||
@@ -41,7 +41,10 @@ class TypeWriterWalker {
|
||||
var lineAndCharacter = this.currentSourceFile.getLineAndCharacterOfPosition(actualPos);
|
||||
var sourceText = ts.getTextOfNodeFromSourceText(this.currentSourceFile.text, node);
|
||||
|
||||
var type = this.checker.getTypeAtLocation(node);
|
||||
// Workaround to ensure we output 'C' instead of 'typeof C' for base class expressions
|
||||
// var type = this.checker.getTypeAtLocation(node);
|
||||
var type = node.parent && ts.isClassExtendsExpressionWithTypeArguments(node.parent) && this.checker.getTypeAtLocation(node.parent) || this.checker.getTypeAtLocation(node);
|
||||
|
||||
ts.Debug.assert(type !== undefined, "type doesn't exist");
|
||||
var symbol = this.checker.getSymbolAtLocation(node);
|
||||
|
||||
|
||||
@@ -5813,7 +5813,8 @@ namespace ts {
|
||||
node = node.parent;
|
||||
}
|
||||
|
||||
return node.parent.kind === SyntaxKind.TypeReference || node.parent.kind === SyntaxKind.ExpressionWithTypeArguments;
|
||||
return node.parent.kind === SyntaxKind.TypeReference ||
|
||||
(node.parent.kind === SyntaxKind.ExpressionWithTypeArguments && !isClassExtendsExpressionWithTypeArguments(<ExpressionWithTypeArguments>node.parent));
|
||||
}
|
||||
|
||||
function isNamespaceReference(node: Node): boolean {
|
||||
|
||||
Reference in New Issue
Block a user