1、项目:由umi脚手架搭建项目,兼容目标浏览器为默认,即
targets:{ chrome: 49, firefox: 64, safari: 10, edge: 13, ios: 10 }
2、问题:项目中用到sql-formatter对sql语句格式化,但是在firefox64版本浏览器中测试时会报错:SyntaxError:invalid identity excape in regular expression.
定位为sql-formatter中的函数。sql-formatter报错代码:
export function createWordRegex(specialChars = []) {
return new RegExp(
`^([\\p{Alphabetic}\\p{Mark}\\p{Decimal_Number}\\p{Connector_Punctuation}\\p{Join_Control}${specialChars.join(
''
)}]+)`,
'u'
);
}
查明应该为浏览器对RegExp: Unicode property escapes (\p{...})的兼容性问题,
https://caniuse.com/mdn-javascript_builtins_regexp_property_escapes
这个是caniuse网站对此特性的兼容性结果,firefox从78版本开始兼容。
3、提问:umi项目中已经配置了兼容firefox64版本,那为什么没有特性转化或者polyfill此特性。
而且查到babel针对此特性的转换也有实现,以下为babel的发版和提交何如记录网址:https://github.com/babel/babel/releases/tag/v7.8.8
Add support for Unicode 13 in regexps
想请教下,为什么firefox64版本还是不能通过测试。