@@ -563,9 +563,10 @@ module TypeScript {
563
563
if ( ! this . emitSuperCall ( callNode ) ) {
564
564
//DCI
565
565
var binaryExpressionTarget : BinaryExpression ,
566
- isCallToSelf = false ,
567
566
operand1 : Identifier ,
568
567
operand2 : Identifier ,
568
+ isRoleMethodCall = false ,
569
+ isCallToSelf = false ,
569
570
roleName : string ;
570
571
571
572
if ( target . nodeType ( ) === NodeType . FunctionDeclaration ) {
@@ -585,16 +586,19 @@ module TypeScript {
585
586
//if currently inside a role
586
587
if ( this . thisRoleNode ) {
587
588
if ( this . thisRoleNode && binaryExpressionTarget . operand1 instanceof ThisExpression ) {
589
+ isRoleMethodCall = true ;
588
590
isCallToSelf = true ;
589
591
this . writeToOutput ( "DCI.callMethodOnCurrentRolePlayer" ) ;
590
592
}
591
593
else {
592
594
roleName = operand1 . actualText ;
593
595
if ( roleName in this . thisFunctionDeclaration . roleDeclarations ) {
596
+ isRoleMethodCall = true ;
597
+
594
598
this . writeToOutput ( "__context.__$" ) ;
595
599
this . writeToOutput ( roleName ) ;
596
600
//binaryExpressionTarget.operand1.emit(this); //role name
597
- this . writeToOutput ( "." ) ;
601
+ this . writeToOutput ( "." ) ;
598
602
}
599
603
else {
600
604
this . emitJavascript ( target , false ) ;
@@ -604,7 +608,7 @@ module TypeScript {
604
608
else {
605
609
roleName = operand1 . actualText ;
606
610
if ( roleName in this . thisFunctionDeclaration . roleDeclarations ) {
607
-
611
+ isRoleMethodCall = true ;
608
612
609
613
//DCI TODO
610
614
@@ -618,10 +622,39 @@ module TypeScript {
618
622
}
619
623
}
620
624
else {
621
- //DCI TODO - context methods
622
- //Check parent function to see if it's a DCI context
625
+ //DCI
626
+ //Check to see if any of the parent functions to which this function belongs are a DCI context
627
+ var declStack = this . declStack ;
628
+ var dciContext : FunctionDeclaration ;
629
+ for ( var i = 0 ; i < declStack . length ; i ++ ) {
630
+ if ( declStack [ i ] instanceof PullFunctionExpressionDecl ) {
631
+ var funcDecl = < FunctionDeclaration > declStack [ i ] . ast ;
632
+ if ( funcDecl . isDCIContext ) {
633
+ dciContext = funcDecl ;
634
+ break ;
635
+ }
636
+ }
637
+ }
638
+
639
+ //TEMP
640
+
641
+ if ( dciContext ) {
642
+ binaryExpressionTarget = < BinaryExpression > target ;
643
+ operand1 = < Identifier > binaryExpressionTarget . operand1 ;
644
+ operand2 = < Identifier > binaryExpressionTarget . operand2 ;
645
+ roleName = operand1 . actualText ;
646
+ }
623
647
624
- this . emitJavascript ( target , false ) ;
648
+ //TEMP
649
+
650
+ if ( dciContext && roleName in dciContext . roleDeclarations ) {
651
+ isRoleMethodCall = true ;
652
+
653
+ this . writeToOutput ( "__context.__$" ) ;
654
+ this . writeToOutput ( roleName ) ;
655
+ this . writeToOutput ( "." ) ;
656
+ }
657
+ else this . emitJavascript ( target , false ) ;
625
658
}
626
659
}
627
660
if ( target . nodeType ( ) === NodeType . FunctionDeclaration ) {
@@ -630,8 +663,7 @@ module TypeScript {
630
663
this . recordSourceMappingStart ( args ) ;
631
664
632
665
//DCI
633
- //if currently inside a role
634
- if ( this . thisRoleNode ) {
666
+ if ( isRoleMethodCall ) {
635
667
if ( isCallToSelf ) {
636
668
this . writeToOutput ( "(__context, this, '" ) ;
637
669
this . writeToOutput ( ( < Identifier > this . thisRoleNode . name ) . actualText ) ;
@@ -640,34 +672,15 @@ module TypeScript {
640
672
//binaryExpressionTarget.operand2.emit(this);
641
673
this . writeToOutput ( "')" ) ;
642
674
} else {
643
- if ( roleName in this . thisFunctionDeclaration . roleDeclarations ) {
644
- this . writeToOutput ( operand2 . actualText + ".call(__context." + operand1 . actualText ) ;
645
- //binaryExpressionTarget.operand2.emit(this);
646
- //this.writeToOutput(".call(");
647
- //binaryExpressionTarget.operand1.emit(this);
648
-
649
- if ( args . members . length > 0 )
650
- this . writeToOutput ( ", " ) ;
651
- this . emitCommaSeparatedList ( args ) ;
652
- this . writeToOutput ( ")" ) ;
653
- }
654
- else {
655
-
656
-
657
- //TEMP - copied from below
658
-
659
-
660
- this . writeToOutput ( "(" ) ;
661
- if ( callNode . target . nodeType ( ) === 32 /* SuperExpression */ && this . emitState . container === 4 /* Constructor */ ) {
662
- this . writeToOutput ( "this" ) ;
663
- if ( args && args . members . length ) {
664
- this . writeToOutput ( ", " ) ;
665
- }
666
- }
667
- this . emitCommaSeparatedList ( args ) ;
668
- this . recordSourceMappingStart ( callNode . closeParenSpan ) ;
669
- this . writeToOutput ( ")" ) ;
670
- }
675
+ this . writeToOutput ( operand2 . actualText + ".call(__context." + operand1 . actualText ) ;
676
+ //binaryExpressionTarget.operand2.emit(this);
677
+ //this.writeToOutput(".call(");
678
+ //binaryExpressionTarget.operand1.emit(this);
679
+
680
+ if ( args . members . length > 0 )
681
+ this . writeToOutput ( ", " ) ;
682
+ this . emitCommaSeparatedList ( args ) ;
683
+ this . writeToOutput ( ")" ) ;
671
684
}
672
685
}
673
686
else {
0 commit comments