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 = {
27
27
value : string
28
28
}
29
29
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 ) + /
32
32
33
33
export function parse ( format : string ) : Array < Token > {
34
34
const tokens : Array < Token > = [ ]
Original file line number Diff line number Diff line change @@ -83,7 +83,7 @@ pathStateMachine[IN_DOUBLE_QUOTE] = {
83
83
* Check if an expression is a literal value.
84
84
*/
85
85
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 ? $ /
87
87
function isLiteral ( exp : string ) : boolean {
88
88
return literalValueRE . test ( exp )
89
89
}
@@ -253,15 +253,6 @@ export type PathValue = PathValueObject | PathValueArray | string | number | boo
253
253
export type PathValueObject = { [ key : string ] : PathValue }
254
254
export type PathValueArray = Array< PathValue >
255
255
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
-
265
256
export default class I18nPath {
266
257
_cache : Object
267
258
@@ -290,25 +281,22 @@ export default class I18nPath {
290
281
if ( ! isObject ( obj ) ) { return null }
291
282
292
283
const paths: Array< string > = this.parsePath(path)
293
- if (empty( paths) ) {
284
+ if (paths.length === 0 ) {
294
285
return null
295
286
} else {
296
287
const length : number = paths . length
297
- let ret : any = null
298
288
let last : any = obj
299
289
let i : number = 0
300
290
while ( i < length ) {
301
291
const value : any = last [ paths [ i ] ]
302
292
if ( value === undefined ) {
303
- last = null
304
- break
293
+ return null
305
294
}
306
295
last = value
307
296
i ++
308
297
}
309
298
310
- ret = last
311
- return ret
299
+ return last
312
300
}
313
301
}
314
302
}
You can’t perform that action at this time.
0 commit comments