Skip to content

Commit 4da9fb7

Browse files
committed
Support export *, see erikd#124
1 parent db8ea4f commit 4da9fb7

File tree

5 files changed

+10
-4
lines changed

5 files changed

+10
-4
lines changed

src/Language/JavaScript/Parser/AST.hs

+3-2
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,8 @@ data JSImportSpecifier
114114
deriving (Data, Eq, Generic, NFData, Show, Typeable)
115115

116116
data JSExportDeclaration
117-
-- = JSExportAllFrom
118-
= JSExportFrom JSExportClause JSFromClause !JSSemi -- ^exports, module, semi
117+
= JSExportAllFrom !JSBinOp !JSFromClause !JSSemi -- ^*, module, semi
118+
| JSExportFrom !JSExportClause JSFromClause !JSSemi -- ^exports, module, semi
119119
| JSExportLocals JSExportClause !JSSemi -- ^exports, autosemi
120120
| JSExport !JSStatement !JSSemi -- ^body, autosemi
121121
-- | JSExportDefault
@@ -499,6 +499,7 @@ instance ShowStripped JSImportSpecifier where
499499
ss (JSImportSpecifierAs x1 _ x2) = "JSImportSpecifierAs (" ++ ss x1 ++ "," ++ ss x2 ++ ")"
500500

501501
instance ShowStripped JSExportDeclaration where
502+
ss (JSExportAllFrom _ from _) = "JSExportAllFrom (" ++ ss from ++ ")"
502503
ss (JSExportFrom xs from _) = "JSExportFrom (" ++ ss xs ++ "," ++ ss from ++ ")"
503504
ss (JSExportLocals xs _) = "JSExportLocals (" ++ ss xs ++ ")"
504505
ss (JSExport x1 _) = "JSExport (" ++ ss x1 ++ ")"

src/Language/JavaScript/Parser/Grammar7.y

+4-2
Original file line numberDiff line numberDiff line change
@@ -1443,7 +1443,7 @@ ImportSpecifier : IdentifierName
14431443
{ AST.JSImportSpecifierAs (identName $1) $2 (identName $3) }
14441444

14451445
-- ExportDeclaration : See 15.2.3
1446-
-- [ ] export * FromClause ;
1446+
-- [x] export * FromClause ;
14471447
-- [x] export ExportClause FromClause ;
14481448
-- [x] export ExportClause ;
14491449
-- [x] export VariableStatement
@@ -1461,7 +1461,9 @@ ImportSpecifier : IdentifierName
14611461
-- [ ] export default ClassDeclaration[Default]
14621462
-- [ ] export default [lookahead ∉ { function, class }] AssignmentExpression[In] ;
14631463
ExportDeclaration :: { AST.JSExportDeclaration }
1464-
ExportDeclaration : ExportClause FromClause AutoSemi
1464+
ExportDeclaration : Mul FromClause AutoSemi
1465+
{ AST.JSExportAllFrom $1 $2 $3 {- 'ExportDeclaration0' -} }
1466+
| ExportClause FromClause AutoSemi
14651467
{ AST.JSExportFrom $1 $2 $3 {- 'ExportDeclaration1' -} }
14661468
| ExportClause AutoSemi
14671469
{ AST.JSExportLocals $1 $2 {- 'ExportDeclaration2' -} }

src/Language/JavaScript/Pretty/Printer.hs

+1
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,7 @@ instance RenderJS JSExportDeclaration where
337337
(|>) pacc (JSExport x1 s) = pacc |> x1 |> s
338338
(|>) pacc (JSExportLocals xs semi) = pacc |> xs |> semi
339339
(|>) pacc (JSExportFrom xs from semi) = pacc |> xs |> from |> semi
340+
(|>) pacc (JSExportAllFrom star from semi) = pacc |> star |> from |> semi
340341

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

src/Language/JavaScript/Process/Minify.hs

+1
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,7 @@ instance MinifyJS JSImportSpecifier where
330330
fix _ (JSImportSpecifierAs x1 _ x2) = JSImportSpecifierAs (fixEmpty x1) spaceAnnot (fixSpace x2)
331331

332332
instance MinifyJS JSExportDeclaration where
333+
fix a (JSExportAllFrom _ from _) = JSExportAllFrom (JSBinOpTimes a) (fix a from) noSemi
333334
fix a (JSExportFrom x1 from _) = JSExportFrom (fix a x1) (fix a from) noSemi
334335
fix _ (JSExportLocals x1 _) = JSExportLocals (fix emptyAnnot x1) noSemi
335336
fix _ (JSExport x1 _) = JSExport (fixStmt spaceAnnot noSemi x1) noSemi

test/Test/Language/Javascript/Minify.hs

+1
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,7 @@ testMinifyModule = describe "Minify modules:" $ do
333333
minifyModule " export const a = 1 ; " `shouldBe` "export const a=1"
334334
minifyModule " export function f () { } ; " `shouldBe` "export function f(){}"
335335
minifyModule " export function * f () { } ; " `shouldBe` "export function*f(){}"
336+
minifyModule " export * from \"mod\" ; " `shouldBe` "export*from\"mod\""
336337

337338
-- -----------------------------------------------------------------------------
338339
-- Minify test helpers.

0 commit comments

Comments
 (0)