Skip to content

[docs-infra] Highlight JavaScript with the TypeScript grammar - #1775

Draft
brijeshb42 wants to merge 1 commit into
di-migration-import-extensionsfrom
di-migration-js-grammar
Draft

[docs-infra] Highlight JavaScript with the TypeScript grammar#1775
brijeshb42 wants to merge 1 commit into
di-migration-import-extensionsfrom
di-migration-js-grammar

Conversation

@brijeshb42

Copy link
Copy Markdown
Contributor

Stacked on #1774, which is stacked on #1773. Review those first.

Problem

.js resolved to source.js, which classifies less than source.ts does. Same code, two grammars:

case source.js source.tsx
/ab+c/g not recognised as a regular expression pl-s pl-sr with delimiters
a < b && c > d identifiers unclassified identifiers pl-smi
#x = 1 unclassified pl-v
export default x default is pl-c1 default is pl-k

The last row is visible to readers: a file and its TypeScript twin were highlighted differently, so default changed colour when a language toggle switched between them.

Change

The JavaScript family shares source.tsx. TypeScript is a superset, so everything source.js classified is still classified, and .jsx already resolved there.

Comparisons are unaffected — a < b stays punctuation rather than opening an element. I checked regular expressions, private class fields, optional chaining, async generators, and JSX before changing the map.

Notes

  • JSX in a .js file no longer needs a language override. DemoEntry.language is still there for extensions that pick no grammar of their own.
  • One precomputeDemo test asserted the old behaviour — that a .js entry does not highlight JSX without an override. It now asserts the opposite, with the override case moved to an unmapped extension.

@code-infra-dashboard

code-infra-dashboard Bot commented Aug 14, 2026

Copy link
Copy Markdown

Deploy preview

Bundle size

Total Size Change: 🔺+334B(+0.01%) - Total Gzip Change: 🔺+95B(+0.01%)
Files: 69 total (0 added, 0 removed, 3 changed)

Show details for 69 more bundles

@mui/internal-docs-infra/CodeProviderparsed: 🔺+331B(+0.21%) gzip: 🔺+99B(+0.21%)
CodeHighlighterClientparsed: 🔺+3B(+0.01%) gzip: ▼-5B(-0.02%)
@mui/internal-docs-infra/abstractCreateDemoparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/abstractCreateDemoClientparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/abstractCreateStreamparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/abstractCreateTypesparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/ChunkProviderparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/cliparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/CodeControllerContextparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/CodeExternalsContextparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/CodeHighlighterparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/CodeHighlighter/errorsparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/CodeHighlighter/typesparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/CoordinatedLazyparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/CoordinatedLazy/typesparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/createDemoDataparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/createDemoData/typesparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/createSitemapparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/createSitemap/typesparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/useCodeparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/useCodeWindowparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/useCoordinatedparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/useCopierparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/useCrossTabStateparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/useDemoparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/useDemoControllerparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/useErrorsparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/useLocalStorageStateparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/usePreferenceparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/useScrollAnchorparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/useSearchparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/useSearch/typesparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/useStreamparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/useStream/typesparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/useTypeparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/useTypesparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/useUrlHashStateparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/withDocsInfraparsed: 0B(0.00%) gzip: 0B(0.00%)
addLineGuttersparsed: 0B(0.00%) gzip: 0B(0.00%)
BuildEngineparsed: 0B(0.00%) gzip: 0B(0.00%)
CodeHighlighterChunkparsed: 0B(0.00%) gzip: 0B(0.00%)
CodeInitialSourceLoaderparsed: 0B(0.00%) gzip: 0B(0.00%)
CodeSourceLoaderparsed: 0B(0.00%) gzip: 0B(0.00%)
compileCssWithPostcssparsed: 0B(0.00%) gzip: 0B(0.00%)
createFrameparsed: 0B(0.00%) gzip: 0B(0.00%)
createParseSourceWorkerClientparsed: 0B(0.00%) gzip: 🔺+1B(+0.11%)
EditingEngineparsed: 0B(0.00%) gzip: 0B(0.00%)
embedTransformsparsed: 0B(0.00%) gzip: 0B(0.00%)
enhanceCodeEmphasisparsed: 0B(0.00%) gzip: 0B(0.00%)
findExpandingRangesparsed: 0B(0.00%) gzip: 0B(0.00%)
getHastTextContentparsed: 0B(0.00%) gzip: 0B(0.00%)
grammarLoadersparsed: 0B(0.00%) gzip: 0B(0.00%)
grammarsparsed: 0B(0.00%) gzip: 0B(0.00%)
isFrameSpanparsed: 0B(0.00%) gzip: 0B(0.00%)
loadIsomorphicCodeVariantparsed: 0B(0.00%) gzip: 0B(0.00%)
parseSourceparsed: 0B(0.00%) gzip: 0B(0.00%)
rolldown-runtimeparsed: 0B(0.00%) gzip: 0B(0.00%)
source.cssparsed: 0B(0.00%) gzip: 0B(0.00%)
source.jsparsed: 0B(0.00%) gzip: 0B(0.00%)
source.jsonparsed: 0B(0.00%) gzip: 0B(0.00%)
source.mdxparsed: 0B(0.00%) gzip: 0B(0.00%)
source.shellparsed: 0B(0.00%) gzip: 0B(0.00%)
source.tsparsed: 0B(0.00%) gzip: 0B(0.00%)
source.tsxparsed: 0B(0.00%) gzip: 0B(0.00%)
source.yamlparsed: 0B(0.00%) gzip: 0B(0.00%)
text.html.basicparsed: 0B(0.00%) gzip: 0B(0.00%)
text.mdparsed: 0B(0.00%) gzip: 0B(0.00%)
TransformEngineparsed: 0B(0.00%) gzip: 0B(0.00%)
transpileSourceparsed: 0B(0.00%) gzip: 0B(0.00%)

Details of bundle changes

Performance

Total duration: 17.80 ms +1.91 ms(+12.1%) | Renders: 5 (+0) | Paint: 63.44 ms +6.83 ms(+12.1%)

Test Duration Renders
DataGrid mount with paint timing 4.04 ms 🔺+1.91 ms(+89.6%) 1 (+0)
custom scalar + discrete metrics 0.00 ms 0 (+0)
sub-series via labels 0.00 ms 0 (+0)

4 tests within noise — details

Metric alarms

Test Metric Change
DataGrid mount with paint timing bench:paint#grid-header 🔺 +2.73 ms
DataGrid mount with paint timing bench:paint#grid-body 🔺 +2.73 ms
DataGrid mount with paint timing bench:paint 🔺 +2.73 ms
custom scalar + discrete metrics fib_duration 🔺 +0.18 ms
sub-series via labels fib_phase#small 🔺 +0.02 ms

…and 1 more metric alarm — details


Check out the code infra dashboard for more information about this PR.

@brijeshb42 brijeshb42 added the scope: docs-infra Involves the docs-infra product (https://www.notion.so/mui-org/b9f676062eb94747b6768209f7751305). label Aug 14, 2026
@brijeshb42
brijeshb42 force-pushed the di-migration-js-grammar branch from cd88007 to be0c198 Compare August 14, 2026 06:26
@brijeshb42
brijeshb42 force-pushed the di-migration-import-extensions branch from 9e6cbcc to 821aefb Compare August 14, 2026 07:43
@github-actions github-actions Bot added the PR: out-of-date The pull request has merge conflicts and can't be merged. label Aug 14, 2026
A .js file was highlighted with source.js, which classifies less than
source.ts does: regular expression literals, private class fields, and
the identifiers in an expression all came back unclassified, and
'default' in 'export default' came back as a constant rather than a
keyword. A file and its TypeScript twin were highlighted differently,
which shows as a colour change when a language toggle switches between
them.

The JavaScript family now shares source.tsx. TypeScript is a superset,
so everything source.js classified is still classified. Comparisons are
unaffected: 'a < b' stays punctuation rather than opening an element.

Type-only styling is withheld from JavaScript, since the scope alone can
no longer tell the two apart and 'string' is an ordinary variable name
in JavaScript. That also fixes .jsx, which shared the grammar already
and was marking type names.

JSX in a .js file needs no language override as a result.
@brijeshb42
brijeshb42 force-pushed the di-migration-js-grammar branch from be0c198 to 76408ea Compare August 14, 2026 18:43
@github-actions github-actions Bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged. label Aug 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

scope: docs-infra Involves the docs-infra product (https://www.notion.so/mui-org/b9f676062eb94747b6768209f7751305).

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant