diff --git a/src/Language/JavaScript/Parser/Grammar7.y b/src/Language/JavaScript/Parser/Grammar7.y index 1c2217b0..3d02791a 100644 --- a/src/Language/JavaScript/Parser/Grammar7.y +++ b/src/Language/JavaScript/Parser/Grammar7.y @@ -1261,6 +1261,15 @@ ImportSpecifier : IdentifierName -- [x] export ExportClause ; -- [x] export VariableStatement -- [ ] export Declaration +-- [ ] Declaration : +-- [ ] HoistableDeclaration +-- [ ] ClassDeclaration +-- [x] LexicalDeclaration +-- [ ] HoistableDeclaration : +-- [x] FunctionDeclaration +-- [ ] GeneratorDeclaration +-- [ ] AsyncFunctionDeclaration +-- [ ] AsyncGeneratorDeclaration -- [ ] export default HoistableDeclaration[Default] -- [ ] export default ClassDeclaration[Default] -- [ ] export default [lookahead ∉ { function, class }] AssignmentExpression[In] ; @@ -1269,6 +1278,8 @@ ExportDeclaration : ExportClause AutoSemi { $1 {- 'ExportDeclaration1' -} } | VariableStatement AutoSemi { AST.JSExport $1 $2 {- 'ExportDeclaration2' -} } + | FunctionDeclaration AutoSemi + { AST.JSExport $1 $2 {- 'ExportDeclaration2' -} } -- ExportClause : -- { } diff --git a/test/Test/Language/Javascript/ModuleParser.hs b/test/Test/Language/Javascript/ModuleParser.hs index 50e3053c..655aa0cb 100644 --- a/test/Test/Language/Javascript/ModuleParser.hs +++ b/test/Test/Language/Javascript/ModuleParser.hs @@ -42,6 +42,9 @@ testModuleParser = describe "Parse modules:" $ do test "export const a = 1;" `shouldBe` "Right (JSAstModule [JSModuleExportDeclaration (JSExport (JSConstant (JSVarInitExpression (JSIdentifier 'a') [JSDecimal '1'])))])" + test "export function f() {};" + `shouldBe` + "Right (JSAstModule [JSModuleExportDeclaration (JSExport (JSFunction 'f' () (JSBlock [])))])" test "export { a };" `shouldBe` "Right (JSAstModule [JSModuleExportDeclaration (JSExportLocals ((JSExportLocalSpecifier (JSIdentifier 'a'))))])"