Skip to content

Commit 944e3e6

Browse files
EricCornelsonEric Cornelson
andauthored
Concurrent program with module resolution (#107)
Co-authored-by: Eric Cornelson <[email protected]>
1 parent d70a58b commit 944e3e6

File tree

11 files changed

+991
-431
lines changed

11 files changed

+991
-431
lines changed

cmd/tsgo/main.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ var singleThreaded = false
2424
var parseAndBindOnly = false
2525
var printTypes = false
2626
var pretty = true
27+
var listFiles = false
2728
var pprofDir = ""
2829

2930
func printDiagnostic(d *ast.Diagnostic, level int, comparePathOptions tspath.ComparePathsOptions) {
@@ -54,6 +55,7 @@ func main() {
5455
flag.BoolVar(&parseAndBindOnly, "p", false, "Parse and bind only")
5556
flag.BoolVar(&printTypes, "t", false, "Print types defined in main.ts")
5657
flag.BoolVar(&pretty, "pretty", true, "Get prettier errors")
58+
flag.BoolVar(&listFiles, "listfiles", false, "List files in the program")
5759
flag.StringVar(&pprofDir, "pprofdir", "", "Generate pprof CPU/memory profiles to the given directory")
5860
flag.Parse()
5961

@@ -66,7 +68,7 @@ func main() {
6668
}
6769
fs := vfs.FromOS()
6870
useCaseSensitiveFileNames := fs.UseCaseSensitiveFileNames()
69-
host := ts.NewCompilerHost(compilerOptions, singleThreaded, currentDirectory, fs)
71+
host := ts.NewCompilerHost(compilerOptions, currentDirectory, fs)
7072

7173
normalizedRootPath := tspath.ResolvePath(currentDirectory, rootPath)
7274
if !fs.DirectoryExists(normalizedRootPath) {
@@ -122,6 +124,12 @@ func main() {
122124
}
123125
}
124126

127+
if listFiles {
128+
for _, file := range program.SourceFiles() {
129+
fmt.Println(file.FileName())
130+
}
131+
}
132+
125133
fmt.Printf("Files: %v\n", len(program.SourceFiles()))
126134
fmt.Printf("Types: %v\n", program.TypeCount())
127135
fmt.Printf("Compile time: %v\n", compileTime)

internal/ast/ast.go

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5436,6 +5436,10 @@ type SourceFile struct {
54365436
AmbientModuleNames []string
54375437
HasNoDefaultLib bool
54385438
jsdocCache map[*Node][]*Node
5439+
Pragmas []Pragma
5440+
ReferencedFiles []*FileReference
5441+
TypeReferenceDirectives []*FileReference
5442+
LibReferenceDirectives []*FileReference
54395443
}
54405444

54415445
func (f *NodeFactory) NewSourceFile(text string, fileName string, statements *NodeList) *Node {
@@ -5482,3 +5486,61 @@ func (node *SourceFile) ForEachChild(v Visitor) bool {
54825486
func IsSourceFile(node *Node) bool {
54835487
return node.Kind == KindSourceFile
54845488
}
5489+
5490+
type CommentRange struct {
5491+
core.TextRange
5492+
HasTrailingNewLine bool
5493+
Kind Kind
5494+
}
5495+
5496+
func NewCommentRange(kind Kind, pos int, end int, hasTrailingNewLine bool) CommentRange {
5497+
return CommentRange{
5498+
TextRange: core.NewTextRange(pos, end),
5499+
HasTrailingNewLine: hasTrailingNewLine,
5500+
Kind: kind,
5501+
}
5502+
}
5503+
5504+
type FileReference struct {
5505+
core.TextRange
5506+
FileName string
5507+
ResolutionMode core.ResolutionMode
5508+
Preserve bool
5509+
}
5510+
5511+
type PragmaArgument struct {
5512+
core.TextRange
5513+
Name string
5514+
Value string
5515+
}
5516+
5517+
type Pragma struct {
5518+
Name string
5519+
Args map[string]PragmaArgument
5520+
ArgsRange CommentRange
5521+
}
5522+
5523+
type PragmaKindFlags = uint8
5524+
5525+
const (
5526+
PragmaKindFlagsNone PragmaKindFlags = iota
5527+
PragmaKindTripleSlashXML
5528+
PragmaKindSingleLine
5529+
PragmaKindMultiLine
5530+
PragmaKindAll = PragmaKindTripleSlashXML | PragmaKindSingleLine | PragmaKindMultiLine
5531+
PragmaKindDefault = PragmaKindAll
5532+
)
5533+
5534+
type PragmaArgumentSpecification struct {
5535+
Name string
5536+
Optional bool
5537+
CaptureSpan bool
5538+
}
5539+
type PragmaSpecification struct {
5540+
Args []PragmaArgumentSpecification
5541+
Kind PragmaKindFlags
5542+
}
5543+
5544+
func (spec *PragmaSpecification) IsTripleSlash() bool {
5545+
return (spec.Kind & PragmaKindTripleSlashXML) > 0
5546+
}

internal/ast/kind.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ type Kind int16
77
const (
88
KindUnknown Kind = iota
99
KindEndOfFile
10+
KindSingleLineCommentTrivia
11+
KindMultiLineCommentTrivia
1012
KindConflictMarkerTrivia
1113
KindNonTextFileMarkerTrivia
1214
KindNumericLiteral
@@ -420,4 +422,5 @@ const (
420422
KindLastJSDocTagNode = KindJSDocImportTag
421423
KindFirstContextualKeyword = KindAbstractKeyword
422424
KindLastContextualKeyword = KindOfKeyword
425+
KindComment = KindSingleLineCommentTrivia | KindMultiLineCommentTrivia
423426
)

0 commit comments

Comments
 (0)