-
Notifications
You must be signed in to change notification settings - Fork 59
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
Don't ignore whitespace in expressions #930
Changes from all commits
9360bfe
f1ddadb
1a8495c
be80b82
fb5325c
46b96bc
fdf90bf
5f41338
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@astrojs/compiler': patch | ||
--- | ||
|
||
Preserve whitespace in expressions |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -230,9 +230,6 @@ declare const Astro: Readonly<import('astro').AstroGlobal<%s, typeof %s`, propsI | |
p.addSourceMapping(n.Loc[0]) | ||
if n.FirstChild == nil { | ||
p.print("{(void 0)") | ||
} else if expressionOnlyHasComment(n) { | ||
// we do not print expressions that only contain comment blocks | ||
return | ||
Comment on lines
-233
to
-235
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. Don't ignore expressions with only comments in the TSX output 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. Interesting, I wonder why Nate added that check initially? 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. I'm not sure, I was wondering the same as that would unexpectedly remove TS directives like 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. I honestly don't remember the context! Guessing it was just a copy + paste from the JS output which has special handling for this case. |
||
} else { | ||
p.print("{") | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { convertToTSX } from '@astrojs/compiler'; | ||
import { test } from 'uvu'; | ||
import * as assert from 'uvu/assert'; | ||
|
||
test('preverve whitespace around jsx comments', async () => { | ||
const input = `{/* @ts-expect-error */} | ||
<Component prop="value"></Component> | ||
|
||
{ | ||
// @ts-expect-error | ||
} | ||
<Component prop="value"></Component> | ||
|
||
{ | ||
/* @ts-expect-error */ | ||
<Component prop="value"></Component> | ||
} | ||
|
||
{ | ||
// @ts-expect-error | ||
<Component prop="value"></Component> | ||
}`; | ||
const output = `<Fragment> | ||
{/* @ts-expect-error */} | ||
<Component prop="value"></Component> | ||
|
||
{ | ||
// @ts-expect-error | ||
} | ||
<Component prop="value"></Component> | ||
|
||
{ | ||
/* @ts-expect-error */ | ||
<Fragment><Component prop="value"></Component></Fragment> | ||
} | ||
|
||
{ | ||
// @ts-expect-error | ||
<Fragment><Component prop="value"></Component></Fragment> | ||
} | ||
</Fragment> | ||
export default function __AstroComponent_(_props: Record<string, any>): any {}\n`; | ||
const { code } = await convertToTSX(input, { sourcemap: 'external' }); | ||
assert.snapshot(code, output, `expected code to match snapshot`); | ||
}); | ||
|
||
test.run(); |
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 now need to check for whitespace too as the parser doesn't remove them in expressions anymore.