Skip to content

Commit

Permalink
Fix macro token parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
mohd-akram committed Jan 30, 2023
1 parent e781052 commit b767694
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/impl/formatter.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export default class Formatter {
const c = fmt.charAt(i);
if (c === "'") {
if (currentFull.length > 0) {
splits.push({ literal: bracketed, val: currentFull });
splits.push({ literal: bracketed || /^\s+$/.test(currentFull), val: currentFull });
}
current = null;
currentFull = "";
Expand All @@ -66,15 +66,15 @@ export default class Formatter {
currentFull += c;
} else {
if (currentFull.length > 0) {
splits.push({ literal: false, val: currentFull });
splits.push({ literal: /^\s+$/.test(currentFull), val: currentFull });
}
currentFull = c;
current = c;
}
}

if (currentFull.length > 0) {
splits.push({ literal: bracketed, val: currentFull });
splits.push({ literal: bracketed || /^\s+$/.test(currentFull), val: currentFull });
}

return splits;
Expand Down
7 changes: 5 additions & 2 deletions src/impl/tokenParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,8 @@ function unitForToken(token, loc) {
// because we don't have any way to figure out what they are
case "z":
return simple(/[a-z_+-/]{1,256}?/i);
case " ":
return simple(/\s/);
default:
return literal(t);
}
Expand Down Expand Up @@ -237,9 +239,10 @@ function tokenForPart(part, formatOpts) {
const { type, value } = part;

if (type === "literal") {
const isSpace = /^\s+$/.test(value);
return {
literal: true,
val: value,
literal: !isSpace,
val: isSpace ? " " : value,
};
}

Expand Down

0 comments on commit b767694

Please sign in to comment.