acorn-umd
Parse acorn ast for AMD, CommonJS, and ES6 definitions.
The Nodes created align as closely as possible with the nodes generated for acorns ES6 import nodes. Example below
var acorn = require('acorn');
var umd = require('acorn-umd');
var code = `
import {a, b, c as d} from 'library';
import foo from 'foo-library';
let _ = require('lodash');
`;
var ast = acorn.parse(code, {ecmaVersion: 6});
var imports = umd(ast, {
es6: true, amd: false, cjs: true
});
console.log(imports);
[
{ type: 'CJSImport',
reference:
{ type: 'VariableDeclaration',
start: 87,
end: 113,
declarations: [Object],
kind: 'let' },
specifiers: [ [Object] ],
start: 87,
end: 113,
source:
{ type: 'Literal',
reference: [Object],
value: 'lodash',
raw: '\'lodash\'',
start: 103,
end: 111 }
},
{ type: 'ImportDeclaration',
start: 5,
end: 42,
specifiers: [ [Object], [Object], [Object] ],
source:
{ type: 'Literal',
start: 32,
end: 41,
value: 'library',
raw: '\'library\'' }
},
{ type: 'ImportDeclaration',
start: 47,
end: 77,
specifiers: [ [Object] ],
source:
{ type: 'Literal',
start: 63,
end: 76,
value: 'foo-library',
raw: '\'foo-library\'' }
}
]
TODO