getOps.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #!/usr/bin/env node
  2. var fs = require('fs');
  3. var path = require('path');
  4. var execSync = require('child_process').execSync;
  5. var $ = require('cheerio');
  6. var fromEntries = require('object.fromentries');
  7. if (process.argv.length !== 3) {
  8. throw new RangeError('please provide a year');
  9. }
  10. var year = parseInt(process.argv[2]);
  11. if (year < 2016) {
  12. throw new RangeError('ES2016+ only');
  13. }
  14. var edition = year - 2009;
  15. var specHTMLurl = new URL('https://raw.githubusercontent.com/tc39/ecma262/es' + year + '/spec.html');
  16. var specHTML = String(execSync('curl --silent ' + specHTMLurl));
  17. var root = $(specHTML);
  18. var aOps = root.filter('[aoid]').add(root.find('[aoid]'));
  19. var missings = [];
  20. var entries = aOps.toArray().map(function (x) {
  21. var op = $(x);
  22. var aoid = op.attr('aoid');
  23. var id = op.attr('id');
  24. if (!id) {
  25. id = op.closest('[id]').attr('id');
  26. }
  27. if (!id) {
  28. missings.push(aoid);
  29. }
  30. return [
  31. aoid,
  32. 'https://ecma-international.org/ecma-262/' + edition + '.0/#' + id
  33. ];
  34. });
  35. if (missings.length > 0) {
  36. console.error('Missing URLs:', missings);
  37. process.exit(1);
  38. }
  39. entries.sort(function (a, b) { return a[0].localeCompare(b[0]); });
  40. var obj = fromEntries(entries);
  41. var outputPath = path.join('operations', year + '.js');
  42. fs.writeFileSync(outputPath, '\'use strict\';\n\nmodule.exports = ' + JSON.stringify(obj, null, '\t')+ ';\n');
  43. console.log('npx eslint --quiet --fix ' + outputPath);
  44. execSync('npx eslint --quiet --fix ' + outputPath);