Skip to content

Commit f6c483f

Browse files
committed
fix: address CRCs
1 parent 38b23fb commit f6c483f

File tree

1 file changed

+23
-2
lines changed
  • packages/apidom-datamodel/src/primitives

1 file changed

+23
-2
lines changed

packages/apidom-datamodel/src/primitives/Element.ts

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,9 @@ class Element implements ToValue, Equatable, Freezable {
273273

274274
/** Unique identifier for this element. */
275275
get id(): Element {
276+
if (this.isFrozen) {
277+
return this.getMetaProperty('id', '') as Element;
278+
}
276279
if (!this.hasMetaProperty('id')) {
277280
this.setMetaProperty('id', '');
278281
}
@@ -285,6 +288,9 @@ class Element implements ToValue, Equatable, Freezable {
285288

286289
/** CSS-like class names. */
287290
get classes(): ArrayElement {
291+
if (this.isFrozen) {
292+
return this.getMetaProperty('classes', []) as ArrayElement;
293+
}
288294
if (!this.hasMetaProperty('classes')) {
289295
this.setMetaProperty('classes', []);
290296
}
@@ -297,6 +303,9 @@ class Element implements ToValue, Equatable, Freezable {
297303

298304
/** Hyperlinks associated with this element. */
299305
get links(): ArrayElement {
306+
if (this.isFrozen) {
307+
return this.getMetaProperty('links', []) as ArrayElement;
308+
}
300309
if (!this.hasMetaProperty('links')) {
301310
this.setMetaProperty('links', []);
302311
}
@@ -460,10 +469,22 @@ class Element implements ToValue, Equatable, Freezable {
460469
}
461470

462471
/**
463-
* Gets a meta property, returning default value if not present.
472+
* Gets a meta property.
473+
*
474+
* When the property doesn't exist:
475+
* - With defaultValue: returns a new refracted element instance (not cached)
476+
* - Without defaultValue: returns undefined
477+
*
478+
* Note: Each call with a default creates a new instance. Use setMetaProperty
479+
* first if you need reference equality across multiple accesses.
464480
*/
465-
public getMetaProperty(name: string, defaultValue: unknown): Element {
481+
public getMetaProperty(name: string, defaultValue: unknown): Element;
482+
public getMetaProperty(name: string): Element | undefined;
483+
public getMetaProperty(name: string, defaultValue?: unknown): Element | undefined {
466484
if (!this.hasMetaProperty(name)) {
485+
if (defaultValue === undefined) {
486+
return undefined;
487+
}
467488
const element = this.refract(defaultValue);
468489
if (element && this.isFrozen) {
469490
element.freeze();

0 commit comments

Comments
 (0)