Skip to content

Commit

Permalink
JS: Added support for import assertions (#2953)
Browse files Browse the repository at this point in the history
  • Loading branch information
RunDevelopment authored Jun 16, 2021
1 parent ac1d12f commit ab7c995
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 3 deletions.
2 changes: 1 addition & 1 deletion components/prism-javascript.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Prism.languages.javascript = Prism.languages.extend('clike', {
lookbehind: true
},
{
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/,
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/,
lookbehind: true
},
],
Expand Down
2 changes: 1 addition & 1 deletion components/prism-javascript.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion prism.js
Original file line number Diff line number Diff line change
Expand Up @@ -1531,7 +1531,7 @@ Prism.languages.javascript = Prism.languages.extend('clike', {
lookbehind: true
},
{
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/,
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/,
lookbehind: true
},
],
Expand Down
28 changes: 28 additions & 0 deletions tests/languages/javascript/keyword_feature.test
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,14 @@ import {} from "foo"
import {} from 'foo'
class { get foo(){} set baz(){} get [value](){} }

// import assertion
import json from "./foo.json" assert { type: "json" };

// variables, not keywords

const { async, from, to } = bar;
promise.catch(foo).finally(bar);
assert.equal(foo, bar);

----------------------------------------------------

Expand Down Expand Up @@ -195,6 +199,20 @@ promise.catch(foo).finally(bar);
["punctuation", "}"],
["punctuation", "}"],

["comment", "// import assertion"],

["keyword", "import"],
" json ",
["keyword", "from"],
["string", "\"./foo.json\""],
["keyword", "assert"],
["punctuation", "{"],
" type",
["operator", ":"],
["string", "\"json\""],
["punctuation", "}"],
["punctuation", ";"],

["comment", "// variables, not keywords"],

["keyword", "const"],
Expand All @@ -220,6 +238,16 @@ promise.catch(foo).finally(bar);
["punctuation", "("],
"bar",
["punctuation", ")"],
["punctuation", ";"],

"\r\nassert",
["punctuation", "."],
["function", "equal"],
["punctuation", "("],
"foo",
["punctuation", ","],
" bar",
["punctuation", ")"],
["punctuation", ";"]
]

Expand Down

0 comments on commit ab7c995

Please sign in to comment.