Skip to content

Conversation

@JoshdRod
Copy link
Owner

Previously, nodes in the expression tree had no defined structure. Hence, it was hard to tell what a node needed, and what the correct syntax was for that property.
The standard Node class contains properties:
NON-COMPUTED:

  • type (*)
  • content (*)
  • leftNode
  • rightNode
  • parent
    COMPUTED:
  • commutative
  • precedence

All website functions now interact with nodes using instances of this Node object.

(*) - properties type and content (when dealing with operators) have enums that define the values they can take.

Node class contains properties:
- type
- content
- leftNode
- rightNode
- parent
- commutative
- precedence
Previously, expressionToComponentList wasn't able to use the new Node class, for a few reasons:
- The Node class needs to be defined before it is accessed (see the Temporal Dead Zone https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let#temporal_dead_zone_tdz)
- Move Node class to a new file
- Add private type and content properties, which are accessed by the Node getter and setters
- Change node type references to the enum, instead of string
- Fix spelling errors
- Change references to node type to reference the enum
- Change references to node type to reference the enum
- Replace references to string literals in the function to use the NodeType and Operator enums
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request refactors the expression tree implementation to use a standardized Node class structure. Previously, nodes were created as plain JavaScript objects with inconsistent properties. The new implementation introduces enum-like classes (Operator and NodeType) and a Node class with defined properties and computed getters.

Changes:

  • Introduces new Node, Operator, and NodeType classes to standardize node representation
  • Refactors all node creation and type checking throughout the codebase to use the new standardized objects
  • Removes manual property assignment for precedence and commutativity in favor of computed getters

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 10 comments.

File Description
pages/index/tree.js New file containing Operator, NodeType, and Node class definitions with enum-like patterns and computed properties
pages/index/script.js Updates all node creation and type checking to use the new Node class and enum values instead of plain objects and string literals
index.html Adds script tag to include the new tree.js file before script.js

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@JoshdRod
Copy link
Owner Author

Adding some documentation as to what each property means would be beneficial.

Copy link

Copilot AI commented Jan 30, 2026

@JoshdRod I've opened a new pull request, #30, to work on those changes. Once the pull request is ready, I'll request review from you.

JoshdRod and others added 3 commits January 30, 2026 21:02
Returning in a switch-case statement terminates the statement. Hence, a break after the return is just dead code, and unneeded.
Previously, a missing break caused the setting of content for any Operator Node to fall into the function case.
e.g: This would set its content as '+', instead of OPERATOR.ADDITION.
Currently, these two things are the same thing, but this could deviate in the future.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copy link

Copilot AI commented Feb 1, 2026

@JoshdRod I've opened a new pull request, #31, to work on those changes. Once the pull request is ready, I'll request review from you.

Error objects return their stack trace, unlike a raw string.
@JoshdRod JoshdRod merged commit 691bc5f into main Feb 1, 2026
@JoshdRod JoshdRod deleted the refactor-node branch February 1, 2026 14:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants