mishoo / UglifyJS

JavaScript parser / mangler / compressor / beautifier toolkit
http://lisperator.net/uglifyjs/
Other
13.14k stars 1.25k forks source link

[ES5] Unexpected token: punc when minifying ES5 LayerSlider Admin JS file #2403

Closed JanThiel closed 6 years ago

JanThiel commented 6 years ago

Bug report or feature request? Bug

ES5 or ES6+ input? ES5

Uglify version (uglifyjs -V) "version": "3.1.4",

JavaScript input

                // UndoManager action name
                var isSlide     = $holder.closest('.ls-slide-options').length,
                        linkData        = isSlide ? LS_activeSlideData.properties : LS_activeLayerDataSet[0],
                        undoText        = isSlide ? LS_l10n.SBUndoSlide : LS_l10n.SBUndoLayer,
                        undoArea        = isSlide ? 'slide.general' : 'layer.general',
                        undoIndex       = isSlide ? LS_activeSlideIndex : LS_activeLayerIndexSet[0],
                        urlField        = isSlide ? 'layer_link' : 'url';

                // Add link change to UndoManager
                LS_UndoManager.add( undoArea, undoText, {
                        itemIndex: undoIndex,
                        undo: {
                                [urlField]: linkData[urlField] || '',
                                linkId: linkData.linkId || '',
                                linkName: linkData.linkName || '',
                                linkType: linkData.linkType || ''
                        },
                        redo: {
                                [urlField]: LS_l10n[l10nKey].replace('%s', item.title),
                                linkId: item['post-id'],
                                linkName: item.title,
                                linkType: item['post-type']
                        }
                });

The uglifyjs CLI command executed or minify() options used.

const uglify = require("gulp-uglify");
const pump = require('pump');
    pump([gulp.src(["**/*.js", "!**/*.min.js", "!**/*-min.js", "!{**/,}gulpfile.js", "!node_modules{,/**}"]),
        uglify(),
        gulp.dest("./")
    ], cb);

JavaScript output or error produced. Can also be reproduced here: https://skalman.github.io/UglifyJS-online/

Parse error: Unexpected token: punc ([)
Line 13, column 33

12:                         undo: {
13:                                 [urlField]: linkData[urlField] || '',
14:                                 linkId: linkData.linkId || '',

I am trying to compress the LayerSlider WordPress Plugin Files and stumbled upon the mentioned error.

alexlamsl commented 6 years ago

That's ES6 - use uglify-es instead.

JanThiel commented 6 years ago

You are right... I am absolutely confused what es6 has to do in a delivered js library file which has to support non es6 browsers O.o. I will nag LayerSlider with this question! Thanks anyway and sorry for bothering you with this.

frank-dspeed commented 6 years ago

@JanThiel it looks like you should hire me to give you some insights Into JavaScript i am german nativ speaking JavaScript Senior Dev :)