I'm trying to build a nodeJS tool to help me analyzing another AngularJS source code. The idea is to :
- read some of the angular project javascript files
- for each file, grab the content
eval
the content from the file- do some stuff
The problem I'm facing is that my Angular source code uses es6 features like import
, export
, arrow functions
, ...Etc. and I using nodeJS which does not support these features yet.
So I tried to use @babel/core
transform()
from my Node app code, but it doesn't work. I keep getting error like Unexpected identifier
which means it doesn't understand the import {stuff} from 'here';
syntaxe.
srcFiles.forEach(content => {
try {
(function() {
eval(require("@babel/core").transform(content.text).code)
}.call(window, angular));
} catch (e) {
console.log(e);
}
});
An sample test file :
import _ from 'loadash';
console.log("I'm a file with import and export");
export const = 42;
Any idea how I can get this stuff working ? Or maybe another approach ?