-
Notifications
You must be signed in to change notification settings - Fork 2.2k
initial work for compile-time evaluation #3495
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
Changes from 26 commits
a2328a1
ab9eebe
735fb2f
91dd467
1a5cc04
f557ee3
49c65b4
7ba8e87
a1df5d5
5afa09e
a5965d3
33bc831
b199016
f3dd2bd
5069bc8
f32943a
d573980
ab246b8
641312a
7a27fef
25d5d7a
4ce3efc
e49eef1
e731362
7c1798f
b986c17
f584071
b593ef6
0c4871b
f985370
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| it("importing a not existing file should throw", () => { | ||
| // This is a check to make sure that the following tests would fail if they require("fail") | ||
| expect(() => { | ||
| require("./not-existing-file"); | ||
| }).toThrow(); | ||
| }); | ||
|
|
||
| function maybeReturn(x) { | ||
| if (x) { | ||
| return true; | ||
| } | ||
| } | ||
|
|
||
| function func() { | ||
| if (false) { | ||
| require("fail"); | ||
| import("fail"); | ||
| } | ||
| if (true) { | ||
| require("./ok"); | ||
| } | ||
| if (true) { | ||
| require("./ok"); | ||
| } else { | ||
| require("fail"); | ||
| import("fail"); | ||
| } | ||
| if (false) { | ||
| require("fail"); | ||
| import("fail"); | ||
| } else { | ||
| require("./ok"); | ||
| } | ||
| } | ||
|
|
||
| it("should not follow conditional references", () => { | ||
| func(); | ||
|
|
||
| expect(func.toString()).not.toContain("import("); | ||
| }); | ||
|
|
||
| it("should allow replacements in IIFEs", () => { | ||
| (function func() { | ||
| if (false) { | ||
| require("fail"); | ||
| import("fail"); | ||
| } | ||
| })(); | ||
| }); | ||
|
|
||
| it("should support functions that only sometimes return", () => { | ||
| let ok = false; | ||
| if (maybeReturn(true)) { | ||
| ok = true; | ||
| } | ||
| expect(ok).toBe(true); | ||
| }); | ||
|
|
||
| it("should evaluate process.turbopack", () => { | ||
| let ok = false; | ||
| if (process.turbopack) { | ||
| ok = true; | ||
| } else { | ||
| require("fail"); | ||
| import("fail"); | ||
| } | ||
| expect(ok).toBe(true); | ||
| }); | ||
|
|
||
| it("should evaluate !process.turbopack", () => { | ||
| if (!process.turbopack) { | ||
| require("fail"); | ||
| import("fail"); | ||
| } | ||
| }); | ||
|
Contributor
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. Add a test that verifies the error case as well.
Member
Author
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. What do you mean with the error case? I added a check if it runs through the "then" branch. Is that enough?
Contributor
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. The error case is when |
||
|
|
||
| // it("should evaluate NODE_ENV", () => { | ||
| // if (process.env.NODE_ENV !== "development") { | ||
| // require("fail"); | ||
| // import("fail"); | ||
| // } | ||
| // }); | ||
Uh oh!
There was an error while loading. Please reload this page.