| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| a | b as c; | ||
| a as b | c; | ||
| (a as b) | c; | ||
| a as (b | c); |
There was a problem hiding this comment.
Here parens are not actually necessary, but our AST has a TSParenthesizedType node so they are preserved. Babel 8 removes the parens, because TSParenthesizedType is not enabled by default anymore.
Sorry, something went wrong.
|
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/57279 |
Sorry, something went wrong.
There was a problem hiding this comment.
This is awesome!
Sorry, something went wrong.
| function getBinaryPrecedence(node: t.Node) { | ||
| if (node.type === "BinaryExpression" || node.type === "LogicalExpression") { | ||
| return PRECEDENCE.get(node.operator); | ||
| } | ||
| if (node.type === "TSAsExpression" || node.type === "TSSatisfiesExpression") { | ||
| return PRECEDENCE.get("in"); | ||
| } | ||
| } |
There was a problem hiding this comment.
Can we add a parameter nodeType to use the parentType of the caller?
Sorry, something went wrong.
|
I noticed this PR was tagged pkg: types and there doesn't seem to be any relevant changes? |
Sorry, something went wrong.
|
by mistake :) |
Sorry, something went wrong.
|
The latest Babel version is causing breakage in Athena Crisis, and I believe this PR is related. Specifically it's breaking the common patterns below: Spread is somehow broken due to the as constexport const MoveAction = (
from: Vector,
to: Vector,
path?: ReadonlyArray<Vector> | null,
complete?: boolean,
) =>
({
...(complete ? { complete } : null),
from,
...(path ? { path } : null),
to,
type: 'Move',
}) as const;Type casting a function isn't workingexport default (function lazy(factory) {
return _lazy(() => factory().catch(importErrorHandler));
} as typeof _lazy);Source: https://github.com/nkzw-tech/athena-crisis/blob/main/ui/lib/lazy.tsx#L13-L15 The latter works with as (typeof _lazy), however prettier will strip the extraneous parenthesis. To repro you can clone the linked repo, run pnpm up -r --latest and then run pnpm vitest tests/__tests__/CreateBuildingFog.test.tsx which should show you a number of "Pre-transform error" messages. I can't tell if this is because of the pipeline (React → Babel → Vite → esbuild/swc) or if this is also an issue with Babel only but the setup is fairly common. |
Sorry, something went wrong.
|
Thanks for the report — that's an easy fix, I'll try to have it ready today. |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
We were being extra conservative and always printing parens in our code generator. This PR avoids it, by considering as/satisfies as having the same precedence on the left as in. Extra care is needed for |/&, since they are different operators at the type and value levels.