Skip to content

Commit

Permalink
Use loader.SourceData directly in the bundle
Browse files Browse the repository at this point in the history
  • Loading branch information
mstoykov committed Mar 6, 2023
1 parent 0c8c08c commit aa208f8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
14 changes: 6 additions & 8 deletions js/bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@ import (
// A Bundle is a self-contained bundle of scripts and resources.
// You can use this to produce identical BundleInstance objects.
type Bundle struct {
Filename *url.URL
Source []byte
Options lib.Options
sourceData *loader.SourceData
Options lib.Options

CompatibilityMode lib.CompatibilityMode // parsed value
preInitState *lib.TestPreInitState
Expand Down Expand Up @@ -79,8 +78,7 @@ func newBundle(

// Make a bundle, instantiate it into a throwaway VM to populate caches.
bundle := &Bundle{
Filename: src.URL,
Source: src.Data,
sourceData: src,
Options: options,
CompatibilityMode: compatMode,
callableExports: make(map[string]struct{}),
Expand Down Expand Up @@ -144,8 +142,8 @@ func (b *Bundle) makeArchive() *lib.Archive {
Type: "js",
Filesystems: b.filesystems,
Options: b.Options,
FilenameURL: b.Filename,
Data: b.Source,
FilenameURL: b.sourceData.URL,
Data: b.sourceData.Data,
PwdURL: b.pwd,
Env: make(map[string]string, len(b.preInitState.RuntimeOptions.Env)),
CompatibilityMode: b.CompatibilityMode.String(),
Expand Down Expand Up @@ -296,7 +294,7 @@ func (b *Bundle) instantiate(vuImpl *moduleVUImpl, vuID uint64) (moduleInstance,
err = common.RunWithPanicCatching(b.preInitState.Logger, rt, func() error {
return vuImpl.eventLoop.Start(func() error {
//nolint:shadow,govet // here we shadow err on purpose
mod, err := b.moduleResolver.resolve(b.pwd, b.Filename.String())
mod, err := b.moduleResolver.resolve(b.pwd, b.sourceData.URL.String())
if err != nil {
return err // TODO wrap as this should never happen
}
Expand Down
2 changes: 1 addition & 1 deletion js/bundle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func TestNewBundle(t *testing.T) {
t.Parallel()
b, err := getSimpleBundle(t, "-", `export default function() {};`)
require.NoError(t, err)
assert.Equal(t, "file://-", b.Filename.String())
assert.Equal(t, "file://-", b.sourceData.URL.String())
assert.Equal(t, "file:///", b.pwd.String())
})
t.Run("CompatibilityMode", func(t *testing.T) {
Expand Down

0 comments on commit aa208f8

Please sign in to comment.