| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- __atomic_acorn = require('./acorn');
- __atomic_beautify = require('./beautify');
- exports.parseToJSON = function (source) {
- var start = new Date().getTime();
- var comments = [];
- var ast = __atomic_acorn.parse( source, {
- // collect ranges for each node
- ranges: true,
- locations: true,
- onComment: comments,
- });
- var end = new Date().getTime();
- var time = end - start;
- // print('Acorn parse time: ' + time);
- ast["comments"] = comments;
- start = new Date().getTime();
- ast = JSON.stringify(ast);
- end = new Date().getTime();
- time = end - start;
- // print('JSON.stringify time: ' + time);
- return ast;
- }
- exports.parseErrorCheck = function(source) {
- try {
- __atomic_acorn.parse( source, {
- ranges: true,
- locations: true,
- });
- } catch(e) {
- //if (!(e instanceof __atomic_acorn.SyntaxError)) throw e;
- if (!(e instanceof SyntaxError))
- return false; // rethrow?
- return e;
- }
- return false;
- }
- // TODO: options
- exports.jsBeautify = function (source) {
- return __atomic_beautify.js_beautify(source);
- }
|