From 4356e2437cf5795231bd48c0a9768679e3519126 Mon Sep 17 00:00:00 2001 From: Denis Pushkarev Date: Wed, 22 Feb 2023 06:32:14 +0700 Subject: [PATCH] simplify code with early exit --- packages/core-js/modules/esnext.json.parse.js | 28 ++++++------------- 1 file changed, 9 insertions(+), 19 deletions(-) diff --git a/packages/core-js/modules/esnext.json.parse.js b/packages/core-js/modules/esnext.json.parse.js index d7549d0704a7..e418d7c4a7fc 100644 --- a/packages/core-js/modules/esnext.json.parse.js +++ b/packages/core-js/modules/esnext.json.parse.js @@ -105,31 +105,21 @@ Context.prototype = { var i = this.skip(IS_WHITESPACE, this.index); var fork = this.fork(i); var chr = at(source, i); - var result; - if (exec(IS_NUMBER_START, chr)) result = fork.number(); - else switch (chr) { + if (exec(IS_NUMBER_START, chr)) return fork.number(); + switch (chr) { case '{': - result = fork.object(); - break; + return fork.object(); case '[': - result = fork.array(); - break; + return fork.array(); case '"': - result = fork.string(); - break; + return fork.string(); case 't': - result = fork.keyword(true); - break; + return fork.keyword(true); case 'f': - result = fork.keyword(false); - break; + return fork.keyword(false); case 'n': - result = fork.keyword(null); - break; - default: - throw SyntaxError('Unexpected character: "' + chr + '" at: ' + i); - } - return result; + return fork.keyword(null); + } throw SyntaxError('Unexpected character: "' + chr + '" at: ' + i); }, node: function (type, value, start, end, nodes) { return new Node(value, end, type ? null : slice(this.source, start, end), nodes);