Skip to content

Commit 8e08f38

Browse files
authored
fix(53006): generate let in namespaces for expando (microsoft#53206)
1 parent c5b2884 commit 8e08f38

35 files changed

+260
-150
lines changed

src/compiler/checker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9460,7 +9460,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
94609460
else {
94619461
const statement = factory.createVariableStatement(/*modifiers*/ undefined, factory.createVariableDeclarationList([
94629462
factory.createVariableDeclaration(varName, /*exclamationToken*/ undefined, serializeTypeForDeclaration(context, typeToSerialize, symbol, enclosingDeclaration, includePrivateSymbol, bundled))
9463-
], NodeFlags.Const));
9463+
], context.enclosingDeclaration?.kind === SyntaxKind.ModuleDeclaration ? NodeFlags.Let : NodeFlags.Const));
94649464
// Inlined JSON types exported with [module.]exports= will already emit an export=, so should use `declare`.
94659465
// Otherwise, the type itself should be exported.
94669466
addResult(statement,

tests/baselines/reference/argumentsReferenceInConstructor5_Js.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class A {
2727

2828
//// [a.d.ts]
2929
declare namespace bar {
30-
const arguments: {};
30+
let arguments: {};
3131
}
3232
declare class A {
3333
/**

tests/baselines/reference/argumentsReferenceInMethod5_Js.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class A {
2525

2626
//// [a.d.ts]
2727
declare namespace bar {
28-
const arguments: {};
28+
let arguments: {};
2929
}
3030
declare class A {
3131
/**

tests/baselines/reference/expandoOnAlias.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ config.y;
2727
export class Vue {
2828
}
2929
export namespace config {
30-
const x: number;
30+
let x: number;
3131
}
3232
//// [test.d.ts]
3333
export {};

tests/baselines/reference/jsDeclarationsClassExtendsVisibility.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,6 @@ declare namespace Foo {
6565
}
6666
import Bar = require("./bar");
6767
declare namespace Strings {
68-
const a: string;
69-
const b: string;
68+
let a: string;
69+
let b: string;
7070
}

tests/baselines/reference/jsDeclarationsClassStatic.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ declare namespace Handler {
6363
}
6464
declare function statische(): void;
6565
declare namespace Strings {
66-
const a: string;
67-
const b: string;
66+
let a: string;
67+
let b: string;
6868
}
6969
type HandlerOptions = {
7070
/**
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
//// [tests/cases/conformance/jsdoc/declarations/jsDeclarationsClassStatic2.ts] ////
2+
3+
//// [Foo.js]
4+
class Base {
5+
static foo = "";
6+
}
7+
export class Foo extends Base {}
8+
Foo.foo = "foo";
9+
10+
//// [Bar.ts]
11+
import { Foo } from "./Foo.js";
12+
13+
class Bar extends Foo {}
14+
Bar.foo = "foo";
15+
16+
17+
18+
19+
//// [Foo.d.ts]
20+
export class Foo extends Base {
21+
}
22+
export namespace Foo {
23+
let foo: string;
24+
}
25+
declare class Base {
26+
static foo: string;
27+
}
28+
export {};
29+
//// [Bar.d.ts]
30+
export {};
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
=== tests/cases/conformance/jsdoc/declarations/Foo.js ===
2+
class Base {
3+
>Base : Symbol(Base, Decl(Foo.js, 0, 0))
4+
5+
static foo = "";
6+
>foo : Symbol(Base.foo, Decl(Foo.js, 0, 12))
7+
}
8+
export class Foo extends Base {}
9+
>Foo : Symbol(Foo, Decl(Foo.js, 2, 1), Decl(Foo.js, 3, 32))
10+
>Base : Symbol(Base, Decl(Foo.js, 0, 0))
11+
12+
Foo.foo = "foo";
13+
>Foo.foo : Symbol(Foo.foo, Decl(Foo.js, 3, 32))
14+
>Foo : Symbol(Foo, Decl(Foo.js, 2, 1), Decl(Foo.js, 3, 32))
15+
>foo : Symbol(Foo.foo, Decl(Foo.js, 3, 32))
16+
17+
=== tests/cases/conformance/jsdoc/declarations/Bar.ts ===
18+
import { Foo } from "./Foo.js";
19+
>Foo : Symbol(Foo, Decl(Bar.ts, 0, 8))
20+
21+
class Bar extends Foo {}
22+
>Bar : Symbol(Bar, Decl(Bar.ts, 0, 31))
23+
>Foo : Symbol(Foo, Decl(Bar.ts, 0, 8))
24+
25+
Bar.foo = "foo";
26+
>Bar.foo : Symbol(Foo.foo, Decl(Foo.js, 3, 32))
27+
>Bar : Symbol(Bar, Decl(Bar.ts, 0, 31))
28+
>foo : Symbol(Foo.foo, Decl(Foo.js, 3, 32))
29+
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
=== tests/cases/conformance/jsdoc/declarations/Foo.js ===
2+
class Base {
3+
>Base : Base
4+
5+
static foo = "";
6+
>foo : string
7+
>"" : ""
8+
}
9+
export class Foo extends Base {}
10+
>Foo : Foo
11+
>Base : Base
12+
13+
Foo.foo = "foo";
14+
>Foo.foo = "foo" : "foo"
15+
>Foo.foo : string
16+
>Foo : typeof Foo
17+
>foo : string
18+
>"foo" : "foo"
19+
20+
=== tests/cases/conformance/jsdoc/declarations/Bar.ts ===
21+
import { Foo } from "./Foo.js";
22+
>Foo : typeof Foo
23+
24+
class Bar extends Foo {}
25+
>Bar : Bar
26+
>Foo : Foo
27+
28+
Bar.foo = "foo";
29+
>Bar.foo = "foo" : "foo"
30+
>Bar.foo : string
31+
>Bar : typeof Bar
32+
>foo : string
33+
>"foo" : "foo"
34+

tests/baselines/reference/jsDeclarationsClassStaticMethodAugmentation.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@ export class Clazz {
2525
export namespace Clazz {
2626
function method(): void;
2727
namespace method {
28-
const prop: number;
28+
let prop: number;
2929
}
3030
}

tests/baselines/reference/jsDeclarationsConstsAsNamespacesWithReferences.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export const brandColors = {
1818

1919
//// [index.d.ts]
2020
export namespace colors {
21-
const royalBlue: string;
21+
let royalBlue: string;
2222
}
2323
export namespace brandColors {
2424
import purple = colors.royalBlue;

tests/baselines/reference/jsDeclarationsEnumTag.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -113,15 +113,15 @@ export function consume(t: Target, s: Second, f: Fs): void;
113113
export function ff(s: string): any;
114114
export type Target = string;
115115
export namespace Target {
116-
const START: string;
117-
const MIDDLE: string;
118-
const END: string;
119-
const OK_I_GUESS: number;
116+
let START: string;
117+
let MIDDLE: string;
118+
let END: string;
119+
let OK_I_GUESS: number;
120120
}
121121
export type Second = number;
122122
export namespace Second {
123-
const OK: number;
124-
const FINE: number;
123+
let OK: number;
124+
let FINE: number;
125125
}
126126
export type Fs = (arg0: number) => number;
127127
export namespace Fs {

tests/baselines/reference/jsDeclarationsExportAssignedClassInstance3.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,5 @@ module.exports.additional = 20;
2121

2222

2323
//// [index.d.ts]
24-
export const member: number;
25-
export const additional: 20;
24+
export let member: number;
25+
export let additional: 20;

tests/baselines/reference/jsDeclarationsExportAssignmentExpressionPlusSecondary.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ module.exports.Strings = Strings;
3030

3131
//// [index.d.ts]
3232
export namespace Strings {
33-
const a: string;
34-
const b: string;
33+
let a: string;
34+
let b: string;
3535
}
36-
export declare const thing: string;
37-
export declare const also: string;
36+
export declare let thing: string;
37+
export declare let also: string;
3838
export declare namespace desc {
39-
const item: string;
39+
let item: string;
4040
}

tests/baselines/reference/jsDeclarationsExportAssignmentWithKeywordName.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ module.exports = {
2121

2222
//// [index.d.ts]
2323
export var x: number;
24-
declare const _extends: string;
24+
declare let _extends: string;
2525
export declare namespace more {
26-
const others: string[];
26+
let others: string[];
2727
}
2828
export { _extends as extends };

tests/baselines/reference/jsDeclarationsExportDefinePropertyEmit.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ Object.defineProperty(module.exports, "j", { value: function j() { } });
114114
export function a(): void;
115115
export function b(): void;
116116
export namespace b {
117-
const cat: string;
117+
let cat: string;
118118
}
119119
/**
120120
* @param {number} a

tests/baselines/reference/jsDeclarationsExportSubAssignments.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,6 @@ declare namespace Foo {
2929
export { Strings };
3030
}
3131
declare namespace Strings {
32-
const a: string;
33-
const b: string;
32+
let a: string;
33+
let b: string;
3434
}

tests/baselines/reference/jsDeclarationsFunctionKeywordProp.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,18 @@ baz.normal = false;
2424
//// [source.d.ts]
2525
declare function foo(): void;
2626
declare namespace foo {
27-
const _null: boolean;
27+
let _null: boolean;
2828
export { _null as null };
2929
}
3030
declare function bar(): void;
3131
declare namespace bar {
32-
const async: boolean;
33-
const normal: boolean;
32+
let async: boolean;
33+
let normal: boolean;
3434
}
3535
declare function baz(): void;
3636
declare namespace baz {
37-
const _class: boolean;
37+
let _class: boolean;
3838
export { _class as class };
39-
const normal_1: boolean;
39+
let normal_1: boolean;
4040
export { normal_1 as normal };
4141
}

0 commit comments

Comments
 (0)