Skip to content

Commit 6fb39e3

Browse files
authored
fix: Better ES6 support for JavaScript Mode
Better ES6 support for JavaScript Mode
2 parents 50044ce + 53427d1 commit 6fb39e3

7 files changed

+778
-51
lines changed

src/ext/static_highlight_test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ module.exports = {
4444
+ "<div class='ace_line'><span class='ace_gutter ace_gutter-cell'></span><span class='ace_comment ace_doc'>*</span>\n</div>"
4545
+ "<div class='ace_line'><span class='ace_gutter ace_gutter-cell'></span><span class='ace_comment ace_doc'>*/</span>\n</div>"
4646
+ "<div class='ace_line'><span class='ace_gutter ace_gutter-cell'></span>\n</div>"
47-
+ "<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>"
47+
+ "<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>"
4848
+ "<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>"
4949
+ "<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>"
5050
+ "<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>"

src/mode/_test/text_javascript.txt

+67-4
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ console.log('\\u1232Feh'
3030
a='
3131
b="\
3232
still a string
33-
34-
33+
34+
3535
function foo(items, nada) {
3636
for (var i=0; i<items.length; i++) {
3737
alert(items[i] + "juhu\n");
@@ -66,7 +66,7 @@ string'
6666
'
6767
string'
6868

69-
"trailing space\
69+
"trailing space\
7070
" " /not a regexp/g
7171

7272
/**
@@ -84,7 +84,7 @@ z>>=t<<f>>r>>>s>=0b1
8484
foo.protoype.d = function(a, b,
8585
c, d)
8686
foo.d =function(a, b)
87-
foo.d =function(a, /*****/ d"string"
87+
foo.d =function(a, /*****/ d"string"
8888

8989
<div
9090
z=<div {...this.props} x={1 + 2} y="z{a}b&amp;" t={
@@ -98,3 +98,66 @@ var o = {
9898
return x
9999
})}`
100100
};
101+
102+
//test generator function
103+
function* range (start, end, step) {
104+
while (start < end) {
105+
yield start
106+
start += step
107+
}
108+
}
109+
//test ES6 new built-in methods
110+
"hello".startsWith("ello", 1) // true
111+
"hello".endsWith("hell", 4) // true
112+
"hello".includes("ell") // true
113+
[ 1, 3, 4, 2 ].find(x => x > 3) // 4
114+
[ 1, 3, 4, 2 ].findIndex(x => x > 3) // 2
115+
"foo".repeat(3)
116+
Number.isSafeInteger(42) === true
117+
118+
let x = Number.MAX_SAFE_INTEGER;
119+
let x = Number.MIN_SAFE_INTEGER;
120+
let x = Number.EPSILON;
121+
//test Promises
122+
new Promise(tetheredGetNumber)
123+
.then(determineParity, troubleWithGetNumber)
124+
.then(promiseGetWord)
125+
.then((info) => {
126+
console.log(`Got: ${info.value}, ${info.wordEvenOdd}`);
127+
return info;
128+
})
129+
.catch((reason) => {
130+
if (reason.cause) {
131+
console.error("Had previously handled error");
132+
} else {
133+
console.error(`Trouble with promiseGetWord(): ${reason}`);
134+
}
135+
})
136+
.finally((info) => console.log("All done"));
137+
//test ES6 arrow functions
138+
param => expression;
139+
140+
(param) => expression;
141+
142+
(param1 = 123, paramN = "test") => expression;
143+
144+
param => {
145+
statements;
146+
};
147+
(param1, paramN) => {
148+
statements
149+
}
150+
151+
(a, b, ...r) => expression;
152+
153+
(a = 400, b = 20, c) => expression;
154+
155+
async param => expression;
156+
157+
//test JSX functions arguments in arrow functions
158+
<Component onclick={(param1, param2 = "Test", ...paramN) => {
159+
console.log("Test")
160+
}}/>
161+
<Component onclick={param1 => {
162+
console.log("Test")
163+
}}/>

src/mode/_test/tokens_ejs.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@
156156
["text"," "],
157157
["identifier","entries"],
158158
["punctuation.operator","."],
159-
["identifier","forEach"],
159+
["support.function","forEach"],
160160
["paren.lparen","("],
161161
["storage.type","function"],
162162
["paren.lparen","("],

0 commit comments

Comments
 (0)