Skip to content

Commit 52f4ae6

Browse files
committed
Merge branch 'main' of https://github.com/microsoft/typescript-go into fix/1374
2 parents e6a6025 + 1f3304f commit 52f4ae6

File tree

220 files changed

+24835
-30093
lines changed

Some content is hidden

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

220 files changed

+24835
-30093
lines changed

.github/workflows/codeql.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ jobs:
4848

4949
# Initializes the CodeQL tools for scanning.
5050
- name: Initialize CodeQL
51-
uses: github/codeql-action/init@3599b3baa15b485a2e49ef411a7a4bb2452e7f93 # v3.29.5
51+
uses: github/codeql-action/init@64d10c13136e1c5bce3e5fbde8d4906eeaafc885 # v3.29.5
5252
with:
5353
config-file: ./.github/codeql/codeql-configuration.yml
5454
# Override language selection by uncommenting this and choosing your languages
@@ -58,7 +58,7 @@ jobs:
5858
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
5959
# If this step fails, then you should remove it and run the build manually (see below).
6060
- name: Autobuild
61-
uses: github/codeql-action/autobuild@3599b3baa15b485a2e49ef411a7a4bb2452e7f93 # v3.29.5
61+
uses: github/codeql-action/autobuild@64d10c13136e1c5bce3e5fbde8d4906eeaafc885 # v3.29.5
6262

6363
# ℹ️ Command-line programs to run using the OS shell.
6464
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
@@ -72,4 +72,4 @@ jobs:
7272
# make release
7373

7474
- name: Perform CodeQL Analysis
75-
uses: github/codeql-action/analyze@3599b3baa15b485a2e49ef411a7a4bb2452e7f93 # v3.29.5
75+
uses: github/codeql-action/analyze@64d10c13136e1c5bce3e5fbde8d4906eeaafc885 # v3.29.5

_packages/api/src/node.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,6 @@ export class RemoteNode extends RemoteNodeBase implements Node {
544544
get isTypeOnly(): boolean | undefined {
545545
switch (this.kind) {
546546
case SyntaxKind.ImportSpecifier:
547-
case SyntaxKind.ImportClause:
548547
case SyntaxKind.ExportSpecifier:
549548
case SyntaxKind.ImportEqualsDeclaration:
550549
case SyntaxKind.ExportDeclaration:
@@ -921,6 +920,18 @@ export class RemoteNode extends RemoteNodeBase implements Node {
921920
}
922921
}
923922

923+
get phaseModifier(): SyntaxKind {
924+
switch (this.kind) {
925+
case SyntaxKind.ImportClause:
926+
const flags = (this.data & (1 << 24 | 1 << 25)) >> 24;
927+
if (flags & 1) return SyntaxKind.TypeKeyword;
928+
if (flags & 2) return SyntaxKind.DeferKeyword;
929+
// fallthrough
930+
default:
931+
return SyntaxKind.Unknown;
932+
}
933+
}
934+
924935
get token(): SyntaxKind | undefined {
925936
switch (this.kind) {
926937
case SyntaxKind.ImportAttributes:

_packages/ast/src/nodes.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1992,11 +1992,16 @@ export type NamedExportBindings =
19921992
export interface ImportClause extends NamedDeclaration {
19931993
readonly kind: SyntaxKind.ImportClause;
19941994
readonly parent: ImportDeclaration | JSDocImportTag;
1995-
readonly isTypeOnly: boolean;
1995+
readonly phaseModifier: ImportPhaseModifierSyntaxKind;
19961996
readonly name?: Identifier; // Default binding
19971997
readonly namedBindings?: NamedImportBindings;
19981998
}
19991999

2000+
export type ImportPhaseModifierSyntaxKind =
2001+
| SyntaxKind.Unknown
2002+
| SyntaxKind.TypeKeyword
2003+
| SyntaxKind.DeferKeyword;
2004+
20002005
/** @deprecated */
20012006
export type AssertionKey = ImportAttributeName;
20022007

_packages/ast/src/syntaxKind.enum.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ export enum SyntaxKind {
165165
BigIntKeyword,
166166
OverrideKeyword,
167167
OfKeyword,
168+
DeferKeyword,
168169
QualifiedName,
169170
ComputedPropertyName,
170171
TypeParameter,

_packages/ast/src/syntaxKind.ts

Lines changed: 189 additions & 188 deletions
Large diffs are not rendered by default.

internal/api/encoder/encoder.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -714,7 +714,7 @@ func getNodeDefinedData(node *ast.Node) uint32 {
714714
return uint32(boolToByte(n.IsTypeOnly)) << 24
715715
case ast.KindImportClause:
716716
n := node.AsImportClause()
717-
return uint32(boolToByte(n.IsTypeOnly)) << 24
717+
return uint32(boolToByte(n.PhaseModifier == ast.KindTypeKeyword))<<24 | uint32(boolToByte(n.PhaseModifier == ast.KindDeferKeyword))<<25
718718
case ast.KindExportSpecifier:
719719
n := node.AsExportSpecifier()
720720
return uint32(boolToByte(n.IsTypeOnly)) << 24

internal/ast/ast.go

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,8 @@ func (n *Node) Text() string {
312312
return n.AsNumericLiteral().Text
313313
case KindBigIntLiteral:
314314
return n.AsBigIntLiteral().Text
315+
case KindMetaProperty:
316+
return n.AsMetaProperty().Name().Text()
315317
case KindNoSubstitutionTemplateLiteral:
316318
return n.AsNoSubstitutionTemplateLiteral().Text
317319
case KindTemplateHead:
@@ -894,7 +896,7 @@ func (n *Node) IsTypeOnly() bool {
894896
case KindImportSpecifier:
895897
return n.AsImportSpecifier().IsTypeOnly
896898
case KindImportClause:
897-
return n.AsImportClause().IsTypeOnly
899+
return n.AsImportClause().PhaseModifier == KindTypeKeyword
898900
case KindExportDeclaration:
899901
return n.AsExportDeclaration().IsTypeOnly
900902
case KindExportSpecifier:
@@ -4945,22 +4947,22 @@ type ImportClause struct {
49454947
DeclarationBase
49464948
ExportableBase
49474949
compositeNodeBase
4948-
IsTypeOnly bool
4950+
PhaseModifier Kind // KindTypeKeyword | KindDeferKeyword
49494951
NamedBindings *NamedImportBindings // NamedImportBindings. Optional, named bindings
49504952
name *IdentifierNode // IdentifierNode. Optional, default binding
49514953
}
49524954

4953-
func (f *NodeFactory) NewImportClause(isTypeOnly bool, name *IdentifierNode, namedBindings *NamedImportBindings) *Node {
4955+
func (f *NodeFactory) NewImportClause(phaseModifier Kind, name *IdentifierNode, namedBindings *NamedImportBindings) *Node {
49544956
data := &ImportClause{}
4955-
data.IsTypeOnly = isTypeOnly
4957+
data.PhaseModifier = phaseModifier
49564958
data.name = name
49574959
data.NamedBindings = namedBindings
49584960
return f.newNode(KindImportClause, data)
49594961
}
49604962

4961-
func (f *NodeFactory) UpdateImportClause(node *ImportClause, isTypeOnly bool, name *IdentifierNode, namedBindings *NamedImportBindings) *Node {
4962-
if isTypeOnly != node.IsTypeOnly || name != node.name || namedBindings != node.NamedBindings {
4963-
return updateNode(f.NewImportClause(isTypeOnly, name, namedBindings), node.AsNode(), f.hooks)
4963+
func (f *NodeFactory) UpdateImportClause(node *ImportClause, phaseModifier Kind, name *IdentifierNode, namedBindings *NamedImportBindings) *Node {
4964+
if phaseModifier != node.PhaseModifier || name != node.name || namedBindings != node.NamedBindings {
4965+
return updateNode(f.NewImportClause(phaseModifier, name, namedBindings), node.AsNode(), f.hooks)
49644966
}
49654967
return node.AsNode()
49664968
}
@@ -4970,19 +4972,19 @@ func (node *ImportClause) ForEachChild(v Visitor) bool {
49704972
}
49714973

49724974
func (node *ImportClause) VisitEachChild(v *NodeVisitor) *Node {
4973-
return v.Factory.UpdateImportClause(node, node.IsTypeOnly, v.visitNode(node.name), v.visitNode(node.NamedBindings))
4975+
return v.Factory.UpdateImportClause(node, node.PhaseModifier, v.visitNode(node.name), v.visitNode(node.NamedBindings))
49744976
}
49754977

49764978
func (node *ImportClause) Clone(f NodeFactoryCoercible) *Node {
4977-
return cloneNode(f.AsNodeFactory().NewImportClause(node.IsTypeOnly, node.Name(), node.NamedBindings), node.AsNode(), f.AsNodeFactory().hooks)
4979+
return cloneNode(f.AsNodeFactory().NewImportClause(node.PhaseModifier, node.Name(), node.NamedBindings), node.AsNode(), f.AsNodeFactory().hooks)
49784980
}
49794981

49804982
func (node *ImportClause) Name() *DeclarationName {
49814983
return node.name
49824984
}
49834985

49844986
func (node *ImportClause) computeSubtreeFacts() SubtreeFacts {
4985-
if node.IsTypeOnly {
4987+
if node.PhaseModifier == KindTypeKeyword {
49864988
return SubtreeContainsTypeScript
49874989
} else {
49884990
return propagateSubtreeFacts(node.name) |

internal/ast/kind.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,8 @@ const (
180180
KindGlobalKeyword
181181
KindBigIntKeyword
182182
KindOverrideKeyword
183-
KindOfKeyword // LastKeyword and LastToken and LastContextualKeyword
183+
KindOfKeyword
184+
KindDeferKeyword // LastKeyword and LastToken and LastContextualKeyword
184185
// Parse tree nodes
185186
// Names
186187
KindQualifiedName
@@ -399,7 +400,7 @@ const (
399400
KindFirstReservedWord = KindBreakKeyword
400401
KindLastReservedWord = KindWithKeyword
401402
KindFirstKeyword = KindBreakKeyword
402-
KindLastKeyword = KindOfKeyword
403+
KindLastKeyword = KindDeferKeyword
403404
KindFirstFutureReservedWord = KindImplementsKeyword
404405
KindLastFutureReservedWord = KindYieldKeyword
405406
KindFirstTypeNode = KindTypePredicate
@@ -422,7 +423,7 @@ const (
422423
KindFirstJSDocTagNode = KindJSDocTag
423424
KindLastJSDocTagNode = KindJSDocImportTag
424425
KindFirstContextualKeyword = KindAbstractKeyword
425-
KindLastContextualKeyword = KindOfKeyword
426+
KindLastContextualKeyword = KindDeferKeyword
426427
KindComment = KindSingleLineCommentTrivia | KindMultiLineCommentTrivia
427428
KindFirstTriviaToken = KindSingleLineCommentTrivia
428429
KindLastTriviaToken = KindConflictMarkerTrivia

0 commit comments

Comments
 (0)