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

Fix printing of Flow internal slot functions #14962

Merged
merged 4 commits into from Sep 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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Expand Up @@ -272,7 +272,7 @@ jobs:
!**/node_modules/**

test-babel-8-breaking:
name: Test Babel 8 breaking changes on Node.js
name: Test Babel 8 breaking changes on
needs: build-babel8
strategy:
matrix:
Expand Down
4 changes: 3 additions & 1 deletion packages/babel-generator/src/generators/expressions.ts
Expand Up @@ -190,12 +190,14 @@ export function OptionalCallExpression(
) {
this.print(node.callee, node);

this.print(node.typeArguments, node); // Flow
this.print(node.typeParameters, node); // TS

if (node.optional) {
this.token("?.");
}

this.print(node.typeArguments, node); // Flow

this.token("(");
this.printList(node.arguments, node);
this.token(")");
Expand Down
1 change: 1 addition & 0 deletions packages/babel-generator/src/generators/flow.ts
Expand Up @@ -332,6 +332,7 @@ export function FunctionTypeAnnotation(
if (
parent &&
(parent.type === "ObjectTypeCallProperty" ||
parent.type === "ObjectTypeInternalSlot" ||
parent.type === "DeclareFunction" ||
(parent.type === "ObjectTypeProperty" && parent.method))
) {
Expand Down
@@ -1,5 +1,6 @@
{
"BABEL_8_BREAKING": false,
"plugins": [["decorators", { "decoratorsBeforeExport": false }]],
"decoratorsBeforeExport": true
"decoratorsBeforeExport": true,
"expectedReParseError": true
}
@@ -1,5 +1,6 @@
{
"BABEL_8_BREAKING": false,
"plugins": [["decorators", { "decoratorsBeforeExport": true }]],
"decoratorsBeforeExport": false
"decoratorsBeforeExport": false,
"expectedReParseError": true
}
Expand Up @@ -8,13 +8,13 @@ interface I1 {
[[foo]]: X
}
interface I2 {
[[foo]]() => X
[[foo]](): X
}
type T1 = {
[[foo]]: X
};
type T2 = {
[[foo]]() => X
[[foo]](): X
};
type T3 = {
[[foo]]?: X
Expand Down
Expand Up @@ -16,6 +16,6 @@ new C<T>();
o.m<T>();
f < T > .0;
o?.m<T>(e);
o.m<T>?.(e);
o.m?.<T>(e);
async<T>();
f<T>?.(e);
f?.<T>(e);
@@ -1 +1,5 @@
{ "plugins": ["decorators-legacy"] }
{
"plugins": ["decorators-legacy"],
"decoratorsBeforeExport": true,
"BABEL_8_BREAKING": false
}
Expand Up @@ -32,15 +32,15 @@ class Foo {

}

export default @foo
class Foo2 {
@foo
export default class Foo2 {
bar() {
class Baz {}
}

}
export @foo
class Foo3 {
@foo
export class Foo3 {
bar() {
class Baz {}
}
Expand Down
12 changes: 9 additions & 3 deletions packages/babel-generator/test/index.js
Expand Up @@ -811,14 +811,15 @@ suites.forEach(function (testSuite) {
const actualCode = actual.code;

if (actualCode) {
const actualAst = parse(actualCode, {
const parserOpts = {
filename: actual.loc,
plugins: task.options.plugins || [],
strictMode: task.options.strictMode === false ? false : true,
sourceType: "module",
sourceMaps: !!task.sourceMap,
...task.options.parserOpts,
});
};
const actualAst = parse(actualCode, parserOpts);
const options = {
sourceFileName: path.relative(
path.dirname(fileURLToPath(import.meta.url)),
Expand All @@ -832,7 +833,7 @@ suites.forEach(function (testSuite) {
return generate(actualAst, options, actualCode);
};

const throwMsg = task.options.throws;
const throwMsg = options.throws;
if (throwMsg) {
expect(() => run()).toThrow(
throwMsg === true ? undefined : throwMsg,
Expand Down Expand Up @@ -864,6 +865,11 @@ suites.forEach(function (testSuite) {
} else {
try {
expect(result.code).toBe(expected.code);
if (!options.expectedReParseError) {
expect(() => {
parse(result.code, parserOpts);
}).not.toThrow();
}
} catch (e) {
if (!process.env.OVERWRITE) throw e;
console.log(`Updated test file: ${expected.loc}`);
Expand Down