diff --git a/packages/ember-template-compiler/lib/plugins/deprecate-render.ts b/packages/ember-template-compiler/lib/plugins/deprecate-render.ts index 16313eae7e3..405bd52e8de 100644 --- a/packages/ember-template-compiler/lib/plugins/deprecate-render.ts +++ b/packages/ember-template-compiler/lib/plugins/deprecate-render.ts @@ -3,7 +3,6 @@ import { RENDER_HELPER } from '@ember/deprecated-features'; import { AST, ASTPlugin, ASTPluginEnvironment } from '@glimmer/syntax'; import calculateLocationDisplay from '../system/calculate-location-display'; -// Remove after 3.4 once _ENABLE_RENDER_SUPPORT flag is no longer needed. export default function deprecateRender(env: ASTPluginEnvironment): ASTPlugin | undefined { if (RENDER_HELPER) { let { moduleName } = env.meta; diff --git a/packages/ember-template-compiler/lib/plugins/deprecate-send-action.ts b/packages/ember-template-compiler/lib/plugins/deprecate-send-action.ts new file mode 100644 index 00000000000..df4fda721f9 --- /dev/null +++ b/packages/ember-template-compiler/lib/plugins/deprecate-send-action.ts @@ -0,0 +1,45 @@ +import { deprecate } from '@ember/debug'; +import { AST, ASTPlugin, ASTPluginEnvironment } from '@glimmer/syntax'; +import calculateLocationDisplay from '../system/calculate-location-display'; + +const EVENTS = [ + 'insert-newline', + 'enter', + 'escape-press', + 'focus-in', + 'focus-out', + 'key-press', + 'key-up', + 'key-down', +]; + +export default function deprecateRender(env: ASTPluginEnvironment): ASTPlugin | undefined { + let { moduleName } = env.meta; + + let deprecationMessage = (node: AST.MustacheStatement, eventName: string, actionName: string) => { + let sourceInformation = calculateLocationDisplay(moduleName, node.loc); + return `Please refactor \`{{input ${eventName}="${actionName}"}}\` to \`{{input ${eventName}=(action "${actionName}")}}\. ${sourceInformation}`; + }; + + return { + name: 'deprecate-send-action', + + visitor: { + MustacheStatement(node: AST.MustacheStatement) { + if (node.path.original !== 'input') { + return; + } + + node.hash.pairs.forEach(pair => { + if (EVENTS.indexOf(pair.key) > -1 && pair.value.type === 'StringLiteral') { + deprecate(deprecationMessage(node, pair.key, pair.value.original), false, { + id: 'ember-template-compiler.send-action', + until: '4.0.0', + url: 'SOME_URL', + }); + } + }); + }, + }, + }; +} diff --git a/packages/ember-template-compiler/lib/plugins/index.ts b/packages/ember-template-compiler/lib/plugins/index.ts index 3e0a59d63f7..3cb8dd09c02 100644 --- a/packages/ember-template-compiler/lib/plugins/index.ts +++ b/packages/ember-template-compiler/lib/plugins/index.ts @@ -4,6 +4,7 @@ import AssertReservedNamedArguments from './assert-reserved-named-arguments'; import AssertSplattributeExpressions from './assert-splattribute-expression'; import DeprecateRender from './deprecate-render'; import DeprecateRenderModel from './deprecate-render-model'; +import DeprecateSendAction from './deprecate-send-action'; import TransformActionSyntax from './transform-action-syntax'; import TransformAngleBracketComponents from './transform-angle-bracket-components'; import TransformAttrsIntoArgs from './transform-attrs-into-args'; @@ -40,6 +41,7 @@ const transforms: Array = [ TransformInElement, AssertIfHelperWithoutArguments, AssertSplattributeExpressions, + DeprecateSendAction ]; if (RENDER_HELPER) { diff --git a/packages/ember-template-compiler/tests/plugins/deprecate-send-action-test.js b/packages/ember-template-compiler/tests/plugins/deprecate-send-action-test.js new file mode 100644 index 00000000000..a5925fa41e0 --- /dev/null +++ b/packages/ember-template-compiler/tests/plugins/deprecate-send-action-test.js @@ -0,0 +1,29 @@ +import { compile } from '../../index'; +import { moduleFor, AbstractTestCase } from 'internal-test-helpers'; + +const EVENTS = [ + 'insert-newline', + 'enter', + 'escape-press', + 'focus-in', + 'focus-out', + 'key-press', + 'key-up', + 'key-down', +]; + +class DeprecateSendActionTest extends AbstractTestCase {} + +EVENTS.forEach(function(e) { + DeprecateSendActionTest.prototype[ + `@test Using \`{{input ${e}="actionName"}}\` provides a deprecation` + ] = function() { + let expectedMessage = `Please refactor \`{{input ${e}="foo-bar"}}\` to \`{{input ${e}=(action "foo-bar")}}\. ('baz/foo-bar' @ L1:C0) `; + + expectDeprecation(() => { + compile(`{{input ${e}="foo-bar"}}`, { moduleName: 'baz/foo-bar' }); + }, expectedMessage); + }; +}); + +moduleFor('ember-template-compiler: deprecate-send-action', DeprecateSendActionTest); diff --git a/packages/ember-views/lib/mixins/text_support.js b/packages/ember-views/lib/mixins/text_support.js index 99a5188ea59..188ed83b593 100644 --- a/packages/ember-views/lib/mixins/text_support.js +++ b/packages/ember-views/lib/mixins/text_support.js @@ -89,7 +89,7 @@ const KEY_EVENTS = { +--------------------+----------------+ | new line inserted | insert-newline | | | | - | enter key pressed | insert-newline | + | enter key pressed | enter | | | | | cancel key pressed | escape-press | | | |