11'use strict' ;
22
33// remove for file that only have 'not strict'
4- function removeSelective ( path , t ) {
4+ function removeSelective ( path , t , directiveTriggers , commentTriggers ) {
55 if ( path . node . value . value === 'use strict' ) {
66 const siblings = path . container // get all the sibilings (code in the same level) of 'use strict'
77
@@ -12,6 +12,37 @@ function removeSelective(path, t) {
1212 break ;
1313 }
1414 }
15+
16+ // remove based on comment triggers
17+ if ( commentTriggers . length ) {
18+ if ( sibling . leadingComments ) {
19+ let foundInLeadingComment = false ;
20+ for ( const leadingComment of sibling . leadingComments ) {
21+ if ( commentTriggers . includes ( leadingComment . value . trim ( ) ) ) {
22+ path . remove ( ) ; // remove 'use strict'
23+ foundInLeadingComment = true ;
24+ break ;
25+ }
26+ }
27+ if ( foundInLeadingComment ) {
28+ break ;
29+ }
30+ }
31+ if ( sibling . trailingComments ) {
32+ let foundInTrailingComment = false ;
33+ for ( const trailingComment of sibling . trailingComments ) {
34+ if ( commentTriggers . includes ( trailingComment . value . trim ( ) ) ) {
35+ path . remove ( ) ; // remove 'use strict'
36+ foundInTrailingComment = true ;
37+ break ;
38+ }
39+ }
40+ if ( foundInTrailingComment ) {
41+ break ;
42+ }
43+ }
44+ }
45+
1546 }
1647 }
1748}
@@ -32,7 +63,7 @@ module.exports = function ({ types: t }) {
3263 if ( state . opts . removeAll ) {
3364 removeAll ( path ) // remove for all files
3465 } else {
35- removeSelective ( path , t ) // remove for file that only have 'not strict'
66+ removeSelective ( path , t , state . opts . directiveTriggers , state . opts . commentTriggers ) // remove for file that only have 'not strict'
3667 }
3768 } ,
3869 } ,
0 commit comments