@@ -17,6 +17,7 @@ const getSymbolValue = function (symbol) {
1717 /* istanbul ignore next */
1818 return null ;
1919 }
20+
2021 /* istanbul ignore next */
2122 if ( symbol . type === 'literal' ) {
2223 return symbol . value . value ;
@@ -59,10 +60,13 @@ let createSymbol = null;
5960const getSymbol = function ( node , globals , scope , opt ) {
6061 const opts = opt || { } ;
6162 /* istanbul ignore next */
63+ // eslint-disable-next-line default-case
6264 switch ( node . type ) {
6365 case 'Identifier' : {
6466 return getIdentifier ( node , globals , scope , opts ) ;
65- } case 'MemberExpression' : {
67+ }
68+
69+ case 'MemberExpression' : {
6670 const obj = getSymbol ( node . object , globals , scope , opts ) ;
6771 const propertySymbol = getSymbol ( node . property , globals , scope , { simpleIdentifier : ! node . computed } ) ;
6872 const propertyValue = getSymbolValue ( propertySymbol ) ;
@@ -87,6 +91,7 @@ const getSymbol = function (node, globals, scope, opt) {
8791 /* istanbul ignore next */
8892 return null ;
8993 }
94+
9095 case 'TSTypeAliasDeclaration' :
9196 case 'TSEnumDeclaration' : case 'TSInterfaceDeclaration' :
9297 case 'ClassDeclaration' : case 'ClassExpression' :
@@ -99,20 +104,27 @@ const getSymbol = function (node, globals, scope, opt) {
99104 val . value = node ;
100105
101106 return val ;
102- } case 'AssignmentExpression' : {
107+ }
108+
109+ case 'AssignmentExpression' : {
103110 return createSymbol ( node . left , globals , node . right , scope , opts ) ;
104- } case 'ClassBody' : {
111+ }
112+
113+ case 'ClassBody' : {
105114 const val = createNode ( ) ;
106115 for ( const method of node . body ) {
107116 val . props [ method . key . name ] = createNode ( ) ;
108117 val . props [ method . key . name ] . type = 'object' ;
109118 val . props [ method . key . name ] . value = method . value ;
110119 }
120+
111121 val . type = 'object' ;
112122 val . value = node ;
113123
114124 return val ;
115- } case 'ObjectExpression' : {
125+ }
126+
127+ case 'ObjectExpression' : {
116128 const val = createNode ( ) ;
117129 val . type = 'object' ;
118130 for ( const prop of node . properties ) {
@@ -125,6 +137,7 @@ const getSymbol = function (node, globals, scope, opt) {
125137 ] . includes ( prop . type ) ) {
126138 continue ;
127139 }
140+
128141 const propVal = getSymbol ( prop . value , globals , scope , opts ) ;
129142 /* istanbul ignore next */
130143 if ( propVal ) {
@@ -133,7 +146,9 @@ const getSymbol = function (node, globals, scope, opt) {
133146 }
134147
135148 return val ;
136- } case 'Literal' : {
149+ }
150+
151+ case 'Literal' : {
137152 const val = createNode ( ) ;
138153 val . type = 'literal' ;
139154 val . value = node ;
@@ -156,6 +171,7 @@ const createBlockSymbol = function (block, name, value, globals, isGlobal) {
156171createSymbol = function ( node , globals , value , scope , isGlobal ) {
157172 const block = scope || globals ;
158173 let symbol ;
174+ // eslint-disable-next-line default-case
159175 switch ( node . type ) {
160176 case 'FunctionDeclaration' :
161177 /* istanbul ignore next */
@@ -168,9 +184,12 @@ createSymbol = function (node, globals, value, scope, isGlobal) {
168184 if ( node . id && node . id . type === 'Identifier' ) {
169185 return createSymbol ( node . id , globals , node , globals ) ;
170186 }
187+
171188 /* istanbul ignore next */
172189 break ;
173- } case 'Identifier' : {
190+ }
191+
192+ case 'Identifier' : {
174193 if ( value ) {
175194 const valueSymbol = getSymbol ( value , globals , block ) ;
176195 /* istanbul ignore next */
@@ -179,16 +198,20 @@ createSymbol = function (node, globals, value, scope, isGlobal) {
179198
180199 return block . props [ node . name ] ;
181200 }
201+
182202 /* istanbul ignore next */
183203 debug ( 'Identifier: Missing value symbol for %s' , node . name ) ;
184204 } else {
185205 createBlockSymbol ( block , node . name , createNode ( ) , globals , isGlobal ) ;
186206
187207 return block . props [ node . name ] ;
188208 }
209+
189210 /* istanbul ignore next */
190211 break ;
191- } case 'MemberExpression' : {
212+ }
213+
214+ case 'MemberExpression' : {
192215 symbol = getSymbol ( node . object , globals , block ) ;
193216
194217 const propertySymbol = getSymbol ( node . property , globals , block , { simpleIdentifier : ! node . computed } ) ;
@@ -198,6 +221,7 @@ createSymbol = function (node, globals, value, scope, isGlobal) {
198221
199222 return symbol . props [ propertyValue ] ;
200223 }
224+
201225 /* istanbul ignore next */
202226 debug ( 'MemberExpression: Missing symbol: %s' , node . property . name ) ;
203227 break ;
@@ -209,16 +233,22 @@ createSymbol = function (node, globals, value, scope, isGlobal) {
209233
210234// Creates variables from variable definitions
211235const initVariables = function ( node , globals , opts ) {
236+ // eslint-disable-next-line default-case
212237 switch ( node . type ) {
213238 case 'Program' : {
214239 for ( const childNode of node . body ) {
215240 initVariables ( childNode , globals , opts ) ;
216241 }
242+
217243 break ;
218- } case 'ExpressionStatement' : {
244+ }
245+
246+ case 'ExpressionStatement' : {
219247 initVariables ( node . expression , globals , opts ) ;
220248 break ;
221- } case 'VariableDeclaration' : {
249+ }
250+
251+ case 'VariableDeclaration' : {
222252 for ( const declaration of node . declarations ) {
223253 // let and const
224254 const symbol = createSymbol ( declaration . id , globals , null , globals ) ;
@@ -227,11 +257,15 @@ const initVariables = function (node, globals, opts) {
227257 globals . props . window . props [ declaration . id . name ] = symbol ;
228258 }
229259 }
260+
230261 break ;
231- } case 'ExportNamedDeclaration' : {
262+ }
263+
264+ case 'ExportNamedDeclaration' : {
232265 if ( node . declaration ) {
233266 initVariables ( node . declaration , globals , opts ) ;
234267 }
268+
235269 break ;
236270 }
237271 }
@@ -248,40 +282,57 @@ const mapVariables = function (node, globals, opt, isExport) {
248282 if ( opts . ancestorsOnly ) {
249283 return false ;
250284 }
285+
251286 for ( const childNode of node . body ) {
252287 mapVariables ( childNode , globals , opts ) ;
253288 }
289+
254290 break ;
255- } case 'ExpressionStatement' : {
291+ }
292+
293+ case 'ExpressionStatement' : {
256294 mapVariables ( node . expression , globals , opts ) ;
257295 break ;
258- } case 'AssignmentExpression' : {
296+ }
297+
298+ case 'AssignmentExpression' : {
259299 createSymbol ( node . left , globals , node . right ) ;
260300 break ;
261- } case 'VariableDeclaration' : {
301+ }
302+
303+ case 'VariableDeclaration' : {
262304 for ( const declaration of node . declarations ) {
263305 const isGlobal = opts . initWindow && node . kind === 'var' && globals . props . window ;
264306 const symbol = createSymbol ( declaration . id , globals , declaration . init , globals , isGlobal ) ;
265307 if ( symbol && isExport ) {
266308 symbol . exported = true ;
267309 }
268310 }
311+
269312 break ;
270- } case 'FunctionDeclaration' : {
313+ }
314+
315+ case 'FunctionDeclaration' : {
271316 /* istanbul ignore next */
272317 if ( node . id . type === 'Identifier' ) {
273318 createSymbol ( node . id , globals , node , globals , true ) ;
274319 }
320+
275321 break ;
276- } case 'ExportDefaultDeclaration' : {
322+ }
323+
324+ case 'ExportDefaultDeclaration' : {
277325 const symbol = createSymbol ( node . declaration , globals , node . declaration ) ;
278326 if ( symbol ) {
279327 symbol . exported = true ;
280328 } else if ( ! node . id ) {
281329 globals . ANONYMOUS_DEFAULT = node . declaration ;
282330 }
331+
283332 break ;
284- } case 'ExportNamedDeclaration' : {
333+ }
334+
335+ case 'ExportNamedDeclaration' : {
285336 if ( node . declaration ) {
286337 if ( node . declaration . type === 'VariableDeclaration' ) {
287338 mapVariables ( node . declaration , globals , opts , true ) ;
@@ -293,21 +344,30 @@ const mapVariables = function (node, globals, opt, isExport) {
293344 }
294345 }
295346 }
347+
296348 for ( const specifier of node . specifiers ) {
297349 mapVariables ( specifier , globals , opts ) ;
298350 }
351+
299352 break ;
300- } case 'ExportSpecifier' : {
353+ }
354+
355+ case 'ExportSpecifier' : {
301356 const symbol = getSymbol ( node . local , globals , globals ) ;
302357 /* istanbul ignore next */
303358 if ( symbol ) {
304359 symbol . exported = true ;
305360 }
361+
306362 break ;
307- } case 'ClassDeclaration' : {
363+ }
364+
365+ case 'ClassDeclaration' : {
308366 createSymbol ( node . id , globals , node . body , globals ) ;
309367 break ;
310- } default : {
368+ }
369+
370+ default : {
311371 /* istanbul ignore next */
312372 return false ;
313373 }
@@ -322,6 +382,7 @@ const findNode = function (node, block, cache) {
322382 if ( ! block || blockCache . includes ( block ) ) {
323383 return false ;
324384 }
385+
325386 blockCache = blockCache . slice ( ) ;
326387 blockCache . push ( block ) ;
327388
@@ -356,6 +417,7 @@ const getExportAncestor = function (nde) {
356417 if ( exportTypes . has ( node . type ) ) {
357418 return node ;
358419 }
420+
359421 node = node . parent ;
360422 }
361423
@@ -381,6 +443,7 @@ const isExportByAncestor = function (nde) {
381443 if ( ! canExportedByAncestorType . has ( nde . type ) ) {
382444 return false ;
383445 }
446+
384447 let node = nde . parent ;
385448 while ( node ) {
386449 if ( exportTypes . has ( node . type ) ) {
@@ -390,6 +453,7 @@ const isExportByAncestor = function (nde) {
390453 if ( ! canExportChildrenType . has ( node . type ) ) {
391454 return false ;
392455 }
456+
393457 node = node . parent ;
394458 }
395459
@@ -401,6 +465,7 @@ const findExportedNode = function (block, node, cache) {
401465 if ( block === null ) {
402466 return false ;
403467 }
468+
404469 const blockCache = cache || [ ] ;
405470 const { props} = block ;
406471 for ( const propval of Object . values ( props ) ) {
@@ -459,6 +524,7 @@ const parse = function (ast, node, opt) {
459524 globalVars . props . module . props . exports = createNode ( ) ;
460525 globalVars . props . exports = globalVars . props . module . props . exports ;
461526 }
527+
462528 if ( opts . initWindow ) {
463529 globalVars . props . window = createNode ( ) ;
464530 globalVars . props . window . special = true ;
0 commit comments