Skip to content

Commit d82af15

Browse files
slevithanantfu
andauthoredJan 15, 2025··
feat(engine-js): update deps, support more languages (#890)
Co-authored-by: Anthony Fu <github@antfu.me>
1 parent 07da2f3 commit d82af15

File tree

7 files changed

+30
-29
lines changed

7 files changed

+30
-29
lines changed
 

‎docs/guide/regex-engines.md

+1-3
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,6 @@ const html = shiki.codeToHtml('const a = 1', { lang: 'javascript', theme: 'nord'
5656

5757
The advantages of using the JavaScript engine are that it doesn't require loading a large WebAssembly file for Oniguruma and it is faster for some grammars (since the regular expressions run as native JavaScript).
5858

59-
Although the JavaScript engine's Oniguruma emulation is quite robust, it's not guaranteed that the highlighting will be 100% the same in some edge cases. Additionally, a few grammars are unsupported.
60-
6159
Please check the [compatibility table](/references/engine-js-compat) for the support status of languages you are using.
6260

6361
The JavaScript engine is strict by default, and will throw an error if it encounters a pattern that it cannot convert. If mismatches are acceptable and you want best-effort results for unsupported grammars, you can enable the `forgiving` option to suppress any conversion errors:
@@ -68,7 +66,7 @@ const jsEngine = createJavaScriptRegexEngine({ forgiving: true })
6866
```
6967

7068
::: info
71-
If you run Shiki on Node.js (or at build time) and bundle size or WebAssembly support is not a concern, we still recommend using the Oniguruma engine for best results.
69+
If you run Shiki on Node.js (or at build time) and bundle size or WebAssembly support is not a concern, we still recommend using the Oniguruma engine.
7270

7371
The JavaScript engine is best when running in the browser and in cases when you want to control the bundle size.
7472
:::

‎docs/references/engine-js-compat.md

+11-11
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@
22

33
Compatibility reference of all built-in grammars with the [JavaScript RegExp engine](/guide/regex-engines#javascript-regexp-engine).
44

5-
> Generated on Monday, January 13, 2025
5+
> Generated on Tuesday, January 14, 2025
66
>
7-
> Version `1.26.1`
7+
> Version `1.27.0`
88
>
9-
> Runtime: Node.js v22.12.0
9+
> Runtime: Node.js v22.11.0
1010
1111
## Report Summary
1212

1313
| | Count |
1414
| :-------------- | --------------------------: |
1515
| Total Languages | 219 |
16-
| Supported | [212](#supported-languages) |
17-
| Mismatched | [1](#mismatched-languages) |
16+
| Supported | [213](#supported-languages) |
17+
| Mismatched | [0](#mismatched-languages) |
1818
| Unsupported | [6](#unsupported-languages) |
1919

2020
## Supported Languages
@@ -147,6 +147,7 @@ In some edge cases, it's not guaranteed that the highlighting will be 100% the s
147147
| move | ✅ OK | 120 | - | |
148148
| narrat | ✅ OK | 34 | - | |
149149
| nextflow | ✅ OK | 32 | - | |
150+
| nginx | ✅ OK | 378 | - | |
150151
| nim | ✅ OK | 1130 | - | |
151152
| nix | ✅ OK | 80 | - | |
152153
| nushell | ✅ OK | 81 | - | |
@@ -204,7 +205,7 @@ In some edge cases, it's not guaranteed that the highlighting will be 100% the s
204205
| talonscript | ✅ OK | 44 | - | |
205206
| tasl | ✅ OK | 23 | - | |
206207
| tcl | ✅ OK | 34 | - | |
207-
| templ | ✅ OK | 680 | - | |
208+
| templ | ✅ OK | 682 | - | |
208209
| terraform | ✅ OK | 68 | - | |
209210
| tex | ✅ OK | 106 | - | |
210211
| toml | ✅ OK | 44 | - | |
@@ -246,11 +247,10 @@ In some edge cases, it's not guaranteed that the highlighting will be 100% the s
246247

247248
## Mismatched Languages
248249

249-
Languages that do not throw with the JavaScript RegExp engine, but will produce different results than the WASM engine. Please use with caution.
250+
Languages that do not throw with the JavaScript RegExp engine, but will produce different results than the WASM engine.
250251

251-
| Language | Highlight Match | Patterns Parsable | Patterns Failed | Diff |
252-
| -------- | :------------------------------------------------------------------------- | ----------------: | --------------: | ---: |
253-
| nginx | [🚧 Mismatch](https://textmate-grammars-themes.netlify.app/?grammar=nginx) | 378 | - | 122 |
252+
| Language | Highlight Match | Patterns Parsable | Patterns Failed | Diff |
253+
| -------- | :-------------- | ----------------: | --------------: | ---: |
254254

255255
## Unsupported Languages
256256

@@ -262,5 +262,5 @@ Languages that throw with the JavaScript RegExp engine, either because they cont
262262
| sass | ✅ OK | 67 | 2 | |
263263
| purescript | ❌ Error | 72 | 1 | |
264264
| csharp | ❌ Error | 310 | 3 | 137 |
265-
| swift | ❌ Error | 326 | 3 | 8 |
265+
| swift | ❌ Error | 326 | 3 | |
266266
| razor | ❌ Error | 957 | 5 | |

‎packages/engine-javascript/src/engine-compile.ts

-3
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,6 @@ export function defaultJavaScriptRegexConstructor(pattern: string, options?: Oni
3838
asciiWordBoundaries: true,
3939
// Follow `vscode-oniguruma` which enables this Oniguruma option by default
4040
captureGroup: true,
41-
// Removing `\G` anchors in cases when they're not supported for emulation allows
42-
// supporting more grammars, but also allows some mismatches
43-
ignoreUnsupportedGAnchors: true,
4441
// Oniguruma uses depth limit `20`; lowered here to keep regexes shorter and maybe
4542
// sometimes faster, but can be increased if issues reported due to low limit
4643
recursionLimit: 5,

‎packages/langs-precompiled/scripts/__snapshots__/precompile.test.ts.snap

+9-3
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,9 @@ exports[`precompile 1`] = `
9191
],
9292
},
9393
},
94-
end: /(?<=^|\\n(?!$))(?=\\P{space})|(?!)/dgv,
94+
end: new EmulatedRegExp("(?<=^|\\\\n(?!$))(?=\\\\P{space})|(?!^)", "dgv", {
95+
strategy: "search_start_clip",
96+
}),
9597
patterns: [
9698
{
9799
begin: /(?<=^|\\n(?!$))([ ]+)(?! )/dgv,
@@ -110,7 +112,9 @@ exports[`precompile 1`] = `
110112
beginCaptures: {
111113
"1": { name: "punctuation.whitespace.comment.leading.yaml" },
112114
},
113-
end: new EmulatedRegExp("", "dgv", { strategy: "not_search_start" }),
115+
end: new EmulatedRegExp("(?!^)", "dgv", {
116+
strategy: "search_start_clip",
117+
}),
114118
patterns: [
115119
{
116120
begin: /#/dgv,
@@ -373,7 +377,9 @@ exports[`precompile 1`] = `
373377
node: { patterns: [{ include: "#block-node" }] },
374378
property: {
375379
begin: /(?=!|&)/dgv,
376-
end: new EmulatedRegExp("", "dgv", { strategy: "not_search_start" }),
380+
end: new EmulatedRegExp("(?!^)", "dgv", {
381+
strategy: "search_start_clip",
382+
}),
377383
name: "meta.property.yaml",
378384
patterns: [
379385
{

‎pnpm-lock.yaml

+7-7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎pnpm-workspace.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ catalog:
5656
monaco-editor-core: ^0.52.2
5757
ofetch: ^1.4.1
5858
ohash: ^1.1.4
59-
oniguruma-to-es: ^1.0.0
59+
oniguruma-to-es: ^2.0.0
6060
picocolors: ^1.1.1
6161
pinia: ^2.3.0
6262
pnpm: ^9.15.4

‎scripts/report-engine-js-compat.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ async function run() {
237237
'',
238238
'## Mismatched Languages',
239239
'',
240-
'Languages that do not throw with the JavaScript RegExp engine, but will produce different results than the WASM engine. Please use with caution.',
240+
'Languages that do not throw with the JavaScript RegExp engine, but will produce different results than the WASM engine.',
241241
'',
242242
createTable(reportMismatch),
243243
'',

0 commit comments

Comments
 (0)
Please sign in to comment.