test.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /*
  2. * Copyright (C) 2024 Puter Technologies Inc.
  3. *
  4. * This file is part of Puter.
  5. *
  6. * Puter is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU Affero General Public License as published
  8. * by the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU Affero General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Affero General Public License
  17. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  18. */
  19. const babelParser = require('@babel/parser');
  20. const generate = (require('@babel/generator')).default;
  21. const fs = require('fs');
  22. const recast = require('recast');
  23. const example = fs.readFileSync('./src/backend/src/filesystem/ll_operations/ll_read.js');
  24. {
  25. const ast = recast.parse(example, {
  26. parser: {
  27. parse (source) {
  28. return babelParser.parse(source, {
  29. ranges: true,
  30. tokens: true,
  31. });
  32. },
  33. },
  34. });
  35. const { code } = recast.print(ast);
  36. }
  37. {
  38. const ast = babelParser.parse('' + example, {
  39. tokens: true,
  40. });
  41. console.log(JSON.stringify(ast, undefined, ' '));
  42. }
  43. /*
  44. const { code } = generate(ast, {
  45. retainLines: true,
  46. });
  47. */
  48. // console.log(code);