Skip to content

Commit

Permalink
Add tests for AST-based deprecation
Browse files Browse the repository at this point in the history
AST deprecation not implemented yet.
  • Loading branch information
Miguel Camba committed Jun 14, 2018
1 parent 53d8e36 commit 1d5687a
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 1 deletion.
@@ -0,0 +1,46 @@
import { deprecate } from '@ember/debug';
import { AST, ASTPlugin, ASTPluginEnvironment } from '@glimmer/syntax';
import calculateLocationDisplay from '../system/calculate-location-display';

export default function deprecateRender(env: ASTPluginEnvironment): ASTPlugin | undefined {
// let { moduleName } = env.meta;

// let deprecationMessage = (node: AST.MustacheStatement) => {
// let sourceInformation = calculateLocationDisplay(moduleName, node.loc);
// let componentName = (node.params[0] as AST.PathExpression).original;
// let original = `{{render "${componentName}"}}`;
// let preferred = `{{${componentName}}}`;

// return (
// `Please refactor \`${original}\` to a component and invoke via` +
// ` \`${preferred}\`. ${sourceInformation}`
// );
// };

// return {
// name: 'deprecate-render',

// visitor: {
// MustacheStatement(node: AST.MustacheStatement) {
// if (node.path.original !== 'render') {
// return;
// }
// if (node.params.length !== 1) {
// return;
// }

// node.params.forEach(param => {
// if (param.type !== 'StringLiteral') {
// return;
// }

// deprecate(deprecationMessage(node), false, {
// id: 'ember-template-compiler.deprecate-render',
// until: '3.0.0',
// url: 'https://emberjs.com/deprecations/v2.x#toc_code-render-code-helper',
// });
// });
// },
// },
// };
}
@@ -0,0 +1,27 @@
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);
2 changes: 1 addition & 1 deletion packages/ember-views/lib/mixins/text_support.js
Expand Up @@ -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 |
| | |
Expand Down

0 comments on commit 1d5687a

Please sign in to comment.