Fix for safari, removing all usage of regex lookbehinds.
This commit is contained in:
parent
b421ddf60b
commit
676ec02380
|
@ -41,8 +41,6 @@
|
||||||
"@spectrum-css/vars": "^3.0.1",
|
"@spectrum-css/vars": "^3.0.1",
|
||||||
"apexcharts": "^3.22.1",
|
"apexcharts": "^3.22.1",
|
||||||
"dayjs": "^1.10.5",
|
"dayjs": "^1.10.5",
|
||||||
"fs-extra": "^8.1.0",
|
|
||||||
"jsdom": "^16.0.1",
|
|
||||||
"postcss": "^8.2.10",
|
"postcss": "^8.2.10",
|
||||||
"rollup": "^2.44.0",
|
"rollup": "^2.44.0",
|
||||||
"rollup-plugin-json": "^4.0.0",
|
"rollup-plugin-json": "^4.0.0",
|
||||||
|
|
|
@ -3,7 +3,7 @@ const { registerAll, registerMinimum } = require("./helpers/index")
|
||||||
const processors = require("./processors")
|
const processors = require("./processors")
|
||||||
const { atob, btoa } = require("./utilities")
|
const { atob, btoa } = require("./utilities")
|
||||||
const manifest = require("../manifest.json")
|
const manifest = require("../manifest.json")
|
||||||
const { FIND_HBS_REGEX, FIND_DOUBLE_HBS_REGEX } = require("./utilities")
|
const { FIND_HBS_REGEX, findDoubleHbsInstances } = require("./utilities")
|
||||||
|
|
||||||
const hbsInstance = handlebars.create()
|
const hbsInstance = handlebars.create()
|
||||||
registerAll(hbsInstance)
|
registerAll(hbsInstance)
|
||||||
|
@ -135,8 +135,7 @@ module.exports.processStringSync = (string, context, opts) => {
|
||||||
* @param string the string to have double HBS statements converted to triple.
|
* @param string the string to have double HBS statements converted to triple.
|
||||||
*/
|
*/
|
||||||
module.exports.disableEscaping = string => {
|
module.exports.disableEscaping = string => {
|
||||||
let regexp = new RegExp(FIND_DOUBLE_HBS_REGEX)
|
const matches = findDoubleHbsInstances(string)
|
||||||
const matches = string.match(regexp)
|
|
||||||
if (matches == null) {
|
if (matches == null) {
|
||||||
return string
|
return string
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,25 @@
|
||||||
const ALPHA_NUMERIC_REGEX = /^[A-Za-z0-9]+$/g
|
const ALPHA_NUMERIC_REGEX = /^[A-Za-z0-9]+$/g
|
||||||
|
|
||||||
module.exports.FIND_HBS_REGEX = /{{([^{].*?)}}/g
|
module.exports.FIND_HBS_REGEX = /{{([^{].*?)}}/g
|
||||||
module.exports.FIND_DOUBLE_HBS_REGEX = /(?<!{){{[^{}]+}}(?!})/g
|
module.exports.FIND_TRIPLE_HBS_REGEX = /{{{([^{].*?)}}}/g
|
||||||
|
|
||||||
|
// originally this could be done with a single regex using look behinds
|
||||||
|
// but safari does not support this feature
|
||||||
|
// original regex: /(?<!{){{[^{}]+}}(?!})/g
|
||||||
|
module.exports.findDoubleHbsInstances = string => {
|
||||||
|
let copied = string
|
||||||
|
const doubleRegex = new RegExp(exports.FIND_HBS_REGEX)
|
||||||
|
const regex = new RegExp(exports.FIND_TRIPLE_HBS_REGEX)
|
||||||
|
const tripleMatches = copied.match(regex)
|
||||||
|
// remove triple braces
|
||||||
|
if (tripleMatches) {
|
||||||
|
tripleMatches.forEach(match => {
|
||||||
|
copied = copied.replace(match, "")
|
||||||
|
})
|
||||||
|
}
|
||||||
|
const doubleMatches = copied.match(doubleRegex)
|
||||||
|
return doubleMatches ? doubleMatches : []
|
||||||
|
}
|
||||||
|
|
||||||
module.exports.isAlphaNumeric = char => {
|
module.exports.isAlphaNumeric = char => {
|
||||||
return char.match(ALPHA_NUMERIC_REGEX)
|
return char.match(ALPHA_NUMERIC_REGEX)
|
||||||
|
|
Loading…
Reference in New Issue