@@ -27,14 +27,6 @@ type OutputPaths interface {
27
27
JsFilePath () string
28
28
}
29
29
30
- type DeclareModifier uint8
31
-
32
- const (
33
- DeclareModifierNone DeclareModifier = 0
34
- DeclareModifierEligible DeclareModifier = 1
35
- DeclareModifierEnforced DeclareModifier = 2
36
- )
37
-
38
30
// Used to be passed in the TransformationContext, which is now just an EmitContext
39
31
type DeclarationEmitHost interface {
40
32
modulespecifiers.ModuleSpecifierGenerationHost
@@ -1860,6 +1852,8 @@ func (tx *DeclarationTransformer) transformExpandoAssignment(node *ast.BinaryExp
1860
1852
}
1861
1853
1862
1854
name := tx .Factory ().NewIdentifier (ns .Text ())
1855
+ tx .transformExpandoHost (name , declaration )
1856
+
1863
1857
synthesizedNamespace := tx .Factory ().NewModuleDeclaration (nil /*modifiers*/ , ast .KindNamespaceKeyword , name , tx .Factory ().NewModuleBlock (tx .Factory ().NewNodeList ([]* ast.Node {})))
1864
1858
synthesizedNamespace .Parent = tx .enclosingDeclaration
1865
1859
@@ -1899,8 +1893,6 @@ func (tx *DeclarationTransformer) transformExpandoAssignment(node *ast.BinaryExp
1899
1893
statements = append (statements , tx .Factory ().NewExportDeclaration (nil /*modifiers*/ , false /*isTypeOnly*/ , namedExports , nil /*moduleSpecifier*/ , nil /*attributes*/ ))
1900
1894
}
1901
1895
1902
- tx .transformExpandoHost (name , declaration )
1903
-
1904
1896
flags := tx .host .GetEffectiveDeclarationFlags (tx .EmitContext ().ParseNode (declaration ), ast .ModifierFlagsAll )
1905
1897
modifierFlags := ast .ModifierFlagsAmbient
1906
1898
@@ -1940,41 +1932,13 @@ func (tx *DeclarationTransformer) transformExpandoHost(name *ast.Node, declarati
1940
1932
modifiers := tx .Factory ().NewModifierList (ast .CreateModifiersFromModifierFlags (modifierFlags , tx .Factory ().NewModifier ))
1941
1933
replacement := make ([]* ast.Node , 0 )
1942
1934
1943
- var typeParameters * ast.TypeParameterList
1944
- var parameters * ast.ParameterList
1945
- var returnType * ast.Node
1946
- var asteriskToken * ast.TokenNode
1947
-
1948
1935
if ast .IsFunctionDeclaration (declaration ) {
1949
- fn := declaration .AsFunctionDeclaration ()
1950
- typeParameters = tx .ensureTypeParams (fn .AsNode (), fn .TypeParameters )
1951
- parameters = tx .updateParamList (fn .AsNode (), fn .Parameters )
1952
- returnType = tx .ensureType (fn .AsNode (), false )
1953
- asteriskToken = fn .AsteriskToken
1936
+ typeParameters , parameters , asteriskToken := extractExpandoHostParams (declaration )
1937
+ replacement = append (replacement , tx .Factory ().UpdateFunctionDeclaration (declaration .AsFunctionDeclaration (), modifiers , asteriskToken , declaration .Name (), tx .ensureTypeParams (declaration , typeParameters ), tx .updateParamList (declaration , parameters ), tx .ensureType (declaration , false ), nil /*fullSignature*/ , nil /*body*/ ))
1954
1938
} else if ast .IsVariableDeclaration (declaration ) && ast .IsFunctionExpressionOrArrowFunction (declaration .Initializer ()) {
1955
- if ast .IsFunctionExpression (declaration .Initializer ()) {
1956
- fn := declaration .Initializer ().AsFunctionExpression ()
1957
- typeParameters = tx .ensureTypeParams (fn .AsNode (), fn .TypeParameters )
1958
- parameters = tx .updateParamList (fn .AsNode (), fn .Parameters )
1959
- returnType = tx .ensureType (fn .AsNode (), false )
1960
- asteriskToken = fn .AsteriskToken
1961
- } else if ast .IsArrowFunction (declaration .Initializer ()) {
1962
- fn := declaration .Initializer ().AsArrowFunction ()
1963
- typeParameters = tx .ensureTypeParams (fn .AsNode (), fn .TypeParameters )
1964
- parameters = tx .updateParamList (fn .AsNode (), fn .Parameters )
1965
- returnType = tx .ensureType (fn .AsNode (), false )
1966
- asteriskToken = fn .AsteriskToken
1967
- } else {
1968
- return
1969
- }
1970
- } else {
1971
- return
1972
- }
1973
-
1974
- if ast .IsFunctionDeclaration (declaration ) {
1975
- replacement = append (replacement , tx .Factory ().UpdateFunctionDeclaration (root .AsFunctionDeclaration (), modifiers , asteriskToken , root .Name (), typeParameters , parameters , returnType , nil /*fullSignature*/ , nil /*body*/ ))
1976
- } else if ast .IsVariableDeclaration (declaration ) {
1977
- replacement = append (replacement , tx .Factory ().NewFunctionDeclaration (modifiers , asteriskToken , tx .Factory ().NewIdentifier (name .Text ()), typeParameters , parameters , returnType , nil /*fullSignature*/ , nil /*body*/ ))
1939
+ fn := declaration .Initializer ()
1940
+ typeParameters , parameters , asteriskToken := extractExpandoHostParams (fn )
1941
+ replacement = append (replacement , tx .Factory ().NewFunctionDeclaration (modifiers , asteriskToken , tx .Factory ().NewIdentifier (name .Text ()), tx .ensureTypeParams (fn , typeParameters ), tx .updateParamList (fn , parameters ), tx .ensureType (fn , false ), nil /*fullSignature*/ , nil /*body*/ ))
1978
1942
} else {
1979
1943
return
1980
1944
}
@@ -1986,3 +1950,17 @@ func (tx *DeclarationTransformer) transformExpandoHost(name *ast.Node, declarati
1986
1950
tx .expandoHosts .Add (id )
1987
1951
tx .lateStatementReplacementMap [id ] = tx .Factory ().NewSyntaxList (replacement )
1988
1952
}
1953
+
1954
+ func extractExpandoHostParams (node * ast.Node ) (typeParameters * ast.TypeParameterList , parameters * ast.ParameterList , asteriskToken * ast.TokenNode ) {
1955
+ switch node .Kind {
1956
+ case ast .KindFunctionExpression :
1957
+ fn := node .AsFunctionExpression ()
1958
+ return fn .TypeParameters , fn .Parameters , fn .AsteriskToken
1959
+ case ast .KindArrowFunction :
1960
+ fn := node .AsArrowFunction ()
1961
+ return fn .TypeParameters , fn .Parameters , fn .AsteriskToken
1962
+ default :
1963
+ fn := node .AsFunctionDeclaration ()
1964
+ return fn .TypeParameters , fn .Parameters , fn .AsteriskToken
1965
+ }
1966
+ }
0 commit comments