-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[BUGFIX beta] Local variables should win over helpers
```hbs {{#let this.foo as |foo|}} {{foo 1 2 3}} ~~~ local variable invocation! {{/let}} ``` Previously, this would have tried to resolve and invoke the helper `foo`, ignoring the presence of the `foo` local variable. This is inconsistent with our general lexical lookup rules. This will now invoke `foo` local variable as a contextual component. In other words, this removes the remaining "dot rule" exceptions for contextual components, as per [RFC #311](https://github.com/emberjs/rfcs/blob/master/text/0311-angle-bracket-invocation.md): > We propose to relax that rule to match the proposed angle bracket > invocation semantics (i.e. allowing local variables without a dot, as > well as `@names`, but disallowing implicit `this` lookup). This commit also fixed another related issue: ```hbs {{#let (hash foo="foo-bar") as |h|}} {{h.foo 1 2 3}} ~~~~~ this is a string, not a component! {{/let}} ``` Previously, this would have tried to resolve and invoke the `foo-bar` component. This is an unintended consequence (i.e. a bug) of the "dot rule" implementation. This will now raise a `TypeError` in development mode and result in undefined behavior in production builds (probably some other runtime error deep inside the Glimmer VM internals). Fixes #17121.
- Loading branch information
1 parent
333a67e
commit fa163cc
Showing
7 changed files
with
387 additions
and
108 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
packages/@ember/-internals/glimmer/lib/helpers/-assert-implicit-component-helper-argument.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { DEBUG } from '@glimmer/env'; | ||
import { Opaque } from '@glimmer/interfaces'; | ||
import { Tag, VersionedPathReference } from '@glimmer/reference'; | ||
import { Arguments, Helper, VM } from '@glimmer/runtime'; | ||
import { Maybe } from '@glimmer/util'; | ||
|
||
let helper: Maybe<Helper> = undefined; | ||
|
||
if (DEBUG) { | ||
class ComponentAssertionReference implements VersionedPathReference<Opaque> { | ||
public tag: Tag; | ||
|
||
constructor(private component: VersionedPathReference<Opaque>, private message: string) { | ||
this.tag = component.tag; | ||
} | ||
|
||
value(): Opaque { | ||
let value = this.component.value(); | ||
|
||
if (typeof value === 'string') { | ||
throw new TypeError(this.message); | ||
} | ||
|
||
return value; | ||
} | ||
|
||
get(property: string): VersionedPathReference<Opaque> { | ||
return this.component.get(property); | ||
} | ||
} | ||
|
||
helper = (_vm: VM, args: Arguments) => | ||
new ComponentAssertionReference(args.positional.at(0), args.positional.at(1).value() as string); | ||
} | ||
|
||
export default helper; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.