fix: add error catch for browsers dont support positive lookbehind

This commit is contained in:
Sivan 2020-03-04 23:08:13 +08:00
parent 06631502ee
commit 5f105fe5d9
2 changed files with 14 additions and 0 deletions

View file

@ -688,6 +688,13 @@
class Heti {
constructor (rootSelector) {
try {
new RegExp(`(?<=\d)\d`, 'g').test('');
} catch (err) {
console.warn(err.name, '浏览器尚未实现 RegExp positive lookbehind');
return
}
this.rootSelector = rootSelector || '.heti';
this.REG_FULL = new RegExp(`(?<=[${CJK}])( *[${ANS}]+(?: +[${ANS}]+)* *)(?=[${CJK}])`, 'g');
this.REG_START = new RegExp(`([${ANS}]+(?: +[${ANS}]+)* *)(?=[${CJK}])`, 'g');

View file

@ -44,6 +44,13 @@ const hasOwn = {}.hasOwnProperty
class Heti {
constructor (rootSelector) {
try {
new RegExp(`(?<=\d)\d`, 'g').test('')
} catch (err) {
console.warn(err.name, '浏览器尚未实现 RegExp positive lookbehind')
return
}
this.rootSelector = rootSelector || '.heti'
this.REG_FULL = new RegExp(`(?<=[${CJK}])( *[${ANS}]+(?: +[${ANS}]+)* *)(?=[${CJK}])`, 'g')
this.REG_START = new RegExp(`([${ANS}]+(?: +[${ANS}]+)* *)(?=[${CJK}])`, 'g')