From 2ec18009695afb7ccbc9798f00f5940a5f0b692a Mon Sep 17 00:00:00 2001 From: Federico Date: Wed, 23 Sep 2020 20:17:02 -0500 Subject: [PATCH 1/4] `no-reduce` --- lib/command.js | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/lib/command.js b/lib/command.js index 871a314bc6..016a4e8b99 100644 --- a/lib/command.js +++ b/lib/command.js @@ -9,27 +9,24 @@ const joinCommand = (file, args = []) => { return [file, ...args].join(' '); }; -// Allow spaces to be escaped by a backslash if not meant as a delimiter const handleEscaping = (tokens, token, index) => { - if (index === 0) { - return [token]; - } - - const previousToken = tokens[tokens.length - 1]; - - if (previousToken.endsWith('\\')) { - return [...tokens.slice(0, -1), `${previousToken.slice(0, -1)} ${token}`]; - } - - return [...tokens, token]; }; // Handle `execa.command()` -const parseCommand = command => { - return command - .trim() - .split(SPACES_REGEXP) - .reduce(handleEscaping, []); +const parseCommand = command => {) + const tokens = []; + for (const token of command.trim().split(SPACES_REGEXP)) { + // Allow spaces to be escaped by a backslash if not meant as a delimiter + const previousToken = tokens[tokens.length - 1]; + if (previousToken && previousToken.endsWith('\\')) { + // Merge previous token with current one + tokens[tokens.length - 1] = `${previousToken.slice(0, -1)} ${token}`]; + } else { + tokens.push(token); + } + } + + return tokens; }; module.exports = { From d50c16a80ffc019bc35f321be99932f4d1e93e4a Mon Sep 17 00:00:00 2001 From: Federico Date: Wed, 23 Sep 2020 20:24:17 -0500 Subject: [PATCH 2/4] Lint --- lib/command.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/command.js b/lib/command.js index 016a4e8b99..0aabcb09cd 100644 --- a/lib/command.js +++ b/lib/command.js @@ -13,7 +13,7 @@ const handleEscaping = (tokens, token, index) => { }; // Handle `execa.command()` -const parseCommand = command => {) +const parseCommand = command => { const tokens = []; for (const token of command.trim().split(SPACES_REGEXP)) { // Allow spaces to be escaped by a backslash if not meant as a delimiter From fbb6e3a50c9513d8b9cbe8fd55b5da9a391c3c83 Mon Sep 17 00:00:00 2001 From: Federico Date: Wed, 23 Sep 2020 20:29:04 -0500 Subject: [PATCH 3/4] =?UTF-8?q?L=CD=88=CD=9A=CC=A0=CD=A4=CC=88=CD=90=CC=83?= =?UTF-8?q?=CD=86i=CC=B9=CD=91=CC=BF=CC=BD=CC=93=CC=91n=CC=B3=CD=AD=CD=A5?= =?UTF-8?q?=CC=BE=C5=A5=CD=94=CD=8D=CC=B1=CC=AE=CC=80=CD=82=CD=A5=CD=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/command.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/command.js b/lib/command.js index 0aabcb09cd..711bc338de 100644 --- a/lib/command.js +++ b/lib/command.js @@ -20,7 +20,7 @@ const parseCommand = command => { const previousToken = tokens[tokens.length - 1]; if (previousToken && previousToken.endsWith('\\')) { // Merge previous token with current one - tokens[tokens.length - 1] = `${previousToken.slice(0, -1)} ${token}`]; + tokens[tokens.length - 1] = `${previousToken.slice(0, -1)} ${token}`; } else { tokens.push(token); } From 67e583ddaea64cbbc2c7bf2070f8a0262f2018b6 Mon Sep 17 00:00:00 2001 From: Federico Date: Wed, 23 Sep 2020 20:32:27 -0500 Subject: [PATCH 4/4] =?UTF-8?q?=20L=CD=89=CC=AD=CD=9A=CC=A9=CC=9D=CD=8B?= =?UTF-8?q?=CC=95=CD=A2=E1=B8=AF=CD=AC=D2=89=CC=B8=CC=A7=CD=89=CC=AE=CC=AB?= =?UTF-8?q?=CD=95=CC=AD=CD=8E=CC=96=CC=B3n=CC=93=CC=BD=CC=89=CD=AC=CC=BE?= =?UTF-8?q?=CD=A4=CC=88=CD=8A=CD=A2=CD=8F=CC=A7=CC=B2=CC=97=CD=8D=CC=B2?= =?UTF-8?q?=CD=8E=CD=94t=CC=A1=CD=93=CC=BB=CC=9C=CC=96=CC=A9=CD=95=CC=B1?= =?UTF-8?q?=CC=B1=CD=A9=CD=AE=CD=92=CC=80=CC=80=CC=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/command.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/lib/command.js b/lib/command.js index 711bc338de..190ce16530 100644 --- a/lib/command.js +++ b/lib/command.js @@ -9,9 +9,6 @@ const joinCommand = (file, args = []) => { return [file, ...args].join(' '); }; -const handleEscaping = (tokens, token, index) => { -}; - // Handle `execa.command()` const parseCommand = command => { const tokens = [];