mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-17 01:49:57 -05:00
Merge pull request #25190 from mprobst/fix-generic-type-emit
Fix decorator design:types emit for type variables.
This commit is contained in:
@@ -61,7 +61,8 @@ namespace ts {
|
||||
let currentSourceFile: SourceFile;
|
||||
let currentNamespace: ModuleDeclaration;
|
||||
let currentNamespaceContainerName: Identifier;
|
||||
let currentScope: SourceFile | Block | ModuleBlock | CaseBlock;
|
||||
let currentLexicalScope: SourceFile | Block | ModuleBlock | CaseBlock;
|
||||
let currentNameScope: ClassDeclaration | undefined;
|
||||
let currentScopeFirstDeclarationsOfName: UnderscoreEscapedMap<Node> | undefined;
|
||||
|
||||
/**
|
||||
@@ -132,7 +133,8 @@ namespace ts {
|
||||
*/
|
||||
function saveStateAndInvoke<T>(node: Node, f: (node: Node) => T): T {
|
||||
// Save state
|
||||
const savedCurrentScope = currentScope;
|
||||
const savedCurrentScope = currentLexicalScope;
|
||||
const savedCurrentNameScope = currentNameScope;
|
||||
const savedCurrentScopeFirstDeclarationsOfName = currentScopeFirstDeclarationsOfName;
|
||||
|
||||
// Handle state changes before visiting a node.
|
||||
@@ -141,11 +143,12 @@ namespace ts {
|
||||
const visited = f(node);
|
||||
|
||||
// Restore state
|
||||
if (currentScope !== savedCurrentScope) {
|
||||
if (currentLexicalScope !== savedCurrentScope) {
|
||||
currentScopeFirstDeclarationsOfName = savedCurrentScopeFirstDeclarationsOfName;
|
||||
}
|
||||
|
||||
currentScope = savedCurrentScope;
|
||||
currentLexicalScope = savedCurrentScope;
|
||||
currentNameScope = savedCurrentNameScope;
|
||||
return visited;
|
||||
}
|
||||
|
||||
@@ -160,7 +163,8 @@ namespace ts {
|
||||
case SyntaxKind.CaseBlock:
|
||||
case SyntaxKind.ModuleBlock:
|
||||
case SyntaxKind.Block:
|
||||
currentScope = <SourceFile | CaseBlock | ModuleBlock | Block>node;
|
||||
currentLexicalScope = <SourceFile | CaseBlock | ModuleBlock | Block>node;
|
||||
currentNameScope = undefined;
|
||||
currentScopeFirstDeclarationsOfName = undefined;
|
||||
break;
|
||||
|
||||
@@ -180,6 +184,10 @@ namespace ts {
|
||||
// programs may also have an undefined name.
|
||||
Debug.assert(node.kind === SyntaxKind.ClassDeclaration || hasModifier(node, ModifierFlags.Default));
|
||||
}
|
||||
if (isClassDeclaration(node)) {
|
||||
// XXX: should probably also cover interfaces and type aliases that can have type variables?
|
||||
currentNameScope = node;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
@@ -1971,7 +1979,7 @@ namespace ts {
|
||||
* @param node The type reference node.
|
||||
*/
|
||||
function serializeTypeReferenceNode(node: TypeReferenceNode): SerializedTypeNode {
|
||||
const kind = resolver.getTypeReferenceSerializationKind(node.typeName, currentScope);
|
||||
const kind = resolver.getTypeReferenceSerializationKind(node.typeName, currentNameScope || currentLexicalScope);
|
||||
switch (kind) {
|
||||
case TypeReferenceSerializationKind.Unknown:
|
||||
const serialized = serializeEntityNameAsExpression(node.typeName, /*useFallback*/ true);
|
||||
@@ -2035,7 +2043,7 @@ namespace ts {
|
||||
const name = getMutableClone(node);
|
||||
name.flags &= ~NodeFlags.Synthesized;
|
||||
name.original = undefined;
|
||||
name.parent = getParseTreeNode(currentScope); // ensure the parent is set to a parse tree node.
|
||||
name.parent = getParseTreeNode(currentLexicalScope); // ensure the parent is set to a parse tree node.
|
||||
if (useFallback) {
|
||||
return createLogicalAnd(
|
||||
createStrictInequality(
|
||||
@@ -2622,7 +2630,7 @@ namespace ts {
|
||||
// enum body.
|
||||
if (addVarForEnumOrModuleDeclaration(statements, node)) {
|
||||
// We should still emit the comments if we are emitting a system module.
|
||||
if (moduleKind !== ModuleKind.System || currentScope !== currentSourceFile) {
|
||||
if (moduleKind !== ModuleKind.System || currentLexicalScope !== currentSourceFile) {
|
||||
emitFlags |= EmitFlags.NoLeadingComments;
|
||||
}
|
||||
}
|
||||
@@ -2835,7 +2843,7 @@ namespace ts {
|
||||
createVariableDeclaration(
|
||||
getLocalName(node, /*allowComments*/ false, /*allowSourceMaps*/ true)
|
||||
)
|
||||
], currentScope.kind === SyntaxKind.SourceFile ? NodeFlags.None : NodeFlags.Let)
|
||||
], currentLexicalScope.kind === SyntaxKind.SourceFile ? NodeFlags.None : NodeFlags.Let)
|
||||
);
|
||||
|
||||
setOriginalNode(statement, node);
|
||||
@@ -2911,7 +2919,7 @@ namespace ts {
|
||||
// module body.
|
||||
if (addVarForEnumOrModuleDeclaration(statements, node)) {
|
||||
// We should still emit the comments if we are emitting a system module.
|
||||
if (moduleKind !== ModuleKind.System || currentScope !== currentSourceFile) {
|
||||
if (moduleKind !== ModuleKind.System || currentLexicalScope !== currentSourceFile) {
|
||||
emitFlags |= EmitFlags.NoLeadingComments;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user