mirror of
https://github.com/go-sylixos/elvish.git
synced 2024-12-13 18:07:51 +08:00
parent
d925c5c8e8
commit
98a8e2f666
|
@ -295,7 +295,7 @@ func loadModule(fm *Frame, name string) (Ns, error) {
|
|||
0, len(src.code), fm.addTraceback(), false,
|
||||
}
|
||||
|
||||
op, err := newFm.Compile(n, src)
|
||||
op, err := compile(newFm.Builtin.static(), modGlobal.static(), n, src)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -39,7 +39,7 @@ var builtinSpecialTests = []Test{
|
|||
// return.
|
||||
{"fn f []{ put a; return; put b }; f", want{out: strs("a")}},
|
||||
|
||||
// Modules (see setup_datadir_test.go for setup)
|
||||
// Modules (see testmain_test.go for setup)
|
||||
// "use" imports a module.
|
||||
{`use lorem; put $lorem:name`, want{out: strs("lorem")}},
|
||||
// imports are lexically scoped
|
||||
|
@ -61,6 +61,9 @@ var builtinSpecialTests = []Test{
|
|||
// relative uses
|
||||
{`use a/b/c/x; put $x:d $x:lorem`, want{out: strs("a/b/c/d", "lorem")}},
|
||||
|
||||
// Variables defined in the default global scope is invisible from modules
|
||||
NewTest("x = foo; use put-x").WantAnyErr(),
|
||||
|
||||
// TODO: Test module namespace
|
||||
}
|
||||
|
||||
|
|
|
@ -206,7 +206,7 @@ func (ev *Evaler) eval(op Op, ports []*Port, src *Source) error {
|
|||
return ec.Eval(op)
|
||||
}
|
||||
|
||||
// Compile compiles elvish code in the global scope. If the error is not nil, it
|
||||
// Compile compiles Elvish code in the global scope. If the error is not nil, it
|
||||
// always has type CompilationError.
|
||||
func (ev *Evaler) Compile(n *parse.Chunk, src *Source) (Op, error) {
|
||||
return compile(ev.Builtin.static(), ev.Global.static(), n, src)
|
||||
|
|
|
@ -68,6 +68,7 @@ var mods = map[string]string{
|
|||
"a/b/c/d": "name = a/b/c/d",
|
||||
"a/b/c/x": "use ./d; d = $d:name; use ../../../lorem; lorem = $lorem:name",
|
||||
"has/init": "put has/init",
|
||||
"put-x": "put $x",
|
||||
}
|
||||
|
||||
var libDir string
|
||||
|
|
Loading…
Reference in New Issue
Block a user