File tree Expand file tree Collapse file tree 1 file changed +12
-25
lines changed Expand file tree Collapse file tree 1 file changed +12
-25
lines changed Original file line number Diff line number Diff line change @@ -173,35 +173,22 @@ const escapeIdentifier = function (str) {
173173}
174174
175175const escapeLiteral = function ( str ) {
176- let hasBackslash = false
177- let escaped = "'"
178-
179- if ( str == null ) {
180- return "''"
181- }
182-
183176 if ( typeof str !== 'string' ) {
184177 return "''"
185178 }
186-
187- for ( let i = 0 ; i < str . length ; i ++ ) {
188- const c = str [ i ]
189- if ( c === "'" ) {
190- escaped += c + c
191- } else if ( c === '\\' ) {
192- escaped += c + c
193- hasBackslash = true
194- } else {
195- escaped += c
196- }
197- }
198-
199- escaped += "'"
200-
201- if ( hasBackslash === true ) {
202- escaped = ' E' + escaped
179+ let hasBackslash = false
180+ let escaped = str
181+ . replace ( / \\ / g, ( ) => {
182+ hasBackslash = true
183+ return '\\\\'
184+ } )
185+ . replace ( / ' / g, "''" )
186+
187+ if ( hasBackslash ) {
188+ escaped = ` E'${ escaped } '`
189+ } else {
190+ escaped = `'${ escaped } '`
203191 }
204-
205192 return escaped
206193}
207194
You can’t perform that action at this time.
0 commit comments