From 9f7816f71ec96a1b966095a9702f61f75737cff8 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Mon, 17 Oct 2011 01:09:06 -0500 Subject: [PATCH] no expect returns --- lib/json.js | 47 +++++++++++++++++++++++++---------------------- 1 file changed, 25 insertions(+), 22 deletions(-) diff --git a/lib/json.js b/lib/json.js index 4e37fa2..9a13ee1 100644 --- a/lib/json.js +++ b/lib/json.js @@ -75,9 +75,11 @@ Parser.prototype.end = function(data) { }; Parser.prototype._expect = function(ch, ex) { - if (ch !== ex) throw new - Error('Unexpected `' + ch + '`.' - + (ex ? ' Expected: `' + ex + '`.' : '')); + if (ch !== ex) { + throw new + Error('Unexpected `' + ch + '`.' + + (ex ? ' Expected: `' + ex + '`.' : '')); + } }; Parser.prototype._parse = function(data) { @@ -95,7 +97,7 @@ Parser.prototype._parse = function(data) { this.emit('object start'); break; default: - return this._expect(ch); + this._expect(ch); } break; case '}': @@ -114,7 +116,7 @@ Parser.prototype._parse = function(data) { this.emit('object end'); break; default: - return this._expect(ch); + this._expect(ch); } break; case '[': @@ -123,7 +125,7 @@ Parser.prototype._parse = function(data) { this.emit('array start'); break; default: - return this._expect(ch); + this._expect(ch); } break; case ']': @@ -142,7 +144,7 @@ Parser.prototype._parse = function(data) { this.emit('array end'); break; default: - return this._expect(ch); + this._expect(ch); } break; case '"': @@ -156,13 +158,12 @@ Parser.prototype._parse = function(data) { this._escapeNext = 0; } else { this.state = 'value'; - // hack for now, or else empty strings wont work - // empty strings need to be truthy + // hack for empty strings if (!this.value) this.value = ' '; } break; default: - return this._expect(ch); + this._expect(ch); } break; case ',': @@ -179,7 +180,7 @@ Parser.prototype._parse = function(data) { } break; default: - return this._expect(ch); + this._expect(ch); } break; case ':': @@ -189,7 +190,7 @@ Parser.prototype._parse = function(data) { this.value = ''; break; default: - return this._expect(ch); + this._expect(ch); } break; case '\\': @@ -202,7 +203,7 @@ Parser.prototype._parse = function(data) { } break; default: - return this._expect(ch); + this._expect(ch); } break; case '-': @@ -220,7 +221,7 @@ Parser.prototype._parse = function(data) { switch (this.state) { case 'unicode': if (ch === '.' || ch === '-') { - return this._expect(ch); + this._expect(ch); } this.unicode += ch; if (this.unicode.length === 4) { @@ -232,7 +233,7 @@ Parser.prototype._parse = function(data) { case 'value': if (ch === '.') { // json doesnt have .x numbers - return this._expect(ch); + this._expect(ch); } this.state = 'number'; this.value += ch; @@ -240,7 +241,7 @@ Parser.prototype._parse = function(data) { case 'number': if (ch === '-') { // json doesnt have expressions - return this._expect(ch); + this._expect(ch); } this.value += ch; break; @@ -248,7 +249,7 @@ Parser.prototype._parse = function(data) { this.value += ch; break; default: - return this._expect(ch); + this._expect(ch); } break; case 'u': @@ -276,7 +277,7 @@ Parser.prototype._parse = function(data) { this.state = ch; break; default: - return this._expect(ch); + this._expect(ch); } break; case 'n': @@ -326,14 +327,14 @@ Parser.prototype._parse = function(data) { this.value += ch; break; default: - return this._expect(ch); + this._expect(ch); } break; default: switch (this.state) { case 'number': if (ch > ' ') { - return this._expect(ch); + this._expect(ch); } this.state = 'value'; this.emit('number', +this.value); @@ -342,11 +343,13 @@ Parser.prototype._parse = function(data) { case 'string': this.value += ch; break; - default: + case 'value': if (ch > ' ') { - return this._expect(ch); + this._expect(ch); } break; + default: + this._expect(ch); } break; }