compiler icon indicating copy to clipboard operation
compiler copied to clipboard

Logical operator breaks dev and build

Open marcosmartini opened this issue 2 years ago • 4 comments

What version of astro are you using?

2.0.6

Are you using an SSR adapter? If so, which one?

None

What package manager are you using?

npm

What operating system are you using?

Mac

Describe the Bug

When using a logical operator (<=), Astro breaks and thinks there is something wrong with a fragment.

Code example:

<Layout title="Welcome to Astro.">
	<main>
		{
			[1,2,3,4,5,6,7,8,9].filter((_, index) => index <= 6 ).map(n => (
				<div>{n}</div>
			))
		}
	</main>
</Layout>

The following breaks it: index <= 6

Link to Minimal Reproducible Example

https://stackblitz.com/edit/github-v8kbtt?file=src/pages/index.astro

Participation

  • [ ] I am willing to submit a pull request for this issue.

marcosmartini avatar Feb 06 '23 04:02 marcosmartini

I found that by removing all the spaces between the StartExpression( { ) and the TextToken it compiles successfully.

<Layout title="Welcome to Astro.">
	<main>
		{[1,2,3,4,5,6,7,8,9].filter((_, index) => index <= 6 ).map(n => (
				<div>{n}</div>
			))
		}
	</main>
</Layout>

Strange bug, probably caused by the tokenizer in the compiler.

cijiugechu avatar Feb 06 '23 16:02 cijiugechu

Thanks, @cijiugechu, that works!

marcosmartini avatar Feb 07 '23 03:02 marcosmartini

Moving to the compiler repo, thank you for investigating!

Princesseuh avatar Feb 08 '23 19:02 Princesseuh