Comments (9)
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.
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.
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.
How about my new commit?
from velocity.js.
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.
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.
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.
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.
You are welcome! Thank you for your work and this great library!
from velocity.js.
Related Issues (20)
- Dashes in Identifiers HOT 1
- Support format quiet syntax $!{reference}
- String.replace() is not global HOT 2
- Map.remove() is not implemented HOT 2
- String pipe symbol not implemented HOT 1
- Support the $util.qr directive HOT 1
- IE or older browsers not supported!!! HOT 1
- Bug with #set inside #foreach: setting properties on loop variable from foreach doesn't work HOT 1
- TypeError: Cannot read property 'charCodeAt' of undefined HOT 1
- 如何实现webpack的热更新? HOT 2
- String matches does not work HOT 2
- 变量名称是null时报错 HOT 1
- Bug with rendering #foreach and $util.map.copyAndRemoveAllKeys HOT 13
- How to figure out which references in AST are able to be set in context HOT 2
- Support method with arguments HOT 2
- Parse String to Int HOT 2
- ESM module build? HOT 10
- #set with array fails for unknown reason HOT 1
- 无法解析vue中使用element-ui的$message语法 HOT 1
- Date functions not working HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from velocity.js.