Skip to content

Commit 3c57269

Browse files
committed
Support export *, see erikd#124
1 parent 376b83a commit 3c57269

File tree

5 files changed

+10
-4
lines changed

5 files changed

+10
-4
lines changed

src/Language/JavaScript/Parser/AST.hs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@ data JSImportSpecifier
110110
deriving (Data, Eq, Show, Typeable)
111111

112112
data JSExportDeclaration
113-
-- = JSExportAllFrom
114-
= JSExportFrom JSExportClause JSFromClause !JSSemi -- ^exports, module, semi
113+
= JSExportAllFrom !JSBinOp !JSFromClause !JSSemi -- ^*, module, semi
114+
| JSExportFrom !JSExportClause JSFromClause !JSSemi -- ^exports, module, semi
115115
| JSExportLocals JSExportClause !JSSemi -- ^exports, autosemi
116116
| JSExport !JSStatement !JSSemi -- ^body, autosemi
117117
-- | JSExportDefault
@@ -485,6 +485,7 @@ instance ShowStripped JSImportSpecifier where
485485
ss (JSImportSpecifierAs x1 _ x2) = "JSImportSpecifierAs (" ++ ss x1 ++ "," ++ ss x2 ++ ")"
486486

487487
instance ShowStripped JSExportDeclaration where
488+
ss (JSExportAllFrom _ from _) = "JSExportAllFrom (" ++ ss from ++ ")"
488489
ss (JSExportFrom xs from _) = "JSExportFrom (" ++ ss xs ++ "," ++ ss from ++ ")"
489490
ss (JSExportLocals xs _) = "JSExportLocals (" ++ ss xs ++ ")"
490491
ss (JSExport x1 _) = "JSExport (" ++ ss x1 ++ ")"

src/Language/JavaScript/Parser/Grammar7.y

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1434,7 +1434,7 @@ ImportSpecifier : IdentifierName
14341434
{ AST.JSImportSpecifierAs (identName $1) $2 (identName $3) }
14351435

14361436
-- ExportDeclaration : See 15.2.3
1437-
-- [ ] export * FromClause ;
1437+
-- [x] export * FromClause ;
14381438
-- [x] export ExportClause FromClause ;
14391439
-- [x] export ExportClause ;
14401440
-- [x] export VariableStatement
@@ -1452,7 +1452,9 @@ ImportSpecifier : IdentifierName
14521452
-- [ ] export default ClassDeclaration[Default]
14531453
-- [ ] export default [lookahead ∉ { function, class }] AssignmentExpression[In] ;
14541454
ExportDeclaration :: { AST.JSExportDeclaration }
1455-
ExportDeclaration : ExportClause FromClause AutoSemi
1455+
ExportDeclaration : Mul FromClause AutoSemi
1456+
{ AST.JSExportAllFrom $1 $2 $3 {- 'ExportDeclaration0' -} }
1457+
| ExportClause FromClause AutoSemi
14561458
{ AST.JSExportFrom $1 $2 $3 {- 'ExportDeclaration1' -} }
14571459
| ExportClause AutoSemi
14581460
{ AST.JSExportLocals $1 $2 {- 'ExportDeclaration2' -} }

src/Language/JavaScript/Pretty/Printer.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,7 @@ instance RenderJS JSExportDeclaration where
332332
(|>) pacc (JSExport x1 s) = pacc |> x1 |> s
333333
(|>) pacc (JSExportLocals xs semi) = pacc |> xs |> semi
334334
(|>) pacc (JSExportFrom xs from semi) = pacc |> xs |> from |> semi
335+
(|>) pacc (JSExportAllFrom star from semi) = pacc |> star |> from |> semi
335336

336337
instance RenderJS JSExportClause where
337338
(|>) pacc (JSExportClause alb JSLNil arb) = pacc |> alb |> "{" |> arb |> "}"

src/Language/JavaScript/Process/Minify.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,7 @@ instance MinifyJS JSImportSpecifier where
326326
fix _ (JSImportSpecifierAs x1 _ x2) = JSImportSpecifierAs (fixEmpty x1) spaceAnnot (fixSpace x2)
327327

328328
instance MinifyJS JSExportDeclaration where
329+
fix a (JSExportAllFrom _ from _) = JSExportAllFrom (JSBinOpTimes a) (fix a from) noSemi
329330
fix a (JSExportFrom x1 from _) = JSExportFrom (fix a x1) (fix a from) noSemi
330331
fix _ (JSExportLocals x1 _) = JSExportLocals (fix emptyAnnot x1) noSemi
331332
fix _ (JSExport x1 _) = JSExport (fixStmt spaceAnnot noSemi x1) noSemi

test/Test/Language/Javascript/Minify.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,7 @@ testMinifyModule = describe "Minify modules:" $ do
331331
minifyModule " export const a = 1 ; " `shouldBe` "export const a=1"
332332
minifyModule " export function f () { } ; " `shouldBe` "export function f(){}"
333333
minifyModule " export function * f () { } ; " `shouldBe` "export function*f(){}"
334+
minifyModule " export * from \"mod\" ; " `shouldBe` "export*from\"mod\""
334335

335336
-- -----------------------------------------------------------------------------
336337
-- Minify test helpers.

0 commit comments

Comments
 (0)