0

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?

rnso
  • 23,686
  • 25
  • 112
  • 234
  • 3
    That reference is from 2012. You may want to look at [the documentation for the current version of the library](https://www.npmjs.com/package/uglify-js) to see how to implement it today. – Andy Jun 09 '23 at 12:46

0 Answers0