@@ -15,6 +15,8 @@ module.exports = {
1515 if ( checker . forEmber ( ) . gte ( '3.1.0' ) ) {
1616 registry . add ( 'htmlbars-ast-plugin' , this . buildPlugin ( ) ) ;
1717 }
18+
19+ registry . add ( 'htmlbars-ast-plugin' , this . buildLegacyPlugin ( ) ) ;
1820 } ,
1921
2022 buildPlugin ( ) {
@@ -38,6 +40,8 @@ module.exports = {
3840 visitor : {
3941 PathExpression ( node ) {
4042 if ( node . original === 'module-name-inliner' ) {
43+ // replacing the path with a string literal, like this
44+ // {{"the-module-name-here"}}
4145 return builders . string ( env . moduleName ) ;
4246 }
4347 } ,
@@ -46,4 +50,47 @@ module.exports = {
4650 } ,
4751 } ;
4852 } ,
53+
54+ // this type of plugin has worked since at least Ember 2.4+
55+ buildLegacyPlugin ( ) {
56+ return {
57+ name : 'module-name-inliner' ,
58+ baseDir ( ) {
59+ return __dirname ;
60+ } ,
61+ parallelBabel : {
62+ requireFile : __filename ,
63+ buildUsing : 'buildPlugin' ,
64+ params : { } ,
65+ } ,
66+
67+ plugin : class LegacyPlugin {
68+ constructor ( options ) {
69+ this . options = options ;
70+ }
71+
72+ transform ( ast ) {
73+ let { meta } = this . options ;
74+ let b = this . syntax . builders ;
75+
76+ this . syntax . traverse ( ast , {
77+ // replacing the mustache with text, like this
78+ // {{module-name-reverser}} -> `some-module-name`
79+ MustacheStatement ( node ) {
80+ if ( node . path . original === 'module-name-reverser' ) {
81+ return b . text (
82+ meta . moduleName
83+ . split ( '' )
84+ . reverse ( )
85+ . join ( '' )
86+ ) ;
87+ }
88+ } ,
89+ } ) ;
90+
91+ return ast ;
92+ }
93+ } ,
94+ } ;
95+ } ,
4996} ;
0 commit comments