Make end brace peek stricter and fix the test

This commit is contained in:
wyozi
2020-10-09 21:18:40 +08:00
committed by Jun Yang
parent e2e410f334
commit e67c3c6924
2 changed files with 4 additions and 3 deletions
+2 -1
View File
@@ -211,7 +211,8 @@ export class Tokenizer {
this.p++ this.p++
const prop = this.readQuoted() const prop = this.readQuoted()
if (!prop) return if (!prop) return
this.readTo(']') if (this.peek() !== ']') return
this.p++
return new PropertyAccessToken(prop, [], this.p) return new PropertyAccessToken(prop, [], this.p)
} }
+2 -2
View File
@@ -40,8 +40,8 @@ describe('Tokenize', function () {
expect((value as PropertyAccessToken).variable.getText()).to.equal('"a prop"') expect((value as PropertyAccessToken).variable.getText()).to.equal('"a prop"')
}) })
it('should throw for incomplete quoted property access', () => { it('should throw for incomplete quoted property access', () => {
const tokenizer = new Tokenizer('["a prop"]') const tokenizer = new Tokenizer('["a prop"')
expect(() => tokenizer.readValue()).to.throw() expect(() => tokenizer.readValueOrThrow()).to.throw()
}) })
it('should read hash', () => { it('should read hash', () => {
const hash1 = new Tokenizer('foo: 3').readHash() const hash1 = new Tokenizer('foo: 3').readHash()