@jsenv/core 31.1.4 → 32.0.0

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.
@@ -222,24 +222,30 @@ const applyMatching = (pattern, string) => {
222
222
  // pattern leading **
223
223
  if (remainingPattern.slice(0, 2) === "**") {
224
224
  consumePattern(2); // consumes "**"
225
+ let skipAllowed = true;
225
226
  if (remainingPattern[0] === "/") {
226
227
  consumePattern(1); // consumes "/"
228
+ if (!remainingString.includes("/")) {
229
+ skipAllowed = false;
230
+ }
227
231
  }
228
- // pattern ending with ** always match remaining string
232
+ // pattern ending with "**" or "**/" always match remaining string
229
233
  if (remainingPattern === "") {
230
234
  consumeRemainingString();
231
235
  return true;
232
236
  }
233
- const skipResult = skipUntilMatch({
234
- pattern: remainingPattern,
235
- string: remainingString,
236
- canSkipSlash: true
237
- });
238
- groups.push(...skipResult.groups);
239
- consumePattern(skipResult.patternIndex);
240
- consumeRemainingString();
241
- restoreIndexes = false;
242
- return skipResult.matched;
237
+ if (skipAllowed) {
238
+ const skipResult = skipUntilMatch({
239
+ pattern: remainingPattern,
240
+ string: remainingString,
241
+ canSkipSlash: true
242
+ });
243
+ groups.push(...skipResult.groups);
244
+ consumePattern(skipResult.patternIndex);
245
+ consumeRemainingString();
246
+ restoreIndexes = false;
247
+ return skipResult.matched;
248
+ }
243
249
  }
244
250
  if (remainingPattern[0] === "*") {
245
251
  consumePattern(1); // consumes "*"
@@ -297,7 +303,7 @@ const skipUntilMatch = ({
297
303
  }) => {
298
304
  let index = 0;
299
305
  let remainingString = string;
300
- let longestMatchRange = null;
306
+ let longestAttemptRange = null;
301
307
  const tryToMatch = () => {
302
308
  const matchAttempt = applyMatching(pattern, remainingString);
303
309
  if (matchAttempt.matched) {
@@ -311,18 +317,25 @@ const skipUntilMatch = ({
311
317
  }
312
318
  };
313
319
  }
314
- const matchAttemptIndex = matchAttempt.index;
315
- const matchRange = {
320
+ const attemptIndex = matchAttempt.index;
321
+ const attemptRange = {
316
322
  patternIndex: matchAttempt.patternIndex,
317
323
  index,
318
- length: matchAttemptIndex,
324
+ length: attemptIndex,
319
325
  groups: matchAttempt.groups
320
326
  };
321
- if (!longestMatchRange || longestMatchRange.length < matchRange.length) {
322
- longestMatchRange = matchRange;
327
+ if (!longestAttemptRange || longestAttemptRange.length < attemptRange.length) {
328
+ longestAttemptRange = attemptRange;
329
+ }
330
+ const nextIndex = attemptIndex + 1;
331
+ let canSkip;
332
+ if (nextIndex >= remainingString.length) {
333
+ canSkip = false;
334
+ } else if (remainingString[0] === "/" && !canSkipSlash) {
335
+ canSkip = false;
336
+ } else {
337
+ canSkip = true;
323
338
  }
324
- const nextIndex = matchAttemptIndex + 1;
325
- const canSkip = nextIndex < remainingString.length && (canSkipSlash || remainingString[0] !== "/");
326
339
  if (canSkip) {
327
340
  // search against the next unattempted string
328
341
  index += nextIndex;
@@ -331,11 +344,11 @@ const skipUntilMatch = ({
331
344
  }
332
345
  return {
333
346
  matched: false,
334
- patternIndex: longestMatchRange.patternIndex,
335
- index: longestMatchRange.index + longestMatchRange.length,
336
- groups: longestMatchRange.groups,
347
+ patternIndex: longestAttemptRange.patternIndex,
348
+ index: longestAttemptRange.index + longestAttemptRange.length,
349
+ groups: longestAttemptRange.groups,
337
350
  group: {
338
- string: string.slice(0, longestMatchRange.index)
351
+ string: string.slice(0, longestAttemptRange.index)
339
352
  }
340
353
  };
341
354
  };