Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow global declarations in modules #302

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
6 changes: 6 additions & 0 deletions common/define-grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@
$.satisfies_expression,
$.instantiation_expression,
$.internal_module,
$.global_namespace,
];

if (dialect === 'typescript') {
Expand Down Expand Up @@ -265,6 +266,11 @@
previous,
),

global_namespace: ($) => seq(
'global',
field('body', $.statement_block)

Check failure on line 271 in common/define-grammar.js

View workflow job for this annotation

GitHub Actions / lint

Missing trailing comma
),

_import_identifier: ($) => choice($.identifier, alias('type', $.identifier)),

import_specifier: ($) => seq(
Expand Down
21 changes: 21 additions & 0 deletions test/corpus/declarations.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1114,6 +1114,27 @@ declare global {
(ambient_declaration
(statement_block)))

=======================================
Ambient global namespace declarations
=======================================

declare module "foo" {
global {
}
}

---

(program
(ambient_declaration
(module
(string
(string_fragment))
(statement_block
(expression_statement
(global_namespace
(statement_block)))))))

=======================================
Abstract classes
=======================================
Expand Down
32 changes: 31 additions & 1 deletion tsx/src/grammar.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
{
"0": "j",
"1": "a",
"2": "v",
"3": "a",
"4": "s",
"5": "c",
"6": "r",
"7": "i",
"8": "p",
"9": "t",
"name": "tsx",
"inherits": "javascript",
"word": "identifier",
"rules": {
"program": {
Expand Down Expand Up @@ -2006,6 +2015,10 @@
"type": "SYMBOL",
"name": "internal_module"
},
{
"type": "SYMBOL",
"name": "global_namespace"
},
{
"type": "SYMBOL",
"name": "primary_expression"
Expand Down Expand Up @@ -7553,6 +7566,23 @@
}
]
},
"global_namespace": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "global"
},
{
"type": "FIELD",
"name": "body",
"content": {
"type": "SYMBOL",
"name": "statement_block"
}
}
]
},
"_import_identifier": {
"type": "CHOICE",
"members": [
Expand Down
24 changes: 22 additions & 2 deletions tsx/src/node-types.json
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,10 @@
"type": "glimmer_template",
"named": true
},
{
"type": "global_namespace",
"named": true
},
{
"type": "instantiation_expression",
"named": true
Expand Down Expand Up @@ -2888,6 +2892,22 @@
}
}
},
{
"type": "global_namespace",
"named": true,
"fields": {
"body": {
"multiple": false,
"required": true,
"types": [
{
"type": "statement_block",
"named": true
}
]
}
}
},
{
"type": "identifier",
"named": true,
Expand Down Expand Up @@ -6554,11 +6574,11 @@
},
{
"type": "number",
"named": false
"named": true
},
{
"type": "number",
"named": true
"named": false
},
{
"type": "object",
Expand Down
Loading
Loading