(context, imports, fileInfo, currentIndex)
| 44 | // |
| 45 | |
| 46 | const Parser = function Parser(context, imports, fileInfo, currentIndex) { |
| 47 | currentIndex = currentIndex || 0; |
| 48 | let parsers; |
| 49 | const parserInput = getParserInput(); |
| 50 | |
| 51 | function error(msg, type) { |
| 52 | throw new LessError( |
| 53 | { |
| 54 | index: parserInput.i, |
| 55 | filename: fileInfo.filename, |
| 56 | type: type || 'Syntax', |
| 57 | message: msg |
| 58 | }, |
| 59 | imports |
| 60 | ); |
| 61 | } |
| 62 | |
| 63 | const deprecationHandler = new DeprecationHandler(); |
| 64 | |
| 65 | /** |
| 66 | * @param {string} msg |
| 67 | * @param {number} index |
| 68 | * @param {string} type |
| 69 | * @param {string} [deprecationId] - stable deprecation ID for repetition limiting |
| 70 | */ |
| 71 | function warn(msg, index, type, deprecationId) { |
| 72 | if (context.quiet) { return; } |
| 73 | if (deprecationId && context.quietDeprecations) { return; } |
| 74 | if (deprecationId && !deprecationHandler.shouldWarn(deprecationId)) { return; } |
| 75 | |
| 76 | logger.warn( |
| 77 | (new LessError( |
| 78 | { |
| 79 | index: index ?? parserInput.i, |
| 80 | filename: fileInfo.filename, |
| 81 | type: type ? `${type.toUpperCase()} WARNING` : 'WARNING', |
| 82 | message: msg |
| 83 | }, |
| 84 | imports |
| 85 | )).toString() |
| 86 | ); |
| 87 | } |
| 88 | |
| 89 | function expect(arg, msg) { |
| 90 | // some older browsers return typeof 'function' for RegExp |
| 91 | const result = (arg instanceof Function) ? arg.call(parsers) : parserInput.$re(arg); |
| 92 | if (result) { |
| 93 | return result; |
| 94 | } |
| 95 | |
| 96 | error(msg || (typeof arg === 'string' |
| 97 | ? `expected '${arg}' got '${parserInput.currentChar()}'` |
| 98 | : 'unexpected token')); |
| 99 | } |
| 100 | |
| 101 | // Specialization of expect() |
| 102 | function expectChar(arg, msg) { |
| 103 | if (parserInput.$char(arg)) { |
nothing calls this directly
no test coverage detected