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

Use legal format for compiler version comment #4621

Open
cardoso opened this issue Oct 9, 2024 · 1 comment
Open

Use legal format for compiler version comment #4621

cardoso opened this issue Oct 9, 2024 · 1 comment
Labels
tests Up for grabs Issues that are relatively small, self-contained, and ready for implementation

Comments

@cardoso
Copy link
Contributor

cardoso commented Oct 9, 2024

Is your feature request related to a problem? Please describe.

Bundlers will often strip most comments even in development mode. The only exception being comments inside classes. The behavior can sometimes be changed through configuration, but most notably in the case of ESBuild, there's no way to keep the comments as it is. This makes it difficult to work with tools that use esbuild under the hood, like Vite and consequently Vitest.

esbuild playground

Input

class Test extends Component {
  /*LWC compiler vX.X.X*/
}

function CustomElement() {
  return LightningElement.apply(this, arguments);
  /*LWC compiler vX.X.X*/
}

function tmpl() {
  return [];
  /*LWC compiler vX.X.X*/
}

function stylesheet() {
  return '';
  /*LWC compiler vX.X.X*/
}

Output

class Test extends Component {
  /*LWC compiler vX.X.X*/
}
function CustomElement() {
  return LightningElement.apply(this, arguments);
}
function tmpl() {
  return [];
}
function stylesheet() {
  return "";
}

This causes the compiler to not log errors when stylesheets and templates are compiled under a different version.

I've also tested OXC, which is used by Rolldown (which will replace ESBuild for Vite in the future), and could find no way to keep any kind of comments. With SWC it was possible, but not obvious and often had mixed results (most funny an instance where comments were kept in functions but not classes which is the opposite of the example above and just as broken).

Describe the solution you'd like

In the short term it would help producing comments in the form of /*!LWC compiler v123.456.789*/ or most likely, for forwards compatibility, /*!/*LWC compiler v123.456.789*/. This is due to esbuild's support for legal comments.

The latter was the solution I had to use in #4594 .

In the long term, it would be better to move away from comments (or just comments).

@nolanlawson nolanlawson added tests Up for grabs Issues that are relatively small, self-contained, and ready for implementation labels Oct 14, 2024
@nolanlawson
Copy link
Collaborator

Using the "legal comments" format seems fine to me. The whole goal here is just to have a nice console.error message in dev mode. (It's assumed that, in dev mode, no minification occurs.)

This should be a non-breaking change and can be done outside of #4617.

@cardoso cardoso changed the title Rethink compiler version comment Use legal format for compiler version comment Oct 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tests Up for grabs Issues that are relatively small, self-contained, and ready for implementation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants