@ttsc/wasm 0.12.2 → 0.12.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cmd/ttsc-wasm/main.go +101 -89
- package/cmd/ttsc-wasm/main_wasm.go +6 -4
- package/dist/ttsc.wasm +0 -0
- package/host/api.go +154 -145
- package/host/doc.go +12 -12
- package/host/host.go +236 -225
- package/host/host_native.go +5 -2
- package/host/plugin.go +31 -31
- package/lib/src/MemFS.d.ts +35 -0
- package/lib/src/MemFS.js +57 -4
- package/lib/src/MemFS.js.map +1 -1
- package/lib/src/api.d.ts +46 -13
- package/lib/src/api.js +7 -4
- package/lib/src/api.js.map +1 -1
- package/lib/src/index.d.ts +1 -1
- package/lib/src/index.js +10 -3
- package/lib/src/index.js.map +1 -1
- package/lib/src/instantiate.d.ts +10 -7
- package/lib/src/instantiate.js +20 -3
- package/lib/src/instantiate.js.map +1 -1
- package/package.json +2 -2
- package/shim-vendor/shim/ast/go.mod +9 -0
- package/shim-vendor/shim/ast/go.sum +20 -0
- package/shim-vendor/shim/ast/safe_text.go +86 -0
- package/shim-vendor/shim/ast/shim.go +24 -0
- package/shim-vendor/shim/ast/test/node_text_joins_multi_hop_qualified_name_test.go +32 -0
- package/shim-vendor/shim/ast/test/node_text_joins_one_hop_qualified_name_test.go +31 -0
- package/shim-vendor/shim/ast/test/node_text_returns_empty_for_nil_test.go +23 -0
- package/shim-vendor/shim/ast/test/node_text_returns_identifier_text_test.go +27 -0
- package/shim-vendor/shim/ast/test/node_text_skips_empty_qualified_left_test.go +30 -0
- package/shim-vendor/shim/checker/shim.go +35 -0
- package/shim-vendor/shim/core/shim.go +17 -0
- package/shim-vendor/shim/diagnosticwriter/shim.go +4 -0
- package/shim-vendor/shim/lsp/shim.go +3 -3
- package/shim-vendor/shim/printer/shim.go +20 -0
- package/src/MemFS.ts +92 -7
- package/src/api.ts +46 -13
- package/src/index.ts +1 -5
- package/src/instantiate.ts +37 -14
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
// gen_shims:hand-maintained
|
|
2
|
+
//
|
|
3
|
+
// Total-function replacement for upstream `(*Node).Text()`.
|
|
4
|
+
//
|
|
5
|
+
// Upstream panics for any Kind missing from its switch — most notably
|
|
6
|
+
// KindQualifiedName, which surfaces in JSDoc parameter names (`@param
|
|
7
|
+
// obj.field`) and dotted entity references. NodeText handles
|
|
8
|
+
// QualifiedName by recursing on the left subtree and joining with the
|
|
9
|
+
// right identifier, and falls back to the source-text slice for any
|
|
10
|
+
// other Kind so downstream code can treat the helper as a total
|
|
11
|
+
// function over *Node instead of guarding each call site.
|
|
12
|
+
|
|
13
|
+
package ast
|
|
14
|
+
|
|
15
|
+
import (
|
|
16
|
+
"strings"
|
|
17
|
+
|
|
18
|
+
innerast "github.com/microsoft/typescript-go/internal/ast"
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
// NodeText returns the identifier-like text of a node. It mirrors
|
|
22
|
+
// upstream `(*Node).Text()` where upstream has an arm, adds a
|
|
23
|
+
// QualifiedName arm that joins `left.right`, and falls back to the
|
|
24
|
+
// node's source slice for any other Kind. Returns "" for nil.
|
|
25
|
+
func NodeText(n *Node) string {
|
|
26
|
+
if n == nil {
|
|
27
|
+
return ""
|
|
28
|
+
}
|
|
29
|
+
switch n.Kind {
|
|
30
|
+
case KindIdentifier,
|
|
31
|
+
innerast.KindPrivateIdentifier,
|
|
32
|
+
KindStringLiteral,
|
|
33
|
+
KindNumericLiteral,
|
|
34
|
+
KindBigIntLiteral,
|
|
35
|
+
KindNoSubstitutionTemplateLiteral,
|
|
36
|
+
KindTemplateHead,
|
|
37
|
+
KindTemplateMiddle,
|
|
38
|
+
KindTemplateTail,
|
|
39
|
+
innerast.KindRegularExpressionLiteral,
|
|
40
|
+
innerast.KindJsxNamespacedName,
|
|
41
|
+
innerast.KindJSDocText,
|
|
42
|
+
innerast.KindJSDocLink,
|
|
43
|
+
innerast.KindJSDocLinkCode,
|
|
44
|
+
innerast.KindJSDocLinkPlain,
|
|
45
|
+
innerast.KindMetaProperty:
|
|
46
|
+
return n.Text()
|
|
47
|
+
case KindQualifiedName:
|
|
48
|
+
qn := n.AsQualifiedName()
|
|
49
|
+
if qn == nil {
|
|
50
|
+
return ""
|
|
51
|
+
}
|
|
52
|
+
left := NodeText(qn.Left)
|
|
53
|
+
right := ""
|
|
54
|
+
if qn.Right != nil {
|
|
55
|
+
right = qn.Right.Text()
|
|
56
|
+
}
|
|
57
|
+
switch {
|
|
58
|
+
case left == "" && right == "":
|
|
59
|
+
return ""
|
|
60
|
+
case left == "":
|
|
61
|
+
return right
|
|
62
|
+
case right == "":
|
|
63
|
+
return left
|
|
64
|
+
default:
|
|
65
|
+
return left + "." + right
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return nodeSourceText(n)
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// nodeSourceText returns the verbatim source slice covered by the node's
|
|
72
|
+
// position range, trimmed of surrounding whitespace. Same byte range
|
|
73
|
+
// scanner.GetTextOfNode would read; safe for any Kind because it does
|
|
74
|
+
// not inspect per-Kind data fields.
|
|
75
|
+
func nodeSourceText(n *innerast.Node) string {
|
|
76
|
+
file := innerast.GetSourceFileOfNode(n)
|
|
77
|
+
if file == nil {
|
|
78
|
+
return ""
|
|
79
|
+
}
|
|
80
|
+
text := file.Text()
|
|
81
|
+
pos, end := n.Pos(), n.End()
|
|
82
|
+
if pos < 0 || end > len(text) || pos >= end {
|
|
83
|
+
return ""
|
|
84
|
+
}
|
|
85
|
+
return strings.TrimSpace(text[pos:end])
|
|
86
|
+
}
|
|
@@ -177,44 +177,68 @@ const (
|
|
|
177
177
|
ModifierFlagsReadonly = innerast.ModifierFlagsReadonly
|
|
178
178
|
)
|
|
179
179
|
|
|
180
|
+
// NewNodeFactory creates an AST node factory with the supplied creation hooks.
|
|
181
|
+
// Pass a zero-value NodeFactoryHooks to get the default factory behaviour.
|
|
180
182
|
func NewNodeFactory(options NodeFactoryHooks) *NodeFactory {
|
|
181
183
|
return innerast.NewNodeFactory(options)
|
|
182
184
|
}
|
|
183
185
|
|
|
186
|
+
// NewNodeVisitor creates a visitor that calls visit for each node encountered
|
|
187
|
+
// during a tree walk, delegating node recreation to factory using hooks.
|
|
184
188
|
func NewNodeVisitor(visit func(node *Node) *Node, factory *NodeFactory, options NodeVisitorHooks) *NodeVisitor {
|
|
185
189
|
return innerast.NewNodeVisitor(visit, factory, options)
|
|
186
190
|
}
|
|
187
191
|
|
|
192
|
+
// IsFunctionLike reports whether node is any function-like construct
|
|
193
|
+
// (function declaration, arrow function, method, constructor, accessor, etc.).
|
|
188
194
|
func IsFunctionLike(node *Node) bool {
|
|
189
195
|
return innerast.IsFunctionLike(node)
|
|
190
196
|
}
|
|
191
197
|
|
|
198
|
+
// IsPropertyAssignment reports whether node is a key:value pair inside an
|
|
199
|
+
// object literal expression.
|
|
192
200
|
func IsPropertyAssignment(node *Node) bool {
|
|
193
201
|
return innerast.IsPropertyAssignment(node)
|
|
194
202
|
}
|
|
195
203
|
|
|
204
|
+
// IsPropertyDeclaration reports whether node is a class property declaration.
|
|
196
205
|
func IsPropertyDeclaration(node *Node) bool {
|
|
197
206
|
return innerast.IsPropertyDeclaration(node)
|
|
198
207
|
}
|
|
199
208
|
|
|
209
|
+
// IsModuleBlock reports whether node is the body block of a namespace or
|
|
210
|
+
// module declaration.
|
|
200
211
|
func IsModuleBlock(node *Node) bool {
|
|
201
212
|
return innerast.IsModuleBlock(node)
|
|
202
213
|
}
|
|
203
214
|
|
|
215
|
+
// IsStringLiteral reports whether node is a string literal token.
|
|
204
216
|
func IsStringLiteral(node *Node) bool {
|
|
205
217
|
return innerast.IsStringLiteral(node)
|
|
206
218
|
}
|
|
207
219
|
|
|
220
|
+
// IsPropertyAccessExpression reports whether node is a dotted member access
|
|
221
|
+
// (e.g. `a.b`).
|
|
208
222
|
func IsPropertyAccessExpression(node *Node) bool {
|
|
209
223
|
return innerast.IsPropertyAccessExpression(node)
|
|
210
224
|
}
|
|
211
225
|
|
|
226
|
+
// IsElementAccessExpression reports whether node is a bracket member access
|
|
227
|
+
// (e.g. `a[b]`).
|
|
212
228
|
func IsElementAccessExpression(node *Node) bool {
|
|
213
229
|
return innerast.IsElementAccessExpression(node)
|
|
214
230
|
}
|
|
215
231
|
|
|
232
|
+
// GetSourceFileOfNode walks up the parent chain to return the SourceFile that
|
|
233
|
+
// owns the given node. Linked from the internal package via go:linkname because
|
|
234
|
+
// the function is unexported there.
|
|
235
|
+
//
|
|
216
236
|
//go:linkname GetSourceFileOfNode github.com/microsoft/typescript-go/internal/ast.GetSourceFileOfNode
|
|
217
237
|
func GetSourceFileOfNode(node *innerast.Node) *innerast.SourceFile
|
|
218
238
|
|
|
239
|
+
// GetNodeAtPosition returns the deepest AST node whose range covers position
|
|
240
|
+
// in file. When includeJSDoc is true the search descends into JSDoc sub-trees.
|
|
241
|
+
// Linked from the internal package via go:linkname.
|
|
242
|
+
//
|
|
219
243
|
//go:linkname GetNodeAtPosition github.com/microsoft/typescript-go/internal/ast.GetNodeAtPosition
|
|
220
244
|
func GetNodeAtPosition(file *innerast.SourceFile, position int, includeJSDoc bool) *innerast.Node
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
package ast_test
|
|
2
|
+
|
|
3
|
+
import (
|
|
4
|
+
"testing"
|
|
5
|
+
|
|
6
|
+
shimast "github.com/microsoft/typescript-go/shim/ast"
|
|
7
|
+
)
|
|
8
|
+
|
|
9
|
+
// TestNodeTextJoinsMultiHopQualifiedName verifies NodeText joins a
|
|
10
|
+
// multi-hop QualifiedName as "A.B.C".
|
|
11
|
+
//
|
|
12
|
+
// Locks the recursion in the QualifiedName arm. QualifiedName.Left is an
|
|
13
|
+
// *EntityName (Identifier OR QualifiedName), so a non-recursive
|
|
14
|
+
// implementation would silently drop everything but the final two
|
|
15
|
+
// segments — breaking dotted references like
|
|
16
|
+
// `IShoppingCoupon.IDirection.Inner` that show up in real-world JSDoc
|
|
17
|
+
// and type-argument positions.
|
|
18
|
+
//
|
|
19
|
+
// 1. Construct A.B then ((A.B).C) via NewQualifiedName.
|
|
20
|
+
// 2. Call NodeText on the outer node.
|
|
21
|
+
// 3. Assert the result is "A.B.C".
|
|
22
|
+
func TestNodeTextJoinsMultiHopQualifiedName(t *testing.T) {
|
|
23
|
+
factory := shimast.NewNodeFactory(shimast.NodeFactoryHooks{})
|
|
24
|
+
a := factory.NewIdentifier("A")
|
|
25
|
+
b := factory.NewIdentifier("B")
|
|
26
|
+
c := factory.NewIdentifier("C")
|
|
27
|
+
ab := factory.NewQualifiedName(a, b)
|
|
28
|
+
abc := factory.NewQualifiedName(ab, c)
|
|
29
|
+
if got := shimast.NodeText(abc); got != "A.B.C" {
|
|
30
|
+
t.Fatalf("NodeText(A.B.C) = %q, want %q", got, "A.B.C")
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
package ast_test
|
|
2
|
+
|
|
3
|
+
import (
|
|
4
|
+
"testing"
|
|
5
|
+
|
|
6
|
+
shimast "github.com/microsoft/typescript-go/shim/ast"
|
|
7
|
+
)
|
|
8
|
+
|
|
9
|
+
// TestNodeTextJoinsOneHopQualifiedName verifies NodeText joins a one-hop
|
|
10
|
+
// QualifiedName as "left.right".
|
|
11
|
+
//
|
|
12
|
+
// Locks the QualifiedName arm that upstream lacks: upstream's
|
|
13
|
+
// (*Node).Text() panics with `Unhandled case in Node.Text:
|
|
14
|
+
// *ast.QualifiedName` because the switch has no arm for the Kind. typia's
|
|
15
|
+
// metadata_js_doc_parameter_name calls Text() on a JSDoc tag's Name()
|
|
16
|
+
// which is a QualifiedName for `@param obj.field description`, so the
|
|
17
|
+
// panic surfaces inside the nestia/typia build pipeline. NodeText must
|
|
18
|
+
// turn a `Foo.Bar` qualified name into the dotted string.
|
|
19
|
+
//
|
|
20
|
+
// 1. Construct Foo.Bar via NewQualifiedName(Foo, Bar).
|
|
21
|
+
// 2. Call NodeText on the qualified node.
|
|
22
|
+
// 3. Assert the result is "Foo.Bar".
|
|
23
|
+
func TestNodeTextJoinsOneHopQualifiedName(t *testing.T) {
|
|
24
|
+
factory := shimast.NewNodeFactory(shimast.NodeFactoryHooks{})
|
|
25
|
+
left := factory.NewIdentifier("Foo")
|
|
26
|
+
right := factory.NewIdentifier("Bar")
|
|
27
|
+
qn := factory.NewQualifiedName(left, right)
|
|
28
|
+
if got := shimast.NodeText(qn); got != "Foo.Bar" {
|
|
29
|
+
t.Fatalf("NodeText(Foo.Bar) = %q, want %q", got, "Foo.Bar")
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
package ast_test
|
|
2
|
+
|
|
3
|
+
import (
|
|
4
|
+
"testing"
|
|
5
|
+
|
|
6
|
+
shimast "github.com/microsoft/typescript-go/shim/ast"
|
|
7
|
+
)
|
|
8
|
+
|
|
9
|
+
// TestNodeTextReturnsEmptyForNil verifies NodeText returns "" for a nil node.
|
|
10
|
+
//
|
|
11
|
+
// Locks the nil-guard at the top of NodeText. The helper is a total function
|
|
12
|
+
// over *Node — typia's JSDoc parameter-name extractor calls it without
|
|
13
|
+
// checking — so a nil-deref here would be a behaviour change for every
|
|
14
|
+
// caller. The empty-string contract is the only signal that lets callers
|
|
15
|
+
// skip "no parameter name" entries cleanly.
|
|
16
|
+
//
|
|
17
|
+
// 1. Call NodeText(nil).
|
|
18
|
+
// 2. Assert the result is "".
|
|
19
|
+
func TestNodeTextReturnsEmptyForNil(t *testing.T) {
|
|
20
|
+
if got := shimast.NodeText(nil); got != "" {
|
|
21
|
+
t.Fatalf("NodeText(nil) = %q, want %q", got, "")
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
package ast_test
|
|
2
|
+
|
|
3
|
+
import (
|
|
4
|
+
"testing"
|
|
5
|
+
|
|
6
|
+
shimast "github.com/microsoft/typescript-go/shim/ast"
|
|
7
|
+
)
|
|
8
|
+
|
|
9
|
+
// TestNodeTextReturnsIdentifierText verifies NodeText returns the
|
|
10
|
+
// identifier text when the node Kind already has an upstream Text() arm.
|
|
11
|
+
//
|
|
12
|
+
// Covers the delegated branch: for Kinds upstream supports (Identifier,
|
|
13
|
+
// StringLiteral, template parts, …), NodeText must forward to the
|
|
14
|
+
// upstream method verbatim. Falling back to the source slice would
|
|
15
|
+
// return "" for synthesised nodes that have no source range, breaking
|
|
16
|
+
// every factory-built tree we hand to the typia metadata factory.
|
|
17
|
+
//
|
|
18
|
+
// 1. Construct a synthesised Identifier via NewIdentifier("Foo").
|
|
19
|
+
// 2. Call NodeText on it.
|
|
20
|
+
// 3. Assert the result is "Foo".
|
|
21
|
+
func TestNodeTextReturnsIdentifierText(t *testing.T) {
|
|
22
|
+
factory := shimast.NewNodeFactory(shimast.NodeFactoryHooks{})
|
|
23
|
+
id := factory.NewIdentifier("Foo")
|
|
24
|
+
if got := shimast.NodeText(id); got != "Foo" {
|
|
25
|
+
t.Fatalf("NodeText(Identifier) = %q, want %q", got, "Foo")
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
package ast_test
|
|
2
|
+
|
|
3
|
+
import (
|
|
4
|
+
"testing"
|
|
5
|
+
|
|
6
|
+
shimast "github.com/microsoft/typescript-go/shim/ast"
|
|
7
|
+
)
|
|
8
|
+
|
|
9
|
+
// TestNodeTextSkipsEmptyQualifiedLeft verifies NodeText does not emit a
|
|
10
|
+
// stray leading "." when the left segment of a QualifiedName resolves
|
|
11
|
+
// to the empty string.
|
|
12
|
+
//
|
|
13
|
+
// Parser recovery (and synthesised trees) can produce a QualifiedName
|
|
14
|
+
// whose Left identifier carries empty text. A naive `left + "." + right`
|
|
15
|
+
// concatenation would yield `.Inner`, which downstream code (the typia
|
|
16
|
+
// metadata factory uses this as a map key) would treat as a distinct
|
|
17
|
+
// parameter name. The arm has to drop the empty segment instead.
|
|
18
|
+
//
|
|
19
|
+
// 1. Build a QualifiedName whose Left is an Identifier created with "".
|
|
20
|
+
// 2. Call NodeText on the qualified node.
|
|
21
|
+
// 3. Assert the result is the right-hand text with no leading dot.
|
|
22
|
+
func TestNodeTextSkipsEmptyQualifiedLeft(t *testing.T) {
|
|
23
|
+
factory := shimast.NewNodeFactory(shimast.NodeFactoryHooks{})
|
|
24
|
+
left := factory.NewIdentifier("")
|
|
25
|
+
right := factory.NewIdentifier("Inner")
|
|
26
|
+
qn := factory.NewQualifiedName(left, right)
|
|
27
|
+
if got := shimast.NodeText(qn); got != "Inner" {
|
|
28
|
+
t.Fatalf("NodeText(<empty>.Inner) = %q, want %q", got, "Inner")
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -59,34 +59,50 @@ const (
|
|
|
59
59
|
ElementFlagsVariadic = innerchecker.ElementFlagsVariadic
|
|
60
60
|
)
|
|
61
61
|
|
|
62
|
+
// IsTupleType reports whether t is a fixed-length tuple type.
|
|
62
63
|
func IsTupleType(t *innerchecker.Type) bool {
|
|
63
64
|
return innerchecker.IsTupleType(t)
|
|
64
65
|
}
|
|
65
66
|
|
|
67
|
+
// Checker_getIndexInfosOfType returns the index signatures (string/number/symbol
|
|
68
|
+
// index infos) declared on t.
|
|
66
69
|
func Checker_getIndexInfosOfType(recv *innerchecker.Checker, t *innerchecker.Type) []*innerchecker.IndexInfo {
|
|
67
70
|
return recv.GetIndexInfosOfType(t)
|
|
68
71
|
}
|
|
69
72
|
|
|
73
|
+
// Checker_getPropertiesOfType returns the named property symbols of t. For
|
|
74
|
+
// union and intersection types this is the set of properties visible on every
|
|
75
|
+
// member.
|
|
70
76
|
func Checker_getPropertiesOfType(recv *innerchecker.Checker, t *innerchecker.Type) []*innerast.Symbol {
|
|
71
77
|
return recv.GetPropertiesOfType(t)
|
|
72
78
|
}
|
|
73
79
|
|
|
80
|
+
// Checker_getApparentProperties returns the properties visible on t after
|
|
81
|
+
// resolving primitive wrapper types (e.g. string → String).
|
|
74
82
|
func Checker_getApparentProperties(recv *innerchecker.Checker, t *innerchecker.Type) []*innerast.Symbol {
|
|
75
83
|
return recv.GetApparentProperties(t)
|
|
76
84
|
}
|
|
77
85
|
|
|
86
|
+
// Checker_getTypeArguments returns the type arguments of a generic reference
|
|
87
|
+
// type, or nil when t is not a reference.
|
|
78
88
|
func Checker_getTypeArguments(recv *innerchecker.Checker, t *innerchecker.Type) []*innerchecker.Type {
|
|
79
89
|
return recv.GetTypeArguments(t)
|
|
80
90
|
}
|
|
81
91
|
|
|
92
|
+
// Checker_getTypeOfSymbol returns the declared type of symbol, resolving
|
|
93
|
+
// aliases and following late-bound types.
|
|
82
94
|
func Checker_getTypeOfSymbol(recv *innerchecker.Checker, symbol *innerast.Symbol) *innerchecker.Type {
|
|
83
95
|
return recv.GetTypeOfSymbol(symbol)
|
|
84
96
|
}
|
|
85
97
|
|
|
98
|
+
// Checker_getTypeOfSymbolAtLocation returns the contextual type of symbol as
|
|
99
|
+
// observed at the given AST node (useful for narrowed types in control flow).
|
|
86
100
|
func Checker_getTypeOfSymbolAtLocation(recv *innerchecker.Checker, symbol *innerast.Symbol, node *innerast.Node) *innerchecker.Type {
|
|
87
101
|
return recv.GetTypeOfSymbolAtLocation(symbol, node)
|
|
88
102
|
}
|
|
89
103
|
|
|
104
|
+
// Checker_getTypeOfPropertyOfType looks up the type of the named property on t
|
|
105
|
+
// and returns nil when no such property exists.
|
|
90
106
|
func Checker_getTypeOfPropertyOfType(recv *innerchecker.Checker, t *innerchecker.Type, name string) *innerchecker.Type {
|
|
91
107
|
return recv.GetTypeOfPropertyOfType(t, name)
|
|
92
108
|
}
|
|
@@ -94,6 +110,8 @@ func Checker_getTypeOfPropertyOfType(recv *innerchecker.Checker, t *innerchecker
|
|
|
94
110
|
//go:linkname checkerGetAliasSymbolForTypeNode github.com/microsoft/typescript-go/internal/checker.(*Checker).getAliasSymbolForTypeNode
|
|
95
111
|
func checkerGetAliasSymbolForTypeNode(recv *innerchecker.Checker, node *innerast.Node) *innerast.Symbol
|
|
96
112
|
|
|
113
|
+
// Checker_getAliasSymbolForTypeNode returns the alias symbol that a type node
|
|
114
|
+
// refers to when the node is itself a type alias reference (e.g. `type Foo = ...`).
|
|
97
115
|
func Checker_getAliasSymbolForTypeNode(recv *innerchecker.Checker, node *innerast.Node) *innerast.Symbol {
|
|
98
116
|
return checkerGetAliasSymbolForTypeNode(recv, node)
|
|
99
117
|
}
|
|
@@ -101,6 +119,8 @@ func Checker_getAliasSymbolForTypeNode(recv *innerchecker.Checker, node *inneras
|
|
|
101
119
|
//go:linkname checkerGetDeclarationOfAliasSymbol github.com/microsoft/typescript-go/internal/checker.(*Checker).getDeclarationOfAliasSymbol
|
|
102
120
|
func checkerGetDeclarationOfAliasSymbol(recv *innerchecker.Checker, symbol *innerast.Symbol) *innerast.Node
|
|
103
121
|
|
|
122
|
+
// Checker_getDeclarationOfAliasSymbol resolves an import/export alias symbol to
|
|
123
|
+
// its original declaration node.
|
|
104
124
|
func Checker_getDeclarationOfAliasSymbol(recv *innerchecker.Checker, symbol *innerast.Symbol) *innerast.Node {
|
|
105
125
|
return checkerGetDeclarationOfAliasSymbol(recv, symbol)
|
|
106
126
|
}
|
|
@@ -108,6 +128,8 @@ func Checker_getDeclarationOfAliasSymbol(recv *innerchecker.Checker, symbol *inn
|
|
|
108
128
|
//go:linkname checkerGetTargetOfImportSpecifier github.com/microsoft/typescript-go/internal/checker.(*Checker).getTargetOfImportSpecifier
|
|
109
129
|
func checkerGetTargetOfImportSpecifier(recv *innerchecker.Checker, node *innerast.Node) *innerast.Symbol
|
|
110
130
|
|
|
131
|
+
// Checker_getTargetOfImportSpecifier resolves an import specifier node to the
|
|
132
|
+
// exported symbol it binds. Returns nil if recv or node is nil.
|
|
111
133
|
func Checker_getTargetOfImportSpecifier(recv *innerchecker.Checker, node *innerast.Node) *innerast.Symbol {
|
|
112
134
|
if recv == nil || node == nil {
|
|
113
135
|
return nil
|
|
@@ -115,6 +137,8 @@ func Checker_getTargetOfImportSpecifier(recv *innerchecker.Checker, node *innera
|
|
|
115
137
|
return checkerGetTargetOfImportSpecifier(recv, node)
|
|
116
138
|
}
|
|
117
139
|
|
|
140
|
+
// Checker_getAliasedSymbol follows an alias chain to its final target symbol.
|
|
141
|
+
// Returns nil if recv or symbol is nil.
|
|
118
142
|
func Checker_getAliasedSymbol(recv *innerchecker.Checker, symbol *innerast.Symbol) *innerast.Symbol {
|
|
119
143
|
if recv == nil || symbol == nil {
|
|
120
144
|
return nil
|
|
@@ -132,6 +156,11 @@ func checkerResolveEntityName(
|
|
|
132
156
|
location *innerast.Node,
|
|
133
157
|
) *innerast.Symbol
|
|
134
158
|
|
|
159
|
+
// Checker_resolveEntityName resolves a dotted entity name (identifier or
|
|
160
|
+
// qualified name) to the symbol it denotes, filtered by meaning flags.
|
|
161
|
+
// When ignoreErrors is true, resolution failures are silent. When
|
|
162
|
+
// dontResolveAlias is true, the returned symbol may still be an alias.
|
|
163
|
+
// Returns nil if recv or name is nil.
|
|
135
164
|
func Checker_resolveEntityName(
|
|
136
165
|
recv *innerchecker.Checker,
|
|
137
166
|
name *innerast.Node,
|
|
@@ -149,6 +178,9 @@ func Checker_resolveEntityName(
|
|
|
149
178
|
//go:linkname checkerGetTypeNameSymbol github.com/microsoft/typescript-go/internal/checker.getTypeNameSymbol
|
|
150
179
|
func checkerGetTypeNameSymbol(t *innerchecker.Type) *innerast.Symbol
|
|
151
180
|
|
|
181
|
+
// Type_getTypeNameSymbol returns the symbol attached to t's type name field,
|
|
182
|
+
// or nil when t has no name symbol or t is nil. Linked via go:linkname because
|
|
183
|
+
// getTypeNameSymbol is a package-level unexported function in the checker.
|
|
152
184
|
func Type_getTypeNameSymbol(t *innerchecker.Type) *innerast.Symbol {
|
|
153
185
|
if t == nil {
|
|
154
186
|
return nil
|
|
@@ -159,6 +191,7 @@ func Type_getTypeNameSymbol(t *innerchecker.Type) *innerast.Symbol {
|
|
|
159
191
|
//go:linkname checkerIsArrayType github.com/microsoft/typescript-go/internal/checker.(*Checker).isArrayType
|
|
160
192
|
func checkerIsArrayType(recv *innerchecker.Checker, t *innerchecker.Type) bool
|
|
161
193
|
|
|
194
|
+
// Checker_isArrayType reports whether t is the built-in Array<T> reference type.
|
|
162
195
|
func Checker_isArrayType(recv *innerchecker.Checker, t *innerchecker.Type) bool {
|
|
163
196
|
return checkerIsArrayType(recv, t)
|
|
164
197
|
}
|
|
@@ -166,6 +199,8 @@ func Checker_isArrayType(recv *innerchecker.Checker, t *innerchecker.Type) bool
|
|
|
166
199
|
//go:linkname checkerGetBaseTypes github.com/microsoft/typescript-go/internal/checker.(*Checker).getBaseTypes
|
|
167
200
|
func checkerGetBaseTypes(recv *innerchecker.Checker, t *innerchecker.Type) []*innerchecker.Type
|
|
168
201
|
|
|
202
|
+
// Checker_getBaseTypes returns the list of base types (from `extends` clauses)
|
|
203
|
+
// for a class or interface type. Returns nil if recv or t is nil.
|
|
169
204
|
func Checker_getBaseTypes(recv *innerchecker.Checker, t *innerchecker.Type) []*innerchecker.Type {
|
|
170
205
|
if recv == nil || t == nil {
|
|
171
206
|
return nil
|
|
@@ -1,17 +1,34 @@
|
|
|
1
|
+
// Package core re-exports the subset of typescript-go's internal/core types
|
|
2
|
+
// and constants that plugins and the ttsc driver need. It provides compiler
|
|
3
|
+
// options, script-kind discrimination, tri-state booleans, and text-range
|
|
4
|
+
// primitives without exposing the full internal surface.
|
|
1
5
|
package core
|
|
2
6
|
|
|
3
7
|
import innercore "github.com/microsoft/typescript-go/internal/core"
|
|
4
8
|
|
|
9
|
+
// CompilerOptions holds the parsed tsconfig compiler options passed to the
|
|
10
|
+
// TypeScript-Go program host.
|
|
5
11
|
type CompilerOptions = innercore.CompilerOptions
|
|
12
|
+
|
|
13
|
+
// Tristate is a three-valued boolean: TSFalse, TSTrue, or TSUnknown. Used by
|
|
14
|
+
// CompilerOptions fields that can be explicitly unset.
|
|
6
15
|
type Tristate = innercore.Tristate
|
|
16
|
+
|
|
17
|
+
// TextPos is a zero-based byte offset into a source file's text.
|
|
7
18
|
type TextPos = innercore.TextPos
|
|
19
|
+
|
|
20
|
+
// TextRange is a half-open [Pos, End) byte range inside a source file.
|
|
8
21
|
type TextRange = innercore.TextRange
|
|
22
|
+
|
|
23
|
+
// ScriptKind identifies the syntactic flavour of a source file.
|
|
9
24
|
type ScriptKind = innercore.ScriptKind
|
|
10
25
|
|
|
11
26
|
const (
|
|
27
|
+
// TSFalse and TSTrue are the explicit-false and explicit-true Tristate values.
|
|
12
28
|
TSFalse = innercore.TSFalse
|
|
13
29
|
TSTrue = innercore.TSTrue
|
|
14
30
|
|
|
31
|
+
// ScriptKind* constants enumerate the file flavours typescript-go recognises.
|
|
15
32
|
ScriptKindUnknown = innercore.ScriptKindUnknown
|
|
16
33
|
ScriptKindJS = innercore.ScriptKindJS
|
|
17
34
|
ScriptKindJSX = innercore.ScriptKindJSX
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
// Package diagnosticwriter re-exports the subset of typescript-go's
|
|
2
|
+
// internal/diagnosticwriter surface that the ttsc driver uses. It provides
|
|
3
|
+
// FormatASTDiagnosticsWithColorAndContext for rendering pure tsgo diagnostics
|
|
4
|
+
// and delegates the mixed lint+tsgo rendering path to the adjacent lint.go.
|
|
1
5
|
package diagnosticwriter
|
|
2
6
|
|
|
3
7
|
import (
|
|
@@ -8,10 +8,10 @@
|
|
|
8
8
|
package lsp
|
|
9
9
|
|
|
10
10
|
import (
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
"io"
|
|
12
|
+
_ "unsafe"
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
innerlsp "github.com/microsoft/typescript-go/internal/lsp"
|
|
15
15
|
)
|
|
16
16
|
|
|
17
17
|
// Server is the opaque LSP server type from tsgo.
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
// Package printer re-exports the typescript-go internal/printer types and
|
|
2
|
+
// wraps the three functions that the ttsc driver and transform plugins need
|
|
3
|
+
// to emit source text from an AST. The surface is intentionally narrow: only
|
|
4
|
+
// the construction and single-file emit path are exposed.
|
|
1
5
|
package printer
|
|
2
6
|
|
|
3
7
|
import (
|
|
@@ -5,19 +9,35 @@ import (
|
|
|
5
9
|
innerprinter "github.com/microsoft/typescript-go/internal/printer"
|
|
6
10
|
)
|
|
7
11
|
|
|
12
|
+
// PrintHandlers provides optional hooks (e.g. substituteNode) called during
|
|
13
|
+
// AST emission.
|
|
8
14
|
type PrintHandlers = innerprinter.PrintHandlers
|
|
15
|
+
|
|
16
|
+
// Printer holds the stateful emitter produced by NewPrinter.
|
|
9
17
|
type Printer = innerprinter.Printer
|
|
18
|
+
|
|
19
|
+
// PrinterOptions configures newline style, source-map generation, and other
|
|
20
|
+
// emission knobs.
|
|
10
21
|
type PrinterOptions = innerprinter.PrinterOptions
|
|
22
|
+
|
|
23
|
+
// EmitContext accumulates per-emit metadata (source maps, comment positions)
|
|
24
|
+
// and must be created fresh for each emit round via NewEmitContext.
|
|
11
25
|
type EmitContext = innerprinter.EmitContext
|
|
12
26
|
|
|
27
|
+
// NewPrinter creates an emitter with the supplied options, substitution hooks,
|
|
28
|
+
// and emit context. Callers must pass the same EmitContext to all operations
|
|
29
|
+
// in a single emit round.
|
|
13
30
|
func NewPrinter(options PrinterOptions, handlers PrintHandlers, emitContext *EmitContext) *Printer {
|
|
14
31
|
return innerprinter.NewPrinter(options, handlers, emitContext)
|
|
15
32
|
}
|
|
16
33
|
|
|
34
|
+
// NewEmitContext allocates a fresh EmitContext for a new emit round.
|
|
17
35
|
func NewEmitContext() *EmitContext {
|
|
18
36
|
return innerprinter.NewEmitContext()
|
|
19
37
|
}
|
|
20
38
|
|
|
39
|
+
// EmitSourceFile renders the full source file through the printer and returns
|
|
40
|
+
// the emitted text.
|
|
21
41
|
func EmitSourceFile(p *Printer, sourceFile *ast.SourceFile) string {
|
|
22
42
|
return p.EmitSourceFile(sourceFile)
|
|
23
43
|
}
|