diff options
author | 2022-02-08 20:43:15 -0800 | |
---|---|---|
committer | 2022-02-08 20:45:55 -0800 | |
commit | 1f137ca78ac72fe2f1a6fb0aadda24ca6e111fee (patch) | |
tree | 8bc681d6d7fc266633fe430837cff448b03b7945 | |
parent | 519c037e4b2bbca1590fa6b502909c8da7248361 (diff) | |
download | bun-1f137ca78ac72fe2f1a6fb0aadda24ca6e111fee.tar.gz bun-1f137ca78ac72fe2f1a6fb0aadda24ca6e111fee.tar.zst bun-1f137ca78ac72fe2f1a6fb0aadda24ca6e111fee.zip |
port like 1/3 of it
-rw-r--r-- | src/ast/base.zig | 10 | ||||
-rw-r--r-- | src/js_parser/js_parser.zig | 9 |
2 files changed, 15 insertions, 4 deletions
diff --git a/src/ast/base.zig b/src/ast/base.zig index ad0d34efd..7cd5032fd 100644 --- a/src/ast/base.zig +++ b/src/ast/base.zig @@ -70,6 +70,16 @@ pub const Ref = packed struct { return @intCast(Int, int); } + pub inline fn slice(this: Ref, text: []const u8) []const u8 { + return if (!this.isNull()) text[this.source_index .. this.source_index + this.inner_index] else ""; + } + + pub fn from(text: []const u8, section: []const u8) Ref { + const start = Ref.toInt(@ptrToInt(section.ptr) - @ptrToInt(text.ptr)); + const end = Ref.toInt(section.len); + return Ref{ .source_index = start, .inner_index = end, .is_source_contents_slice = true }; + } + pub fn hash(key: Ref) u32 { return @truncate(u32, key.hash64()); } diff --git a/src/js_parser/js_parser.zig b/src/js_parser/js_parser.zig index a7d079108..fc11a3b24 100644 --- a/src/js_parser/js_parser.zig +++ b/src/js_parser/js_parser.zig @@ -2681,7 +2681,7 @@ pub const Parser = struct { fn _parse(self: *Parser, comptime ParserType: type) !js_ast.Result { var p: ParserType = undefined; - try ParserType.init(self.allocator, self.log, self.source, self.define, try js_lexer.Lexer.init(self.log, self.source.*, self.allocator), self.options, &p); + try ParserType.init(self.allocator, self.log, self.source, self.define, self.lexer, self.options, &p); defer p.lexer.deinit(); // Consume a leading hashbang comment @@ -2700,7 +2700,7 @@ pub const Parser = struct { // June 4: "Rest of this took: 8003000" const stmts = try p.parseStmtsUpTo(js_lexer.T.t_end_of_file, &opts); - const result = try runVisitPassAndFinish(ParserType, &p, stmts); + const result = self.runVisitPassAndFinish(ParserType, &p, stmts); return result; } @@ -3983,7 +3983,7 @@ pub fn NewParser( try p.scopes_for_current_part.append(p.allocator, order.scope); } - pub fn pushScopeForParsePass(p: *P, comptime kind: js_ast.Scope.Kind, loc: logger.Loc) !usize { + fn pushScopeForParsePass(p: *P, comptime kind: js_ast.Scope.Kind, loc: logger.Loc) !usize { var parent: *Scope = p.current_scope; const allocator = p.allocator; var scope = try allocator.create(Scope); @@ -10518,6 +10518,7 @@ pub fn NewParser( .utf8 = name, }, loc) }, .range = tag_range, + .name = name, }; } @@ -15437,7 +15438,7 @@ pub fn NewParser( const JavaScriptParser = NewParser(.{}); const JSXParser = NewParser(.{ .jsx = .react }); const TSXParser = NewParser(.{ .jsx = .react, .typescript = true }); -pub const MDXParser = NewParser(.{ .jsx = .mdx }); +const MDXParser = NewParser(.{ .jsx = .mdx }); const TypeScriptParser = NewParser(.{ .typescript = true }); const JSParserMacro = NewParser(.{ |