Skip to content

Commit 1cffb6e

Browse files
committed
Add JSExportDeclaration
I'm adding this to show the changes, but I plan to revert it. The results are more correct, but the amount of code in the checker is twice the previous commit, so I don't think the improvement is worthwhile.
1 parent 689d0e7 commit 1cffb6e

File tree

287 files changed

+1846
-1570
lines changed

Some content is hidden

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

287 files changed

+1846
-1570
lines changed

internal/api/encoder/encoder.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ func getChildrenPropertyMask(node *ast.Node) uint8 {
474474
case ast.KindNamespaceExportDeclaration:
475475
n := node.AsNamespaceExportDeclaration()
476476
return (boolToByte(n.Modifiers() != nil) << 0) | (boolToByte(n.Name() != nil) << 1)
477-
case ast.KindExportDeclaration:
477+
case ast.KindExportDeclaration, ast.KindJSExportDeclaration:
478478
n := node.AsExportDeclaration()
479479
return (boolToByte(n.Modifiers() != nil) << 0) | (boolToByte(n.ExportClause != nil) << 1) | (boolToByte(n.ModuleSpecifier != nil) << 2) | (boolToByte(n.Attributes != nil) << 3)
480480
case ast.KindExportSpecifier:
@@ -733,7 +733,7 @@ func getNodeDefinedData(node *ast.Node) uint32 {
733733
case ast.KindExportAssignment:
734734
n := node.AsExportAssignment()
735735
return uint32(boolToByte(n.IsExportEquals)) << 24
736-
case ast.KindExportDeclaration:
736+
case ast.KindExportDeclaration, ast.KindJSExportDeclaration:
737737
n := node.AsExportDeclaration()
738738
return uint32(boolToByte(n.IsTypeOnly)) << 24
739739
case ast.KindBlock:

internal/ast/ast.go

+17-5
Original file line numberDiff line numberDiff line change
@@ -753,7 +753,7 @@ func (n *Node) ModuleSpecifier() *Expression {
753753
switch n.Kind {
754754
case KindImportDeclaration:
755755
return n.AsImportDeclaration().ModuleSpecifier
756-
case KindExportDeclaration:
756+
case KindExportDeclaration, KindJSExportDeclaration:
757757
return n.AsExportDeclaration().ModuleSpecifier
758758
case KindJSDocImportTag:
759759
return n.AsJSDocImportTag().ModuleSpecifier
@@ -4482,19 +4482,27 @@ type ExportDeclaration struct {
44824482
Attributes *ImportAttributesNode // ImportAttributesNode. Optional
44834483
}
44844484

4485-
func (f *NodeFactory) NewExportDeclaration(modifiers *ModifierList, isTypeOnly bool, exportClause *NamedExportBindings, moduleSpecifier *Expression, attributes *ImportAttributesNode) *Node {
4485+
func (f *NodeFactory) newExportOrJSExportDeclaration(kind Kind, modifiers *ModifierList, isTypeOnly bool, exportClause *NamedExportBindings, moduleSpecifier *Expression, attributes *ImportAttributesNode) *Node {
44864486
data := &ExportDeclaration{}
44874487
data.modifiers = modifiers
44884488
data.IsTypeOnly = isTypeOnly
44894489
data.ExportClause = exportClause
44904490
data.ModuleSpecifier = moduleSpecifier
44914491
data.Attributes = attributes
4492-
return f.newNode(KindExportDeclaration, data)
4492+
return f.newNode(kind, data)
4493+
}
4494+
4495+
func (f *NodeFactory) NewExportDeclaration(modifiers *ModifierList, isTypeOnly bool, exportClause *NamedExportBindings, moduleSpecifier *Expression, attributes *ImportAttributesNode) *Node {
4496+
return f.newExportOrJSExportDeclaration(KindExportDeclaration, modifiers, isTypeOnly, exportClause, moduleSpecifier, attributes)
4497+
}
4498+
4499+
func (f *NodeFactory) NewJSExportDeclaration(moduleSpecifier *Expression) *Node {
4500+
return f.newExportOrJSExportDeclaration(KindJSExportDeclaration, nil /*modifiers*/, false /*isTypeOnly*/, nil /*exportClause*/, moduleSpecifier, nil /*attributes*/)
44934501
}
44944502

44954503
func (f *NodeFactory) UpdateExportDeclaration(node *ExportDeclaration, modifiers *ModifierList, isTypeOnly bool, exportClause *NamedExportBindings, moduleSpecifier *Expression, attributes *ImportAttributesNode) *Node {
44964504
if modifiers != node.modifiers || exportClause != node.ExportClause || moduleSpecifier != node.ModuleSpecifier || attributes != node.Attributes {
4497-
return updateNode(f.NewExportDeclaration(modifiers, isTypeOnly, exportClause, moduleSpecifier, attributes), node.AsNode(), f.hooks)
4505+
return updateNode(f.newExportOrJSExportDeclaration(node.Kind, modifiers, isTypeOnly, exportClause, moduleSpecifier, attributes), node.AsNode(), f.hooks)
44984506
}
44994507
return node.AsNode()
45004508
}
@@ -4508,7 +4516,7 @@ func (node *ExportDeclaration) VisitEachChild(v *NodeVisitor) *Node {
45084516
}
45094517

45104518
func (node *ExportDeclaration) Clone(f NodeFactoryCoercible) *Node {
4511-
return cloneNode(f.AsNodeFactory().NewExportDeclaration(node.Modifiers(), node.IsTypeOnly, node.ExportClause, node.ModuleSpecifier, node.Attributes), node.AsNode(), f.AsNodeFactory().hooks)
4519+
return cloneNode(f.AsNodeFactory().newExportOrJSExportDeclaration(node.Kind, node.Modifiers(), node.IsTypeOnly, node.ExportClause, node.ModuleSpecifier, node.Attributes), node.AsNode(), f.AsNodeFactory().hooks)
45124520
}
45134521

45144522
func (node *ExportDeclaration) computeSubtreeFacts() SubtreeFacts {
@@ -4523,6 +4531,10 @@ func IsExportDeclaration(node *Node) bool {
45234531
return node.Kind == KindExportDeclaration
45244532
}
45254533

4534+
func IsJSExportDeclaration(node *Node) bool {
4535+
return node.Kind == KindJSExportDeclaration
4536+
}
4537+
45264538
// NamespaceExport
45274539

45284540
type NamespaceExport struct {

internal/ast/kind.go

+1
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,7 @@ const (
380380
// Reparsed JS nodes
381381
KindJSTypeAliasDeclaration
382382
KindJSExportAssignment
383+
KindJSExportDeclaration
383384
KindCommonJSExport
384385
// Transformation nodes
385386
KindNotEmittedStatement

internal/ast/kind_stringer_generated.go

+9-8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/ast/utilities.go

+6-4
Original file line numberDiff line numberDiff line change
@@ -648,6 +648,7 @@ func isDeclarationStatementKind(kind Kind) bool {
648648
KindImportDeclaration,
649649
KindImportEqualsDeclaration,
650650
KindExportDeclaration,
651+
KindJSExportDeclaration,
651652
KindExportAssignment,
652653
KindJSExportAssignment,
653654
KindNamespaceExportDeclaration:
@@ -1677,7 +1678,7 @@ func GetExternalModuleName(node *Node) *Expression {
16771678
switch node.Kind {
16781679
case KindImportDeclaration:
16791680
return node.AsImportDeclaration().ModuleSpecifier
1680-
case KindExportDeclaration:
1681+
case KindExportDeclaration, KindJSExportDeclaration:
16811682
return node.AsExportDeclaration().ModuleSpecifier
16821683
case KindJSDocImportTag:
16831684
return node.AsJSDocImportTag().ModuleSpecifier
@@ -1703,7 +1704,7 @@ func GetImportAttributes(node *Node) *Node {
17031704
switch node.Kind {
17041705
case KindImportDeclaration:
17051706
return node.AsImportDeclaration().Attributes
1706-
case KindExportDeclaration:
1707+
case KindExportDeclaration, KindJSExportDeclaration:
17071708
return node.AsExportDeclaration().Attributes
17081709
}
17091710
panic("Unhandled case in getImportAttributes")
@@ -2055,7 +2056,8 @@ func GetMeaningFromDeclaration(node *Node) SemanticMeaning {
20552056
KindImportDeclaration,
20562057
KindExportAssignment,
20572058
KindJSExportAssignment,
2058-
KindExportDeclaration:
2059+
KindExportDeclaration,
2060+
KindJSExportDeclaration:
20592061
return SemanticMeaningAll
20602062

20612063
// An external module can be a Value
@@ -2346,7 +2348,7 @@ func GetNamespaceDeclarationNode(node *Node) *Node {
23462348
}
23472349
case KindImportEqualsDeclaration:
23482350
return node
2349-
case KindExportDeclaration:
2351+
case KindExportDeclaration, KindJSExportDeclaration:
23502352
exportClause := node.AsExportDeclaration().ExportClause
23512353
if exportClause != nil && IsNamespaceExport(exportClause) {
23522354
return exportClause

internal/binder/binder.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ func (b *Binder) getDeclarationName(node *ast.Node) string {
376376
return ast.InternalSymbolNameNew
377377
case ast.KindIndexSignature:
378378
return ast.InternalSymbolNameIndex
379-
case ast.KindExportDeclaration:
379+
case ast.KindExportDeclaration, ast.KindJSExportDeclaration:
380380
return ast.InternalSymbolNameExportStar
381381
case ast.KindSourceFile:
382382
return ast.InternalSymbolNameExportEquals
@@ -728,7 +728,7 @@ func (b *Binder) bind(node *ast.Node) bool {
728728
b.bindNamespaceExportDeclaration(node)
729729
case ast.KindImportClause:
730730
b.bindImportClause(node)
731-
case ast.KindExportDeclaration:
731+
case ast.KindExportDeclaration, ast.KindJSExportDeclaration:
732732
b.bindExportDeclaration(node)
733733
case ast.KindExportAssignment, ast.KindJSExportAssignment:
734734
b.bindExportAssignment(node)

internal/binder/referenceresolver.go

+2
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ func (r *referenceResolver) isTypeOnlyAliasDeclaration(symbol *ast.Symbol) bool
112112
switch node.Kind {
113113
case ast.KindImportEqualsDeclaration, ast.KindExportDeclaration:
114114
return node.IsTypeOnly()
115+
case ast.KindJSExportDeclaration:
116+
return false
115117
case ast.KindImportClause, ast.KindImportSpecifier, ast.KindExportSpecifier:
116118
if node.IsTypeOnly() {
117119
return true

0 commit comments

Comments
 (0)