Git Product home page Git Product logo

Comments (9)

shepherdwind avatar shepherdwind commented on July 20, 2024

This bug is fix now, I just publish the 0.4.7 version. You can try it, If there is other problem, I will take action soon.

So glad to hear from you voice.

Tests is very usefull.

from velocity.js.

DavidWiesner avatar DavidWiesner commented on July 20, 2024

Year this was a little to much. So this patch remove all double newlines, even i want to have.

I don´t have a locked deep in the code but bug is hiding on an other place.
The newlines should only be removed when the hole line is a #*** statement. For example it works for #set statement outside an #if or #foreach but not inside.

from velocity.js.

shepherdwind avatar shepherdwind commented on July 20, 2024

Ok, I know where the bug happen now. Before, the asts was lineal, so I can forEach ast element, when find its type to be directives, I will remove the next new line.

But, after sometimes, I change asts structure. So the ast may be an array, when #if and #set come together, trim fail.

from velocity.js.

shepherdwind avatar shepherdwind commented on July 20, 2024

How about my new commit?

from velocity.js.

DavidWiesner avatar DavidWiesner commented on July 20, 2024

Much much better!!!
But I´m sorry, still not perfect. I now have problems with newlines and references in a foreach-loop.
You can´t solve the newline problem in the preprocessor. The preprocessor don´t know what happen in the logical line before. So for example: Was there a statement, reference or a string at the end of the previous loop?
So here is an Unit-Test for that:

        it('multiline: with references', function(){
            var vm = [ 'a',
                        '#foreach($b in $nums)',
                        '#if($b)',
                        'b',
                        'e $b.alm',
                        '#end',
                        '#end',
                        'c'].join("\n");
            assert.equal([  'a',
                            'b',
                            'e 1',
                            'b',
                            'e 2',
                            'b',
                            'e 3',
                            'c'].join("\n"), render(vm, {nums:[{alm:1},{alm:2},{alm:3}],bar:""}))
        })

from velocity.js.

shepherdwind avatar shepherdwind commented on July 20, 2024

You unit-test run ok. But when #if end with blank space and newline, such as#if($a) \n $b #end, that condition will fail. And I fix it at 45fd82e.

But I don't know what condition will preprocessor go wrong. Maybe you can give me some other unit-test.

from velocity.js.

DavidWiesner avatar DavidWiesner commented on July 20, 2024

That was my fault. I have checkout the wrong branch.
I can´t find any condition yet were the preprocessor can get wrong. So your patches will work.
But there is one another condition that failed: two newlines after statement.

        it('multiple newlines after statement', function(){
            var vm = '#if(1>0)\n\nb#end'
            assert.equal('\nb', render(vm))
        })

just change the var TRIM_REG = /^\s*\n/; to var TRIM_REG = /^[ \t]*\n/; and this will also pass.

from velocity.js.

shepherdwind avatar shepherdwind commented on July 20, 2024

You are right, thanks for review my code.

So help me check if there are some other mistakes. If all is fine, I will merge #34 to master now, and pubilsh new version to npm.

After all, thank you give me so much advice, and even the unit-test, so nice.

from velocity.js.

DavidWiesner avatar DavidWiesner commented on July 20, 2024

You are welcome! Thank you for your work and this great library!

from velocity.js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.