Tokenizer: Copy optional tokens prior to being set to null #3737 (#3910)

* Tokenizer: Copy optional tokens prior to being set to null #3737

* Add TODO comments, reminder to audit copying optional pattern.
This commit is contained in:
Lachlan Easton 2019-12-17 03:01:02 +11:00 committed by Andrew Kelley
parent 0f09ff4923
commit fe0e8c87b7
2 changed files with 7 additions and 2 deletions

View File

@ -886,6 +886,7 @@ pub const TokenStream = struct {
pub fn next(self: *TokenStream) Error!?Token {
if (self.token) |token| {
// TODO: Audit this pattern once #2915 is closed
const copy = token;
self.token = null;
return copy;

View File

@ -411,8 +411,10 @@ pub const Tokenizer = struct {
pub fn next(self: *Tokenizer) Token {
if (self.pending_invalid_token) |token| {
// TODO: Audit this pattern once #2915 is closed
const copy = token;
self.pending_invalid_token = null;
return token;
return copy;
}
const start_index = self.index;
var state = State.Start;
@ -1265,8 +1267,10 @@ pub const Tokenizer = struct {
if (result.id == Token.Id.Eof) {
if (self.pending_invalid_token) |token| {
// TODO: Audit this pattern once #2915 is closed
const copy = token;
self.pending_invalid_token = null;
return token;
return copy;
}
}