2
2
/// <reference path="core.ts"/>
3
3
/// <reference path="scanner.ts"/>
4
4
/// <reference path="parser.ts"/>
5
+ /// <reference path="binder.ts"/>
5
6
6
7
module ts {
7
8
interface EmitTextWriter {
@@ -2281,27 +2282,31 @@ module ts {
2281
2282
emit ( node . expression ) ;
2282
2283
write ( "]" ) ;
2283
2284
}
2284
-
2285
- function emitPropertyAssignment ( node : PropertyDeclaration ) {
2285
+
2286
+ function emitMethod ( node : MethodDeclaration ) {
2287
+ if ( ! isObjectLiteralMethod ( node ) ) {
2288
+ return ;
2289
+ }
2286
2290
emitLeadingComments ( node ) ;
2287
2291
emit ( node . name ) ;
2288
- write ( ": " ) ;
2289
- emit ( node . initializer ) ;
2292
+ if ( compilerOptions . target < ScriptTarget . ES6 ) {
2293
+ write ( ": function " ) ;
2294
+ }
2295
+ emitSignatureAndBody ( node ) ;
2290
2296
emitTrailingComments ( node ) ;
2291
2297
}
2292
2298
2293
- function emitDownlevelShorthandPropertyAssignment ( node : ShorthandPropertyDeclaration ) {
2299
+ function emitPropertyAssignment ( node : PropertyDeclaration ) {
2294
2300
emitLeadingComments ( node ) ;
2295
- // Emit identifier as an identifier
2296
2301
emit ( node . name ) ;
2297
2302
write ( ": " ) ;
2298
- // Even though this is stored as identifier treat it as an expression
2299
- // Short-hand, { x }, is equivalent of normal form { x: x }
2300
- emitExpressionIdentifier ( node . name ) ;
2303
+ emit ( node . initializer ) ;
2301
2304
emitTrailingComments ( node ) ;
2302
2305
}
2303
2306
2304
- function emitShorthandPropertyAssignment ( node : ShorthandPropertyDeclaration ) {
2307
+ function emitShorthandPropertyAssignment ( node : ShorthandPropertyAssignment ) {
2308
+ emitLeadingComments ( node ) ;
2309
+ emit ( node . name ) ;
2305
2310
// If short-hand property has a prefix, then regardless of the target version, we will emit it as normal property assignment. For example:
2306
2311
// module m {
2307
2312
// export var y;
@@ -2310,16 +2315,14 @@ module ts {
2310
2315
// export var obj = { y };
2311
2316
// }
2312
2317
// The short-hand property in obj need to emit as such ... = { y : m.y } regardless of the TargetScript version
2313
- var prefix = resolver . getExpressionNamePrefix ( node . name ) ;
2314
- if ( prefix ) {
2315
- emitDownlevelShorthandPropertyAssignment ( node ) ;
2316
- }
2317
- // If short-hand property has no prefix, emit it as short-hand.
2318
- else {
2319
- emitLeadingComments ( node ) ;
2320
- emit ( node . name ) ;
2321
- emitTrailingComments ( node ) ;
2318
+ if ( compilerOptions . target < ScriptTarget . ES6 || resolver . getExpressionNamePrefix ( node . name ) ) {
2319
+ // Emit identifier as an identifier
2320
+ write ( ": " ) ;
2321
+ // Even though this is stored as identifier treat it as an expression
2322
+ // Short-hand, { x }, is equivalent of normal form { x: x }
2323
+ emitExpressionIdentifier ( node . name ) ;
2322
2324
}
2325
+ emitTrailingComments ( node ) ;
2323
2326
}
2324
2327
2325
2328
function tryEmitConstantValue ( node : PropertyAccessExpression | ElementAccessExpression ) : boolean {
@@ -2868,8 +2871,8 @@ module ts {
2868
2871
var p = properties [ i ] ;
2869
2872
if ( p . kind === SyntaxKind . PropertyAssignment || p . kind === SyntaxKind . ShorthandPropertyAssignment ) {
2870
2873
// TODO(andersh): Computed property support
2871
- var propName = < Identifier > ( ( < PropertyDeclaration > p ) . name ) ;
2872
- emitDestructuringAssignment ( ( < PropertyDeclaration > p ) . initializer || propName , createPropertyAccess ( value , propName ) ) ;
2874
+ var propName = < Identifier > ( ( < PropertyAssignment > p ) . name ) ;
2875
+ emitDestructuringAssignment ( ( < PropertyAssignment > p ) . initializer || propName , createPropertyAccess ( value , propName ) ) ;
2873
2876
}
2874
2877
}
2875
2878
}
@@ -3139,17 +3142,17 @@ module ts {
3139
3142
scopeEmitStart ( node ) ;
3140
3143
increaseIndent ( ) ;
3141
3144
3142
- emitDetachedComments ( node . body . kind === SyntaxKind . FunctionBlock ? ( < Block > node . body ) . statements : node . body ) ;
3145
+ emitDetachedComments ( node . body . kind === SyntaxKind . Block ? ( < Block > node . body ) . statements : node . body ) ;
3143
3146
3144
3147
var startIndex = 0 ;
3145
- if ( node . body . kind === SyntaxKind . FunctionBlock ) {
3148
+ if ( node . body . kind === SyntaxKind . Block ) {
3146
3149
startIndex = emitDirectivePrologues ( ( < Block > node . body ) . statements , /*startWithNewLine*/ true ) ;
3147
3150
}
3148
3151
var outPos = writer . getTextPos ( ) ;
3149
3152
emitCaptureThisForNodeIfNecessary ( node ) ;
3150
3153
emitDefaultValueAssignments ( node ) ;
3151
3154
emitRestParameter ( node ) ;
3152
- if ( node . body . kind !== SyntaxKind . FunctionBlock && outPos === writer . getTextPos ( ) ) {
3155
+ if ( node . body . kind !== SyntaxKind . Block && outPos === writer . getTextPos ( ) ) {
3153
3156
decreaseIndent ( ) ;
3154
3157
write ( " " ) ;
3155
3158
emitStart ( node . body ) ;
@@ -3164,7 +3167,7 @@ module ts {
3164
3167
emitEnd ( node . body ) ;
3165
3168
}
3166
3169
else {
3167
- if ( node . body . kind === SyntaxKind . FunctionBlock ) {
3170
+ if ( node . body . kind === SyntaxKind . Block ) {
3168
3171
emitLinesStartingAt ( ( < Block > node . body ) . statements , startIndex ) ;
3169
3172
}
3170
3173
else {
@@ -3177,7 +3180,7 @@ module ts {
3177
3180
}
3178
3181
emitTempDeclarations ( /*newLine*/ true ) ;
3179
3182
writeLine ( ) ;
3180
- if ( node . body . kind === SyntaxKind . FunctionBlock ) {
3183
+ if ( node . body . kind === SyntaxKind . Block ) {
3181
3184
emitLeadingCommentsOfPosition ( ( < Block > node . body ) . statements . end ) ;
3182
3185
decreaseIndent ( ) ;
3183
3186
emitToken ( SyntaxKind . CloseBraceToken , ( < Block > node . body ) . statements . end ) ;
@@ -3812,6 +3815,8 @@ module ts {
3812
3815
return emitIdentifier ( < Identifier > node ) ;
3813
3816
case SyntaxKind . Parameter :
3814
3817
return emitParameter ( < ParameterDeclaration > node ) ;
3818
+ case SyntaxKind . Method :
3819
+ return emitMethod ( < MethodDeclaration > node ) ;
3815
3820
case SyntaxKind . GetAccessor :
3816
3821
case SyntaxKind . SetAccessor :
3817
3822
return emitAccessor ( < AccessorDeclaration > node ) ;
@@ -3849,6 +3854,8 @@ module ts {
3849
3854
return emitObjectLiteral ( < ObjectLiteralExpression > node ) ;
3850
3855
case SyntaxKind . PropertyAssignment :
3851
3856
return emitPropertyAssignment ( < PropertyDeclaration > node ) ;
3857
+ case SyntaxKind . ShorthandPropertyAssignment :
3858
+ return emitShorthandPropertyAssignment ( < ShorthandPropertyAssignment > node ) ;
3852
3859
case SyntaxKind . ComputedPropertyName :
3853
3860
return emitComputedPropertyName ( < ComputedPropertyName > node ) ;
3854
3861
case SyntaxKind . PropertyAccessExpression :
@@ -3888,7 +3895,6 @@ module ts {
3888
3895
case SyntaxKind . Block :
3889
3896
case SyntaxKind . TryBlock :
3890
3897
case SyntaxKind . FinallyBlock :
3891
- case SyntaxKind . FunctionBlock :
3892
3898
case SyntaxKind . ModuleBlock :
3893
3899
return emitBlock ( < Block > node ) ;
3894
3900
case SyntaxKind . VariableStatement :
@@ -3944,23 +3950,6 @@ module ts {
3944
3950
case SyntaxKind . SourceFile :
3945
3951
return emitSourceFile ( < SourceFile > node ) ;
3946
3952
}
3947
-
3948
- // Emit node which needs to be emitted differently depended on ScriptTarget
3949
- if ( compilerOptions . target < ScriptTarget . ES6 ) {
3950
- // Emit node down-level
3951
- switch ( node . kind ) {
3952
- case SyntaxKind . ShorthandPropertyAssignment :
3953
- return emitDownlevelShorthandPropertyAssignment ( < ShorthandPropertyDeclaration > node ) ;
3954
- }
3955
- }
3956
- else {
3957
- // Emit node natively
3958
- Debug . assert ( compilerOptions . target >= ScriptTarget . ES6 , "Invalid ScriptTarget. We should emit as ES6 or above" ) ;
3959
- switch ( node . kind ) {
3960
- case SyntaxKind . ShorthandPropertyAssignment :
3961
- return emitShorthandPropertyAssignment ( < ShorthandPropertyDeclaration > node ) ;
3962
- }
3963
- }
3964
3953
}
3965
3954
3966
3955
function hasDetachedComments ( pos : number ) {
0 commit comments