Skip to content

Commit 4c20b54

Browse files
authored
Merge pull request #159 from tree-sitter/exports
Extend export syntax, piggybacking on javascript grammar
2 parents d0c7857 + 8e4e2ff commit 4c20b54

File tree

9 files changed

+394434
-389769
lines changed

9 files changed

+394434
-389769
lines changed

common/corpus/declarations.txt

+21-2
Original file line numberDiff line numberDiff line change
@@ -265,15 +265,15 @@ export async function readFile(filename: string): Promise<Buffer>
265265

266266
(program
267267
(export_statement
268-
(function
268+
(function_declaration
269269
(identifier)
270270
(formal_parameters
271271
(required_parameter (identifier) (type_annotation (predefined_type)))
272272
(required_parameter (identifier) (type_annotation (predefined_type))))
273273
(statement_block
274274
(return_statement (object (shorthand_property_identifier) (shorthand_property_identifier))))))
275275
(comment)
276-
(export_statement (class (type_identifier) (class_body)))
276+
(export_statement (class_declaration (type_identifier) (class_body)))
277277
(export_statement (function_signature
278278
(identifier)
279279
(formal_parameters (required_parameter (identifier) (type_annotation (predefined_type))))
@@ -858,3 +858,22 @@ let a!: b;
858858
(identifier)
859859
(type_annotation
860860
(type_identifier)))))
861+
862+
====================================
863+
Top-level exports
864+
====================================
865+
866+
export default abstract class C { }
867+
export default class C { }
868+
export class C { }
869+
export default interface I { }
870+
export interface I { }
871+
872+
---
873+
874+
(program
875+
(export_statement (abstract_class_declaration (type_identifier) (class_body)))
876+
(export_statement (class_declaration (type_identifier) (class_body)))
877+
(export_statement (class_declaration (type_identifier) (class_body)))
878+
(export_statement (interface_declaration (type_identifier) (object_type)))
879+
(export_statement (interface_declaration (type_identifier) (object_type))))

common/define-grammar.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -255,8 +255,7 @@ module.exports = function defineGrammar(dialect) {
255255
previous,
256256
seq('export', 'type', $.export_clause),
257257
seq('export', '=', $.identifier, $._semicolon),
258-
seq('export', 'as', 'namespace', $.identifier, $._semicolon),
259-
seq('export', 'default', $.function_signature)
258+
seq('export', 'as', 'namespace', $.identifier, $._semicolon)
260259
),
261260

262261
non_null_expression: $ => prec.left('unary', seq(

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"main": "./bindings/node",
1616
"devDependencies": {
1717
"tree-sitter-cli": "^0.19.1",
18-
"tree-sitter-javascript": "github:tree-sitter/tree-sitter-javascript#v0.19.0"
18+
"tree-sitter-javascript": "github:tree-sitter/tree-sitter-javascript#40a1427"
1919
},
2020
"scripts": {
2121
"build": "npm run build-typescript && npm run build-tsx",

tsx/src/grammar.json

+28-27
Original file line numberDiff line numberDiff line change
@@ -134,16 +134,34 @@
134134
"value": "default"
135135
},
136136
{
137-
"type": "FIELD",
138-
"name": "value",
139-
"content": {
140-
"type": "SYMBOL",
141-
"name": "expression"
142-
}
143-
},
144-
{
145-
"type": "SYMBOL",
146-
"name": "_semicolon"
137+
"type": "CHOICE",
138+
"members": [
139+
{
140+
"type": "FIELD",
141+
"name": "declaration",
142+
"content": {
143+
"type": "SYMBOL",
144+
"name": "declaration"
145+
}
146+
},
147+
{
148+
"type": "SEQ",
149+
"members": [
150+
{
151+
"type": "FIELD",
152+
"name": "value",
153+
"content": {
154+
"type": "SYMBOL",
155+
"name": "expression"
156+
}
157+
},
158+
{
159+
"type": "SYMBOL",
160+
"name": "_semicolon"
161+
}
162+
]
163+
}
164+
]
147165
}
148166
]
149167
}
@@ -215,23 +233,6 @@
215233
"name": "_semicolon"
216234
}
217235
]
218-
},
219-
{
220-
"type": "SEQ",
221-
"members": [
222-
{
223-
"type": "STRING",
224-
"value": "export"
225-
},
226-
{
227-
"type": "STRING",
228-
"value": "default"
229-
},
230-
{
231-
"type": "SYMBOL",
232-
"name": "function_signature"
233-
}
234-
]
235236
}
236237
]
237238
},

tsx/src/node-types.json

-4
Original file line numberDiff line numberDiff line change
@@ -1969,10 +1969,6 @@
19691969
"type": "export_clause",
19701970
"named": true
19711971
},
1972-
{
1973-
"type": "function_signature",
1974-
"named": true
1975-
},
19761972
{
19771973
"type": "identifier",
19781974
"named": true

0 commit comments

Comments
 (0)