I have a repo here with some demo code It's written with babel so you'd need to use babel-node ./parse.js to run it. https://github.com/reggi/test-acorn-umd
The issue is that acorn builds an AST of a file, and when it encounters a syntax it's not familiar with it's not sure how to parse it.
Here's two examples, one with typescript, and one using babel and async / await.
@megawac tell me how you feel about this, but I don't think I need to build an AST at all. A complicated regex could look for the module definition. It's hard because you have to allow for ", ', ` and get the contents of the definition, and you have to ensure the definition is not within a comment.
import x from 'x'
require('something')
Thoughts on how I can get the module definitions of any file.
I just want to pass this in and get ['x', 'lodash', 'bluebird'].
import x from 'x'
// import y from 'y'
blah blah blah invalid ( javascript ] should not function matter get
require("lodash")
this should work as well
require(`bluebird`)
This is a crazy case, and may be over the top. Alternatively I might be comfortable with a syntax declaration.
I have a repo here with some demo code It's written with babel so you'd need to use
babel-node ./parse.js
to run it. https://github.com/reggi/test-acorn-umdThe issue is that acorn builds an AST of a file, and when it encounters a syntax it's not familiar with it's not sure how to parse it.
Here's two examples, one with typescript, and one using babel and async / await.
@megawac tell me how you feel about this, but I don't think I need to build an AST at all. A complicated regex could look for the module definition. It's hard because you have to allow for
"
,'
, ` and get the contents of the definition, and you have to ensure the definition is not within a comment.Thoughts on how I can get the module definitions of any file.
I just want to pass this in and get
['x', 'lodash', 'bluebird']
.This is a crazy case, and may be over the top. Alternatively I might be comfortable with a syntax declaration.
Or even run down the list and hope one doesn't throw an error.