|
Last change
on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 12 days ago |
|
Fix frontend appearance
|
-
Property mode
set to
100644
|
|
File size:
941 bytes
|
| Line | |
|---|
| 1 | 'use strict';
|
|---|
| 2 |
|
|---|
| 3 | const crypto = require('crypto');
|
|---|
| 4 | const moduleRequire = require('eslint-module-utils/module-require').default;
|
|---|
| 5 | const hashObject = require('eslint-module-utils/hash').hashObject;
|
|---|
| 6 |
|
|---|
| 7 | const cache = new Map();
|
|---|
| 8 |
|
|---|
| 9 | // must match ESLint default options or we'll miss the cache every time
|
|---|
| 10 | const parserOptions = {
|
|---|
| 11 | loc: true,
|
|---|
| 12 | range: true,
|
|---|
| 13 | raw: true,
|
|---|
| 14 | tokens: true,
|
|---|
| 15 | comment: true,
|
|---|
| 16 | attachComment: true,
|
|---|
| 17 | };
|
|---|
| 18 |
|
|---|
| 19 | exports.parse = function parse(content, options) {
|
|---|
| 20 | options = { ...options, ...parserOptions };
|
|---|
| 21 |
|
|---|
| 22 | if (!options.filePath) {
|
|---|
| 23 | throw new Error('no file path provided!');
|
|---|
| 24 | }
|
|---|
| 25 |
|
|---|
| 26 | const keyHash = crypto.createHash('sha256');
|
|---|
| 27 | keyHash.update(content);
|
|---|
| 28 | hashObject(options, keyHash);
|
|---|
| 29 |
|
|---|
| 30 | const key = keyHash.digest('hex');
|
|---|
| 31 |
|
|---|
| 32 | let ast = cache.get(key);
|
|---|
| 33 | if (ast != null) { return ast; }
|
|---|
| 34 |
|
|---|
| 35 | const realParser = moduleRequire(options.parser);
|
|---|
| 36 |
|
|---|
| 37 | ast = realParser.parse(content, options);
|
|---|
| 38 | cache.set(key, ast);
|
|---|
| 39 |
|
|---|
| 40 | return ast;
|
|---|
| 41 | };
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.