mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Merge pull request #1021 from Microsoft/incrementalPerf
Move back to how we used to walk trees for incremental parsing perf.
This commit is contained in:
commit
756cc7b146
19 files changed
+2238
-1596
No files matched your search
@@ -104,8 +104,8 @@ module TypeScript.Services.Formatting {
|
||||
this.visitToken(<ISyntaxToken>element);
|
||||
}
|
||||
else if (element.kind() === SyntaxKind.List || element.kind() === SyntaxKind.SeparatedList) {
|
||||
for (var i = 0, n = childCount(element); i < n; i++) {
|
||||
this.walk(childAt(element, i));
|
||||
for (var i = 0, n = element.childCount(); i < n; i++) {
|
||||
this.walk(element.childAt(i));
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -126,8 +126,8 @@ module TypeScript.Services.Formatting {
|
||||
this._parent = this._indentationNodeContextPool.getNode(currentParent, node, this._position, indentation.indentationAmount, indentation.indentationAmountDelta);
|
||||
|
||||
// Visit node
|
||||
for (var i = 0, n = childCount(node); i < n; i++) {
|
||||
this.walk(childAt(node, i));
|
||||
for (var i = 0, n = node.childCount(); i < n; i++) {
|
||||
this.walk(node.childAt(i));
|
||||
}
|
||||
|
||||
// Reset state
|
||||
|
||||
@@ -66,7 +66,7 @@ module TypeScript.IncrementalParser {
|
||||
|
||||
// Start the cursor pointing at the first element in the source unit (if it exists).
|
||||
if (oldSourceUnit.moduleElements.length > 0) {
|
||||
_oldSourceUnitCursor.pushElement(childAt(oldSourceUnit.moduleElements, 0), /*indexInParent:*/ 0);
|
||||
_oldSourceUnitCursor.pushElement(oldSourceUnit.moduleElements.childAt(0), /*indexInParent:*/ 0);
|
||||
}
|
||||
|
||||
// In general supporting multiple individual edits is just not that important. So we
|
||||
@@ -719,8 +719,8 @@ module TypeScript.IncrementalParser {
|
||||
// Either the node has some existent child, then move to it. if it doesn't, then it's
|
||||
// an empty node. Conceptually the first child of an empty node is really just the
|
||||
// next sibling of the empty node.
|
||||
for (var i = 0, n = childCount(nodeOrToken); i < n; i++) {
|
||||
var child = childAt(nodeOrToken, i);
|
||||
for (var i = 0, n = nodeOrToken.childCount(); i < n; i++) {
|
||||
var child = nodeOrToken.childAt(i);
|
||||
if (child && !isShared(child)) {
|
||||
// Great, we found a real child. Push that.
|
||||
pushElement(child, /*indexInParent:*/ i);
|
||||
@@ -746,8 +746,8 @@ module TypeScript.IncrementalParser {
|
||||
var parent = currentPiece.element.parent;
|
||||
|
||||
// We start searching at the index one past our own index in the parent.
|
||||
for (var i = currentPiece.indexInParent + 1, n = childCount(parent); i < n; i++) {
|
||||
var sibling = childAt(parent, i);
|
||||
for (var i = currentPiece.indexInParent + 1, n = parent.childCount(); i < n; i++) {
|
||||
var sibling = parent.childAt(i);
|
||||
|
||||
if (sibling && !isShared(sibling)) {
|
||||
// We found a good sibling that we can move to. Just reuse our existing piece
|
||||
@@ -782,7 +782,7 @@ module TypeScript.IncrementalParser {
|
||||
// we make sure to filter that out before pushing any children.
|
||||
// Debug.assert(childCount(element) > 0);
|
||||
|
||||
pushElement(childAt(element, 0), /*indexInParent:*/ 0);
|
||||
pushElement(element.childAt(0), /*indexInParent:*/ 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -594,8 +594,8 @@ module TypeScript.Parser {
|
||||
}
|
||||
else if (isSeparatedList(parent)) {
|
||||
var list2 = <ISyntaxNodeOrToken[]>parent;
|
||||
for (var i = 0, n = childCount(list2); i < n; i++) {
|
||||
if (childAt(list2, i) === oldToken) {
|
||||
for (var i = 0, n = list2.childCount(); i < n; i++) {
|
||||
if (list2.childAt(i) === oldToken) {
|
||||
if (i % 2 === 0) {
|
||||
list2[i / 2] = newToken;
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ module TypeScript.PrettyPrinter {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (childCount(element1.statements) === 0) {
|
||||
if (element1.statements.childCount() === 0) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -131,12 +131,12 @@ module TypeScript.PrettyPrinter {
|
||||
}
|
||||
|
||||
private appendSpaceList(list: ISyntaxNodeOrToken[]): void {
|
||||
for (var i = 0, n = childCount(list); i < n; i++) {
|
||||
if (isNode(childAt(list, i))) {
|
||||
this.appendNode(<ISyntaxNode>childAt(list, i));
|
||||
for (var i = 0, n = list.childCount(); i < n; i++) {
|
||||
if (isNode(list.childAt(i))) {
|
||||
this.appendNode(<ISyntaxNode>list.childAt(i));
|
||||
}
|
||||
else {
|
||||
this.appendToken(<ISyntaxToken>childAt(list, i));
|
||||
this.appendToken(<ISyntaxToken>list.childAt(i));
|
||||
}
|
||||
|
||||
this.ensureSpace();
|
||||
@@ -144,31 +144,31 @@ module TypeScript.PrettyPrinter {
|
||||
}
|
||||
|
||||
private appendSeparatorSpaceList(list: ISyntaxNodeOrToken[]): void {
|
||||
for (var i = 0, n = childCount(list); i < n; i++) {
|
||||
for (var i = 0, n = list.childCount(); i < n; i++) {
|
||||
if (i % 2 === 0) {
|
||||
if (i > 0) {
|
||||
this.ensureSpace();
|
||||
}
|
||||
|
||||
visitNodeOrToken(this, childAt(list, i));
|
||||
visitNodeOrToken(this, list.childAt(i));
|
||||
}
|
||||
else {
|
||||
this.appendToken(<ISyntaxToken>childAt(list, i));
|
||||
this.appendToken(<ISyntaxToken>list.childAt(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private appendSeparatorNewLineList(list: ISyntaxNodeOrToken[]): void {
|
||||
for (var i = 0, n = childCount(list); i < n; i++) {
|
||||
for (var i = 0, n = list.childCount(); i < n; i++) {
|
||||
if (i % 2 === 0) {
|
||||
if (i > 0) {
|
||||
this.ensureNewLine();
|
||||
}
|
||||
|
||||
visitNodeOrToken(this, childAt(list, i));
|
||||
visitNodeOrToken(this, list.childAt(i));
|
||||
}
|
||||
else {
|
||||
this.appendToken(<ISyntaxToken>childAt(list, i));
|
||||
this.appendToken(<ISyntaxToken>list.childAt(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -277,8 +277,8 @@ module TypeScript.PrettyPrinter {
|
||||
this.ensureSpace();
|
||||
}
|
||||
|
||||
for (var i = 0, n = childCount(node.typeMembers); i < n; i++) {
|
||||
visitNodeOrToken(this, childAt(node.typeMembers, i));
|
||||
for (var i = 0, n = node.typeMembers.childCount(); i < n; i++) {
|
||||
visitNodeOrToken(this, node.typeMembers.childAt(i));
|
||||
|
||||
if (appendNewLines) {
|
||||
this.ensureNewLine();
|
||||
@@ -774,11 +774,11 @@ module TypeScript.PrettyPrinter {
|
||||
}
|
||||
|
||||
private appendSwitchClauseStatements(node: ISwitchClauseSyntax): void {
|
||||
if (childCount(node.statements) === 1 && childAt(node.statements, 0).kind() === SyntaxKind.Block) {
|
||||
if (node.statements.childCount() === 1 && node.statements.childAt(0).kind() === SyntaxKind.Block) {
|
||||
this.ensureSpace();
|
||||
visitNodeOrToken(this, childAt(node.statements, 0));
|
||||
visitNodeOrToken(this, node.statements.childAt(0));
|
||||
}
|
||||
else if (childCount(node.statements) > 0) {
|
||||
else if (node.statements.childCount() > 0) {
|
||||
this.ensureNewLine();
|
||||
|
||||
this.indentation++;
|
||||
@@ -910,12 +910,12 @@ module TypeScript.PrettyPrinter {
|
||||
public visitObjectLiteralExpression(node: ObjectLiteralExpressionSyntax): void {
|
||||
this.appendToken(node.openBraceToken);
|
||||
|
||||
if (childCount(node.propertyAssignments) === 1) {
|
||||
if (node.propertyAssignments.childCount() === 1) {
|
||||
this.ensureSpace();
|
||||
visitNodeOrToken(this, <ISyntaxNodeOrToken>childAt(node.propertyAssignments, 0));
|
||||
visitNodeOrToken(this, <ISyntaxNodeOrToken>node.propertyAssignments.childAt(0));
|
||||
this.ensureSpace();
|
||||
}
|
||||
else if (childCount(node.propertyAssignments) > 0) {
|
||||
else if (node.propertyAssignments.childCount() > 0) {
|
||||
this.indentation++;
|
||||
this.ensureNewLine();
|
||||
this.appendSeparatorNewLineList(node.propertyAssignments);
|
||||
|
||||
@@ -255,6 +255,10 @@ module TypeScript.Scanner {
|
||||
this._packedData = fixedWidthTokenPackData(fullStart, this.kind());
|
||||
}
|
||||
|
||||
public childCount() { return 0 }
|
||||
public childAt(index: number): ISyntaxElement { throw Errors.invalidOperation() }
|
||||
public accept(visitor: ISyntaxVisitor): any { return visitor.visitToken(this) }
|
||||
|
||||
public isIncrementallyUnusable(): boolean { return false; }
|
||||
public isKeywordConvertedToIdentifier(): boolean { return false; }
|
||||
public hasSkippedToken(): boolean { return false; }
|
||||
@@ -290,6 +294,10 @@ module TypeScript.Scanner {
|
||||
largeTokenUnpackTriviaInfo(this._packedFullStartAndInfo));
|
||||
}
|
||||
|
||||
public childCount() { return 0 }
|
||||
public childAt(index: number): ISyntaxElement { throw Errors.invalidOperation() }
|
||||
public accept(visitor: ISyntaxVisitor): any { return visitor.visitToken(this) }
|
||||
|
||||
private syntaxTreeText(text: ISimpleText) {
|
||||
var result = text || syntaxTree(this).text;
|
||||
Debug.assert(result);
|
||||
|
||||
@@ -4,8 +4,8 @@ module TypeScript.Syntax {
|
||||
export var _nextSyntaxID: number = 1;
|
||||
|
||||
export function childIndex(parent: ISyntaxElement, child: ISyntaxElement) {
|
||||
for (var i = 0, n = childCount(parent); i < n; i++) {
|
||||
var current = childAt(parent, i);
|
||||
for (var i = 0, n = parent.childCount(); i < n; i++) {
|
||||
var current = parent.childAt(i);
|
||||
if (current === child) {
|
||||
return i;
|
||||
}
|
||||
@@ -15,8 +15,8 @@ module TypeScript.Syntax {
|
||||
}
|
||||
|
||||
export function nodeHasSkippedOrMissingTokens(node: ISyntaxNode): boolean {
|
||||
for (var i = 0; i < childCount(node); i++) {
|
||||
var child = childAt(node, i);
|
||||
for (var i = 0; i < node.childCount(); i++) {
|
||||
var child = node.childAt(i);
|
||||
if (isToken(child)) {
|
||||
var token = <ISyntaxToken>child;
|
||||
// If a token is skipped, return true. Or if it is a missing token. The only empty token that is not missing is EOF
|
||||
|
||||
@@ -11,36 +11,6 @@ module TypeScript {
|
||||
return (kind === SyntaxKind.List || kind === SyntaxKind.SeparatedList) && (<ISyntaxNodeOrToken[]>element).length === 0;
|
||||
}
|
||||
|
||||
export function childCount(element: ISyntaxElement): number {
|
||||
var kind = element.kind();
|
||||
if (kind === SyntaxKind.List) {
|
||||
return (<ISyntaxNodeOrToken[]>element).length;
|
||||
}
|
||||
else if (kind === SyntaxKind.SeparatedList) {
|
||||
return (<ISyntaxNodeOrToken[]>element).length + (<ISyntaxNodeOrToken[]>element).separators.length;
|
||||
}
|
||||
else if (kind >= SyntaxKind.FirstToken && kind <= SyntaxKind.LastToken) {
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
return nodeMetadata[kind].length;
|
||||
}
|
||||
}
|
||||
|
||||
export function childAt(element: ISyntaxElement, index: number): ISyntaxElement {
|
||||
var kind = element.kind();
|
||||
if (kind === SyntaxKind.List) {
|
||||
return (<ISyntaxNodeOrToken[]>element)[index];
|
||||
}
|
||||
else if (kind === SyntaxKind.SeparatedList) {
|
||||
return (index % 2 === 0) ? (<ISyntaxNodeOrToken[]>element)[index / 2] : (<ISyntaxNodeOrToken[]>element).separators[(index - 1) / 2];
|
||||
}
|
||||
else {
|
||||
// Debug.assert(isNode(element));
|
||||
return (<any>element)[nodeMetadata[element.kind()][index]];
|
||||
}
|
||||
}
|
||||
|
||||
export function syntaxTree(element: ISyntaxElement): SyntaxTree {
|
||||
if (element) {
|
||||
Debug.assert(!isShared(element));
|
||||
@@ -179,8 +149,8 @@ module TypeScript {
|
||||
}
|
||||
|
||||
// Consider: we could use a binary search here to find the child more quickly.
|
||||
for (var i = 0, n = childCount(element); i < n; i++) {
|
||||
var child = childAt(element, i);
|
||||
for (var i = 0, n = element.childCount(); i < n; i++) {
|
||||
var child = element.childAt(i);
|
||||
|
||||
if (child) {
|
||||
var childFullWidth = fullWidth(child);
|
||||
@@ -278,8 +248,8 @@ module TypeScript {
|
||||
elements.push((<ISyntaxToken>element).fullText(text));
|
||||
}
|
||||
else {
|
||||
for (var i = 0, n = childCount(element); i < n; i++) {
|
||||
collectTextElements(childAt(element, i), elements, text);
|
||||
for (var i = 0, n = element.childCount(); i < n; i++) {
|
||||
collectTextElements(element.childAt(i), elements, text);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -314,37 +284,10 @@ module TypeScript {
|
||||
return fullWidth(element) > 0 || element.kind() === SyntaxKind.EndOfFileToken ? <ISyntaxToken>element : undefined;
|
||||
}
|
||||
|
||||
if (kind === SyntaxKind.List) {
|
||||
var array = <ISyntaxNodeOrToken[]>element;
|
||||
for (var i = 0, n = array.length; i < n; i++) {
|
||||
var token = firstToken(array[i]);
|
||||
if (token) {
|
||||
return token;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (kind === SyntaxKind.SeparatedList) {
|
||||
var array = <ISyntaxNodeOrToken[]>element;
|
||||
var separators = array.separators;
|
||||
for (var i = 0, n = array.length + separators.length; i < n; i++) {
|
||||
var token = firstToken(i % 2 === 0 ? array[i / 2] : separators[(i - 1) / 2]);
|
||||
if (token) {
|
||||
return token;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
var metadata = nodeMetadata[kind];
|
||||
for (var i = 0, n = metadata.length; i < n; i++) {
|
||||
var child = (<any>element)[metadata[i]];
|
||||
var token = firstToken(child);
|
||||
if (token) {
|
||||
return token;
|
||||
}
|
||||
}
|
||||
|
||||
if (element.kind() === SyntaxKind.SourceUnit) {
|
||||
return (<SourceUnitSyntax>element).endOfFileToken;
|
||||
for (var i = 0, n = element.childCount(); i < n; i++) {
|
||||
var token = firstToken(element.childAt(i));
|
||||
if (token) {
|
||||
return token;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -361,8 +304,8 @@ module TypeScript {
|
||||
return (<SourceUnitSyntax>element).endOfFileToken;
|
||||
}
|
||||
|
||||
for (var i = childCount(element) - 1; i >= 0; i--) {
|
||||
var child = childAt(element, i);
|
||||
for (var i = element.childCount() - 1; i >= 0; i--) {
|
||||
var child = element.childAt(i);
|
||||
if (child) {
|
||||
var token = lastToken(child);
|
||||
if (token) {
|
||||
@@ -426,7 +369,7 @@ module TypeScript {
|
||||
}
|
||||
|
||||
function computeData(element: ISyntaxElement): number {
|
||||
var slotCount = childCount(element);
|
||||
var slotCount = element.childCount();
|
||||
|
||||
var fullWidth = 0;
|
||||
|
||||
@@ -434,7 +377,7 @@ module TypeScript {
|
||||
var isIncrementallyUnusable = slotCount === 0;
|
||||
|
||||
for (var i = 0, n = slotCount; i < n; i++) {
|
||||
var child = childAt(element, i);
|
||||
var child = element.childAt(i);
|
||||
|
||||
if (child) {
|
||||
fullWidth += TypeScript.fullWidth(child);
|
||||
@@ -485,6 +428,8 @@ module TypeScript {
|
||||
export interface ISyntaxElement {
|
||||
kind(): SyntaxKind;
|
||||
parent?: ISyntaxElement;
|
||||
childCount(): number;
|
||||
childAt(index: number): ISyntaxElement;
|
||||
}
|
||||
|
||||
export interface ISyntaxNode extends ISyntaxNodeOrToken {
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
///<reference path='..\core\references.ts' />
|
||||
///<reference path='..\core\environment.ts' />
|
||||
///<reference path='..\..\compiler\sys.ts' />
|
||||
///<reference path='..\..\services\core\arrayUtilities.ts' />
|
||||
///<reference path='..\..\services\core\stringUtilities.ts' />
|
||||
///<reference path='syntaxFacts.ts' />
|
||||
///<reference path='syntaxKind.ts' />
|
||||
///<reference path='..\..\..\tests\fidelity\es5compat.ts' />
|
||||
// ///<reference path='..\..\..\tests\fidelity\es5compat.ts' />
|
||||
|
||||
// Adds argument checking to the generated nodes. Argument checking appears to slow things down
|
||||
// parsing about 7%. If we want to get that perf back, we can always remove this.
|
||||
@@ -32,7 +33,7 @@ interface IMemberDefinition {
|
||||
excludeFromAST?: boolean;
|
||||
}
|
||||
|
||||
var interfaces: TypeScript.IIndexable<any> = {
|
||||
var interfaces: any = {
|
||||
IMemberDeclarationSyntax: 'IClassElementSyntax',
|
||||
IStatementSyntax: 'IModuleElementSyntax',
|
||||
INameSyntax: 'ITypeSyntax',
|
||||
@@ -1560,22 +1561,34 @@ function generateBrands(definition: ITypeDefinition, accessibility: boolean): st
|
||||
return properties;
|
||||
}
|
||||
|
||||
function generateAcceptMethod(definition: ITypeDefinition): string {
|
||||
var result = "";
|
||||
|
||||
if (!hasKind) {
|
||||
result += "\r\n";
|
||||
result += " public accept(visitor: ISyntaxVisitor): SyntaxKind {\r\n";
|
||||
result += " return visitor.visit" + getNameWithoutSuffix(definition) + "(this);\r\n";
|
||||
result += " }\r\n";
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
function generateKindMethod(definition: ITypeDefinition): string {
|
||||
var result = "";
|
||||
|
||||
//if (!hasKind) {
|
||||
// result += "\r\n";
|
||||
// result += " public get kind(): SyntaxKind {\r\n";
|
||||
// result += " return SyntaxKind." + getNameWithoutSuffix(definition) + ";\r\n";
|
||||
// result += " }\r\n";
|
||||
//}
|
||||
if (!hasKind) {
|
||||
result += "\r\n";
|
||||
result += " public kind(): SyntaxKind {\r\n";
|
||||
result += " return SyntaxKind." + getNameWithoutSuffix(definition) + ";\r\n";
|
||||
result += " }\r\n";
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
function generateSlotMethods(definition: ITypeDefinition): string {
|
||||
var result = "";
|
||||
return result;
|
||||
|
||||
result += "\r\n";
|
||||
result += " public childCount(): number {\r\n";
|
||||
@@ -1973,6 +1986,11 @@ function generateNode(definition: ITypeDefinition, abstract: boolean): string {
|
||||
}
|
||||
|
||||
result += " }\r\n";
|
||||
|
||||
result += generateKindMethod(definition);
|
||||
result += generateSlotMethods(definition);
|
||||
result += generateAcceptMethod(definition);
|
||||
|
||||
result += " }";
|
||||
return result;
|
||||
}
|
||||
@@ -2020,6 +2038,7 @@ function generateSyntaxInterfaces(): string {
|
||||
|
||||
result += "\r\n\r\n";
|
||||
|
||||
/*
|
||||
result += " export var nodeMetadata: string[][] = [";
|
||||
for (var i = 0; i <= TypeScript.SyntaxKind.LastNode; i++) {
|
||||
if (i < TypeScript.SyntaxKind.FirstNode) {
|
||||
@@ -2039,6 +2058,7 @@ function generateSyntaxInterfaces(): string {
|
||||
result += metadata;
|
||||
}
|
||||
result += "];\r\n\r\n";
|
||||
*/
|
||||
|
||||
result += " export module Syntax {\r\n"
|
||||
|
||||
@@ -2111,7 +2131,7 @@ function generateNodes(abstract: boolean): string {
|
||||
|
||||
result += generateNode(definition, abstract);
|
||||
}
|
||||
|
||||
/*
|
||||
result += "\r\n\r\n ";
|
||||
|
||||
for (var i = 0; i < definitions.length; i++) {
|
||||
@@ -2128,9 +2148,9 @@ function generateNodes(abstract: boolean): string {
|
||||
result += "(<any>" + definition.name + ").prototype.__kind = SyntaxKind." + getNameWithoutSuffix(definition)
|
||||
}
|
||||
|
||||
result += ";\r\n";
|
||||
result += ";\r\n";*/
|
||||
|
||||
result += "}";
|
||||
result += "\r\n}";
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -2285,16 +2305,28 @@ function generateWalker(): string {
|
||||
" this.visitToken(token);\r\n" +
|
||||
" }\r\n" +
|
||||
"\r\n" +
|
||||
" private visitOptionalNode(node: ISyntaxNode): void {\r\n" +
|
||||
" if (node === undefined) {\r\n" +
|
||||
" return;\r\n" +
|
||||
" }\r\n" +
|
||||
"\r\n" +
|
||||
" node.accept(this);\r\n" +
|
||||
" }\r\n" +
|
||||
"\r\n" +
|
||||
" public visitList(list: ISyntaxNodeOrToken[]): void {\r\n" +
|
||||
" for (var i = 0, n = list.length; i < n; i++) {\r\n" +
|
||||
" visitNodeOrToken(this, list[i]);\r\n" +
|
||||
" list[i].accept(this);\r\n" +
|
||||
" }\r\n" +
|
||||
" }\r\n" +
|
||||
"\r\n" +
|
||||
" public visitSeparatedList(list: ISyntaxNodeOrToken[]): void {\r\n" +
|
||||
" for (var i = 0, n = childCount(list); i < n; i++) {\r\n" +
|
||||
" var item = childAt(list, i);\r\n" +
|
||||
" visitNodeOrToken(this, item);\r\n" +
|
||||
" for (var i = 0, n = separatedListChildCount(list); i < n; i++) {\r\n" +
|
||||
" if (i % 2 === 0) {\r\n" +
|
||||
" list[i >> 1].accept(this);\r\n" +
|
||||
" }\r\n" +
|
||||
" else {\r\n" +
|
||||
" this.visitToken(list.separators[i >> 1]);\r\n" +
|
||||
" }\r\n" +
|
||||
" }\r\n" +
|
||||
" }\r\n";
|
||||
|
||||
@@ -2322,10 +2354,28 @@ function generateWalker(): string {
|
||||
result += " this.visitSeparatedList(node." + child.name + ");\r\n";
|
||||
}
|
||||
else if (isNodeOrToken(child)) {
|
||||
result += " visitNodeOrToken(this, node." + child.name + ");\r\n";
|
||||
if (child.isOptional) {
|
||||
result += " visitNodeOrToken(this, node." + child.name + ");\r\n";
|
||||
}
|
||||
else {
|
||||
result += " node." + child.name + ".accept(this);\r\n";
|
||||
}
|
||||
}
|
||||
else if (child.type === "ISyntaxToken") {
|
||||
if (child.isOptional) {
|
||||
result += " this.visitOptionalToken(node." + child.name + ");\r\n";
|
||||
}
|
||||
else {
|
||||
result += " this.visitToken(node." + child.name + ");\r\n";
|
||||
}
|
||||
}
|
||||
else if (child.type !== "SyntaxKind") {
|
||||
result += " visitNodeOrToken(this, node." + child.name + ");\r\n";
|
||||
if (child.isOptional) {
|
||||
result += " this.visitOptionalNode(node." + child.name + ");\r\n";
|
||||
}
|
||||
else {
|
||||
result += " node." + child.name + ".accept(this);\r\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2346,7 +2396,7 @@ function firstEnumName(e: any, value: number) {
|
||||
}
|
||||
|
||||
function groupBy<T>(array: T[], func: (v: T) => string): any {
|
||||
var result: TypeScript.IIndexable<T[]> = {};
|
||||
var result: any = {};
|
||||
|
||||
for (var i = 0, n = array.length; i < n; i++) {
|
||||
var v: any = array[i];
|
||||
@@ -2485,6 +2535,8 @@ function generateVisitor(): string {
|
||||
result += "module TypeScript {\r\n";
|
||||
result += " export function visitNodeOrToken(visitor: ISyntaxVisitor, element: ISyntaxNodeOrToken): any {\r\n";
|
||||
result += " if (element === undefined) { return undefined; }\r\n";
|
||||
result += " return element.accept(visitor);\r\n";
|
||||
/*
|
||||
result += " if (isToken(element)) { return visitor.visitToken(<ISyntaxToken>element); }\r\n";
|
||||
result += " switch (element.kind()) {\r\n";
|
||||
|
||||
@@ -2507,13 +2559,14 @@ function generateVisitor(): string {
|
||||
|
||||
result += " }\r\n\r\n";
|
||||
result += " throw Errors.invalidOperation();\r\n";
|
||||
*/
|
||||
result += " }\r\n\r\n";
|
||||
|
||||
result += " export interface ISyntaxVisitor {\r\n";
|
||||
result += " visitToken(token: ISyntaxToken): any;\r\n";
|
||||
|
||||
for (i = 0; i < definitions.length; i++) {
|
||||
definition = definitions[i];
|
||||
for (var i = 0; i < definitions.length; i++) {
|
||||
var definition = definitions[i];
|
||||
result += " visit" + getNameWithoutSuffix(definition) + "(node: " + definition.name + "): any;\r\n";
|
||||
}
|
||||
|
||||
@@ -2669,8 +2722,8 @@ function generateIsTypeScriptSpecific(): string {
|
||||
result += "module TypeScript {\r\n";
|
||||
|
||||
result += " function isSeparatedListTypeScriptSpecific(list: ISyntaxNodeOrToken[]): boolean {\r\n"
|
||||
result += " for (var i = 0, n = childCount(list); i < n; i++) {\r\n";
|
||||
result += " if (isTypeScriptSpecific(childAt(list, i))) {\r\n";
|
||||
result += " for (var i = 0, n = list.childCount(); i < n; i++) {\r\n";
|
||||
result += " if (isTypeScriptSpecific(list.childAt(i))) {\r\n";
|
||||
result += " return true;\r\n";
|
||||
result += " }\r\n";
|
||||
result += " }\r\n\r\n";
|
||||
@@ -2823,7 +2876,6 @@ function generateIsTypeScriptSpecificMethod(definition: ITypeDefinition): string
|
||||
}
|
||||
|
||||
var syntaxNodesConcrete = generateNodes(/*abstract:*/ false);
|
||||
var syntaxNodesAbstract = generateNodes(/*abstract:*/ true);
|
||||
var syntaxInterfaces = generateSyntaxInterfaces();
|
||||
var rewriter = generateRewriter();
|
||||
var walker = generateWalker();
|
||||
@@ -2832,12 +2884,11 @@ var visitor = generateVisitor();
|
||||
var defaultVisitor = generateDefaultVisitor();
|
||||
var servicesUtilities = generateServicesUtilities();
|
||||
|
||||
TypeScript.Environment.writeFile(TypeScript.Environment.currentDirectory() + "\\src\\compiler\\syntax\\syntaxNodes.concrete.generated.ts", syntaxNodesConcrete, false);
|
||||
TypeScript.Environment.writeFile(TypeScript.Environment.currentDirectory() + "\\src\\compiler\\syntax\\syntaxNodes.abstract.generated.ts", syntaxNodesAbstract, false);
|
||||
TypeScript.Environment.writeFile(TypeScript.Environment.currentDirectory() + "\\src\\compiler\\syntax\\syntaxNodes.interfaces.generated.ts", syntaxInterfaces, false);
|
||||
TypeScript.Environment.writeFile(TypeScript.Environment.currentDirectory() + "\\src\\services\\syntaxRewriter.generated.ts", rewriter, false);
|
||||
TypeScript.Environment.writeFile(TypeScript.Environment.currentDirectory() + "\\src\\compiler\\syntax\\syntaxWalker.generated.ts", walker, false);
|
||||
TypeScript.Environment.writeFile(TypeScript.Environment.currentDirectory() + "\\src\\compiler\\syntax\\scannerUtilities.generated.ts", scannerUtilities, false);
|
||||
TypeScript.Environment.writeFile(TypeScript.Environment.currentDirectory() + "\\src\\compiler\\syntax\\syntaxVisitor.generated.ts", visitor, false);
|
||||
TypeScript.Environment.writeFile(TypeScript.Environment.currentDirectory() + "\\src\\compiler\\syntax\\defaultSyntaxVisitor.generated.ts", defaultVisitor, false);
|
||||
TypeScript.Environment.writeFile(TypeScript.Environment.currentDirectory() + "\\src\\services\\syntaxUtilities.generated.ts", servicesUtilities, false);
|
||||
sys.writeFile(sys.getCurrentDirectory() + "\\src\\services\\syntax\\syntaxNodes.concrete.generated.ts", syntaxNodesConcrete, false);
|
||||
sys.writeFile(sys.getCurrentDirectory() + "\\src\\services\\syntax\\syntaxNodes.interfaces.generated.ts", syntaxInterfaces, false);
|
||||
sys.writeFile(sys.getCurrentDirectory() + "\\src\\services\\syntax\\syntaxRewriter.generated.ts", rewriter, false);
|
||||
sys.writeFile(sys.getCurrentDirectory() + "\\src\\services\\syntax\\syntaxWalker.generated.ts", walker, false);
|
||||
sys.writeFile(sys.getCurrentDirectory() + "\\src\\services\\syntax\\scannerUtilities.generated.ts", scannerUtilities, false);
|
||||
sys.writeFile(sys.getCurrentDirectory() + "\\src\\services\\syntax\\syntaxVisitor.generated.ts", visitor, false);
|
||||
sys.writeFile(sys.getCurrentDirectory() + "\\src\\services\\syntax\\defaultSyntaxVisitor.generated.ts", defaultVisitor, false);
|
||||
sys.writeFile(sys.getCurrentDirectory() + "\\src\\services\\syntax\\syntaxUtilities.generated.ts", servicesUtilities, false);
|
||||
@@ -9,6 +9,19 @@ interface Array<T> {
|
||||
|
||||
separatorCount(): number;
|
||||
separatorAt(index: number): TypeScript.ISyntaxToken;
|
||||
|
||||
childCount(): number;
|
||||
childAt(index: number): TypeScript.ISyntaxNodeOrToken;
|
||||
}
|
||||
|
||||
module TypeScript {
|
||||
export function separatedListChildCount(list: ISyntaxNodeOrToken[]) {
|
||||
return list.length + list.separators.length;
|
||||
}
|
||||
|
||||
export function separatedListChildAt(list: ISyntaxNodeOrToken[], index: number) {
|
||||
return index % 2 === 0 ? list[index >> 1] : list.separators[index >> 1];
|
||||
}
|
||||
}
|
||||
|
||||
module TypeScript.Syntax {
|
||||
@@ -29,6 +42,19 @@ module TypeScript.Syntax {
|
||||
return this.separators === undefined ? SyntaxKind.List : SyntaxKind.SeparatedList;
|
||||
}
|
||||
|
||||
Array.prototype.childCount = function (): number {
|
||||
return this.separators ? separatedListChildCount(this) : this.length;
|
||||
}
|
||||
|
||||
Array.prototype.childAt = function (index: number): ISyntaxNodeOrToken {
|
||||
if (this.separators) {
|
||||
return index % 2 === 0 ? this[index >> 1] : this.separators[index >> 1];
|
||||
}
|
||||
else {
|
||||
return this[index];
|
||||
}
|
||||
}
|
||||
|
||||
Array.prototype.separatorCount = function (): number {
|
||||
assertEmptyLists();
|
||||
// Debug.assert(this.kind === SyntaxKind.SeparatedList);
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
module TypeScript {
|
||||
export class SyntaxNode implements ISyntaxNodeOrToken {
|
||||
private __kind: SyntaxKind;
|
||||
// private __kind: SyntaxKind;
|
||||
public data: number;
|
||||
public parent: ISyntaxElement;
|
||||
|
||||
@@ -13,7 +13,19 @@ module TypeScript {
|
||||
}
|
||||
|
||||
public kind(): SyntaxKind {
|
||||
return this.__kind;
|
||||
throw Errors.abstract();
|
||||
}
|
||||
|
||||
public childCount(): number {
|
||||
throw Errors.abstract();
|
||||
}
|
||||
|
||||
public childAt(index: number): ISyntaxElement {
|
||||
throw Errors.abstract();
|
||||
}
|
||||
|
||||
public accept(visitor: ISyntaxVisitor): any {
|
||||
throw Errors.abstract();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,5 +2,6 @@
|
||||
|
||||
module TypeScript {
|
||||
export interface ISyntaxNodeOrToken extends ISyntaxElement {
|
||||
accept(visitor: ISyntaxVisitor): any;
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
@@ -493,8 +493,6 @@ module TypeScript {
|
||||
moduleName: INameSyntax;
|
||||
}
|
||||
|
||||
export var nodeMetadata: string[][] = [[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],["moduleElements","endOfFileToken"],["left","dotToken","right"],["openBraceToken","typeMembers","closeBraceToken"],["typeParameterList","parameterList","equalsGreaterThanToken","type"],["type","openBracketToken","closeBracketToken"],["newKeyword","typeParameterList","parameterList","equalsGreaterThanToken","type"],["name","typeArgumentList"],["typeOfKeyword","name"],["openBracketToken","types","closeBracketToken"],["left","barToken","right"],["openParenToken","type","closeParenToken"],["modifiers","interfaceKeyword","identifier","typeParameterList","heritageClauses","body"],["modifiers","functionKeyword","identifier","callSignature","block","semicolonToken"],["modifiers","moduleKeyword","name","stringLiteral","openBraceToken","moduleElements","closeBraceToken"],["modifiers","classKeyword","identifier","typeParameterList","heritageClauses","openBraceToken","classElements","closeBraceToken"],["modifiers","enumKeyword","identifier","openBraceToken","enumElements","closeBraceToken"],["modifiers","importKeyword","identifier","equalsToken","moduleReference","semicolonToken"],["exportKeyword","equalsToken","identifier","semicolonToken"],["modifiers","propertyName","callSignature","block","semicolonToken"],["modifiers","variableDeclarator","semicolonToken"],["modifiers","constructorKeyword","callSignature","block","semicolonToken"],["modifiers","indexSignature","semicolonToken"],["modifiers","getKeyword","propertyName","callSignature","block"],["modifiers","setKeyword","propertyName","callSignature","block"],["propertyName","questionToken","typeAnnotation"],["typeParameterList","parameterList","typeAnnotation"],["newKeyword","callSignature"],["openBracketToken","parameters","closeBracketToken","typeAnnotation"],["propertyName","questionToken","callSignature"],["openBraceToken","statements","closeBraceToken"],["ifKeyword","openParenToken","condition","closeParenToken","statement","elseClause"],["modifiers","variableDeclaration","semicolonToken"],["expression","semicolonToken"],["returnKeyword","expression","semicolonToken"],["switchKeyword","openParenToken","expression","closeParenToken","openBraceToken","switchClauses","closeBraceToken"],["breakKeyword","identifier","semicolonToken"],["continueKeyword","identifier","semicolonToken"],["forKeyword","openParenToken","variableDeclaration","initializer","firstSemicolonToken","condition","secondSemicolonToken","incrementor","closeParenToken","statement"],["forKeyword","openParenToken","variableDeclaration","left","inKeyword","expression","closeParenToken","statement"],["semicolonToken"],["throwKeyword","expression","semicolonToken"],["whileKeyword","openParenToken","condition","closeParenToken","statement"],["tryKeyword","block","catchClause","finallyClause"],["identifier","colonToken","statement"],["doKeyword","statement","whileKeyword","openParenToken","condition","closeParenToken","semicolonToken"],["debuggerKeyword","semicolonToken"],["withKeyword","openParenToken","condition","closeParenToken","statement"],["operatorToken","operand"],["deleteKeyword","expression"],["typeOfKeyword","expression"],["voidKeyword","expression"],["condition","questionToken","whenTrue","colonToken","whenFalse"],["left","operatorToken","right"],["operand","operatorToken"],["expression","dotToken","name"],["expression","argumentList"],["openBracketToken","expressions","closeBracketToken"],["openBraceToken","propertyAssignments","closeBraceToken"],["newKeyword","expression","argumentList"],["openParenToken","expression","closeParenToken"],["callSignature","equalsGreaterThanToken","block","expression"],["parameter","equalsGreaterThanToken","block","expression"],["lessThanToken","type","greaterThanToken","expression"],["expression","openBracketToken","argumentExpression","closeBracketToken"],["functionKeyword","identifier","callSignature","block"],[],["varKeyword","variableDeclarators"],["propertyName","typeAnnotation","equalsValueClause"],["typeArgumentList","openParenToken","arguments","closeParenToken"],["openParenToken","parameters","closeParenToken"],["lessThanToken","typeArguments","greaterThanToken"],["lessThanToken","typeParameters","greaterThanToken"],["extendsOrImplementsKeyword","typeNames"],["equalsToken","value"],["caseKeyword","expression","colonToken","statements"],["defaultKeyword","colonToken","statements"],["elseKeyword","statement"],["catchKeyword","openParenToken","identifier","typeAnnotation","closeParenToken","block"],["finallyKeyword","block"],["identifier","constraint"],["extendsKeyword","typeOrExpression"],["propertyName","colonToken","expression"],["propertyName","callSignLine truncated
|
||||
|
||||
export module Syntax {
|
||||
export interface ISyntaxFactory {
|
||||
isConcrete: boolean;
|
||||
|
||||
@@ -297,6 +297,10 @@ module TypeScript.Syntax {
|
||||
return this._kind;
|
||||
}
|
||||
|
||||
public childCount() { return 0 }
|
||||
public childAt(index: number): ISyntaxElement { throw Errors.invalidOperation() }
|
||||
public accept(visitor: ISyntaxVisitor): any { return visitor.visitToken(this) }
|
||||
|
||||
public clone(): ISyntaxToken {
|
||||
return new EmptyToken(this.kind());
|
||||
}
|
||||
@@ -352,8 +356,8 @@ module TypeScript.Syntax {
|
||||
}
|
||||
|
||||
// Ok. We have a parent. First, find out which slot we're at in the parent.
|
||||
for (var i = 0, n = childCount(parent); i < n; i++) {
|
||||
if (childAt(parent, i) === current) {
|
||||
for (var i = 0, n = parent.childCount(); i < n; i++) {
|
||||
if (parent.childAt(i) === current) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -362,7 +366,7 @@ module TypeScript.Syntax {
|
||||
|
||||
// Walk backward from this element, looking for a non-zero-width sibling.
|
||||
for (var j = i - 1; j >= 0; j--) {
|
||||
var sibling = childAt(parent, j);
|
||||
var sibling = parent.childAt(j);
|
||||
if (sibling && fullWidth(sibling) > 0) {
|
||||
return sibling;
|
||||
}
|
||||
@@ -435,6 +439,10 @@ module TypeScript.Syntax {
|
||||
public kind(): SyntaxKind {
|
||||
return this._kind;
|
||||
}
|
||||
|
||||
public childCount() { return 0 }
|
||||
public childAt(index: number): ISyntaxElement { throw Errors.invalidOperation() }
|
||||
public accept(visitor: ISyntaxVisitor): any { return visitor.visitToken(this) }
|
||||
|
||||
public clone(): ISyntaxToken {
|
||||
return new RealizedToken(this._fullStart, this.kind(), this._isKeywordConvertedToIdentifier, this._leadingTrivia, this._text, this._trailingTrivia);
|
||||
@@ -481,6 +489,10 @@ module TypeScript.Syntax {
|
||||
this.underlyingToken.setFullStart(fullStart);
|
||||
}
|
||||
|
||||
public childCount() { return 0 }
|
||||
public childAt(index: number): ISyntaxElement { throw Errors.invalidOperation() }
|
||||
public accept(visitor: ISyntaxVisitor): any { return visitor.visitToken(this) }
|
||||
|
||||
public fullStart(): number {
|
||||
return this.underlyingToken.fullStart();
|
||||
}
|
||||
|
||||
@@ -255,18 +255,18 @@ module TypeScript {
|
||||
private checkForTrailingComma(list: ISyntaxNodeOrToken[]): boolean {
|
||||
// If we have at least one child, and we have an even number of children, then that
|
||||
// means we have an illegal trailing separator.
|
||||
if (childCount(list) === 0 || childCount(list) % 2 === 1) {
|
||||
if (list.childCount() === 0 || list.childCount() % 2 === 1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
var child = childAt(list, childCount(list) - 1);
|
||||
var child = list.childAt(list.childCount() - 1);
|
||||
this.pushDiagnostic(child, DiagnosticCode.Trailing_comma_not_allowed);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private checkForAtLeastOneElement(parent: ISyntaxElement, list: ISyntaxNodeOrToken[], reportToken: ISyntaxToken, listKind: string): boolean {
|
||||
if (childCount(list) > 0) {
|
||||
if (list.childCount() > 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -589,7 +589,7 @@ module TypeScript {
|
||||
|
||||
private checkIndexMemberModifiers(node: IndexMemberDeclarationSyntax): boolean {
|
||||
if (node.modifiers.length > 0) {
|
||||
this.pushDiagnostic(childAt(node.modifiers, 0), DiagnosticCode.Modifiers_cannot_appear_here);
|
||||
this.pushDiagnostic(node.modifiers.childAt(0), DiagnosticCode.Modifiers_cannot_appear_here);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -654,7 +654,7 @@ module TypeScript {
|
||||
|
||||
private checkSetAccessorParameter(node: SetAccessorSyntax): boolean {
|
||||
var parameters = node.callSignature.parameterList.parameters;
|
||||
if (childCount(parameters) !== 1) {
|
||||
if (parameters.childCount() !== 1) {
|
||||
this.pushDiagnostic(node.propertyName, DiagnosticCode.set_accessor_must_have_exactly_one_parameter);
|
||||
return true;
|
||||
}
|
||||
@@ -710,8 +710,8 @@ module TypeScript {
|
||||
|
||||
private checkEnumElements(node: EnumDeclarationSyntax): boolean {
|
||||
var previousValueWasComputed = false;
|
||||
for (var i = 0, n = childCount(node.enumElements); i < n; i++) {
|
||||
var child = childAt(node.enumElements, i);
|
||||
for (var i = 0, n = node.enumElements.childCount(); i < n; i++) {
|
||||
var child = node.enumElements.childAt(i);
|
||||
|
||||
if (i % 2 === 0) {
|
||||
var enumElement = <EnumElementSyntax>child;
|
||||
@@ -1286,7 +1286,7 @@ module TypeScript {
|
||||
private checkForDisallowedModifiers(parent: ISyntaxElement, modifiers: ISyntaxToken[]): boolean {
|
||||
if (this.inBlock || this.inObjectLiteralExpression) {
|
||||
if (modifiers.length > 0) {
|
||||
this.pushDiagnostic(childAt(modifiers, 0), DiagnosticCode.Modifiers_cannot_appear_here);
|
||||
this.pushDiagnostic(modifiers.childAt(0), DiagnosticCode.Modifiers_cannot_appear_here);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -1334,8 +1334,8 @@ module TypeScript {
|
||||
}
|
||||
|
||||
private checkListSeparators<T extends ISyntaxNodeOrToken>(parent: ISyntaxElement, list: T[], kind: SyntaxKind): boolean {
|
||||
for (var i = 0, n = childCount(list); i < n; i++) {
|
||||
var child = childAt(list, i);
|
||||
for (var i = 0, n = list.childCount(); i < n; i++) {
|
||||
var child = list.childAt(i);
|
||||
if (i % 2 === 1 && child.kind() !== kind) {
|
||||
this.pushDiagnostic(child, DiagnosticCode._0_expected, [SyntaxFacts.getText(kind)]);
|
||||
}
|
||||
|
||||
@@ -3,99 +3,7 @@
|
||||
module TypeScript {
|
||||
export function visitNodeOrToken(visitor: ISyntaxVisitor, element: ISyntaxNodeOrToken): any {
|
||||
if (element === undefined) { return undefined; }
|
||||
if (isToken(element)) { return visitor.visitToken(<ISyntaxToken>element); }
|
||||
switch (element.kind()) {
|
||||
case SyntaxKind.SourceUnit: return visitor.visitSourceUnit(<SourceUnitSyntax>element);
|
||||
case SyntaxKind.QualifiedName: return visitor.visitQualifiedName(<QualifiedNameSyntax>element);
|
||||
case SyntaxKind.ObjectType: return visitor.visitObjectType(<ObjectTypeSyntax>element);
|
||||
case SyntaxKind.FunctionType: return visitor.visitFunctionType(<FunctionTypeSyntax>element);
|
||||
case SyntaxKind.ArrayType: return visitor.visitArrayType(<ArrayTypeSyntax>element);
|
||||
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.UnionType: return visitor.visitUnionType(<UnionTypeSyntax>element);
|
||||
case SyntaxKind.ParenthesizedType: return visitor.visitParenthesizedType(<ParenthesizedTypeSyntax>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);
|
||||
case SyntaxKind.ClassDeclaration: return visitor.visitClassDeclaration(<ClassDeclarationSyntax>element);
|
||||
case SyntaxKind.EnumDeclaration: return visitor.visitEnumDeclaration(<EnumDeclarationSyntax>element);
|
||||
case SyntaxKind.ImportDeclaration: return visitor.visitImportDeclaration(<ImportDeclarationSyntax>element);
|
||||
case SyntaxKind.ExportAssignment: return visitor.visitExportAssignment(<ExportAssignmentSyntax>element);
|
||||
case SyntaxKind.MemberFunctionDeclaration: return visitor.visitMemberFunctionDeclaration(<MemberFunctionDeclarationSyntax>element);
|
||||
case SyntaxKind.MemberVariableDeclaration: return visitor.visitMemberVariableDeclaration(<MemberVariableDeclarationSyntax>element);
|
||||
case SyntaxKind.ConstructorDeclaration: return visitor.visitConstructorDeclaration(<ConstructorDeclarationSyntax>element);
|
||||
case SyntaxKind.IndexMemberDeclaration: return visitor.visitIndexMemberDeclaration(<IndexMemberDeclarationSyntax>element);
|
||||
case SyntaxKind.GetAccessor: return visitor.visitGetAccessor(<GetAccessorSyntax>element);
|
||||
case SyntaxKind.SetAccessor: return visitor.visitSetAccessor(<SetAccessorSyntax>element);
|
||||
case SyntaxKind.PropertySignature: return visitor.visitPropertySignature(<PropertySignatureSyntax>element);
|
||||
case SyntaxKind.CallSignature: return visitor.visitCallSignature(<CallSignatureSyntax>element);
|
||||
case SyntaxKind.ConstructSignature: return visitor.visitConstructSignature(<ConstructSignatureSyntax>element);
|
||||
case SyntaxKind.IndexSignature: return visitor.visitIndexSignature(<IndexSignatureSyntax>element);
|
||||
case SyntaxKind.MethodSignature: return visitor.visitMethodSignature(<MethodSignatureSyntax>element);
|
||||
case SyntaxKind.Block: return visitor.visitBlock(<BlockSyntax>element);
|
||||
case SyntaxKind.IfStatement: return visitor.visitIfStatement(<IfStatementSyntax>element);
|
||||
case SyntaxKind.VariableStatement: return visitor.visitVariableStatement(<VariableStatementSyntax>element);
|
||||
case SyntaxKind.ExpressionStatement: return visitor.visitExpressionStatement(<ExpressionStatementSyntax>element);
|
||||
case SyntaxKind.ReturnStatement: return visitor.visitReturnStatement(<ReturnStatementSyntax>element);
|
||||
case SyntaxKind.SwitchStatement: return visitor.visitSwitchStatement(<SwitchStatementSyntax>element);
|
||||
case SyntaxKind.BreakStatement: return visitor.visitBreakStatement(<BreakStatementSyntax>element);
|
||||
case SyntaxKind.ContinueStatement: return visitor.visitContinueStatement(<ContinueStatementSyntax>element);
|
||||
case SyntaxKind.ForStatement: return visitor.visitForStatement(<ForStatementSyntax>element);
|
||||
case SyntaxKind.ForInStatement: return visitor.visitForInStatement(<ForInStatementSyntax>element);
|
||||
case SyntaxKind.EmptyStatement: return visitor.visitEmptyStatement(<EmptyStatementSyntax>element);
|
||||
case SyntaxKind.ThrowStatement: return visitor.visitThrowStatement(<ThrowStatementSyntax>element);
|
||||
case SyntaxKind.WhileStatement: return visitor.visitWhileStatement(<WhileStatementSyntax>element);
|
||||
case SyntaxKind.TryStatement: return visitor.visitTryStatement(<TryStatementSyntax>element);
|
||||
case SyntaxKind.LabeledStatement: return visitor.visitLabeledStatement(<LabeledStatementSyntax>element);
|
||||
case SyntaxKind.DoStatement: return visitor.visitDoStatement(<DoStatementSyntax>element);
|
||||
case SyntaxKind.DebuggerStatement: return visitor.visitDebuggerStatement(<DebuggerStatementSyntax>element);
|
||||
case SyntaxKind.WithStatement: return visitor.visitWithStatement(<WithStatementSyntax>element);
|
||||
case SyntaxKind.PrefixUnaryExpression: return visitor.visitPrefixUnaryExpression(<PrefixUnaryExpressionSyntax>element);
|
||||
case SyntaxKind.DeleteExpression: return visitor.visitDeleteExpression(<DeleteExpressionSyntax>element);
|
||||
case SyntaxKind.TypeOfExpression: return visitor.visitTypeOfExpression(<TypeOfExpressionSyntax>element);
|
||||
case SyntaxKind.VoidExpression: return visitor.visitVoidExpression(<VoidExpressionSyntax>element);
|
||||
case SyntaxKind.ConditionalExpression: return visitor.visitConditionalExpression(<ConditionalExpressionSyntax>element);
|
||||
case SyntaxKind.BinaryExpression: return visitor.visitBinaryExpression(<BinaryExpressionSyntax>element);
|
||||
case SyntaxKind.PostfixUnaryExpression: return visitor.visitPostfixUnaryExpression(<PostfixUnaryExpressionSyntax>element);
|
||||
case SyntaxKind.MemberAccessExpression: return visitor.visitMemberAccessExpression(<MemberAccessExpressionSyntax>element);
|
||||
case SyntaxKind.InvocationExpression: return visitor.visitInvocationExpression(<InvocationExpressionSyntax>element);
|
||||
case SyntaxKind.ArrayLiteralExpression: return visitor.visitArrayLiteralExpression(<ArrayLiteralExpressionSyntax>element);
|
||||
case SyntaxKind.ObjectLiteralExpression: return visitor.visitObjectLiteralExpression(<ObjectLiteralExpressionSyntax>element);
|
||||
case SyntaxKind.ObjectCreationExpression: return visitor.visitObjectCreationExpression(<ObjectCreationExpressionSyntax>element);
|
||||
case SyntaxKind.ParenthesizedExpression: return visitor.visitParenthesizedExpression(<ParenthesizedExpressionSyntax>element);
|
||||
case SyntaxKind.ParenthesizedArrowFunctionExpression: return visitor.visitParenthesizedArrowFunctionExpression(<ParenthesizedArrowFunctionExpressionSyntax>element);
|
||||
case SyntaxKind.SimpleArrowFunctionExpression: return visitor.visitSimpleArrowFunctionExpression(<SimpleArrowFunctionExpressionSyntax>element);
|
||||
case SyntaxKind.CastExpression: return visitor.visitCastExpression(<CastExpressionSyntax>element);
|
||||
case SyntaxKind.ElementAccessExpression: return visitor.visitElementAccessExpression(<ElementAccessExpressionSyntax>element);
|
||||
case SyntaxKind.FunctionExpression: return visitor.visitFunctionExpression(<FunctionExpressionSyntax>element);
|
||||
case SyntaxKind.OmittedExpression: return visitor.visitOmittedExpression(<OmittedExpressionSyntax>element);
|
||||
case SyntaxKind.VariableDeclaration: return visitor.visitVariableDeclaration(<VariableDeclarationSyntax>element);
|
||||
case SyntaxKind.VariableDeclarator: return visitor.visitVariableDeclarator(<VariableDeclaratorSyntax>element);
|
||||
case SyntaxKind.ArgumentList: return visitor.visitArgumentList(<ArgumentListSyntax>element);
|
||||
case SyntaxKind.ParameterList: return visitor.visitParameterList(<ParameterListSyntax>element);
|
||||
case SyntaxKind.TypeArgumentList: return visitor.visitTypeArgumentList(<TypeArgumentListSyntax>element);
|
||||
case SyntaxKind.TypeParameterList: return visitor.visitTypeParameterList(<TypeParameterListSyntax>element);
|
||||
case SyntaxKind.HeritageClause: return visitor.visitHeritageClause(<HeritageClauseSyntax>element);
|
||||
case SyntaxKind.EqualsValueClause: return visitor.visitEqualsValueClause(<EqualsValueClauseSyntax>element);
|
||||
case SyntaxKind.CaseSwitchClause: return visitor.visitCaseSwitchClause(<CaseSwitchClauseSyntax>element);
|
||||
case SyntaxKind.DefaultSwitchClause: return visitor.visitDefaultSwitchClause(<DefaultSwitchClauseSyntax>element);
|
||||
case SyntaxKind.ElseClause: return visitor.visitElseClause(<ElseClauseSyntax>element);
|
||||
case SyntaxKind.CatchClause: return visitor.visitCatchClause(<CatchClauseSyntax>element);
|
||||
case SyntaxKind.FinallyClause: return visitor.visitFinallyClause(<FinallyClauseSyntax>element);
|
||||
case SyntaxKind.TypeParameter: return visitor.visitTypeParameter(<TypeParameterSyntax>element);
|
||||
case SyntaxKind.Constraint: return visitor.visitConstraint(<ConstraintSyntax>element);
|
||||
case SyntaxKind.SimplePropertyAssignment: return visitor.visitSimplePropertyAssignment(<SimplePropertyAssignmentSyntax>element);
|
||||
case SyntaxKind.FunctionPropertyAssignment: return visitor.visitFunctionPropertyAssignment(<FunctionPropertyAssignmentSyntax>element);
|
||||
case SyntaxKind.Parameter: return visitor.visitParameter(<ParameterSyntax>element);
|
||||
case SyntaxKind.EnumElement: return visitor.visitEnumElement(<EnumElementSyntax>element);
|
||||
case SyntaxKind.TypeAnnotation: return visitor.visitTypeAnnotation(<TypeAnnotationSyntax>element);
|
||||
case SyntaxKind.ExternalModuleReference: return visitor.visitExternalModuleReference(<ExternalModuleReferenceSyntax>element);
|
||||
case SyntaxKind.ModuleNameModuleReference: return visitor.visitModuleNameModuleReference(<ModuleNameModuleReferenceSyntax>element);
|
||||
}
|
||||
|
||||
throw Errors.invalidOperation();
|
||||
return element.accept(visitor);
|
||||
}
|
||||
|
||||
export interface ISyntaxVisitor {
|
||||
|
||||
@@ -13,16 +13,28 @@ module TypeScript {
|
||||
this.visitToken(token);
|
||||
}
|
||||
|
||||
private visitOptionalNode(node: ISyntaxNode): void {
|
||||
if (node === undefined) {
|
||||
return;
|
||||
}
|
||||
|
||||
node.accept(this);
|
||||
}
|
||||
|
||||
public visitList(list: ISyntaxNodeOrToken[]): void {
|
||||
for (var i = 0, n = list.length; i < n; i++) {
|
||||
visitNodeOrToken(this, list[i]);
|
||||
list[i].accept(this);
|
||||
}
|
||||
}
|
||||
|
||||
public visitSeparatedList(list: ISyntaxNodeOrToken[]): void {
|
||||
for (var i = 0, n = childCount(list); i < n; i++) {
|
||||
var item = childAt(list, i);
|
||||
visitNodeOrToken(this, item);
|
||||
for (var i = 0, n = separatedListChildCount(list); i < n; i++) {
|
||||
if (i % 2 === 0) {
|
||||
list[i >> 1].accept(this);
|
||||
}
|
||||
else {
|
||||
this.visitToken(list.separators[i >> 1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,7 +44,7 @@ module TypeScript {
|
||||
}
|
||||
|
||||
public visitQualifiedName(node: QualifiedNameSyntax): void {
|
||||
visitNodeOrToken(this, node.left);
|
||||
node.left.accept(this);
|
||||
this.visitToken(node.dotToken);
|
||||
this.visitToken(node.right);
|
||||
}
|
||||
@@ -44,34 +56,34 @@ module TypeScript {
|
||||
}
|
||||
|
||||
public visitFunctionType(node: FunctionTypeSyntax): void {
|
||||
visitNodeOrToken(this, node.typeParameterList);
|
||||
visitNodeOrToken(this, node.parameterList);
|
||||
this.visitOptionalNode(node.typeParameterList);
|
||||
node.parameterList.accept(this);
|
||||
this.visitToken(node.equalsGreaterThanToken);
|
||||
visitNodeOrToken(this, node.type);
|
||||
node.type.accept(this);
|
||||
}
|
||||
|
||||
public visitArrayType(node: ArrayTypeSyntax): void {
|
||||
visitNodeOrToken(this, node.type);
|
||||
node.type.accept(this);
|
||||
this.visitToken(node.openBracketToken);
|
||||
this.visitToken(node.closeBracketToken);
|
||||
}
|
||||
|
||||
public visitConstructorType(node: ConstructorTypeSyntax): void {
|
||||
this.visitToken(node.newKeyword);
|
||||
visitNodeOrToken(this, node.typeParameterList);
|
||||
visitNodeOrToken(this, node.parameterList);
|
||||
this.visitOptionalNode(node.typeParameterList);
|
||||
node.parameterList.accept(this);
|
||||
this.visitToken(node.equalsGreaterThanToken);
|
||||
visitNodeOrToken(this, node.type);
|
||||
node.type.accept(this);
|
||||
}
|
||||
|
||||
public visitGenericType(node: GenericTypeSyntax): void {
|
||||
visitNodeOrToken(this, node.name);
|
||||
visitNodeOrToken(this, node.typeArgumentList);
|
||||
node.name.accept(this);
|
||||
node.typeArgumentList.accept(this);
|
||||
}
|
||||
|
||||
public visitTypeQuery(node: TypeQuerySyntax): void {
|
||||
this.visitToken(node.typeOfKeyword);
|
||||
visitNodeOrToken(this, node.name);
|
||||
node.name.accept(this);
|
||||
}
|
||||
|
||||
public visitTupleType(node: TupleTypeSyntax): void {
|
||||
@@ -81,14 +93,14 @@ module TypeScript {
|
||||
}
|
||||
|
||||
public visitUnionType(node: UnionTypeSyntax): void {
|
||||
visitNodeOrToken(this, node.left);
|
||||
node.left.accept(this);
|
||||
this.visitToken(node.barToken);
|
||||
visitNodeOrToken(this, node.right);
|
||||
node.right.accept(this);
|
||||
}
|
||||
|
||||
public visitParenthesizedType(node: ParenthesizedTypeSyntax): void {
|
||||
this.visitToken(node.openParenToken);
|
||||
visitNodeOrToken(this, node.type);
|
||||
node.type.accept(this);
|
||||
this.visitToken(node.closeParenToken);
|
||||
}
|
||||
|
||||
@@ -96,17 +108,17 @@ module TypeScript {
|
||||
this.visitList(node.modifiers);
|
||||
this.visitToken(node.interfaceKeyword);
|
||||
this.visitToken(node.identifier);
|
||||
visitNodeOrToken(this, node.typeParameterList);
|
||||
this.visitOptionalNode(node.typeParameterList);
|
||||
this.visitList(node.heritageClauses);
|
||||
visitNodeOrToken(this, node.body);
|
||||
node.body.accept(this);
|
||||
}
|
||||
|
||||
public visitFunctionDeclaration(node: FunctionDeclarationSyntax): void {
|
||||
this.visitList(node.modifiers);
|
||||
this.visitToken(node.functionKeyword);
|
||||
this.visitToken(node.identifier);
|
||||
visitNodeOrToken(this, node.callSignature);
|
||||
visitNodeOrToken(this, node.block);
|
||||
node.callSignature.accept(this);
|
||||
this.visitOptionalNode(node.block);
|
||||
this.visitOptionalToken(node.semicolonToken);
|
||||
}
|
||||
|
||||
@@ -124,7 +136,7 @@ module TypeScript {
|
||||
this.visitList(node.modifiers);
|
||||
this.visitToken(node.classKeyword);
|
||||
this.visitToken(node.identifier);
|
||||
visitNodeOrToken(this, node.typeParameterList);
|
||||
this.visitOptionalNode(node.typeParameterList);
|
||||
this.visitList(node.heritageClauses);
|
||||
this.visitToken(node.openBraceToken);
|
||||
this.visitList(node.classElements);
|
||||
@@ -145,7 +157,7 @@ module TypeScript {
|
||||
this.visitToken(node.importKeyword);
|
||||
this.visitToken(node.identifier);
|
||||
this.visitToken(node.equalsToken);
|
||||
visitNodeOrToken(this, node.moduleReference);
|
||||
node.moduleReference.accept(this);
|
||||
this.visitOptionalToken(node.semicolonToken);
|
||||
}
|
||||
|
||||
@@ -159,28 +171,28 @@ module TypeScript {
|
||||
public visitMemberFunctionDeclaration(node: MemberFunctionDeclarationSyntax): void {
|
||||
this.visitList(node.modifiers);
|
||||
this.visitToken(node.propertyName);
|
||||
visitNodeOrToken(this, node.callSignature);
|
||||
visitNodeOrToken(this, node.block);
|
||||
node.callSignature.accept(this);
|
||||
this.visitOptionalNode(node.block);
|
||||
this.visitOptionalToken(node.semicolonToken);
|
||||
}
|
||||
|
||||
public visitMemberVariableDeclaration(node: MemberVariableDeclarationSyntax): void {
|
||||
this.visitList(node.modifiers);
|
||||
visitNodeOrToken(this, node.variableDeclarator);
|
||||
node.variableDeclarator.accept(this);
|
||||
this.visitOptionalToken(node.semicolonToken);
|
||||
}
|
||||
|
||||
public visitConstructorDeclaration(node: ConstructorDeclarationSyntax): void {
|
||||
this.visitList(node.modifiers);
|
||||
this.visitToken(node.constructorKeyword);
|
||||
visitNodeOrToken(this, node.callSignature);
|
||||
visitNodeOrToken(this, node.block);
|
||||
node.callSignature.accept(this);
|
||||
this.visitOptionalNode(node.block);
|
||||
this.visitOptionalToken(node.semicolonToken);
|
||||
}
|
||||
|
||||
public visitIndexMemberDeclaration(node: IndexMemberDeclarationSyntax): void {
|
||||
this.visitList(node.modifiers);
|
||||
visitNodeOrToken(this, node.indexSignature);
|
||||
node.indexSignature.accept(this);
|
||||
this.visitOptionalToken(node.semicolonToken);
|
||||
}
|
||||
|
||||
@@ -188,46 +200,46 @@ module TypeScript {
|
||||
this.visitList(node.modifiers);
|
||||
this.visitToken(node.getKeyword);
|
||||
this.visitToken(node.propertyName);
|
||||
visitNodeOrToken(this, node.callSignature);
|
||||
visitNodeOrToken(this, node.block);
|
||||
node.callSignature.accept(this);
|
||||
node.block.accept(this);
|
||||
}
|
||||
|
||||
public visitSetAccessor(node: SetAccessorSyntax): void {
|
||||
this.visitList(node.modifiers);
|
||||
this.visitToken(node.setKeyword);
|
||||
this.visitToken(node.propertyName);
|
||||
visitNodeOrToken(this, node.callSignature);
|
||||
visitNodeOrToken(this, node.block);
|
||||
node.callSignature.accept(this);
|
||||
node.block.accept(this);
|
||||
}
|
||||
|
||||
public visitPropertySignature(node: PropertySignatureSyntax): void {
|
||||
this.visitToken(node.propertyName);
|
||||
this.visitOptionalToken(node.questionToken);
|
||||
visitNodeOrToken(this, node.typeAnnotation);
|
||||
this.visitOptionalNode(node.typeAnnotation);
|
||||
}
|
||||
|
||||
public visitCallSignature(node: CallSignatureSyntax): void {
|
||||
visitNodeOrToken(this, node.typeParameterList);
|
||||
visitNodeOrToken(this, node.parameterList);
|
||||
visitNodeOrToken(this, node.typeAnnotation);
|
||||
this.visitOptionalNode(node.typeParameterList);
|
||||
node.parameterList.accept(this);
|
||||
this.visitOptionalNode(node.typeAnnotation);
|
||||
}
|
||||
|
||||
public visitConstructSignature(node: ConstructSignatureSyntax): void {
|
||||
this.visitToken(node.newKeyword);
|
||||
visitNodeOrToken(this, node.callSignature);
|
||||
node.callSignature.accept(this);
|
||||
}
|
||||
|
||||
public visitIndexSignature(node: IndexSignatureSyntax): void {
|
||||
this.visitToken(node.openBracketToken);
|
||||
this.visitSeparatedList(node.parameters);
|
||||
this.visitToken(node.closeBracketToken);
|
||||
visitNodeOrToken(this, node.typeAnnotation);
|
||||
this.visitOptionalNode(node.typeAnnotation);
|
||||
}
|
||||
|
||||
public visitMethodSignature(node: MethodSignatureSyntax): void {
|
||||
this.visitToken(node.propertyName);
|
||||
this.visitOptionalToken(node.questionToken);
|
||||
visitNodeOrToken(this, node.callSignature);
|
||||
node.callSignature.accept(this);
|
||||
}
|
||||
|
||||
public visitBlock(node: BlockSyntax): void {
|
||||
@@ -239,20 +251,20 @@ module TypeScript {
|
||||
public visitIfStatement(node: IfStatementSyntax): void {
|
||||
this.visitToken(node.ifKeyword);
|
||||
this.visitToken(node.openParenToken);
|
||||
visitNodeOrToken(this, node.condition);
|
||||
node.condition.accept(this);
|
||||
this.visitToken(node.closeParenToken);
|
||||
visitNodeOrToken(this, node.statement);
|
||||
visitNodeOrToken(this, node.elseClause);
|
||||
node.statement.accept(this);
|
||||
this.visitOptionalNode(node.elseClause);
|
||||
}
|
||||
|
||||
public visitVariableStatement(node: VariableStatementSyntax): void {
|
||||
this.visitList(node.modifiers);
|
||||
visitNodeOrToken(this, node.variableDeclaration);
|
||||
node.variableDeclaration.accept(this);
|
||||
this.visitOptionalToken(node.semicolonToken);
|
||||
}
|
||||
|
||||
public visitExpressionStatement(node: ExpressionStatementSyntax): void {
|
||||
visitNodeOrToken(this, node.expression);
|
||||
node.expression.accept(this);
|
||||
this.visitOptionalToken(node.semicolonToken);
|
||||
}
|
||||
|
||||
@@ -265,7 +277,7 @@ module TypeScript {
|
||||
public visitSwitchStatement(node: SwitchStatementSyntax): void {
|
||||
this.visitToken(node.switchKeyword);
|
||||
this.visitToken(node.openParenToken);
|
||||
visitNodeOrToken(this, node.expression);
|
||||
node.expression.accept(this);
|
||||
this.visitToken(node.closeParenToken);
|
||||
this.visitToken(node.openBraceToken);
|
||||
this.visitList(node.switchClauses);
|
||||
@@ -287,25 +299,25 @@ module TypeScript {
|
||||
public visitForStatement(node: ForStatementSyntax): void {
|
||||
this.visitToken(node.forKeyword);
|
||||
this.visitToken(node.openParenToken);
|
||||
visitNodeOrToken(this, node.variableDeclaration);
|
||||
this.visitOptionalNode(node.variableDeclaration);
|
||||
visitNodeOrToken(this, node.initializer);
|
||||
this.visitToken(node.firstSemicolonToken);
|
||||
visitNodeOrToken(this, node.condition);
|
||||
this.visitToken(node.secondSemicolonToken);
|
||||
visitNodeOrToken(this, node.incrementor);
|
||||
this.visitToken(node.closeParenToken);
|
||||
visitNodeOrToken(this, node.statement);
|
||||
node.statement.accept(this);
|
||||
}
|
||||
|
||||
public visitForInStatement(node: ForInStatementSyntax): void {
|
||||
this.visitToken(node.forKeyword);
|
||||
this.visitToken(node.openParenToken);
|
||||
visitNodeOrToken(this, node.variableDeclaration);
|
||||
this.visitOptionalNode(node.variableDeclaration);
|
||||
visitNodeOrToken(this, node.left);
|
||||
this.visitToken(node.inKeyword);
|
||||
visitNodeOrToken(this, node.expression);
|
||||
node.expression.accept(this);
|
||||
this.visitToken(node.closeParenToken);
|
||||
visitNodeOrToken(this, node.statement);
|
||||
node.statement.accept(this);
|
||||
}
|
||||
|
||||
public visitEmptyStatement(node: EmptyStatementSyntax): void {
|
||||
@@ -314,37 +326,37 @@ module TypeScript {
|
||||
|
||||
public visitThrowStatement(node: ThrowStatementSyntax): void {
|
||||
this.visitToken(node.throwKeyword);
|
||||
visitNodeOrToken(this, node.expression);
|
||||
node.expression.accept(this);
|
||||
this.visitOptionalToken(node.semicolonToken);
|
||||
}
|
||||
|
||||
public visitWhileStatement(node: WhileStatementSyntax): void {
|
||||
this.visitToken(node.whileKeyword);
|
||||
this.visitToken(node.openParenToken);
|
||||
visitNodeOrToken(this, node.condition);
|
||||
node.condition.accept(this);
|
||||
this.visitToken(node.closeParenToken);
|
||||
visitNodeOrToken(this, node.statement);
|
||||
node.statement.accept(this);
|
||||
}
|
||||
|
||||
public visitTryStatement(node: TryStatementSyntax): void {
|
||||
this.visitToken(node.tryKeyword);
|
||||
visitNodeOrToken(this, node.block);
|
||||
visitNodeOrToken(this, node.catchClause);
|
||||
visitNodeOrToken(this, node.finallyClause);
|
||||
node.block.accept(this);
|
||||
this.visitOptionalNode(node.catchClause);
|
||||
this.visitOptionalNode(node.finallyClause);
|
||||
}
|
||||
|
||||
public visitLabeledStatement(node: LabeledStatementSyntax): void {
|
||||
this.visitToken(node.identifier);
|
||||
this.visitToken(node.colonToken);
|
||||
visitNodeOrToken(this, node.statement);
|
||||
node.statement.accept(this);
|
||||
}
|
||||
|
||||
public visitDoStatement(node: DoStatementSyntax): void {
|
||||
this.visitToken(node.doKeyword);
|
||||
visitNodeOrToken(this, node.statement);
|
||||
node.statement.accept(this);
|
||||
this.visitToken(node.whileKeyword);
|
||||
this.visitToken(node.openParenToken);
|
||||
visitNodeOrToken(this, node.condition);
|
||||
node.condition.accept(this);
|
||||
this.visitToken(node.closeParenToken);
|
||||
this.visitOptionalToken(node.semicolonToken);
|
||||
}
|
||||
@@ -357,59 +369,59 @@ module TypeScript {
|
||||
public visitWithStatement(node: WithStatementSyntax): void {
|
||||
this.visitToken(node.withKeyword);
|
||||
this.visitToken(node.openParenToken);
|
||||
visitNodeOrToken(this, node.condition);
|
||||
node.condition.accept(this);
|
||||
this.visitToken(node.closeParenToken);
|
||||
visitNodeOrToken(this, node.statement);
|
||||
node.statement.accept(this);
|
||||
}
|
||||
|
||||
public visitPrefixUnaryExpression(node: PrefixUnaryExpressionSyntax): void {
|
||||
this.visitToken(node.operatorToken);
|
||||
visitNodeOrToken(this, node.operand);
|
||||
node.operand.accept(this);
|
||||
}
|
||||
|
||||
public visitDeleteExpression(node: DeleteExpressionSyntax): void {
|
||||
this.visitToken(node.deleteKeyword);
|
||||
visitNodeOrToken(this, node.expression);
|
||||
node.expression.accept(this);
|
||||
}
|
||||
|
||||
public visitTypeOfExpression(node: TypeOfExpressionSyntax): void {
|
||||
this.visitToken(node.typeOfKeyword);
|
||||
visitNodeOrToken(this, node.expression);
|
||||
node.expression.accept(this);
|
||||
}
|
||||
|
||||
public visitVoidExpression(node: VoidExpressionSyntax): void {
|
||||
this.visitToken(node.voidKeyword);
|
||||
visitNodeOrToken(this, node.expression);
|
||||
node.expression.accept(this);
|
||||
}
|
||||
|
||||
public visitConditionalExpression(node: ConditionalExpressionSyntax): void {
|
||||
visitNodeOrToken(this, node.condition);
|
||||
node.condition.accept(this);
|
||||
this.visitToken(node.questionToken);
|
||||
visitNodeOrToken(this, node.whenTrue);
|
||||
node.whenTrue.accept(this);
|
||||
this.visitToken(node.colonToken);
|
||||
visitNodeOrToken(this, node.whenFalse);
|
||||
node.whenFalse.accept(this);
|
||||
}
|
||||
|
||||
public visitBinaryExpression(node: BinaryExpressionSyntax): void {
|
||||
visitNodeOrToken(this, node.left);
|
||||
node.left.accept(this);
|
||||
this.visitToken(node.operatorToken);
|
||||
visitNodeOrToken(this, node.right);
|
||||
node.right.accept(this);
|
||||
}
|
||||
|
||||
public visitPostfixUnaryExpression(node: PostfixUnaryExpressionSyntax): void {
|
||||
visitNodeOrToken(this, node.operand);
|
||||
node.operand.accept(this);
|
||||
this.visitToken(node.operatorToken);
|
||||
}
|
||||
|
||||
public visitMemberAccessExpression(node: MemberAccessExpressionSyntax): void {
|
||||
visitNodeOrToken(this, node.expression);
|
||||
node.expression.accept(this);
|
||||
this.visitToken(node.dotToken);
|
||||
this.visitToken(node.name);
|
||||
}
|
||||
|
||||
public visitInvocationExpression(node: InvocationExpressionSyntax): void {
|
||||
visitNodeOrToken(this, node.expression);
|
||||
visitNodeOrToken(this, node.argumentList);
|
||||
node.expression.accept(this);
|
||||
node.argumentList.accept(this);
|
||||
}
|
||||
|
||||
public visitArrayLiteralExpression(node: ArrayLiteralExpressionSyntax): void {
|
||||
@@ -426,49 +438,49 @@ module TypeScript {
|
||||
|
||||
public visitObjectCreationExpression(node: ObjectCreationExpressionSyntax): void {
|
||||
this.visitToken(node.newKeyword);
|
||||
visitNodeOrToken(this, node.expression);
|
||||
visitNodeOrToken(this, node.argumentList);
|
||||
node.expression.accept(this);
|
||||
this.visitOptionalNode(node.argumentList);
|
||||
}
|
||||
|
||||
public visitParenthesizedExpression(node: ParenthesizedExpressionSyntax): void {
|
||||
this.visitToken(node.openParenToken);
|
||||
visitNodeOrToken(this, node.expression);
|
||||
node.expression.accept(this);
|
||||
this.visitToken(node.closeParenToken);
|
||||
}
|
||||
|
||||
public visitParenthesizedArrowFunctionExpression(node: ParenthesizedArrowFunctionExpressionSyntax): void {
|
||||
visitNodeOrToken(this, node.callSignature);
|
||||
node.callSignature.accept(this);
|
||||
this.visitToken(node.equalsGreaterThanToken);
|
||||
visitNodeOrToken(this, node.block);
|
||||
this.visitOptionalNode(node.block);
|
||||
visitNodeOrToken(this, node.expression);
|
||||
}
|
||||
|
||||
public visitSimpleArrowFunctionExpression(node: SimpleArrowFunctionExpressionSyntax): void {
|
||||
visitNodeOrToken(this, node.parameter);
|
||||
node.parameter.accept(this);
|
||||
this.visitToken(node.equalsGreaterThanToken);
|
||||
visitNodeOrToken(this, node.block);
|
||||
this.visitOptionalNode(node.block);
|
||||
visitNodeOrToken(this, node.expression);
|
||||
}
|
||||
|
||||
public visitCastExpression(node: CastExpressionSyntax): void {
|
||||
this.visitToken(node.lessThanToken);
|
||||
visitNodeOrToken(this, node.type);
|
||||
node.type.accept(this);
|
||||
this.visitToken(node.greaterThanToken);
|
||||
visitNodeOrToken(this, node.expression);
|
||||
node.expression.accept(this);
|
||||
}
|
||||
|
||||
public visitElementAccessExpression(node: ElementAccessExpressionSyntax): void {
|
||||
visitNodeOrToken(this, node.expression);
|
||||
node.expression.accept(this);
|
||||
this.visitToken(node.openBracketToken);
|
||||
visitNodeOrToken(this, node.argumentExpression);
|
||||
node.argumentExpression.accept(this);
|
||||
this.visitToken(node.closeBracketToken);
|
||||
}
|
||||
|
||||
public visitFunctionExpression(node: FunctionExpressionSyntax): void {
|
||||
this.visitToken(node.functionKeyword);
|
||||
this.visitOptionalToken(node.identifier);
|
||||
visitNodeOrToken(this, node.callSignature);
|
||||
visitNodeOrToken(this, node.block);
|
||||
node.callSignature.accept(this);
|
||||
node.block.accept(this);
|
||||
}
|
||||
|
||||
public visitOmittedExpression(node: OmittedExpressionSyntax): void {
|
||||
@@ -481,12 +493,12 @@ module TypeScript {
|
||||
|
||||
public visitVariableDeclarator(node: VariableDeclaratorSyntax): void {
|
||||
this.visitToken(node.propertyName);
|
||||
visitNodeOrToken(this, node.typeAnnotation);
|
||||
visitNodeOrToken(this, node.equalsValueClause);
|
||||
this.visitOptionalNode(node.typeAnnotation);
|
||||
this.visitOptionalNode(node.equalsValueClause);
|
||||
}
|
||||
|
||||
public visitArgumentList(node: ArgumentListSyntax): void {
|
||||
visitNodeOrToken(this, node.typeArgumentList);
|
||||
this.visitOptionalNode(node.typeArgumentList);
|
||||
this.visitToken(node.openParenToken);
|
||||
this.visitSeparatedList(node.arguments);
|
||||
this.visitToken(node.closeParenToken);
|
||||
@@ -517,12 +529,12 @@ module TypeScript {
|
||||
|
||||
public visitEqualsValueClause(node: EqualsValueClauseSyntax): void {
|
||||
this.visitToken(node.equalsToken);
|
||||
visitNodeOrToken(this, node.value);
|
||||
node.value.accept(this);
|
||||
}
|
||||
|
||||
public visitCaseSwitchClause(node: CaseSwitchClauseSyntax): void {
|
||||
this.visitToken(node.caseKeyword);
|
||||
visitNodeOrToken(this, node.expression);
|
||||
node.expression.accept(this);
|
||||
this.visitToken(node.colonToken);
|
||||
this.visitList(node.statements);
|
||||
}
|
||||
@@ -535,43 +547,43 @@ module TypeScript {
|
||||
|
||||
public visitElseClause(node: ElseClauseSyntax): void {
|
||||
this.visitToken(node.elseKeyword);
|
||||
visitNodeOrToken(this, node.statement);
|
||||
node.statement.accept(this);
|
||||
}
|
||||
|
||||
public visitCatchClause(node: CatchClauseSyntax): void {
|
||||
this.visitToken(node.catchKeyword);
|
||||
this.visitToken(node.openParenToken);
|
||||
this.visitToken(node.identifier);
|
||||
visitNodeOrToken(this, node.typeAnnotation);
|
||||
this.visitOptionalNode(node.typeAnnotation);
|
||||
this.visitToken(node.closeParenToken);
|
||||
visitNodeOrToken(this, node.block);
|
||||
node.block.accept(this);
|
||||
}
|
||||
|
||||
public visitFinallyClause(node: FinallyClauseSyntax): void {
|
||||
this.visitToken(node.finallyKeyword);
|
||||
visitNodeOrToken(this, node.block);
|
||||
node.block.accept(this);
|
||||
}
|
||||
|
||||
public visitTypeParameter(node: TypeParameterSyntax): void {
|
||||
this.visitToken(node.identifier);
|
||||
visitNodeOrToken(this, node.constraint);
|
||||
this.visitOptionalNode(node.constraint);
|
||||
}
|
||||
|
||||
public visitConstraint(node: ConstraintSyntax): void {
|
||||
this.visitToken(node.extendsKeyword);
|
||||
visitNodeOrToken(this, node.typeOrExpression);
|
||||
node.typeOrExpression.accept(this);
|
||||
}
|
||||
|
||||
public visitSimplePropertyAssignment(node: SimplePropertyAssignmentSyntax): void {
|
||||
this.visitToken(node.propertyName);
|
||||
this.visitToken(node.colonToken);
|
||||
visitNodeOrToken(this, node.expression);
|
||||
node.expression.accept(this);
|
||||
}
|
||||
|
||||
public visitFunctionPropertyAssignment(node: FunctionPropertyAssignmentSyntax): void {
|
||||
this.visitToken(node.propertyName);
|
||||
visitNodeOrToken(this, node.callSignature);
|
||||
visitNodeOrToken(this, node.block);
|
||||
node.callSignature.accept(this);
|
||||
node.block.accept(this);
|
||||
}
|
||||
|
||||
public visitParameter(node: ParameterSyntax): void {
|
||||
@@ -579,18 +591,18 @@ module TypeScript {
|
||||
this.visitList(node.modifiers);
|
||||
this.visitToken(node.identifier);
|
||||
this.visitOptionalToken(node.questionToken);
|
||||
visitNodeOrToken(this, node.typeAnnotation);
|
||||
visitNodeOrToken(this, node.equalsValueClause);
|
||||
this.visitOptionalNode(node.typeAnnotation);
|
||||
this.visitOptionalNode(node.equalsValueClause);
|
||||
}
|
||||
|
||||
public visitEnumElement(node: EnumElementSyntax): void {
|
||||
this.visitToken(node.propertyName);
|
||||
visitNodeOrToken(this, node.equalsValueClause);
|
||||
this.visitOptionalNode(node.equalsValueClause);
|
||||
}
|
||||
|
||||
public visitTypeAnnotation(node: TypeAnnotationSyntax): void {
|
||||
this.visitToken(node.colonToken);
|
||||
visitNodeOrToken(this, node.type);
|
||||
node.type.accept(this);
|
||||
}
|
||||
|
||||
public visitExternalModuleReference(node: ExternalModuleReferenceSyntax): void {
|
||||
@@ -601,7 +613,7 @@ module TypeScript {
|
||||
}
|
||||
|
||||
public visitModuleNameModuleReference(node: ModuleNameModuleReferenceSyntax): void {
|
||||
visitNodeOrToken(this, node.moduleName);
|
||||
node.moduleName.accept(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -13,11 +13,11 @@ module TypeScript {
|
||||
Debug.assert(node2.kind() === TypeScript.SyntaxKind.SourceUnit || node2.parent);
|
||||
|
||||
if (node1.kind() !== node2.kind()) { return false; }
|
||||
if (childCount(node1) !== childCount(node2)) { return false; }
|
||||
if (node1.childCount() !== node2.childCount()) { return false; }
|
||||
|
||||
for (var i = 0, n = childCount(node1); i < n; i++) {
|
||||
var element1 = childAt(node1, i);
|
||||
var element2 = childAt(node2, i);
|
||||
for (var i = 0, n = node1.childCount(); i < n; i++) {
|
||||
var element1 = node1.childAt(i);
|
||||
var element2 = node2.childAt(i);
|
||||
|
||||
if (checkParents) {
|
||||
assertParent(node1, element1);
|
||||
@@ -105,13 +105,13 @@ module TypeScript {
|
||||
Debug.assert(TypeScript.isShared(list1) || list1.parent);
|
||||
Debug.assert(TypeScript.isShared(list2) || list2.parent);
|
||||
|
||||
if (childCount(list1) !== childCount(list2)) {
|
||||
if (list1.childCount() !== list2.childCount()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (var i = 0, n = childCount(list1); i < n; i++) {
|
||||
var child1 = childAt(list1, i);
|
||||
var child2 = childAt(list2, i);
|
||||
for (var i = 0, n = list1.childCount(); i < n; i++) {
|
||||
var child1 = list1.childAt(i);
|
||||
var child2 = list2.childAt(i);
|
||||
|
||||
if (checkParents) {
|
||||
assertParent(list1, child1);
|
||||
@@ -130,13 +130,13 @@ module TypeScript {
|
||||
Debug.assert(TypeScript.isShared(list1) || list1.parent);
|
||||
Debug.assert(TypeScript.isShared(list2) || list2.parent);
|
||||
|
||||
if (childCount(list1) !== childCount(list2)) {
|
||||
if (list1.childCount() !== list2.childCount()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (var i = 0, n = childCount(list1); i < n; i++) {
|
||||
var element1 = childAt(list1, i);
|
||||
var element2 = childAt(list2, i);
|
||||
for (var i = 0, n = list1.childCount(); i < n; i++) {
|
||||
var element1 = list1.childAt(i);
|
||||
var element2 = list2.childAt(i);
|
||||
|
||||
if (checkParents) {
|
||||
assertParent(list1, element1);
|
||||
|
||||
Reference in new issue
Block a user