From e775814aa710bbd07c15daa1b93189ec391196c7 Mon Sep 17 00:00:00 2001 From: Abdulaziz Ghuloum Date: Wed, 18 Dec 2024 07:13:55 +0300 Subject: [PATCH] removed suffixes from imported names --- rtsc/.rts/testing-file-extensions.rts.json | 2 +- src/expander.ts | 6 +++++- src/library-manager.ts | 2 +- test-project/.rts/main.rts.json | 2 +- test-project/.rts/main.rts.ts | 4 ++-- test-project/.rts/mod.rts.json | 2 +- 6 files changed, 11 insertions(+), 7 deletions(-) diff --git a/rtsc/.rts/testing-file-extensions.rts.json b/rtsc/.rts/testing-file-extensions.rts.json index 68b995d..155d0d1 100644 --- a/rtsc/.rts/testing-file-extensions.rts.json +++ b/rtsc/.rts/testing-file-extensions.rts.json @@ -1,6 +1,6 @@ { "cid": "rtsc/testing-file-extensions.rts rewrite-ts-visualized 0.0.0", - "cookie": "rewrite-ts-009", + "cookie": "rewrite-ts-010", "exported_identifiers": { "x": [ { diff --git a/src/expander.ts b/src/expander.ts index 0fe90c4..54ac44a 100644 --- a/src/expander.ts +++ b/src/expander.ts @@ -1037,6 +1037,10 @@ const sort_env = { type: "types_env" as const, value: "normal_env" as const }; const postexpand_forms = (sort: "type" | "value") => non_modular(postexpand_body(sort)); +function cleanup_name(name: string): string { + return name.replace(/(_\d+)+$/, ""); +} + const postexpand_body = (sort: "type" | "value") => (data: data) => { const cont: walker = ({ loc, ...data }) => go_next( @@ -1080,7 +1084,7 @@ const postexpand_body = (sort: "type" | "value") => (data: data) => { return cont({ ...data, loc: rename(loc, existing.new_name) }); } else { const { name } = binding; - const new_name = `${name}_${counters.vars}`; + const new_name = `${cleanup_name(name)}_${counters.vars}`; const new_counters = { ...counters, vars: counters.vars + 1 }; const new_imp: import_req = { ...imp, diff --git a/src/library-manager.ts b/src/library-manager.ts index 98792d7..7d38434 100644 --- a/src/library-manager.ts +++ b/src/library-manager.ts @@ -19,7 +19,7 @@ import { Binding, CompilationUnit, Context, Loc } from "./syntax-structures"; import stringify from "json-stringify-pretty-compact"; import { init_global_context } from "./global-module"; -const cookie = "rewrite-ts-009"; +const cookie = "rewrite-ts-010"; type module_state = | { type: "initial" } diff --git a/test-project/.rts/main.rts.json b/test-project/.rts/main.rts.json index 25f648a..1e76d28 100644 --- a/test-project/.rts/main.rts.json +++ b/test-project/.rts/main.rts.json @@ -1,6 +1,6 @@ { "cid": "test-project/main.rts rewrite-ts-visualized 0.0.0", - "cookie": "rewrite-ts-009", + "cookie": "rewrite-ts-010", "exported_identifiers": {}, "context": {"l1": {"type": "lexical", "name": "y_1"}} } \ No newline at end of file diff --git a/test-project/.rts/main.rts.ts b/test-project/.rts/main.rts.ts index 0783b8f..e710bb7 100644 --- a/test-project/.rts/main.rts.ts +++ b/test-project/.rts/main.rts.ts @@ -1,3 +1,3 @@ -import { type t_2 as t_2_2, x_1 as x_1_3 } from "./mod.rts.ts"; -export const y_1: t_2_2 = x_1_3; +import { type t_2 as t_2, x_1 as x_3 } from "./mod.rts.ts"; +export const y_1: t_2 = x_3; console.log(y_1); diff --git a/test-project/.rts/mod.rts.json b/test-project/.rts/mod.rts.json index 8eeb0cf..be7dd12 100644 --- a/test-project/.rts/mod.rts.json +++ b/test-project/.rts/mod.rts.json @@ -1,6 +1,6 @@ { "cid": "test-project/mod.rts rewrite-ts-visualized 0.0.0", - "cookie": "rewrite-ts-009", + "cookie": "rewrite-ts-010", "exported_identifiers": { "x": [ {