Skip to content

Commit

Permalink
Fixed MBX AssignmentExpr
Browse files Browse the repository at this point in the history
  • Loading branch information
rhpo committed Jan 27, 2024
1 parent ab573a4 commit 175aed2
Showing 1 changed file with 10 additions and 30 deletions.
40 changes: 10 additions & 30 deletions src/lib/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,38 +93,18 @@ export default class Environment {
if (properties) {
let lastone: RuntimeValue = mainObj as RuntimeValue;

let i = 0;

name.properties.forEach((prop, idx) => {
// make a code that changes 'lastone' into the property 'prop', until reaching the last one...

if (lastone && lastone.type !== "undef") {
if (lastone.properties && lastone.properties.has(prop.value)) {
lastone = lastone.properties.get(prop.value) || MK.undefined();
} else if (
lastone.prototypes &&
lastone.prototypes[prop.value] !== undefined
) {
lastone = lastone.prototypes[prop.value];
} else {
if (idx !== (name as MemberExprX).properties.length - 1) {
lastone = MK.undefined();
}
}
for (let i = 0; i < name.properties.length - 1; i++) {
let prop = name.properties[i].value;

if (lastone.properties?.has(prop)) {
lastone = lastone.properties.get(prop) as RuntimeValue;
} else {
throw Err(
"NameError",
`Cannot read properties of an undefined value, READING: ${
[(name as MemberExprX).parent]
.concat((name as MemberExprX).properties)
.slice(0, i + 2)
.map((i) => i.value)
.join(" → ".green).white
}`
);
let obj = MK.object({});

lastone.properties?.set(prop, obj);
lastone = obj;
}
i++;
});
}

lastone.properties?.set(
name.properties[name.properties.length - 1].value,
Expand Down

0 comments on commit 175aed2

Please sign in to comment.