Skip to content

Commit 2748845

Browse files
authored
Merge branch 'main' into fix/slice-bounds-panic-issue-1691
2 parents 36ec2ef + 3d33f0e commit 2748845

Some content is hidden

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

49 files changed

+263
-226
lines changed

_extension/src/commands.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as vscode from "vscode";
22
import { Client } from "./client";
3+
import { restartExtHostOnChangeIfNeeded } from "./util";
34

45
export function registerEnablementCommands(context: vscode.ExtensionContext): void {
56
context.subscriptions.push(vscode.commands.registerCommand("typescript.native-preview.enable", () => {
@@ -50,7 +51,7 @@ async function updateUseTsgoSetting(enable: boolean): Promise<void> {
5051
}
5152
// Update the setting and restart the extension host (needed to change the state of the built-in TS extension)
5253
await tsConfig.update("experimental.useTsgo", enable, target);
53-
await vscode.commands.executeCommand("workbench.action.restartExtensionHost");
54+
await restartExtHostOnChangeIfNeeded();
5455
}
5556

5657
/**

_extension/src/extension.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
registerLanguageCommands,
77
} from "./commands";
88
import { setupStatusBar } from "./statusBar";
9+
import { needsExtHostRestartOnChange } from "./util";
910
import { setupVersionStatusItem } from "./versionStatusItem";
1011

1112
export async function activate(context: vscode.ExtensionContext) {
@@ -15,14 +16,11 @@ export async function activate(context: vscode.ExtensionContext) {
1516
const traceOutput = vscode.window.createOutputChannel("typescript-native-preview (LSP)");
1617
context.subscriptions.push(output, traceOutput);
1718

18-
const majorVersion = parseInt(vscode.version.split(".")[0]);
19-
const minorVersion = parseInt(vscode.version.split(".")[1]);
20-
const needsExtHostRestartOnChange = majorVersion <= 1 && minorVersion < 105;
2119
let disposeLanguageFeatures: vscode.Disposable | undefined;
2220

2321
context.subscriptions.push(vscode.workspace.onDidChangeConfiguration(async event => {
2422
if (event.affectsConfiguration("typescript.experimental.useTsgo")) {
25-
if (needsExtHostRestartOnChange) {
23+
if (needsExtHostRestartOnChange()) {
2624
// Delay because the command to change the config setting will restart
2725
// the extension host, so no need to show a message
2826
setTimeout(async () => {

_extension/src/util.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,3 +89,15 @@ export function getLanguageForUri(uri: vscode.Uri): string | undefined {
8989
return undefined;
9090
}
9191
}
92+
93+
export function needsExtHostRestartOnChange() {
94+
const majorVersion = parseInt(vscode.version.split(".")[0]);
95+
const minorVersion = parseInt(vscode.version.split(".")[1]);
96+
return majorVersion <= 1 && minorVersion < 105;
97+
}
98+
99+
export async function restartExtHostOnChangeIfNeeded(): Promise<void> {
100+
if (needsExtHostRestartOnChange()) {
101+
await vscode.commands.executeCommand("workbench.action.restartExtensionHost");
102+
}
103+
}

internal/ast/ast.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10724,10 +10724,10 @@ type SourceFile struct {
1072410724
ClassifiableNames collections.Set[string]
1072510725
PatternAmbientModules []*PatternAmbientModule
1072610726

10727-
// Fields set by LineMap
10727+
// Fields set by ECMALineMap
1072810728

10729-
lineMapMu sync.RWMutex
10730-
lineMap []core.TextPos
10729+
ecmaLineMapMu sync.RWMutex
10730+
ecmaLineMap []core.TextPos
1073110731

1073210732
// Fields set by language service
1073310733

@@ -10862,17 +10862,17 @@ func (f *NodeFactory) UpdateSourceFile(node *SourceFile, statements *StatementLi
1086210862
return node.AsNode()
1086310863
}
1086410864

10865-
func (node *SourceFile) LineMap() []core.TextPos {
10866-
node.lineMapMu.RLock()
10867-
lineMap := node.lineMap
10868-
node.lineMapMu.RUnlock()
10865+
func (node *SourceFile) ECMALineMap() []core.TextPos {
10866+
node.ecmaLineMapMu.RLock()
10867+
lineMap := node.ecmaLineMap
10868+
node.ecmaLineMapMu.RUnlock()
1086910869
if lineMap == nil {
10870-
node.lineMapMu.Lock()
10871-
defer node.lineMapMu.Unlock()
10872-
lineMap = node.lineMap
10870+
node.ecmaLineMapMu.Lock()
10871+
defer node.ecmaLineMapMu.Unlock()
10872+
lineMap = node.ecmaLineMap
1087310873
if lineMap == nil {
10874-
lineMap = core.ComputeLineStarts(node.Text())
10875-
node.lineMap = lineMap
10874+
lineMap = core.ComputeECMALineStarts(node.Text())
10875+
node.ecmaLineMap = lineMap
1087610876
}
1087710877
}
1087810878
return lineMap
@@ -11054,7 +11054,7 @@ func getDeclarationName(declaration *Node) string {
1105411054

1105511055
type SourceFileLike interface {
1105611056
Text() string
11057-
LineMap() []core.TextPos
11057+
ECMALineMap() []core.TextPos
1105811058
}
1105911059

1106011060
type CommentRange struct {

internal/astnav/tokens_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ func tsGetTouchingPropertyName(t testing.TB, fileText string, positions []int) [
240240
}
241241

242242
func writeRangeDiff(output *strings.Builder, file *ast.SourceFile, diff tokenDiff, rng core.TextRange, position int) {
243-
lines := file.LineMap()
243+
lines := file.ECMALineMap()
244244

245245
tsTokenPos := position
246246
goTokenPos := position

internal/checker/checker.go

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8053,7 +8053,6 @@ func (c *Checker) checkCallExpression(node *ast.Node, checkMode CheckMode) *Type
80538053
if !ast.IsDottedName(node.Expression()) {
80548054
c.error(node.Expression(), diagnostics.Assertions_require_the_call_target_to_be_an_identifier_or_qualified_name)
80558055
} else if c.getEffectsSignature(node) == nil {
8056-
c.error(node.Expression(), diagnostics.Assertions_require_every_name_in_the_call_target_to_be_declared_with_an_explicit_type_annotation)
80578056
diagnostic := c.error(node.Expression(), diagnostics.Assertions_require_every_name_in_the_call_target_to_be_declared_with_an_explicit_type_annotation)
80588057
c.getTypeOfDottedName(node.Expression(), diagnostic)
80598058
}
@@ -18332,6 +18331,11 @@ func (c *Checker) getBaseTypes(t *Type) []*Type {
1833218331
}
1833318332
}
1833418333
}
18334+
// In general, base type resolution always precedes member resolution. However, it is possible
18335+
// for resolution of type parameter defaults to cause circularity errors, possibly leaving
18336+
// members partially resolved. Here we ensure any such partial resolution is reset.
18337+
// See https://github.com/microsoft/TypeScript/issues/16861 for an example.
18338+
t.objectFlags &^= ObjectFlagsMembersResolved
1833518339
data.baseTypesResolved = true
1833618340
}
1833718341
return data.resolvedBaseTypes
@@ -18395,14 +18399,6 @@ func (c *Checker) resolveBaseTypesOfClass(t *Type) {
1839518399
c.error(t.symbol.ValueDeclaration, diagnostics.Type_0_recursively_references_itself_as_a_base_type, c.TypeToString(t))
1839618400
return
1839718401
}
18398-
// !!! This logic is suspicious. We really shouldn't be un-resolving members after they've been resolved.
18399-
// if t.resolvedBaseTypes == resolvingEmptyArray {
18400-
// // Circular reference, likely through instantiation of default parameters
18401-
// // (otherwise there'd be an error from hasBaseType) - this is fine, but `.members` should be reset
18402-
// // as `getIndexedAccessType` via `instantiateType` via `getTypeFromClassOrInterfaceReference` forces a
18403-
// // partial instantiation of the members without the base types fully resolved
18404-
// t.members = nil
18405-
// }
1840618402
t.AsInterfaceType().resolvedBaseTypes = []*Type{reducedBaseType}
1840718403
}
1840818404

internal/checker/flow.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2160,7 +2160,17 @@ func (c *Checker) getExplicitTypeOfSymbol(symbol *ast.Symbol, diagnostic *ast.Di
21602160
}
21612161

21622162
func (c *Checker) isDeclarationWithExplicitTypeAnnotation(node *ast.Node) bool {
2163-
return (ast.IsVariableDeclaration(node) || ast.IsPropertyDeclaration(node) || ast.IsPropertySignatureDeclaration(node) || ast.IsParameter(node)) && node.Type() != nil
2163+
return (ast.IsVariableDeclaration(node) || ast.IsPropertyDeclaration(node) || ast.IsPropertySignatureDeclaration(node) || ast.IsParameter(node)) && node.Type() != nil ||
2164+
c.isExpandoPropertyFunctionWithReturnTypeAnnotation(node)
2165+
}
2166+
2167+
func (c *Checker) isExpandoPropertyFunctionWithReturnTypeAnnotation(node *ast.Node) bool {
2168+
if ast.IsBinaryExpression(node) {
2169+
if expr := node.AsBinaryExpression().Right; ast.IsFunctionLike(expr) && expr.Type() != nil {
2170+
return true
2171+
}
2172+
}
2173+
return false
21642174
}
21652175

21662176
func (c *Checker) hasTypePredicateOrNeverReturnType(sig *Signature) bool {

internal/checker/grammarchecks.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -814,8 +814,8 @@ func (c *Checker) checkGrammarArrowFunction(node *ast.Node, file *ast.SourceFile
814814
}
815815

816816
equalsGreaterThanToken := arrowFunc.EqualsGreaterThanToken
817-
startLine, _ := scanner.GetLineAndCharacterOfPosition(file, equalsGreaterThanToken.Pos())
818-
endLine, _ := scanner.GetLineAndCharacterOfPosition(file, equalsGreaterThanToken.End())
817+
startLine, _ := scanner.GetECMALineAndCharacterOfPosition(file, equalsGreaterThanToken.Pos())
818+
endLine, _ := scanner.GetECMALineAndCharacterOfPosition(file, equalsGreaterThanToken.End())
819819
return startLine != endLine && c.grammarErrorOnNode(equalsGreaterThanToken, diagnostics.Line_terminator_not_permitted_before_arrow)
820820
}
821821

internal/compiler/program.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1074,10 +1074,10 @@ func (p *Program) getDiagnosticsWithPrecedingDirectives(sourceFile *ast.SourceFi
10741074
// Build map of directives by line number
10751075
directivesByLine := make(map[int]ast.CommentDirective)
10761076
for _, directive := range sourceFile.CommentDirectives {
1077-
line, _ := scanner.GetLineAndCharacterOfPosition(sourceFile, directive.Loc.Pos())
1077+
line, _ := scanner.GetECMALineAndCharacterOfPosition(sourceFile, directive.Loc.Pos())
10781078
directivesByLine[line] = directive
10791079
}
1080-
lineStarts := scanner.GetLineStarts(sourceFile)
1080+
lineStarts := scanner.GetECMALineStarts(sourceFile)
10811081
filtered := make([]*ast.Diagnostic, 0, len(diags))
10821082
for _, diagnostic := range diags {
10831083
ignoreDiagnostic := false
@@ -1225,7 +1225,7 @@ func (p *Program) getDiagnosticsHelper(ctx context.Context, sourceFile *ast.Sour
12251225
func (p *Program) LineCount() int {
12261226
var count int
12271227
for _, file := range p.files {
1228-
count += len(file.LineMap())
1228+
count += len(file.ECMALineMap())
12291229
}
12301230
return count
12311231
}

internal/core/core.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -362,12 +362,12 @@ func Coalesce[T *U, U any](a T, b T) T {
362362
}
363363
}
364364

365-
func ComputeLineStarts(text string) []TextPos {
365+
func ComputeECMALineStarts(text string) []TextPos {
366366
result := make([]TextPos, 0, strings.Count(text, "\n")+1)
367-
return slices.AppendSeq(result, ComputeLineStartsSeq(text))
367+
return slices.AppendSeq(result, ComputeECMALineStartsSeq(text))
368368
}
369369

370-
func ComputeLineStartsSeq(text string) iter.Seq[TextPos] {
370+
func ComputeECMALineStartsSeq(text string) iter.Seq[TextPos] {
371371
return func(yield func(TextPos) bool) {
372372
textLen := TextPos(len(text))
373373
var pos TextPos

0 commit comments

Comments
 (0)