Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 17 additions & 9 deletions packages/apidom-datamodel/src/primitives/Element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,10 @@ class Element implements ToValue, Equatable, Freezable {

/** Unique identifier for this element. */
get id(): Element {
return this.getMetaProperty('id', '');
if (!this.hasMetaProperty('id')) {
this.setMetaProperty('id', '');
}
return this.meta.get('id') as Element;
}

set id(value: Element | string) {
Expand All @@ -282,7 +285,10 @@ class Element implements ToValue, Equatable, Freezable {

/** CSS-like class names. */
get classes(): ArrayElement {
return this.getMetaProperty('classes', []) as ArrayElement;
if (!this.hasMetaProperty('classes')) {
this.setMetaProperty('classes', []);
}
return this.meta.get('classes') as ArrayElement;
}

set classes(value: ArrayElement | unknown[]) {
Expand All @@ -291,7 +297,10 @@ class Element implements ToValue, Equatable, Freezable {

/** Hyperlinks associated with this element. */
get links(): ArrayElement {
return this.getMetaProperty('links', []) as ArrayElement;
if (!this.hasMetaProperty('links')) {
this.setMetaProperty('links', []);
}
return this.meta.get('links') as ArrayElement;
}

set links(value: ArrayElement | unknown[]) {
Expand Down Expand Up @@ -451,16 +460,15 @@ class Element implements ToValue, Equatable, Freezable {
}

/**
* Gets a meta property, creating it with default value if not present.
* Gets a meta property, returning default value if not present.
*/
public getMetaProperty(name: string, defaultValue: unknown): Element {
if (!this.meta.hasKey(name)) {
if (this.isFrozen) {
const element = this.refract(defaultValue);
if (!this.hasMetaProperty(name)) {
const element = this.refract(defaultValue);
if (element && this.isFrozen) {
element.freeze();
return element;
}
this.meta.set(name, defaultValue);
return element;
}
return this.meta.get(name)!;
}
Comment on lines +481 to 495
Copy link

Copilot AI Feb 12, 2026

Choose a reason for hiding this comment

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

The overload getMetaProperty(name, defaultValue): Element is not guaranteed by the implementation: if the meta key exists with an explicit undefined value (possible via setMetaProperty/ObjectElement.set), this.meta.get(name) returns undefined, even when a defaultValue is provided. Either prevent storing undefined for meta properties, treat undefined values as “missing” when reading (so the default applies), or relax the overload return type to Element | undefined to match runtime behavior.

Copilot uses AI. Check for mistakes.
Expand Down
Loading