Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
#!/usr/bin/env node
"use strict";
var opts = {
"mangle": {
"properties": true,
"toplevel": true
},
nameCache: { vars: {}, props: {} }
};
var terser = require('terser');
var hasOptionUndeclared = require('terser/package').version >= '4.1.1';
if (hasOptionUndeclared) {
opts.mangle.properties = {
"undeclared": true
};
}
terser.minify('var Bar = {};', opts);
var result = terser.minify('var Foo = { foo: function() { return Bar.bar() } };', opts);
var expected = `var r={o:function(){return a.${hasOptionUndeclared ? "t" : "v"}()}};`;
console.log("[task] test uglifying external properties",
"\n[Current ]", result.code, "\n[Expected]", expected);
if (result.code === expected) {
console.log(">>> same");
} else {
// https://github.com/terser-js/terser/issues/397
console.log(">>> different, so", hasOptionUndeclared ? "please check test code" : "recommend a terser <= v3.14.0");
}
p.regex = ToRegExp(p.regex);
}
if (m && typeof m.keep_fnames === "string") {
m.keep_fnames = ToRegExp(m.keep_fnames);
}
else if (m && !m.keep_fnames) {
m.keep_fnames = c.keep_fnames;
}
var comments = o.comments;
if (comments && typeof comments === "string") {
o.comments = ToRegExp(comments);
}
let ver = "", terser = null;
try {
// @ts-ignore
ver = require("terser/package").version;
} catch (e) {
console.log("Can not read the version of terser.");
}
try {
// @ts-ignore
terser = require("terser");
} catch (e) {
console.log("Can not read the module of terser.");
}
if (ver) {
var hasOptionUndeclared = ver >= '4.1.2', has_wrap_func_args = ver >= '4.3';
if (m) {
if (hasOptionUndeclared) {
if (p.undeclared == null) {
p.undeclared = true;
}