Skip to content

Commit

Permalink
added warnings to generated files
Browse files Browse the repository at this point in the history
  • Loading branch information
azizghuloum committed Jan 2, 2025
1 parent 5321c19 commit e79c31d
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 8 deletions.
3 changes: 2 additions & 1 deletion src/library-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import stringify from "json-stringify-pretty-compact";
import { init_global_context } from "./global-module";
import { parse_dts } from "./parse-dts";

const cookie = "rewrite-ts-024";
const cookie = "rewrite-ts-025";

type module_state =
| { type: "initial" }
Expand Down Expand Up @@ -406,6 +406,7 @@ class RtsModule extends Module {
code_path,
await pprint(loc, {
prettify: false,
add_warning: true,
map: {
filename: basename(code_path),
resolve: async (cuid: string) => {
Expand Down
5 changes: 4 additions & 1 deletion src/pprint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ export async function pretty_print(code: string) {

type options = {
prettify: boolean;
add_warning?: boolean;
map?: map_options;
};

Expand Down Expand Up @@ -272,7 +273,9 @@ function remap(ls: n[], diffs: d[]): n[] {
export async function pprint(loc: Loc, options: options): Promise<string> {
const ls = ns_flatten(loc_to_ns(loc));
const code = ls.map((x) => x.val).join("");
const pretty = await pretty_print(code);
const pretty =
(options.add_warning ? "/* This file is automatically generated. Do not edit. */\n" : "") +
(await pretty_print(code));
const diff = Diff.diffWordsWithSpace(code, pretty);
const pretty_ls = remap(ls, diff);
return options.map ? add_src_map(pretty, pretty_ls, options.map) : pretty;
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-024",
"cookie": "rewrite-ts-025",
"imports": [
{
"pkg": {"name": "rewrite-ts-visualized", "version": "0.0.0"},
Expand Down
3 changes: 2 additions & 1 deletion test-project/.rts/main.rts.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/* This file is automatically generated. Do not edit. */
import { type t$2 as t$2, x$1 as x$3, f$3 as f$4 } from "./mod.rts.ts";
import { expect as expect$5 } from "vitest";
export const y$1: t$2 = x$3 + f$4;
console.log(expect$5);
console.log(y$1);

//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uL21haW4ucnRzIiwiLi4vbW9kLnJ0cyJdLCJuYW1lcyI6WyJ5IiwidCIsIngiLCJmIiwiY29uc29sZSIsImxvZyIsImV4cGVjdCJdLCJtYXBwaW5ncyI6Ijs7T0FFQSxNQUFNQSxHQUFDLEVBQUVDLElBQUUsRUFBRUMsSUFBRSxFQ0d5QkM7QURGeENDLE9BQU8sQ0FBQ0MsR0FBRyxDQUFDQyxRQUFNO0FBQ2xCRixPQUFPLENBQUNDLEdBQUcsQ0FBQ0wsR0FBQyIsImZpbGUiOiJtYWluLnJ0cy50cyJ9
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uL21haW4ucnRzIiwiLi4vbW9kLnJ0cyJdLCJuYW1lcyI6WyJ5IiwidCIsIngiLCJmIiwiY29uc29sZSIsImxvZyIsImV4cGVjdCJdLCJtYXBwaW5ncyI6Ijs7O09BRUEsTUFBTUEsR0FBQyxFQUFFQyxJQUFFLEVBQUVDLElBQUUsRUNHeUJDO0FERnhDQyxPQUFPLENBQUNDLEdBQUcsQ0FBQ0MsUUFBTTtBQUNsQkYsT0FBTyxDQUFDQyxHQUFHLENBQUNMLEdBQUMiLCJmaWxlIjoibWFpbi5ydHMudHMifQ==
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-024",
"cookie": "rewrite-ts-025",
"imports": [],
"exported_identifiers": {
"x": [
Expand Down
3 changes: 2 additions & 1 deletion test-project/.rts/mod.rts.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* This file is automatically generated. Do not edit. */
export const x$1 = 12;
export type t$2 = number;
export const f$3 = 13;

//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uL21vZC5ydHMiXSwibmFtZXMiOlsieCIsInQiLCJmIl0sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLE1BQU1BLElBQUUsRUFBRSxFQUFFO0FBQ25CLE9BQU8sS0FBS0MsSUFBRSxFQUFFLE1BQU07T0FFdEIsTUFBTUMsSUFBRSxFQUFFIiwiZmlsZSI6Im1vZC5ydHMudHMifQ==
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uL21vZC5ydHMiXSwibmFtZXMiOlsieCIsInQiLCJmIl0sIm1hcHBpbmdzIjoiO0FBQUEsT0FBTyxNQUFNQSxJQUFFLEVBQUUsRUFBRTtBQUNuQixPQUFPLEtBQUtDLElBQUUsRUFBRSxNQUFNO09BRXRCLE1BQU1DLElBQUUsRUFBRSIsImZpbGUiOiJtb2QucnRzLnRzIn0=
2 changes: 1 addition & 1 deletion test-project/.rts/sourcemap1.test.rts.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"cid": "test-project/sourcemap1.test.rts rewrite-ts-visualized 0.0.0",
"cookie": "rewrite-ts-024",
"cookie": "rewrite-ts-025",
"imports": [
{
"pkg": {"name": "vitest", "version": "2.1.8"},
Expand Down
3 changes: 2 additions & 1 deletion test-project/.rts/sourcemap1.test.rts.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* This file is automatically generated. Do not edit. */
import { suite as suite$1, test as test$2, expect as expect$5 } from "vitest";
suite$1("source mapping for errors", () => {
test$2("simple error", () => {
Expand All @@ -7,4 +8,4 @@ suite$1("source mapping for errors", () => {
});
});

//# sourceMappingURL=data:application/json;charset=utf-8;base64,e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