Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Evaluate also getter from classes #177

Open
Labels
@WebDucer

Description

Could be related to #174

Motivation

Currently the getter from classes, that encapsulate fields, are not "visible" to the library, so it is not possible to get a value from getter property. Becase getter are "seen" from developer as readonly fields, the library should at least also be able to "read" them.

Current behavior

getter are ignored

Desired behavior

The getters should be evaluated exactly the same as pure fields in classes.

Code example

import { JSONPath } from 'jsonpath-plus';
class TestData {
 #value;
 
 constructor(value) {
 this.#value = value;
 }
 get value() {
 return this.#value;
 }
 toJSON() {
 return { jsonValue: this.value };
 }
 someValue = 33;
}
const data = new TestData(11);
console.log(data); // TestData {someValue: 33}
console.log(data.value); // 11
console.log(data['value']); // 11
console.log(JSON.stringify(data)); // {"jsonValue":11}
const val = JSONPath({ path: '$.value', json: data });
const val1 = JSONPath({ path: '$.jsonValue', json: data });
const val2 = JSONPath({ path: '$.#value', json: data });
const val3 = JSONPath({ path: '$.someValue', json: data });
console.log(val); // [] - expected [11]
console.log(val1); // []
console.log(val2); // []
console.log(val3); // [33]
console.log(Object.prototype.hasOwnProperty.call(data, 'value')); // false
console.log('value' in data); // true

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

        AltStyle によって変換されたページ (->オリジナル) /