1

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 ?

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
Guillaume
  • 59
  • 6

1 Answers1

0

You can pass options as the second parameter of transform method. See examples here

likerRr
  • 1,248
  • 1
  • 13
  • 19