From 817b913cc6f037175638fab51f991b3a8b9cc6dc Mon Sep 17 00:00:00 2001 From: Jason Williams Date: Tue, 27 Dec 2016 22:05:00 -0600 Subject: [PATCH 1/2] [BUGFIX release] Compile input type sexprs - Allow {{input}} with a SubExpression type (e.g., {{input type=(if true 'password' 'text')}}) to be compiled. --- .../plugins/transform-input-type-syntax.js | 4 +++- .../transform-input-type-syntax-test.js | 21 +++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 packages/ember-template-compiler/tests/plugins/transform-input-type-syntax-test.js diff --git a/packages/ember-template-compiler/lib/plugins/transform-input-type-syntax.js b/packages/ember-template-compiler/lib/plugins/transform-input-type-syntax.js index 5292846a65e..1705551666c 100644 --- a/packages/ember-template-compiler/lib/plugins/transform-input-type-syntax.js +++ b/packages/ember-template-compiler/lib/plugins/transform-input-type-syntax.js @@ -62,6 +62,8 @@ function insertTypeHelperParameter(node, builders) { } } if (pair && pair.value.type !== 'StringLiteral') { - node.params.unshift(builders.sexpr('-input-type', [builders.path(pair.value.original, pair.loc)], null, pair.loc)); + let path = pair.value.path ? pair.value.path.original : pair.value.original; + + node.params.unshift(builders.sexpr('-input-type', [builders.path(path, pair.loc)], null, pair.loc)); } } diff --git a/packages/ember-template-compiler/tests/plugins/transform-input-type-syntax-test.js b/packages/ember-template-compiler/tests/plugins/transform-input-type-syntax-test.js new file mode 100644 index 00000000000..c07802bb209 --- /dev/null +++ b/packages/ember-template-compiler/tests/plugins/transform-input-type-syntax-test.js @@ -0,0 +1,21 @@ +import { compile } from '../../index'; + +QUnit.module('ember-template-compiler: input type syntax'); + +QUnit.test('Can compile an {{input}} helper that has a sub-expression value as its type', function() { + expect(0); + + compile(`{{input type=(if true 'password' 'text')}}`); +}); + +QUnit.test('Can compile an {{input}} helper with a string literal type', function() { + expect(0); + + compile(`{{input type='text'}}`); +}); + +QUnit.test('Can compile an {{input}} helper with a type stored in a var', function() { + expect(0); + + compile(`{{input type=_type}}`); +}); From 771cbecf6441767908f5e833620897cabdab4058 Mon Sep 17 00:00:00 2001 From: Robert Jackson Date: Mon, 23 Jan 2017 16:01:13 -0500 Subject: [PATCH 2/2] [BUGFIX beta] Allow any expression for `{{input type=***}}`. --- .../tests/integration/helpers/input-test.js | 21 +++++++++++++++++++ .../plugins/transform-input-type-syntax.js | 4 +--- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/packages/ember-glimmer/tests/integration/helpers/input-test.js b/packages/ember-glimmer/tests/integration/helpers/input-test.js index 10f5dcf07ba..b21d1b542ca 100644 --- a/packages/ember-glimmer/tests/integration/helpers/input-test.js +++ b/packages/ember-glimmer/tests/integration/helpers/input-test.js @@ -436,6 +436,27 @@ moduleFor('Helpers test: {{input}} with dynamic type', class extends InputRender this.assertAttr('type', 'password'); } + ['@test a subexpression can be used to determine type']() { + this.render(`{{input type=(if isTruthy trueType falseType)}}`, { + isTruthy: true, + trueType: 'text', + falseType: 'password' + }); + + this.assertAttr('type', 'text'); + + this.runTask(() => this.rerender()); + + this.assertAttr('type', 'text'); + + this.runTask(() => set(this.context, 'isTruthy', false)); + + this.assertAttr('type', 'password'); + + this.runTask(() => set(this.context, 'isTruthy', true)); + + this.assertAttr('type', 'text'); + } }); moduleFor(`Helpers test: {{input type='checkbox'}}`, class extends InputRenderingTest { diff --git a/packages/ember-template-compiler/lib/plugins/transform-input-type-syntax.js b/packages/ember-template-compiler/lib/plugins/transform-input-type-syntax.js index 1705551666c..8085dea48a5 100644 --- a/packages/ember-template-compiler/lib/plugins/transform-input-type-syntax.js +++ b/packages/ember-template-compiler/lib/plugins/transform-input-type-syntax.js @@ -62,8 +62,6 @@ function insertTypeHelperParameter(node, builders) { } } if (pair && pair.value.type !== 'StringLiteral') { - let path = pair.value.path ? pair.value.path.original : pair.value.original; - - node.params.unshift(builders.sexpr('-input-type', [builders.path(path, pair.loc)], null, pair.loc)); + node.params.unshift(builders.sexpr('-input-type', [pair.value], null, pair.loc)); } }