Skip to content

Commit 94678b6

Browse files
authored
Collection fn respects parent env (#201)
* Collection functions that create their own environment can now have a parent environment * Update package ID and increment version to 1.29
1 parent f0a5ee4 commit 94678b6

File tree

4 files changed

+26
-20
lines changed

4 files changed

+26
-20
lines changed

docs/public/packages.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
2-
"packageId": "04tRb0000036OFdIAM",
2+
"packageId": "04tRb0000036fbRIAQ",
33
"componentPackageId": "04tRb0000012Mv8IAE"
44
}

expression-src/main/src/interpreter/Environment.cls

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,11 @@ public with sharing class Environment {
7474
this.context = context;
7575
}
7676

77+
public Environment(Environment parentEnvironment, SObject context) {
78+
this.parentEnvironment = parentEnvironment;
79+
this.context = context;
80+
}
81+
7782
public void define(String name, Object value) {
7883
variables.put(name.toLowerCase(), value);
7984
}

expression-src/main/src/interpreter/std-lib/CollectionFunctions.cls

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,12 @@ public with sharing class CollectionFunctions {
4848
}
4949
}
5050

51-
private static Environment getEnvironmentFromObject(Object currentVal) {
51+
private static Environment getEnvironmentFromObject(Environment parentEnvironment, Object currentVal) {
5252
Environment env;
5353
if (currentVal instanceof SObject) {
54-
env = new Environment((SObject) currentVal);
54+
env = new Environment(parentEnvironment, (SObject) currentVal);
5555
} else {
56-
env = new Environment();
56+
env = new Environment(parentEnvironment);
5757
}
5858
return env;
5959
}
@@ -118,7 +118,7 @@ public with sharing class CollectionFunctions {
118118
List<Object> result = new List<Object>();
119119
for (Integer i = 0; i < childrenAsList.size(); i++) {
120120
Object child = childrenAsList.get(i);
121-
Environment env = getEnvironmentFromObject(child);
121+
Environment env = getEnvironmentFromObject(this.interpreter.getEnvironment(), child);
122122
env.define('$current', child);
123123
env.define('$index', i);
124124
env.define('$total', childrenAsList.size());
@@ -170,7 +170,7 @@ public with sharing class CollectionFunctions {
170170
List<Object> result = new List<Object>();
171171
for (Integer i = 0; i < childrenAsList.size(); i++) {
172172
Object child = childrenAsList.get(i);
173-
Environment env = getEnvironmentFromObject(child);
173+
Environment env = getEnvironmentFromObject(this.interpreter.getEnvironment(), child);
174174

175175
env.define('$current', child);
176176
env.define('$index', i);
@@ -774,7 +774,7 @@ public with sharing class CollectionFunctions {
774774
// The result of the expression will be the new value.
775775
Object accumulator = initialValue;
776776
for (Object currentVal : listVal) {
777-
Environment env = getEnvironmentFromObject(currentVal);
777+
Environment env = getEnvironmentFromObject(this.interpreter.getEnvironment(), currentVal);
778778
env.define('$current', currentVal);
779779
env.define('$accumulator', accumulator);
780780
Interpreter interpreter = new Interpreter(env);
@@ -902,7 +902,7 @@ public with sharing class CollectionFunctions {
902902
// Loop through each element in the list, evaluating the
903903
// expression with the current value (as $current) being looped.
904904
for (Object currentVal : listVal) {
905-
Environment env = getEnvironmentFromObject(currentVal);
905+
Environment env = getEnvironmentFromObject(this.interpreter.getEnvironment(), currentVal);
906906
env.define('$current', currentVal);
907907
Interpreter interpreter = new Interpreter(env);
908908
Object result = interpreter.interpret(expr);
@@ -999,7 +999,7 @@ public with sharing class CollectionFunctions {
999999
// Loop through each element in the list, evaluating the
10001000
// expression with the current value (as $current) being looped.
10011001
for (Object currentVal : listVal) {
1002-
Environment env = getEnvironmentFromObject(currentVal);
1002+
Environment env = getEnvironmentFromObject(this.interpreter.getEnvironment(), currentVal);
10031003
env.define('$current', currentVal);
10041004
Interpreter interpreter = new Interpreter(env);
10051005
Object result = interpreter.interpret(expr);
@@ -1059,7 +1059,7 @@ public with sharing class CollectionFunctions {
10591059
// expression with the current value (as $current) being looped.
10601060
List<Object> result = new List<Object>();
10611061
for (Object currentVal : listVal) {
1062-
Environment env = getEnvironmentFromObject(currentVal);
1062+
Environment env = getEnvironmentFromObject(this.interpreter.getEnvironment(), currentVal);
10631063
env.define('$current', currentVal);
10641064
Interpreter interpreter = new Interpreter(env);
10651065
Object evaluated = interpreter.interpret(expr);
@@ -1118,7 +1118,7 @@ public with sharing class CollectionFunctions {
11181118
// Loop through each element in the list, evaluating the
11191119
// expression with the current value (as $current) being looped.
11201120
for (Object currentVal : listVal) {
1121-
Environment env = getEnvironmentFromObject(currentVal);
1121+
Environment env = getEnvironmentFromObject(this.interpreter.getEnvironment(), currentVal);
11221122
env.define('$current', currentVal);
11231123
Interpreter interpreter = new Interpreter(env);
11241124
Object result = interpreter.interpret(expr);
@@ -1254,7 +1254,7 @@ public with sharing class CollectionFunctions {
12541254
// expression with the current value (as $current) being looped.
12551255
for (Integer i = listVal.size() - 1; i >= 0; i--) {
12561256
Object currentVal = listVal.get(i);
1257-
Environment env = getEnvironmentFromObject(currentVal);
1257+
Environment env = getEnvironmentFromObject(this.interpreter.getEnvironment(), currentVal);
12581258
env.define('$current', currentVal);
12591259
Interpreter interpreter = new Interpreter(env);
12601260
Object result = interpreter.interpret(expr);
@@ -1361,7 +1361,7 @@ public with sharing class CollectionFunctions {
13611361
List<Object> listVal = (List<Object>) listObj;
13621362
for (Integer i = 0; i < listVal.size(); i++) {
13631363
Object currentVal = listVal.get(i);
1364-
Environment env = getEnvironmentFromObject(currentVal);
1364+
Environment env = getEnvironmentFromObject(this.interpreter.getEnvironment(), currentVal);
13651365
env.define('$current', currentVal);
13661366
Interpreter interpreter = new Interpreter(env);
13671367
Object result = interpreter.interpret(expr);
@@ -1475,7 +1475,7 @@ public with sharing class CollectionFunctions {
14751475
List<Object> listVal = (List<Object>) listObj;
14761476
for (Integer i = 0; i < listVal.size(); i++) {
14771477
Object currentVal = listVal.get(i);
1478-
Environment env = getEnvironmentFromObject(currentVal);
1478+
Environment env = getEnvironmentFromObject(this.interpreter.getEnvironment(), currentVal);
14791479
env.define('$current', currentVal);
14801480
Interpreter interpreter = new Interpreter(env);
14811481
Object result = interpreter.interpret(expr);
@@ -1629,7 +1629,7 @@ public with sharing class CollectionFunctions {
16291629
Object acc = null;
16301630
for (Integer i = 0; i < values.size(); i++) {
16311631
Object current = values.get(i);
1632-
Environment env = getEnvironmentFromObject(current);
1632+
Environment env = getEnvironmentFromObject(this.interpreter.getEnvironment(), current);
16331633

16341634
env.define('$current', current);
16351635
env.define('$key', key);
@@ -1676,7 +1676,7 @@ public with sharing class CollectionFunctions {
16761676
Expr expr = arguments.get(1);
16771677
Map<Object, Object> result = new Map<Object, Object>();
16781678
for (Object currentVal : listVal) {
1679-
Environment env = getEnvironmentFromObject(currentVal);
1679+
Environment env = getEnvironmentFromObject(this.interpreter.getEnvironment(), currentVal);
16801680
env.define('$current', currentVal);
16811681
Interpreter interpreter = new Interpreter(env);
16821682
Object key = interpreter.interpret(expr);
@@ -1719,7 +1719,7 @@ public with sharing class CollectionFunctions {
17191719
Expr expr = arguments.get(1);
17201720
Map<Object, List<Object>> result = new Map<Object, List<Object>>();
17211721
for (Object currentVal : listVal) {
1722-
Environment env = getEnvironmentFromObject(currentVal);
1722+
Environment env = getEnvironmentFromObject(this.interpreter.getEnvironment(), currentVal);
17231723
env.define('$current', currentVal);
17241724
Interpreter interpreter = new Interpreter(env);
17251725
Object key = interpreter.interpret(expr);

sfdx-project_packaging.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
{
44
"path": "expression-src",
55
"package": "Expression",
6-
"versionName": "Version 1.28",
7-
"versionNumber": "1.28.0.NEXT",
6+
"versionName": "Version 1.29",
7+
"versionNumber": "1.29.0.NEXT",
88
"default": false,
99
"versionDescription": "Expression core language",
1010
"ancestorVersion": "HIGHEST"
@@ -57,6 +57,7 @@
5757
"[email protected]": "04tRb0000034Z5VIAU",
5858
"[email protected]": "04tRb0000034ahVIAQ",
5959
"[email protected]": "04tRb0000034eMvIAI",
60-
"[email protected]": "04tRb0000036OFdIAM"
60+
"[email protected]": "04tRb0000036OFdIAM",
61+
"[email protected]": "04tRb0000036fbRIAQ"
6162
}
6263
}

0 commit comments

Comments
 (0)