aboutsummaryrefslogtreecommitdiff
path: root/src/js_lexer.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/js_lexer.zig')
-rw-r--r--src/js_lexer.zig61
1 files changed, 26 insertions, 35 deletions
diff --git a/src/js_lexer.zig b/src/js_lexer.zig
index 47b6fdcb9..24484a02b 100644
--- a/src/js_lexer.zig
+++ b/src/js_lexer.zig
@@ -295,7 +295,7 @@ fn NewLexer_(
this.comments_to_preserve_before.clearAndFree();
}
- pub fn decodeEscapeSequences(lexer: *LexerType, start: usize, text: string, comptime BufType: type, buf_: *BufType) !void {
+ fn decodeEscapeSequences(lexer: *LexerType, start: usize, text: string, comptime BufType: type, buf_: *BufType) !void {
var buf = buf_.*;
defer buf_.* = buf;
if (comptime is_json) lexer.is_ascii_only = false;
@@ -2075,11 +2075,9 @@ fn NewLexer_(
if (comptime is_json) unreachable;
}
- // returns true of the regex contents need to be decoded
- pub fn scanRegExp(lexer: *LexerType) !bool {
+ pub fn scanRegExp(lexer: *LexerType) !void {
lexer.assertNotJSON();
lexer.regex_flags_start = null;
- var decode = lexer.code_point >= 0x80;
while (true) {
switch (lexer.code_point) {
'/' => {
@@ -2123,48 +2121,20 @@ fn NewLexer_(
},
}
}
-
- return decode;
+ return;
},
'[' => {
lexer.step();
- if (lexer.code_point >= 0x80) decode = true;
while (lexer.code_point != ']') {
- try lexer.scanRegExpValidateAndStep(&decode);
+ try lexer.scanRegExpValidateAndStep();
}
lexer.step();
- if (lexer.code_point >= 0x80) decode = true;
},
else => {
- try lexer.scanRegExpValidateAndStep(&decode);
+ try lexer.scanRegExpValidateAndStep();
},
}
}
-
- return decode;
- }
-
- fn scanRegExpValidateAndStep(lexer: *LexerType, decode: *bool) !void {
- lexer.assertNotJSON();
-
- if (lexer.code_point == '\\') {
- lexer.step();
- if (lexer.code_point >= 0x80) decode.* = true;
- }
-
- switch (lexer.code_point) {
- '\r', '\n', 0x2028, 0x2029 => {
- // Newlines aren't allowed in regular expressions
- try lexer.syntaxError();
- },
- -1 => { // EOF
- try lexer.syntaxError();
- },
- else => {
- lexer.step();
- if (lexer.code_point >= 0x80) decode.* = true;
- },
- }
}
// TODO: use wtf-8 encoding.
@@ -2622,6 +2592,27 @@ fn NewLexer_(
try lexer.nextInsideJSXElement();
}
+ fn scanRegExpValidateAndStep(lexer: *LexerType) !void {
+ lexer.assertNotJSON();
+
+ if (lexer.code_point == '\\') {
+ lexer.step();
+ }
+
+ switch (lexer.code_point) {
+ '\r', '\n', 0x2028, 0x2029 => {
+ // Newlines aren't allowed in regular expressions
+ try lexer.syntaxError();
+ },
+ -1 => { // EOF
+ try lexer.syntaxError();
+ },
+ else => {
+ lexer.step();
+ },
+ }
+ }
+
pub fn rescanCloseBraceAsTemplateToken(lexer: *LexerType) !void {
lexer.assertNotJSON();