diff --git a/newtests/new_target/_flowconfig b/newtests/new_target/_flowconfig deleted file mode 100644 index 9d019a11bad..00000000000 --- a/newtests/new_target/_flowconfig +++ /dev/null @@ -1,10 +0,0 @@ -[ignore] - -[include] - -[libs] - -[options] -all=true -no_flowlib=true - diff --git a/newtests/new_target/test.js b/newtests/new_target/test.js deleted file mode 100644 index 6d7f36259b1..00000000000 --- a/newtests/new_target/test.js +++ /dev/null @@ -1,28 +0,0 @@ -/* - * @flow - */ - - -import type Suite from "flow-dev-tools/src/test/Suite.js"; -import {suite, test} from 'flow-dev-tools/src/test/Tester'; - -export default (suite(({addFile, addFiles, addCode}) => [ - test('new.target is not supported yet', [ - addCode(` - function x() { new.target(); } - `).newErrors( - ` - test.js:4 - 4: function x() { new.target(); } - ^^^^^^^^^^ Not supported. [unsupported-syntax] - `, - ), - ]), - - test('new.target can be suppressed', [ - addCode(` - // $FlowFixMe - function x() { new.target; } - `).noNewErrors(), - ]), -]): Suite); diff --git a/src/typing/statement.ml b/src/typing/statement.ml index 992006a8ae0..9ab50e3781c 100644 --- a/src/typing/statement.ml +++ b/src/typing/statement.ml @@ -3643,6 +3643,22 @@ and expression_ ~cond ~annot cx loc e : (ALoc.t, ALoc.t * Type.t) Ast.Expression | Generator _ -> Flow.add_output cx Error_message.(EUnsupportedSyntax (loc, GeneratorExpression)); Tast_utils.error_mapper#expression ex + | MetaProperty + { + MetaProperty.meta = (_, { Ast.Identifier.name = "new"; _ }) as meta; + property = (_, { Ast.Identifier.name = "target"; _ }) as property; + comments; + } -> + let t = bogus_trust () |> MixedT.at loc in + ((loc, t), MetaProperty { MetaProperty.meta; property; comments }) + | MetaProperty + { + MetaProperty.meta = (_, { Ast.Identifier.name = "import"; _ }) as meta; + property = (_, { Ast.Identifier.name = "meta"; _ }) as property; + comments; + } -> + let t = bogus_trust () |> MixedT.at loc in + ((loc, t), MetaProperty { MetaProperty.meta; property; comments }) | MetaProperty _ -> Flow.add_output cx Error_message.(EUnsupportedSyntax (loc, MetaPropertyExpression)); Tast_utils.error_mapper#expression ex diff --git a/tests/meta_property/.flowconfig b/tests/meta_property/.flowconfig new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/meta_property/import_meta.js b/tests/meta_property/import_meta.js new file mode 100644 index 00000000000..9da9ab702aa --- /dev/null +++ b/tests/meta_property/import_meta.js @@ -0,0 +1,4 @@ +// @flow + +(import.meta: mixed); // OK +(import.meta: 1); // Error diff --git a/tests/meta_property/meta_property.exp b/tests/meta_property/meta_property.exp new file mode 100644 index 00000000000..9f8059aad38 --- /dev/null +++ b/tests/meta_property/meta_property.exp @@ -0,0 +1,45 @@ +Error ----------------------------------------------------------------------------------------------- import_meta.js:4:2 + +Cannot cast `import.meta` to number literal `1` because mixed [1] is incompatible with number literal `1` [2]. +[incompatible-cast] + + import_meta.js:4:2 + 4| (import.meta: 1); // Error + ^^^^^^^^^^^ [1] + +References: + import_meta.js:4:15 + 4| (import.meta: 1); // Error + ^ [2] + + +Error ------------------------------------------------------------------------------------------------ new_target.js:5:4 + +Cannot cast `new.target` to boolean because mixed [1] is incompatible with boolean [2]. [incompatible-cast] + + new_target.js:5:4 + 5| (new.target: boolean); // Error + ^^^^^^^^^^ [1] + +References: + new_target.js:5:16 + 5| (new.target: boolean); // Error + ^^^^^^^ [2] + + +Error ----------------------------------------------------------------------------------------------- new_target.js:13:6 + +Cannot cast `new.target` to boolean because mixed [1] is incompatible with boolean [2]. [incompatible-cast] + + new_target.js:13:6 + 13| (new.target: boolean); // Error + ^^^^^^^^^^ [1] + +References: + new_target.js:13:18 + 13| (new.target: boolean); // Error + ^^^^^^^ [2] + + + +Found 3 errors diff --git a/tests/meta_property/new_target.js b/tests/meta_property/new_target.js new file mode 100644 index 00000000000..4a8a3d7db62 --- /dev/null +++ b/tests/meta_property/new_target.js @@ -0,0 +1,15 @@ +// @flow + +function Foo() { + (new.target: mixed); // OK + (new.target: boolean); // Error + + if (!new.target) {} // OK +} + +class A { + constructor() { + (new.target: mixed); // OK + (new.target: boolean); // Error + } +}