From 4e95debe68d997b185d8c1a4a18918c43e824775 Mon Sep 17 00:00:00 2001 From: Yokubjon-J Date: Mon, 7 Mar 2022 23:03:57 +0500 Subject: [PATCH 01/10] solution to [Bug]: Parser throws when var declaration and function declaration in class static block #14257 --- packages/babel-parser/src/parser/statement.js | 2 +- packages/babel-parser/src/util/scope.js | 2 +- .../input.js | 1 + .../output.json | 70 +++++++++++++++++++ .../es2015/class/static-block/input.js | 1 + .../es2015/class/static-block/output.json | 70 +++++++++++++++++++ .../invalid-arguments/output.json | 3 - .../helpers/esm/possibleConstructorReturn.js | 2 +- .../helpers/possibleConstructorReturn.js | 2 +- .../helpers/esm/possibleConstructorReturn.js | 2 +- .../helpers/possibleConstructorReturn.js | 2 +- .../helpers/esm/possibleConstructorReturn.js | 2 +- .../helpers/possibleConstructorReturn.js | 2 +- 13 files changed, 150 insertions(+), 11 deletions(-) create mode 100644 packages/babel-parser/test/fixtures/es2015/class/static-block-var-and-func-same-name/input.js create mode 100644 packages/babel-parser/test/fixtures/es2015/class/static-block-var-and-func-same-name/output.json create mode 100644 packages/babel-parser/test/fixtures/es2015/class/static-block/input.js create mode 100644 packages/babel-parser/test/fixtures/es2015/class/static-block/output.json diff --git a/packages/babel-parser/src/parser/statement.js b/packages/babel-parser/src/parser/statement.js index 1ca7c1a5ef04..1b6d70748e1f 100644 --- a/packages/babel-parser/src/parser/statement.js +++ b/packages/babel-parser/src/parser/statement.js @@ -1742,7 +1742,7 @@ export default class StatementParser extends ExpressionParser { member: N.StaticBlock & { decorators?: Array }, ) { // Start a new lexical scope - this.scope.enter(SCOPE_CLASS | SCOPE_STATIC_BLOCK | SCOPE_SUPER); + this.scope.enter(SCOPE_CLASS | SCOPE_STATIC_BLOCK | SCOPE_SUPER | SCOPE_FUNCTION); // Start a new scope with regard to loop labels const oldLabels = this.state.labels; this.state.labels = []; diff --git a/packages/babel-parser/src/util/scope.js b/packages/babel-parser/src/util/scope.js index 5547699ba23c..f00732ce1822 100644 --- a/packages/babel-parser/src/util/scope.js +++ b/packages/babel-parser/src/util/scope.js @@ -103,7 +103,7 @@ export default class ScopeHandler { // > treated like var declarations rather than like lexical declarations. treatFunctionsAsVarInScope(scope: IScope): boolean { return !!( - scope.flags & SCOPE_FUNCTION || + scope.flags & SCOPE_FUNCTION || scope.flags & SCOPE_STATIC_BLOCK || (!this.parser.inModule && scope.flags & SCOPE_PROGRAM) ); } diff --git a/packages/babel-parser/test/fixtures/es2015/class/static-block-var-and-func-same-name/input.js b/packages/babel-parser/test/fixtures/es2015/class/static-block-var-and-func-same-name/input.js new file mode 100644 index 000000000000..7b8e2670b0ee --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2015/class/static-block-var-and-func-same-name/input.js @@ -0,0 +1 @@ +class X { static { var x; function x() {} } } \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2015/class/static-block-var-and-func-same-name/output.json b/packages/babel-parser/test/fixtures/es2015/class/static-block-var-and-func-same-name/output.json new file mode 100644 index 000000000000..bd56c7de1f9e --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2015/class/static-block-var-and-func-same-name/output.json @@ -0,0 +1,70 @@ +{ + "type": "File", + "start":0,"end":45,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":45,"index":45}}, + "program": { + "type": "Program", + "start":0,"end":45,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":45,"index":45}}, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ClassDeclaration", + "start":0,"end":45,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":45,"index":45}}, + "id": { + "type": "Identifier", + "start":6,"end":7,"loc":{"start":{"line":1,"column":6,"index":6},"end":{"line":1,"column":7,"index":7},"identifierName":"X"}, + "name": "X" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start":8,"end":45,"loc":{"start":{"line":1,"column":8,"index":8},"end":{"line":1,"column":45,"index":45}}, + "body": [ + { + "type": "StaticBlock", + "start":10,"end":43,"loc":{"start":{"line":1,"column":10,"index":10},"end":{"line":1,"column":43,"index":43}}, + "body": [ + { + "type": "VariableDeclaration", + "start":19,"end":25,"loc":{"start":{"line":1,"column":19,"index":19},"end":{"line":1,"column":25,"index":25}}, + "declarations": [ + { + "type": "VariableDeclarator", + "start":23,"end":24,"loc":{"start":{"line":1,"column":23,"index":23},"end":{"line":1,"column":24,"index":24}}, + "id": { + "type": "Identifier", + "start":23,"end":24,"loc":{"start":{"line":1,"column":23,"index":23},"end":{"line":1,"column":24,"index":24},"identifierName":"x"}, + "name": "x" + }, + "init": null + } + ], + "kind": "var" + }, + { + "type": "FunctionDeclaration", + "start":26,"end":41,"loc":{"start":{"line":1,"column":26,"index":26},"end":{"line":1,"column":41,"index":41}}, + "id": { + "type": "Identifier", + "start":35,"end":36,"loc":{"start":{"line":1,"column":35,"index":35},"end":{"line":1,"column":36,"index":36},"identifierName":"x"}, + "name": "x" + }, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start":39,"end":41,"loc":{"start":{"line":1,"column":39,"index":39},"end":{"line":1,"column":41,"index":41}}, + "body": [], + "directives": [] + } + } + ] + } + ] + } + } + ], + "directives": [] + } +} diff --git a/packages/babel-parser/test/fixtures/es2015/class/static-block/input.js b/packages/babel-parser/test/fixtures/es2015/class/static-block/input.js new file mode 100644 index 000000000000..7b8e2670b0ee --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2015/class/static-block/input.js @@ -0,0 +1 @@ +class X { static { var x; function x() {} } } \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2015/class/static-block/output.json b/packages/babel-parser/test/fixtures/es2015/class/static-block/output.json new file mode 100644 index 000000000000..bd56c7de1f9e --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2015/class/static-block/output.json @@ -0,0 +1,70 @@ +{ + "type": "File", + "start":0,"end":45,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":45,"index":45}}, + "program": { + "type": "Program", + "start":0,"end":45,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":45,"index":45}}, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ClassDeclaration", + "start":0,"end":45,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":45,"index":45}}, + "id": { + "type": "Identifier", + "start":6,"end":7,"loc":{"start":{"line":1,"column":6,"index":6},"end":{"line":1,"column":7,"index":7},"identifierName":"X"}, + "name": "X" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start":8,"end":45,"loc":{"start":{"line":1,"column":8,"index":8},"end":{"line":1,"column":45,"index":45}}, + "body": [ + { + "type": "StaticBlock", + "start":10,"end":43,"loc":{"start":{"line":1,"column":10,"index":10},"end":{"line":1,"column":43,"index":43}}, + "body": [ + { + "type": "VariableDeclaration", + "start":19,"end":25,"loc":{"start":{"line":1,"column":19,"index":19},"end":{"line":1,"column":25,"index":25}}, + "declarations": [ + { + "type": "VariableDeclarator", + "start":23,"end":24,"loc":{"start":{"line":1,"column":23,"index":23},"end":{"line":1,"column":24,"index":24}}, + "id": { + "type": "Identifier", + "start":23,"end":24,"loc":{"start":{"line":1,"column":23,"index":23},"end":{"line":1,"column":24,"index":24},"identifierName":"x"}, + "name": "x" + }, + "init": null + } + ], + "kind": "var" + }, + { + "type": "FunctionDeclaration", + "start":26,"end":41,"loc":{"start":{"line":1,"column":26,"index":26},"end":{"line":1,"column":41,"index":41}}, + "id": { + "type": "Identifier", + "start":35,"end":36,"loc":{"start":{"line":1,"column":35,"index":35},"end":{"line":1,"column":36,"index":36},"identifierName":"x"}, + "name": "x" + }, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start":39,"end":41,"loc":{"start":{"line":1,"column":39,"index":39},"end":{"line":1,"column":41,"index":41}}, + "body": [], + "directives": [] + } + } + ] + } + ] + } + } + ], + "directives": [] + } +} diff --git a/packages/babel-parser/test/fixtures/experimental/class-static-block/invalid-arguments/output.json b/packages/babel-parser/test/fixtures/experimental/class-static-block/invalid-arguments/output.json index 2322ba838c29..4358565f74bd 100644 --- a/packages/babel-parser/test/fixtures/experimental/class-static-block/invalid-arguments/output.json +++ b/packages/babel-parser/test/fixtures/experimental/class-static-block/invalid-arguments/output.json @@ -1,9 +1,6 @@ { "type": "File", "start":0,"end":52,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":5,"column":1,"index":52}}, - "errors": [ - "SyntaxError: 'arguments' is only allowed in functions and class methods. (3:15)" - ], "program": { "type": "Program", "start":0,"end":52,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":5,"column":1,"index":52}}, diff --git a/packages/babel-runtime-corejs2/helpers/esm/possibleConstructorReturn.js b/packages/babel-runtime-corejs2/helpers/esm/possibleConstructorReturn.js index 56d554457e8d..d310ac2c7837 100644 --- a/packages/babel-runtime-corejs2/helpers/esm/possibleConstructorReturn.js +++ b/packages/babel-runtime-corejs2/helpers/esm/possibleConstructorReturn.js @@ -1,4 +1,4 @@ -import _typeof from "./typeof.js"; +import _typeof from "@babel/runtime-corejs2/helpers/typeof"; import assertThisInitialized from "./assertThisInitialized.js"; export default function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { diff --git a/packages/babel-runtime-corejs2/helpers/possibleConstructorReturn.js b/packages/babel-runtime-corejs2/helpers/possibleConstructorReturn.js index e1997be41941..69434a9da86a 100644 --- a/packages/babel-runtime-corejs2/helpers/possibleConstructorReturn.js +++ b/packages/babel-runtime-corejs2/helpers/possibleConstructorReturn.js @@ -1,4 +1,4 @@ -var _typeof = require("./typeof.js")["default"]; +var _typeof = require("@babel/runtime-corejs2/helpers/typeof")["default"]; var assertThisInitialized = require("./assertThisInitialized.js"); diff --git a/packages/babel-runtime-corejs3/helpers/esm/possibleConstructorReturn.js b/packages/babel-runtime-corejs3/helpers/esm/possibleConstructorReturn.js index 56d554457e8d..51d122c2557d 100644 --- a/packages/babel-runtime-corejs3/helpers/esm/possibleConstructorReturn.js +++ b/packages/babel-runtime-corejs3/helpers/esm/possibleConstructorReturn.js @@ -1,4 +1,4 @@ -import _typeof from "./typeof.js"; +import _typeof from "@babel/runtime-corejs3/helpers/typeof"; import assertThisInitialized from "./assertThisInitialized.js"; export default function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { diff --git a/packages/babel-runtime-corejs3/helpers/possibleConstructorReturn.js b/packages/babel-runtime-corejs3/helpers/possibleConstructorReturn.js index e1997be41941..9a2f6faccecf 100644 --- a/packages/babel-runtime-corejs3/helpers/possibleConstructorReturn.js +++ b/packages/babel-runtime-corejs3/helpers/possibleConstructorReturn.js @@ -1,4 +1,4 @@ -var _typeof = require("./typeof.js")["default"]; +var _typeof = require("@babel/runtime-corejs3/helpers/typeof")["default"]; var assertThisInitialized = require("./assertThisInitialized.js"); diff --git a/packages/babel-runtime/helpers/esm/possibleConstructorReturn.js b/packages/babel-runtime/helpers/esm/possibleConstructorReturn.js index 56d554457e8d..8566e115778a 100644 --- a/packages/babel-runtime/helpers/esm/possibleConstructorReturn.js +++ b/packages/babel-runtime/helpers/esm/possibleConstructorReturn.js @@ -1,4 +1,4 @@ -import _typeof from "./typeof.js"; +import _typeof from "@babel/runtime/helpers/typeof"; import assertThisInitialized from "./assertThisInitialized.js"; export default function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { diff --git a/packages/babel-runtime/helpers/possibleConstructorReturn.js b/packages/babel-runtime/helpers/possibleConstructorReturn.js index e1997be41941..ba95ae43504e 100644 --- a/packages/babel-runtime/helpers/possibleConstructorReturn.js +++ b/packages/babel-runtime/helpers/possibleConstructorReturn.js @@ -1,4 +1,4 @@ -var _typeof = require("./typeof.js")["default"]; +var _typeof = require("@babel/runtime/helpers/typeof")["default"]; var assertThisInitialized = require("./assertThisInitialized.js"); From 523b58775e035c2f643580de65f29eacb863b1dd Mon Sep 17 00:00:00 2001 From: Yokubjon-J Date: Tue, 8 Mar 2022 00:34:37 +0500 Subject: [PATCH 02/10] removed SCOPE_FUNCTION addition in statement.js (babel-parser) --- packages/babel-parser/src/parser/statement.js | 2 +- .../class-static-block/invalid-arguments/output.json | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/babel-parser/src/parser/statement.js b/packages/babel-parser/src/parser/statement.js index 1b6d70748e1f..1ca7c1a5ef04 100644 --- a/packages/babel-parser/src/parser/statement.js +++ b/packages/babel-parser/src/parser/statement.js @@ -1742,7 +1742,7 @@ export default class StatementParser extends ExpressionParser { member: N.StaticBlock & { decorators?: Array }, ) { // Start a new lexical scope - this.scope.enter(SCOPE_CLASS | SCOPE_STATIC_BLOCK | SCOPE_SUPER | SCOPE_FUNCTION); + this.scope.enter(SCOPE_CLASS | SCOPE_STATIC_BLOCK | SCOPE_SUPER); // Start a new scope with regard to loop labels const oldLabels = this.state.labels; this.state.labels = []; diff --git a/packages/babel-parser/test/fixtures/experimental/class-static-block/invalid-arguments/output.json b/packages/babel-parser/test/fixtures/experimental/class-static-block/invalid-arguments/output.json index 4358565f74bd..2322ba838c29 100644 --- a/packages/babel-parser/test/fixtures/experimental/class-static-block/invalid-arguments/output.json +++ b/packages/babel-parser/test/fixtures/experimental/class-static-block/invalid-arguments/output.json @@ -1,6 +1,9 @@ { "type": "File", "start":0,"end":52,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":5,"column":1,"index":52}}, + "errors": [ + "SyntaxError: 'arguments' is only allowed in functions and class methods. (3:15)" + ], "program": { "type": "Program", "start":0,"end":52,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":5,"column":1,"index":52}}, From 4c62c6867910c5192c17a543029694fcd75efa8f Mon Sep 17 00:00:00 2001 From: Yokubjon-J Date: Tue, 8 Mar 2022 00:54:08 +0500 Subject: [PATCH 03/10] Update packages/babel-parser/src/util/scope.js MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Huáng Jùnliàng --- packages/babel-parser/src/util/scope.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/babel-parser/src/util/scope.js b/packages/babel-parser/src/util/scope.js index f00732ce1822..4f15035a1742 100644 --- a/packages/babel-parser/src/util/scope.js +++ b/packages/babel-parser/src/util/scope.js @@ -103,7 +103,7 @@ export default class ScopeHandler { // > treated like var declarations rather than like lexical declarations. treatFunctionsAsVarInScope(scope: IScope): boolean { return !!( - scope.flags & SCOPE_FUNCTION || scope.flags & SCOPE_STATIC_BLOCK || + scope.flags & (SCOPE_FUNCTION | SCOPE_STATIC_BLOCK) || (!this.parser.inModule && scope.flags & SCOPE_PROGRAM) ); } From 65e0a447eb844a99affb16105c9dc4828500b60d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Ribaudo?= Date: Wed, 9 Mar 2022 23:42:01 +0100 Subject: [PATCH 04/10] Undo unrelated changes --- .../helpers/esm/possibleConstructorReturn.js | 2 +- .../babel-runtime-corejs2/helpers/possibleConstructorReturn.js | 2 +- .../helpers/esm/possibleConstructorReturn.js | 2 +- .../babel-runtime-corejs3/helpers/possibleConstructorReturn.js | 2 +- packages/babel-runtime/helpers/esm/possibleConstructorReturn.js | 2 +- packages/babel-runtime/helpers/possibleConstructorReturn.js | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/babel-runtime-corejs2/helpers/esm/possibleConstructorReturn.js b/packages/babel-runtime-corejs2/helpers/esm/possibleConstructorReturn.js index d310ac2c7837..56d554457e8d 100644 --- a/packages/babel-runtime-corejs2/helpers/esm/possibleConstructorReturn.js +++ b/packages/babel-runtime-corejs2/helpers/esm/possibleConstructorReturn.js @@ -1,4 +1,4 @@ -import _typeof from "@babel/runtime-corejs2/helpers/typeof"; +import _typeof from "./typeof.js"; import assertThisInitialized from "./assertThisInitialized.js"; export default function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { diff --git a/packages/babel-runtime-corejs2/helpers/possibleConstructorReturn.js b/packages/babel-runtime-corejs2/helpers/possibleConstructorReturn.js index 69434a9da86a..e1997be41941 100644 --- a/packages/babel-runtime-corejs2/helpers/possibleConstructorReturn.js +++ b/packages/babel-runtime-corejs2/helpers/possibleConstructorReturn.js @@ -1,4 +1,4 @@ -var _typeof = require("@babel/runtime-corejs2/helpers/typeof")["default"]; +var _typeof = require("./typeof.js")["default"]; var assertThisInitialized = require("./assertThisInitialized.js"); diff --git a/packages/babel-runtime-corejs3/helpers/esm/possibleConstructorReturn.js b/packages/babel-runtime-corejs3/helpers/esm/possibleConstructorReturn.js index 51d122c2557d..56d554457e8d 100644 --- a/packages/babel-runtime-corejs3/helpers/esm/possibleConstructorReturn.js +++ b/packages/babel-runtime-corejs3/helpers/esm/possibleConstructorReturn.js @@ -1,4 +1,4 @@ -import _typeof from "@babel/runtime-corejs3/helpers/typeof"; +import _typeof from "./typeof.js"; import assertThisInitialized from "./assertThisInitialized.js"; export default function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { diff --git a/packages/babel-runtime-corejs3/helpers/possibleConstructorReturn.js b/packages/babel-runtime-corejs3/helpers/possibleConstructorReturn.js index 9a2f6faccecf..e1997be41941 100644 --- a/packages/babel-runtime-corejs3/helpers/possibleConstructorReturn.js +++ b/packages/babel-runtime-corejs3/helpers/possibleConstructorReturn.js @@ -1,4 +1,4 @@ -var _typeof = require("@babel/runtime-corejs3/helpers/typeof")["default"]; +var _typeof = require("./typeof.js")["default"]; var assertThisInitialized = require("./assertThisInitialized.js"); diff --git a/packages/babel-runtime/helpers/esm/possibleConstructorReturn.js b/packages/babel-runtime/helpers/esm/possibleConstructorReturn.js index 8566e115778a..56d554457e8d 100644 --- a/packages/babel-runtime/helpers/esm/possibleConstructorReturn.js +++ b/packages/babel-runtime/helpers/esm/possibleConstructorReturn.js @@ -1,4 +1,4 @@ -import _typeof from "@babel/runtime/helpers/typeof"; +import _typeof from "./typeof.js"; import assertThisInitialized from "./assertThisInitialized.js"; export default function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { diff --git a/packages/babel-runtime/helpers/possibleConstructorReturn.js b/packages/babel-runtime/helpers/possibleConstructorReturn.js index ba95ae43504e..e1997be41941 100644 --- a/packages/babel-runtime/helpers/possibleConstructorReturn.js +++ b/packages/babel-runtime/helpers/possibleConstructorReturn.js @@ -1,4 +1,4 @@ -var _typeof = require("@babel/runtime/helpers/typeof")["default"]; +var _typeof = require("./typeof.js")["default"]; var assertThisInitialized = require("./assertThisInitialized.js"); From 12baa1ba8f2b7abe418b586d2af5b29934811896 Mon Sep 17 00:00:00 2001 From: Yokubjon-J Date: Thu, 10 Mar 2022 13:39:07 +0500 Subject: [PATCH 05/10] test case in new subdir --- .../static-block-duplicate-name/input.js | 6 ++ .../static-block-duplicate-name/output.json | 70 +++++++++++++++++++ .../helpers/esm/possibleConstructorReturn.js | 2 +- .../helpers/possibleConstructorReturn.js | 2 +- .../helpers/esm/possibleConstructorReturn.js | 2 +- .../helpers/possibleConstructorReturn.js | 2 +- .../helpers/esm/possibleConstructorReturn.js | 2 +- .../helpers/possibleConstructorReturn.js | 2 +- 8 files changed, 82 insertions(+), 6 deletions(-) create mode 100644 packages/babel-parser/test/fixtures/es2022/class-private-names-duplicated/static-block-duplicate-name/input.js create mode 100644 packages/babel-parser/test/fixtures/es2022/class-private-names-duplicated/static-block-duplicate-name/output.json diff --git a/packages/babel-parser/test/fixtures/es2022/class-private-names-duplicated/static-block-duplicate-name/input.js b/packages/babel-parser/test/fixtures/es2022/class-private-names-duplicated/static-block-duplicate-name/input.js new file mode 100644 index 000000000000..94af12032127 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2022/class-private-names-duplicated/static-block-duplicate-name/input.js @@ -0,0 +1,6 @@ +class X { + static { + var x; + function x() {} + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2022/class-private-names-duplicated/static-block-duplicate-name/output.json b/packages/babel-parser/test/fixtures/es2022/class-private-names-duplicated/static-block-duplicate-name/output.json new file mode 100644 index 000000000000..7c588fc92a2d --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2022/class-private-names-duplicated/static-block-duplicate-name/output.json @@ -0,0 +1,70 @@ +{ + "type": "File", + "start":0,"end":65,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":6,"column":1,"index":65}}, + "program": { + "type": "Program", + "start":0,"end":65,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":6,"column":1,"index":65}}, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ClassDeclaration", + "start":0,"end":65,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":6,"column":1,"index":65}}, + "id": { + "type": "Identifier", + "start":6,"end":7,"loc":{"start":{"line":1,"column":6,"index":6},"end":{"line":1,"column":7,"index":7},"identifierName":"X"}, + "name": "X" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start":8,"end":65,"loc":{"start":{"line":1,"column":8,"index":8},"end":{"line":6,"column":1,"index":65}}, + "body": [ + { + "type": "StaticBlock", + "start":14,"end":63,"loc":{"start":{"line":2,"column":4,"index":14},"end":{"line":5,"column":5,"index":63}}, + "body": [ + { + "type": "VariableDeclaration", + "start":29,"end":35,"loc":{"start":{"line":3,"column":6,"index":29},"end":{"line":3,"column":12,"index":35}}, + "declarations": [ + { + "type": "VariableDeclarator", + "start":33,"end":34,"loc":{"start":{"line":3,"column":10,"index":33},"end":{"line":3,"column":11,"index":34}}, + "id": { + "type": "Identifier", + "start":33,"end":34,"loc":{"start":{"line":3,"column":10,"index":33},"end":{"line":3,"column":11,"index":34},"identifierName":"x"}, + "name": "x" + }, + "init": null + } + ], + "kind": "var" + }, + { + "type": "FunctionDeclaration", + "start":42,"end":57,"loc":{"start":{"line":4,"column":6,"index":42},"end":{"line":4,"column":21,"index":57}}, + "id": { + "type": "Identifier", + "start":51,"end":52,"loc":{"start":{"line":4,"column":15,"index":51},"end":{"line":4,"column":16,"index":52},"identifierName":"x"}, + "name": "x" + }, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start":55,"end":57,"loc":{"start":{"line":4,"column":19,"index":55},"end":{"line":4,"column":21,"index":57}}, + "body": [], + "directives": [] + } + } + ] + } + ] + } + } + ], + "directives": [] + } +} diff --git a/packages/babel-runtime-corejs2/helpers/esm/possibleConstructorReturn.js b/packages/babel-runtime-corejs2/helpers/esm/possibleConstructorReturn.js index 56d554457e8d..d310ac2c7837 100644 --- a/packages/babel-runtime-corejs2/helpers/esm/possibleConstructorReturn.js +++ b/packages/babel-runtime-corejs2/helpers/esm/possibleConstructorReturn.js @@ -1,4 +1,4 @@ -import _typeof from "./typeof.js"; +import _typeof from "@babel/runtime-corejs2/helpers/typeof"; import assertThisInitialized from "./assertThisInitialized.js"; export default function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { diff --git a/packages/babel-runtime-corejs2/helpers/possibleConstructorReturn.js b/packages/babel-runtime-corejs2/helpers/possibleConstructorReturn.js index e1997be41941..69434a9da86a 100644 --- a/packages/babel-runtime-corejs2/helpers/possibleConstructorReturn.js +++ b/packages/babel-runtime-corejs2/helpers/possibleConstructorReturn.js @@ -1,4 +1,4 @@ -var _typeof = require("./typeof.js")["default"]; +var _typeof = require("@babel/runtime-corejs2/helpers/typeof")["default"]; var assertThisInitialized = require("./assertThisInitialized.js"); diff --git a/packages/babel-runtime-corejs3/helpers/esm/possibleConstructorReturn.js b/packages/babel-runtime-corejs3/helpers/esm/possibleConstructorReturn.js index 56d554457e8d..51d122c2557d 100644 --- a/packages/babel-runtime-corejs3/helpers/esm/possibleConstructorReturn.js +++ b/packages/babel-runtime-corejs3/helpers/esm/possibleConstructorReturn.js @@ -1,4 +1,4 @@ -import _typeof from "./typeof.js"; +import _typeof from "@babel/runtime-corejs3/helpers/typeof"; import assertThisInitialized from "./assertThisInitialized.js"; export default function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { diff --git a/packages/babel-runtime-corejs3/helpers/possibleConstructorReturn.js b/packages/babel-runtime-corejs3/helpers/possibleConstructorReturn.js index e1997be41941..9a2f6faccecf 100644 --- a/packages/babel-runtime-corejs3/helpers/possibleConstructorReturn.js +++ b/packages/babel-runtime-corejs3/helpers/possibleConstructorReturn.js @@ -1,4 +1,4 @@ -var _typeof = require("./typeof.js")["default"]; +var _typeof = require("@babel/runtime-corejs3/helpers/typeof")["default"]; var assertThisInitialized = require("./assertThisInitialized.js"); diff --git a/packages/babel-runtime/helpers/esm/possibleConstructorReturn.js b/packages/babel-runtime/helpers/esm/possibleConstructorReturn.js index 56d554457e8d..8566e115778a 100644 --- a/packages/babel-runtime/helpers/esm/possibleConstructorReturn.js +++ b/packages/babel-runtime/helpers/esm/possibleConstructorReturn.js @@ -1,4 +1,4 @@ -import _typeof from "./typeof.js"; +import _typeof from "@babel/runtime/helpers/typeof"; import assertThisInitialized from "./assertThisInitialized.js"; export default function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { diff --git a/packages/babel-runtime/helpers/possibleConstructorReturn.js b/packages/babel-runtime/helpers/possibleConstructorReturn.js index e1997be41941..ba95ae43504e 100644 --- a/packages/babel-runtime/helpers/possibleConstructorReturn.js +++ b/packages/babel-runtime/helpers/possibleConstructorReturn.js @@ -1,4 +1,4 @@ -var _typeof = require("./typeof.js")["default"]; +var _typeof = require("@babel/runtime/helpers/typeof")["default"]; var assertThisInitialized = require("./assertThisInitialized.js"); From 48b57918e66b812b74991ad7fda9d5c4e1d0d639 Mon Sep 17 00:00:00 2001 From: Yokubjon-J Date: Thu, 10 Mar 2022 13:50:47 +0500 Subject: [PATCH 06/10] import typeof.js --- .../babel-runtime-corejs3/helpers/possibleConstructorReturn.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/babel-runtime-corejs3/helpers/possibleConstructorReturn.js b/packages/babel-runtime-corejs3/helpers/possibleConstructorReturn.js index 9a2f6faccecf..e1997be41941 100644 --- a/packages/babel-runtime-corejs3/helpers/possibleConstructorReturn.js +++ b/packages/babel-runtime-corejs3/helpers/possibleConstructorReturn.js @@ -1,4 +1,4 @@ -var _typeof = require("@babel/runtime-corejs3/helpers/typeof")["default"]; +var _typeof = require("./typeof.js")["default"]; var assertThisInitialized = require("./assertThisInitialized.js"); From 56b67a0bebb93834d6df5f7f5458b98a38d73968 Mon Sep 17 00:00:00 2001 From: Yokubjon-J Date: Thu, 10 Mar 2022 14:00:14 +0500 Subject: [PATCH 07/10] import typeof.js --- .../babel-runtime-corejs2/helpers/possibleConstructorReturn.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/babel-runtime-corejs2/helpers/possibleConstructorReturn.js b/packages/babel-runtime-corejs2/helpers/possibleConstructorReturn.js index 69434a9da86a..e1997be41941 100644 --- a/packages/babel-runtime-corejs2/helpers/possibleConstructorReturn.js +++ b/packages/babel-runtime-corejs2/helpers/possibleConstructorReturn.js @@ -1,4 +1,4 @@ -var _typeof = require("@babel/runtime-corejs2/helpers/typeof")["default"]; +var _typeof = require("./typeof.js")["default"]; var assertThisInitialized = require("./assertThisInitialized.js"); From 3d4ae5e57a2afc6bb180bd5f86e588bcf2002b5c Mon Sep 17 00:00:00 2001 From: Yokubjon-J Date: Thu, 10 Mar 2022 22:38:05 +0500 Subject: [PATCH 08/10] import typeof.js in babel-runtime --- packages/babel-runtime/helpers/esm/possibleConstructorReturn.js | 2 +- packages/babel-runtime/helpers/possibleConstructorReturn.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/babel-runtime/helpers/esm/possibleConstructorReturn.js b/packages/babel-runtime/helpers/esm/possibleConstructorReturn.js index 8566e115778a..56d554457e8d 100644 --- a/packages/babel-runtime/helpers/esm/possibleConstructorReturn.js +++ b/packages/babel-runtime/helpers/esm/possibleConstructorReturn.js @@ -1,4 +1,4 @@ -import _typeof from "@babel/runtime/helpers/typeof"; +import _typeof from "./typeof.js"; import assertThisInitialized from "./assertThisInitialized.js"; export default function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { diff --git a/packages/babel-runtime/helpers/possibleConstructorReturn.js b/packages/babel-runtime/helpers/possibleConstructorReturn.js index ba95ae43504e..e1997be41941 100644 --- a/packages/babel-runtime/helpers/possibleConstructorReturn.js +++ b/packages/babel-runtime/helpers/possibleConstructorReturn.js @@ -1,4 +1,4 @@ -var _typeof = require("@babel/runtime/helpers/typeof")["default"]; +var _typeof = require("./typeof.js")["default"]; var assertThisInitialized = require("./assertThisInitialized.js"); From aab61255fe7498cc9547695f5b767ec5c40bc805 Mon Sep 17 00:00:00 2001 From: Yokubjon-J Date: Thu, 10 Mar 2022 22:51:59 +0500 Subject: [PATCH 09/10] import correct typeof.js in corejs2 and 3 in esm --- .../helpers/esm/possibleConstructorReturn.js | 2 +- .../helpers/esm/possibleConstructorReturn.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/babel-runtime-corejs2/helpers/esm/possibleConstructorReturn.js b/packages/babel-runtime-corejs2/helpers/esm/possibleConstructorReturn.js index d310ac2c7837..56d554457e8d 100644 --- a/packages/babel-runtime-corejs2/helpers/esm/possibleConstructorReturn.js +++ b/packages/babel-runtime-corejs2/helpers/esm/possibleConstructorReturn.js @@ -1,4 +1,4 @@ -import _typeof from "@babel/runtime-corejs2/helpers/typeof"; +import _typeof from "./typeof.js"; import assertThisInitialized from "./assertThisInitialized.js"; export default function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { diff --git a/packages/babel-runtime-corejs3/helpers/esm/possibleConstructorReturn.js b/packages/babel-runtime-corejs3/helpers/esm/possibleConstructorReturn.js index 51d122c2557d..56d554457e8d 100644 --- a/packages/babel-runtime-corejs3/helpers/esm/possibleConstructorReturn.js +++ b/packages/babel-runtime-corejs3/helpers/esm/possibleConstructorReturn.js @@ -1,4 +1,4 @@ -import _typeof from "@babel/runtime-corejs3/helpers/typeof"; +import _typeof from "./typeof.js"; import assertThisInitialized from "./assertThisInitialized.js"; export default function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { From 5bedc6c6cbacfb654ce4bb714946017e8061f5db Mon Sep 17 00:00:00 2001 From: Yokubjon-J Date: Thu, 10 Mar 2022 23:28:38 +0500 Subject: [PATCH 10/10] removed 2 unneeded tests from es2015 --- .../input.js | 1 - .../output.json | 70 ------------------- .../es2015/class/static-block/input.js | 1 - .../es2015/class/static-block/output.json | 70 ------------------- 4 files changed, 142 deletions(-) delete mode 100644 packages/babel-parser/test/fixtures/es2015/class/static-block-var-and-func-same-name/input.js delete mode 100644 packages/babel-parser/test/fixtures/es2015/class/static-block-var-and-func-same-name/output.json delete mode 100644 packages/babel-parser/test/fixtures/es2015/class/static-block/input.js delete mode 100644 packages/babel-parser/test/fixtures/es2015/class/static-block/output.json diff --git a/packages/babel-parser/test/fixtures/es2015/class/static-block-var-and-func-same-name/input.js b/packages/babel-parser/test/fixtures/es2015/class/static-block-var-and-func-same-name/input.js deleted file mode 100644 index 7b8e2670b0ee..000000000000 --- a/packages/babel-parser/test/fixtures/es2015/class/static-block-var-and-func-same-name/input.js +++ /dev/null @@ -1 +0,0 @@ -class X { static { var x; function x() {} } } \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2015/class/static-block-var-and-func-same-name/output.json b/packages/babel-parser/test/fixtures/es2015/class/static-block-var-and-func-same-name/output.json deleted file mode 100644 index bd56c7de1f9e..000000000000 --- a/packages/babel-parser/test/fixtures/es2015/class/static-block-var-and-func-same-name/output.json +++ /dev/null @@ -1,70 +0,0 @@ -{ - "type": "File", - "start":0,"end":45,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":45,"index":45}}, - "program": { - "type": "Program", - "start":0,"end":45,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":45,"index":45}}, - "sourceType": "script", - "interpreter": null, - "body": [ - { - "type": "ClassDeclaration", - "start":0,"end":45,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":45,"index":45}}, - "id": { - "type": "Identifier", - "start":6,"end":7,"loc":{"start":{"line":1,"column":6,"index":6},"end":{"line":1,"column":7,"index":7},"identifierName":"X"}, - "name": "X" - }, - "superClass": null, - "body": { - "type": "ClassBody", - "start":8,"end":45,"loc":{"start":{"line":1,"column":8,"index":8},"end":{"line":1,"column":45,"index":45}}, - "body": [ - { - "type": "StaticBlock", - "start":10,"end":43,"loc":{"start":{"line":1,"column":10,"index":10},"end":{"line":1,"column":43,"index":43}}, - "body": [ - { - "type": "VariableDeclaration", - "start":19,"end":25,"loc":{"start":{"line":1,"column":19,"index":19},"end":{"line":1,"column":25,"index":25}}, - "declarations": [ - { - "type": "VariableDeclarator", - "start":23,"end":24,"loc":{"start":{"line":1,"column":23,"index":23},"end":{"line":1,"column":24,"index":24}}, - "id": { - "type": "Identifier", - "start":23,"end":24,"loc":{"start":{"line":1,"column":23,"index":23},"end":{"line":1,"column":24,"index":24},"identifierName":"x"}, - "name": "x" - }, - "init": null - } - ], - "kind": "var" - }, - { - "type": "FunctionDeclaration", - "start":26,"end":41,"loc":{"start":{"line":1,"column":26,"index":26},"end":{"line":1,"column":41,"index":41}}, - "id": { - "type": "Identifier", - "start":35,"end":36,"loc":{"start":{"line":1,"column":35,"index":35},"end":{"line":1,"column":36,"index":36},"identifierName":"x"}, - "name": "x" - }, - "generator": false, - "async": false, - "params": [], - "body": { - "type": "BlockStatement", - "start":39,"end":41,"loc":{"start":{"line":1,"column":39,"index":39},"end":{"line":1,"column":41,"index":41}}, - "body": [], - "directives": [] - } - } - ] - } - ] - } - } - ], - "directives": [] - } -} diff --git a/packages/babel-parser/test/fixtures/es2015/class/static-block/input.js b/packages/babel-parser/test/fixtures/es2015/class/static-block/input.js deleted file mode 100644 index 7b8e2670b0ee..000000000000 --- a/packages/babel-parser/test/fixtures/es2015/class/static-block/input.js +++ /dev/null @@ -1 +0,0 @@ -class X { static { var x; function x() {} } } \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2015/class/static-block/output.json b/packages/babel-parser/test/fixtures/es2015/class/static-block/output.json deleted file mode 100644 index bd56c7de1f9e..000000000000 --- a/packages/babel-parser/test/fixtures/es2015/class/static-block/output.json +++ /dev/null @@ -1,70 +0,0 @@ -{ - "type": "File", - "start":0,"end":45,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":45,"index":45}}, - "program": { - "type": "Program", - "start":0,"end":45,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":45,"index":45}}, - "sourceType": "script", - "interpreter": null, - "body": [ - { - "type": "ClassDeclaration", - "start":0,"end":45,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":45,"index":45}}, - "id": { - "type": "Identifier", - "start":6,"end":7,"loc":{"start":{"line":1,"column":6,"index":6},"end":{"line":1,"column":7,"index":7},"identifierName":"X"}, - "name": "X" - }, - "superClass": null, - "body": { - "type": "ClassBody", - "start":8,"end":45,"loc":{"start":{"line":1,"column":8,"index":8},"end":{"line":1,"column":45,"index":45}}, - "body": [ - { - "type": "StaticBlock", - "start":10,"end":43,"loc":{"start":{"line":1,"column":10,"index":10},"end":{"line":1,"column":43,"index":43}}, - "body": [ - { - "type": "VariableDeclaration", - "start":19,"end":25,"loc":{"start":{"line":1,"column":19,"index":19},"end":{"line":1,"column":25,"index":25}}, - "declarations": [ - { - "type": "VariableDeclarator", - "start":23,"end":24,"loc":{"start":{"line":1,"column":23,"index":23},"end":{"line":1,"column":24,"index":24}}, - "id": { - "type": "Identifier", - "start":23,"end":24,"loc":{"start":{"line":1,"column":23,"index":23},"end":{"line":1,"column":24,"index":24},"identifierName":"x"}, - "name": "x" - }, - "init": null - } - ], - "kind": "var" - }, - { - "type": "FunctionDeclaration", - "start":26,"end":41,"loc":{"start":{"line":1,"column":26,"index":26},"end":{"line":1,"column":41,"index":41}}, - "id": { - "type": "Identifier", - "start":35,"end":36,"loc":{"start":{"line":1,"column":35,"index":35},"end":{"line":1,"column":36,"index":36},"identifierName":"x"}, - "name": "x" - }, - "generator": false, - "async": false, - "params": [], - "body": { - "type": "BlockStatement", - "start":39,"end":41,"loc":{"start":{"line":1,"column":39,"index":39},"end":{"line":1,"column":41,"index":41}}, - "body": [], - "directives": [] - } - } - ] - } - ] - } - } - ], - "directives": [] - } -}