Skip to content

Commit fb94aa2

Browse files
committed
skip emitting function properties
1 parent 2600771 commit fb94aa2

23 files changed

+373
-208
lines changed

internal/transformers/declarations/transform.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1842,13 +1842,6 @@ func (tx *DeclarationTransformer) transformExpandoAssignment(node *ast.BinaryExp
18421842
return nil
18431843
}
18441844

1845-
if ast.IsVariableDeclaration(declaration) {
1846-
id := ast.GetNodeId(tx.EmitContext().MostOriginal(declaration.Parent.Parent))
1847-
if tx.lateStatementReplacementMap[id] != nil {
1848-
return nil
1849-
}
1850-
}
1851-
18521845
host := declaration.Symbol()
18531846
if host == nil {
18541847
return nil
@@ -1861,6 +1854,11 @@ func (tx *DeclarationTransformer) transformExpandoAssignment(node *ast.BinaryExp
18611854
}
18621855

18631856
tx.transformExpandoHost(name, declaration)
1857+
1858+
if ast.IsFunctionDeclaration(declaration) && !shouldEmitFunctionProperties(declaration.AsFunctionDeclaration()) {
1859+
return nil
1860+
}
1861+
18641862
isNonContextualKeywordName := ast.IsNonContextualKeyword(scanner.StringToToken(property))
18651863
exportName := core.IfElse(isNonContextualKeywordName, tx.Factory().NewGeneratedNameForNode(left), tx.Factory().NewIdentifier(property))
18661864

testdata/baselines/reference/submodule/compiler/declarationEmitExpandoWithGenericConstraint.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ export interface Rect<p extends Point> {
3636
readonly a: p;
3737
readonly b: p;
3838
}
39-
export declare const Point: {
40-
(x: number, y: number): Point;
41-
zero: () => Point;
42-
};
39+
export declare function Point(x: number, y: number): Point;
4340
export declare const Rect: <p extends Point>(a: p, b: p) => Rect<p>;
41+
export declare namespace Point {
42+
const zero: () => Point;
43+
}
Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
--- old.declarationEmitExpandoWithGenericConstraint.js
22
+++ new.declarationEmitExpandoWithGenericConstraint.js
3-
@@= skipped -37, +37 lines =@@
3+
@@= skipped -35, +35 lines =@@
4+
readonly a: p;
5+
readonly b: p;
46
}
5-
export declare const Point: {
6-
(x: number, y: number): Point;
7+
-export declare const Point: {
8+
- (x: number, y: number): Point;
79
- zero(): Point;
8-
+ zero: () => Point;
9-
};
10-
export declare const Rect: <p extends Point>(a: p, b: p) => Rect<p>;
10+
-};
11+
+export declare function Point(x: number, y: number): Point;
12+
export declare const Rect: <p extends Point>(a: p, b: p) => Rect<p>;
13+
+export declare namespace Point {
14+
+ const zero: () => Point;
15+
+}

testdata/baselines/reference/submodule/compiler/declarationEmitFunctionDuplicateNamespace.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,3 @@ f.x = 2;
2020
//// [declarationEmitFunctionDuplicateNamespace.d.ts]
2121
declare function f(a: 0): 0;
2222
declare function f(a: 1): 1;
23-
declare namespace f {
24-
const x: number;
25-
}
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
--- old.declarationEmitFunctionDuplicateNamespace.js
22
+++ new.declarationEmitFunctionDuplicateNamespace.js
3-
@@= skipped -20, +20 lines =@@
3+
@@= skipped -19, +19 lines =@@
4+
//// [declarationEmitFunctionDuplicateNamespace.d.ts]
45
declare function f(a: 0): 0;
56
declare function f(a: 1): 1;
6-
declare namespace f {
7+
-declare namespace f {
78
- var x: number;
8-
+ const x: number;
9-
}
9+
-}

testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundAssignments2.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -136,14 +136,14 @@ export declare function decl7(): void;
136136
export declare function decl8(): void;
137137
export declare function decl9(): void;
138138
export declare function decl10(): void;
139-
export declare const arrow: {
140-
(): void;
141-
B: string;
142-
};
143-
export declare const arrow2: {
144-
(): void;
145-
C: number;
146-
};
139+
export declare function arrow(): void;
140+
export declare namespace arrow {
141+
const B: string;
142+
}
143+
export declare function arrow2(): void;
144+
export declare namespace arrow2 {
145+
const C: number;
146+
}
147147
export declare const arrow3: {
148148
(): void;
149149
77: number;

testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundAssignments2.js.diff

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,22 @@
2828
-export declare namespace decl9 { }
2929
export declare function decl10(): void;
3030
-export declare namespace decl10 { }
31-
export declare const arrow: {
31+
-export declare const arrow: {
32+
- (): void;
33+
- B: string;
34+
-};
35+
-export declare const arrow2: {
36+
- (): void;
37+
- C: number;
38+
-};
39+
+export declare function arrow(): void;
40+
+export declare namespace arrow {
41+
+ const B: string;
42+
+}
43+
+export declare function arrow2(): void;
44+
+export declare namespace arrow2 {
45+
+ const C: number;
46+
+}
47+
export declare const arrow3: {
3248
(): void;
33-
B: string;
49+
77: number;

testdata/baselines/reference/submodule/compiler/expandoFunctionExpressionsWithDynamicNames.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ exports.expr2[s] = 0;
2727

2828

2929
//// [expandoFunctionExpressionsWithDynamicNames.d.ts]
30-
export declare const expr: {
31-
(): void;
32-
X: number;
33-
};
34-
export declare const expr2: {
35-
(): void;
36-
X: number;
37-
};
30+
export declare function expr(): void;
31+
export declare namespace expr {
32+
const X: number;
33+
}
34+
export declare function expr2(): void;
35+
export declare namespace expr2 {
36+
const X: number;
37+
}

testdata/baselines/reference/submodule/compiler/expandoFunctionExpressionsWithDynamicNames.js.diff

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,24 @@
1010
+// https://github.com/microsoft/TypeScript/issues/54809
1111
const s = "X";
1212
const expr = () => { };
13-
exports.expr = expr;
13+
exports.expr = expr;
14+
@@= skipped -13, +13 lines =@@
15+
16+
17+
//// [expandoFunctionExpressionsWithDynamicNames.d.ts]
18+
-export declare const expr: {
19+
- (): void;
20+
- X: number;
21+
-};
22+
-export declare const expr2: {
23+
- (): void;
24+
- X: number;
25+
-};
26+
+export declare function expr(): void;
27+
+export declare namespace expr {
28+
+ const X: number;
29+
+}
30+
+export declare function expr2(): void;
31+
+export declare namespace expr2 {
32+
+ const X: number;
33+
+}

testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrors.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ declare function errorOnAssignmentBelowDecl(): void;
2525
declare namespace errorOnAssignmentBelowDecl {
2626
const a: string;
2727
}
28-
declare const errorOnAssignmentBelow: {
29-
(): void;
30-
a: string;
31-
};
32-
declare const errorOnMissingReturn: {
33-
(): void;
34-
a: string;
35-
};
28+
declare function errorOnAssignmentBelow(): void;
29+
declare namespace errorOnAssignmentBelow {
30+
const a: string;
31+
}
32+
declare function errorOnMissingReturn(): void;
33+
declare namespace errorOnMissingReturn {
34+
const a: string;
35+
}

0 commit comments

Comments
 (0)