build.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536
  1. var fs = require('fs')
  2. var path = require('path')
  3. var mkdirp = require('mkdirp')
  4. var buble = require('buble')
  5. var HEADER = '/* Generated by `npm run build`, do not edit! */\n\n'
  6. function compile (name, output, fix) {
  7. console.log(name, '→', output)
  8. mkdirp.sync(path.dirname(path.join(__dirname, output)))
  9. var source = fs.readFileSync(require.resolve(name), 'utf8')
  10. if (fix) source = fix(source)
  11. var result = buble.transform(source, {
  12. transforms: {
  13. dangerousForOf: true
  14. }
  15. })
  16. fs.writeFileSync(path.join(__dirname, output), HEADER + result.code, 'utf8')
  17. }
  18. function privateClassElements (str) {
  19. return str.replace('acorn-private-class-elements', '../private-class-elements')
  20. }
  21. compile('acorn-bigint', './lib/bigint/index.js')
  22. compile('acorn-numeric-separator', './lib/numeric-separator/index.js')
  23. compile('acorn-dynamic-import', './lib/dynamic-import/index.js')
  24. compile('acorn-import-meta', './lib/import-meta/index.js')
  25. compile('acorn-export-ns-from', './lib/export-ns-from/index.js')
  26. compile('acorn-class-fields', './lib/class-fields/index.js', privateClassElements)
  27. compile('acorn-static-class-features', './lib/static-class-features/index.js', privateClassElements)
  28. compile('acorn-private-class-elements', './lib/private-class-elements/index.js', function (str) {
  29. return str.replace('class extends Parser', 'class Parser_ extends Parser')
  30. // it also works with v7
  31. .replace('if (acorn.version.indexOf("6.") != 0 || acorn.version.indexOf("6.0.") == 0) {', 'if (false) {')
  32. })