Skip to content

fix: remove extra margin between multiline object#100

Merged
Rich-Harris merged 9 commits intomainfrom
fix/object-margin
Jan 20, 2026
Merged

fix: remove extra margin between multiline object#100
Rich-Harris merged 9 commits intomainfrom
fix/object-margin

Conversation

@jycouet
Copy link
Copy Markdown
Contributor

@jycouet jycouet commented Dec 5, 2025

I'm not sure if it was on purpose or not.

With today's margin, vite config looks like https://github.com/sveltejs/cli/blob/main/packages/sv/lib/cli/tests/snapshots/create-with-all-addons/vite.config.ts

What do you think ?

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Dec 5, 2025

🦋 Changeset detected

Latest commit: 3b0f385

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
esrap Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Dec 5, 2025

npm i https://pkg.pr.new/sveltejs/esrap@100

commit: 3b0f385

@manuel3108
Copy link
Copy Markdown
Member

I'm pretty sure this was added intentionally as this is the way code is formatted inside esrap and svelte codebases:

AssignmentExpression(node, context) {
context.visit(node.left);
context.write(` ${node.operator} `);
context.visit(node.right);
},
AssignmentPattern(node, context) {
context.visit(node.left);
context.write(' = ');
context.visit(node.right);
},

and

https://github.com/sveltejs/svelte/blob/965bf6ceec0c6ee5347df6b04781fe9fe41aa5a5/packages/svelte/src/compiler/print/index.js#L455-L465

I haven't checked many more places, but this does appear to be intentional. But I do agree that this looks weird in some places like you showed. Maybe we could avoid adding this extra line break if [i-1] and [i] are ObjectExpressions? That should solve the problem at hand and still work good for other use cases

@jycouet
Copy link
Copy Markdown
Contributor Author

jycouet commented Jan 19, 2026

extra line break if [i-1] and [i] are ObjectExpressions

That is just better!

Copy link
Copy Markdown
Member

@manuel3108 manuel3108 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, hoping for another approval though :D

Copy link
Copy Markdown
Member

@Rich-Harris Rich-Harris left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure this is quite right — the test in this PR also passes on main, but IIUC the intent is to format things like this (in other words margin should only apply to statements, I guess?):

const obj = {
	before: 1,
	object: {
		a: 'lorem ipsum dolor sit amet',
		b: 'lorem ipsum dolor sit amet',
		c: 'lorem ipsum dolor sit amet',
		d: 'lorem ipsum dolor sit amet',
		e: 'lorem ipsum dolor sit amet'
	},
	array: [
		'lorem ipsum dolor sit amet',
		'lorem ipsum dolor sit amet',
		'lorem ipsum dolor sit amet',
		'lorem ipsum dolor sit amet',
		'lorem ipsum dolor sit amet'
	],
	after: 2
};

Right now, there's an unwanted new line between object and array:

const obj = {
	before: 1,
	object: {
		a: 'lorem ipsum dolor sit amet',
		b: 'lorem ipsum dolor sit amet',
		c: 'lorem ipsum dolor sit amet',
		d: 'lorem ipsum dolor sit amet',
		e: 'lorem ipsum dolor sit amet'
	},

	array: [
		'lorem ipsum dolor sit amet',
		'lorem ipsum dolor sit amet',
		'lorem ipsum dolor sit amet',
		'lorem ipsum dolor sit amet',
		'lorem ipsum dolor sit amet'
	],
	after: 2
};

@jycouet jycouet requested a review from Rich-Harris January 20, 2026 18:06
@jycouet
Copy link
Copy Markdown
Contributor Author

jycouet commented Jan 20, 2026

Thx, updated with your test

Copy link
Copy Markdown
Member

@Rich-Harris Rich-Harris left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@Rich-Harris Rich-Harris merged commit 8f2fc99 into main Jan 20, 2026
9 of 10 checks passed
@Rich-Harris Rich-Harris deleted the fix/object-margin branch January 20, 2026 18:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants