Last active
November 15, 2017 09:21
-
-
Save gdborton/c6a8ce4532d12e2198ed1987bfe39097 to your computer and use it in GitHub Desktop.
Script used to compare acorn.parse on source vs JSON.parse on existing ASTs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require('fs'); | |
const glob = require('glob'); | |
const acorn = require('acorn-dynamic-import').default; | |
const sourceFiles = glob.sync('../location/*.source.json'); | |
const astFiles = glob.sync('../location/*.ast.json'); | |
const filesToParse = sourceFiles.map(fileLocation => { | |
return JSON.parse(fs.readFileSync(fileLocation, 'utf8')); | |
}); | |
console.log('found', filesToParse.length, ' source files to parse'); | |
console.time('parsing all the files'); | |
filesToParse.forEach((thing) => { | |
acorn.parse(thing.source, thing.parseOptions); | |
}); | |
console.timeEnd('parsing all the files'); | |
const astContents = astFiles.map((astFileLocation) => { | |
return fs.readFileSync(astFileLocation, 'utf8'); | |
}); | |
console.log('found', astContents.length, ' ast files to parse'); | |
console.time('json parsing asts'); | |
astContents.forEach((astString) => { | |
return JSON.parse(astString); | |
}); | |
console.timeEnd('json parsing asts'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment