MCPcopy Index your code
hub / github.com/nodejs/node / resolveNewExpression

Function resolveNewExpression

test/fixtures/snapshot/typescript.js:76543–76616  ·  view source on GitHub ↗
(node, candidatesOutArray, checkMode)

Source from the content-addressed store, hash-verified

76541 !numCallSignatures && !numConstructSignatures && !(apparentFuncType.flags & 1048576 /* TypeFlags.Union */) && !(getReducedType(apparentFuncType).flags & 131072 /* TypeFlags.Never */) && isTypeAssignableTo(funcType, globalFunctionType);
76542 }
76543 function resolveNewExpression(node, candidatesOutArray, checkMode) {
76544 if (node.arguments && languageVersion < 1 /* ScriptTarget.ES5 */) {
76545 var spreadIndex = getSpreadArgumentIndex(node.arguments);
76546 if (spreadIndex >= 0) {
76547 error(node.arguments[spreadIndex], ts.Diagnostics.Spread_operator_in_new_expressions_is_only_available_when_targeting_ECMAScript_5_and_higher);
76548 }
76549 }
76550 var expressionType = checkNonNullExpression(node.expression);
76551 if (expressionType === silentNeverType) {
76552 return silentNeverSignature;
76553 }
76554 // If expressionType's apparent type(section 3.8.1) is an object type with one or
76555 // more construct signatures, the expression is processed in the same manner as a
76556 // function call, but using the construct signatures as the initial set of candidate
76557 // signatures for overload resolution. The result type of the function call becomes
76558 // the result type of the operation.
76559 expressionType = getApparentType(expressionType);
76560 if (isErrorType(expressionType)) {
76561 // Another error has already been reported
76562 return resolveErrorCall(node);
76563 }
76564 // TS 1.0 spec: 4.11
76565 // If expressionType is of type Any, Args can be any argument
76566 // list and the result of the operation is of type Any.
76567 if (isTypeAny(expressionType)) {
76568 if (node.typeArguments) {
76569 error(node, ts.Diagnostics.Untyped_function_calls_may_not_accept_type_arguments);
76570 }
76571 return resolveUntypedCall(node);
76572 }
76573 // Technically, this signatures list may be incomplete. We are taking the apparent type,
76574 // but we are not including construct signatures that may have been added to the Object or
76575 // Function interface, since they have none by default. This is a bit of a leap of faith
76576 // that the user will not add any.
76577 var constructSignatures = getSignaturesOfType(expressionType, 1 /* SignatureKind.Construct */);
76578 if (constructSignatures.length) {
76579 if (!isConstructorAccessible(node, constructSignatures[0])) {
76580 return resolveErrorCall(node);
76581 }
76582 // If the expression is a class of abstract type, or an abstract construct signature,
76583 // then it cannot be instantiated.
76584 // In the case of a merged class-module or class-interface declaration,
76585 // only the class declaration node will have the Abstract flag set.
76586 if (someSignature(constructSignatures, function (signature) { return !!(signature.flags & 4 /* SignatureFlags.Abstract */); })) {
76587 error(node, ts.Diagnostics.Cannot_create_an_instance_of_an_abstract_class);
76588 return resolveErrorCall(node);
76589 }
76590 var valueDecl = expressionType.symbol && ts.getClassLikeDeclarationOfSymbol(expressionType.symbol);
76591 if (valueDecl && ts.hasSyntacticModifier(valueDecl, 128 /* ModifierFlags.Abstract */)) {
76592 error(node, ts.Diagnostics.Cannot_create_an_instance_of_an_abstract_class);
76593 return resolveErrorCall(node);
76594 }
76595 return resolveCall(node, constructSignatures, candidatesOutArray, checkMode, 0 /* SignatureFlags.None */);
76596 }
76597 // If expressionType's apparent type is an object type with no construct signatures but
76598 // one or more call signatures, the expression is processed as a function call. A compile-time
76599 // error occurs if the result of the function call is not Void. The type of the result of the
76600 // operation is Any. It is an error to have a Void this type.

Callers 1

resolveSignatureFunction · 0.85

Calls 15

getSpreadArgumentIndexFunction · 0.85
checkNonNullExpressionFunction · 0.85
getApparentTypeFunction · 0.85
isErrorTypeFunction · 0.85
resolveErrorCallFunction · 0.85
isTypeAnyFunction · 0.85
resolveUntypedCallFunction · 0.85
getSignaturesOfTypeFunction · 0.85
isConstructorAccessibleFunction · 0.85
someSignatureFunction · 0.85
resolveCallFunction · 0.85
isJSConstructorFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…