@@ -864,6 +864,7 @@ type Checker struct {
864864 couldContainTypeVariables func(*Type) bool
865865 isStringIndexSignatureOnlyType func(*Type) bool
866866 markNodeAssignments func(*ast.Node) bool
867+ compareTypesAssignable TypeComparer
867868 emitResolver *EmitResolver
868869 emitResolverOnce sync.Once
869870 _jsxNamespace string
@@ -897,7 +898,7 @@ func NewChecker(program Program) (*Checker, *sync.Mutex) {
897898 c.moduleKind = c.compilerOptions.GetEmitModuleKind()
898899 c.moduleResolutionKind = c.compilerOptions.GetModuleResolutionKind()
899900 c.legacyDecorators = c.compilerOptions.ExperimentalDecorators == core.TSTrue
900- c.emitStandardClassFields = ! c.compilerOptions.UseDefineForClassFields.IsFalse() && c.compilerOptions.GetEmitScriptTarget() >= core.ScriptTargetES2022
901+ c.emitStandardClassFields = c.compilerOptions.GetEmitStandardClassFields()
901902 c.strictNullChecks = c.compilerOptions.GetStrictOptionValue(c.compilerOptions.StrictNullChecks)
902903 c.strictFunctionTypes = c.compilerOptions.GetStrictOptionValue(c.compilerOptions.StrictFunctionTypes)
903904 c.strictBindCallApply = c.compilerOptions.GetStrictOptionValue(c.compilerOptions.StrictBindCallApply)
@@ -1234,6 +1235,7 @@ func (c *Checker) initializeClosures() {
12341235 c.couldContainTypeVariables = c.couldContainTypeVariablesWorker
12351236 c.isStringIndexSignatureOnlyType = c.isStringIndexSignatureOnlyTypeWorker
12361237 c.markNodeAssignments = c.markNodeAssignmentsWorker
1238+ c.compareTypesAssignable = c.compareTypesAssignableWorker
12371239}
12381240
12391241func (c *Checker) initializeIterationResolvers() {
@@ -4482,7 +4484,7 @@ basePropertyCheck:
44824484 diagnostics.X_0_is_defined_as_an_accessor_in_class_1_but_is_overridden_here_in_2_as_an_instance_property,
44834485 diagnostics.X_0_is_defined_as_a_property_in_class_1_but_is_overridden_here_in_2_as_an_accessor)
44844486 c.error(core.OrElse(ast.GetNameOfDeclaration(derived.ValueDeclaration), derived.ValueDeclaration), errorMessage, c.symbolToString(base), c.TypeToString(baseType), c.TypeToString(t))
4485- } else if c.compilerOptions.UseDefineForClassFields.IsTrue () {
4487+ } else if c.compilerOptions.GetUseDefineForClassFields () {
44864488 uninitialized := core.Find(derived.Declarations, func(d *ast.Node) bool {
44874489 return ast.IsPropertyDeclaration(d) && d.Initializer() == nil
44884490 })
@@ -7695,91 +7697,6 @@ func (c *Checker) checkSuperExpression(node *ast.Node) *Type {
76957697 if !isCallExpression && ast.IsConstructorDeclaration(immediateContainer) {
76967698 c.checkThisBeforeSuper(node, container, diagnostics.X_super_must_be_called_before_accessing_a_property_of_super_in_the_constructor_of_a_derived_class)
76977699 }
7698- // !!!
7699- // nodeCheckFlag := NodeCheckFlagsNone
7700- // if ast.IsStatic(container) || isCallExpression {
7701- // nodeCheckFlag = NodeCheckFlagsSuperStatic
7702- // if !isCallExpression && c.languageVersion >= core.ScriptTargetES2015 && c.languageVersion <= core.ScriptTargetES2021 && (ast.IsPropertyDeclaration(container) || ast.IsClassStaticBlockDeclaration(container)) {
7703- // // for `super.x` or `super[x]` in a static initializer, mark all enclosing
7704- // // block scope containers so that we can report potential collisions with
7705- // // `Reflect`.
7706- // forEachEnclosingBlockScopeContainer(node.Parent, func(current *ast.Node) {
7707- // if !isSourceFile(current) || isExternalOrCommonJSModule(current) {
7708- // c.getNodeLinks(current).flags |= NodeCheckFlagsContainsSuperPropertyInStaticInitializer
7709- // }
7710- // })
7711- // }
7712- // } else {
7713- // nodeCheckFlag = NodeCheckFlagsSuperInstance
7714- // }
7715- // c.getNodeLinks(node).flags |= nodeCheckFlag
7716- // // Due to how we emit async functions, we need to specialize the emit for an async method that contains a `super` reference.
7717- // // This is due to the fact that we emit the body of an async function inside of a generator function. As generator
7718- // // functions cannot reference `super`, we emit a helper inside of the method body, but outside of the generator. This helper
7719- // // uses an arrow function, which is permitted to reference `super`.
7720- // //
7721- // // There are two primary ways we can access `super` from within an async method. The first is getting the value of a property
7722- // // or indexed access on super, either as part of a right-hand-side expression or call expression. The second is when setting the value
7723- // // of a property or indexed access, either as part of an assignment expression or destructuring assignment.
7724- // //
7725- // // The simplest case is reading a value, in which case we will emit something like the following:
7726- // //
7727- // // // ts
7728- // // ...
7729- // // async asyncMethod() {
7730- // // let x = await super.asyncMethod();
7731- // // return x;
7732- // // }
7733- // // ...
7734- // //
7735- // // // js
7736- // // ...
7737- // // asyncMethod() {
7738- // // const _super = Object.create(null, {
7739- // // asyncMethod: { get: () => super.asyncMethod },
7740- // // });
7741- // // return __awaiter(this, arguments, Promise, function *() {
7742- // // let x = yield _super.asyncMethod.call(this);
7743- // // return x;
7744- // // });
7745- // // }
7746- // // ...
7747- // //
7748- // // The more complex case is when we wish to assign a value, especially as part of a destructuring assignment. As both cases
7749- // // are legal in ES6, but also likely less frequent, we only emit setters if there is an assignment:
7750- // //
7751- // // // ts
7752- // // ...
7753- // // async asyncMethod(ar: Promise<any[]>) {
7754- // // [super.a, super.b] = await ar;
7755- // // }
7756- // // ...
7757- // //
7758- // // // js
7759- // // ...
7760- // // asyncMethod(ar) {
7761- // // const _super = Object.create(null, {
7762- // // a: { get: () => super.a, set: (v) => super.a = v },
7763- // // b: { get: () => super.b, set: (v) => super.b = v }
7764- // // };
7765- // // return __awaiter(this, arguments, Promise, function *() {
7766- // // [_super.a, _super.b] = yield ar;
7767- // // });
7768- // // }
7769- // // ...
7770- // //
7771- // // Creating an object that has getter and setters instead of just an accessor function is required for destructuring assignments
7772- // // as a call expression cannot be used as the target of a destructuring assignment while a property access can.
7773- // //
7774- // // For element access expressions (`super[x]`), we emit a generic helper that forwards the element access in both situations.
7775- // if container.Kind == ast.KindMethodDeclaration && inAsyncFunction {
7776- // }
7777- // if needToCaptureLexicalThis {
7778- // // call expressions are allowed only in constructors so they should always capture correct 'this'
7779- // // super property access expressions can also appear in arrow functions -
7780- // // in this case they should also use correct lexical this
7781- // c.captureLexicalThis(node.Parent, container)
7782- // }
77837700 if container.Parent.Kind == ast.KindObjectLiteralExpression {
77847701 // for object literal assume that type of 'super' is 'any'
77857702 return c.anyType
@@ -11346,7 +11263,7 @@ func (c *Checker) checkPropertyNotUsedBeforeDeclaration(prop *ast.Symbol, node *
1134611263 !(ast.IsAccessExpression(node) && ast.IsAccessExpression(node.Expression())) &&
1134711264 !c.isBlockScopedNameDeclaredBeforeUse(valueDeclaration, right) &&
1134811265 !(ast.IsMethodDeclaration(valueDeclaration) && c.getCombinedModifierFlagsCached(valueDeclaration)&ast.ModifierFlagsStatic != 0) &&
11349- (c.compilerOptions.UseDefineForClassFields.IsTrue () || !c.isPropertyDeclaredInAncestorClass(prop)) {
11266+ (c.compilerOptions.GetUseDefineForClassFields () || !c.isPropertyDeclaredInAncestorClass(prop)) {
1135011267 diagnostic = c.error(right, diagnostics.Property_0_is_used_before_its_initialization, declarationName)
1135111268 } else if ast.IsClassDeclaration(valueDeclaration) && !ast.IsTypeReferenceNode(node.Parent) && valueDeclaration.Flags&ast.NodeFlagsAmbient == 0 && !c.isBlockScopedNameDeclaredBeforeUse(valueDeclaration, right) {
1135211269 diagnostic = c.error(right, diagnostics.Class_0_used_before_its_declaration, declarationName)
@@ -12370,7 +12287,7 @@ func (c *Checker) checkAssignmentOperator(left *ast.Node, operator ast.Kind, rig
1237012287 }
1237112288 }
1237212289 // getters can be a subtype of setters, so to check for assignability we use the setter's type instead
12373- if isCompoundAssignment (operator) && ast.IsPropertyAccessExpression(left) {
12290+ if ast.IsCompoundAssignment (operator) && ast.IsPropertyAccessExpression(left) {
1237412291 leftType = c.checkPropertyAccessExpression(left, CheckModeNormal, true /*writeOnly*/)
1237512292 }
1237612293 if c.checkReferenceExpression(left, diagnostics.The_left_hand_side_of_an_assignment_expression_must_be_a_variable_or_a_property_access, diagnostics.The_left_hand_side_of_an_assignment_expression_may_not_be_an_optional_property_access) {
@@ -13763,47 +13680,17 @@ func (c *Checker) reportMergeSymbolError(target *ast.Symbol, source *ast.Symbol)
1376313680 default:
1376413681 message = diagnostics.Duplicate_identifier_0
1376513682 }
13766- // sourceSymbolFile := ast.GetSourceFileOfNode(getFirstDeclaration(source))
13767- // targetSymbolFile := ast.GetSourceFileOfNode(getFirstDeclaration(target))
13683+ sourceSymbolFile := ast.GetSourceFileOfNode(getFirstDeclaration(source))
13684+ targetSymbolFile := ast.GetSourceFileOfNode(getFirstDeclaration(target))
13685+ isSourcePlainJS := ast.IsPlainJSFile(sourceSymbolFile, c.compilerOptions.CheckJs)
13686+ isTargetPlainJS := ast.IsPlainJSFile(targetSymbolFile, c.compilerOptions.CheckJs)
1376813687 symbolName := c.symbolToString(source)
13769- // !!!
13770- // Collect top-level duplicate identifier errors into one mapping, so we can then merge their diagnostics if there are a bunch
13771- // if sourceSymbolFile != nil && targetSymbolFile != nil && c.amalgamatedDuplicates && !isEitherEnum && sourceSymbolFile != targetSymbolFile {
13772- // var firstFile SourceFile
13773- // if comparePaths(sourceSymbolFile.path, targetSymbolFile.path) == ComparisonLessThan {
13774- // firstFile = sourceSymbolFile
13775- // } else {
13776- // firstFile = targetSymbolFile
13777- // }
13778- // var secondFile SourceFile
13779- // if firstFile == sourceSymbolFile {
13780- // secondFile = targetSymbolFile
13781- // } else {
13782- // secondFile = sourceSymbolFile
13783- // }
13784- // filesDuplicates := getOrUpdate(c.amalgamatedDuplicates, __TEMPLATE__(firstFile.path, "|", secondFile.path), func() DuplicateInfoForFiles {
13785- // return (map[any]any{ /* TODO(TS-TO-GO): was object literal */
13786- // "firstFile": firstFile,
13787- // "secondFile": secondFile,
13788- // "conflictingSymbols": NewMap(),
13789- // })
13790- // })
13791- // conflictingSymbolInfo := getOrUpdate(filesDuplicates.conflictingSymbols, symbolName, func() DuplicateInfoForSymbol {
13792- // return (map[any]any{ /* TODO(TS-TO-GO): was object literal */
13793- // "isBlockScoped": isEitherBlockScoped,
13794- // "firstFileLocations": []never{},
13795- // "secondFileLocations": []never{},
13796- // })
13797- // })
13798- // if !isSourcePlainJS {
13799- // addDuplicateLocations(conflictingSymbolInfo.firstFileLocations, source)
13800- // }
13801- // if !isTargetPlainJS {
13802- // addDuplicateLocations(conflictingSymbolInfo.secondFileLocations, target)
13803- // }
13804- // } else {
13805- c.addDuplicateDeclarationErrorsForSymbols(source, message, symbolName, target)
13806- c.addDuplicateDeclarationErrorsForSymbols(target, message, symbolName, source)
13688+ if !isSourcePlainJS {
13689+ c.addDuplicateDeclarationErrorsForSymbols(source, message, symbolName, target)
13690+ }
13691+ if !isTargetPlainJS {
13692+ c.addDuplicateDeclarationErrorsForSymbols(target, message, symbolName, source)
13693+ }
1380713694}
1380813695
1380913696func (c *Checker) addDuplicateDeclarationErrorsForSymbols(target *ast.Symbol, message *diagnostics.Message, symbolName string, source *ast.Symbol) {
@@ -16236,6 +16123,10 @@ func (c *Checker) getTypeForVariableLikeDeclaration(declaration *ast.Node, inclu
1623616123 }
1623716124 }
1623816125 if ast.IsParameter(declaration) {
16126+ if declaration.Symbol() == nil {
16127+ // parameters of function types defined in JSDoc in TS files don't have symbols
16128+ return nil
16129+ }
1623916130 fn := declaration.Parent
1624016131 // For a parameter of a set accessor, use the type of the get accessor if one is present
1624116132 if ast.IsSetAccessorDeclaration(fn) && c.hasBindableName(fn) {
@@ -25234,7 +25125,7 @@ func (c *Checker) removeStringLiteralsMatchedByTemplateLiterals(types []*Type) [
2523425125
2523525126func (c *Checker) isTypeMatchedByTemplateLiteralOrStringMapping(t *Type, template *Type) bool {
2523625127 if template.flags&TypeFlagsTemplateLiteral != 0 {
25237- return c.isTypeMatchedByTemplateLiteralType(t, template.AsTemplateLiteralType())
25128+ return c.isTypeMatchedByTemplateLiteralType(t, template.AsTemplateLiteralType(), c.compareTypesAssignable )
2523825129 }
2523925130 return c.isMemberOfStringMapping(t, template)
2524025131}
@@ -26340,11 +26231,17 @@ func (c *Checker) getPropertyTypeForIndexType(originalObjectType *Type, objectTy
2634026231 }
2634126232 prop := c.getPropertyOfType(objectType, propName)
2634226233 if prop != nil {
26343- // !!!
26344- // if accessFlags&AccessFlagsReportDeprecated != 0 && accessNode != nil && len(prop.declarations) != 0 && c.isDeprecatedSymbol(prop) && c.isUncalledFunctionReference(accessNode, prop) {
26345- // deprecatedNode := /* TODO(TS-TO-GO) QuestionQuestionToken BinaryExpression: accessExpression?.argumentExpression ?? (isIndexedAccessTypeNode(accessNode) ? accessNode.indexType : accessNode) */ TODO
26346- // c.addDeprecatedSuggestion(deprecatedNode, prop.declarations, propName /* as string */)
26347- // }
26234+ if accessFlags&AccessFlagsReportDeprecated != 0 && accessNode != nil && len(prop.Declarations) != 0 && c.isDeprecatedSymbol(prop) && c.isUncalledFunctionReference(accessNode, prop) {
26235+ var deprecatedNode *ast.Node
26236+ if accessExpression != nil {
26237+ deprecatedNode = accessExpression.AsElementAccessExpression().ArgumentExpression
26238+ } else if ast.IsIndexedAccessTypeNode(accessNode) {
26239+ deprecatedNode = accessNode.AsIndexedAccessTypeNode().IndexType
26240+ } else {
26241+ deprecatedNode = accessNode
26242+ }
26243+ c.addDeprecatedSuggestion(deprecatedNode, prop.Declarations, propName)
26244+ }
2634826245 if accessExpression != nil {
2634926246 c.markPropertyAsReferenced(prop, accessExpression, c.isSelfTypeAccess(accessExpression.Expression(), objectType.symbol))
2635026247 if c.isAssignmentToReadonlyEntity(accessExpression, prop, getAssignmentTargetKind(accessExpression)) {
0 commit comments