[docs-infra] Highlight JavaScript with the TypeScript grammar - #1775
[docs-infra] Highlight JavaScript with the TypeScript grammar#1775brijeshb42 wants to merge 1 commit into
Conversation
Deploy previewBundle sizeTotal Size Change: 🔺+334B(+0.01%) - Total Gzip Change: 🔺+95B(+0.01%) Show details for 69 more bundles@mui/internal-docs-infra/CodeProvider parsed: 🔺+331B(+0.21%) gzip: 🔺+99B(+0.21%) PerformanceTotal duration: 17.80 ms +1.91 ms(+12.1%) | Renders: 5 (+0) | Paint: 63.44 ms +6.83 ms(+12.1%)
4 tests within noise — details Metric alarms
…and 1 more metric alarm — details Check out the code infra dashboard for more information about this PR. |
cd88007 to
be0c198
Compare
9e6cbcc to
821aefb
Compare
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.
be0c198 to
76408ea
Compare
Stacked on #1774, which is stacked on #1773. Review those first.
Problem
.jsresolved tosource.js, which classifies less thansource.tsdoes. Same code, two grammars:source.jssource.tsx/ab+c/gpl-s pl-srwith delimitersa < b && c > dpl-smi#x = 1pl-vexport default xdefaultispl-c1defaultispl-kThe last row is visible to readers: a file and its TypeScript twin were highlighted differently, so
defaultchanged colour when a language toggle switched between them.Change
The JavaScript family shares
source.tsx. TypeScript is a superset, so everythingsource.jsclassified is still classified, and.jsxalready resolved there.Comparisons are unaffected —
a < bstays punctuation rather than opening an element. I checked regular expressions, private class fields, optional chaining, async generators, and JSX before changing the map.Notes
.jsfile no longer needs alanguageoverride.DemoEntry.languageis still there for extensions that pick no grammar of their own.precomputeDemotest asserted the old behaviour — that a.jsentry does not highlight JSX without an override. It now asserts the opposite, with the override case moved to an unmapped extension.