Otto loaded js file error: (anonymous): Line 1:59374 Invalid regular expression:re2:Invalid (? =) (and 1 more errors)
Enclose main code
vm := otto.New()
vm.Set("require", require)
val,err := vm.Run(`
require("raphael.js");
`)
Enclose Load method
func require(call otto.FunctionCall) otto.Value {
file := call.Argument(0).String()
fmt.Printf("requiring: %s
", file)
data, err := ioutil.ReadFile(file)
if err != nil {
fmt.Println(err)
panic(err)
}
_, err = call.Otto.Run(string(data))
if err != nil {
fmt.Println(err)
panic(err)
}
return otto.TrueValue()
}
Js file address (I saved locally)
http://index.baidu.com/static/js/raphael.js
The problem occur because otto dont fully support regular expression.
In the doc from otto they said :
(?=) // Lookahead (positive), currently a parsing error
(?!) // Lookahead (backhead), currently a parsing error
\1 // Backreference (\1, \2, \3, ...), currently a parsing error
https://github.com/robertkrimen/otto#regular-expression-incompatibility