-
Notifications
You must be signed in to change notification settings - Fork 570
Open
Labels
Description
I noticed that the order of files in compiler.Compile must be identical to ensure reproducible output. Would sorting them be a good idea?
// Files must be in the same order to get reproducible JS
sort.Slice(files, func(i, j int) bool {
return fileSet.File(files[i].Pos()).Name() > fileSet.File(files[j].Pos()).Name()
})This causes problems in parseAndAugment... In the fileSet, the additional files added are named as if they are not in the same directory as the other files... you'll get something like this:
/my_go_root/src/time/format.go
/my_go_root/src/time/sleep.go
/my_go_root/src/time/sys_unix.go
/my_go_root/src/time/tick.go
/my_go_root/src/time/time.go
/my_go_root/src/time/zoneinfo.go
/my_go_root/src/time/zoneinfo_read.go
/src/time/time.go
The order of the additional file would be dependent on the goroot of the user running the command, so not ideal again. I propose a small change to fix this:
...
// Files should be uniquely named and in the original package directory in order to be
// ordered correctly
newPath := path.Join(pkg.Dir, "__"+name)
file, err := parser.ParseFile(fileSet, newPath, r, parser.ParseComments)
...Just fixing the directory isn't quite enough, because it then appears there are two files with identical names. We can fix this by making the filename unique.
I've created a quick PR for this: #742 - let me know what you think!