Mercurial > vim
diff src/vim9expr.c @ 26980:8796f1384750 v8.2.4019
patch 8.2.4019: Vim9: import mechanism is too complicated
Commit: https://github.com/vim/vim/commit/d5f400c607182db6d4fbe2964471d796277f67e8
Author: Bram Moolenaar <Bram@vim.org>
Date: Thu Jan 6 21:10:28 2022 +0000
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.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Thu, 06 Jan 2022 22:15:04 +0100 |
parents | ccb9be1cdd71 |
children | fc19375787dd |
line wrap: on
line diff
--- a/src/vim9expr.c +++ b/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; + 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; + // 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; + } - idx = find_exported(import->imp_sid, exp_name, &ufunc, &type, + // 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; + *p = cc; + p = skipwhite(p); + *end = p; - if (idx < 0) + if (idx < 0) + { + if (ufunc != NULL) { - if (*p == '(' && ufunc != NULL) - { - generate_PUSHFUNC(cctx, ufunc->uf_name, import->imp_type); - return OK; - } - return FAIL; + // 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); - } - 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); + generate_VIM9SCRIPT(cctx, ISN_LOADSCRIPT, + import->imp_sid, + idx, + type); return OK; }