mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-26 20:14:05 -05:00
Merge branch 'master' into sourceMapDestructuring
This commit is contained in:
@@ -1499,10 +1499,7 @@ namespace ts {
|
||||
|
||||
// If this is a property-parameter, then also declare the property symbol into the
|
||||
// containing class.
|
||||
if (node.flags & NodeFlags.AccessibilityModifier &&
|
||||
node.parent.kind === SyntaxKind.Constructor &&
|
||||
isClassLike(node.parent.parent)) {
|
||||
|
||||
if (isParameterPropertyDeclaration(node)) {
|
||||
const classDeclaration = <ClassLikeDeclaration>node.parent.parent;
|
||||
declareSymbol(classDeclaration.symbol.members, classDeclaration.symbol, node, SymbolFlags.Property, SymbolFlags.PropertyExcludes);
|
||||
}
|
||||
|
||||
@@ -67,6 +67,7 @@ namespace ts {
|
||||
// The language service will always care about the narrowed type of a symbol, because that is
|
||||
// the type the language says the symbol should have.
|
||||
getTypeOfSymbolAtLocation: getNarrowedTypeOfSymbol,
|
||||
getSymbolsOfParameterPropertyDeclaration,
|
||||
getDeclaredTypeOfSymbol,
|
||||
getPropertiesOfType,
|
||||
getPropertyOfType,
|
||||
@@ -430,6 +431,26 @@ namespace ts {
|
||||
// return undefined if we can't find a symbol.
|
||||
}
|
||||
|
||||
/**
|
||||
* Get symbols that represent parameter-property-declaration as parameter and as property declaration
|
||||
* @param parameter a parameterDeclaration node
|
||||
* @param parameterName a name of the parameter to get the symbols for.
|
||||
* @return a tuple of two symbols
|
||||
*/
|
||||
function getSymbolsOfParameterPropertyDeclaration(parameter: ParameterDeclaration, parameterName: string): [Symbol, Symbol] {
|
||||
const constructoDeclaration = parameter.parent;
|
||||
const classDeclaration = parameter.parent.parent;
|
||||
|
||||
const parameterSymbol = getSymbol(constructoDeclaration.locals, parameterName, SymbolFlags.Value);
|
||||
const propertySymbol = getSymbol(classDeclaration.symbol.members, parameterName, SymbolFlags.Value);
|
||||
|
||||
if (parameterSymbol && propertySymbol) {
|
||||
return [parameterSymbol, propertySymbol];
|
||||
}
|
||||
|
||||
Debug.fail("There should exist two symbols, one as property declaration and one as parameter declaration");
|
||||
}
|
||||
|
||||
function isBlockScopedNameDeclaredBeforeUse(declaration: Declaration, usage: Node): boolean {
|
||||
const declarationFile = getSourceFileOfNode(declaration);
|
||||
const useFile = getSourceFileOfNode(usage);
|
||||
@@ -819,15 +840,6 @@ namespace ts {
|
||||
return resolveESModuleSymbol(resolveExternalModuleName(node, moduleSpecifier), moduleSpecifier);
|
||||
}
|
||||
|
||||
function getMemberOfModuleVariable(moduleSymbol: Symbol, name: string): Symbol {
|
||||
if (moduleSymbol.flags & SymbolFlags.Variable) {
|
||||
const typeAnnotation = (<VariableDeclaration>moduleSymbol.valueDeclaration).type;
|
||||
if (typeAnnotation) {
|
||||
return getPropertyOfType(getTypeFromTypeNode(typeAnnotation), name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// This function creates a synthetic symbol that combines the value side of one symbol with the
|
||||
// type/namespace side of another symbol. Consider this example:
|
||||
//
|
||||
@@ -1063,7 +1075,6 @@ namespace ts {
|
||||
}
|
||||
|
||||
const moduleReferenceLiteral = <LiteralExpression>moduleReferenceExpression;
|
||||
const searchPath = getDirectoryPath(getSourceFile(location).fileName);
|
||||
|
||||
// Module names are escaped in our symbol table. However, string literal values aren't.
|
||||
// Escape the name in the "require(...)" clause to ensure we find the right symbol.
|
||||
@@ -2183,65 +2194,15 @@ namespace ts {
|
||||
}
|
||||
|
||||
function isDeclarationVisible(node: Declaration): boolean {
|
||||
function getContainingExternalModule(node: Node) {
|
||||
for (; node; node = node.parent) {
|
||||
if (node.kind === SyntaxKind.ModuleDeclaration) {
|
||||
if ((<ModuleDeclaration>node).name.kind === SyntaxKind.StringLiteral) {
|
||||
return node;
|
||||
}
|
||||
}
|
||||
else if (node.kind === SyntaxKind.SourceFile) {
|
||||
return isExternalOrCommonJsModule(<SourceFile>node) ? node : undefined;
|
||||
}
|
||||
if (node) {
|
||||
const links = getNodeLinks(node);
|
||||
if (links.isVisible === undefined) {
|
||||
links.isVisible = !!determineIfDeclarationIsVisible();
|
||||
}
|
||||
Debug.fail("getContainingModule cant reach here");
|
||||
return links.isVisible;
|
||||
}
|
||||
|
||||
function isUsedInExportAssignment(node: Node) {
|
||||
// Get source File and see if it is external module and has export assigned symbol
|
||||
const externalModule = getContainingExternalModule(node);
|
||||
let exportAssignmentSymbol: Symbol;
|
||||
let resolvedExportSymbol: Symbol;
|
||||
if (externalModule) {
|
||||
// This is export assigned symbol node
|
||||
const externalModuleSymbol = getSymbolOfNode(externalModule);
|
||||
exportAssignmentSymbol = getExportAssignmentSymbol(externalModuleSymbol);
|
||||
const symbolOfNode = getSymbolOfNode(node);
|
||||
if (isSymbolUsedInExportAssignment(symbolOfNode)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// if symbolOfNode is alias declaration, resolve the symbol declaration and check
|
||||
if (symbolOfNode.flags & SymbolFlags.Alias) {
|
||||
return isSymbolUsedInExportAssignment(resolveAlias(symbolOfNode));
|
||||
}
|
||||
}
|
||||
|
||||
// Check if the symbol is used in export assignment
|
||||
function isSymbolUsedInExportAssignment(symbol: Symbol) {
|
||||
if (exportAssignmentSymbol === symbol) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (exportAssignmentSymbol && !!(exportAssignmentSymbol.flags & SymbolFlags.Alias)) {
|
||||
// if export assigned symbol is alias declaration, resolve the alias
|
||||
resolvedExportSymbol = resolvedExportSymbol || resolveAlias(exportAssignmentSymbol);
|
||||
if (resolvedExportSymbol === symbol) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Container of resolvedExportSymbol is visible
|
||||
return forEach(resolvedExportSymbol.declarations, (current: Node) => {
|
||||
while (current) {
|
||||
if (current === node) {
|
||||
return true;
|
||||
}
|
||||
current = current.parent;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
||||
function determineIfDeclarationIsVisible() {
|
||||
switch (node.kind) {
|
||||
@@ -2320,14 +2281,6 @@ namespace ts {
|
||||
Debug.fail("isDeclarationVisible unknown: SyntaxKind: " + node.kind);
|
||||
}
|
||||
}
|
||||
|
||||
if (node) {
|
||||
const links = getNodeLinks(node);
|
||||
if (links.isVisible === undefined) {
|
||||
links.isVisible = !!determineIfDeclarationIsVisible();
|
||||
}
|
||||
return links.isVisible;
|
||||
}
|
||||
}
|
||||
|
||||
function collectLinkedAliases(node: Identifier): Node[] {
|
||||
@@ -3373,14 +3326,6 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
|
||||
function addInheritedSignatures(signatures: Signature[], baseSignatures: Signature[]) {
|
||||
if (baseSignatures) {
|
||||
for (const signature of baseSignatures) {
|
||||
signatures.push(signature);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function resolveDeclaredMembers(type: InterfaceType): InterfaceTypeWithDeclaredMembers {
|
||||
if (!(<InterfaceTypeWithDeclaredMembers>type).declaredProperties) {
|
||||
const symbol = type.symbol;
|
||||
@@ -3507,7 +3452,7 @@ namespace ts {
|
||||
|
||||
function findMatchingSignature(signatureList: Signature[], signature: Signature, partialMatch: boolean, ignoreReturnTypes: boolean): Signature {
|
||||
for (const s of signatureList) {
|
||||
if (compareSignatures(s, signature, partialMatch, ignoreReturnTypes, compareTypes)) {
|
||||
if (compareSignaturesIdentical(s, signature, partialMatch, ignoreReturnTypes, compareTypesIdentical)) {
|
||||
return s;
|
||||
}
|
||||
}
|
||||
@@ -3768,11 +3713,14 @@ namespace ts {
|
||||
function createUnionOrIntersectionProperty(containingType: UnionOrIntersectionType, name: string): Symbol {
|
||||
const types = containingType.types;
|
||||
let props: Symbol[];
|
||||
// Flags we want to propagate to the result if they exist in all source symbols
|
||||
let commonFlags = (containingType.flags & TypeFlags.Intersection) ? SymbolFlags.Optional : SymbolFlags.None;
|
||||
for (const current of types) {
|
||||
const type = getApparentType(current);
|
||||
if (type !== unknownType) {
|
||||
const prop = getPropertyOfType(type, name);
|
||||
if (prop && !(getDeclarationFlagsFromSymbol(prop) & (NodeFlags.Private | NodeFlags.Protected))) {
|
||||
commonFlags &= prop.flags;
|
||||
if (!props) {
|
||||
props = [prop];
|
||||
}
|
||||
@@ -3800,7 +3748,12 @@ namespace ts {
|
||||
}
|
||||
propTypes.push(getTypeOfSymbol(prop));
|
||||
}
|
||||
const result = <TransientSymbol>createSymbol(SymbolFlags.Property | SymbolFlags.Transient | SymbolFlags.SyntheticProperty, name);
|
||||
const result = <TransientSymbol>createSymbol(
|
||||
SymbolFlags.Property |
|
||||
SymbolFlags.Transient |
|
||||
SymbolFlags.SyntheticProperty |
|
||||
commonFlags,
|
||||
name);
|
||||
result.containingType = containingType;
|
||||
result.declarations = declarations;
|
||||
result.type = containingType.flags & TypeFlags.Union ? getUnionType(propTypes) : getIntersectionType(propTypes);
|
||||
@@ -3861,25 +3814,6 @@ namespace ts {
|
||||
function getSignaturesOfType(type: Type, kind: SignatureKind): Signature[] {
|
||||
return getSignaturesOfStructuredType(getApparentType(type), kind);
|
||||
}
|
||||
|
||||
function typeHasConstructSignatures(type: Type): boolean {
|
||||
const apparentType = getApparentType(type);
|
||||
if (apparentType.flags & (TypeFlags.ObjectType | TypeFlags.Union)) {
|
||||
const resolved = resolveStructuredTypeMembers(<ObjectType>type);
|
||||
return resolved.constructSignatures.length > 0;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function typeHasCallOrConstructSignatures(type: Type): boolean {
|
||||
const apparentType = getApparentType(type);
|
||||
if (apparentType.flags & TypeFlags.StructuredType) {
|
||||
const resolved = resolveStructuredTypeMembers(<ObjectType>type);
|
||||
return resolved.callSignatures.length > 0 || resolved.constructSignatures.length > 0;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function getIndexTypeOfStructuredType(type: Type, kind: IndexKind): Type {
|
||||
if (type.flags & TypeFlags.StructuredType) {
|
||||
const resolved = resolveStructuredTypeMembers(<ObjectType>type);
|
||||
@@ -4381,10 +4315,6 @@ namespace ts {
|
||||
return getTypeOfGlobalSymbol(getGlobalTypeSymbol(name), arity);
|
||||
}
|
||||
|
||||
function tryGetGlobalType(name: string, arity = 0): ObjectType {
|
||||
return getTypeOfGlobalSymbol(getGlobalSymbol(name, SymbolFlags.Type, /*diagnostic*/ undefined), arity);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a type that is inside a namespace at the global scope, e.g.
|
||||
* getExportedTypeFromNamespace('JSX', 'Element') returns the JSX.Element type
|
||||
@@ -4959,7 +4889,7 @@ namespace ts {
|
||||
return checkTypeRelatedTo(source, target, identityRelation, /*errorNode*/ undefined);
|
||||
}
|
||||
|
||||
function compareTypes(source: Type, target: Type): Ternary {
|
||||
function compareTypesIdentical(source: Type, target: Type): Ternary {
|
||||
return checkTypeRelatedTo(source, target, identityRelation, /*errorNode*/ undefined) ? Ternary.True : Ternary.False;
|
||||
}
|
||||
|
||||
@@ -4979,10 +4909,96 @@ namespace ts {
|
||||
return checkTypeRelatedTo(source, target, assignableRelation, errorNode, headMessage, containingMessageChain);
|
||||
}
|
||||
|
||||
function isSignatureAssignableTo(source: Signature, target: Signature): boolean {
|
||||
const sourceType = getOrCreateTypeFromSignature(source);
|
||||
const targetType = getOrCreateTypeFromSignature(target);
|
||||
return checkTypeRelatedTo(sourceType, targetType, assignableRelation, /*errorNode*/ undefined);
|
||||
/**
|
||||
* See signatureRelatedTo, compareSignaturesIdentical
|
||||
*/
|
||||
function isSignatureAssignableTo(source: Signature, target: Signature, ignoreReturnTypes: boolean): boolean {
|
||||
// TODO (drosen): De-duplicate code between related functions.
|
||||
if (source === target) {
|
||||
return true;
|
||||
}
|
||||
if (!target.hasRestParameter && source.minArgumentCount > target.parameters.length) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Spec 1.0 Section 3.8.3 & 3.8.4:
|
||||
// M and N (the signatures) are instantiated using type Any as the type argument for all type parameters declared by M and N
|
||||
source = getErasedSignature(source);
|
||||
target = getErasedSignature(target);
|
||||
|
||||
const sourceMax = getNumNonRestParameters(source);
|
||||
const targetMax = getNumNonRestParameters(target);
|
||||
const checkCount = getNumParametersToCheckForSignatureRelatability(source, sourceMax, target, targetMax);
|
||||
for (let i = 0; i < checkCount; i++) {
|
||||
const s = i < sourceMax ? getTypeOfSymbol(source.parameters[i]) : getRestTypeOfSignature(source);
|
||||
const t = i < targetMax ? getTypeOfSymbol(target.parameters[i]) : getRestTypeOfSignature(target);
|
||||
const related = isTypeAssignableTo(t, s) || isTypeAssignableTo(s, t);
|
||||
if (!related) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!ignoreReturnTypes) {
|
||||
const targetReturnType = getReturnTypeOfSignature(target);
|
||||
if (targetReturnType === voidType) {
|
||||
return true;
|
||||
}
|
||||
const sourceReturnType = getReturnTypeOfSignature(source);
|
||||
|
||||
// The following block preserves behavior forbidding boolean returning functions from being assignable to type guard returning functions
|
||||
if (targetReturnType.flags & TypeFlags.PredicateType && (targetReturnType as PredicateType).predicate.kind === TypePredicateKind.Identifier) {
|
||||
if (!(sourceReturnType.flags & TypeFlags.PredicateType)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return isTypeAssignableTo(sourceReturnType, targetReturnType);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function isImplementationCompatibleWithOverload(implementation: Signature, overload: Signature): boolean {
|
||||
const erasedSource = getErasedSignature(implementation);
|
||||
const erasedTarget = getErasedSignature(overload);
|
||||
|
||||
// First see if the return types are compatible in either direction.
|
||||
const sourceReturnType = getReturnTypeOfSignature(erasedSource);
|
||||
const targetReturnType = getReturnTypeOfSignature(erasedTarget);
|
||||
if (targetReturnType === voidType
|
||||
|| checkTypeRelatedTo(targetReturnType, sourceReturnType, assignableRelation, /*errorNode*/ undefined)
|
||||
|| checkTypeRelatedTo(sourceReturnType, targetReturnType, assignableRelation, /*errorNode*/ undefined)) {
|
||||
|
||||
return isSignatureAssignableTo(erasedSource, erasedTarget, /*ignoreReturnTypes*/ true);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function getNumNonRestParameters(signature: Signature) {
|
||||
const numParams = signature.parameters.length;
|
||||
return signature.hasRestParameter ?
|
||||
numParams - 1 :
|
||||
numParams;
|
||||
}
|
||||
|
||||
function getNumParametersToCheckForSignatureRelatability(source: Signature, sourceNonRestParamCount: number, target: Signature, targetNonRestParamCount: number) {
|
||||
if (source.hasRestParameter === target.hasRestParameter) {
|
||||
if (source.hasRestParameter) {
|
||||
// If both have rest parameters, get the max and add 1 to
|
||||
// compensate for the rest parameter.
|
||||
return Math.max(sourceNonRestParamCount, targetNonRestParamCount) + 1;
|
||||
}
|
||||
else {
|
||||
return Math.min(sourceNonRestParamCount, targetNonRestParamCount);
|
||||
}
|
||||
}
|
||||
else {
|
||||
// Return the count for whichever signature doesn't have rest parameters.
|
||||
return source.hasRestParameter ?
|
||||
targetNonRestParamCount :
|
||||
sourceNonRestParamCount;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -5066,6 +5082,11 @@ namespace ts {
|
||||
if (source === undefinedType) return Ternary.True;
|
||||
if (source === nullType && target !== undefinedType) return Ternary.True;
|
||||
if (source.flags & TypeFlags.Enum && target === numberType) return Ternary.True;
|
||||
if (source.flags & TypeFlags.Enum && target.flags & TypeFlags.Enum) {
|
||||
if (result = enumRelatedTo(source, target)) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
if (source.flags & TypeFlags.StringLiteral && target === stringType) return Ternary.True;
|
||||
if (relation === assignableRelation) {
|
||||
if (isTypeAny(source)) return Ternary.True;
|
||||
@@ -5528,32 +5549,24 @@ namespace ts {
|
||||
if (target === anyFunctionType || source === anyFunctionType) {
|
||||
return Ternary.True;
|
||||
}
|
||||
|
||||
const sourceSignatures = getSignaturesOfType(source, kind);
|
||||
const targetSignatures = getSignaturesOfType(target, kind);
|
||||
if (kind === SignatureKind.Construct && sourceSignatures.length && targetSignatures.length &&
|
||||
isAbstractConstructorType(source) && !isAbstractConstructorType(target)) {
|
||||
// An abstract constructor type is not assignable to a non-abstract constructor type
|
||||
// as it would otherwise be possible to new an abstract class. Note that the assignablity
|
||||
// check we perform for an extends clause excludes construct signatures from the target,
|
||||
// so this check never proceeds.
|
||||
if (reportErrors) {
|
||||
reportError(Diagnostics.Cannot_assign_an_abstract_constructor_type_to_a_non_abstract_constructor_type);
|
||||
}
|
||||
return Ternary.False;
|
||||
}
|
||||
|
||||
let result = Ternary.True;
|
||||
const saveErrorInfo = errorInfo;
|
||||
|
||||
|
||||
|
||||
if (kind === SignatureKind.Construct) {
|
||||
// Only want to compare the construct signatures for abstractness guarantees.
|
||||
|
||||
// Because the "abstractness" of a class is the same across all construct signatures
|
||||
// (internally we are checking the corresponding declaration), it is enough to perform
|
||||
// the check and report an error once over all pairs of source and target construct signatures.
|
||||
//
|
||||
// sourceSig and targetSig are (possibly) undefined.
|
||||
//
|
||||
// Note that in an extends-clause, targetSignatures is stripped, so the check never proceeds.
|
||||
const sourceSig = sourceSignatures[0];
|
||||
const targetSig = targetSignatures[0];
|
||||
|
||||
result &= abstractSignatureRelatedTo(source, sourceSig, target, targetSig);
|
||||
if (result !== Ternary.True) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
outer: for (const t of targetSignatures) {
|
||||
if (!t.hasStringLiterals || target.flags & TypeFlags.FromSignature) {
|
||||
// Only elaborate errors from the first failure
|
||||
@@ -5569,7 +5582,7 @@ namespace ts {
|
||||
shouldElaborateErrors = false;
|
||||
}
|
||||
}
|
||||
// don't elaborate the primitive apparent types (like Number)
|
||||
// don't elaborate the primitive apparent types (like Number)
|
||||
// because the actual primitives will have already been reported.
|
||||
if (shouldElaborateErrors && !isPrimitiveApparentType(source)) {
|
||||
reportError(Diagnostics.Type_0_provides_no_match_for_the_signature_1,
|
||||
@@ -5580,43 +5593,13 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
return result;
|
||||
|
||||
function abstractSignatureRelatedTo(source: Type, sourceSig: Signature, target: Type, targetSig: Signature) {
|
||||
if (sourceSig && targetSig) {
|
||||
|
||||
const sourceDecl = source.symbol && getClassLikeDeclarationOfSymbol(source.symbol);
|
||||
const targetDecl = target.symbol && getClassLikeDeclarationOfSymbol(target.symbol);
|
||||
|
||||
if (!sourceDecl) {
|
||||
// If the source object isn't itself a class declaration, it can be freely assigned, regardless
|
||||
// of whether the constructed object is abstract or not.
|
||||
return Ternary.True;
|
||||
}
|
||||
|
||||
const sourceErasedSignature = getErasedSignature(sourceSig);
|
||||
const targetErasedSignature = getErasedSignature(targetSig);
|
||||
|
||||
const sourceReturnType = sourceErasedSignature && getReturnTypeOfSignature(sourceErasedSignature);
|
||||
const targetReturnType = targetErasedSignature && getReturnTypeOfSignature(targetErasedSignature);
|
||||
|
||||
const sourceReturnDecl = sourceReturnType && sourceReturnType.symbol && getClassLikeDeclarationOfSymbol(sourceReturnType.symbol);
|
||||
const targetReturnDecl = targetReturnType && targetReturnType.symbol && getClassLikeDeclarationOfSymbol(targetReturnType.symbol);
|
||||
const sourceIsAbstract = sourceReturnDecl && sourceReturnDecl.flags & NodeFlags.Abstract;
|
||||
const targetIsAbstract = targetReturnDecl && targetReturnDecl.flags & NodeFlags.Abstract;
|
||||
|
||||
if (sourceIsAbstract && !(targetIsAbstract && targetDecl)) {
|
||||
// if target isn't a class-declaration type, then it can be new'd, so we forbid the assignment.
|
||||
if (reportErrors) {
|
||||
reportError(Diagnostics.Cannot_assign_an_abstract_constructor_type_to_a_non_abstract_constructor_type);
|
||||
}
|
||||
return Ternary.False;
|
||||
}
|
||||
}
|
||||
return Ternary.True;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* See signatureAssignableTo, signatureAssignableTo
|
||||
*/
|
||||
function signatureRelatedTo(source: Signature, target: Signature, reportErrors: boolean): Ternary {
|
||||
// TODO (drosen): De-duplicate code between related functions.
|
||||
if (source === target) {
|
||||
return Ternary.True;
|
||||
}
|
||||
@@ -5668,10 +5651,12 @@ namespace ts {
|
||||
}
|
||||
|
||||
const targetReturnType = getReturnTypeOfSignature(target);
|
||||
if (targetReturnType === voidType) return result;
|
||||
if (targetReturnType === voidType) {
|
||||
return result;
|
||||
}
|
||||
const sourceReturnType = getReturnTypeOfSignature(source);
|
||||
|
||||
// The follow block preserves old behavior forbidding boolean returning functions from being assignable to type guard returning functions
|
||||
// The following block preserves behavior forbidding boolean returning functions from being assignable to type guard returning functions
|
||||
if (targetReturnType.flags & TypeFlags.PredicateType && (targetReturnType as PredicateType).predicate.kind === TypePredicateKind.Identifier) {
|
||||
if (!(sourceReturnType.flags & TypeFlags.PredicateType)) {
|
||||
if (reportErrors) {
|
||||
@@ -5692,7 +5677,7 @@ namespace ts {
|
||||
}
|
||||
let result = Ternary.True;
|
||||
for (let i = 0, len = sourceSignatures.length; i < len; ++i) {
|
||||
const related = compareSignatures(sourceSignatures[i], targetSignatures[i], /*partialMatch*/ false, /*ignoreReturnTypes*/ false, isRelatedTo);
|
||||
const related = compareSignaturesIdentical(sourceSignatures[i], targetSignatures[i], /*partialMatch*/ false, /*ignoreReturnTypes*/ false, isRelatedTo);
|
||||
if (!related) {
|
||||
return Ternary.False;
|
||||
}
|
||||
@@ -5780,6 +5765,41 @@ namespace ts {
|
||||
}
|
||||
return Ternary.False;
|
||||
}
|
||||
|
||||
function enumRelatedTo(source: Type, target: Type) {
|
||||
if (source.symbol.name !== target.symbol.name ||
|
||||
source.symbol.flags & SymbolFlags.ConstEnum ||
|
||||
target.symbol.flags & SymbolFlags.ConstEnum) {
|
||||
return Ternary.False;
|
||||
}
|
||||
const targetEnumType = getTypeOfSymbol(target.symbol);
|
||||
for (const property of getPropertiesOfType(getTypeOfSymbol(source.symbol))) {
|
||||
if (property.flags & SymbolFlags.EnumMember) {
|
||||
const targetProperty = getPropertyOfType(targetEnumType, property.name);
|
||||
if (!targetProperty || !(targetProperty.flags & SymbolFlags.EnumMember)) {
|
||||
reportError(Diagnostics.Property_0_is_missing_in_type_1,
|
||||
property.name,
|
||||
typeToString(target, /*enclosingDeclaration*/ undefined, TypeFormatFlags.UseFullyQualifiedType));
|
||||
return Ternary.False;
|
||||
}
|
||||
}
|
||||
}
|
||||
return Ternary.True;
|
||||
}
|
||||
}
|
||||
|
||||
// Return true if the given type is the constructor type for an abstract class
|
||||
function isAbstractConstructorType(type: Type) {
|
||||
if (type.flags & TypeFlags.Anonymous) {
|
||||
const symbol = type.symbol;
|
||||
if (symbol && symbol.flags & SymbolFlags.Class) {
|
||||
const declaration = getClassLikeDeclarationOfSymbol(symbol);
|
||||
if (declaration && declaration.flags & NodeFlags.Abstract) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Return true if the given type is part of a deeply nested chain of generic instantiations. We consider this to be the case
|
||||
@@ -5804,7 +5824,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
function isPropertyIdenticalTo(sourceProp: Symbol, targetProp: Symbol): boolean {
|
||||
return compareProperties(sourceProp, targetProp, compareTypes) !== Ternary.False;
|
||||
return compareProperties(sourceProp, targetProp, compareTypesIdentical) !== Ternary.False;
|
||||
}
|
||||
|
||||
function compareProperties(sourceProp: Symbol, targetProp: Symbol, compareTypes: (source: Type, target: Type) => Ternary): Ternary {
|
||||
@@ -5851,7 +5871,11 @@ namespace ts {
|
||||
return false;
|
||||
}
|
||||
|
||||
function compareSignatures(source: Signature, target: Signature, partialMatch: boolean, ignoreReturnTypes: boolean, compareTypes: (s: Type, t: Type) => Ternary): Ternary {
|
||||
/**
|
||||
* See signatureRelatedTo, compareSignaturesIdentical
|
||||
*/
|
||||
function compareSignaturesIdentical(source: Signature, target: Signature, partialMatch: boolean, ignoreReturnTypes: boolean, compareTypes: (s: Type, t: Type) => Ternary): Ternary {
|
||||
// TODO (drosen): De-duplicate code between related functions.
|
||||
if (source === target) {
|
||||
return Ternary.True;
|
||||
}
|
||||
@@ -6148,12 +6172,8 @@ namespace ts {
|
||||
}
|
||||
|
||||
function createInferenceContext(typeParameters: TypeParameter[], inferUnionTypes: boolean): InferenceContext {
|
||||
const inferences: TypeInferences[] = [];
|
||||
for (const unused of typeParameters) {
|
||||
inferences.push({
|
||||
primary: undefined, secondary: undefined, isFixed: false
|
||||
});
|
||||
}
|
||||
const inferences = map(typeParameters, createTypeInferencesObject);
|
||||
|
||||
return {
|
||||
typeParameters,
|
||||
inferUnionTypes,
|
||||
@@ -6162,6 +6182,14 @@ namespace ts {
|
||||
};
|
||||
}
|
||||
|
||||
function createTypeInferencesObject(): TypeInferences {
|
||||
return {
|
||||
primary: undefined,
|
||||
secondary: undefined,
|
||||
isFixed: false,
|
||||
};
|
||||
}
|
||||
|
||||
function inferTypes(context: InferenceContext, source: Type, target: Type) {
|
||||
let sourceStack: Type[];
|
||||
let targetStack: Type[];
|
||||
@@ -6432,10 +6460,6 @@ namespace ts {
|
||||
return context.inferredTypes;
|
||||
}
|
||||
|
||||
function hasAncestor(node: Node, kind: SyntaxKind): boolean {
|
||||
return getAncestor(node, kind) !== undefined;
|
||||
}
|
||||
|
||||
// EXPRESSION TYPE CHECKING
|
||||
|
||||
function getResolvedSymbol(node: Identifier): Symbol {
|
||||
@@ -7058,17 +7082,14 @@ namespace ts {
|
||||
|
||||
function checkSuperExpression(node: Node): Type {
|
||||
const isCallExpression = node.parent.kind === SyntaxKind.CallExpression && (<CallExpression>node.parent).expression === node;
|
||||
const classDeclaration = getContainingClass(node);
|
||||
const classType = classDeclaration && <InterfaceType>getDeclaredTypeOfSymbol(getSymbolOfNode(classDeclaration));
|
||||
const baseClassType = classType && getBaseTypes(classType)[0];
|
||||
|
||||
let container = getSuperContainer(node, /*includeFunctions*/ true);
|
||||
let container = getSuperContainer(node, /*stopOnFunctions*/ true);
|
||||
let needToCaptureLexicalThis = false;
|
||||
|
||||
if (!isCallExpression) {
|
||||
// adjust the container reference in case if super is used inside arrow functions with arbitrary deep nesting
|
||||
while (container && container.kind === SyntaxKind.ArrowFunction) {
|
||||
container = getSuperContainer(container, /*includeFunctions*/ true);
|
||||
container = getSuperContainer(container, /*stopOnFunctions*/ true);
|
||||
needToCaptureLexicalThis = languageVersion < ScriptTarget.ES6;
|
||||
}
|
||||
}
|
||||
@@ -7076,43 +7097,66 @@ namespace ts {
|
||||
const canUseSuperExpression = isLegalUsageOfSuperExpression(container);
|
||||
let nodeCheckFlag: NodeCheckFlags = 0;
|
||||
|
||||
// always set NodeCheckFlags for 'super' expression node
|
||||
if (canUseSuperExpression) {
|
||||
if ((container.flags & NodeFlags.Static) || isCallExpression) {
|
||||
nodeCheckFlag = NodeCheckFlags.SuperStatic;
|
||||
}
|
||||
else {
|
||||
nodeCheckFlag = NodeCheckFlags.SuperInstance;
|
||||
}
|
||||
|
||||
getNodeLinks(node).flags |= nodeCheckFlag;
|
||||
|
||||
if (needToCaptureLexicalThis) {
|
||||
// call expressions are allowed only in constructors so they should always capture correct 'this'
|
||||
// super property access expressions can also appear in arrow functions -
|
||||
// in this case they should also use correct lexical this
|
||||
captureLexicalThis(node.parent, container);
|
||||
}
|
||||
}
|
||||
|
||||
if (!baseClassType) {
|
||||
if (!classDeclaration || !getClassExtendsHeritageClauseElement(classDeclaration)) {
|
||||
error(node, Diagnostics.super_can_only_be_referenced_in_a_derived_class);
|
||||
}
|
||||
return unknownType;
|
||||
}
|
||||
|
||||
if (!canUseSuperExpression) {
|
||||
if (container && container.kind === SyntaxKind.ComputedPropertyName) {
|
||||
// issue more specific error if super is used in computed property name
|
||||
// class A { foo() { return "1" }}
|
||||
// class B {
|
||||
// [super.foo()]() {}
|
||||
// }
|
||||
let current = node;
|
||||
while (current && current !== container && current.kind !== SyntaxKind.ComputedPropertyName) {
|
||||
current = current.parent;
|
||||
}
|
||||
if (current && current.kind === SyntaxKind.ComputedPropertyName) {
|
||||
error(node, Diagnostics.super_cannot_be_referenced_in_a_computed_property_name);
|
||||
}
|
||||
else if (isCallExpression) {
|
||||
error(node, Diagnostics.Super_calls_are_not_permitted_outside_constructors_or_in_nested_functions_inside_constructors);
|
||||
}
|
||||
else if (!container || !container.parent || !(isClassLike(container.parent) || container.parent.kind === SyntaxKind.ObjectLiteralExpression)) {
|
||||
error(node, Diagnostics.super_can_only_be_referenced_in_members_of_derived_classes_or_object_literal_expressions);
|
||||
}
|
||||
else {
|
||||
error(node, Diagnostics.super_property_access_is_permitted_only_in_a_constructor_member_function_or_member_accessor_of_a_derived_class);
|
||||
}
|
||||
return unknownType;
|
||||
}
|
||||
|
||||
if ((container.flags & NodeFlags.Static) || isCallExpression) {
|
||||
nodeCheckFlag = NodeCheckFlags.SuperStatic;
|
||||
}
|
||||
else {
|
||||
nodeCheckFlag = NodeCheckFlags.SuperInstance;
|
||||
}
|
||||
|
||||
getNodeLinks(node).flags |= nodeCheckFlag;
|
||||
|
||||
if (needToCaptureLexicalThis) {
|
||||
// call expressions are allowed only in constructors so they should always capture correct 'this'
|
||||
// super property access expressions can also appear in arrow functions -
|
||||
// in this case they should also use correct lexical this
|
||||
captureLexicalThis(node.parent, container);
|
||||
}
|
||||
|
||||
if (container.parent.kind === SyntaxKind.ObjectLiteralExpression) {
|
||||
if (languageVersion < ScriptTarget.ES6) {
|
||||
error(node, Diagnostics.super_is_only_allowed_in_members_of_object_literal_expressions_when_option_target_is_ES2015_or_higher);
|
||||
return unknownType;
|
||||
}
|
||||
else {
|
||||
// for object literal assume that type of 'super' is 'any'
|
||||
return anyType;
|
||||
}
|
||||
}
|
||||
|
||||
// at this point the only legal case for parent is ClassLikeDeclaration
|
||||
const classLikeDeclaration = <ClassLikeDeclaration>container.parent;
|
||||
const classType = <InterfaceType>getDeclaredTypeOfSymbol(getSymbolOfNode(classLikeDeclaration));
|
||||
const baseClassType = classType && getBaseTypes(classType)[0];
|
||||
if (!baseClassType) {
|
||||
if (!getClassExtendsHeritageClauseElement(classLikeDeclaration)) {
|
||||
error(node, Diagnostics.super_can_only_be_referenced_in_a_derived_class);
|
||||
}
|
||||
return unknownType;
|
||||
}
|
||||
|
||||
@@ -7142,8 +7186,8 @@ namespace ts {
|
||||
// - In a constructor, instance member function, instance member accessor, or instance member variable initializer where this references a derived class instance
|
||||
// - In a static member function or static member accessor
|
||||
|
||||
// topmost container must be something that is directly nested in the class declaration
|
||||
if (container && isClassLike(container.parent)) {
|
||||
// topmost container must be something that is directly nested in the class declaration\object literal expression
|
||||
if (isClassLike(container.parent) || container.parent.kind === SyntaxKind.ObjectLiteralExpression) {
|
||||
if (container.flags & NodeFlags.Static) {
|
||||
return container.kind === SyntaxKind.MethodDeclaration ||
|
||||
container.kind === SyntaxKind.MethodSignature ||
|
||||
@@ -7559,7 +7603,7 @@ namespace ts {
|
||||
// This signature will contribute to contextual union signature
|
||||
signatureList = [signature];
|
||||
}
|
||||
else if (!compareSignatures(signatureList[0], signature, /*partialMatch*/ false, /*ignoreReturnTypes*/ true, compareTypes)) {
|
||||
else if (!compareSignaturesIdentical(signatureList[0], signature, /*partialMatch*/ false, /*ignoreReturnTypes*/ true, compareTypesIdentical)) {
|
||||
// Signatures aren't identical, do not use
|
||||
return undefined;
|
||||
}
|
||||
@@ -8035,7 +8079,6 @@ namespace ts {
|
||||
/// type or factory function.
|
||||
/// Otherwise, returns unknownSymbol.
|
||||
function getJsxElementTagSymbol(node: JsxOpeningLikeElement | JsxClosingElement): Symbol {
|
||||
const flags: JsxFlags = JsxFlags.UnknownElement;
|
||||
const links = getNodeLinks(node);
|
||||
if (!links.resolvedSymbol) {
|
||||
if (isJsxIntrinsicIdentifier(node.tagName)) {
|
||||
@@ -8234,9 +8277,9 @@ namespace ts {
|
||||
// Props is of type 'any' or unknown
|
||||
return links.resolvedJsxType = attributesType;
|
||||
}
|
||||
else if (!(attributesType.flags & TypeFlags.ObjectType)) {
|
||||
// Props is not an object type
|
||||
error(node.tagName, Diagnostics.JSX_element_attributes_type_0_must_be_an_object_type, typeToString(attributesType));
|
||||
else if (attributesType.flags & TypeFlags.Union) {
|
||||
// Props cannot be a union type
|
||||
error(node.tagName, Diagnostics.JSX_element_attributes_type_0_may_not_be_a_union_type, typeToString(attributesType));
|
||||
return links.resolvedJsxType = anyType;
|
||||
}
|
||||
else {
|
||||
@@ -11580,7 +11623,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
for (const otherSignature of signaturesToCheck) {
|
||||
if (!otherSignature.hasStringLiterals && isSignatureAssignableTo(signature, otherSignature)) {
|
||||
if (!otherSignature.hasStringLiterals && isSignatureAssignableTo(signature, otherSignature, /*ignoreReturnTypes*/ false)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -11827,7 +11870,7 @@ namespace ts {
|
||||
//
|
||||
// The implementation is completely unrelated to the specialized signature, yet we do not check this.
|
||||
for (const signature of signatures) {
|
||||
if (!signature.hasStringLiterals && !isSignatureAssignableTo(bodySignature, signature)) {
|
||||
if (!signature.hasStringLiterals && !isImplementationCompatibleWithOverload(bodySignature, signature)) {
|
||||
error(signature.declaration, Diagnostics.Overload_signature_is_not_compatible_with_function_implementation);
|
||||
break;
|
||||
}
|
||||
@@ -14308,16 +14351,6 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
|
||||
function getModuleStatements(node: Declaration): Statement[] {
|
||||
if (node.kind === SyntaxKind.SourceFile) {
|
||||
return (<SourceFile>node).statements;
|
||||
}
|
||||
if (node.kind === SyntaxKind.ModuleDeclaration && (<ModuleDeclaration>node).body.kind === SyntaxKind.ModuleBlock) {
|
||||
return (<ModuleBlock>(<ModuleDeclaration>node).body).statements;
|
||||
}
|
||||
return emptyArray;
|
||||
}
|
||||
|
||||
function hasExportedMembers(moduleSymbol: Symbol) {
|
||||
for (var id in moduleSymbol.exports) {
|
||||
if (id !== "export=") {
|
||||
@@ -15396,20 +15429,6 @@ namespace ts {
|
||||
return symbol && getExportSymbolOfValueSymbolIfExported(symbol).valueDeclaration;
|
||||
}
|
||||
|
||||
function instantiateSingleCallFunctionType(functionType: Type, typeArguments: Type[]): Type {
|
||||
if (functionType === unknownType) {
|
||||
return unknownType;
|
||||
}
|
||||
|
||||
const signature = getSingleCallSignature(functionType);
|
||||
if (!signature) {
|
||||
return unknownType;
|
||||
}
|
||||
|
||||
const instantiatedSignature = getSignatureInstantiation(signature, typeArguments);
|
||||
return getOrCreateTypeFromSignature(instantiatedSignature);
|
||||
}
|
||||
|
||||
function createResolver(): EmitResolver {
|
||||
return {
|
||||
getReferencedExportContainer,
|
||||
@@ -15544,7 +15563,12 @@ namespace ts {
|
||||
return false;
|
||||
}
|
||||
if (!nodeCanBeDecorated(node)) {
|
||||
return grammarErrorOnFirstToken(node, Diagnostics.Decorators_are_not_valid_here);
|
||||
if (node.kind === SyntaxKind.MethodDeclaration && !ts.nodeIsPresent((<MethodDeclaration>node).body)) {
|
||||
return grammarErrorOnFirstToken(node, Diagnostics.A_decorator_can_only_decorate_a_method_implementation_not_an_overload);
|
||||
}
|
||||
else {
|
||||
return grammarErrorOnFirstToken(node, Diagnostics.Decorators_are_not_valid_here);
|
||||
}
|
||||
}
|
||||
else if (node.kind === SyntaxKind.GetAccessor || node.kind === SyntaxKind.SetAccessor) {
|
||||
const accessors = getAllAccessorDeclarations((<ClassDeclaration>node.parent).members, <AccessorDeclaration>node);
|
||||
@@ -16458,25 +16482,6 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
|
||||
function isIntegerLiteral(expression: Expression): boolean {
|
||||
if (expression.kind === SyntaxKind.PrefixUnaryExpression) {
|
||||
const unaryExpression = <PrefixUnaryExpression>expression;
|
||||
if (unaryExpression.operator === SyntaxKind.PlusToken || unaryExpression.operator === SyntaxKind.MinusToken) {
|
||||
expression = unaryExpression.operand;
|
||||
}
|
||||
}
|
||||
if (expression.kind === SyntaxKind.NumericLiteral) {
|
||||
// Allows for scientific notation since literalExpression.text was formed by
|
||||
// coercing a number to a string. Sometimes this coercion can yield a string
|
||||
// in scientific notation.
|
||||
// We also don't need special logic for hex because a hex integer is converted
|
||||
// to decimal when it is coerced.
|
||||
return /^[0-9]+([eE]\+?[0-9]+)?$/.test((<LiteralExpression>expression).text);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function hasParseDiagnostics(sourceFile: SourceFile): boolean {
|
||||
return sourceFile.parseDiagnostics.length > 0;
|
||||
}
|
||||
@@ -16505,11 +16510,6 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
|
||||
function isEvalOrArgumentsIdentifier(node: Node): boolean {
|
||||
return node.kind === SyntaxKind.Identifier &&
|
||||
((<Identifier>node).text === "eval" || (<Identifier>node).text === "arguments");
|
||||
}
|
||||
|
||||
function checkGrammarConstructorTypeParameters(node: ConstructorDeclaration) {
|
||||
if (node.typeParameters) {
|
||||
return grammarErrorAtPos(getSourceFileOfNode(node), node.typeParameters.pos, node.typeParameters.end - node.typeParameters.pos, Diagnostics.Type_parameters_cannot_appear_on_a_constructor_declaration);
|
||||
|
||||
@@ -794,23 +794,6 @@ namespace ts {
|
||||
return path;
|
||||
}
|
||||
|
||||
const backslashOrDoubleQuote = /[\"\\]/g;
|
||||
const escapedCharsRegExp = /[\u0000-\u001f\t\v\f\b\r\n\u2028\u2029\u0085]/g;
|
||||
const escapedCharsMap: Map<string> = {
|
||||
"\0": "\\0",
|
||||
"\t": "\\t",
|
||||
"\v": "\\v",
|
||||
"\f": "\\f",
|
||||
"\b": "\\b",
|
||||
"\r": "\\r",
|
||||
"\n": "\\n",
|
||||
"\\": "\\\\",
|
||||
"\"": "\\\"",
|
||||
"\u2028": "\\u2028", // lineSeparator
|
||||
"\u2029": "\\u2029", // paragraphSeparator
|
||||
"\u0085": "\\u0085" // nextLine
|
||||
};
|
||||
|
||||
export interface ObjectAllocator {
|
||||
getNodeConstructor(): new (kind: SyntaxKind, pos?: number, end?: number) => Node;
|
||||
getSourceFileConstructor(): new (kind: SyntaxKind, pos?: number, end?: number) => SourceFile;
|
||||
|
||||
@@ -1534,14 +1534,6 @@ namespace ts {
|
||||
}
|
||||
|
||||
function emitBindingElement(bindingElement: BindingElement) {
|
||||
function getBindingElementTypeVisibilityError(symbolAccesibilityResult: SymbolAccessiblityResult): SymbolAccessibilityDiagnostic {
|
||||
const diagnosticMessage = getParameterDeclarationTypeVisibilityDiagnosticMessage(symbolAccesibilityResult);
|
||||
return diagnosticMessage !== undefined ? {
|
||||
diagnosticMessage,
|
||||
errorNode: bindingElement,
|
||||
typeName: bindingElement.name
|
||||
} : undefined;
|
||||
}
|
||||
|
||||
if (bindingElement.kind === SyntaxKind.OmittedExpression) {
|
||||
// If bindingElement is an omittedExpression (i.e. containing elision),
|
||||
|
||||
@@ -795,6 +795,10 @@
|
||||
"category": "Error",
|
||||
"code": 1248
|
||||
},
|
||||
"A decorator can only decorate a method implementation, not an overload.": {
|
||||
"category": "Error",
|
||||
"code": 1249
|
||||
},
|
||||
"'with' statements are not allowed in an async function block.": {
|
||||
"category": "Error",
|
||||
"code": 1300
|
||||
@@ -1691,7 +1695,7 @@
|
||||
"category": "Error",
|
||||
"code": 2528
|
||||
},
|
||||
"JSX element attributes type '{0}' must be an object type.": {
|
||||
"JSX element attributes type '{0}' may not be a union type.": {
|
||||
"category": "Error",
|
||||
"code": 2600
|
||||
},
|
||||
@@ -1759,6 +1763,14 @@
|
||||
"category": "Error",
|
||||
"code": 2658
|
||||
},
|
||||
"'super' is only allowed in members of object literal expressions when option 'target' is 'ES2015' or higher.": {
|
||||
"category": "Error",
|
||||
"code": 2659
|
||||
},
|
||||
"'super' can only be referenced in members of derived classes or object literal expressions.": {
|
||||
"category": "Error",
|
||||
"code": 2660
|
||||
},
|
||||
"Import declaration '{0}' is using private name '{1}'.": {
|
||||
"category": "Error",
|
||||
"code": 4000
|
||||
|
||||
@@ -781,12 +781,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
|
||||
}
|
||||
}
|
||||
|
||||
function emitTrailingCommaIfPresent(nodeList: NodeArray<Node>): void {
|
||||
if (nodeList.hasTrailingComma) {
|
||||
write(",");
|
||||
}
|
||||
}
|
||||
|
||||
function emitLinePreservingList(parent: Node, nodes: NodeArray<Node>, allowTrailingComma: boolean, spacesBetweenBraces: boolean) {
|
||||
Debug.assert(nodes.length > 0);
|
||||
|
||||
@@ -2452,7 +2446,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
|
||||
}
|
||||
|
||||
function emitPrefixUnaryExpression(node: PrefixUnaryExpression) {
|
||||
const exportChanged = isNameOfExportedSourceLevelDeclarationInSystemExternalModule(node.operand);
|
||||
const exportChanged = (node.operator === SyntaxKind.PlusPlusToken || node.operator === SyntaxKind.MinusMinusToken) &&
|
||||
isNameOfExportedSourceLevelDeclarationInSystemExternalModule(node.operand);
|
||||
|
||||
if (exportChanged) {
|
||||
// emit
|
||||
@@ -3238,10 +3233,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
|
||||
}
|
||||
}
|
||||
|
||||
function emitDownLevelForOfStatement(node: ForOfStatement) {
|
||||
emitLoop(node, emitDownLevelForOfStatementWorker);
|
||||
}
|
||||
|
||||
function emitDownLevelForOfStatementWorker(node: ForOfStatement, loop: ConvertedLoop) {
|
||||
// The following ES6 code:
|
||||
//
|
||||
@@ -4310,22 +4301,29 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
|
||||
|
||||
// TODO (yuisu) : we should not have special cases to condition emitting comments
|
||||
// but have one place to fix check for these conditions.
|
||||
if (node.kind !== SyntaxKind.MethodDeclaration && node.kind !== SyntaxKind.MethodSignature &&
|
||||
node.parent && node.parent.kind !== SyntaxKind.PropertyAssignment &&
|
||||
node.parent.kind !== SyntaxKind.CallExpression) {
|
||||
// 1. Methods will emit the comments as part of emitting method declaration
|
||||
|
||||
const { kind, parent } = node;
|
||||
if (kind !== SyntaxKind.MethodDeclaration &&
|
||||
kind !== SyntaxKind.MethodSignature &&
|
||||
parent &&
|
||||
parent.kind !== SyntaxKind.PropertyAssignment &&
|
||||
parent.kind !== SyntaxKind.CallExpression &&
|
||||
parent.kind !== SyntaxKind.ArrayLiteralExpression) {
|
||||
// 1. Methods will emit comments at their assignment declaration sites.
|
||||
//
|
||||
// 2. If the function is a property of object literal, emitting leading-comments
|
||||
// is done by emitNodeWithoutSourceMap which then call this function.
|
||||
// In particular, we would like to avoid emit comments twice in following case:
|
||||
// For example:
|
||||
// is done by emitNodeWithoutSourceMap which then call this function.
|
||||
// In particular, we would like to avoid emit comments twice in following case:
|
||||
//
|
||||
// var obj = {
|
||||
// id:
|
||||
// /*comment*/ () => void
|
||||
// }
|
||||
|
||||
//
|
||||
// 3. If the function is an argument in call expression, emitting of comments will be
|
||||
// taken care of in emit list of arguments inside of emitCallexpression
|
||||
// taken care of in emit list of arguments inside of 'emitCallExpression'.
|
||||
//
|
||||
// 4. If the function is in an array literal, 'emitLinePreservingList' will take care
|
||||
// of leading comments.
|
||||
emitLeadingComments(node);
|
||||
}
|
||||
|
||||
@@ -4352,12 +4350,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
|
||||
}
|
||||
|
||||
emitSignatureAndBody(node);
|
||||
if (modulekind !== ModuleKind.ES6 && node.kind === SyntaxKind.FunctionDeclaration && node.parent === currentSourceFile && node.name) {
|
||||
if (modulekind !== ModuleKind.ES6 && kind === SyntaxKind.FunctionDeclaration && parent === currentSourceFile && node.name) {
|
||||
emitExportMemberAssignments((<FunctionDeclaration>node).name);
|
||||
}
|
||||
|
||||
emitEnd(node);
|
||||
if (node.kind !== SyntaxKind.MethodDeclaration && node.kind !== SyntaxKind.MethodSignature) {
|
||||
if (kind !== SyntaxKind.MethodDeclaration && kind !== SyntaxKind.MethodSignature) {
|
||||
emitTrailingComments(node);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -771,10 +771,6 @@ namespace ts {
|
||||
return doInsideOfContext(ParserContextFlags.Yield, func);
|
||||
}
|
||||
|
||||
function doOutsideOfYieldContext<T>(func: () => T): T {
|
||||
return doOutsideOfContext(ParserContextFlags.Yield, func);
|
||||
}
|
||||
|
||||
function doInDecoratorContext<T>(func: () => T): T {
|
||||
return doInsideOfContext(ParserContextFlags.Decorator, func);
|
||||
}
|
||||
@@ -791,10 +787,6 @@ namespace ts {
|
||||
return doInsideOfContext(ParserContextFlags.Yield | ParserContextFlags.Await, func);
|
||||
}
|
||||
|
||||
function doOutsideOfYieldAndAwaitContext<T>(func: () => T): T {
|
||||
return doOutsideOfContext(ParserContextFlags.Yield | ParserContextFlags.Await, func);
|
||||
}
|
||||
|
||||
function inContext(flags: ParserContextFlags) {
|
||||
return (contextFlags & flags) !== 0;
|
||||
}
|
||||
@@ -851,10 +843,6 @@ namespace ts {
|
||||
return token = scanner.scan();
|
||||
}
|
||||
|
||||
function getTokenPos(pos: number): number {
|
||||
return skipTrivia(sourceText, pos);
|
||||
}
|
||||
|
||||
function reScanGreaterToken(): SyntaxKind {
|
||||
return token = scanner.reScanGreaterToken();
|
||||
}
|
||||
@@ -2644,10 +2632,6 @@ namespace ts {
|
||||
isStartOfExpression();
|
||||
}
|
||||
|
||||
function allowInAndParseExpression(): Expression {
|
||||
return allowInAnd(parseExpression);
|
||||
}
|
||||
|
||||
function parseExpression(): Expression {
|
||||
// Expression[in]:
|
||||
// AssignmentExpression[in]
|
||||
@@ -3962,7 +3946,6 @@ namespace ts {
|
||||
|
||||
const asteriskToken = parseOptionalToken(SyntaxKind.AsteriskToken);
|
||||
const tokenIsIdentifier = isIdentifier();
|
||||
const nameToken = token;
|
||||
const propertyName = parsePropertyName();
|
||||
|
||||
// Disallowing of optional property assignments happens in the grammar checker.
|
||||
@@ -5104,10 +5087,6 @@ namespace ts {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
function parseHeritageClausesWorker() {
|
||||
return parseList(ParsingContext.HeritageClauses, parseHeritageClause);
|
||||
}
|
||||
|
||||
function parseHeritageClause() {
|
||||
if (token === SyntaxKind.ExtendsKeyword || token === SyntaxKind.ImplementsKeyword) {
|
||||
const node = <HeritageClause>createNode(SyntaxKind.HeritageClause);
|
||||
@@ -5253,12 +5232,6 @@ namespace ts {
|
||||
return nextToken() === SyntaxKind.SlashToken;
|
||||
}
|
||||
|
||||
function nextTokenIsCommaOrFromKeyword() {
|
||||
nextToken();
|
||||
return token === SyntaxKind.CommaToken ||
|
||||
token === SyntaxKind.FromKeyword;
|
||||
}
|
||||
|
||||
function parseImportDeclarationOrImportEqualsDeclaration(fullStart: number, decorators: NodeArray<Decorator>, modifiers: ModifiersArray): ImportEqualsDeclaration | ImportDeclaration {
|
||||
parseExpected(SyntaxKind.ImportKeyword);
|
||||
const afterImportPos = scanner.getStartPos();
|
||||
@@ -5751,13 +5724,6 @@ namespace ts {
|
||||
return finishNode(parameter);
|
||||
}
|
||||
|
||||
function parseJSDocOptionalType(type: JSDocType): JSDocOptionalType {
|
||||
const result = <JSDocOptionalType>createNode(SyntaxKind.JSDocOptionalType, type.pos);
|
||||
nextToken();
|
||||
result.type = type;
|
||||
return finishNode(result);
|
||||
}
|
||||
|
||||
function parseJSDocTypeReference(): JSDocTypeReference {
|
||||
const result = <JSDocTypeReference>createNode(SyntaxKind.JSDocTypeReference);
|
||||
result.name = parseSimplePropertyName();
|
||||
|
||||
@@ -573,8 +573,11 @@ namespace ts {
|
||||
// If the noEmitOnError flag is set, then check if we have any errors so far. If so,
|
||||
// immediately bail out. Note that we pass 'undefined' for 'sourceFile' so that we
|
||||
// get any preEmit diagnostics, not just the ones
|
||||
if (options.noEmitOnError && getPreEmitDiagnostics(program, /*sourceFile:*/ undefined, cancellationToken).length > 0) {
|
||||
return { diagnostics: [], sourceMaps: undefined, emitSkipped: true };
|
||||
if (options.noEmitOnError) {
|
||||
const preEmitDiagnostics = getPreEmitDiagnostics(program, /*sourceFile:*/ undefined, cancellationToken);
|
||||
if (preEmitDiagnostics.length > 0) {
|
||||
return { diagnostics: preEmitDiagnostics, sourceMaps: undefined, emitSkipped: true };
|
||||
}
|
||||
}
|
||||
|
||||
// Create the emit resolver outside of the "emitTime" tracking code below. That way
|
||||
|
||||
@@ -15,7 +15,6 @@ namespace ts {
|
||||
reset(): void;
|
||||
}
|
||||
|
||||
const nop = <(...args: any[]) => any>Function.prototype;
|
||||
let nullSourceMapWriter: SourceMapWriter;
|
||||
|
||||
export function getNullSourceMapWriter(): SourceMapWriter {
|
||||
|
||||
@@ -218,7 +218,6 @@ namespace ts {
|
||||
const _fs = require("fs");
|
||||
const _path = require("path");
|
||||
const _os = require("os");
|
||||
const _tty = require("tty");
|
||||
|
||||
// average async stat takes about 30 microseconds
|
||||
// set chunk size to do 30 files in < 1 millisecond
|
||||
@@ -313,10 +312,6 @@ namespace ts {
|
||||
// time dynamically to match the large reference set?
|
||||
const watchedFileSet = createWatchedFileSet();
|
||||
|
||||
function isNode4OrLater(): Boolean {
|
||||
return parseInt(process.version.charAt(1)) >= 4;
|
||||
}
|
||||
|
||||
const platform: string = _os.platform();
|
||||
// win32\win64 are case insensitive platforms, MacOS (darwin) by default is also case insensitive
|
||||
const useCaseSensitiveFileNames = platform !== "win32" && platform !== "win64" && platform !== "darwin";
|
||||
|
||||
@@ -1195,7 +1195,7 @@ namespace ts {
|
||||
|
||||
// @kind(SyntaxKind.CaseClause)
|
||||
export interface CaseClause extends Node {
|
||||
expression?: Expression;
|
||||
expression: Expression;
|
||||
statements: NodeArray<Statement>;
|
||||
}
|
||||
|
||||
@@ -1723,6 +1723,7 @@ namespace ts {
|
||||
|
||||
getSymbolsInScope(location: Node, meaning: SymbolFlags): Symbol[];
|
||||
getSymbolAtLocation(node: Node): Symbol;
|
||||
getSymbolsOfParameterPropertyDeclaration(parameter: ParameterDeclaration, parameterName: string): Symbol[];
|
||||
getShorthandAssignmentValueSymbol(location: Node): Symbol;
|
||||
getTypeAtLocation(node: Node): Type;
|
||||
typeToString(type: Type, enclosingDeclaration?: Node, flags?: TypeFormatFlags): string;
|
||||
|
||||
@@ -775,26 +775,38 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
|
||||
export function getSuperContainer(node: Node, includeFunctions: boolean): Node {
|
||||
/**
|
||||
* Given an super call\property node returns a closest node where either
|
||||
* - super call\property is legal in the node and not legal in the parent node the node.
|
||||
* i.e. super call is legal in constructor but not legal in the class body.
|
||||
* - node is arrow function (so caller might need to call getSuperContainer in case if he needs to climb higher)
|
||||
* - super call\property is definitely illegal in the node (but might be legal in some subnode)
|
||||
* i.e. super property access is illegal in function declaration but can be legal in the statement list
|
||||
*/
|
||||
export function getSuperContainer(node: Node, stopOnFunctions: boolean): Node {
|
||||
while (true) {
|
||||
node = node.parent;
|
||||
if (!node) return node;
|
||||
if (!node) {
|
||||
return node;
|
||||
}
|
||||
switch (node.kind) {
|
||||
case SyntaxKind.ComputedPropertyName:
|
||||
// If the grandparent node is an object literal (as opposed to a class),
|
||||
// then the computed property is not a 'super' container.
|
||||
// A computed property name in a class needs to be a super container
|
||||
// so that we can error on it.
|
||||
if (isClassLike(node.parent.parent)) {
|
||||
return node;
|
||||
}
|
||||
// If this is a computed property, then the parent should not
|
||||
// make it a super container. The parent might be a property
|
||||
// in an object literal, like a method or accessor. But in order for
|
||||
// such a parent to be a super container, the reference must be in
|
||||
// the *body* of the container.
|
||||
node = node.parent;
|
||||
break;
|
||||
case SyntaxKind.FunctionDeclaration:
|
||||
case SyntaxKind.FunctionExpression:
|
||||
case SyntaxKind.ArrowFunction:
|
||||
if (!stopOnFunctions) {
|
||||
continue;
|
||||
}
|
||||
case SyntaxKind.PropertyDeclaration:
|
||||
case SyntaxKind.PropertySignature:
|
||||
case SyntaxKind.MethodDeclaration:
|
||||
case SyntaxKind.MethodSignature:
|
||||
case SyntaxKind.Constructor:
|
||||
case SyntaxKind.GetAccessor:
|
||||
case SyntaxKind.SetAccessor:
|
||||
return node;
|
||||
case SyntaxKind.Decorator:
|
||||
// Decorators are always applied outside of the body of a class or method.
|
||||
if (node.parent.kind === SyntaxKind.Parameter && isClassElement(node.parent.parent)) {
|
||||
@@ -808,20 +820,6 @@ namespace ts {
|
||||
node = node.parent;
|
||||
}
|
||||
break;
|
||||
case SyntaxKind.FunctionDeclaration:
|
||||
case SyntaxKind.FunctionExpression:
|
||||
case SyntaxKind.ArrowFunction:
|
||||
if (!includeFunctions) {
|
||||
continue;
|
||||
}
|
||||
case SyntaxKind.PropertyDeclaration:
|
||||
case SyntaxKind.PropertySignature:
|
||||
case SyntaxKind.MethodDeclaration:
|
||||
case SyntaxKind.MethodSignature:
|
||||
case SyntaxKind.Constructor:
|
||||
case SyntaxKind.GetAccessor:
|
||||
case SyntaxKind.SetAccessor:
|
||||
return node;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2748,4 +2746,8 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function isParameterPropertyDeclaration(node: ParameterDeclaration): boolean {
|
||||
return node.flags & NodeFlags.AccessibilityModifier && node.parent.kind === SyntaxKind.Constructor && isClassLike(node.parent.parent);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user