Commit 27ffa5b04a53c3ea0927e43d5ac9efb3a3e056e2

Lea Verou 2012-07-27T03:24:09

Fixed serious highlighting bug, reduced known failures from 3 to 1

diff --git a/components/prism-javascript.js b/components/prism-javascript.js
index ce66820..1cd0d84 100644
--- a/components/prism-javascript.js
+++ b/components/prism-javascript.js
@@ -1,11 +1,14 @@
 Prism.languages.javascript = {
 	'comment': /\/\*[\w\W]*?\*\//g,
+	'line-comment': {
+		pattern: /(^|[^\\])\/\/.*?(\r?\n|$)/g,
+		lookbehind: true
+	},
+	'string': /("|')(\\?.)*?\1/g,
 	'regex': {
 		pattern: /(^|[^/])\/(?!\/)(\[.+?]|\\.|[^/\r\n])+\/[gim]{0,3}/g,
 		lookbehind: true
 	},
-	'line-comment': /\/\/.*?(\r?\n|$)/g,
-	'string': /("|')(\\?.)*?\1/g,
 	'keyword': /\b(var|let|if|else|while|do|for|return|in|instanceof|function|new|with|typeof|try|catch|finally|null|break|continue)\b/g,
 	'boolean': /\b(true|false)\b/g,
 	'number': /\b-?(0x)?\d*\.?\d+\b/g,
diff --git a/components/prism-javascript.min.js b/components/prism-javascript.min.js
index fb169ad..1a0d247 100644
--- a/components/prism-javascript.min.js
+++ b/components/prism-javascript.min.js
@@ -1 +1 @@
-Prism.languages.javascript={comment:/\/\*[\w\W]*?\*\//g,regex:{pattern:/(^|[^/])\/(?!\/)(\[.+?]|\\.|[^/\r\n])+\/[gim]{0,3}/g,lookbehind:!0},"line-comment":/\/\/.*?(\r?\n|$)/g,string:/("|')(\\?.)*?\1/g,keyword:/\b(var|let|if|else|while|do|for|return|in|instanceof|function|new|with|typeof|try|catch|finally|null|break|continue)\b/g,"boolean":/\b(true|false)\b/g,number:/\b-?(0x)?\d*\.?\d+\b/g,operator:/[-+]{1,2}|!|=?<|=?>|={1,2}|(&){1,2}|\|?\||\?|\*|\//g,ignore:/&(lt|gt|amp);/gi,punctuation:/[{}[\];(),.:]/g};
\ No newline at end of file
+Prism.languages.javascript={comment:/\/\*[\w\W]*?\*\//g,"line-comment":{pattern:/(^|[^\\])\/\/.*?(\r?\n|$)/g,lookbehind:!0},string:/("|')(\\?.)*?\1/g,regex:{pattern:/(^|[^/])\/(?!\/)(\[.+?]|\\.|[^/\r\n])+\/[gim]{0,3}/g,lookbehind:!0},keyword:/\b(var|let|if|else|while|do|for|return|in|instanceof|function|new|with|typeof|try|catch|finally|null|break|continue)\b/g,"boolean":/\b(true|false)\b/g,number:/\b-?(0x)?\d*\.?\d+\b/g,operator:/[-+]{1,2}|!|=?<|=?>|={1,2}|(&){1,2}|\|?\||\?|\*|\//g,ignore:/&(lt|gt|amp);/gi,punctuation:/[{}[\];(),.:]/g};
\ No newline at end of file
diff --git a/examples.html b/examples.html
index ca7aa65..309d13c 100644
--- a/examples.html
+++ b/examples.html
@@ -163,6 +163,10 @@ var comment = /\/\*[\w\W]*?\*\//g;</code></pre>
 
 	<h2>Strings with slashes</h2>
 	<pre><code>env.content + '&lt;/' + env.tag + '>'</code></pre>
+	<pre><code>var foo = "/" + "/";</code></pre>
+	
+	<h2>Regex inside single line comment</h2>
+	<pre><code>// hey, /this doesn’t fail!/ :D</code></pre>
 </section>
 
 <section id="failures" class="language-javascript">
@@ -173,14 +177,8 @@ var comment = /\/\*[\w\W]*?\*\//g;</code></pre>
 	If a failure is listed here, it doesn’t mean it will never be fixed. This is more of a “known bugs” list, just with a certain type of bug.
 	</p>
 	
-	<h2>Two strings with slashes on the same line</h2>
-	<pre><code>var foo = "/" + "/";</code></pre>
-	
 	<h2>Comment-like strings</h2>
 	<pre><code>"foo /* bar */ baz"; "foo // bar";</code></pre>
-	
-	<h2>Regex inside single line comment</h2>
-	<pre><code>// hey, /this fails/ :(</code></pre>
 </section>
 
 <footer data-src="templates/footer.html" data-type="text/html"></footer>
diff --git a/prism.js b/prism.js
index d082ec6..512c55c 100644
--- a/prism.js
+++ b/prism.js
@@ -300,12 +300,15 @@ Prism.languages.css = {
 
 Prism.languages.javascript = {
 	'comment': /\/\*[\w\W]*?\*\//g,
+	'line-comment': {
+		pattern: /(^|[^\\])\/\/.*?(\r?\n|$)/g,
+		lookbehind: true
+	},
+	'string': /("|')(\\?.)*?\1/g,
 	'regex': {
 		pattern: /(^|[^/])\/(?!\/)(\[.+?]|\\.|[^/\r\n])+\/[gim]{0,3}/g,
 		lookbehind: true
 	},
-	'line-comment': /\/\/.*?(\r?\n|$)/g,
-	'string': /("|')(\\?.)*?\1/g,
 	'keyword': /\b(var|let|if|else|while|do|for|return|in|instanceof|function|new|with|typeof|try|catch|finally|null|break|continue)\b/g,
 	'boolean': /\b(true|false)\b/g,
 	'number': /\b-?(0x)?\d*\.?\d+\b/g,