meriyah 4.5.0 → 6.0.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.
Files changed (81) hide show
  1. package/CHANGELOG.md +415 -445
  2. package/README.md +52 -34
  3. package/dist/meriyah.cjs +9203 -8807
  4. package/dist/meriyah.min.mjs +1 -0
  5. package/dist/{meriyah.esm.js → meriyah.mjs} +9203 -8807
  6. package/dist/meriyah.umd.js +9203 -8807
  7. package/dist/meriyah.umd.min.js +1 -1
  8. package/dist/src/chars.d.ts +135 -135
  9. package/dist/src/common.d.ts +225 -200
  10. package/dist/src/common.d.ts.map +1 -1
  11. package/dist/src/errors.d.ts +197 -187
  12. package/dist/src/errors.d.ts.map +1 -1
  13. package/dist/src/estree.d.ts +524 -507
  14. package/dist/src/estree.d.ts.map +1 -1
  15. package/dist/src/lexer/charClassifier.d.ts +24 -24
  16. package/dist/src/lexer/charClassifier.d.ts.map +1 -1
  17. package/dist/src/lexer/comments.d.ts +14 -14
  18. package/dist/src/lexer/common.d.ts +25 -26
  19. package/dist/src/lexer/common.d.ts.map +1 -1
  20. package/dist/src/lexer/decodeHTML.d.ts +1 -1
  21. package/dist/src/lexer/decodeHTML.d.ts.map +1 -1
  22. package/dist/src/lexer/identifier.d.ts +8 -8
  23. package/dist/src/lexer/identifier.d.ts.map +1 -1
  24. package/dist/src/lexer/index.d.ts +9 -9
  25. package/dist/src/lexer/index.d.ts.map +1 -1
  26. package/dist/src/lexer/jsx.d.ts +6 -6
  27. package/dist/src/lexer/jsx.d.ts.map +1 -1
  28. package/dist/src/lexer/numeric.d.ts +5 -5
  29. package/dist/src/lexer/numeric.d.ts.map +1 -1
  30. package/dist/src/lexer/regexp.d.ts +3 -3
  31. package/dist/src/lexer/regexp.d.ts.map +1 -1
  32. package/dist/src/lexer/scan.d.ts +6 -6
  33. package/dist/src/lexer/scan.d.ts.map +1 -1
  34. package/dist/src/lexer/string.d.ts +12 -12
  35. package/dist/src/lexer/string.d.ts.map +1 -1
  36. package/dist/src/lexer/template.d.ts +4 -4
  37. package/dist/src/lexer/template.d.ts.map +1 -1
  38. package/dist/src/meriyah.d.ts +7 -7
  39. package/dist/src/meriyah.d.ts.map +1 -1
  40. package/dist/src/parser.d.ts +119 -118
  41. package/dist/src/parser.d.ts.map +1 -1
  42. package/dist/src/token.d.ts +167 -167
  43. package/dist/src/token.d.ts.map +1 -1
  44. package/dist/src/unicode.d.ts +5 -5
  45. package/package.json +44 -48
  46. package/dist/meriyah.amd.js +0 -8854
  47. package/dist/meriyah.amd.min.js +0 -1
  48. package/dist/meriyah.cjs.js +0 -8852
  49. package/dist/meriyah.cjs.min.js +0 -1
  50. package/dist/meriyah.esm.min.js +0 -1
  51. package/dist/meriyah.esm.min.mjs +0 -1
  52. package/dist/meriyah.esm.mjs +0 -8846
  53. package/dist/meriyah.iife.js +0 -8857
  54. package/dist/meriyah.iife.min.js +0 -1
  55. package/dist/meriyah.min.cjs +0 -1
  56. package/dist/meriyah.system.js +0 -8860
  57. package/dist/meriyah.system.min.js +0 -1
  58. package/dist/meriyah.umd.cjs +0 -8858
  59. package/dist/meriyah.umd.es5.js +0 -8927
  60. package/dist/meriyah.umd.es5.min.js +0 -1
  61. package/dist/meriyah.umd.min.cjs +0 -1
  62. package/src/chars.ts +0 -155
  63. package/src/common.ts +0 -841
  64. package/src/errors.ts +0 -419
  65. package/src/estree.ts +0 -817
  66. package/src/lexer/charClassifier.ts +0 -449
  67. package/src/lexer/comments.ts +0 -178
  68. package/src/lexer/common.ts +0 -140
  69. package/src/lexer/decodeHTML.ts +0 -2186
  70. package/src/lexer/identifier.ts +0 -196
  71. package/src/lexer/index.ts +0 -32
  72. package/src/lexer/jsx.ts +0 -126
  73. package/src/lexer/numeric.ts +0 -259
  74. package/src/lexer/regexp.ts +0 -156
  75. package/src/lexer/scan.ts +0 -655
  76. package/src/lexer/string.ts +0 -242
  77. package/src/lexer/template.ts +0 -108
  78. package/src/meriyah.ts +0 -29
  79. package/src/parser.ts +0 -9210
  80. package/src/token.ts +0 -307
  81. package/src/unicode.ts +0 -36
package/README.md CHANGED
@@ -4,11 +4,8 @@
4
4
 
5
5
  <p align="center">
6
6
  <a href="https://www.npmjs.com/package/meriyah"><img src="https://img.shields.io/npm/v/meriyah.svg?style=flat-square" alt="Meriyah NPM"/></a>
7
- <a href="https://lgtm.com/projects/g/meriyah/meriyah/context:javascript"><img src="https://img.shields.io/lgtm/grade/javascript/g/meriyah/meriyah.svg?logo=lgtm&logoWidth=18" alt="GitHub license" /></a>
8
- <a href="https://lgtm.com/projects/g/meriyah/meriyah/alerts"><img src="https://img.shields.io/lgtm/alerts/g/meriyah/meriyah.svg?logo=lgtm&logoWidth=18" alt="Total alerts" /></a>
9
- <a href="https://circleci.com/gh/meriyah/meriyah"><img src="https://circleci.com/gh/meriyah/meriyah.svg?style=svg" alt="Circle" /></a>
7
+ <a href="https://github.com/meriyah/meriyah/actions/workflows/node.js.yml"><img src="https://github.com/meriyah/meriyah/actions/workflows/node.js.yml/badge.svg" alt="Node.js CI"/></a>
10
8
  <a href="https://github.com/meriyah/meriyah/blob/master/LICENSE.md"><img src="https://img.shields.io/github/license/meriyah/meriyah.svg" alt="License" /></a>
11
-
12
9
  </p>
13
10
 
14
11
  <br>
@@ -17,27 +14,46 @@
17
14
 
18
15
  ## Features
19
16
 
20
- * Conforms to the standard ECMAScript® 2021 (ECMA-262 11th Edition) language specification
21
- * Support TC39 proposals via option
22
- * Support for additional ECMAScript features for Web Browsers
23
- * JSX support via option
24
- * Does **not** support TypeScript or Flow
25
- * Optionally track syntactic node locations
26
- * Emits an ESTree-compatible abstract syntax tree
27
- * No backtracking
28
- * Low memory usage
29
- * Very well tested (~99 000 unit tests with full code coverage)
30
- * Lightweight - ~90 KB minified
17
+ - Conforms to the standard ECMAScript® 2024 (ECMA-262 15th Edition) language specification
18
+ - Except RegExp duplicate named groups (See [RegExp support](#regexp-support))
19
+ - Support some TC39 stage 3 proposals via option "next"
20
+ - Support for additional ECMAScript features for Web Browsers (Annex B)
21
+ - JSX support via option "jsx"
22
+ - Does **NOT** support TypeScript or Flow syntax
23
+ - Track syntactic node locations with option "ranges" or "loc"
24
+ - Emits an ESTree-compatible abstract syntax tree
25
+ - No backtracking
26
+ - Low memory usage
27
+
28
+ ## ESNext Stage 3 features
29
+
30
+ ### Supported stage 3 features:
31
+
32
+ These features need to be enabled with the `next` option.
33
+
34
+ - [Decorators](https://github.com/tc39/proposal-decorators)
35
+ - [Import Attributes](https://github.com/tc39/proposal-import-attributes)
36
+ - [JSON Modules](https://github.com/tc39/proposal-json-modules)
37
+
38
+ ### Not yet supported stage 3 features:
39
+
40
+ - [Explicit resource management](https://github.com/tc39/proposal-explicit-resource-management)
41
+ - [Source phase import](https://github.com/tc39/proposal-source-phase-imports)
42
+ - [RegExp modifiers](https://github.com/tc39/proposal-regexp-modifiers) (See [RegExp support](#regexp-support))
43
+
44
+ ## RegExp support
45
+
46
+ Meriyah doesn't parse RegExp internal syntax, ESTree spec didn't require internal structure of RegExp. Meriyah
47
+ does use JavaScript runtime to validate the RegExp literal. That means Meriyah's RegExp support is only as good
48
+ as JavaScript runtime's RegExp support.
31
49
 
32
- ## ESNext features
50
+ As of Auguest 2024, some latest RegExp features are not supported due to missing implementation in general
51
+ JavaScript runtime.
33
52
 
34
- * [Decorators](https://github.com/tc39/proposal-decorators)
35
- * [Class Public Instance Fields & Private Instance Fields](https://github.com/tc39/proposal-class-fields)
36
- * [Hashbang grammar](https://github.com/tc39/proposal-hashbang)
37
- * [Private methods](https://github.com/tc39/proposal-private-methods)
38
- * [Static class fields and private static methods](https://github.com/tc39/proposal-static-class-features/)
53
+ - [RegExp modifiers](https://github.com/tc39/proposal-regexp-modifiers) (stage 3) is not supported
54
+ - [RegExp duplicate named groups](https://github.com/tc39/proposal-duplicate-named-capturing-groups) is not supported
39
55
 
40
- **Note:** These features need to be enabled with the `next` option.
56
+ In addition, RegExp v flag (unicodeSets) only works on Nodejs v20+ and latest browsers.
41
57
 
42
58
  ## Installation
43
59
 
@@ -51,7 +67,13 @@ Meriyah generates `AST` according to [ESTree AST format](https://github.com/estr
51
67
 
52
68
  The `parse` method exposed by meriyah takes an optional `options` object which allows you to specify whether to parse in [`script`](https://tc39.github.io/ecma262/#sec-parse-script) mode (the default) or in [`module`](https://tc39.github.io/ecma262/#sec-parsemodule) mode.
53
69
 
54
- This is the available options:
70
+ ```js
71
+ // There are also "parseScript" and "parseModule" exported.
72
+ import { parse } from 'meriyah';
73
+ const result = parse('let some = "code";', { ranges: true });
74
+ ```
75
+
76
+ The available options:
55
77
 
56
78
  ```js
57
79
  {
@@ -73,9 +95,6 @@ This is the available options:
73
95
  // The flag to attach raw property to each literal and identifier node
74
96
  raw: false;
75
97
 
76
- // Enabled directives
77
- directives: false;
78
-
79
98
  // The flag to allow return in the global scope
80
99
  globalReturn: false;
81
100
 
@@ -83,13 +102,13 @@ This is the available options:
83
102
  impliedStrict: false;
84
103
 
85
104
  // Allows comment extraction. Accepts either a function or array
86
- onComment: []
105
+ onComment: [];
87
106
 
88
107
  // Allows detection of automatic semicolon insertion. Accepts a callback function that will be passed the charater offset where the semicolon was inserted
89
- onInsertedSemicolon: (pos) => {}
108
+ onInsertedSemicolon: (pos) => {};
90
109
 
91
110
  // Allows token extraction. Accepts either a function or array
92
- onToken: []
111
+ onToken: [];
93
112
 
94
113
  // Enable non-standard parenthesized expression node
95
114
  preserveParens: false;
@@ -100,13 +119,13 @@ This is the available options:
100
119
  // Adds a source attribute in every node’s loc object when the locations option is `true`
101
120
  source: false;
102
121
 
103
- // Enable React JSX parsing
104
- jsx: false
122
+ // Enable React JSX parsing
123
+ jsx: false;
105
124
  }
106
-
107
125
  ```
108
126
 
109
127
  ### onComment and onToken
128
+
110
129
  If an array is supplied, comments/tokens will be pushed to the array, the item in the array contains `start/end/range` information when ranges flag is true, it will also contain `loc` information when loc flag is true.
111
130
 
112
131
  If a function callback is supplied, the signature must be
@@ -120,6 +139,7 @@ declare function onToken(token: string, start: number, end: number, loc: SourceL
120
139
  Note the `start/end/loc` information are provided to the function callback regardless of the settings on ranges and loc flags. onComment callback has one extra argument `value: string` for the body string of the comment.
121
140
 
122
141
  ### onInsertedSemicolon
142
+
123
143
  If a function callback is supplied, the signature must be
124
144
 
125
145
  ```ts
@@ -129,11 +149,9 @@ declare function onInsertedSemicolon(position: number): void;
129
149
  ## Example usage
130
150
 
131
151
  ```js
132
-
133
152
  import { parseScript } from './meriyah';
134
153
 
135
154
  parseScript('({x: [y] = 0} = 1)');
136
-
137
155
  ```
138
156
 
139
157
  This will return when serialized in json: