package resolver

import (
	
	

	
	
	
	
	
)

The absolute path of "compilerOptions.baseUrl"
This is used if "Paths" is non-nil. It's equal to "BaseURL" except if "BaseURL" is missing, in which case it is as if "BaseURL" was ".". This is to implement the "paths without baseUrl" feature from TypeScript 4.1. More info: https://github.com/microsoft/TypeScript/issues/31869
The verbatim values of "compilerOptions.paths". The keys are patterns to match and the values are arrays of fallback paths to search. Each key and each fallback path can optionally have a single "*" wildcard character. If both the key and the value have a wildcard, the substring matched by the wildcard is substituted into the fallback path. The keys represent module-style path names and the fallback paths are relative to the "baseUrl" value in the "tsconfig.json" file.
Unfortunately "tsconfig.json" isn't actually JSON. It's some other format that appears to be defined by the implementation details of the TypeScript compiler. Attempt to parse it anyway by modifying the JSON parser, but just for these particular files. This is likely not a completely accurate emulation of what the TypeScript compiler does (e.g. string escape behavior may also be different).
	,  := .Parse(, , js_parser.JSONOptions{
		AllowComments:       true, // https://github.com/microsoft/TypeScript/issues/4987
		AllowTrailingCommas: true,
	})
	if ! {
		return nil
	}

	var  TSConfigJSON
Parse "extends"
	if  != nil {
		if , ,  := getProperty(, "extends");  {
			if ,  := getString();  {
				if  := (, .RangeOfString(.Loc));  != nil {
					 = *
				}
			}
		}
	}
Parse "compilerOptions"
Parse "baseUrl"
		if , ,  := getProperty(, "baseUrl");  {
			if ,  := getString();  {
				.BaseURL = &
			}
		}
Parse "jsxFactory"
		if , ,  := getProperty(, "jsxFactory");  {
			if ,  := getString();  {
				.JSXFactory = parseMemberExpressionForJSX(, , .Loc, )
			}
		}
Parse "jsxFragmentFactory"
		if , ,  := getProperty(, "jsxFragmentFactory");  {
			if ,  := getString();  {
				.JSXFragmentFactory = parseMemberExpressionForJSX(, , .Loc, )
			}
		}
Parse "useDefineForClassFields"
		if , ,  := getProperty(, "useDefineForClassFields");  {
			if ,  := getBool();  {
				.UseDefineForClassFields = 
			}
		}
Parse "importsNotUsedAsValues"
		if , ,  := getProperty(, "importsNotUsedAsValues");  {
			if ,  := getString();  {
				switch  {
				case "preserve", "error":
					.PreserveImportsNotUsedAsValues = true
				case "remove":
				default:
					.AddRangeWarning(&, .RangeOfString(.Loc),
						fmt.Sprintf("Invalid value %q for \"importsNotUsedAsValues\"", ))
				}
			}
		}
Parse "paths"
		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
						}
The "paths" field is an object which maps a pattern to an array of remapping patterns to try, in priority order. See the documentation for examples of how this is used: https://www.typescriptlang.org/docs/handbook/module-resolution.html#path-mapping. One particular example: { "compilerOptions": { "baseUrl": "projectRoot", "paths": { "*": [ "*", "generated" ] } } } Matching "folder1/file2" should first check "projectRoot/folder1/file2" and then, if that didn't work, also check "projectRoot/generated/folder1/file2".
						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]
			}
		}
	}
Relative "." or ".."
	if  == '.' && ( == 1 || ( == 2 &&  == '.')) {
		return true
	}
Relative "./" or "../" or ".\\" or "..\\"
	if  == '.' && (isSlash() || ( == '.' && isSlash())) {
		return true
	}
Absolute POSIX "/" or UNC "\\"
	if isSlash() {
		return true
	}
Absolute DOS "c:/" or "c:\\"
	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