puter/experiments/js-parse-and-output/test.js

57 lines
1.5 KiB
JavaScript
Raw Normal View History

2024-07-09 08:10:33 +00:00
/*
* Copyright (C) 2024 Puter Technologies Inc.
*
2024-07-09 08:10:33 +00:00
* This file is part of Puter.
*
2024-07-09 08:10:33 +00:00
* Puter is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
2024-07-09 08:10:33 +00:00
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
2024-07-09 08:10:33 +00:00
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
const babelParser = require('@babel/parser');
const generate = (require('@babel/generator')).default;
const fs = require('fs');
const recast = require('recast');
const example = fs.readFileSync('./src/backend/src/filesystem/ll_operations/ll_read.js');
{
const ast = recast.parse(example, {
parser: {
parse (source) {
return babelParser.parse(source, {
ranges: true,
tokens: true,
});
},
},
});
const { code } = recast.print(ast);
}
{
const ast = babelParser.parse('' + example, {
tokens: true,
});
console.log(JSON.stringify(ast, undefined, ' '));
}
/*
const { code } = generate(ast, {
retainLines: true,
});
*/
// console.log(code);