Possible bug with dot at beginning of line, ternary and object

1.7.0 added “Leading . now closes all open calls, allowing for simpler chaining syntax.”

This is great, but I may have just stumbled on a bug with that when using the ternary operator and an object argument.

gulp.task 'stylus', ->
    gulp.src [
        './src/stylus/vars.styl'
        './src/stylus/**/*.styl'
    ]
        .pipe if argv.sourcemaps then require('gulp-sourcemaps').init() else gutil.noop()
        .pipe require('gulp-concat') 'styles.styl'
        .pipe require('gulp-stylus')
            use: require('nib')()
        .pipe if isLocal() then gutil.noop() else require('gulp-minify-css')
            compatibility: '' # Empty string is IE9+ (this is default)
        .pipe if argv.sourcemaps then require('gulp-sourcemaps').write() else gutil.noop()
        .pipe gulp.dest './dist/css'

This is coming out as

// Generated by CoffeeScript 1.9.2
gulp.task('stylus', function() {
  return gulp.src(['./src/stylus/vars.styl', './src/stylus/**/*.styl']).pipe(argv.sourcemaps ? require('gulp-sourcemaps').init() : gutil.noop()).pipe(require('gulp-concat')('styles.styl')).pipe(require('gulp-stylus')({
    use: require('nib')()
  })).pipe(isLocal() ? gutil.noop() : require('gulp-minify-css')({
    compatilibilty: ''
  }).pipe(argv.sourcemaps ? require('gulp-sourcemaps').write() : gutil.noop())).pipe(gulp.dest('./dist/css'));
});

I was expecting

  • compatibility: '' object to be an argument to require('gulp-minify-css') — in this case the result is as expected.
  • the dot at the start of the next line to close both the ternary and the pipe() from the preceding line — in this case the result is not as expected: the next .pipe() is chained on the end of the gulp-minify-css object.

Note that the gulp-stylus pipe above also receives an object as an argument but does not have a ternary. This one compiles as I expect.

Note also that the gulp-sourcemaps pipes have ternaries but no object argument, and these ones also compile as I expect.

So it seems it’s a combination of the tenary and the object argument on a new line.

Is this a bug or am I understanding something incorrectly?

1 possible answer(s) on “Possible bug with dot at beginning of line, ternary and object

  1. Chaining is supposed to be unindented

    I’ve never heard about chaining being “supposed” to be in any particular way. All CoffeeScript I’ve ever written has used indented chaining (because that’s what I’m used to from JavaScript). I don’t think anyone knows the exact rules. What makes things harder is that the compiler has always been a little too permissive and since CoffeeScript has been around for so long now, it’s hard to tell intended behavior from accidental. CoffeeScriptRedux tried to define sane rules for stuff like this, but people have come to depend on accidental quirks (which is one reason people sadly had problems adopting CSR).