Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
support backslash escaping, retain exact newline escaping (#3638)
- Loading branch information
1 parent
08a6255
commit 6d977a3
Showing
9 changed files
with
53 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,7 @@ | ||
const quoteNewlineRegEx = /['\r\n\u2028\u2029]/g; | ||
const replacements = { | ||
'\n': '\\n', | ||
'\r': '\\r', | ||
"'": "\\'", | ||
'\u2028': '\\u2028', | ||
'\u2029': '\\u2029' | ||
}; | ||
|
||
const needsEscapeRegEx = /[\\'\r\n\u2028\u2029]/; | ||
const quoteNewlineRegEx = /(['\r\n\u2028\u2029])/g; | ||
const backSlashRegEx = /\\/g; | ||
export function escapeId(id: string) { | ||
return id.replace(quoteNewlineRegEx, match => replacements[match as keyof typeof replacements]); | ||
if (!id.match(needsEscapeRegEx)) return id; | ||
return id.replace(backSlashRegEx, '\\\\').replace(quoteNewlineRegEx, '\\$1'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
(function (quoted_____external1, quoted_____external2) { | ||
(function (quoted_____external1, quoted_____external2, Path_js) { | ||
'use strict'; | ||
|
||
console.log(quoted_____external1.foo, quoted_____external2.bar); | ||
console.log(quoted_____external1.foo, quoted_____external2.bar, Path_js.baz); | ||
|
||
}(quotedExternal1, quotedExternal2)); | ||
}(quotedExternal1, quotedExternal2, quotedExternal3)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
import { foo } from 'external1'; | ||
import { bar } from 'external2'; | ||
console.log(foo, bar); | ||
import { baz } from 'external3'; | ||
console.log(foo, bar, baz); |