Sha256: 62976d01c8cc816705987b269df0dedc523d85861ea1496c900925e8f4285b1c

Contents?: true

Size: 941 Bytes

Versions: 49

Compression:

Stored size: 941 Bytes

Contents

'use strict';

const crypto = require('crypto');
const moduleRequire = require('eslint-module-utils/module-require').default;
const hashObject = require('eslint-module-utils/hash').hashObject;

const cache = new Map();

// must match ESLint default options or we'll miss the cache every time
const parserOptions = {
  loc: true,
  range: true,
  raw: true,
  tokens: true,
  comment: true,
  attachComment: true,
};

exports.parse = function parse(content, options) {
  options = { ...options, ...parserOptions };

  if (!options.filePath) {
    throw new Error('no file path provided!');
  }

  const keyHash = crypto.createHash('sha256');
  keyHash.update(content);
  hashObject(options, keyHash);

  const key = keyHash.digest('hex');

  let ast = cache.get(key);
  if (ast != null) { return ast; }

  const realParser = moduleRequire(options.parser);

  ast = realParser.parse(content, options);
  cache.set(key, ast);

  return ast;
};

Version data entries

49 entries across 49 versions & 1 rubygems

Version Path
immosquare-cleaner-0.1.60 node_modules/eslint-plugin-import/memo-parser/index.js
immosquare-cleaner-0.1.59 node_modules/eslint-plugin-import/memo-parser/index.js
immosquare-cleaner-0.1.58 node_modules/eslint-plugin-import/memo-parser/index.js
immosquare-cleaner-0.1.57 node_modules/eslint-plugin-import/memo-parser/index.js
immosquare-cleaner-0.1.56 node_modules/eslint-plugin-import/memo-parser/index.js
immosquare-cleaner-0.1.55 node_modules/eslint-plugin-import/memo-parser/index.js
immosquare-cleaner-0.1.54 node_modules/eslint-plugin-import/memo-parser/index.js
immosquare-cleaner-0.1.53 node_modules/eslint-plugin-import/memo-parser/index.js
immosquare-cleaner-0.1.52 node_modules/eslint-plugin-import/memo-parser/index.js
immosquare-cleaner-0.1.51 node_modules/eslint-plugin-import/memo-parser/index.js
immosquare-cleaner-0.1.50 node_modules/eslint-plugin-import/memo-parser/index.js
immosquare-cleaner-0.1.49 node_modules/eslint-plugin-import/memo-parser/index.js
immosquare-cleaner-0.1.48 node_modules/eslint-plugin-import/memo-parser/index.js
immosquare-cleaner-0.1.47 node_modules/eslint-plugin-import/memo-parser/index.js
immosquare-cleaner-0.1.46 node_modules/eslint-plugin-import/memo-parser/index.js
immosquare-cleaner-0.1.45 node_modules/eslint-plugin-import/memo-parser/index.js
immosquare-cleaner-0.1.44 node_modules/eslint-plugin-import/memo-parser/index.js
immosquare-cleaner-0.1.43 node_modules/eslint-plugin-import/memo-parser/index.js
immosquare-cleaner-0.1.42 node_modules/eslint-plugin-import/memo-parser/index.js
immosquare-cleaner-0.1.41 node_modules/eslint-plugin-import/memo-parser/index.js