Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trailing semicolon #2962

Merged
merged 4 commits into from
Feb 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 3 additions & 4 deletions packages/pug-runtime/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ function pug_merge(a, b) {
a[key] = (Array.isArray(valA) ? valA : [valA]).concat(b[key] || []);
} else if (key === 'style') {
var valA = pug_style(a[key]);
valA = valA && valA[valA.length - 1] !== ';' ? valA + ';' : valA;
var valB = pug_style(b[key]);
valB = valB && valB[valB.length - 1] !== ';' ? valB + ';' : valB;
a[key] = valA + valB;
} else {
a[key] = b[key];
Expand Down Expand Up @@ -109,10 +111,7 @@ function pug_style(val) {
}
return out;
} else {
val += '';
if (val[val.length - 1] !== ';')
return val + ';';
return val;
return val + '';
}
};

Expand Down
2 changes: 1 addition & 1 deletion packages/pug-runtime/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ addTest('merge', function (merge) {
addTest('style', function (style) {
expect(style(null)).toBe('');
expect(style('')).toBe('');
expect(style('foo: bar')).toBe('foo: bar;');
expect(style('foo: bar')).toBe('foo: bar');
expect(style('foo: bar;')).toBe('foo: bar;');
expect(style({foo: 'bar'})).toBe('foo:bar;');
expect(style({foo: 'bar', baz: 'bash'})).toBe('foo:bar;baz:bash;');
Expand Down
2 changes: 1 addition & 1 deletion packages/pug/test/cases-es2015/attr.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<div class="avatar-div" style="background-image: url(https://www.gravatar.com/avatar/219b77f9d21de75e81851b6b886057c7);"></div>
<div class="avatar-div" style="background-image: url(https://www.gravatar.com/avatar/219b77f9d21de75e81851b6b886057c7)"></div>
6 changes: 3 additions & 3 deletions packages/pug/test/cases/styles.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
</style>
</head>
<body>
<div style="color:red;background:green"></div>
<div style="color:red;background:green;"></div>
<div style="color:red;background:green"></div>
<div style="color:red;background:green;"></div>
<div style="color:red;background:green;"></div>
<div style="color:red;background:green;"></div>
<div style="color:red;background:green;"></div>
<div style="color:red;background:green"></div>
<div style="color:red;background:green;"></div>
<div style="color:red;background:green;"></div>
<div style="color:red;background:green;"></div>
Expand Down
2 changes: 1 addition & 1 deletion packages/pug/test/output-es2015/attr.html
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@

<div class="avatar-div" style="background-image: url(https://www.gravatar.com/avatar/219b77f9d21de75e81851b6b886057c7);"></div>
<div class="avatar-div" style="background-image: url(https://www.gravatar.com/avatar/219b77f9d21de75e81851b6b886057c7)"></div>
12 changes: 6 additions & 6 deletions packages/pug/test/pug.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -371,8 +371,8 @@ describe('pug', function(){
assert.equal('<a href="http://google.com" title="Some : weird = title"></a>', pug.render('a(href= "http://google.com", title= "Some : weird = title")'));
assert.equal('<label for="name"></label>', pug.render('label(for="name")'));
assert.equal('<meta name="viewport" content="width=device-width"/>', pug.render("meta(name= 'viewport', content='width=device-width')"), 'Test attrs that contain attr separators');
assert.equal('<div style="color= white;"></div>', pug.render("div(style='color= white')"));
assert.equal('<div style="color: white;"></div>', pug.render("div(style='color: white')"));
assert.equal('<div style="color= white"></div>', pug.render("div(style='color= white')"));
assert.equal('<div style="color: white"></div>', pug.render("div(style='color: white')"));
assert.equal('<p class="foo"></p>', pug.render("p('class'='foo')"), 'Test keys with single quotes');
assert.equal('<p class="foo"></p>', pug.render("p(\"class\"= 'foo')"), 'Test keys with double quotes');

Expand All @@ -389,10 +389,10 @@ describe('pug', function(){

assert.equal('<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>', pug.render('meta(http-equiv="X-UA-Compatible", content="IE=edge,chrome=1")'));

assert.equal('<div style="background: url(/images/test.png);">Foo</div>', pug.render("div(style= 'background: url(/images/test.png)') Foo"));
assert.equal('<div style="background = url(/images/test.png);">Foo</div>', pug.render("div(style= 'background = url(/images/test.png)') Foo"));
assert.equal('<div style="foo;">Foo</div>', pug.render("div(style= ['foo', 'bar'][0]) Foo"));
assert.equal('<div style="bar;">Foo</div>', pug.render("div(style= { foo: 'bar', baz: 'raz' }['foo']) Foo"));
assert.equal('<div style="background: url(/images/test.png)">Foo</div>', pug.render("div(style= 'background: url(/images/test.png)') Foo"));
assert.equal('<div style="background = url(/images/test.png)">Foo</div>', pug.render("div(style= 'background = url(/images/test.png)') Foo"));
assert.equal('<div style="foo">Foo</div>', pug.render("div(style= ['foo', 'bar'][0]) Foo"));
assert.equal('<div style="bar">Foo</div>', pug.render("div(style= { foo: 'bar', baz: 'raz' }['foo']) Foo"));
assert.equal('<a href="def">Foo</a>', pug.render("a(href='abcdefg'.substr(3,3)) Foo"));
assert.equal('<a href="def">Foo</a>', pug.render("a(href={test: 'abcdefg'}.test.substr(3,3)) Foo"));
assert.equal('<a href="def">Foo</a>', pug.render("a(href={test: 'abcdefg'}.test.substr(3,[0,3][1])) Foo"));
Expand Down