From e37b9483351540267f2484c1ba81a0d7844f718e Mon Sep 17 00:00:00 2001 From: Ben Date: Wed, 27 Nov 2024 21:38:20 +0000 Subject: [PATCH 01/22] Random fixes --- checker/definitions/overrides.d.ts | 2 + checker/specification/specification.md | 6 +- src/ast_explorer.rs | 4 +- src/build.rs | 1 - .../comparison/comparison_generator.mjs | 17 +- src/playground/index.html | 20 ++- src/playground/main.js | 53 ++++-- src/playground/package-lock.json | 164 +++++++++--------- src/repl.rs | 6 +- 9 files changed, 156 insertions(+), 117 deletions(-) diff --git a/checker/definitions/overrides.d.ts b/checker/definitions/overrides.d.ts index b5c0e66f..15f5d3e8 100644 --- a/checker/definitions/overrides.d.ts +++ b/checker/definitions/overrides.d.ts @@ -359,6 +359,8 @@ interface PropertyDescriptor { enumerable?: boolean; } +declare class Date { } + declare class Object { @Constant static setPrototypeOf(on: object, to: object): object; diff --git a/checker/specification/specification.md b/checker/specification/specification.md index 7e2841af..3d07ddd4 100644 --- a/checker/specification/specification.md +++ b/checker/specification/specification.md @@ -4098,12 +4098,12 @@ type Required = { #### Readonly ```ts -type Mutable = { +type Immutable = { readonly [P in keyof T]: T[P]; }; interface Y { a: string } -declare let x: Mutable; +declare let x: Immutable; x.a = "hi"; ``` @@ -4122,7 +4122,7 @@ x.a = "hi"; x.a = 4; ``` - +> TODO this message is incorrect!!!!, should be string - Type 4 does not meet property constraint "hi" diff --git a/src/ast_explorer.rs b/src/ast_explorer.rs index d8fd7b8a..a29af511 100644 --- a/src/ast_explorer.rs +++ b/src/ast_explorer.rs @@ -36,13 +36,13 @@ impl ExplorerArguments { eprintln!("Could not find file at {}", file.display()); } } else { - print_to_cli(format_args!("ezno ast-explorer\nUse #exit to leave. Also #switch-mode *mode name* and #load-file *path*")); + print_to_cli(format_args!("ezno ast-explorer\nUse #exist, .exit or close() to leave. Also #switch-mode *mode name* and #load-file *path*")); loop { let input = crate::utilities::cli_input_resolver(self.nested.to_str()); if input.is_empty() { continue; - } else if input.trim() == "#exit" { + } else if let "#exit" | ".exit" | "close()" = input.trim() { break; } else if let Some(new_mode) = input.strip_prefix("#switch-mode ") { self.nested = match ExplorerSubCommand::from_str(new_mode.trim()) { diff --git a/src/build.rs b/src/build.rs index e2b4fcb0..180c501e 100644 --- a/src/build.rs +++ b/src/build.rs @@ -182,7 +182,6 @@ mod tests { use super::*; #[test] - #[ignore = "not fixed implemented"] fn tree_shaking() { let source = r#" function make_observable(obj) { diff --git a/src/playground/comparison/comparison_generator.mjs b/src/playground/comparison/comparison_generator.mjs index 6d129dc9..21184442 100644 --- a/src/playground/comparison/comparison_generator.mjs +++ b/src/playground/comparison/comparison_generator.mjs @@ -9,6 +9,17 @@ const { compressToEncodedURIComponent } = lz; const dirname = import.meta.dirname; +function escapeHTML(code) { + const lookup = { + '&': "&", + '"': """, + '\'': "'", + '<': "<", + '>': ">" + }; + return s.replace(/[&"'<>]/g, c => lookup[c]); +} + function getSpecificationSections() { const content = readFileSync(join(dirname, "../../../checker/specification/specification.md")).toString(); const output = lexer(content); @@ -85,7 +96,7 @@ async function renderDifferences(sections) { const tscPlaygroundLink = `https://www.typescriptlang.org/play?#code/${codeCompressed}`; acc += `
  • -

    ${title}

    +

    ${escapeHTML(title)}

    ${highlightedCode}
    @@ -94,14 +105,14 @@ async function renderDifferences(sections) { ezno (Playground)
    -
      ${row.ezno.map(msg => `
    • ${msg}
    • `).join("")}
    +
      ${row.ezno.map(msg => `
    • ${escapeHTML(msg)}
    • `).join("")}
    -
      ${row.tsc.map(msg => `
    • ${msg}
    • `).join("")}
    +
      ${row.tsc.map(msg => `
    • ${escapeHTML(msg)}
    • `).join("")}
    diff --git a/src/playground/index.html b/src/playground/index.html index 83ec1c92..95ab3e45 100644 --- a/src/playground/index.html +++ b/src/playground/index.html @@ -7,16 +7,16 @@ Ezno Playground - - + + - - + +
    - EZNO + EZNO

    Playground for the Ezno type checker. See @@ -37,11 +37,21 @@

    Diagnostics

    +
    More:
    +
    + + + + + + +
    +