Skip to content

Commit f59cb60

Browse files
Simplify API for nodes htat have both a block and a semicolon token.
Conflicts: src/services/syntax/SyntaxGenerator.js.map
1 parent 535dc0d commit f59cb60

8 files changed

Lines changed: 56 additions & 94 deletions

src/services/syntax/SyntaxGenerator.js

Lines changed: 3 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/services/syntax/SyntaxGenerator.js.map

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/services/syntax/parser.ts

Lines changed: 15 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1130,21 +1130,13 @@ module TypeScript.Parser {
11301130
}
11311131

11321132
function parseConstructorDeclaration(): ConstructorDeclarationSyntax {
1133-
var modifiers = parseModifiers();
1134-
var constructorKeyword = eatToken(SyntaxKind.ConstructorKeyword);
1135-
var callSignature = parseCallSignature(/*requireCompleteTypeParameterList:*/ false);
1136-
1137-
var semicolonToken: ISyntaxToken = undefined;
1138-
var block: BlockSyntax = undefined;
1139-
1140-
if (isBlock()) {
1141-
block = parseBlock(/*parseStatementsEvenWithNoOpenBrace:*/ false, /*checkForStrictMode:*/ true);
1142-
}
1143-
else {
1144-
semicolonToken = eatExplicitOrAutomaticSemicolon(/*allowWithoutNewline:*/ false);
1145-
}
1146-
1147-
return new ConstructorDeclarationSyntax(parseNodeData, modifiers, constructorKeyword, callSignature, block, semicolonToken);
1133+
return new ConstructorDeclarationSyntax(parseNodeData,
1134+
parseModifiers(),
1135+
eatToken(SyntaxKind.ConstructorKeyword),
1136+
parseCallSignature(/*requireCompleteTypeParameterList:*/ false),
1137+
isBlock()
1138+
? parseBlock(/*parseStatementsEvenWithNoOpenBrace:*/ false, /*checkForStrictMode:*/ true)
1139+
: eatExplicitOrAutomaticSemicolon(/*allowWithoutNewline:*/ false));
11481140
}
11491141

11501142
function parseMemberFunctionDeclaration(modifiers: ISyntaxToken[], propertyName: IPropertyNameSyntax): MemberFunctionDeclarationSyntax {
@@ -1153,18 +1145,11 @@ module TypeScript.Parser {
11531145
// If we got an errant => then we want to parse what's coming up without requiring an
11541146
// open brace.
11551147
var parseBlockEvenWithNoOpenBrace = tryAddUnexpectedEqualsGreaterThanToken(callSignature);
1148+
var blockOrSemicolonToken = parseBlockEvenWithNoOpenBrace || isBlock()
1149+
? parseBlock(parseBlockEvenWithNoOpenBrace, /*checkForStrictMode:*/ true)
1150+
: eatExplicitOrAutomaticSemicolon(/*allowWithoutNewline:*/ false);
11561151

1157-
var block: BlockSyntax = undefined;
1158-
var semicolon: ISyntaxToken = undefined;
1159-
1160-
if (parseBlockEvenWithNoOpenBrace || isBlock()) {
1161-
block = parseBlock(parseBlockEvenWithNoOpenBrace, /*checkForStrictMode:*/ true);
1162-
}
1163-
else {
1164-
semicolon = eatExplicitOrAutomaticSemicolon(/*allowWithoutNewline:*/ false);
1165-
}
1166-
1167-
return new MemberFunctionDeclarationSyntax(parseNodeData, modifiers, propertyName, callSignature, block, semicolon);
1152+
return new MemberFunctionDeclarationSyntax(parseNodeData, modifiers, propertyName, callSignature, blockOrSemicolonToken);
11681153
}
11691154

11701155
function parseMemberVariableDeclaration(modifiers: ISyntaxToken[], propertyName: IPropertyNameSyntax): MemberVariableDeclarationSyntax {
@@ -1226,18 +1211,12 @@ module TypeScript.Parser {
12261211
// open brace.
12271212
var parseBlockEvenWithNoOpenBrace = tryAddUnexpectedEqualsGreaterThanToken(callSignature);
12281213

1229-
var semicolonToken: ISyntaxToken = undefined;
1230-
var block: BlockSyntax = undefined;
1231-
12321214
// Parse a block if we're on a bock, or if we saw a '=>'
1233-
if (parseBlockEvenWithNoOpenBrace || isBlock()) {
1234-
block = parseBlock(parseBlockEvenWithNoOpenBrace, /*checkForStrictMode:*/ true);
1235-
}
1236-
else {
1237-
semicolonToken = eatExplicitOrAutomaticSemicolon(/*allowWithoutNewline:*/ false);
1238-
}
1215+
var blockOrSemicolonToken = parseBlockEvenWithNoOpenBrace || isBlock()
1216+
? parseBlock(parseBlockEvenWithNoOpenBrace, /*checkForStrictMode:*/ true)
1217+
: eatExplicitOrAutomaticSemicolon(/*allowWithoutNewline:*/ false);
12391218

1240-
return new FunctionDeclarationSyntax(parseNodeData, modifiers, functionKeyword, identifier, callSignature, block, semicolonToken);
1219+
return new FunctionDeclarationSyntax(parseNodeData, modifiers, functionKeyword, identifier, callSignature, blockOrSemicolonToken);
12411220
}
12421221

12431222
function parseModuleName(): INameSyntax {

src/services/syntax/prettyPrinter.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -316,13 +316,13 @@ module TypeScript.PrettyPrinter {
316316
this.appendToken(node.closeBraceToken);
317317
}
318318

319-
private appendBlockOrSemicolon(block: BlockSyntax, semicolonToken: ISyntaxToken) {
320-
if (block) {
319+
private appendBlockOrSemicolon(body: BlockSyntax | ISyntaxToken) {
320+
if (body.kind === SyntaxKind.Block) {
321321
this.ensureSpace();
322-
visitNodeOrToken(this, block);
322+
visitNodeOrToken(this, body);
323323
}
324324
else {
325-
this.appendToken(semicolonToken);
325+
this.appendToken(<ISyntaxToken>body);
326326
}
327327
}
328328

@@ -333,7 +333,7 @@ module TypeScript.PrettyPrinter {
333333
this.ensureSpace();
334334
this.appendToken(node.identifier);
335335
this.appendNode(node.callSignature);
336-
this.appendBlockOrSemicolon(node.block, node.semicolonToken);
336+
this.appendBlockOrSemicolon(node.body);
337337
}
338338

339339
public visitVariableStatement(node: VariableStatementSyntax): void {
@@ -668,7 +668,7 @@ module TypeScript.PrettyPrinter {
668668
public visitConstructorDeclaration(node: ConstructorDeclarationSyntax): void {
669669
this.appendToken(node.constructorKeyword);
670670
visitNodeOrToken(this, node.callSignature);
671-
this.appendBlockOrSemicolon(node.block, node.semicolonToken);
671+
this.appendBlockOrSemicolon(node.body);
672672
}
673673

674674
public visitIndexMemberDeclaration(node: IndexMemberDeclarationSyntax): void {
@@ -683,7 +683,7 @@ module TypeScript.PrettyPrinter {
683683
this.ensureSpace();
684684
visitNodeOrToken(this, node.propertyName);
685685
visitNodeOrToken(this, node.callSignature);
686-
this.appendBlockOrSemicolon(node.block, node.semicolonToken);
686+
this.appendBlockOrSemicolon(node.body);
687687
}
688688

689689
public visitGetAccessor(node: GetAccessorSyntax): void {

src/services/syntax/syntaxGenerator.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,7 @@ var definitions:ITypeDefinition[] = [
160160
<any>{ name: 'functionKeyword', isToken: true, excludeFromAST: true },
161161
<any>{ name: 'identifier', isToken: true, tokenKinds: ['IdentifierName'] },
162162
<any>{ name: 'callSignature', type: 'CallSignatureSyntax' },
163-
<any>{ name: 'block', type: 'BlockSyntax', isOptional: true },
164-
<any>{ name: 'semicolonToken', isToken: true, isOptional: true, excludeFromAST: true }
163+
<any>{ name: 'body', type: 'BlockSyntax | ISyntaxToken' }
165164
]
166165
},
167166
<any>{
@@ -638,8 +637,7 @@ var definitions:ITypeDefinition[] = [
638637
<any>{ name: 'modifiers', isList: true, elementType: 'ISyntaxToken' },
639638
<any>{ name: 'constructorKeyword', isToken: true },
640639
<any>{ name: 'callSignature', type: 'CallSignatureSyntax' },
641-
<any>{ name: 'block', type: 'BlockSyntax', isOptional: true },
642-
<any>{ name: 'semicolonToken', isToken: true, isOptional: true, excludeFromAST: true }
640+
<any>{ name: 'body', type: 'BlockSyntax | ISyntaxToken', }
643641
],
644642
isTypeScriptSpecific: true
645643
},
@@ -651,8 +649,7 @@ var definitions:ITypeDefinition[] = [
651649
<any>{ name: 'modifiers', isList: true, elementType: 'ISyntaxToken' },
652650
<any>{ name: 'propertyName', type: 'IPropertyNameSyntax' },
653651
<any>{ name: 'callSignature', type: 'CallSignatureSyntax' },
654-
<any>{ name: 'block', type: 'BlockSyntax', isOptional: true },
655-
<any>{ name: 'semicolonToken', isToken: true, isOptional: true, excludeFromAST: true }
652+
<any>{ name: 'body', type: 'BlockSyntax | ISyntaxToken' }
656653
],
657654
isTypeScriptSpecific: true
658655
},

src/services/syntax/syntaxInterfaces.generated.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,9 @@ module TypeScript {
9494
functionKeyword: ISyntaxToken;
9595
identifier: ISyntaxToken;
9696
callSignature: CallSignatureSyntax;
97-
block: BlockSyntax;
98-
semicolonToken: ISyntaxToken;
97+
body: BlockSyntax | ISyntaxToken;
9998
}
100-
export interface FunctionDeclarationConstructor { new (data: number, modifiers: ISyntaxToken[], functionKeyword: ISyntaxToken, identifier: ISyntaxToken, callSignature: CallSignatureSyntax, block: BlockSyntax, semicolonToken: ISyntaxToken): FunctionDeclarationSyntax }
99+
export interface FunctionDeclarationConstructor { new (data: number, modifiers: ISyntaxToken[], functionKeyword: ISyntaxToken, identifier: ISyntaxToken, callSignature: CallSignatureSyntax, body: BlockSyntax | ISyntaxToken): FunctionDeclarationSyntax }
101100

102101
export interface ModuleDeclarationSyntax extends ISyntaxNode, IModuleElementSyntax {
103102
modifiers: ISyntaxToken[];
@@ -153,10 +152,9 @@ module TypeScript {
153152
modifiers: ISyntaxToken[];
154153
propertyName: IPropertyNameSyntax;
155154
callSignature: CallSignatureSyntax;
156-
block: BlockSyntax;
157-
semicolonToken: ISyntaxToken;
155+
body: BlockSyntax | ISyntaxToken;
158156
}
159-
export interface MemberFunctionDeclarationConstructor { new (data: number, modifiers: ISyntaxToken[], propertyName: IPropertyNameSyntax, callSignature: CallSignatureSyntax, block: BlockSyntax, semicolonToken: ISyntaxToken): MemberFunctionDeclarationSyntax }
157+
export interface MemberFunctionDeclarationConstructor { new (data: number, modifiers: ISyntaxToken[], propertyName: IPropertyNameSyntax, callSignature: CallSignatureSyntax, body: BlockSyntax | ISyntaxToken): MemberFunctionDeclarationSyntax }
160158

161159
export interface MemberVariableDeclarationSyntax extends ISyntaxNode, IMemberDeclarationSyntax {
162160
modifiers: ISyntaxToken[];
@@ -169,10 +167,9 @@ module TypeScript {
169167
modifiers: ISyntaxToken[];
170168
constructorKeyword: ISyntaxToken;
171169
callSignature: CallSignatureSyntax;
172-
block: BlockSyntax;
173-
semicolonToken: ISyntaxToken;
170+
body: BlockSyntax | ISyntaxToken;
174171
}
175-
export interface ConstructorDeclarationConstructor { new (data: number, modifiers: ISyntaxToken[], constructorKeyword: ISyntaxToken, callSignature: CallSignatureSyntax, block: BlockSyntax, semicolonToken: ISyntaxToken): ConstructorDeclarationSyntax }
172+
export interface ConstructorDeclarationConstructor { new (data: number, modifiers: ISyntaxToken[], constructorKeyword: ISyntaxToken, callSignature: CallSignatureSyntax, body: BlockSyntax | ISyntaxToken): ConstructorDeclarationSyntax }
176173

177174
export interface IndexMemberDeclarationSyntax extends ISyntaxNode, IClassElementSyntax {
178175
modifiers: ISyntaxToken[];

src/services/syntax/syntaxNodes.concrete.generated.ts

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -238,31 +238,28 @@ module TypeScript {
238238
}
239239
}
240240

241-
export var FunctionDeclarationSyntax: FunctionDeclarationConstructor = <any>function(data: number, modifiers: ISyntaxToken[], functionKeyword: ISyntaxToken, identifier: ISyntaxToken, callSignature: CallSignatureSyntax, block: BlockSyntax, semicolonToken: ISyntaxToken) {
241+
export var FunctionDeclarationSyntax: FunctionDeclarationConstructor = <any>function(data: number, modifiers: ISyntaxToken[], functionKeyword: ISyntaxToken, identifier: ISyntaxToken, callSignature: CallSignatureSyntax, body: BlockSyntax | ISyntaxToken) {
242242
if (data) { this.__data = data; }
243243
this.modifiers = modifiers,
244244
this.functionKeyword = functionKeyword,
245245
this.identifier = identifier,
246246
this.callSignature = callSignature,
247-
this.block = block,
248-
this.semicolonToken = semicolonToken,
247+
this.body = body,
249248
modifiers.parent = this,
250249
functionKeyword.parent = this,
251250
identifier.parent = this,
252251
callSignature.parent = this,
253-
block && (block.parent = this),
254-
semicolonToken && (semicolonToken.parent = this);
252+
body.parent = this;
255253
};
256254
FunctionDeclarationSyntax.prototype.kind = SyntaxKind.FunctionDeclaration;
257-
FunctionDeclarationSyntax.prototype.childCount = 6;
255+
FunctionDeclarationSyntax.prototype.childCount = 5;
258256
FunctionDeclarationSyntax.prototype.childAt = function(index: number): ISyntaxElement {
259257
switch (index) {
260258
case 0: return this.modifiers;
261259
case 1: return this.functionKeyword;
262260
case 2: return this.identifier;
263261
case 3: return this.callSignature;
264-
case 4: return this.block;
265-
case 5: return this.semicolonToken;
262+
case 4: return this.body;
266263
}
267264
}
268265

@@ -406,28 +403,25 @@ module TypeScript {
406403
}
407404
}
408405

409-
export var MemberFunctionDeclarationSyntax: MemberFunctionDeclarationConstructor = <any>function(data: number, modifiers: ISyntaxToken[], propertyName: IPropertyNameSyntax, callSignature: CallSignatureSyntax, block: BlockSyntax, semicolonToken: ISyntaxToken) {
406+
export var MemberFunctionDeclarationSyntax: MemberFunctionDeclarationConstructor = <any>function(data: number, modifiers: ISyntaxToken[], propertyName: IPropertyNameSyntax, callSignature: CallSignatureSyntax, body: BlockSyntax | ISyntaxToken) {
410407
if (data) { this.__data = data; }
411408
this.modifiers = modifiers,
412409
this.propertyName = propertyName,
413410
this.callSignature = callSignature,
414-
this.block = block,
415-
this.semicolonToken = semicolonToken,
411+
this.body = body,
416412
modifiers.parent = this,
417413
propertyName.parent = this,
418414
callSignature.parent = this,
419-
block && (block.parent = this),
420-
semicolonToken && (semicolonToken.parent = this);
415+
body.parent = this;
421416
};
422417
MemberFunctionDeclarationSyntax.prototype.kind = SyntaxKind.MemberFunctionDeclaration;
423-
MemberFunctionDeclarationSyntax.prototype.childCount = 5;
418+
MemberFunctionDeclarationSyntax.prototype.childCount = 4;
424419
MemberFunctionDeclarationSyntax.prototype.childAt = function(index: number): ISyntaxElement {
425420
switch (index) {
426421
case 0: return this.modifiers;
427422
case 1: return this.propertyName;
428423
case 2: return this.callSignature;
429-
case 3: return this.block;
430-
case 4: return this.semicolonToken;
424+
case 3: return this.body;
431425
}
432426
}
433427

@@ -450,28 +444,25 @@ module TypeScript {
450444
}
451445
}
452446

453-
export var ConstructorDeclarationSyntax: ConstructorDeclarationConstructor = <any>function(data: number, modifiers: ISyntaxToken[], constructorKeyword: ISyntaxToken, callSignature: CallSignatureSyntax, block: BlockSyntax, semicolonToken: ISyntaxToken) {
447+
export var ConstructorDeclarationSyntax: ConstructorDeclarationConstructor = <any>function(data: number, modifiers: ISyntaxToken[], constructorKeyword: ISyntaxToken, callSignature: CallSignatureSyntax, body: BlockSyntax | ISyntaxToken) {
454448
if (data) { this.__data = data; }
455449
this.modifiers = modifiers,
456450
this.constructorKeyword = constructorKeyword,
457451
this.callSignature = callSignature,
458-
this.block = block,
459-
this.semicolonToken = semicolonToken,
452+
this.body = body,
460453
modifiers.parent = this,
461454
constructorKeyword.parent = this,
462455
callSignature.parent = this,
463-
block && (block.parent = this),
464-
semicolonToken && (semicolonToken.parent = this);
456+
body.parent = this;
465457
};
466458
ConstructorDeclarationSyntax.prototype.kind = SyntaxKind.ConstructorDeclaration;
467-
ConstructorDeclarationSyntax.prototype.childCount = 5;
459+
ConstructorDeclarationSyntax.prototype.childCount = 4;
468460
ConstructorDeclarationSyntax.prototype.childAt = function(index: number): ISyntaxElement {
469461
switch (index) {
470462
case 0: return this.modifiers;
471463
case 1: return this.constructorKeyword;
472464
case 2: return this.callSignature;
473-
case 3: return this.block;
474-
case 4: return this.semicolonToken;
465+
case 3: return this.body;
475466
}
476467
}
477468

src/services/syntax/syntaxWalker.generated.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,7 @@ module TypeScript {
9999
this.visitToken(node.functionKeyword);
100100
this.visitToken(node.identifier);
101101
visitNodeOrToken(this, node.callSignature);
102-
visitNodeOrToken(this, node.block);
103-
this.visitOptionalToken(node.semicolonToken);
102+
visitNodeOrToken(this, node.body);
104103
}
105104

106105
public visitModuleDeclaration(node: ModuleDeclarationSyntax): void {
@@ -152,8 +151,7 @@ module TypeScript {
152151
this.visitList(node.modifiers);
153152
visitNodeOrToken(this, node.propertyName);
154153
visitNodeOrToken(this, node.callSignature);
155-
visitNodeOrToken(this, node.block);
156-
this.visitOptionalToken(node.semicolonToken);
154+
visitNodeOrToken(this, node.body);
157155
}
158156

159157
public visitMemberVariableDeclaration(node: MemberVariableDeclarationSyntax): void {
@@ -166,8 +164,7 @@ module TypeScript {
166164
this.visitList(node.modifiers);
167165
this.visitToken(node.constructorKeyword);
168166
visitNodeOrToken(this, node.callSignature);
169-
visitNodeOrToken(this, node.block);
170-
this.visitOptionalToken(node.semicolonToken);
167+
visitNodeOrToken(this, node.body);
171168
}
172169

173170
public visitIndexMemberDeclaration(node: IndexMemberDeclarationSyntax): void {

0 commit comments

Comments
 (0)