Skip to content

Commit

Permalink
ECMAScript 6 modules import now do not require closing semicolon, fixes
Browse files Browse the repository at this point in the history
#958

# Conflicts:
#	CHANGES.md
  • Loading branch information
Sannis committed Oct 20, 2015
1 parent 628a921 commit 4decafa
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 11 deletions.
5 changes: 5 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
## MASTER (UNRELEASED)

Notable fixes and improvements to existing languages:

- ECMAScript 6 modules import now do not require closing semicolon
- ECMAScript 6 classes constructors now highlighted

Other notable changes:

- License added to not minified browser build
Expand Down
18 changes: 8 additions & 10 deletions src/languages/javascript.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ function(hljs) {
keyword:
'in of if for while finally var new function do return void else break catch ' +
'instanceof with throw case default try this switch continue typeof delete ' +
'let yield const export super debugger as async await',
'let yield const export super debugger as async await ' +
// ECMAScript 6 modules import
'import from as'
,
literal:
'true false null undefined NaN Infinity',
built_in:
Expand Down Expand Up @@ -92,15 +95,6 @@ function(hljs) {
{
begin: '\\.' + hljs.IDENT_RE, relevance: 0 // hack: prevents detection of keywords after dots
},
// ECMAScript 6 modules import
{
beginKeywords: 'import', end: '[;$]',
keywords: 'import from as',
contains: [
hljs.APOS_STRING_MODE,
hljs.QUOTE_STRING_MODE
]
},
{ // ES6 class
className: 'class',
beginKeywords: 'class', end: /[{;=]/, excludeEnd: true,
Expand All @@ -109,6 +103,10 @@ function(hljs) {
{beginKeywords: 'extends'},
hljs.UNDERSCORE_TITLE_MODE
]
},
{
beginKeywords: 'constructor', end: /\{/, excludeEnd: true,
relevance: 10
}
],
illegal: /#/
Expand Down
1 change: 0 additions & 1 deletion src/languages/typescript.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ function(hljs) {
relevance: 0 // () => {} is more typical in TypeScript
},
{
className: 'constructor',
beginKeywords: 'constructor', end: /\{/, excludeEnd: true,
relevance: 10
},
Expand Down
11 changes: 11 additions & 0 deletions test/markup/javascript/class.expect.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Car</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Vehicle</span> </span>{
<span class="hljs-keyword">constructor</span>(speed, cost) {
<span class="hljs-keyword">super</span>(speed);

<span class="hljs-keyword">var</span> c = <span class="hljs-built_in">Symbol</span>(<span class="hljs-string">'cost'</span>);
<span class="hljs-keyword">this</span>[c] = cost;

<span class="hljs-keyword">this</span>.intro = <span class="hljs-string">`This is a car runs at
<span class="hljs-subst">${speed}</span>.`</span>;
}
}
11 changes: 11 additions & 0 deletions test/markup/javascript/class.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class Car extends Vehicle {
constructor(speed, cost) {
super(speed);

var c = Symbol('cost');
this[c] = cost;

this.intro = `This is a car runs at
${speed}.`;
}
}
11 changes: 11 additions & 0 deletions test/markup/typescript/class.expect.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<span class="hljs-keyword">class</span> Car extends Vehicle {
<span class="hljs-keyword">constructor</span>(speed, cost) {
<span class="hljs-keyword">super</span>(speed);

<span class="hljs-keyword">var</span> c = Symbol(<span class="hljs-string">'cost'</span>);
<span class="hljs-keyword">this</span>[c] = cost;

<span class="hljs-keyword">this</span>.intro = `This is a car runs at
${speed}.`;
}
}
11 changes: 11 additions & 0 deletions test/markup/typescript/class.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class Car extends Vehicle {
constructor(speed, cost) {
super(speed);

var c = Symbol('cost');
this[c] = cost;

this.intro = `This is a car runs at
${speed}.`;
}
}

0 comments on commit 4decafa

Please sign in to comment.