Skip to content

Commit ab7c995

Browse files
JS: Added support for import assertions (#2953)
1 parent ac1d12f commit ab7c995

File tree

4 files changed

+31
-3
lines changed

4 files changed

+31
-3
lines changed

components/prism-javascript.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Prism.languages.javascript = Prism.languages.extend('clike', {
1212
lookbehind: true
1313
},
1414
{
15-
pattern: /(^|[^.]|\.\.\.\s*)\b(?:as|async(?=\s*(?:function\b|\(|[$\w\xA0-\uFFFF]|$))|await|break|case|class|const|continue|debugger|default|delete|do|else|enum|export|extends|finally(?=\s*(?:\{|$))|for|from(?=\s*(?:['"]|$))|function|(?:get|set)(?=\s*(?:[#\[$\w\xA0-\uFFFF]|$))|if|implements|import|in|instanceof|interface|let|new|null|of|package|private|protected|public|return|static|super|switch|this|throw|try|typeof|undefined|var|void|while|with|yield)\b/,
15+
pattern: /(^|[^.]|\.\.\.\s*)\b(?:as|assert(?=\s*\{)|async(?=\s*(?:function\b|\(|[$\w\xA0-\uFFFF]|$))|await|break|case|class|const|continue|debugger|default|delete|do|else|enum|export|extends|finally(?=\s*(?:\{|$))|for|from(?=\s*(?:['"]|$))|function|(?:get|set)(?=\s*(?:[#\[$\w\xA0-\uFFFF]|$))|if|implements|import|in|instanceof|interface|let|new|null|of|package|private|protected|public|return|static|super|switch|this|throw|try|typeof|undefined|var|void|while|with|yield)\b/,
1616
lookbehind: true
1717
},
1818
],

components/prism-javascript.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

prism.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1531,7 +1531,7 @@ Prism.languages.javascript = Prism.languages.extend('clike', {
15311531
lookbehind: true
15321532
},
15331533
{
1534-
pattern: /(^|[^.]|\.\.\.\s*)\b(?:as|async(?=\s*(?:function\b|\(|[$\w\xA0-\uFFFF]|$))|await|break|case|class|const|continue|debugger|default|delete|do|else|enum|export|extends|finally(?=\s*(?:\{|$))|for|from(?=\s*(?:['"]|$))|function|(?:get|set)(?=\s*(?:[#\[$\w\xA0-\uFFFF]|$))|if|implements|import|in|instanceof|interface|let|new|null|of|package|private|protected|public|return|static|super|switch|this|throw|try|typeof|undefined|var|void|while|with|yield)\b/,
1534+
pattern: /(^|[^.]|\.\.\.\s*)\b(?:as|assert(?=\s*\{)|async(?=\s*(?:function\b|\(|[$\w\xA0-\uFFFF]|$))|await|break|case|class|const|continue|debugger|default|delete|do|else|enum|export|extends|finally(?=\s*(?:\{|$))|for|from(?=\s*(?:['"]|$))|function|(?:get|set)(?=\s*(?:[#\[$\w\xA0-\uFFFF]|$))|if|implements|import|in|instanceof|interface|let|new|null|of|package|private|protected|public|return|static|super|switch|this|throw|try|typeof|undefined|var|void|while|with|yield)\b/,
15351535
lookbehind: true
15361536
},
15371537
],

tests/languages/javascript/keyword_feature.test

+28
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,14 @@ import {} from "foo"
5454
import {} from 'foo'
5555
class { get foo(){} set baz(){} get [value](){} }
5656

57+
// import assertion
58+
import json from "./foo.json" assert { type: "json" };
59+
5760
// variables, not keywords
5861

5962
const { async, from, to } = bar;
6063
promise.catch(foo).finally(bar);
64+
assert.equal(foo, bar);
6165

6266
----------------------------------------------------
6367

@@ -195,6 +199,20 @@ promise.catch(foo).finally(bar);
195199
["punctuation", "}"],
196200
["punctuation", "}"],
197201

202+
["comment", "// import assertion"],
203+
204+
["keyword", "import"],
205+
" json ",
206+
["keyword", "from"],
207+
["string", "\"./foo.json\""],
208+
["keyword", "assert"],
209+
["punctuation", "{"],
210+
" type",
211+
["operator", ":"],
212+
["string", "\"json\""],
213+
["punctuation", "}"],
214+
["punctuation", ";"],
215+
198216
["comment", "// variables, not keywords"],
199217

200218
["keyword", "const"],
@@ -220,6 +238,16 @@ promise.catch(foo).finally(bar);
220238
["punctuation", "("],
221239
"bar",
222240
["punctuation", ")"],
241+
["punctuation", ";"],
242+
243+
"\r\nassert",
244+
["punctuation", "."],
245+
["function", "equal"],
246+
["punctuation", "("],
247+
"foo",
248+
["punctuation", ","],
249+
" bar",
250+
["punctuation", ")"],
223251
["punctuation", ";"]
224252
]
225253

0 commit comments

Comments
 (0)