mirror of
https://github.com/robertkrimen/otto
synced 2025-09-28 18:45:22 +08:00
Fix parsing of null, etc. on Object intialization
true, false, etc.
This commit is contained in:
parent
d6bb7b6285
commit
05ee181c34
|
@ -2,4 +2,12 @@ function $ERROR(message) {
|
|||
console.log(message)
|
||||
}
|
||||
|
||||
function runTestCase(fn) {
|
||||
if (fn()) {
|
||||
console.log("pass")
|
||||
} else {
|
||||
console.log("=== fail")
|
||||
}
|
||||
}
|
||||
|
||||
// ---
|
||||
|
|
6
lexer.go
6
lexer.go
|
@ -433,18 +433,19 @@ func (self *_lexer) scanIdentifierKeyword() (token _token) {
|
|||
chr := convertHexadecimalRune(string(read[2:]))
|
||||
if chr == utf8.RuneError {
|
||||
word = append(word, 'u')
|
||||
self.skip(2)
|
||||
self.skip(2) // Skip \u
|
||||
} else {
|
||||
if chr == '\\' || !identifierCheck(chr) {
|
||||
return
|
||||
}
|
||||
word = append(word, chr)
|
||||
self.skip(6)
|
||||
self.skip(6) // Skip \u????
|
||||
}
|
||||
} else {
|
||||
return
|
||||
}
|
||||
} else {
|
||||
// Basically a skip of 1
|
||||
word = append(word, self.next())
|
||||
}
|
||||
default:
|
||||
|
@ -467,6 +468,7 @@ func (self *_lexer) scanIdentifierKeyword() (token _token) {
|
|||
// Now we're looking at the body of the identiifer
|
||||
identifierCheck = isIdentifierPart
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
|
|
26
otto_test.go
26
otto_test.go
|
@ -2022,3 +2022,29 @@ func TestUnicode(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestDotMember(t *testing.T) {
|
||||
Terst(t)
|
||||
|
||||
test := runTest()
|
||||
|
||||
test(`
|
||||
abc = {
|
||||
ghi: 11,
|
||||
}
|
||||
abc.def = "Xyzzy"
|
||||
abc.null = "Nothing happens."
|
||||
`)
|
||||
test(`abc.def`, "Xyzzy")
|
||||
test(`abc.null`, "Nothing happens.")
|
||||
test(`abc.ghi`, "11")
|
||||
|
||||
test(`
|
||||
abc = {
|
||||
null: 11,
|
||||
}
|
||||
`)
|
||||
test(`abc.def`, "undefined")
|
||||
test(`abc.null`, "11")
|
||||
test(`abc.ghi`, "undefined")
|
||||
}
|
||||
|
||||
|
|
|
@ -49,7 +49,11 @@ func (self *_parser) ParseObjectPropertyKey() string {
|
|||
} else if self.Match("string") {
|
||||
return toString(self.ConsumeString().Value)
|
||||
}
|
||||
panic(self.Unexpected(self.Peek()))
|
||||
token := self.Next()
|
||||
if !isIdentifierName(token) {
|
||||
panic(self.Unexpected(token))
|
||||
}
|
||||
return token.Text
|
||||
}
|
||||
|
||||
func (self *_parser) ParseObjectProperty() *_objectPropertyNode {
|
||||
|
@ -147,7 +151,11 @@ func (self *_parser) ParseCallExpression(left _node) _node {
|
|||
|
||||
func (self *_parser) ParseDotMember(left _node) _node {
|
||||
self.Expect(".")
|
||||
member := self.ConsumeIdentifier().Value
|
||||
token := self.Next()
|
||||
member := token.Text
|
||||
if !isIdentifierName(token) {
|
||||
panic(token.newSyntaxError("Unexpected token %s", token.Kind))
|
||||
}
|
||||
node := newDotMemberNode(left, member)
|
||||
self.markNode(node)
|
||||
return node
|
||||
|
|
Loading…
Reference in New Issue
Block a user