`AccessMember.evaluate` should always return `undefined` for non-existing members
- Dominant language
- JavaScript
- Stars
- 110
- Forks
- 98
- PR merge metrics
- No merged PRs in 30d
Description
**The Issue**
Current version of `aurelia-bindinig@2.5.5` resolves value of non-existing member of an object differently when the object is `null` vs `undefined` or non existant.
For example, binding expression `foo.bar` would resolve to `null` for:
```js
{ foo: null }
```
but would resolve to `undefined` for:
```js
{ foo: undefined }
```
and
```js
{}
```
while if `foo` is an empty object, binding expression `foo.bar` would correctly return `undefined`:
```js
{ foo: {} }
```
This unpredictability produces issue in some binding scenarios. For example:
```html
```
The culprit is this method:
https://github.com/aurelia/binding/blob/ed35588117f52508e628570921bc2361c3861cc7/src/ast.js#L251-L254
Instead of returning `instance`, it should return `undefined`:
```js
evaluate(scope, lookupFunctions) {
let instance = this.object.evaluate(scope, lookupFunctions);
return instance === null || instance === undefined ? undefined: instance[this.name];
}
```
**Expected behavior**
`foo.bar` binding expression should return `undefined` for all 4 cases:
```js
{ foo: null }
{ foo: undefined }
{ foo: {} }
{}
```
It would also be consistant with result of JavaScript optinal chaning syntax `this.foo?.bar`.
Contributor guide
Research direction
Start in src/ast.js at AccessMember.evaluate, the method identified as the culprit. Check how it evaluates foo.bar when foo is null, undefined, missing, or an empty object. Done means all four cases return undefined, consistently with optional chaining behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 68/100