-
-
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.
This commit consistently fixes the interaction between keywords and lexical variables (JS or Handlebars) to match the specified behavior: keywords are **always** superseded by in-scope lexical variables. Ember keywords are implemented as AST transformations, and there were two sources of bugs that made implementation of these keywords inconsistent with the specified behavior: 1. In some cases, AST transforms applied to situations where the keyword in question was shadowed by a Handlebars block param. This means that the variable would be silently overridden by the AST transform. 2. In all cases, AST transforms applied when the keyword was shadowed by a lexical variable (i.e. in-scope JS variable) of the same name. This isn't supposed to happen, as lexical JS variables are supposed to have the same rules as variables bound via JS block params. This commit has tests for many of these cases. Some additional tests are forthcoming, mostly in cases where the transform in question wasn't tested at all before this change.
- Loading branch information
Showing
12 changed files
with
127 additions
and
63 deletions.
There are no files selected for viewing
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
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
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
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
42 changes: 42 additions & 0 deletions
42
packages/ember-template-compiler/tests/plugins/assert-array-test.js
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,42 @@ | ||
import { defineComponent, moduleFor, RenderingTestCase } from 'internal-test-helpers'; | ||
|
||
moduleFor( | ||
'ember-template-compiler: assert-array-test', | ||
class extends RenderingTestCase { | ||
['@test block param `array` is not transformed']() { | ||
// Intentionally double all of the values to verify that this | ||
// version of the `array` function is used. | ||
function customArray(...values) { | ||
return values.map((value) => value * 2); | ||
} | ||
|
||
let Root = defineComponent( | ||
{ customArray }, | ||
`{{#let customArray as |array|}}<ul>{{#each (array 1 2 3) as |item|}}<li>{{item}}</li>{{/each}}</ul>{{/let}}` | ||
); | ||
this.registerComponent('root', { ComponentClass: Root }); | ||
|
||
this.render('<Root />'); | ||
this.assertHTML('<ul><li>2</li><li>4</li><li>6</li></ul>'); | ||
this.assertStableRerender(); | ||
} | ||
|
||
['@test lexical scope `array` is not transformed']() { | ||
// Intentionally double all of the values to verify that this | ||
// version of the `array` function is used. | ||
function array(...values) { | ||
return values.map((value) => value * 2); | ||
} | ||
|
||
let Root = defineComponent( | ||
{ array }, | ||
`<ul>{{#each (array 1 2 3) as |item|}}<li>{{item}}</li>{{/each}}</ul>` | ||
); | ||
this.registerComponent('root', { ComponentClass: Root }); | ||
|
||
this.render('<Root />'); | ||
this.assertHTML('<ul><li>2</li><li>4</li><li>6</li></ul>'); | ||
this.assertStableRerender(); | ||
} | ||
} | ||
); |
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