File tree 2 files changed +241
-116
lines changed
2 files changed +241
-116
lines changed Original file line number Diff line number Diff line change @@ -7,10 +7,21 @@ function processOptions(source, options) {
7
7
options . search = new RegExp ( options . search , options . flags ) ;
8
8
}
9
9
10
- source = source . replace ( options . search , options . replace ) ;
10
+ newSource = source . replace ( options . search , options . replace ) ;
11
+ if ( options . strict === true && newSource === source ) {
12
+ throw new Error ( 'Cannot replace ' + options . search + ' → ' + options . replace ) ;
13
+ }
11
14
}
12
15
13
- return source ;
16
+ if ( options . strict === true && _ . isUndefined ( options . search ) ) {
17
+ throw new Error ( 'Cannot replace: search option is not defined → ' + JSON . stringify ( options ) ) ;
18
+ }
19
+
20
+ if ( options . strict === true && _ . isUndefined ( options . replace ) ) {
21
+ throw new Error ( 'Cannot replace: replace option is not defined → ' + JSON . stringify ( options ) ) ;
22
+ }
23
+
24
+ return newSource ;
14
25
}
15
26
16
27
module . exports = function ( source ) {
@@ -20,6 +31,7 @@ module.exports = function (source) {
20
31
21
32
if ( _ . isArray ( options . multiple ) ) {
22
33
options . multiple . forEach ( function ( suboptions ) {
34
+ suboptions . strict = ! _ . isUndefined ( suboptions . strict ) ? suboptions . strict : options . strict ;
23
35
source = processOptions ( source , suboptions ) ;
24
36
} ) ;
25
37
} else {
You can’t perform that action at this time.
0 commit comments