diff src/vim9compile.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 fceb494e22de
children eebbcc83fb75
line wrap: on
line diff
--- a/src/vim9compile.c
+++ b/src/vim9compile.c
@@ -1357,7 +1357,39 @@ compile_lhs(
 		    // existing script-local variables should have a type
 		    lhs->lhs_scriptvar_sid = current_sctx.sc_sid;
 		    if (import != NULL)
+		    {
+			char_u	*dot = vim_strchr(var_start, '.');
+			char_u	*p;
+
+			// for an import the name is what comes after the dot
+			if (dot == NULL)
+			{
+			    semsg(_(e_no_dot_after_imported_name_str),
+								    var_start);
+			    return FAIL;
+			}
+			p = skipwhite(dot + 1);
+			var_end = to_name_end(p, TRUE);
+			if (var_end == p)
+			{
+			    semsg(_(e_missing_name_after_imported_name_str),
+								    var_start);
+			    return FAIL;
+			}
+			vim_free(lhs->lhs_name);
+			lhs->lhs_varlen = var_end - p;
+			lhs->lhs_name = vim_strnsave(p, lhs->lhs_varlen);
+			if (lhs->lhs_name == NULL)
+			    return FAIL;
+			rawname = lhs->lhs_name;
 			lhs->lhs_scriptvar_sid = import->imp_sid;
+			// TODO: where do we check this name is exported?
+
+			// Check if something follows: "exp.var[idx]" or
+			// "exp.var.key".
+			lhs->lhs_has_index = lhs->lhs_dest_end
+							  > skipwhite(var_end);
+		    }
 		    if (SCRIPT_ID_VALID(lhs->lhs_scriptvar_sid))
 		    {
 			// Check writable only when no index follows.