Skip to content

Commit

Permalink
inserted "undefined" variable into generated es5 lib
Browse files Browse the repository at this point in the history
  • Loading branch information
azizghuloum committed Jan 5, 2025
1 parent abddbe2 commit 1d0370d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
12 changes: 10 additions & 2 deletions src/generate-stdlibs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import TS from "typescript";
import fs from "node:fs/promises";
import { pretty_print } from "./pprint";
import stringify from "json-stable-stringify";
import { assert } from "./assert";

const libdir = "./node_modules/typescript/lib";

Expand Down Expand Up @@ -83,7 +84,7 @@ async function get_libs(start: string) {
const content = await fs.readFile(`${libdir}/lib.${libname}.d.ts`, {
encoding: "utf8",
});
const src = TS.createSourceFile("test.ts", content, {
const src = TS.createSourceFile("lib.ts", content, {
languageVersion: TS.ScriptTarget.ESNext,
});
src.statements.forEach((x) => dostmt(x, libname));
Expand All @@ -96,6 +97,13 @@ async function get_libs(start: string) {

async function get_libs(start: string) {
await readit(start);
assert(libs["es5"] !== undefined);
assert(libs["es5"].type !== undefined);
assert(libs["es5"].value !== undefined);
assert(!libs["es5"].value.includes("undefined"));
assert(!libs["es5"].type.includes("undefined"));
libs["es5"].type.unshift("undefined");
libs["es5"].value.unshift("undefined");
return libs;
}

Expand All @@ -106,7 +114,7 @@ export async function generate_libs_file(start: string) {
const libs = await get_libs(start);
const file = `
/* this file is automatically generated. do not edit. */
/* This file is automatically generated. do not edit. */
/* one more reason why macros are needed */
Expand Down
4 changes: 3 additions & 1 deletion src/generated-stdlibs.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* this file is automatically generated. do not edit. */
/* This file is automatically generated. do not edit. */

/* one more reason why macros are needed */

Expand Down Expand Up @@ -2949,6 +2949,7 @@ export const stdlibs: libs = {
],
module: ["Intl"],
type: [
"undefined",
"PropertyKey",
"ThisParameterType",
"OmitThisParameter",
Expand Down Expand Up @@ -2976,6 +2977,7 @@ export const stdlibs: libs = {
"ArrayBufferLike",
],
value: [
"undefined",
"NaN",
"Infinity",
"eval",
Expand Down

0 comments on commit 1d0370d

Please sign in to comment.