aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <jarred@jarredsumner.com> 2021-04-18 21:35:31 -0700
committerGravatar Jarred Sumner <jarred@jarredsumner.com> 2021-04-18 21:35:31 -0700
commit422e2e8329990a313a150900b5527b47be89d20c (patch)
tree9ceded7026e5f6295838b84b02ccc6942113b9d3
parentc6b137b4add937cb9f771f63b8b189b233c66d78 (diff)
downloadbun-422e2e8329990a313a150900b5527b47be89d20c.tar.gz
bun-422e2e8329990a313a150900b5527b47be89d20c.tar.zst
bun-422e2e8329990a313a150900b5527b47be89d20c.zip
asdasdqweqweqwd
-rw-r--r--src/js_lexer.zig117
1 files changed, 114 insertions, 3 deletions
diff --git a/src/js_lexer.zig b/src/js_lexer.zig
index b54ff2d81..878d81df1 100644
--- a/src/js_lexer.zig
+++ b/src/js_lexer.zig
@@ -10,6 +10,9 @@ pub const Keywords = tables.Keywords;
pub const tokenToString = tables.tokenToString;
pub const jsxEntity = tables.jsxEntity;
+// TODO: JSON
+const IS_JSON_FILE = false;
+
const string = []const u8;
pub const Lexer = struct {
@@ -518,16 +521,16 @@ pub const Lexer = struct {
switch (lexer.code_point) {
'=' => {
lexer.step();
- lexer.Token = TExclamationEqualsEquals;
+ lexer.token = T.t_exclamation_equals_equals;
},
else => {
- lexer.Token = TExclamationEquals;
+ lexer.token = T.t_exclamation_equals;
},
}
},
else => {
- lexer.Token = TExclamation;
+ lexer.token = T.t_exclamation;
},
}
},
@@ -545,6 +548,114 @@ pub const Lexer = struct {
lexer.token = T.t_no_substitution_template_literal;
}
lexer.step();
+
+ stringLiteral: while (true) {
+ switch (lexer.codePoint) {
+ '\\' => {
+ needs_slow_path = true;
+ lexer.step();
+
+ // Handle Windows CRLF
+ if (lexer.code_point == '\r' and IS_JSON_FILE) {
+ lexer.step();
+ if (lexer.code_point == '\n') {
+ lexer.step();
+ }
+ continue;
+ }
+ },
+ // This indicates the end of the file
+
+ -1 => {
+ lexer.addError("Unterminated string literal");
+ },
+
+ '\r' => {
+ if (quote != '`') {
+ lexer.addError("Unterminated string literal");
+ }
+
+ // Template literals require newline normalization
+ needsSlowPath = true;
+ },
+
+ '\n' => {
+ if (quote != '`') {
+ lexer.addError("Unterminated string literal");
+ }
+ },
+
+ '$' => {
+ if (quote == '`') {
+ lexer.step();
+ if (lexer.codePoint == '{') {
+ suffixLen = 2;
+ lexer.step();
+ if (lexer.rescan_close_brace_as_template_token) {
+ lexer.token = T.t_template_middle;
+ } else {
+ lexer.token = T.t_template_head;
+ }
+ break stringLiteral;
+ }
+ continue;
+ }
+ },
+
+ quote => {
+ lexer.step();
+ break stringLiteral;
+ },
+
+ else => {
+ // Non-ASCII strings need the slow path
+ if (lexer.codePoint >= 0x80) {
+ needsSlowPath = true;
+ } else if (IS_JSON_FILE and lexer.codePoint < 0x20) {
+ lexer.syntax_error();
+ }
+ },
+ }
+ lexer.step();
+ }
+
+ const text = lexer.source.Contents[lexer.start + 1 .. lexer.end - suffixLen];
+
+ if (needsSlowPath) {
+ // Slow path
+ lexer.string_literal = lexer.decodeEscapeSequences(lexer.start + 1, text);
+ } else {
+ // Fast path
+
+ }
+ },
+
+ '_', '$', 'a'...'z', 'A'...'Z' => {
+ lexer.step();
+ while (isIdentifierContinue(lexer.code_point)) {
+ lexer.step();
+ }
+
+ if (lexer.codePoint == '\\') {
+ lexer.scanIdentifierWithEscapes();
+ } else {
+ const contents = lexer.raw();
+ lexer.identifier = contents;
+ if (Keywords.get(contents)) |keyword| {
+ lexer.token = keyword;
+ } else {
+ lexer.token = T.t_identifier;
+ }
+ }
+ },
+
+ '\\' => {
+ // TODO: normal
+ lexer.scanIdentifierWithEscapes();
+ },
+
+ '.', '0'...'9' => {
+ lexer.parseNumericLiteralOrDot();
},
else => {