ttsc 0.4.4-dev.20260426 → 0.5.0-dev.20260429
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/README.md +35 -3
- package/cmd/ttsc/main.go +2 -2
- package/driver/program.go +120 -15
- package/go.mod +3 -3
- package/go.sum +6 -6
- package/lib/api.d.ts +3 -3
- package/lib/api.js +275 -624
- package/lib/api.js.map +1 -1
- package/lib/cli.js +78 -2
- package/lib/cli.js.map +1 -1
- package/lib/index.d.ts +3 -3
- package/lib/index.js +3 -3
- package/lib/native.d.ts +5 -0
- package/lib/native.js +8 -0
- package/lib/native.js.map +1 -1
- package/lib/plugin.d.ts +8 -48
- package/lib/plugin.js +79 -132
- package/lib/plugin.js.map +1 -1
- package/lib/runner/cli.js +1 -0
- package/lib/runner/cli.js.map +1 -1
- package/lib/source-build.d.ts +30 -0
- package/lib/source-build.js +365 -0
- package/lib/source-build.js.map +1 -0
- package/package.json +9 -9
- package/shim/ast/go.mod +1 -1
- package/shim/ast/lint.go +328 -0
- package/shim/bundled/go.mod +1 -1
- package/shim/checker/go.mod +1 -1
- package/shim/compiler/go.mod +1 -1
- package/shim/core/go.mod +1 -1
- package/shim/core/shim.go +15 -0
- package/shim/diagnosticwriter/go.mod +1 -1
- package/shim/diagnosticwriter/lint.go +137 -0
- package/shim/parser/go.mod +1 -1
- package/shim/scanner/go.mod +1 -1
- package/shim/tsoptions/go.mod +1 -1
- package/shim/tspath/go.mod +1 -1
- package/shim/vfs/cachedvfs/go.mod +1 -1
- package/shim/vfs/go.mod +1 -1
- package/shim/vfs/osvfs/go.mod +1 -1
- package/src/api.ts +413 -771
- package/src/cli.ts +82 -2
- package/src/index.ts +3 -3
- package/src/native.ts +18 -0
- package/src/plugin.ts +107 -213
- package/src/runner/cli.ts +5 -0
- package/src/source-build.ts +383 -0
- package/test/native.test.ts +43 -0
- package/test/source-build.test.ts +219 -0
package/shim/ast/lint.go
ADDED
|
@@ -0,0 +1,328 @@
|
|
|
1
|
+
// Lint-oriented additions to the AST shim.
|
|
2
|
+
//
|
|
3
|
+
// The handcrafted shim.go in this directory exposes only the kinds/types the
|
|
4
|
+
// existing fixtures need. Lint rules walk a much wider AST surface (every
|
|
5
|
+
// statement / expression node), so this file extends the shim with the
|
|
6
|
+
// kinds, type aliases, helpers, and node-flag constants the `@ttsc/lint`
|
|
7
|
+
// plugin (and any other AST-walking plugin) needs to navigate the tree.
|
|
8
|
+
//
|
|
9
|
+
// Everything here is a pure re-export of `internal/ast` symbols — there is
|
|
10
|
+
// no behavior, no copy of upstream logic. Adding a new node type is
|
|
11
|
+
// mechanical: add a `type X = innerast.X` line and the matching
|
|
12
|
+
// `KindX = innerast.KindX` entry.
|
|
13
|
+
package ast
|
|
14
|
+
|
|
15
|
+
import (
|
|
16
|
+
innerast "github.com/microsoft/typescript-go/internal/ast"
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
// ---- Node-list / visitor primitives ----
|
|
20
|
+
|
|
21
|
+
type Visitor = innerast.Visitor
|
|
22
|
+
type NodeFlags = innerast.NodeFlags
|
|
23
|
+
type ModifierFlags = innerast.ModifierFlags
|
|
24
|
+
|
|
25
|
+
// ---- Statement-shaped node types ----
|
|
26
|
+
|
|
27
|
+
type Block = innerast.Block
|
|
28
|
+
type BreakStatement = innerast.BreakStatement
|
|
29
|
+
type CaseBlock = innerast.CaseBlock
|
|
30
|
+
type CaseOrDefaultClause = innerast.CaseOrDefaultClause
|
|
31
|
+
type CatchClause = innerast.CatchClause
|
|
32
|
+
type ContinueStatement = innerast.ContinueStatement
|
|
33
|
+
type DebuggerStatement = innerast.DebuggerStatement
|
|
34
|
+
type DoStatement = innerast.DoStatement
|
|
35
|
+
type EmptyStatement = innerast.EmptyStatement
|
|
36
|
+
type ExpressionStatement = innerast.ExpressionStatement
|
|
37
|
+
type ForInOrOfStatement = innerast.ForInOrOfStatement
|
|
38
|
+
type ForStatement = innerast.ForStatement
|
|
39
|
+
type FunctionDeclaration = innerast.FunctionDeclaration
|
|
40
|
+
type IfStatement = innerast.IfStatement
|
|
41
|
+
type LabeledStatement = innerast.LabeledStatement
|
|
42
|
+
type ModuleDeclaration = innerast.ModuleDeclaration
|
|
43
|
+
type ModuleBlock = innerast.ModuleBlock
|
|
44
|
+
type ReturnStatement = innerast.ReturnStatement
|
|
45
|
+
type SwitchStatement = innerast.SwitchStatement
|
|
46
|
+
type ThrowStatement = innerast.ThrowStatement
|
|
47
|
+
type TryStatement = innerast.TryStatement
|
|
48
|
+
type VariableDeclaration = innerast.VariableDeclaration
|
|
49
|
+
type VariableDeclarationList = innerast.VariableDeclarationList
|
|
50
|
+
type VariableStatement = innerast.VariableStatement
|
|
51
|
+
type WhileStatement = innerast.WhileStatement
|
|
52
|
+
type WithStatement = innerast.WithStatement
|
|
53
|
+
|
|
54
|
+
// ---- Class / module / enum shapes ----
|
|
55
|
+
|
|
56
|
+
type ClassDeclaration = innerast.ClassDeclaration
|
|
57
|
+
type ClassExpression = innerast.ClassExpression
|
|
58
|
+
type ConstructorDeclaration = innerast.ConstructorDeclaration
|
|
59
|
+
type EnumDeclaration = innerast.EnumDeclaration
|
|
60
|
+
type EnumMember = innerast.EnumMember
|
|
61
|
+
type GetAccessorDeclaration = innerast.GetAccessorDeclaration
|
|
62
|
+
type SetAccessorDeclaration = innerast.SetAccessorDeclaration
|
|
63
|
+
type HeritageClause = innerast.HeritageClause
|
|
64
|
+
type PropertyDeclaration = innerast.PropertyDeclaration
|
|
65
|
+
|
|
66
|
+
// ---- Module syntax ----
|
|
67
|
+
|
|
68
|
+
type ImportDeclaration = innerast.ImportDeclaration
|
|
69
|
+
type ImportSpecifier = innerast.ImportSpecifier
|
|
70
|
+
type ImportEqualsDeclaration = innerast.ImportEqualsDeclaration
|
|
71
|
+
type ExternalModuleReference = innerast.ExternalModuleReference
|
|
72
|
+
type NamedImports = innerast.NamedImports
|
|
73
|
+
type NamespaceImport = innerast.NamespaceImport
|
|
74
|
+
type ExportDeclaration = innerast.ExportDeclaration
|
|
75
|
+
type ExportSpecifier = innerast.ExportSpecifier
|
|
76
|
+
type ExportAssignment = innerast.ExportAssignment
|
|
77
|
+
type ImportTypeNode = innerast.ImportTypeNode
|
|
78
|
+
|
|
79
|
+
// ---- Binding patterns ----
|
|
80
|
+
|
|
81
|
+
type BindingElement = innerast.BindingElement
|
|
82
|
+
type BindingPattern = innerast.BindingPattern
|
|
83
|
+
|
|
84
|
+
// ---- Expressions ----
|
|
85
|
+
|
|
86
|
+
type ArrayLiteralExpression = innerast.ArrayLiteralExpression
|
|
87
|
+
type ArrowFunction = innerast.ArrowFunction
|
|
88
|
+
type AsExpression = innerast.AsExpression
|
|
89
|
+
type AwaitExpression = innerast.AwaitExpression
|
|
90
|
+
type BinaryExpression = innerast.BinaryExpression
|
|
91
|
+
type ConditionalExpression = innerast.ConditionalExpression
|
|
92
|
+
type DeleteExpression = innerast.DeleteExpression
|
|
93
|
+
type ElementAccessExpression = innerast.ElementAccessExpression
|
|
94
|
+
type FunctionExpression = innerast.FunctionExpression
|
|
95
|
+
type NewExpression = innerast.NewExpression
|
|
96
|
+
type NonNullExpression = innerast.NonNullExpression
|
|
97
|
+
type ObjectLiteralExpression = innerast.ObjectLiteralExpression
|
|
98
|
+
type ParenthesizedExpression = innerast.ParenthesizedExpression
|
|
99
|
+
type PostfixUnaryExpression = innerast.PostfixUnaryExpression
|
|
100
|
+
type PropertyAccessExpression = innerast.PropertyAccessExpression
|
|
101
|
+
type PropertyAssignment = innerast.PropertyAssignment
|
|
102
|
+
type ShorthandPropertyAssignment = innerast.ShorthandPropertyAssignment
|
|
103
|
+
type SpreadAssignment = innerast.SpreadAssignment
|
|
104
|
+
type SpreadElement = innerast.SpreadElement
|
|
105
|
+
type TaggedTemplateExpression = innerast.TaggedTemplateExpression
|
|
106
|
+
type TemplateExpression = innerast.TemplateExpression
|
|
107
|
+
type TemplateSpan = innerast.TemplateSpan
|
|
108
|
+
type TypeAssertion = innerast.TypeAssertion
|
|
109
|
+
type TypeOfExpression = innerast.TypeOfExpression
|
|
110
|
+
type VoidExpression = innerast.VoidExpression
|
|
111
|
+
type YieldExpression = innerast.YieldExpression
|
|
112
|
+
type RegularExpressionLiteral = innerast.RegularExpressionLiteral
|
|
113
|
+
type SatisfiesExpression = innerast.SatisfiesExpression
|
|
114
|
+
|
|
115
|
+
// ---- Comment directives (ban-ts-comment) ----
|
|
116
|
+
|
|
117
|
+
type CommentDirective = innerast.CommentDirective
|
|
118
|
+
type CommentDirectiveKind = innerast.CommentDirectiveKind
|
|
119
|
+
|
|
120
|
+
// ---- Source file parse options (test harness) ----
|
|
121
|
+
|
|
122
|
+
type SourceFileParseOptions = innerast.SourceFileParseOptions
|
|
123
|
+
type ExternalModuleIndicatorOptions = innerast.ExternalModuleIndicatorOptions
|
|
124
|
+
|
|
125
|
+
// ---- Node-flag constants ----
|
|
126
|
+
|
|
127
|
+
const (
|
|
128
|
+
NodeFlagsNone = innerast.NodeFlagsNone
|
|
129
|
+
NodeFlagsLet = innerast.NodeFlagsLet
|
|
130
|
+
NodeFlagsConst = innerast.NodeFlagsConst
|
|
131
|
+
NodeFlagsBlockScoped = innerast.NodeFlagsBlockScoped
|
|
132
|
+
NodeFlagsAwaitContext = innerast.NodeFlagsAwaitContext
|
|
133
|
+
)
|
|
134
|
+
|
|
135
|
+
// ---- Statement / declaration / expression kinds ----
|
|
136
|
+
|
|
137
|
+
const (
|
|
138
|
+
KindSourceFile = innerast.KindSourceFile
|
|
139
|
+
|
|
140
|
+
// Statements
|
|
141
|
+
KindBlock = innerast.KindBlock
|
|
142
|
+
KindBreakStatement = innerast.KindBreakStatement
|
|
143
|
+
KindCaseBlock = innerast.KindCaseBlock
|
|
144
|
+
KindCaseClause = innerast.KindCaseClause
|
|
145
|
+
KindCatchClause = innerast.KindCatchClause
|
|
146
|
+
KindContinueStatement = innerast.KindContinueStatement
|
|
147
|
+
KindDebuggerStatement = innerast.KindDebuggerStatement
|
|
148
|
+
KindDefaultClause = innerast.KindDefaultClause
|
|
149
|
+
KindDoStatement = innerast.KindDoStatement
|
|
150
|
+
KindEmptyStatement = innerast.KindEmptyStatement
|
|
151
|
+
KindExpressionStatement = innerast.KindExpressionStatement
|
|
152
|
+
KindForInStatement = innerast.KindForInStatement
|
|
153
|
+
KindForOfStatement = innerast.KindForOfStatement
|
|
154
|
+
KindForStatement = innerast.KindForStatement
|
|
155
|
+
KindIfStatement = innerast.KindIfStatement
|
|
156
|
+
KindLabeledStatement = innerast.KindLabeledStatement
|
|
157
|
+
KindReturnStatement = innerast.KindReturnStatement
|
|
158
|
+
KindSwitchStatement = innerast.KindSwitchStatement
|
|
159
|
+
KindThrowStatement = innerast.KindThrowStatement
|
|
160
|
+
KindTryStatement = innerast.KindTryStatement
|
|
161
|
+
KindVariableDeclaration = innerast.KindVariableDeclaration
|
|
162
|
+
KindVariableDeclarationList = innerast.KindVariableDeclarationList
|
|
163
|
+
KindVariableStatement = innerast.KindVariableStatement
|
|
164
|
+
KindWhileStatement = innerast.KindWhileStatement
|
|
165
|
+
KindWithStatement = innerast.KindWithStatement
|
|
166
|
+
|
|
167
|
+
// Class / enum / module
|
|
168
|
+
KindClassDeclaration = innerast.KindClassDeclaration
|
|
169
|
+
KindClassExpression = innerast.KindClassExpression
|
|
170
|
+
KindConstructor = innerast.KindConstructor
|
|
171
|
+
KindEnumDeclaration = innerast.KindEnumDeclaration
|
|
172
|
+
KindEnumMember = innerast.KindEnumMember
|
|
173
|
+
KindGetAccessor = innerast.KindGetAccessor
|
|
174
|
+
KindSetAccessor = innerast.KindSetAccessor
|
|
175
|
+
KindHeritageClause = innerast.KindHeritageClause
|
|
176
|
+
KindPropertyDeclaration = innerast.KindPropertyDeclaration
|
|
177
|
+
|
|
178
|
+
// Module syntax
|
|
179
|
+
KindExportAssignment = innerast.KindExportAssignment
|
|
180
|
+
KindExportDeclaration = innerast.KindExportDeclaration
|
|
181
|
+
KindImportEqualsDeclaration = innerast.KindImportEqualsDeclaration
|
|
182
|
+
KindExternalModuleReference = innerast.KindExternalModuleReference
|
|
183
|
+
KindImportType = innerast.KindImportType
|
|
184
|
+
KindImportKeyword = innerast.KindImportKeyword
|
|
185
|
+
|
|
186
|
+
// Binding
|
|
187
|
+
KindBindingElement = innerast.KindBindingElement
|
|
188
|
+
KindObjectBindingPattern = innerast.KindObjectBindingPattern
|
|
189
|
+
KindArrayBindingPattern = innerast.KindArrayBindingPattern
|
|
190
|
+
KindOmittedExpression = innerast.KindOmittedExpression
|
|
191
|
+
|
|
192
|
+
// Expressions
|
|
193
|
+
KindArrayLiteralExpression = innerast.KindArrayLiteralExpression
|
|
194
|
+
KindArrowFunction = innerast.KindArrowFunction
|
|
195
|
+
KindAsExpression = innerast.KindAsExpression
|
|
196
|
+
KindAwaitExpression = innerast.KindAwaitExpression
|
|
197
|
+
KindBinaryExpression = innerast.KindBinaryExpression
|
|
198
|
+
KindConditionalExpression = innerast.KindConditionalExpression
|
|
199
|
+
KindDeleteExpression = innerast.KindDeleteExpression
|
|
200
|
+
KindElementAccessExpression = innerast.KindElementAccessExpression
|
|
201
|
+
KindFunctionExpression = innerast.KindFunctionExpression
|
|
202
|
+
KindNewExpression = innerast.KindNewExpression
|
|
203
|
+
KindNonNullExpression = innerast.KindNonNullExpression
|
|
204
|
+
KindObjectLiteralExpression = innerast.KindObjectLiteralExpression
|
|
205
|
+
KindParenthesizedExpression = innerast.KindParenthesizedExpression
|
|
206
|
+
KindPostfixUnaryExpression = innerast.KindPostfixUnaryExpression
|
|
207
|
+
KindPropertyAssignment = innerast.KindPropertyAssignment
|
|
208
|
+
KindShorthandPropertyAssignment = innerast.KindShorthandPropertyAssignment
|
|
209
|
+
KindSpreadAssignment = innerast.KindSpreadAssignment
|
|
210
|
+
KindSpreadElement = innerast.KindSpreadElement
|
|
211
|
+
KindTaggedTemplateExpression = innerast.KindTaggedTemplateExpression
|
|
212
|
+
KindTemplateExpression = innerast.KindTemplateExpression
|
|
213
|
+
KindTemplateSpan = innerast.KindTemplateSpan
|
|
214
|
+
KindTypeAssertionExpression = innerast.KindTypeAssertionExpression
|
|
215
|
+
KindTypeOfExpression = innerast.KindTypeOfExpression
|
|
216
|
+
KindVoidExpression = innerast.KindVoidExpression
|
|
217
|
+
KindYieldExpression = innerast.KindYieldExpression
|
|
218
|
+
KindRegularExpressionLiteral = innerast.KindRegularExpressionLiteral
|
|
219
|
+
KindSatisfiesExpression = innerast.KindSatisfiesExpression
|
|
220
|
+
|
|
221
|
+
// Keywords / tokens used by rules
|
|
222
|
+
KindThisKeyword = innerast.KindThisKeyword
|
|
223
|
+
KindSuperKeyword = innerast.KindSuperKeyword
|
|
224
|
+
KindEqualsToken = innerast.KindEqualsToken
|
|
225
|
+
KindEqualsEqualsToken = innerast.KindEqualsEqualsToken
|
|
226
|
+
KindEqualsEqualsEqualsToken = innerast.KindEqualsEqualsEqualsToken
|
|
227
|
+
KindExclamationEqualsToken = innerast.KindExclamationEqualsToken
|
|
228
|
+
KindExclamationEqualsEqualsToken = innerast.KindExclamationEqualsEqualsToken
|
|
229
|
+
KindLessThanToken = innerast.KindLessThanToken
|
|
230
|
+
KindGreaterThanToken = innerast.KindGreaterThanToken
|
|
231
|
+
KindLessThanEqualsToken = innerast.KindLessThanEqualsToken
|
|
232
|
+
KindGreaterThanEqualsToken = innerast.KindGreaterThanEqualsToken
|
|
233
|
+
KindPlusToken = innerast.KindPlusToken
|
|
234
|
+
KindPlusEqualsToken = innerast.KindPlusEqualsToken
|
|
235
|
+
KindMinusEqualsToken = innerast.KindMinusEqualsToken
|
|
236
|
+
KindAsteriskToken = innerast.KindAsteriskToken
|
|
237
|
+
KindSlashToken = innerast.KindSlashToken
|
|
238
|
+
KindAmpersandAmpersandToken = innerast.KindAmpersandAmpersandToken
|
|
239
|
+
KindBarBarToken = innerast.KindBarBarToken
|
|
240
|
+
KindQuestionQuestionToken = innerast.KindQuestionQuestionToken
|
|
241
|
+
KindExclamationToken = innerast.KindExclamationToken
|
|
242
|
+
KindTildeToken = innerast.KindTildeToken
|
|
243
|
+
KindInKeyword = innerast.KindInKeyword
|
|
244
|
+
KindInstanceOfKeyword = innerast.KindInstanceOfKeyword
|
|
245
|
+
KindAsKeyword = innerast.KindAsKeyword
|
|
246
|
+
KindPlusPlusToken = innerast.KindPlusPlusToken
|
|
247
|
+
KindMinusMinusToken = innerast.KindMinusMinusToken
|
|
248
|
+
KindDotToken = innerast.KindDotToken
|
|
249
|
+
|
|
250
|
+
// Bitwise / shift / exponent operator tokens — needed by
|
|
251
|
+
// no-bitwise, prefer-exponentiation-operator, etc.
|
|
252
|
+
KindAmpersandToken = innerast.KindAmpersandToken
|
|
253
|
+
KindBarToken = innerast.KindBarToken
|
|
254
|
+
KindCaretToken = innerast.KindCaretToken
|
|
255
|
+
KindLessThanLessThanToken = innerast.KindLessThanLessThanToken
|
|
256
|
+
KindGreaterThanGreaterThanToken = innerast.KindGreaterThanGreaterThanToken
|
|
257
|
+
KindGreaterThanGreaterThanGreaterThanToken = innerast.KindGreaterThanGreaterThanGreaterThanToken
|
|
258
|
+
KindAsteriskAsteriskToken = innerast.KindAsteriskAsteriskToken
|
|
259
|
+
KindAmpersandAmpersandEqualsToken = innerast.KindAmpersandAmpersandEqualsToken
|
|
260
|
+
KindBarBarEqualsToken = innerast.KindBarBarEqualsToken
|
|
261
|
+
KindQuestionQuestionEqualsToken = innerast.KindQuestionQuestionEqualsToken
|
|
262
|
+
KindAsteriskEqualsToken = innerast.KindAsteriskEqualsToken
|
|
263
|
+
KindSlashEqualsToken = innerast.KindSlashEqualsToken
|
|
264
|
+
KindPercentEqualsToken = innerast.KindPercentEqualsToken
|
|
265
|
+
KindAsteriskAsteriskEqualsToken = innerast.KindAsteriskAsteriskEqualsToken
|
|
266
|
+
KindAmpersandEqualsToken = innerast.KindAmpersandEqualsToken
|
|
267
|
+
KindBarEqualsToken = innerast.KindBarEqualsToken
|
|
268
|
+
KindCaretEqualsToken = innerast.KindCaretEqualsToken
|
|
269
|
+
KindLessThanLessThanEqualsToken = innerast.KindLessThanLessThanEqualsToken
|
|
270
|
+
KindGreaterThanGreaterThanEqualsToken = innerast.KindGreaterThanGreaterThanEqualsToken
|
|
271
|
+
KindGreaterThanGreaterThanGreaterThanEqualsToken = innerast.KindGreaterThanGreaterThanGreaterThanEqualsToken
|
|
272
|
+
KindCommaToken = innerast.KindCommaToken
|
|
273
|
+
KindQuestionToken = innerast.KindQuestionToken
|
|
274
|
+
|
|
275
|
+
// Metaprogramming / privacy / async syntax
|
|
276
|
+
KindMetaProperty = innerast.KindMetaProperty
|
|
277
|
+
KindPrivateIdentifier = innerast.KindPrivateIdentifier
|
|
278
|
+
KindClassStaticBlockDeclaration = innerast.KindClassStaticBlockDeclaration
|
|
279
|
+
|
|
280
|
+
// Misc syntax used by suggestion rules
|
|
281
|
+
KindSymbolKeyword = innerast.KindSymbolKeyword
|
|
282
|
+
KindObjectKeyword = innerast.KindObjectKeyword
|
|
283
|
+
|
|
284
|
+
// Modifier-style keywords
|
|
285
|
+
KindAsyncKeyword = innerast.KindAsyncKeyword
|
|
286
|
+
KindAwaitKeyword = innerast.KindAwaitKeyword
|
|
287
|
+
KindReadonlyKeyword = innerast.KindReadonlyKeyword
|
|
288
|
+
KindStaticKeyword = innerast.KindStaticKeyword
|
|
289
|
+
KindAbstractKeyword = innerast.KindAbstractKeyword
|
|
290
|
+
KindExportKeyword = innerast.KindExportKeyword
|
|
291
|
+
KindDeclareKeyword = innerast.KindDeclareKeyword
|
|
292
|
+
KindModuleKeyword = innerast.KindModuleKeyword
|
|
293
|
+
KindTypeKeyword = innerast.KindTypeKeyword
|
|
294
|
+
|
|
295
|
+
// TypeScript-specific kinds used by ts rules
|
|
296
|
+
KindCallSignature = innerast.KindCallSignature
|
|
297
|
+
KindConstructSignature = innerast.KindConstructSignature
|
|
298
|
+
KindTypeQuery = innerast.KindTypeQuery
|
|
299
|
+
KindTypeOperator = innerast.KindTypeOperator
|
|
300
|
+
)
|
|
301
|
+
|
|
302
|
+
// ---- Comment-directive kind constants ----
|
|
303
|
+
|
|
304
|
+
const (
|
|
305
|
+
CommentDirectiveKindIgnore = innerast.CommentDirectiveKindIgnore
|
|
306
|
+
CommentDirectiveKindExpectError = innerast.CommentDirectiveKindExpectError
|
|
307
|
+
)
|
|
308
|
+
|
|
309
|
+
// ---- Helpers ----
|
|
310
|
+
|
|
311
|
+
// GetCombinedNodeFlags returns the combined node flags for a declaration,
|
|
312
|
+
// consulting parents where applicable. This is what `IsLet` / `IsConst` use
|
|
313
|
+
// internally; lint rules need it to detect `var` declarations whose flag
|
|
314
|
+
// lives on the VariableDeclarationList rather than the declaration itself.
|
|
315
|
+
func GetCombinedNodeFlags(node *Node) NodeFlags {
|
|
316
|
+
return innerast.GetCombinedNodeFlags(node)
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
// IsLet reports whether the declaration was introduced by `let` / `using`.
|
|
320
|
+
func IsLet(node *Node) bool { return GetCombinedNodeFlags(node)&NodeFlagsLet != 0 }
|
|
321
|
+
|
|
322
|
+
// IsConst reports whether the declaration was introduced by `const` /
|
|
323
|
+
// `await using` / `using`.
|
|
324
|
+
func IsConst(node *Node) bool { return GetCombinedNodeFlags(node)&NodeFlagsConst != 0 }
|
|
325
|
+
|
|
326
|
+
// IsVar reports whether the declaration was introduced by `var`. The block
|
|
327
|
+
// scoped flag bits are clear when the keyword is plain `var`.
|
|
328
|
+
func IsVar(node *Node) bool { return GetCombinedNodeFlags(node)&NodeFlagsBlockScoped == 0 }
|
package/shim/bundled/go.mod
CHANGED
package/shim/checker/go.mod
CHANGED
package/shim/compiler/go.mod
CHANGED
package/shim/core/go.mod
CHANGED
package/shim/core/shim.go
CHANGED
|
@@ -4,8 +4,23 @@ import innercore "github.com/microsoft/typescript-go/internal/core"
|
|
|
4
4
|
|
|
5
5
|
type CompilerOptions = innercore.CompilerOptions
|
|
6
6
|
type Tristate = innercore.Tristate
|
|
7
|
+
type TextPos = innercore.TextPos
|
|
8
|
+
type TextRange = innercore.TextRange
|
|
9
|
+
type ScriptKind = innercore.ScriptKind
|
|
7
10
|
|
|
8
11
|
const (
|
|
9
12
|
TSFalse = innercore.TSFalse
|
|
10
13
|
TSTrue = innercore.TSTrue
|
|
14
|
+
|
|
15
|
+
ScriptKindUnknown = innercore.ScriptKindUnknown
|
|
16
|
+
ScriptKindJS = innercore.ScriptKindJS
|
|
17
|
+
ScriptKindJSX = innercore.ScriptKindJSX
|
|
18
|
+
ScriptKindTS = innercore.ScriptKindTS
|
|
19
|
+
ScriptKindTSX = innercore.ScriptKindTSX
|
|
20
|
+
ScriptKindExternal = innercore.ScriptKindExternal
|
|
21
|
+
ScriptKindJSON = innercore.ScriptKindJSON
|
|
22
|
+
ScriptKindDeferred = innercore.ScriptKindDeferred
|
|
11
23
|
)
|
|
24
|
+
|
|
25
|
+
// NewTextRange constructs a closed/open [pos, end) text range.
|
|
26
|
+
func NewTextRange(pos, end int) TextRange { return innercore.NewTextRange(pos, end) }
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
// Lint diagnostic helpers.
|
|
2
|
+
//
|
|
3
|
+
// Plugins that participate in `ttsc check` / `ttsc build` (e.g. `@ttsc/lint`)
|
|
4
|
+
// need to emit findings that ride the same color/context renderer as tsgo's
|
|
5
|
+
// own typecheck diagnostics. The plumbing has to live next to the existing
|
|
6
|
+
// shim so the renderer keeps its single owner of `internal/diagnosticwriter`
|
|
7
|
+
// and `internal/diagnostics`.
|
|
8
|
+
//
|
|
9
|
+
// Consumers construct a `LintDiagnostic` from `(file, pos, end, code,
|
|
10
|
+
// category, message)` and pass it to `FormatMixedDiagnostics` together with
|
|
11
|
+
// any raw tsgo diagnostics. The renderer treats both the same way.
|
|
12
|
+
package diagnosticwriter
|
|
13
|
+
|
|
14
|
+
import (
|
|
15
|
+
"io"
|
|
16
|
+
|
|
17
|
+
"github.com/microsoft/typescript-go/internal/ast"
|
|
18
|
+
"github.com/microsoft/typescript-go/internal/diagnostics"
|
|
19
|
+
inner "github.com/microsoft/typescript-go/internal/diagnosticwriter"
|
|
20
|
+
"github.com/microsoft/typescript-go/internal/locale"
|
|
21
|
+
"github.com/microsoft/typescript-go/internal/tspath"
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
// LintCategory selects warning vs error rendering. Warnings render yellow,
|
|
25
|
+
// errors render red — the exit-code decision lives in the caller.
|
|
26
|
+
type LintCategory int
|
|
27
|
+
|
|
28
|
+
const (
|
|
29
|
+
LintCategoryWarning LintCategory = iota
|
|
30
|
+
LintCategoryError
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
// LintDiagnostic is a public, plugin-emittable diagnostic shaped like the
|
|
34
|
+
// `internal/diagnosticwriter.Diagnostic` interface. The internal type is
|
|
35
|
+
// unexported, so this is the only way to mix lint output with tsgo's own
|
|
36
|
+
// diagnostics in a single render pass.
|
|
37
|
+
type LintDiagnostic struct {
|
|
38
|
+
file *ast.SourceFile
|
|
39
|
+
pos int
|
|
40
|
+
end int
|
|
41
|
+
code int32
|
|
42
|
+
category LintCategory
|
|
43
|
+
message string
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// NewLintDiagnostic builds a lint diagnostic anchored at [pos, end) in the
|
|
47
|
+
// supplied source file. `code` shows up in the rendered banner — the
|
|
48
|
+
// convention is to give each rule its own stable integer.
|
|
49
|
+
func NewLintDiagnostic(file *ast.SourceFile, pos, end int, code int32, category LintCategory, message string) *LintDiagnostic {
|
|
50
|
+
if end <= pos {
|
|
51
|
+
end = pos + 1
|
|
52
|
+
}
|
|
53
|
+
return &LintDiagnostic{
|
|
54
|
+
file: file,
|
|
55
|
+
pos: pos,
|
|
56
|
+
end: end,
|
|
57
|
+
code: code,
|
|
58
|
+
category: category,
|
|
59
|
+
message: message,
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
func (d *LintDiagnostic) File() inner.FileLike {
|
|
64
|
+
if d == nil || d.file == nil {
|
|
65
|
+
return nil
|
|
66
|
+
}
|
|
67
|
+
return d.file
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
func (d *LintDiagnostic) Pos() int { return d.pos }
|
|
71
|
+
func (d *LintDiagnostic) End() int { return d.end }
|
|
72
|
+
func (d *LintDiagnostic) Len() int { return d.end - d.pos }
|
|
73
|
+
func (d *LintDiagnostic) Code() int32 { return d.code }
|
|
74
|
+
|
|
75
|
+
func (d *LintDiagnostic) Category() diagnostics.Category {
|
|
76
|
+
if d.category == LintCategoryError {
|
|
77
|
+
return diagnostics.CategoryError
|
|
78
|
+
}
|
|
79
|
+
return diagnostics.CategoryWarning
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
func (d *LintDiagnostic) Localize(_ locale.Locale) string { return d.message }
|
|
83
|
+
func (d *LintDiagnostic) MessageChain() []inner.Diagnostic { return nil }
|
|
84
|
+
func (d *LintDiagnostic) RelatedInformation() []inner.Diagnostic { return nil }
|
|
85
|
+
|
|
86
|
+
// IsError reports whether the diagnostic should fail the build. Lint plugins
|
|
87
|
+
// use this to compute their exit code separately from the renderer.
|
|
88
|
+
func (d *LintDiagnostic) IsError() bool { return d.category == LintCategoryError }
|
|
89
|
+
|
|
90
|
+
// FormatMixedDiagnostics renders raw tsgo diagnostics and lint diagnostics
|
|
91
|
+
// together with TypeScript-style colors and source context, followed by the
|
|
92
|
+
// `Found N errors` summary. Returns the count of error-level diagnostics so
|
|
93
|
+
// callers can decide on an exit code.
|
|
94
|
+
func FormatMixedDiagnostics(
|
|
95
|
+
output io.Writer,
|
|
96
|
+
astDiags []*ast.Diagnostic,
|
|
97
|
+
lintDiags []*LintDiagnostic,
|
|
98
|
+
currentDirectory string,
|
|
99
|
+
) int {
|
|
100
|
+
if len(astDiags) == 0 && len(lintDiags) == 0 {
|
|
101
|
+
return 0
|
|
102
|
+
}
|
|
103
|
+
all := make([]inner.Diagnostic, 0, len(astDiags)+len(lintDiags))
|
|
104
|
+
errors := 0
|
|
105
|
+
for _, d := range astDiags {
|
|
106
|
+
if d == nil {
|
|
107
|
+
continue
|
|
108
|
+
}
|
|
109
|
+
all = append(all, inner.WrapASTDiagnostic(d))
|
|
110
|
+
if d.Category() == diagnostics.CategoryError {
|
|
111
|
+
errors++
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
for _, d := range lintDiags {
|
|
115
|
+
if d == nil {
|
|
116
|
+
continue
|
|
117
|
+
}
|
|
118
|
+
all = append(all, d)
|
|
119
|
+
if d.IsError() {
|
|
120
|
+
errors++
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
if len(all) == 0 {
|
|
124
|
+
return 0
|
|
125
|
+
}
|
|
126
|
+
options := &inner.FormattingOptions{
|
|
127
|
+
Locale: locale.Default,
|
|
128
|
+
ComparePathsOptions: tspath.ComparePathsOptions{
|
|
129
|
+
CurrentDirectory: currentDirectory,
|
|
130
|
+
UseCaseSensitiveFileNames: true,
|
|
131
|
+
},
|
|
132
|
+
NewLine: "\n",
|
|
133
|
+
}
|
|
134
|
+
inner.FormatDiagnosticsWithColorAndContext(output, all, options)
|
|
135
|
+
inner.WriteErrorSummaryText(output, all, options)
|
|
136
|
+
return errors
|
|
137
|
+
}
|
package/shim/parser/go.mod
CHANGED
package/shim/scanner/go.mod
CHANGED
package/shim/tsoptions/go.mod
CHANGED
package/shim/tspath/go.mod
CHANGED
package/shim/vfs/go.mod
CHANGED
package/shim/vfs/osvfs/go.mod
CHANGED