Skip to content
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

Filter #private static members from js declaration emit #60977

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
3 changes: 2 additions & 1 deletion src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1133,6 +1133,7 @@ import {
WithStatement,
WriterContextOut,
YieldExpression,
isPrivateIdentifierSymbol,
} from "./_namespaces/ts.js";
import * as moduleSpecifiers from "./_namespaces/ts.moduleSpecifiers.js";
import * as performance from "./_namespaces/ts.performance.js";
Expand Down Expand Up @@ -9770,7 +9771,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
const publicProperties = flatMap<Symbol, ClassElement>(publicSymbolProps, p => serializePropertySymbolForClass(p, /*isStatic*/ false, baseTypes[0]));
// Consider static members empty if symbol also has function or module meaning - function namespacey emit will handle statics
const staticMembers = flatMap(
filter(getPropertiesOfType(staticType), p => !(p.flags & SymbolFlags.Prototype) && p.escapedName !== "prototype" && !isNamespaceMember(p)),
filter(getPropertiesOfType(staticType), p => !(p.flags & SymbolFlags.Prototype) && p.escapedName !== "prototype" && !isNamespaceMember(p) && !isPrivateIdentifierSymbol(p)),
p => serializePropertySymbolForClass(p, /*isStatic*/ true, staticBaseType),
);
// When we encounter an `X.prototype.y` assignment in a JS file, we bind `X` as a class regardless as to whether
Expand Down
20 changes: 20 additions & 0 deletions tests/baselines/reference/declarationEmitJsPrivateClassStatics.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//// [tests/cases/compiler/declarationEmitJsPrivateClassStatics.ts] ////

//// [input.js]
class Test {
static #privateStaticProp = 'Not removed for JS declaration generation; is removed for TS.';

static #privateStaticFn() { return 'Not removed for JS declaration generation; is removed for TS.'; }

#privateProp = 'This is removed in JS / TS declaration generation.';

#privateFn() { return 'This is removed in JS / TS declaration generation.'; }
}




//// [input.d.ts]
declare class Test {
#private;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//// [tests/cases/compiler/declarationEmitJsPrivateClassStatics.ts] ////

=== input.js ===
class Test {
>Test : Symbol(Test, Decl(input.js, 0, 0))

static #privateStaticProp = 'Not removed for JS declaration generation; is removed for TS.';
>#privateStaticProp : Symbol(Test.#privateStaticProp, Decl(input.js, 0, 12))

static #privateStaticFn() { return 'Not removed for JS declaration generation; is removed for TS.'; }
>#privateStaticFn : Symbol(Test.#privateStaticFn, Decl(input.js, 1, 96))

#privateProp = 'This is removed in JS / TS declaration generation.';
>#privateProp : Symbol(Test.#privateProp, Decl(input.js, 3, 105))

#privateFn() { return 'This is removed in JS / TS declaration generation.'; }
>#privateFn : Symbol(Test.#privateFn, Decl(input.js, 5, 72))
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//// [tests/cases/compiler/declarationEmitJsPrivateClassStatics.ts] ////

=== input.js ===
class Test {
>Test : Test
> : ^^^^

static #privateStaticProp = 'Not removed for JS declaration generation; is removed for TS.';
>#privateStaticProp : string
> : ^^^^^^
>'Not removed for JS declaration generation; is removed for TS.' : "Not removed for JS declaration generation; is removed for TS."
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

static #privateStaticFn() { return 'Not removed for JS declaration generation; is removed for TS.'; }
>#privateStaticFn : () => string
> : ^^^^^^^^^^^^
>'Not removed for JS declaration generation; is removed for TS.' : "Not removed for JS declaration generation; is removed for TS."
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

#privateProp = 'This is removed in JS / TS declaration generation.';
>#privateProp : string
> : ^^^^^^
>'This is removed in JS / TS declaration generation.' : "This is removed in JS / TS declaration generation."
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

#privateFn() { return 'This is removed in JS / TS declaration generation.'; }
>#privateFn : () => string
> : ^^^^^^^^^^^^
>'This is removed in JS / TS declaration generation.' : "This is removed in JS / TS declaration generation."
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
}

14 changes: 14 additions & 0 deletions tests/cases/compiler/declarationEmitJsPrivateClassStatics.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// @allowJs: true
// @emitDeclarationOnly: true
// @declaration: true
// @target: es2015
// @filename: input.js
class Test {
static #privateStaticProp = 'Not removed for JS declaration generation; is removed for TS.';

static #privateStaticFn() { return 'Not removed for JS declaration generation; is removed for TS.'; }

#privateProp = 'This is removed in JS / TS declaration generation.';

#privateFn() { return 'This is removed in JS / TS declaration generation.'; }
}
Loading