Skip to content

Commit c872613

Browse files
authored
Only transform expando assignments that wont be represented elsewhere in the emit already (#3741)
1 parent 5c67e17 commit c872613

6 files changed

Lines changed: 22 additions & 147 deletions

File tree

internal/transformers/declarations/transform.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2216,6 +2216,14 @@ func (tx *DeclarationTransformer) transformExpandoAssignment(node *ast.BinaryExp
22162216
return nil
22172217
}
22182218

2219+
if ast.IsFunctionDeclaration(declaration) && declaration.FunctionLikeData().FullSignature != nil {
2220+
return nil
2221+
}
2222+
2223+
if ast.IsVariableDeclaration(declaration) && !ast.IsFunctionLike(declaration.Initializer()) {
2224+
return nil // We're going to add a type, no need to dupe members with a namespace
2225+
}
2226+
22192227
host := declaration.Symbol()
22202228
if host == nil {
22212229
return nil

testdata/baselines/reference/compiler/jsExpandoAssignmentElementAccess.js

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -13,41 +13,3 @@ declare var x: {
1313
if: number;
1414
else: number;
1515
};
16-
declare namespace x {
17-
var _a: number;
18-
export { _a as if };
19-
}
20-
declare namespace x {
21-
var _b: number;
22-
export { _b as else };
23-
}
24-
25-
26-
//// [DtsFileErrors]
27-
28-
29-
repro.d.ts(1,13): error TS2300: Duplicate identifier 'x'.
30-
repro.d.ts(5,19): error TS2300: Duplicate identifier 'x'.
31-
repro.d.ts(9,19): error TS2300: Duplicate identifier 'x'.
32-
33-
34-
==== repro.d.ts (3 errors) ====
35-
declare var x: {
36-
~
37-
!!! error TS2300: Duplicate identifier 'x'.
38-
if: number;
39-
else: number;
40-
};
41-
declare namespace x {
42-
~
43-
!!! error TS2300: Duplicate identifier 'x'.
44-
var _a: number;
45-
export { _a as if };
46-
}
47-
declare namespace x {
48-
~
49-
!!! error TS2300: Duplicate identifier 'x'.
50-
var _b: number;
51-
export { _b as else };
52-
}
53-

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

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,6 @@ declare var Ns: {
8787
};
8888
};
8989
};
90-
declare namespace Ns {
91-
var C1: {
92-
new (): {
93-
method(): number;
94-
};
95-
};
96-
}
9790
/** @implements {A} */
9891
declare var C2: {
9992
new (): {
@@ -117,10 +110,3 @@ declare class CC {
117110
};
118111
}
119112
declare var C5: any;
120-
declare namespace Ns {
121-
var C5: {
122-
new (): {
123-
method(): number;
124-
};
125-
};
126-
}

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

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -14,42 +14,3 @@ declare const foo: {
1414
blah: number;
1515
};
1616
};
17-
declare namespace foo {
18-
var baz: {
19-
blah: number;
20-
};
21-
}
22-
declare namespace foo {
23-
var blah: number;
24-
}
25-
26-
27-
//// [DtsFileErrors]
28-
29-
30-
a.d.ts(1,15): error TS2451: Cannot redeclare block-scoped variable 'foo'.
31-
a.d.ts(6,19): error TS2451: Cannot redeclare block-scoped variable 'foo'.
32-
a.d.ts(11,19): error TS2451: Cannot redeclare block-scoped variable 'foo'.
33-
34-
35-
==== a.d.ts (3 errors) ====
36-
declare const foo: {
37-
~~~
38-
!!! error TS2451: Cannot redeclare block-scoped variable 'foo'.
39-
baz: {
40-
blah: number;
41-
};
42-
};
43-
declare namespace foo {
44-
~~~
45-
!!! error TS2451: Cannot redeclare block-scoped variable 'foo'.
46-
var baz: {
47-
blah: number;
48-
};
49-
}
50-
declare namespace foo {
51-
~~~
52-
!!! error TS2451: Cannot redeclare block-scoped variable 'foo'.
53-
var blah: number;
54-
}
55-

testdata/baselines/reference/submoduleAccepted/conformance/jsdocImplements_class.js.diff

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@
44
/** @implements {A} */
55
declare class B3 implements A {
66
}
7+
-declare namespace Ns {
8+
- export { C1 };
9+
- export let C5: {
10+
- new (): {
11+
- method(): number;
12+
- };
13+
- };
14+
-}
715
+declare var Ns: {
816
+ /** @implements {A} */
917
+ C1: {
@@ -18,14 +26,9 @@
1826
+ };
1927
+ };
2028
+};
21-
declare namespace Ns {
22-
- export { C1 };
23-
- export let C5: {
24-
+ var C1: {
25-
new (): {
26-
method(): number;
27-
};
28-
@@= skipped -14, +27 lines =@@
29+
/** @implements {A} */
30+
declare var C2: {
31+
new (): {
2932
method(): number;
3033
};
3134
};
@@ -43,7 +46,7 @@
4346
declare class CC {
4447
/** @implements {A} */
4548
C4: {
46-
@@= skipped -12, +17 lines =@@
49+
@@= skipped -26, +37 lines =@@
4750
};
4851
}
4952
declare var C5: any;
@@ -52,10 +55,4 @@
5255
-}
5356
-declare class C3 implements A {
5457
- method(): number;
55-
+declare namespace Ns {
56-
+ var C5: {
57-
+ new (): {
58-
+ method(): number;
59-
+ };
60-
+ };
61-
}
58+
-}

testdata/baselines/reference/submoduleTriaged/conformance/typeFromPropertyAssignment39.js.diff

Lines changed: 1 addition & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -13,43 +13,4 @@
1313
+ baz: {
1414
+ blah: number;
1515
+ };
16-
+};
17-
+declare namespace foo {
18-
+ var baz: {
19-
+ blah: number;
20-
+ };
21-
+}
22-
+declare namespace foo {
23-
+ var blah: number;
24-
+}
25-
+
26-
+
27-
+//// [DtsFileErrors]
28-
+
29-
+
30-
+a.d.ts(1,15): error TS2451: Cannot redeclare block-scoped variable 'foo'.
31-
+a.d.ts(6,19): error TS2451: Cannot redeclare block-scoped variable 'foo'.
32-
+a.d.ts(11,19): error TS2451: Cannot redeclare block-scoped variable 'foo'.
33-
+
34-
+
35-
+==== a.d.ts (3 errors) ====
36-
+ declare const foo: {
37-
+ ~~~
38-
+!!! error TS2451: Cannot redeclare block-scoped variable 'foo'.
39-
+ baz: {
40-
+ blah: number;
41-
+ };
42-
+ };
43-
+ declare namespace foo {
44-
+ ~~~
45-
+!!! error TS2451: Cannot redeclare block-scoped variable 'foo'.
46-
+ var baz: {
47-
+ blah: number;
48-
+ };
49-
+ }
50-
+ declare namespace foo {
51-
+ ~~~
52-
+!!! error TS2451: Cannot redeclare block-scoped variable 'foo'.
53-
+ var blah: number;
54-
+ }
55-
+
16+
+};

0 commit comments

Comments
 (0)