mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-10 02:47:50 +00:00
Expand stringToPath to matching more non-string expressions.
This commit is contained in:
@@ -7,8 +7,8 @@ const rePropName = RegExp(
|
|||||||
'[^.[\\]]+' + '|' +
|
'[^.[\\]]+' + '|' +
|
||||||
// Or match property names within brackets.
|
// Or match property names within brackets.
|
||||||
'\\[(?:' +
|
'\\[(?:' +
|
||||||
// Match numbers.
|
// Match a non-string expression.
|
||||||
'(-?\\d+(?:\\.\\d+)?)' + '|' +
|
'([^"\'].*)' + '|' +
|
||||||
// Or match strings (supports escaping characters).
|
// Or match strings (supports escaping characters).
|
||||||
'(["\'])((?:(?!\\2)[^\\\\]|\\\\.)*?)\\2' +
|
'(["\'])((?:(?!\\2)[^\\\\]|\\\\.)*?)\\2' +
|
||||||
')\\]'+ '|' +
|
')\\]'+ '|' +
|
||||||
@@ -28,8 +28,15 @@ const stringToPath = memoizeCapped(string => {
|
|||||||
if (reLeadingDot.test(string)) {
|
if (reLeadingDot.test(string)) {
|
||||||
result.push('')
|
result.push('')
|
||||||
}
|
}
|
||||||
string.replace(rePropName, (match, number, quote, string) => {
|
string.replace(rePropName, (match, expression, quote, string) => {
|
||||||
result.push(quote ? string.replace(reEscapeChar, '$1') : (number || match))
|
let key = match
|
||||||
|
if (quote) {
|
||||||
|
key = string.replace(reEscapeChar, '$1')
|
||||||
|
}
|
||||||
|
else if (expression) {
|
||||||
|
key = expression.trim()
|
||||||
|
}
|
||||||
|
result.push(key)
|
||||||
})
|
})
|
||||||
return result
|
return result
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user