Ignore:
Timestamp:
09/19/26 10:30:30 (10 days ago)
Author:
Klimentina Efremova <klimentina08642@…>
Branches:
finki-main, main
Children:
06ebe74
Parents:
62b2964
Message:

Turned database from SQLite to PostgressSQL, updated database changes from Phase 1 and 2

File:
1 edited

Legend:

Unmodified
Added
Removed
  • node_modules/minimatch/dist/commonjs/ast.js

    r62b2964 r33517cc  
    11"use strict";
    22// parse a single path portion
     3var _a;
    34Object.defineProperty(exports, "__esModule", { value: true });
    45exports.AST = void 0;
    … …  
    78const types = new Set(['!', '?', '+', '*', '@']);
    89const isExtglobType = (c) => types.has(c);
     10const isExtglobAST = (c) => isExtglobType(c.type);
     11// Map of which extglob types can adopt the children of a nested extglob
     12//
     13// anything but ! can adopt a matching type:
     14// +(a|+(b|c)|d) => +(a|b|c|d)
     15// *(a|*(b|c)|d) => *(a|b|c|d)
     16// @(a|@(b|c)|d) => @(a|b|c|d)
     17// ?(a|?(b|c)|d) => ?(a|b|c|d)
     18//
     19// * can adopt anything, because 0 or repetition is allowed
     20// *(a|?(b|c)|d) => *(a|b|c|d)
     21// *(a|+(b|c)|d) => *(a|b|c|d)
     22// *(a|@(b|c)|d) => *(a|b|c|d)
     23//
     24// + can adopt @, because 1 or repetition is allowed
     25// +(a|@(b|c)|d) => +(a|b|c|d)
     26//
     27// + and @ CANNOT adopt *, because 0 would be allowed
     28// +(a|*(b|c)|d) => would match "", on *(b|c)
     29// @(a|*(b|c)|d) => would match "", on *(b|c)
     30//
     31// + and @ CANNOT adopt ?, because 0 would be allowed
     32// +(a|?(b|c)|d) => would match "", on ?(b|c)
     33// @(a|?(b|c)|d) => would match "", on ?(b|c)
     34//
     35// ? can adopt @, because 0 or 1 is allowed
     36// ?(a|@(b|c)|d) => ?(a|b|c|d)
     37//
     38// ? and @ CANNOT adopt * or +, because >1 would be allowed
     39// ?(a|*(b|c)|d) => would match bbb on *(b|c)
     40// @(a|*(b|c)|d) => would match bbb on *(b|c)
     41// ?(a|+(b|c)|d) => would match bbb on +(b|c)
     42// @(a|+(b|c)|d) => would match bbb on +(b|c)
     43//
     44// ! CANNOT adopt ! (nothing else can either)
     45// !(a|!(b|c)|d) => !(a|b|c|d) would fail to match on b (not not b|c)
     46//
     47// ! can adopt @
     48// !(a|@(b|c)|d) => !(a|b|c|d)
     49//
     50// ! CANNOT adopt *
     51// !(a|*(b|c)|d) => !(a|b|c|d) would match on bbb, not allowed
     52//
     53// ! CANNOT adopt +
     54// !(a|+(b|c)|d) => !(a|b|c|d) would match on bbb, not allowed
     55//
     56// ! CANNOT adopt ?
     57// x!(a|?(b|c)|d) => x!(a|b|c|d) would fail to match "x"
     58const adoptionMap = new Map([
     59    ['!', ['@']],
     60    ['?', ['?', '@']],
     61    ['@', ['@']],
     62    ['*', ['*', '+', '?', '@']],
     63    ['+', ['+', '@']],
     64]);
     65// nested extglobs that can be adopted in, but with the addition of
     66// a blank '' element.
     67const adoptionWithSpaceMap = new Map([
     68    ['!', ['?']],
     69    ['@', ['?']],
     70    ['+', ['?', '*']],
     71]);
     72// union of the previous two maps
     73const adoptionAnyMap = new Map([
     74    ['!', ['?', '@']],
     75    ['?', ['?', '@']],
     76    ['@', ['?', '@']],
     77    ['*', ['*', '+', '?', '@']],
     78    ['+', ['+', '@', '?', '*']],
     79]);
     80// Extglobs that can take over their parent if they are the only child
     81// the key is parent, value maps child to resulting extglob parent type
     82// '@' is omitted because it's a special case. An `@` extglob with a single
     83// member can always be usurped by that subpattern.
     84const usurpMap = new Map([
     85    ['!', new Map([['!', '@']])],
     86    [
     87        '?',
     88        new Map([
     89            ['*', '*'],
     90            ['+', '*'],
     91        ]),
     92    ],
     93    [
     94        '@',
     95        new Map([
     96            ['!', '!'],
     97            ['?', '?'],
     98            ['@', '@'],
     99            ['*', '*'],
     100            ['+', '+'],
     101        ]),
     102    ],
     103    [
     104        '+',
     105        new Map([
     106            ['?', '*'],
     107            ['*', '*'],
     108        ]),
     109    ],
     110]);
    9111// Patterns that get prepended to bind to the start of either the
    10112// entire string, or just a single path portion, to prevent dots
    … …  
    30132// remove the \ chars that we added if we end up doing a nonmagic compare
    31133// const deslash = (s: string) => s.replace(/\\(.)/g, '$1')
     134let ID = 0;
    32135class AST {
    33136    type;
    … …  
    45148    // (which really means one child of '')
    46149    #emptyExt = false;
     150    id = ++ID;
     151    get depth() {
     152        return (this.#parent?.depth ?? -1) + 1;
     153    }
     154    [Symbol.for('nodejs.util.inspect.custom')]() {
     155        return {
     156            '@@type': 'AST',
     157            id: this.id,
     158            type: this.type,
     159            root: this.#root.id,
     160            parent: this.#parent?.id,
     161            depth: this.depth,
     162            partsLength: this.#parts.length,
     163            parts: this.#parts,
     164        };
     165    }
    47166    constructor(type, parent, options = {}) {
    48167        this.type = type;
    … …  
    74193    // reconstructs the pattern
    75194    toString() {
    76         if (this.#toString !== undefined)
    77             return this.#toString;
    78         if (!this.type) {
    79             return (this.#toString = this.#parts.map(p => String(p)).join(''));
    80         }
    81         else {
    82             return (this.#toString =
    83                 this.type + '(' + this.#parts.map(p => String(p)).join('|') + ')');
    84         }
     195        return (this.#toString !== undefined ? this.#toString
     196            : !this.type ?
     197                (this.#toString = this.#parts.map(p => String(p)).join(''))
     198                : (this.#toString =
     199                    this.type +
     200                        '(' +
     201                        this.#parts.map(p => String(p)).join('|') +
     202                        ')'));
    85203    }
    86204    #fillNegs() {
    … …  
    124242            /* c8 ignore start */
    125243            if (typeof p !== 'string' &&
    126                 !(p instanceof AST && p.#parent === this)) {
     244                !(p instanceof _a && p.#parent === this)) {
    127245                throw new Error('invalid part: ' + p);
    128246            }
    … …  
    158276        for (let i = 0; i < this.#parentIndex; i++) {
    159277            const pp = p.#parts[i];
    160             if (!(pp instanceof AST && pp.type === '!')) {
     278            if (!(pp instanceof _a && pp.type === '!')) {
    161279                return false;
    162280            }
    … …  
    186304    }
    187305    clone(parent) {
    188         const c = new AST(this.type, parent);
     306        const c = new _a(this.type, parent);
    189307        for (const p of this.#parts) {
    190308            c.copyIn(p);
    … …  
    192310        return c;
    193311    }
    194     static #parseAST(str, ast, pos, opt) {
     312    static #parseAST(str, ast, pos, opt, extDepth) {
     313        const maxDepth = opt.maxExtglobRecursion ?? 2;
    195314        let escaping = false;
    196315        let inBrace = false;
    … …  
    229348                    continue;
    230349                }
    231                 if (!opt.noext && isExtglobType(c) && str.charAt(i) === '(') {
     350                // we don't have to check for adoption here, because that's
     351                // done at the other recursion point.
     352                const doRecurse = !opt.noext &&
     353                    isExtglobType(c) &&
     354                    str.charAt(i) === '(' &&
     355                    extDepth <= maxDepth;
     356                if (doRecurse) {
    232357                    ast.push(acc);
    233358                    acc = '';
    234                     const ext = new AST(c, ast);
    235                     i = AST.#parseAST(str, ext, i, opt);
     359                    const ext = new _a(c, ast);
     360                    i = _a.#parseAST(str, ext, i, opt, extDepth + 1);
    236361                    ast.push(ext);
    237362                    continue;
    … …  
    245370        // find the next | or )
    246371        let i = pos + 1;
    247         let part = new AST(null, ast);
     372        let part = new _a(null, ast);
    248373        const parts = [];
    249374        let acc = '';
    … …  
    276401                continue;
    277402            }
    278             if (isExtglobType(c) && str.charAt(i) === '(') {
     403            const doRecurse = !opt.noext &&
     404                isExtglobType(c) &&
     405                str.charAt(i) === '(' &&
     406                /* c8 ignore start - the maxDepth is sufficient here */
     407                (extDepth <= maxDepth || (ast && ast.#canAdoptType(c)));
     408            /* c8 ignore stop */
     409            if (doRecurse) {
     410                const depthAdd = ast && ast.#canAdoptType(c) ? 0 : 1;
    279411                part.push(acc);
    280412                acc = '';
    281                 const ext = new AST(c, part);
     413                const ext = new _a(c, part);
    282414                part.push(ext);
    283                 i = AST.#parseAST(str, ext, i, opt);
     415                i = _a.#parseAST(str, ext, i, opt, extDepth + depthAdd);
    284416                continue;
    285417            }
    … …  
    288420                acc = '';
    289421                parts.push(part);
    290                 part = new AST(null, ast);
     422                part = new _a(null, ast);
    291423                continue;
    292424            }
    … …  
    310442        return i;
    311443    }
     444    #canAdoptWithSpace(child) {
     445        return this.#canAdopt(child, adoptionWithSpaceMap);
     446    }
     447    #canAdopt(child, map = adoptionMap) {
     448        if (!child ||
     449            typeof child !== 'object' ||
     450            child.type !== null ||
     451            child.#parts.length !== 1 ||
     452            this.type === null) {
     453            return false;
     454        }
     455        const gc = child.#parts[0];
     456        if (!gc || typeof gc !== 'object' || gc.type === null) {
     457            return false;
     458        }
     459        return this.#canAdoptType(gc.type, map);
     460    }
     461    #canAdoptType(c, map = adoptionAnyMap) {
     462        return !!map.get(this.type)?.includes(c);
     463    }
     464    #adoptWithSpace(child, index) {
     465        const gc = child.#parts[0];
     466        const blank = new _a(null, gc, this.options);
     467        blank.#parts.push('');
     468        gc.push(blank);
     469        this.#adopt(child, index);
     470    }
     471    #adopt(child, index) {
     472        const gc = child.#parts[0];
     473        this.#parts.splice(index, 1, ...gc.#parts);
     474        for (const p of gc.#parts) {
     475            if (typeof p === 'object')
     476                p.#parent = this;
     477        }
     478        this.#toString = undefined;
     479    }
     480    #canUsurpType(c) {
     481        const m = usurpMap.get(this.type);
     482        return !!m?.has(c);
     483    }
     484    #canUsurp(child) {
     485        if (!child ||
     486            typeof child !== 'object' ||
     487            child.type !== null ||
     488            child.#parts.length !== 1 ||
     489            this.type === null ||
     490            this.#parts.length !== 1) {
     491            return false;
     492        }
     493        const gc = child.#parts[0];
     494        if (!gc || typeof gc !== 'object' || gc.type === null) {
     495            return false;
     496        }
     497        return this.#canUsurpType(gc.type);
     498    }
     499    #usurp(child) {
     500        const m = usurpMap.get(this.type);
     501        const gc = child.#parts[0];
     502        const nt = m?.get(gc.type);
     503        /* c8 ignore start - impossible */
     504        if (!nt)
     505            return false;
     506        /* c8 ignore stop */
     507        this.#parts = gc.#parts;
     508        for (const p of this.#parts) {
     509            if (typeof p === 'object') {
     510                p.#parent = this;
     511            }
     512        }
     513        this.type = nt;
     514        this.#toString = undefined;
     515        this.#emptyExt = false;
     516    }
    312517    static fromGlob(pattern, options = {}) {
    313         const ast = new AST(null, undefined, options);
    314         AST.#parseAST(pattern, ast, 0, options);
     518        const ast = new _a(null, undefined, options);
     519        _a.#parseAST(pattern, ast, 0, options, 0);
    315520        return ast;
    316521    }
    … …  
    416621    toRegExpSource(allowDot) {
    417622        const dot = allowDot ?? !!this.#options.dot;
    418         if (this.#root === this)
     623        if (this.#root === this) {
     624            this.#flatten();
    419625            this.#fillNegs();
    420         if (!this.type) {
     626        }
     627        if (!isExtglobAST(this)) {
    421628            const noEmpty = this.isStart() &&
    422629                this.isEnd() &&
    … …  
    425632                .map(p => {
    426633                const [re, _, hasMagic, uflag] = typeof p === 'string' ?
    427                     AST.#parseGlob(p, this.#hasMagic, noEmpty)
     634                    _a.#parseGlob(p, this.#hasMagic, noEmpty)
    428635                    : p.toRegExpSource(allowDot);
    429636                this.#hasMagic = this.#hasMagic || hasMagic;
    … …  
    487694            // the entire path portion.
    488695            const s = this.toString();
    489             this.#parts = [s];
    490             this.type = null;
    491             this.#hasMagic = undefined;
     696            const me = this;
     697            me.#parts = [s];
     698            me.type = null;
     699            me.#hasMagic = undefined;
    492700            return [s, (0, unescape_js_1.unescape)(this.toString()), false, false];
    493701        }
    494         // XXX abstract out this map method
    495702        let bodyDotAllowed = !repeated || allowDot || dot || !startNoDot ?
    496703            ''
    … …  
    528735        ];
    529736    }
     737    #flatten() {
     738        if (!isExtglobAST(this)) {
     739            for (const p of this.#parts) {
     740                if (typeof p === 'object') {
     741                    p.#flatten();
     742                }
     743            }
     744        }
     745        else {
     746            // do up to 10 passes to flatten as much as possible
     747            let iterations = 0;
     748            let done = false;
     749            do {
     750                done = true;
     751                for (let i = 0; i < this.#parts.length; i++) {
     752                    const c = this.#parts[i];
     753                    if (typeof c === 'object') {
     754                        c.#flatten();
     755                        if (this.#canAdopt(c)) {
     756                            done = false;
     757                            this.#adopt(c, i);
     758                        }
     759                        else if (this.#canAdoptWithSpace(c)) {
     760                            done = false;
     761                            this.#adoptWithSpace(c, i);
     762                        }
     763                        else if (this.#canUsurp(c)) {
     764                            done = false;
     765                            this.#usurp(c);
     766                        }
     767                    }
     768                }
     769            } while (!done && ++iterations < 10);
     770        }
     771        this.#toString = undefined;
     772    }
    530773    #partsToRegExp(dot) {
    531774        return this.#parts
    … …  
    599842}
    600843exports.AST = AST;
     844_a = AST;
    601845//# sourceMappingURL=ast.js.map
Note: See TracChangeset for help on using the changeset viewer.