Skip to content

Commit

Permalink
Merge pull request #1270 from visionmedia/remove/!!!
Browse files Browse the repository at this point in the history
Remove !!!
  • Loading branch information
ForbesLindesay committed Nov 11, 2013
2 parents af6e52b + 7b34782 commit fb4a7f1
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 13 deletions.
3 changes: 3 additions & 0 deletions lib/compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ Compiler.prototype = {

setDoctype: function(name){
name = name || 'default';
if (name.toLowerCase() === '5') {
throw new Error('`doctype 5` is deprecated, you must now use `doctype html`');
}
this.doctype = doctypes[name.toLowerCase()] || '<!DOCTYPE ' + name + '>';
this.terse = this.doctype.toLowerCase() == '<!doctype html>';
this.xml = 0 == this.doctype.indexOf('<?xml');
Expand Down
3 changes: 1 addition & 2 deletions lib/doctypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
*/

module.exports = {
'5': '<!DOCTYPE html>'
, 'default': '<!DOCTYPE html>'
'default': '<!DOCTYPE html>'
, 'xml': '<?xml version="1.0" encoding="utf-8" ?>'
, 'transitional': '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'
, 'strict': '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">'
Expand Down
5 changes: 4 additions & 1 deletion lib/lexer.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,10 @@ Lexer.prototype = {
*/

doctype: function() {
return this.scan(/^(?:!!!|doctype) *([^\n]+)?/, 'doctype');
if (this.scan(/^!!! *([^\n]+)?/, 'doctype')) {
throw new Error('`!!!` is deprecated, you must now use `doctype`');
}
return this.scan(/^(?:doctype) *([^\n]+)?/, 'doctype');
},

/**
Expand Down
2 changes: 1 addition & 1 deletion test/cases/doctype.default.jade
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
!!!
doctype
html
body
h1 Title
2 changes: 1 addition & 1 deletion test/cases/escape-test.jade
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
!!! 5
doctype html
html
head
title escape-test
Expand Down
2 changes: 1 addition & 1 deletion test/cases/html5.jade
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
doctype 5
doctype html
input(type='checkbox', checked)
input(type='checkbox', checked=true)
input(type='checkbox', checked=false)
12 changes: 12 additions & 0 deletions test/error.reporting.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,16 @@ describe('error reporting', function () {
});
});
});
describe('deprecated features', function () {
it('deprecates `!!!` in favour of `doctype`', function () {
var err = getError('!!! 5', {filename: 'test.jade'})
assert(/test\.jade:1/.test(err.message))
assert(/`!!!` is deprecated, you must now use `doctype`/.test(err.message))
});
it('deprecates `doctype 5` in favour of `doctype html`', function () {
var err = getError('doctype 5', {filename: 'test.jade'})
assert(/test\.jade:1/.test(err.message))
assert(/`doctype 5` is deprecated, you must now use `doctype html`/.test(err.message))
});
});
});
14 changes: 7 additions & 7 deletions test/jade.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ describe('jade', function(){

describe('.compile()', function(){
it('should support doctypes', function(){
assert.equal('<?xml version="1.0" encoding="utf-8" ?>', jade.render('!!! xml'));
assert.equal('<?xml version="1.0" encoding="utf-8" ?>', jade.render('doctype xml'));
assert.equal('<!DOCTYPE html>', jade.render('doctype html'));
assert.equal('<!DOCTYPE foo bar baz>', jade.render('doctype foo bar baz'));
assert.equal('<!DOCTYPE html>', jade.render('!!! 5'));
assert.equal('<!DOCTYPE html>', jade.render('!!!', { doctype:'html' }));
assert.equal('<!DOCTYPE html>', jade.render('!!! html', { doctype:'xml' }));
assert.equal('<!DOCTYPE html>', jade.render('doctype html'));
assert.equal('<!DOCTYPE html>', jade.render('doctype', { doctype:'html' }));
assert.equal('<!DOCTYPE html>', jade.render('doctype html', { doctype:'xml' }));
assert.equal('<html></html>', jade.render('html'));
assert.equal('<!DOCTYPE html><html></html>', jade.render('html', { doctype:'html' }));
assert.equal('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML Basic 1.1//EN>', jade.render('doctype html PUBLIC "-//W3C//DTD XHTML Basic 1.1//EN'));
Expand Down Expand Up @@ -349,9 +349,9 @@ describe('jade', function(){
});

it('should support test html 5 mode', function(){
assert.equal('<!DOCTYPE html><input type="checkbox" checked>', jade.render('!!! 5\ninput(type="checkbox", checked)'));
assert.equal('<!DOCTYPE html><input type="checkbox" checked>', jade.render('!!! 5\ninput(type="checkbox", checked=true)'));
assert.equal('<!DOCTYPE html><input type="checkbox">', jade.render('!!! 5\ninput(type="checkbox", checked= false)'));
assert.equal('<!DOCTYPE html><input type="checkbox" checked>', jade.render('doctype html\ninput(type="checkbox", checked)'));
assert.equal('<!DOCTYPE html><input type="checkbox" checked>', jade.render('doctype html\ninput(type="checkbox", checked=true)'));
assert.equal('<!DOCTYPE html><input type="checkbox">', jade.render('doctype html\ninput(type="checkbox", checked= false)'));
});

it('should support multi-line attrs', function(){
Expand Down

0 comments on commit fb4a7f1

Please sign in to comment.