mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-22 22:55:36 -05:00
Port fidelity changes to github.
This commit is contained in:
@@ -42,6 +42,10 @@ module TypeScript {
|
||||
walker.walk(preAst.typeArguments);
|
||||
}
|
||||
|
||||
function walkTupleTypeChildren(preAst: TupleTypeSyntax, walker: AstWalker): void {
|
||||
walker.walk(preAst.types);
|
||||
}
|
||||
|
||||
function walkTypeOfExpressionChildren(preAst: TypeOfExpressionSyntax, walker: AstWalker): void {
|
||||
walker.walk(preAst.expression);
|
||||
}
|
||||
@@ -561,6 +565,7 @@ module TypeScript {
|
||||
childrenWalkers[SyntaxKind.TriviaList] = null;
|
||||
childrenWalkers[SyntaxKind.TrueKeyword] = null;
|
||||
childrenWalkers[SyntaxKind.TryStatement] = walkTryStatementChildren;
|
||||
childrenWalkers[SyntaxKind.TupleType] = walkTupleTypeChildren;
|
||||
childrenWalkers[SyntaxKind.TypeAnnotation] = walkTypeAnnotationChildren;
|
||||
childrenWalkers[SyntaxKind.TypeArgumentList] = walkTypeArgumentListChildren;
|
||||
childrenWalkers[SyntaxKind.TypeOfExpression] = walkTypeOfExpressionChildren;
|
||||
|
||||
@@ -42,6 +42,10 @@ module TypeScript {
|
||||
return this.defaultVisit(node);
|
||||
}
|
||||
|
||||
public visitTupleType(node: TupleTypeSyntax): any {
|
||||
return this.defaultVisit(node);
|
||||
}
|
||||
|
||||
public visitInterfaceDeclaration(node: InterfaceDeclarationSyntax): any {
|
||||
return this.defaultVisit(node);
|
||||
}
|
||||
|
||||
@@ -1048,6 +1048,7 @@ module TypeScript.Parser {
|
||||
case SyntaxKind.ExportKeyword:
|
||||
case SyntaxKind.PublicKeyword:
|
||||
case SyntaxKind.PrivateKeyword:
|
||||
case SyntaxKind.ProtectedKeyword:
|
||||
case SyntaxKind.StaticKeyword:
|
||||
case SyntaxKind.DeclareKeyword:
|
||||
return true;
|
||||
@@ -1434,6 +1435,19 @@ module TypeScript.Parser {
|
||||
return new syntaxFactory.ObjectTypeSyntax(parseNodeData, openBraceToken, typeMembers, eatToken(SyntaxKind.CloseBraceToken));
|
||||
}
|
||||
|
||||
function parseTupleType(currentToken: ISyntaxToken): TupleTypeSyntax {
|
||||
var openBracket = consumeToken(currentToken);
|
||||
|
||||
var types = Syntax.emptySeparatedList<ITypeSyntax>();
|
||||
if (openBracket.fullWidth() > 0) {
|
||||
var skippedTokens: ISyntaxToken[] = getArray();
|
||||
types = parseSeparatedSyntaxList<ITypeSyntax>(ListParsingState.TupleType_Types, skippedTokens);
|
||||
openBracket = addSkippedTokensAfterToken(openBracket, skippedTokens);
|
||||
}
|
||||
|
||||
return new syntaxFactory.TupleTypeSyntax(parseNodeData, openBracket, types, eatToken(SyntaxKind.CloseBracketToken));
|
||||
}
|
||||
|
||||
function isTypeMember(inErrorRecovery: boolean): boolean {
|
||||
if (SyntaxUtilities.isTypeMember(currentNode())) {
|
||||
return true;
|
||||
@@ -1663,6 +1677,7 @@ module TypeScript.Parser {
|
||||
// ERROR RECOVERY
|
||||
case SyntaxKind.PublicKeyword:
|
||||
case SyntaxKind.PrivateKeyword:
|
||||
case SyntaxKind.ProtectedKeyword:
|
||||
case SyntaxKind.StaticKeyword:
|
||||
// None of the above are actually keywords. And they might show up in a real
|
||||
// statement (i.e. "public();"). However, if we see 'public <identifier>' then
|
||||
@@ -1731,6 +1746,7 @@ module TypeScript.Parser {
|
||||
// ERROR RECOVERY
|
||||
case SyntaxKind.PublicKeyword:
|
||||
case SyntaxKind.PrivateKeyword:
|
||||
case SyntaxKind.ProtectedKeyword:
|
||||
case SyntaxKind.StaticKeyword:
|
||||
// None of the above are actually keywords. And they might show up in a real
|
||||
// statement (i.e. "public();"). However, if we see 'public <identifier>' then
|
||||
@@ -3133,7 +3149,7 @@ module TypeScript.Parser {
|
||||
token2 = peekToken(2);
|
||||
token2Kind = token2.kind();
|
||||
|
||||
if (token1Kind === SyntaxKind.PublicKeyword || token1Kind === SyntaxKind.PrivateKeyword) {
|
||||
if (SyntaxFacts.isAccessibilityModifier(token1Kind)) {
|
||||
if (isIdentifier(token2)) {
|
||||
// "(public id" or "(function id". Definitely an arrow function. Could never
|
||||
// be a parenthesized expression. Note: this will be an *illegal* arrow
|
||||
@@ -3557,11 +3573,12 @@ module TypeScript.Parser {
|
||||
|
||||
return consumeToken(_currentToken);
|
||||
case SyntaxKind.OpenParenToken:
|
||||
case SyntaxKind.LessThanToken: return tryParseFunctionType();
|
||||
case SyntaxKind.VoidKeyword: return consumeToken(_currentToken);
|
||||
case SyntaxKind.OpenBraceToken: return parseObjectType();
|
||||
case SyntaxKind.NewKeyword: return parseConstructorType();
|
||||
case SyntaxKind.TypeOfKeyword: return parseTypeQuery(_currentToken);
|
||||
case SyntaxKind.LessThanToken: return tryParseFunctionType();
|
||||
case SyntaxKind.VoidKeyword: return consumeToken(_currentToken);
|
||||
case SyntaxKind.OpenBraceToken: return parseObjectType();
|
||||
case SyntaxKind.NewKeyword: return parseConstructorType();
|
||||
case SyntaxKind.TypeOfKeyword: return parseTypeQuery(_currentToken);
|
||||
case SyntaxKind.OpenBracketToken: return parseTupleType(_currentToken);
|
||||
}
|
||||
|
||||
return tryParseNameOrGenericType();
|
||||
@@ -3973,6 +3990,7 @@ module TypeScript.Parser {
|
||||
case ListParsingState.IndexSignature_Parameters: return isExpectedIndexSignature_ParametersTerminator();
|
||||
case ListParsingState.TypeArgumentList_Types: return isExpectedTypeArgumentList_TypesTerminator();
|
||||
case ListParsingState.TypeParameterList_TypeParameters: return isExpectedTypeParameterList_TypeParametersTerminator();
|
||||
case ListParsingState.TupleType_Types: return isExpectedTupleType_TypesTerminator();
|
||||
default:
|
||||
throw Errors.invalidOperation();
|
||||
}
|
||||
@@ -4019,6 +4037,17 @@ module TypeScript.Parser {
|
||||
return false;
|
||||
}
|
||||
|
||||
function isExpectedTupleType_TypesTerminator(): boolean {
|
||||
var token = currentToken();
|
||||
var tokenKind = token.kind();
|
||||
if (tokenKind === SyntaxKind.CloseBracketToken) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// TODO: add more cases as necessary for error tolerance.
|
||||
return false;
|
||||
}
|
||||
|
||||
function isExpectedTypeParameterList_TypeParametersTerminator(): boolean {
|
||||
var tokenKind = currentToken().kind();
|
||||
if (tokenKind === SyntaxKind.GreaterThanToken) {
|
||||
@@ -4187,7 +4216,8 @@ module TypeScript.Parser {
|
||||
case ListParsingState.IndexSignature_Parameters: return isParameter();
|
||||
case ListParsingState.TypeArgumentList_Types: return isType();
|
||||
case ListParsingState.TypeParameterList_TypeParameters: return isTypeParameter();
|
||||
default: throw Errors.invalidOperation();
|
||||
case ListParsingState.TupleType_Types: return isType();
|
||||
default: throw Errors.invalidOperation();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4230,6 +4260,7 @@ module TypeScript.Parser {
|
||||
case ListParsingState.IndexSignature_Parameters: return tryParseParameter();
|
||||
case ListParsingState.TypeArgumentList_Types: return tryParseType();
|
||||
case ListParsingState.TypeParameterList_TypeParameters: return tryParseTypeParameter();
|
||||
case ListParsingState.TupleType_Types: return tryParseType();
|
||||
default: throw Errors.invalidOperation();
|
||||
}
|
||||
}
|
||||
@@ -4254,6 +4285,7 @@ module TypeScript.Parser {
|
||||
case ListParsingState.IndexSignature_Parameters: return getLocalizedText(DiagnosticCode.parameter, null);
|
||||
case ListParsingState.TypeArgumentList_Types: return getLocalizedText(DiagnosticCode.type, null);
|
||||
case ListParsingState.TypeParameterList_TypeParameters: return getLocalizedText(DiagnosticCode.type_parameter, null);
|
||||
case ListParsingState.TupleType_Types: return getLocalizedText(DiagnosticCode.type, null);
|
||||
case ListParsingState.ArrayLiteralExpression_AssignmentExpressions: return getLocalizedText(DiagnosticCode.expression, null);
|
||||
default: throw Errors.invalidOperation();
|
||||
}
|
||||
@@ -4376,9 +4408,10 @@ module TypeScript.Parser {
|
||||
IndexSignature_Parameters = 18,
|
||||
TypeArgumentList_Types = 19,
|
||||
TypeParameterList_TypeParameters = 20,
|
||||
TupleType_Types = 21,
|
||||
|
||||
FirstListParsingState = SourceUnit_ModuleElements,
|
||||
LastListParsingState = TypeParameterList_TypeParameters,
|
||||
LastListParsingState = TupleType_Types,
|
||||
}
|
||||
|
||||
// We keep the parser around as a singleton. This is because calling createParser is actually
|
||||
|
||||
@@ -421,6 +421,12 @@ module TypeScript.PrettyPrinter {
|
||||
this.appendToken(node.greaterThanToken);
|
||||
}
|
||||
|
||||
public visitTupleType(node: TupleTypeSyntax): void {
|
||||
this.appendToken(node.openBracketToken);
|
||||
this.appendSeparatorSpaceList(node.types);
|
||||
this.appendToken(node.closeBracketToken);
|
||||
}
|
||||
|
||||
public visitConstructorType(node: ConstructorTypeSyntax): void {
|
||||
this.appendToken(node.newKeyword);
|
||||
this.ensureSpace();
|
||||
|
||||
@@ -26,4 +26,15 @@ module TypeScript.SyntaxFacts {
|
||||
var tokenKind = token.kind();
|
||||
return tokenKind === SyntaxKind.IdentifierName || SyntaxFacts.isAnyKeyword(tokenKind);
|
||||
}
|
||||
|
||||
export function isAccessibilityModifier(kind: SyntaxKind): boolean {
|
||||
switch (kind) {
|
||||
case SyntaxKind.PublicKeyword:
|
||||
case SyntaxKind.PrivateKeyword:
|
||||
case SyntaxKind.ProtectedKeyword:
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -354,6 +354,17 @@ var definitions:ITypeDefinition[] = [
|
||||
],
|
||||
isTypeScriptSpecific: true
|
||||
},
|
||||
<any> {
|
||||
name: 'TupleTypeSyntax',
|
||||
baseType: 'ISyntaxNode',
|
||||
interfaces: ['ITypeSyntax'],
|
||||
children: [
|
||||
<any>{ name: 'openBracketToken', isToken: true, excludeFromAST: true },
|
||||
<any>{ name: 'types', isSeparatedList: true, elementType: 'ITypeSyntax' },
|
||||
<any>{ name: 'closeBracketToken', isToken: true, excludeFromAST: true }
|
||||
],
|
||||
isTypeScriptSpecific: true
|
||||
},
|
||||
<any>{
|
||||
name: 'TypeAnnotationSyntax',
|
||||
baseType: 'ISyntaxNode',
|
||||
|
||||
@@ -158,6 +158,7 @@ module TypeScript {
|
||||
ConstructorType,
|
||||
GenericType,
|
||||
TypeQuery,
|
||||
TupleType,
|
||||
|
||||
// Module elements.
|
||||
InterfaceDeclaration,
|
||||
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -84,6 +84,7 @@ module TypeScript {
|
||||
private cacheSyntaxTreeInfo(): void {
|
||||
// If we're not keeping around the syntax tree, store the diagnostics and line
|
||||
// map so they don't have to be recomputed.
|
||||
var sourceUnit = this.sourceUnit();
|
||||
var firstToken = firstSyntaxTreeToken(this);
|
||||
var leadingTrivia = firstToken.leadingTrivia(this.text);
|
||||
|
||||
@@ -238,7 +239,7 @@ module TypeScript {
|
||||
}
|
||||
|
||||
private checkParameterAccessibilityModifier(parameterList: ParameterListSyntax, modifier: ISyntaxToken, modifierIndex: number): boolean {
|
||||
if (modifier.kind() !== SyntaxKind.PublicKeyword && modifier.kind() !== SyntaxKind.PrivateKeyword) {
|
||||
if (!SyntaxFacts.isAccessibilityModifier(modifier.kind())) {
|
||||
this.pushDiagnostic(modifier, DiagnosticCode._0_modifier_cannot_appear_on_a_parameter, [modifier.text()]);
|
||||
return true;
|
||||
}
|
||||
@@ -320,6 +321,15 @@ module TypeScript {
|
||||
super.visitTypeArgumentList(node);
|
||||
}
|
||||
|
||||
public visitTupleType(node: TupleTypeSyntax): void {
|
||||
if (this.checkForTrailingComma(node.types) ||
|
||||
this.checkForAtLeastOneElement(node, node.types, node.openBracketToken, getLocalizedText(DiagnosticCode.type, null))) {
|
||||
return
|
||||
}
|
||||
|
||||
super.visitTupleType(node);
|
||||
}
|
||||
|
||||
public visitTypeParameterList(node: TypeParameterListSyntax): void {
|
||||
if (this.checkForTrailingComma(node.typeParameters) ||
|
||||
this.checkForAtLeastOneElement(node, node.typeParameters, node.lessThanToken, getLocalizedText(DiagnosticCode.type_parameter, null))) {
|
||||
@@ -514,9 +524,7 @@ module TypeScript {
|
||||
|
||||
for (var i = 0, n = list.length; i < n; i++) {
|
||||
var modifier = list[i];
|
||||
if (modifier.kind() === SyntaxKind.PublicKeyword ||
|
||||
modifier.kind() === SyntaxKind.PrivateKeyword) {
|
||||
|
||||
if (SyntaxFacts.isAccessibilityModifier(modifier.kind())) {
|
||||
if (seenAccessibilityModifier) {
|
||||
this.pushDiagnostic(modifier, DiagnosticCode.Accessibility_modifier_already_seen);
|
||||
return true;
|
||||
@@ -751,8 +759,7 @@ module TypeScript {
|
||||
|
||||
for (var i = 0, n = modifiers.length; i < n; i++) {
|
||||
var modifier = modifiers[i];
|
||||
if (modifier.kind() === SyntaxKind.PublicKeyword ||
|
||||
modifier.kind() === SyntaxKind.PrivateKeyword ||
|
||||
if (SyntaxFacts.isAccessibilityModifier(modifier.kind()) ||
|
||||
modifier.kind() === SyntaxKind.StaticKeyword) {
|
||||
this.pushDiagnostic(modifier, DiagnosticCode._0_modifier_cannot_appear_on_a_module_element, [modifier.text()]);
|
||||
return true;
|
||||
|
||||
@@ -13,6 +13,7 @@ module TypeScript {
|
||||
case SyntaxKind.ConstructorType: return visitor.visitConstructorType(<ConstructorTypeSyntax>element);
|
||||
case SyntaxKind.GenericType: return visitor.visitGenericType(<GenericTypeSyntax>element);
|
||||
case SyntaxKind.TypeQuery: return visitor.visitTypeQuery(<TypeQuerySyntax>element);
|
||||
case SyntaxKind.TupleType: return visitor.visitTupleType(<TupleTypeSyntax>element);
|
||||
case SyntaxKind.InterfaceDeclaration: return visitor.visitInterfaceDeclaration(<InterfaceDeclarationSyntax>element);
|
||||
case SyntaxKind.FunctionDeclaration: return visitor.visitFunctionDeclaration(<FunctionDeclarationSyntax>element);
|
||||
case SyntaxKind.ModuleDeclaration: return visitor.visitModuleDeclaration(<ModuleDeclarationSyntax>element);
|
||||
@@ -109,6 +110,7 @@ module TypeScript {
|
||||
visitConstructorType(node: ConstructorTypeSyntax): any;
|
||||
visitGenericType(node: GenericTypeSyntax): any;
|
||||
visitTypeQuery(node: TypeQuerySyntax): any;
|
||||
visitTupleType(node: TupleTypeSyntax): any;
|
||||
visitInterfaceDeclaration(node: InterfaceDeclarationSyntax): any;
|
||||
visitFunctionDeclaration(node: FunctionDeclarationSyntax): any;
|
||||
visitModuleDeclaration(node: ModuleDeclarationSyntax): any;
|
||||
|
||||
@@ -103,6 +103,12 @@ module TypeScript {
|
||||
this.visitNodeOrToken(node.name);
|
||||
}
|
||||
|
||||
public visitTupleType(node: TupleTypeSyntax): void {
|
||||
this.visitToken(node.openBracketToken);
|
||||
this.visitSeparatedList(node.types);
|
||||
this.visitToken(node.closeBracketToken);
|
||||
}
|
||||
|
||||
public visitInterfaceDeclaration(node: InterfaceDeclarationSyntax): void {
|
||||
this.visitList(node.modifiers);
|
||||
this.visitToken(node.interfaceKeyword);
|
||||
|
||||
Reference in New Issue
Block a user