@shikijs/engine-javascript 1.23.0 → 1.24.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { PatternScanner, RegexEngineString, RegexEngine } from '@shikijs/types';
2
2
  import { IOnigMatch } from '@shikijs/vscode-textmate';
3
- import { Options } from 'oniguruma-to-es';
3
+ import { OnigurumaToEsOptions } from 'oniguruma-to-es';
4
4
 
5
5
  interface JavaScriptRegexEngineOptions {
6
6
  /**
@@ -9,26 +9,22 @@ interface JavaScriptRegexEngineOptions {
9
9
  * @default false
10
10
  */
11
11
  forgiving?: boolean;
12
- /**
13
- * Cleanup some grammar patterns before use.
14
- *
15
- * @default true
16
- */
17
- simulation?: boolean;
18
12
  /**
19
13
  * The target ECMAScript version.
20
14
  *
21
- * For the best accuracy, Oniguruma-to-ES needs the `v` flag support in RegExp which is landed in ES2024.
22
- * Which requires Node.js 20+ or Chrome 112+.
15
+ * Oniguruma-To-ES uses RegExp features from later versions of ECMAScript to provide improved
16
+ * accuracy and add support for more grammars. If using target `ES2024` or later, the RegExp `v`
17
+ * flag is used which requires Node.js 20+ or Chrome 112+.
23
18
  * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/unicodeSets
24
19
  *
25
- * For the maximum compatibility, you can set it to `ES2018`. Which will use the `u` flag to simulate and will be less accurate.
20
+ * For maximum compatibility, you can set it to `ES2018` which uses the RegExp `u` flag but
21
+ * supports a few less grammars.
26
22
  *
27
- * Set to `auto` to detect the target version automatically.
23
+ * Set to `auto` to automatically detect the latest version supported by the environment.
28
24
  *
29
25
  * @default 'auto'
30
26
  */
31
- target?: 'ES2024' | 'ES2025' | 'ES2018' | 'auto';
27
+ target?: 'auto' | 'ES2025' | 'ES2024' | 'ES2018';
32
28
  /**
33
29
  * Cache for regex patterns.
34
30
  */
@@ -43,7 +39,7 @@ interface JavaScriptRegexEngineOptions {
43
39
  /**
44
40
  * The default RegExp constructor for JavaScript regex engine.
45
41
  */
46
- declare function defaultJavaScriptRegexConstructor(pattern: string, options?: Options): RegExp;
42
+ declare function defaultJavaScriptRegexConstructor(pattern: string, options?: OnigurumaToEsOptions): RegExp;
47
43
  declare class JavaScriptScanner implements PatternScanner {
48
44
  patterns: string[];
49
45
  options: JavaScriptRegexEngineOptions;
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { PatternScanner, RegexEngineString, RegexEngine } from '@shikijs/types';
2
2
  import { IOnigMatch } from '@shikijs/vscode-textmate';
3
- import { Options } from 'oniguruma-to-es';
3
+ import { OnigurumaToEsOptions } from 'oniguruma-to-es';
4
4
 
5
5
  interface JavaScriptRegexEngineOptions {
6
6
  /**
@@ -9,26 +9,22 @@ interface JavaScriptRegexEngineOptions {
9
9
  * @default false
10
10
  */
11
11
  forgiving?: boolean;
12
- /**
13
- * Cleanup some grammar patterns before use.
14
- *
15
- * @default true
16
- */
17
- simulation?: boolean;
18
12
  /**
19
13
  * The target ECMAScript version.
20
14
  *
21
- * For the best accuracy, Oniguruma-to-ES needs the `v` flag support in RegExp which is landed in ES2024.
22
- * Which requires Node.js 20+ or Chrome 112+.
15
+ * Oniguruma-To-ES uses RegExp features from later versions of ECMAScript to provide improved
16
+ * accuracy and add support for more grammars. If using target `ES2024` or later, the RegExp `v`
17
+ * flag is used which requires Node.js 20+ or Chrome 112+.
23
18
  * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/unicodeSets
24
19
  *
25
- * For the maximum compatibility, you can set it to `ES2018`. Which will use the `u` flag to simulate and will be less accurate.
20
+ * For maximum compatibility, you can set it to `ES2018` which uses the RegExp `u` flag but
21
+ * supports a few less grammars.
26
22
  *
27
- * Set to `auto` to detect the target version automatically.
23
+ * Set to `auto` to automatically detect the latest version supported by the environment.
28
24
  *
29
25
  * @default 'auto'
30
26
  */
31
- target?: 'ES2024' | 'ES2025' | 'ES2018' | 'auto';
27
+ target?: 'auto' | 'ES2025' | 'ES2024' | 'ES2018';
32
28
  /**
33
29
  * Cache for regex patterns.
34
30
  */
@@ -43,7 +39,7 @@ interface JavaScriptRegexEngineOptions {
43
39
  /**
44
40
  * The default RegExp constructor for JavaScript regex engine.
45
41
  */
46
- declare function defaultJavaScriptRegexConstructor(pattern: string, options?: Options): RegExp;
42
+ declare function defaultJavaScriptRegexConstructor(pattern: string, options?: OnigurumaToEsOptions): RegExp;
47
43
  declare class JavaScriptScanner implements PatternScanner {
48
44
  patterns: string[];
49
45
  options: JavaScriptRegexEngineOptions;
package/dist/index.mjs CHANGED
@@ -7,27 +7,17 @@ var __publicField = (obj, key, value) => {
7
7
  return value;
8
8
  };
9
9
  const MAX = 4294967295;
10
- let supportedRegExpTarget;
11
- function detectRegExpTarget() {
12
- if (supportedRegExpTarget != null)
13
- return supportedRegExpTarget;
14
- supportedRegExpTarget = "ES2018";
15
- try {
16
- new RegExp("a", "v");
17
- supportedRegExpTarget = "ES2024";
18
- } catch {
19
- supportedRegExpTarget = "ES2018";
20
- }
21
- return supportedRegExpTarget;
22
- }
23
10
  function defaultJavaScriptRegexConstructor(pattern, options) {
24
11
  return toRegExp(
25
12
  pattern,
26
13
  {
27
- accuracy: "loose",
28
14
  global: true,
29
15
  hasIndices: true,
30
- tmGrammar: true,
16
+ rules: {
17
+ allowOrphanBackrefs: true,
18
+ allowUnhandledGAnchors: true,
19
+ asciiWordBoundaries: true
20
+ },
31
21
  ...options
32
22
  }
33
23
  );
@@ -41,14 +31,9 @@ class JavaScriptScanner {
41
31
  forgiving = false,
42
32
  cache,
43
33
  target = "auto",
44
- simulation = true,
45
- regexConstructor = (pattern) => defaultJavaScriptRegexConstructor(pattern, {
46
- target: target === "auto" ? detectRegExpTarget() : target
47
- })
34
+ regexConstructor = (pattern) => defaultJavaScriptRegexConstructor(pattern, { target })
48
35
  } = options;
49
36
  this.regexps = patterns.map((p) => {
50
- if (simulation)
51
- p = p.replaceAll("(^|\\\uFFFF)", "(^|\\G)");
52
37
  const cached = cache?.get(p);
53
38
  if (cached) {
54
39
  if (cached instanceof RegExp) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@shikijs/engine-javascript",
3
3
  "type": "module",
4
- "version": "1.23.0",
4
+ "version": "1.24.0",
5
5
  "description": "Engine for Shiki using JavaScript's native RegExp",
6
6
  "author": "Anthony Fu <anthonyfu117@hotmail.com>",
7
7
  "license": "MIT",
@@ -31,8 +31,8 @@
31
31
  ],
32
32
  "dependencies": {
33
33
  "@shikijs/vscode-textmate": "^9.3.0",
34
- "oniguruma-to-es": "0.1.2",
35
- "@shikijs/types": "1.23.0"
34
+ "oniguruma-to-es": "0.7.0",
35
+ "@shikijs/types": "1.24.0"
36
36
  },
37
37
  "scripts": {
38
38
  "build": "unbuild",