Skip to content

Commit 4e8793e

Browse files
committed
Get type pointer
1 parent ba05562 commit 4e8793e

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

internal/ast/node_unsafe.go

+17-8
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ package ast
44

55
import (
66
"sync/atomic"
7+
"unsafe"
78

89
"github.com/microsoft/typescript-go/internal/core"
910
)
@@ -13,22 +14,30 @@ import (
1314
// interface valued properties either store a true nil or a reference to a non-nil struct.
1415

1516
type Node struct {
16-
Kind Kind
17-
Flags NodeFlags
18-
Loc core.TextRange
19-
id atomic.Uint32
20-
Parent *Node
21-
_data nodeData
17+
Kind Kind
18+
Flags NodeFlags
19+
Loc core.TextRange
20+
id atomic.Uint32
21+
Parent *Node
22+
dataType unsafe.Pointer
23+
}
24+
25+
type interfaceValue struct {
26+
typ unsafe.Pointer
27+
value unsafe.Pointer
2228
}
2329

2430
func (n *Node) data() nodeData {
25-
return n._data
31+
var data nodeData
32+
(*interfaceValue)(unsafe.Pointer(&data)).typ = n.dataType
33+
(*interfaceValue)(unsafe.Pointer(&data)).value = unsafe.Pointer(n)
34+
return data
2635
}
2736

2837
func newNode(kind Kind, data nodeData) *Node {
2938
n := data.AsNode()
3039
n.Loc = core.UndefinedTextRange()
3140
n.Kind = kind
32-
n._data = data
41+
n.dataType = (*interfaceValue)(unsafe.Pointer(&data)).typ
3342
return n
3443
}

0 commit comments

Comments
 (0)