Skip to content

Commit

Permalink
Fix undeclared modules variable when bundling (#151)
Browse files Browse the repository at this point in the history
The generated code when bundling is broken and the modules identifier is
not declared when running through the load function
  • Loading branch information
jeparlefrancais authored Nov 6, 2023
1 parent 7032199 commit 961f52a
Show file tree
Hide file tree
Showing 16 changed files with 47 additions and 15 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Unreleased

* fix undeclared modules variable when bundling ([#151](https://github.com/seaofvoices/darklua/pull/151))

## 0.11.2

* fix bundling to handle modules with early return calls. This change also makes the bundled code preserve the module require ordering ([#147](https://github.com/seaofvoices/darklua/pull/147))
Expand Down
6 changes: 5 additions & 1 deletion src/rules/bundle/path_require_mode/module_definitions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,11 @@ impl BuildModuleDefinitions {
let modules_table = self.build_modules_table();
block.insert_statement(
0,
LocalAssignStatement::from_variable(self.modules_identifier).with_value(modules_table),
AssignStatement::from_variable(modules_identifier, modules_table),
);
block.insert_statement(
0,
LocalAssignStatement::from_variable(self.modules_identifier),
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
source: tests/bundle.rs
expression: main
---
local __DARKLUA_BUNDLE_MODULES = {
local __DARKLUA_BUNDLE_MODULES

__DARKLUA_BUNDLE_MODULES = {
cache = {},
load = function(m)
if not __DARKLUA_BUNDLE_MODULES.cache[m] then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
source: tests/bundle.rs
expression: main
---
local __DARKLUA_BUNDLE_MODULES = {
local __DARKLUA_BUNDLE_MODULES

__DARKLUA_BUNDLE_MODULES = {
cache = {},
load = function(m)
if not __DARKLUA_BUNDLE_MODULES.cache[m] then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
source: tests/bundle.rs
expression: main
---
local __DARKLUA_BUNDLE_MODULES = {
local __DARKLUA_BUNDLE_MODULES

__DARKLUA_BUNDLE_MODULES = {
cache = {},
load = function(m)
if not __DARKLUA_BUNDLE_MODULES.cache[m] then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
source: tests/bundle.rs
expression: main
---
local __DARKLUA_BUNDLE_MODULES = {
local __DARKLUA_BUNDLE_MODULES

__DARKLUA_BUNDLE_MODULES = {
cache = {},
load = function(m)
if not __DARKLUA_BUNDLE_MODULES.cache[m] then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
source: tests/bundle.rs
expression: main
---
local __DARKLUA_BUNDLE_MODULES = {
local __DARKLUA_BUNDLE_MODULES

__DARKLUA_BUNDLE_MODULES = {
cache = {},
load = function(m)
if not __DARKLUA_BUNDLE_MODULES.cache[m] then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
source: tests/bundle.rs
expression: main
---
local __DARKLUA_BUNDLE_MODULES = {
local __DARKLUA_BUNDLE_MODULES

__DARKLUA_BUNDLE_MODULES = {
cache = {},
load = function(m)
if not __DARKLUA_BUNDLE_MODULES.cache[m] then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
source: tests/bundle.rs
expression: main
---
local __DARKLUA_BUNDLE_MODULES = {
local __DARKLUA_BUNDLE_MODULES

__DARKLUA_BUNDLE_MODULES = {
cache = {},
load = function(m)
if not __DARKLUA_BUNDLE_MODULES.cache[m] then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
source: tests/bundle.rs
expression: main
---
local __DARKLUA_BUNDLE_MODULES = {
local __DARKLUA_BUNDLE_MODULES

__DARKLUA_BUNDLE_MODULES = {
cache = {},
load = function(m)
if not __DARKLUA_BUNDLE_MODULES.cache[m] then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
source: tests/bundle.rs
expression: main
---
local __DARKLUA_BUNDLE_MODULES = {
local __DARKLUA_BUNDLE_MODULES

__DARKLUA_BUNDLE_MODULES = {
cache = {},
load = function(m)
if not __DARKLUA_BUNDLE_MODULES.cache[m] then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
source: tests/bundle.rs
expression: main
---
local __DARKLUA_BUNDLE_MODULES={cache={}, load=function(m)if not __DARKLUA_BUNDLE_MODULES.cache[m]then __DARKLUA_BUNDLE_MODULES.cache[m]={c=__DARKLUA_BUNDLE_MODULES[m]()}end return __DARKLUA_BUNDLE_MODULES.cache[m].c end}do function __DARKLUA_BUNDLE_MODULES.a()local function initialize()
local __DARKLUA_BUNDLE_MODULES __DARKLUA_BUNDLE_MODULES={cache={}, load=function(m)if not __DARKLUA_BUNDLE_MODULES.cache[m]then __DARKLUA_BUNDLE_MODULES.cache[m]={c=__DARKLUA_BUNDLE_MODULES[m]()}end return __DARKLUA_BUNDLE_MODULES.cache[m].c end}do function __DARKLUA_BUNDLE_MODULES.a()local function initialize()
end

return initialize
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
source: tests/bundle.rs
expression: main
---
local __DARKLUA_BUNDLE_MODULES = {
local __DARKLUA_BUNDLE_MODULES

__DARKLUA_BUNDLE_MODULES = {
cache = {},
load = function(m)
if not __DARKLUA_BUNDLE_MODULES.cache[m] then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
source: tests/bundle.rs
expression: main
---
local __DARKLUA_BUNDLE_MODULES = {
local __DARKLUA_BUNDLE_MODULES

__DARKLUA_BUNDLE_MODULES = {
cache = {},
load = function(m)
if not __DARKLUA_BUNDLE_MODULES.cache[m] then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
source: tests/bundle.rs
expression: main
---
local __DARKLUA_BUNDLE_MODULES = {
local __DARKLUA_BUNDLE_MODULES

__DARKLUA_BUNDLE_MODULES = {
cache = {},
load = function(m)
if not __DARKLUA_BUNDLE_MODULES.cache[m] then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
source: tests/bundle.rs
expression: main
---
local __DARKLUA_BUNDLE_MODULES = {
local __DARKLUA_BUNDLE_MODULES

__DARKLUA_BUNDLE_MODULES = {
cache = {},
load = function(m)
if not __DARKLUA_BUNDLE_MODULES.cache[m] then
Expand Down

0 comments on commit 961f52a

Please sign in to comment.