From c83a6685f589f6a765685e9660745eee29572390 Mon Sep 17 00:00:00 2001 From: bekzod Date: Fri, 1 Dec 2017 19:47:56 +0500 Subject: [PATCH] removed `transform-input-on-to-onEvent` --- .../lib/plugins/index.js | 2 - .../plugins/transform-input-on-to-onEvent.js | 125 ------------------ .../tests/plugins/transform-input-on-test.js | 43 ------ .../ember-views/lib/mixins/text_support.js | 43 +----- 4 files changed, 2 insertions(+), 211 deletions(-) delete mode 100644 packages/ember-template-compiler/lib/plugins/transform-input-on-to-onEvent.js delete mode 100644 packages/ember-template-compiler/tests/plugins/transform-input-on-test.js diff --git a/packages/ember-template-compiler/lib/plugins/index.js b/packages/ember-template-compiler/lib/plugins/index.js index 9b009b383ee..7fbd84663e7 100644 --- a/packages/ember-template-compiler/lib/plugins/index.js +++ b/packages/ember-template-compiler/lib/plugins/index.js @@ -1,6 +1,5 @@ import TransformOldBindingSyntax from './transform-old-binding-syntax'; import TransformAngleBracketComponents from './transform-angle-bracket-components'; -import TransformInputOnToOnEvent from './transform-input-on-to-onEvent'; import TransformTopLevelComponents from './transform-top-level-components'; import TransformInlineLinkTo from './transform-inline-link-to'; import TransformOldClassBindingSyntax from './transform-old-class-binding-syntax'; @@ -24,7 +23,6 @@ const transforms = [ TransformDotComponentInvocation, TransformOldBindingSyntax, TransformAngleBracketComponents, - TransformInputOnToOnEvent, TransformTopLevelComponents, TransformInlineLinkTo, TransformOldClassBindingSyntax, diff --git a/packages/ember-template-compiler/lib/plugins/transform-input-on-to-onEvent.js b/packages/ember-template-compiler/lib/plugins/transform-input-on-to-onEvent.js deleted file mode 100644 index 23bb94cfaa4..00000000000 --- a/packages/ember-template-compiler/lib/plugins/transform-input-on-to-onEvent.js +++ /dev/null @@ -1,125 +0,0 @@ -import { deprecate } from 'ember-debug'; -import calculateLocationDisplay from '../system/calculate-location-display'; - -/** - @module ember -*/ - -/** - An HTMLBars AST transformation that replaces all instances of - - ```handlebars - {{input on="enter" action="doStuff"}} - {{input on="key-press" action="doStuff"}} - ``` - - with - - ```handlebars - {{input enter="doStuff"}} - {{input key-press="doStuff"}} - ``` - - @private - @class TransformInputOnToOnEvent -*/ -export default function transformInputOnToOnEvent(env) { - let b = env.syntax.builders; - let { moduleName } = env.meta; - - return { - name: 'transform-input-on-to-onEvent', - - visitors: { - MustacheStatement(node) { - if (node.path.original !== 'input') { - return; - } - - let action = hashPairForKey(node.hash, 'action'); - let on = hashPairForKey(node.hash, 'on'); - let onEvent = hashPairForKey(node.hash, 'onEvent'); - - if (!action && !on && !onEvent) { - return; - } - - - let normalizedOn = on || onEvent; - let moduleInfo = calculateLocationDisplay(moduleName, node.loc); - - if (normalizedOn && normalizedOn.value.type !== 'StringLiteral') { - deprecate( - `Using a dynamic value for '#{normalizedOn.key}=' with the '{{input}}' helper ${moduleInfo}is deprecated.`, - false, - { id: 'ember-template-compiler.transform-input-on-to-onEvent.dynamic-value', until: '3.0.0' } - ); - - normalizedOn.key = 'onEvent'; - return; // exit early, as we cannot transform further - } - - removeFromHash(node.hash, normalizedOn); - removeFromHash(node.hash, action); - - if (!action) { - deprecate( - `Using '{{input ${normalizedOn.key}="${normalizedOn.value.value}" ...}}' without specifying an action ${moduleInfo}will do nothing.`, - false, - { id: 'ember-template-compiler.transform-input-on-to-onEvent.no-action', until: '3.0.0' } - ); - - return; // exit early, if no action was available there is nothing to do - } - - - let specifiedOn = normalizedOn ? `${normalizedOn.key}="${normalizedOn.value.value}" ` : ''; - if (normalizedOn && normalizedOn.value.value === 'keyPress') { - // using `keyPress` in the root of the component will - // clobber the keyPress event handler - normalizedOn.value.value = 'key-press'; - } - - let expected = `${normalizedOn ? normalizedOn.value.value : 'enter'}="${action.value.original}"`; - - deprecate( - `Using '{{input ${specifiedOn}action="${action.value.original}"}}' ${moduleInfo}is deprecated. Please use '{{input ${expected}}}' instead.`, - false, - { id: 'ember-template-compiler.transform-input-on-to-onEvent.normalized-on', until: '3.0.0' } - ); - if (!normalizedOn) { - normalizedOn = b.pair('onEvent', b.string('enter')); - } - - node.hash.pairs.push(b.pair( - normalizedOn.value.value, - action.value - )); - } - } - }; -} - -function hashPairForKey(hash, key) { - for (let i = 0; i < hash.pairs.length; i++) { - let pair = hash.pairs[i]; - if (pair.key === key) { - return pair; - } - } - - return false; -} - -function removeFromHash(hash, pairToRemove) { - let newPairs = []; - for (let i = 0; i < hash.pairs.length; i++) { - let pair = hash.pairs[i]; - - if (pair !== pairToRemove) { - newPairs.push(pair); - } - } - - hash.pairs = newPairs; -} diff --git a/packages/ember-template-compiler/tests/plugins/transform-input-on-test.js b/packages/ember-template-compiler/tests/plugins/transform-input-on-test.js deleted file mode 100644 index 90225b59b3d..00000000000 --- a/packages/ember-template-compiler/tests/plugins/transform-input-on-test.js +++ /dev/null @@ -1,43 +0,0 @@ -import { compile } from '../../index'; - -QUnit.module('ember-template-compiler: transform-input-on'); - -QUnit.test('Using `action` without `on` provides a deprecation', function() { - expect(1); - - expectDeprecation(() => { - compile('{{input action="foo"}}', { - moduleName: 'foo/bar/baz' - }); - }, `Using '{{input action="foo"}}' ('foo/bar/baz' @ L1:C0) is deprecated. Please use '{{input enter="foo"}}' instead.`); -}); - -QUnit.test('Using `action` with `on` provides a deprecation', function() { - expect(1); - - expectDeprecation(() => { - compile('{{input on="focus-in" action="foo"}}', { - moduleName: 'foo/bar/baz' - }); - }, `Using '{{input on="focus-in" action="foo"}}' ('foo/bar/baz' @ L1:C0) is deprecated. Please use '{{input focus-in="foo"}}' instead.`); -}); - -QUnit.test('Using `on=\'keyPress\'` does not clobber `keyPress`', function() { - expect(1); - - expectDeprecation(() => { - compile('{{input on="keyPress" action="foo"}}', { - moduleName: 'foo/bar/baz' - }); - }, `Using '{{input on="keyPress" action="foo"}}' ('foo/bar/baz' @ L1:C0) is deprecated. Please use '{{input key-press="foo"}}' instead.`); -}); - -QUnit.test('Using `on=\'foo\'` without `action=\'asdf\'` raises specific deprecation', function() { - expect(1); - - expectDeprecation(() => { - compile('{{input on="asdf"}}', { - moduleName: 'foo/bar/baz' - }); - }, `Using '{{input on="asdf" ...}}' without specifying an action ('foo/bar/baz' @ L1:C0) will do nothing.`); -}); diff --git a/packages/ember-views/lib/mixins/text_support.js b/packages/ember-views/lib/mixins/text_support.js index 7a23824a75e..a15a0e8f5dd 100644 --- a/packages/ember-views/lib/mixins/text_support.js +++ b/packages/ember-views/lib/mixins/text_support.js @@ -142,35 +142,6 @@ export default Mixin.create(TargetActionSupport, { this.on('input', this, this._elementValueDidChange); }, - /** - The action to be sent when the user presses the return key. - - This is similar to the `{{action}}` helper, but is fired when - the user presses the return key when editing a text field, and sends - the value of the field as the context. - - @property action - @type String - @default null - @private - */ - action: null, - - /** - The event that should send the action. - - Options are: - - * `enter`: the user pressed enter - * `keyPress`: the user pressed a key - - @property onEvent - @type String - @default enter - @private - */ - onEvent: 'enter', - /** Whether the `keyUp` event that triggers an `action` to be sent continues propagating to other views. @@ -335,21 +306,11 @@ export default Mixin.create(TargetActionSupport, { // the component semantics so this method normalizes them. function sendAction(eventName, view, event) { let action = get(view, `attrs.${eventName}`) || get(view, eventName); - let on = get(view, 'onEvent'); let value = get(view, 'value'); - // back-compat support for keyPress as an event name even though - // it's also a method name that consumes the event (and therefore - // incompatible with sendAction semantics). - if (on === eventName || (on === 'keyPress' && eventName === 'key-press')) { - view.sendAction('action', value); - } - view.sendAction(eventName, value); - if (action || on === eventName) { - if (!get(view, 'bubbles')) { - event.stopPropagation(); - } + if (action && !get(view, 'bubbles')) { + event.stopPropagation(); } }