-
-
Couldn't load subscription status.
- Fork 155
Improve debugging of Mint values. #704
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| crystal 1.14.0 | ||
| mint 0.19.0 | ||
| mint 0.20.0 | ||
| nodejs 20.10.0 | ||
| yarn 1.22.19 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,128 @@ | ||
| import indentString from "indent-string"; | ||
| import { isVnode } from './equality'; | ||
| import { Variant } from './variant'; | ||
| import { Name } from './symbols'; | ||
|
|
||
| const render = (items, prefix, suffix, fn) => { | ||
| items = | ||
| items.map(fn); | ||
|
|
||
| const newLines = | ||
| items.size > 3 || items.filter((item) => item.indexOf("\n") > 0).length; | ||
|
|
||
| const joined = | ||
| items.join(newLines ? ",\n" : ", "); | ||
|
|
||
| if (newLines) { | ||
| return `${prefix.trim()}\n${indentString(joined, 2)}\n${suffix.trim()}`; | ||
| } else { | ||
| return `${prefix}${joined}${suffix}`; | ||
| } | ||
| } | ||
|
|
||
| const toString = (object) => { | ||
| if (object.type === "null") { | ||
| return "null"; | ||
| } else if (object.type === "undefined") { | ||
| return "undefined"; | ||
| } else if (object.type === "string") { | ||
| return `"${object.value}"`; | ||
| } else if (object.type === "number") { | ||
| return `${object.value}`; | ||
| } else if (object.type === "boolean") { | ||
| return `${object.value}`; | ||
| } else if (object.type === "element") { | ||
| return `<${object.value.toLowerCase()}>` | ||
| } else if (object.type === "variant") { | ||
| if (object.items) { | ||
| return render(object.items, `${object.value}(`, `)`, toString); | ||
| } else { | ||
| return object.value; | ||
| } | ||
| } else if (object.type === "array") { | ||
| return render(object.items, `[`, `]`, toString); | ||
| } else if (object.type === "object") { | ||
| return render(object.items, `{ `, ` }`, toString); | ||
| } else if (object.type === "record") { | ||
| return render(object.items, `${object.value} { `, ` }`, toString); | ||
| } else if (object.type === "unknown") { | ||
| return `{ ${object.value} }`; | ||
| } else if (object.type === "vnode") { | ||
| return `VNode`; | ||
| } else if (object.key) { | ||
| return `${object.key}: ${toString(object.value)}`; | ||
| } else if (object.value) { | ||
| return toString(object.value); | ||
| } | ||
| } | ||
|
|
||
| const objectify = (value) => { | ||
| if (value === null) { | ||
| return { type: "null" }; | ||
| } else if (value === undefined) { | ||
| return { type: "undefined" }; | ||
| } else if (typeof value === "string") { | ||
| return { type: "string", value: value }; | ||
| } else if (typeof value === "number") { | ||
| return { type: "number", value: value.toString() }; | ||
| } else if (typeof value === "boolean") { | ||
| return { type: "boolean", value: value.toString() }; | ||
| } else if (value instanceof HTMLElement) { | ||
| return { type: "element", value: value.tagName }; | ||
| } else if (value instanceof Variant) { | ||
| const items = []; | ||
|
|
||
| if (value.record) { | ||
| for (const key in value) { | ||
| if (key === "length" || key === "record" || key.startsWith("_")) { | ||
| continue; | ||
| }; | ||
|
|
||
| items.push({ | ||
| value: objectify(value[key]), | ||
| key: key | ||
| }); | ||
| } | ||
| } else { | ||
| for (let i = 0; i < value.length; i++) { | ||
| items.push({ | ||
| value: objectify(value[`_${i}`]) | ||
| }); | ||
| }; | ||
| } | ||
|
|
||
| if (items.length) { | ||
| return { type: "variant", value: value[Name], items: items }; | ||
| } else { | ||
| return { type: "variant", value: value[Name] }; | ||
| } | ||
| } else if (Array.isArray(value)) { | ||
| return { | ||
| items: value.map((item) => ({ value: objectify(item) })), | ||
| type: "array" | ||
| }; | ||
| } else if (isVnode(value)) { | ||
| return { type: "vnode" } | ||
| } else if (typeof value == "object") { | ||
| const items = []; | ||
|
|
||
| for (const key in value) { | ||
| items.push({ | ||
| value: objectify(value[key]), | ||
| key: key | ||
| }); | ||
| }; | ||
|
|
||
| if (Name in value) { | ||
| return { type: "record", value: value[Name], items: items }; | ||
| } else { | ||
| return { type: "object", items: items }; | ||
| } | ||
| } else { | ||
| return { type: "unknown", value: value.toString() }; | ||
| } | ||
| } | ||
|
|
||
| export const inspect = (value) => { | ||
| return toString(objectify(value)) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| export const Equals = Symbol("Equals"); | ||
| export const Name = Symbol('Name'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| import { variant, newVariant, inspect, record } from "../index_testing"; | ||
| import { expect, test, describe } from "vitest"; | ||
|
|
||
| test("inspecting null", () => { | ||
| expect(inspect(null)).toBe("null"); | ||
| }); | ||
|
|
||
| test("inspecting undefined", () => { | ||
| expect(inspect(undefined)).toBe("undefined"); | ||
| }); | ||
|
|
||
| test("inspecting string", () => { | ||
| expect(inspect("Hello")).toBe(`"Hello"`); | ||
| }); | ||
|
|
||
| test("inspecting number", () => { | ||
| expect(inspect(0)).toBe(`0`); | ||
| }); | ||
|
|
||
| test("inspecting boolean", () => { | ||
| expect(inspect(true)).toBe(`true`); | ||
| }); | ||
|
|
||
| test("inspecting boolean", () => { | ||
| expect(inspect({props: {}, type: {}, ref: {}, key: {},"__": {}})).toBe(`VNode`); | ||
| }); | ||
|
|
||
| test("inspecting object", () => { | ||
| expect(inspect({ name: "Joe" })).toBe(`{ name: "Joe" }`); | ||
| }); | ||
|
|
||
| test("inspecting element", () => { | ||
| expect(inspect(document.createElement("div"))).toBe(`<div>`); | ||
| }); | ||
|
|
||
| test("inspecting element", () => { | ||
| expect(inspect(document.createElement("div"))).toBe(`<div>`); | ||
| }); | ||
|
|
||
| test("inspecting variant", () => { | ||
| const Test = variant(0, `Test`) | ||
| expect(inspect(newVariant(Test)())).toBe(`Test`); | ||
| }); | ||
|
|
||
| test("inspecting variant (with parameters)", () => { | ||
| const Test = variant(1, `Test`) | ||
| expect(inspect(newVariant(Test)("Hello"))).toBe(`Test("Hello")`); | ||
| }); | ||
|
|
||
| test("inspecting variant (with named parameters)", () => { | ||
| const Test = variant(["a", "b"], `Test`) | ||
| expect(inspect(newVariant(Test)("Hello", "World!"))).toBe(`Test(a: "Hello", b: "World!")`); | ||
| }); | ||
|
|
||
| test("inspecting record", () => { | ||
| const Test = record(`Test`) | ||
| expect(inspect(Test({ a: "Hello", b: "World!"}))).toBe(`Test { a: "Hello", b: "World!" }`); | ||
| }); | ||
|
|
||
| test("inspecting array", () => { | ||
| expect(inspect(["Hello", "World!"])).toBe(`["Hello", "World!"]`); | ||
| }); | ||
|
|
||
| test("inspecting unkown", () => { | ||
| expect(inspect(Symbol("WTF"))).toBe(`{ Symbol(WTF) }`); | ||
| }); | ||
|
|
||
| test("inspecting nested", () => { | ||
| expect(inspect({ a: "Hello", b: "World!", nested: { x: "With new line!\nYes!"}})).toBe(`{ | ||
| a: "Hello", | ||
| b: "World!", | ||
| nested: { | ||
| x: "With new line! | ||
| Yes!" | ||
| } | ||
| }`); | ||
| }); |
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.