Fix cases with missing semi when printing DeclareExportDeclaration (#3979)
parent
86f0b93e29
commit
a8fe401b26
|
@ -3485,7 +3485,9 @@ function printExportDeclaration(path, options, print) {
|
|||
const semi = options.semi ? ";" : "";
|
||||
const parts = ["export "];
|
||||
|
||||
if (decl["default"] || decl.type === "ExportDefaultDeclaration") {
|
||||
const isDefault = decl["default"] || decl.type === "ExportDefaultDeclaration";
|
||||
|
||||
if (isDefault) {
|
||||
parts.push("default ");
|
||||
}
|
||||
|
||||
|
@ -3497,10 +3499,12 @@ function printExportDeclaration(path, options, print) {
|
|||
parts.push(path.call(print, "declaration"));
|
||||
|
||||
if (
|
||||
decl.type === "ExportDefaultDeclaration" &&
|
||||
isDefault &&
|
||||
(decl.declaration.type !== "ClassDeclaration" &&
|
||||
decl.declaration.type !== "FunctionDeclaration" &&
|
||||
decl.declaration.type !== "TSAbstractClassDeclaration")
|
||||
decl.declaration.type !== "TSAbstractClassDeclaration" &&
|
||||
decl.declaration.type !== "DeclareClass" &&
|
||||
decl.declaration.type !== "DeclareFunction")
|
||||
) {
|
||||
parts.push(semi);
|
||||
}
|
||||
|
|
|
@ -142,7 +142,7 @@ declare export default () => number;
|
|||
* @flow
|
||||
*/
|
||||
|
||||
declare export default () => number
|
||||
declare export default () => number;
|
||||
|
||||
`;
|
||||
|
||||
|
@ -159,7 +159,7 @@ declare export default () =>number;
|
|||
* @flow
|
||||
*/
|
||||
|
||||
declare export default () => number
|
||||
declare export default () => number;
|
||||
|
||||
`;
|
||||
|
||||
|
@ -251,7 +251,7 @@ declare export var str: string;
|
|||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
/* @flow */
|
||||
|
||||
declare export default number
|
||||
declare export default number;
|
||||
declare export var str: string;
|
||||
|
||||
`;
|
||||
|
|
|
@ -1,5 +1,19 @@
|
|||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`declare_export.js 1`] = `
|
||||
declare export default 5;
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
declare export default 5;
|
||||
|
||||
`;
|
||||
|
||||
exports[`declare_export.js 2`] = `
|
||||
declare export default 5;
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
declare export default 5
|
||||
|
||||
`;
|
||||
|
||||
exports[`declare_type.js 1`] = `
|
||||
declare type A = string;
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
@ -7,6 +21,13 @@ declare type A = string;
|
|||
|
||||
`;
|
||||
|
||||
exports[`declare_type.js 2`] = `
|
||||
declare type A = string;
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
declare type A = string
|
||||
|
||||
`;
|
||||
|
||||
exports[`declare_var.js 1`] = `
|
||||
declare var bool: React$PropType$Primitive<boolean>;
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
@ -14,6 +35,13 @@ declare var bool: React$PropType$Primitive<boolean>;
|
|||
|
||||
`;
|
||||
|
||||
exports[`declare_var.js 2`] = `
|
||||
declare var bool: React$PropType$Primitive<boolean>;
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
declare var bool: React$PropType$Primitive<boolean>
|
||||
|
||||
`;
|
||||
|
||||
exports[`long.js 1`] = `
|
||||
export type AdamPlacementValidationSingleErrorKey =
|
||||
'SOME_FANCY_TARGETS.GLOBAL_TARGET';
|
||||
|
@ -35,6 +63,27 @@ type SomeOtherLongLongLongLongLongLongLongLongLongLongLongLongLongLongKey = Some
|
|||
|
||||
`;
|
||||
|
||||
exports[`long.js 2`] = `
|
||||
export type AdamPlacementValidationSingleErrorKey =
|
||||
'SOME_FANCY_TARGETS.GLOBAL_TARGET';
|
||||
|
||||
export type SomeReallyLongLongLongLongLongLongLongLongLongLongLongLongLongLongKey = true;
|
||||
|
||||
export type SomeOtherLongLongLongLongLongLongLongLongLongLongLongLongLongLongKey = null;
|
||||
|
||||
type SomeOtherLongLongLongLongLongLongLongLongLongLongLongLongLongLongKey = SomeReallyLongLongLongLongLongLongIdentifier;
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
export type AdamPlacementValidationSingleErrorKey =
|
||||
"SOME_FANCY_TARGETS.GLOBAL_TARGET"
|
||||
|
||||
export type SomeReallyLongLongLongLongLongLongLongLongLongLongLongLongLongLongKey = true
|
||||
|
||||
export type SomeOtherLongLongLongLongLongLongLongLongLongLongLongLongLongLongKey = null
|
||||
|
||||
type SomeOtherLongLongLongLongLongLongLongLongLongLongLongLongLongLongKey = SomeReallyLongLongLongLongLongLongIdentifier
|
||||
|
||||
`;
|
||||
|
||||
exports[`opaque.js 1`] = `
|
||||
declare export opaque type Foo;
|
||||
declare export opaque type Bar<T>;
|
||||
|
@ -67,3 +116,36 @@ opaque type union = { type: "A" } | { type: "B" };
|
|||
opaque type overloads = ((x: string) => number) & ((x: number) => string);
|
||||
|
||||
`;
|
||||
|
||||
exports[`opaque.js 2`] = `
|
||||
declare export opaque type Foo;
|
||||
declare export opaque type Bar<T>;
|
||||
declare export opaque type Baz: Foo;
|
||||
declare export opaque type Foo<T>: Bar<T>;
|
||||
declare export opaque type Foo<T>: Bar;
|
||||
declare export opaque type Foo: Bar<T>;
|
||||
opaque type ID = string;
|
||||
opaque type Foo<T> = Bar<T>;
|
||||
opaque type Maybe<T> = _Maybe<T, *>;
|
||||
export opaque type Foo = number;
|
||||
opaque type union =
|
||||
| {type: "A"}
|
||||
| {type: "B"};
|
||||
opaque type overloads =
|
||||
& ((x: string) => number)
|
||||
& ((x: number) => string);
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
declare export opaque type Foo
|
||||
declare export opaque type Bar<T>
|
||||
declare export opaque type Baz: Foo
|
||||
declare export opaque type Foo<T>: Bar<T>
|
||||
declare export opaque type Foo<T>: Bar
|
||||
declare export opaque type Foo: Bar<T>
|
||||
opaque type ID = string
|
||||
opaque type Foo<T> = Bar<T>
|
||||
opaque type Maybe<T> = _Maybe<T, *>
|
||||
export opaque type Foo = number
|
||||
opaque type union = { type: "A" } | { type: "B" }
|
||||
opaque type overloads = ((x: string) => number) & ((x: number) => string)
|
||||
|
||||
`;
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
declare export default 5;
|
|
@ -1 +1,2 @@
|
|||
run_spec(__dirname, ["flow", "babylon"]);
|
||||
run_spec(__dirname, ["flow", "babylon"], { semi: false });
|
||||
|
|
Loading…
Reference in New Issue