| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3060,7 +3060,7 @@ namespace ts { | |||
| 3060 | 3060 | flags, | |
| 3061 | 3061 | tracker: tracker && tracker.trackSymbol ? tracker : { trackSymbol: noop }, | |
| 3062 | 3062 | encounteredError: false, | |
| 3063 | - symbolStack: undefined, | ||
| 3063 | + visitedSymbols: undefined, | ||
| 3064 | 3064 | inferTypeParameters: undefined | |
| 3065 | 3065 | }; | |
| 3066 | 3066 | } | |
@@ -3242,7 +3242,10 @@ namespace ts { | |||
| 3242 | 3242 | ||
| 3243 | 3243 | function createAnonymousTypeNode(type: ObjectType): TypeNode { | |
| 3244 | 3244 | const symbol = type.symbol; | |
| 3245 | + let id: string; | ||
| 3245 | 3246 | if (symbol) { | |
| 3247 | + const isConstructorObject = getObjectFlags(type) & ObjectFlags.Anonymous && type.symbol && type.symbol.flags & SymbolFlags.Class; | ||
| 3248 | + id = (isConstructorObject ? "+" : "") + getSymbolId(symbol); | ||
| 3246 | 3249 | if (isJavaScriptConstructor(symbol.valueDeclaration)) { | |
| 3247 | 3250 | // Instance and static types share the same symbol; only add 'typeof' for the static side. | |
| 3248 | 3251 | const isInstanceType = type === getInferredClassType(symbol) ? SymbolFlags.Type : SymbolFlags.Value; | |
@@ -3254,7 +3257,7 @@ namespace ts { | |||
| 3254 | 3257 | shouldWriteTypeOfFunctionSymbol()) { | |
| 3255 | 3258 | return symbolToTypeNode(symbol, context, SymbolFlags.Value); | |
| 3256 | 3259 | } | |
| 3257 | - else if (contains(context.symbolStack, symbol)) { | ||
| 3260 | + else if (context.visitedSymbols && context.visitedSymbols.has(id)) { | ||
| 3258 | 3261 | // If type is an anonymous type literal in a type alias declaration, use type alias name | |
| 3259 | 3262 | const typeAlias = getTypeAliasForTypeLiteral(type); | |
| 3260 | 3263 | if (typeAlias) { | |
@@ -3268,20 +3271,14 @@ namespace ts { | |||
| 3268 | 3271 | else { | |
| 3269 | 3272 | // Since instantiations of the same anonymous type have the same symbol, tracking symbols instead | |
| 3270 | 3273 | // of types allows us to catch circular references to instantiations of the same anonymous type | |
| 3271 | - if (!context.symbolStack) { | ||
| 3272 | - context.symbolStack = []; | ||
| 3274 | + if (!context.visitedSymbols) { | ||
| 3275 | + context.visitedSymbols = createMap<true>(); | ||
| 3273 | 3276 | } | |
| 3274 | 3277 | ||
| 3275 | - const isConstructorObject = getObjectFlags(type) & ObjectFlags.Anonymous && type.symbol && type.symbol.flags & SymbolFlags.Class; | ||
| 3276 | - if (isConstructorObject) { | ||
| 3277 | - return createTypeNodeFromObjectType(type); | ||
| 3278 | - } | ||
| 3279 | - else { | ||
| 3280 | - context.symbolStack.push(symbol); | ||
| 3281 | - const result = createTypeNodeFromObjectType(type); | ||
| 3282 | - context.symbolStack.pop(); | ||
| 3283 | - return result; | ||
| 3284 | - } | ||
| 3278 | + context.visitedSymbols.set(id, true); | ||
| 3279 | + const result = createTypeNodeFromObjectType(type); | ||
| 3280 | + context.visitedSymbols.delete(id); | ||
| 3281 | + return result; | ||
| 3285 | 3282 | } | |
| 3286 | 3283 | } | |
| 3287 | 3284 | else { | |
@@ -3298,7 +3295,7 @@ namespace ts { | |||
| 3298 | 3295 | declaration.parent.kind === SyntaxKind.SourceFile || declaration.parent.kind === SyntaxKind.ModuleBlock)); | |
| 3299 | 3296 | if (isStaticMethodSymbol || isNonLocalFunctionSymbol) { | |
| 3300 | 3297 | // typeof is allowed only for static/non local functions | |
| 3301 | - return (!!(context.flags & NodeBuilderFlags.UseTypeOfFunction) || contains(context.symbolStack, symbol)) && // it is type of the symbol uses itself recursively | ||
| 3298 | + return (!!(context.flags & NodeBuilderFlags.UseTypeOfFunction) || (context.visitedSymbols && context.visitedSymbols.has(id))) && // it is type of the symbol uses itself recursively | ||
| 3302 | 3299 | (!(context.flags & NodeBuilderFlags.UseStructuralFallback) || isValueSymbolAccessible(symbol, context.enclosingDeclaration)); // And the build is going to succeed without visibility error or there is no structural fallback allowed | |
| 3303 | 3300 | } | |
| 3304 | 3301 | } | |
@@ -3997,7 +3994,7 @@ namespace ts { | |||
| 3997 | 3994 | ||
| 3998 | 3995 | // State | |
| 3999 | 3996 | encounteredError: boolean; | |
| 4000 | - symbolStack: Symbol[] | undefined; | ||
| 3997 | + visitedSymbols: Map<true> | undefined; | ||
| 4001 | 3998 | inferTypeParameters: TypeParameter[] | undefined; | |
| 4002 | 3999 | } | |
| 4003 | 4000 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,37 @@ | |||
| 1 | + //// [classExpressionInClassStaticDeclarations.ts] | ||
| 2 | + class C { | ||
| 3 | + static D = class extends C {}; | ||
| 4 | + } | ||
| 5 | + | ||
| 6 | + //// [classExpressionInClassStaticDeclarations.js] | ||
| 7 | + var __extends = (this && this.__extends) || (function () { | ||
| 8 | + var extendStatics = Object.setPrototypeOf || | ||
| 9 | + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
| 10 | + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; | ||
| 11 | + return function (d, b) { | ||
| 12 | + extendStatics(d, b); | ||
| 13 | + function __() { this.constructor = d; } | ||
| 14 | + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
| 15 | + }; | ||
| 16 | + })(); | ||
| 17 | + var C = /** @class */ (function () { | ||
| 18 | + function C() { | ||
| 19 | + } | ||
| 20 | + C.D = /** @class */ (function (_super) { | ||
| 21 | + __extends(class_1, _super); | ||
| 22 | + function class_1() { | ||
| 23 | + return _super !== null && _super.apply(this, arguments) || this; | ||
| 24 | + } | ||
| 25 | + return class_1; | ||
| 26 | + }(C)); | ||
| 27 | + return C; | ||
| 28 | + }()); | ||
| 29 | + | ||
| 30 | + | ||
| 31 | + //// [classExpressionInClassStaticDeclarations.d.ts] | ||
| 32 | + declare class C { | ||
| 33 | + static D: { | ||
| 34 | + new (): {}; | ||
| 35 | + D: any; | ||
| 36 | + }; | ||
| 37 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,8 @@ | |||
| 1 | + === tests/cases/compiler/classExpressionInClassStaticDeclarations.ts === | ||
| 2 | + class C { | ||
| 3 | + >C : Symbol(C, Decl(classExpressionInClassStaticDeclarations.ts, 0, 0)) | ||
| 4 | + | ||
| 5 | + static D = class extends C {}; | ||
| 6 | + >D : Symbol(C.D, Decl(classExpressionInClassStaticDeclarations.ts, 0, 9)) | ||
| 7 | + >C : Symbol(C, Decl(classExpressionInClassStaticDeclarations.ts, 0, 0)) | ||
| 8 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,9 @@ | |||
| 1 | + === tests/cases/compiler/classExpressionInClassStaticDeclarations.ts === | ||
| 2 | + class C { | ||
| 3 | + >C : C | ||
| 4 | + | ||
| 5 | + static D = class extends C {}; | ||
| 6 | + >D : typeof (Anonymous class) | ||
| 7 | + >class extends C {} : typeof (Anonymous class) | ||
| 8 | + >C : C | ||
| 9 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,4 @@ | |||
| 1 | + // @declaration: true | ||
| 2 | + class C { | ||
| 3 | + static D = class extends C {}; | ||
| 4 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments