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

Export internal functions needed by dtsBundler.mjs #52941

Merged
merged 14 commits into from
Jan 11, 2024

Conversation

jakebailey
Copy link
Member

@jakebailey jakebailey commented Feb 23, 2023

These functions are used by our mini dts bundler; it'd be nice to not as any to use them.

@typescript-bot typescript-bot added Author: Team For Uncommitted Bug PR for untriaged, rejected, closed or missing bug labels Feb 23, 2023
@sandersn sandersn added this to Not started in PR Backlog Mar 6, 2023
sandersn
sandersn previously approved these changes Mar 6, 2023
PR Backlog automation moved this from Not started to Needs merge Mar 6, 2023
@jakebailey jakebailey marked this pull request as draft March 15, 2023 21:40
@typescript-bot
Copy link
Collaborator

Looks like you're introducing a change to the public API surface area. If this includes breaking changes, please document them on our wiki's API Breaking Changes page.

Also, please make sure @DanielRosenwasser and @RyanCavanaugh are aware of the changes, just as a heads up.

@sandersn
Copy link
Member

@jakebailey I'm going through old PRs: Is this still worth bringing up at a design meeting?

@jakebailey
Copy link
Member Author

Yes; it's still an API that I use unsafely in dtsBundler and would like to make public.

@jakebailey jakebailey marked this pull request as ready for review October 26, 2023 00:37
@jakebailey
Copy link
Member Author

Undrafting since we seemed to have added a new API for similar reasons. I think I also should propose nullTransformationContext and isPartOfTypeNode.

@jakebailey jakebailey changed the title Export isInternalDeclaration and isDeclarationStatement Export internal functions needed by dtsBundler.mjs Oct 27, 2023
@jakebailey
Copy link
Member Author

Updated for further discussion; I'm not sure if we should make context optional or nullTransformationContext exported. In the design meeting, we seemed to favor the former. But, maybe overriding it like in the below is desirable:

const textChangesTransformationContext: TransformationContext = {
...nullTransformationContext,
factory: createNodeFactory(
nullTransformationContext.factory.flags | NodeFactoryFlags.NoParenthesizerRules,
nullTransformationContext.factory.baseFactory,
),
};

PR Backlog automation moved this from Needs merge to Waiting on author Oct 27, 2023
PR Backlog automation moved this from Waiting on author to Needs merge Nov 2, 2023
@jakebailey
Copy link
Member Author

Would definitely like @rbuckton to give his opinion on the visitor change here; we were unsure in the meeting which way was good but we thought that making the context option sounded fine, so I updated the PR to do so.

@@ -580,20 +581,20 @@ export function visitCommaListElements(elements: NodeArray<Expression>, visitor:
* @param visitor The callback used to visit each child.
* @param context A lexical environment context for the visitor.
*/
export function visitEachChild<T extends Node>(node: T, visitor: Visitor, context: TransformationContext): T;
export function visitEachChild<T extends Node>(node: T, visitor: Visitor, context?: TransformationContext): T;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rather these be | undefined instead of optional, as it's too easy to neglect to supply the context when it is needed. We do the same for NodeFactory.createTempVariable, where you have to explicitly pass undefined for the recordTempVariable callback parameter.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I can do that; do you prefer that to exporting the null transformation context? (Just checking, you couldn't make it to the meeting last Friday)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have an issue with making nullTransformationContext public, but I think the approach of just passing undefined works just as well.

PR Backlog automation moved this from Needs merge to Waiting on author Nov 3, 2023
@@ -1642,12 +1641,12 @@ export function transformES2015(context: TransformationContext): (x: SourceFile
case SyntaxKind.PropertyDeclaration: {
const named = node as AccessorDeclaration | MethodDeclaration | PropertyDeclaration;
if (isComputedPropertyName(named.name)) {
return factory.replacePropertyName(named, visitEachChild(named.name, elideUnusedThisCaptureWorker, nullTransformationContext));
return factory.replacePropertyName(named, visitEachChild(named.name, elideUnusedThisCaptureWorker, /*context*/ undefined));
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The uses of nullTransformationContext (and now undefined) in this file seem suspicious; all of these call sites have a context available and using it still passes tests. @rbuckton should I be "fixing" these?

@@ -580,20 +581,20 @@ export function visitCommaListElements(elements: NodeArray<Expression>, visitor:
* @param visitor The callback used to visit each child.
* @param context A lexical environment context for the visitor.
*/
export function visitEachChild<T extends Node>(node: T, visitor: Visitor, context: TransformationContext): T;
export function visitEachChild<T extends Node>(node: T, visitor: Visitor, context: TransformationContext | undefined): T;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, debating whether or not visitLexicalEnvironment, visitParameterList, visitFunctionBody, and visitIterationBody need this change. Those are pretty explicitly about working with the context and within a transform, though, so I'm leaning towards no.

https://github.com/search?q=%2Fts%5C.%28visitLexicalEnvironment%7CvisitParameterList%7CvisitFunctionBody%7CvisitIterationBody%29%2F+%28language%3ATypeScript+OR+language%3AJavaScript%29&type=code

@jakebailey jakebailey merged commit 67b644e into microsoft:main Jan 11, 2024
19 checks passed
PR Backlog automation moved this from Waiting on author to Done Jan 11, 2024
@jakebailey jakebailey deleted the export-dts-bundler-funcs branch January 11, 2024 19:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Author: Team For Uncommitted Bug PR for untriaged, rejected, closed or missing bug
Projects
Archived in project
PR Backlog
  
Done
Development

Successfully merging this pull request may close these issues.

None yet

5 participants