rollup 4.59.1 → 4.60.1
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/dist/bin/rollup +3 -3
- package/dist/es/getLogFilter.js +2 -2
- package/dist/es/parseAst.js +2 -2
- package/dist/es/rollup.js +2 -2
- package/dist/es/shared/node-entry.js +429 -37
- package/dist/es/shared/parseAst.js +29 -7
- package/dist/es/shared/watch.js +614 -2
- package/dist/getLogFilter.js +2 -2
- package/dist/loadConfigFile.js +2 -2
- package/dist/parseAst.js +2 -2
- package/dist/rollup.js +2 -2
- package/dist/shared/fsevents-importer.js +2 -2
- package/dist/shared/index.js +614 -2
- package/dist/shared/loadConfigFile.js +2 -2
- package/dist/shared/parseAst.js +30 -6
- package/dist/shared/rollup.js +428 -36
- package/dist/shared/watch-cli.js +2 -2
- package/dist/shared/watch.js +2 -2
- package/package.json +34 -33
package/dist/shared/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/*
|
|
2
2
|
@license
|
|
3
|
-
Rollup.js v4.
|
|
4
|
-
|
|
3
|
+
Rollup.js v4.60.1
|
|
4
|
+
Mon, 30 Mar 2026 04:32:12 GMT - commit ae871d762f6bbeb4320d28fe179211168f27a434
|
|
5
5
|
|
|
6
6
|
https://github.com/rollup/rollup
|
|
7
7
|
|
|
@@ -33,6 +33,8 @@ function requireConstants$3 () {
|
|
|
33
33
|
const WIN_SLASH = '\\\\/';
|
|
34
34
|
const WIN_NO_SLASH = `[^${WIN_SLASH}]`;
|
|
35
35
|
|
|
36
|
+
const DEFAULT_MAX_EXTGLOB_RECURSION = 0;
|
|
37
|
+
|
|
36
38
|
/**
|
|
37
39
|
* Posix glob regex
|
|
38
40
|
*/
|
|
@@ -96,6 +98,7 @@ function requireConstants$3 () {
|
|
|
96
98
|
*/
|
|
97
99
|
|
|
98
100
|
const POSIX_REGEX_SOURCE = {
|
|
101
|
+
__proto__: null,
|
|
99
102
|
alnum: 'a-zA-Z0-9',
|
|
100
103
|
alpha: 'a-zA-Z',
|
|
101
104
|
ascii: '\\x00-\\x7F',
|
|
@@ -113,6 +116,7 @@ function requireConstants$3 () {
|
|
|
113
116
|
};
|
|
114
117
|
|
|
115
118
|
constants$3 = {
|
|
119
|
+
DEFAULT_MAX_EXTGLOB_RECURSION,
|
|
116
120
|
MAX_LENGTH: 1024 * 64,
|
|
117
121
|
POSIX_REGEX_SOURCE,
|
|
118
122
|
|
|
@@ -126,6 +130,7 @@ function requireConstants$3 () {
|
|
|
126
130
|
|
|
127
131
|
// Replace globs with equivalent patterns to reduce parsing time.
|
|
128
132
|
REPLACEMENTS: {
|
|
133
|
+
__proto__: null,
|
|
129
134
|
'***': '*',
|
|
130
135
|
'**/**': '**',
|
|
131
136
|
'**/**/**': '**'
|
|
@@ -726,6 +731,277 @@ function requireParse$2 () {
|
|
|
726
731
|
return `Missing ${type}: "${char}" - use "\\\\${char}" to match literal characters`;
|
|
727
732
|
};
|
|
728
733
|
|
|
734
|
+
const splitTopLevel = input => {
|
|
735
|
+
const parts = [];
|
|
736
|
+
let bracket = 0;
|
|
737
|
+
let paren = 0;
|
|
738
|
+
let quote = 0;
|
|
739
|
+
let value = '';
|
|
740
|
+
let escaped = false;
|
|
741
|
+
|
|
742
|
+
for (const ch of input) {
|
|
743
|
+
if (escaped === true) {
|
|
744
|
+
value += ch;
|
|
745
|
+
escaped = false;
|
|
746
|
+
continue;
|
|
747
|
+
}
|
|
748
|
+
|
|
749
|
+
if (ch === '\\') {
|
|
750
|
+
value += ch;
|
|
751
|
+
escaped = true;
|
|
752
|
+
continue;
|
|
753
|
+
}
|
|
754
|
+
|
|
755
|
+
if (ch === '"') {
|
|
756
|
+
quote = quote === 1 ? 0 : 1;
|
|
757
|
+
value += ch;
|
|
758
|
+
continue;
|
|
759
|
+
}
|
|
760
|
+
|
|
761
|
+
if (quote === 0) {
|
|
762
|
+
if (ch === '[') {
|
|
763
|
+
bracket++;
|
|
764
|
+
} else if (ch === ']' && bracket > 0) {
|
|
765
|
+
bracket--;
|
|
766
|
+
} else if (bracket === 0) {
|
|
767
|
+
if (ch === '(') {
|
|
768
|
+
paren++;
|
|
769
|
+
} else if (ch === ')' && paren > 0) {
|
|
770
|
+
paren--;
|
|
771
|
+
} else if (ch === '|' && paren === 0) {
|
|
772
|
+
parts.push(value);
|
|
773
|
+
value = '';
|
|
774
|
+
continue;
|
|
775
|
+
}
|
|
776
|
+
}
|
|
777
|
+
}
|
|
778
|
+
|
|
779
|
+
value += ch;
|
|
780
|
+
}
|
|
781
|
+
|
|
782
|
+
parts.push(value);
|
|
783
|
+
return parts;
|
|
784
|
+
};
|
|
785
|
+
|
|
786
|
+
const isPlainBranch = branch => {
|
|
787
|
+
let escaped = false;
|
|
788
|
+
|
|
789
|
+
for (const ch of branch) {
|
|
790
|
+
if (escaped === true) {
|
|
791
|
+
escaped = false;
|
|
792
|
+
continue;
|
|
793
|
+
}
|
|
794
|
+
|
|
795
|
+
if (ch === '\\') {
|
|
796
|
+
escaped = true;
|
|
797
|
+
continue;
|
|
798
|
+
}
|
|
799
|
+
|
|
800
|
+
if (/[?*+@!()[\]{}]/.test(ch)) {
|
|
801
|
+
return false;
|
|
802
|
+
}
|
|
803
|
+
}
|
|
804
|
+
|
|
805
|
+
return true;
|
|
806
|
+
};
|
|
807
|
+
|
|
808
|
+
const normalizeSimpleBranch = branch => {
|
|
809
|
+
let value = branch.trim();
|
|
810
|
+
let changed = true;
|
|
811
|
+
|
|
812
|
+
while (changed === true) {
|
|
813
|
+
changed = false;
|
|
814
|
+
|
|
815
|
+
if (/^@\([^\\()[\]{}|]+\)$/.test(value)) {
|
|
816
|
+
value = value.slice(2, -1);
|
|
817
|
+
changed = true;
|
|
818
|
+
}
|
|
819
|
+
}
|
|
820
|
+
|
|
821
|
+
if (!isPlainBranch(value)) {
|
|
822
|
+
return;
|
|
823
|
+
}
|
|
824
|
+
|
|
825
|
+
return value.replace(/\\(.)/g, '$1');
|
|
826
|
+
};
|
|
827
|
+
|
|
828
|
+
const hasRepeatedCharPrefixOverlap = branches => {
|
|
829
|
+
const values = branches.map(normalizeSimpleBranch).filter(Boolean);
|
|
830
|
+
|
|
831
|
+
for (let i = 0; i < values.length; i++) {
|
|
832
|
+
for (let j = i + 1; j < values.length; j++) {
|
|
833
|
+
const a = values[i];
|
|
834
|
+
const b = values[j];
|
|
835
|
+
const char = a[0];
|
|
836
|
+
|
|
837
|
+
if (!char || a !== char.repeat(a.length) || b !== char.repeat(b.length)) {
|
|
838
|
+
continue;
|
|
839
|
+
}
|
|
840
|
+
|
|
841
|
+
if (a === b || a.startsWith(b) || b.startsWith(a)) {
|
|
842
|
+
return true;
|
|
843
|
+
}
|
|
844
|
+
}
|
|
845
|
+
}
|
|
846
|
+
|
|
847
|
+
return false;
|
|
848
|
+
};
|
|
849
|
+
|
|
850
|
+
const parseRepeatedExtglob = (pattern, requireEnd = true) => {
|
|
851
|
+
if ((pattern[0] !== '+' && pattern[0] !== '*') || pattern[1] !== '(') {
|
|
852
|
+
return;
|
|
853
|
+
}
|
|
854
|
+
|
|
855
|
+
let bracket = 0;
|
|
856
|
+
let paren = 0;
|
|
857
|
+
let quote = 0;
|
|
858
|
+
let escaped = false;
|
|
859
|
+
|
|
860
|
+
for (let i = 1; i < pattern.length; i++) {
|
|
861
|
+
const ch = pattern[i];
|
|
862
|
+
|
|
863
|
+
if (escaped === true) {
|
|
864
|
+
escaped = false;
|
|
865
|
+
continue;
|
|
866
|
+
}
|
|
867
|
+
|
|
868
|
+
if (ch === '\\') {
|
|
869
|
+
escaped = true;
|
|
870
|
+
continue;
|
|
871
|
+
}
|
|
872
|
+
|
|
873
|
+
if (ch === '"') {
|
|
874
|
+
quote = quote === 1 ? 0 : 1;
|
|
875
|
+
continue;
|
|
876
|
+
}
|
|
877
|
+
|
|
878
|
+
if (quote === 1) {
|
|
879
|
+
continue;
|
|
880
|
+
}
|
|
881
|
+
|
|
882
|
+
if (ch === '[') {
|
|
883
|
+
bracket++;
|
|
884
|
+
continue;
|
|
885
|
+
}
|
|
886
|
+
|
|
887
|
+
if (ch === ']' && bracket > 0) {
|
|
888
|
+
bracket--;
|
|
889
|
+
continue;
|
|
890
|
+
}
|
|
891
|
+
|
|
892
|
+
if (bracket > 0) {
|
|
893
|
+
continue;
|
|
894
|
+
}
|
|
895
|
+
|
|
896
|
+
if (ch === '(') {
|
|
897
|
+
paren++;
|
|
898
|
+
continue;
|
|
899
|
+
}
|
|
900
|
+
|
|
901
|
+
if (ch === ')') {
|
|
902
|
+
paren--;
|
|
903
|
+
|
|
904
|
+
if (paren === 0) {
|
|
905
|
+
if (requireEnd === true && i !== pattern.length - 1) {
|
|
906
|
+
return;
|
|
907
|
+
}
|
|
908
|
+
|
|
909
|
+
return {
|
|
910
|
+
type: pattern[0],
|
|
911
|
+
body: pattern.slice(2, i),
|
|
912
|
+
end: i
|
|
913
|
+
};
|
|
914
|
+
}
|
|
915
|
+
}
|
|
916
|
+
}
|
|
917
|
+
};
|
|
918
|
+
|
|
919
|
+
const getStarExtglobSequenceOutput = pattern => {
|
|
920
|
+
let index = 0;
|
|
921
|
+
const chars = [];
|
|
922
|
+
|
|
923
|
+
while (index < pattern.length) {
|
|
924
|
+
const match = parseRepeatedExtglob(pattern.slice(index), false);
|
|
925
|
+
|
|
926
|
+
if (!match || match.type !== '*') {
|
|
927
|
+
return;
|
|
928
|
+
}
|
|
929
|
+
|
|
930
|
+
const branches = splitTopLevel(match.body).map(branch => branch.trim());
|
|
931
|
+
if (branches.length !== 1) {
|
|
932
|
+
return;
|
|
933
|
+
}
|
|
934
|
+
|
|
935
|
+
const branch = normalizeSimpleBranch(branches[0]);
|
|
936
|
+
if (!branch || branch.length !== 1) {
|
|
937
|
+
return;
|
|
938
|
+
}
|
|
939
|
+
|
|
940
|
+
chars.push(branch);
|
|
941
|
+
index += match.end + 1;
|
|
942
|
+
}
|
|
943
|
+
|
|
944
|
+
if (chars.length < 1) {
|
|
945
|
+
return;
|
|
946
|
+
}
|
|
947
|
+
|
|
948
|
+
const source = chars.length === 1
|
|
949
|
+
? utils.escapeRegex(chars[0])
|
|
950
|
+
: `[${chars.map(ch => utils.escapeRegex(ch)).join('')}]`;
|
|
951
|
+
|
|
952
|
+
return `${source}*`;
|
|
953
|
+
};
|
|
954
|
+
|
|
955
|
+
const repeatedExtglobRecursion = pattern => {
|
|
956
|
+
let depth = 0;
|
|
957
|
+
let value = pattern.trim();
|
|
958
|
+
let match = parseRepeatedExtglob(value);
|
|
959
|
+
|
|
960
|
+
while (match) {
|
|
961
|
+
depth++;
|
|
962
|
+
value = match.body.trim();
|
|
963
|
+
match = parseRepeatedExtglob(value);
|
|
964
|
+
}
|
|
965
|
+
|
|
966
|
+
return depth;
|
|
967
|
+
};
|
|
968
|
+
|
|
969
|
+
const analyzeRepeatedExtglob = (body, options) => {
|
|
970
|
+
if (options.maxExtglobRecursion === false) {
|
|
971
|
+
return { risky: false };
|
|
972
|
+
}
|
|
973
|
+
|
|
974
|
+
const max =
|
|
975
|
+
typeof options.maxExtglobRecursion === 'number'
|
|
976
|
+
? options.maxExtglobRecursion
|
|
977
|
+
: constants.DEFAULT_MAX_EXTGLOB_RECURSION;
|
|
978
|
+
|
|
979
|
+
const branches = splitTopLevel(body).map(branch => branch.trim());
|
|
980
|
+
|
|
981
|
+
if (branches.length > 1) {
|
|
982
|
+
if (
|
|
983
|
+
branches.some(branch => branch === '') ||
|
|
984
|
+
branches.some(branch => /^[*?]+$/.test(branch)) ||
|
|
985
|
+
hasRepeatedCharPrefixOverlap(branches)
|
|
986
|
+
) {
|
|
987
|
+
return { risky: true };
|
|
988
|
+
}
|
|
989
|
+
}
|
|
990
|
+
|
|
991
|
+
for (const branch of branches) {
|
|
992
|
+
const safeOutput = getStarExtglobSequenceOutput(branch);
|
|
993
|
+
if (safeOutput) {
|
|
994
|
+
return { risky: true, safeOutput };
|
|
995
|
+
}
|
|
996
|
+
|
|
997
|
+
if (repeatedExtglobRecursion(branch) > max) {
|
|
998
|
+
return { risky: true };
|
|
999
|
+
}
|
|
1000
|
+
}
|
|
1001
|
+
|
|
1002
|
+
return { risky: false };
|
|
1003
|
+
};
|
|
1004
|
+
|
|
729
1005
|
/**
|
|
730
1006
|
* Parse the given input string.
|
|
731
1007
|
* @param {String} input
|
|
@@ -907,6 +1183,8 @@ function requireParse$2 () {
|
|
|
907
1183
|
token.prev = prev;
|
|
908
1184
|
token.parens = state.parens;
|
|
909
1185
|
token.output = state.output;
|
|
1186
|
+
token.startIndex = state.index;
|
|
1187
|
+
token.tokensIndex = tokens.length;
|
|
910
1188
|
const output = (opts.capture ? '(' : '') + token.open;
|
|
911
1189
|
|
|
912
1190
|
increment('parens');
|
|
@@ -916,6 +1194,34 @@ function requireParse$2 () {
|
|
|
916
1194
|
};
|
|
917
1195
|
|
|
918
1196
|
const extglobClose = token => {
|
|
1197
|
+
const literal = input.slice(token.startIndex, state.index + 1);
|
|
1198
|
+
const body = input.slice(token.startIndex + 2, state.index);
|
|
1199
|
+
const analysis = analyzeRepeatedExtglob(body, opts);
|
|
1200
|
+
|
|
1201
|
+
if ((token.type === 'plus' || token.type === 'star') && analysis.risky) {
|
|
1202
|
+
const safeOutput = analysis.safeOutput
|
|
1203
|
+
? (token.output ? '' : ONE_CHAR) + (opts.capture ? `(${analysis.safeOutput})` : analysis.safeOutput)
|
|
1204
|
+
: undefined;
|
|
1205
|
+
const open = tokens[token.tokensIndex];
|
|
1206
|
+
|
|
1207
|
+
open.type = 'text';
|
|
1208
|
+
open.value = literal;
|
|
1209
|
+
open.output = safeOutput || utils.escapeRegex(literal);
|
|
1210
|
+
|
|
1211
|
+
for (let i = token.tokensIndex + 1; i < tokens.length; i++) {
|
|
1212
|
+
tokens[i].value = '';
|
|
1213
|
+
tokens[i].output = '';
|
|
1214
|
+
delete tokens[i].suffix;
|
|
1215
|
+
}
|
|
1216
|
+
|
|
1217
|
+
state.output = token.output + open.output;
|
|
1218
|
+
state.backtrack = true;
|
|
1219
|
+
|
|
1220
|
+
push({ type: 'paren', extglob: true, value, output: '' });
|
|
1221
|
+
decrement('parens');
|
|
1222
|
+
return;
|
|
1223
|
+
}
|
|
1224
|
+
|
|
919
1225
|
let output = token.close + (opts.capture ? ')' : '');
|
|
920
1226
|
let rest;
|
|
921
1227
|
|
|
@@ -2444,6 +2750,8 @@ function requireConstants$2 () {
|
|
|
2444
2750
|
const WIN_SLASH = '\\\\/';
|
|
2445
2751
|
const WIN_NO_SLASH = `[^${WIN_SLASH}]`;
|
|
2446
2752
|
|
|
2753
|
+
const DEFAULT_MAX_EXTGLOB_RECURSION = 0;
|
|
2754
|
+
|
|
2447
2755
|
/**
|
|
2448
2756
|
* Posix glob regex
|
|
2449
2757
|
*/
|
|
@@ -2507,6 +2815,7 @@ function requireConstants$2 () {
|
|
|
2507
2815
|
*/
|
|
2508
2816
|
|
|
2509
2817
|
const POSIX_REGEX_SOURCE = {
|
|
2818
|
+
__proto__: null,
|
|
2510
2819
|
alnum: 'a-zA-Z0-9',
|
|
2511
2820
|
alpha: 'a-zA-Z',
|
|
2512
2821
|
ascii: '\\x00-\\x7F',
|
|
@@ -2524,6 +2833,7 @@ function requireConstants$2 () {
|
|
|
2524
2833
|
};
|
|
2525
2834
|
|
|
2526
2835
|
constants$2 = {
|
|
2836
|
+
DEFAULT_MAX_EXTGLOB_RECURSION,
|
|
2527
2837
|
MAX_LENGTH: 1024 * 64,
|
|
2528
2838
|
POSIX_REGEX_SOURCE,
|
|
2529
2839
|
|
|
@@ -2537,6 +2847,7 @@ function requireConstants$2 () {
|
|
|
2537
2847
|
|
|
2538
2848
|
// Replace globs with equivalent patterns to reduce parsing time.
|
|
2539
2849
|
REPLACEMENTS: {
|
|
2850
|
+
__proto__: null,
|
|
2540
2851
|
'***': '*',
|
|
2541
2852
|
'**/**': '**',
|
|
2542
2853
|
'**/**/**': '**'
|
|
@@ -3137,6 +3448,277 @@ function requireParse$1 () {
|
|
|
3137
3448
|
return `Missing ${type}: "${char}" - use "\\\\${char}" to match literal characters`;
|
|
3138
3449
|
};
|
|
3139
3450
|
|
|
3451
|
+
const splitTopLevel = input => {
|
|
3452
|
+
const parts = [];
|
|
3453
|
+
let bracket = 0;
|
|
3454
|
+
let paren = 0;
|
|
3455
|
+
let quote = 0;
|
|
3456
|
+
let value = '';
|
|
3457
|
+
let escaped = false;
|
|
3458
|
+
|
|
3459
|
+
for (const ch of input) {
|
|
3460
|
+
if (escaped === true) {
|
|
3461
|
+
value += ch;
|
|
3462
|
+
escaped = false;
|
|
3463
|
+
continue;
|
|
3464
|
+
}
|
|
3465
|
+
|
|
3466
|
+
if (ch === '\\') {
|
|
3467
|
+
value += ch;
|
|
3468
|
+
escaped = true;
|
|
3469
|
+
continue;
|
|
3470
|
+
}
|
|
3471
|
+
|
|
3472
|
+
if (ch === '"') {
|
|
3473
|
+
quote = quote === 1 ? 0 : 1;
|
|
3474
|
+
value += ch;
|
|
3475
|
+
continue;
|
|
3476
|
+
}
|
|
3477
|
+
|
|
3478
|
+
if (quote === 0) {
|
|
3479
|
+
if (ch === '[') {
|
|
3480
|
+
bracket++;
|
|
3481
|
+
} else if (ch === ']' && bracket > 0) {
|
|
3482
|
+
bracket--;
|
|
3483
|
+
} else if (bracket === 0) {
|
|
3484
|
+
if (ch === '(') {
|
|
3485
|
+
paren++;
|
|
3486
|
+
} else if (ch === ')' && paren > 0) {
|
|
3487
|
+
paren--;
|
|
3488
|
+
} else if (ch === '|' && paren === 0) {
|
|
3489
|
+
parts.push(value);
|
|
3490
|
+
value = '';
|
|
3491
|
+
continue;
|
|
3492
|
+
}
|
|
3493
|
+
}
|
|
3494
|
+
}
|
|
3495
|
+
|
|
3496
|
+
value += ch;
|
|
3497
|
+
}
|
|
3498
|
+
|
|
3499
|
+
parts.push(value);
|
|
3500
|
+
return parts;
|
|
3501
|
+
};
|
|
3502
|
+
|
|
3503
|
+
const isPlainBranch = branch => {
|
|
3504
|
+
let escaped = false;
|
|
3505
|
+
|
|
3506
|
+
for (const ch of branch) {
|
|
3507
|
+
if (escaped === true) {
|
|
3508
|
+
escaped = false;
|
|
3509
|
+
continue;
|
|
3510
|
+
}
|
|
3511
|
+
|
|
3512
|
+
if (ch === '\\') {
|
|
3513
|
+
escaped = true;
|
|
3514
|
+
continue;
|
|
3515
|
+
}
|
|
3516
|
+
|
|
3517
|
+
if (/[?*+@!()[\]{}]/.test(ch)) {
|
|
3518
|
+
return false;
|
|
3519
|
+
}
|
|
3520
|
+
}
|
|
3521
|
+
|
|
3522
|
+
return true;
|
|
3523
|
+
};
|
|
3524
|
+
|
|
3525
|
+
const normalizeSimpleBranch = branch => {
|
|
3526
|
+
let value = branch.trim();
|
|
3527
|
+
let changed = true;
|
|
3528
|
+
|
|
3529
|
+
while (changed === true) {
|
|
3530
|
+
changed = false;
|
|
3531
|
+
|
|
3532
|
+
if (/^@\([^\\()[\]{}|]+\)$/.test(value)) {
|
|
3533
|
+
value = value.slice(2, -1);
|
|
3534
|
+
changed = true;
|
|
3535
|
+
}
|
|
3536
|
+
}
|
|
3537
|
+
|
|
3538
|
+
if (!isPlainBranch(value)) {
|
|
3539
|
+
return;
|
|
3540
|
+
}
|
|
3541
|
+
|
|
3542
|
+
return value.replace(/\\(.)/g, '$1');
|
|
3543
|
+
};
|
|
3544
|
+
|
|
3545
|
+
const hasRepeatedCharPrefixOverlap = branches => {
|
|
3546
|
+
const values = branches.map(normalizeSimpleBranch).filter(Boolean);
|
|
3547
|
+
|
|
3548
|
+
for (let i = 0; i < values.length; i++) {
|
|
3549
|
+
for (let j = i + 1; j < values.length; j++) {
|
|
3550
|
+
const a = values[i];
|
|
3551
|
+
const b = values[j];
|
|
3552
|
+
const char = a[0];
|
|
3553
|
+
|
|
3554
|
+
if (!char || a !== char.repeat(a.length) || b !== char.repeat(b.length)) {
|
|
3555
|
+
continue;
|
|
3556
|
+
}
|
|
3557
|
+
|
|
3558
|
+
if (a === b || a.startsWith(b) || b.startsWith(a)) {
|
|
3559
|
+
return true;
|
|
3560
|
+
}
|
|
3561
|
+
}
|
|
3562
|
+
}
|
|
3563
|
+
|
|
3564
|
+
return false;
|
|
3565
|
+
};
|
|
3566
|
+
|
|
3567
|
+
const parseRepeatedExtglob = (pattern, requireEnd = true) => {
|
|
3568
|
+
if ((pattern[0] !== '+' && pattern[0] !== '*') || pattern[1] !== '(') {
|
|
3569
|
+
return;
|
|
3570
|
+
}
|
|
3571
|
+
|
|
3572
|
+
let bracket = 0;
|
|
3573
|
+
let paren = 0;
|
|
3574
|
+
let quote = 0;
|
|
3575
|
+
let escaped = false;
|
|
3576
|
+
|
|
3577
|
+
for (let i = 1; i < pattern.length; i++) {
|
|
3578
|
+
const ch = pattern[i];
|
|
3579
|
+
|
|
3580
|
+
if (escaped === true) {
|
|
3581
|
+
escaped = false;
|
|
3582
|
+
continue;
|
|
3583
|
+
}
|
|
3584
|
+
|
|
3585
|
+
if (ch === '\\') {
|
|
3586
|
+
escaped = true;
|
|
3587
|
+
continue;
|
|
3588
|
+
}
|
|
3589
|
+
|
|
3590
|
+
if (ch === '"') {
|
|
3591
|
+
quote = quote === 1 ? 0 : 1;
|
|
3592
|
+
continue;
|
|
3593
|
+
}
|
|
3594
|
+
|
|
3595
|
+
if (quote === 1) {
|
|
3596
|
+
continue;
|
|
3597
|
+
}
|
|
3598
|
+
|
|
3599
|
+
if (ch === '[') {
|
|
3600
|
+
bracket++;
|
|
3601
|
+
continue;
|
|
3602
|
+
}
|
|
3603
|
+
|
|
3604
|
+
if (ch === ']' && bracket > 0) {
|
|
3605
|
+
bracket--;
|
|
3606
|
+
continue;
|
|
3607
|
+
}
|
|
3608
|
+
|
|
3609
|
+
if (bracket > 0) {
|
|
3610
|
+
continue;
|
|
3611
|
+
}
|
|
3612
|
+
|
|
3613
|
+
if (ch === '(') {
|
|
3614
|
+
paren++;
|
|
3615
|
+
continue;
|
|
3616
|
+
}
|
|
3617
|
+
|
|
3618
|
+
if (ch === ')') {
|
|
3619
|
+
paren--;
|
|
3620
|
+
|
|
3621
|
+
if (paren === 0) {
|
|
3622
|
+
if (requireEnd === true && i !== pattern.length - 1) {
|
|
3623
|
+
return;
|
|
3624
|
+
}
|
|
3625
|
+
|
|
3626
|
+
return {
|
|
3627
|
+
type: pattern[0],
|
|
3628
|
+
body: pattern.slice(2, i),
|
|
3629
|
+
end: i
|
|
3630
|
+
};
|
|
3631
|
+
}
|
|
3632
|
+
}
|
|
3633
|
+
}
|
|
3634
|
+
};
|
|
3635
|
+
|
|
3636
|
+
const getStarExtglobSequenceOutput = pattern => {
|
|
3637
|
+
let index = 0;
|
|
3638
|
+
const chars = [];
|
|
3639
|
+
|
|
3640
|
+
while (index < pattern.length) {
|
|
3641
|
+
const match = parseRepeatedExtglob(pattern.slice(index), false);
|
|
3642
|
+
|
|
3643
|
+
if (!match || match.type !== '*') {
|
|
3644
|
+
return;
|
|
3645
|
+
}
|
|
3646
|
+
|
|
3647
|
+
const branches = splitTopLevel(match.body).map(branch => branch.trim());
|
|
3648
|
+
if (branches.length !== 1) {
|
|
3649
|
+
return;
|
|
3650
|
+
}
|
|
3651
|
+
|
|
3652
|
+
const branch = normalizeSimpleBranch(branches[0]);
|
|
3653
|
+
if (!branch || branch.length !== 1) {
|
|
3654
|
+
return;
|
|
3655
|
+
}
|
|
3656
|
+
|
|
3657
|
+
chars.push(branch);
|
|
3658
|
+
index += match.end + 1;
|
|
3659
|
+
}
|
|
3660
|
+
|
|
3661
|
+
if (chars.length < 1) {
|
|
3662
|
+
return;
|
|
3663
|
+
}
|
|
3664
|
+
|
|
3665
|
+
const source = chars.length === 1
|
|
3666
|
+
? utils.escapeRegex(chars[0])
|
|
3667
|
+
: `[${chars.map(ch => utils.escapeRegex(ch)).join('')}]`;
|
|
3668
|
+
|
|
3669
|
+
return `${source}*`;
|
|
3670
|
+
};
|
|
3671
|
+
|
|
3672
|
+
const repeatedExtglobRecursion = pattern => {
|
|
3673
|
+
let depth = 0;
|
|
3674
|
+
let value = pattern.trim();
|
|
3675
|
+
let match = parseRepeatedExtglob(value);
|
|
3676
|
+
|
|
3677
|
+
while (match) {
|
|
3678
|
+
depth++;
|
|
3679
|
+
value = match.body.trim();
|
|
3680
|
+
match = parseRepeatedExtglob(value);
|
|
3681
|
+
}
|
|
3682
|
+
|
|
3683
|
+
return depth;
|
|
3684
|
+
};
|
|
3685
|
+
|
|
3686
|
+
const analyzeRepeatedExtglob = (body, options) => {
|
|
3687
|
+
if (options.maxExtglobRecursion === false) {
|
|
3688
|
+
return { risky: false };
|
|
3689
|
+
}
|
|
3690
|
+
|
|
3691
|
+
const max =
|
|
3692
|
+
typeof options.maxExtglobRecursion === 'number'
|
|
3693
|
+
? options.maxExtglobRecursion
|
|
3694
|
+
: constants.DEFAULT_MAX_EXTGLOB_RECURSION;
|
|
3695
|
+
|
|
3696
|
+
const branches = splitTopLevel(body).map(branch => branch.trim());
|
|
3697
|
+
|
|
3698
|
+
if (branches.length > 1) {
|
|
3699
|
+
if (
|
|
3700
|
+
branches.some(branch => branch === '') ||
|
|
3701
|
+
branches.some(branch => /^[*?]+$/.test(branch)) ||
|
|
3702
|
+
hasRepeatedCharPrefixOverlap(branches)
|
|
3703
|
+
) {
|
|
3704
|
+
return { risky: true };
|
|
3705
|
+
}
|
|
3706
|
+
}
|
|
3707
|
+
|
|
3708
|
+
for (const branch of branches) {
|
|
3709
|
+
const safeOutput = getStarExtglobSequenceOutput(branch);
|
|
3710
|
+
if (safeOutput) {
|
|
3711
|
+
return { risky: true, safeOutput };
|
|
3712
|
+
}
|
|
3713
|
+
|
|
3714
|
+
if (repeatedExtglobRecursion(branch) > max) {
|
|
3715
|
+
return { risky: true };
|
|
3716
|
+
}
|
|
3717
|
+
}
|
|
3718
|
+
|
|
3719
|
+
return { risky: false };
|
|
3720
|
+
};
|
|
3721
|
+
|
|
3140
3722
|
/**
|
|
3141
3723
|
* Parse the given input string.
|
|
3142
3724
|
* @param {String} input
|
|
@@ -3318,6 +3900,8 @@ function requireParse$1 () {
|
|
|
3318
3900
|
token.prev = prev;
|
|
3319
3901
|
token.parens = state.parens;
|
|
3320
3902
|
token.output = state.output;
|
|
3903
|
+
token.startIndex = state.index;
|
|
3904
|
+
token.tokensIndex = tokens.length;
|
|
3321
3905
|
const output = (opts.capture ? '(' : '') + token.open;
|
|
3322
3906
|
|
|
3323
3907
|
increment('parens');
|
|
@@ -3327,6 +3911,34 @@ function requireParse$1 () {
|
|
|
3327
3911
|
};
|
|
3328
3912
|
|
|
3329
3913
|
const extglobClose = token => {
|
|
3914
|
+
const literal = input.slice(token.startIndex, state.index + 1);
|
|
3915
|
+
const body = input.slice(token.startIndex + 2, state.index);
|
|
3916
|
+
const analysis = analyzeRepeatedExtglob(body, opts);
|
|
3917
|
+
|
|
3918
|
+
if ((token.type === 'plus' || token.type === 'star') && analysis.risky) {
|
|
3919
|
+
const safeOutput = analysis.safeOutput
|
|
3920
|
+
? (token.output ? '' : ONE_CHAR) + (opts.capture ? `(${analysis.safeOutput})` : analysis.safeOutput)
|
|
3921
|
+
: undefined;
|
|
3922
|
+
const open = tokens[token.tokensIndex];
|
|
3923
|
+
|
|
3924
|
+
open.type = 'text';
|
|
3925
|
+
open.value = literal;
|
|
3926
|
+
open.output = safeOutput || utils.escapeRegex(literal);
|
|
3927
|
+
|
|
3928
|
+
for (let i = token.tokensIndex + 1; i < tokens.length; i++) {
|
|
3929
|
+
tokens[i].value = '';
|
|
3930
|
+
tokens[i].output = '';
|
|
3931
|
+
delete tokens[i].suffix;
|
|
3932
|
+
}
|
|
3933
|
+
|
|
3934
|
+
state.output = token.output + open.output;
|
|
3935
|
+
state.backtrack = true;
|
|
3936
|
+
|
|
3937
|
+
push({ type: 'paren', extglob: true, value, output: '' });
|
|
3938
|
+
decrement('parens');
|
|
3939
|
+
return;
|
|
3940
|
+
}
|
|
3941
|
+
|
|
3330
3942
|
let output = token.close + (opts.capture ? ')' : '');
|
|
3331
3943
|
let rest;
|
|
3332
3944
|
|