Browse files

Support `<!--` comment syntax

  • Loading branch information...
1 parent e476ca2 commit 38b068d55c3e2160479afeeddf5afa2d30ba6c2e @mathiasbynens mathiasbynens committed Sep 5, 2013
Showing with 45 additions and 0 deletions.
  1. +11 −0 esprima.js
  2. +34 −0 test/test.js
View
11 esprima.js
@@ -1,6 +1,7 @@
/*
Copyright (C) 2013 Ariya Hidayat <ariya.hidayat@gmail.com>
Copyright (C) 2013 Thaddee Tyl <thaddee.tyl@gmail.com>
+ Copyright (C) 2013 Mathias Bynens <mathias@qiwi.be>
Copyright (C) 2012 Ariya Hidayat <ariya.hidayat@gmail.com>
Copyright (C) 2012 Mathias Bynens <mathias@qiwi.be>
Copyright (C) 2012 Joost-Wim Boekesteijn <joost-wim@boekesteijn.nl>
@@ -484,6 +485,16 @@ parseStatement: true, parseSourceElement: true */
} else {
break;
}
+ } else if (ch === 60) { // 60 is '<'
+ if (source.slice(index + 1, index + 4) === '!--') {
+ ++index; // `<`
+ ++index; // `!`
+ ++index; // `-`
+ ++index; // `-`
+ skipSingleLineComment();
+ } else {
+ break;
+ }
} else {
break;
}
View
34 test/test.js
@@ -1,4 +1,5 @@
/*
+ Copyright (C) 2013 Mathias Bynens <mathias@qiwi.be>
Copyright (C) 2012 Ariya Hidayat <ariya.hidayat@gmail.com>
Copyright (C) 2012 Joost-Wim Boekesteijn <joost-wim@boekesteijn.nl>
Copyright (C) 2012 Yusuke Suzuki <utatane.tea@gmail.com>
@@ -22790,6 +22791,39 @@ var testFixture = {
column: 7,
message: 'Error: Line 1: Invalid left-hand side in for-in'
}]
+ },
+
+ '<!-- foo': {
+ type: 'Program',
+ body: [],
+ comments: [{
+ type: 'Line',
+ value: ' foo'
+ }]
+ },
+
+ 'var x = 1<!--foo': {
+ type: 'Program',
+ body: [{
+ type: 'VariableDeclaration',
+ declarations: [{
+ type: 'VariableDeclarator',
+ id: {
+ type: 'Identifier',
+ name: 'x'
+ },
+ init: {
+ type: 'Literal',
+ value: 1,
+ raw: '1'
+ }
+ }],
+ kind: 'var'
+ }],
+ comments: [{
+ type: 'Line',
+ value: 'foo'
+ }]
}

0 comments on commit 38b068d

Please sign in to comment.