Skip to content

Commit 76cbc7e

Browse files
authored
feat: improve js engine support (and run tests) in pre-ES2024 envs (#847)
1 parent fc87512 commit 76cbc7e

File tree

8 files changed

+16
-24
lines changed

8 files changed

+16
-24
lines changed

docs/guide/regex-engines.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ The JavaScript engine is best when running in the browser and in cases when you
7979

8080
For the best result, [Oniguruma-To-ES](https://github.com/slevithan/oniguruma-to-es) uses the [RegExp `v` flag](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/unicodeSets), which is available in Node.js v20+ and ES2024 ([Browser compatibility](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/unicodeSets#browser_compatibility)).
8181

82-
For older environments, it can use the `u` flag but somewhat fewer grammars are supported.
82+
For older environments, it can use the `u` flag but this results in a few less grammars being supported.
8383

8484
By default, the runtime target is automatically detected. You can override this behavior by setting the `target` option:
8585

docs/references/engine-js-compat.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

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

5-
> Generated on Friday, November 22, 2024
5+
> Generated on Sunday, November 24, 2024
66
>
77
> Version `1.23.1`
88
>
@@ -20,7 +20,7 @@ Compatibility reference of all built-in grammars with the [JavaScript RegExp eng
2020
## Supported Languages
2121

2222
Languages that work with the JavaScript RegExp engine, and will produce the same result as the WASM engine (with the [sample snippets in the registry](https://github.com/shikijs/textmate-grammars-themes/tree/main/samples)).
23-
In some edge cases, it's not guaranteed that the the highlighting will be 100% the same. If that happens, please create an issue with the sample snippet.
23+
In some edge cases, it's not guaranteed that the highlighting will be 100% the same. If that happens, please create an issue with the sample snippet.
2424

2525
| Language | Highlight Match | Patterns Parsable | Patterns Failed | Diff |
2626
| ------------------ | :-------------- | ----------------: | --------------: | ---: |
@@ -210,7 +210,7 @@ In some edge cases, it's not guaranteed that the the highlighting will be 100% t
210210
| wenyan | ✅ OK | 18 | - | |
211211
| wgsl | ✅ OK | 44 | - | |
212212
| wikitext | ✅ OK | 104 | - | |
213-
| wolfram | ✅ OK | 501 | - | |
213+
| wolfram | ✅ OK | 501 | - | 10 |
214214
| xml | ✅ OK | 169 | - | |
215215
| xsl | ✅ OK | 171 | - | |
216216
| yaml | ✅ OK | 48 | - | |
@@ -254,7 +254,7 @@ Languages that throw with the JavaScript RegExp engine, either because they cont
254254
| rst | [🚧 Mismatch](https://textmate-grammars-themes.netlify.app/?grammar=rst) | 1855 | 2 | 62 |
255255
| hack | ❌ Error | 947 | 1 | 114 |
256256
| purescript | ❌ Error | 72 | 1 | 42 |
257-
| cpp | ❌ Error | 510 | 2 | 27 |
257+
| cpp | ❌ Error | 510 | 2 | 8 |
258258
| csharp | ❌ Error | 306 | 3 | 204 |
259259
| markdown | ❌ Error | 115 | 3 | 857 |
260260
| swift | ❌ Error | 326 | 3 | 40 |

packages/engine-javascript/test/compare.test.ts

+1-4
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,7 @@ const cases: Cases[] = [
142142
},
143143
]
144144

145-
describe.skipIf(
146-
+process.versions.node.split('.')[0] < 20,
147-
)('cases', async () => {
145+
describe('cases', async () => {
148146
await loadWasm(import('@shikijs/core/wasm-inlined'))
149147

150148
const resolved = await Promise.all(cases.map(async (c) => {
@@ -163,7 +161,6 @@ describe.skipIf(
163161
const engineWasm = createWasmOnigLibWrapper()
164162
const engineJs = createJavaScriptRegexEngine({
165163
forgiving: true,
166-
target: 'ES2024',
167164
})
168165

169166
const shiki1 = await createHighlighterCore({

packages/engine-javascript/test/general.test.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@ import { describe, expect, it } from 'vitest'
22
import { createHighlighter } from '../../shiki/src/index'
33
import { createJavaScriptRegexEngine } from '../src'
44

5-
describe.skipIf(
6-
+process.versions.node.split('.')[0] < 20,
7-
)('should', () => {
5+
describe('should', () => {
86
it('works', async () => {
97
const shiki = await createHighlighter({
108
themes: ['vitesse-light'],

packages/shiki/test/core-sync.test.ts

+1-4
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,7 @@ import { createHighlighterCoreSync } from '../src/core'
44
import js from '../src/langs/javascript.mjs'
55
import nord from '../src/themes/nord.mjs'
66

7-
describe.skipIf(
8-
// JavaScript engine requires Node v20+
9-
+process.versions.node.split('.')[0] < 20,
10-
)('should', () => {
7+
describe('should', () => {
118
const engine = createJavaScriptRegexEngine()
129

1310
it('works', () => {

pnpm-lock.yaml

+6-6
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
@@ -53,7 +53,7 @@ catalog:
5353
minimist: ^1.2.8
5454
monaco-editor-core: ^0.52.0
5555
ofetch: ^1.4.1
56-
oniguruma-to-es: 0.6.0
56+
oniguruma-to-es: 0.6.1
5757
picocolors: ^1.1.1
5858
pinia: ^2.2.6
5959
pnpm: ^9.13.2

scripts/report-engine-js-compat.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ async function run() {
223223
'## Supported Languages',
224224
'',
225225
'Languages that work with the JavaScript RegExp engine, and will produce the same result as the WASM engine (with the [sample snippets in the registry](https://github.com/shikijs/textmate-grammars-themes/tree/main/samples)).',
226-
'In some edge cases, it\'s not guaranteed that the the highlighting will be 100% the same. If that happens, please create an issue with the sample snippet.',
226+
'In some edge cases, it\'s not guaranteed that the highlighting will be 100% the same. If that happens, please create an issue with the sample snippet.',
227227
'',
228228
createTable(reportOk),
229229
'',

0 commit comments

Comments
 (0)