This repository was archived by the owner on Dec 31, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +6
-18
lines changed
Expand file tree Collapse file tree 2 files changed +6
-18
lines changed Original file line number Diff line number Diff line change @@ -27,8 +27,8 @@ type Token = {
2727 value : string
2828}
2929
30- const RE_TOKEN_LIST_VALUE : RegExp = / ^ ( \d ) + /
31- const RE_TOKEN_NAMED_VALUE : RegExp = / ^ ( \w ) + /
30+ const RE_TOKEN_LIST_VALUE : RegExp = / ^ (?: \d ) + /
31+ const RE_TOKEN_NAMED_VALUE : RegExp = / ^ (?: \w ) + /
3232
3333export function parse ( format : string ) : Array < Token > {
3434 const tokens : Array < Token > = [ ]
Original file line number Diff line number Diff line change @@ -83,7 +83,7 @@ pathStateMachine[IN_DOUBLE_QUOTE] = {
8383 * Check if an expression is a literal value.
8484 */
8585
86- const literalValueRE : RegExp = / ^ \s ? ( t r u e | f a l s e | - ? [ \d . ] + | ' [ ^ ' ] * ' | " [ ^ " ] * " ) \s ? $ /
86+ const literalValueRE : RegExp = / ^ \s ? (?: t r u e | f a l s e | - ? [ \d . ] + | ' [ ^ ' ] * ' | " [ ^ " ] * " ) \s ? $ /
8787function isLiteral ( exp : string ) : boolean {
8888 return literalValueRE . test ( exp )
8989}
@@ -253,15 +253,6 @@ export type PathValue = PathValueObject | PathValueArray | string | number | boo
253253export type PathValueObject = { [ key : string ] : PathValue }
254254export type PathValueArray = Array< PathValue >
255255
256- function empty (target: any): boolean {
257- /* istanbul ignore else */
258- if ( Array . isArray ( target ) ) {
259- return target . length === 0
260- } else {
261- return false
262- }
263- }
264-
265256export default class I18nPath {
266257 _cache : Object
267258
@@ -290,25 +281,22 @@ export default class I18nPath {
290281 if ( ! isObject ( obj ) ) { return null }
291282
292283 const paths: Array< string > = this.parsePath(path)
293- if (empty( paths) ) {
284+ if (paths.length === 0 ) {
294285 return null
295286 } else {
296287 const length : number = paths . length
297- let ret : any = null
298288 let last : any = obj
299289 let i : number = 0
300290 while ( i < length ) {
301291 const value : any = last [ paths [ i ] ]
302292 if ( value === undefined ) {
303- last = null
304- break
293+ return null
305294 }
306295 last = value
307296 i ++
308297 }
309298
310- ret = last
311- return ret
299+ return last
312300 }
313301 }
314302}
You can’t perform that action at this time.
0 commit comments