Skip to content

Commit

Permalink
Merge pull request #19374 from patocallaghan/patoc/has-block-deprecation
Browse files Browse the repository at this point in the history
Add hasBlock and hasBlockParams deprecation messages
  • Loading branch information
Chris Garrett authored Feb 3, 2021
2 parents 002e4e8 + b9e1946 commit b480c96
Show file tree
Hide file tree
Showing 3 changed files with 119 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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: '<div>{{hasBlock}}</div>',
Expand All @@ -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: '<div>{{hasBlock}}</div>',
Expand All @@ -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: '<div>{{hasBlock}}</div>',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
Expand All @@ -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}}
Expand All @@ -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}}
Expand All @@ -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}}
Expand Down Expand Up @@ -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")}}
Expand All @@ -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)}}
Expand All @@ -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")}}
Expand All @@ -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)}}
Expand All @@ -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}}
Expand All @@ -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)}}
Expand All @@ -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}}
Expand All @@ -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: '<button name={{hasBlock}}></button>',
});
Expand All @@ -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',
{
Expand All @@ -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: '<button name={{hasBlockParams}}></button>',
});
Expand All @@ -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',
{
Expand All @@ -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"}}',
});
Expand All @@ -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"}}',
});
Expand All @@ -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"}}',
});
Expand All @@ -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"}}',
});
Expand All @@ -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"}}',
});
Expand All @@ -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"}}',
});
Expand Down
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -23,25 +25,45 @@ 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',

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,
Expand All @@ -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);
}
},
Expand Down

0 comments on commit b480c96

Please sign in to comment.