@@ -28413,6 +28413,7 @@ var TypeScript;
28413
28413
this.thisClassNode = null;
28414
28414
this.thisRoleNode = null;
28415
28415
this.thisFunctionNode = null;
28416
+ this.thisDCIContextNode = null;
28416
28417
this.moduleName = "";
28417
28418
this.emitState = new EmitState();
28418
28419
this.indenter = new Indenter();
@@ -28799,69 +28800,81 @@ var TypeScript;
28799
28800
var binExpTarget, operand1, operand2, dciContext, isCallToRoleMethod = false, isCallToSelf = false, roleName;
28800
28801
28801
28802
if (this.thisFunctionNode && target instanceof TypeScript.BinaryExpression) {
28802
- if (this.thisFunctionNode.isDCIContext) {
28803
- dciContext = this.thisFunctionNode;
28804
- }
28805
-
28806
- var declStack = this.declStack;
28807
- for (var i = 0; i < declStack.length; i++) {
28808
- if (declStack[i] instanceof TypeScript.PullFunctionExpressionDecl) {
28809
- var funcDecl = declStack[i].ast;
28810
- if (funcDecl.isDCIContext) {
28811
- dciContext = funcDecl;
28812
- break;
28813
- }
28814
- }
28815
- }
28816
-
28817
- if (dciContext) {
28803
+ if (this.thisDCIContextNode) {
28804
+ dciContext = this.thisDCIContextNode;
28818
28805
binExpTarget = target;
28819
28806
operand1 = binExpTarget.operand1;
28820
28807
operand2 = binExpTarget.operand2;
28821
28808
28822
28809
if (this.thisRoleNode) {
28823
- if (this.thisRoleNode && operand1 instanceof TypeScript.ThisExpression) {
28810
+ if (operand1 instanceof TypeScript.ThisExpression || operand1.actualText == 'self' ) {
28824
28811
roleName = this.thisRoleNode.name.actualText;
28825
28812
isCallToSelf = true;
28826
28813
}
28827
28814
}
28828
28815
28829
- if (!isCallToSelf) {
28816
+ if (!roleName)
28830
28817
roleName = operand1.actualText;
28831
- if (roleName in dciContext.roleDeclarations) {
28832
- var methodName = operand2.actualText;
28833
- var roleDecl = dciContext.roleDeclarations[roleName] ;
28834
- roleDecl.members.members.forEach(function (member) {
28835
- if ((member).name.actualText == methodName ) {
28836
- isCallToRoleMethod = true;
28837
- return false ;
28838
- }
28839
- });
28840
- }
28818
+
28819
+ if (roleName && roleName in dciContext.roleDeclarations) {
28820
+ var methodName = operand2.actualText ;
28821
+ var roleDecl = dciContext.roleDeclarations[roleName];
28822
+ roleDecl.members.members.forEach(function (member ) {
28823
+ if ((member).name.actualText == methodName) {
28824
+ isCallToRoleMethod = true ;
28825
+ return false;
28826
+ }
28827
+ });
28841
28828
}
28842
28829
}
28843
28830
}
28844
28831
28845
28832
if (isCallToRoleMethod || isCallToSelf) {
28833
+ var isCallToThis = false;
28846
28834
if (isCallToSelf) {
28847
- this.writeToOutput("__dci_internal__.callMethodOnSelf");
28835
+ if (operand1 instanceof TypeScript.ThisExpression) {
28836
+ isCallToThis = true;
28848
28837
28849
- this.writeToOutput("(__context, this, '" + roleName + "'");
28850
- this.writeToOutput(", '" + operand2.actualText + "'");
28838
+ this.writeToOutput("__dci_internal.callMethodOnSelf");
28839
+
28840
+ this.writeToOutput("(__context, this, '" + roleName + "'");
28841
+
28842
+ this.writeToOutput(", '" + operand2.actualText + "'");
28843
+
28844
+ if (args && args.members.length)
28845
+ this.writeToOutput(", ");
28846
+ } else {
28847
+ if (isCallToRoleMethod) {
28848
+ this.writeToOutput("__context.__$" + roleName + "." + operand2.actualText + ".");
28849
+ this.writeToOutput("call(__context." + roleName);
28850
+
28851
+ if (args && args.members.length)
28852
+ this.writeToOutput(", ");
28853
+ } else {
28854
+ if (target.nodeType() == 37 /* ElementAccessExpression */) {
28855
+ this.writeToOutput("__dci_internal.getRoleMember(__context, __context." + roleName + ', "' + roleName + '", ');
28856
+ operand2.emit(this);
28857
+ this.writeToOutput(")(");
28858
+ } else {
28859
+ this.writeToOutput("__context." + roleName + "." + operand2.actualText + "(");
28860
+ }
28861
+ }
28862
+ }
28851
28863
} else {
28852
28864
this.writeToOutput("__context.__$" + roleName + "." + operand2.actualText + ".");
28853
28865
this.writeToOutput("call(__context." + roleName);
28866
+
28867
+ if (args && args.members.length)
28868
+ this.writeToOutput(", ");
28854
28869
}
28855
- if (args && args.members.length)
28856
- this.writeToOutput(", ");
28857
28870
28858
28871
this.recordSourceMappingStart(args);
28859
28872
28860
28873
if (args && args.members.length) {
28861
- if (isCallToSelf )
28874
+ if (isCallToThis )
28862
28875
this.writeToOutput("[");
28863
28876
this.emitCommaSeparatedList(args);
28864
- if (isCallToSelf )
28877
+ if (isCallToThis )
28865
28878
this.writeToOutput("]");
28866
28879
}
28867
28880
} else {
@@ -28959,8 +28972,6 @@ var TypeScript;
28959
28972
}
28960
28973
this.writeLineToOutput(") {");
28961
28974
28962
- funcDecl.isDCIContext = (Object.keys(funcDecl.roleDeclarations).length > 0);
28963
-
28964
28975
if (funcDecl.isDCIContext) {
28965
28976
this.indenter.increaseIndent();
28966
28977
this.writeLineToOutput("var __context = this;");
@@ -29222,7 +29233,7 @@ var TypeScript;
29222
29233
29223
29234
if (hasDCIContext) {
29224
29235
dependencyList += ", \"typescript-dci/dci\"";
29225
- importList += ", __dci_internal__ ";
29236
+ importList += ", __dci_internal ";
29226
29237
}
29227
29238
29228
29239
var importAndDependencyList = this.getModuleImportAndDependencyList(moduleDecl);
@@ -29231,7 +29242,7 @@ var TypeScript;
29231
29242
29232
29243
this.writeLineToOutput("define(" + dependencyList + "," + " function(" + importList + ") {");
29233
29244
} else if (hasDCIContext)
29234
- this.writeLineToOutput("var __dci_internal__ = require('typescript-dci/dci');");
29245
+ this.writeLineToOutput("var __dci_internal = require('typescript-dci/dci');");
29235
29246
} else {
29236
29247
if (!isExported) {
29237
29248
this.recordSourceMappingStart(moduleDecl);
@@ -29388,6 +29399,28 @@ var TypeScript;
29388
29399
};
29389
29400
29390
29401
Emitter.prototype.emitIndex = function (operand1, operand2) {
29402
+ if (this.thisFunctionNode && this.thisDCIContextNode) {
29403
+ var dciContext = this.thisDCIContextNode;
29404
+ var potentialRoleIdentifier = operand1;
29405
+ var roleName;
29406
+
29407
+ if (this.thisRoleNode && potentialRoleIdentifier.actualText == 'self') {
29408
+ roleName = this.thisRoleNode.name.actualText;
29409
+ }
29410
+
29411
+ if (!roleName)
29412
+ roleName = potentialRoleIdentifier.actualText;
29413
+
29414
+ if (roleName && roleName in dciContext.roleDeclarations) {
29415
+ this.writeToOutput('__dci_internal.getRoleMember(__context, __context.' + roleName + ', "' + roleName + '", ');
29416
+
29417
+ operand2.emit(this);
29418
+ this.writeToOutput(')');
29419
+
29420
+ return;
29421
+ }
29422
+ }
29423
+
29391
29424
operand1.emit(this);
29392
29425
this.writeToOutput("[");
29393
29426
operand2.emit(this);
@@ -29402,6 +29435,12 @@ var TypeScript;
29402
29435
var tempFnc = this.thisFunctionNode;
29403
29436
this.thisFunctionNode = funcDecl;
29404
29437
29438
+ funcDecl.isDCIContext = (Object.keys(funcDecl.roleDeclarations).length > 0);
29439
+ if (funcDecl.isDCIContext) {
29440
+ var tmpDCIContext = this.thisDCIContextNode;
29441
+ this.thisDCIContextNode = funcDecl;
29442
+ }
29443
+
29405
29444
if (funcDecl.isConstructor) {
29406
29445
temp = this.setContainer(4 /* Constructor */);
29407
29446
} else {
@@ -29417,6 +29456,10 @@ var TypeScript;
29417
29456
this.setContainer(temp);
29418
29457
this.thisFunctionNode = tempFnc;
29419
29458
29459
+ if (funcDecl.isDCIContext) {
29460
+ this.thisDCIContextNode = tmpDCIContext;
29461
+ }
29462
+
29420
29463
if (!TypeScript.hasFlag(funcDecl.getFunctionFlags(), 128 /* Signature */)) {
29421
29464
var pullFunctionDecl = this.semanticInfoChain.getDeclForAST(funcDecl, this.document.fileName);
29422
29465
if (TypeScript.hasFlag(funcDecl.getFunctionFlags(), 16 /* Static */)) {
@@ -40193,11 +40236,11 @@ var TypeScript;
40193
40236
40194
40237
nameSymbol = this.resolveNameSymbol(nameSymbol, context);
40195
40238
40196
- if (!nameSymbol && !lhsType.isPrimitive() && this.cachedObjectInterfaceType()) {
40197
- nameSymbol = this.getMemberSymbol(rhsName, TypeScript.PullElementKind.SomeValue, this.cachedObjectInterfaceType());
40198
- }
40199
-
40200
40239
if (!nameSymbol) {
40240
+ if (!lhsType.isPrimitive() && this.cachedObjectInterfaceType()) {
40241
+ nameSymbol = this.getMemberSymbol(rhsName, TypeScript.PullElementKind.SomeValue, this.cachedObjectInterfaceType());
40242
+ }
40243
+
40201
40244
if (lhs.kind != TypeScript.PullElementKind.Role) {
40202
40245
context.postError(this.unitPath, dottedNameAST.operand2.minChar, dottedNameAST.operand2.getLength(), TypeScript.DiagnosticCode.The_property_0_does_not_exist_on_value_of_type_1, [(dottedNameAST.operand2).actualText, lhsType.toString(enclosingDecl ? enclosingDecl.getSymbol() : null)], enclosingDecl);
40203
40246
}
@@ -53610,8 +53653,11 @@ var TypeScript;
53610
53653
};
53611
53654
53612
53655
Identifier.prototype.emit = function (emitter) {
53613
- if (emitter.thisFunctionNode && emitter.thisFunctionNode.isDCIContext) {
53614
- if (this.actualText in emitter.thisFunctionNode.roleDeclarations) {
53656
+ if (emitter.thisDCIContextNode) {
53657
+ if (emitter.thisRoleNode && this.actualText == 'self') {
53658
+ emitter.writeToOutput("__context." + emitter.thisRoleNode.name.actualText);
53659
+ return;
53660
+ } else if (this.actualText in emitter.thisDCIContextNode.roleDeclarations) {
53615
53661
emitter.writeToOutput("__context.");
53616
53662
}
53617
53663
}
@@ -54525,6 +54571,8 @@ var TypeScript;
54525
54571
_super.call(this, name, typeParameters, extendsList, implementsList, members);
54526
54572
this.endingToken = endingToken;
54527
54573
this.constructorDecl = null;
54574
+ this.isDCIContext = false;
54575
+ this.roleDeclarations = {};
54528
54576
}
54529
54577
ClassDeclaration.prototype.nodeType = function () {
54530
54578
return 14 /* ClassDeclaration */;
@@ -54644,9 +54692,6 @@ var TypeScript;
54644
54692
var operand1 = (this.expression).operand1;
54645
54693
var operand2 = (this.expression).operand2;
54646
54694
54647
- if (!emitter.thisFunctionNode.isDCIContext) {
54648
- emitter.writeToOutput("__context.");
54649
- }
54650
54695
operand1.emit(emitter);
54651
54696
emitter.writeToOutput(" = ");
54652
54697
0 commit comments