@@ -14,6 +14,7 @@ module.exports = class Transformer extends ReadyResource {
14
14
worker = null
15
15
pipe = null
16
16
stream = null
17
+ transforms = null
17
18
18
19
constructor ( app , link , args ) {
19
20
super ( )
@@ -22,6 +23,7 @@ module.exports = class Transformer extends ReadyResource {
22
23
this . app = app
23
24
this . link = link
24
25
this . args = args
26
+ this . transforms = app . state ?. transforms
25
27
26
28
app . transformer = this
27
29
}
@@ -56,7 +58,7 @@ module.exports = class Transformer extends ReadyResource {
56
58
57
59
async transform ( buffer , filename ) {
58
60
const transforms = [ ]
59
- const patterns = this . app . state ?. transforms
61
+ const patterns = this . transforms
60
62
for ( const ptn in patterns ) {
61
63
const isMatch = picomatch ( ptn )
62
64
if ( isMatch ( filename ) ) {
@@ -124,6 +126,31 @@ module.exports = class Transformer extends ReadyResource {
124
126
return b . toBuffer ( )
125
127
}
126
128
129
+ identify ( doubles , singles ) {
130
+ const patterns = this . transforms
131
+ const jsx = Object . keys ( patterns ) . some ( pattern => pattern . includes ( 'jsx' ) )
132
+ const double = jsx ? / \. ( m | c ) ? j s x ? " $ / : / \. ( m | c ) ? j s " $ /
133
+ const single = jsx ? / \. ( m | c ) ? j s x ? ' $ / : / \. ( m | c ) ? j s ' $ /
134
+
135
+ const entries = [ ]
136
+ if ( doubles ) {
137
+ for ( const s of doubles ) {
138
+ if ( double . test ( s ) ) {
139
+ entries . push ( s . slice ( 1 , - 1 ) )
140
+ }
141
+ }
142
+ }
143
+
144
+ if ( singles ) {
145
+ for ( const s of singles ) {
146
+ if ( single . test ( s ) ) {
147
+ entries . push ( s . slice ( 1 , - 1 ) )
148
+ }
149
+ }
150
+ }
151
+ return entries
152
+ }
153
+
127
154
static validate ( transforms ) {
128
155
if ( ! transforms ) return null
129
156
0 commit comments