Skip to content

Commit 5f6eb6e

Browse files
committed
exclude expando initializers
1 parent 9b5b919 commit 5f6eb6e

21 files changed

+60
-216
lines changed

internal/transformers/declarations/transform.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1826,11 +1826,17 @@ func (tx *DeclarationTransformer) visitExpressionStatement(node *ast.ExpressionS
18261826

18271827
func (tx *DeclarationTransformer) transformExpandoAssignment(node *ast.BinaryExpression) *ast.Node {
18281828
left := node.Left
1829+
right := node.Right
1830+
18291831
symbol := node.Symbol
18301832
if symbol == nil || symbol.Flags&ast.SymbolFlagsAssignment == 0 {
18311833
return nil
18321834
}
18331835

1836+
if ast.IsExpandoInitializer(right) {
1837+
return nil
1838+
}
1839+
18341840
ns := ast.GetLeftmostAccessExpression(left)
18351841
if ns == nil || ns.Kind != ast.KindIdentifier {
18361842
return nil

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 function Point(x: number, y: number): Point;
39+
export declare const Point: {
40+
(x: number, y: number): Point;
41+
zero: () => Point;
42+
};
4043
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: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
11
--- old.declarationEmitExpandoWithGenericConstraint.js
22
+++ new.declarationEmitExpandoWithGenericConstraint.js
3-
@@= skipped -35, +35 lines =@@
4-
readonly a: p;
5-
readonly b: p;
3+
@@= skipped -37, +37 lines =@@
64
}
7-
-export declare const Point: {
8-
- (x: number, y: number): Point;
5+
export declare const Point: {
6+
(x: number, y: number): Point;
97
- zero(): Point;
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-
+}
8+
+ zero: () => Point;
9+
};
10+
export declare const Rect: <p extends Point>(a: p, b: p) => Rect<p>;

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

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,6 @@ foo.length = 10;
2525

2626
//// [isolatedDeclarationErrorsExpandoFunctions.d.ts]
2727
export declare function foo(): void;
28-
export declare namespace foo {
29-
const apply: () => void;
30-
}
31-
export declare namespace foo {
32-
const call: () => void;
33-
}
34-
export declare namespace foo {
35-
const bind: () => void;
36-
}
37-
export declare namespace foo {
38-
const caller: () => void;
39-
}
40-
export declare namespace foo {
41-
const toString: () => void;
42-
}
4328
export declare namespace foo {
4429
const length: number;
4530
}
@@ -51,27 +36,12 @@ export declare namespace foo {
5136
//// [DtsFileErrors]
5237

5338

54-
isolatedDeclarationErrorsExpandoFunctions.d.ts(18,11): error TS2451: Cannot redeclare block-scoped variable 'length'.
55-
isolatedDeclarationErrorsExpandoFunctions.d.ts(21,11): error TS2451: Cannot redeclare block-scoped variable 'length'.
39+
isolatedDeclarationErrorsExpandoFunctions.d.ts(3,11): error TS2451: Cannot redeclare block-scoped variable 'length'.
40+
isolatedDeclarationErrorsExpandoFunctions.d.ts(6,11): error TS2451: Cannot redeclare block-scoped variable 'length'.
5641

5742

5843
==== isolatedDeclarationErrorsExpandoFunctions.d.ts (2 errors) ====
5944
export declare function foo(): void;
60-
export declare namespace foo {
61-
const apply: () => void;
62-
}
63-
export declare namespace foo {
64-
const call: () => void;
65-
}
66-
export declare namespace foo {
67-
const bind: () => void;
68-
}
69-
export declare namespace foo {
70-
const caller: () => void;
71-
}
72-
export declare namespace foo {
73-
const toString: () => void;
74-
}
7545
export declare namespace foo {
7646
const length: number;
7747
~~~~~~

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

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,6 @@
99
+//// [isolatedDeclarationErrorsExpandoFunctions.d.ts]
1010
+export declare function foo(): void;
1111
+export declare namespace foo {
12-
+ const apply: () => void;
13-
+}
14-
+export declare namespace foo {
15-
+ const call: () => void;
16-
+}
17-
+export declare namespace foo {
18-
+ const bind: () => void;
19-
+}
20-
+export declare namespace foo {
21-
+ const caller: () => void;
22-
+}
23-
+export declare namespace foo {
24-
+ const toString: () => void;
25-
+}
26-
+export declare namespace foo {
2712
+ const length: number;
2813
+}
2914
+export declare namespace foo {
@@ -34,28 +19,13 @@
3419
+//// [DtsFileErrors]
3520
+
3621
+
37-
+isolatedDeclarationErrorsExpandoFunctions.d.ts(18,11): error TS2451: Cannot redeclare block-scoped variable 'length'.
38-
+isolatedDeclarationErrorsExpandoFunctions.d.ts(21,11): error TS2451: Cannot redeclare block-scoped variable 'length'.
22+
+isolatedDeclarationErrorsExpandoFunctions.d.ts(3,11): error TS2451: Cannot redeclare block-scoped variable 'length'.
23+
+isolatedDeclarationErrorsExpandoFunctions.d.ts(6,11): error TS2451: Cannot redeclare block-scoped variable 'length'.
3924
+
4025
+
4126
+==== isolatedDeclarationErrorsExpandoFunctions.d.ts (2 errors) ====
4227
+ export declare function foo(): void;
4328
+ export declare namespace foo {
44-
+ const apply: () => void;
45-
+ }
46-
+ export declare namespace foo {
47-
+ const call: () => void;
48-
+ }
49-
+ export declare namespace foo {
50-
+ const bind: () => void;
51-
+ }
52-
+ export declare namespace foo {
53-
+ const caller: () => void;
54-
+ }
55-
+ export declare namespace foo {
56-
+ const toString: () => void;
57-
+ }
58-
+ export declare namespace foo {
5929
+ const length: number;
6030
+ ~~~~~~
6131
+!!! error TS2451: Cannot redeclare block-scoped variable 'length'.

testdata/baselines/reference/submodule/conformance/commonJSImportNestedClassTypeReference.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,6 @@ function f(k) {
3838

3939

4040
//// [mod1.d.ts]
41-
declare namespace NS {
42-
const K: {
43-
new (): {
44-
values(): /*elided*/ any;
45-
};
46-
};
47-
}
4841
export var K = NS.K;
4942
export {};
5043
//// [main.d.ts]

testdata/baselines/reference/submodule/conformance/commonJSImportNestedClassTypeReference.js.diff

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,8 @@
2222
-export var K: {
2323
- new (): {
2424
- values(): /*elided*/ any;
25-
+declare namespace NS {
26-
+ const K: {
27-
+ new (): {
28-
+ values(): /*elided*/ any;
29-
+ };
30-
};
25+
- };
3126
-};
32-
+}
3327
+export var K = NS.K;
3428
+export {};
3529
//// [main.d.ts]

testdata/baselines/reference/submodule/conformance/jsDeclarationsClassMethod.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,6 @@ C2.staticProp = function (x, y) {
129129

130130
//// [jsDeclarationsClassMethod.d.ts]
131131
declare function C1(): void;
132-
declare namespace C1 {
133-
const staticProp: (x: any, y: any) => any;
134-
}
135132
declare class C2 {
136133
/**
137134
* A comment method1
@@ -141,6 +138,3 @@ declare class C2 {
141138
*/
142139
method1(x: number, y: number): number;
143140
}
144-
declare namespace C2 {
145-
const staticProp: (x: any, y: any) => any;
146-
}

testdata/baselines/reference/submodule/conformance/jsDeclarationsClassMethod.js.diff

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,19 @@
2020
- */
2121
- method(x: number, y: number): number;
2222
-}
23-
declare namespace C1 {
23+
-declare namespace C1 {
2424
- /**
2525
- * A comment staticProp
2626
- * @param {number} x
2727
- * @param {number} y
2828
- * @returns {number}
2929
- */
3030
- function staticProp(x: number, y: number): number;
31-
+ const staticProp: (x: any, y: any) => any;
32-
}
31+
-}
3332
declare class C2 {
3433
/**
35-
@@= skipped -33, +11 lines =@@
34+
* A comment method1
35+
@@= skipped -33, +8 lines =@@
3636
* @returns {number}
3737
*/
3838
method1(x: number, y: number): number;
@@ -43,14 +43,13 @@
4343
- * @returns {number}
4444
- */
4545
- method2(x: number, y: number): number;
46-
}
47-
declare namespace C2 {
46+
-}
47+
-declare namespace C2 {
4848
- /**
4949
- * A comment staticProp
5050
- * @param {number} x
5151
- * @param {number} y
5252
- * @returns {number}
5353
- */
5454
- function staticProp(x: number, y: number): number;
55-
+ const staticProp: (x: any, y: any) => any;
5655
}

testdata/baselines/reference/submodule/conformance/jsDeclarationsClassStatic.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,6 @@ module.exports.Strings = Strings;
5252

5353

5454
//// [source.d.ts]
55-
declare namespace Handler {
56-
const statische: () => void;
57-
}
5855
export = Handler;
5956
export var Strings = Strings;
6057
export type HandlerOptions = {

0 commit comments

Comments
 (0)