@tonycodes-ui/mortar 0.22.0 → 0.22.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/cli/audit.mjs CHANGED
@@ -219,6 +219,21 @@ export function blankComments(text, { css = false } = {}) {
219
219
  return out.join("");
220
220
  }
221
221
 
222
+ /**
223
+ * True when `src[i]` starts a JS string or template literal. An apostrophe in
224
+ * JSX text (`Don't`) does not: it must follow an operator, bracket, or a
225
+ * keyword such as `return` (same rule as blankStrings).
226
+ */
227
+ function quoteStarts(src, i) {
228
+ const q = src[i];
229
+ if (q !== '"' && q !== "'" && q !== "`") return false;
230
+ if (q === "`") return true;
231
+ const before = src.slice(0, i).trimEnd();
232
+ return /(?:^|=>|[=(,:?&|[{}+;!]|\b(?:return|case|throw|from|import))$/.test(
233
+ before,
234
+ );
235
+ }
236
+
222
237
  /** Index of the character after the `{…}` group starting at `i`. */
223
238
  function skipBraces(src, i) {
224
239
  let depth = 0;
@@ -229,7 +244,7 @@ function skipBraces(src, i) {
229
244
  else if (c === "}") {
230
245
  depth--;
231
246
  if (depth === 0) return i + 1;
232
- } else if (c === '"' || c === "'") {
247
+ } else if ((c === '"' || c === "'") && quoteStarts(src, i)) {
233
248
  i++;
234
249
  while (i < n && src[i] !== c && src[i] !== "\n") {
235
250
  if (src[i] === "\\") i++;
@@ -309,16 +324,6 @@ export function jsxAttributes(src, i) {
309
324
  export function blankStrings(src) {
310
325
  const out = src.split("");
311
326
  const n = src.length;
312
- // A quote in JSX text (Don't) is not a string.
313
- const starts = (i) => {
314
- const q = src[i];
315
- if (q !== '"' && q !== "'" && q !== "`") return false;
316
- if (q === "`") return true;
317
- const before = src.slice(0, i).trimEnd();
318
- return /(?:^|=>|[=(,:?&|[{}+;!]|\b(?:return|case|throw|from|import))$/.test(
319
- before,
320
- );
321
- };
322
327
  const blank = (from, to) => {
323
328
  for (let k = from; k < Math.min(to, n); k++)
324
329
  if (out[k] !== "\n") out[k] = " ";
@@ -358,7 +363,7 @@ export function blankStrings(src) {
358
363
  if (expr && c === "{") depth++;
359
364
  else if (expr && c === "}") {
360
365
  if (--depth === 0) return i;
361
- } else if ((c === '"' || c === "'" || c === "`") && starts(i)) {
366
+ } else if ((c === '"' || c === "'" || c === "`") && quoteStarts(src, i)) {
362
367
  i = blankOne(i, end);
363
368
  if (i < end) i++;
364
369
  continue;