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

Support more of the export syntax #125

Closed
wants to merge 2 commits into from
Closed
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
19 changes: 19 additions & 0 deletions common/corpus/declarations.txt
Original file line number Diff line number Diff line change
Expand Up @@ -832,3 +832,22 @@ let a!: b;
(identifier)
(type_annotation
(type_identifier)))))

====================================
Top-level exports
====================================

export default abstract class C { }
export default class C { }
export class C { }
export default interface I { }
export interface I { }

---

(program
(export_statement (class (type_identifier) (class_body)))
(export_statement (class (type_identifier) (class_body)))
(export_statement (class_declaration (type_identifier) (class_body)))
(export_statement (interface_declaration (type_identifier) (object_type)))
(export_statement (interface_declaration (type_identifier) (object_type))))
9 changes: 8 additions & 1 deletion common/define-grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,14 @@ module.exports = function defineGrammar(dialect) {
previous,
seq('export', '=', $.identifier, $._semicolon),
seq('export', 'as', 'namespace', $.identifier, $._semicolon),
seq('export', 'default', $.function_signature)
seq('export', 'default', $.function_signature),
seq(
'export', 'default',
choice(
seq(optional("abstract"), $.class),
$.interface_declaration
)
)
),

non_null_expression: $ => prec.left('unary', seq(
Expand Down
43 changes: 43 additions & 0 deletions tsx/src/grammar.json
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,49 @@
"name": "function_signature"
}
]
},
{
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "export"
},
{
"type": "STRING",
"value": "default"
},
{
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "abstract"
},
{
"type": "BLANK"
}
]
},
{
"type": "SYMBOL",
"name": "class"
}
]
},
{
"type": "SYMBOL",
"name": "interface_declaration"
}
]
}
]
}
]
},
Expand Down
12 changes: 10 additions & 2 deletions tsx/src/node-types.json
Original file line number Diff line number Diff line change
Expand Up @@ -1955,6 +1955,10 @@
"multiple": false,
"required": false,
"types": [
{
"type": "class",
"named": true
},
{
"type": "export_clause",
"named": true
Expand All @@ -1966,6 +1970,10 @@
{
"type": "identifier",
"named": true
},
{
"type": "interface_declaration",
"named": true
}
]
}
Expand Down Expand Up @@ -5852,11 +5860,11 @@
},
{
"type": "number",
"named": true
"named": false
},
{
"type": "number",
"named": false
"named": true
},
{
"type": "of",
Expand Down
Loading