meriyah 5.0.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 (69) hide show
  1. package/CHANGELOG.md +79 -0
  2. package/README.md +38 -14
  3. package/dist/meriyah.cjs +2356 -2070
  4. package/dist/meriyah.min.mjs +1 -0
  5. package/dist/{meriyah.esm.js → meriyah.mjs} +2356 -2070
  6. package/dist/meriyah.umd.js +2356 -2070
  7. package/dist/meriyah.umd.min.js +1 -1
  8. package/dist/src/common.d.ts +71 -47
  9. package/dist/src/common.d.ts.map +1 -1
  10. package/dist/src/errors.d.ts +186 -177
  11. package/dist/src/errors.d.ts.map +1 -1
  12. package/dist/src/estree.d.ts +15 -6
  13. package/dist/src/estree.d.ts.map +1 -1
  14. package/dist/src/lexer/charClassifier.d.ts +2 -2
  15. package/dist/src/lexer/charClassifier.d.ts.map +1 -1
  16. package/dist/src/lexer/common.d.ts +1 -2
  17. package/dist/src/lexer/common.d.ts.map +1 -1
  18. package/dist/src/lexer/identifier.d.ts.map +1 -1
  19. package/dist/src/lexer/index.d.ts +1 -1
  20. package/dist/src/lexer/index.d.ts.map +1 -1
  21. package/dist/src/lexer/jsx.d.ts +2 -2
  22. package/dist/src/lexer/jsx.d.ts.map +1 -1
  23. package/dist/src/lexer/numeric.d.ts.map +1 -1
  24. package/dist/src/lexer/regexp.d.ts.map +1 -1
  25. package/dist/src/lexer/scan.d.ts.map +1 -1
  26. package/dist/src/lexer/string.d.ts +1 -1
  27. package/dist/src/lexer/string.d.ts.map +1 -1
  28. package/dist/src/lexer/template.d.ts.map +1 -1
  29. package/dist/src/parser.d.ts +72 -72
  30. package/dist/src/parser.d.ts.map +1 -1
  31. package/dist/src/token.d.ts +115 -115
  32. package/dist/src/token.d.ts.map +1 -1
  33. package/package.json +25 -34
  34. package/dist/meriyah.amd.js +0 -8964
  35. package/dist/meriyah.amd.min.js +0 -1
  36. package/dist/meriyah.cjs.js +0 -8962
  37. package/dist/meriyah.cjs.min.js +0 -1
  38. package/dist/meriyah.esm.min.js +0 -1
  39. package/dist/meriyah.esm.min.mjs +0 -1
  40. package/dist/meriyah.esm.mjs +0 -8956
  41. package/dist/meriyah.iife.js +0 -8967
  42. package/dist/meriyah.iife.min.js +0 -1
  43. package/dist/meriyah.min.cjs +0 -1
  44. package/dist/meriyah.system.js +0 -8970
  45. package/dist/meriyah.system.min.js +0 -1
  46. package/dist/meriyah.umd.cjs +0 -8968
  47. package/dist/meriyah.umd.es5.js +0 -9022
  48. package/dist/meriyah.umd.es5.min.js +0 -1
  49. package/dist/meriyah.umd.min.cjs +0 -1
  50. package/src/chars.ts +0 -155
  51. package/src/common.ts +0 -834
  52. package/src/errors.ts +0 -421
  53. package/src/estree.ts +0 -827
  54. package/src/lexer/charClassifier.ts +0 -449
  55. package/src/lexer/comments.ts +0 -178
  56. package/src/lexer/common.ts +0 -140
  57. package/src/lexer/decodeHTML.ts +0 -2184
  58. package/src/lexer/identifier.ts +0 -196
  59. package/src/lexer/index.ts +0 -32
  60. package/src/lexer/jsx.ts +0 -127
  61. package/src/lexer/numeric.ts +0 -259
  62. package/src/lexer/regexp.ts +0 -156
  63. package/src/lexer/scan.ts +0 -657
  64. package/src/lexer/string.ts +0 -242
  65. package/src/lexer/template.ts +0 -108
  66. package/src/meriyah.ts +0 -28
  67. package/src/parser.ts +0 -9358
  68. package/src/token.ts +0 -307
  69. package/src/unicode.ts +0 -36
@@ -1,242 +0,0 @@
1
- import { ParserState, Context, Flags } from '../common';
2
- import { Token } from '../token';
3
- import { Chars } from '../chars';
4
- import { report, Errors } from '../errors';
5
- import { toHex, advanceChar, fromCodePoint } from './common';
6
- import { CharTypes, CharFlags } from './charClassifier';
7
- // Intentionally negative
8
- export const enum Escape {
9
- Empty = -1,
10
- StrictOctal = -2,
11
- EightOrNine = -3,
12
- InvalidHex = -4,
13
- OutOfRange = -5
14
- }
15
-
16
- /**
17
- * Scan a string token.
18
- */
19
- export function scanString(parser: ParserState, context: Context, quote: number): Token {
20
- const { index: start } = parser;
21
-
22
- let ret: string | void = '';
23
- let char = advanceChar(parser);
24
- let marker = parser.index; // Consumes the quote
25
-
26
- while ((CharTypes[char] & CharFlags.LineTerminator) === 0) {
27
- if (char === quote) {
28
- ret += parser.source.slice(marker, parser.index);
29
- advanceChar(parser); // skip closing quote
30
- if (context & Context.OptionsRaw) parser.tokenRaw = parser.source.slice(start, parser.index);
31
- parser.tokenValue = ret;
32
- return Token.StringLiteral;
33
- }
34
-
35
- if ((char & 8) === 8 && char === Chars.Backslash) {
36
- ret += parser.source.slice(marker, parser.index);
37
- char = advanceChar(parser);
38
-
39
- if (char < 0x7f || char === Chars.LineSeparator || char === Chars.ParagraphSeparator) {
40
- const code = parseEscape(parser, context, char);
41
- if (code >= 0) ret += fromCodePoint(code);
42
- else handleStringError(parser, code as Escape, /* isTemplate */ 0);
43
- } else {
44
- ret += fromCodePoint(char);
45
- }
46
- marker = parser.index + 1;
47
- }
48
-
49
- if (parser.index >= parser.end) report(parser, Errors.UnterminatedString);
50
-
51
- char = advanceChar(parser);
52
- }
53
-
54
- report(parser, Errors.UnterminatedString);
55
- }
56
-
57
- // TODO! Use table lookup
58
-
59
- export function parseEscape(parser: ParserState, context: Context, first: number): number {
60
- switch (first) {
61
- // https://tc39.github.io/ecma262/#prod-SingleEscapeCharacter
62
- // one of ' " \ b f n r t v
63
- case Chars.LowerB:
64
- return Chars.Backspace;
65
- case Chars.LowerF:
66
- return Chars.FormFeed;
67
- case Chars.LowerR:
68
- return Chars.CarriageReturn;
69
- case Chars.LowerN:
70
- return Chars.LineFeed;
71
- case Chars.LowerT:
72
- return Chars.Tab;
73
- case Chars.LowerV:
74
- return Chars.VerticalTab;
75
-
76
- // Line continuations
77
- case Chars.CarriageReturn: {
78
- if (parser.index < parser.end) {
79
- const nextChar = parser.source.charCodeAt(parser.index + 1);
80
- if (nextChar === Chars.LineFeed) {
81
- parser.index = parser.index + 1;
82
- parser.currentChar = nextChar;
83
- }
84
- }
85
- }
86
- // falls through
87
-
88
- case Chars.LineFeed:
89
- case Chars.LineSeparator:
90
- case Chars.ParagraphSeparator:
91
- parser.column = -1;
92
- parser.line++;
93
- return Escape.Empty;
94
-
95
- // Null character, octals
96
- case Chars.Zero:
97
- case Chars.One:
98
- case Chars.Two:
99
- case Chars.Three: {
100
- let code = first - Chars.Zero;
101
- let index = parser.index + 1;
102
- let column = parser.column + 1;
103
-
104
- if (index < parser.end) {
105
- const next = parser.source.charCodeAt(index);
106
-
107
- if ((CharTypes[next] & CharFlags.Octal) === 0) {
108
- // Verify that it's `\0` if we're in strict mode.
109
- if ((code !== 0 || CharTypes[next] & CharFlags.ImplicitOctalDigits) && context & Context.Strict)
110
- return Escape.StrictOctal;
111
- } else if (context & Context.Strict) {
112
- return Escape.StrictOctal;
113
- } else {
114
- parser.currentChar = next;
115
- code = (code << 3) | (next - Chars.Zero);
116
- index++;
117
- column++;
118
- if (index < parser.end) {
119
- const next = parser.source.charCodeAt(index);
120
-
121
- if (CharTypes[next] & CharFlags.Octal) {
122
- parser.currentChar = next;
123
- code = (code << 3) | (next - Chars.Zero);
124
- index++;
125
- column++;
126
- }
127
- }
128
-
129
- parser.flags |= Flags.Octals;
130
-
131
- parser.index = index - 1;
132
- parser.column = column - 1;
133
- }
134
- }
135
-
136
- return code;
137
- }
138
-
139
- case Chars.Four:
140
- case Chars.Five:
141
- case Chars.Six:
142
- case Chars.Seven: {
143
- if (context & Context.Strict) return Escape.StrictOctal;
144
-
145
- let code = first - Chars.Zero;
146
- const index = parser.index + 1;
147
- const column = parser.column + 1;
148
-
149
- if (index < parser.end) {
150
- const next = parser.source.charCodeAt(index);
151
-
152
- if (CharTypes[next] & CharFlags.Octal) {
153
- code = (code << 3) | (next - Chars.Zero);
154
- parser.currentChar = next;
155
- parser.index = index;
156
- parser.column = column;
157
- }
158
- }
159
-
160
- parser.flags |= Flags.Octals;
161
-
162
- return code;
163
- }
164
-
165
- // HexEscapeSequence
166
- // \x HexDigit HexDigit
167
- case Chars.LowerX: {
168
- const ch1 = advanceChar(parser);
169
- if ((CharTypes[ch1] & CharFlags.Hex) === 0) return Escape.InvalidHex;
170
- const hi = toHex(ch1);
171
- const ch2 = advanceChar(parser);
172
- if ((CharTypes[ch2] & CharFlags.Hex) === 0) return Escape.InvalidHex;
173
- const lo = toHex(ch2);
174
-
175
- return (hi << 4) | lo;
176
- }
177
-
178
- // UnicodeEscapeSequence
179
- // \u HexDigit HexDigit HexDigit HexDigit
180
- // \u { HexDigit HexDigit HexDigit ... }
181
- case Chars.LowerU: {
182
- const ch = advanceChar(parser);
183
-
184
- if (parser.currentChar === Chars.LeftBrace) {
185
- let code = 0;
186
- while ((CharTypes[advanceChar(parser)] & CharFlags.Hex) !== 0) {
187
- code = (code << 4) | toHex(parser.currentChar);
188
- if (code > Chars.NonBMPMax) return Escape.OutOfRange;
189
- }
190
-
191
- if (parser.currentChar < 1 || (parser.currentChar as number) !== Chars.RightBrace) {
192
- return Escape.InvalidHex;
193
- }
194
- return code;
195
- } else {
196
- if ((CharTypes[ch] & CharFlags.Hex) === 0) return Escape.InvalidHex; // first one is mandatory
197
- const ch2 = parser.source.charCodeAt(parser.index + 1);
198
- if ((CharTypes[ch2] & CharFlags.Hex) === 0) return Escape.InvalidHex;
199
- const ch3 = parser.source.charCodeAt(parser.index + 2);
200
- if ((CharTypes[ch3] & CharFlags.Hex) === 0) return Escape.InvalidHex;
201
- const ch4 = parser.source.charCodeAt(parser.index + 3);
202
- if ((CharTypes[ch4] & CharFlags.Hex) === 0) return Escape.InvalidHex;
203
-
204
- parser.index += 3;
205
- parser.column += 3;
206
-
207
- parser.currentChar = parser.source.charCodeAt(parser.index);
208
-
209
- return (toHex(ch) << 12) | (toHex(ch2) << 8) | (toHex(ch3) << 4) | toHex(ch4);
210
- }
211
- }
212
-
213
- // `8`, `9` (invalid escapes)
214
- case Chars.Eight:
215
- case Chars.Nine:
216
- if ((context & Context.OptionsWebCompat) === 0) return Escape.EightOrNine;
217
- // fallthrough
218
- default:
219
- return first;
220
- }
221
- }
222
-
223
- export function handleStringError(state: ParserState, code: Escape, isTemplate: 0 | 1): void {
224
- switch (code) {
225
- case Escape.Empty:
226
- return;
227
-
228
- case Escape.StrictOctal:
229
- report(state, isTemplate ? Errors.TemplateOctalLiteral : Errors.StrictOctalEscape);
230
-
231
- case Escape.EightOrNine:
232
- report(state, Errors.InvalidEightAndNine);
233
-
234
- case Escape.InvalidHex:
235
- report(state, Errors.InvalidHexEscapeSequence);
236
-
237
- case Escape.OutOfRange:
238
- report(state, Errors.UnicodeOverflow);
239
-
240
- // No default
241
- }
242
- }
@@ -1,108 +0,0 @@
1
- import { ParserState, Context } from '../common';
2
- import { Token } from '../token';
3
- import { Chars } from '../chars';
4
- import { advanceChar, fromCodePoint } from './common';
5
- import { parseEscape, Escape, handleStringError } from './string';
6
- import { report, Errors } from '../errors';
7
-
8
- /**
9
- * Scan a template section. It can start either from the quote or closing brace.
10
- */
11
- export function scanTemplate(parser: ParserState, context: Context): Token {
12
- const { index: start } = parser;
13
- let token: Token = Token.TemplateSpan;
14
- let ret: string | void = '';
15
-
16
- let char = advanceChar(parser);
17
-
18
- while (char !== Chars.Backtick) {
19
- if (char === Chars.Dollar && parser.source.charCodeAt(parser.index + 1) === Chars.LeftBrace) {
20
- advanceChar(parser); // Skip: '}'
21
- token = Token.TemplateContinuation;
22
- break;
23
- } else if ((char & 8) === 8 && char === Chars.Backslash) {
24
- char = advanceChar(parser);
25
- if (char > 0x7e) {
26
- ret += fromCodePoint(char);
27
- } else {
28
- const code = parseEscape(parser, context | Context.Strict, char);
29
- if (code >= 0) {
30
- ret += fromCodePoint(code);
31
- } else if (code !== Escape.Empty && context & Context.TaggedTemplate) {
32
- ret = undefined;
33
- char = scanBadTemplate(parser, char);
34
- if (char < 0) token = Token.TemplateContinuation;
35
- break;
36
- } else {
37
- handleStringError(parser, code as Escape, /* isTemplate */ 1);
38
- }
39
- }
40
- } else {
41
- if (
42
- parser.index < parser.end &&
43
- char === Chars.CarriageReturn &&
44
- parser.source.charCodeAt(parser.index) === Chars.LineFeed
45
- ) {
46
- ret += fromCodePoint(char);
47
- parser.currentChar = parser.source.charCodeAt(++parser.index);
48
- }
49
-
50
- if (((char & 83) < 3 && char === Chars.LineFeed) || (char ^ Chars.LineSeparator) <= 1) {
51
- parser.column = -1;
52
- parser.line++;
53
- }
54
- ret += fromCodePoint(char);
55
- }
56
- if (parser.index >= parser.end) report(parser, Errors.UnterminatedTemplate);
57
- char = advanceChar(parser);
58
- }
59
-
60
- advanceChar(parser); // Consume the quote or opening brace
61
- parser.tokenValue = ret;
62
-
63
- parser.tokenRaw = parser.source.slice(start + 1, parser.index - (token === Token.TemplateSpan ? 1 : 2));
64
-
65
- return token;
66
- }
67
-
68
- /**
69
- * Scans looser template segment
70
- *
71
- * @param parser Parser state
72
- * @param ch Code point
73
- */
74
- function scanBadTemplate(parser: ParserState, ch: number): number {
75
- while (ch !== Chars.Backtick) {
76
- switch (ch) {
77
- case Chars.Dollar: {
78
- const index = parser.index + 1;
79
- if (index < parser.end && parser.source.charCodeAt(index) === Chars.LeftBrace) {
80
- parser.index = index;
81
- parser.column++;
82
- return -ch;
83
- }
84
- break;
85
- }
86
- case Chars.LineFeed:
87
- case Chars.LineSeparator:
88
- case Chars.ParagraphSeparator:
89
- parser.column = -1;
90
- parser.line++;
91
- // falls through
92
-
93
- default:
94
- // do nothing
95
- }
96
- if (parser.index >= parser.end) report(parser, Errors.UnterminatedTemplate);
97
- ch = advanceChar(parser);
98
- }
99
-
100
- return ch;
101
- }
102
-
103
- export function scanTemplateTail(parser: ParserState, context: Context): Token {
104
- if (parser.index >= parser.end) report(parser, Errors.Unexpected);
105
- parser.index--;
106
- parser.column--;
107
- return scanTemplate(parser, context);
108
- }
package/src/meriyah.ts DELETED
@@ -1,28 +0,0 @@
1
- import { Context } from './common';
2
- import { parseSource, Options } from './parser';
3
- import * as ESTree from './estree';
4
- // Current version
5
- import { version } from '../package.json';
6
-
7
- /**
8
- * Parse a script, optionally with various options.
9
- */
10
- export function parseScript(source: string, options?: Options): ESTree.Program {
11
- return parseSource(source, options, Context.None);
12
- }
13
-
14
- /**
15
- * Parse a module, optionally with various options.
16
- */
17
- export function parseModule(source: string, options?: Options): ESTree.Program {
18
- return parseSource(source, options, Context.Strict | Context.Module);
19
- }
20
-
21
- /**
22
- * Parse a module or a script, optionally with various options.
23
- */
24
- export function parse(source: string, options?: Options): ESTree.Program {
25
- return parseSource(source, options, Context.None);
26
- }
27
-
28
- export { Options, ESTree, version };