Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/languages/javascript.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ export default {
},
],
'keyword': [
{
pattern:
/(^|[^.]|\.\.\.\s*)\busing(?=\s+(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*\s*(?:=(?!=)|\bof\b))/,
lookbehind: true,
},
{
pattern:
/(^|[^.]|\.\.\.\s*)\b(?:as|assert(?=\s*\{)|export|from(?=\s*(?:['"]|$))|import)\b/,
Expand Down
88 changes: 88 additions & 0 deletions tests/languages/javascript/keyword_feature.test
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,23 @@ async (a,b,c) => {}
import {} from "foo"
import {} from 'foo'
class { get foo(){} set baz(){} get [value](){} }
using file = openFile();
await using conn = getConn();
using x = a, y = b;
for (using x of arr) {}
for (await using y of arr) {}

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

// variables, not keywords

const { async, from, to } = bar;
const using = 1;
obj.using;
using();
using {x} = obj;
import using from "foo";
promise.catch(foo).finally(bar);
assert.equal(foo, bar);

Expand Down Expand Up @@ -199,6 +209,54 @@ assert.equal(foo, bar);
["punctuation", "}"],
["punctuation", "}"],

["keyword", "using"],
" file ",
["operator", "="],
["function", "openFile"],
["punctuation", "("],
["punctuation", ")"],
["punctuation", ";"],

["keyword", "await"],
["keyword", "using"],
" conn ",
["operator", "="],
["function", "getConn"],
["punctuation", "("],
["punctuation", ")"],
["punctuation", ";"],

["keyword", "using"],
" x ",
["operator", "="],
" a",
["punctuation", ","],
" y ",
["operator", "="],
" b",
["punctuation", ";"],

["keyword", "for"],
["punctuation", "("],
["keyword", "using"],
" x ",
["keyword", "of"],
" arr",
["punctuation", ")"],
["punctuation", "{"],
["punctuation", "}"],

["keyword", "for"],
["punctuation", "("],
["keyword", "await"],
["keyword", "using"],
" y ",
["keyword", "of"],
" arr",
["punctuation", ")"],
["punctuation", "{"],
["punctuation", "}"],

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

["keyword", "import"],
Expand Down Expand Up @@ -227,6 +285,36 @@ assert.equal(foo, bar);
" bar",
["punctuation", ";"],

["keyword", "const"],
" using ",
["operator", "="],
["number", "1"],
["punctuation", ";"],

"\r\nobj",
["punctuation", "."],
"using",
["punctuation", ";"],

["function", "using"],
["punctuation", "("],
["punctuation", ")"],
["punctuation", ";"],

"\r\nusing ",
["punctuation", "{"],
"x",
["punctuation", "}"],
["operator", "="],
" obj",
["punctuation", ";"],

["keyword", "import"],
" using ",
["keyword", "from"],
["string", "\"foo\""],
["punctuation", ";"],

"\r\npromise",
["punctuation", "."],
["function", "catch"],
Expand Down
88 changes: 88 additions & 0 deletions tests/languages/typescript/keyword_feature.test
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,20 @@ async (a,b,c) => {}
import {} from "foo"
import {} from 'foo'
class { get foo(){} set baz(){} get [value](){} }
using file = openFile();
await using conn = getConn();
using x = a, y = b;
for (using x of arr) {}
for (await using y of arr) {}

// variables, not keywords

const { async, from, to } = bar;
const using = 1;
obj.using;
using();
using {x} = obj;
import using from "foo";
promise.catch(foo).finally(bar);

// TypeScript keywords
Expand Down Expand Up @@ -220,6 +230,54 @@ import type *, {}
["punctuation", "}"],
["punctuation", "}"],

["keyword", "using"],
" file ",
["operator", "="],
["function", "openFile"],
["punctuation", "("],
["punctuation", ")"],
["punctuation", ";"],

["keyword", "await"],
["keyword", "using"],
" conn ",
["operator", "="],
["function", "getConn"],
["punctuation", "("],
["punctuation", ")"],
["punctuation", ";"],

["keyword", "using"],
" x ",
["operator", "="],
" a",
["punctuation", ","],
" y ",
["operator", "="],
" b",
["punctuation", ";"],

["keyword", "for"],
["punctuation", "("],
["keyword", "using"],
" x ",
["keyword", "of"],
" arr",
["punctuation", ")"],
["punctuation", "{"],
["punctuation", "}"],

["keyword", "for"],
["punctuation", "("],
["keyword", "await"],
["keyword", "using"],
" y ",
["keyword", "of"],
" arr",
["punctuation", ")"],
["punctuation", "{"],
["punctuation", "}"],

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

["keyword", "const"],
Expand All @@ -234,6 +292,36 @@ import type *, {}
" bar",
["punctuation", ";"],

["keyword", "const"],
" using ",
["operator", "="],
["number", "1"],
["punctuation", ";"],

"\r\nobj",
["punctuation", "."],
"using",
["punctuation", ";"],

["function", "using"],
["punctuation", "("],
["punctuation", ")"],
["punctuation", ";"],

"\r\nusing ",
["punctuation", "{"],
"x",
["punctuation", "}"],
["operator", "="],
" obj",
["punctuation", ";"],

["keyword", "import"],
" using ",
["keyword", "from"],
["string", "\"foo\""],
["punctuation", ";"],

"\r\npromise",
["punctuation", "."],
["function", "catch"],
Expand Down