parse is undefined even after specifying require statement

23 Views Asked by At

I am using code from this page with my sample code:

var jsp = require("uglify-js").parser;
var pro = require("uglify-js").uglify;

var orig_code = `
    function myfn(msg, abcd){
        print abcd 
        }
    function secondfn ( msg2, "xyz"){
        print  second 
        }
    let abc = "ABCD"; var pqr = "PQRS"; const pi = 3.14159; let xyz="XYZ";
    const ten=10; use abc; myfn(); secondfn(); secondfn(); myfn(); use pqr; use pi; use pqr; 
`;
var options = {
    mangle: true
};

var ast = jsp.parse(orig_code); // parse code and get the initial AST
ast = pro.ast_mangle(ast, options); // get a new AST with mangled names
ast = pro.ast_squeeze(ast); // get an AST with compression optimizations
var final_code = pro.gen_code(ast); // compressed code here

console.log(final_code); 

However, when I run this file with command node mysrc.js, I get following error:

var ast = jsp.parse(orig_code); // parse code and get the initial AST
              ^

TypeError: Cannot read property 'parse' of undefined

Where is the problem and how can it be solved?

0

There are 0 best solutions below