File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11'use strict' ;
22
3+ // remove for file that only have 'not strict'
4+ function removeSelective ( path , t ) {
5+ if ( path . node . value . value === 'use strict' ) {
6+ const siblings = path . container // get all the sibilings (code in the same level) of 'use strict'
7+
8+ for ( const sibling of siblings ) {
9+ if ( t . isDirective ( sibling ) ) { // if the sibiling is a directive
10+ if ( sibling . value . value === 'not strict' ) { // check if its 'not strict'
11+ path . remove ( ) ; // remove 'use strict'
12+ break ;
13+ }
14+ }
15+ }
16+ }
17+ }
18+
19+ // remove for all files
20+ function removeAll ( path ) {
21+ if ( path . node . value . value === 'use strict' ) {
22+ path . node . value . value = 'not strict' // replace 'use strict' with 'not strict'
23+ }
24+ }
25+
26+
327module . exports = function ( { types : t } ) {
428 return {
529 name : 'transform-not-strict' ,
630 visitor : {
7- Directive ( path ) {
8- if ( path . node . value . value === 'use strict' ) {
9- const siblings = path . container // get all the sibilings (code in the same level) of 'use strict'
10-
11- for ( const sibling of siblings ) {
12- if ( t . isDirective ( sibling ) ) { // if the sibiling is a directive
13- if ( sibling . value . value === 'not strict' ) { // check if its 'not strict'
14- path . remove ( ) ; // remove 'use strict'
15- break ;
16- }
17- }
18- }
31+ Directive ( path , state ) {
32+ if ( state . opts . removeAll ) {
33+ removeAll ( path ) // remove for all files
34+ } else {
35+ removeSelective ( path , t ) // remove for file that only have 'not strict'
1936 }
2037 } ,
2138 } ,
You can’t perform that action at this time.
0 commit comments