Skip to content

Commit

Permalink
Random fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
kaleidawave committed Nov 27, 2024
1 parent 16f7779 commit e37b948
Show file tree
Hide file tree
Showing 9 changed files with 156 additions and 117 deletions.
2 changes: 2 additions & 0 deletions checker/definitions/overrides.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,8 @@ interface PropertyDescriptor {
enumerable?: boolean;
}

declare class Date { }

declare class Object {
@Constant
static setPrototypeOf(on: object, to: object): object;
Expand Down
6 changes: 3 additions & 3 deletions checker/specification/specification.md
Original file line number Diff line number Diff line change
Expand Up @@ -4098,12 +4098,12 @@ type Required<T> = {
#### Readonly

```ts
type Mutable<T> = {
type Immutable<T> = {
readonly [P in keyof T]: T[P];
};

interface Y { a: string }
declare let x: Mutable<Y>;
declare let x: Immutable<Y>;
x.a = "hi";
```

Expand All @@ -4122,7 +4122,7 @@ x.a = "hi";
x.a = 4;
```

<!-- TODO this is incorrect!!!!, should be string -->
> TODO this message is incorrect!!!!, should be string
- Type 4 does not meet property constraint "hi"

Expand Down
4 changes: 2 additions & 2 deletions src/ast_explorer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
1 change: 0 additions & 1 deletion src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,6 @@ mod tests {
use super::*;

#[test]
#[ignore = "not fixed implemented"]
fn tree_shaking() {
let source = r#"
function make_observable(obj) {
Expand Down
17 changes: 14 additions & 3 deletions src/playground/comparison/comparison_generator.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,17 @@ const { compressToEncodedURIComponent } = lz;

const dirname = import.meta.dirname;

function escapeHTML(code) {
const lookup = {
'&': "&amp;",
'"': "&quot;",
'\'': "&apos;",
'<': "&lt;",
'>': "&gt;"
};
return s.replace(/[&"'<>]/g, c => lookup[c]);
}

function getSpecificationSections() {
const content = readFileSync(join(dirname, "../../../checker/specification/specification.md")).toString();
const output = lexer(content);
Expand Down Expand Up @@ -85,7 +96,7 @@ async function renderDifferences(sections) {
const tscPlaygroundLink = `https://www.typescriptlang.org/play?#code/${codeCompressed}`;

acc += `<li>
<h3 id="${href}">${title}</h3>
<h3 id="${href}">${escapeHTML(title)}</h3>
<div>
${highlightedCode}
<div>
Expand All @@ -94,14 +105,14 @@ async function renderDifferences(sections) {
<img src="./assets/ezno.svg" alt="ezno" height="14px">
<a href="${eznoPlaygroundLink}">(Playground)</a>
</div>
<ul>${row.ezno.map(msg => `<li>${msg}</li>`).join("")}</ul>
<ul>${row.ezno.map(msg => `<li>${escapeHTML(msg)}</li>`).join("")}</ul>
</div>
<div class="tsc-diagnostics">
<div class="checker-name">
<img src="./assets/typescript.svg" alt="typescript" height="20px">
<a href="${tscPlaygroundLink}">(Playground)</a>
</div>
<ul>${row.tsc.map(msg => `<li>${msg}</li>`).join("")}</ul>
<ul>${row.tsc.map(msg => `<li>${escapeHTML(msg)}</li>`).join("")}</ul>
</div>
</div>
</div>
Expand Down
20 changes: 15 additions & 5 deletions src/playground/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@
<title>Ezno Playground</title>
<!-- Vite doesn't rewrite them :( https://github.com/vitejs/vite/issues/7362 -->
<!-- Also maybe they should be in the parent directory? -->
<meta property="twitter:image" content="/ezno/playground/assets/banner.png">
<meta property="og:image" content="/ezno/playground/assets/banner.png">
<meta property="twitter:image" content="assets/banner.png">
<meta property="og:image" content="assets/banner.png">

<link rel="stylesheet" href="assets/index.css">
<link rel="icon" href="assets/ezno.svg">
<link rel="stylesheet" href="/assets/index.css">
<link rel="icon" href="/assets/ezno.svg">
</head>

<body>
<header>
<img src="assets/ezno.svg" alt="EZNO" height="40px">
<img src="/assets/ezno.svg" alt="EZNO" height="40px">
<p>
Playground for the Ezno type checker.
<a href="https://kaleidawave.github.io/posts/the-quest-continues/#there-is-a-new-web-based-playground">See
Expand All @@ -37,11 +37,21 @@ <h3>Diagnostics</h3>
</ol>
</div>
<button id="share">Share</button>
<button id="build">Compile</button>
<details>
<summary>More:</summary>
<div id="version"></div>
<div id="time"></div>
<form action="">
<label for="">Whitespace minify</label>
<input type="checkbox" name="" id="">
<label for="">Tree shake</label>
<input type="checkbox" name="" id="">
<label for="">Run linter</label>
<input type="checkbox" name="" id="">
</form>
</details>
<pre id="build-output"></pre>
</main>
<footer>
<hr>
Expand Down
53 changes: 35 additions & 18 deletions src/playground/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,29 +39,36 @@ const theme = EditorView.theme({

const STORE = "https://kaleidawave-savednamedplaygrounds.web.val.run"

let text = "const x: 2 = 3;";
let initialText = text;
const defaultCode = "const x: string = 5;"
let text = defaultCode;

const { searchParams } = new URL(location);
const id = searchParams.get("id");
const raw = searchParams.get("raw");

const LOCAL_STORAGE_KEY = "code";

if (id) {
fetch(STORE + `?id=${id}`, { method: "GET" }).then(res => res.json()).then((result) => {
if (result.content) {
initialText = text = result.content
text = result.content;
setup()
} else if (result.error) {
alert(`Error getting code for id '${result.error}'`)
}
})
} else {
if (raw) {
initialText = text = raw;
text = raw;
} else {
text = window.localStorage.getItem(LOCAL_STORAGE_KEY) ?? defaultCode;
}
setup()
}

/** Used for not resharing same code, Mutable as set after sharing */
let initialText = text;

let currentState = null;

const ROOT_PATH = "index.tsx";
Expand All @@ -71,15 +78,16 @@ const options = {
// For hover
store_type_mappings: true,
// For showing off
number_intrinsics: true
advanced_numbers: true
};

async function setup() {
await init_ezno();

function getLinter() {
function runChecker() {
return linter((args) => {
text = args.state.doc.text.join("\n");
localStorage.setItem(LOCAL_STORAGE_KEY, text);
try {
const start = performance.now();
currentState = check(ROOT_PATH, (_) => text, options);
Expand Down Expand Up @@ -149,13 +157,18 @@ async function setup() {
return [cursor, cursorTooltipBaseTheme]
}

const tsLanguage = LRLanguage.define({
parser: jsParser.configure({ dialect: "ts" }),
languageData: { commentTokens: { line: "// " } }
});

const _editor = new EditorView({
state: EditorState.create({
doc: Text.of([text]),
extensions: [
keymap.of([...defaultKeymap, indentWithTab, toggleLineComment]),
EditorState.tabSize.of(4),
new LanguageSupport(LRLanguage.define({ parser: jsParser.configure({ dialect: "ts" }), languageData: { commentTokens: { line: "// " } } }), [getLinter()]),
new LanguageSupport(tsLanguage, [runChecker()]),
syntaxHighlighting(myHighlightStyle),
getHover(),
theme,
Expand All @@ -178,18 +191,22 @@ async function setup() {
fetch(STORE, {
method: "POST",
body: JSON.stringify({ content: text })
}).then(res => res.json()).then((result) => {
if (result.id) {
url.searchParams.set("id", result.id);
url.searchParams.delete("raw");
history.pushState({}, "", url);
navigator.clipboard.writeText(url.toString()).then(() => {
alert("Share URL copied to clipboard")
});
} else if (result.error) {
alert(`Error sharing code '${result.error}'`)
}
})
.then(res => res.json())
.then((result) => {
if (result.id) {
url.searchParams.set("id", result.id);
url.searchParams.delete("raw");
history.pushState({}, "", url);
navigator.clipboard
.writeText(url.toString())
.then(() => {
alert("Share URL copied to clipboard")
});
} else if (result.error) {
alert(`Error sharing code '${result.error}'`)
}
})
} else {
alert("Sharing existing code")
}
Expand Down
Loading

0 comments on commit e37b948

Please sign in to comment.