-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
fix(turbopack): Analyze for-of stmts to allow using sharp
#7424
Conversation
shart
sharp
The latest updates on your projects. Learn more about Vercel for Git ↗︎
7 Ignored Deployments
|
🟢 Turbopack Benchmark CI successful 🟢Thanks |
|
✅ This change can build |
if let JsValue::Variable(id) = &array { | ||
if let Some(value) = self.data.values.get(id) { | ||
array = value.clone(); | ||
} | ||
} |
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.
You shouldn't read from values
here. This should only happen during linking
. Imagine this example:
let y;
x();
for(const z of y) {
}
function x() {
y = [1,2,3];
}
In this case values
is not set yet while visiting the for of loop.
Instead you need to keep the Variable
and have some operation that converts an array to all iterated values of it: JsValue::Iterated
.
Now you can define a built-in transform for JsValue::Iterated(JsValue::Array(...))
to JsValue::Alternatives
.
if let JsValue::Array { items, .. } = array { | ||
for item in items { | ||
let mut ast_path = | ||
ast_path.with_guard(AstParentNodeRef::ForOfStmt(n, ForOfStmtField::Left)); | ||
|
||
self.current_value = Some(item); | ||
|
||
self.visit_for_head(&n.left, &mut ast_path); | ||
} | ||
|
||
let mut ast_path = | ||
ast_path.with_guard(AstParentNodeRef::ForOfStmt(n, ForOfStmtField::Body)); | ||
|
||
self.visit_stmt(&n.body, &mut ast_path); | ||
} else { | ||
n.visit_children_with_path(self, ast_path); | ||
} |
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.
We don't want to visit the AST nodes multiple times. Just once.
path = ( | ||
| `../src/build/Release/sharp-${runtimePlatform}.node` | ||
| "../src/build/Release/sharp-wasm32.node" | ||
| `@img/sharp-${runtimePlatform}/sharp.node` | ||
| "@img/sharp-wasm32/sharp.node" | ||
) |
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.
It's unexpected that it already has this value here. It should have some kind of operation of paths
. Maybe path = Iterated(paths)
Co-authored-by: Tobias Koppers <tobias.koppers@googlemail.com>
Co-authored-by: Tobias Koppers <tobias.koppers@googlemail.com>
Co-authored-by: Tobias Koppers <tobias.koppers@googlemail.com>
* vercel/turbo#7437 <!-- Tobias Koppers - report relative start/end and fix start time for events --> * vercel/turbo#7446 <!-- Tobias Koppers - allow to aggregate all spans --> * vercel/turbo#6651 <!-- max - fix(postcss_configs): support for resolve `postcss.config.json` file --> * vercel/turbo#7448 <!-- Leah - chore: remove "rust" npm package --> * vercel/turbo#7436 <!-- Leah - refactor(turbo-tasks-fs): move file watching into separate file --> * vercel/turbo#7396 <!-- Donny/강동윤 - feat(turbopack): Apply critical ES lint rules --> * vercel/turbo#7421 <!-- Donny/강동윤 - fix(turbopack): Use different title for non-parsing issues --> * vercel/turbo#7501 <!-- Tobias Koppers - Tracing: Report progress on initial read --> * vercel/turbo#7508 <!-- Donny/강동윤 - fix(turbopack): Fix CSS Modules of turbopack in swc mode --> * vercel/turbo#7424 <!-- Donny/강동윤 - fix(turbopack): Analyze for-of stmts to allow using `sharp` --> * vercel/turbo#7510 <!-- Tobias Koppers - dedupe primary_modules to avoid deduping in chunking, reduce memory usage --> * vercel/turbo#7509 <!-- Tobias Koppers - split graph_node_to_referenced_nodes into cacheable and non-cacheable parts --> * vercel/turbo#7516 <!-- Tobias Koppers - fix ignore in package.json --> * vercel/turbo#7500 <!-- Tobias Koppers - add span count to trace-server --> * vercel/turbo#7507 <!-- Donny/강동윤 - fix(turbopack): Fix CSS module purity validator -->
Description
Analyze code like
Testing Instructions
Look at test changes.
sharp
when usingplaiceholder
next.js#62088