Skip to content

Commit b5d92b6

Browse files
kl0tlerikd
authored andcommitted
Add support for function declarations export statements
1 parent 623e6d0 commit b5d92b6

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

src/Language/JavaScript/Parser/Grammar7.y

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1262,6 +1262,15 @@ ImportSpecifier : IdentifierName
12621262
-- [x] export ExportClause ;
12631263
-- [x] export VariableStatement
12641264
-- [ ] export Declaration
1265+
-- [ ] Declaration :
1266+
-- [ ] HoistableDeclaration
1267+
-- [ ] ClassDeclaration
1268+
-- [x] LexicalDeclaration
1269+
-- [ ] HoistableDeclaration :
1270+
-- [x] FunctionDeclaration
1271+
-- [ ] GeneratorDeclaration
1272+
-- [ ] AsyncFunctionDeclaration
1273+
-- [ ] AsyncGeneratorDeclaration
12651274
-- [ ] export default HoistableDeclaration[Default]
12661275
-- [ ] export default ClassDeclaration[Default]
12671276
-- [ ] export default [lookahead ∉ { function, class }] AssignmentExpression[In] ;
@@ -1270,6 +1279,8 @@ ExportDeclaration : ExportClause AutoSemi
12701279
{ $1 {- 'ExportDeclaration1' -} }
12711280
| VariableStatement AutoSemi
12721281
{ AST.JSExport $1 $2 {- 'ExportDeclaration2' -} }
1282+
| FunctionDeclaration AutoSemi
1283+
{ AST.JSExport $1 $2 {- 'ExportDeclaration2' -} }
12731284

12741285
-- ExportClause :
12751286
-- { }

test/Test/Language/Javascript/ModuleParser.hs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ testModuleParser = describe "Parse modules:" $ do
4747
test "export const a = 1;"
4848
`shouldBe`
4949
"Right (JSAstModule [JSModuleExportDeclaration (JSExport (JSConstant (JSVarInitExpression (JSIdentifier 'a') [JSDecimal '1'])))])"
50+
test "export function f() {};"
51+
`shouldBe`
52+
"Right (JSAstModule [JSModuleExportDeclaration (JSExport (JSFunction 'f' () (JSBlock [])))])"
5053
test "export { a };"
5154
`shouldBe`
5255
"Right (JSAstModule [JSModuleExportDeclaration (JSExportLocals ((JSExportLocalSpecifier (JSIdentifier 'a'))))])"

0 commit comments

Comments
 (0)