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

Method checkImportCallExpression

internal/checker/checker.go:8244–8291  ·  view source on GitHub ↗
(node *ast.Node)

Source from the content-addressed store, hash-verified

8242}
8243
8244func (c *Checker) checkImportCallExpression(node *ast.Node) *Type {
8245 // Check grammar of dynamic import
8246 c.checkGrammarImportCallExpression(node)
8247 args := node.Arguments()
8248 if len(args) == 0 {
8249 return c.createPromiseReturnType(node, c.anyType)
8250 }
8251 specifier := args[0]
8252 specifierType := c.checkExpressionCached(specifier)
8253 var optionsType *Type
8254 if len(args) > 1 {
8255 optionsType = c.checkExpressionCached(args[1])
8256 }
8257 // Even though multiple arguments is grammatically incorrect, type-check extra arguments for completion
8258 for i := 2; i < len(args); i++ {
8259 c.checkExpressionCached(args[i])
8260 }
8261 if specifierType.flags&TypeFlagsNullable != 0 || !c.isTypeAssignableTo(specifierType, c.stringType) {
8262 c.error(specifier, diagnostics.Dynamic_import_s_specifier_must_be_of_type_string_but_here_has_type_0, c.TypeToString(specifierType))
8263 }
8264 if optionsType != nil {
8265 importCallOptionsType := c.getGlobalImportCallOptionsTypeChecked()
8266 if importCallOptionsType != c.emptyObjectType {
8267 c.checkTypeAssignableTo(optionsType, c.getNullableType(importCallOptionsType, TypeFlagsUndefined), args[1], nil)
8268 }
8269 if ast.IsObjectLiteralExpression(args[1]) {
8270 for _, prop := range args[1].AsObjectLiteralExpression().Properties.Nodes {
8271 if ast.IsPropertyAssignment(prop) && ast.IsIdentifier(prop.Name()) && prop.Name().Text() == "assert" {
8272 c.error(prop.Name(), diagnostics.Import_assertions_have_been_replaced_by_import_attributes_Use_with_instead_of_assert)
8273 break
8274 }
8275 }
8276 }
8277 }
8278 // resolveExternalModuleName will return undefined if the moduleReferenceExpression is not a string literal
8279 moduleSymbol := c.resolveExternalModuleName(node, specifier, false /*ignoreErrors*/)
8280 if moduleSymbol != nil {
8281 esModuleSymbol := c.resolveExternalModuleSymbol(moduleSymbol, true /*dontResolveAlias*/)
8282 if esModuleSymbol != nil {
8283 syntheticType := c.getTypeWithSyntheticDefaultOnly(c.getTypeOfSymbol(esModuleSymbol), esModuleSymbol, moduleSymbol, specifier)
8284 if syntheticType == nil {
8285 syntheticType = c.getTypeWithSyntheticDefaultImportType(c.getTypeOfSymbol(esModuleSymbol), esModuleSymbol, moduleSymbol, specifier)
8286 }
8287 return c.createPromiseReturnType(node, syntheticType)
8288 }
8289 }
8290 return c.createPromiseReturnType(node, c.anyType)
8291}
8292
8293/**
8294 * Syntactically and semantically checks a call or new expression.

Callers 1

checkExpressionWorkerMethod · 0.95

Calls 15

checkExpressionCachedMethod · 0.95
isTypeAssignableToMethod · 0.95
errorMethod · 0.95
TypeToStringMethod · 0.95
checkTypeAssignableToMethod · 0.95
getNullableTypeMethod · 0.95
getTypeOfSymbolMethod · 0.95

Tested by

no test coverage detected