Skip to content

Commit a8a71db

Browse files
committed
Added support for calling role methods dynamically
1 parent 203963d commit a8a71db

File tree

9 files changed

+126
-208
lines changed

9 files changed

+126
-208
lines changed

bin/tsc.js

Lines changed: 47 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,3 @@
1-
/*! *****************************************************************************
2-
Copyright (c) Microsoft Corporation. All rights reserved.
3-
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4-
this file except in compliance with the License. You may obtain a copy of the
5-
License at http://www.apache.org/licenses/LICENSE-2.0
6-
7-
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
8-
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
9-
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
10-
MERCHANTABLITY OR NON-INFRINGEMENT.
11-
12-
See the Apache Version 2.0 License for specific language governing permissions
13-
and limitations under the License.
14-
***************************************************************************** */
15-
161
var TypeScript;
172
(function (TypeScript) {
183
TypeScript.DiagnosticCode = {
@@ -28428,7 +28413,6 @@ var TypeScript;
2842828413
this.thisClassNode = null;
2842928414
this.thisRoleNode = null;
2843028415
this.thisFunctionNode = null;
28431-
this.thisDCIContextNode = null;
2843228416
this.moduleName = "";
2843328417
this.emitState = new EmitState();
2843428418
this.indenter = new Indenter();
@@ -28815,74 +28799,69 @@ var TypeScript;
2881528799
var binExpTarget, operand1, operand2, dciContext, isCallToRoleMethod = false, isCallToSelf = false, roleName;
2881628800

2881728801
if (this.thisFunctionNode && target instanceof TypeScript.BinaryExpression) {
28818-
if (this.thisDCIContextNode) {
28819-
dciContext = this.thisDCIContextNode;
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) {
2882028818
binExpTarget = target;
2882128819
operand1 = binExpTarget.operand1;
2882228820
operand2 = binExpTarget.operand2;
2882328821

2882428822
if (this.thisRoleNode) {
28825-
if (this.thisRoleNode && (operand1 instanceof TypeScript.ThisExpression || operand1.actualText == 'self')) {
28823+
if (this.thisRoleNode && operand1 instanceof TypeScript.ThisExpression) {
2882628824
roleName = this.thisRoleNode.name.actualText;
2882728825
isCallToSelf = true;
2882828826
}
2882928827
}
2883028828

28831-
if (!roleName)
28829+
if (!isCallToSelf) {
2883228830
roleName = operand1.actualText;
28833-
28834-
if (roleName && roleName in dciContext.roleDeclarations) {
28835-
var methodName = operand2.actualText;
28836-
var roleDecl = dciContext.roleDeclarations[roleName];
28837-
roleDecl.members.members.forEach(function (member) {
28838-
if ((member).name.actualText == methodName) {
28839-
isCallToRoleMethod = true;
28840-
return false;
28841-
}
28842-
});
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+
}
2884328841
}
2884428842
}
2884528843
}
2884628844

2884728845
if (isCallToRoleMethod || isCallToSelf) {
28848-
var isCallToThis = false;
2884928846
if (isCallToSelf) {
28850-
if (operand1 instanceof TypeScript.ThisExpression) {
28851-
isCallToThis = true;
28852-
28853-
this.writeToOutput("__dci_internal__.callMethodOnSelf");
28854-
28855-
this.writeToOutput("(__context, this, '" + roleName + "'");
28856-
this.writeToOutput(", '" + operand2.actualText + "'");
28847+
this.writeToOutput("__dci_internal__.callMethodOnSelf");
2885728848

28858-
if (args && args.members.length)
28859-
this.writeToOutput(", ");
28860-
} else {
28861-
if (isCallToRoleMethod) {
28862-
this.writeToOutput("__context.__$" + roleName + "." + operand2.actualText + ".");
28863-
this.writeToOutput("call(__context." + roleName);
28864-
28865-
if (args && args.members.length)
28866-
this.writeToOutput(", ");
28867-
} else {
28868-
this.writeToOutput("__context." + roleName + "." + operand2.actualText + "(");
28869-
}
28870-
}
28849+
this.writeToOutput("(__context, this, '" + roleName + "'");
28850+
this.writeToOutput(", '" + operand2.actualText + "'");
2887128851
} else {
2887228852
this.writeToOutput("__context.__$" + roleName + "." + operand2.actualText + ".");
2887328853
this.writeToOutput("call(__context." + roleName);
28874-
28875-
if (args && args.members.length)
28876-
this.writeToOutput(", ");
2887728854
}
28855+
if (args && args.members.length)
28856+
this.writeToOutput(", ");
2887828857

2887928858
this.recordSourceMappingStart(args);
2888028859

2888128860
if (args && args.members.length) {
28882-
if (isCallToThis)
28861+
if (isCallToSelf)
2888328862
this.writeToOutput("[");
2888428863
this.emitCommaSeparatedList(args);
28885-
if (isCallToThis)
28864+
if (isCallToSelf)
2888628865
this.writeToOutput("]");
2888728866
}
2888828867
} else {
@@ -28980,6 +28959,8 @@ var TypeScript;
2898028959
}
2898128960
this.writeLineToOutput(") {");
2898228961

28962+
funcDecl.isDCIContext = (Object.keys(funcDecl.roleDeclarations).length > 0);
28963+
2898328964
if (funcDecl.isDCIContext) {
2898428965
this.indenter.increaseIndent();
2898528966
this.writeLineToOutput("var __context = this;");
@@ -29421,12 +29402,6 @@ var TypeScript;
2942129402
var tempFnc = this.thisFunctionNode;
2942229403
this.thisFunctionNode = funcDecl;
2942329404

29424-
funcDecl.isDCIContext = (Object.keys(funcDecl.roleDeclarations).length > 0);
29425-
if (funcDecl.isDCIContext) {
29426-
var tmpDCIContext = this.thisDCIContextNode;
29427-
this.thisDCIContextNode = funcDecl;
29428-
}
29429-
2943029405
if (funcDecl.isConstructor) {
2943129406
temp = this.setContainer(4 /* Constructor */);
2943229407
} else {
@@ -29442,10 +29417,6 @@ var TypeScript;
2944229417
this.setContainer(temp);
2944329418
this.thisFunctionNode = tempFnc;
2944429419

29445-
if (funcDecl.isDCIContext) {
29446-
this.thisDCIContextNode = tmpDCIContext;
29447-
}
29448-
2944929420
if (!TypeScript.hasFlag(funcDecl.getFunctionFlags(), 128 /* Signature */)) {
2945029421
var pullFunctionDecl = this.semanticInfoChain.getDeclForAST(funcDecl, this.document.fileName);
2945129422
if (TypeScript.hasFlag(funcDecl.getFunctionFlags(), 16 /* Static */)) {
@@ -40222,11 +40193,11 @@ var TypeScript;
4022240193

4022340194
nameSymbol = this.resolveNameSymbol(nameSymbol, context);
4022440195

40225-
if (!nameSymbol) {
40226-
if (!lhsType.isPrimitive() && this.cachedObjectInterfaceType()) {
40227-
nameSymbol = this.getMemberSymbol(rhsName, TypeScript.PullElementKind.SomeValue, this.cachedObjectInterfaceType());
40228-
}
40196+
if (!nameSymbol && !lhsType.isPrimitive() && this.cachedObjectInterfaceType()) {
40197+
nameSymbol = this.getMemberSymbol(rhsName, TypeScript.PullElementKind.SomeValue, this.cachedObjectInterfaceType());
40198+
}
4022940199

40200+
if (!nameSymbol) {
4023040201
if (lhs.kind != TypeScript.PullElementKind.Role) {
4023140202
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);
4023240203
}
@@ -53639,11 +53610,8 @@ var TypeScript;
5363953610
};
5364053611

5364153612
Identifier.prototype.emit = function (emitter) {
53642-
if (emitter.thisDCIContextNode) {
53643-
if (emitter.thisRoleNode && this.actualText == 'self') {
53644-
emitter.writeToOutput("__context." + emitter.thisRoleNode.name.actualText);
53645-
return;
53646-
} else if (this.actualText in emitter.thisDCIContextNode.roleDeclarations) {
53613+
if (emitter.thisFunctionNode && emitter.thisFunctionNode.isDCIContext) {
53614+
if (this.actualText in emitter.thisFunctionNode.roleDeclarations) {
5364753615
emitter.writeToOutput("__context.");
5364853616
}
5364953617
}
@@ -54557,8 +54525,6 @@ var TypeScript;
5455754525
_super.call(this, name, typeParameters, extendsList, implementsList, members);
5455854526
this.endingToken = endingToken;
5455954527
this.constructorDecl = null;
54560-
this.isDCIContext = false;
54561-
this.roleDeclarations = {};
5456254528
}
5456354529
ClassDeclaration.prototype.nodeType = function () {
5456454530
return 14 /* ClassDeclaration */;
@@ -54678,6 +54644,9 @@ var TypeScript;
5467854644
var operand1 = (this.expression).operand1;
5467954645
var operand2 = (this.expression).operand2;
5468054646

54647+
if (!emitter.thisFunctionNode.isDCIContext) {
54648+
emitter.writeToOutput("__context.");
54649+
}
5468154650
operand1.emit(emitter);
5468254651
emitter.writeToOutput(" = ");
5468354652

@@ -57069,3 +57038,4 @@ var TypeScript;
5706957038

5707057039
var batch = new TypeScript.BatchCompiler(IO);
5707157040
batch.batchCompile();
57041+
//# sourceMappingURL=file:////www/node_modules/typescript-dci/built/local/tsc.js.map

bin/typescript.js

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,3 @@
1-
/*! *****************************************************************************
2-
Copyright (c) Microsoft Corporation. All rights reserved.
3-
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4-
this file except in compliance with the License. You may obtain a copy of the
5-
License at http://www.apache.org/licenses/LICENSE-2.0
6-
7-
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
8-
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
9-
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
10-
MERCHANTABLITY OR NON-INFRINGEMENT.
11-
12-
See the Apache Version 2.0 License for specific language governing permissions
13-
and limitations under the License.
14-
***************************************************************************** */
15-
161
var TypeScript;
172
(function (TypeScript) {
183
TypeScript.DiagnosticCode = {
@@ -55670,3 +55655,4 @@ var TypeScript;
5567055655
})(AST);
5567155656
TypeScript.Comment = Comment;
5567255657
})(TypeScript || (TypeScript = {}));
55658+
//# sourceMappingURL=file:////www/node_modules/typescript-dci/built/local/typescript.js.map

bin/typescriptServices.js

Lines changed: 1 addition & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -1,103 +1,3 @@
1-
/*! *****************************************************************************
2-
Copyright (c) Microsoft Corporation. All rights reserved.
3-
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4-
this file except in compliance with the License. You may obtain a copy of the
5-
License at http://www.apache.org/licenses/LICENSE-2.0
6-
7-
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
8-
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
9-
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
10-
MERCHANTABLITY OR NON-INFRINGEMENT.
11-
12-
See the Apache Version 2.0 License for specific language governing permissions
13-
and limitations under the License.
14-
***************************************************************************** */
15-
16-
/*!----------------- TypeScript ThirdPartyNotices -------------------------------------------------------
17-
18-
The TypeScript software is based on or incorporates material and code from the projects listed below
19-
(collectively "Third Party Code"). Microsoft is not the original author of the
20-
Third Party Code. The original copyright notice and the license, under which
21-
Microsoft received such Third Party Code, are set forth below. Such license and
22-
notices are provided for informational purposes only. Microsoft licenses the Third
23-
Party Code to you under the terms of the Apache 2.0 License.
24-
All Third Party Code licensed by Microsoft under the Apache License, Version 2.0 (the "License"); you
25-
may not use this file except in compliance with the License. You may obtain a copy
26-
of the License at http://www.apache.org/licenses/LICENSE-2.0
27-
28-
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
29-
EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR
30-
CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT.
31-
32-
See the Apache Version 2.0 License for specific language governing permissions and
33-
limitations under the License.
34-
---------------------------------------------
35-
Third Party Code Components
36-
--------------------------------------------
37-
---- Mozilla Developer Code---------
38-
The following Mozilla Developer Code is under Public Domain as updated after Aug. 20, 2012, see, https://developer.mozilla.org/en-US/docs/Project:Copyrights
39-
1. Array filter Compatibility Method,
40-
Available at https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Array/filter
41-
Any copyright is dedicated to the Public Domain.
42-
43-
2. Array forEach Compatibility Method,
44-
Available at https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Array/forEach
45-
Any copyright is dedicated to the Public Domain.
46-
47-
3. Array indexOf Compatibility Method,
48-
Available at https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Array/indexOf
49-
Any copyright is dedicated to the Public Domain.
50-
51-
4. Array map Compatibility Method,
52-
Available at https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Array/map
53-
Any copyright is dedicated to the Public Domain.
54-
55-
5. Array Reduce Compatibility Method,
56-
Available at https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Array/Reduce
57-
Any copyright is dedicated to the Public Domain.
58-
59-
6. String Trim Compatibility Method,
60-
Available at https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/String/Trim
61-
Any copyright is dedicated to the Public Domain.
62-
63-
7. Date now Compatibility Method,
64-
Available at https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Date/now
65-
Any copyright is dedicated to the Public Domain.
66-
67-
------------JSON2 Script------------------------
68-
json2.js 2012-10-08
69-
Public Domain.
70-
NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.
71-
See, http://www.JSON.org/js.html
72-
73-
--------------r.js----------------------
74-
Copyright (c) 2010-2011 Dojo Foundation. All Rights Reserved.
75-
Originally License under MIT License
76-
-------------------------------------------------------------------------
77-
Provided for Informational Purposes Only
78-
MIT License
79-
80-
Permission is hereby granted, free of charge, to any person obtaining
81-
a copy of this software and associated documentation files (the
82-
"Software"), to deal in the Software without restriction, including
83-
without limitation the rights to use, copy, modify, merge, publish,
84-
distribute, sublicense, and/or sell copies of the Software, and to
85-
permit persons to whom the Software is furnished to do so, subject to
86-
the following conditions:
87-
88-
The above copyright notice and this permission notice shall be
89-
included in all copies or substantial portions of the Software.
90-
91-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
92-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
93-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
94-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
95-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
96-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
97-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
98-
--------------------------------------------------------------------------------------
99-
100-
------------- End of ThirdPartyNotices --------------------------------------------------- */
1011
var TypeScript;
1022
(function (TypeScript) {
1033
TypeScript.DiagnosticCode = {
@@ -63487,3 +63387,4 @@ var Services;
6348763387
})();
6348863388
Services.BraceMatcher = BraceMatcher;
6348963389
})(Services || (Services = {}));
63390+
//# sourceMappingURL=file:////www/node_modules/typescript-dci/built/local/typescriptServices.js.map

samples/dci/js/TransferMoney/Account.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
var __dci_internal__ = require('typescript-dci/dci');
1+
var __dci_internal = require('typescript-dci/dci');
22
var DCI = require('../../DCI');
33

44

0 commit comments

Comments
 (0)