marko-js / htmljs-parser

An HTML parser recognizes content and string placeholders and allows JavaScript expressions as attribute values
MIT License
135 stars 20 forks source link

Unable to export multiline types #166

Closed vwong closed 1 year ago

vwong commented 1 year ago

Version

5.5.0

Details

I have this line in my icons.marko file:

export type IconType = "error" | "information" | "unknown" | "success" | "warning";

Consumers of this can import the IconType and everything works correctly.

When I run prettier through this, it gets reformatted to:

export type IconType =
  | "error"
  | "information"
  | "unknown"
  | "success"
  | "warning";

Still looks like valid code, but I now get compile errors.

DylanPiercey commented 1 year ago

This is a known limitation of the htmljs parser, specifically that these top level statements are terminated by unbracket enclosed newlines.

Making this change to follow operators on the next line would cause code like the following to break:

export const x = "hi"

.myclass

Currently parses as:

export const x = "hi";

<div class="myclass"></div>

but if we followed expressions it'd confusingly be:

export const x = "hi".myclass;

Either way the fact that prettier is outputting something that is incompatible with what Marko can parse is definitely a problem. I've created a fix for that over here https://github.com/marko-js/prettier/pull/40