Skip to content

Commit 67593eb

Browse files
committed
Bug fixes; working on core DCI module
1 parent 7519531 commit 67593eb

File tree

7 files changed

+2308
-2399
lines changed

7 files changed

+2308
-2399
lines changed

bin/typescript.js

Lines changed: 2281 additions & 1522 deletions
Large diffs are not rendered by default.

samples/amd/greeter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@ export class Greeter
2222
{
2323
clearTimeout(this.timerToken);
2424
}
25-
}
25+
}

samples/dci/test-old.js

Lines changed: 0 additions & 16 deletions
This file was deleted.

samples/dci/tmp.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
eval('try { require("dci"); } catch(e) { console.error("ERROR"); }');
1+
eval('try { require("typescript-dci"); } catch(e) { console.error("ERROR"); }');
22

src/compiler/emitter.ts

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -604,14 +604,14 @@ module TypeScript {
604604
}
605605
else {
606606
roleName = operand1.actualText;
607-
if (roleName in this.thisFunctionNode.roleDeclarations) {
607+
if (roleName in dciContext.roleDeclarations) {
608608
isCallToRoleMethod = true;
609609
}
610610
}
611611
}
612612
else {
613613
roleName = operand1.actualText;
614-
if (roleName in this.thisFunctionNode.roleDeclarations) {
614+
if (roleName in dciContext.roleDeclarations) {
615615
isCallToRoleMethod = true;
616616
}
617617
}
@@ -622,20 +622,24 @@ module TypeScript {
622622
if (isCallToRoleMethod) {
623623
//If the call is within a role and begins with `this.`
624624
if (isCallToSelf) {
625-
this.writeToOutput("DCI.callMethodOnSelf");
625+
this.writeToOutput("__dci_internal__.callMethodOnSelf");
626+
//this.writeToOutput("DCI.callMethodOnSelf");
626627
this.writeToOutput("(__context, this, '" + roleName + "'");
627628
this.writeToOutput(", '" + operand2.actualText + "'");
628629
}
629630
else {
630-
this.writeToOutput("__context.__$" + roleName + ".");
631+
this.writeToOutput("__context.__$" + roleName + "." + operand2.actualText + ".");
631632
this.writeToOutput("call(__context." + roleName);
632633
}
633634
if (args && args.members.length) this.writeToOutput(", ");
634635

635636
this.recordSourceMappingStart(args);
636-
if (isCallToSelf) this.writeToOutput("[");
637-
this.emitCommaSeparatedList(args);
638-
if (isCallToSelf) this.writeToOutput("]");
637+
638+
if (args && args.members.length) {
639+
if (isCallToSelf) this.writeToOutput("[");
640+
this.emitCommaSeparatedList(args);
641+
if (isCallToSelf) this.writeToOutput("]");
642+
}
639643
}
640644
else {
641645
if (target.nodeType() === NodeType.FunctionDeclaration) {
@@ -998,6 +1002,15 @@ module TypeScript {
9981002
hasDCIContext = true;
9991003
}
10001004
}
1005+
else if (initVal instanceof InvocationExpression) {
1006+
(<InvocationExpression>initVal).arguments.members.forEach(function(arg) {
1007+
if (arg instanceof FunctionDeclaration) {
1008+
if (Object.keys((<FunctionDeclaration>arg).roleDeclarations).length) {
1009+
hasDCIContext = true;
1010+
}
1011+
}
1012+
});
1013+
}
10011014
});
10021015
}
10031016
});
@@ -1026,11 +1039,11 @@ module TypeScript {
10261039
//DCI
10271040
if (hasDCIContext) {
10281041
//DCI TODO indent
1029-
this.writeLineToOutput("var DCI = typescriptDCI.DCI;");
1042+
this.writeLineToOutput("var __dci_internal__ = typescriptDCI.DCI;");
10301043
}
10311044
}
10321045
//DCI
1033-
else if (hasDCIContext) this.writeLineToOutput("var DCI = require('typescript-dci').DCI;");
1046+
else if (hasDCIContext) this.writeLineToOutput("var __dci_internal__ = require('typescript-dci').DCI;");
10341047
}
10351048
else {
10361049
if (!isExported) {

0 commit comments

Comments
 (0)