fix(runtime): 由于在一些js引擎(主要是react-native hemers)中不支持正则表达式的命名捕获组从而导致运行时不可用,废弃命名捕获组
This commit is contained in:
parent
fae66ba0a6
commit
ad679f6942
@ -165,6 +165,7 @@ function getNestingParamsRegex(...tags){
|
|||||||
// const formatterParamsRegex = /((([\'\"])(.*?)\3)|(\{.*?\})|(\[.*?\])|([\d]+\.?[\d]?)|((true|false|null)(?=[,\b\s]))|([\w\.]+)|((?<=,)\s*(?=,)))(?<=\s*[,\)]?\s*)/g;
|
// const formatterParamsRegex = /((([\'\"])(.*?)\3)|(\{.*?\})|(\[.*?\])|([\d]+\.?[\d]?)|((true|false|null)(?=[,\b\s]))|([\w\.]+)|((?<=,)\s*(?=,)))(?<=\s*[,\)]?\s*)/g;
|
||||||
|
|
||||||
// 支持解析嵌套的{}和[]参数, 前提是:字符串需要经addTagHelperFlags操作后,会在{}[]等位置添加辅助字符
|
// 支持解析嵌套的{}和[]参数, 前提是:字符串需要经addTagHelperFlags操作后,会在{}[]等位置添加辅助字符
|
||||||
|
// 解析嵌套的{}和[]参数基本原理:在{}[]等位置添加辅助字符,然后使用正则表达式匹配,匹配到的字符串中包含辅助字符,然后再去除辅助字符
|
||||||
const formatterNestingParamsRegex = String.raw`((([\'\"])(.*?)\3))|__TAG_REGEXP__([\d]+\.?[\d]?)|((true|false|null)(?=[,\b\s]))|([\w\.]+)|((?<=,)\s*(?=,))(?<=\s*[,\)]?\s*)`
|
const formatterNestingParamsRegex = String.raw`((([\'\"])(.*?)\3))|__TAG_REGEXP__([\d]+\.?[\d]?)|((true|false|null)(?=[,\b\s]))|([\w\.]+)|((?<=,)\s*(?=,))(?<=\s*[,\)]?\s*)`
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -33,7 +33,10 @@ const { parseFormatters } = require("./formatter")
|
|||||||
|
|
||||||
// 用来提取字符里面的插值变量参数 , 支持管道符 { var | formatter | formatter }
|
// 用来提取字符里面的插值变量参数 , 支持管道符 { var | formatter | formatter }
|
||||||
// 支持参数: { var | formatter(x,x,..) | formatter }
|
// 支持参数: { var | formatter(x,x,..) | formatter }
|
||||||
let varWithPipeRegexp = /\{\s*(?<varname>\w+)?(?<formatters>(\s*\|\s*\w*(\(.*\)){0,1}\s*)*)\s*\}/g;
|
// v1 采用命名捕获组
|
||||||
|
//let varWithPipeRegexp = /\{\s*(?<varname>\w+)?(?<formatters>(\s*\|\s*\w*(\(.*\)){0,1}\s*)*)\s*\}/g;
|
||||||
|
// v2: 由于一些js引擎(如react-native Hermes )不支持命名捕获组而导致运行时不能使用,所以此处移除命名捕获组
|
||||||
|
let varWithPipeRegexp = /\{\s*(\w+)?((\s*\|\s*\w*(\(.*\)){0,1}\s*)*)\s*\}/g;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 考虑到通过正则表达式进行插值的替换可能较慢
|
* 考虑到通过正则表达式进行插值的替换可能较慢
|
||||||
@ -102,9 +105,9 @@ function forEachInterpolatedVars(str, replacer, options = {}) {
|
|||||||
let opts = Object.assign({replaceAll: true },options);
|
let opts = Object.assign({replaceAll: true },options);
|
||||||
varWithPipeRegexp.lastIndex = 0;
|
varWithPipeRegexp.lastIndex = 0;
|
||||||
while ((matched = varWithPipeRegexp.exec(result)) !== null) {
|
while ((matched = varWithPipeRegexp.exec(result)) !== null) {
|
||||||
const varname = matched.groups.varname || "";
|
const varname = matched[1] || "";
|
||||||
// 解析格式化器和参数 = [<formatterName>,[<formatterName>,[<arg>,<arg>,...]]]
|
// 解析格式化器和参数 = [<formatterName>,[<formatterName>,[<arg>,<arg>,...]]]
|
||||||
const formatters = parseFormatters(matched.groups.formatters);
|
const formatters = parseFormatters(matched[2] || "");
|
||||||
if (isFunction(replacer)) {
|
if (isFunction(replacer)) {
|
||||||
try {
|
try {
|
||||||
const finalValue = replacer(varname, formatters, matched[0]);
|
const finalValue = replacer(varname, formatters, matched[0]);
|
||||||
|
22
pnpm-lock.yaml
generated
22
pnpm-lock.yaml
generated
@ -301,10 +301,12 @@ importers:
|
|||||||
fs-extra: ^10.0.1
|
fs-extra: ^10.0.1
|
||||||
semver: ^7.3.7
|
semver: ^7.3.7
|
||||||
shelljs: ^0.8.5
|
shelljs: ^0.8.5
|
||||||
|
string.prototype.replaceall: ^1.0.7
|
||||||
dependencies:
|
dependencies:
|
||||||
fs-extra: 10.1.0
|
fs-extra: 10.1.0
|
||||||
semver: 7.3.8
|
semver: 7.3.8
|
||||||
shelljs: 0.8.5
|
shelljs: 0.8.5
|
||||||
|
string.prototype.replaceall: 1.0.7
|
||||||
|
|
||||||
packages/vite:
|
packages/vite:
|
||||||
specifiers:
|
specifiers:
|
||||||
@ -8882,13 +8884,6 @@ packages:
|
|||||||
resolution: {integrity: sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg==}
|
resolution: {integrity: sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg==}
|
||||||
engines: {node: 6.* || 8.* || >= 10.*}
|
engines: {node: 6.* || 8.* || >= 10.*}
|
||||||
|
|
||||||
/get-intrinsic/1.1.2:
|
|
||||||
resolution: {integrity: sha512-Jfm3OyCxHh9DJyc28qGk+JmfkpO41A4XkneDSujN9MDXrm4oDKdHvndhZ2dN94+ERNfkYJWDclW6k2L/ZGHjXA==}
|
|
||||||
dependencies:
|
|
||||||
function-bind: 1.1.1
|
|
||||||
has: 1.0.3
|
|
||||||
has-symbols: 1.0.3
|
|
||||||
|
|
||||||
/get-intrinsic/1.2.0:
|
/get-intrinsic/1.2.0:
|
||||||
resolution: {integrity: sha512-L049y6nFOuom5wGyRc3/gdTLO94dySVKRACj1RmJZBQXlbTMhtNIgkWkUHq+jYmZvKf14EW1EoJnnjbmoHij0Q==}
|
resolution: {integrity: sha512-L049y6nFOuom5wGyRc3/gdTLO94dySVKRACj1RmJZBQXlbTMhtNIgkWkUHq+jYmZvKf14EW1EoJnnjbmoHij0Q==}
|
||||||
dependencies:
|
dependencies:
|
||||||
@ -12224,15 +12219,6 @@ packages:
|
|||||||
dependencies:
|
dependencies:
|
||||||
isobject: 3.0.1
|
isobject: 3.0.1
|
||||||
|
|
||||||
/object.assign/4.1.2:
|
|
||||||
resolution: {integrity: sha512-ixT2L5THXsApyiUPYKmW+2EHpXXe5Ii3M+f4e+aJFAHao5amFRW6J0OO6c/LU8Be47utCx2GL89hxGB6XSmKuQ==}
|
|
||||||
engines: {node: '>= 0.4'}
|
|
||||||
dependencies:
|
|
||||||
call-bind: 1.0.2
|
|
||||||
define-properties: 1.1.4
|
|
||||||
has-symbols: 1.0.3
|
|
||||||
object-keys: 1.1.1
|
|
||||||
|
|
||||||
/object.assign/4.1.4:
|
/object.assign/4.1.4:
|
||||||
resolution: {integrity: sha512-1mxKf0e58bvyjSCtKYY4sRe9itRk3PJpquJOjeIkz885CczcI4IvJJDLPS72oowuSh+pBxUFROpX+TU++hxhZQ==}
|
resolution: {integrity: sha512-1mxKf0e58bvyjSCtKYY4sRe9itRk3PJpquJOjeIkz885CczcI4IvJJDLPS72oowuSh+pBxUFROpX+TU++hxhZQ==}
|
||||||
engines: {node: '>= 0.4'}
|
engines: {node: '>= 0.4'}
|
||||||
@ -15472,7 +15458,7 @@ packages:
|
|||||||
resolution: {integrity: sha512-q5XPytqFEIKHkGdiMIrY10mvLRvnQh42/+GoBlFW3b2LXLE2xxJpZFdm94we0BaoV3RwJyGqg5wS7epxTv0Zvw==}
|
resolution: {integrity: sha512-q5XPytqFEIKHkGdiMIrY10mvLRvnQh42/+GoBlFW3b2LXLE2xxJpZFdm94we0BaoV3RwJyGqg5wS7epxTv0Zvw==}
|
||||||
dependencies:
|
dependencies:
|
||||||
call-bind: 1.0.2
|
call-bind: 1.0.2
|
||||||
get-intrinsic: 1.1.2
|
get-intrinsic: 1.2.0
|
||||||
object-inspect: 1.12.2
|
object-inspect: 1.12.2
|
||||||
|
|
||||||
/signal-exit/3.0.7:
|
/signal-exit/3.0.7:
|
||||||
@ -16936,7 +16922,7 @@ packages:
|
|||||||
is-valid-glob: 1.0.0
|
is-valid-glob: 1.0.0
|
||||||
lazystream: 1.0.1
|
lazystream: 1.0.1
|
||||||
lead: 1.0.0
|
lead: 1.0.0
|
||||||
object.assign: 4.1.2
|
object.assign: 4.1.4
|
||||||
pumpify: 1.5.1
|
pumpify: 1.5.1
|
||||||
readable-stream: 2.3.7
|
readable-stream: 2.3.7
|
||||||
remove-bom-buffer: 3.0.0
|
remove-bom-buffer: 3.0.0
|
||||||
|
Loading…
x
Reference in New Issue
Block a user