Skip to content

Commit 8c0536f

Browse files
committed
Assign let statement after const with same name
1 parent 399ae4b commit 8c0536f

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

src/nuc/LET.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@ class LET {
99
run(scope) {
1010
const name = this.name;
1111

12-
const instance = scope.retrieveGraph(this.name.first);
12+
if (this.reassign) {
13+
const instance = scope.retrieveGraph(this.name.first);
1314

14-
if (instance?.constant) {
15-
throw TypeError("Assignment to constant variable.");
15+
if (instance?.constant) {
16+
throw TypeError("Assignment to constant variable.");
17+
}
1618
}
1719

1820
const evaluation = this.value.run(scope, false, false);

src/test/nucleoid.spec.js

+19
Original file line numberDiff line numberDiff line change
@@ -1117,6 +1117,25 @@ describe("Nucleoid", () => {
11171117
equal(nucleoid.run("trade1.worth"), 100);
11181118
});
11191119

1120+
it("assigns let statement after const statement with the same name", () => {
1121+
const result = nucleoid.run(
1122+
`
1123+
const barcode = "barcode";
1124+
{
1125+
let barcode = "barcode";
1126+
{
1127+
barcode = "barcode2";
1128+
{
1129+
return barcode;
1130+
}
1131+
}
1132+
}
1133+
`
1134+
);
1135+
1136+
equal(result, "barcode2");
1137+
});
1138+
11201139
it("holds result of function in let", () => {
11211140
nucleoid.run("bugs = [ ]");
11221141
nucleoid.run("ticket = 1");

0 commit comments

Comments
 (0)