-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
/
transform-has-block-syntax.ts
84 lines (73 loc) · 2.31 KB
/
transform-has-block-syntax.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
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);
}
},
},
};
}