Skip to content

Commit 492e486

Browse files
openorclosemartin-henz
authored andcommitted
Fix let (requires prelude to be merged first) (BREAKING CHANGE) (#321)
* Add prelude, that predeclares Source-implementable functions List and stream functions that can be implemented in Source now are put in the prelude, and are no longer native JS functions. * Update tests * Add tests for stream * Add tests for stream * Add tests for stream * Fix bug where mutating variables in a outer scope didn't work properly * Make mutating let variables in outer scopes propagate properly * Order imports * Remove redundant assigning for constant * Revert yarn.lock * Remove inconsistent snapshot * Add check for undefined variables too * Update tests
1 parent 8739509 commit 492e486

28 files changed

+23673
-3557
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
node_modules
22
*.js
3+
!*.prelude.js
34
*.map
45
dist/
56

src/__tests__/__snapshots__/allowed-syntax.ts.snap

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3181,7 +3181,10 @@ let lastStatementResult = undefined;
31813181
lastStatementResult = eval(\\"i;\\");
31823182
native.globals.variables.set(\\"i\\", {
31833183
kind: \\"let\\",
3184-
value: i
3184+
value: i,
3185+
assignNewValue: function (unique) {
3186+
return i = this.value = unique;
3187+
}
31853188
});
31863189
native.globals.variables.set(\\"startTime\\", {
31873190
kind: \\"const\\",
@@ -3899,7 +3902,10 @@ let lastStatementResult = undefined;
38993902
lastStatementResult = eval(\\"i;\\");
39003903
native.globals.variables.set(\\"i\\", {
39013904
kind: \\"let\\",
3902-
value: i
3905+
value: i,
3906+
assignNewValue: function (unique) {
3907+
return i = this.value = unique;
3908+
}
39033909
});
39043910
native.globals.variables.set(\\"startTime\\", {
39053911
kind: \\"const\\",
@@ -5356,7 +5362,10 @@ let lastStatementResult = undefined;
53565362
lastStatementResult = eval(\\"i;\\");
53575363
native.globals.variables.set(\\"i\\", {
53585364
kind: \\"let\\",
5359-
value: i
5365+
value: i,
5366+
assignNewValue: function (unique) {
5367+
return i = this.value = unique;
5368+
}
53605369
});
53615370
native.globals.variables.set(\\"startTime\\", {
53625371
kind: \\"const\\",
@@ -6325,7 +6334,10 @@ let lastStatementResult = undefined;
63256334
lastStatementResult = eval(\\"getProp(x, 1, 2, 0);\\");
63266335
native.globals.variables.set(\\"x\\", {
63276336
kind: \\"let\\",
6328-
value: x
6337+
value: x,
6338+
assignNewValue: function (unique) {
6339+
return x = this.value = unique;
6340+
}
63296341
});
63306342
}
63316343
}
@@ -6818,7 +6830,10 @@ let lastStatementResult = undefined;
68186830
lastStatementResult = eval(\\"setProp(x, 1, 4, 2, 0);\\");
68196831
native.globals.variables.set(\\"x\\", {
68206832
kind: \\"let\\",
6821-
value: x
6833+
value: x,
6834+
assignNewValue: function (unique) {
6835+
return x = this.value = unique;
6836+
}
68226837
});
68236838
}
68246839
}

src/__tests__/__snapshots__/environment.ts.snap

Lines changed: 11 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -55,33 +55,22 @@ Array [
5555
"head": Object {
5656
"Infinity": Infinity,
5757
"NaN": NaN,
58-
"accumulate": [Function],
59-
"append": [Function],
6058
"apply_in_underlying_javascript": [Function],
6159
"array_length": [Function],
62-
"build_list": [Function],
6360
"display": [Function],
6461
"draw_data": [Function],
65-
"enum_list": [Function],
66-
"equal": [Function],
6762
"error": [Function],
68-
"filter": [Function],
69-
"for_each": [Function],
7063
"head": [Function],
7164
"is_array": [Function],
7265
"is_boolean": [Function],
7366
"is_function": [Function],
74-
"is_list": [Function],
7567
"is_null": [Function],
7668
"is_number": [Function],
7769
"is_pair": [Function],
7870
"is_string": [Function],
7971
"is_undefined": [Function],
80-
"length": [Function],
8172
"list": [Function],
82-
"list_ref": [Function],
83-
"list_to_string": [Function],
84-
"map": [Function],
73+
"list_to_stream": [Function],
8574
"math_E": 2.718281828459045,
8675
"math_LN10": 2.302585092994046,
8776
"math_LN2": 0.6931471805599453,
@@ -125,18 +114,16 @@ Array [
125114
"math_tan": [Function],
126115
"math_tanh": [Function],
127116
"math_trunc": [Function],
128-
"member": [Function],
129117
"pair": [Function],
130118
"parse": [Function],
131119
"parse_int": [Function],
132120
"prompt": [Function],
133121
"raw_display": [Function],
134-
"remove": [Function],
135-
"remove_all": [Function],
136-
"reverse": [Function],
137122
"runtime": [Function],
138123
"set_head": [Function],
139124
"set_tail": [Function],
125+
"stream": [Function],
126+
"stream_tail": [Function],
140127
"stringify": [Function],
141128
"tail": [Function],
142129
"undefined": undefined,
@@ -162,6 +149,7 @@ Array [
162149
"externalContext": undefined,
163150
"externalSymbols": Array [],
164151
"numberOfOuterEnvironments": 2,
152+
"prelude": null,
165153
"runtime": Object {
166154
"break": false,
167155
"debuggerOn": true,
@@ -547,33 +535,22 @@ Array [
547535
"head": Object {
548536
"Infinity": Infinity,
549537
"NaN": NaN,
550-
"accumulate": [Function],
551-
"append": [Function],
552538
"apply_in_underlying_javascript": [Function],
553539
"array_length": [Function],
554-
"build_list": [Function],
555540
"display": [Function],
556541
"draw_data": [Function],
557-
"enum_list": [Function],
558-
"equal": [Function],
559542
"error": [Function],
560-
"filter": [Function],
561-
"for_each": [Function],
562543
"head": [Function],
563544
"is_array": [Function],
564545
"is_boolean": [Function],
565546
"is_function": [Function],
566-
"is_list": [Function],
567547
"is_null": [Function],
568548
"is_number": [Function],
569549
"is_pair": [Function],
570550
"is_string": [Function],
571551
"is_undefined": [Function],
572-
"length": [Function],
573552
"list": [Function],
574-
"list_ref": [Function],
575-
"list_to_string": [Function],
576-
"map": [Function],
553+
"list_to_stream": [Function],
577554
"math_E": 2.718281828459045,
578555
"math_LN10": 2.302585092994046,
579556
"math_LN2": 0.6931471805599453,
@@ -617,18 +594,16 @@ Array [
617594
"math_tan": [Function],
618595
"math_tanh": [Function],
619596
"math_trunc": [Function],
620-
"member": [Function],
621597
"pair": [Function],
622598
"parse": [Function],
623599
"parse_int": [Function],
624600
"prompt": [Function],
625601
"raw_display": [Function],
626-
"remove": [Function],
627-
"remove_all": [Function],
628-
"reverse": [Function],
629602
"runtime": [Function],
630603
"set_head": [Function],
631604
"set_tail": [Function],
605+
"stream": [Function],
606+
"stream_tail": [Function],
632607
"stringify": [Function],
633608
"tail": [Function],
634609
"undefined": undefined,
@@ -654,6 +629,7 @@ Array [
654629
"externalContext": undefined,
655630
"externalSymbols": Array [],
656631
"numberOfOuterEnvironments": 2,
632+
"prelude": null,
657633
"runtime": Object {
658634
"break": false,
659635
"debuggerOn": true,
@@ -1032,33 +1008,22 @@ Array [
10321008
"head": Object {
10331009
"Infinity": Infinity,
10341010
"NaN": NaN,
1035-
"accumulate": [Function],
1036-
"append": [Function],
10371011
"apply_in_underlying_javascript": [Function],
10381012
"array_length": [Function],
1039-
"build_list": [Function],
10401013
"display": [Function],
10411014
"draw_data": [Function],
1042-
"enum_list": [Function],
1043-
"equal": [Function],
10441015
"error": [Function],
1045-
"filter": [Function],
1046-
"for_each": [Function],
10471016
"head": [Function],
10481017
"is_array": [Function],
10491018
"is_boolean": [Function],
10501019
"is_function": [Function],
1051-
"is_list": [Function],
10521020
"is_null": [Function],
10531021
"is_number": [Function],
10541022
"is_pair": [Function],
10551023
"is_string": [Function],
10561024
"is_undefined": [Function],
1057-
"length": [Function],
10581025
"list": [Function],
1059-
"list_ref": [Function],
1060-
"list_to_string": [Function],
1061-
"map": [Function],
1026+
"list_to_stream": [Function],
10621027
"math_E": 2.718281828459045,
10631028
"math_LN10": 2.302585092994046,
10641029
"math_LN2": 0.6931471805599453,
@@ -1102,18 +1067,16 @@ Array [
11021067
"math_tan": [Function],
11031068
"math_tanh": [Function],
11041069
"math_trunc": [Function],
1105-
"member": [Function],
11061070
"pair": [Function],
11071071
"parse": [Function],
11081072
"parse_int": [Function],
11091073
"prompt": [Function],
11101074
"raw_display": [Function],
1111-
"remove": [Function],
1112-
"remove_all": [Function],
1113-
"reverse": [Function],
11141075
"runtime": [Function],
11151076
"set_head": [Function],
11161077
"set_tail": [Function],
1078+
"stream": [Function],
1079+
"stream_tail": [Function],
11171080
"stringify": [Function],
11181081
"tail": [Function],
11191082
"undefined": undefined,

src/__tests__/__snapshots__/index.ts.snap

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -878,11 +878,11 @@ Object {
878878
"code": "function f(x) {
879879
return 5;
880880
}
881-
toString(a=>b) + toString(f);",
881+
toString(a=>a) + toString(f);",
882882
"displayResult": Array [],
883883
"errors": Array [],
884884
"parsedErrors": "",
885-
"result": "a => bfunction f(x) {
885+
"result": "a => afunction f(x) {
886886
return 5;
887887
}",
888888
"resultStatus": "finished",
@@ -906,7 +906,7 @@ let lastStatementResult = undefined;
906906
value: 5
907907
};
908908
}, \\"function f(x) {\\\\n return 5;\\\\n}\\");
909-
lastStatementResult = eval(\\"binaryOp(\\\\\\"+\\\\\\", callIfFuncAndRightArgs(toString, 4, 0, wrap(a => ({ isTail: false, value: b }), \\\\\\"a => b\\\\\\")), callIfFuncAndRightArgs(toString, 4, 17, f), 4, 0);\\");
909+
lastStatementResult = eval(\\"binaryOp(\\\\\\"+\\\\\\", callIfFuncAndRightArgs(toString, 4, 0, wrap(a => ({ isTail: false, value: a }), \\\\\\"a => a\\\\\\")), callIfFuncAndRightArgs(toString, 4, 17, f), 4, 0);\\");
910910
native.globals.variables.set(\\"f\\", {
911911
kind: \\"const\\",
912912
value: f

0 commit comments

Comments
 (0)