Skip to content

Commit 0ddc898

Browse files
committed
Merge branch 'main' into guyllian.gomez/yarn-pnp
2 parents 1df2287 + 179ff49 commit 0ddc898

File tree

1,325 files changed

+8670
-19831
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,325 files changed

+8670
-19831
lines changed

_submodules/TypeScript

Submodule TypeScript updated 1922 files

internal/ast/parseoptions.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"github.com/microsoft/typescript-go/internal/tspath"
66
)
77

8-
type JSDocParsingMode int
8+
type JSDocParsingMode uint8
99

1010
const (
1111
JSDocParsingModeParseAll JSDocParsingMode = iota

internal/ast/subtreefacts.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"github.com/microsoft/typescript-go/internal/core"
55
)
66

7-
type SubtreeFacts int32
7+
type SubtreeFacts uint32
88

99
const (
1010
// Facts

internal/ast/symbol.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,18 @@ type Symbol struct {
2323
GlobalExports SymbolTable // Conditional global UMD exports
2424
}
2525

26+
func (s *Symbol) IsExternalModule() bool {
27+
return s.Flags&SymbolFlagsModule != 0 && len(s.Name) > 0 && s.Name[0] == '"'
28+
}
29+
30+
func (s *Symbol) IsStatic() bool {
31+
if s.ValueDeclaration == nil {
32+
return false
33+
}
34+
modifierFlags := s.ValueDeclaration.ModifierFlags()
35+
return modifierFlags&ModifierFlagsStatic != 0
36+
}
37+
2638
// SymbolTable
2739

2840
type SymbolTable map[string]*Symbol

internal/ast/utilities.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3526,6 +3526,10 @@ func IsTypeDeclarationName(name *Node) bool {
35263526
GetNameOfDeclaration(name.Parent) == name
35273527
}
35283528

3529+
func IsRightSideOfPropertyAccess(node *Node) bool {
3530+
return node.Parent.Kind == KindPropertyAccessExpression && node.Parent.Name() == node
3531+
}
3532+
35293533
func IsRightSideOfQualifiedNameOrPropertyAccess(node *Node) bool {
35303534
parent := node.Parent
35313535
switch parent.Kind {

internal/binder/nameresolver.go

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -205,13 +205,6 @@ loop:
205205
return nil
206206
}
207207
}
208-
case ast.KindArrowFunction:
209-
// when targeting ES6 or higher there is no 'arguments' in an arrow function
210-
// for lower compile targets the resolved symbol is used to emit an error
211-
if r.CompilerOptions.GetEmitScriptTarget() >= core.ScriptTargetES2015 {
212-
break
213-
}
214-
fallthrough
215208
case ast.KindMethodDeclaration, ast.KindConstructor, ast.KindGetAccessor, ast.KindSetAccessor, ast.KindFunctionDeclaration:
216209
if meaning&ast.SymbolFlagsVariable != 0 && name == "arguments" {
217210
result = r.argumentsSymbol()
@@ -354,21 +347,18 @@ func (r *NameResolver) useOuterVariableScopeInParameter(result *ast.Symbol, loca
354347
// - optional chaining pre-es2020
355348
// - nullish coalesce pre-es2020
356349
// - spread assignment in binding pattern pre-es2017
357-
target := r.CompilerOptions.GetEmitScriptTarget()
358-
if target >= core.ScriptTargetES2015 {
359-
functionLocation := location
360-
declarationRequiresScopeChange := core.TSUnknown
361-
if r.GetRequiresScopeChangeCache != nil {
362-
declarationRequiresScopeChange = r.GetRequiresScopeChangeCache(functionLocation)
363-
}
364-
if declarationRequiresScopeChange == core.TSUnknown {
365-
declarationRequiresScopeChange = core.IfElse(core.Some(functionLocation.Parameters(), r.requiresScopeChange), core.TSTrue, core.TSFalse)
366-
if r.SetRequiresScopeChangeCache != nil {
367-
r.SetRequiresScopeChangeCache(functionLocation, declarationRequiresScopeChange)
368-
}
350+
functionLocation := location
351+
declarationRequiresScopeChange := core.TSUnknown
352+
if r.GetRequiresScopeChangeCache != nil {
353+
declarationRequiresScopeChange = r.GetRequiresScopeChangeCache(functionLocation)
354+
}
355+
if declarationRequiresScopeChange == core.TSUnknown {
356+
declarationRequiresScopeChange = core.IfElse(core.Some(functionLocation.Parameters(), r.requiresScopeChange), core.TSTrue, core.TSFalse)
357+
if r.SetRequiresScopeChangeCache != nil {
358+
r.SetRequiresScopeChangeCache(functionLocation, declarationRequiresScopeChange)
369359
}
370-
return declarationRequiresScopeChange != core.TSTrue
371360
}
361+
return declarationRequiresScopeChange != core.TSTrue
372362
}
373363
}
374364
return false

internal/checker/checker.go

Lines changed: 13 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -3257,9 +3257,6 @@ func (c *Checker) checkFunctionOrMethodDeclaration(node *ast.Node) {
32573257
if c.getContextualCallSignature(c.getTypeFromTypeNode(node.FunctionLikeData().FullSignature), node) == nil {
32583258
c.error(node.FunctionLikeData().FullSignature, diagnostics.A_JSDoc_type_tag_on_a_function_must_have_a_signature_with_the_correct_number_of_arguments)
32593259
}
3260-
if node.Type() != nil || core.Some(node.Parameters(), func(p *ast.Node) bool { return p.Type() != nil }) {
3261-
c.error(node.FunctionLikeData().FullSignature, diagnostics.A_JSDoc_type_tag_may_not_occur_with_a_param_or_returns_tag)
3262-
}
32633260
}
32643261
if node.Type() == nil {
32653262
// Report an implicit any error if there is no body, no explicit return type, and node is not a private method
@@ -5817,6 +5814,7 @@ func (c *Checker) getIteratedTypeOrElementType(use IterationUse, inputType *Type
58175814
}
58185815
return nil
58195816
}
5817+
// TODO: remove ScriptTargetES2015
58205818
uplevelIteration := c.languageVersion >= core.ScriptTargetES2015
58215819
downlevelIteration := !uplevelIteration && c.compilerOptions.DownlevelIteration == core.TSTrue
58225820
possibleOutOfBounds := c.compilerOptions.NoUncheckedIndexedAccess == core.TSTrue && use&IterationUsePossiblyOutOfBounds != 0
@@ -7675,10 +7673,6 @@ func (c *Checker) checkSuperExpression(node *ast.Node) *Type {
76757673
// c.captureLexicalThis(node.Parent, container)
76767674
// }
76777675
if container.Parent.Kind == ast.KindObjectLiteralExpression {
7678-
if c.languageVersion < core.ScriptTargetES2015 {
7679-
c.error(node, diagnostics.X_super_is_only_allowed_in_members_of_object_literal_expressions_when_option_target_is_ES2015_or_higher)
7680-
return c.errorType
7681-
}
76827676
// for object literal assume that type of 'super' is 'any'
76837677
return c.anyType
76847678
}
@@ -9833,9 +9827,6 @@ func (c *Checker) checkFunctionExpressionOrObjectLiteralMethod(node *ast.Node, c
98339827
if c.getContextualCallSignature(c.getTypeFromTypeNode(node.FunctionLikeData().FullSignature), node) == nil {
98349828
c.error(node.FunctionLikeData().FullSignature, diagnostics.A_JSDoc_type_tag_on_a_function_must_have_a_signature_with_the_correct_number_of_arguments)
98359829
}
9836-
if node.Type() != nil || core.Some(node.Parameters(), func(p *ast.Node) bool { return p.Type() != nil }) {
9837-
c.error(node.FunctionLikeData().FullSignature, diagnostics.A_JSDoc_type_tag_may_not_occur_with_a_param_or_returns_tag)
9838-
}
98399830
}
98409831
c.contextuallyCheckFunctionExpressionOrObjectLiteralMethod(node, checkMode)
98419832
return c.getTypeOfSymbol(c.getSymbolOfDeclaration(node))
@@ -11343,14 +11334,6 @@ func (c *Checker) checkPropertyAccessibilityAtLocation(location *ast.Node, isSup
1134311334
// - In a static member function or static member accessor
1134411335
// where this references the constructor function object of a derived class,
1134511336
// a super property access is permitted and must specify a public static member function of the base class.
11346-
if c.languageVersion < core.ScriptTargetES2015 {
11347-
if c.symbolHasNonMethodDeclaration(prop) {
11348-
if errorNode != nil {
11349-
c.error(errorNode, diagnostics.Only_public_and_protected_methods_of_the_base_class_are_accessible_via_the_super_keyword)
11350-
}
11351-
return false
11352-
}
11353-
}
1135411337
if flags&ast.ModifierFlagsAbstract != 0 {
1135511338
// A method cannot be accessed in a super property access if the method is abstract.
1135611339
// This error could mask a private property access error. But, a member
@@ -11689,12 +11672,11 @@ func (c *Checker) TryGetThisTypeAtEx(node *ast.Node, includeGlobalThis bool, con
1168911672
container = c.getThisContainer(node, false /*includeArrowFunctions*/, false /*includeClassComputedPropertyName*/)
1169011673
}
1169111674
if ast.IsFunctionLike(container) && (!c.isInParameterInitializerBeforeContainingFunction(node) || ast.GetThisParameter(container) != nil) {
11692-
thisType := c.getThisTypeOfDeclaration(container)
11693-
if thisType == nil && ast.IsInJSFile(container) {
11694-
if sig := c.getSignatureOfFullSignatureType(container); sig != nil {
11695-
thisType = c.getThisTypeOfSignature(sig)
11696-
}
11675+
sig := c.getSignatureOfFullSignatureType(container)
11676+
if sig == nil {
11677+
sig = c.getSignatureFromDeclaration(container)
1169711678
}
11679+
thisType := c.getThisTypeOfSignature(sig)
1169811680
// Note: a parameter initializer should refer to class-this unless function-this is explicitly annotated.
1169911681
// If this is a function in a JS file, it might be a class method.
1170011682
if thisType == nil {
@@ -11793,10 +11775,6 @@ func (c *Checker) isInParameterInitializerBeforeContainingFunction(node *ast.Nod
1179311775
return false
1179411776
}
1179511777

11796-
func (c *Checker) getThisTypeOfDeclaration(declaration *ast.Node) *Type {
11797-
return c.getThisTypeOfSignature(c.getSignatureFromDeclaration(declaration))
11798-
}
11799-
1180011778
func (c *Checker) checkThisInStaticClassFieldInitializerInDecoratedClass(thisExpression *ast.Node, container *ast.Node) {
1180111779
if ast.IsPropertyDeclaration(container) && ast.HasStaticModifier(container) && c.legacyDecorators {
1180211780
initializer := container.Initializer()
@@ -17356,6 +17334,7 @@ func (c *Checker) getTypeFromArrayBindingPattern(pattern *ast.Node, includePatte
1735617334
restElement = lastElement
1735717335
}
1735817336
if len(elements) == 0 || len(elements) == 1 && restElement != nil {
17337+
// TODO: remove ScriptTargetES2015
1735917338
if c.languageVersion >= core.ScriptTargetES2015 {
1736017339
return c.createIterableType(c.anyType)
1736117340
}
@@ -19101,11 +19080,11 @@ func (c *Checker) getSignaturesOfSymbol(symbol *ast.Symbol) []*Signature {
1910119080
}
1910219081
// If this is a function or method declaration, get the signature from the @type tag for the sake of optional parameters.
1910319082
// Exclude contextually-typed kinds because we already apply the @type tag to the context, plus applying it here to the initializer would suppress checks that the two are compatible.
19104-
if sig := c.getSignatureOfFullSignatureType(decl); sig != nil {
19105-
result = append(result, sig)
19106-
continue
19083+
sig := c.getSignatureOfFullSignatureType(decl)
19084+
if sig == nil {
19085+
sig = c.getSignatureFromDeclaration(decl)
1910719086
}
19108-
result = append(result, c.getSignatureFromDeclaration(decl))
19087+
result = append(result, sig)
1910919088
}
1911019089
return result
1911119090
}
@@ -19187,15 +19166,13 @@ func (c *Checker) getSignatureFromDeclaration(declaration *ast.Node) *Signature
1918719166
}
1918819167

1918919168
func (c *Checker) getTypeParametersFromDeclaration(declaration *ast.Node) []*Type {
19169+
if sig := c.getSignatureOfFullSignatureType(declaration); sig != nil {
19170+
return sig.TypeParameters()
19171+
}
1919019172
var result []*Type
1919119173
for _, node := range declaration.TypeParameters() {
1919219174
result = core.AppendIfUnique(result, c.getDeclaredTypeOfTypeParameter(node.Symbol()))
1919319175
}
19194-
if len(result) == 0 && ast.IsFunctionDeclaration(declaration) {
19195-
if sig := c.getSignatureOfFullSignatureType(declaration); sig != nil {
19196-
return sig.TypeParameters()
19197-
}
19198-
}
1919919176
return result
1920019177
}
1920119178

internal/checker/grammarchecks.go

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1338,9 +1338,6 @@ func (c *Checker) checkGrammarForInOrForOfStatement(forInOrOfStatement *ast.ForI
13381338
func (c *Checker) checkGrammarAccessor(accessor *ast.AccessorDeclaration) bool {
13391339
body := accessor.Body()
13401340
if accessor.Flags&ast.NodeFlagsAmbient == 0 && (accessor.Parent.Kind != ast.KindTypeLiteral) && (accessor.Parent.Kind != ast.KindInterfaceDeclaration) {
1341-
if c.languageVersion < core.ScriptTargetES2015 && ast.IsPrivateIdentifier(accessor.Name()) {
1342-
return c.grammarErrorOnNode(accessor.Name(), diagnostics.Private_identifiers_are_only_available_when_targeting_ECMAScript_2015_and_higher)
1343-
}
13441341
if body == nil && !ast.HasSyntacticModifier(accessor, ast.ModifierFlagsAbstract) {
13451342
return c.grammarErrorAtPos(accessor, accessor.End()-1, len(";"), diagnostics.X_0_expected, "{")
13461343
}
@@ -1492,9 +1489,6 @@ func (c *Checker) checkGrammarMethod(node *ast.Node /*Union[MethodDeclaration, M
14921489
}
14931490

14941491
if ast.IsClassLike(node.Parent) {
1495-
if c.languageVersion < core.ScriptTargetES2015 && ast.IsPrivateIdentifier(node.Name()) {
1496-
return c.grammarErrorOnNode(node.Name(), diagnostics.Private_identifiers_are_only_available_when_targeting_ECMAScript_2015_and_higher)
1497-
}
14981492
// Technically, computed properties in ambient contexts is disallowed
14991493
// for property declarations and accessors too, not just methods.
15001494
// However, property declarations disallow computed names in general,
@@ -1934,12 +1928,6 @@ func (c *Checker) checkGrammarProperty(node *ast.Node /*Union[PropertyDeclaratio
19341928
if c.checkGrammarForInvalidDynamicName(propertyName, diagnostics.A_computed_property_name_in_a_class_property_declaration_must_have_a_simple_literal_type_or_a_unique_symbol_type) {
19351929
return true
19361930
}
1937-
if c.languageVersion < core.ScriptTargetES2015 && ast.IsPrivateIdentifier(propertyName) {
1938-
return c.grammarErrorOnNode(propertyName, diagnostics.Private_identifiers_are_only_available_when_targeting_ECMAScript_2015_and_higher)
1939-
}
1940-
if c.languageVersion < core.ScriptTargetES2015 && ast.IsAutoAccessorPropertyDeclaration(node) && node.Flags&ast.NodeFlagsAmbient == 0 {
1941-
return c.grammarErrorOnNode(propertyName, diagnostics.Properties_with_the_accessor_modifier_are_only_available_when_targeting_ECMAScript_2015_and_higher)
1942-
}
19431931
if ast.IsAutoAccessorPropertyDeclaration(node) && c.checkGrammarForInvalidQuestionMark(node.AsPropertyDeclaration().PostfixToken, diagnostics.An_accessor_property_cannot_be_declared_optional) {
19441932
return true
19451933
}

internal/checker/relater.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1994,19 +1994,11 @@ func (c *Checker) getTypePredicateOfSignature(sig *Signature) *TypePredicate {
19941994
default:
19951995
if sig.declaration != nil {
19961996
typeNode := sig.declaration.Type()
1997-
var jsdocTypePredicate *TypePredicate
1998-
if typeNode == nil {
1999-
if jsdocSignature := c.getSignatureOfFullSignatureType(sig.declaration); jsdocSignature != nil {
2000-
jsdocTypePredicate = c.getTypePredicateOfSignature(jsdocSignature)
2001-
}
2002-
}
20031997
switch {
20041998
case typeNode != nil:
20051999
if ast.IsTypePredicateNode(typeNode) {
20062000
sig.resolvedTypePredicate = c.createTypePredicateFromTypePredicateNode(typeNode, sig)
20072001
}
2008-
case jsdocTypePredicate != nil:
2009-
sig.resolvedTypePredicate = jsdocTypePredicate
20102002
case ast.IsFunctionLikeDeclaration(sig.declaration) && (sig.resolvedReturnType == nil || sig.resolvedReturnType.flags&TypeFlagsBoolean != 0) && c.getParameterCount(sig) > 0:
20112003
sig.resolvedTypePredicate = c.noTypePredicate // avoid infinite loop
20122004
sig.resolvedTypePredicate = c.getTypePredicateFromBody(sig.declaration)

internal/checker/types.go

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ const TypeFormatFlagsNodeBuilderFlagsMask = TypeFormatFlagsNoTruncation | TypeFo
8282
TypeFormatFlagsUseTypeOfFunction | TypeFormatFlagsOmitParameterModifiers | TypeFormatFlagsUseAliasDefinedOutsideCurrentScope | TypeFormatFlagsAllowUniqueESSymbolType | TypeFormatFlagsInTypeAlias |
8383
TypeFormatFlagsUseSingleQuotesForStringLiteralType | TypeFormatFlagsNoTypeReduction | TypeFormatFlagsOmitThisParameter
8484

85-
type SymbolFormatFlags int32
85+
type SymbolFormatFlags uint32
8686

8787
const (
8888
SymbolFormatFlagsNone SymbolFormatFlags = 0
@@ -1210,20 +1210,6 @@ const (
12101210
type TypeComparer func(s *Type, t *Type, reportErrors bool) Ternary
12111211

12121212
type LanguageFeatureMinimumTargetMap struct {
1213-
Classes core.ScriptTarget
1214-
ForOf core.ScriptTarget
1215-
Generators core.ScriptTarget
1216-
Iteration core.ScriptTarget
1217-
SpreadElements core.ScriptTarget
1218-
RestElements core.ScriptTarget
1219-
TaggedTemplates core.ScriptTarget
1220-
DestructuringAssignment core.ScriptTarget
1221-
BindingPatterns core.ScriptTarget
1222-
ArrowFunctions core.ScriptTarget
1223-
BlockScopedVariables core.ScriptTarget
1224-
ObjectAssign core.ScriptTarget
1225-
RegularExpressionFlagsUnicode core.ScriptTarget
1226-
RegularExpressionFlagsSticky core.ScriptTarget
12271213
Exponentiation core.ScriptTarget
12281214
AsyncFunctions core.ScriptTarget
12291215
ForAwaitOf core.ScriptTarget
@@ -1247,20 +1233,6 @@ type LanguageFeatureMinimumTargetMap struct {
12471233
}
12481234

12491235
var LanguageFeatureMinimumTarget = LanguageFeatureMinimumTargetMap{
1250-
Classes: core.ScriptTargetES2015,
1251-
ForOf: core.ScriptTargetES2015,
1252-
Generators: core.ScriptTargetES2015,
1253-
Iteration: core.ScriptTargetES2015,
1254-
SpreadElements: core.ScriptTargetES2015,
1255-
RestElements: core.ScriptTargetES2015,
1256-
TaggedTemplates: core.ScriptTargetES2015,
1257-
DestructuringAssignment: core.ScriptTargetES2015,
1258-
BindingPatterns: core.ScriptTargetES2015,
1259-
ArrowFunctions: core.ScriptTargetES2015,
1260-
BlockScopedVariables: core.ScriptTargetES2015,
1261-
ObjectAssign: core.ScriptTargetES2015,
1262-
RegularExpressionFlagsUnicode: core.ScriptTargetES2015,
1263-
RegularExpressionFlagsSticky: core.ScriptTargetES2015,
12641236
Exponentiation: core.ScriptTargetES2016,
12651237
AsyncFunctions: core.ScriptTargetES2017,
12661238
ForAwaitOf: core.ScriptTargetES2018,

0 commit comments

Comments
 (0)