-
-
Notifications
You must be signed in to change notification settings - Fork 524
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
WIP: feat: adds frag
snippet
#738
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { describe, it } from "node:test"; | ||
import { strictEqual as equal } from "node:assert"; | ||
import expand, { UserConfig } from "../src"; | ||
|
||
describe("frag", () => { | ||
const config: UserConfig = { options: { "jsx.enabled": true } }; | ||
|
||
it("should expand fragment", () => { | ||
// should it work without explicit jsx.enabled ? It's not a valid html tag afaik | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here is the question i had. Should the result actually be expanded to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it’s OK to expand to |
||
equal(expand("frag"), "<></>"); | ||
// invalid result, adds one more fragment | ||
equal(expand("frag", config), "<></>"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TODO: actual result is invalid ( |
||
}); | ||
|
||
it("should wrap any content with fragment", () => { | ||
equal( | ||
expand("frag", { ...config, text: "frag test" }), | ||
"<>frag test</>" | ||
); | ||
}); | ||
|
||
it("should preserve formatting", () => { | ||
equal( | ||
expand("frag", { | ||
...config, | ||
text: "test\n\ttext\twith\nsome\t\tformatting", | ||
}), | ||
"<>test\n\ttext\twith\nsome\t\tformatting</>" | ||
); | ||
}); | ||
|
||
it("should wrap jsx with fragment", () => { | ||
equal( | ||
expand("frag", { ...config, text: "<span>foo</span>" }), | ||
"<><span>foo</span></>" | ||
); | ||
equal( | ||
expand("frag", { ...config, text: "foo<div>foo</div>" }), | ||
"<>foo<div>foo</div></>" | ||
); | ||
}); | ||
|
||
it("should wrap fragment with fragment", () => { | ||
equal( | ||
expand("frag", { ...config, text: "<>nested</>" }), | ||
"<><>nested</></>" | ||
); | ||
}); | ||
|
||
it("should wrap snippets with fragment", () => { | ||
// invalid result, adds one more fragment at start | ||
equal( | ||
expand("frag>ul>li*4", config), | ||
"<><ul>\n\t<li></li>\n\t<li></li>\n\t<li></li>\n\t<li></li>\n</ul></>" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TODO: actual result is invalid ( |
||
); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That defineitely should be tweaked, but Im not sure yet if its a valid way to handle jsx fragment in general
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, nodes without name could be a
(group)
, e.g.(ul>.item*4)+footer