Conversation
SpacesVisitor implements visitBinary and nothing dispatches on JS.Binary, J.InstanceOf, JS.As or JS.SatisfiesExpression, so `===`, `!==`, `in`, `??`, the comma operator, `instanceof`, `as` and `satisfies` keep whatever spacing the source had, and the aroundOperators settings that name them do nothing. The punctuators take their setting the way the Java-model operators already do. The word operators take none: MinimumViableSpacingVisitor guarantees their separator earlier in the pipeline and this visitor runs after it, so honouring `relational: false` here would print `"k"ino`. Normalizing two spaces to one is what is left for it to do.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
autoFormatnormalizes the spacing around every operator the Java model already had and leaves every operator TypeScript added alone.x == ycomes back asx == y;x === ycomes back untouched. ThearoundOperatorssettings that name equality, relational and logical do nothing for those operators in either direction — withequality: false,x == ycollapses tox==ywhilex === yis left as written. Measured onmainatee6e1f0718.x ⋯ yafterautoFormatbefore this change===!==JS.Binaryx === yinJS.Binary"k" in o??JS.Binaryx ?? y,JS.Binaryx , yinstanceofJ.InstanceOfx instanceof YasJS.Asx as anysatisfiesJS.SatisfiesExpressionobj satisfies ShapeThe mechanism
SpacesVisitorimplementsvisitBinaryand nothing dispatches on the four kinds beside it. The parser decides which one you get:===,!==,in,??and the comma operator areJS.Binary, whileinstanceof,asandsatisfieshave kinds of their own.visitBinary's switch ends indefault: throw new Error("Unsupported operator type " + ...), so it was written to be reachable only fromJ.Binary$Type— the JS half was never a gap someone left open, it was never in scope.Four overrides close it. The punctuators read the same style fields
visitBinaryalready reads.Why the word operators take no setting
in,instanceof,asandsatisfiesnormalize to exactly one space and consult nothing.MinimumViableSpacingVisitorsits at index 1 of theAutoformatVisitorpipeline and guarantees their separator, but itsensureSpaceonly fills whitespace that is empty — it never collapsesx as any.SpacesVisitorsits at index 4, so a setting honoured here would undo that guarantee with nothing left to repair it, and print"k"ino.SpacesVisitoris also constructed directly by recipes that want spacing without a full autoformat, so it cannot assume the earlier visitor ran at all.That leaves it one job on those operators, which is turning two spaces into one.
WORD_OPERATOR_KEEPS_ITS_SEPARATORnames the constant so the next reader doesn't wire the setting in.One deliberate difference from
visitBinaryThe new switch's
defaultarm returns the node unchanged wherevisitBinarythrows. An operator kind added later should cost a line of unnormalized spacing, not an exception in the middle of formatting a file. Worth a second opinion if you'd rather the pair be identical.Derived styles reach this the same way they reach
==spacesFromoverrideswithin.objectLiteralBracesandwithin.es6ImportExportBracesfrombracketSpacingand spreads the fallback for the rest, andSpacesStatistics.getSpacesStylesamples indentation and the three brace cases only. Neither derivesaroundOperators, so===now resolves to the same value==already resolved to, from the same field. A project with a Prettier configuration reprints throughapplyPrettierFormattingand returns before any of this runs.Tests
Four in
spaces-visitor.test.ts: the normalization above; the settings being consulted, withequalityandlogicaloff collapsing==,===,!==,&&and??; the word operators keeping their separator withequality,relationalandlogicalall off; and a line break around??surviving. Each was confirmed to fail without the corresponding override.Scope
The keywords
MinimumViableSpacingVisitoralso protects —typeof,void,delete,await,yield,keyof,is— are prefix forms that noaroundOperatorssetting names, so normalizing their spacing is a separate question rather than part of this defect.Typecheck, build and the whole of
test/javascriptare green: 156 files, 1916 passed, 21 skipped, nothing re-baselined. The diff adds 162 lines and changes none.