11'use strict' ;
22
33const utils = require ( './utils' ) ;
4- const semver = require ( 'semver' ) ;
54
65module . exports = class ClassTransformPlugin {
76 constructor ( env , options ) {
87 this . syntax = env . syntax ;
98 this . builders = env . syntax . builders ;
109 this . options = options ;
1110 this . stylesModule = this . determineStylesModule ( env ) ;
12- this . isGlimmer = this . detectGlimmer ( ) ;
1311 this . visitor = this . buildVisitor ( env ) ;
14-
15- // Alias for 2.15 <= Ember < 3.1
16- this . visitors = this . visitor ;
1712 }
1813
19- static instantiate ( { emberVersion , options } ) {
14+ static instantiate ( options ) {
2015 return {
2116 name : 'ember-css-modules' ,
22- plugin : semver . lt ( emberVersion , '2.15.0-alpha' )
23- ? LegacyAdapter . bind ( null , this , options )
24- : ( env ) => new this ( env , options ) ,
17+ plugin : ( env ) => new this ( env , options ) ,
2518 parallelBabel : {
2619 requireFile : __filename ,
2720 buildUsing : 'instantiate' ,
28- params : { emberVersion , options } ,
21+ params : options ,
2922 } ,
3023 baseDir ( ) {
3124 return `${ __dirname } /../..` ;
@@ -54,17 +47,6 @@ module.exports = class ClassTransformPlugin {
5447 return name ;
5548 }
5649
57- detectGlimmer ( ) {
58- if ( ! this . syntax . parse ) {
59- return false ;
60- }
61-
62- // HTMLBars builds ConcatStatements with StringLiterals + raw PathExpressions
63- // Glimmer builds ConcatStatements with TextNodes + MustacheStatements
64- let ast = this . syntax . parse ( '<div class="foo {{bar}}"></div>' ) ;
65- return ast . body [ 0 ] . attributes [ 0 ] . value . parts [ 0 ] . type === 'TextNode' ;
66- }
67-
6850 buildVisitor ( env ) {
6951 if ( env . moduleName === env . filename ) {
7052 // No-op for the stage 1 Embroider pass (which only contains relative paths)
@@ -133,7 +115,6 @@ module.exports = class ClassTransformPlugin {
133115
134116 utils . removeAttr ( node , localClassAttr ) ;
135117
136- let stringBuilder = this . isGlimmer ? 'text' : 'string' ;
137118 let classAttr = utils . getAttr ( node , 'class' ) ;
138119 let parts = [ ] ;
139120 let classAttrValue ;
@@ -149,26 +130,18 @@ module.exports = class ClassTransformPlugin {
149130 parts . push (
150131 this . builders . mustache (
151132 this . builders . path ( 'concat' ) ,
152- utils . concatStatementToParams (
153- this . builders ,
154- classAttrValue ,
155- this . isGlimmer
156- )
133+ utils . concatStatementToParams ( this . builders , classAttrValue )
157134 )
158135 ) ;
159136 } else if ( classAttrValue . type === 'TextNode' ) {
160- parts . push ( this . builders [ stringBuilder ] ( classAttrValue . chars ) ) ;
137+ parts . push ( this . builders . text ( classAttrValue . chars ) ) ;
161138 } else if ( classAttrValue . type === 'MustacheStatement' ) {
162- if ( classAttrValue . params . length || this . isGlimmer ) {
163- parts . push ( classAttrValue ) ;
164- } else {
165- parts . push ( this . builders . path ( classAttrValue . path . original ) ) ;
166- }
139+ parts . push ( classAttrValue ) ;
167140 }
168141 }
169142
170143 utils . pushAll ( parts , this . localToPath ( localClassAttr . value ) ) ;
171- this . divide ( parts , this . isGlimmer ? 'text' : 'string ') ;
144+ this . divide ( parts , 'text' ) ;
172145 node . attributes . unshift (
173146 this . builders . attr ( 'class' , this . builders . concat ( parts ) )
174147 ) ;
@@ -225,11 +198,7 @@ module.exports = class ClassTransformPlugin {
225198
226199 concatLocalPath ( node ) {
227200 let concatPath = this . builders . path ( 'concat' ) ;
228- let concatParts = utils . concatStatementToParams (
229- this . builders ,
230- node ,
231- this . isGlimmer
232- ) ;
201+ let concatParts = utils . concatStatementToParams ( this . builders , node ) ;
233202 let concatStatement = this . builders . mustache ( concatPath , concatParts ) ;
234203 return this . dynamicLocalPath ( concatStatement ) ;
235204 }
@@ -268,22 +237,3 @@ module.exports = class ClassTransformPlugin {
268237 return parts ;
269238 }
270239} ;
271-
272- // For Ember < 2.15
273- class LegacyAdapter {
274- constructor ( plugin , options , env ) {
275- this . plugin = plugin ;
276- this . options = options ;
277- this . meta = env . meta ;
278- this . syntax = null ;
279- }
280-
281- transform ( ast ) {
282- let plugin = new this . plugin (
283- Object . assign ( { syntax : this . syntax } , this . meta ) ,
284- this . options
285- ) ;
286- this . syntax . traverse ( ast , plugin . visitor ) ;
287- return ast ;
288- }
289- }
0 commit comments