From a74a52f62ce7bddcb8a7b5876580fea9d3a613d1 Mon Sep 17 00:00:00 2001 From: Jorge Henriquez Date: Mon, 15 Jun 2020 19:26:22 -0700 Subject: [PATCH 1/6] Add "<" parser tests * No {jsx,flow,typescript} plugin * Type parameter * Valid JS Code --- .../jsx/errors/_no-plugin-no-jsx/input.js | 2 + .../jsx/errors/_no-plugin-no-jsx/output.json | 36 ++++++++++++++++ .../errors/_no-plugin-ts-type-param/input.js | 1 + .../_no-plugin-ts-type-param/output.json | 43 +++++++++++++++++++ .../fixtures/jsx/errors/_no_plugin/input.js | 1 + .../jsx/errors/_no_plugin/options.json | 4 ++ 6 files changed, 87 insertions(+) create mode 100644 packages/babel-parser/test/fixtures/jsx/errors/_no-plugin-no-jsx/input.js create mode 100644 packages/babel-parser/test/fixtures/jsx/errors/_no-plugin-no-jsx/output.json create mode 100644 packages/babel-parser/test/fixtures/jsx/errors/_no-plugin-ts-type-param/input.js create mode 100644 packages/babel-parser/test/fixtures/jsx/errors/_no-plugin-ts-type-param/output.json create mode 100644 packages/babel-parser/test/fixtures/jsx/errors/_no_plugin/input.js create mode 100644 packages/babel-parser/test/fixtures/jsx/errors/_no_plugin/options.json diff --git a/packages/babel-parser/test/fixtures/jsx/errors/_no-plugin-no-jsx/input.js b/packages/babel-parser/test/fixtures/jsx/errors/_no-plugin-no-jsx/input.js new file mode 100644 index 000000000000..fbc4c110bd81 --- /dev/null +++ b/packages/babel-parser/test/fixtures/jsx/errors/_no-plugin-no-jsx/input.js @@ -0,0 +1,2 @@ +"use strict" +
() => {} diff --git a/packages/babel-parser/test/fixtures/jsx/errors/_no-plugin-ts-type-param/output.json b/packages/babel-parser/test/fixtures/jsx/errors/_no-plugin-ts-type-param/output.json new file mode 100644 index 000000000000..44b47bc7920b --- /dev/null +++ b/packages/babel-parser/test/fixtures/jsx/errors/_no-plugin-ts-type-param/output.json @@ -0,0 +1,43 @@ +{ + "type": "File", + "start":0,"end":13,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":13}}, + "program": { + "type": "Program", + "start":0,"end":13,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":13}}, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start":0,"end":13,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":13}}, + "expression": { + "type": "ArrowFunctionExpression", + "start":0,"end":13,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":13}}, + "id": null, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start":11,"end":13,"loc":{"start":{"line":1,"column":11},"end":{"line":1,"column":13}}, + "body": [], + "directives": [] + }, + "typeParameters": { + "type": "TypeParameterDeclaration", + "start":0,"end":5,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":5}}, + "params": [ + { + "type": "TypeParameter", + "start":1,"end":4,"loc":{"start":{"line":1,"column":1},"end":{"line":1,"column":4}}, + "name": "div", + "variance": null + } + ] + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/jsx/errors/_no_plugin/input.js b/packages/babel-parser/test/fixtures/jsx/errors/_no_plugin/input.js new file mode 100644 index 000000000000..7c89b545c5ac --- /dev/null +++ b/packages/babel-parser/test/fixtures/jsx/errors/_no_plugin/input.js @@ -0,0 +1 @@ +
diff --git a/packages/babel-parser/test/fixtures/jsx/errors/_no_plugin/options.json b/packages/babel-parser/test/fixtures/jsx/errors/_no_plugin/options.json new file mode 100644 index 000000000000..7e0538ba8978 --- /dev/null +++ b/packages/babel-parser/test/fixtures/jsx/errors/_no_plugin/options.json @@ -0,0 +1,4 @@ +{ + "throws": "This experimental syntax requires enabling one of the following parser plugin(s): 'jsx, flow, typescript' (1:0)", + "plugins": [] +} From 36c699eac3b921314515d144b4f3b038b51b913a Mon Sep 17 00:00:00 2001 From: Jorge Henriquez Date: Mon, 15 Jun 2020 19:28:03 -0700 Subject: [PATCH 2/6] Add: better parser error when using jsx Address #11499 --- packages/babel-parser/src/parser/expression.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/packages/babel-parser/src/parser/expression.js b/packages/babel-parser/src/parser/expression.js index 0ef5ca4270ef..e63401b4747b 100644 --- a/packages/babel-parser/src/parser/expression.js +++ b/packages/babel-parser/src/parser/expression.js @@ -1170,6 +1170,12 @@ export default class ExpressionParser extends LValParser { } } // fall through + case tt.relational: { + if (this.state.value === "<") { + throw this.expectOnePlugin(["jsx", "flow", "typescript"]); + } + } + // fall through default: throw this.unexpected(); } From 22fda5a8b8acf4646abefc790eff57c4cb792d34 Mon Sep 17 00:00:00 2001 From: Jorge Henriquez Date: Tue, 16 Jun 2020 19:43:33 -0700 Subject: [PATCH 3/6] Add: babel parser test Test parser with no plugins and when jsx is given with a js expression --- .../fixtures/jsx/errors/_no-plugin-jsx-expression/input.js | 1 + .../jsx/errors/_no-plugin-jsx-expression/options.json | 4 ++++ 2 files changed, 5 insertions(+) create mode 100644 packages/babel-parser/test/fixtures/jsx/errors/_no-plugin-jsx-expression/input.js create mode 100644 packages/babel-parser/test/fixtures/jsx/errors/_no-plugin-jsx-expression/options.json diff --git a/packages/babel-parser/test/fixtures/jsx/errors/_no-plugin-jsx-expression/input.js b/packages/babel-parser/test/fixtures/jsx/errors/_no-plugin-jsx-expression/input.js new file mode 100644 index 000000000000..f56238150ab2 --- /dev/null +++ b/packages/babel-parser/test/fixtures/jsx/errors/_no-plugin-jsx-expression/input.js @@ -0,0 +1 @@ +
{name}
diff --git a/packages/babel-parser/test/fixtures/jsx/errors/_no-plugin-jsx-expression/options.json b/packages/babel-parser/test/fixtures/jsx/errors/_no-plugin-jsx-expression/options.json new file mode 100644 index 000000000000..f11e7c5d0451 --- /dev/null +++ b/packages/babel-parser/test/fixtures/jsx/errors/_no-plugin-jsx-expression/options.json @@ -0,0 +1,4 @@ +{ + "plugins": [], + "throws": "This experimental syntax requires enabling one of the following parser plugin(s): 'jsx, flow, typescript' (1:0)" +} From d81329fe68bfe89aaf8c371083bfad347eeefc51 Mon Sep 17 00:00:00 2001 From: Jorge Henriquez Date: Wed, 17 Jun 2020 19:19:55 -0700 Subject: [PATCH 4/6] Add: no flow but with typescript test --- .../jsx/errors/_no-plugin-ts-type-param-no-flow/input.js | 1 + .../jsx/errors/_no-plugin-ts-type-param-no-flow/options.json | 3 +++ 2 files changed, 4 insertions(+) create mode 100644 packages/babel-parser/test/fixtures/jsx/errors/_no-plugin-ts-type-param-no-flow/input.js create mode 100644 packages/babel-parser/test/fixtures/jsx/errors/_no-plugin-ts-type-param-no-flow/options.json diff --git a/packages/babel-parser/test/fixtures/jsx/errors/_no-plugin-ts-type-param-no-flow/input.js b/packages/babel-parser/test/fixtures/jsx/errors/_no-plugin-ts-type-param-no-flow/input.js new file mode 100644 index 000000000000..2791c2c7a3a0 --- /dev/null +++ b/packages/babel-parser/test/fixtures/jsx/errors/_no-plugin-ts-type-param-no-flow/input.js @@ -0,0 +1 @@ +
() => {} diff --git a/packages/babel-parser/test/fixtures/jsx/errors/_no-plugin-ts-type-param-no-flow/options.json b/packages/babel-parser/test/fixtures/jsx/errors/_no-plugin-ts-type-param-no-flow/options.json new file mode 100644 index 000000000000..5047d6993fe8 --- /dev/null +++ b/packages/babel-parser/test/fixtures/jsx/errors/_no-plugin-ts-type-param-no-flow/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["typescript"] +} From 31c9f073a63ebf2aa4c4b928ed4abd9c2beaf9c1 Mon Sep 17 00:00:00 2001 From: Jorge Henriquez Date: Wed, 17 Jun 2020 19:20:24 -0700 Subject: [PATCH 5/6] Add: type paramter test with no plugins (no flow) --- .../output.json | 42 +++++++++++++++++++ .../jsx/errors/_no-plugin-type-param/input.js | 1 + .../errors/_no-plugin-type-param/options.json | 4 ++ 3 files changed, 47 insertions(+) create mode 100644 packages/babel-parser/test/fixtures/jsx/errors/_no-plugin-ts-type-param-no-flow/output.json create mode 100644 packages/babel-parser/test/fixtures/jsx/errors/_no-plugin-type-param/input.js create mode 100644 packages/babel-parser/test/fixtures/jsx/errors/_no-plugin-type-param/options.json diff --git a/packages/babel-parser/test/fixtures/jsx/errors/_no-plugin-ts-type-param-no-flow/output.json b/packages/babel-parser/test/fixtures/jsx/errors/_no-plugin-ts-type-param-no-flow/output.json new file mode 100644 index 000000000000..d1ca421c201b --- /dev/null +++ b/packages/babel-parser/test/fixtures/jsx/errors/_no-plugin-ts-type-param-no-flow/output.json @@ -0,0 +1,42 @@ +{ + "type": "File", + "start":0,"end":13,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":13}}, + "program": { + "type": "Program", + "start":0,"end":13,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":13}}, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start":0,"end":13,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":13}}, + "expression": { + "type": "ArrowFunctionExpression", + "start":0,"end":13,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":13}}, + "id": null, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start":11,"end":13,"loc":{"start":{"line":1,"column":11},"end":{"line":1,"column":13}}, + "body": [], + "directives": [] + }, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "start":0,"end":5,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":5}}, + "params": [ + { + "type": "TSTypeParameter", + "start":1,"end":4,"loc":{"start":{"line":1,"column":1},"end":{"line":1,"column":4}}, + "name": "div" + } + ] + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/jsx/errors/_no-plugin-type-param/input.js b/packages/babel-parser/test/fixtures/jsx/errors/_no-plugin-type-param/input.js new file mode 100644 index 000000000000..2791c2c7a3a0 --- /dev/null +++ b/packages/babel-parser/test/fixtures/jsx/errors/_no-plugin-type-param/input.js @@ -0,0 +1 @@ +
() => {} diff --git a/packages/babel-parser/test/fixtures/jsx/errors/_no-plugin-type-param/options.json b/packages/babel-parser/test/fixtures/jsx/errors/_no-plugin-type-param/options.json new file mode 100644 index 000000000000..f11e7c5d0451 --- /dev/null +++ b/packages/babel-parser/test/fixtures/jsx/errors/_no-plugin-type-param/options.json @@ -0,0 +1,4 @@ +{ + "plugins": [], + "throws": "This experimental syntax requires enabling one of the following parser plugin(s): 'jsx, flow, typescript' (1:0)" +} From 43576842a3d2c0150d2e19137e658b72de0f7dff Mon Sep 17 00:00:00 2001 From: Jorge Henriquez Date: Sun, 21 Jun 2020 13:12:27 -0700 Subject: [PATCH 6/6] Add: unclosed jsx element test --- .../test/fixtures/jsx/errors/unclosed-jsx-element/input.js | 1 + .../fixtures/jsx/errors/unclosed-jsx-element/options.json | 4 ++++ 2 files changed, 5 insertions(+) create mode 100644 packages/babel-parser/test/fixtures/jsx/errors/unclosed-jsx-element/input.js create mode 100644 packages/babel-parser/test/fixtures/jsx/errors/unclosed-jsx-element/options.json diff --git a/packages/babel-parser/test/fixtures/jsx/errors/unclosed-jsx-element/input.js b/packages/babel-parser/test/fixtures/jsx/errors/unclosed-jsx-element/input.js new file mode 100644 index 000000000000..2791c2c7a3a0 --- /dev/null +++ b/packages/babel-parser/test/fixtures/jsx/errors/unclosed-jsx-element/input.js @@ -0,0 +1 @@ +
() => {} diff --git a/packages/babel-parser/test/fixtures/jsx/errors/unclosed-jsx-element/options.json b/packages/babel-parser/test/fixtures/jsx/errors/unclosed-jsx-element/options.json new file mode 100644 index 000000000000..05048c2000ee --- /dev/null +++ b/packages/babel-parser/test/fixtures/jsx/errors/unclosed-jsx-element/options.json @@ -0,0 +1,4 @@ +{ + "plugins": ["jsx"], + "throws": "Unexpected token (1:13)" +}