diff options
author | 2021-05-28 13:27:05 -0700 | |
---|---|---|
committer | 2021-05-28 13:27:05 -0700 | |
commit | 2172f3c5e367e604349ad17866f7408ac259ca73 (patch) | |
tree | fbd7de1fceb0e956b88a23c3740000a2b9e376da | |
parent | d44fa1ca928ff69d7073607d6ea0d8dd31511341 (diff) | |
download | bun-2172f3c5e367e604349ad17866f7408ac259ca73.tar.gz bun-2172f3c5e367e604349ad17866f7408ac259ca73.tar.zst bun-2172f3c5e367e604349ad17866f7408ac259ca73.zip |
keep lexer/loc
-rw-r--r-- | build.zig | 2 | ||||
-rw-r--r-- | src/js_lexer.zig | 26 | ||||
-rw-r--r-- | src/logger.zig | 4 |
3 files changed, 28 insertions, 4 deletions
@@ -118,7 +118,7 @@ pub fn build(b: *std.build.Builder) void { const env = std.process.getEnvMap(std.heap.c_allocator) catch unreachable; // if (env.get("SDKROOT")) |sdkroot| { - // const joined = resolve_path.normalizeAndJoin2(cwd, .auto, sdkroot, "usr/include"); + // const joined = resolve_path.joinAbs2(cwd, .auto, sdkroot, "usr/include"); // const sys = std.heap.c_allocator.dupe(u8, joined) catch unreachable; // exe.addSystemIncludeDir(sys); // } diff --git a/src/js_lexer.zig b/src/js_lexer.zig index 80a30e045..132268f10 100644 --- a/src/js_lexer.zig +++ b/src/js_lexer.zig @@ -126,9 +126,13 @@ pub const Lexer = struct { } inline fn nextCodepointSlice(it: *LexerType) !?[]const u8 { + @setRuntimeSafety(false); + if (it.current >= it.source.contents.len) { // without this line, strings cut off one before the last characte it.end = it.current; + @setRuntimeSafety(false); + return null; } @@ -234,7 +238,7 @@ pub const Lexer = struct { const start_length = buf.items.len; while (iter.nextCodepoint()) |c| { const width = iter.width; - + @setRuntimeSafety(false); switch (c) { '\r' => { // From the specification: @@ -257,6 +261,8 @@ pub const Lexer = struct { }, '\\' => { + @setRuntimeSafety(false); + const c2 = iter.nextCodepoint() orelse return; const width2 = iter.width; switch (c2) { @@ -492,6 +498,8 @@ pub const Lexer = struct { var needs_slow_path = false; var suffix_len: u3 = 1; stringLiteral: while (true) { + @setRuntimeSafety(false); + switch (lexer.code_point) { '\\' => { try lexer.step(); @@ -924,6 +932,7 @@ pub const Lexer = struct { while (true) { lexer.start = lexer.end; lexer.token = T.t_end_of_file; + @setRuntimeSafety(false); switch (lexer.code_point) { -1 => { @@ -931,10 +940,14 @@ pub const Lexer = struct { }, '#' => { + @setRuntimeSafety(false); + if (lexer.start == 0 and lexer.source.contents[1] == '!') { // "#!/usr/bin/env node" lexer.token = .t_hashbang; hashbang: while (true) { + @setRuntimeSafety(false); + try lexer.step(); switch (lexer.code_point) { '\r', '\n', 0x2028, 0x2029 => { @@ -950,10 +963,14 @@ pub const Lexer = struct { } else { try lexer.step(); if (lexer.code_point == '\\') { + @setRuntimeSafety(false); + const scan_result = try lexer.scanIdentifierWithEscapes(.private); lexer.identifier = scan_result.contents; lexer.token = T.t_private_identifier; } else { + @setRuntimeSafety(false); + if (!isIdentifierStart(lexer.code_point)) { try lexer.syntaxError(); } @@ -2529,6 +2546,8 @@ pub fn isIdentifierStart(codepoint: CodePoint) bool { } } pub fn isIdentifierContinue(codepoint: CodePoint) bool { + @setRuntimeSafety(false); + switch (codepoint) { '_', '$', '0'...'9', 'a'...'z', 'A'...'Z' => { return true; @@ -2612,6 +2631,8 @@ pub fn isIdentifierUTF16(text: JavascriptString) bool { var i: usize = 0; while (i < n) : (i += 1) { + @setRuntimeSafety(false); + var r1 = @intCast(i32, text[i]); if (r1 >= 0xD800 and r1 <= 0xDBFF and i + 1 < n) { const r2 = @intCast(i32, text[i + 1]); @@ -2654,6 +2675,7 @@ pub const CodepointIterator = struct { pub fn nextCodepoint(it: *CodepointIterator) ?CodePoint { const slice = it.nextCodepointSlice() orelse return null; it.width = @intCast(u3, slice.len); + @setRuntimeSafety(false); it.c = switch (it.width) { 1 => @intCast(CodePoint, slice[0]), @@ -2707,6 +2729,8 @@ pub fn rangeOfIdentifier(source: *const Source, loc: logger.Loc) logger.Range { defer r.len = @intCast(i32, iter.i); while (iter.nextCodepoint()) |code_point| { if (code_point == '\\') { + @setRuntimeSafety(false); + // Search for the end of the identifier // Skip over bracketed unicode escapes such as "\u{10000}" diff --git a/src/logger.zig b/src/logger.zig index 233df0485..4d9e5150a 100644 --- a/src/logger.zig +++ b/src/logger.zig @@ -373,8 +373,8 @@ pub const Log = struct { } }; -pub fn usize2Loc(loc: usize) Loc { - return Loc{ .start = std.math.lossyCast(i32, loc) }; +pub inline fn usize2Loc(loc: usize) Loc { + return Loc{ .start = @intCast(i32, loc) }; } pub const Source = struct { |