diff --git a/packages/@ember/-internals/glimmer/index.ts b/packages/@ember/-internals/glimmer/index.ts index b85bf0842dc..cf7ecfdd08b 100644 --- a/packages/@ember/-internals/glimmer/index.ts +++ b/packages/@ember/-internals/glimmer/index.ts @@ -150,7 +150,7 @@ */ /** - `{{has-block}}` indicates if the component was invoked with a block. + `{{(has-block)}}` indicates if the component was invoked with a block. This component is invoked with a block: @@ -187,7 +187,7 @@ {{/if}} ``` - @method hasBlock + @method has-block @for Ember.Templates.helpers @param {String} the name of the block. The name (at the moment) is either "main" or "inverse" (though only curly components support inverse) @return {Boolean} `true` if the component was invoked with a block @@ -195,7 +195,7 @@ */ /** - `{{has-block-params}}` indicates if the component was invoked with block params. + `{{(has-block-params)}}` indicates if the component was invoked with block params. This component is invoked with block params: @@ -242,7 +242,7 @@ {{/if}} ``` - @method hasBlockParams + @method has-block-params @for Ember.Templates.helpers @param {String} the name of the block. The name (at the moment) is either "main" or "inverse" (though only curly components support inverse) @return {Boolean} `true` if the component was invoked with block params 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 750f9df7538..4d102a4b072 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 @@ -1357,13 +1357,10 @@ moduleFor( this.assertStableRerender(); } - ['@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) ` - ); + ['@test GH#18732 (has-block) works within a yielded curried component invoked within mustaches']() { this.registerComponent('component-with-has-block', { ComponentClass: Component.extend(), - template: '
{{hasBlock}}
', + template: '
{{(has-block)}}
', }); this.registerComponent('yielding-component', { @@ -1382,14 +1379,10 @@ moduleFor( this.assertText('false'); } - ['@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) ` - ); - + ['@test GH#18732 (has-block) works within a yielded curried component invoked with angle bracket invocation (falsy)']() { this.registerComponent('component-with-has-block', { ComponentClass: Component.extend(), - template: '
{{hasBlock}}
', + template: '
{{(has-block)}}
', }); this.registerComponent('yielding-component', { @@ -1408,14 +1401,10 @@ moduleFor( this.assertText('false'); } - ['@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) ` - ); - + ['@test GH#18732 (has-block) works within a yielded curried component invoked with angle bracket invocation (truthy)']() { this.registerComponent('component-with-has-block', { ComponentClass: Component.extend(), - template: '
{{hasBlock}}
', + template: '
{{(has-block)}}
', }); this.registerComponent('yielding-component', { 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 f63c56cbc98..5932a7a9e0c 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 @@ -1949,14 +1949,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) ` - ); - + ['@test (has-block) is true when block supplied']() { this.registerComponent('with-block', { template: strip` - {{#if hasBlock}} + {{#if (has-block)}} {{yield}} {{else}} No Block! @@ -1975,14 +1971,10 @@ moduleFor( this.assertText('In template'); } - ['@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) ` - ); - + ['@test (has-block) is false when no block supplied']() { this.registerComponent('with-block', { template: strip` - {{#if hasBlock}} + {{#if (has-block)}} {{yield}} {{else}} No Block! @@ -1998,14 +1990,10 @@ moduleFor( this.assertText('No Block!'); } - ['@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) ` - ); - + ['@test (has-block-params) is true when block param supplied']() { this.registerComponent('with-block', { template: strip` - {{#if hasBlockParams}} + {{#if (has-block-params)}} {{yield this}} - In Component {{else}} {{yield}} No Block! @@ -2024,14 +2012,10 @@ moduleFor( this.assertText('In template - In Component'); } - ['@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) ` - ); - + ['@test (has-block-params) is false when no block param supplied']() { this.registerComponent('with-block', { template: strip` - {{#if hasBlockParams}} + {{#if (has-block-params)}} {{yield this}} {{else}} {{yield}} No Block Param! @@ -2155,14 +2139,10 @@ moduleFor( this.assertText('Yes:Hello42'); } - ['@test expression hasBlock inverse']() { - expectDeprecation( - `\`hasBlock\` is deprecated. Use \`has-block\` instead. ('my-app/templates/components/check-inverse.hbs' @ L1:C6) ` - ); - + ['@test expression (has-block) inverse']() { this.registerComponent('check-inverse', { template: strip` - {{#if (hasBlock "inverse")}} + {{#if (has-block "inverse")}} Yes {{else}} No @@ -2179,14 +2159,10 @@ moduleFor( this.assertStableRerender(); } - ['@test expression hasBlock default']() { - expectDeprecation( - `\`hasBlock\` is deprecated. Use \`has-block\` instead. ('my-app/templates/components/check-block.hbs' @ L1:C6) ` - ); - + ['@test expression (has-block) default']() { this.registerComponent('check-block', { template: strip` - {{#if (hasBlock)}} + {{#if (has-block)}} Yes {{else}} No @@ -2203,14 +2179,10 @@ moduleFor( this.assertStableRerender(); } - ['@test expression hasBlockParams inverse']() { - expectDeprecation( - `\`hasBlockParams\` is deprecated. Use \`has-block-params\` instead. ('my-app/templates/components/check-inverse.hbs' @ L1:C6) ` - ); - + ['@test expression (has-block-params) inverse']() { this.registerComponent('check-inverse', { template: strip` - {{#if (hasBlockParams "inverse")}} + {{#if (has-block-params "inverse")}} Yes {{else}} No @@ -2227,14 +2199,10 @@ moduleFor( this.assertStableRerender(); } - ['@test expression hasBlockParams default']() { - expectDeprecation( - `\`hasBlockParams\` is deprecated. Use \`has-block-params\` instead. ('my-app/templates/components/check-block.hbs' @ L1:C6) ` - ); - + ['@test expression (has-block-params) default']() { this.registerComponent('check-block', { template: strip` - {{#if (hasBlockParams)}} + {{#if (has-block-params)}} Yes {{else}} No @@ -2251,85 +2219,9 @@ moduleFor( this.assertStableRerender(); } - ['@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}} - Yes - {{else}} - No - {{/if}}`, - }); - - this.render(strip` - {{check-block}} - {{#check-block}}{{/check-block}}`); - - this.assertComponentElement(this.firstChild, { content: 'No' }); - this.assertComponentElement(this.nthChild(1), { content: 'Yes' }); - - this.assertStableRerender(); - } - - ['@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)}} - Yes - {{else}} - No - {{/if}}`, - }); - - this.render(strip` - {{#check-params}}{{/check-params}} - {{#check-params as |foo|}}{{/check-params}}`); - - this.assertComponentElement(this.firstChild, { content: 'No' }); - this.assertComponentElement(this.nthChild(1), { content: 'Yes' }); - - this.assertStableRerender(); - } - - ['@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}} - Yes - {{else}} - No - {{/if}}`, - }); - - this.render(strip` - {{#check-params}}{{/check-params}} - {{#check-params as |foo|}}{{/check-params}}`); - - this.assertComponentElement(this.firstChild, { content: 'No' }); - this.assertComponentElement(this.nthChild(1), { content: 'Yes' }); - - this.assertStableRerender(); - } - - ['@test hasBlock expression in an attribute'](assert) { - expectDeprecation( - `\`hasBlock\` is deprecated. Use \`has-block\` instead. ('my-app/templates/components/check-attr.hbs' @ L1:C13) ` - ); - + ['@test (has-block) expression in an attribute'](assert) { this.registerComponent('check-attr', { - template: '', + template: '', }); this.render(strip` @@ -2342,15 +2234,11 @@ moduleFor( this.assertStableRerender(); } - ['@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) ` - ); - + ['@test (has-block) inverse expression in an attribute'](assert) { this.registerComponent( 'check-attr', { - template: '', + template: '', }, '' ); @@ -2365,13 +2253,9 @@ moduleFor( this.assertStableRerender(); } - ['@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) ` - ); - + ['@test (has-block-params) expression in an attribute'](assert) { this.registerComponent('check-attr', { - template: '', + template: '', }); this.render(strip` @@ -2384,15 +2268,11 @@ moduleFor( this.assertStableRerender(); } - ['@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) ` - ); - + ['@test (has-block-params) inverse expression in an attribute'](assert) { this.registerComponent( 'check-attr', { - template: '', + template: '', }, '' ); @@ -2407,32 +2287,9 @@ moduleFor( this.assertStableRerender(); } - ['@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"}}', - }); - - this.render(strip` - {{check-helper}} - {{#check-helper}}{{/check-helper}}`); - - this.assertComponentElement(this.firstChild, { content: 'false' }); - this.assertComponentElement(this.nthChild(1), { content: 'true' }); - - this.assertStableRerender(); - } - - ['@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) ` - ); - + ['@test (has-block) as a param to a helper']() { this.registerComponent('check-helper', { - template: '{{if (hasBlock) "true" "false"}}', + template: '{{if (has-block) "true" "false"}}', }); this.render(strip` @@ -2445,13 +2302,9 @@ moduleFor( this.assertStableRerender(); } - ['@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) ` - ); - + ['@test (has-block) inverse as a param to a helper']() { this.registerComponent('check-helper', { - template: '{{if (hasBlock "inverse") "true" "false"}}', + template: '{{if (has-block "inverse") "true" "false"}}', }); this.render(strip` @@ -2464,32 +2317,9 @@ moduleFor( this.assertStableRerender(); } - ['@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"}}', - }); - - this.render(strip` - {{#check-helper}}{{/check-helper}} - {{#check-helper as |something|}}{{/check-helper}}`); - - this.assertComponentElement(this.firstChild, { content: 'false' }); - this.assertComponentElement(this.nthChild(1), { content: 'true' }); - - this.assertStableRerender(); - } - - ['@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) ` - ); - + ['@test (has-block-params) as a param to a helper']() { this.registerComponent('check-helper', { - template: '{{if (hasBlockParams) "true" "false"}}', + template: '{{if (has-block-params) "true" "false"}}', }); this.render(strip` @@ -2502,13 +2332,9 @@ moduleFor( this.assertStableRerender(); } - ['@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) ` - ); - + ['@test (has-block-params) inverse as a param to a helper']() { this.registerComponent('check-helper', { - template: '{{if (hasBlockParams "inverse") "true" "false"}}', + template: '{{if (has-block-params "inverse") "true" "false"}}', }); this.render(strip` diff --git a/packages/ember-template-compiler/lib/plugins/index.ts b/packages/ember-template-compiler/lib/plugins/index.ts index 7d610b69e96..1f6d69ad01e 100644 --- a/packages/ember-template-compiler/lib/plugins/index.ts +++ b/packages/ember-template-compiler/lib/plugins/index.ts @@ -7,7 +7,6 @@ import TransformActionSyntax from './transform-action-syntax'; import TransformAttrsIntoArgs from './transform-attrs-into-args'; import TransformEachInIntoEach from './transform-each-in-into-each'; import TransformEachTrackArray from './transform-each-track-array'; -import TransformHasBlockSyntax from './transform-has-block-syntax'; import TransformInElement from './transform-in-element'; import TransformLinkTo from './transform-link-to'; import TransformOldClassBindingSyntax from './transform-old-class-binding-syntax'; @@ -26,7 +25,6 @@ export const RESOLUTION_MODE_TRANSFORMS = Object.freeze( TransformActionSyntax, TransformAttrsIntoArgs, TransformEachInIntoEach, - TransformHasBlockSyntax, TransformLinkTo, AssertInputHelperWithoutBlock, TransformInElement, 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 deleted file mode 100644 index ac45872bf34..00000000000 --- a/packages/ember-template-compiler/lib/plugins/transform-has-block-syntax.ts +++ /dev/null @@ -1,84 +0,0 @@ -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'; - -/** - @module ember -*/ - -/** - A Glimmer2 AST transformation that replaces all instances of - - ```handlebars - {{hasBlock}} - ``` - - with - - ```handlebars - {{has-block}} - ``` - - @private - @class TransformHasBlockSyntax -*/ - -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?.moduleName; - - 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://deprecations.emberjs.com/v3.x#toc_has-block-and-has-block-params', - for: 'ember-source', - since: { - enabled: '3.25.0', - }, - } - ); - } - - return { - name: 'transform-has-block-syntax', - - 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, - node.hash, - undefined, - node.loc - ); - } - }, - 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); - } - }, - }, - }; -} diff --git a/tests/docs/expected.js b/tests/docs/expected.js index f262415fcb0..abb2b8d86ff 100644 --- a/tests/docs/expected.js +++ b/tests/docs/expected.js @@ -270,8 +270,8 @@ module.exports = { 'handleURL', 'has', 'hasArrayObservers', - 'hasBlock', - 'hasBlockParams', + 'has-block', + 'has-block-params', 'hash', 'hashSettled', 'hasListeners',