Skip to content

Commit

Permalink
Merge pull request #1259 from visionmedia/remove-assignment-operator
Browse files Browse the repository at this point in the history
Remove the assignment operator
  • Loading branch information
ForbesLindesay committed Oct 19, 2013
2 parents 3961798 + b5e7160 commit bd6233b
Show file tree
Hide file tree
Showing 13 changed files with 21 additions and 51 deletions.
19 changes: 0 additions & 19 deletions lib/lexer.js
Original file line number Diff line number Diff line change
Expand Up @@ -417,24 +417,6 @@ Lexer.prototype = {
return this.scan(/^default */, 'default');
},

/**
* Assignment.
*/

assignment: function() {
var captures;
if (captures = /^([\w_]+) += *([^\n]+)/.exec(this.input)) {
this.consume(captures[0].length);
var name = captures[1]
, val = captures[2].trim();
if (val[val.length - 1] === ';') {
val = val.substr(0, val.length - 1);
}
assertExpression(val);
return this.tok('code', 'var ' + name + ' = (' + val + ');');
}
},

/**
* Call mixin.
*/
Expand Down Expand Up @@ -829,7 +811,6 @@ Lexer.prototype = {
|| this.conditional()
|| this.each()
|| this["while"]()
|| this.assignment()
|| this.tag()
|| this.filter()
|| this.code()
Expand Down
2 changes: 1 addition & 1 deletion test/cases/attrs-data.jade
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
user = { name: 'tobi' }
- var user = { name: 'tobi' }
foo(data-user=user)
foo(data-items=[1,2,3])
foo(data-username='tobi')
Expand Down
2 changes: 1 addition & 1 deletion test/cases/case-blocks.jade
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
html
body
friends = 1
- var friends = 1
case friends
when 0
p you have no friends
Expand Down
2 changes: 1 addition & 1 deletion test/cases/case.jade
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
html
body
friends = 1
- var friends = 1
case friends
when 0: p you have no friends
when 1: p you have a friend
Expand Down
10 changes: 5 additions & 5 deletions test/cases/code.iteration.jade
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ ul
li= item
- })

items = [1,2,3]
- var items = [1,2,3]

ul
for item, i in items
Expand All @@ -20,16 +20,16 @@ ul
each $item in items
li= $item

nums = [1, 2, 3]
letters = ['a', 'b', 'c']
- var nums = [1, 2, 3]
- var letters = ['a', 'b', 'c']

ul
for l in letters
for n in nums
li #{n}: #{l}

count = 1
counter = function() { return [count++, count++, count++] }
- var count = 1
- var counter = function() { return [count++, count++, count++] }
ul
for n in counter()
li #{n}
10 changes: 5 additions & 5 deletions test/cases/each.else.jade
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

users = []
- var users = []

ul
for user in users
Expand All @@ -8,7 +8,7 @@ ul
li no users!


users = [{ name: 'tobi', friends: ['loki'] }, { name: 'loki' }]
- var users = [{ name: 'tobi', friends: ['loki'] }, { name: 'loki' }]

if users
ul
Expand All @@ -17,15 +17,15 @@ if users
else
li no users!

user = { name: 'tobi', age: 10 }
- var user = { name: 'tobi', age: 10 }

ul
each val, key in user
li #{key}: #{val}
else
li user has no details!

user = {}
- var user = {}

ul
each prop, key in user
Expand All @@ -39,7 +39,7 @@ ul
- else
li user has no details!

user = Object.create(null)
- var user = Object.create(null)
- user.name = 'tobi'

ul
Expand Down
2 changes: 1 addition & 1 deletion test/cases/filters-empty.jade
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
users = [{ name: 'tobi', age: 2 }]
- var users = [{ name: 'tobi', age: 2 }]

fb:users
for user in users
Expand Down
2 changes: 1 addition & 1 deletion test/cases/filters.cdata.jade
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

users = [{ name: 'tobi', age: 2 }]
- users = [{ name: 'tobi', age: 2 }]

fb:users
for user in users
Expand Down
2 changes: 1 addition & 1 deletion test/cases/mixin.blocks.jade
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

mixin form(method, action)
form(method=method, action=action)
csrf_token_from_somewhere = 'hey'
- var csrf_token_from_somewhere = 'hey'
input(type='hidden', name='_csrf', value=csrf_token_from_somewhere)
block

Expand Down
2 changes: 1 addition & 1 deletion test/cases/regression.784.jade
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
url = 'http://www.google.com'
- var url = 'http://www.google.com'
.url #{url.replace('http://', '').replace(/^www\./, '')}
4 changes: 2 additions & 2 deletions test/cases/tag.interpolation.jade
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

tag = 'p'
foo = 'bar'
- var tag = 'p'
- var foo = 'bar'

#{tag} value
#{tag}(foo='bar') value
Expand Down
4 changes: 2 additions & 2 deletions test/cases/vars.jade
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
foo = 'bar'
list = [1,2,3]
- var foo = 'bar'
- var list = [1,2,3]
a(class=list, id=foo)
11 changes: 0 additions & 11 deletions test/jade.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -962,17 +962,6 @@ describe('jade', function(){
assert.ok(!tag.getAttribute(name))
});

it('should support assignment', function(){
assert.equal('<div>5</div>', jade.render('a = 5;\ndiv= a'));
assert.equal('<div>5</div>', jade.render('a = 5\ndiv= a'));
assert.equal('<div>foo bar baz</div>', jade.render('a = "foo bar baz"\ndiv= a'));
assert.equal('<div>5</div>', jade.render('a = 5 \ndiv= a'));
assert.equal('<div>5</div>', jade.render('a = 5 ; \ndiv= a'));

var fn = jade.compile('test = local\np=test');
assert.equal('<p>bar</p>', fn({ local: 'bar' }));
});

it('should be reasonably fast', function(){
jade.compile(perfTest, {})
})
Expand Down

0 comments on commit bd6233b

Please sign in to comment.