Skip to content

tsx: multiline JSX tags lose tag and attribute classification #6

Description

@mehdibha

Version: @tanstack/highlight 0.0.9

When a JSX element's attributes span multiple lines, neither the tag name nor its attributes are classified — the tag name falls back to the Capitalized-identifier type class and the attributes come out plain (or property when they read like member access).

Repro

import { createHighlighter } from '@tanstack/highlight/core'
import { tsx } from '@tanstack/highlight/languages/tsx'

const h = createHighlighter({ languages: [tsx] })
const code = `<AriaLink
  href={props.href}
  render={({ ref }) => null}
/>`
console.log(h.tokenize(code, { lang: 'tsx' }).tokens)

Actual:

["<", ["AriaLink","type"], "\n  href={props.", ["href","property"], "}\n  render={({ ref }) => ", ["null","literal"], "}\n/>"]
  • AriaLink is classed type, not tag
  • href / render attribute names get no attr class

Single-line elements work as expected — <Input value={value} placeholder="x" /> produces tag + attr classes correctly, including for expression values. So the regression is specifically the newline inside the open tag.

Multiline formatting is what Prettier & co. emit for any element with more than a couple of attributes, so most real-world component snippets hit this.

Context: found while migrating dotui.org's docs from shiki, character-diffing both engines over our full corpus (~733k chars of tsx).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions