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

enable TS compiler option: strictBindCallApply #14685

Merged
merged 1 commit into from Jun 22, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 6 additions & 3 deletions packages/babel-generator/src/generators/flow.ts
Expand Up @@ -156,13 +156,16 @@ export function DeclareExportDeclaration(
this.space();
}

FlowExportDeclaration.apply(this, arguments);
FlowExportDeclaration.call(this, node);
}

export function DeclareExportAllDeclaration(this: Printer) {
export function DeclareExportAllDeclaration(
this: Printer,
node: t.DeclareExportAllDeclaration,
) {
this.word("declare");
this.space();
ExportAllDeclaration.apply(this, arguments);
ExportAllDeclaration.call(this, node);
}

export function EnumDeclaration(this: Printer, node: t.EnumDeclaration) {
Expand Down
3 changes: 2 additions & 1 deletion packages/babel-generator/src/generators/modules.ts
Expand Up @@ -68,7 +68,7 @@ export function ExportNamespaceSpecifier(

export function ExportAllDeclaration(
this: Printer,
node: t.ExportAllDeclaration,
node: t.ExportAllDeclaration | t.DeclareExportAllDeclaration,
) {
this.word("export");
this.space();
Expand All @@ -81,6 +81,7 @@ export function ExportAllDeclaration(
this.word("from");
this.space();
this.print(node.source, node);
// @ts-expect-error Fixme: assertions is not defined in DeclareExportAllDeclaration
Copy link
Contributor Author

@JLHwung JLHwung Jun 22, 2022

Choose a reason for hiding this comment

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

Currently the flow parser plugin accepts

declare export * from "./module.json" assert { type: "json" }
declare export * as ns from "./module.json" assert { type: "json" }
declare export { default } from "./module.json" assert { type: "json" }

None of them are supported by Flow as of Jun 2022.

However only

declare export * from "./module.json" assert { type: "json" }

works on generator because the DeclareExportAllDeclaration reuses the ExportAllDeclaration printer.

There are two solutions:

  1. Add the missing assertions type definition to DeclareExportDeclaration and add the generator support
  2. Throw an error (i.e. JSON modules are not yet supported in Flow) when DeclareExport*Declaration have assertions and remove the generator support mentioned above

While I personally think Flow should eventually support declared JSON modules imports. I am good with either supporting it prior to the Flow project or disabling it.

Note that

declare export default from "./module.json" assert { type: "json" }

is not supported when Flow and exportDefaultFrom are both enabled, though the error message "Missing semicolon. (1:27)" after from is not very helpful.

Copy link
Member

Choose a reason for hiding this comment

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

While I personally think Flow should eventually support declared JSON modules imports. I am good with either supporting it prior to the Flow project or disabling it.

I tend to do that too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@liuxingbaoyu I am not sure I can follow. Do you tend to agree that we should support import assertions in Flow declare exports or disallow it (like Flow current does)?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, I prefer to disable them before they actually work.

this.printAssertions(node);
this.semicolon();
}
Expand Down
1 change: 1 addition & 0 deletions packages/babel-types/src/converters/valueToNode.ts
Expand Up @@ -31,6 +31,7 @@ export default valueToNode as {
(value: unknown): t.Expression;
};

// @ts-expect-error: Object.prototype.toString must return a string
const objectToString: (value: unknown) => string = Function.call.bind(
Object.prototype.toString,
);
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.base.json
Expand Up @@ -13,6 +13,7 @@
"skipLibCheck": true,
"resolveJsonModule": true,
"noImplicitThis": true,
"noImplicitAny": true
"noImplicitAny": true,
"strictBindCallApply": true
}
}