@@ -31,8 +31,6 @@ export default class Macros {
31
31
*/
32
32
expand ( path ) {
33
33
let debugBinding = path . scope . getBinding ( DEBUG ) ;
34
- let { builder, envFlags } = this ;
35
-
36
34
37
35
if ( this . _hasDebugModule ( debugBinding ) ) {
38
36
debugBinding . path . parentPath . remove ( ) ;
@@ -41,12 +39,12 @@ export default class Macros {
41
39
this . _inlineFeatureFlags ( path ) ;
42
40
this . _inlineSvelteFlags ( path ) ;
43
41
this . _inlineEnvFlags ( path )
44
- this . builder . expandMacros ( envFlags . DEBUG ) ;
42
+ this . builder . expandMacros ( this . envFlags . DEBUG ) ;
45
43
this . _cleanImports ( path ) ;
46
44
}
47
45
48
46
_inlineFeatureFlags ( path ) {
49
- let { envFlags , builder , featureFlags , featuresMap } = this ;
47
+ let featuresMap = this . featuresMap ;
50
48
51
49
if ( this . envFlags . DEBUG ) { return ; }
52
50
Object . keys ( featuresMap ) . forEach ( ( source ) => {
@@ -56,7 +54,7 @@ export default class Macros {
56
54
57
55
if ( binding && flagValue !== null ) {
58
56
binding . referencePaths . forEach ( referencePath => {
59
- referencePath . replaceWith ( builder . t . booleanLiteral ( flagValue ) ) ;
57
+ referencePath . replaceWith ( this . builder . t . booleanLiteral ( flagValue ) ) ;
60
58
} ) ;
61
59
62
60
if ( binding . path . parentPath . isImportDeclaration ( ) ) {
@@ -68,38 +66,42 @@ export default class Macros {
68
66
}
69
67
70
68
_inlineEnvFlags ( path ) {
71
- let { envFlags, builder } = this ;
69
+ let envFlags = this . envFlags ;
70
+
72
71
Object . keys ( envFlags ) . forEach ( flag => {
73
72
let binding = path . scope . getBinding ( flag ) ;
74
73
if ( binding &&
75
74
binding . path . isImportSpecifier ( ) &&
76
75
binding . path . parent . source . value === this . envFlagsSource ) {
77
76
78
- binding . referencePaths . forEach ( p => p . replaceWith ( builder . t . booleanLiteral ( envFlags [ flag ] ) ) ) ;
77
+ binding . referencePaths . forEach ( p => p . replaceWith ( this . builder . t . booleanLiteral ( envFlags [ flag ] ) ) ) ;
79
78
}
80
79
} ) ;
81
80
}
82
81
83
82
_inlineSvelteFlags ( path ) {
84
- let { svelteMap, envFlags, builder } = this ;
83
+ let svelteMap = this . svelteMap ;
84
+ let envFlags = this . envFlags ;
85
+ let builder = this . builder ;
86
+
85
87
let sources = Object . keys ( svelteMap ) ;
86
88
sources . forEach ( ( source ) => {
87
89
Object . keys ( svelteMap [ source ] ) . forEach ( ( flag ) => {
88
90
let binding = path . scope . getBinding ( flag ) ;
89
91
if ( binding !== undefined ) {
90
92
binding . referencePaths . forEach ( ( p ) => {
93
+ let t = builder . t ;
91
94
if ( envFlags . DEBUG ) {
92
95
if ( svelteMap [ source ] [ flag ] === false ) {
93
- let { t } = builder ;
94
96
if ( ! p . parentPath . isIfStatement ( ) ) { return ; }
95
97
let consequent = p . parentPath . get ( 'consequent' ) ;
96
- consequent . unshiftContainer ( 'body' , builder . t . throwStatement (
98
+ consequent . unshiftContainer ( 'body' , t . throwStatement (
97
99
t . newExpression ( t . identifier ( 'Error' ) , [ t . stringLiteral ( `You indicated you don't have any deprecations, however you are relying on ${ flag } .` ) ] )
98
100
) ) ;
99
101
}
100
102
} else {
101
103
if ( p . parentPath . isIfStatement ( ) ) {
102
- p . replaceWith ( builder . t . booleanLiteral ( svelteMap [ source ] [ flag ] ) ) ;
104
+ p . replaceWith ( t . booleanLiteral ( svelteMap [ source ] [ flag ] ) ) ;
103
105
}
104
106
}
105
107
} ) ;
@@ -130,8 +132,8 @@ export default class Macros {
130
132
*/
131
133
build ( path ) {
132
134
let expression = path . node . expression ;
133
- let { builder , localDebugBindings } = this ;
134
- if ( builder . t . isCallExpression ( expression ) && localDebugBindings . some ( ( b ) => b . node . name === expression . callee . name ) ) {
135
+
136
+ if ( this . builder . t . isCallExpression ( expression ) && this . localDebugBindings . some ( ( b ) => b . node . name === expression . callee . name ) ) {
135
137
let imported = path . scope . getBinding ( expression . callee . name ) . path . node . imported . name ;
136
138
this . builder [ `${ imported } ` ] ( path ) ;
137
139
}
@@ -152,31 +154,23 @@ export default class Macros {
152
154
}
153
155
154
156
_detectForeignFeatureFlag ( specifiers , source ) {
155
- let { featuresMap } = this ;
156
157
specifiers . forEach ( ( specifier ) => {
157
- if ( specifier . imported && featuresMap [ source ] [ specifier . imported . name ] !== null ) {
158
+ if ( specifier . imported && this . featuresMap [ source ] [ specifier . imported . name ] !== null ) {
158
159
throw new Error ( `Imported ${ specifier . imported . name } from ${ source } which is not a supported flag.` ) ;
159
160
}
160
161
} ) ;
161
162
}
162
163
163
164
_cleanImports ( path ) {
164
- let {
165
- debugHelpers,
166
- builder,
167
- featureFlags,
168
- featureSources
169
- } = this ;
170
-
171
165
let body = path . get ( 'body' ) ;
172
166
173
167
if ( ! this . envFlags . DEBUG ) {
174
168
for ( let i = 0 ; i < body . length ; i ++ ) {
175
169
let decl = body [ i ] ;
176
170
177
- if ( builder . t . isImportDeclaration ( decl ) ) {
171
+ if ( this . builder . t . isImportDeclaration ( decl ) ) {
178
172
let source = decl . node . source . value ;
179
- if ( featureSources . indexOf ( source ) > - 1 ) {
173
+ if ( this . featureSources . indexOf ( source ) > - 1 ) {
180
174
if ( decl . node . specifiers . length > 0 ) {
181
175
this . _detectForeignFeatureFlag ( decl . node . specifiers , source ) ;
182
176
} else {
@@ -188,7 +182,7 @@ export default class Macros {
188
182
}
189
183
}
190
184
191
- if ( ! debugHelpers . module ) {
185
+ if ( ! this . debugHelpers . module ) {
192
186
if ( this . localDebugBindings . length > 0 ) {
193
187
this . localDebugBindings [ 0 ] . parentPath . parentPath
194
188
let importPath = this . localDebugBindings [ 0 ] . findParent ( p => p . isImportDeclaration ( ) ) ;
0 commit comments