be62e3b841010b4ed7f33411b24bfc41c419a7fe42b3c5b5e4832be7268735a30b9f9deb37525e76ff3e9a69d32fab76cedca1007fdfa4d0ff69346576bea6 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /* @flow */
  2. /**
  3. * unicode letters used for parsing html tags, component names and property paths.
  4. * using https://www.w3.org/TR/html53/semantics-scripting.html#potentialcustomelementname
  5. * skipping \u10000-\uEFFFF due to it freezing up PhantomJS
  6. */
  7. export const unicodeRegExp = /a-zA-Z\u00B7\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u037D\u037F-\u1FFF\u200C-\u200D\u203F-\u2040\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD/
  8. /**
  9. * Check if a string starts with $ or _
  10. */
  11. export function isReserved (str: string): boolean {
  12. const c = (str + '').charCodeAt(0)
  13. return c === 0x24 || c === 0x5F
  14. }
  15. /**
  16. * Define a property.
  17. */
  18. export function def (obj: Object, key: string, val: any, enumerable?: boolean) {
  19. Object.defineProperty(obj, key, {
  20. value: val,
  21. enumerable: !!enumerable,
  22. writable: true,
  23. configurable: true
  24. })
  25. }
  26. /**
  27. * Parse simple path.
  28. */
  29. const bailRE = new RegExp(`[^${unicodeRegExp.source}.$_\\d]`)
  30. export function parsePath (path: string): any {
  31. if (bailRE.test(path)) {
  32. return
  33. }
  34. const segments = path.split('.')
  35. return function (obj) {
  36. for (let i = 0; i < segments.length; i++) {
  37. if (!obj) return
  38. obj = obj[segments[i]]
  39. }
  40. return obj
  41. }
  42. }