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

(typescript) Highlighting breaks if using ' in a comment word (e.g // don't) #3995

Closed
paladox opened this issue Feb 20, 2024 · 3 comments
Closed
Labels
bug help welcome Could use help from community language

Comments

@paladox
Copy link
Member

paladox commented Feb 20, 2024

Describe the issue

Which language seems to have the issue?
Typescript

Are you using highlight or highlightAuto?
highlight

Sample Code to Reproduce
You can reproduce with the following on https://highlightjs.org/demo

  private renderHeaderTitle() {
    const changeStatuses = this.computeChangeStatusChips();
    const resolveWeblinks =
      this.revision?.commit?.resolve_conflicts_web_links ?? [];
    return html` <div class="headerTitle">
      <div class="changeStatuses">
        ${changeStatuses.map(
          status => html` <gr-change-status
            .revertedChange=${this.revertingChange}
            .status=${status}
            .resolveWeblinks=${resolveWeblinks}
          ></gr-change-status>`
        )}
      </div>
      ${this.renderCopyLinksDropdown()}
      <gr-button
        flatten
        down-arrow
        class="showCopyLinkDialogButton"
        @click=${(e: MouseEvent) => {
          // We don't want to handle clicks on the star or the <a> link.
          // Calling `stopPropagation()` from the click handler of <a> is not an
          // option, because then the click does not reach the top-level gr-page
          // click handler and would result is a full page reload.
          if ((e.target as HTMLElement)?.nodeName !== 'GR-BUTTON') return;
          this.copyLinksDropdown?.toggleDropdown();
        }}
        ><gr-change-star
          id="changeStar"
          .change=${this.change}
          @toggle-star=${(e: CustomEvent<ChangeStarToggleStarDetail>) =>
            this.handleToggleStar(e)}
          ?hidden=${!this.loggedIn}
        ></gr-change-star>
        <a
          class="changeNumber"
          aria-label=${`Change ${this.change?._number}`}
          href=${ifDefined(this.computeChangeUrl(true))}
          >${this.change?._number}</a
        >
      </gr-button>
      <span class="headerSubject">${this.change?.subject}</span>
      <gr-copy-clipboard
        class="changeCopyClipboard"
        hideInput=""
        text=${this.computeCopyTextForTitle()}
      >
      </gr-copy-clipboard>
    </div>`;
  }
Screenshot 2024-02-20 at 13 34 34

Expected behavior
Highlighting not to break after ${(e: MouseEvent) => {

Additional context
Happens on https://gerrit-review.googlesource.com/c/gerrit/+/410005/2/polygerrit-ui/app/elements/change/gr-change-view/gr-change-view.ts

@paladox paladox added bug help welcome Could use help from community language labels Feb 20, 2024
@paladox
Copy link
Member Author

paladox commented Feb 20, 2024

Oh... it appears to be due to the use of // within ${(e: MouseEvent) => {

Ah because of ' in don't.

@paladox paladox changed the title (typescript) Highlighting breaks if using ${(e: MouseEvent) => {} in html tag (typescript) Highlighting breaks if using ' in a comment word (e.g // don't) Feb 20, 2024
@paladox
Copy link
Member Author

paladox commented Feb 20, 2024

Seems a comment isn't properly highlighted as a comment within ${(e: MouseEvent) => {. As you can see if you do it in private renderHeaderTitle() {, it's grey. But within ${(e: MouseEvent) => { it's red. Highlighting breaks when using a '.

@joshgoebel
Copy link
Member

We don't really support JSX/TSX very well - it's quite hard without a real parser. Closing this as a duplicate of #2998.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug help welcome Could use help from community language
Projects
None yet
Development

No branches or pull requests

2 participants