[babel 8] Enable allowDeclareFields option by default w/ Flow (#12457)
Co-authored-by: Nicolò Ribaudo <nicolo.ribaudo@gmail.com> Co-authored-by: Ajaykumar <pajay2507@gmail.com>
This commit is contained in:
parent
98aa72ca74
commit
a17e4715c9
@ -149,6 +149,8 @@ function pushTask(taskName, taskDir, suite, suiteName) {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
delete taskOpts.BABEL_8_BREAKING;
|
||||||
|
|
||||||
// If there's node requirement, check it before pushing task
|
// If there's node requirement, check it before pushing task
|
||||||
if (taskOpts.minNodeVersion) {
|
if (taskOpts.minNodeVersion) {
|
||||||
const minimumVersion = semver.clean(taskOpts.minNodeVersion);
|
const minimumVersion = semver.clean(taskOpts.minNodeVersion);
|
||||||
|
|||||||
@ -9,7 +9,12 @@ export default declare((api, opts) => {
|
|||||||
|
|
||||||
let skipStrip = false;
|
let skipStrip = false;
|
||||||
|
|
||||||
const { requireDirective = false, allowDeclareFields = false } = opts;
|
const { requireDirective = false } = opts;
|
||||||
|
|
||||||
|
if (!process.env.BABEL_8_BREAKING) {
|
||||||
|
// eslint-disable-next-line no-var
|
||||||
|
var { allowDeclareFields = false } = opts;
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
name: "transform-flow-strip-types",
|
name: "transform-flow-strip-types",
|
||||||
@ -90,6 +95,7 @@ export default declare((api, opts) => {
|
|||||||
if (child.isClassProperty()) {
|
if (child.isClassProperty()) {
|
||||||
const { node } = child;
|
const { node } = child;
|
||||||
|
|
||||||
|
if (!process.env.BABEL_8_BREAKING) {
|
||||||
if (!allowDeclareFields && node.declare) {
|
if (!allowDeclareFields && node.declare) {
|
||||||
throw child.buildCodeFrameError(
|
throw child.buildCodeFrameError(
|
||||||
`The 'declare' modifier is only allowed when the ` +
|
`The 'declare' modifier is only allowed when the ` +
|
||||||
@ -98,12 +104,18 @@ export default declare((api, opts) => {
|
|||||||
`@babel/preset-flow is enabled.`,
|
`@babel/preset-flow is enabled.`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (node.declare) {
|
if (node.declare) {
|
||||||
child.remove();
|
child.remove();
|
||||||
} else if (!allowDeclareFields && !node.value && !node.decorators) {
|
|
||||||
child.remove();
|
|
||||||
} else {
|
} else {
|
||||||
|
if (!process.env.BABEL_8_BREAKING) {
|
||||||
|
if (!allowDeclareFields && !node.value && !node.decorators) {
|
||||||
|
child.remove();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
node.variance = null;
|
node.variance = null;
|
||||||
node.typeAnnotation = null;
|
node.typeAnnotation = null;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,3 @@
|
|||||||
|
class A {
|
||||||
|
declare x;
|
||||||
|
}
|
||||||
@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"BABEL_8_BREAKING": false,
|
||||||
|
"plugins": [
|
||||||
|
["transform-flow-strip-types", { "allowDeclareFields": true }],
|
||||||
|
"syntax-class-properties"
|
||||||
|
]
|
||||||
|
}
|
||||||
@ -0,0 +1 @@
|
|||||||
|
class A {}
|
||||||
@ -1,4 +1,5 @@
|
|||||||
{
|
{
|
||||||
|
"BABEL_8_BREAKING": false,
|
||||||
"plugins": [
|
"plugins": [
|
||||||
"transform-flow-strip-types",
|
"transform-flow-strip-types",
|
||||||
"syntax-class-properties"
|
"syntax-class-properties"
|
||||||
@ -1,6 +1,7 @@
|
|||||||
{
|
{
|
||||||
|
"BABEL_8_BREAKING": true,
|
||||||
"plugins": [
|
"plugins": [
|
||||||
["transform-flow-strip-types", { "allowDeclareFields": true }],
|
"transform-flow-strip-types",
|
||||||
"syntax-class-properties"
|
"syntax-class-properties"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,4 @@
|
|||||||
class X {
|
class X {
|
||||||
foo = 2
|
foo = 2
|
||||||
bar: number = 3
|
bar: number = 3
|
||||||
baz: ?string
|
|
||||||
}
|
}
|
||||||
@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"BABEL_8_BREAKING": false,
|
||||||
|
"plugins": [
|
||||||
|
"transform-flow-strip-types",
|
||||||
|
"proposal-class-properties",
|
||||||
|
"external-helpers"
|
||||||
|
]
|
||||||
|
}
|
||||||
@ -0,0 +1 @@
|
|||||||
|
class Test {}
|
||||||
@ -0,0 +1,3 @@
|
|||||||
|
class Test {
|
||||||
|
prop: string;
|
||||||
|
}
|
||||||
@ -1,7 +1,8 @@
|
|||||||
{
|
{
|
||||||
|
"BABEL_8_BREAKING": true,
|
||||||
"plugins": [
|
"plugins": [
|
||||||
"transform-flow-strip-types",
|
"transform-flow-strip-types",
|
||||||
"transform-classes",
|
"proposal-class-properties",
|
||||||
"external-helpers"
|
"external-helpers"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
@ -0,0 +1,6 @@
|
|||||||
|
class Test {
|
||||||
|
constructor() {
|
||||||
|
babelHelpers.defineProperty(this, "prop", void 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -1,5 +0,0 @@
|
|||||||
let Test = function Test() {
|
|
||||||
"use strict";
|
|
||||||
|
|
||||||
babelHelpers.classCallCheck(this, Test);
|
|
||||||
};
|
|
||||||
@ -0,0 +1,17 @@
|
|||||||
|
class C1<+T, -U> {}
|
||||||
|
function f<+T, -U>() {}
|
||||||
|
type T<+T, -U> = {}
|
||||||
|
type T1 = { +p: T }
|
||||||
|
type T2 = { -p: T }
|
||||||
|
type T3 = { +[k:K]: V }
|
||||||
|
type T4 = { -[k:K]: V }
|
||||||
|
interface I1 { +p: T }
|
||||||
|
interface I2 { -p: T }
|
||||||
|
interface I3 { +[k:K]: V }
|
||||||
|
interface I4 { -[k:K]: V }
|
||||||
|
declare class I { +p: T }
|
||||||
|
declare class I { -p: T }
|
||||||
|
declare class I { +[k:K]: V }
|
||||||
|
declare class I { -[k:K]: V }
|
||||||
|
class C2 { +p: T }
|
||||||
|
class C3 { -p: T }
|
||||||
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"BABEL_8_BREAKING": false
|
||||||
|
}
|
||||||
@ -0,0 +1,7 @@
|
|||||||
|
class C1 {}
|
||||||
|
|
||||||
|
function f() {}
|
||||||
|
|
||||||
|
class C2 {}
|
||||||
|
|
||||||
|
class C3 {}
|
||||||
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"BABEL_8_BREAKING": true
|
||||||
|
}
|
||||||
@ -2,6 +2,10 @@ class C1 {}
|
|||||||
|
|
||||||
function f() {}
|
function f() {}
|
||||||
|
|
||||||
class C2 {}
|
class C2 {
|
||||||
|
p;
|
||||||
|
}
|
||||||
|
|
||||||
class C3 {}
|
class C3 {
|
||||||
|
p;
|
||||||
|
}
|
||||||
|
|||||||
@ -0,0 +1,111 @@
|
|||||||
|
function foo1(numVal: any) {}
|
||||||
|
function foo2(numVal: number) {}
|
||||||
|
function foo3(numVal: number, strVal: string) {}
|
||||||
|
function foo4(numVal: number, untypedVal) {}
|
||||||
|
function foo5(untypedVal, numVal: number) {}
|
||||||
|
function foo6(nullableNum: ?number) {}
|
||||||
|
function foo7(callback: () => void) {}
|
||||||
|
function foo8(callback: () => number) {}
|
||||||
|
function foo9(callback: (_: bool) => number) {}
|
||||||
|
function foo10(callback: (_1: bool, _2: string) => number) {}
|
||||||
|
function foo11(callback: (_1: bool, ...foo: Array<number>) => number) {}
|
||||||
|
function foo12(): number{}
|
||||||
|
function foo13():() => void {}
|
||||||
|
function foo14():(_:bool) => number{}
|
||||||
|
function foo15():(_?:bool) => number{}
|
||||||
|
function foo16(): {} {}
|
||||||
|
function foo17<T>() {}
|
||||||
|
function foo18<T,S>() {}
|
||||||
|
a1 = function<T,S>() {};
|
||||||
|
a2 = { set fooProp(value: number) {} };
|
||||||
|
a3 = { set fooProp(value: number): void {} };
|
||||||
|
a4 = { get fooProp():number{} };
|
||||||
|
a5 = { id<T>(x: T): T {} };
|
||||||
|
a6 = { *id<T>(x: T): T {} };
|
||||||
|
a7 = { async id<T>(x: T): T {} };
|
||||||
|
a8 = { 123<T>(x: T): T {} };
|
||||||
|
class Foo {
|
||||||
|
set fooProp(value: number) {}
|
||||||
|
}
|
||||||
|
class Foo2 {
|
||||||
|
set fooProp(value: number): void {}
|
||||||
|
}
|
||||||
|
class Foo3 {
|
||||||
|
get fooProp(): number {}
|
||||||
|
}
|
||||||
|
var numVal: number;
|
||||||
|
var numVal: number = otherNumVal;
|
||||||
|
var a1: { numVal: number };
|
||||||
|
var a2: { numVal: number; };
|
||||||
|
var a3: { numVal: number; [indexer: string]: number };
|
||||||
|
var a4: ?{ numVal: number };
|
||||||
|
var a5: { numVal: number; strVal: string }
|
||||||
|
var a6: { subObj: {strVal: string} }
|
||||||
|
var a7: { subObj: ?{strVal: string} }
|
||||||
|
var a8: { param1: number; param2: string }
|
||||||
|
var a9: { param1: number; param2?: string }
|
||||||
|
var a10: { ...any; ...{}|{p: void} };
|
||||||
|
var a11: { [a: number]: string; [b: number]: string; };
|
||||||
|
var a12: { add(x: number, ...y: Array<string>): void };
|
||||||
|
var a13: { id<T>(x: T): T; };
|
||||||
|
var a14:Array<number> = [1, 2, 3]
|
||||||
|
a13 = class Foo<T> {}
|
||||||
|
a14 = class Foo<T> extends Bar<T> {}
|
||||||
|
class Foo4<T> {}
|
||||||
|
class Foo5<T> extends Bar<T> {}
|
||||||
|
class Foo6<T> extends mixin(Bar) {}
|
||||||
|
class Foo7<T> {
|
||||||
|
bar<U>():number { return 42; }
|
||||||
|
}
|
||||||
|
class Foo8 {
|
||||||
|
"bar"<T>() {}
|
||||||
|
}
|
||||||
|
function foo19(requiredParam, optParam?) {}
|
||||||
|
class Foo9 {
|
||||||
|
prop1: string;
|
||||||
|
prop2: number;
|
||||||
|
}
|
||||||
|
class Foo10 {
|
||||||
|
static prop1: string;
|
||||||
|
prop2: number;
|
||||||
|
}
|
||||||
|
class Foo11 {
|
||||||
|
#prop1: string;
|
||||||
|
#prop2: number;
|
||||||
|
}
|
||||||
|
var x1: number | string = 4;
|
||||||
|
class Array { concat(items:number | string) {}; }
|
||||||
|
var x2: () => number | () => string = fn;
|
||||||
|
var x3: typeof Y = Y;
|
||||||
|
var x4: typeof Y | number = Y;
|
||||||
|
var {x5}: {x5: string; } = { x5: "hello" };
|
||||||
|
var {x6}: {x6: string } = { x6: "hello" };
|
||||||
|
var [x7]: Array<string> = [ "hello" ];
|
||||||
|
function foo20({x}: { x: string; }) {}
|
||||||
|
function foo21([x]: Array<string>) {}
|
||||||
|
function foo22(...rest: Array<number>) {}
|
||||||
|
(function (...rest: Array<number>) {});
|
||||||
|
((...rest: Array<number>) => rest);
|
||||||
|
var a15: Map<string, Array<string> >
|
||||||
|
var a16: Map<string, Array<string>>
|
||||||
|
var a17: number[]
|
||||||
|
var a18: ?string[]
|
||||||
|
var a19: Promise<bool>[]
|
||||||
|
var a20:(...rest:Array<number>) => number
|
||||||
|
var identity1: <T>(x: T) => T
|
||||||
|
var identity2: <T>(x: T, ...y:T[]) => T
|
||||||
|
import type imp1 from "bar";
|
||||||
|
import type { imp2, imp3 } from "baz";
|
||||||
|
import type { foo as imp4 } from "baz";
|
||||||
|
import type from "foo";
|
||||||
|
import typeof * as namespace from "bar";
|
||||||
|
export type { foo1 };
|
||||||
|
export type { foo2 } from "bar";
|
||||||
|
import {type T} from "foo";
|
||||||
|
import {type T2, V1} from "foo";
|
||||||
|
import {typeof V2} from "foo";
|
||||||
|
import {typeof V3, V4} from "foo";
|
||||||
|
export interface int5 { p: number }
|
||||||
|
export interface int6<T> { p: T }
|
||||||
|
import 'foo';
|
||||||
|
export type * from "foo";
|
||||||
@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"BABEL_8_BREAKING": false,
|
||||||
|
"plugins": ["transform-flow-strip-types", "syntax-class-properties"]
|
||||||
|
}
|
||||||
@ -0,0 +1,176 @@
|
|||||||
|
function foo1(numVal) {}
|
||||||
|
|
||||||
|
function foo2(numVal) {}
|
||||||
|
|
||||||
|
function foo3(numVal, strVal) {}
|
||||||
|
|
||||||
|
function foo4(numVal, untypedVal) {}
|
||||||
|
|
||||||
|
function foo5(untypedVal, numVal) {}
|
||||||
|
|
||||||
|
function foo6(nullableNum) {}
|
||||||
|
|
||||||
|
function foo7(callback) {}
|
||||||
|
|
||||||
|
function foo8(callback) {}
|
||||||
|
|
||||||
|
function foo9(callback) {}
|
||||||
|
|
||||||
|
function foo10(callback) {}
|
||||||
|
|
||||||
|
function foo11(callback) {}
|
||||||
|
|
||||||
|
function foo12() {}
|
||||||
|
|
||||||
|
function foo13() {}
|
||||||
|
|
||||||
|
function foo14() {}
|
||||||
|
|
||||||
|
function foo15() {}
|
||||||
|
|
||||||
|
function foo16() {}
|
||||||
|
|
||||||
|
function foo17() {}
|
||||||
|
|
||||||
|
function foo18() {}
|
||||||
|
|
||||||
|
a1 = function () {};
|
||||||
|
|
||||||
|
a2 = {
|
||||||
|
set fooProp(value) {}
|
||||||
|
|
||||||
|
};
|
||||||
|
a3 = {
|
||||||
|
set fooProp(value) {}
|
||||||
|
|
||||||
|
};
|
||||||
|
a4 = {
|
||||||
|
get fooProp() {}
|
||||||
|
|
||||||
|
};
|
||||||
|
a5 = {
|
||||||
|
id(x) {}
|
||||||
|
|
||||||
|
};
|
||||||
|
a6 = {
|
||||||
|
*id(x) {}
|
||||||
|
|
||||||
|
};
|
||||||
|
a7 = {
|
||||||
|
async id(x) {}
|
||||||
|
|
||||||
|
};
|
||||||
|
a8 = {
|
||||||
|
123(x) {}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
class Foo {
|
||||||
|
set fooProp(value) {}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
class Foo2 {
|
||||||
|
set fooProp(value) {}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
class Foo3 {
|
||||||
|
get fooProp() {}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
var numVal;
|
||||||
|
var numVal = otherNumVal;
|
||||||
|
var a1;
|
||||||
|
var a2;
|
||||||
|
var a3;
|
||||||
|
var a4;
|
||||||
|
var a5;
|
||||||
|
var a6;
|
||||||
|
var a7;
|
||||||
|
var a8;
|
||||||
|
var a9;
|
||||||
|
var a10;
|
||||||
|
var a11;
|
||||||
|
var a12;
|
||||||
|
var a13;
|
||||||
|
var a14 = [1, 2, 3];
|
||||||
|
a13 = class Foo {};
|
||||||
|
a14 = class Foo extends Bar {};
|
||||||
|
|
||||||
|
class Foo4 {}
|
||||||
|
|
||||||
|
class Foo5 extends Bar {}
|
||||||
|
|
||||||
|
class Foo6 extends mixin(Bar) {}
|
||||||
|
|
||||||
|
class Foo7 {
|
||||||
|
bar() {
|
||||||
|
return 42;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
class Foo8 {
|
||||||
|
"bar"() {}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
function foo19(requiredParam, optParam) {}
|
||||||
|
|
||||||
|
class Foo9 {}
|
||||||
|
|
||||||
|
class Foo10 {}
|
||||||
|
|
||||||
|
class Foo11 {
|
||||||
|
#prop1;
|
||||||
|
#prop2;
|
||||||
|
}
|
||||||
|
|
||||||
|
var x1 = 4;
|
||||||
|
|
||||||
|
class Array {
|
||||||
|
concat(items) {}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
var x2 = fn;
|
||||||
|
var x3 = Y;
|
||||||
|
var x4 = Y;
|
||||||
|
var {
|
||||||
|
x5
|
||||||
|
} = {
|
||||||
|
x5: "hello"
|
||||||
|
};
|
||||||
|
var {
|
||||||
|
x6
|
||||||
|
} = {
|
||||||
|
x6: "hello"
|
||||||
|
};
|
||||||
|
var [x7] = ["hello"];
|
||||||
|
|
||||||
|
function foo20({
|
||||||
|
x
|
||||||
|
}) {}
|
||||||
|
|
||||||
|
function foo21([x]) {}
|
||||||
|
|
||||||
|
function foo22(...rest) {}
|
||||||
|
|
||||||
|
(function (...rest) {});
|
||||||
|
|
||||||
|
(...rest) => rest;
|
||||||
|
|
||||||
|
var a15;
|
||||||
|
var a16;
|
||||||
|
var a17;
|
||||||
|
var a18;
|
||||||
|
var a19;
|
||||||
|
var a20;
|
||||||
|
var identity1;
|
||||||
|
var identity2;
|
||||||
|
import type from "foo";
|
||||||
|
import { V1 } from "foo";
|
||||||
|
import { V4 } from "foo";
|
||||||
|
import 'foo';
|
||||||
@ -1 +1,4 @@
|
|||||||
{ "plugins": ["transform-flow-strip-types", "syntax-class-properties"] }
|
{
|
||||||
|
"BABEL_8_BREAKING": true,
|
||||||
|
"plugins": ["transform-flow-strip-types", "syntax-class-properties"]
|
||||||
|
}
|
||||||
|
|||||||
@ -119,9 +119,15 @@ class Foo8 {
|
|||||||
|
|
||||||
function foo19(requiredParam, optParam) {}
|
function foo19(requiredParam, optParam) {}
|
||||||
|
|
||||||
class Foo9 {}
|
class Foo9 {
|
||||||
|
prop1;
|
||||||
|
prop2;
|
||||||
|
}
|
||||||
|
|
||||||
class Foo10 {}
|
class Foo10 {
|
||||||
|
static prop1;
|
||||||
|
prop2;
|
||||||
|
}
|
||||||
|
|
||||||
class Foo11 {
|
class Foo11 {
|
||||||
#prop1;
|
#prop1;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user