11module . exports = safe
22
3- var compilePattern = require ( './compile-pattern' )
3+ var patternCompile = require ( './pattern-compile' )
4+ var patternInScope = require ( './pattern-in-scope' )
45
56function safe ( context , input , config ) {
67 var value = ( config . before || '' ) + ( input || '' ) + ( config . after || '' )
@@ -20,14 +21,11 @@ function safe(context, input, config) {
2021 while ( ++ index < context . unsafe . length ) {
2122 pattern = context . unsafe [ index ]
2223
23- if (
24- ! inScope ( context . stack , pattern . inConstruct , true ) ||
25- inScope ( context . stack , pattern . notInConstruct )
26- ) {
24+ if ( ! patternInScope ( context . stack , pattern ) ) {
2725 continue
2826 }
2927
30- expression = compilePattern ( pattern )
28+ expression = patternCompile ( pattern )
3129
3230 while ( ( match = expression . exec ( value ) ) ) {
3331 // Often, patterns which depend on a character before or after it, such
@@ -118,28 +116,6 @@ function safe(context, input, config) {
118116 return result . join ( '' )
119117}
120118
121- function inScope ( stack , list , none ) {
122- var index
123-
124- if ( ! list ) {
125- return none
126- }
127-
128- if ( typeof list === 'string' ) {
129- list = [ list ]
130- }
131-
132- index = - 1
133-
134- while ( ++ index < list . length ) {
135- if ( stack . indexOf ( list [ index ] ) !== - 1 ) {
136- return true
137- }
138- }
139-
140- return false
141- }
142-
143119function numerical ( a , b ) {
144120 return a - b
145121}
0 commit comments