web 3d图形渲染器
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

41 lines
927 B

  1. 'use strict'
  2. const crypto = require('crypto')
  3. , moduleRequire = require('eslint-module-utils/module-require').default
  4. , hashObject = require('eslint-module-utils/hash').hashObject
  5. const cache = new Map()
  6. // must match ESLint default options or we'll miss the cache every time
  7. const parserOptions = {
  8. loc: true,
  9. range: true,
  10. raw: true,
  11. tokens: true,
  12. comment: true,
  13. attachComment: true,
  14. }
  15. exports.parse = function parse(content, options) {
  16. options = Object.assign({}, options, parserOptions)
  17. if (!options.filePath) {
  18. throw new Error('no file path provided!')
  19. }
  20. const keyHash = crypto.createHash('sha256')
  21. keyHash.update(content)
  22. hashObject(options, keyHash)
  23. const key = keyHash.digest('hex')
  24. let ast = cache.get(key)
  25. if (ast != null) return ast
  26. const realParser = moduleRequire(options.parser)
  27. ast = realParser.parse(content, options)
  28. cache.set(key, ast)
  29. return ast
  30. }