From 198f335415ec7cf5dd7992c8a7b57984cfd44efb Mon Sep 17 00:00:00 2001 From: Cyril Sobierajewicz Date: Sun, 4 Apr 2021 16:14:53 +0200 Subject: [PATCH 1/4] Add support for bundling function declarations --- src/Language/PureScript/Bundle.hs | 4 ++++ tests/purs/bundle/FunctionDeclaration.js | 19 +++++++++++++++++++ tests/purs/bundle/FunctionDeclaration.purs | 14 ++++++++++++++ 3 files changed, 37 insertions(+) create mode 100644 tests/purs/bundle/FunctionDeclaration.js create mode 100644 tests/purs/bundle/FunctionDeclaration.purs diff --git a/src/Language/PureScript/Bundle.hs b/src/Language/PureScript/Bundle.hs index 734c61da8c..0ab9e79589 100644 --- a/src/Language/PureScript/Bundle.hs +++ b/src/Language/PureScript/Bundle.hs @@ -474,6 +474,10 @@ matchMember stmt , JSIdentifier _ name <- var , JSVarInit _ decl <- varInit = Just (Internal, name, decl) + -- function foo(...args) { body } + | JSFunction a0 jsIdent a1 args a2 body _ <- stmt + , JSIdentName _ name <- jsIdent + = pure (Internal, name, JSFunctionExpression a0 jsIdent a1 args a2 body) -- exports.foo = expr; exports["foo"] = expr; | JSAssignStatement e (JSAssign _) decl _ <- stmt , Just name <- exportsAccessor e diff --git a/tests/purs/bundle/FunctionDeclaration.js b/tests/purs/bundle/FunctionDeclaration.js new file mode 100644 index 0000000000..6d7bfdc1e0 --- /dev/null +++ b/tests/purs/bundle/FunctionDeclaration.js @@ -0,0 +1,19 @@ +"use strict"; + +var foo = 0; + +function bar(foo) { + return foo; +} + +var baz = "Done"; + +function qux() { + return bar(baz); +} + +exports.qux = qux; + +var fs = require('fs'); +var source = fs.readFileSync(__filename, 'utf-8'); +exports.fooIsEliminated = !/^ *var foo/m.test(source); diff --git a/tests/purs/bundle/FunctionDeclaration.purs b/tests/purs/bundle/FunctionDeclaration.purs new file mode 100644 index 0000000000..5d9810c71b --- /dev/null +++ b/tests/purs/bundle/FunctionDeclaration.purs @@ -0,0 +1,14 @@ +module Main (main) where + +import Prelude +import Effect (Effect) +import Effect.Console (log) +import Test.Assert (assert') + +main :: Effect Unit +main = do + assert' "foo" fooIsEliminated + qux >>= log + +foreign import qux :: Effect String +foreign import fooIsEliminated :: Boolean From 4b43185cc7e4ac5002f037f392f27f9456078aae Mon Sep 17 00:00:00 2001 From: Cyril Sobierajewicz Date: Sun, 4 Apr 2021 17:48:42 +0200 Subject: [PATCH 2/4] Update CHANGELOG.md --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2123b42e0f..8c62057e98 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -165,6 +165,8 @@ Bugfixes: corefn.json file in your output directory which would be incorrectly considered up-to-date by the compiler. +* Do not remove bindings referenced in function declarations when bundling (#4044, @kl0tl) + Other improvements: * Add white outline stroke to logo in README (#4003, @ptrfrncsmrph) From f9281848223e08fe30af2b3a68fddac33b6c5627 Mon Sep 17 00:00:00 2001 From: Cyril Sobierajewicz Date: Wed, 30 Jun 2021 10:39:22 +0200 Subject: [PATCH 3/4] fixup! Update CHANGELOG.md --- CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8c62057e98..722db003a3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -37,6 +37,8 @@ Bugfixes: * Improve apartness checking (#4064, @rhendric) +* Do not remove bindings referenced in function declarations when bundling (#4044, @kl0tl) + Internal: * Fix for Haddock (#4072 by @ncaq and @JordanMartinez) @@ -165,8 +167,6 @@ Bugfixes: corefn.json file in your output directory which would be incorrectly considered up-to-date by the compiler. -* Do not remove bindings referenced in function declarations when bundling (#4044, @kl0tl) - Other improvements: * Add white outline stroke to logo in README (#4003, @ptrfrncsmrph) From 9b35823f2f8ccaa397e84aacfb3937890344f797 Mon Sep 17 00:00:00 2001 From: Cyril Sobierajewicz Date: Tue, 20 Jul 2021 17:55:16 +0200 Subject: [PATCH 4/4] Add changelog entry --- CHANGELOG.d/fix_bundle-function-declarations.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 CHANGELOG.d/fix_bundle-function-declarations.md diff --git a/CHANGELOG.d/fix_bundle-function-declarations.md b/CHANGELOG.d/fix_bundle-function-declarations.md new file mode 100644 index 0000000000..ce613debd4 --- /dev/null +++ b/CHANGELOG.d/fix_bundle-function-declarations.md @@ -0,0 +1 @@ +* Do not remove bindings referenced in function declarations when bundling