Skip to content

Commit

Permalink
fix: Better ES6 support for JavaScript Mode
Browse files Browse the repository at this point in the history
Better ES6 support for JavaScript Mode
  • Loading branch information
andrewnester authored Nov 16, 2022
2 parents 50044ce + 53427d1 commit 6fb39e3
Show file tree
Hide file tree
Showing 7 changed files with 778 additions and 51 deletions.
2 changes: 1 addition & 1 deletion src/ext/static_highlight_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ module.exports = {
+ "<div class='ace_line'><span class='ace_gutter ace_gutter-cell'></span><span class='ace_comment ace_doc'>*</span>\n</div>"
+ "<div class='ace_line'><span class='ace_gutter ace_gutter-cell'></span><span class='ace_comment ace_doc'>*/</span>\n</div>"
+ "<div class='ace_line'><span class='ace_gutter ace_gutter-cell'></span>\n</div>"
+ "<div class='ace_line'><span class='ace_gutter ace_gutter-cell'></span><span class='ace_storage ace_type'>function</span><span> </span><span class='ace_entity ace_name ace_function'>hello</span><span> </span><span class='ace_paren ace_lparen'>(</span><span class='ace_variable ace_parameter'>a</span><span class='ace_punctuation ace_operator'>, </span><span class='ace_variable ace_parameter'>b</span><span class='ace_punctuation ace_operator'>, </span><span class='ace_variable ace_parameter'>c</span><span class='ace_paren ace_rparen'>)</span><span> </span><span class='ace_paren ace_lparen'>{</span>\n</div>"
+ "<div class='ace_line'><span class='ace_gutter ace_gutter-cell'></span><span class='ace_storage ace_type'>function</span><span> </span><span class='ace_entity ace_name ace_function'>hello</span><span> </span><span class='ace_paren ace_lparen'>(</span><span class='ace_variable ace_parameter'>a</span><span class='ace_punctuation ace_operator'>,</span><span> </span><span class='ace_variable ace_parameter'>b</span><span class='ace_punctuation ace_operator'>,</span><span> </span><span class='ace_variable ace_parameter'>c</span><span class='ace_paren ace_rparen'>)</span><span> </span><span class='ace_paren ace_lparen'>{</span>\n</div>"
+ "<div class='ace_line'><span class='ace_gutter ace_gutter-cell'></span><span> </span><span class='ace_storage ace_type'>console</span><span class='ace_punctuation ace_operator'>.</span><span class='ace_support ace_function ace_firebug'>log</span><span class='ace_paren ace_lparen'>(</span><span class='ace_identifier'>a</span><span> </span><span class='ace_keyword ace_operator'>*</span><span> </span><span class='ace_identifier'>b</span><span> </span><span class='ace_keyword ace_operator'>+</span><span> </span><span class='ace_identifier'>c</span><span> </span><span class='ace_keyword ace_operator'>+</span><span> </span><span class='ace_string'>&#39;sup$&#39;</span><span class='ace_paren ace_rparen'>)</span><span class='ace_punctuation ace_operator'>;</span>\n</div>"
+ "<div class='ace_line'><span class='ace_gutter ace_gutter-cell'></span><span class='ace_indent-guide'> </span><span class='ace_indent-guide'> </span><span> </span><span class='ace_comment'>//</span>\n</div>"
+ "<div class='ace_line'><span class='ace_gutter ace_gutter-cell'></span><span class='ace_indent-guide'> </span><span class='ace_indent-guide'> </span><span> </span><span class='ace_comment'>//</span>\n</div>"
Expand Down
71 changes: 67 additions & 4 deletions src/mode/_test/text_javascript.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ console.log('\\u1232Feh'
a='
b="\
still a string


function foo(items, nada) {
for (var i=0; i<items.length; i++) {
alert(items[i] + "juhu\n");
Expand Down Expand Up @@ -66,7 +66,7 @@ string'
'
string'

"trailing space\
"trailing space\
" " /not a regexp/g

/**
Expand All @@ -84,7 +84,7 @@ z>>=t<<f>>r>>>s>=0b1
foo.protoype.d = function(a, b,
c, d)
foo.d =function(a, b)
foo.d =function(a, /*****/ d"string"
foo.d =function(a, /*****/ d"string"

<div
z=<div {...this.props} x={1 + 2} y="z{a}b&amp;" t={
Expand All @@ -98,3 +98,66 @@ var o = {
return x
})}`
};

//test generator function
function* range (start, end, step) {
while (start < end) {
yield start
start += step
}
}
//test ES6 new built-in methods
"hello".startsWith("ello", 1) // true
"hello".endsWith("hell", 4) // true
"hello".includes("ell") // true
[ 1, 3, 4, 2 ].find(x => x > 3) // 4
[ 1, 3, 4, 2 ].findIndex(x => x > 3) // 2
"foo".repeat(3)
Number.isSafeInteger(42) === true

let x = Number.MAX_SAFE_INTEGER;
let x = Number.MIN_SAFE_INTEGER;
let x = Number.EPSILON;
//test Promises
new Promise(tetheredGetNumber)
.then(determineParity, troubleWithGetNumber)
.then(promiseGetWord)
.then((info) => {
console.log(`Got: ${info.value}, ${info.wordEvenOdd}`);
return info;
})
.catch((reason) => {
if (reason.cause) {
console.error("Had previously handled error");
} else {
console.error(`Trouble with promiseGetWord(): ${reason}`);
}
})
.finally((info) => console.log("All done"));
//test ES6 arrow functions
param => expression;

(param) => expression;

(param1 = 123, paramN = "test") => expression;

param => {
statements;
};
(param1, paramN) => {
statements
}

(a, b, ...r) => expression;

(a = 400, b = 20, c) => expression;

async param => expression;

//test JSX functions arguments in arrow functions
<Component onclick={(param1, param2 = "Test", ...paramN) => {
console.log("Test")
}}/>
<Component onclick={param1 => {
console.log("Test")
}}/>
2 changes: 1 addition & 1 deletion src/mode/_test/tokens_ejs.json
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@
["text"," "],
["identifier","entries"],
["punctuation.operator","."],
["identifier","forEach"],
["support.function","forEach"],
["paren.lparen","("],
["storage.type","function"],
["paren.lparen","("],
Expand Down
Loading

0 comments on commit 6fb39e3

Please sign in to comment.