Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
drew-y committed Sep 13, 2024
1 parent 25f2fe3 commit 0ebd273
Showing 1 changed file with 9 additions and 17 deletions.
26 changes: 9 additions & 17 deletions src/syntax-objects/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,23 @@ import { Float } from "./float.js";
import { getIdStr } from "./lib/get-id-str.js";
import { Id, Identifier } from "./identifier.js";
import { Int } from "./int.js";
import { NamedEntity } from "./named-entity.js";
import { Syntax, SyntaxMetadata } from "./syntax.js";
import { ChildList } from "./lib/child-list.js";

type ListOpts =
| ListValue[]
| (SyntaxMetadata & {
value?: ListValue[] | List;
isParentheticalList?: boolean;
});

export class List extends Syntax {
readonly syntaxType = "list";
/** True when the list was defined by the user using parenthesis i.e. (hey, there) */
mayBeTuple?: boolean;
#store = new ChildList(undefined, this);

constructor(
opts:
| ListValue[]
| (SyntaxMetadata & {
value?: ListValue[] | List;
isParentheticalList?: boolean;
})
) {
constructor(opts: ListOpts) {
opts = Array.isArray(opts) ? { value: opts } : opts;
super(opts);

Expand Down Expand Up @@ -83,7 +82,6 @@ export class List extends Syntax {

set(index: number, expr: Expr | string) {
const result = typeof expr === "string" ? Identifier.from(expr) : expr;
result.parent = this;
this.#store.set(index, result);
return this;
}
Expand Down Expand Up @@ -142,12 +140,6 @@ export class List extends Syntax {
return;
}

ex.parent = this;

if (ex instanceof NamedEntity) {
this.registerEntity(ex);
}

if (ex.isList() && ex.calls("splice_quote")) {
this.#store.push(...ex.argsArray());
return;
Expand Down Expand Up @@ -229,7 +221,7 @@ export class List extends Syntax {
clone(parent?: Expr): List {
return new List({
...super.getCloneOpts(parent),
value: this.toArray().map((v) => v.clone()),
value: this.#store.clone().toArray(),
isParentheticalList: this.mayBeTuple,
});
}
Expand Down

0 comments on commit 0ebd273

Please sign in to comment.