Add SymbolFlag for containers of JS special decls

And update some doc comments
This commit is contained in:
Nathan Shively-Sanders 2017-11-30 10:27:38 -08:00
parent 098a05268a
commit 665c2ecf91
3 changed files with 13 additions and 10 deletions

View file

@ -2355,7 +2355,7 @@ namespace ts {
}
function bindPrototypePropertyAssignment(node: BinaryExpression) {
// We saw a node of the form 'x.prototype.y = z'. Declare a 'member' y on x if x was a function.
// We saw a node of the form 'x.prototype.y = z'. Declare a 'member' y on x if x is a function or class, or not declared.
// Look up the function in the local scope, since prototype assignments should
// follow the function declaration
@ -2372,7 +2372,7 @@ namespace ts {
}
/**
* For nodes like `x.y = z`, declare a member 'y' on 'x' if x was a function.
* For nodes like `x.y = z`, declare a member 'y' on 'x' if x is a function or class, or not declared.
* Also works for expression statements preceded by JSDoc, like / ** @type number * / x.y;
*/
function bindStaticPropertyAssignment(node: BinaryExpression | PropertyAccessExpression) {
@ -2427,9 +2427,11 @@ namespace ts {
const identifier = propertyAccess.expression as Identifier;
if (targetSymbol) {
addDeclarationToSymbol(symbol, identifier, SymbolFlags.Module);
symbol.flags |= SymbolFlags.JSContainer;
}
else {
targetSymbol = declareSymbol(container.locals, /*parent*/ undefined, identifier, SymbolFlags.Module, SymbolFlags.ValueModuleExcludes);
targetSymbol.flags |= SymbolFlags.JSContainer;
}
}
if (!targetSymbol || !(targetSymbol.flags & (SymbolFlags.Function | SymbolFlags.Class | SymbolFlags.NamespaceModule))) {

View file

@ -633,8 +633,7 @@ namespace ts {
function mergeSymbol(target: Symbol, source: Symbol) {
if (!(target.flags & getExcludedSymbolFlags(source.flags)) ||
source.valueDeclaration && source.valueDeclaration.kind === SyntaxKind.Identifier ||
target.valueDeclaration && target.valueDeclaration.kind === SyntaxKind.Identifier) {
source.flags & SymbolFlags.JSContainer || target.flags & SymbolFlags.JSContainer) {
// Javascript static-property-assignment declarations always merge, even though they are also values
if (source.flags & SymbolFlags.ValueModule && target.flags & SymbolFlags.ValueModule && target.constEnumOnlyModule && !source.constEnumOnlyModule) {
// reset flag when merging instantiated module into value module that has only const enums
@ -4480,7 +4479,9 @@ namespace ts {
if (!jsDocType) {
jsDocType = declarationType;
}
else if (jsDocType !== unknownType && declarationType !== unknownType && !isTypeIdenticalTo(jsDocType, declarationType)) {
else if (jsDocType !== unknownType && declarationType !== unknownType &&
!isTypeIdenticalTo(jsDocType, declarationType) &&
!(symbol.flags & SymbolFlags.JSContainer)) {
errorNextVariableOrPropertyDeclarationMustHaveSameType(symbol.valueDeclaration, jsDocType, declaration, declarationType);
}
}
@ -21435,7 +21436,10 @@ namespace ts {
// Node is a secondary declaration, check that type is identical to primary declaration and check that
// initializer is consistent with type associated with the node
const declarationType = convertAutoToAny(getWidenedTypeForVariableLikeDeclaration(node));
if (type !== unknownType && declarationType !== unknownType && !isTypeIdenticalTo(type, declarationType)) {
if (type !== unknownType && declarationType !== unknownType &&
!isTypeIdenticalTo(type, declarationType) &&
!(symbol.flags & SymbolFlags.JSContainer)) {
errorNextVariableOrPropertyDeclarationMustHaveSameType(symbol.valueDeclaration, type, node, declarationType);
}
if (node.initializer) {
@ -21461,10 +21465,6 @@ namespace ts {
}
function errorNextVariableOrPropertyDeclarationMustHaveSameType(firstDeclaration: Declaration, firstType: Type, nextDeclaration: Declaration, nextType: Type): void {
if (isIdentifier(firstDeclaration) || isIdentifier(nextDeclaration)) {
// js static assignment declarations don't have a type, so don't have to be consistent
return;
}
const firstSourceFile = getSourceFileOfNode(firstDeclaration);
const firstSpan = getErrorSpanForNode(firstSourceFile, getNameOfDeclaration(firstDeclaration) || firstDeclaration);
const firstLocation = getLineAndCharacterOfPosition(firstSourceFile, firstSpan.start);

View file

@ -3059,6 +3059,7 @@ namespace ts {
ExportStar = 1 << 23, // Export * declaration
Optional = 1 << 24, // Optional property
Transient = 1 << 25, // Transient symbol (created during type check)
JSContainer = 1 << 26, // Contains Javascript special declarations
/* @internal */
All = FunctionScopedVariable | BlockScopedVariable | Property | EnumMember | Function | Class | Interface | ConstEnum | RegularEnum | ValueModule | NamespaceModule | TypeLiteral