handlebars-lang / handlebars-lang/handlebars.js
with helper should not change evaluation context if "as" operator is used
- Dominant language
- JavaScript
- Stars
- 18.7k
- Forks
- 2.1k
- PR merge metrics
- No merged PRs in 30d
Description
The with helper changes the evaluation context even when the "as" operator is used. This is not intuitive. The whole point of specifying "as" is to redirect the context to the specified variable *instead* of modifying "this". Under the current behavior, the context changes either way. And that means variables in the parent scope get masked or become invisible.
Handlebars version: 4.4.3
```js
{{#with city as |c|}}
{{#with c.location as |l|}}
{{city.name}} should equal {{c.name}}
{{/with}}
{{/with}}
```
Granted, there are some cases when the properties from the parent context are visible, but often they are not. It's just really confusing.
Contributor guide
Research direction
Start by reproducing the Handlebars 4.4.3 example using nested with helpers and an as alias. Trace the with helper's evaluation-context handling, then add a regression test showing that parent-scope variables remain visible when as is used; done when the example produces the expected names without changing the context.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- handlebars, javascript
- Domain
- web-dev
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100