Skip to content

Commit a7be10e

Browse files
committed
Updated bin/tsc.js
1 parent ae299c0 commit a7be10e

File tree

1 file changed

+93
-48
lines changed

1 file changed

+93
-48
lines changed

bin/tsc.js

Lines changed: 93 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -28413,6 +28413,7 @@ var TypeScript;
2841328413
this.thisClassNode = null;
2841428414
this.thisRoleNode = null;
2841528415
this.thisFunctionNode = null;
28416+
this.thisDCIContextNode = null;
2841628417
this.moduleName = "";
2841728418
this.emitState = new EmitState();
2841828419
this.indenter = new Indenter();
@@ -28799,69 +28800,81 @@ var TypeScript;
2879928800
var binExpTarget, operand1, operand2, dciContext, isCallToRoleMethod = false, isCallToSelf = false, roleName;
2880028801

2880128802
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;
2881828805
binExpTarget = target;
2881928806
operand1 = binExpTarget.operand1;
2882028807
operand2 = binExpTarget.operand2;
2882128808

2882228809
if (this.thisRoleNode) {
28823-
if (this.thisRoleNode && operand1 instanceof TypeScript.ThisExpression) {
28810+
if (operand1 instanceof TypeScript.ThisExpression || operand1.actualText == 'self') {
2882428811
roleName = this.thisRoleNode.name.actualText;
2882528812
isCallToSelf = true;
2882628813
}
2882728814
}
2882828815

28829-
if (!isCallToSelf) {
28816+
if (!roleName)
2883028817
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+
});
2884128828
}
2884228829
}
2884328830
}
2884428831

2884528832
if (isCallToRoleMethod || isCallToSelf) {
28833+
var isCallToThis = false;
2884628834
if (isCallToSelf) {
28847-
this.writeToOutput("__dci_internal__.callMethodOnSelf");
28835+
if (operand1 instanceof TypeScript.ThisExpression) {
28836+
isCallToThis = true;
2884828837

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+
}
2885128863
} else {
2885228864
this.writeToOutput("__context.__$" + roleName + "." + operand2.actualText + ".");
2885328865
this.writeToOutput("call(__context." + roleName);
28866+
28867+
if (args && args.members.length)
28868+
this.writeToOutput(", ");
2885428869
}
28855-
if (args && args.members.length)
28856-
this.writeToOutput(", ");
2885728870

2885828871
this.recordSourceMappingStart(args);
2885928872

2886028873
if (args && args.members.length) {
28861-
if (isCallToSelf)
28874+
if (isCallToThis)
2886228875
this.writeToOutput("[");
2886328876
this.emitCommaSeparatedList(args);
28864-
if (isCallToSelf)
28877+
if (isCallToThis)
2886528878
this.writeToOutput("]");
2886628879
}
2886728880
} else {
@@ -28959,8 +28972,6 @@ var TypeScript;
2895928972
}
2896028973
this.writeLineToOutput(") {");
2896128974

28962-
funcDecl.isDCIContext = (Object.keys(funcDecl.roleDeclarations).length > 0);
28963-
2896428975
if (funcDecl.isDCIContext) {
2896528976
this.indenter.increaseIndent();
2896628977
this.writeLineToOutput("var __context = this;");
@@ -29222,7 +29233,7 @@ var TypeScript;
2922229233

2922329234
if (hasDCIContext) {
2922429235
dependencyList += ", \"typescript-dci/dci\"";
29225-
importList += ", __dci_internal__";
29236+
importList += ", __dci_internal";
2922629237
}
2922729238

2922829239
var importAndDependencyList = this.getModuleImportAndDependencyList(moduleDecl);
@@ -29231,7 +29242,7 @@ var TypeScript;
2923129242

2923229243
this.writeLineToOutput("define(" + dependencyList + "," + " function(" + importList + ") {");
2923329244
} else if (hasDCIContext)
29234-
this.writeLineToOutput("var __dci_internal__ = require('typescript-dci/dci');");
29245+
this.writeLineToOutput("var __dci_internal = require('typescript-dci/dci');");
2923529246
} else {
2923629247
if (!isExported) {
2923729248
this.recordSourceMappingStart(moduleDecl);
@@ -29388,6 +29399,28 @@ var TypeScript;
2938829399
};
2938929400

2939029401
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+
2939129424
operand1.emit(this);
2939229425
this.writeToOutput("[");
2939329426
operand2.emit(this);
@@ -29402,6 +29435,12 @@ var TypeScript;
2940229435
var tempFnc = this.thisFunctionNode;
2940329436
this.thisFunctionNode = funcDecl;
2940429437

29438+
funcDecl.isDCIContext = (Object.keys(funcDecl.roleDeclarations).length > 0);
29439+
if (funcDecl.isDCIContext) {
29440+
var tmpDCIContext = this.thisDCIContextNode;
29441+
this.thisDCIContextNode = funcDecl;
29442+
}
29443+
2940529444
if (funcDecl.isConstructor) {
2940629445
temp = this.setContainer(4 /* Constructor */);
2940729446
} else {
@@ -29417,6 +29456,10 @@ var TypeScript;
2941729456
this.setContainer(temp);
2941829457
this.thisFunctionNode = tempFnc;
2941929458

29459+
if (funcDecl.isDCIContext) {
29460+
this.thisDCIContextNode = tmpDCIContext;
29461+
}
29462+
2942029463
if (!TypeScript.hasFlag(funcDecl.getFunctionFlags(), 128 /* Signature */)) {
2942129464
var pullFunctionDecl = this.semanticInfoChain.getDeclForAST(funcDecl, this.document.fileName);
2942229465
if (TypeScript.hasFlag(funcDecl.getFunctionFlags(), 16 /* Static */)) {
@@ -40193,11 +40236,11 @@ var TypeScript;
4019340236

4019440237
nameSymbol = this.resolveNameSymbol(nameSymbol, context);
4019540238

40196-
if (!nameSymbol && !lhsType.isPrimitive() && this.cachedObjectInterfaceType()) {
40197-
nameSymbol = this.getMemberSymbol(rhsName, TypeScript.PullElementKind.SomeValue, this.cachedObjectInterfaceType());
40198-
}
40199-
4020040239
if (!nameSymbol) {
40240+
if (!lhsType.isPrimitive() && this.cachedObjectInterfaceType()) {
40241+
nameSymbol = this.getMemberSymbol(rhsName, TypeScript.PullElementKind.SomeValue, this.cachedObjectInterfaceType());
40242+
}
40243+
4020140244
if (lhs.kind != TypeScript.PullElementKind.Role) {
4020240245
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);
4020340246
}
@@ -53610,8 +53653,11 @@ var TypeScript;
5361053653
};
5361153654

5361253655
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) {
5361553661
emitter.writeToOutput("__context.");
5361653662
}
5361753663
}
@@ -54525,6 +54571,8 @@ var TypeScript;
5452554571
_super.call(this, name, typeParameters, extendsList, implementsList, members);
5452654572
this.endingToken = endingToken;
5452754573
this.constructorDecl = null;
54574+
this.isDCIContext = false;
54575+
this.roleDeclarations = {};
5452854576
}
5452954577
ClassDeclaration.prototype.nodeType = function () {
5453054578
return 14 /* ClassDeclaration */;
@@ -54644,9 +54692,6 @@ var TypeScript;
5464454692
var operand1 = (this.expression).operand1;
5464554693
var operand2 = (this.expression).operand2;
5464654694

54647-
if (!emitter.thisFunctionNode.isDCIContext) {
54648-
emitter.writeToOutput("__context.");
54649-
}
5465054695
operand1.emit(emitter);
5465154696
emitter.writeToOutput(" = ");
5465254697

0 commit comments

Comments
 (0)