Skip to content
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

Ignore trailing whitespace in files #698

Merged
merged 5 commits into from
Jan 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/short-mangos-fly.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@astrojs/compiler': patch
---

Ignore trailing whitespace in components
2 changes: 0 additions & 2 deletions .gitpod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,3 @@
tasks:
- init: pnpm install && pnpm run build && go get && go build ./... && go test ./... && make
command: go run .


6 changes: 3 additions & 3 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ issues:

- linters:
- typecheck
text: "syscall/js"
text: 'syscall/js'
- linters:
- staticcheck
text: "SA9003"
text: 'SA9003'
- linters:
- typecheck
text: "by package vert"
text: 'by package vert'
2 changes: 1 addition & 1 deletion cmd/astro-wasm/astro-wasm.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ func ConvertToTSX() any {

func Transform() any {
return js.FuncOf(func(this js.Value, args []js.Value) any {
source := jsString(args[0])
source := strings.TrimRightFunc(jsString(args[0]), unicode.IsSpace)

transformOptions := makeTransformOptions(js.Value(args[1]))
scopeStr := transformOptions.NormalizedFilename
Expand Down
33 changes: 33 additions & 0 deletions packages/compiler/test/basic/trailing-newline.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { test } from 'uvu';
import * as assert from 'uvu/assert';
import { transform } from '@astrojs/compiler';

const FIXTURE = `{
node.shouldRenderChildren() ? (
// IMPORTANT - DO NOT SELF CLOSE THIS TAG. ASTRO FREAKS OUT.
<Fragment set:html={children}></Fragment>
) : node.shouldRenderSelf() ? (
// @ts-ignore
content.map((element) => {
return <Astro.self content={element} components={components} />;
})
) : node.shouldRenderTag() ? (
<Tag {...props}>
{node.hasChildren() ? (
<Astro.self content={children} components={components} />
) : null}
</Tag>
) : null
}
`;

let result;
test.before(async () => {
result = await transform(FIXTURE);
});

test('does not add trailing newline to rendered output', () => {
assert.match(result.code, `}\`;\n}, '<stdin>');`, 'Does not include a trailing newline in the render function');
});

test.run();