Skip to content

Commit 85d921e

Browse files
feat(output): add export * rendering and minification support
Extends PR #125 implementation with complete output generation: - Pretty/Printer.hs: Add RenderJS instance for JSExportAllFrom - Pretty/JSON.hs: Add JSON serialization pattern match for export * - Process/Minify.hs: Add MinifyJS instance for efficient export * minification Export * statements now render correctly as 'export*from"module"' when minified and preserve proper formatting in pretty-printed output.
1 parent bb07aec commit 85d921e

File tree

3 files changed

+8
-0
lines changed

3 files changed

+8
-0
lines changed

src/Language/JavaScript/Pretty/JSON.hs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,12 @@ renderExportDeclarationToJSON decl = case decl of
357357
, ("declaration", renderStatementToJSON statement)
358358
, ("semicolon", renderSemiColonToJSON semi)
359359
]
360+
AST.JSExportAllFrom star fromClause semi -> formatJSONObject
361+
[ ("type", "\"ExportAllFromDeclaration\"")
362+
, ("star", renderBinOpToJSON star)
363+
, ("source", renderFromClauseToJSON fromClause)
364+
, ("semicolon", renderSemiColonToJSON semi)
365+
]
360366

361367
-- | Render export clause to JSON.
362368
renderExportClauseToJSON :: AST.JSExportClause -> Text

src/Language/JavaScript/Pretty/Printer.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,7 @@ instance RenderJS JSImportSpecifier where
340340
(|>) pacc (JSImportSpecifierAs x1 annot x2) = pacc |> x1 |> annot |> "as" |> x2
341341

342342
instance RenderJS JSExportDeclaration where
343+
(|>) pacc (JSExportAllFrom star from semi) = pacc |> star |> from |> semi
343344
(|>) pacc (JSExport x1 s) = pacc |> x1 |> s
344345
(|>) pacc (JSExportLocals xs semi) = pacc |> xs |> semi
345346
(|>) pacc (JSExportFrom xs from semi) = pacc |> xs |> from |> semi

src/Language/JavaScript/Process/Minify.hs

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

338338
instance MinifyJS JSExportDeclaration where
339+
fix a (JSExportAllFrom star from _) = JSExportAllFrom (fix a star) (fix a from) noSemi
339340
fix a (JSExportFrom x1 from _) = JSExportFrom (fix a x1) (fix a from) noSemi
340341
fix _ (JSExportLocals x1 _) = JSExportLocals (fix emptyAnnot x1) noSemi
341342
fix _ (JSExport x1 _) = JSExport (fixStmt spaceAnnot noSemi x1) noSemi

0 commit comments

Comments
 (0)