MCPcopy Create free account
hub / github.com/microsoft/typescript-go / processPragmasIntoFields

Method processPragmasIntoFields

internal/parser/parser.go:6611–6669  ·  view source on GitHub ↗
(context *ast.SourceFile)

Source from the content-addressed store, hash-verified

6609}
6610
6611func (p *Parser) processPragmasIntoFields(context *ast.SourceFile) {
6612 context.CheckJsDirective = nil
6613 context.ReferencedFiles = nil
6614 context.TypeReferenceDirectives = nil
6615 context.LibReferenceDirectives = nil
6616 // context.AmdDependencies = nil
6617 for _, pragma := range context.Pragmas {
6618 switch pragma.Name {
6619 case "reference":
6620 types, typesOk := pragma.Args["types"]
6621 lib, libOk := pragma.Args["lib"]
6622 path, pathOk := pragma.Args["path"]
6623 resolutionMode, resolutionModeOk := pragma.Args["resolution-mode"]
6624 preserve, preserveOk := pragma.Args["preserve"]
6625 noDefaultLib, noDefaultLibOk := pragma.Args["no-default-lib"]
6626 switch {
6627 case noDefaultLibOk && noDefaultLib.Value == "true":
6628 // Ignored.
6629 case typesOk:
6630 var parsed core.ResolutionMode
6631 if resolutionModeOk {
6632 parsed = p.parseResolutionMode(resolutionMode.Value, resolutionMode.Pos(), resolutionMode.End())
6633 }
6634 context.TypeReferenceDirectives = append(context.TypeReferenceDirectives, &ast.FileReference{
6635 TextRange: types.TextRange,
6636 FileName: types.Value,
6637 ResolutionMode: parsed,
6638 Preserve: preserveOk && preserve.Value == "true",
6639 })
6640 case libOk:
6641 context.LibReferenceDirectives = append(context.LibReferenceDirectives, &ast.FileReference{
6642 TextRange: lib.TextRange,
6643 FileName: lib.Value,
6644 Preserve: preserveOk && preserve.Value == "true",
6645 })
6646 case pathOk:
6647 context.ReferencedFiles = append(context.ReferencedFiles, &ast.FileReference{
6648 TextRange: path.TextRange,
6649 FileName: path.Value,
6650 Preserve: preserveOk && preserve.Value == "true",
6651 })
6652 default:
6653 p.parseErrorAtRange(pragma.TextRange, diagnostics.Invalid_reference_directive_syntax)
6654 }
6655 case "ts-check", "ts-nocheck":
6656 // _last_ of either nocheck or check in a file is the "winner"
6657 if context.CheckJsDirective == nil || pragma.TextRange.Pos() > context.CheckJsDirective.Range.Pos() {
6658 context.CheckJsDirective = &ast.CheckJsDirective{
6659 Enabled: pragma.Name == "ts-check",
6660 Range: pragma.CommentRange,
6661 }
6662 }
6663 case "jsx", "jsxfrag", "jsximportsource", "jsxruntime":
6664 // Nothing to do here
6665 default:
6666 panic("Unhandled pragma kind: " + pragma.Name)
6667 }
6668 }

Callers 1

finishSourceFileMethod · 0.95

Calls 6

parseResolutionModeMethod · 0.95
parseErrorAtRangeMethod · 0.95
panicFunction · 0.85
PosMethod · 0.65
EndMethod · 0.65
appendFunction · 0.50

Tested by

no test coverage detected