Skip to content

Commit f20c7a0

Browse files
committed
Merge remote-tracking branch 'origin/main' into eof
2 parents 5bb73c4 + 12cbd18 commit f20c7a0

File tree

351 files changed

+3089
-6476
lines changed

Some content is hidden

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

351 files changed

+3089
-6476
lines changed

.github/copilot-instructions.md

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
This is the codebase for a native port of the TypeScript compiler and language server.
2+
The source directories of interest that we have are:
3+
4+
- `internal` - Contains the compiler and language server code.
5+
- `_extension` - Contains a preview VS Code extension code that integrates with the language server.
6+
- `_submodules/TypeScript` - the stable TypeScript repository, checked out at the appropriate commit.
7+
8+
Most of our development takes place in the `internal` directory, and most behaviors can be tested via compiler tests.
9+
10+
Most development on the codebase is in Go.
11+
Standard Go commands and practices apply, but we primarily use a tool called `hereby` to build, run tests, and other tasks.
12+
Feel free to install `hereby` globally (`npm install -g hereby`) if it is easier, and run `hereby --list` to see all available commands.
13+
14+
```sh
15+
hereby build # Build the project
16+
hereby test # Run tests
17+
hereby format # Format the code
18+
hereby lint # Run linters
19+
```
20+
21+
Always make sure code is formatted, linted, and tested before sending a pull request.
22+
23+
## Compiler Features, Fixes, and Tests
24+
25+
When fixing a bug or implementing a new feature, at least one minimal test case should always be added in advance to verify the fix.
26+
This project primarily uses snapshot/baseline/golden tests rather than unit tests.
27+
New compiler tests are written in `.ts`/`.tsx` files in the directory `testdata/tests/cases/compiler/`, and are written in the following format:
28+
29+
```ts
30+
// @target: esnext
31+
// @module: preserve
32+
// @moduleResolution: bundler
33+
// @strict: true
34+
// @checkJs: true
35+
36+
// @filename: fileA.ts
37+
38+
export interface Person {
39+
name: string;
40+
age: number;
41+
}
42+
43+
// @filename: fileB.js
44+
45+
/** @import { Person } from "./fileA" */
46+
47+
/**
48+
* @param {Person} person
49+
*/
50+
function greet(person) {
51+
console.log(`Hello, ${person.name}!`);
52+
}
53+
```
54+
55+
Tests don't always need the above `@option`s specified, but they are common to specify or modify.
56+
Tests can be run with multiple settings for a given option by using a comma-separated list (e.g. `@option: settingA,settingB`).
57+
`@filename` is only required when a test has multiple files, or when writing a test for a single JavaScript file (where `allowJs` or `checkJs` is enabled).
58+
You can see more tests in `_submodules/TypeScript/tests/cases/{compiler,conformance}`.
59+
60+
When tests are run, they will produce output files in the `testdata/baselines/local` directory.
61+
**Test failures are fine** if they are just differences in output files.
62+
A reduction/removal of `.diff` file baselines is **ideal** because it indicates the port has converged in behavior with the stable TypeScript codebase.
63+
The new outputs can be diffed against `testdata/baselines/reference` to see if the output has changed.
64+
65+
Running
66+
67+
```sh
68+
npx hereby baseline-accept
69+
```
70+
71+
will update the baselines/snapshots, and `git diff` can be used to see what has changed.
72+
73+
It is ideal to implement features and fixes in the following order, and commit code after each step:
74+
75+
1. Write a minimal test case, or test cases, that demonstrate the bug or feature.
76+
1. Run the tests to ensure it fails (for a bug) or passes (for a feature). Then accept generated baselines (not applicable in the case of a crash).
77+
1. Implement the fix or feature.
78+
1. Run the tests again to ensure everything is working correctly. Accept the baselines.
79+
80+
It is fine to implement more and more of a feature across commits, but be sure to update baselines every time so that reviewers can measure progress.
81+
82+
# Other Instructions
83+
84+
- Do not add or change existing dependencies unless asked to.
85+

.github/workflows/copilot-setup-steps.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,5 @@ jobs:
2626
cache-name: copilot-setup-steps
2727
- run: npm i -g @playwright/[email protected]
2828
- run: npm ci
29+
# pull dprint caches before network access is blocked
30+
- run: npx hereby check:format || true

_submodules/TypeScript

Submodule TypeScript updated 63 files

internal/api/encoder/encoder.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -774,7 +774,7 @@ func recordNodeStrings(node *ast.Node, strs *stringTable) uint32 {
774774
case ast.KindNoSubstitutionTemplateLiteral:
775775
return strs.add(node.AsNoSubstitutionTemplateLiteral().Text, node.Kind, node.Pos(), node.End())
776776
case ast.KindJSDocText:
777-
return strs.add(node.AsJSDocText().Text, node.Kind, node.Pos(), node.End())
777+
return strs.add(node.AsJSDocText().Text(), node.Kind, node.Pos(), node.End())
778778
default:
779779
panic(fmt.Sprintf("Unexpected node kind %v", node.Kind))
780780
}

internal/ast/ast.go

Lines changed: 43 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -53,23 +53,33 @@ type NodeFactory struct {
5353
blockPool core.Pool[Block]
5454
callExpressionPool core.Pool[CallExpression]
5555
expressionStatementPool core.Pool[ExpressionStatement]
56+
functionDeclarationPool core.Pool[FunctionDeclaration]
57+
functionTypeNodePool core.Pool[FunctionTypeNode]
5658
identifierPool core.Pool[Identifier]
5759
ifStatementPool core.Pool[IfStatement]
60+
interfaceDeclarationPool core.Pool[InterfaceDeclaration]
5861
jsdocPool core.Pool[JSDoc]
5962
jsdocTextPool core.Pool[JSDocText]
63+
keywordExpressionPool core.Pool[KeywordExpression]
6064
keywordTypeNodePool core.Pool[KeywordTypeNode]
6165
literalTypeNodePool core.Pool[LiteralTypeNode]
66+
methodSignatureDeclarationPool core.Pool[MethodSignatureDeclaration]
6267
modifierListPool core.Pool[ModifierList]
6368
nodeListPool core.Pool[NodeList]
69+
numericLiteralPool core.Pool[NumericLiteral]
6470
parameterDeclarationPool core.Pool[ParameterDeclaration]
6571
parenthesizedExpressionPool core.Pool[ParenthesizedExpression]
72+
parenthesizedTypeNodePool core.Pool[ParenthesizedTypeNode]
73+
prefixUnaryExpressionPool core.Pool[PrefixUnaryExpression]
6674
propertyAccessExpressionPool core.Pool[PropertyAccessExpression]
6775
propertyAssignmentPool core.Pool[PropertyAssignment]
6876
propertySignatureDeclarationPool core.Pool[PropertySignatureDeclaration]
6977
returnStatementPool core.Pool[ReturnStatement]
7078
stringLiteralPool core.Pool[StringLiteral]
7179
tokenPool core.Pool[Token]
80+
typeLiteralNodePool core.Pool[TypeLiteralNode]
7281
typeReferenceNodePool core.Pool[TypeReferenceNode]
82+
unionTypeNodePool core.Pool[UnionTypeNode]
7383
variableDeclarationListPool core.Pool[VariableDeclarationList]
7484
variableDeclarationPool core.Pool[VariableDeclaration]
7585
variableStatementPool core.Pool[VariableStatement]
@@ -296,7 +306,7 @@ func (n *Node) Text() string {
296306
case KindRegularExpressionLiteral:
297307
return n.AsRegularExpressionLiteral().Text
298308
case KindJSDocText:
299-
return n.AsJSDocText().Text
309+
return strings.Join(n.AsJSDocText().text, "")
300310
}
301311
panic(fmt.Sprintf("Unhandled case in Node.Text: %T", n.data))
302312
}
@@ -3466,7 +3476,7 @@ type FunctionDeclaration struct {
34663476
}
34673477

34683478
func (f *NodeFactory) NewFunctionDeclaration(modifiers *ModifierList, asteriskToken *TokenNode, name *IdentifierNode, typeParameters *NodeList, parameters *NodeList, returnType *TypeNode, body *BlockNode) *Node {
3469-
data := &FunctionDeclaration{}
3479+
data := f.functionDeclarationPool.New()
34703480
data.modifiers = modifiers
34713481
data.AsteriskToken = asteriskToken
34723482
data.name = name
@@ -3722,7 +3732,7 @@ type InterfaceDeclaration struct {
37223732
}
37233733

37243734
func (f *NodeFactory) NewInterfaceDeclaration(modifiers *ModifierList, name *IdentifierNode, typeParameters *NodeList, heritageClauses *NodeList, members *NodeList) *Node {
3725-
data := &InterfaceDeclaration{}
3735+
data := f.interfaceDeclarationPool.New()
37263736
data.modifiers = modifiers
37273737
data.name = name
37283738
data.TypeParameters = typeParameters
@@ -5124,7 +5134,7 @@ type MethodSignatureDeclaration struct {
51245134
}
51255135

51265136
func (f *NodeFactory) NewMethodSignatureDeclaration(modifiers *ModifierList, name *PropertyName, postfixToken *TokenNode, typeParameters *NodeList, parameters *NodeList, returnType *TypeNode) *Node {
5127-
data := &MethodSignatureDeclaration{}
5137+
data := f.methodSignatureDeclarationPool.New()
51285138
data.modifiers = modifiers
51295139
data.name = name
51305140
data.PostfixToken = postfixToken
@@ -5433,7 +5443,7 @@ type KeywordExpression struct {
54335443
}
54345444

54355445
func (f *NodeFactory) NewKeywordExpression(kind Kind) *Node {
5436-
return f.newNode(kind, &KeywordExpression{})
5446+
return f.newNode(kind, f.keywordExpressionPool.New())
54375447
}
54385448

54395449
func (node *KeywordExpression) Clone(f NodeFactoryCoercible) *Node {
@@ -5489,7 +5499,7 @@ type NumericLiteral struct {
54895499
}
54905500

54915501
func (f *NodeFactory) NewNumericLiteral(text string) *Node {
5492-
data := &NumericLiteral{}
5502+
data := f.numericLiteralPool.New()
54935503
data.Text = text
54945504
f.textCount++
54955505
return f.newNode(KindNumericLiteral, data)
@@ -5638,7 +5648,7 @@ type PrefixUnaryExpression struct {
56385648
}
56395649

56405650
func (f *NodeFactory) NewPrefixUnaryExpression(operator Kind, operand *Expression) *Node {
5641-
data := &PrefixUnaryExpression{}
5651+
data := f.prefixUnaryExpressionPool.New()
56425652
data.Operator = operator
56435653
data.Operand = operand
56445654
return f.newNode(KindPrefixUnaryExpression, data)
@@ -7035,7 +7045,7 @@ func (f *NodeFactory) UpdateUnionTypeNode(node *UnionTypeNode, types *TypeList)
70357045
}
70367046

70377047
func (f *NodeFactory) NewUnionTypeNode(types *NodeList) *Node {
7038-
data := &UnionTypeNode{}
7048+
data := f.unionTypeNodePool.New()
70397049
data.Types = types
70407050
return f.newNode(KindUnionType, data)
70417051
}
@@ -7718,7 +7728,7 @@ type TypeLiteralNode struct {
77187728
}
77197729

77207730
func (f *NodeFactory) NewTypeLiteralNode(members *NodeList) *Node {
7721-
data := &TypeLiteralNode{}
7731+
data := f.typeLiteralNodePool.New()
77227732
data.Members = members
77237733
return f.newNode(KindTypeLiteral, data)
77247734
}
@@ -7909,7 +7919,7 @@ type ParenthesizedTypeNode struct {
79097919
}
79107920

79117921
func (f *NodeFactory) NewParenthesizedTypeNode(typeNode *TypeNode) *Node {
7912-
data := &ParenthesizedTypeNode{}
7922+
data := f.parenthesizedTypeNodePool.New()
79137923
data.Type = typeNode
79147924
return f.newNode(KindParenthesizedType, data)
79157925
}
@@ -7957,7 +7967,7 @@ type FunctionTypeNode struct {
79577967
}
79587968

79597969
func (f *NodeFactory) NewFunctionTypeNode(typeParameters *NodeList, parameters *NodeList, returnType *TypeNode) *Node {
7960-
data := &FunctionTypeNode{}
7970+
data := f.functionTypeNodePool.New()
79617971
data.TypeParameters = typeParameters
79627972
data.Parameters = parameters
79637973
data.Type = returnType
@@ -8814,40 +8824,40 @@ type JSDocTagBase struct {
88148824

88158825
type JSDocCommentBase struct {
88168826
NodeBase
8817-
Text string
8827+
text []string
88188828
}
88198829

88208830
// JSDoc comments
88218831
type JSDocText struct {
88228832
JSDocCommentBase
88238833
}
88248834

8825-
func (f *NodeFactory) NewJSDocText(text string) *Node {
8835+
func (f *NodeFactory) NewJSDocText(text []string) *Node {
88268836
data := f.jsdocTextPool.New()
8827-
data.Text = text
8837+
data.text = text
88288838
f.textCount++
88298839
return f.newNode(KindJSDocText, data)
88308840
}
88318841

88328842
func (node *JSDocText) Clone(f NodeFactoryCoercible) *Node {
8833-
return cloneNode(f.AsNodeFactory().NewJSDocText(node.Text), node.AsNode(), f.AsNodeFactory().hooks)
8843+
return cloneNode(f.AsNodeFactory().NewJSDocText(node.text), node.AsNode(), f.AsNodeFactory().hooks)
88348844
}
88358845

88368846
type JSDocLink struct {
88378847
JSDocCommentBase
88388848
name *Node // optional (should only be EntityName)
88398849
}
88408850

8841-
func (f *NodeFactory) NewJSDocLink(name *Node, text string) *Node {
8851+
func (f *NodeFactory) NewJSDocLink(name *Node, text []string) *Node {
88428852
data := &JSDocLink{}
88438853
data.name = name
8844-
data.Text = text
8854+
data.text = text
88458855
f.textCount++
88468856
return f.newNode(KindJSDocLink, data)
88478857
}
88488858

8849-
func (f *NodeFactory) UpdateJSDocLink(node *JSDocLink, name *Node, text string) *Node {
8850-
if name != node.name || text != node.Text {
8859+
func (f *NodeFactory) UpdateJSDocLink(node *JSDocLink, name *Node, text []string) *Node {
8860+
if name != node.name || !core.Same(text, node.text) {
88518861
return updateNode(f.NewJSDocLink(name, text), node.AsNode(), f.hooks)
88528862
}
88538863
return node.AsNode()
@@ -8858,11 +8868,11 @@ func (node *JSDocLink) ForEachChild(v Visitor) bool {
88588868
}
88598869

88608870
func (node *JSDocLink) VisitEachChild(v *NodeVisitor) *Node {
8861-
return v.Factory.UpdateJSDocLink(node, v.visitNode(node.name), node.Text)
8871+
return v.Factory.UpdateJSDocLink(node, v.visitNode(node.name), node.text)
88628872
}
88638873

88648874
func (node *JSDocLink) Clone(f NodeFactoryCoercible) *Node {
8865-
return cloneNode(f.AsNodeFactory().NewJSDocLink(node.Name(), node.Text), node.AsNode(), f.AsNodeFactory().hooks)
8875+
return cloneNode(f.AsNodeFactory().NewJSDocLink(node.Name(), node.text), node.AsNode(), f.AsNodeFactory().hooks)
88668876
}
88678877

88688878
func (node *JSDocLink) Name() *DeclarationName {
@@ -8874,16 +8884,16 @@ type JSDocLinkPlain struct {
88748884
name *Node // optional (should only be EntityName)
88758885
}
88768886

8877-
func (f *NodeFactory) NewJSDocLinkPlain(name *Node, text string) *Node {
8887+
func (f *NodeFactory) NewJSDocLinkPlain(name *Node, text []string) *Node {
88788888
data := &JSDocLinkPlain{}
88798889
data.name = name
8880-
data.Text = text
8890+
data.text = text
88818891
f.textCount++
88828892
return f.newNode(KindJSDocLinkPlain, data)
88838893
}
88848894

8885-
func (f *NodeFactory) UpdateJSDocLinkPlain(node *JSDocLinkPlain, name *Node, text string) *Node {
8886-
if name != node.name || text != node.Text {
8895+
func (f *NodeFactory) UpdateJSDocLinkPlain(node *JSDocLinkPlain, name *Node, text []string) *Node {
8896+
if name != node.name || !core.Same(text, node.text) {
88878897
return updateNode(f.NewJSDocLinkPlain(name, text), node.AsNode(), f.hooks)
88888898
}
88898899
return node.AsNode()
@@ -8894,11 +8904,11 @@ func (node *JSDocLinkPlain) ForEachChild(v Visitor) bool {
88948904
}
88958905

88968906
func (node *JSDocLinkPlain) VisitEachChild(v *NodeVisitor) *Node {
8897-
return v.Factory.UpdateJSDocLinkPlain(node, v.visitNode(node.name), node.Text)
8907+
return v.Factory.UpdateJSDocLinkPlain(node, v.visitNode(node.name), node.text)
88988908
}
88998909

89008910
func (node *JSDocLinkPlain) Clone(f NodeFactoryCoercible) *Node {
8901-
return cloneNode(f.AsNodeFactory().NewJSDocLinkPlain(node.Name(), node.Text), node.AsNode(), f.AsNodeFactory().hooks)
8911+
return cloneNode(f.AsNodeFactory().NewJSDocLinkPlain(node.Name(), node.text), node.AsNode(), f.AsNodeFactory().hooks)
89028912
}
89038913

89048914
func (node *JSDocLinkPlain) Name() *DeclarationName {
@@ -8910,16 +8920,16 @@ type JSDocLinkCode struct {
89108920
name *Node // optional (should only be EntityName)
89118921
}
89128922

8913-
func (f *NodeFactory) NewJSDocLinkCode(name *Node, text string) *Node {
8923+
func (f *NodeFactory) NewJSDocLinkCode(name *Node, text []string) *Node {
89148924
data := &JSDocLinkCode{}
89158925
data.name = name
8916-
data.Text = text
8926+
data.text = text
89178927
f.textCount++
89188928
return f.newNode(KindJSDocLinkCode, data)
89198929
}
89208930

8921-
func (f *NodeFactory) UpdateJSDocLinkCode(node *JSDocLinkCode, name *Node, text string) *Node {
8922-
if name != node.name || text != node.Text {
8931+
func (f *NodeFactory) UpdateJSDocLinkCode(node *JSDocLinkCode, name *Node, text []string) *Node {
8932+
if name != node.name || !core.Same(text, node.text) {
89238933
return updateNode(f.NewJSDocLinkCode(name, text), node.AsNode(), f.hooks)
89248934
}
89258935
return node.AsNode()
@@ -8930,11 +8940,11 @@ func (node *JSDocLinkCode) ForEachChild(v Visitor) bool {
89308940
}
89318941

89328942
func (node *JSDocLinkCode) VisitEachChild(v *NodeVisitor) *Node {
8933-
return v.Factory.UpdateJSDocLinkCode(node, v.visitNode(node.name), node.Text)
8943+
return v.Factory.UpdateJSDocLinkCode(node, v.visitNode(node.name), node.text)
89348944
}
89358945

89368946
func (node *JSDocLinkCode) Clone(f NodeFactoryCoercible) *Node {
8937-
return cloneNode(f.AsNodeFactory().NewJSDocLinkCode(node.Name(), node.Text), node.AsNode(), f.AsNodeFactory().hooks)
8947+
return cloneNode(f.AsNodeFactory().NewJSDocLinkCode(node.Name(), node.text), node.AsNode(), f.AsNodeFactory().hooks)
89388948
}
89398949

89408950
func (node *JSDocLinkCode) Name() *DeclarationName {

internal/checker/checker.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22640,9 +22640,9 @@ func (c *Checker) getAliasForTypeNode(node *ast.Node) *TypeAlias {
2264022640
}
2264122641

2264222642
func (c *Checker) getAliasSymbolForTypeNode(node *ast.Node) *ast.Symbol {
22643-
host := node.Parent
22643+
host := ast.GetEffectiveTypeParent(node.Parent)
2264422644
for ast.IsParenthesizedTypeNode(host) || ast.IsTypeOperatorNode(host) && host.AsTypeOperatorNode().Operator == ast.KindReadonlyKeyword {
22645-
host = host.Parent
22645+
host = ast.GetEffectiveTypeParent(host.Parent)
2264622646
}
2264722647
if isTypeAlias(host) {
2264822648
return c.getSymbolOfDeclaration(host)

0 commit comments

Comments
 (0)