return value;
}
-var fnPrefix = '!function(){';
-var fnSuffix = '}();';
-
function processOptions(options) {
['html5', 'includeAutoGeneratedTags'].forEach(function(key) {
if (!(key in options)) {
}
minifyJS.fromString = true;
(minifyJS.output || (minifyJS.output = {})).inline_script = true;
+ (minifyJS.parse || (minifyJS.parse = {})).bare_returns = false;
options.minifyJS = function(text, inline) {
var start = text.match(/^\s*<!--.*/);
var code = start ? text.slice(start[0].length).replace(/\n\s*-->\s*$/, '') : text;
try {
- if (inline) {
- code = fnPrefix + code + fnSuffix;
- }
+ minifyJS.parse.bare_returns = inline;
code = UglifyJS.minify(code, minifyJS).code;
- if (inline) {
- code = code.slice(fnPrefix.length, -fnSuffix.length);
- }
if (/;$/.test(code)) {
code = code.slice(0, -1);
}
assert.equal(minify(input, { minifyJS: true }), output);
input = '<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({\'gtm.start\':new Date().getTime(),event:\'gtm.js\'});var f=d.getElementsByTagName(s)[0],j=d.createElement(s),dl=l!=\'dataLayer\'?\'&l=\'+l:\'\';j.async=true;j.src=\'//www.googletagmanager.com/gtm.js?id=\'+i+dl;f.parentNode.insertBefore(j,f);})(window,document,\'script\',\'dataLayer\',\'GTM-67NT\');</script>';
- output = '<script>!function(w,d,s,l,i){w[l]=w[l]||[],w[l].push({"gtm.start":(new Date).getTime(),event:"gtm.js"});var f=d.getElementsByTagName(s)[0],j=d.createElement(s);j.async=!0,j.src="//www.googletagmanager.com/gtm.js?id=GTM-67NT",f.parentNode.insertBefore(j,f)}(window,document,"script","dataLayer","GTM-67NT")</script>';
+ output = '<script>!function(w,d,s,l,i){w[l]=w[l]||[],w[l].push({"gtm.start":(new Date).getTime(),event:"gtm.js"});var f=d.getElementsByTagName(s)[0],j=d.createElement(s);j.async=!0,j.src="//www.googletagmanager.com/gtm.js?id=GTM-67NT",f.parentNode.insertBefore(j,f)}(window,document,"script","dataLayer")</script>';
assert.equal(minify(input, { minifyJS: { mangle: false } }), output);