diff options
author | Yusuke Sakurai <kerokerokerop@gmail.com> | 2020-02-09 05:15:59 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-08 14:15:59 -0600 |
commit | a4bb8bab44cc778e6e455f19fdae9f3e4acc809b (patch) | |
tree | dcd78cd45f493588b04d3949aeb7c57b8d53d92e /std/encoding/toml.ts | |
parent | cdba5ab6fc633606aaa6f95d0825832c3ac6fe5c (diff) |
remove non-null assertion operator from std (part2) (#3927)
Diffstat (limited to 'std/encoding/toml.ts')
-rw-r--r-- | std/encoding/toml.ts | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/std/encoding/toml.ts b/std/encoding/toml.ts index 6af31a1a1..53b907fbf 100644 --- a/std/encoding/toml.ts +++ b/std/encoding/toml.ts @@ -1,6 +1,7 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. import { deepAssign } from "../util/deep_assign.ts"; import { pad } from "../strings/pad.ts"; +import { assert } from "../testing/asserts.ts"; class KeyValuePair { constructor(public key: string, public value: unknown) {} @@ -138,15 +139,16 @@ class Parser { } } _groupToOutput(): void { - const arrProperty = this.context - .currentGroup!.name.replace(/"/g, "") + assert(this.context.currentGroup != null, "currentGroup must be set"); + const arrProperty = this.context.currentGroup.name + .replace(/"/g, "") .replace(/'/g, "") .split("."); let u = {}; - if (this.context.currentGroup!.type === "array") { - u = this._unflat(arrProperty, this.context.currentGroup!.arrValues); + if (this.context.currentGroup.type === "array") { + u = this._unflat(arrProperty, this.context.currentGroup.arrValues); } else { - u = this._unflat(arrProperty, this.context.currentGroup!.objValues); + u = this._unflat(arrProperty, this.context.currentGroup.objValues); } deepAssign(this.context.output, u); delete this.context.currentGroup; @@ -170,10 +172,14 @@ class Parser { } let type; - let name = line.match(captureReg)![1]; + let m = line.match(captureReg); + assert(m != null, "line mut be matched"); + let name = m[1]; if (name.match(/\[.*\]/)) { type = "array"; - name = name.match(captureReg)![1]; + m = name.match(captureReg); + assert(m != null, "name must be matched"); + name = m[1]; } else { type = "object"; } |