Closed
Description
Go source code is Unicode text encoded in UTF-8. (Source.)
GopherJS fails to process some unicode characters in Go code and emits JavaScript that does not print the correct characters.
I think it fails on "astral planes", or unicode characters that require more than 2 bytes using utf-8 encoding. But this is just a hypothesis from limited evidence/investigation.
Compare:
console.log("Hello, 世界. 😀!"); // U+1F600 emoji.
package main
import "fmt"
func main() {
fmt.Println("Hello, 世界. 😀!") // U+1F600 emoji.
}
https://play.golang.org/p/M1rXP8bm6L
http://www.gopherjs.org/playground/
(You'll have to manually paste the code into GopherJS Playground. Due to the bug in GopherJS, the snippet cannot be loaded correctly.)
Thank you to @peggyl for the original report of this issue at https://gist.github.com/peggyl/72d47f6652d30a4f566a!
Relevant Reading
- http://www.fileformat.info/info/unicode/char/1f600/index.htm
- https://mathiasbynens.be/notes/javascript-unicode
- https://mathiasbynens.be/notes/javascript-escapes#unicode-code-point
- https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode
- https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCodePoint
Metadata
Metadata
Assignees
Labels
No labels