Source File
tsconfig_json.go
Belonging Package
github.com/evanw/esbuild/internal/resolver
package resolver
import (
)
Paths map[string][]string
JSXFactory []string
JSXFragmentFactory []string
UseDefineForClassFields bool
PreserveImportsNotUsedAsValues bool
}
func (
logger.Log,
logger.Source,
*cache.JSONCache,
func(string, logger.Range) *TSConfigJSON,
, := .Parse(, , js_parser.JSONOptions{
AllowComments: true, // https://github.com/microsoft/TypeScript/issues/4987
AllowTrailingCommas: true,
})
if ! {
return nil
}
var TSConfigJSON
if != nil {
if , , := getProperty(, "extends"); {
if , := getString(); {
if := (, .RangeOfString(.Loc)); != nil {
= *
}
}
}
}
if , , := getProperty(, "baseUrl"); {
if , := getString(); {
.BaseURL = &
}
}
if , , := getProperty(, "jsxFactory"); {
if , := getString(); {
.JSXFactory = parseMemberExpressionForJSX(, , .Loc, )
}
}
if , , := getProperty(, "jsxFragmentFactory"); {
if , := getString(); {
.JSXFragmentFactory = parseMemberExpressionForJSX(, , .Loc, )
}
}
if , , := getProperty(, "useDefineForClassFields"); {
if , := getBool(); {
.UseDefineForClassFields =
}
}
if , , := getProperty(, "importsNotUsedAsValues"); {
if , := getString(); {
switch {
case "preserve", "error":
.PreserveImportsNotUsedAsValues = true
case "remove":
default:
.AddRangeWarning(&, .RangeOfString(.Loc),
fmt.Sprintf("Invalid value %q for \"importsNotUsedAsValues\"", ))
}
}
}
if , , := getProperty(, "paths"); {
if , := .Data.(*js_ast.EObject); {
:= .BaseURL != nil
if {
.BaseURLForPaths = *.BaseURL
} else {
.BaseURLForPaths = "."
}
.Paths = make(map[string][]string)
for , := range .Properties {
if , := getString(.Key); {
if !isValidTSConfigPathPattern(, , , .Key.Loc) {
continue
}
if , := .Value.Data.(*js_ast.EArray); {
for , := range .Items {
if , := getString(); {
if isValidTSConfigPathPattern(, , , .Loc) &&
( || isValidTSConfigPathNoBaseURLPattern(, , , .Loc)) {
.Paths[] = append(.Paths[], )
}
}
}
} else {
.AddRangeWarning(&, .RangeOfString(.Value.Loc), fmt.Sprintf(
"Substitutions for pattern %q should be an array", ))
}
}
}
}
}
}
return &
}
func ( logger.Log, logger.Source, logger.Loc, string) []string {
if == "" {
return nil
}
:= strings.Split(, ".")
for , := range {
if !js_lexer.IsIdentifier() {
:= .RangeOfString()
.AddRangeWarning(&, , fmt.Sprintf("Invalid JSX member expression: %q", ))
return nil
}
}
return
}
func ( string, logger.Log, logger.Source, logger.Loc) bool {
:= false
for := 0; < len(); ++ {
if [] == '*' {
if {
:= .RangeOfString()
.AddRangeWarning(&, , fmt.Sprintf(
"Invalid pattern %q, must have at most one \"*\" character", ))
return false
}
= true
}
}
return true
}
func ( byte) bool {
return == '/' || == '\\'
}
func ( string, logger.Log, logger.Source, logger.Loc) bool {
var byte
var byte
var byte
:= len()
if > 0 {
= [0]
if > 1 {
= [1]
if > 2 {
= [2]
}
}
}
if == '.' && ( == 1 || ( == 2 && == '.')) {
return true
}
if (( >= 'a' && <= 'z') || ( >= 'A' && <= 'Z')) && == ':' && isSlash() {
return true
}
:= .RangeOfString()
.AddRangeWarning(&, , fmt.Sprintf(
"Non-relative path %q is not allowed when \"baseUrl\" is not set (did you forget a leading \"./\"?)", ))
return false
![]() |
The pages are generated with Golds v0.3.2-preview. (GOOS=darwin GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |