1
1
'use strict' ;
2
2
3
3
const utils = require ( './utils' ) ;
4
- const semver = require ( 'semver' ) ;
5
4
6
5
module . exports = class ClassTransformPlugin {
7
6
constructor ( env , options ) {
8
7
this . syntax = env . syntax ;
9
8
this . builders = env . syntax . builders ;
10
9
this . options = options ;
11
10
this . stylesModule = this . determineStylesModule ( env ) ;
12
- this . isGlimmer = this . detectGlimmer ( ) ;
13
11
this . visitor = this . buildVisitor ( env ) ;
14
-
15
- // Alias for 2.15 <= Ember < 3.1
16
- this . visitors = this . visitor ;
17
12
}
18
13
19
- static instantiate ( { emberVersion , options } ) {
14
+ static instantiate ( options ) {
20
15
return {
21
16
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 ) ,
25
18
parallelBabel : {
26
19
requireFile : __filename ,
27
20
buildUsing : 'instantiate' ,
28
- params : { emberVersion , options } ,
21
+ params : options ,
29
22
} ,
30
23
baseDir ( ) {
31
24
return `${ __dirname } /../..` ;
@@ -54,17 +47,6 @@ module.exports = class ClassTransformPlugin {
54
47
return name ;
55
48
}
56
49
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
-
68
50
buildVisitor ( env ) {
69
51
if ( env . moduleName === env . filename ) {
70
52
// No-op for the stage 1 Embroider pass (which only contains relative paths)
@@ -133,7 +115,6 @@ module.exports = class ClassTransformPlugin {
133
115
134
116
utils . removeAttr ( node , localClassAttr ) ;
135
117
136
- let stringBuilder = this . isGlimmer ? 'text' : 'string' ;
137
118
let classAttr = utils . getAttr ( node , 'class' ) ;
138
119
let parts = [ ] ;
139
120
let classAttrValue ;
@@ -149,26 +130,18 @@ module.exports = class ClassTransformPlugin {
149
130
parts . push (
150
131
this . builders . mustache (
151
132
this . builders . path ( 'concat' ) ,
152
- utils . concatStatementToParams (
153
- this . builders ,
154
- classAttrValue ,
155
- this . isGlimmer
156
- )
133
+ utils . concatStatementToParams ( this . builders , classAttrValue )
157
134
)
158
135
) ;
159
136
} else if ( classAttrValue . type === 'TextNode' ) {
160
- parts . push ( this . builders [ stringBuilder ] ( classAttrValue . chars ) ) ;
137
+ parts . push ( this . builders . text ( classAttrValue . chars ) ) ;
161
138
} 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 ) ;
167
140
}
168
141
}
169
142
170
143
utils . pushAll ( parts , this . localToPath ( localClassAttr . value ) ) ;
171
- this . divide ( parts , this . isGlimmer ? 'text' : 'string ') ;
144
+ this . divide ( parts , 'text' ) ;
172
145
node . attributes . unshift (
173
146
this . builders . attr ( 'class' , this . builders . concat ( parts ) )
174
147
) ;
@@ -225,11 +198,7 @@ module.exports = class ClassTransformPlugin {
225
198
226
199
concatLocalPath ( node ) {
227
200
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 ) ;
233
202
let concatStatement = this . builders . mustache ( concatPath , concatParts ) ;
234
203
return this . dynamicLocalPath ( concatStatement ) ;
235
204
}
@@ -268,22 +237,3 @@ module.exports = class ClassTransformPlugin {
268
237
return parts ;
269
238
}
270
239
} ;
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