Skip to content

Commit 6780ec5

Browse files
committed
[Refactor] parse: a bit of cleanup
1 parent 227d474 commit 6780ec5

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

parse.js

+14-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,16 @@
33
// '<(' is process substitution operator and
44
// can be parsed the same as control operator
55
var CONTROL = '(?:' + [
6-
'\\|\\|', '\\&\\&', ';;', '\\|\\&', '\\<\\(', '\\<\\<\\<', '>>', '>\\&', '<\\&', '[&;()|<>]'
6+
'\\|\\|',
7+
'\\&\\&',
8+
';;',
9+
'\\|\\&',
10+
'\\<\\(',
11+
'\\<\\<\\<',
12+
'>>',
13+
'>\\&',
14+
'<\\&',
15+
'[&;()|<>]'
716
].join('|') + ')';
817
var controlRE = new RegExp('^' + CONTROL + '$');
918
var META = '|&;()<> \\t';
@@ -148,10 +157,11 @@ function parseInternal(s, env, opts) {
148157
return { op: s };
149158
} else if (hash.test(c)) {
150159
commented = true;
160+
var commentObj = { comment: s.slice(i + 1) + match.slice(j + 1).join(' ') };
151161
if (out.length) {
152-
return [out, { comment: s.slice(i + 1) + match.slice(j + 1).join(' ') }];
162+
return [out, commentObj];
153163
}
154-
return [{ comment: s.slice(i + 1) + match.slice(j + 1).join(' ') }];
164+
return [commentObj];
155165
} else if (c === BS) {
156166
esc = true;
157167
} else if (c === DS) {
@@ -166,7 +176,7 @@ function parseInternal(s, env, opts) {
166176
}
167177

168178
return out;
169-
}).reduce(function (prev, arg) { // finalize parsed aruments
179+
}).reduce(function (prev, arg) { // finalize parsed arguments
170180
return typeof arg === 'undefined' ? prev : prev.concat(arg);
171181
}, []);
172182
}

0 commit comments

Comments
 (0)