pluginutils.cjs.js 109 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', { value: true });
  3. function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
  4. var path = require('path');
  5. var path__default = _interopDefault(path);
  6. var estreeWalker = require('estree-walker');
  7. var util = _interopDefault(require('util'));
  8. const addExtension = function addExtension(filename, ext = '.js') {
  9. if (!path.extname(filename))
  10. filename += ext;
  11. return filename;
  12. };
  13. const extractors = {
  14. ArrayPattern(names, param) {
  15. for (const element of param.elements) {
  16. if (element)
  17. extractors[element.type](names, element);
  18. }
  19. },
  20. AssignmentPattern(names, param) {
  21. extractors[param.left.type](names, param.left);
  22. },
  23. Identifier(names, param) {
  24. names.push(param.name);
  25. },
  26. MemberExpression() { },
  27. ObjectPattern(names, param) {
  28. for (const prop of param.properties) {
  29. if (prop.type === 'RestElement') {
  30. extractors.RestElement(names, prop);
  31. }
  32. else {
  33. extractors[prop.value.type](names, prop.value);
  34. }
  35. }
  36. },
  37. RestElement(names, param) {
  38. extractors[param.argument.type](names, param.argument);
  39. }
  40. };
  41. const extractAssignedNames = function extractAssignedNames(param) {
  42. const names = [];
  43. extractors[param.type](names, param);
  44. return names;
  45. };
  46. const blockDeclarations = {
  47. const: true,
  48. let: true
  49. };
  50. class Scope {
  51. constructor(options = {}) {
  52. this.parent = options.parent;
  53. this.isBlockScope = !!options.block;
  54. this.declarations = Object.create(null);
  55. if (options.params) {
  56. options.params.forEach(param => {
  57. extractAssignedNames(param).forEach(name => {
  58. this.declarations[name] = true;
  59. });
  60. });
  61. }
  62. }
  63. addDeclaration(node, isBlockDeclaration, isVar) {
  64. if (!isBlockDeclaration && this.isBlockScope) {
  65. // it's a `var` or function node, and this
  66. // is a block scope, so we need to go up
  67. this.parent.addDeclaration(node, isBlockDeclaration, isVar);
  68. }
  69. else if (node.id) {
  70. extractAssignedNames(node.id).forEach(name => {
  71. this.declarations[name] = true;
  72. });
  73. }
  74. }
  75. contains(name) {
  76. return this.declarations[name] || (this.parent ? this.parent.contains(name) : false);
  77. }
  78. }
  79. const attachScopes = function attachScopes(ast, propertyName = 'scope') {
  80. let scope = new Scope();
  81. estreeWalker.walk(ast, {
  82. enter(node, parent) {
  83. // function foo () {...}
  84. // class Foo {...}
  85. if (/(Function|Class)Declaration/.test(node.type)) {
  86. scope.addDeclaration(node, false, false);
  87. }
  88. // var foo = 1
  89. if (node.type === 'VariableDeclaration') {
  90. const kind = node.kind;
  91. const isBlockDeclaration = blockDeclarations[kind];
  92. node.declarations.forEach((declaration) => {
  93. scope.addDeclaration(declaration, isBlockDeclaration, true);
  94. });
  95. }
  96. let newScope;
  97. // create new function scope
  98. if (/Function/.test(node.type)) {
  99. newScope = new Scope({
  100. parent: scope,
  101. block: false,
  102. params: node.params
  103. });
  104. // named function expressions - the name is considered
  105. // part of the function's scope
  106. if (node.type === 'FunctionExpression' && node.id) {
  107. newScope.addDeclaration(node, false, false);
  108. }
  109. }
  110. // create new block scope
  111. if (node.type === 'BlockStatement' && !/Function/.test(parent.type)) {
  112. newScope = new Scope({
  113. parent: scope,
  114. block: true
  115. });
  116. }
  117. // catch clause has its own block scope
  118. if (node.type === 'CatchClause') {
  119. newScope = new Scope({
  120. parent: scope,
  121. params: node.param ? [node.param] : [],
  122. block: true
  123. });
  124. }
  125. if (newScope) {
  126. Object.defineProperty(node, propertyName, {
  127. value: newScope,
  128. configurable: true
  129. });
  130. scope = newScope;
  131. }
  132. },
  133. leave(node) {
  134. if (node[propertyName])
  135. scope = scope.parent;
  136. }
  137. });
  138. return scope;
  139. };
  140. function createCommonjsModule(fn, module) {
  141. return module = { exports: {} }, fn(module, module.exports), module.exports;
  142. }
  143. var utils = createCommonjsModule(function (module, exports) {
  144. exports.isInteger = num => {
  145. if (typeof num === 'number') {
  146. return Number.isInteger(num);
  147. }
  148. if (typeof num === 'string' && num.trim() !== '') {
  149. return Number.isInteger(Number(num));
  150. }
  151. return false;
  152. };
  153. /**
  154. * Find a node of the given type
  155. */
  156. exports.find = (node, type) => node.nodes.find(node => node.type === type);
  157. /**
  158. * Find a node of the given type
  159. */
  160. exports.exceedsLimit = (min, max, step = 1, limit) => {
  161. if (limit === false)
  162. return false;
  163. if (!exports.isInteger(min) || !exports.isInteger(max))
  164. return false;
  165. return ((Number(max) - Number(min)) / Number(step)) >= limit;
  166. };
  167. /**
  168. * Escape the given node with '\\' before node.value
  169. */
  170. exports.escapeNode = (block, n = 0, type) => {
  171. let node = block.nodes[n];
  172. if (!node)
  173. return;
  174. if ((type && node.type === type) || node.type === 'open' || node.type === 'close') {
  175. if (node.escaped !== true) {
  176. node.value = '\\' + node.value;
  177. node.escaped = true;
  178. }
  179. }
  180. };
  181. /**
  182. * Returns true if the given brace node should be enclosed in literal braces
  183. */
  184. exports.encloseBrace = node => {
  185. if (node.type !== 'brace')
  186. return false;
  187. if ((node.commas >> 0 + node.ranges >> 0) === 0) {
  188. node.invalid = true;
  189. return true;
  190. }
  191. return false;
  192. };
  193. /**
  194. * Returns true if a brace node is invalid.
  195. */
  196. exports.isInvalidBrace = block => {
  197. if (block.type !== 'brace')
  198. return false;
  199. if (block.invalid === true || block.dollar)
  200. return true;
  201. if ((block.commas >> 0 + block.ranges >> 0) === 0) {
  202. block.invalid = true;
  203. return true;
  204. }
  205. if (block.open !== true || block.close !== true) {
  206. block.invalid = true;
  207. return true;
  208. }
  209. return false;
  210. };
  211. /**
  212. * Returns true if a node is an open or close node
  213. */
  214. exports.isOpenOrClose = node => {
  215. if (node.type === 'open' || node.type === 'close') {
  216. return true;
  217. }
  218. return node.open === true || node.close === true;
  219. };
  220. /**
  221. * Reduce an array of text nodes.
  222. */
  223. exports.reduce = nodes => nodes.reduce((acc, node) => {
  224. if (node.type === 'text')
  225. acc.push(node.value);
  226. if (node.type === 'range')
  227. node.type = 'text';
  228. return acc;
  229. }, []);
  230. /**
  231. * Flatten an array
  232. */
  233. exports.flatten = (...args) => {
  234. const result = [];
  235. const flat = arr => {
  236. for (let i = 0; i < arr.length; i++) {
  237. let ele = arr[i];
  238. Array.isArray(ele) ? flat(ele, result) : ele !== void 0 && result.push(ele);
  239. }
  240. return result;
  241. };
  242. flat(args);
  243. return result;
  244. };
  245. });
  246. var utils_1 = utils.isInteger;
  247. var utils_2 = utils.find;
  248. var utils_3 = utils.exceedsLimit;
  249. var utils_4 = utils.escapeNode;
  250. var utils_5 = utils.encloseBrace;
  251. var utils_6 = utils.isInvalidBrace;
  252. var utils_7 = utils.isOpenOrClose;
  253. var utils_8 = utils.reduce;
  254. var utils_9 = utils.flatten;
  255. var stringify = (ast, options = {}) => {
  256. let stringify = (node, parent = {}) => {
  257. let invalidBlock = options.escapeInvalid && utils.isInvalidBrace(parent);
  258. let invalidNode = node.invalid === true && options.escapeInvalid === true;
  259. let output = '';
  260. if (node.value) {
  261. if ((invalidBlock || invalidNode) && utils.isOpenOrClose(node)) {
  262. return '\\' + node.value;
  263. }
  264. return node.value;
  265. }
  266. if (node.value) {
  267. return node.value;
  268. }
  269. if (node.nodes) {
  270. for (let child of node.nodes) {
  271. output += stringify(child);
  272. }
  273. }
  274. return output;
  275. };
  276. return stringify(ast);
  277. };
  278. /*!
  279. * is-number <https://github.com/jonschlinkert/is-number>
  280. *
  281. * Copyright (c) 2014-present, Jon Schlinkert.
  282. * Released under the MIT License.
  283. */
  284. var isNumber = function (num) {
  285. if (typeof num === 'number') {
  286. return num - num === 0;
  287. }
  288. if (typeof num === 'string' && num.trim() !== '') {
  289. return Number.isFinite ? Number.isFinite(+num) : isFinite(+num);
  290. }
  291. return false;
  292. };
  293. const toRegexRange = (min, max, options) => {
  294. if (isNumber(min) === false) {
  295. throw new TypeError('toRegexRange: expected the first argument to be a number');
  296. }
  297. if (max === void 0 || min === max) {
  298. return String(min);
  299. }
  300. if (isNumber(max) === false) {
  301. throw new TypeError('toRegexRange: expected the second argument to be a number.');
  302. }
  303. let opts = Object.assign({ relaxZeros: true }, options);
  304. if (typeof opts.strictZeros === 'boolean') {
  305. opts.relaxZeros = opts.strictZeros === false;
  306. }
  307. let relax = String(opts.relaxZeros);
  308. let shorthand = String(opts.shorthand);
  309. let capture = String(opts.capture);
  310. let wrap = String(opts.wrap);
  311. let cacheKey = min + ':' + max + '=' + relax + shorthand + capture + wrap;
  312. if (toRegexRange.cache.hasOwnProperty(cacheKey)) {
  313. return toRegexRange.cache[cacheKey].result;
  314. }
  315. let a = Math.min(min, max);
  316. let b = Math.max(min, max);
  317. if (Math.abs(a - b) === 1) {
  318. let result = min + '|' + max;
  319. if (opts.capture) {
  320. return `(${result})`;
  321. }
  322. if (opts.wrap === false) {
  323. return result;
  324. }
  325. return `(?:${result})`;
  326. }
  327. let isPadded = hasPadding(min) || hasPadding(max);
  328. let state = { min, max, a, b };
  329. let positives = [];
  330. let negatives = [];
  331. if (isPadded) {
  332. state.isPadded = isPadded;
  333. state.maxLen = String(state.max).length;
  334. }
  335. if (a < 0) {
  336. let newMin = b < 0 ? Math.abs(b) : 1;
  337. negatives = splitToPatterns(newMin, Math.abs(a), state, opts);
  338. a = state.a = 0;
  339. }
  340. if (b >= 0) {
  341. positives = splitToPatterns(a, b, state, opts);
  342. }
  343. state.negatives = negatives;
  344. state.positives = positives;
  345. state.result = collatePatterns(negatives, positives, opts);
  346. if (opts.capture === true) {
  347. state.result = `(${state.result})`;
  348. }
  349. else if (opts.wrap !== false && (positives.length + negatives.length) > 1) {
  350. state.result = `(?:${state.result})`;
  351. }
  352. toRegexRange.cache[cacheKey] = state;
  353. return state.result;
  354. };
  355. function collatePatterns(neg, pos, options) {
  356. let onlyNegative = filterPatterns(neg, pos, '-', false, options) || [];
  357. let onlyPositive = filterPatterns(pos, neg, '', false, options) || [];
  358. let intersected = filterPatterns(neg, pos, '-?', true, options) || [];
  359. let subpatterns = onlyNegative.concat(intersected).concat(onlyPositive);
  360. return subpatterns.join('|');
  361. }
  362. function splitToRanges(min, max) {
  363. let nines = 1;
  364. let zeros = 1;
  365. let stop = countNines(min, nines);
  366. let stops = new Set([max]);
  367. while (min <= stop && stop <= max) {
  368. stops.add(stop);
  369. nines += 1;
  370. stop = countNines(min, nines);
  371. }
  372. stop = countZeros(max + 1, zeros) - 1;
  373. while (min < stop && stop <= max) {
  374. stops.add(stop);
  375. zeros += 1;
  376. stop = countZeros(max + 1, zeros) - 1;
  377. }
  378. stops = [...stops];
  379. stops.sort(compare);
  380. return stops;
  381. }
  382. /**
  383. * Convert a range to a regex pattern
  384. * @param {Number} `start`
  385. * @param {Number} `stop`
  386. * @return {String}
  387. */
  388. function rangeToPattern(start, stop, options) {
  389. if (start === stop) {
  390. return { pattern: start, count: [], digits: 0 };
  391. }
  392. let zipped = zip(start, stop);
  393. let digits = zipped.length;
  394. let pattern = '';
  395. let count = 0;
  396. for (let i = 0; i < digits; i++) {
  397. let [startDigit, stopDigit] = zipped[i];
  398. if (startDigit === stopDigit) {
  399. pattern += startDigit;
  400. }
  401. else if (startDigit !== '0' || stopDigit !== '9') {
  402. pattern += toCharacterClass(startDigit, stopDigit, options);
  403. }
  404. else {
  405. count++;
  406. }
  407. }
  408. if (count) {
  409. pattern += options.shorthand === true ? '\\d' : '[0-9]';
  410. }
  411. return { pattern, count: [count], digits };
  412. }
  413. function splitToPatterns(min, max, tok, options) {
  414. let ranges = splitToRanges(min, max);
  415. let tokens = [];
  416. let start = min;
  417. let prev;
  418. for (let i = 0; i < ranges.length; i++) {
  419. let max = ranges[i];
  420. let obj = rangeToPattern(String(start), String(max), options);
  421. let zeros = '';
  422. if (!tok.isPadded && prev && prev.pattern === obj.pattern) {
  423. if (prev.count.length > 1) {
  424. prev.count.pop();
  425. }
  426. prev.count.push(obj.count[0]);
  427. prev.string = prev.pattern + toQuantifier(prev.count);
  428. start = max + 1;
  429. continue;
  430. }
  431. if (tok.isPadded) {
  432. zeros = padZeros(max, tok, options);
  433. }
  434. obj.string = zeros + obj.pattern + toQuantifier(obj.count);
  435. tokens.push(obj);
  436. start = max + 1;
  437. prev = obj;
  438. }
  439. return tokens;
  440. }
  441. function filterPatterns(arr, comparison, prefix, intersection, options) {
  442. let result = [];
  443. for (let ele of arr) {
  444. let { string } = ele;
  445. // only push if _both_ are negative...
  446. if (!intersection && !contains(comparison, 'string', string)) {
  447. result.push(prefix + string);
  448. }
  449. // or _both_ are positive
  450. if (intersection && contains(comparison, 'string', string)) {
  451. result.push(prefix + string);
  452. }
  453. }
  454. return result;
  455. }
  456. /**
  457. * Zip strings
  458. */
  459. function zip(a, b) {
  460. let arr = [];
  461. for (let i = 0; i < a.length; i++)
  462. arr.push([a[i], b[i]]);
  463. return arr;
  464. }
  465. function compare(a, b) {
  466. return a > b ? 1 : b > a ? -1 : 0;
  467. }
  468. function contains(arr, key, val) {
  469. return arr.some(ele => ele[key] === val);
  470. }
  471. function countNines(min, len) {
  472. return Number(String(min).slice(0, -len) + '9'.repeat(len));
  473. }
  474. function countZeros(integer, zeros) {
  475. return integer - (integer % Math.pow(10, zeros));
  476. }
  477. function toQuantifier(digits) {
  478. let [start = 0, stop = ''] = digits;
  479. if (stop || start > 1) {
  480. return `{${start + (stop ? ',' + stop : '')}}`;
  481. }
  482. return '';
  483. }
  484. function toCharacterClass(a, b, options) {
  485. return `[${a}${(b - a === 1) ? '' : '-'}${b}]`;
  486. }
  487. function hasPadding(str) {
  488. return /^-?(0+)\d/.test(str);
  489. }
  490. function padZeros(value, tok, options) {
  491. if (!tok.isPadded) {
  492. return value;
  493. }
  494. let diff = Math.abs(tok.maxLen - String(value).length);
  495. let relax = options.relaxZeros !== false;
  496. switch (diff) {
  497. case 0:
  498. return '';
  499. case 1:
  500. return relax ? '0?' : '0';
  501. case 2:
  502. return relax ? '0{0,2}' : '00';
  503. default: {
  504. return relax ? `0{0,${diff}}` : `0{${diff}}`;
  505. }
  506. }
  507. }
  508. /**
  509. * Cache
  510. */
  511. toRegexRange.cache = {};
  512. toRegexRange.clearCache = () => (toRegexRange.cache = {});
  513. /**
  514. * Expose `toRegexRange`
  515. */
  516. var toRegexRange_1 = toRegexRange;
  517. const isObject = val => val !== null && typeof val === 'object' && !Array.isArray(val);
  518. const transform = toNumber => {
  519. return value => toNumber === true ? Number(value) : String(value);
  520. };
  521. const isValidValue = value => {
  522. return typeof value === 'number' || (typeof value === 'string' && value !== '');
  523. };
  524. const isNumber$1 = num => Number.isInteger(+num);
  525. const zeros = input => {
  526. let value = `${input}`;
  527. let index = -1;
  528. if (value[0] === '-')
  529. value = value.slice(1);
  530. if (value === '0')
  531. return false;
  532. while (value[++index] === '0')
  533. ;
  534. return index > 0;
  535. };
  536. const stringify$1 = (start, end, options) => {
  537. if (typeof start === 'string' || typeof end === 'string') {
  538. return true;
  539. }
  540. return options.stringify === true;
  541. };
  542. const pad = (input, maxLength, toNumber) => {
  543. if (maxLength > 0) {
  544. let dash = input[0] === '-' ? '-' : '';
  545. if (dash)
  546. input = input.slice(1);
  547. input = (dash + input.padStart(dash ? maxLength - 1 : maxLength, '0'));
  548. }
  549. if (toNumber === false) {
  550. return String(input);
  551. }
  552. return input;
  553. };
  554. const toMaxLen = (input, maxLength) => {
  555. let negative = input[0] === '-' ? '-' : '';
  556. if (negative) {
  557. input = input.slice(1);
  558. maxLength--;
  559. }
  560. while (input.length < maxLength)
  561. input = '0' + input;
  562. return negative ? ('-' + input) : input;
  563. };
  564. const toSequence = (parts, options) => {
  565. parts.negatives.sort((a, b) => a < b ? -1 : a > b ? 1 : 0);
  566. parts.positives.sort((a, b) => a < b ? -1 : a > b ? 1 : 0);
  567. let prefix = options.capture ? '' : '?:';
  568. let positives = '';
  569. let negatives = '';
  570. let result;
  571. if (parts.positives.length) {
  572. positives = parts.positives.join('|');
  573. }
  574. if (parts.negatives.length) {
  575. negatives = `-(${prefix}${parts.negatives.join('|')})`;
  576. }
  577. if (positives && negatives) {
  578. result = `${positives}|${negatives}`;
  579. }
  580. else {
  581. result = positives || negatives;
  582. }
  583. if (options.wrap) {
  584. return `(${prefix}${result})`;
  585. }
  586. return result;
  587. };
  588. const toRange = (a, b, isNumbers, options) => {
  589. if (isNumbers) {
  590. return toRegexRange_1(a, b, Object.assign({ wrap: false }, options));
  591. }
  592. let start = String.fromCharCode(a);
  593. if (a === b)
  594. return start;
  595. let stop = String.fromCharCode(b);
  596. return `[${start}-${stop}]`;
  597. };
  598. const toRegex = (start, end, options) => {
  599. if (Array.isArray(start)) {
  600. let wrap = options.wrap === true;
  601. let prefix = options.capture ? '' : '?:';
  602. return wrap ? `(${prefix}${start.join('|')})` : start.join('|');
  603. }
  604. return toRegexRange_1(start, end, options);
  605. };
  606. const rangeError = (...args) => {
  607. return new RangeError('Invalid range arguments: ' + util.inspect(...args));
  608. };
  609. const invalidRange = (start, end, options) => {
  610. if (options.strictRanges === true)
  611. throw rangeError([start, end]);
  612. return [];
  613. };
  614. const invalidStep = (step, options) => {
  615. if (options.strictRanges === true) {
  616. throw new TypeError(`Expected step "${step}" to be a number`);
  617. }
  618. return [];
  619. };
  620. const fillNumbers = (start, end, step = 1, options = {}) => {
  621. let a = Number(start);
  622. let b = Number(end);
  623. if (!Number.isInteger(a) || !Number.isInteger(b)) {
  624. if (options.strictRanges === true)
  625. throw rangeError([start, end]);
  626. return [];
  627. }
  628. // fix negative zero
  629. if (a === 0)
  630. a = 0;
  631. if (b === 0)
  632. b = 0;
  633. let descending = a > b;
  634. let startString = String(start);
  635. let endString = String(end);
  636. let stepString = String(step);
  637. step = Math.max(Math.abs(step), 1);
  638. let padded = zeros(startString) || zeros(endString) || zeros(stepString);
  639. let maxLen = padded ? Math.max(startString.length, endString.length, stepString.length) : 0;
  640. let toNumber = padded === false && stringify$1(start, end, options) === false;
  641. let format = options.transform || transform(toNumber);
  642. if (options.toRegex && step === 1) {
  643. return toRange(toMaxLen(start, maxLen), toMaxLen(end, maxLen), true, options);
  644. }
  645. let parts = { negatives: [], positives: [] };
  646. let push = num => parts[num < 0 ? 'negatives' : 'positives'].push(Math.abs(num));
  647. let range = [];
  648. let index = 0;
  649. while (descending ? a >= b : a <= b) {
  650. if (options.toRegex === true && step > 1) {
  651. push(a);
  652. }
  653. else {
  654. range.push(pad(format(a, index), maxLen, toNumber));
  655. }
  656. a = descending ? a - step : a + step;
  657. index++;
  658. }
  659. if (options.toRegex === true) {
  660. return step > 1
  661. ? toSequence(parts, options)
  662. : toRegex(range, null, Object.assign({ wrap: false }, options));
  663. }
  664. return range;
  665. };
  666. const fillLetters = (start, end, step = 1, options = {}) => {
  667. if ((!isNumber$1(start) && start.length > 1) || (!isNumber$1(end) && end.length > 1)) {
  668. return invalidRange(start, end, options);
  669. }
  670. let format = options.transform || (val => String.fromCharCode(val));
  671. let a = `${start}`.charCodeAt(0);
  672. let b = `${end}`.charCodeAt(0);
  673. let descending = a > b;
  674. let min = Math.min(a, b);
  675. let max = Math.max(a, b);
  676. if (options.toRegex && step === 1) {
  677. return toRange(min, max, false, options);
  678. }
  679. let range = [];
  680. let index = 0;
  681. while (descending ? a >= b : a <= b) {
  682. range.push(format(a, index));
  683. a = descending ? a - step : a + step;
  684. index++;
  685. }
  686. if (options.toRegex === true) {
  687. return toRegex(range, null, { wrap: false, options });
  688. }
  689. return range;
  690. };
  691. const fill = (start, end, step, options = {}) => {
  692. if (end == null && isValidValue(start)) {
  693. return [start];
  694. }
  695. if (!isValidValue(start) || !isValidValue(end)) {
  696. return invalidRange(start, end, options);
  697. }
  698. if (typeof step === 'function') {
  699. return fill(start, end, 1, { transform: step });
  700. }
  701. if (isObject(step)) {
  702. return fill(start, end, 0, step);
  703. }
  704. let opts = Object.assign({}, options);
  705. if (opts.capture === true)
  706. opts.wrap = true;
  707. step = step || opts.step || 1;
  708. if (!isNumber$1(step)) {
  709. if (step != null && !isObject(step))
  710. return invalidStep(step, opts);
  711. return fill(start, end, 1, step);
  712. }
  713. if (isNumber$1(start) && isNumber$1(end)) {
  714. return fillNumbers(start, end, step, opts);
  715. }
  716. return fillLetters(start, end, Math.max(Math.abs(step), 1), opts);
  717. };
  718. var fillRange = fill;
  719. const compile = (ast, options = {}) => {
  720. let walk = (node, parent = {}) => {
  721. let invalidBlock = utils.isInvalidBrace(parent);
  722. let invalidNode = node.invalid === true && options.escapeInvalid === true;
  723. let invalid = invalidBlock === true || invalidNode === true;
  724. let prefix = options.escapeInvalid === true ? '\\' : '';
  725. let output = '';
  726. if (node.isOpen === true) {
  727. return prefix + node.value;
  728. }
  729. if (node.isClose === true) {
  730. return prefix + node.value;
  731. }
  732. if (node.type === 'open') {
  733. return invalid ? (prefix + node.value) : '(';
  734. }
  735. if (node.type === 'close') {
  736. return invalid ? (prefix + node.value) : ')';
  737. }
  738. if (node.type === 'comma') {
  739. return node.prev.type === 'comma' ? '' : (invalid ? node.value : '|');
  740. }
  741. if (node.value) {
  742. return node.value;
  743. }
  744. if (node.nodes && node.ranges > 0) {
  745. let args = utils.reduce(node.nodes);
  746. let range = fillRange(...args, Object.assign({}, options, { wrap: false, toRegex: true }));
  747. if (range.length !== 0) {
  748. return args.length > 1 && range.length > 1 ? `(${range})` : range;
  749. }
  750. }
  751. if (node.nodes) {
  752. for (let child of node.nodes) {
  753. output += walk(child, node);
  754. }
  755. }
  756. return output;
  757. };
  758. return walk(ast);
  759. };
  760. var compile_1 = compile;
  761. const append = (queue = '', stash = '', enclose = false) => {
  762. let result = [];
  763. queue = [].concat(queue);
  764. stash = [].concat(stash);
  765. if (!stash.length)
  766. return queue;
  767. if (!queue.length) {
  768. return enclose ? utils.flatten(stash).map(ele => `{${ele}}`) : stash;
  769. }
  770. for (let item of queue) {
  771. if (Array.isArray(item)) {
  772. for (let value of item) {
  773. result.push(append(value, stash, enclose));
  774. }
  775. }
  776. else {
  777. for (let ele of stash) {
  778. if (enclose === true && typeof ele === 'string')
  779. ele = `{${ele}}`;
  780. result.push(Array.isArray(ele) ? append(item, ele, enclose) : (item + ele));
  781. }
  782. }
  783. }
  784. return utils.flatten(result);
  785. };
  786. const expand = (ast, options = {}) => {
  787. let rangeLimit = options.rangeLimit === void 0 ? 1000 : options.rangeLimit;
  788. let walk = (node, parent = {}) => {
  789. node.queue = [];
  790. let p = parent;
  791. let q = parent.queue;
  792. while (p.type !== 'brace' && p.type !== 'root' && p.parent) {
  793. p = p.parent;
  794. q = p.queue;
  795. }
  796. if (node.invalid || node.dollar) {
  797. q.push(append(q.pop(), stringify(node, options)));
  798. return;
  799. }
  800. if (node.type === 'brace' && node.invalid !== true && node.nodes.length === 2) {
  801. q.push(append(q.pop(), ['{}']));
  802. return;
  803. }
  804. if (node.nodes && node.ranges > 0) {
  805. let args = utils.reduce(node.nodes);
  806. if (utils.exceedsLimit(...args, options.step, rangeLimit)) {
  807. throw new RangeError('expanded array length exceeds range limit. Use options.rangeLimit to increase or disable the limit.');
  808. }
  809. let range = fillRange(...args, options);
  810. if (range.length === 0) {
  811. range = stringify(node, options);
  812. }
  813. q.push(append(q.pop(), range));
  814. node.nodes = [];
  815. return;
  816. }
  817. let enclose = utils.encloseBrace(node);
  818. let queue = node.queue;
  819. let block = node;
  820. while (block.type !== 'brace' && block.type !== 'root' && block.parent) {
  821. block = block.parent;
  822. queue = block.queue;
  823. }
  824. for (let i = 0; i < node.nodes.length; i++) {
  825. let child = node.nodes[i];
  826. if (child.type === 'comma' && node.type === 'brace') {
  827. if (i === 1)
  828. queue.push('');
  829. queue.push('');
  830. continue;
  831. }
  832. if (child.type === 'close') {
  833. q.push(append(q.pop(), queue, enclose));
  834. continue;
  835. }
  836. if (child.value && child.type !== 'open') {
  837. queue.push(append(queue.pop(), child.value));
  838. continue;
  839. }
  840. if (child.nodes) {
  841. walk(child, node);
  842. }
  843. }
  844. return queue;
  845. };
  846. return utils.flatten(walk(ast));
  847. };
  848. var expand_1 = expand;
  849. var constants = {
  850. MAX_LENGTH: 1024 * 64,
  851. // Digits
  852. CHAR_0: '0',
  853. CHAR_9: '9',
  854. // Alphabet chars.
  855. CHAR_UPPERCASE_A: 'A',
  856. CHAR_LOWERCASE_A: 'a',
  857. CHAR_UPPERCASE_Z: 'Z',
  858. CHAR_LOWERCASE_Z: 'z',
  859. CHAR_LEFT_PARENTHESES: '(',
  860. CHAR_RIGHT_PARENTHESES: ')',
  861. CHAR_ASTERISK: '*',
  862. // Non-alphabetic chars.
  863. CHAR_AMPERSAND: '&',
  864. CHAR_AT: '@',
  865. CHAR_BACKSLASH: '\\',
  866. CHAR_BACKTICK: '`',
  867. CHAR_CARRIAGE_RETURN: '\r',
  868. CHAR_CIRCUMFLEX_ACCENT: '^',
  869. CHAR_COLON: ':',
  870. CHAR_COMMA: ',',
  871. CHAR_DOLLAR: '$',
  872. CHAR_DOT: '.',
  873. CHAR_DOUBLE_QUOTE: '"',
  874. CHAR_EQUAL: '=',
  875. CHAR_EXCLAMATION_MARK: '!',
  876. CHAR_FORM_FEED: '\f',
  877. CHAR_FORWARD_SLASH: '/',
  878. CHAR_HASH: '#',
  879. CHAR_HYPHEN_MINUS: '-',
  880. CHAR_LEFT_ANGLE_BRACKET: '<',
  881. CHAR_LEFT_CURLY_BRACE: '{',
  882. CHAR_LEFT_SQUARE_BRACKET: '[',
  883. CHAR_LINE_FEED: '\n',
  884. CHAR_NO_BREAK_SPACE: '\u00A0',
  885. CHAR_PERCENT: '%',
  886. CHAR_PLUS: '+',
  887. CHAR_QUESTION_MARK: '?',
  888. CHAR_RIGHT_ANGLE_BRACKET: '>',
  889. CHAR_RIGHT_CURLY_BRACE: '}',
  890. CHAR_RIGHT_SQUARE_BRACKET: ']',
  891. CHAR_SEMICOLON: ';',
  892. CHAR_SINGLE_QUOTE: '\'',
  893. CHAR_SPACE: ' ',
  894. CHAR_TAB: '\t',
  895. CHAR_UNDERSCORE: '_',
  896. CHAR_VERTICAL_LINE: '|',
  897. CHAR_ZERO_WIDTH_NOBREAK_SPACE: '\uFEFF' /* \uFEFF */
  898. };
  899. /**
  900. * Constants
  901. */
  902. const { MAX_LENGTH, CHAR_BACKSLASH, /* \ */ CHAR_BACKTICK, /* ` */ CHAR_COMMA, /* , */ CHAR_DOT, /* . */ CHAR_LEFT_PARENTHESES, /* ( */ CHAR_RIGHT_PARENTHESES, /* ) */ CHAR_LEFT_CURLY_BRACE, /* { */ CHAR_RIGHT_CURLY_BRACE, /* } */ CHAR_LEFT_SQUARE_BRACKET, /* [ */ CHAR_RIGHT_SQUARE_BRACKET, /* ] */ CHAR_DOUBLE_QUOTE, /* " */ CHAR_SINGLE_QUOTE, /* ' */ CHAR_NO_BREAK_SPACE, CHAR_ZERO_WIDTH_NOBREAK_SPACE } = constants;
  903. /**
  904. * parse
  905. */
  906. const parse = (input, options = {}) => {
  907. if (typeof input !== 'string') {
  908. throw new TypeError('Expected a string');
  909. }
  910. let opts = options || {};
  911. let max = typeof opts.maxLength === 'number' ? Math.min(MAX_LENGTH, opts.maxLength) : MAX_LENGTH;
  912. if (input.length > max) {
  913. throw new SyntaxError(`Input length (${input.length}), exceeds max characters (${max})`);
  914. }
  915. let ast = { type: 'root', input, nodes: [] };
  916. let stack = [ast];
  917. let block = ast;
  918. let prev = ast;
  919. let brackets = 0;
  920. let length = input.length;
  921. let index = 0;
  922. let depth = 0;
  923. let value;
  924. /**
  925. * Helpers
  926. */
  927. const advance = () => input[index++];
  928. const push = node => {
  929. if (node.type === 'text' && prev.type === 'dot') {
  930. prev.type = 'text';
  931. }
  932. if (prev && prev.type === 'text' && node.type === 'text') {
  933. prev.value += node.value;
  934. return;
  935. }
  936. block.nodes.push(node);
  937. node.parent = block;
  938. node.prev = prev;
  939. prev = node;
  940. return node;
  941. };
  942. push({ type: 'bos' });
  943. while (index < length) {
  944. block = stack[stack.length - 1];
  945. value = advance();
  946. /**
  947. * Invalid chars
  948. */
  949. if (value === CHAR_ZERO_WIDTH_NOBREAK_SPACE || value === CHAR_NO_BREAK_SPACE) {
  950. continue;
  951. }
  952. /**
  953. * Escaped chars
  954. */
  955. if (value === CHAR_BACKSLASH) {
  956. push({ type: 'text', value: (options.keepEscaping ? value : '') + advance() });
  957. continue;
  958. }
  959. /**
  960. * Right square bracket (literal): ']'
  961. */
  962. if (value === CHAR_RIGHT_SQUARE_BRACKET) {
  963. push({ type: 'text', value: '\\' + value });
  964. continue;
  965. }
  966. /**
  967. * Left square bracket: '['
  968. */
  969. if (value === CHAR_LEFT_SQUARE_BRACKET) {
  970. brackets++;
  971. let next;
  972. while (index < length && (next = advance())) {
  973. value += next;
  974. if (next === CHAR_LEFT_SQUARE_BRACKET) {
  975. brackets++;
  976. continue;
  977. }
  978. if (next === CHAR_BACKSLASH) {
  979. value += advance();
  980. continue;
  981. }
  982. if (next === CHAR_RIGHT_SQUARE_BRACKET) {
  983. brackets--;
  984. if (brackets === 0) {
  985. break;
  986. }
  987. }
  988. }
  989. push({ type: 'text', value });
  990. continue;
  991. }
  992. /**
  993. * Parentheses
  994. */
  995. if (value === CHAR_LEFT_PARENTHESES) {
  996. block = push({ type: 'paren', nodes: [] });
  997. stack.push(block);
  998. push({ type: 'text', value });
  999. continue;
  1000. }
  1001. if (value === CHAR_RIGHT_PARENTHESES) {
  1002. if (block.type !== 'paren') {
  1003. push({ type: 'text', value });
  1004. continue;
  1005. }
  1006. block = stack.pop();
  1007. push({ type: 'text', value });
  1008. block = stack[stack.length - 1];
  1009. continue;
  1010. }
  1011. /**
  1012. * Quotes: '|"|`
  1013. */
  1014. if (value === CHAR_DOUBLE_QUOTE || value === CHAR_SINGLE_QUOTE || value === CHAR_BACKTICK) {
  1015. let open = value;
  1016. let next;
  1017. if (options.keepQuotes !== true) {
  1018. value = '';
  1019. }
  1020. while (index < length && (next = advance())) {
  1021. if (next === CHAR_BACKSLASH) {
  1022. value += next + advance();
  1023. continue;
  1024. }
  1025. if (next === open) {
  1026. if (options.keepQuotes === true)
  1027. value += next;
  1028. break;
  1029. }
  1030. value += next;
  1031. }
  1032. push({ type: 'text', value });
  1033. continue;
  1034. }
  1035. /**
  1036. * Left curly brace: '{'
  1037. */
  1038. if (value === CHAR_LEFT_CURLY_BRACE) {
  1039. depth++;
  1040. let dollar = prev.value && prev.value.slice(-1) === '$' || block.dollar === true;
  1041. let brace = {
  1042. type: 'brace',
  1043. open: true,
  1044. close: false,
  1045. dollar,
  1046. depth,
  1047. commas: 0,
  1048. ranges: 0,
  1049. nodes: []
  1050. };
  1051. block = push(brace);
  1052. stack.push(block);
  1053. push({ type: 'open', value });
  1054. continue;
  1055. }
  1056. /**
  1057. * Right curly brace: '}'
  1058. */
  1059. if (value === CHAR_RIGHT_CURLY_BRACE) {
  1060. if (block.type !== 'brace') {
  1061. push({ type: 'text', value });
  1062. continue;
  1063. }
  1064. let type = 'close';
  1065. block = stack.pop();
  1066. block.close = true;
  1067. push({ type, value });
  1068. depth--;
  1069. block = stack[stack.length - 1];
  1070. continue;
  1071. }
  1072. /**
  1073. * Comma: ','
  1074. */
  1075. if (value === CHAR_COMMA && depth > 0) {
  1076. if (block.ranges > 0) {
  1077. block.ranges = 0;
  1078. let open = block.nodes.shift();
  1079. block.nodes = [open, { type: 'text', value: stringify(block) }];
  1080. }
  1081. push({ type: 'comma', value });
  1082. block.commas++;
  1083. continue;
  1084. }
  1085. /**
  1086. * Dot: '.'
  1087. */
  1088. if (value === CHAR_DOT && depth > 0 && block.commas === 0) {
  1089. let siblings = block.nodes;
  1090. if (depth === 0 || siblings.length === 0) {
  1091. push({ type: 'text', value });
  1092. continue;
  1093. }
  1094. if (prev.type === 'dot') {
  1095. block.range = [];
  1096. prev.value += value;
  1097. prev.type = 'range';
  1098. if (block.nodes.length !== 3 && block.nodes.length !== 5) {
  1099. block.invalid = true;
  1100. block.ranges = 0;
  1101. prev.type = 'text';
  1102. continue;
  1103. }
  1104. block.ranges++;
  1105. block.args = [];
  1106. continue;
  1107. }
  1108. if (prev.type === 'range') {
  1109. siblings.pop();
  1110. let before = siblings[siblings.length - 1];
  1111. before.value += prev.value + value;
  1112. prev = before;
  1113. block.ranges--;
  1114. continue;
  1115. }
  1116. push({ type: 'dot', value });
  1117. continue;
  1118. }
  1119. /**
  1120. * Text
  1121. */
  1122. push({ type: 'text', value });
  1123. }
  1124. // Mark imbalanced braces and brackets as invalid
  1125. do {
  1126. block = stack.pop();
  1127. if (block.type !== 'root') {
  1128. block.nodes.forEach(node => {
  1129. if (!node.nodes) {
  1130. if (node.type === 'open')
  1131. node.isOpen = true;
  1132. if (node.type === 'close')
  1133. node.isClose = true;
  1134. if (!node.nodes)
  1135. node.type = 'text';
  1136. node.invalid = true;
  1137. }
  1138. });
  1139. // get the location of the block on parent.nodes (block's siblings)
  1140. let parent = stack[stack.length - 1];
  1141. let index = parent.nodes.indexOf(block);
  1142. // replace the (invalid) block with it's nodes
  1143. parent.nodes.splice(index, 1, ...block.nodes);
  1144. }
  1145. } while (stack.length > 0);
  1146. push({ type: 'eos' });
  1147. return ast;
  1148. };
  1149. var parse_1 = parse;
  1150. /**
  1151. * Expand the given pattern or create a regex-compatible string.
  1152. *
  1153. * ```js
  1154. * const braces = require('braces');
  1155. * console.log(braces('{a,b,c}', { compile: true })); //=> ['(a|b|c)']
  1156. * console.log(braces('{a,b,c}')); //=> ['a', 'b', 'c']
  1157. * ```
  1158. * @param {String} `str`
  1159. * @param {Object} `options`
  1160. * @return {String}
  1161. * @api public
  1162. */
  1163. const braces = (input, options = {}) => {
  1164. let output = [];
  1165. if (Array.isArray(input)) {
  1166. for (let pattern of input) {
  1167. let result = braces.create(pattern, options);
  1168. if (Array.isArray(result)) {
  1169. output.push(...result);
  1170. }
  1171. else {
  1172. output.push(result);
  1173. }
  1174. }
  1175. }
  1176. else {
  1177. output = [].concat(braces.create(input, options));
  1178. }
  1179. if (options && options.expand === true && options.nodupes === true) {
  1180. output = [...new Set(output)];
  1181. }
  1182. return output;
  1183. };
  1184. /**
  1185. * Parse the given `str` with the given `options`.
  1186. *
  1187. * ```js
  1188. * // braces.parse(pattern, [, options]);
  1189. * const ast = braces.parse('a/{b,c}/d');
  1190. * console.log(ast);
  1191. * ```
  1192. * @param {String} pattern Brace pattern to parse
  1193. * @param {Object} options
  1194. * @return {Object} Returns an AST
  1195. * @api public
  1196. */
  1197. braces.parse = (input, options = {}) => parse_1(input, options);
  1198. /**
  1199. * Creates a braces string from an AST, or an AST node.
  1200. *
  1201. * ```js
  1202. * const braces = require('braces');
  1203. * let ast = braces.parse('foo/{a,b}/bar');
  1204. * console.log(stringify(ast.nodes[2])); //=> '{a,b}'
  1205. * ```
  1206. * @param {String} `input` Brace pattern or AST.
  1207. * @param {Object} `options`
  1208. * @return {Array} Returns an array of expanded values.
  1209. * @api public
  1210. */
  1211. braces.stringify = (input, options = {}) => {
  1212. if (typeof input === 'string') {
  1213. return stringify(braces.parse(input, options), options);
  1214. }
  1215. return stringify(input, options);
  1216. };
  1217. /**
  1218. * Compiles a brace pattern into a regex-compatible, optimized string.
  1219. * This method is called by the main [braces](#braces) function by default.
  1220. *
  1221. * ```js
  1222. * const braces = require('braces');
  1223. * console.log(braces.compile('a/{b,c}/d'));
  1224. * //=> ['a/(b|c)/d']
  1225. * ```
  1226. * @param {String} `input` Brace pattern or AST.
  1227. * @param {Object} `options`
  1228. * @return {Array} Returns an array of expanded values.
  1229. * @api public
  1230. */
  1231. braces.compile = (input, options = {}) => {
  1232. if (typeof input === 'string') {
  1233. input = braces.parse(input, options);
  1234. }
  1235. return compile_1(input, options);
  1236. };
  1237. /**
  1238. * Expands a brace pattern into an array. This method is called by the
  1239. * main [braces](#braces) function when `options.expand` is true. Before
  1240. * using this method it's recommended that you read the [performance notes](#performance))
  1241. * and advantages of using [.compile](#compile) instead.
  1242. *
  1243. * ```js
  1244. * const braces = require('braces');
  1245. * console.log(braces.expand('a/{b,c}/d'));
  1246. * //=> ['a/b/d', 'a/c/d'];
  1247. * ```
  1248. * @param {String} `pattern` Brace pattern
  1249. * @param {Object} `options`
  1250. * @return {Array} Returns an array of expanded values.
  1251. * @api public
  1252. */
  1253. braces.expand = (input, options = {}) => {
  1254. if (typeof input === 'string') {
  1255. input = braces.parse(input, options);
  1256. }
  1257. let result = expand_1(input, options);
  1258. // filter out empty strings if specified
  1259. if (options.noempty === true) {
  1260. result = result.filter(Boolean);
  1261. }
  1262. // filter out duplicates if specified
  1263. if (options.nodupes === true) {
  1264. result = [...new Set(result)];
  1265. }
  1266. return result;
  1267. };
  1268. /**
  1269. * Processes a brace pattern and returns either an expanded array
  1270. * (if `options.expand` is true), a highly optimized regex-compatible string.
  1271. * This method is called by the main [braces](#braces) function.
  1272. *
  1273. * ```js
  1274. * const braces = require('braces');
  1275. * console.log(braces.create('user-{200..300}/project-{a,b,c}-{1..10}'))
  1276. * //=> 'user-(20[0-9]|2[1-9][0-9]|300)/project-(a|b|c)-([1-9]|10)'
  1277. * ```
  1278. * @param {String} `pattern` Brace pattern
  1279. * @param {Object} `options`
  1280. * @return {Array} Returns an array of expanded values.
  1281. * @api public
  1282. */
  1283. braces.create = (input, options = {}) => {
  1284. if (input === '' || input.length < 3) {
  1285. return [input];
  1286. }
  1287. return options.expand !== true
  1288. ? braces.compile(input, options)
  1289. : braces.expand(input, options);
  1290. };
  1291. /**
  1292. * Expose "braces"
  1293. */
  1294. var braces_1 = braces;
  1295. const WIN_SLASH = '\\\\/';
  1296. const WIN_NO_SLASH = `[^${WIN_SLASH}]`;
  1297. /**
  1298. * Posix glob regex
  1299. */
  1300. const DOT_LITERAL = '\\.';
  1301. const PLUS_LITERAL = '\\+';
  1302. const QMARK_LITERAL = '\\?';
  1303. const SLASH_LITERAL = '\\/';
  1304. const ONE_CHAR = '(?=.)';
  1305. const QMARK = '[^/]';
  1306. const END_ANCHOR = `(?:${SLASH_LITERAL}|$)`;
  1307. const START_ANCHOR = `(?:^|${SLASH_LITERAL})`;
  1308. const DOTS_SLASH = `${DOT_LITERAL}{1,2}${END_ANCHOR}`;
  1309. const NO_DOT = `(?!${DOT_LITERAL})`;
  1310. const NO_DOTS = `(?!${START_ANCHOR}${DOTS_SLASH})`;
  1311. const NO_DOT_SLASH = `(?!${DOT_LITERAL}{0,1}${END_ANCHOR})`;
  1312. const NO_DOTS_SLASH = `(?!${DOTS_SLASH})`;
  1313. const QMARK_NO_DOT = `[^.${SLASH_LITERAL}]`;
  1314. const STAR = `${QMARK}*?`;
  1315. const POSIX_CHARS = {
  1316. DOT_LITERAL,
  1317. PLUS_LITERAL,
  1318. QMARK_LITERAL,
  1319. SLASH_LITERAL,
  1320. ONE_CHAR,
  1321. QMARK,
  1322. END_ANCHOR,
  1323. DOTS_SLASH,
  1324. NO_DOT,
  1325. NO_DOTS,
  1326. NO_DOT_SLASH,
  1327. NO_DOTS_SLASH,
  1328. QMARK_NO_DOT,
  1329. STAR,
  1330. START_ANCHOR
  1331. };
  1332. /**
  1333. * Windows glob regex
  1334. */
  1335. const WINDOWS_CHARS = Object.assign({}, POSIX_CHARS, { SLASH_LITERAL: `[${WIN_SLASH}]`, QMARK: WIN_NO_SLASH, STAR: `${WIN_NO_SLASH}*?`, DOTS_SLASH: `${DOT_LITERAL}{1,2}(?:[${WIN_SLASH}]|$)`, NO_DOT: `(?!${DOT_LITERAL})`, NO_DOTS: `(?!(?:^|[${WIN_SLASH}])${DOT_LITERAL}{1,2}(?:[${WIN_SLASH}]|$))`, NO_DOT_SLASH: `(?!${DOT_LITERAL}{0,1}(?:[${WIN_SLASH}]|$))`, NO_DOTS_SLASH: `(?!${DOT_LITERAL}{1,2}(?:[${WIN_SLASH}]|$))`, QMARK_NO_DOT: `[^.${WIN_SLASH}]`, START_ANCHOR: `(?:^|[${WIN_SLASH}])`, END_ANCHOR: `(?:[${WIN_SLASH}]|$)` });
  1336. /**
  1337. * POSIX Bracket Regex
  1338. */
  1339. const POSIX_REGEX_SOURCE = {
  1340. alnum: 'a-zA-Z0-9',
  1341. alpha: 'a-zA-Z',
  1342. ascii: '\\x00-\\x7F',
  1343. blank: ' \\t',
  1344. cntrl: '\\x00-\\x1F\\x7F',
  1345. digit: '0-9',
  1346. graph: '\\x21-\\x7E',
  1347. lower: 'a-z',
  1348. print: '\\x20-\\x7E ',
  1349. punct: '\\-!"#$%&\'()\\*+,./:;<=>?@[\\]^_`{|}~',
  1350. space: ' \\t\\r\\n\\v\\f',
  1351. upper: 'A-Z',
  1352. word: 'A-Za-z0-9_',
  1353. xdigit: 'A-Fa-f0-9'
  1354. };
  1355. var constants$1 = {
  1356. MAX_LENGTH: 1024 * 64,
  1357. POSIX_REGEX_SOURCE,
  1358. // regular expressions
  1359. REGEX_BACKSLASH: /\\(?![*+?^${}(|)[\]])/g,
  1360. REGEX_NON_SPECIAL_CHAR: /^[^@![\].,$*+?^{}()|\\/]+/,
  1361. REGEX_SPECIAL_CHARS: /[-*+?.^${}(|)[\]]/,
  1362. REGEX_SPECIAL_CHARS_BACKREF: /(\\?)((\W)(\3*))/g,
  1363. REGEX_SPECIAL_CHARS_GLOBAL: /([-*+?.^${}(|)[\]])/g,
  1364. REGEX_REMOVE_BACKSLASH: /(?:\[.*?[^\\]\]|\\(?=.))/g,
  1365. // Replace globs with equivalent patterns to reduce parsing time.
  1366. REPLACEMENTS: {
  1367. '***': '*',
  1368. '**/**': '**',
  1369. '**/**/**': '**'
  1370. },
  1371. // Digits
  1372. CHAR_0: 48,
  1373. CHAR_9: 57,
  1374. // Alphabet chars.
  1375. CHAR_UPPERCASE_A: 65,
  1376. CHAR_LOWERCASE_A: 97,
  1377. CHAR_UPPERCASE_Z: 90,
  1378. CHAR_LOWERCASE_Z: 122,
  1379. CHAR_LEFT_PARENTHESES: 40,
  1380. CHAR_RIGHT_PARENTHESES: 41,
  1381. CHAR_ASTERISK: 42,
  1382. // Non-alphabetic chars.
  1383. CHAR_AMPERSAND: 38,
  1384. CHAR_AT: 64,
  1385. CHAR_BACKWARD_SLASH: 92,
  1386. CHAR_CARRIAGE_RETURN: 13,
  1387. CHAR_CIRCUMFLEX_ACCENT: 94,
  1388. CHAR_COLON: 58,
  1389. CHAR_COMMA: 44,
  1390. CHAR_DOT: 46,
  1391. CHAR_DOUBLE_QUOTE: 34,
  1392. CHAR_EQUAL: 61,
  1393. CHAR_EXCLAMATION_MARK: 33,
  1394. CHAR_FORM_FEED: 12,
  1395. CHAR_FORWARD_SLASH: 47,
  1396. CHAR_GRAVE_ACCENT: 96,
  1397. CHAR_HASH: 35,
  1398. CHAR_HYPHEN_MINUS: 45,
  1399. CHAR_LEFT_ANGLE_BRACKET: 60,
  1400. CHAR_LEFT_CURLY_BRACE: 123,
  1401. CHAR_LEFT_SQUARE_BRACKET: 91,
  1402. CHAR_LINE_FEED: 10,
  1403. CHAR_NO_BREAK_SPACE: 160,
  1404. CHAR_PERCENT: 37,
  1405. CHAR_PLUS: 43,
  1406. CHAR_QUESTION_MARK: 63,
  1407. CHAR_RIGHT_ANGLE_BRACKET: 62,
  1408. CHAR_RIGHT_CURLY_BRACE: 125,
  1409. CHAR_RIGHT_SQUARE_BRACKET: 93,
  1410. CHAR_SEMICOLON: 59,
  1411. CHAR_SINGLE_QUOTE: 39,
  1412. CHAR_SPACE: 32,
  1413. CHAR_TAB: 9,
  1414. CHAR_UNDERSCORE: 95,
  1415. CHAR_VERTICAL_LINE: 124,
  1416. CHAR_ZERO_WIDTH_NOBREAK_SPACE: 65279,
  1417. SEP: path__default.sep,
  1418. /**
  1419. * Create EXTGLOB_CHARS
  1420. */
  1421. extglobChars(chars) {
  1422. return {
  1423. '!': { type: 'negate', open: '(?:(?!(?:', close: `))${chars.STAR})` },
  1424. '?': { type: 'qmark', open: '(?:', close: ')?' },
  1425. '+': { type: 'plus', open: '(?:', close: ')+' },
  1426. '*': { type: 'star', open: '(?:', close: ')*' },
  1427. '@': { type: 'at', open: '(?:', close: ')' }
  1428. };
  1429. },
  1430. /**
  1431. * Create GLOB_CHARS
  1432. */
  1433. globChars(win32) {
  1434. return win32 === true ? WINDOWS_CHARS : POSIX_CHARS;
  1435. }
  1436. };
  1437. var utils$1 = createCommonjsModule(function (module, exports) {
  1438. const win32 = process.platform === 'win32';
  1439. const { REGEX_SPECIAL_CHARS, REGEX_SPECIAL_CHARS_GLOBAL, REGEX_REMOVE_BACKSLASH } = constants$1;
  1440. exports.isObject = val => val !== null && typeof val === 'object' && !Array.isArray(val);
  1441. exports.hasRegexChars = str => REGEX_SPECIAL_CHARS.test(str);
  1442. exports.isRegexChar = str => str.length === 1 && exports.hasRegexChars(str);
  1443. exports.escapeRegex = str => str.replace(REGEX_SPECIAL_CHARS_GLOBAL, '\\$1');
  1444. exports.toPosixSlashes = str => str.replace(/\\/g, '/');
  1445. exports.removeBackslashes = str => {
  1446. return str.replace(REGEX_REMOVE_BACKSLASH, match => {
  1447. return match === '\\' ? '' : match;
  1448. });
  1449. };
  1450. exports.supportsLookbehinds = () => {
  1451. let segs = process.version.slice(1).split('.');
  1452. if (segs.length === 3 && +segs[0] >= 9 || (+segs[0] === 8 && +segs[1] >= 10)) {
  1453. return true;
  1454. }
  1455. return false;
  1456. };
  1457. exports.isWindows = options => {
  1458. if (options && typeof options.windows === 'boolean') {
  1459. return options.windows;
  1460. }
  1461. return win32 === true || path__default.sep === '\\';
  1462. };
  1463. exports.escapeLast = (input, char, lastIdx) => {
  1464. let idx = input.lastIndexOf(char, lastIdx);
  1465. if (idx === -1)
  1466. return input;
  1467. if (input[idx - 1] === '\\')
  1468. return exports.escapeLast(input, char, idx - 1);
  1469. return input.slice(0, idx) + '\\' + input.slice(idx);
  1470. };
  1471. });
  1472. var utils_1$1 = utils$1.isObject;
  1473. var utils_2$1 = utils$1.hasRegexChars;
  1474. var utils_3$1 = utils$1.isRegexChar;
  1475. var utils_4$1 = utils$1.escapeRegex;
  1476. var utils_5$1 = utils$1.toPosixSlashes;
  1477. var utils_6$1 = utils$1.removeBackslashes;
  1478. var utils_7$1 = utils$1.supportsLookbehinds;
  1479. var utils_8$1 = utils$1.isWindows;
  1480. var utils_9$1 = utils$1.escapeLast;
  1481. const { CHAR_ASTERISK, /* * */ CHAR_AT, /* @ */ CHAR_BACKWARD_SLASH, /* \ */ CHAR_COMMA: CHAR_COMMA$1, /* , */ CHAR_DOT: CHAR_DOT$1, /* . */ CHAR_EXCLAMATION_MARK, /* ! */ CHAR_FORWARD_SLASH, /* / */ CHAR_LEFT_CURLY_BRACE: CHAR_LEFT_CURLY_BRACE$1, /* { */ CHAR_LEFT_PARENTHESES: CHAR_LEFT_PARENTHESES$1, /* ( */ CHAR_LEFT_SQUARE_BRACKET: CHAR_LEFT_SQUARE_BRACKET$1, /* [ */ CHAR_PLUS, /* + */ CHAR_QUESTION_MARK, /* ? */ CHAR_RIGHT_CURLY_BRACE: CHAR_RIGHT_CURLY_BRACE$1, /* } */ CHAR_RIGHT_PARENTHESES: CHAR_RIGHT_PARENTHESES$1, /* ) */ CHAR_RIGHT_SQUARE_BRACKET: CHAR_RIGHT_SQUARE_BRACKET$1 /* ] */ } = constants$1;
  1482. const isPathSeparator = code => {
  1483. return code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH;
  1484. };
  1485. /**
  1486. * Quickly scans a glob pattern and returns an object with a handful of
  1487. * useful properties, like `isGlob`, `path` (the leading non-glob, if it exists),
  1488. * `glob` (the actual pattern), and `negated` (true if the path starts with `!`).
  1489. *
  1490. * ```js
  1491. * const pm = require('picomatch');
  1492. * console.log(pm.scan('foo/bar/*.js'));
  1493. * { isGlob: true, input: 'foo/bar/*.js', base: 'foo/bar', glob: '*.js' }
  1494. * ```
  1495. * @param {String} `str`
  1496. * @param {Object} `options`
  1497. * @return {Object} Returns an object with tokens and regex source string.
  1498. * @api public
  1499. */
  1500. var scan = (input, options) => {
  1501. let opts = options || {};
  1502. let length = input.length - 1;
  1503. let index = -1;
  1504. let start = 0;
  1505. let lastIndex = 0;
  1506. let isGlob = false;
  1507. let backslashes = false;
  1508. let negated = false;
  1509. let braces = 0;
  1510. let prev;
  1511. let code;
  1512. let braceEscaped = false;
  1513. let eos = () => index >= length;
  1514. let advance = () => {
  1515. prev = code;
  1516. return input.charCodeAt(++index);
  1517. };
  1518. while (index < length) {
  1519. code = advance();
  1520. let next;
  1521. if (code === CHAR_BACKWARD_SLASH) {
  1522. backslashes = true;
  1523. next = advance();
  1524. if (next === CHAR_LEFT_CURLY_BRACE$1) {
  1525. braceEscaped = true;
  1526. }
  1527. continue;
  1528. }
  1529. if (braceEscaped === true || code === CHAR_LEFT_CURLY_BRACE$1) {
  1530. braces++;
  1531. while (!eos() && (next = advance())) {
  1532. if (next === CHAR_BACKWARD_SLASH) {
  1533. backslashes = true;
  1534. next = advance();
  1535. continue;
  1536. }
  1537. if (next === CHAR_LEFT_CURLY_BRACE$1) {
  1538. braces++;
  1539. continue;
  1540. }
  1541. if (!braceEscaped && next === CHAR_DOT$1 && (next = advance()) === CHAR_DOT$1) {
  1542. isGlob = true;
  1543. break;
  1544. }
  1545. if (!braceEscaped && next === CHAR_COMMA$1) {
  1546. isGlob = true;
  1547. break;
  1548. }
  1549. if (next === CHAR_RIGHT_CURLY_BRACE$1) {
  1550. braces--;
  1551. if (braces === 0) {
  1552. braceEscaped = false;
  1553. break;
  1554. }
  1555. }
  1556. }
  1557. }
  1558. if (code === CHAR_FORWARD_SLASH) {
  1559. if (prev === CHAR_DOT$1 && index === (start + 1)) {
  1560. start += 2;
  1561. continue;
  1562. }
  1563. lastIndex = index + 1;
  1564. continue;
  1565. }
  1566. if (code === CHAR_ASTERISK) {
  1567. isGlob = true;
  1568. break;
  1569. }
  1570. if (code === CHAR_ASTERISK || code === CHAR_QUESTION_MARK) {
  1571. isGlob = true;
  1572. break;
  1573. }
  1574. if (code === CHAR_LEFT_SQUARE_BRACKET$1) {
  1575. while (!eos() && (next = advance())) {
  1576. if (next === CHAR_BACKWARD_SLASH) {
  1577. backslashes = true;
  1578. next = advance();
  1579. continue;
  1580. }
  1581. if (next === CHAR_RIGHT_SQUARE_BRACKET$1) {
  1582. isGlob = true;
  1583. break;
  1584. }
  1585. }
  1586. }
  1587. let isExtglobChar = code === CHAR_PLUS
  1588. || code === CHAR_AT
  1589. || code === CHAR_EXCLAMATION_MARK;
  1590. if (isExtglobChar && input.charCodeAt(index + 1) === CHAR_LEFT_PARENTHESES$1) {
  1591. isGlob = true;
  1592. break;
  1593. }
  1594. if (code === CHAR_EXCLAMATION_MARK && index === start) {
  1595. negated = true;
  1596. start++;
  1597. continue;
  1598. }
  1599. if (code === CHAR_LEFT_PARENTHESES$1) {
  1600. while (!eos() && (next = advance())) {
  1601. if (next === CHAR_BACKWARD_SLASH) {
  1602. backslashes = true;
  1603. next = advance();
  1604. continue;
  1605. }
  1606. if (next === CHAR_RIGHT_PARENTHESES$1) {
  1607. isGlob = true;
  1608. break;
  1609. }
  1610. }
  1611. }
  1612. if (isGlob) {
  1613. break;
  1614. }
  1615. }
  1616. let prefix = '';
  1617. let orig = input;
  1618. let base = input;
  1619. let glob = '';
  1620. if (start > 0) {
  1621. prefix = input.slice(0, start);
  1622. input = input.slice(start);
  1623. lastIndex -= start;
  1624. }
  1625. if (base && isGlob === true && lastIndex > 0) {
  1626. base = input.slice(0, lastIndex);
  1627. glob = input.slice(lastIndex);
  1628. }
  1629. else if (isGlob === true) {
  1630. base = '';
  1631. glob = input;
  1632. }
  1633. else {
  1634. base = input;
  1635. }
  1636. if (base && base !== '' && base !== '/' && base !== input) {
  1637. if (isPathSeparator(base.charCodeAt(base.length - 1))) {
  1638. base = base.slice(0, -1);
  1639. }
  1640. }
  1641. if (opts.unescape === true) {
  1642. if (glob)
  1643. glob = utils$1.removeBackslashes(glob);
  1644. if (base && backslashes === true) {
  1645. base = utils$1.removeBackslashes(base);
  1646. }
  1647. }
  1648. return { prefix, input: orig, base, glob, negated, isGlob };
  1649. };
  1650. /**
  1651. * Constants
  1652. */
  1653. const { MAX_LENGTH: MAX_LENGTH$1, POSIX_REGEX_SOURCE: POSIX_REGEX_SOURCE$1, REGEX_NON_SPECIAL_CHAR, REGEX_SPECIAL_CHARS_BACKREF, REPLACEMENTS } = constants$1;
  1654. /**
  1655. * Helpers
  1656. */
  1657. const expandRange = (args, options) => {
  1658. if (typeof options.expandRange === 'function') {
  1659. return options.expandRange(...args, options);
  1660. }
  1661. args.sort();
  1662. let value = `[${args.join('-')}]`;
  1663. try {
  1664. }
  1665. catch (ex) {
  1666. return args.map(v => utils$1.escapeRegex(v)).join('..');
  1667. }
  1668. return value;
  1669. };
  1670. const negate = state => {
  1671. let count = 1;
  1672. while (state.peek() === '!' && (state.peek(2) !== '(' || state.peek(3) === '?')) {
  1673. state.advance();
  1674. state.start++;
  1675. count++;
  1676. }
  1677. if (count % 2 === 0) {
  1678. return false;
  1679. }
  1680. state.negated = true;
  1681. state.start++;
  1682. return true;
  1683. };
  1684. /**
  1685. * Create the message for a syntax error
  1686. */
  1687. const syntaxError = (type, char) => {
  1688. return `Missing ${type}: "${char}" - use "\\\\${char}" to match literal characters`;
  1689. };
  1690. /**
  1691. * Parse the given input string.
  1692. * @param {String} input
  1693. * @param {Object} options
  1694. * @return {Object}
  1695. */
  1696. const parse$1 = (input, options) => {
  1697. if (typeof input !== 'string') {
  1698. throw new TypeError('Expected a string');
  1699. }
  1700. input = REPLACEMENTS[input] || input;
  1701. let opts = Object.assign({}, options);
  1702. let max = typeof opts.maxLength === 'number' ? Math.min(MAX_LENGTH$1, opts.maxLength) : MAX_LENGTH$1;
  1703. let len = input.length;
  1704. if (len > max) {
  1705. throw new SyntaxError(`Input length: ${len}, exceeds maximum allowed length: ${max}`);
  1706. }
  1707. let bos = { type: 'bos', value: '', output: opts.prepend || '' };
  1708. let tokens = [bos];
  1709. let capture = opts.capture ? '' : '?:';
  1710. let win32 = utils$1.isWindows(options);
  1711. // create constants based on platform, for windows or posix
  1712. const PLATFORM_CHARS = constants$1.globChars(win32);
  1713. const EXTGLOB_CHARS = constants$1.extglobChars(PLATFORM_CHARS);
  1714. const { DOT_LITERAL, PLUS_LITERAL, SLASH_LITERAL, ONE_CHAR, DOTS_SLASH, NO_DOT, NO_DOT_SLASH, NO_DOTS_SLASH, QMARK, QMARK_NO_DOT, STAR, START_ANCHOR } = PLATFORM_CHARS;
  1715. const globstar = (opts) => {
  1716. return `(${capture}(?:(?!${START_ANCHOR}${opts.dot ? DOTS_SLASH : DOT_LITERAL}).)*?)`;
  1717. };
  1718. let nodot = opts.dot ? '' : NO_DOT;
  1719. let star = opts.bash === true ? globstar(opts) : STAR;
  1720. let qmarkNoDot = opts.dot ? QMARK : QMARK_NO_DOT;
  1721. if (opts.capture) {
  1722. star = `(${star})`;
  1723. }
  1724. // minimatch options support
  1725. if (typeof opts.noext === 'boolean') {
  1726. opts.noextglob = opts.noext;
  1727. }
  1728. let state = {
  1729. index: -1,
  1730. start: 0,
  1731. consumed: '',
  1732. output: '',
  1733. backtrack: false,
  1734. brackets: 0,
  1735. braces: 0,
  1736. parens: 0,
  1737. quotes: 0,
  1738. tokens
  1739. };
  1740. let extglobs = [];
  1741. let stack = [];
  1742. let prev = bos;
  1743. let value;
  1744. /**
  1745. * Tokenizing helpers
  1746. */
  1747. const eos = () => state.index === len - 1;
  1748. const peek = state.peek = (n = 1) => input[state.index + n];
  1749. const advance = state.advance = () => input[++state.index];
  1750. const append = token => {
  1751. state.output += token.output != null ? token.output : token.value;
  1752. state.consumed += token.value || '';
  1753. };
  1754. const increment = type => {
  1755. state[type]++;
  1756. stack.push(type);
  1757. };
  1758. const decrement = type => {
  1759. state[type]--;
  1760. stack.pop();
  1761. };
  1762. /**
  1763. * Push tokens onto the tokens array. This helper speeds up
  1764. * tokenizing by 1) helping us avoid backtracking as much as possible,
  1765. * and 2) helping us avoid creating extra tokens when consecutive
  1766. * characters are plain text. This improves performance and simplifies
  1767. * lookbehinds.
  1768. */
  1769. const push = tok => {
  1770. if (prev.type === 'globstar') {
  1771. let isBrace = state.braces > 0 && (tok.type === 'comma' || tok.type === 'brace');
  1772. let isExtglob = extglobs.length && (tok.type === 'pipe' || tok.type === 'paren');
  1773. if (tok.type !== 'slash' && tok.type !== 'paren' && !isBrace && !isExtglob) {
  1774. state.output = state.output.slice(0, -prev.output.length);
  1775. prev.type = 'star';
  1776. prev.value = '*';
  1777. prev.output = star;
  1778. state.output += prev.output;
  1779. }
  1780. }
  1781. if (extglobs.length && tok.type !== 'paren' && !EXTGLOB_CHARS[tok.value]) {
  1782. extglobs[extglobs.length - 1].inner += tok.value;
  1783. }
  1784. if (tok.value || tok.output)
  1785. append(tok);
  1786. if (prev && prev.type === 'text' && tok.type === 'text') {
  1787. prev.value += tok.value;
  1788. return;
  1789. }
  1790. tok.prev = prev;
  1791. tokens.push(tok);
  1792. prev = tok;
  1793. };
  1794. const extglobOpen = (type, value) => {
  1795. let token = Object.assign({}, EXTGLOB_CHARS[value], { conditions: 1, inner: '' });
  1796. token.prev = prev;
  1797. token.parens = state.parens;
  1798. token.output = state.output;
  1799. let output = (opts.capture ? '(' : '') + token.open;
  1800. push({ type, value, output: state.output ? '' : ONE_CHAR });
  1801. push({ type: 'paren', extglob: true, value: advance(), output });
  1802. increment('parens');
  1803. extglobs.push(token);
  1804. };
  1805. const extglobClose = token => {
  1806. let output = token.close + (opts.capture ? ')' : '');
  1807. if (token.type === 'negate') {
  1808. let extglobStar = star;
  1809. if (token.inner && token.inner.length > 1 && token.inner.includes('/')) {
  1810. extglobStar = globstar(opts);
  1811. }
  1812. if (extglobStar !== star || eos() || /^\)+$/.test(input.slice(state.index + 1))) {
  1813. output = token.close = ')$))' + extglobStar;
  1814. }
  1815. if (token.prev.type === 'bos' && eos()) {
  1816. state.negatedExtglob = true;
  1817. }
  1818. }
  1819. push({ type: 'paren', extglob: true, value, output });
  1820. decrement('parens');
  1821. };
  1822. if (opts.fastpaths !== false && !/(^[*!]|[/{[()\]}"])/.test(input)) {
  1823. let backslashes = false;
  1824. let output = input.replace(REGEX_SPECIAL_CHARS_BACKREF, (m, esc, chars, first, rest, index) => {
  1825. if (first === '\\') {
  1826. backslashes = true;
  1827. return m;
  1828. }
  1829. if (first === '?') {
  1830. if (esc) {
  1831. return esc + first + (rest ? QMARK.repeat(rest.length) : '');
  1832. }
  1833. if (index === 0) {
  1834. return qmarkNoDot + (rest ? QMARK.repeat(rest.length) : '');
  1835. }
  1836. return QMARK.repeat(chars.length);
  1837. }
  1838. if (first === '.') {
  1839. return DOT_LITERAL.repeat(chars.length);
  1840. }
  1841. if (first === '*') {
  1842. if (esc) {
  1843. return esc + first + (rest ? star : '');
  1844. }
  1845. return star;
  1846. }
  1847. return esc ? m : '\\' + m;
  1848. });
  1849. if (backslashes === true) {
  1850. if (opts.unescape === true) {
  1851. output = output.replace(/\\/g, '');
  1852. }
  1853. else {
  1854. output = output.replace(/\\+/g, m => {
  1855. return m.length % 2 === 0 ? '\\\\' : (m ? '\\' : '');
  1856. });
  1857. }
  1858. }
  1859. state.output = output;
  1860. return state;
  1861. }
  1862. /**
  1863. * Tokenize input until we reach end-of-string
  1864. */
  1865. while (!eos()) {
  1866. value = advance();
  1867. if (value === '\u0000') {
  1868. continue;
  1869. }
  1870. /**
  1871. * Escaped characters
  1872. */
  1873. if (value === '\\') {
  1874. let next = peek();
  1875. if (next === '/' && opts.bash !== true) {
  1876. continue;
  1877. }
  1878. if (next === '.' || next === ';') {
  1879. continue;
  1880. }
  1881. if (!next) {
  1882. value += '\\';
  1883. push({ type: 'text', value });
  1884. continue;
  1885. }
  1886. // collapse slashes to reduce potential for exploits
  1887. let match = /^\\+/.exec(input.slice(state.index + 1));
  1888. let slashes = 0;
  1889. if (match && match[0].length > 2) {
  1890. slashes = match[0].length;
  1891. state.index += slashes;
  1892. if (slashes % 2 !== 0) {
  1893. value += '\\';
  1894. }
  1895. }
  1896. if (opts.unescape === true) {
  1897. value = advance() || '';
  1898. }
  1899. else {
  1900. value += advance() || '';
  1901. }
  1902. if (state.brackets === 0) {
  1903. push({ type: 'text', value });
  1904. continue;
  1905. }
  1906. }
  1907. /**
  1908. * If we're inside a regex character class, continue
  1909. * until we reach the closing bracket.
  1910. */
  1911. if (state.brackets > 0 && (value !== ']' || prev.value === '[' || prev.value === '[^')) {
  1912. if (opts.posix !== false && value === ':') {
  1913. let inner = prev.value.slice(1);
  1914. if (inner.includes('[')) {
  1915. prev.posix = true;
  1916. if (inner.includes(':')) {
  1917. let idx = prev.value.lastIndexOf('[');
  1918. let pre = prev.value.slice(0, idx);
  1919. let rest = prev.value.slice(idx + 2);
  1920. let posix = POSIX_REGEX_SOURCE$1[rest];
  1921. if (posix) {
  1922. prev.value = pre + posix;
  1923. state.backtrack = true;
  1924. advance();
  1925. if (!bos.output && tokens.indexOf(prev) === 1) {
  1926. bos.output = ONE_CHAR;
  1927. }
  1928. continue;
  1929. }
  1930. }
  1931. }
  1932. }
  1933. if ((value === '[' && peek() !== ':') || (value === '-' && peek() === ']')) {
  1934. value = '\\' + value;
  1935. }
  1936. if (value === ']' && (prev.value === '[' || prev.value === '[^')) {
  1937. value = '\\' + value;
  1938. }
  1939. if (opts.posix === true && value === '!' && prev.value === '[') {
  1940. value = '^';
  1941. }
  1942. prev.value += value;
  1943. append({ value });
  1944. continue;
  1945. }
  1946. /**
  1947. * If we're inside a quoted string, continue
  1948. * until we reach the closing double quote.
  1949. */
  1950. if (state.quotes === 1 && value !== '"') {
  1951. value = utils$1.escapeRegex(value);
  1952. prev.value += value;
  1953. append({ value });
  1954. continue;
  1955. }
  1956. /**
  1957. * Double quotes
  1958. */
  1959. if (value === '"') {
  1960. state.quotes = state.quotes === 1 ? 0 : 1;
  1961. if (opts.keepQuotes === true) {
  1962. push({ type: 'text', value });
  1963. }
  1964. continue;
  1965. }
  1966. /**
  1967. * Parentheses
  1968. */
  1969. if (value === '(') {
  1970. push({ type: 'paren', value });
  1971. increment('parens');
  1972. continue;
  1973. }
  1974. if (value === ')') {
  1975. if (state.parens === 0 && opts.strictBrackets === true) {
  1976. throw new SyntaxError(syntaxError('opening', '('));
  1977. }
  1978. let extglob = extglobs[extglobs.length - 1];
  1979. if (extglob && state.parens === extglob.parens + 1) {
  1980. extglobClose(extglobs.pop());
  1981. continue;
  1982. }
  1983. push({ type: 'paren', value, output: state.parens ? ')' : '\\)' });
  1984. decrement('parens');
  1985. continue;
  1986. }
  1987. /**
  1988. * Brackets
  1989. */
  1990. if (value === '[') {
  1991. if (opts.nobracket === true || !input.slice(state.index + 1).includes(']')) {
  1992. if (opts.nobracket !== true && opts.strictBrackets === true) {
  1993. throw new SyntaxError(syntaxError('closing', ']'));
  1994. }
  1995. value = '\\' + value;
  1996. }
  1997. else {
  1998. increment('brackets');
  1999. }
  2000. push({ type: 'bracket', value });
  2001. continue;
  2002. }
  2003. if (value === ']') {
  2004. if (opts.nobracket === true || (prev && prev.type === 'bracket' && prev.value.length === 1)) {
  2005. push({ type: 'text', value, output: '\\' + value });
  2006. continue;
  2007. }
  2008. if (state.brackets === 0) {
  2009. if (opts.strictBrackets === true) {
  2010. throw new SyntaxError(syntaxError('opening', '['));
  2011. }
  2012. push({ type: 'text', value, output: '\\' + value });
  2013. continue;
  2014. }
  2015. decrement('brackets');
  2016. let prevValue = prev.value.slice(1);
  2017. if (prev.posix !== true && prevValue[0] === '^' && !prevValue.includes('/')) {
  2018. value = '/' + value;
  2019. }
  2020. prev.value += value;
  2021. append({ value });
  2022. // when literal brackets are explicitly disabled
  2023. // assume we should match with a regex character class
  2024. if (opts.literalBrackets === false || utils$1.hasRegexChars(prevValue)) {
  2025. continue;
  2026. }
  2027. let escaped = utils$1.escapeRegex(prev.value);
  2028. state.output = state.output.slice(0, -prev.value.length);
  2029. // when literal brackets are explicitly enabled
  2030. // assume we should escape the brackets to match literal characters
  2031. if (opts.literalBrackets === true) {
  2032. state.output += escaped;
  2033. prev.value = escaped;
  2034. continue;
  2035. }
  2036. // when the user specifies nothing, try to match both
  2037. prev.value = `(${capture}${escaped}|${prev.value})`;
  2038. state.output += prev.value;
  2039. continue;
  2040. }
  2041. /**
  2042. * Braces
  2043. */
  2044. if (value === '{' && opts.nobrace !== true) {
  2045. push({ type: 'brace', value, output: '(' });
  2046. increment('braces');
  2047. continue;
  2048. }
  2049. if (value === '}') {
  2050. if (opts.nobrace === true || state.braces === 0) {
  2051. push({ type: 'text', value, output: '\\' + value });
  2052. continue;
  2053. }
  2054. let output = ')';
  2055. if (state.dots === true) {
  2056. let arr = tokens.slice();
  2057. let range = [];
  2058. for (let i = arr.length - 1; i >= 0; i--) {
  2059. tokens.pop();
  2060. if (arr[i].type === 'brace') {
  2061. break;
  2062. }
  2063. if (arr[i].type !== 'dots') {
  2064. range.unshift(arr[i].value);
  2065. }
  2066. }
  2067. output = expandRange(range, opts);
  2068. state.backtrack = true;
  2069. }
  2070. push({ type: 'brace', value, output });
  2071. decrement('braces');
  2072. continue;
  2073. }
  2074. /**
  2075. * Pipes
  2076. */
  2077. if (value === '|') {
  2078. if (extglobs.length > 0) {
  2079. extglobs[extglobs.length - 1].conditions++;
  2080. }
  2081. push({ type: 'text', value });
  2082. continue;
  2083. }
  2084. /**
  2085. * Commas
  2086. */
  2087. if (value === ',') {
  2088. let output = value;
  2089. if (state.braces > 0 && stack[stack.length - 1] === 'braces') {
  2090. output = '|';
  2091. }
  2092. push({ type: 'comma', value, output });
  2093. continue;
  2094. }
  2095. /**
  2096. * Slashes
  2097. */
  2098. if (value === '/') {
  2099. // if the beginning of the glob is "./", advance the start
  2100. // to the current index, and don't add the "./" characters
  2101. // to the state. This greatly simplifies lookbehinds when
  2102. // checking for BOS characters like "!" and "." (not "./")
  2103. if (prev.type === 'dot' && state.index === 1) {
  2104. state.start = state.index + 1;
  2105. state.consumed = '';
  2106. state.output = '';
  2107. tokens.pop();
  2108. prev = bos; // reset "prev" to the first token
  2109. continue;
  2110. }
  2111. push({ type: 'slash', value, output: SLASH_LITERAL });
  2112. continue;
  2113. }
  2114. /**
  2115. * Dots
  2116. */
  2117. if (value === '.') {
  2118. if (state.braces > 0 && prev.type === 'dot') {
  2119. if (prev.value === '.')
  2120. prev.output = DOT_LITERAL;
  2121. prev.type = 'dots';
  2122. prev.output += value;
  2123. prev.value += value;
  2124. state.dots = true;
  2125. continue;
  2126. }
  2127. push({ type: 'dot', value, output: DOT_LITERAL });
  2128. continue;
  2129. }
  2130. /**
  2131. * Question marks
  2132. */
  2133. if (value === '?') {
  2134. if (prev && prev.type === 'paren') {
  2135. let next = peek();
  2136. let output = value;
  2137. if (next === '<' && !utils$1.supportsLookbehinds()) {
  2138. throw new Error('Node.js v10 or higher is required for regex lookbehinds');
  2139. }
  2140. if (prev.value === '(' && !/[!=<:]/.test(next) || (next === '<' && !/[!=]/.test(peek(2)))) {
  2141. output = '\\' + value;
  2142. }
  2143. push({ type: 'text', value, output });
  2144. continue;
  2145. }
  2146. if (opts.noextglob !== true && peek() === '(' && peek(2) !== '?') {
  2147. extglobOpen('qmark', value);
  2148. continue;
  2149. }
  2150. if (opts.dot !== true && (prev.type === 'slash' || prev.type === 'bos')) {
  2151. push({ type: 'qmark', value, output: QMARK_NO_DOT });
  2152. continue;
  2153. }
  2154. push({ type: 'qmark', value, output: QMARK });
  2155. continue;
  2156. }
  2157. /**
  2158. * Exclamation
  2159. */
  2160. if (value === '!') {
  2161. if (opts.noextglob !== true && peek() === '(') {
  2162. if (peek(2) !== '?' || !/[!=<:]/.test(peek(3))) {
  2163. extglobOpen('negate', value);
  2164. continue;
  2165. }
  2166. }
  2167. if (opts.nonegate !== true && state.index === 0) {
  2168. negate(state);
  2169. continue;
  2170. }
  2171. }
  2172. /**
  2173. * Plus
  2174. */
  2175. if (value === '+') {
  2176. if (opts.noextglob !== true && peek() === '(' && peek(2) !== '?') {
  2177. extglobOpen('plus', value);
  2178. continue;
  2179. }
  2180. if (prev && (prev.type === 'bracket' || prev.type === 'paren' || prev.type === 'brace')) {
  2181. let output = prev.extglob === true ? '\\' + value : value;
  2182. push({ type: 'plus', value, output });
  2183. continue;
  2184. }
  2185. // use regex behavior inside parens
  2186. if (state.parens > 0 && opts.regex !== false) {
  2187. push({ type: 'plus', value });
  2188. continue;
  2189. }
  2190. push({ type: 'plus', value: PLUS_LITERAL });
  2191. continue;
  2192. }
  2193. /**
  2194. * Plain text
  2195. */
  2196. if (value === '@') {
  2197. if (opts.noextglob !== true && peek() === '(' && peek(2) !== '?') {
  2198. push({ type: 'at', value, output: '' });
  2199. continue;
  2200. }
  2201. push({ type: 'text', value });
  2202. continue;
  2203. }
  2204. /**
  2205. * Plain text
  2206. */
  2207. if (value !== '*') {
  2208. if (value === '$' || value === '^') {
  2209. value = '\\' + value;
  2210. }
  2211. let match = REGEX_NON_SPECIAL_CHAR.exec(input.slice(state.index + 1));
  2212. if (match) {
  2213. value += match[0];
  2214. state.index += match[0].length;
  2215. }
  2216. push({ type: 'text', value });
  2217. continue;
  2218. }
  2219. /**
  2220. * Stars
  2221. */
  2222. if (prev && (prev.type === 'globstar' || prev.star === true)) {
  2223. prev.type = 'star';
  2224. prev.star = true;
  2225. prev.value += value;
  2226. prev.output = star;
  2227. state.backtrack = true;
  2228. state.consumed += value;
  2229. continue;
  2230. }
  2231. if (opts.noextglob !== true && peek() === '(' && peek(2) !== '?') {
  2232. extglobOpen('star', value);
  2233. continue;
  2234. }
  2235. if (prev.type === 'star') {
  2236. if (opts.noglobstar === true) {
  2237. state.consumed += value;
  2238. continue;
  2239. }
  2240. let prior = prev.prev;
  2241. let before = prior.prev;
  2242. let isStart = prior.type === 'slash' || prior.type === 'bos';
  2243. let afterStar = before && (before.type === 'star' || before.type === 'globstar');
  2244. if (opts.bash === true && (!isStart || (!eos() && peek() !== '/'))) {
  2245. push({ type: 'star', value, output: '' });
  2246. continue;
  2247. }
  2248. let isBrace = state.braces > 0 && (prior.type === 'comma' || prior.type === 'brace');
  2249. let isExtglob = extglobs.length && (prior.type === 'pipe' || prior.type === 'paren');
  2250. if (!isStart && prior.type !== 'paren' && !isBrace && !isExtglob) {
  2251. push({ type: 'star', value, output: '' });
  2252. continue;
  2253. }
  2254. // strip consecutive `/**/`
  2255. while (input.slice(state.index + 1, state.index + 4) === '/**') {
  2256. let after = input[state.index + 4];
  2257. if (after && after !== '/') {
  2258. break;
  2259. }
  2260. state.consumed += '/**';
  2261. state.index += 3;
  2262. }
  2263. if (prior.type === 'bos' && eos()) {
  2264. prev.type = 'globstar';
  2265. prev.value += value;
  2266. prev.output = globstar(opts);
  2267. state.output = prev.output;
  2268. state.consumed += value;
  2269. continue;
  2270. }
  2271. if (prior.type === 'slash' && prior.prev.type !== 'bos' && !afterStar && eos()) {
  2272. state.output = state.output.slice(0, -(prior.output + prev.output).length);
  2273. prior.output = '(?:' + prior.output;
  2274. prev.type = 'globstar';
  2275. prev.output = globstar(opts) + '|$)';
  2276. prev.value += value;
  2277. state.output += prior.output + prev.output;
  2278. state.consumed += value;
  2279. continue;
  2280. }
  2281. let next = peek();
  2282. if (prior.type === 'slash' && prior.prev.type !== 'bos' && next === '/') {
  2283. let end = peek(2) !== void 0 ? '|$' : '';
  2284. state.output = state.output.slice(0, -(prior.output + prev.output).length);
  2285. prior.output = '(?:' + prior.output;
  2286. prev.type = 'globstar';
  2287. prev.output = `${globstar(opts)}${SLASH_LITERAL}|${SLASH_LITERAL}${end})`;
  2288. prev.value += value;
  2289. state.output += prior.output + prev.output;
  2290. state.consumed += value + advance();
  2291. push({ type: 'slash', value, output: '' });
  2292. continue;
  2293. }
  2294. if (prior.type === 'bos' && next === '/') {
  2295. prev.type = 'globstar';
  2296. prev.value += value;
  2297. prev.output = `(?:^|${SLASH_LITERAL}|${globstar(opts)}${SLASH_LITERAL})`;
  2298. state.output = prev.output;
  2299. state.consumed += value + advance();
  2300. push({ type: 'slash', value, output: '' });
  2301. continue;
  2302. }
  2303. // remove single star from output
  2304. state.output = state.output.slice(0, -prev.output.length);
  2305. // reset previous token to globstar
  2306. prev.type = 'globstar';
  2307. prev.output = globstar(opts);
  2308. prev.value += value;
  2309. // reset output with globstar
  2310. state.output += prev.output;
  2311. state.consumed += value;
  2312. continue;
  2313. }
  2314. let token = { type: 'star', value, output: star };
  2315. if (opts.bash === true) {
  2316. token.output = '.*?';
  2317. if (prev.type === 'bos' || prev.type === 'slash') {
  2318. token.output = nodot + token.output;
  2319. }
  2320. push(token);
  2321. continue;
  2322. }
  2323. if (prev && (prev.type === 'bracket' || prev.type === 'paren') && opts.regex === true) {
  2324. token.output = value;
  2325. push(token);
  2326. continue;
  2327. }
  2328. if (state.index === state.start || prev.type === 'slash' || prev.type === 'dot') {
  2329. if (prev.type === 'dot') {
  2330. state.output += NO_DOT_SLASH;
  2331. prev.output += NO_DOT_SLASH;
  2332. }
  2333. else if (opts.dot === true) {
  2334. state.output += NO_DOTS_SLASH;
  2335. prev.output += NO_DOTS_SLASH;
  2336. }
  2337. else {
  2338. state.output += nodot;
  2339. prev.output += nodot;
  2340. }
  2341. if (peek() !== '*') {
  2342. state.output += ONE_CHAR;
  2343. prev.output += ONE_CHAR;
  2344. }
  2345. }
  2346. push(token);
  2347. }
  2348. while (state.brackets > 0) {
  2349. if (opts.strictBrackets === true)
  2350. throw new SyntaxError(syntaxError('closing', ']'));
  2351. state.output = utils$1.escapeLast(state.output, '[');
  2352. decrement('brackets');
  2353. }
  2354. while (state.parens > 0) {
  2355. if (opts.strictBrackets === true)
  2356. throw new SyntaxError(syntaxError('closing', ')'));
  2357. state.output = utils$1.escapeLast(state.output, '(');
  2358. decrement('parens');
  2359. }
  2360. while (state.braces > 0) {
  2361. if (opts.strictBrackets === true)
  2362. throw new SyntaxError(syntaxError('closing', '}'));
  2363. state.output = utils$1.escapeLast(state.output, '{');
  2364. decrement('braces');
  2365. }
  2366. if (opts.strictSlashes !== true && (prev.type === 'star' || prev.type === 'bracket')) {
  2367. push({ type: 'maybe_slash', value: '', output: `${SLASH_LITERAL}?` });
  2368. }
  2369. // rebuild the output if we had to backtrack at any point
  2370. if (state.backtrack === true) {
  2371. state.output = '';
  2372. for (let token of state.tokens) {
  2373. state.output += token.output != null ? token.output : token.value;
  2374. if (token.suffix) {
  2375. state.output += token.suffix;
  2376. }
  2377. }
  2378. }
  2379. return state;
  2380. };
  2381. /**
  2382. * Fast paths for creating regular expressions for common glob patterns.
  2383. * This can significantly speed up processing and has very little downside
  2384. * impact when none of the fast paths match.
  2385. */
  2386. parse$1.fastpaths = (input, options) => {
  2387. let opts = Object.assign({}, options);
  2388. let max = typeof opts.maxLength === 'number' ? Math.min(MAX_LENGTH$1, opts.maxLength) : MAX_LENGTH$1;
  2389. let len = input.length;
  2390. if (len > max) {
  2391. throw new SyntaxError(`Input length: ${len}, exceeds maximum allowed length: ${max}`);
  2392. }
  2393. input = REPLACEMENTS[input] || input;
  2394. let win32 = utils$1.isWindows(options);
  2395. // create constants based on platform, for windows or posix
  2396. const { DOT_LITERAL, SLASH_LITERAL, ONE_CHAR, DOTS_SLASH, NO_DOT, NO_DOTS, NO_DOTS_SLASH, STAR, START_ANCHOR } = constants$1.globChars(win32);
  2397. let capture = opts.capture ? '' : '?:';
  2398. let star = opts.bash === true ? '.*?' : STAR;
  2399. let nodot = opts.dot ? NO_DOTS : NO_DOT;
  2400. let slashDot = opts.dot ? NO_DOTS_SLASH : NO_DOT;
  2401. if (opts.capture) {
  2402. star = `(${star})`;
  2403. }
  2404. const globstar = (opts) => {
  2405. return `(${capture}(?:(?!${START_ANCHOR}${opts.dot ? DOTS_SLASH : DOT_LITERAL}).)*?)`;
  2406. };
  2407. const create = str => {
  2408. switch (str) {
  2409. case '*':
  2410. return `${nodot}${ONE_CHAR}${star}`;
  2411. case '.*':
  2412. return `${DOT_LITERAL}${ONE_CHAR}${star}`;
  2413. case '*.*':
  2414. return `${nodot}${star}${DOT_LITERAL}${ONE_CHAR}${star}`;
  2415. case '*/*':
  2416. return `${nodot}${star}${SLASH_LITERAL}${ONE_CHAR}${slashDot}${star}`;
  2417. case '**':
  2418. return nodot + globstar(opts);
  2419. case '**/*':
  2420. return `(?:${nodot}${globstar(opts)}${SLASH_LITERAL})?${slashDot}${ONE_CHAR}${star}`;
  2421. case '**/*.*':
  2422. return `(?:${nodot}${globstar(opts)}${SLASH_LITERAL})?${slashDot}${star}${DOT_LITERAL}${ONE_CHAR}${star}`;
  2423. case '**/.*':
  2424. return `(?:${nodot}${globstar(opts)}${SLASH_LITERAL})?${DOT_LITERAL}${ONE_CHAR}${star}`;
  2425. default: {
  2426. let match = /^(.*?)\.(\w+)$/.exec(str);
  2427. if (!match)
  2428. return;
  2429. let source = create(match[1], options);
  2430. if (!source)
  2431. return;
  2432. return source + DOT_LITERAL + match[2];
  2433. }
  2434. }
  2435. };
  2436. let output = create(input);
  2437. if (output && opts.strictSlashes !== true) {
  2438. output += `${SLASH_LITERAL}?`;
  2439. }
  2440. return output;
  2441. };
  2442. var parse_1$1 = parse$1;
  2443. /**
  2444. * Creates a matcher function from one or more glob patterns. The
  2445. * returned function takes a string to match as its first argument,
  2446. * and returns true if the string is a match. The returned matcher
  2447. * function also takes a boolean as the second argument that, when true,
  2448. * returns an object with additional information.
  2449. *
  2450. * ```js
  2451. * const picomatch = require('picomatch');
  2452. * // picomatch(glob[, options]);
  2453. *
  2454. * const isMatch = picomatch('*.!(*a)');
  2455. * console.log(isMatch('a.a')); //=> false
  2456. * console.log(isMatch('a.b')); //=> true
  2457. * ```
  2458. * @name picomatch
  2459. * @param {String|Array} `globs` One or more glob patterns.
  2460. * @param {Object=} `options`
  2461. * @return {Function=} Returns a matcher function.
  2462. * @api public
  2463. */
  2464. const picomatch = (glob, options, returnState = false) => {
  2465. if (Array.isArray(glob)) {
  2466. let fns = glob.map(input => picomatch(input, options, returnState));
  2467. return str => {
  2468. for (let isMatch of fns) {
  2469. let state = isMatch(str);
  2470. if (state)
  2471. return state;
  2472. }
  2473. return false;
  2474. };
  2475. }
  2476. if (typeof glob !== 'string' || glob === '') {
  2477. throw new TypeError('Expected pattern to be a non-empty string');
  2478. }
  2479. let opts = options || {};
  2480. let posix = utils$1.isWindows(options);
  2481. let regex = picomatch.makeRe(glob, options, false, true);
  2482. let state = regex.state;
  2483. delete regex.state;
  2484. let isIgnored = () => false;
  2485. if (opts.ignore) {
  2486. let ignoreOpts = Object.assign({}, options, { ignore: null, onMatch: null, onResult: null });
  2487. isIgnored = picomatch(opts.ignore, ignoreOpts, returnState);
  2488. }
  2489. const matcher = (input, returnObject = false) => {
  2490. let { isMatch, match, output } = picomatch.test(input, regex, options, { glob, posix });
  2491. let result = { glob, state, regex, posix, input, output, match, isMatch };
  2492. if (typeof opts.onResult === 'function') {
  2493. opts.onResult(result);
  2494. }
  2495. if (isMatch === false) {
  2496. result.isMatch = false;
  2497. return returnObject ? result : false;
  2498. }
  2499. if (isIgnored(input)) {
  2500. if (typeof opts.onIgnore === 'function') {
  2501. opts.onIgnore(result);
  2502. }
  2503. result.isMatch = false;
  2504. return returnObject ? result : false;
  2505. }
  2506. if (typeof opts.onMatch === 'function') {
  2507. opts.onMatch(result);
  2508. }
  2509. return returnObject ? result : true;
  2510. };
  2511. if (returnState) {
  2512. matcher.state = state;
  2513. }
  2514. return matcher;
  2515. };
  2516. /**
  2517. * Test `input` with the given `regex`. This is used by the main
  2518. * `picomatch()` function to test the input string.
  2519. *
  2520. * ```js
  2521. * const picomatch = require('picomatch');
  2522. * // picomatch.test(input, regex[, options]);
  2523. *
  2524. * console.log(picomatch.test('foo/bar', /^(?:([^/]*?)\/([^/]*?))$/));
  2525. * // { isMatch: true, match: [ 'foo/', 'foo', 'bar' ], output: 'foo/bar' }
  2526. * ```
  2527. * @param {String} `input` String to test.
  2528. * @param {RegExp} `regex`
  2529. * @return {Object} Returns an object with matching info.
  2530. * @api public
  2531. */
  2532. picomatch.test = (input, regex, options, { glob, posix } = {}) => {
  2533. if (typeof input !== 'string') {
  2534. throw new TypeError('Expected input to be a string');
  2535. }
  2536. if (input === '') {
  2537. return { isMatch: false, output: '' };
  2538. }
  2539. let opts = options || {};
  2540. let format = opts.format || (posix ? utils$1.toPosixSlashes : null);
  2541. let match = input === glob;
  2542. let output = (match && format) ? format(input) : input;
  2543. if (match === false) {
  2544. output = format ? format(input) : input;
  2545. match = output === glob;
  2546. }
  2547. if (match === false || opts.capture === true) {
  2548. if (opts.matchBase === true || opts.basename === true) {
  2549. match = picomatch.matchBase(input, regex, options, posix);
  2550. }
  2551. else {
  2552. match = regex.exec(output);
  2553. }
  2554. }
  2555. return { isMatch: !!match, match, output };
  2556. };
  2557. /**
  2558. * Match the basename of a filepath.
  2559. *
  2560. * ```js
  2561. * const picomatch = require('picomatch');
  2562. * // picomatch.matchBase(input, glob[, options]);
  2563. * console.log(picomatch.matchBase('foo/bar.js', '*.js'); // true
  2564. * ```
  2565. * @param {String} `input` String to test.
  2566. * @param {RegExp|String} `glob` Glob pattern or regex created by [.makeRe](#makeRe).
  2567. * @return {Boolean}
  2568. * @api public
  2569. */
  2570. picomatch.matchBase = (input, glob, options, posix = utils$1.isWindows(options)) => {
  2571. let regex = glob instanceof RegExp ? glob : picomatch.makeRe(glob, options);
  2572. return regex.test(path__default.basename(input));
  2573. };
  2574. /**
  2575. * Returns true if **any** of the given glob `patterns` match the specified `string`.
  2576. *
  2577. * ```js
  2578. * const picomatch = require('picomatch');
  2579. * // picomatch.isMatch(string, patterns[, options]);
  2580. *
  2581. * console.log(picomatch.isMatch('a.a', ['b.*', '*.a'])); //=> true
  2582. * console.log(picomatch.isMatch('a.a', 'b.*')); //=> false
  2583. * ```
  2584. * @param {String|Array} str The string to test.
  2585. * @param {String|Array} patterns One or more glob patterns to use for matching.
  2586. * @param {Object} [options] See available [options](#options).
  2587. * @return {Boolean} Returns true if any patterns match `str`
  2588. * @api public
  2589. */
  2590. picomatch.isMatch = (str, patterns, options) => picomatch(patterns, options)(str);
  2591. /**
  2592. * Parse a glob pattern to create the source string for a regular
  2593. * expression.
  2594. *
  2595. * ```js
  2596. * const picomatch = require('picomatch');
  2597. * const result = picomatch.parse(glob[, options]);
  2598. * ```
  2599. * @param {String} `glob`
  2600. * @param {Object} `options`
  2601. * @return {Object} Returns an object with useful properties and output to be used as a regex source string.
  2602. * @api public
  2603. */
  2604. picomatch.parse = (glob, options) => parse_1$1(glob, options);
  2605. /**
  2606. * Scan a glob pattern to separate the pattern into segments.
  2607. *
  2608. * ```js
  2609. * const picomatch = require('picomatch');
  2610. * // picomatch.scan(input[, options]);
  2611. *
  2612. * const result = picomatch.scan('!./foo/*.js');
  2613. * console.log(result);
  2614. * // { prefix: '!./',
  2615. * // input: '!./foo/*.js',
  2616. * // base: 'foo',
  2617. * // glob: '*.js',
  2618. * // negated: true,
  2619. * // isGlob: true }
  2620. * ```
  2621. * @param {String} `input` Glob pattern to scan.
  2622. * @param {Object} `options`
  2623. * @return {Object} Returns an object with
  2624. * @api public
  2625. */
  2626. picomatch.scan = (input, options) => scan(input, options);
  2627. /**
  2628. * Create a regular expression from a glob pattern.
  2629. *
  2630. * ```js
  2631. * const picomatch = require('picomatch');
  2632. * // picomatch.makeRe(input[, options]);
  2633. *
  2634. * console.log(picomatch.makeRe('*.js'));
  2635. * //=> /^(?:(?!\.)(?=.)[^/]*?\.js)$/
  2636. * ```
  2637. * @param {String} `input` A glob pattern to convert to regex.
  2638. * @param {Object} `options`
  2639. * @return {RegExp} Returns a regex created from the given pattern.
  2640. * @api public
  2641. */
  2642. picomatch.makeRe = (input, options, returnOutput = false, returnState = false) => {
  2643. if (!input || typeof input !== 'string') {
  2644. throw new TypeError('Expected a non-empty string');
  2645. }
  2646. let opts = options || {};
  2647. let prepend = opts.contains ? '' : '^';
  2648. let append = opts.contains ? '' : '$';
  2649. let state = { negated: false, fastpaths: true };
  2650. let prefix = '';
  2651. let output;
  2652. if (input.startsWith('./')) {
  2653. input = input.slice(2);
  2654. prefix = state.prefix = './';
  2655. }
  2656. if (opts.fastpaths !== false && (input[0] === '.' || input[0] === '*')) {
  2657. output = parse_1$1.fastpaths(input, options);
  2658. }
  2659. if (output === void 0) {
  2660. state = picomatch.parse(input, options);
  2661. state.prefix = prefix + (state.prefix || '');
  2662. output = state.output;
  2663. }
  2664. if (returnOutput === true) {
  2665. return output;
  2666. }
  2667. let source = `${prepend}(?:${output})${append}`;
  2668. if (state && state.negated === true) {
  2669. source = `^(?!${source}).*$`;
  2670. }
  2671. let regex = picomatch.toRegex(source, options);
  2672. if (returnState === true) {
  2673. regex.state = state;
  2674. }
  2675. return regex;
  2676. };
  2677. /**
  2678. * Create a regular expression from the given regex source string.
  2679. *
  2680. * ```js
  2681. * const picomatch = require('picomatch');
  2682. * // picomatch.toRegex(source[, options]);
  2683. *
  2684. * const { output } = picomatch.parse('*.js');
  2685. * console.log(picomatch.toRegex(output));
  2686. * //=> /^(?:(?!\.)(?=.)[^/]*?\.js)$/
  2687. * ```
  2688. * @param {String} `source` Regular expression source string.
  2689. * @param {Object} `options`
  2690. * @return {RegExp}
  2691. * @api public
  2692. */
  2693. picomatch.toRegex = (source, options) => {
  2694. try {
  2695. let opts = options || {};
  2696. return new RegExp(source, opts.flags || (opts.nocase ? 'i' : ''));
  2697. }
  2698. catch (err) {
  2699. if (options && options.debug === true)
  2700. throw err;
  2701. return /$^/;
  2702. }
  2703. };
  2704. /**
  2705. * Picomatch constants.
  2706. * @return {Object}
  2707. */
  2708. picomatch.constants = constants$1;
  2709. /**
  2710. * Expose "picomatch"
  2711. */
  2712. var picomatch_1 = picomatch;
  2713. var picomatch$1 = picomatch_1;
  2714. const isEmptyString = val => typeof val === 'string' && (val === '' || val === './');
  2715. /**
  2716. * Returns an array of strings that match one or more glob patterns.
  2717. *
  2718. * ```js
  2719. * const mm = require('micromatch');
  2720. * // mm(list, patterns[, options]);
  2721. *
  2722. * console.log(mm(['a.js', 'a.txt'], ['*.js']));
  2723. * //=> [ 'a.js' ]
  2724. * ```
  2725. * @param {String|Array<string>} list List of strings to match.
  2726. * @param {String|Array<string>} patterns One or more glob patterns to use for matching.
  2727. * @param {Object} options See available [options](#options)
  2728. * @return {Array} Returns an array of matches
  2729. * @summary false
  2730. * @api public
  2731. */
  2732. const micromatch = (list, patterns, options) => {
  2733. patterns = [].concat(patterns);
  2734. list = [].concat(list);
  2735. let omit = new Set();
  2736. let keep = new Set();
  2737. let items = new Set();
  2738. let negatives = 0;
  2739. let onResult = state => {
  2740. items.add(state.output);
  2741. if (options && options.onResult) {
  2742. options.onResult(state);
  2743. }
  2744. };
  2745. for (let i = 0; i < patterns.length; i++) {
  2746. let isMatch = picomatch$1(String(patterns[i]), Object.assign({}, options, { onResult }), true);
  2747. let negated = isMatch.state.negated || isMatch.state.negatedExtglob;
  2748. if (negated)
  2749. negatives++;
  2750. for (let item of list) {
  2751. let matched = isMatch(item, true);
  2752. let match = negated ? !matched.isMatch : matched.isMatch;
  2753. if (!match)
  2754. continue;
  2755. if (negated) {
  2756. omit.add(matched.output);
  2757. }
  2758. else {
  2759. omit.delete(matched.output);
  2760. keep.add(matched.output);
  2761. }
  2762. }
  2763. }
  2764. let result = negatives === patterns.length ? [...items] : [...keep];
  2765. let matches = result.filter(item => !omit.has(item));
  2766. if (options && matches.length === 0) {
  2767. if (options.failglob === true) {
  2768. throw new Error(`No matches found for "${patterns.join(', ')}"`);
  2769. }
  2770. if (options.nonull === true || options.nullglob === true) {
  2771. return options.unescape ? patterns.map(p => p.replace(/\\/g, '')) : patterns;
  2772. }
  2773. }
  2774. return matches;
  2775. };
  2776. /**
  2777. * Backwards compatibility
  2778. */
  2779. micromatch.match = micromatch;
  2780. /**
  2781. * Returns a matcher function from the given glob `pattern` and `options`.
  2782. * The returned function takes a string to match as its only argument and returns
  2783. * true if the string is a match.
  2784. *
  2785. * ```js
  2786. * const mm = require('micromatch');
  2787. * // mm.matcher(pattern[, options]);
  2788. *
  2789. * const isMatch = mm.matcher('*.!(*a)');
  2790. * console.log(isMatch('a.a')); //=> false
  2791. * console.log(isMatch('a.b')); //=> true
  2792. * ```
  2793. * @param {String} `pattern` Glob pattern
  2794. * @param {Object} `options`
  2795. * @return {Function} Returns a matcher function.
  2796. * @api public
  2797. */
  2798. micromatch.matcher = (pattern, options) => picomatch$1(pattern, options);
  2799. /**
  2800. * Returns true if **any** of the given glob `patterns` match the specified `string`.
  2801. *
  2802. * ```js
  2803. * const mm = require('micromatch');
  2804. * // mm.isMatch(string, patterns[, options]);
  2805. *
  2806. * console.log(mm.isMatch('a.a', ['b.*', '*.a'])); //=> true
  2807. * console.log(mm.isMatch('a.a', 'b.*')); //=> false
  2808. * ```
  2809. * @param {String} str The string to test.
  2810. * @param {String|Array} patterns One or more glob patterns to use for matching.
  2811. * @param {Object} [options] See available [options](#options).
  2812. * @return {Boolean} Returns true if any patterns match `str`
  2813. * @api public
  2814. */
  2815. micromatch.isMatch = (str, patterns, options) => picomatch$1(patterns, options)(str);
  2816. /**
  2817. * Backwards compatibility
  2818. */
  2819. micromatch.any = micromatch.isMatch;
  2820. /**
  2821. * Returns a list of strings that _**do not match any**_ of the given `patterns`.
  2822. *
  2823. * ```js
  2824. * const mm = require('micromatch');
  2825. * // mm.not(list, patterns[, options]);
  2826. *
  2827. * console.log(mm.not(['a.a', 'b.b', 'c.c'], '*.a'));
  2828. * //=> ['b.b', 'c.c']
  2829. * ```
  2830. * @param {Array} `list` Array of strings to match.
  2831. * @param {String|Array} `patterns` One or more glob pattern to use for matching.
  2832. * @param {Object} `options` See available [options](#options) for changing how matches are performed
  2833. * @return {Array} Returns an array of strings that **do not match** the given patterns.
  2834. * @api public
  2835. */
  2836. micromatch.not = (list, patterns, options = {}) => {
  2837. patterns = [].concat(patterns).map(String);
  2838. let result = new Set();
  2839. let items = [];
  2840. let onResult = state => {
  2841. if (options.onResult)
  2842. options.onResult(state);
  2843. items.push(state.output);
  2844. };
  2845. let matches = micromatch(list, patterns, Object.assign({}, options, { onResult }));
  2846. for (let item of items) {
  2847. if (!matches.includes(item)) {
  2848. result.add(item);
  2849. }
  2850. }
  2851. return [...result];
  2852. };
  2853. /**
  2854. * Returns true if the given `string` contains the given pattern. Similar
  2855. * to [.isMatch](#isMatch) but the pattern can match any part of the string.
  2856. *
  2857. * ```js
  2858. * var mm = require('micromatch');
  2859. * // mm.contains(string, pattern[, options]);
  2860. *
  2861. * console.log(mm.contains('aa/bb/cc', '*b'));
  2862. * //=> true
  2863. * console.log(mm.contains('aa/bb/cc', '*d'));
  2864. * //=> false
  2865. * ```
  2866. * @param {String} `str` The string to match.
  2867. * @param {String|Array} `patterns` Glob pattern to use for matching.
  2868. * @param {Object} `options` See available [options](#options) for changing how matches are performed
  2869. * @return {Boolean} Returns true if the patter matches any part of `str`.
  2870. * @api public
  2871. */
  2872. micromatch.contains = (str, pattern, options) => {
  2873. if (typeof str !== 'string') {
  2874. throw new TypeError(`Expected a string: "${util.inspect(str)}"`);
  2875. }
  2876. if (Array.isArray(pattern)) {
  2877. return pattern.some(p => micromatch.contains(str, p, options));
  2878. }
  2879. if (typeof pattern === 'string') {
  2880. if (isEmptyString(str) || isEmptyString(pattern)) {
  2881. return false;
  2882. }
  2883. if (str.includes(pattern) || (str.startsWith('./') && str.slice(2).includes(pattern))) {
  2884. return true;
  2885. }
  2886. }
  2887. return micromatch.isMatch(str, pattern, Object.assign({}, options, { contains: true }));
  2888. };
  2889. /**
  2890. * Filter the keys of the given object with the given `glob` pattern
  2891. * and `options`. Does not attempt to match nested keys. If you need this feature,
  2892. * use [glob-object][] instead.
  2893. *
  2894. * ```js
  2895. * const mm = require('micromatch');
  2896. * // mm.matchKeys(object, patterns[, options]);
  2897. *
  2898. * const obj = { aa: 'a', ab: 'b', ac: 'c' };
  2899. * console.log(mm.matchKeys(obj, '*b'));
  2900. * //=> { ab: 'b' }
  2901. * ```
  2902. * @param {Object} `object` The object with keys to filter.
  2903. * @param {String|Array} `patterns` One or more glob patterns to use for matching.
  2904. * @param {Object} `options` See available [options](#options) for changing how matches are performed
  2905. * @return {Object} Returns an object with only keys that match the given patterns.
  2906. * @api public
  2907. */
  2908. micromatch.matchKeys = (obj, patterns, options) => {
  2909. if (!utils$1.isObject(obj)) {
  2910. throw new TypeError('Expected the first argument to be an object');
  2911. }
  2912. let keys = micromatch(Object.keys(obj), patterns, options);
  2913. let res = {};
  2914. for (let key of keys)
  2915. res[key] = obj[key];
  2916. return res;
  2917. };
  2918. /**
  2919. * Returns true if some of the strings in the given `list` match any of the given glob `patterns`.
  2920. *
  2921. * ```js
  2922. * const mm = require('micromatch');
  2923. * // mm.some(list, patterns[, options]);
  2924. *
  2925. * console.log(mm.some(['foo.js', 'bar.js'], ['*.js', '!foo.js']));
  2926. * // true
  2927. * console.log(mm.some(['foo.js'], ['*.js', '!foo.js']));
  2928. * // false
  2929. * ```
  2930. * @param {String|Array} `list` The string or array of strings to test. Returns as soon as the first match is found.
  2931. * @param {String|Array} `patterns` One or more glob patterns to use for matching.
  2932. * @param {Object} `options` See available [options](#options) for changing how matches are performed
  2933. * @return {Boolean} Returns true if any patterns match `str`
  2934. * @api public
  2935. */
  2936. micromatch.some = (list, patterns, options) => {
  2937. let items = [].concat(list);
  2938. for (let pattern of [].concat(patterns)) {
  2939. let isMatch = picomatch$1(String(pattern), options);
  2940. if (items.some(item => isMatch(item))) {
  2941. return true;
  2942. }
  2943. }
  2944. return false;
  2945. };
  2946. /**
  2947. * Returns true if every string in the given `list` matches
  2948. * any of the given glob `patterns`.
  2949. *
  2950. * ```js
  2951. * const mm = require('micromatch');
  2952. * // mm.every(list, patterns[, options]);
  2953. *
  2954. * console.log(mm.every('foo.js', ['foo.js']));
  2955. * // true
  2956. * console.log(mm.every(['foo.js', 'bar.js'], ['*.js']));
  2957. * // true
  2958. * console.log(mm.every(['foo.js', 'bar.js'], ['*.js', '!foo.js']));
  2959. * // false
  2960. * console.log(mm.every(['foo.js'], ['*.js', '!foo.js']));
  2961. * // false
  2962. * ```
  2963. * @param {String|Array} `list` The string or array of strings to test.
  2964. * @param {String|Array} `patterns` One or more glob patterns to use for matching.
  2965. * @param {Object} `options` See available [options](#options) for changing how matches are performed
  2966. * @return {Boolean} Returns true if any patterns match `str`
  2967. * @api public
  2968. */
  2969. micromatch.every = (list, patterns, options) => {
  2970. let items = [].concat(list);
  2971. for (let pattern of [].concat(patterns)) {
  2972. let isMatch = picomatch$1(String(pattern), options);
  2973. if (!items.every(item => isMatch(item))) {
  2974. return false;
  2975. }
  2976. }
  2977. return true;
  2978. };
  2979. /**
  2980. * Returns true if **all** of the given `patterns` match
  2981. * the specified string.
  2982. *
  2983. * ```js
  2984. * const mm = require('micromatch');
  2985. * // mm.all(string, patterns[, options]);
  2986. *
  2987. * console.log(mm.all('foo.js', ['foo.js']));
  2988. * // true
  2989. *
  2990. * console.log(mm.all('foo.js', ['*.js', '!foo.js']));
  2991. * // false
  2992. *
  2993. * console.log(mm.all('foo.js', ['*.js', 'foo.js']));
  2994. * // true
  2995. *
  2996. * console.log(mm.all('foo.js', ['*.js', 'f*', '*o*', '*o.js']));
  2997. * // true
  2998. * ```
  2999. * @param {String|Array} `str` The string to test.
  3000. * @param {String|Array} `patterns` One or more glob patterns to use for matching.
  3001. * @param {Object} `options` See available [options](#options) for changing how matches are performed
  3002. * @return {Boolean} Returns true if any patterns match `str`
  3003. * @api public
  3004. */
  3005. micromatch.all = (str, patterns, options) => {
  3006. if (typeof str !== 'string') {
  3007. throw new TypeError(`Expected a string: "${util.inspect(str)}"`);
  3008. }
  3009. return [].concat(patterns).every(p => picomatch$1(p, options)(str));
  3010. };
  3011. /**
  3012. * Returns an array of matches captured by `pattern` in `string, or `null` if the pattern did not match.
  3013. *
  3014. * ```js
  3015. * const mm = require('micromatch');
  3016. * // mm.capture(pattern, string[, options]);
  3017. *
  3018. * console.log(mm.capture('test/*.js', 'test/foo.js'));
  3019. * //=> ['foo']
  3020. * console.log(mm.capture('test/*.js', 'foo/bar.css'));
  3021. * //=> null
  3022. * ```
  3023. * @param {String} `glob` Glob pattern to use for matching.
  3024. * @param {String} `input` String to match
  3025. * @param {Object} `options` See available [options](#options) for changing how matches are performed
  3026. * @return {Boolean} Returns an array of captures if the input matches the glob pattern, otherwise `null`.
  3027. * @api public
  3028. */
  3029. micromatch.capture = (glob, input, options) => {
  3030. let posix = utils$1.isWindows(options);
  3031. let regex = picomatch$1.makeRe(String(glob), Object.assign({}, options, { capture: true }));
  3032. let match = regex.exec(posix ? utils$1.toPosixSlashes(input) : input);
  3033. if (match) {
  3034. return match.slice(1).map(v => v === void 0 ? '' : v);
  3035. }
  3036. };
  3037. /**
  3038. * Create a regular expression from the given glob `pattern`.
  3039. *
  3040. * ```js
  3041. * const mm = require('micromatch');
  3042. * // mm.makeRe(pattern[, options]);
  3043. *
  3044. * console.log(mm.makeRe('*.js'));
  3045. * //=> /^(?:(\.[\\\/])?(?!\.)(?=.)[^\/]*?\.js)$/
  3046. * ```
  3047. * @param {String} `pattern` A glob pattern to convert to regex.
  3048. * @param {Object} `options`
  3049. * @return {RegExp} Returns a regex created from the given pattern.
  3050. * @api public
  3051. */
  3052. micromatch.makeRe = (...args) => picomatch$1.makeRe(...args);
  3053. /**
  3054. * Scan a glob pattern to separate the pattern into segments. Used
  3055. * by the [split](#split) method.
  3056. *
  3057. * ```js
  3058. * const mm = require('micromatch');
  3059. * const state = mm.scan(pattern[, options]);
  3060. * ```
  3061. * @param {String} `pattern`
  3062. * @param {Object} `options`
  3063. * @return {Object} Returns an object with
  3064. * @api public
  3065. */
  3066. micromatch.scan = (...args) => picomatch$1.scan(...args);
  3067. /**
  3068. * Parse a glob pattern to create the source string for a regular
  3069. * expression.
  3070. *
  3071. * ```js
  3072. * const mm = require('micromatch');
  3073. * const state = mm(pattern[, options]);
  3074. * ```
  3075. * @param {String} `glob`
  3076. * @param {Object} `options`
  3077. * @return {Object} Returns an object with useful properties and output to be used as regex source string.
  3078. * @api public
  3079. */
  3080. micromatch.parse = (patterns, options) => {
  3081. let res = [];
  3082. for (let pattern of [].concat(patterns || [])) {
  3083. for (let str of braces_1(String(pattern), options)) {
  3084. res.push(picomatch$1.parse(str, options));
  3085. }
  3086. }
  3087. return res;
  3088. };
  3089. /**
  3090. * Process the given brace `pattern`.
  3091. *
  3092. * ```js
  3093. * const { braces } = require('micromatch');
  3094. * console.log(braces('foo/{a,b,c}/bar'));
  3095. * //=> [ 'foo/(a|b|c)/bar' ]
  3096. *
  3097. * console.log(braces('foo/{a,b,c}/bar', { expand: true }));
  3098. * //=> [ 'foo/a/bar', 'foo/b/bar', 'foo/c/bar' ]
  3099. * ```
  3100. * @param {String} `pattern` String with brace pattern to process.
  3101. * @param {Object} `options` Any [options](#options) to change how expansion is performed. See the [braces][] library for all available options.
  3102. * @return {Array}
  3103. * @api public
  3104. */
  3105. micromatch.braces = (pattern, options) => {
  3106. if (typeof pattern !== 'string')
  3107. throw new TypeError('Expected a string');
  3108. if ((options && options.nobrace === true) || !/\{.*\}/.test(pattern)) {
  3109. return [pattern];
  3110. }
  3111. return braces_1(pattern, options);
  3112. };
  3113. /**
  3114. * Expand braces
  3115. */
  3116. micromatch.braceExpand = (pattern, options) => {
  3117. if (typeof pattern !== 'string')
  3118. throw new TypeError('Expected a string');
  3119. return micromatch.braces(pattern, Object.assign({}, options, { expand: true }));
  3120. };
  3121. /**
  3122. * Expose micromatch
  3123. */
  3124. var micromatch_1 = micromatch;
  3125. function ensureArray(thing) {
  3126. if (Array.isArray(thing))
  3127. return thing;
  3128. if (thing == undefined)
  3129. return [];
  3130. return [thing];
  3131. }
  3132. function getMatcherString(id, resolutionBase) {
  3133. if (resolutionBase === false) {
  3134. return id;
  3135. }
  3136. return path.resolve(...(typeof resolutionBase === 'string' ? [resolutionBase, id] : [id]));
  3137. }
  3138. const createFilter = function createFilter(include, exclude, options) {
  3139. const resolutionBase = options && options.resolve;
  3140. const getMatcher = (id) => {
  3141. return id instanceof RegExp
  3142. ? id
  3143. : {
  3144. test: micromatch_1.matcher(getMatcherString(id, resolutionBase)
  3145. .split(path.sep)
  3146. .join('/'), { dot: true })
  3147. };
  3148. };
  3149. const includeMatchers = ensureArray(include).map(getMatcher);
  3150. const excludeMatchers = ensureArray(exclude).map(getMatcher);
  3151. return function (id) {
  3152. if (typeof id !== 'string')
  3153. return false;
  3154. if (/\0/.test(id))
  3155. return false;
  3156. id = id.split(path.sep).join('/');
  3157. for (let i = 0; i < excludeMatchers.length; ++i) {
  3158. const matcher = excludeMatchers[i];
  3159. if (matcher.test(id))
  3160. return false;
  3161. }
  3162. for (let i = 0; i < includeMatchers.length; ++i) {
  3163. const matcher = includeMatchers[i];
  3164. if (matcher.test(id))
  3165. return true;
  3166. }
  3167. return !includeMatchers.length;
  3168. };
  3169. };
  3170. const reservedWords = 'break case class catch const continue debugger default delete do else export extends finally for function if import in instanceof let new return super switch this throw try typeof var void while with yield enum await implements package protected static interface private public';
  3171. const builtins = 'arguments Infinity NaN undefined null true false eval uneval isFinite isNaN parseFloat parseInt decodeURI decodeURIComponent encodeURI encodeURIComponent escape unescape Object Function Boolean Symbol Error EvalError InternalError RangeError ReferenceError SyntaxError TypeError URIError Number Math Date String RegExp Array Int8Array Uint8Array Uint8ClampedArray Int16Array Uint16Array Int32Array Uint32Array Float32Array Float64Array Map Set WeakMap WeakSet SIMD ArrayBuffer DataView JSON Promise Generator GeneratorFunction Reflect Proxy Intl';
  3172. const forbiddenIdentifiers = new Set(`${reservedWords} ${builtins}`.split(' '));
  3173. forbiddenIdentifiers.add('');
  3174. const makeLegalIdentifier = function makeLegalIdentifier(str) {
  3175. str = str.replace(/-(\w)/g, (_, letter) => letter.toUpperCase()).replace(/[^$_a-zA-Z0-9]/g, '_');
  3176. if (/\d/.test(str[0]) || forbiddenIdentifiers.has(str)) {
  3177. str = `_${str}`;
  3178. }
  3179. return str || '_';
  3180. };
  3181. function stringify$2(obj) {
  3182. return (JSON.stringify(obj) || 'undefined').replace(/[\u2028\u2029]/g, char => `\\u${('000' + char.charCodeAt(0).toString(16)).slice(-4)}`);
  3183. }
  3184. function serializeArray(arr, indent, baseIndent) {
  3185. let output = '[';
  3186. const separator = indent ? '\n' + baseIndent + indent : '';
  3187. for (let i = 0; i < arr.length; i++) {
  3188. const key = arr[i];
  3189. output += `${i > 0 ? ',' : ''}${separator}${serialize(key, indent, baseIndent + indent)}`;
  3190. }
  3191. return output + `${indent ? '\n' + baseIndent : ''}]`;
  3192. }
  3193. function serializeObject(obj, indent, baseIndent) {
  3194. let output = '{';
  3195. const separator = indent ? '\n' + baseIndent + indent : '';
  3196. const keys = Object.keys(obj);
  3197. for (let i = 0; i < keys.length; i++) {
  3198. const key = keys[i];
  3199. const stringKey = makeLegalIdentifier(key) === key ? key : stringify$2(key);
  3200. output += `${i > 0 ? ',' : ''}${separator}${stringKey}:${indent ? ' ' : ''}${serialize(obj[key], indent, baseIndent + indent)}`;
  3201. }
  3202. return output + `${indent ? '\n' + baseIndent : ''}}`;
  3203. }
  3204. function serialize(obj, indent, baseIndent) {
  3205. if (obj === Infinity)
  3206. return 'Infinity';
  3207. if (obj === -Infinity)
  3208. return '-Infinity';
  3209. if (obj === 0 && 1 / obj === -Infinity)
  3210. return '-0';
  3211. if (obj instanceof Date)
  3212. return 'new Date(' + obj.getTime() + ')';
  3213. if (obj instanceof RegExp)
  3214. return obj.toString();
  3215. if (obj !== obj)
  3216. return 'NaN';
  3217. if (Array.isArray(obj))
  3218. return serializeArray(obj, indent, baseIndent);
  3219. if (obj === null)
  3220. return 'null';
  3221. if (typeof obj === 'object')
  3222. return serializeObject(obj, indent, baseIndent);
  3223. return stringify$2(obj);
  3224. }
  3225. const dataToEsm = function dataToEsm(data, options = {}) {
  3226. const t = options.compact ? '' : 'indent' in options ? options.indent : '\t';
  3227. const _ = options.compact ? '' : ' ';
  3228. const n = options.compact ? '' : '\n';
  3229. const declarationType = options.preferConst ? 'const' : 'var';
  3230. if (options.namedExports === false ||
  3231. typeof data !== 'object' ||
  3232. Array.isArray(data) ||
  3233. data instanceof Date ||
  3234. data instanceof RegExp ||
  3235. data === null) {
  3236. const code = serialize(data, options.compact ? null : t, '');
  3237. const __ = _ || (/^[{[\-\/]/.test(code) ? '' : ' ');
  3238. return `export default${__}${code};`;
  3239. }
  3240. let namedExportCode = '';
  3241. const defaultExportRows = [];
  3242. const dataKeys = Object.keys(data);
  3243. for (let i = 0; i < dataKeys.length; i++) {
  3244. const key = dataKeys[i];
  3245. if (key === makeLegalIdentifier(key)) {
  3246. if (options.objectShorthand)
  3247. defaultExportRows.push(key);
  3248. else
  3249. defaultExportRows.push(`${key}:${_}${key}`);
  3250. namedExportCode += `export ${declarationType} ${key}${_}=${_}${serialize(data[key], options.compact ? null : t, '')};${n}`;
  3251. }
  3252. else {
  3253. defaultExportRows.push(`${stringify$2(key)}:${_}${serialize(data[key], options.compact ? null : t, '')}`);
  3254. }
  3255. }
  3256. return (namedExportCode + `export default${_}{${n}${t}${defaultExportRows.join(`,${n}${t}`)}${n}};${n}`);
  3257. };
  3258. exports.addExtension = addExtension;
  3259. exports.attachScopes = attachScopes;
  3260. exports.createFilter = createFilter;
  3261. exports.dataToEsm = dataToEsm;
  3262. exports.extractAssignedNames = extractAssignedNames;
  3263. exports.makeLegalIdentifier = makeLegalIdentifier;