Skip to main content

Module diagnostics

Module diagnostics 

Source
Expand description

Every error and warning this crate reports, by its code.

A Diagnostic’s code is stable: a code isn’t renamed or reused for something else, so you can match on it, count it or turn it off. The message beside it is for people and may be reworded. Where a second place matters, like the first of two declarations or the bracket left open, a label points at it.

parse stops at the first error; parse_recovering goes on and reports each; early_errors gives the ones checked on the finished tree. Diagnostic::render prints any of them as a code frame:

use parsec_js::{LineIndex, Options, RenderOptions, parse_recovering};

let src = "let total = 0;\nouter: outer: total++;\n";
let errors = parse_recovering(src, &Options::default()).unwrap_err();
let lines = LineIndex::ecmascript(src);
let frame = errors[0].render(src, &lines, &RenderOptions::default());
assert_eq!(frame, "\
error[duplicate-label]: the label `outer` is already in use here
 --> 2:8
  |
2 | outer: outer: total++;
  | -----  ^^^^^
  | |
  | the label is defined here
");

The section in each row is ECMAScript 2025’s, where the rule is.

§The lexer’s

CodeWhat’s wrongSpec
input-too-largethe source is longer than Limits::max_input, or 4 GiB
unexpected-charactera character that starts no token, like @ or ⸯ12.6
unterminated-commenta /* with no */12.4
invalid-escapea \ in a name that doesn’t start \u, or a \x or \u escape in a string without its hex digits12.7, 12.9.4
invalid-identifier-escapea \u escape in a name for a character a name can’t hold there12.7.1.1
missing-digits0x, 0o or 0b with no digits after it12.9.3
missing-exponentan e with no digits after it, like 1e12.9.3
identifier-after-numbera letter or digit straight after a number, like 3in12.9.3
invalid-numeric-separatora _ in a number that isn’t between two digits12.9.3
legacy-octal-literal017 in strict code; a warning in sloppy code12.9.3.1
leading-zero-literal08 in strict code; a warning in sloppy code12.9.3.1
unterminated-stringa string with no closing quote on its line12.9.4
legacy-octal-escape"\01" or "\8" in strict code; a warning in sloppy code12.9.4.1
unterminated-templatea template with no closing `12.9.6
unterminated-regexpa regular expression with no closing / on its line12.9.5
invalid-regexp-flagsa regular expression’s flags written with an escape12.9.5

§The parser’s

Syntax errors, and the early errors the parser checks as it goes.

CodeWhat’s wrongSpec
unexpected-tokena token the grammar doesn’t allow where it is
unexpected-endthe source ends in the middle of something
too-deepthe tree nests deeper than Limits::max_depth
step-budgetthe parse read more tokens than Limits::max_steps
reserved-worda reserved word, or one strict code, a generator, an async function or a module reserves, as a name13.1.1
strict-bindingeval or arguments declared or assigned in strict code13.1.1
legacy-octal-in-stricta legacy octal literal or escape in code a later "use strict" makes strict12.9.3.1, 12.9.4.1
arguments-in-class-initarguments in a class field’s initializer or a static block15.7.1
await-in-class-initawait in a class field’s initializer or a static block15.7.1
shorthand-init{a = 1} as an object literal, not a pattern13.2.5.1
duplicate-proto__proto__ set twice in an object literal13.2.5.1
invalid-template-escapea bad escape in a template that isn’t tagged13.2.8.1
tagged-template-in-chainan optional chain as a template’s tag, like a?.b`c` 13.3.1.1
optional-chain-in-newnew a?.b()13.3.9
super-outside-methodsuper.x outside a method, or super() outside a derived class’s constructor15.2.1, 15.7.1
super-privatesuper.#x13.3.7
new-target-outside-functionnew.target outside a function16.1.1, 16.2.1.1
import-meta-outside-moduleimport.meta in a script13.3.1.1
new-importnew import(...)13.3.10
invalid-targetan assignment, update or binding of something that can’t be assigned, like 1 = a or a() ++13.4.1, 13.15.1
delete-identifierdelete x of a plain name in strict code13.5.1.1
delete-privatedelete this.#x13.5.1.1
unary-before-exponent-a ** b without parentheses13.6
mixed-coalesce?? beside || or && without parentheses13.13
lone-private-name#x alone, anywhere but before in13.10
arrow-operandan arrow function as an operand without parentheses15.3
arrow-params-only(), (...a) or a trailing comma kept by an expression that isn’t an arrow’s parameters13.2.9.1
rest-not-lasta rest element or parameter that isn’t last14.3.3, 15.1.1
rest-defaulta rest element with a default, like [...a = 1]14.3.3
comma-after-resta comma after a rest parameter15.1.1
yield-in-paramsyield in a generator’s parameters15.5.1
await-in-paramsawait in an async function’s parameters15.8.1, 15.9.1
duplicate-bindinga parameter given twice where that’s not allowed, or a name a let or const declares twice in one declaration14.3.1.1, 15.1.1, 15.2.1
use-strict-with-complex-params"use strict" in a function with defaults, patterns or a rest parameter15.2.1
accessor-paramsa getter with parameters, or a setter without exactly one15.4.1
special-constructora constructor that’s a getter, setter, generator or async15.7.1
duplicate-constructora class with two constructors15.7.1
static-prototypea static method or accessor named prototype15.7.1
bad-field-namea field named constructor, or a static one prototype15.7.1
private-constructor#constructor15.7.1
private-outside-classa private name declared outside a class15.7.1
duplicate-private-namea private name declared twice in a class, other than a getter and a setter15.7.1
undeclared-private-namea private name no class around it declares15.7.1, 16.1.1
declaration-not-alloweda declaration as the body of an if, loop, label or with14.6.1, B.3.1
const-without-inita const without an initializer14.3.1.1
pattern-without-inita destructuring declaration without an initializer14.3.1, 14.3.2
let-bindinglet as a name a let or const declares14.3.1.1
for-await-outside-asyncfor await outside an async function or a module14.7.5
for-in-of-declarationsa for-in or for-of head that declares more than one binding14.7.5
for-in-of-initializeran initializer in a for-in or for-of head, except Annex B’s for (var a = 1 in b)14.7.5, B.3.5
for-of-ambiguousa for-of head that starts with let, or is async of14.7.5
jump-outside-loopbreak outside a loop or a switch, or continue outside a loop14.8.1, 14.9.1
continue-not-loopcontinue a where a isn’t on a loop15.2.1, 16.1.1
undefined-labela break or continue to a label that isn’t around it15.2.1, 16.1.1
duplicate-labela label inside another of the same name15.2.1, 16.1.1
return-outside-functionreturn outside a function14.10
with-in-strictwith in strict code14.11.1
newline-after-throwa line break between throw and its expression14.14
duplicate-defaulta switch with two defaults14.12
module-item-not-allowedimport or export anywhere but a module’s top level16.2
duplicate-exporta name a module exports twice16.2.1.1
duplicate-attributean import attribute given twice16.2.2.1
import-needs-asa string imported without as a name16.2.2
export-string-locala string as the local name in an export that isn’t a re-export16.2.3.1
lone-surrogate-namean import or export name, as a string, with a lone surrogate16.2.1.1

§From early_errors

CodeWhat’s wrongSpec
duplicate-declarationa lexical name declared twice in a scope, or as a parameter too14.2.1, 15.2.1, 16.1.1
lexical-var-conflicta var and a lexical declaration of one name in a scope14.2.1, 16.1.1
export-undeclareda module exports a name it doesn’t declare16.2.1.1
regexp-…a regular expression’s pattern or flags that don’t compile; the regexp module has each13.2.7.1, 22.2.1.1

§From Ast::reparse

Besides the new source’s syntax errors:

CodeWhat’s wrongSpec
edit-out-of-rangethe edit’s range is past the end of the source, backwards, or splits a character