From b12e116ffa01b115d6147d16163e932d46c7da8f Mon Sep 17 00:00:00 2001 From: Volodymyr Radchenko Date: Tue, 22 Sep 2020 00:36:55 +0300 Subject: [PATCH] [BUGFIX] args lost when passed to {{component}} Because iterator was not working as expected. `@` character was not applied to all of the @arg names in hash array, except for the first argument. It resulted in `[["@firstArg", "secondArg"], ["valOne", "valTwo"]]`, instead of `[["@firstArg", "@secondArg"], ["valOne", "valTwo"]]` Fixes emberjs/ember.js#19061 --- .../lib/suites/emberish-components.ts | 36 ++++++++++++------- .../lib/opcode-builder/helpers/components.ts | 4 +-- 2 files changed, 26 insertions(+), 14 deletions(-) diff --git a/packages/@glimmer/integration-tests/lib/suites/emberish-components.ts b/packages/@glimmer/integration-tests/lib/suites/emberish-components.ts index 195eaaac8..03c2593be 100644 --- a/packages/@glimmer/integration-tests/lib/suites/emberish-components.ts +++ b/packages/@glimmer/integration-tests/lib/suites/emberish-components.ts @@ -50,25 +50,37 @@ export class EmberishComponentTests extends RenderTest { @test({ kind: 'glimmer' }) 'Static block component helper'() { - this.registerComponent('Glimmer', 'A', 'A {{#component "B" arg1=@one}}{{/component}}'); - this.registerComponent('Glimmer', 'B', 'B {{@arg1}}'); - this.render('', { arg: 1 }); - this.assertHTML('A B 1'); + this.registerComponent( + 'Glimmer', + 'A', + 'A {{#component "B" arg1=@one arg2=@two arg3=@three}}{{/component}}' + ); + this.registerComponent('Glimmer', 'B', 'B {{@arg1}} {{@arg2}} {{@arg3}}'); + this.render('', { + first: 1, + second: 2, + third: 3, + }); + this.assertHTML('A B 1 2 3'); this.assertStableRerender(); - this.rerender({ arg: 2 }); - this.assertHTML('A B 2'); + this.rerender({ first: 2, second: 3, third: 4 }); + this.assertHTML('A B 2 3 4'); this.assertStableNodes(); } @test({ kind: 'glimmer' }) 'Static inline component helper'() { - this.registerComponent('Glimmer', 'A', 'A {{component "B" arg1=@one}}'); - this.registerComponent('Glimmer', 'B', 'B {{@arg1}}'); - this.render('', { arg: 1 }); - this.assertHTML('A B 1'); + this.registerComponent('Glimmer', 'A', 'A {{component "B" arg1=@one arg2=@two arg3=@three}}'); + this.registerComponent('Glimmer', 'B', 'B {{@arg1}} {{@arg2}} {{@arg3}}'); + this.render('', { + first: 1, + second: 2, + third: 3, + }); + this.assertHTML('A B 1 2 3'); this.assertStableRerender(); - this.rerender({ arg: 2 }); - this.assertHTML('A B 2'); + this.rerender({ first: 2, second: 3, third: 4 }); + this.assertHTML('A B 2 3 4'); this.assertStableNodes(); } diff --git a/packages/@glimmer/opcode-compiler/lib/opcode-builder/helpers/components.ts b/packages/@glimmer/opcode-compiler/lib/opcode-builder/helpers/components.ts index c51b41975..7d78a9369 100644 --- a/packages/@glimmer/opcode-compiler/lib/opcode-builder/helpers/components.ts +++ b/packages/@glimmer/opcode-compiler/lib/opcode-builder/helpers/components.ts @@ -95,8 +95,8 @@ export function StaticComponentHelper( if (compilable) { if (hash) { - for (let i = 0; i < hash.length; i = i + 2) { - hash[i][0] = `@${hash[i][0]}`; + for (let i = 0; i < hash[0].length; i = i + 1) { + hash[0][i] = `@${hash[0][i]}`; } }