@@ -2227,6 +2227,30 @@ module ts {
2227
2227
emit ( node . expression ) ;
2228
2228
write ( "]" ) ;
2229
2229
}
2230
+
2231
+ function emitDownlevelMethod ( node : MethodDeclaration ) {
2232
+ if ( ! isObjectLiteralMethod ( node ) ) {
2233
+ return ;
2234
+ }
2235
+
2236
+ emitLeadingComments ( node ) ;
2237
+ emit ( node . name ) ;
2238
+ write ( ": " ) ;
2239
+ write ( "function " ) ;
2240
+ emitSignatureAndBody ( node ) ;
2241
+ emitTrailingComments ( node ) ;
2242
+ }
2243
+
2244
+ function emitMethod ( node : MethodDeclaration ) {
2245
+ if ( ! isObjectLiteralMethod ( node ) ) {
2246
+ return ;
2247
+ }
2248
+
2249
+ emitLeadingComments ( node ) ;
2250
+ emit ( node . name ) ;
2251
+ emitSignatureAndBody ( node ) ;
2252
+ emitTrailingComments ( node ) ;
2253
+ }
2230
2254
2231
2255
function emitPropertyAssignment ( node : PropertyDeclaration ) {
2232
2256
emitLeadingComments ( node ) ;
@@ -2236,7 +2260,7 @@ module ts {
2236
2260
emitTrailingComments ( node ) ;
2237
2261
}
2238
2262
2239
- function emitDownlevelShorthandPropertyAssignment ( node : ShorthandPropertyDeclaration ) {
2263
+ function emitDownlevelShorthandPropertyAssignment ( node : ShorthandPropertyAssignment ) {
2240
2264
emitLeadingComments ( node ) ;
2241
2265
// Emit identifier as an identifier
2242
2266
emit ( node . name ) ;
@@ -2247,7 +2271,7 @@ module ts {
2247
2271
emitTrailingComments ( node ) ;
2248
2272
}
2249
2273
2250
- function emitShorthandPropertyAssignment ( node : ShorthandPropertyDeclaration ) {
2274
+ function emitShorthandPropertyAssignment ( node : ShorthandPropertyAssignment ) {
2251
2275
// If short-hand property has a prefix, then regardless of the target version, we will emit it as normal property assignment. For example:
2252
2276
// module m {
2253
2277
// export var y;
@@ -2841,17 +2865,17 @@ module ts {
2841
2865
scopeEmitStart ( node ) ;
2842
2866
increaseIndent ( ) ;
2843
2867
2844
- emitDetachedComments ( node . body . kind === SyntaxKind . FunctionBlock ? ( < Block > node . body ) . statements : node . body ) ;
2868
+ emitDetachedComments ( node . body . kind === SyntaxKind . Block ? ( < Block > node . body ) . statements : node . body ) ;
2845
2869
2846
2870
var startIndex = 0 ;
2847
- if ( node . body . kind === SyntaxKind . FunctionBlock ) {
2871
+ if ( node . body . kind === SyntaxKind . Block ) {
2848
2872
startIndex = emitDirectivePrologues ( ( < Block > node . body ) . statements , /*startWithNewLine*/ true ) ;
2849
2873
}
2850
2874
var outPos = writer . getTextPos ( ) ;
2851
2875
emitCaptureThisForNodeIfNecessary ( node ) ;
2852
2876
emitDefaultValueAssignments ( node ) ;
2853
2877
emitRestParameter ( node ) ;
2854
- if ( node . body . kind !== SyntaxKind . FunctionBlock && outPos === writer . getTextPos ( ) ) {
2878
+ if ( node . body . kind !== SyntaxKind . Block && outPos === writer . getTextPos ( ) ) {
2855
2879
decreaseIndent ( ) ;
2856
2880
write ( " " ) ;
2857
2881
emitStart ( node . body ) ;
@@ -2864,7 +2888,7 @@ module ts {
2864
2888
emitEnd ( node . body ) ;
2865
2889
}
2866
2890
else {
2867
- if ( node . body . kind === SyntaxKind . FunctionBlock ) {
2891
+ if ( node . body . kind === SyntaxKind . Block ) {
2868
2892
emitLinesStartingAt ( ( < Block > node . body ) . statements , startIndex ) ;
2869
2893
}
2870
2894
else {
@@ -2876,7 +2900,7 @@ module ts {
2876
2900
emitTrailingComments ( node . body ) ;
2877
2901
}
2878
2902
writeLine ( ) ;
2879
- if ( node . body . kind === SyntaxKind . FunctionBlock ) {
2903
+ if ( node . body . kind === SyntaxKind . Block ) {
2880
2904
emitLeadingCommentsOfPosition ( ( < Block > node . body ) . statements . end ) ;
2881
2905
decreaseIndent ( ) ;
2882
2906
emitToken ( SyntaxKind . CloseBraceToken , ( < Block > node . body ) . statements . end ) ;
@@ -3566,7 +3590,6 @@ module ts {
3566
3590
case SyntaxKind . Block :
3567
3591
case SyntaxKind . TryBlock :
3568
3592
case SyntaxKind . FinallyBlock :
3569
- case SyntaxKind . FunctionBlock :
3570
3593
case SyntaxKind . ModuleBlock :
3571
3594
return emitBlock ( < Block > node ) ;
3572
3595
case SyntaxKind . VariableStatement :
@@ -3628,15 +3651,19 @@ module ts {
3628
3651
// Emit node down-level
3629
3652
switch ( node . kind ) {
3630
3653
case SyntaxKind . ShorthandPropertyAssignment :
3631
- return emitDownlevelShorthandPropertyAssignment ( < ShorthandPropertyDeclaration > node ) ;
3654
+ return emitDownlevelShorthandPropertyAssignment ( < ShorthandPropertyAssignment > node ) ;
3655
+ case SyntaxKind . Method :
3656
+ return emitDownlevelMethod ( < MethodDeclaration > node ) ;
3632
3657
}
3633
3658
}
3634
3659
else {
3635
3660
// Emit node natively
3636
3661
Debug . assert ( compilerOptions . target >= ScriptTarget . ES6 , "Invalid ScriptTarget. We should emit as ES6 or above" ) ;
3637
3662
switch ( node . kind ) {
3638
3663
case SyntaxKind . ShorthandPropertyAssignment :
3639
- return emitShorthandPropertyAssignment ( < ShorthandPropertyDeclaration > node ) ;
3664
+ return emitShorthandPropertyAssignment ( < ShorthandPropertyAssignment > node ) ;
3665
+ case SyntaxKind . Method :
3666
+ return emitMethod ( < MethodDeclaration > node ) ;
3640
3667
}
3641
3668
}
3642
3669
}
0 commit comments