Skip to content

Commit

Permalink
cleaner implementation recursing on the double quote case
Browse files Browse the repository at this point in the history
  • Loading branch information
James Halliday committed Apr 15, 2013
1 parent efa4084 commit adae66f
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,13 @@ exports.parse = function parse (s, env) {
.replace(/\\([ "'\\$`(){}!#&*|])/g, '$1')
;
}
else return s
.replace(/(['"])((\\\1|[^\1])*?)\1|[^'"]+/g, function (s, q) {
else return s.replace(
/(['"])((\\\1|[^\1])*?)\1|[^'"]+/g,
function (s, q) {
if (/^['"]/.test(s)) return parse(s, env);
return s
.replace(/(^|[^\\])\$(\w+)/g, getVar)
.replace(/(^|[^\\])\${(\w+)}/g, getVar)
.replace(/\\([ "'\\$`(){}!#&*|])/g, '$1')
;
})
;
return parse('"' + s + '"', env);
}
);
});

function getVar (_, pre, key) {
Expand Down

0 comments on commit adae66f

Please sign in to comment.