Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
gwleuverink committed Jun 3, 2024
1 parent 63bf381 commit 78e4bcb
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions src/Components/Import.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,21 +76,10 @@ protected function import(): string
//--------------------------------------------------------------------------
(() => {
// Check if module is already loaded under a different alias
const previous = document.querySelector(`script[data-module="{$this->module}"]`)
// Was previously loaded & needs to be pushed to import map
if(previous && '{$this->as}') {
// Throw error when previously imported under different alias. Otherwise continue
if(previous.dataset.alias !== '{$this->as}') {
throw `BUNDLING ERROR: '{$this->as}' already imported as '\${previous.dataset.alias}'`
}
}
// Import was marked as invokable
if('{$this->init}') {
return import('{$this->module}')
// Note: don't return, since we might need to still register the module
import('{$this->module}')
.then(invokable => {
if(typeof invokable.default !== 'function') {
throw `BUNDLING ERROR: '{$this->module}' not invokable - default export is not a function`
Expand All @@ -104,6 +93,17 @@ protected function import(): string
})
}
// Check if module is already loaded under a different alias
const previous = document.querySelector(`script[data-module="{$this->module}"]`)
// Was previously loaded & needs to be pushed to import map
if(previous && '{$this->as}') {
// Throw error when previously imported under different alias. Otherwise continue
if(previous.dataset.alias !== '{$this->as}') {
throw `BUNDLING ERROR: '{$this->as}' already imported as '\${previous.dataset.alias}'`
}
}
// Handle CSS injection
if('{$this->module}'.endsWith('.css') || '{$this->module}'.endsWith('.scss')) {
return import('{$this->module}').then(result => {
Expand Down

0 comments on commit 78e4bcb

Please sign in to comment.