From b9e19460ea30e5e214863aa8edf27194dda0865a Mon Sep 17 00:00:00 2001 From: Pat O'Callaghan Date: Tue, 2 Feb 2021 23:22:00 +0000 Subject: [PATCH] Add hasBlock and hasBlockParams deprecation messages --- .../components/contextual-components-test.js | 11 +++ .../components/curly-components-test.js | 84 +++++++++++++++++++ .../lib/plugins/transform-has-block-syntax.ts | 25 +++++- 3 files changed, 119 insertions(+), 1 deletion(-) diff --git a/packages/@ember/-internals/glimmer/tests/integration/components/contextual-components-test.js b/packages/@ember/-internals/glimmer/tests/integration/components/contextual-components-test.js index 60b18b65fa7..3920ae482c2 100644 --- a/packages/@ember/-internals/glimmer/tests/integration/components/contextual-components-test.js +++ b/packages/@ember/-internals/glimmer/tests/integration/components/contextual-components-test.js @@ -1359,6 +1359,9 @@ moduleFor( } ['@test GH#18732 hasBlock works within a yielded curried component invoked within mustaches']() { + expectDeprecation( + `\`hasBlock\` is deprecated. Use \`has-block\` instead. ('my-app/templates/components/component-with-has-block.hbs' @ L1:C5) ` + ); this.registerComponent('component-with-has-block', { ComponentClass: Component.extend(), template: '
{{hasBlock}}
', @@ -1381,6 +1384,10 @@ moduleFor( } ['@test GH#18732 has-block works within a yielded curried component invoked with angle bracket invocation (falsy)']() { + expectDeprecation( + `\`hasBlock\` is deprecated. Use \`has-block\` instead. ('my-app/templates/components/component-with-has-block.hbs' @ L1:C5) ` + ); + this.registerComponent('component-with-has-block', { ComponentClass: Component.extend(), template: '
{{hasBlock}}
', @@ -1403,6 +1410,10 @@ moduleFor( } ['@test GH#18732 has-block works within a yielded curried component invoked with angle bracket invocation (truthy)']() { + expectDeprecation( + `\`hasBlock\` is deprecated. Use \`has-block\` instead. ('my-app/templates/components/component-with-has-block.hbs' @ L1:C5) ` + ); + this.registerComponent('component-with-has-block', { ComponentClass: Component.extend(), template: '
{{hasBlock}}
', diff --git a/packages/@ember/-internals/glimmer/tests/integration/components/curly-components-test.js b/packages/@ember/-internals/glimmer/tests/integration/components/curly-components-test.js index 7b9f65c8f69..c2ae8cbd9bb 100644 --- a/packages/@ember/-internals/glimmer/tests/integration/components/curly-components-test.js +++ b/packages/@ember/-internals/glimmer/tests/integration/components/curly-components-test.js @@ -1928,6 +1928,10 @@ moduleFor( } ['@test hasBlock is true when block supplied']() { + expectDeprecation( + `\`hasBlock\` is deprecated. Use \`has-block\` instead. ('my-app/templates/components/with-block.hbs' @ L1:C6) ` + ); + this.registerComponent('with-block', { template: strip` {{#if hasBlock}} @@ -1950,6 +1954,10 @@ moduleFor( } ['@test hasBlock is false when no block supplied']() { + expectDeprecation( + `\`hasBlock\` is deprecated. Use \`has-block\` instead. ('my-app/templates/components/with-block.hbs' @ L1:C6) ` + ); + this.registerComponent('with-block', { template: strip` {{#if hasBlock}} @@ -1969,6 +1977,10 @@ moduleFor( } ['@test hasBlockParams is true when block param supplied']() { + expectDeprecation( + `\`hasBlockParams\` is deprecated. Use \`has-block-params\` instead. ('my-app/templates/components/with-block.hbs' @ L1:C6) ` + ); + this.registerComponent('with-block', { template: strip` {{#if hasBlockParams}} @@ -1991,6 +2003,10 @@ moduleFor( } ['@test hasBlockParams is false when no block param supplied']() { + expectDeprecation( + `\`hasBlockParams\` is deprecated. Use \`has-block-params\` instead. ('my-app/templates/components/with-block.hbs' @ L1:C6) ` + ); + this.registerComponent('with-block', { template: strip` {{#if hasBlockParams}} @@ -2118,6 +2134,10 @@ moduleFor( } ['@test expression hasBlock inverse']() { + expectDeprecation( + `\`hasBlock\` is deprecated. Use \`has-block\` instead. ('my-app/templates/components/check-inverse.hbs' @ L1:C6) ` + ); + this.registerComponent('check-inverse', { template: strip` {{#if (hasBlock "inverse")}} @@ -2138,6 +2158,10 @@ moduleFor( } ['@test expression hasBlock default']() { + expectDeprecation( + `\`hasBlock\` is deprecated. Use \`has-block\` instead. ('my-app/templates/components/check-block.hbs' @ L1:C6) ` + ); + this.registerComponent('check-block', { template: strip` {{#if (hasBlock)}} @@ -2158,6 +2182,10 @@ moduleFor( } ['@test expression hasBlockParams inverse']() { + expectDeprecation( + `\`hasBlockParams\` is deprecated. Use \`has-block-params\` instead. ('my-app/templates/components/check-inverse.hbs' @ L1:C6) ` + ); + this.registerComponent('check-inverse', { template: strip` {{#if (hasBlockParams "inverse")}} @@ -2178,6 +2206,10 @@ moduleFor( } ['@test expression hasBlockParams default']() { + expectDeprecation( + `\`hasBlockParams\` is deprecated. Use \`has-block-params\` instead. ('my-app/templates/components/check-block.hbs' @ L1:C6) ` + ); + this.registerComponent('check-block', { template: strip` {{#if (hasBlockParams)}} @@ -2198,6 +2230,10 @@ moduleFor( } ['@test non-expression hasBlock']() { + expectDeprecation( + `\`hasBlock\` is deprecated. Use \`has-block\` instead. ('my-app/templates/components/check-block.hbs' @ L1:C6) ` + ); + this.registerComponent('check-block', { template: strip` {{#if hasBlock}} @@ -2218,6 +2254,10 @@ moduleFor( } ['@test expression hasBlockParams']() { + expectDeprecation( + `\`hasBlockParams\` is deprecated. Use \`has-block-params\` instead. ('my-app/templates/components/check-params.hbs' @ L1:C6) ` + ); + this.registerComponent('check-params', { template: strip` {{#if (hasBlockParams)}} @@ -2238,6 +2278,10 @@ moduleFor( } ['@test non-expression hasBlockParams']() { + expectDeprecation( + `\`hasBlockParams\` is deprecated. Use \`has-block-params\` instead. ('my-app/templates/components/check-params.hbs' @ L1:C6) ` + ); + this.registerComponent('check-params', { template: strip` {{#if hasBlockParams}} @@ -2258,6 +2302,10 @@ moduleFor( } ['@test hasBlock expression in an attribute'](assert) { + expectDeprecation( + `\`hasBlock\` is deprecated. Use \`has-block\` instead. ('my-app/templates/components/check-attr.hbs' @ L1:C13) ` + ); + this.registerComponent('check-attr', { template: '', }); @@ -2273,6 +2321,10 @@ moduleFor( } ['@test hasBlock inverse expression in an attribute'](assert) { + expectDeprecation( + `\`hasBlock\` is deprecated. Use \`has-block\` instead. ('my-app/templates/components/check-attr.hbs' @ L1:C13) ` + ); + this.registerComponent( 'check-attr', { @@ -2292,6 +2344,10 @@ moduleFor( } ['@test hasBlockParams expression in an attribute'](assert) { + expectDeprecation( + `\`hasBlockParams\` is deprecated. Use \`has-block-params\` instead. ('my-app/templates/components/check-attr.hbs' @ L1:C13) ` + ); + this.registerComponent('check-attr', { template: '', }); @@ -2307,6 +2363,10 @@ moduleFor( } ['@test hasBlockParams inverse expression in an attribute'](assert) { + expectDeprecation( + `\`hasBlockParams\` is deprecated. Use \`has-block-params\` instead. ('my-app/templates/components/check-attr.hbs' @ L1:C13) ` + ); + this.registerComponent( 'check-attr', { @@ -2326,6 +2386,10 @@ moduleFor( } ['@test hasBlock as a param to a helper']() { + expectDeprecation( + `\`hasBlock\` is deprecated. Use \`has-block\` instead. ('my-app/templates/components/check-helper.hbs' @ L1:C5) ` + ); + this.registerComponent('check-helper', { template: '{{if hasBlock "true" "false"}}', }); @@ -2341,6 +2405,10 @@ moduleFor( } ['@test hasBlock as an expression param to a helper']() { + expectDeprecation( + `\`hasBlock\` is deprecated. Use \`has-block\` instead. ('my-app/templates/components/check-helper.hbs' @ L1:C5) ` + ); + this.registerComponent('check-helper', { template: '{{if (hasBlock) "true" "false"}}', }); @@ -2356,6 +2424,10 @@ moduleFor( } ['@test hasBlock inverse as a param to a helper']() { + expectDeprecation( + `\`hasBlock\` is deprecated. Use \`has-block\` instead. ('my-app/templates/components/check-helper.hbs' @ L1:C5) ` + ); + this.registerComponent('check-helper', { template: '{{if (hasBlock "inverse") "true" "false"}}', }); @@ -2371,6 +2443,10 @@ moduleFor( } ['@test hasBlockParams as a param to a helper']() { + expectDeprecation( + `\`hasBlockParams\` is deprecated. Use \`has-block-params\` instead. ('my-app/templates/components/check-helper.hbs' @ L1:C5) ` + ); + this.registerComponent('check-helper', { template: '{{if hasBlockParams "true" "false"}}', }); @@ -2386,6 +2462,10 @@ moduleFor( } ['@test hasBlockParams as an expression param to a helper']() { + expectDeprecation( + `\`hasBlockParams\` is deprecated. Use \`has-block-params\` instead. ('my-app/templates/components/check-helper.hbs' @ L1:C5) ` + ); + this.registerComponent('check-helper', { template: '{{if (hasBlockParams) "true" "false"}}', }); @@ -2401,6 +2481,10 @@ moduleFor( } ['@test hasBlockParams inverse as a param to a helper']() { + expectDeprecation( + `\`hasBlockParams\` is deprecated. Use \`has-block-params\` instead. ('my-app/templates/components/check-helper.hbs' @ L1:C5) ` + ); + this.registerComponent('check-helper', { template: '{{if (hasBlockParams "inverse") "true" "false"}}', }); diff --git a/packages/ember-template-compiler/lib/plugins/transform-has-block-syntax.ts b/packages/ember-template-compiler/lib/plugins/transform-has-block-syntax.ts index 0a9a4e090b7..5bf41da1fa3 100644 --- a/packages/ember-template-compiler/lib/plugins/transform-has-block-syntax.ts +++ b/packages/ember-template-compiler/lib/plugins/transform-has-block-syntax.ts @@ -1,4 +1,6 @@ +import { deprecate } from '@ember/debug'; import { AST, ASTPlugin } from '@glimmer/syntax'; +import calculateLocationDisplay from '../system/calculate-location-display'; import { EmberASTPluginEnvironment } from '../types'; import { isPath } from './utils'; @@ -23,13 +25,31 @@ import { isPath } from './utils'; @class TransformHasBlockSyntax */ -const TRANSFORMATIONS = { +const TRANSFORMATIONS: { [key: string]: string } = { hasBlock: 'has-block', hasBlockParams: 'has-block-params', }; export default function transformHasBlockSyntax(env: EmberASTPluginEnvironment): ASTPlugin { let { builders: b } = env.syntax; + let { moduleName } = env.meta; + + function emitDeprecationMessage(node: AST.Node, name: string) { + let sourceInformation = calculateLocationDisplay(moduleName, node.loc); + deprecate( + `\`${name}\` is deprecated. Use \`${TRANSFORMATIONS[name]}\` instead. ${sourceInformation}`, + false, + { + id: 'has-block-and-has-block-params', + until: '4.0.0', + url: 'https://emberjs.com/deprecations/v3.x#toc_has-block-and-has-block-params', + for: 'ember-source', + since: { + enabled: '3.25.0', + }, + } + ); + } return { name: 'transform-has-block-syntax', @@ -37,11 +57,13 @@ export default function transformHasBlockSyntax(env: EmberASTPluginEnvironment): visitor: { PathExpression(node: AST.PathExpression): AST.Node | void { if (TRANSFORMATIONS[node.original]) { + emitDeprecationMessage(node, node.original); return b.sexpr(b.path(TRANSFORMATIONS[node.original])); } }, MustacheStatement(node: AST.MustacheStatement): AST.Node | void { if (isPath(node.path) && TRANSFORMATIONS[node.path.original]) { + emitDeprecationMessage(node, node.path.original); return b.mustache( b.path(TRANSFORMATIONS[node.path.original]), node.params, @@ -53,6 +75,7 @@ export default function transformHasBlockSyntax(env: EmberASTPluginEnvironment): }, SubExpression(node: AST.SubExpression): AST.Node | void { if (isPath(node.path) && TRANSFORMATIONS[node.path.original]) { + emitDeprecationMessage(node, node.path.original); return b.sexpr(b.path(TRANSFORMATIONS[node.path.original]), node.params, node.hash); } },