Skip to content

Commit 34bf783

Browse files
committed
prevented role assignment from being output as a Javascript expression
1 parent 8e8b0a4 commit 34bf783

18 files changed

+237
-1
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
When testing, remember to run the version you just built, don't just run `tsc somefile.ts` (which will run whatever version of `tsc` is currently configured in your shell)!
2+
3+
e.g. run:
4+
5+
node built/local/tsc.js /path/to/your/file.ts
6+
7+
====
8+
9+
The .generated.ts files are not regenerated just by running `jake local`; it's necessary to run `jake run-syntax-generator`.
10+
11+
The run-syntax-generator task is a bit tricky because it relies on a working compiler in the built/local directory in order to do its job. This can result in a catch-22 where you've made a change to src/compiler/syntax/syntaxGenerator.ts that would resolve an error you're currently getting for a change you recently made to any of the other .ts files, but it's still trying to use the files you generated previously BEFORE it can run the run-syntax-generator task.
12+
13+
So when making changes to syntaxGenerator.ts or SyntaxGenerator.d.ts, always make those changes without changing any of the other .ts files, and run `jake run-syntax-generator` BEFORE making your other modifications and running `jake local`.
14+
15+
Solution
16+
========
17+
18+
Copy syntaxGenerator.ts, syntaxGenerator.d.ts, and syntaxElement.ts *to* the official distro and then, *from the official distro*, run:
19+
jake run-syntax-generator
20+
21+
Make sure to copy all 3 files; the official distro's version of syntaxGenerator.ts doesn't support Mac properly (see comments at bottom of syntaxGenerator.ts for details).
22+
23+
Then copy the .generated files back to typescript-dci.
24+
25+
Note that this will only work once unless you restore all the .generated files back to their original versions in the official distro, or just re-download the official distro, before doing this procedure again.
26+
27+
28+
OR
29+
In some cases, just copying all the .generated files in src/compiler/syntax *from* from the official distro may be sufficient, then (from the DCI version) run:
30+
jake run-syntax-generator
31+
32+
Also maybe helpful:
33+
In Jakefile, set useBuiltCompiler to false
34+
---
35+
36+
NOTE:
37+
Sometimes syntax-generator appears to work the first time, then doesn't work when you run it again immediately afterward, apparently because the first time it might use the already-generated files, but not the second time.

dci-doc/tmp--old-tips.txt

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
NOTE:
2+
Sometimes syntax-generator appears to work the first time, then doesn't work when you run it again immediately afterward
3+
4+
Real fix
5+
======
6+
7+
Copy syntaxGenerator.ts, syntaxGenerator.d.ts, and syntaxElement.ts *to* the official distro and then run jake run-syntax-generator *from the official distro*
8+
9+
OR
10+
just copying those .generated files from from the official distro may be sufficient, then run:
11+
jake run-syntax-generator
12+
13+
Also maybe helpful:
14+
In Jakefile, set useBuiltCompiler to false
15+
---
16+
17+
18+
The .generated.ts files are not regenerated just by running `jake local`; it's necessary to run `jake run-syntax-generator`.
19+
20+
The run-syntax-generator task is a bit tricky because it relies on a working compiler in the built/local directory in order to do its job. This can result in a catch-22 where you've made a change to src/compiler/syntax/syntaxGenerator.ts that would resolve an error you're currently getting for a change you recently made to any of the other .ts files, but it's still trying to use the files you generated previously BEFORE it can run the run-syntax-generator task.
21+
22+
So when making changes to syntaxGenerator.ts or SyntaxGenerator.d.ts, always make those changes without changing any of the other .ts files, and run `jake run-syntax-generator` BEFORE making your other modifications and running `jake local`.
23+
24+
25+
--- TODO - UPDATE THIS DOCUMENTATION - THE BELOW DOESN'T REALLY FIX IT, AS IS REVEALED BY RUNNING THE jake run-syntax-generator COMMAND AGAIN
26+
27+
28+
If you end up in the catch-22 situation mentioned above, then you can try the following:
29+
30+
git checkout src/compiler/syntax/SyntaxGenerator.js
31+
jake run-syntax-generator
32+
33+
RPOBLEM!
34+
Running
35+
jake run-syntax-generator
36+
again here reveals this doesn't work
37+
38+
You may also need to overwrite the tsc.js in built/local with the one from bin/.

samples/dci/_goal.html

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<script>
2+
"use strict";
3+
4+
var isNodeJs = (typeof window == 'undefined' && typeof global != 'undefined');
5+
if (!isNodeJs) var global = window;
6+
7+
//Calls a method on a role player - could be either a role method or a method on the data object
8+
function callRolePlayerMethod(context, player, playerName, roleName, methodName, args) {
9+
if (player != context.__rolePlayers[playerName]) {
10+
//support constructor functions within role methods - make sure we don't wrongly
11+
//assume `this` refers to the current role
12+
if (player != undefined && player != global) {
13+
return player[methodName].apply(player, args);
14+
}
15+
//if we're here, then `this` probably *should* refer to the current role and the only
16+
//reason it's undefined is most likely a nested function
17+
//(e.g. a callback function passed to forEach() to loop over an array)
18+
else {
19+
player = context.__rolePlayers[playerName];
20+
}
21+
}
22+
23+
var roleMethod = context['__$'+roleName][methodName];
24+
//if the method exists on the role, we always call it (role methods can override data object methods)
25+
if (typeof roleMethod == 'function') {
26+
return (args ? roleMethod.apply(player, args): roleMethod.call(player));
27+
}
28+
return player[methodName].apply(player, args);
29+
}
30+
31+
function TransferMoney(sourceAcct) {
32+
var __context = this;
33+
34+
this.__rolePlayers = {
35+
'SourceAccount': sourceAcct
36+
};
37+
38+
this.__$SourceAccount = {
39+
greet: function () {
40+
console.log("greetings!");
41+
this.increaseBalance();
42+
}
43+
44+
, foo: function () {
45+
console.log('foo');
46+
//this.greet();
47+
callRolePlayerMethod(__context, this, 'SourceAccount', 'SourceAccount', 'greet');
48+
49+
// [1,2,3].forEach(function() {
50+
// callRolePlayerMethod(__context, this, 'SourceAccount', 'SourceAccount', 'greet');
51+
// });
52+
}
53+
}
54+
55+
this.execute = function() {
56+
this.__$SourceAccount.foo.call(sourceAcct);
57+
}
58+
}
59+
60+
var sourceAcct = {
61+
increaseBalance: function() {
62+
console.log('increaseBalance');
63+
}
64+
};
65+
var transferMoneyCtx = new TransferMoney(sourceAcct);
66+
transferMoneyCtx.execute();
67+
68+
</script>

samples/dci/test-old.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
function TransferMoney(sourceAcct) {
2+
var __context = this;
3+
var blah = '123';
4+
5+
this.__$test = {
6+
greet: function () {
7+
this.__$ROLE.deposit.call(DestinationAccount);
8+
//console.log("greetings!");
9+
}
10+
11+
,foo: function () {
12+
//console.log('foo');
13+
DCI.callRolePlayerMethod(__context, this, 'greet');
14+
}
15+
}
16+
}

samples/dci/test.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
function TransferMoney(sourceAcct2) {
2+
var __context = this;
3+
4+
var test = '123';
5+
this.__$SourceAccount = { test: function () {
6+
__context.__$DestinationAccount.deposit.call(rolePlayer);
7+
}
8+
,foo: function () {
9+
DCI.callRolePlayerMethod(__context, this, TODO-playerName, 'SourceAccount', 'greet');
10+
}
11+
}
12+
}

samples/dci/test.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
function TransferMoney(sourceAcct2) {
2+
3+
SourceAccount <- sourceAcct2;
4+
var test = '123';
5+
6+
role SourceAccount {
7+
test() {
8+
DestinationAccount.deposit();
9+
}
10+
11+
foo() {
12+
this.greet();
13+
}
14+
}
15+
}

samples/dci/tmp.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
var a, b;
2+
;

src/compiler/ast.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1205,6 +1205,16 @@ module TypeScript {
12051205
}
12061206

12071207
public emitWorker(emitter: Emitter) {
1208+
//DCI
1209+
if (this.expression.nodeType() == NodeType.RoleAssignmentExpression) {
1210+
//DCI TODO
1211+
//Is this the right place to add the role to the collection?
1212+
//Maybe do this in parser and simply do nothing here
1213+
var operand1 = (<BinaryExpression>this.expression).operand1;
1214+
console.log('adding role ' + (<Identifier>operand1).actualText);
1215+
return;
1216+
}
1217+
12081218
var isArrowExpression = this.expression.nodeType() === NodeType.FunctionDeclaration &&
12091219
hasFlag((<FunctionDeclaration>this.expression).getFunctionFlags(), FunctionFlags.IsFatArrowFunction);
12101220

src/compiler/astWalker.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ module TypeScript {
125125
this.childrenWalkers[NodeType.InvocationExpression] = ChildrenWalkers.walkInvocationExpressionChildren;
126126
this.childrenWalkers[NodeType.ObjectCreationExpression] = ChildrenWalkers.walkObjectCreationExpressionChildren;
127127
this.childrenWalkers[NodeType.AssignmentExpression] = ChildrenWalkers.walkBinaryExpressionChildren;
128+
//DCI
129+
this.childrenWalkers[NodeType.RoleAssignmentExpression] = ChildrenWalkers.walkBinaryExpressionChildren;
128130
this.childrenWalkers[NodeType.AddAssignmentExpression] = ChildrenWalkers.walkBinaryExpressionChildren;
129131
this.childrenWalkers[NodeType.SubtractAssignmentExpression] = ChildrenWalkers.walkBinaryExpressionChildren;
130132
this.childrenWalkers[NodeType.DivideAssignmentExpression] = ChildrenWalkers.walkBinaryExpressionChildren;

src/compiler/nodeTypes.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ module TypeScript {
6868
InvocationExpression,
6969
ObjectCreationExpression,
7070
AssignmentExpression,
71+
RoleAssignmentExpression, //DCI
7172
AddAssignmentExpression,
7273
SubtractAssignmentExpression,
7374
DivideAssignmentExpression,

src/compiler/syntax/SyntaxGenerator.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2260,6 +2260,7 @@ declare module TypeScript {
22602260
CaretEqualsToken,
22612261
SlashToken,
22622262
SlashEqualsToken,
2263+
LeftArrowToken, //DCI
22632264
SourceUnit,
22642265
QualifiedName,
22652266
ObjectType,
@@ -2315,6 +2316,7 @@ declare module TypeScript {
23152316
VoidExpression,
23162317
CommaExpression,
23172318
AssignmentExpression,
2319+
RoleAssignmentExpression, //DCI
23182320
AddAssignmentExpression,
23192321
SubtractAssignmentExpression,
23202322
MultiplyAssignmentExpression,

src/compiler/syntax/parser.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1454,6 +1454,10 @@ module TypeScript.Parser {
14541454
case SyntaxKind.InstanceOfExpression:
14551455
case SyntaxKind.InExpression:
14561456
return ExpressionPrecedence.RelationalExpressionPrecedence;
1457+
1458+
//DCI
1459+
case SyntaxKind.RoleAssignmentExpression:
1460+
return ExpressionPrecedence.AssignmentExpressionPrecedence;
14571461

14581462
case SyntaxKind.LeftShiftExpression:
14591463
case SyntaxKind.SignedRightShiftExpression:
@@ -3794,6 +3798,8 @@ module TypeScript.Parser {
37943798
private isRightAssociative(expressionKind: SyntaxKind): boolean {
37953799
switch (expressionKind) {
37963800
case SyntaxKind.AssignmentExpression:
3801+
//DCI TODO
3802+
//Should SyntaxKind.RoleAssignmentExpression be here?
37973803
case SyntaxKind.AddAssignmentExpression:
37983804
case SyntaxKind.SubtractAssignmentExpression:
37993805
case SyntaxKind.MultiplyAssignmentExpression:

src/compiler/syntax/scanner.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -705,6 +705,10 @@ module TypeScript {
705705
return SyntaxKind.LessThanLessThanToken;
706706
}
707707
}
708+
//DCI
709+
else if (this.currentCharCode() == CharacterCodes.minus) {
710+
return SyntaxKind.LeftArrowToken;
711+
}
708712
else {
709713
return SyntaxKind.LessThanToken;
710714
}

src/compiler/syntax/syntax.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,11 @@ module TypeScript.Syntax {
275275
export function assignmentExpression(left: IExpressionSyntax, token: ISyntaxToken, right: IExpressionSyntax): BinaryExpressionSyntax {
276276
return Syntax.normalModeFactory.binaryExpression(SyntaxKind.AssignmentExpression, left, token, right);
277277
}
278+
279+
//DCI
280+
export function roleAssignmentExpression(left: IExpressionSyntax, token: ISyntaxToken, right: IExpressionSyntax): BinaryExpressionSyntax {
281+
return Syntax.normalModeFactory.binaryExpression(SyntaxKind.AssignmentExpression, left, token, right);
282+
}
278283

279284
export function nodeHasSkippedOrMissingTokens(node: SyntaxNode): boolean {
280285
for (var i = 0; i < node.childCount(); i++) {

src/compiler/syntax/syntaxFacts.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,9 @@ module TypeScript.SyntaxFacts {
110110
"^=": SyntaxKind.CaretEqualsToken,
111111
"/": SyntaxKind.SlashToken,
112112
"/=": SyntaxKind.SlashEqualsToken,
113+
114+
//DCI
115+
"<-": SyntaxKind.LeftArrowToken,
113116
};
114117

115118
var kindToText = new Array<string>();
@@ -313,6 +316,10 @@ module TypeScript.SyntaxFacts {
313316

314317
case SyntaxKind.EqualsToken:
315318
return SyntaxKind.AssignmentExpression;
319+
320+
//DCI
321+
case SyntaxKind.LeftArrowToken:
322+
return SyntaxKind.RoleAssignmentExpression;
316323

317324
case SyntaxKind.CommaToken:
318325
return SyntaxKind.CommaExpression;
@@ -360,6 +367,7 @@ module TypeScript.SyntaxFacts {
360367
switch (kind) {
361368
case SyntaxKind.CommaExpression:
362369
case SyntaxKind.AssignmentExpression:
370+
case SyntaxKind.RoleAssignmentExpression: //DCI
363371
case SyntaxKind.AddAssignmentExpression:
364372
case SyntaxKind.SubtractAssignmentExpression:
365373
case SyntaxKind.MultiplyAssignmentExpression:

src/compiler/syntax/syntaxKind.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ module TypeScript {
146146
CaretEqualsToken,
147147
SlashToken,
148148
SlashEqualsToken,
149+
LeftArrowToken, //DCI
149150

150151
// SyntaxNodes
151152
SourceUnit,
@@ -217,6 +218,7 @@ module TypeScript {
217218
VoidExpression,
218219
CommaExpression,
219220
AssignmentExpression,
221+
RoleAssignmentExpression, //DCI
220222
AddAssignmentExpression,
221223
SubtractAssignmentExpression,
222224
MultiplyAssignmentExpression,
@@ -325,7 +327,10 @@ module TypeScript {
325327
LastToken = SlashEqualsToken,
326328

327329
FirstPunctuation = OpenBraceToken,
328-
LastPunctuation = SlashEqualsToken,
330+
331+
//DCI
332+
LastPunctuation = LeftArrowToken,
333+
//LastPunctuation = SlashEqualsToken,
329334

330335
FirstFixedWidth = FirstKeyword,
331336
LastFixedWidth = LastPunctuation,

src/compiler/syntaxTreeToAstVisitor.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1373,6 +1373,8 @@ module TypeScript {
13731373
switch (node.kind()) {
13741374
case SyntaxKind.CommaExpression: return NodeType.CommaExpression;
13751375
case SyntaxKind.AssignmentExpression: return NodeType.AssignmentExpression;
1376+
//DCI
1377+
case SyntaxKind.RoleAssignmentExpression: return NodeType.RoleAssignmentExpression;
13761378
case SyntaxKind.AddAssignmentExpression: return NodeType.AddAssignmentExpression;
13771379
case SyntaxKind.SubtractAssignmentExpression: return NodeType.SubtractAssignmentExpression;
13781380
case SyntaxKind.MultiplyAssignmentExpression: return NodeType.MultiplyAssignmentExpression;

src/compiler/typecheck/pullTypeResolution.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4169,6 +4169,9 @@ module TypeScript {
41694169
// assignment
41704170
case NodeType.AssignmentExpression:
41714171
return this.resolveAssignmentStatement(<BinaryExpression>ast, inContextuallyTypedAssignment, enclosingDecl, context);
4172+
4173+
//DCI TODO
4174+
//should NodeType.RoleAssignmentExpression be here?
41724175

41734176
// boolean operations
41744177
case NodeType.LogicalNotExpression:

0 commit comments

Comments
 (0)