Skip to content

Commit

Permalink
removed suffixes from imported names
Browse files Browse the repository at this point in the history
  • Loading branch information
azizghuloum committed Dec 18, 2024
1 parent 629f95c commit e775814
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion rtsc/.rts/testing-file-extensions.rts.json
Original file line number Diff line number Diff line change
@@ -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": [
{
Expand Down
6 changes: 5 additions & 1 deletion src/expander.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/library-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
2 changes: 1 addition & 1 deletion test-project/.rts/main.rts.json
Original file line number Diff line number Diff line change
@@ -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"}}
}
4 changes: 2 additions & 2 deletions test-project/.rts/main.rts.ts
Original file line number Diff line number Diff line change
@@ -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);
2 changes: 1 addition & 1 deletion test-project/.rts/mod.rts.json
Original file line number Diff line number Diff line change
@@ -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": [
{
Expand Down

0 comments on commit e775814

Please sign in to comment.