Skip to content

fix(53006): generate let in namespaces for expando #53206

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9438,7 +9438,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
else {
const statement = factory.createVariableStatement(/*modifiers*/ undefined, factory.createVariableDeclarationList([
factory.createVariableDeclaration(varName, /*exclamationToken*/ undefined, serializeTypeForDeclaration(context, typeToSerialize, symbol, enclosingDeclaration, includePrivateSymbol, bundled))
], NodeFlags.Const));
], context.enclosingDeclaration?.kind === SyntaxKind.ModuleDeclaration ? NodeFlags.Let : NodeFlags.Const));
// Inlined JSON types exported with [module.]exports= will already emit an export=, so should use `declare`.
// Otherwise, the type itself should be exported.
addResult(statement,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class A {

//// [a.d.ts]
declare namespace bar {
const arguments: {};
let arguments: {};
}
declare class A {
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class A {

//// [a.d.ts]
declare namespace bar {
const arguments: {};
let arguments: {};
}
declare class A {
/**
Expand Down
2 changes: 1 addition & 1 deletion tests/baselines/reference/expandoOnAlias.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ config.y;
export class Vue {
}
export namespace config {
const x: number;
let x: number;
}
//// [test.d.ts]
export {};
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,6 @@ declare namespace Foo {
}
import Bar = require("./bar");
declare namespace Strings {
const a: string;
const b: string;
let a: string;
let b: string;
}
4 changes: 2 additions & 2 deletions tests/baselines/reference/jsDeclarationsClassStatic.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ declare namespace Handler {
}
declare function statische(): void;
declare namespace Strings {
const a: string;
const b: string;
let a: string;
let b: string;
}
type HandlerOptions = {
/**
Expand Down
30 changes: 30 additions & 0 deletions tests/baselines/reference/jsDeclarationsClassStatic2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//// [tests/cases/conformance/jsdoc/declarations/jsDeclarationsClassStatic2.ts] ////

//// [Foo.js]
class Base {
static foo = "";
}
export class Foo extends Base {}
Foo.foo = "foo";

//// [Bar.ts]
import { Foo } from "./Foo.js";

class Bar extends Foo {}
Bar.foo = "foo";




//// [Foo.d.ts]
export class Foo extends Base {
}
export namespace Foo {
let foo: string;
}
declare class Base {
static foo: string;
}
export {};
//// [Bar.d.ts]
export {};
29 changes: 29 additions & 0 deletions tests/baselines/reference/jsDeclarationsClassStatic2.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
=== tests/cases/conformance/jsdoc/declarations/Foo.js ===
class Base {
>Base : Symbol(Base, Decl(Foo.js, 0, 0))

static foo = "";
>foo : Symbol(Base.foo, Decl(Foo.js, 0, 12))
}
export class Foo extends Base {}
>Foo : Symbol(Foo, Decl(Foo.js, 2, 1), Decl(Foo.js, 3, 32))
>Base : Symbol(Base, Decl(Foo.js, 0, 0))

Foo.foo = "foo";
>Foo.foo : Symbol(Foo.foo, Decl(Foo.js, 3, 32))
>Foo : Symbol(Foo, Decl(Foo.js, 2, 1), Decl(Foo.js, 3, 32))
>foo : Symbol(Foo.foo, Decl(Foo.js, 3, 32))

=== tests/cases/conformance/jsdoc/declarations/Bar.ts ===
import { Foo } from "./Foo.js";
>Foo : Symbol(Foo, Decl(Bar.ts, 0, 8))

class Bar extends Foo {}
>Bar : Symbol(Bar, Decl(Bar.ts, 0, 31))
>Foo : Symbol(Foo, Decl(Bar.ts, 0, 8))

Bar.foo = "foo";
>Bar.foo : Symbol(Foo.foo, Decl(Foo.js, 3, 32))
>Bar : Symbol(Bar, Decl(Bar.ts, 0, 31))
>foo : Symbol(Foo.foo, Decl(Foo.js, 3, 32))

34 changes: 34 additions & 0 deletions tests/baselines/reference/jsDeclarationsClassStatic2.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
=== tests/cases/conformance/jsdoc/declarations/Foo.js ===
class Base {
>Base : Base

static foo = "";
>foo : string
>"" : ""
}
export class Foo extends Base {}
>Foo : Foo
>Base : Base

Foo.foo = "foo";
>Foo.foo = "foo" : "foo"
>Foo.foo : string
>Foo : typeof Foo
>foo : string
>"foo" : "foo"

=== tests/cases/conformance/jsdoc/declarations/Bar.ts ===
import { Foo } from "./Foo.js";
>Foo : typeof Foo

class Bar extends Foo {}
>Bar : Bar
>Foo : Foo

Bar.foo = "foo";
>Bar.foo = "foo" : "foo"
>Bar.foo : string
>Bar : typeof Bar
>foo : string
>"foo" : "foo"

Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ export class Clazz {
export namespace Clazz {
function method(): void;
namespace method {
const prop: number;
let prop: number;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const brandColors = {

//// [index.d.ts]
export namespace colors {
const royalBlue: string;
let royalBlue: string;
}
export namespace brandColors {
import purple = colors.royalBlue;
Expand Down
12 changes: 6 additions & 6 deletions tests/baselines/reference/jsDeclarationsEnumTag.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,15 @@ export function consume(t: Target, s: Second, f: Fs): void;
export function ff(s: string): any;
export type Target = string;
export namespace Target {
const START: string;
const MIDDLE: string;
const END: string;
const OK_I_GUESS: number;
let START: string;
let MIDDLE: string;
let END: string;
let OK_I_GUESS: number;
}
export type Second = number;
export namespace Second {
const OK: number;
const FINE: number;
let OK: number;
let FINE: number;
}
export type Fs = (arg0: number) => number;
export namespace Fs {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ module.exports.additional = 20;


//// [index.d.ts]
export const member: number;
export const additional: 20;
export let member: number;
export let additional: 20;
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ module.exports.Strings = Strings;

//// [index.d.ts]
export namespace Strings {
const a: string;
const b: string;
let a: string;
let b: string;
}
export declare const thing: string;
export declare const also: string;
export declare let thing: string;
export declare let also: string;
export declare namespace desc {
const item: string;
let item: string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ module.exports = {

//// [index.d.ts]
export var x: number;
declare const _extends: string;
declare let _extends: string;
export declare namespace more {
const others: string[];
let others: string[];
}
export { _extends as extends };
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ Object.defineProperty(module.exports, "j", { value: function j() { } });
export function a(): void;
export function b(): void;
export namespace b {
const cat: string;
let cat: string;
}
/**
* @param {number} a
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ declare namespace Foo {
export { Strings };
}
declare namespace Strings {
const a: string;
const b: string;
let a: string;
let b: string;
}
10 changes: 5 additions & 5 deletions tests/baselines/reference/jsDeclarationsFunctionKeywordProp.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,18 @@ baz.normal = false;
//// [source.d.ts]
declare function foo(): void;
declare namespace foo {
const _null: boolean;
let _null: boolean;
export { _null as null };
}
declare function bar(): void;
declare namespace bar {
const async: boolean;
const normal: boolean;
let async: boolean;
let normal: boolean;
}
declare function baz(): void;
declare namespace baz {
const _class: boolean;
let _class: boolean;
export { _class as class };
const normal_1: boolean;
let normal_1: boolean;
export { normal_1 as normal };
}
Loading