Skip to content

Commit b24a384

Browse files
committed
amended previous commit
1 parent 3893ae9 commit b24a384

File tree

8 files changed

+34
-22
lines changed

8 files changed

+34
-22
lines changed

samples/dci/js/TransferMoney/Account.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ var __dci_internal__ = require('typescript-dci/dci');
44
var Account = Context.extend(function () {
55
var __context = this;
66
this.__$Ledgers = { addEntry: function (message, amount) {
7-
__context.__$Ledgers.push.call(__context.Ledgers, new LedgerEntry(message, amount));
7+
__context.Ledgers.push(new LedgerEntry(message, amount));
88
}
99
,getBalance: function () {
1010
var sum = 0;
11-
__context.__$Ledgers.each.call(__context.Ledgers, function (ledgerEntry) {
11+
__context.Ledgers.forEach(function (ledgerEntry) {
1212
sum += ledgerEntry.amount;
1313
});
1414
return sum;

samples/dci/js/TransferMoney/Account.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ var Account = Context.extend(function() {
3131

3232
getBalance() {
3333
var sum = 0;
34-
Ledgers.each(function(ledgerEntry) {
34+
Ledgers.forEach(function(ledgerEntry) {
3535
sum += ledgerEntry.amount;
3636
});
3737
return sum;

samples/dci/js/TransferMoney/TransferMoney.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
var __dci_internal__ = require('typescript-dci/dci');
2-
var DCI = '../../DCI';
32

43

54
/**
@@ -11,7 +10,7 @@ var DCI = '../../DCI';
1110
* @param {Account} destination
1211
* @param {number} amount
1312
*/
14-
var TransferMoney = DCI.Context.extend(function () {
13+
var TransferMoney = Context.extend(function () {
1514
var __context = this;
1615
this.__$SourceAccount = { transferOut: function () {
1716
__dci_internal__.callMethodOnSelf(__context, this, 'SourceAccount', 'withdraw');

samples/dci/js/TransferMoney/TransferMoney.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
import DCI = require('../../DCI');
1+
///<reference path='../../DCI.d.ts'/>
2+
3+
//import DCI = require('../../DCI');
4+
25
export = TransferMoney;
36

47
/**
@@ -10,7 +13,7 @@ export = TransferMoney;
1013
* @param {Account} destination
1114
* @param {number} amount
1215
*/
13-
var TransferMoney = DCI.Context.extend(function() {
16+
var TransferMoney = Context.extend(function() {
1417
this.bindRoles = function(sourceAcct, destinationAcct, amount) {
1518
SourceAccount <- sourceAcct;
1619
DestinationAccount <- destinationAcct;

samples/dci/js/TransferMoney/index.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
var Account = require('./Account');
22
var TransferMoney = require('./TransferMoney');
33

4-
var src = new Account(20);
5-
var dst = new Account(10);
4+
var src = new Account();
5+
src.increaseBalance(20);
6+
7+
var dst = new Account();
8+
dst.increaseBalance(10);
69

710
var ctx = new TransferMoney(src, dst, 10);
811

samples/dci/js/TransferMoney/index.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
import Account = require('./Account');
22
import TransferMoney = require('./TransferMoney');
33

4-
var src = new Account(20);
5-
var dst = new Account(10);
4+
var src = new Account();
5+
src.increaseBalance(20);
6+
7+
var dst = new Account();
8+
dst.increaseBalance(10);
69

710
var ctx = new TransferMoney(src, dst, 10);
811

src/compiler/emitter.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -599,27 +599,29 @@ module TypeScript {
599599
if (this.thisRoleNode) {
600600
if (this.thisRoleNode && operand1 instanceof ThisExpression) {
601601
roleName = this.thisRoleNode.name.actualText;
602-
isCallToRoleMethod = true;
603602
isCallToSelf = true;
604603
}
605-
else {
606-
roleName = operand1.actualText;
607-
if (roleName in dciContext.roleDeclarations) {
608-
isCallToRoleMethod = true;
609-
}
610-
}
611604
}
612-
else {
605+
606+
if (!isCallToSelf) {
613607
roleName = operand1.actualText;
614608
if (roleName in dciContext.roleDeclarations) {
615-
isCallToRoleMethod = true;
609+
//Check whether the method exists on the role - if not, it's a data object method, not a role method
610+
var methodName = operand2.actualText;
611+
var roleDecl: RoleDeclaration = dciContext.roleDeclarations[roleName];
612+
roleDecl.members.members.forEach(function(member) {
613+
if ((<FunctionDeclaration>member).name.actualText == methodName) {
614+
isCallToRoleMethod = true;
615+
return false; //exit loop
616+
}
617+
});
616618
}
617619
}
618620
}
619621
}
620622

621623
//DCI
622-
if (isCallToRoleMethod) {
624+
if (isCallToRoleMethod || isCallToSelf) {
623625
//If the call is within a role and begins with `this.`
624626
if (isCallToSelf) {
625627
this.writeToOutput("__dci_internal__.callMethodOnSelf");

src/compiler/typecheck/pullTypeResolution.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4644,10 +4644,12 @@ module TypeScript {
46444644

46454645
if (!nameSymbol) {
46464646
//DCI TODO is it ok to be returning an ErrorTypeSymbol here?
4647+
//DCI TODO is there really no reliable way to check if it's a valid data object method at compile time?
4648+
// TypeScript seems to check this ordinarily, for regular objects, at compile time....
46474649

46484650
//DCI
46494651
//Don't check whether or not the method exists, because it could be a data object method,
4650-
//and there's no way to check that at compile time without a role contract (data object interface), which we don't want to require
4652+
//and there's probably no way to check that at compile time without a role contract (data object interface), which we don't want to require
46514653
if (lhs.kind != PullElementKind.Role) {
46524654
context.postError(this.unitPath, dottedNameAST.operand2.minChar, dottedNameAST.operand2.getLength(), DiagnosticCode.The_property_0_does_not_exist_on_value_of_type_1, [(<Identifier>dottedNameAST.operand2).actualText, lhsType.toString(enclosingDecl ? enclosingDecl.getSymbol() : null)], enclosingDecl)
46534655
}

0 commit comments

Comments
 (0)