diff options
author | 2022-11-07 16:00:14 -0800 | |
---|---|---|
committer | 2022-11-07 16:00:14 -0800 | |
commit | 204f51463387c7327a5731c762923ef2c53cd335 (patch) | |
tree | 80efa4340c530518e2e42a07ffe09abb983ef5d5 /src/js_parser.zig | |
parent | 5005188a13c5a48e761fe4b65531ccb0757bc4cd (diff) | |
download | bun-204f51463387c7327a5731c762923ef2c53cd335.tar.gz bun-204f51463387c7327a5731c762923ef2c53cd335.tar.zst bun-204f51463387c7327a5731c762923ef2c53cd335.zip |
[JS Parser] Do not perform the visit pass if the parse pass had "tolerable" errors
Diffstat (limited to 'src/js_parser.zig')
-rw-r--r-- | src/js_parser.zig | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/js_parser.zig b/src/js_parser.zig index 9efdf4c14..0ea126be8 100644 --- a/src/js_parser.zig +++ b/src/js_parser.zig @@ -2335,6 +2335,7 @@ pub const Parser = struct { fn _parse(self: *Parser, comptime ParserType: type) !js_ast.Result { var p: ParserType = undefined; + const orig_error_count = self.log.errors; try ParserType.init(self.allocator, self.log, self.source, self.define, self.lexer, self.options, &p); p.should_fold_numeric_constants = self.options.features.should_fold_numeric_constants; defer p.lexer.deinit(); @@ -2364,6 +2365,15 @@ pub const Parser = struct { // June 4: "Rest of this took: 8003000" const stmts = try p.parseStmtsUpTo(js_lexer.T.t_end_of_file, &opts); + // Halt parsing right here if there were any errors + // This fixes various conditions that would cause crashes due to the AST being in an invalid state while visiting + // In a number of situations, we continue to parsing despite errors so that we can report more errors to the user + // Example where NOT halting causes a crash: A TS enum with a number literal as a member name + // https://discord.com/channels/876711213126520882/876711213126520885/1039325382488371280 + if (self.log.errors > orig_error_count) { + return error.SyntaxError; + } + try p.prepareForVisitPass(); // ESM is always strict mode. I don't think we need this. @@ -2426,6 +2436,11 @@ pub const Parser = struct { } } + // If there were errors while visiting, also halt here + if (self.log.errors > orig_error_count) { + return error.SyntaxError; + } + const uses_dirname = p.symbols.items[p.dirname_ref.innerIndex()].use_count_estimate > 0; const uses_filename = p.symbols.items[p.filename_ref.innerIndex()].use_count_estimate > 0; |