mirror of
https://github.com/leporello-js/leporello-js
synced 2026-01-13 21:14:28 -08:00
fix external imports bug
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import {map_object, pick_keys, collect_nodes_with_parents, uniq}
|
import {map_object, filter_object, pick_keys, collect_nodes_with_parents, uniq}
|
||||||
from './utils.js'
|
from './utils.js'
|
||||||
import {
|
import {
|
||||||
is_eq, is_child, ancestry, ancestry_inc, map_tree,
|
is_eq, is_child, ancestry, ancestry_inc, map_tree,
|
||||||
@@ -105,6 +105,7 @@ const run_code = (s, index, dirty_files) => {
|
|||||||
external_imports.some(i => state.external_imports_cache[i] == null)
|
external_imports.some(i => state.external_imports_cache[i] == null)
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
|
// Trigger loading of external modules
|
||||||
return {...state,
|
return {...state,
|
||||||
loading_external_imports_state: {
|
loading_external_imports_state: {
|
||||||
index,
|
index,
|
||||||
@@ -112,10 +113,16 @@ const run_code = (s, index, dirty_files) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
// Modules were loaded and cached, proceed
|
||||||
return external_imports_loaded(
|
return external_imports_loaded(
|
||||||
state,
|
state,
|
||||||
state,
|
state,
|
||||||
|
state.external_imports_cache == null
|
||||||
|
? null
|
||||||
|
: filter_object(
|
||||||
state.external_imports_cache,
|
state.external_imports_cache,
|
||||||
|
(module_name, module) => external_imports.includes(module_name)
|
||||||
|
),
|
||||||
index
|
index
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
28
test/test.js
28
test/test.js
@@ -951,6 +951,34 @@ export const tests = [
|
|||||||
)
|
)
|
||||||
}),
|
}),
|
||||||
|
|
||||||
|
test('module external cache invalidation bug', () => {
|
||||||
|
const code = `
|
||||||
|
// external
|
||||||
|
import {foo_var} from 'foo.js'
|
||||||
|
`
|
||||||
|
const initial = test_initial_state(code)
|
||||||
|
|
||||||
|
// simulate module load error
|
||||||
|
const next = COMMANDS.external_imports_loaded(initial, initial, {
|
||||||
|
'foo.js': {
|
||||||
|
ok: false,
|
||||||
|
error: new Error('Failed to resolve module'),
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
const edited = ``
|
||||||
|
|
||||||
|
// edit code
|
||||||
|
const {state, effects} = COMMANDS.input(
|
||||||
|
next,
|
||||||
|
edited,
|
||||||
|
0,
|
||||||
|
)
|
||||||
|
|
||||||
|
assert_equal(state.parse_result.ok, true)
|
||||||
|
}),
|
||||||
|
|
||||||
|
|
||||||
// Static analysis
|
// Static analysis
|
||||||
|
|
||||||
test('undeclared', () => {
|
test('undeclared', () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user