fix(compiler-core): improve the isMemberExpression function (#3675)

This commit is contained in:
HcySunYang
2021-05-28 09:07:26 +08:00
committed by GitHub
parent 1ff06376ff
commit 9b2e894017
2 changed files with 27 additions and 3 deletions

View File

@@ -56,10 +56,14 @@ const nonIdentifierRE = /^\d|[^\$\w]/
export const isSimpleIdentifier = (name: string): boolean =>
!nonIdentifierRE.test(name)
const memberExpRE = /^[A-Za-z_$\xA0-\uFFFF][\w$\xA0-\uFFFF]*(?:\s*\.\s*[A-Za-z_$\xA0-\uFFFF][\w$\xA0-\uFFFF]*|\[[^\]]+\])*$/
const memberExpRE = /^[A-Za-z_$\xA0-\uFFFF][\w$\xA0-\uFFFF]*(?:\s*\.\s*[A-Za-z_$\xA0-\uFFFF][\w$\xA0-\uFFFF]*|\[(.+)\])*$/
export const isMemberExpression = (path: string): boolean => {
if (!path) return false
return memberExpRE.test(path.trim())
const matched = memberExpRE.exec(path.trim())
if (!matched) return false
if (!matched[1]) return true
if (!/[\[\]]/.test(matched[1])) return true
return isMemberExpression(matched[1].trim())
}
export function getInnerRange(