diff --git a/src/format.js b/src/format.js index 64335360c..5b26d11f0 100644 --- a/src/format.js +++ b/src/format.js @@ -27,8 +27,8 @@ type Token = { value: string } -const RE_TOKEN_LIST_VALUE: RegExp = /^(\d)+/ -const RE_TOKEN_NAMED_VALUE: RegExp = /^(\w)+/ +const RE_TOKEN_LIST_VALUE: RegExp = /^(?:\d)+/ +const RE_TOKEN_NAMED_VALUE: RegExp = /^(?:\w)+/ export function parse (format: string): Array { const tokens: Array = [] diff --git a/src/path.js b/src/path.js index 9337ae432..5976e82fc 100644 --- a/src/path.js +++ b/src/path.js @@ -83,7 +83,7 @@ pathStateMachine[IN_DOUBLE_QUOTE] = { * Check if an expression is a literal value. */ -const literalValueRE: RegExp = /^\s?(true|false|-?[\d.]+|'[^']*'|"[^"]*")\s?$/ +const literalValueRE: RegExp = /^\s?(?:true|false|-?[\d.]+|'[^']*'|"[^"]*")\s?$/ function isLiteral (exp: string): boolean { return literalValueRE.test(exp) } @@ -253,15 +253,6 @@ export type PathValue = PathValueObject | PathValueArray | string | number | boo export type PathValueObject = { [key: string]: PathValue } export type PathValueArray = Array -function empty (target: any): boolean { - /* istanbul ignore else */ - if (Array.isArray(target)) { - return target.length === 0 - } else { - return false - } -} - export default class I18nPath { _cache: Object @@ -290,25 +281,22 @@ export default class I18nPath { if (!isObject(obj)) { return null } const paths: Array = this.parsePath(path) - if (empty(paths)) { + if (paths.length === 0) { return null } else { const length: number = paths.length - let ret: any = null let last: any = obj let i: number = 0 while (i < length) { const value: any = last[paths[i]] if (value === undefined) { - last = null - break + return null } last = value i++ } - ret = last - return ret + return last } } }