|
6 | 6 |
|
7 | 7 | "github.com/coder/guts"
|
8 | 8 | "github.com/coder/guts/bindings"
|
9 |
| - "github.com/coder/guts/bindings/walk" |
10 | 9 | "github.com/coder/guts/config"
|
11 | 10 | )
|
12 | 11 |
|
@@ -77,7 +76,6 @@ func TsMutations(ts *guts.Typescript) {
|
77 | 76 | // Omitempty + null is just '?' in golang json marshal
|
78 | 77 | // number?: number | null --> number?: number
|
79 | 78 | config.SimplifyOmitEmpty,
|
80 |
| - SimplifyUndefinedUnionFields, |
81 | 79 | )
|
82 | 80 | }
|
83 | 81 |
|
@@ -149,32 +147,3 @@ func FixSerpentStruct(gen *guts.Typescript) {
|
149 | 147 | }
|
150 | 148 | })
|
151 | 149 | }
|
152 |
| - |
153 |
| -// SimplifyUndefinedUnionFields converts 'foo: string | undefined' to 'foo?: string' |
154 |
| -func SimplifyUndefinedUnionFields(gen *guts.Typescript) { |
155 |
| - gen.ForEach(func(key string, originalNode bindings.Node) { |
156 |
| - walk.Walk(questionTokenWalker{}, originalNode) |
157 |
| - }) |
158 |
| -} |
159 |
| - |
160 |
| -type questionTokenWalker struct { |
161 |
| -} |
162 |
| - |
163 |
| -func (q questionTokenWalker) Visit(node bindings.Node) (w walk.Visitor) { |
164 |
| - switch n := node.(type) { |
165 |
| - case *bindings.PropertySignature: |
166 |
| - isUnion, ok := n.Type.(*bindings.UnionType) |
167 |
| - if !ok { |
168 |
| - return q |
169 |
| - } |
170 |
| - for i, t := range isUnion.Types { |
171 |
| - if keyword, ok := t.(*bindings.LiteralKeyword); ok && *keyword == bindings.KeywordUndefined { |
172 |
| - n.QuestionToken = true |
173 |
| - // Remove undefined |
174 |
| - isUnion.Types = append(isUnion.Types[:i], isUnion.Types[i+1:]...) |
175 |
| - break |
176 |
| - } |
177 |
| - } |
178 |
| - } |
179 |
| - return q |
180 |
| -} |
0 commit comments