Skip to content

Conversation

a-tarasyuk
Copy link
Contributor

Fixes #1685


This patch addresses the issue of incomplete export assignment validation by aligning the check with Strada logic.

const declaration = getDeclarationOfAliasSymbol(exportEqualsSymbol) || exportEqualsSymbol.valueDeclaration;
if (declaration && !isTopLevelInExternalModuleAugmentation(declaration) && !isInJSFile(declaration)) {
    error(declaration, Diagnostics.An_export_assignment_cannot_be_used_in_a_module_with_other_exported_elements);
}

+ */
+
+
+//// [DtsFileErrors]
Copy link
Member

Choose a reason for hiding this comment

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

This one's a regression.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jakebailey This may not be directly related to the change; it seems the issue is that the jsdoc callback is emitted as exported in the .d.ts files.

// !!! Don't mark typedefs as exported if they are not in a module

export = MyClass;
....
export type DoneCB = (failures: number) ;

while strada handles this case as

export = MyClass;
....
type DoneCB = (failures: number) => any;

I think the way to address this regression is to elide the export modifier. WDYT?

Copy link
Member

Choose a reason for hiding this comment

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

That sounds plausible. Thankfully I believe ExternalModuleIndicator is set before reparsing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It looks like ExternalModuleIndicator is set only after parsing top-level statements

p.finishSourceFile(result, isDeclarationFile)

ast.SetExternalModuleIndicator(result, p.opts.ExternalModuleIndicatorOptions)

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, the declaration emitter or reparser definitely needs to be adjusted to handle this. Probably the reparser, in this case - it probably shouldn't add an export modifier if there's an export assignment in the file. Truth be told, though, this is one of those cases where we can't accurately represent the input as a declaration file, and no matter what we do we're probably going to change behavior from strada.

@jakebailey
Copy link
Member

@sandersn @weswigham Is this the thing we were discussing about relaxing this for even TS code and not erroring at all? I can't remember where we left that.

@weswigham
Copy link
Member

We're at the "just do it like strada" stage because trying to improve it just moved where the jank in our code is - better the jank we know.

Copy link
Member

@weswigham weswigham left a comment

Choose a reason for hiding this comment

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

Definitely an improvement. I'm sure we'll have to keep adjusting the JS declaration emit for export assignments, though, since they're still only partially supported.



==== out/source.d.ts (2 errors) ====
export = MyClass;
Copy link
Member

Choose a reason for hiding this comment

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

Hm. This is because we don't actually support constructor functions yet, right @sandersn ?

Comment on lines +70 to +71
-export type SomeType = {
+type SomeType = {
Copy link
Member

Choose a reason for hiding this comment

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

This one is regressing; maybe a mad interplay with the new code?

Comment on lines +46 to +47
-export type Conn = import("./conn");
+type Conn = import("./conn");
Copy link
Member

Choose a reason for hiding this comment

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

This one too? (I hate JSDoc typedef rules)

Comment on lines 30 to +33
-export type TaskGroupIds = "parseHTML" | "styleLayout";
+export type TaskGroupIds = 'parseHTML' | 'styleLayout';
export type TaskGroup = {
-export type TaskGroup = {
+type TaskGroupIds = 'parseHTML' | 'styleLayout';
+type TaskGroup = {
Copy link
Member

Choose a reason for hiding this comment

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

This file's also regressing in a similar way, it seems...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ts-check used with @typedef causes an error on module.exports = ...
3 participants