@jsenv/core 32.0.0 → 32.1.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.
@@ -225,11 +225,14 @@ const applyMatching = (pattern, string) => {
225
225
  let skipAllowed = true;
226
226
  if (remainingPattern[0] === "/") {
227
227
  consumePattern(1); // consumes "/"
228
+ // when remainingPattern was preceeded by "**/"
229
+ // and remainingString have no "/"
230
+ // then skip is not allowed, a regular match will be performed
228
231
  if (!remainingString.includes("/")) {
229
232
  skipAllowed = false;
230
233
  }
231
234
  }
232
- // pattern ending with "**" or "**/" always match remaining string
235
+ // pattern ending with "**" or "**/" match remaining string
233
236
  if (remainingPattern === "") {
234
237
  consumeRemainingString();
235
238
  return true;
@@ -250,7 +253,7 @@ const applyMatching = (pattern, string) => {
250
253
  if (remainingPattern[0] === "*") {
251
254
  consumePattern(1); // consumes "*"
252
255
  if (remainingPattern === "") {
253
- // matches everything except '/'
256
+ // matches everything except "/"
254
257
  const slashIndex = remainingString.indexOf("/");
255
258
  if (slashIndex === -1) {
256
259
  groups.push({
@@ -304,6 +307,18 @@ const skipUntilMatch = ({
304
307
  let index = 0;
305
308
  let remainingString = string;
306
309
  let longestAttemptRange = null;
310
+ let isLastAttempt = false;
311
+ const failure = () => {
312
+ return {
313
+ matched: false,
314
+ patternIndex: longestAttemptRange.patternIndex,
315
+ index: longestAttemptRange.index + longestAttemptRange.length,
316
+ groups: longestAttemptRange.groups,
317
+ group: {
318
+ string: string.slice(0, longestAttemptRange.index)
319
+ }
320
+ };
321
+ };
307
322
  const tryToMatch = () => {
308
323
  const matchAttempt = applyMatching(pattern, remainingString);
309
324
  if (matchAttempt.matched) {
@@ -327,30 +342,26 @@ const skipUntilMatch = ({
327
342
  if (!longestAttemptRange || longestAttemptRange.length < attemptRange.length) {
328
343
  longestAttemptRange = attemptRange;
329
344
  }
345
+ if (isLastAttempt) {
346
+ return failure();
347
+ }
330
348
  const nextIndex = attemptIndex + 1;
331
- let canSkip;
332
349
  if (nextIndex >= remainingString.length) {
333
- canSkip = false;
334
- } else if (remainingString[0] === "/" && !canSkipSlash) {
335
- canSkip = false;
336
- } else {
337
- canSkip = true;
350
+ return failure();
338
351
  }
339
- if (canSkip) {
340
- // search against the next unattempted string
341
- index += nextIndex;
342
- remainingString = remainingString.slice(nextIndex);
343
- return tryToMatch();
344
- }
345
- return {
346
- matched: false,
347
- patternIndex: longestAttemptRange.patternIndex,
348
- index: longestAttemptRange.index + longestAttemptRange.length,
349
- groups: longestAttemptRange.groups,
350
- group: {
351
- string: string.slice(0, longestAttemptRange.index)
352
+ if (remainingString[0] === "/") {
353
+ if (!canSkipSlash) {
354
+ return failure();
352
355
  }
353
- };
356
+ // when it's the last slash, the next attempt is the last
357
+ if (remainingString.indexOf("/", 1) === -1) {
358
+ isLastAttempt = true;
359
+ }
360
+ }
361
+ // search against the next unattempted string
362
+ index += nextIndex;
363
+ remainingString = remainingString.slice(nextIndex);
364
+ return tryToMatch();
354
365
  };
355
366
  return tryToMatch();
356
367
  };