mirror of
https://github.com/zhigang1992/esbuild.git
synced 2026-01-12 22:46:54 +08:00
remove unnecessary dependency: kylelemons/godebug
This commit is contained in:
5
go.mod
5
go.mod
@@ -2,7 +2,4 @@ module github.com/evanw/esbuild
|
||||
|
||||
go 1.13
|
||||
|
||||
require (
|
||||
github.com/kylelemons/godebug v1.1.0
|
||||
golang.org/x/sys v0.0.0-20200501145240-bc7a7d42d5c3
|
||||
)
|
||||
require golang.org/x/sys v0.0.0-20200501145240-bc7a7d42d5c3
|
||||
|
||||
2
go.sum
2
go.sum
@@ -1,4 +1,2 @@
|
||||
github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc=
|
||||
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
|
||||
golang.org/x/sys v0.0.0-20200501145240-bc7a7d42d5c3 h1:5B6i6EAiSYyejWfvc5Rc9BbI3rzIsrrXfAQBWnYfn+w=
|
||||
golang.org/x/sys v0.0.0-20200501145240-bc7a7d42d5c3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
|
||||
@@ -21,7 +21,7 @@ import (
|
||||
"github.com/evanw/esbuild/internal/fs"
|
||||
"github.com/evanw/esbuild/internal/logger"
|
||||
"github.com/evanw/esbuild/internal/resolver"
|
||||
"github.com/kylelemons/godebug/diff"
|
||||
"github.com/evanw/esbuild/internal/test"
|
||||
)
|
||||
|
||||
func es(version int) compat.JSFeature {
|
||||
@@ -36,7 +36,7 @@ func assertEqual(t *testing.T, a interface{}, b interface{}) {
|
||||
stringA := fmt.Sprintf("%v", a)
|
||||
stringB := fmt.Sprintf("%v", b)
|
||||
if strings.Contains(stringA, "\n") {
|
||||
t.Fatal(diff.Diff(stringB, stringA))
|
||||
t.Fatal(test.Diff(stringB, stringA))
|
||||
} else {
|
||||
t.Fatalf("%s != %s", a, b)
|
||||
}
|
||||
|
||||
66
internal/test/diff.go
Normal file
66
internal/test/diff.go
Normal file
@@ -0,0 +1,66 @@
|
||||
package test
|
||||
|
||||
import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
func Diff(old string, new string) string {
|
||||
return strings.Join(diffRec(nil, strings.Split(old, "\n"), strings.Split(new, "\n")), "\n")
|
||||
}
|
||||
|
||||
// This is a simple recursive line-by-line diff implementation
|
||||
func diffRec(result []string, old []string, new []string) []string {
|
||||
o, n, common := lcSubstr(old, new)
|
||||
|
||||
if common == 0 {
|
||||
// Everything changed
|
||||
for _, line := range old {
|
||||
result = append(result, "-"+line)
|
||||
}
|
||||
for _, line := range new {
|
||||
result = append(result, "+"+line)
|
||||
}
|
||||
} else {
|
||||
// Something in the middle stayed the same
|
||||
result = diffRec(result, old[:o], new[:n])
|
||||
for _, line := range old[o : o+common] {
|
||||
result = append(result, " "+line)
|
||||
}
|
||||
result = diffRec(result, old[o+common:], new[n+common:])
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
// From: https://en.wikipedia.org/wiki/Longest_common_substring_problem
|
||||
func lcSubstr(S []string, T []string) (int, int, int) {
|
||||
r := len(S)
|
||||
n := len(T)
|
||||
Lprev := make([]int, n)
|
||||
Lnext := make([]int, n)
|
||||
z := 0
|
||||
retI := 0
|
||||
retJ := 0
|
||||
|
||||
for i := 0; i < r; i++ {
|
||||
for j := 0; j < n; j++ {
|
||||
if S[i] == T[j] {
|
||||
if j == 0 {
|
||||
Lnext[j] = 1
|
||||
} else {
|
||||
Lnext[j] = Lprev[j-1] + 1
|
||||
}
|
||||
if Lnext[j] > z {
|
||||
z = Lnext[j]
|
||||
retI = i + 1
|
||||
retJ = j + 1
|
||||
}
|
||||
} else {
|
||||
Lnext[j] = 0
|
||||
}
|
||||
}
|
||||
Lprev, Lnext = Lnext, Lprev
|
||||
}
|
||||
|
||||
return retI - z, retJ - z, z
|
||||
}
|
||||
Reference in New Issue
Block a user