gulp-swig icon indicating copy to clipboard operation
gulp-swig copied to clipboard

clone(options) breaks ability to pass data around.

Open michaeldewayneharris opened this issue 10 years ago • 3 comments

The way the code is now it breaks when you need to run a function from the html that is defined in the context. The way it is now, variables are static once they are passed into swig and they are unable to be modified.

var opts = options ? clone(options) : {};

should be

var opts = options ? options : {};

michaeldewayneharris avatar Dec 10 '14 20:12 michaeldewayneharris

Can you give me an example or write a test showing that it breaks? That will help clarify what you're talking about. Thanks.

colynb avatar Dec 11 '14 00:12 colynb

index.html

{{ pushToArray('something') }}
{{myArray}}

gulpfile.js

var gulp = require('gulp');
gulp.task('default', function() {
    var swig = require('gulp-swig');
    var ctx = {
        data: {
            pushToArray: function(style){
                ctx.data.myArray.push(style); 
                return '';
            },
            myArray: []
        }
    };

    return gulp.src('index.html')
    .pipe(swig(ctx))
    .pipe(gulp.dest("output"));
});

the output folder that gets generated will contain a index.html

the way gulp-swig is now myArray never gets updated. and so the output is blank. if you make the change i suggested, you will see the the array does get updated.

michaeldewayneharris avatar Dec 11 '14 13:12 michaeldewayneharris

The problem is that the clone breaks the reference to the original object because it makes a brand new object instead of passing the reference to the one already created.

michaeldewayneharris avatar Dec 11 '14 14:12 michaeldewayneharris