1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
// SPDX-License-Identifier: Apache-2.0
// Copyright 2026 James Conway
//! The spec's early errors: what makes a program a SyntaxError though
//! its grammar is fine.
//!
//! Most are the parser's, since it knows enough where it stands to
//! check them as it goes: [`parse`](crate::parse) fails with the first.
//! The rest need the whole program or a grammar of their own, and are
//! here, opt-in, so a parse costs nothing for them: [`early_errors`]
//! gives every one in a tree the parser accepted.
//!
//! ```
//! use parsec_js::{early_errors, parse_script};
//!
//! let src = "let total = 0;\nvar total;\nconst digits = /[9-0]/;";
//! let ast = parse_script(src).unwrap();
//! let codes: Vec<_> = early_errors(&ast, src).iter().map(|d| d.code).collect();
//! assert_eq!(codes, ["lexical-var-conflict", "regexp-range-order"]);
//! ```
//!
//! Where each rule is checked, and its code:
//!
//! | Rule | Code | Where |
//! |---|---|---|
//! | A lexical name declared twice in a scope, or as a parameter too | `duplicate-declaration` | here, from [`Scopes`] |
//! | A `var` and a lexical name of one name in a scope | `lexical-var-conflict` | here, from [`Scopes`] |
//! | A module exports a name it doesn't declare | `export-undeclared` | here |
//! | A regular expression's pattern doesn't compile | `regexp-…`, see [`regexp`] | here |
//! | A parameter given twice in strict code, an arrow, a method, or a list with defaults or patterns | `duplicate-binding` | the parser |
//! | `break` or `continue` with nothing to leave or go on with | `jump-outside-loop` | the parser |
//! | `continue` to a label that isn't on a loop | `continue-not-loop` | the parser |
//! | A label that isn't around the jump, or is used twice | `undefined-label`, `duplicate-label` | the parser |
//! | An assignment or update of something that can't be assigned | `invalid-target` | the parser |
//! | `with` in strict code | `with-in-strict` | the parser |
//! | A legacy octal literal or escape in strict code | `legacy-octal-in-strict` | the parser |
//! | `eval` or `arguments` bound or assigned in strict code | `strict-binding` | the parser |
//! | A word reserved where it's used | `reserved-word` | the parser |
//! | `delete` of a plain name in strict code | `delete-identifier` | the parser |
//! | "use strict" in a function with defaults, patterns or rest | `use-strict-with-complex-params` | the parser |
//! | `super` outside a method, `super()` outside a derived constructor | `super-outside-method` | the parser |
//! | `new.target` outside a function | `new-target-outside-function` | the parser |
//! | `yield` or `await` in parameters | `yield-in-params`, `await-in-params` | the parser |
//! | `return` outside a function | `return-outside-function` | the parser |
//! | A name exported twice | `duplicate-export` | the parser |
//! | `__proto__` twice in an object literal, not a pattern | `duplicate-proto` | the parser |
//! | A private name not declared in a class around it, or declared twice | `undeclared-private-name`, `duplicate-private-name` | the parser |
//! | `arguments` in a class field or static block | `arguments-in-class-init` | the parser |
use ;
use crate;
use crateregexp;
use crateScopes;
/// Every early error in `ast`, parsed from `src`, that the parser leaves
/// to a later pass, in source order. Empty when there's none.
/// [`early_errors`] with the [`Scopes`] already analyzed.