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
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ jobs:
with:
test-rust: true
test-node: true
node-version: 22
test-python: true
test-go: true
test-swift: true
Expand Down
71 changes: 23 additions & 48 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,20 @@
/// <reference types="tree-sitter-cli/dsl" />
// @ts-check

// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Lexical_grammar#reserved_words
const RESERVED_WORDS = [
'break', 'case', 'catch', 'class', 'const', 'continue',
'debugger', 'default', 'delete', 'do', 'else', 'export',
'extends', 'false', 'finally', 'for', 'function', 'if',
'import', 'in', 'instanceof', 'new', 'null', 'return',
'super', 'switch', 'this', 'throw', 'true', 'try',
'typeof', 'var', 'void', 'while', 'with',
];

const CONTEXTUAL_KEYWORDS = [
'get', 'set', 'async', 'await', 'static', 'export', 'let',
];

module.exports = grammar({
name: 'javascript',

Expand All @@ -31,44 +45,7 @@ module.exports = grammar({
],

reserved: {
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Lexical_grammar#reserved_words
global: $ => [
'break',
'case',
'catch',
'class',
'const',
'continue',
'debugger',
'default',
'delete',
'do',
'else',
'export',
'extends',
'false',
'finally',
'for',
'function',
'if',
'import',
'in',
'instanceof',
'new',
'null',
'return',
'super',
'switch',
'this',
'throw',
'true',
'try',
'typeof',
'var',
'void',
'while',
'with',
],
global: $ => RESERVED_WORDS,
properties: $ => [],
},

Expand All @@ -95,6 +72,7 @@ module.exports = grammar({
$._jsx_attribute_value,
$._jsx_identifier,
$._lhs_expression,
$._keyword_identifier,
],

precedences: $ => [
Expand Down Expand Up @@ -886,7 +864,10 @@ module.exports = grammar({
choice('.', field('optional_chain', $.optional_chain)),
field('property', choice(
$.private_property_identifier,
reserved('properties', alias($.identifier, $.property_identifier)),
reserved('properties', alias(
choice($.identifier, $._keyword_identifier),
$.property_identifier,
)),
)),
)),

Expand Down Expand Up @@ -1287,15 +1268,9 @@ module.exports = grammar({
']',
),

_reserved_identifier: _ => choice(
'get',
'set',
'async',
'await',
'static',
'export',
'let',
),
_reserved_identifier: _ => choice(...CONTEXTUAL_KEYWORDS),

_keyword_identifier: _ => choice(...RESERVED_WORDS, ...CONTEXTUAL_KEYWORDS),

_semicolon: $ => choice($._automatic_semicolon, ';'),
},
Expand Down
1 change: 1 addition & 0 deletions package.json

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

189 changes: 186 additions & 3 deletions src/grammar.json

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

Loading