forked from aniani/vim
patch 8.2.4019: Vim9: import mechanism is too complicated
Problem: Vim9: import mechanism is too complicated. Solution: Do not use the Javascript mechanism but a much simpler one.
This commit is contained in:
103
src/vim9expr.c
103
src/vim9expr.c
@@ -240,7 +240,7 @@ compile_load_scriptvar(
|
||||
cctx_T *cctx,
|
||||
char_u *name, // variable NUL terminated
|
||||
char_u *start, // start of variable
|
||||
char_u **end, // end of variable
|
||||
char_u **end, // end of variable, may be NULL
|
||||
int error) // when TRUE may give error
|
||||
{
|
||||
scriptitem_T *si;
|
||||
@@ -266,65 +266,56 @@ compile_load_scriptvar(
|
||||
return OK;
|
||||
}
|
||||
|
||||
import = find_imported(name, 0, cctx);
|
||||
import = end == NULL ? NULL : find_imported(name, 0, cctx);
|
||||
if (import != NULL)
|
||||
{
|
||||
if (import->imp_flags & IMP_FLAGS_STAR)
|
||||
char_u *p = skipwhite(*end);
|
||||
char_u *exp_name;
|
||||
int cc;
|
||||
ufunc_T *ufunc;
|
||||
type_T *type;
|
||||
|
||||
// Need to lookup the member.
|
||||
if (*p != '.')
|
||||
{
|
||||
char_u *p = skipwhite(*end);
|
||||
char_u *exp_name;
|
||||
int cc;
|
||||
ufunc_T *ufunc;
|
||||
type_T *type;
|
||||
|
||||
// Used "import * as Name", need to lookup the member.
|
||||
if (*p != '.')
|
||||
{
|
||||
semsg(_(e_expected_dot_after_name_str), start);
|
||||
return FAIL;
|
||||
}
|
||||
++p;
|
||||
if (VIM_ISWHITE(*p))
|
||||
{
|
||||
emsg(_(e_no_white_space_allowed_after_dot));
|
||||
return FAIL;
|
||||
}
|
||||
|
||||
// isolate one name
|
||||
exp_name = p;
|
||||
while (eval_isnamec(*p))
|
||||
++p;
|
||||
cc = *p;
|
||||
*p = NUL;
|
||||
|
||||
idx = find_exported(import->imp_sid, exp_name, &ufunc, &type,
|
||||
cctx, TRUE);
|
||||
*p = cc;
|
||||
p = skipwhite(p);
|
||||
*end = p;
|
||||
|
||||
if (idx < 0)
|
||||
{
|
||||
if (*p == '(' && ufunc != NULL)
|
||||
{
|
||||
generate_PUSHFUNC(cctx, ufunc->uf_name, import->imp_type);
|
||||
return OK;
|
||||
}
|
||||
return FAIL;
|
||||
}
|
||||
|
||||
generate_VIM9SCRIPT(cctx, ISN_LOADSCRIPT,
|
||||
import->imp_sid,
|
||||
idx,
|
||||
type);
|
||||
semsg(_(e_expected_dot_after_name_str), start);
|
||||
return FAIL;
|
||||
}
|
||||
else if (import->imp_funcname != NULL)
|
||||
generate_PUSHFUNC(cctx, import->imp_funcname, import->imp_type);
|
||||
else
|
||||
generate_VIM9SCRIPT(cctx, ISN_LOADSCRIPT,
|
||||
import->imp_sid,
|
||||
import->imp_var_vals_idx,
|
||||
import->imp_type);
|
||||
++p;
|
||||
if (VIM_ISWHITE(*p))
|
||||
{
|
||||
emsg(_(e_no_white_space_allowed_after_dot));
|
||||
return FAIL;
|
||||
}
|
||||
|
||||
// isolate one name
|
||||
exp_name = p;
|
||||
while (eval_isnamec(*p))
|
||||
++p;
|
||||
cc = *p;
|
||||
*p = NUL;
|
||||
|
||||
idx = find_exported(import->imp_sid, exp_name, &ufunc, &type,
|
||||
cctx, TRUE);
|
||||
*p = cc;
|
||||
p = skipwhite(p);
|
||||
*end = p;
|
||||
|
||||
if (idx < 0)
|
||||
{
|
||||
if (ufunc != NULL)
|
||||
{
|
||||
// function call or function reference
|
||||
generate_PUSHFUNC(cctx, ufunc->uf_name, NULL);
|
||||
return OK;
|
||||
}
|
||||
return FAIL;
|
||||
}
|
||||
|
||||
generate_VIM9SCRIPT(cctx, ISN_LOADSCRIPT,
|
||||
import->imp_sid,
|
||||
idx,
|
||||
type);
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user