@@ -143,7 +143,7 @@ namespace ts {
143143 getAugmentedPropertiesOfType,
144144 getRootSymbols,
145145 getContextualType: node => {
146- node = getParseTreeNode(node, isExpression)
146+ node = getParseTreeNode(node, isExpression);
147147 return node ? getContextualType(node) : undefined;
148148 },
149149 getFullyQualifiedName,
@@ -16133,7 +16133,7 @@ namespace ts {
1613316133 }
1613416134
1613516135 function checkDeclarationInitializer(declaration: VariableLikeDeclaration) {
16136- const type = checkExpressionCached (declaration.initializer);
16136+ const type = getTypeOfExpression (declaration.initializer, /*cache*/ true );
1613716137 return getCombinedNodeFlags(declaration) & NodeFlags.Const ||
1613816138 getCombinedModifierFlags(declaration) & ModifierFlags.Readonly && !isParameterPropertyDeclaration(declaration) ||
1613916139 isTypeAssertion(declaration.initializer) ? type : getWidenedLiteralType(type);
@@ -16206,10 +16206,12 @@ namespace ts {
1620616206
1620716207 // Returns the type of an expression. Unlike checkExpression, this function is simply concerned
1620816208 // with computing the type and may not fully check all contained sub-expressions for errors.
16209- function getTypeOfExpression(node: Expression) {
16209+ // A cache argument of true indicates that if the function performs a full type check, it is ok
16210+ // to cache the result.
16211+ function getTypeOfExpression(node: Expression, cache?: boolean) {
1621016212 // Optimize for the common case of a call to a function with a single non-generic call
1621116213 // signature where we can just fetch the return type without checking the arguments.
16212- if (node.kind === SyntaxKind.CallExpression && (<CallExpression>node).expression.kind !== SyntaxKind.SuperKeyword) {
16214+ if (node.kind === SyntaxKind.CallExpression && (<CallExpression>node).expression.kind !== SyntaxKind.SuperKeyword && !isRequireCall(node, /*checkArgumentIsStringLiteral*/true) ) {
1621316215 const funcType = checkNonNullExpression((<CallExpression>node).expression);
1621416216 const signature = getSingleCallSignature(funcType);
1621516217 if (signature && !signature.typeParameters) {
@@ -16219,7 +16221,7 @@ namespace ts {
1621916221 // Otherwise simply call checkExpression. Ideally, the entire family of checkXXX functions
1622016222 // should have a parameter that indicates whether full error checking is required such that
1622116223 // we can perform the optimizations locally.
16222- return checkExpression(node);
16224+ return cache ? checkExpressionCached(node) : checkExpression(node);
1622316225 }
1622416226
1622516227 // Checks an expression and returns its type. The contextualMapper parameter serves two purposes: When
@@ -20676,7 +20678,7 @@ namespace ts {
2067620678 }
2067720679
2067820680 if (potentialNewTargetCollisions.length) {
20679- forEach(potentialNewTargetCollisions, checkIfNewTargetIsCapturedInEnclosingScope)
20681+ forEach(potentialNewTargetCollisions, checkIfNewTargetIsCapturedInEnclosingScope);
2068020682 potentialNewTargetCollisions.length = 0;
2068120683 }
2068220684
0 commit comments