Simplify API for nodes that have both a block and an expression.
Conflicts: src/services/syntax/SyntaxGenerator.js.map
This commit is contained in:
parent
f59cb6044d
commit
2288f4268f
8 changed files with 42 additions and 57 deletions
|
@ -998,7 +998,7 @@ var definitions = [
|
|||
children: [
|
||||
{ name: 'modifiers', isList: true, elementType: 'ISyntaxToken' },
|
||||
{ name: 'moduleKeyword', isToken: true, excludeFromAST: true },
|
||||
{ name: 'name', type: 'INameSyntax', isOptional: true },
|
||||
{ name: 'name', type: 'INameSyntax' },
|
||||
{ name: 'openBraceToken', isToken: true, excludeFromAST: true },
|
||||
{ name: 'moduleElements', isList: true, elementType: 'IModuleElementSyntax' },
|
||||
{ name: 'closeBraceToken', isToken: true, excludeFromAST: true }
|
||||
|
@ -1094,8 +1094,7 @@ var definitions = [
|
|||
children: [
|
||||
{ name: 'parameter', type: 'ParameterSyntax' },
|
||||
{ name: 'equalsGreaterThanToken', isToken: true, excludeFromAST: true },
|
||||
{ name: 'block', type: 'BlockSyntax', isOptional: true },
|
||||
{ name: 'expression', type: 'IExpressionSyntax', isOptional: true }
|
||||
{ name: 'body', type: 'BlockSyntax | IExpressionSyntax' }
|
||||
],
|
||||
isTypeScriptSpecific: true
|
||||
},
|
||||
|
@ -1106,8 +1105,7 @@ var definitions = [
|
|||
children: [
|
||||
{ name: 'callSignature', type: 'CallSignatureSyntax' },
|
||||
{ name: 'equalsGreaterThanToken', isToken: true, excludeFromAST: true },
|
||||
{ name: 'block', type: 'BlockSyntax', isOptional: true },
|
||||
{ name: 'expression', type: 'IExpressionSyntax', isOptional: true }
|
||||
{ name: 'body', type: 'BlockSyntax | IExpressionSyntax' }
|
||||
],
|
||||
isTypeScriptSpecific: true
|
||||
},
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -2876,15 +2876,19 @@ module TypeScript.Parser {
|
|||
return undefined;
|
||||
}
|
||||
|
||||
var equalsGreaterThanToken = eatToken(SyntaxKind.EqualsGreaterThanToken);
|
||||
return new ParenthesizedArrowFunctionExpressionSyntax(parseNodeData,
|
||||
callSignature,
|
||||
eatToken(SyntaxKind.EqualsGreaterThanToken),
|
||||
parseArrowFunctionBody());
|
||||
}
|
||||
|
||||
function parseArrowFunctionBody(): BlockSyntax | IExpressionSyntax {
|
||||
var block = tryParseArrowFunctionBlock();
|
||||
var expression: IExpressionSyntax = undefined;
|
||||
if (block === undefined) {
|
||||
expression = tryParseAssignmentExpressionOrHigher(/*force:*/ true, /*allowIn:*/ true);
|
||||
if (block !== undefined) {
|
||||
return block;
|
||||
}
|
||||
|
||||
return new ParenthesizedArrowFunctionExpressionSyntax(parseNodeData, callSignature, equalsGreaterThanToken, block, expression);
|
||||
return tryParseAssignmentExpressionOrHigher(/*force:*/ true, /*allowIn:*/ true);
|
||||
}
|
||||
|
||||
function tryParseArrowFunctionBlock(): BlockSyntax {
|
||||
|
@ -2930,17 +2934,10 @@ module TypeScript.Parser {
|
|||
|
||||
function parseSimpleArrowFunctionExpression(): SimpleArrowFunctionExpressionSyntax {
|
||||
// Debug.assert(isSimpleArrowFunctionExpression());
|
||||
|
||||
var parameter = eatSimpleParameter();
|
||||
var equalsGreaterThanToken = eatToken(SyntaxKind.EqualsGreaterThanToken);
|
||||
|
||||
var block = tryParseArrowFunctionBlock();
|
||||
var expression: IExpressionSyntax = undefined;
|
||||
if (block === undefined) {
|
||||
expression = tryParseAssignmentExpressionOrHigher(/*force:*/ true, /*allowIn:*/ true);
|
||||
}
|
||||
|
||||
return new SimpleArrowFunctionExpressionSyntax(parseNodeData, parameter, equalsGreaterThanToken, block, expression);
|
||||
return new SimpleArrowFunctionExpressionSyntax(parseNodeData,
|
||||
eatSimpleParameter(),
|
||||
eatToken(SyntaxKind.EqualsGreaterThanToken),
|
||||
parseArrowFunctionBody());
|
||||
}
|
||||
|
||||
function isBlock(): boolean {
|
||||
|
|
|
@ -387,8 +387,7 @@ module TypeScript.PrettyPrinter {
|
|||
this.ensureSpace();
|
||||
this.appendToken(node.equalsGreaterThanToken);
|
||||
this.ensureSpace();
|
||||
this.appendNode(node.block);
|
||||
this.appendElement(node.expression);
|
||||
visitNodeOrToken(this, node.body);
|
||||
}
|
||||
|
||||
public visitParenthesizedArrowFunctionExpression(node: ParenthesizedArrowFunctionExpressionSyntax): void {
|
||||
|
@ -396,8 +395,7 @@ module TypeScript.PrettyPrinter {
|
|||
this.ensureSpace();
|
||||
this.appendToken(node.equalsGreaterThanToken);
|
||||
this.ensureSpace();
|
||||
this.appendNode(node.block);
|
||||
this.appendElement(node.expression);
|
||||
visitNodeOrToken(this, node.body);
|
||||
}
|
||||
|
||||
public visitQualifiedName(node: QualifiedNameSyntax): void {
|
||||
|
|
|
@ -144,7 +144,7 @@ var definitions:ITypeDefinition[] = [
|
|||
children: [
|
||||
<any>{ name: 'modifiers', isList: true, elementType: 'ISyntaxToken' },
|
||||
<any>{ name: 'moduleKeyword', isToken: true, excludeFromAST: true },
|
||||
<any>{ name: 'name', type: 'INameSyntax', isOptional: true },
|
||||
<any>{ name: 'name', type: 'INameSyntax' },
|
||||
<any>{ name: 'openBraceToken', isToken: true, excludeFromAST: true },
|
||||
<any>{ name: 'moduleElements', isList: true, elementType: 'IModuleElementSyntax' },
|
||||
<any>{ name: 'closeBraceToken', isToken: true, excludeFromAST: true }
|
||||
|
@ -240,8 +240,7 @@ var definitions:ITypeDefinition[] = [
|
|||
children: [
|
||||
<any>{ name: 'parameter', type: 'ParameterSyntax' },
|
||||
<any>{ name: 'equalsGreaterThanToken', isToken: true, excludeFromAST: true },
|
||||
<any>{ name: 'block', type: 'BlockSyntax', isOptional: true },
|
||||
<any>{ name: 'expression', type: 'IExpressionSyntax', isOptional: true }
|
||||
<any>{ name: 'body', type: 'BlockSyntax | IExpressionSyntax' }
|
||||
],
|
||||
isTypeScriptSpecific: true
|
||||
},
|
||||
|
@ -252,8 +251,7 @@ var definitions:ITypeDefinition[] = [
|
|||
children: [
|
||||
<any>{ name: 'callSignature', type: 'CallSignatureSyntax' },
|
||||
<any>{ name: 'equalsGreaterThanToken', isToken: true, excludeFromAST: true },
|
||||
<any>{ name: 'block', type: 'BlockSyntax', isOptional: true },
|
||||
<any>{ name: 'expression', type: 'IExpressionSyntax', isOptional: true }
|
||||
<any>{ name: 'body', type: 'BlockSyntax | IExpressionSyntax' }
|
||||
],
|
||||
isTypeScriptSpecific: true
|
||||
},
|
||||
|
|
|
@ -471,18 +471,16 @@ module TypeScript {
|
|||
export interface ParenthesizedArrowFunctionExpressionSyntax extends ISyntaxNode, IUnaryExpressionSyntax {
|
||||
callSignature: CallSignatureSyntax;
|
||||
equalsGreaterThanToken: ISyntaxToken;
|
||||
block: BlockSyntax;
|
||||
expression: IExpressionSyntax;
|
||||
body: BlockSyntax | IExpressionSyntax;
|
||||
}
|
||||
export interface ParenthesizedArrowFunctionExpressionConstructor { new (data: number, callSignature: CallSignatureSyntax, equalsGreaterThanToken: ISyntaxToken, block: BlockSyntax, expression: IExpressionSyntax): ParenthesizedArrowFunctionExpressionSyntax }
|
||||
export interface ParenthesizedArrowFunctionExpressionConstructor { new (data: number, callSignature: CallSignatureSyntax, equalsGreaterThanToken: ISyntaxToken, body: BlockSyntax | IExpressionSyntax): ParenthesizedArrowFunctionExpressionSyntax }
|
||||
|
||||
export interface SimpleArrowFunctionExpressionSyntax extends ISyntaxNode, IUnaryExpressionSyntax {
|
||||
parameter: ParameterSyntax;
|
||||
equalsGreaterThanToken: ISyntaxToken;
|
||||
block: BlockSyntax;
|
||||
expression: IExpressionSyntax;
|
||||
body: BlockSyntax | IExpressionSyntax;
|
||||
}
|
||||
export interface SimpleArrowFunctionExpressionConstructor { new (data: number, parameter: ParameterSyntax, equalsGreaterThanToken: ISyntaxToken, block: BlockSyntax, expression: IExpressionSyntax): SimpleArrowFunctionExpressionSyntax }
|
||||
export interface SimpleArrowFunctionExpressionConstructor { new (data: number, parameter: ParameterSyntax, equalsGreaterThanToken: ISyntaxToken, body: BlockSyntax | IExpressionSyntax): SimpleArrowFunctionExpressionSyntax }
|
||||
|
||||
export interface CastExpressionSyntax extends ISyntaxNode, IUnaryExpressionSyntax {
|
||||
lessThanToken: ISyntaxToken;
|
||||
|
|
|
@ -273,7 +273,7 @@ module TypeScript {
|
|||
this.closeBraceToken = closeBraceToken,
|
||||
modifiers.parent = this,
|
||||
moduleKeyword.parent = this,
|
||||
name && (name.parent = this),
|
||||
name.parent = this,
|
||||
openBraceToken.parent = this,
|
||||
moduleElements.parent = this,
|
||||
closeBraceToken.parent = this;
|
||||
|
@ -1279,47 +1279,41 @@ module TypeScript {
|
|||
}
|
||||
}
|
||||
|
||||
export var ParenthesizedArrowFunctionExpressionSyntax: ParenthesizedArrowFunctionExpressionConstructor = <any>function(data: number, callSignature: CallSignatureSyntax, equalsGreaterThanToken: ISyntaxToken, block: BlockSyntax, expression: IExpressionSyntax) {
|
||||
export var ParenthesizedArrowFunctionExpressionSyntax: ParenthesizedArrowFunctionExpressionConstructor = <any>function(data: number, callSignature: CallSignatureSyntax, equalsGreaterThanToken: ISyntaxToken, body: BlockSyntax | IExpressionSyntax) {
|
||||
if (data) { this.__data = data; }
|
||||
this.callSignature = callSignature,
|
||||
this.equalsGreaterThanToken = equalsGreaterThanToken,
|
||||
this.block = block,
|
||||
this.expression = expression,
|
||||
this.body = body,
|
||||
callSignature.parent = this,
|
||||
equalsGreaterThanToken.parent = this,
|
||||
block && (block.parent = this),
|
||||
expression && (expression.parent = this);
|
||||
body.parent = this;
|
||||
};
|
||||
ParenthesizedArrowFunctionExpressionSyntax.prototype.kind = SyntaxKind.ParenthesizedArrowFunctionExpression;
|
||||
ParenthesizedArrowFunctionExpressionSyntax.prototype.childCount = 4;
|
||||
ParenthesizedArrowFunctionExpressionSyntax.prototype.childCount = 3;
|
||||
ParenthesizedArrowFunctionExpressionSyntax.prototype.childAt = function(index: number): ISyntaxElement {
|
||||
switch (index) {
|
||||
case 0: return this.callSignature;
|
||||
case 1: return this.equalsGreaterThanToken;
|
||||
case 2: return this.block;
|
||||
case 3: return this.expression;
|
||||
case 2: return this.body;
|
||||
}
|
||||
}
|
||||
|
||||
export var SimpleArrowFunctionExpressionSyntax: SimpleArrowFunctionExpressionConstructor = <any>function(data: number, parameter: ParameterSyntax, equalsGreaterThanToken: ISyntaxToken, block: BlockSyntax, expression: IExpressionSyntax) {
|
||||
export var SimpleArrowFunctionExpressionSyntax: SimpleArrowFunctionExpressionConstructor = <any>function(data: number, parameter: ParameterSyntax, equalsGreaterThanToken: ISyntaxToken, body: BlockSyntax | IExpressionSyntax) {
|
||||
if (data) { this.__data = data; }
|
||||
this.parameter = parameter,
|
||||
this.equalsGreaterThanToken = equalsGreaterThanToken,
|
||||
this.block = block,
|
||||
this.expression = expression,
|
||||
this.body = body,
|
||||
parameter.parent = this,
|
||||
equalsGreaterThanToken.parent = this,
|
||||
block && (block.parent = this),
|
||||
expression && (expression.parent = this);
|
||||
body.parent = this;
|
||||
};
|
||||
SimpleArrowFunctionExpressionSyntax.prototype.kind = SyntaxKind.SimpleArrowFunctionExpression;
|
||||
SimpleArrowFunctionExpressionSyntax.prototype.childCount = 4;
|
||||
SimpleArrowFunctionExpressionSyntax.prototype.childCount = 3;
|
||||
SimpleArrowFunctionExpressionSyntax.prototype.childAt = function(index: number): ISyntaxElement {
|
||||
switch (index) {
|
||||
case 0: return this.parameter;
|
||||
case 1: return this.equalsGreaterThanToken;
|
||||
case 2: return this.block;
|
||||
case 3: return this.expression;
|
||||
case 2: return this.body;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -428,15 +428,13 @@ module TypeScript {
|
|||
public visitParenthesizedArrowFunctionExpression(node: ParenthesizedArrowFunctionExpressionSyntax): void {
|
||||
visitNodeOrToken(this, node.callSignature);
|
||||
this.visitToken(node.equalsGreaterThanToken);
|
||||
visitNodeOrToken(this, node.block);
|
||||
visitNodeOrToken(this, node.expression);
|
||||
visitNodeOrToken(this, node.body);
|
||||
}
|
||||
|
||||
public visitSimpleArrowFunctionExpression(node: SimpleArrowFunctionExpressionSyntax): void {
|
||||
visitNodeOrToken(this, node.parameter);
|
||||
this.visitToken(node.equalsGreaterThanToken);
|
||||
visitNodeOrToken(this, node.block);
|
||||
visitNodeOrToken(this, node.expression);
|
||||
visitNodeOrToken(this, node.body);
|
||||
}
|
||||
|
||||
public visitCastExpression(node: CastExpressionSyntax): void {
|
||||
|
|
Loading…
Reference in a new issue