E
E
Eugene Zubkov2018-08-27 12:44:54
JavaScript
Eugene Zubkov, 2018-08-27 12:44:54

Why is Gulp.js replacing a while loop with a for?

I did not find anything in the settings that clearly indicates such changes in the code. Google didn't help much either.
gulpfile.js

var gulp = require('gulp'),
    autoprefixer = require('gulp-autoprefixer'),
    minifyCSS = require('gulp-minify-css'),
    sourcemaps = require('gulp-sourcemaps'),
    sass = require('gulp-sass'),
    uglify = require('gulp-uglify'),
    concat = require('gulp-concat');


// css
gulp.task('css', function () {

  return gulp.src('scss/*.scss')
  	.pipe(sourcemaps.init())
    .pipe(sass().on('error', sass.logError))
    .pipe(autoprefixer({
        browsers: ['last 100 versions','ie > 8', 'opera > 12.1', 'Safari > 5', 'ff > 5']
    }))
    .pipe(minifyCSS())
    .pipe(sourcemaps.write('maps/'))
    .pipe(gulp.dest('../css/'));

});

// js
gulp.task('js', function () {
    gulp.src([
        'js/lang.js',
        'js/jquery.js',
        'js/lib/jquery.validate.js',
        'js/lib/masonry.js',
        'js/lib/moment.js',
        'js/lib/daterangepicker.js',
        'js/lib/slick.js',
        'js/lib/ion.rangeSlider.min.js',
        'js/lib/lli.js',
        'js/lib/simpleCalendar.js',
        'js/lib/jquery.Photostack.js',
        'js/scripts/*.js'
    ])
    .pipe(uglify())
    .pipe(concat('app.js'))
    .pipe(gulp.dest('../js/'));
});

// watcher
gulp.task('watch', function () {
  gulp.watch('scss/*.scss', ['css'])
  gulp.watch('js/**/*.js', ['js'])
});

// deafault
gulp.task('default', ['css', 'js', 'watch']);

Initial code
var day = 1;
    var dayCount = monthData.monthDaysCount();
    var self = this;
    
    while (day < dayCount) {
       // 
    }

Result
for (var n = 1, r = t.monthDaysCount(), a = this; n < r; ) {
       //
    }

Moreover, the next 3 variables fall into the for conditions before the while loop, the rest are generally removed (this is generally some kind of game, change cycles, variables).
I tried to remove uglify but the problem remains.
Js is only minified and merged into one file.
UPD
Corrected the code, what was originally, so it is immediately clear that this is absolutely not the same thing (as they wrote in the comments).
What is happening is clear and there are no problems with it. An interesting point is why uglify changes cycles since it is not always less than characters + well, in this example, it is clear that the logic is completely broken, which should not be.
UPD v2
There is no question in general, the problem is in uglify

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Spirin, 2018-08-27
@rockon404

Both options are equivalent. What is the problem?
Read: gulp-uglify compression options

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question