Parse class static block (#12079)
Co-authored-by: Brian Ng <bng412@gmail.com>
This commit is contained in:
committed by
Nicolò Ribaudo
parent
6830c90ac9
commit
3ccca88178
6
packages/babel-parser/test/fixtures/experimental/_no-plugin/class-static-block/input.js
vendored
Normal file
6
packages/babel-parser/test/fixtures/experimental/_no-plugin/class-static-block/input.js
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
class C {
|
||||
static foo() {}
|
||||
static {
|
||||
this.bar = this.foo;
|
||||
}
|
||||
}
|
||||
3
packages/babel-parser/test/fixtures/experimental/_no-plugin/class-static-block/options.json
vendored
Normal file
3
packages/babel-parser/test/fixtures/experimental/_no-plugin/class-static-block/options.json
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"throws": "This experimental syntax requires enabling the parser plugin: 'classStaticBlock' (3:2)"
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
"type": "File",
|
||||
"start":0,"end":60,"loc":{"start":{"line":1,"column":0},"end":{"line":5,"column":1}},
|
||||
"errors": [
|
||||
"SyntaxError: 'arguments' is not allowed in class field initializer (3:16)"
|
||||
"SyntaxError: 'arguments' is only allowed in functions and class methods (3:16)"
|
||||
],
|
||||
"program": {
|
||||
"type": "Program",
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
"type": "File",
|
||||
"start":0,"end":76,"loc":{"start":{"line":1,"column":0},"end":{"line":5,"column":1}},
|
||||
"errors": [
|
||||
"SyntaxError: 'arguments' is not allowed in class field initializer (3:25)"
|
||||
"SyntaxError: 'arguments' is only allowed in functions and class methods (3:25)"
|
||||
],
|
||||
"program": {
|
||||
"type": "Program",
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
"type": "File",
|
||||
"start":0,"end":54,"loc":{"start":{"line":1,"column":0},"end":{"line":5,"column":1}},
|
||||
"errors": [
|
||||
"SyntaxError: 'arguments' is not allowed in class field initializer (3:10)"
|
||||
"SyntaxError: 'arguments' is only allowed in functions and class methods (3:10)"
|
||||
],
|
||||
"program": {
|
||||
"type": "Program",
|
||||
|
||||
6
packages/babel-parser/test/fixtures/experimental/class-static-block/basic/input.js
vendored
Normal file
6
packages/babel-parser/test/fixtures/experimental/class-static-block/basic/input.js
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
class C {
|
||||
static foo() {}
|
||||
static {
|
||||
this.bar = this.foo;
|
||||
}
|
||||
}
|
||||
94
packages/babel-parser/test/fixtures/experimental/class-static-block/basic/output.json
vendored
Normal file
94
packages/babel-parser/test/fixtures/experimental/class-static-block/basic/output.json
vendored
Normal file
@@ -0,0 +1,94 @@
|
||||
{
|
||||
"type": "File",
|
||||
"start":0,"end":69,"loc":{"start":{"line":1,"column":0},"end":{"line":6,"column":1}},
|
||||
"program": {
|
||||
"type": "Program",
|
||||
"start":0,"end":69,"loc":{"start":{"line":1,"column":0},"end":{"line":6,"column":1}},
|
||||
"sourceType": "script",
|
||||
"interpreter": null,
|
||||
"body": [
|
||||
{
|
||||
"type": "ClassDeclaration",
|
||||
"start":0,"end":69,"loc":{"start":{"line":1,"column":0},"end":{"line":6,"column":1}},
|
||||
"id": {
|
||||
"type": "Identifier",
|
||||
"start":6,"end":7,"loc":{"start":{"line":1,"column":6},"end":{"line":1,"column":7},"identifierName":"C"},
|
||||
"name": "C"
|
||||
},
|
||||
"superClass": null,
|
||||
"body": {
|
||||
"type": "ClassBody",
|
||||
"start":8,"end":69,"loc":{"start":{"line":1,"column":8},"end":{"line":6,"column":1}},
|
||||
"body": [
|
||||
{
|
||||
"type": "ClassMethod",
|
||||
"start":12,"end":27,"loc":{"start":{"line":2,"column":2},"end":{"line":2,"column":17}},
|
||||
"static": true,
|
||||
"key": {
|
||||
"type": "Identifier",
|
||||
"start":19,"end":22,"loc":{"start":{"line":2,"column":9},"end":{"line":2,"column":12},"identifierName":"foo"},
|
||||
"name": "foo"
|
||||
},
|
||||
"computed": false,
|
||||
"kind": "method",
|
||||
"id": null,
|
||||
"generator": false,
|
||||
"async": false,
|
||||
"params": [],
|
||||
"body": {
|
||||
"type": "BlockStatement",
|
||||
"start":25,"end":27,"loc":{"start":{"line":2,"column":15},"end":{"line":2,"column":17}},
|
||||
"body": [],
|
||||
"directives": []
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "StaticBlock",
|
||||
"start":30,"end":67,"loc":{"start":{"line":3,"column":2},"end":{"line":5,"column":3}},
|
||||
"body": [
|
||||
{
|
||||
"type": "ExpressionStatement",
|
||||
"start":43,"end":63,"loc":{"start":{"line":4,"column":4},"end":{"line":4,"column":24}},
|
||||
"expression": {
|
||||
"type": "AssignmentExpression",
|
||||
"start":43,"end":62,"loc":{"start":{"line":4,"column":4},"end":{"line":4,"column":23}},
|
||||
"operator": "=",
|
||||
"left": {
|
||||
"type": "MemberExpression",
|
||||
"start":43,"end":51,"loc":{"start":{"line":4,"column":4},"end":{"line":4,"column":12}},
|
||||
"object": {
|
||||
"type": "ThisExpression",
|
||||
"start":43,"end":47,"loc":{"start":{"line":4,"column":4},"end":{"line":4,"column":8}}
|
||||
},
|
||||
"computed": false,
|
||||
"property": {
|
||||
"type": "Identifier",
|
||||
"start":48,"end":51,"loc":{"start":{"line":4,"column":9},"end":{"line":4,"column":12},"identifierName":"bar"},
|
||||
"name": "bar"
|
||||
}
|
||||
},
|
||||
"right": {
|
||||
"type": "MemberExpression",
|
||||
"start":54,"end":62,"loc":{"start":{"line":4,"column":15},"end":{"line":4,"column":23}},
|
||||
"object": {
|
||||
"type": "ThisExpression",
|
||||
"start":54,"end":58,"loc":{"start":{"line":4,"column":15},"end":{"line":4,"column":19}}
|
||||
},
|
||||
"computed": false,
|
||||
"property": {
|
||||
"type": "Identifier",
|
||||
"start":59,"end":62,"loc":{"start":{"line":4,"column":20},"end":{"line":4,"column":23},"identifierName":"foo"},
|
||||
"name": "foo"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
class C {
|
||||
static foo() {}
|
||||
static {
|
||||
"use strict"; // will not be parsed as directives
|
||||
this.bar = this.foo;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
{
|
||||
"type": "File",
|
||||
"start":0,"end":123,"loc":{"start":{"line":1,"column":0},"end":{"line":7,"column":1}},
|
||||
"program": {
|
||||
"type": "Program",
|
||||
"start":0,"end":123,"loc":{"start":{"line":1,"column":0},"end":{"line":7,"column":1}},
|
||||
"sourceType": "script",
|
||||
"interpreter": null,
|
||||
"body": [
|
||||
{
|
||||
"type": "ClassDeclaration",
|
||||
"start":0,"end":123,"loc":{"start":{"line":1,"column":0},"end":{"line":7,"column":1}},
|
||||
"id": {
|
||||
"type": "Identifier",
|
||||
"start":6,"end":7,"loc":{"start":{"line":1,"column":6},"end":{"line":1,"column":7},"identifierName":"C"},
|
||||
"name": "C"
|
||||
},
|
||||
"superClass": null,
|
||||
"body": {
|
||||
"type": "ClassBody",
|
||||
"start":8,"end":123,"loc":{"start":{"line":1,"column":8},"end":{"line":7,"column":1}},
|
||||
"body": [
|
||||
{
|
||||
"type": "ClassMethod",
|
||||
"start":12,"end":27,"loc":{"start":{"line":2,"column":2},"end":{"line":2,"column":17}},
|
||||
"static": true,
|
||||
"key": {
|
||||
"type": "Identifier",
|
||||
"start":19,"end":22,"loc":{"start":{"line":2,"column":9},"end":{"line":2,"column":12},"identifierName":"foo"},
|
||||
"name": "foo"
|
||||
},
|
||||
"computed": false,
|
||||
"kind": "method",
|
||||
"id": null,
|
||||
"generator": false,
|
||||
"async": false,
|
||||
"params": [],
|
||||
"body": {
|
||||
"type": "BlockStatement",
|
||||
"start":25,"end":27,"loc":{"start":{"line":2,"column":15},"end":{"line":2,"column":17}},
|
||||
"body": [],
|
||||
"directives": []
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "StaticBlock",
|
||||
"start":30,"end":121,"loc":{"start":{"line":3,"column":2},"end":{"line":6,"column":3}},
|
||||
"body": [
|
||||
{
|
||||
"type": "ExpressionStatement",
|
||||
"start":43,"end":56,"loc":{"start":{"line":4,"column":4},"end":{"line":4,"column":17}},
|
||||
"trailingComments": [
|
||||
{
|
||||
"type": "CommentLine",
|
||||
"value": " will not be parsed as directives",
|
||||
"start":57,"end":92,"loc":{"start":{"line":4,"column":18},"end":{"line":4,"column":53}}
|
||||
}
|
||||
],
|
||||
"expression": {
|
||||
"type": "StringLiteral",
|
||||
"start":43,"end":55,"loc":{"start":{"line":4,"column":4},"end":{"line":4,"column":16}},
|
||||
"extra": {
|
||||
"rawValue": "use strict",
|
||||
"raw": "\"use strict\""
|
||||
},
|
||||
"value": "use strict"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "ExpressionStatement",
|
||||
"start":97,"end":117,"loc":{"start":{"line":5,"column":4},"end":{"line":5,"column":24}},
|
||||
"leadingComments": [
|
||||
{
|
||||
"type": "CommentLine",
|
||||
"value": " will not be parsed as directives",
|
||||
"start":57,"end":92,"loc":{"start":{"line":4,"column":18},"end":{"line":4,"column":53}}
|
||||
}
|
||||
],
|
||||
"expression": {
|
||||
"type": "AssignmentExpression",
|
||||
"start":97,"end":116,"loc":{"start":{"line":5,"column":4},"end":{"line":5,"column":23}},
|
||||
"operator": "=",
|
||||
"left": {
|
||||
"type": "MemberExpression",
|
||||
"start":97,"end":105,"loc":{"start":{"line":5,"column":4},"end":{"line":5,"column":12}},
|
||||
"object": {
|
||||
"type": "ThisExpression",
|
||||
"start":97,"end":101,"loc":{"start":{"line":5,"column":4},"end":{"line":5,"column":8}}
|
||||
},
|
||||
"computed": false,
|
||||
"property": {
|
||||
"type": "Identifier",
|
||||
"start":102,"end":105,"loc":{"start":{"line":5,"column":9},"end":{"line":5,"column":12},"identifierName":"bar"},
|
||||
"name": "bar"
|
||||
}
|
||||
},
|
||||
"right": {
|
||||
"type": "MemberExpression",
|
||||
"start":108,"end":116,"loc":{"start":{"line":5,"column":15},"end":{"line":5,"column":23}},
|
||||
"object": {
|
||||
"type": "ThisExpression",
|
||||
"start":108,"end":112,"loc":{"start":{"line":5,"column":15},"end":{"line":5,"column":19}}
|
||||
},
|
||||
"computed": false,
|
||||
"property": {
|
||||
"type": "Identifier",
|
||||
"start":113,"end":116,"loc":{"start":{"line":5,"column":20},"end":{"line":5,"column":23},"identifierName":"foo"},
|
||||
"name": "foo"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
],
|
||||
"directives": []
|
||||
},
|
||||
"comments": [
|
||||
{
|
||||
"type": "CommentLine",
|
||||
"value": " will not be parsed as directives",
|
||||
"start":57,"end":92,"loc":{"start":{"line":4,"column":18},"end":{"line":4,"column":53}}
|
||||
}
|
||||
]
|
||||
}
|
||||
4
packages/babel-parser/test/fixtures/experimental/class-static-block/empty-statement/input.js
vendored
Normal file
4
packages/babel-parser/test/fixtures/experimental/class-static-block/empty-statement/input.js
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
class C {
|
||||
static foo() {}
|
||||
static {}
|
||||
}
|
||||
56
packages/babel-parser/test/fixtures/experimental/class-static-block/empty-statement/output.json
vendored
Normal file
56
packages/babel-parser/test/fixtures/experimental/class-static-block/empty-statement/output.json
vendored
Normal file
@@ -0,0 +1,56 @@
|
||||
{
|
||||
"type": "File",
|
||||
"start":0,"end":41,"loc":{"start":{"line":1,"column":0},"end":{"line":4,"column":1}},
|
||||
"program": {
|
||||
"type": "Program",
|
||||
"start":0,"end":41,"loc":{"start":{"line":1,"column":0},"end":{"line":4,"column":1}},
|
||||
"sourceType": "script",
|
||||
"interpreter": null,
|
||||
"body": [
|
||||
{
|
||||
"type": "ClassDeclaration",
|
||||
"start":0,"end":41,"loc":{"start":{"line":1,"column":0},"end":{"line":4,"column":1}},
|
||||
"id": {
|
||||
"type": "Identifier",
|
||||
"start":6,"end":7,"loc":{"start":{"line":1,"column":6},"end":{"line":1,"column":7},"identifierName":"C"},
|
||||
"name": "C"
|
||||
},
|
||||
"superClass": null,
|
||||
"body": {
|
||||
"type": "ClassBody",
|
||||
"start":8,"end":41,"loc":{"start":{"line":1,"column":8},"end":{"line":4,"column":1}},
|
||||
"body": [
|
||||
{
|
||||
"type": "ClassMethod",
|
||||
"start":12,"end":27,"loc":{"start":{"line":2,"column":2},"end":{"line":2,"column":17}},
|
||||
"static": true,
|
||||
"key": {
|
||||
"type": "Identifier",
|
||||
"start":19,"end":22,"loc":{"start":{"line":2,"column":9},"end":{"line":2,"column":12},"identifierName":"foo"},
|
||||
"name": "foo"
|
||||
},
|
||||
"computed": false,
|
||||
"kind": "method",
|
||||
"id": null,
|
||||
"generator": false,
|
||||
"async": false,
|
||||
"params": [],
|
||||
"body": {
|
||||
"type": "BlockStatement",
|
||||
"start":25,"end":27,"loc":{"start":{"line":2,"column":15},"end":{"line":2,"column":17}},
|
||||
"body": [],
|
||||
"directives": []
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "StaticBlock",
|
||||
"start":30,"end":39,"loc":{"start":{"line":3,"column":2},"end":{"line":3,"column":11}},
|
||||
"body": []
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
class C {
|
||||
static {
|
||||
this.foo = arguments;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
{
|
||||
"type": "File",
|
||||
"start":0,"end":52,"loc":{"start":{"line":1,"column":0},"end":{"line":5,"column":1}},
|
||||
"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},"end":{"line":5,"column":1}},
|
||||
"sourceType": "script",
|
||||
"interpreter": null,
|
||||
"body": [
|
||||
{
|
||||
"type": "ClassDeclaration",
|
||||
"start":0,"end":52,"loc":{"start":{"line":1,"column":0},"end":{"line":5,"column":1}},
|
||||
"id": {
|
||||
"type": "Identifier",
|
||||
"start":6,"end":7,"loc":{"start":{"line":1,"column":6},"end":{"line":1,"column":7},"identifierName":"C"},
|
||||
"name": "C"
|
||||
},
|
||||
"superClass": null,
|
||||
"body": {
|
||||
"type": "ClassBody",
|
||||
"start":8,"end":52,"loc":{"start":{"line":1,"column":8},"end":{"line":5,"column":1}},
|
||||
"body": [
|
||||
{
|
||||
"type": "StaticBlock",
|
||||
"start":12,"end":50,"loc":{"start":{"line":2,"column":2},"end":{"line":4,"column":3}},
|
||||
"body": [
|
||||
{
|
||||
"type": "ExpressionStatement",
|
||||
"start":25,"end":46,"loc":{"start":{"line":3,"column":4},"end":{"line":3,"column":25}},
|
||||
"expression": {
|
||||
"type": "AssignmentExpression",
|
||||
"start":25,"end":45,"loc":{"start":{"line":3,"column":4},"end":{"line":3,"column":24}},
|
||||
"operator": "=",
|
||||
"left": {
|
||||
"type": "MemberExpression",
|
||||
"start":25,"end":33,"loc":{"start":{"line":3,"column":4},"end":{"line":3,"column":12}},
|
||||
"object": {
|
||||
"type": "ThisExpression",
|
||||
"start":25,"end":29,"loc":{"start":{"line":3,"column":4},"end":{"line":3,"column":8}}
|
||||
},
|
||||
"computed": false,
|
||||
"property": {
|
||||
"type": "Identifier",
|
||||
"start":30,"end":33,"loc":{"start":{"line":3,"column":9},"end":{"line":3,"column":12},"identifierName":"foo"},
|
||||
"name": "foo"
|
||||
}
|
||||
},
|
||||
"right": {
|
||||
"type": "Identifier",
|
||||
"start":36,"end":45,"loc":{"start":{"line":3,"column":15},"end":{"line":3,"column":24},"identifierName":"arguments"},
|
||||
"name": "arguments"
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
8
packages/babel-parser/test/fixtures/experimental/class-static-block/invalid-await/input.js
vendored
Normal file
8
packages/babel-parser/test/fixtures/experimental/class-static-block/invalid-await/input.js
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
async function foo() {
|
||||
class C {
|
||||
static foo() {}
|
||||
static {
|
||||
await 42;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"plugins": [
|
||||
"classStaticBlock"
|
||||
],
|
||||
"throws": "Unexpected token, expected \";\" (5:12)"
|
||||
}
|
||||
10
packages/babel-parser/test/fixtures/experimental/class-static-block/invalid-break/input.js
vendored
Normal file
10
packages/babel-parser/test/fixtures/experimental/class-static-block/invalid-break/input.js
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
switch (0) {
|
||||
default: {
|
||||
class C {
|
||||
static foo() {}
|
||||
static {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
94
packages/babel-parser/test/fixtures/experimental/class-static-block/invalid-break/output.json
vendored
Normal file
94
packages/babel-parser/test/fixtures/experimental/class-static-block/invalid-break/output.json
vendored
Normal file
@@ -0,0 +1,94 @@
|
||||
{
|
||||
"type": "File",
|
||||
"start":0,"end":111,"loc":{"start":{"line":1,"column":0},"end":{"line":10,"column":1}},
|
||||
"errors": [
|
||||
"SyntaxError: Unsyntactic break (6:8)"
|
||||
],
|
||||
"program": {
|
||||
"type": "Program",
|
||||
"start":0,"end":111,"loc":{"start":{"line":1,"column":0},"end":{"line":10,"column":1}},
|
||||
"sourceType": "script",
|
||||
"interpreter": null,
|
||||
"body": [
|
||||
{
|
||||
"type": "SwitchStatement",
|
||||
"start":0,"end":111,"loc":{"start":{"line":1,"column":0},"end":{"line":10,"column":1}},
|
||||
"discriminant": {
|
||||
"type": "NumericLiteral",
|
||||
"start":8,"end":9,"loc":{"start":{"line":1,"column":8},"end":{"line":1,"column":9}},
|
||||
"extra": {
|
||||
"rawValue": 0,
|
||||
"raw": "0"
|
||||
},
|
||||
"value": 0
|
||||
},
|
||||
"cases": [
|
||||
{
|
||||
"type": "SwitchCase",
|
||||
"start":15,"end":109,"loc":{"start":{"line":2,"column":2},"end":{"line":9,"column":3}},
|
||||
"consequent": [
|
||||
{
|
||||
"type": "BlockStatement",
|
||||
"start":24,"end":109,"loc":{"start":{"line":2,"column":11},"end":{"line":9,"column":3}},
|
||||
"body": [
|
||||
{
|
||||
"type": "ClassDeclaration",
|
||||
"start":30,"end":105,"loc":{"start":{"line":3,"column":4},"end":{"line":8,"column":5}},
|
||||
"id": {
|
||||
"type": "Identifier",
|
||||
"start":36,"end":37,"loc":{"start":{"line":3,"column":10},"end":{"line":3,"column":11},"identifierName":"C"},
|
||||
"name": "C"
|
||||
},
|
||||
"superClass": null,
|
||||
"body": {
|
||||
"type": "ClassBody",
|
||||
"start":38,"end":105,"loc":{"start":{"line":3,"column":12},"end":{"line":8,"column":5}},
|
||||
"body": [
|
||||
{
|
||||
"type": "ClassMethod",
|
||||
"start":46,"end":61,"loc":{"start":{"line":4,"column":6},"end":{"line":4,"column":21}},
|
||||
"static": true,
|
||||
"key": {
|
||||
"type": "Identifier",
|
||||
"start":53,"end":56,"loc":{"start":{"line":4,"column":13},"end":{"line":4,"column":16},"identifierName":"foo"},
|
||||
"name": "foo"
|
||||
},
|
||||
"computed": false,
|
||||
"kind": "method",
|
||||
"id": null,
|
||||
"generator": false,
|
||||
"async": false,
|
||||
"params": [],
|
||||
"body": {
|
||||
"type": "BlockStatement",
|
||||
"start":59,"end":61,"loc":{"start":{"line":4,"column":19},"end":{"line":4,"column":21}},
|
||||
"body": [],
|
||||
"directives": []
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "StaticBlock",
|
||||
"start":68,"end":99,"loc":{"start":{"line":5,"column":6},"end":{"line":7,"column":7}},
|
||||
"body": [
|
||||
{
|
||||
"type": "BreakStatement",
|
||||
"start":85,"end":91,"loc":{"start":{"line":6,"column":8},"end":{"line":6,"column":14}},
|
||||
"label": null
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
],
|
||||
"directives": []
|
||||
}
|
||||
],
|
||||
"test": null
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
while (0) {
|
||||
class C {
|
||||
static foo() {}
|
||||
static {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
85
packages/babel-parser/test/fixtures/experimental/class-static-block/invalid-continue/output.json
vendored
Normal file
85
packages/babel-parser/test/fixtures/experimental/class-static-block/invalid-continue/output.json
vendored
Normal file
@@ -0,0 +1,85 @@
|
||||
{
|
||||
"type": "File",
|
||||
"start":0,"end":84,"loc":{"start":{"line":1,"column":0},"end":{"line":8,"column":1}},
|
||||
"errors": [
|
||||
"SyntaxError: Unsyntactic continue (5:6)"
|
||||
],
|
||||
"program": {
|
||||
"type": "Program",
|
||||
"start":0,"end":84,"loc":{"start":{"line":1,"column":0},"end":{"line":8,"column":1}},
|
||||
"sourceType": "script",
|
||||
"interpreter": null,
|
||||
"body": [
|
||||
{
|
||||
"type": "WhileStatement",
|
||||
"start":0,"end":84,"loc":{"start":{"line":1,"column":0},"end":{"line":8,"column":1}},
|
||||
"test": {
|
||||
"type": "NumericLiteral",
|
||||
"start":7,"end":8,"loc":{"start":{"line":1,"column":7},"end":{"line":1,"column":8}},
|
||||
"extra": {
|
||||
"rawValue": 0,
|
||||
"raw": "0"
|
||||
},
|
||||
"value": 0
|
||||
},
|
||||
"body": {
|
||||
"type": "BlockStatement",
|
||||
"start":10,"end":84,"loc":{"start":{"line":1,"column":10},"end":{"line":8,"column":1}},
|
||||
"body": [
|
||||
{
|
||||
"type": "ClassDeclaration",
|
||||
"start":14,"end":82,"loc":{"start":{"line":2,"column":2},"end":{"line":7,"column":3}},
|
||||
"id": {
|
||||
"type": "Identifier",
|
||||
"start":20,"end":21,"loc":{"start":{"line":2,"column":8},"end":{"line":2,"column":9},"identifierName":"C"},
|
||||
"name": "C"
|
||||
},
|
||||
"superClass": null,
|
||||
"body": {
|
||||
"type": "ClassBody",
|
||||
"start":22,"end":82,"loc":{"start":{"line":2,"column":10},"end":{"line":7,"column":3}},
|
||||
"body": [
|
||||
{
|
||||
"type": "ClassMethod",
|
||||
"start":28,"end":43,"loc":{"start":{"line":3,"column":4},"end":{"line":3,"column":19}},
|
||||
"static": true,
|
||||
"key": {
|
||||
"type": "Identifier",
|
||||
"start":35,"end":38,"loc":{"start":{"line":3,"column":11},"end":{"line":3,"column":14},"identifierName":"foo"},
|
||||
"name": "foo"
|
||||
},
|
||||
"computed": false,
|
||||
"kind": "method",
|
||||
"id": null,
|
||||
"generator": false,
|
||||
"async": false,
|
||||
"params": [],
|
||||
"body": {
|
||||
"type": "BlockStatement",
|
||||
"start":41,"end":43,"loc":{"start":{"line":3,"column":17},"end":{"line":3,"column":19}},
|
||||
"body": [],
|
||||
"directives": []
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "StaticBlock",
|
||||
"start":48,"end":78,"loc":{"start":{"line":4,"column":4},"end":{"line":6,"column":5}},
|
||||
"body": [
|
||||
{
|
||||
"type": "ContinueStatement",
|
||||
"start":63,"end":72,"loc":{"start":{"line":5,"column":6},"end":{"line":5,"column":15}},
|
||||
"label": null
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
class C {
|
||||
static foo() {}
|
||||
@dec
|
||||
static {
|
||||
this.bar = this.foo;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"plugins": [
|
||||
"classStaticBlock",
|
||||
["decorators", { "decoratorsBeforeExport": true }]
|
||||
]
|
||||
}
|
||||
108
packages/babel-parser/test/fixtures/experimental/class-static-block/invalid-decorators/output.json
vendored
Normal file
108
packages/babel-parser/test/fixtures/experimental/class-static-block/invalid-decorators/output.json
vendored
Normal file
@@ -0,0 +1,108 @@
|
||||
{
|
||||
"type": "File",
|
||||
"start":0,"end":76,"loc":{"start":{"line":1,"column":0},"end":{"line":7,"column":1}},
|
||||
"errors": [
|
||||
"SyntaxError: Decorators can't be used with a static block (3:2)"
|
||||
],
|
||||
"program": {
|
||||
"type": "Program",
|
||||
"start":0,"end":76,"loc":{"start":{"line":1,"column":0},"end":{"line":7,"column":1}},
|
||||
"sourceType": "script",
|
||||
"interpreter": null,
|
||||
"body": [
|
||||
{
|
||||
"type": "ClassDeclaration",
|
||||
"start":0,"end":76,"loc":{"start":{"line":1,"column":0},"end":{"line":7,"column":1}},
|
||||
"id": {
|
||||
"type": "Identifier",
|
||||
"start":6,"end":7,"loc":{"start":{"line":1,"column":6},"end":{"line":1,"column":7},"identifierName":"C"},
|
||||
"name": "C"
|
||||
},
|
||||
"superClass": null,
|
||||
"body": {
|
||||
"type": "ClassBody",
|
||||
"start":8,"end":76,"loc":{"start":{"line":1,"column":8},"end":{"line":7,"column":1}},
|
||||
"body": [
|
||||
{
|
||||
"type": "ClassMethod",
|
||||
"start":12,"end":27,"loc":{"start":{"line":2,"column":2},"end":{"line":2,"column":17}},
|
||||
"static": true,
|
||||
"key": {
|
||||
"type": "Identifier",
|
||||
"start":19,"end":22,"loc":{"start":{"line":2,"column":9},"end":{"line":2,"column":12},"identifierName":"foo"},
|
||||
"name": "foo"
|
||||
},
|
||||
"computed": false,
|
||||
"kind": "method",
|
||||
"id": null,
|
||||
"generator": false,
|
||||
"async": false,
|
||||
"params": [],
|
||||
"body": {
|
||||
"type": "BlockStatement",
|
||||
"start":25,"end":27,"loc":{"start":{"line":2,"column":15},"end":{"line":2,"column":17}},
|
||||
"body": [],
|
||||
"directives": []
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "StaticBlock",
|
||||
"start":30,"end":74,"loc":{"start":{"line":3,"column":2},"end":{"line":6,"column":3}},
|
||||
"decorators": [
|
||||
{
|
||||
"type": "Decorator",
|
||||
"start":30,"end":34,"loc":{"start":{"line":3,"column":2},"end":{"line":3,"column":6}},
|
||||
"expression": {
|
||||
"type": "Identifier",
|
||||
"start":31,"end":34,"loc":{"start":{"line":3,"column":3},"end":{"line":3,"column":6},"identifierName":"dec"},
|
||||
"name": "dec"
|
||||
}
|
||||
}
|
||||
],
|
||||
"body": [
|
||||
{
|
||||
"type": "ExpressionStatement",
|
||||
"start":50,"end":70,"loc":{"start":{"line":5,"column":4},"end":{"line":5,"column":24}},
|
||||
"expression": {
|
||||
"type": "AssignmentExpression",
|
||||
"start":50,"end":69,"loc":{"start":{"line":5,"column":4},"end":{"line":5,"column":23}},
|
||||
"operator": "=",
|
||||
"left": {
|
||||
"type": "MemberExpression",
|
||||
"start":50,"end":58,"loc":{"start":{"line":5,"column":4},"end":{"line":5,"column":12}},
|
||||
"object": {
|
||||
"type": "ThisExpression",
|
||||
"start":50,"end":54,"loc":{"start":{"line":5,"column":4},"end":{"line":5,"column":8}}
|
||||
},
|
||||
"computed": false,
|
||||
"property": {
|
||||
"type": "Identifier",
|
||||
"start":55,"end":58,"loc":{"start":{"line":5,"column":9},"end":{"line":5,"column":12},"identifierName":"bar"},
|
||||
"name": "bar"
|
||||
}
|
||||
},
|
||||
"right": {
|
||||
"type": "MemberExpression",
|
||||
"start":61,"end":69,"loc":{"start":{"line":5,"column":15},"end":{"line":5,"column":23}},
|
||||
"object": {
|
||||
"type": "ThisExpression",
|
||||
"start":61,"end":65,"loc":{"start":{"line":5,"column":15},"end":{"line":5,"column":19}}
|
||||
},
|
||||
"computed": false,
|
||||
"property": {
|
||||
"type": "Identifier",
|
||||
"start":66,"end":69,"loc":{"start":{"line":5,"column":20},"end":{"line":5,"column":23},"identifierName":"foo"},
|
||||
"name": "foo"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
class C {
|
||||
static foo() {}
|
||||
static {}
|
||||
static {}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
{
|
||||
"type": "File",
|
||||
"start":0,"end":53,"loc":{"start":{"line":1,"column":0},"end":{"line":5,"column":1}},
|
||||
"errors": [
|
||||
"SyntaxError: Duplicate static block in the same class (4:2)"
|
||||
],
|
||||
"program": {
|
||||
"type": "Program",
|
||||
"start":0,"end":53,"loc":{"start":{"line":1,"column":0},"end":{"line":5,"column":1}},
|
||||
"sourceType": "script",
|
||||
"interpreter": null,
|
||||
"body": [
|
||||
{
|
||||
"type": "ClassDeclaration",
|
||||
"start":0,"end":53,"loc":{"start":{"line":1,"column":0},"end":{"line":5,"column":1}},
|
||||
"id": {
|
||||
"type": "Identifier",
|
||||
"start":6,"end":7,"loc":{"start":{"line":1,"column":6},"end":{"line":1,"column":7},"identifierName":"C"},
|
||||
"name": "C"
|
||||
},
|
||||
"superClass": null,
|
||||
"body": {
|
||||
"type": "ClassBody",
|
||||
"start":8,"end":53,"loc":{"start":{"line":1,"column":8},"end":{"line":5,"column":1}},
|
||||
"body": [
|
||||
{
|
||||
"type": "ClassMethod",
|
||||
"start":12,"end":27,"loc":{"start":{"line":2,"column":2},"end":{"line":2,"column":17}},
|
||||
"static": true,
|
||||
"key": {
|
||||
"type": "Identifier",
|
||||
"start":19,"end":22,"loc":{"start":{"line":2,"column":9},"end":{"line":2,"column":12},"identifierName":"foo"},
|
||||
"name": "foo"
|
||||
},
|
||||
"computed": false,
|
||||
"kind": "method",
|
||||
"id": null,
|
||||
"generator": false,
|
||||
"async": false,
|
||||
"params": [],
|
||||
"body": {
|
||||
"type": "BlockStatement",
|
||||
"start":25,"end":27,"loc":{"start":{"line":2,"column":15},"end":{"line":2,"column":17}},
|
||||
"body": [],
|
||||
"directives": []
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "StaticBlock",
|
||||
"start":30,"end":39,"loc":{"start":{"line":3,"column":2},"end":{"line":3,"column":11}},
|
||||
"body": []
|
||||
},
|
||||
{
|
||||
"type": "StaticBlock",
|
||||
"start":42,"end":51,"loc":{"start":{"line":4,"column":2},"end":{"line":4,"column":11}},
|
||||
"body": []
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
class C {
|
||||
static foo() {}
|
||||
@dec
|
||||
static {
|
||||
this.bar = this.foo;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"plugins": ["classStaticBlock", "decorators-legacy"]
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
{
|
||||
"type": "File",
|
||||
"start":0,"end":76,"loc":{"start":{"line":1,"column":0},"end":{"line":7,"column":1}},
|
||||
"errors": [
|
||||
"SyntaxError: Decorators can't be used with a static block (3:2)"
|
||||
],
|
||||
"program": {
|
||||
"type": "Program",
|
||||
"start":0,"end":76,"loc":{"start":{"line":1,"column":0},"end":{"line":7,"column":1}},
|
||||
"sourceType": "script",
|
||||
"interpreter": null,
|
||||
"body": [
|
||||
{
|
||||
"type": "ClassDeclaration",
|
||||
"start":0,"end":76,"loc":{"start":{"line":1,"column":0},"end":{"line":7,"column":1}},
|
||||
"id": {
|
||||
"type": "Identifier",
|
||||
"start":6,"end":7,"loc":{"start":{"line":1,"column":6},"end":{"line":1,"column":7},"identifierName":"C"},
|
||||
"name": "C"
|
||||
},
|
||||
"superClass": null,
|
||||
"body": {
|
||||
"type": "ClassBody",
|
||||
"start":8,"end":76,"loc":{"start":{"line":1,"column":8},"end":{"line":7,"column":1}},
|
||||
"body": [
|
||||
{
|
||||
"type": "ClassMethod",
|
||||
"start":12,"end":27,"loc":{"start":{"line":2,"column":2},"end":{"line":2,"column":17}},
|
||||
"static": true,
|
||||
"key": {
|
||||
"type": "Identifier",
|
||||
"start":19,"end":22,"loc":{"start":{"line":2,"column":9},"end":{"line":2,"column":12},"identifierName":"foo"},
|
||||
"name": "foo"
|
||||
},
|
||||
"computed": false,
|
||||
"kind": "method",
|
||||
"id": null,
|
||||
"generator": false,
|
||||
"async": false,
|
||||
"params": [],
|
||||
"body": {
|
||||
"type": "BlockStatement",
|
||||
"start":25,"end":27,"loc":{"start":{"line":2,"column":15},"end":{"line":2,"column":17}},
|
||||
"body": [],
|
||||
"directives": []
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "StaticBlock",
|
||||
"start":30,"end":74,"loc":{"start":{"line":3,"column":2},"end":{"line":6,"column":3}},
|
||||
"decorators": [
|
||||
{
|
||||
"type": "Decorator",
|
||||
"start":30,"end":34,"loc":{"start":{"line":3,"column":2},"end":{"line":3,"column":6}},
|
||||
"expression": {
|
||||
"type": "Identifier",
|
||||
"start":31,"end":34,"loc":{"start":{"line":3,"column":3},"end":{"line":3,"column":6},"identifierName":"dec"},
|
||||
"name": "dec"
|
||||
}
|
||||
}
|
||||
],
|
||||
"body": [
|
||||
{
|
||||
"type": "ExpressionStatement",
|
||||
"start":50,"end":70,"loc":{"start":{"line":5,"column":4},"end":{"line":5,"column":24}},
|
||||
"expression": {
|
||||
"type": "AssignmentExpression",
|
||||
"start":50,"end":69,"loc":{"start":{"line":5,"column":4},"end":{"line":5,"column":23}},
|
||||
"operator": "=",
|
||||
"left": {
|
||||
"type": "MemberExpression",
|
||||
"start":50,"end":58,"loc":{"start":{"line":5,"column":4},"end":{"line":5,"column":12}},
|
||||
"object": {
|
||||
"type": "ThisExpression",
|
||||
"start":50,"end":54,"loc":{"start":{"line":5,"column":4},"end":{"line":5,"column":8}}
|
||||
},
|
||||
"computed": false,
|
||||
"property": {
|
||||
"type": "Identifier",
|
||||
"start":55,"end":58,"loc":{"start":{"line":5,"column":9},"end":{"line":5,"column":12},"identifierName":"bar"},
|
||||
"name": "bar"
|
||||
}
|
||||
},
|
||||
"right": {
|
||||
"type": "MemberExpression",
|
||||
"start":61,"end":69,"loc":{"start":{"line":5,"column":15},"end":{"line":5,"column":23}},
|
||||
"object": {
|
||||
"type": "ThisExpression",
|
||||
"start":61,"end":65,"loc":{"start":{"line":5,"column":15},"end":{"line":5,"column":19}}
|
||||
},
|
||||
"computed": false,
|
||||
"property": {
|
||||
"type": "Identifier",
|
||||
"start":66,"end":69,"loc":{"start":{"line":5,"column":20},"end":{"line":5,"column":23},"identifierName":"foo"},
|
||||
"name": "foo"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
class C {
|
||||
static foo() {}
|
||||
static {
|
||||
042;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
{
|
||||
"type": "File",
|
||||
"start":0,"end":53,"loc":{"start":{"line":1,"column":0},"end":{"line":6,"column":1}},
|
||||
"errors": [
|
||||
"SyntaxError: Legacy octal literals are not allowed in strict mode (4:4)"
|
||||
],
|
||||
"program": {
|
||||
"type": "Program",
|
||||
"start":0,"end":53,"loc":{"start":{"line":1,"column":0},"end":{"line":6,"column":1}},
|
||||
"sourceType": "script",
|
||||
"interpreter": null,
|
||||
"body": [
|
||||
{
|
||||
"type": "ClassDeclaration",
|
||||
"start":0,"end":53,"loc":{"start":{"line":1,"column":0},"end":{"line":6,"column":1}},
|
||||
"id": {
|
||||
"type": "Identifier",
|
||||
"start":6,"end":7,"loc":{"start":{"line":1,"column":6},"end":{"line":1,"column":7},"identifierName":"C"},
|
||||
"name": "C"
|
||||
},
|
||||
"superClass": null,
|
||||
"body": {
|
||||
"type": "ClassBody",
|
||||
"start":8,"end":53,"loc":{"start":{"line":1,"column":8},"end":{"line":6,"column":1}},
|
||||
"body": [
|
||||
{
|
||||
"type": "ClassMethod",
|
||||
"start":12,"end":27,"loc":{"start":{"line":2,"column":2},"end":{"line":2,"column":17}},
|
||||
"static": true,
|
||||
"key": {
|
||||
"type": "Identifier",
|
||||
"start":19,"end":22,"loc":{"start":{"line":2,"column":9},"end":{"line":2,"column":12},"identifierName":"foo"},
|
||||
"name": "foo"
|
||||
},
|
||||
"computed": false,
|
||||
"kind": "method",
|
||||
"id": null,
|
||||
"generator": false,
|
||||
"async": false,
|
||||
"params": [],
|
||||
"body": {
|
||||
"type": "BlockStatement",
|
||||
"start":25,"end":27,"loc":{"start":{"line":2,"column":15},"end":{"line":2,"column":17}},
|
||||
"body": [],
|
||||
"directives": []
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "StaticBlock",
|
||||
"start":30,"end":51,"loc":{"start":{"line":3,"column":2},"end":{"line":5,"column":3}},
|
||||
"body": [
|
||||
{
|
||||
"type": "ExpressionStatement",
|
||||
"start":43,"end":47,"loc":{"start":{"line":4,"column":4},"end":{"line":4,"column":8}},
|
||||
"expression": {
|
||||
"type": "NumericLiteral",
|
||||
"start":43,"end":46,"loc":{"start":{"line":4,"column":4},"end":{"line":4,"column":7}},
|
||||
"extra": {
|
||||
"rawValue": 34,
|
||||
"raw": "042"
|
||||
},
|
||||
"value": 34
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
6
packages/babel-parser/test/fixtures/experimental/class-static-block/invalid-return/input.js
vendored
Normal file
6
packages/babel-parser/test/fixtures/experimental/class-static-block/invalid-return/input.js
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
class C {
|
||||
static foo() {}
|
||||
static {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
68
packages/babel-parser/test/fixtures/experimental/class-static-block/invalid-return/output.json
vendored
Normal file
68
packages/babel-parser/test/fixtures/experimental/class-static-block/invalid-return/output.json
vendored
Normal file
@@ -0,0 +1,68 @@
|
||||
{
|
||||
"type": "File",
|
||||
"start":0,"end":61,"loc":{"start":{"line":1,"column":0},"end":{"line":6,"column":1}},
|
||||
"errors": [
|
||||
"SyntaxError: 'return' outside of function (4:4)"
|
||||
],
|
||||
"program": {
|
||||
"type": "Program",
|
||||
"start":0,"end":61,"loc":{"start":{"line":1,"column":0},"end":{"line":6,"column":1}},
|
||||
"sourceType": "script",
|
||||
"interpreter": null,
|
||||
"body": [
|
||||
{
|
||||
"type": "ClassDeclaration",
|
||||
"start":0,"end":61,"loc":{"start":{"line":1,"column":0},"end":{"line":6,"column":1}},
|
||||
"id": {
|
||||
"type": "Identifier",
|
||||
"start":6,"end":7,"loc":{"start":{"line":1,"column":6},"end":{"line":1,"column":7},"identifierName":"C"},
|
||||
"name": "C"
|
||||
},
|
||||
"superClass": null,
|
||||
"body": {
|
||||
"type": "ClassBody",
|
||||
"start":8,"end":61,"loc":{"start":{"line":1,"column":8},"end":{"line":6,"column":1}},
|
||||
"body": [
|
||||
{
|
||||
"type": "ClassMethod",
|
||||
"start":12,"end":27,"loc":{"start":{"line":2,"column":2},"end":{"line":2,"column":17}},
|
||||
"static": true,
|
||||
"key": {
|
||||
"type": "Identifier",
|
||||
"start":19,"end":22,"loc":{"start":{"line":2,"column":9},"end":{"line":2,"column":12},"identifierName":"foo"},
|
||||
"name": "foo"
|
||||
},
|
||||
"computed": false,
|
||||
"kind": "method",
|
||||
"id": null,
|
||||
"generator": false,
|
||||
"async": false,
|
||||
"params": [],
|
||||
"body": {
|
||||
"type": "BlockStatement",
|
||||
"start":25,"end":27,"loc":{"start":{"line":2,"column":15},"end":{"line":2,"column":17}},
|
||||
"body": [],
|
||||
"directives": []
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "StaticBlock",
|
||||
"start":30,"end":59,"loc":{"start":{"line":3,"column":2},"end":{"line":5,"column":3}},
|
||||
"body": [
|
||||
{
|
||||
"type": "ReturnStatement",
|
||||
"start":43,"end":55,"loc":{"start":{"line":4,"column":4},"end":{"line":4,"column":16}},
|
||||
"argument": {
|
||||
"type": "ThisExpression",
|
||||
"start":50,"end":54,"loc":{"start":{"line":4,"column":11},"end":{"line":4,"column":15}}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
class B {}
|
||||
class C extends B {
|
||||
static foo() {}
|
||||
static {
|
||||
super();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
{
|
||||
"type": "File",
|
||||
"start":0,"end":78,"loc":{"start":{"line":1,"column":0},"end":{"line":7,"column":1}},
|
||||
"errors": [
|
||||
"SyntaxError: super() is only valid inside a class constructor of a subclass. Maybe a typo in the method name ('constructor') or not extending another class? (5:4)"
|
||||
],
|
||||
"program": {
|
||||
"type": "Program",
|
||||
"start":0,"end":78,"loc":{"start":{"line":1,"column":0},"end":{"line":7,"column":1}},
|
||||
"sourceType": "script",
|
||||
"interpreter": null,
|
||||
"body": [
|
||||
{
|
||||
"type": "ClassDeclaration",
|
||||
"start":0,"end":10,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":10}},
|
||||
"id": {
|
||||
"type": "Identifier",
|
||||
"start":6,"end":7,"loc":{"start":{"line":1,"column":6},"end":{"line":1,"column":7},"identifierName":"B"},
|
||||
"name": "B"
|
||||
},
|
||||
"superClass": null,
|
||||
"body": {
|
||||
"type": "ClassBody",
|
||||
"start":8,"end":10,"loc":{"start":{"line":1,"column":8},"end":{"line":1,"column":10}},
|
||||
"body": []
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "ClassDeclaration",
|
||||
"start":11,"end":78,"loc":{"start":{"line":2,"column":0},"end":{"line":7,"column":1}},
|
||||
"id": {
|
||||
"type": "Identifier",
|
||||
"start":17,"end":18,"loc":{"start":{"line":2,"column":6},"end":{"line":2,"column":7},"identifierName":"C"},
|
||||
"name": "C"
|
||||
},
|
||||
"superClass": {
|
||||
"type": "Identifier",
|
||||
"start":27,"end":28,"loc":{"start":{"line":2,"column":16},"end":{"line":2,"column":17},"identifierName":"B"},
|
||||
"name": "B"
|
||||
},
|
||||
"body": {
|
||||
"type": "ClassBody",
|
||||
"start":29,"end":78,"loc":{"start":{"line":2,"column":18},"end":{"line":7,"column":1}},
|
||||
"body": [
|
||||
{
|
||||
"type": "ClassMethod",
|
||||
"start":33,"end":48,"loc":{"start":{"line":3,"column":2},"end":{"line":3,"column":17}},
|
||||
"static": true,
|
||||
"key": {
|
||||
"type": "Identifier",
|
||||
"start":40,"end":43,"loc":{"start":{"line":3,"column":9},"end":{"line":3,"column":12},"identifierName":"foo"},
|
||||
"name": "foo"
|
||||
},
|
||||
"computed": false,
|
||||
"kind": "method",
|
||||
"id": null,
|
||||
"generator": false,
|
||||
"async": false,
|
||||
"params": [],
|
||||
"body": {
|
||||
"type": "BlockStatement",
|
||||
"start":46,"end":48,"loc":{"start":{"line":3,"column":15},"end":{"line":3,"column":17}},
|
||||
"body": [],
|
||||
"directives": []
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "StaticBlock",
|
||||
"start":51,"end":76,"loc":{"start":{"line":4,"column":2},"end":{"line":6,"column":3}},
|
||||
"body": [
|
||||
{
|
||||
"type": "ExpressionStatement",
|
||||
"start":64,"end":72,"loc":{"start":{"line":5,"column":4},"end":{"line":5,"column":12}},
|
||||
"expression": {
|
||||
"type": "CallExpression",
|
||||
"start":64,"end":71,"loc":{"start":{"line":5,"column":4},"end":{"line":5,"column":11}},
|
||||
"callee": {
|
||||
"type": "Super",
|
||||
"start":64,"end":69,"loc":{"start":{"line":5,"column":4},"end":{"line":5,"column":9}}
|
||||
},
|
||||
"arguments": []
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
8
packages/babel-parser/test/fixtures/experimental/class-static-block/invalid-yield/input.js
vendored
Normal file
8
packages/babel-parser/test/fixtures/experimental/class-static-block/invalid-yield/input.js
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
function* foo() {
|
||||
class C {
|
||||
static foo() {}
|
||||
static {
|
||||
yield 42;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"plugins": [
|
||||
"classStaticBlock"
|
||||
],
|
||||
"throws": "Unexpected token, expected \";\" (5:12)"
|
||||
}
|
||||
6
packages/babel-parser/test/fixtures/experimental/class-static-block/lexical-scope/input.js
vendored
Normal file
6
packages/babel-parser/test/fixtures/experimental/class-static-block/lexical-scope/input.js
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
class C {
|
||||
static foo() {}
|
||||
static {
|
||||
const C = {};
|
||||
}
|
||||
}
|
||||
78
packages/babel-parser/test/fixtures/experimental/class-static-block/lexical-scope/output.json
vendored
Normal file
78
packages/babel-parser/test/fixtures/experimental/class-static-block/lexical-scope/output.json
vendored
Normal file
@@ -0,0 +1,78 @@
|
||||
{
|
||||
"type": "File",
|
||||
"start":0,"end":62,"loc":{"start":{"line":1,"column":0},"end":{"line":6,"column":1}},
|
||||
"program": {
|
||||
"type": "Program",
|
||||
"start":0,"end":62,"loc":{"start":{"line":1,"column":0},"end":{"line":6,"column":1}},
|
||||
"sourceType": "script",
|
||||
"interpreter": null,
|
||||
"body": [
|
||||
{
|
||||
"type": "ClassDeclaration",
|
||||
"start":0,"end":62,"loc":{"start":{"line":1,"column":0},"end":{"line":6,"column":1}},
|
||||
"id": {
|
||||
"type": "Identifier",
|
||||
"start":6,"end":7,"loc":{"start":{"line":1,"column":6},"end":{"line":1,"column":7},"identifierName":"C"},
|
||||
"name": "C"
|
||||
},
|
||||
"superClass": null,
|
||||
"body": {
|
||||
"type": "ClassBody",
|
||||
"start":8,"end":62,"loc":{"start":{"line":1,"column":8},"end":{"line":6,"column":1}},
|
||||
"body": [
|
||||
{
|
||||
"type": "ClassMethod",
|
||||
"start":12,"end":27,"loc":{"start":{"line":2,"column":2},"end":{"line":2,"column":17}},
|
||||
"static": true,
|
||||
"key": {
|
||||
"type": "Identifier",
|
||||
"start":19,"end":22,"loc":{"start":{"line":2,"column":9},"end":{"line":2,"column":12},"identifierName":"foo"},
|
||||
"name": "foo"
|
||||
},
|
||||
"computed": false,
|
||||
"kind": "method",
|
||||
"id": null,
|
||||
"generator": false,
|
||||
"async": false,
|
||||
"params": [],
|
||||
"body": {
|
||||
"type": "BlockStatement",
|
||||
"start":25,"end":27,"loc":{"start":{"line":2,"column":15},"end":{"line":2,"column":17}},
|
||||
"body": [],
|
||||
"directives": []
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "StaticBlock",
|
||||
"start":30,"end":60,"loc":{"start":{"line":3,"column":2},"end":{"line":5,"column":3}},
|
||||
"body": [
|
||||
{
|
||||
"type": "VariableDeclaration",
|
||||
"start":43,"end":56,"loc":{"start":{"line":4,"column":4},"end":{"line":4,"column":17}},
|
||||
"declarations": [
|
||||
{
|
||||
"type": "VariableDeclarator",
|
||||
"start":49,"end":55,"loc":{"start":{"line":4,"column":10},"end":{"line":4,"column":16}},
|
||||
"id": {
|
||||
"type": "Identifier",
|
||||
"start":49,"end":50,"loc":{"start":{"line":4,"column":10},"end":{"line":4,"column":11},"identifierName":"C"},
|
||||
"name": "C"
|
||||
},
|
||||
"init": {
|
||||
"type": "ObjectExpression",
|
||||
"start":53,"end":55,"loc":{"start":{"line":4,"column":14},"end":{"line":4,"column":16}},
|
||||
"properties": []
|
||||
}
|
||||
}
|
||||
],
|
||||
"kind": "const"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
17
packages/babel-parser/test/fixtures/experimental/class-static-block/nested-control-flow/input.js
vendored
Normal file
17
packages/babel-parser/test/fixtures/experimental/class-static-block/nested-control-flow/input.js
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
class C {
|
||||
static foo() {}
|
||||
static {
|
||||
while (this.foo) {
|
||||
if (this.foo) {
|
||||
break;
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
class C2 {
|
||||
bar() {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
168
packages/babel-parser/test/fixtures/experimental/class-static-block/nested-control-flow/output.json
vendored
Normal file
168
packages/babel-parser/test/fixtures/experimental/class-static-block/nested-control-flow/output.json
vendored
Normal file
@@ -0,0 +1,168 @@
|
||||
{
|
||||
"type": "File",
|
||||
"start":0,"end":210,"loc":{"start":{"line":1,"column":0},"end":{"line":17,"column":1}},
|
||||
"program": {
|
||||
"type": "Program",
|
||||
"start":0,"end":210,"loc":{"start":{"line":1,"column":0},"end":{"line":17,"column":1}},
|
||||
"sourceType": "script",
|
||||
"interpreter": null,
|
||||
"body": [
|
||||
{
|
||||
"type": "ClassDeclaration",
|
||||
"start":0,"end":210,"loc":{"start":{"line":1,"column":0},"end":{"line":17,"column":1}},
|
||||
"id": {
|
||||
"type": "Identifier",
|
||||
"start":6,"end":7,"loc":{"start":{"line":1,"column":6},"end":{"line":1,"column":7},"identifierName":"C"},
|
||||
"name": "C"
|
||||
},
|
||||
"superClass": null,
|
||||
"body": {
|
||||
"type": "ClassBody",
|
||||
"start":8,"end":210,"loc":{"start":{"line":1,"column":8},"end":{"line":17,"column":1}},
|
||||
"body": [
|
||||
{
|
||||
"type": "ClassMethod",
|
||||
"start":12,"end":27,"loc":{"start":{"line":2,"column":2},"end":{"line":2,"column":17}},
|
||||
"static": true,
|
||||
"key": {
|
||||
"type": "Identifier",
|
||||
"start":19,"end":22,"loc":{"start":{"line":2,"column":9},"end":{"line":2,"column":12},"identifierName":"foo"},
|
||||
"name": "foo"
|
||||
},
|
||||
"computed": false,
|
||||
"kind": "method",
|
||||
"id": null,
|
||||
"generator": false,
|
||||
"async": false,
|
||||
"params": [],
|
||||
"body": {
|
||||
"type": "BlockStatement",
|
||||
"start":25,"end":27,"loc":{"start":{"line":2,"column":15},"end":{"line":2,"column":17}},
|
||||
"body": [],
|
||||
"directives": []
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "StaticBlock",
|
||||
"start":30,"end":208,"loc":{"start":{"line":3,"column":2},"end":{"line":16,"column":3}},
|
||||
"body": [
|
||||
{
|
||||
"type": "WhileStatement",
|
||||
"start":43,"end":145,"loc":{"start":{"line":4,"column":4},"end":{"line":10,"column":5}},
|
||||
"test": {
|
||||
"type": "MemberExpression",
|
||||
"start":50,"end":58,"loc":{"start":{"line":4,"column":11},"end":{"line":4,"column":19}},
|
||||
"object": {
|
||||
"type": "ThisExpression",
|
||||
"start":50,"end":54,"loc":{"start":{"line":4,"column":11},"end":{"line":4,"column":15}}
|
||||
},
|
||||
"computed": false,
|
||||
"property": {
|
||||
"type": "Identifier",
|
||||
"start":55,"end":58,"loc":{"start":{"line":4,"column":16},"end":{"line":4,"column":19},"identifierName":"foo"},
|
||||
"name": "foo"
|
||||
}
|
||||
},
|
||||
"body": {
|
||||
"type": "BlockStatement",
|
||||
"start":60,"end":145,"loc":{"start":{"line":4,"column":21},"end":{"line":10,"column":5}},
|
||||
"body": [
|
||||
{
|
||||
"type": "IfStatement",
|
||||
"start":68,"end":139,"loc":{"start":{"line":5,"column":6},"end":{"line":9,"column":7}},
|
||||
"test": {
|
||||
"type": "MemberExpression",
|
||||
"start":72,"end":80,"loc":{"start":{"line":5,"column":10},"end":{"line":5,"column":18}},
|
||||
"object": {
|
||||
"type": "ThisExpression",
|
||||
"start":72,"end":76,"loc":{"start":{"line":5,"column":10},"end":{"line":5,"column":14}}
|
||||
},
|
||||
"computed": false,
|
||||
"property": {
|
||||
"type": "Identifier",
|
||||
"start":77,"end":80,"loc":{"start":{"line":5,"column":15},"end":{"line":5,"column":18},"identifierName":"foo"},
|
||||
"name": "foo"
|
||||
}
|
||||
},
|
||||
"consequent": {
|
||||
"type": "BlockStatement",
|
||||
"start":82,"end":106,"loc":{"start":{"line":5,"column":20},"end":{"line":7,"column":7}},
|
||||
"body": [
|
||||
{
|
||||
"type": "BreakStatement",
|
||||
"start":92,"end":98,"loc":{"start":{"line":6,"column":8},"end":{"line":6,"column":14}},
|
||||
"label": null
|
||||
}
|
||||
],
|
||||
"directives": []
|
||||
},
|
||||
"alternate": {
|
||||
"type": "BlockStatement",
|
||||
"start":112,"end":139,"loc":{"start":{"line":7,"column":13},"end":{"line":9,"column":7}},
|
||||
"body": [
|
||||
{
|
||||
"type": "ContinueStatement",
|
||||
"start":122,"end":131,"loc":{"start":{"line":8,"column":8},"end":{"line":8,"column":17}},
|
||||
"label": null
|
||||
}
|
||||
],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
],
|
||||
"directives": []
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "ClassDeclaration",
|
||||
"start":150,"end":204,"loc":{"start":{"line":11,"column":4},"end":{"line":15,"column":5}},
|
||||
"id": {
|
||||
"type": "Identifier",
|
||||
"start":156,"end":158,"loc":{"start":{"line":11,"column":10},"end":{"line":11,"column":12},"identifierName":"C2"},
|
||||
"name": "C2"
|
||||
},
|
||||
"superClass": null,
|
||||
"body": {
|
||||
"type": "ClassBody",
|
||||
"start":159,"end":204,"loc":{"start":{"line":11,"column":13},"end":{"line":15,"column":5}},
|
||||
"body": [
|
||||
{
|
||||
"type": "ClassMethod",
|
||||
"start":167,"end":198,"loc":{"start":{"line":12,"column":6},"end":{"line":14,"column":7}},
|
||||
"static": false,
|
||||
"key": {
|
||||
"type": "Identifier",
|
||||
"start":167,"end":170,"loc":{"start":{"line":12,"column":6},"end":{"line":12,"column":9},"identifierName":"bar"},
|
||||
"name": "bar"
|
||||
},
|
||||
"computed": false,
|
||||
"kind": "method",
|
||||
"id": null,
|
||||
"generator": false,
|
||||
"async": false,
|
||||
"params": [],
|
||||
"body": {
|
||||
"type": "BlockStatement",
|
||||
"start":173,"end":198,"loc":{"start":{"line":12,"column":12},"end":{"line":14,"column":7}},
|
||||
"body": [
|
||||
{
|
||||
"type": "ReturnStatement",
|
||||
"start":183,"end":190,"loc":{"start":{"line":13,"column":8},"end":{"line":13,"column":15}},
|
||||
"argument": null
|
||||
}
|
||||
],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
3
packages/babel-parser/test/fixtures/experimental/class-static-block/options.json
vendored
Normal file
3
packages/babel-parser/test/fixtures/experimental/class-static-block/options.json
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"plugins": ["classStaticBlock"]
|
||||
}
|
||||
8
packages/babel-parser/test/fixtures/experimental/class-static-block/super-property/input.js
vendored
Normal file
8
packages/babel-parser/test/fixtures/experimental/class-static-block/super-property/input.js
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
class B {
|
||||
static foo() {}
|
||||
}
|
||||
class C extends B {
|
||||
static {
|
||||
this.bar = super.foo;
|
||||
}
|
||||
}
|
||||
114
packages/babel-parser/test/fixtures/experimental/class-static-block/super-property/output.json
vendored
Normal file
114
packages/babel-parser/test/fixtures/experimental/class-static-block/super-property/output.json
vendored
Normal file
@@ -0,0 +1,114 @@
|
||||
{
|
||||
"type": "File",
|
||||
"start":0,"end":92,"loc":{"start":{"line":1,"column":0},"end":{"line":8,"column":1}},
|
||||
"program": {
|
||||
"type": "Program",
|
||||
"start":0,"end":92,"loc":{"start":{"line":1,"column":0},"end":{"line":8,"column":1}},
|
||||
"sourceType": "script",
|
||||
"interpreter": null,
|
||||
"body": [
|
||||
{
|
||||
"type": "ClassDeclaration",
|
||||
"start":0,"end":29,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}},
|
||||
"id": {
|
||||
"type": "Identifier",
|
||||
"start":6,"end":7,"loc":{"start":{"line":1,"column":6},"end":{"line":1,"column":7},"identifierName":"B"},
|
||||
"name": "B"
|
||||
},
|
||||
"superClass": null,
|
||||
"body": {
|
||||
"type": "ClassBody",
|
||||
"start":8,"end":29,"loc":{"start":{"line":1,"column":8},"end":{"line":3,"column":1}},
|
||||
"body": [
|
||||
{
|
||||
"type": "ClassMethod",
|
||||
"start":12,"end":27,"loc":{"start":{"line":2,"column":2},"end":{"line":2,"column":17}},
|
||||
"static": true,
|
||||
"key": {
|
||||
"type": "Identifier",
|
||||
"start":19,"end":22,"loc":{"start":{"line":2,"column":9},"end":{"line":2,"column":12},"identifierName":"foo"},
|
||||
"name": "foo"
|
||||
},
|
||||
"computed": false,
|
||||
"kind": "method",
|
||||
"id": null,
|
||||
"generator": false,
|
||||
"async": false,
|
||||
"params": [],
|
||||
"body": {
|
||||
"type": "BlockStatement",
|
||||
"start":25,"end":27,"loc":{"start":{"line":2,"column":15},"end":{"line":2,"column":17}},
|
||||
"body": [],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "ClassDeclaration",
|
||||
"start":30,"end":92,"loc":{"start":{"line":4,"column":0},"end":{"line":8,"column":1}},
|
||||
"id": {
|
||||
"type": "Identifier",
|
||||
"start":36,"end":37,"loc":{"start":{"line":4,"column":6},"end":{"line":4,"column":7},"identifierName":"C"},
|
||||
"name": "C"
|
||||
},
|
||||
"superClass": {
|
||||
"type": "Identifier",
|
||||
"start":46,"end":47,"loc":{"start":{"line":4,"column":16},"end":{"line":4,"column":17},"identifierName":"B"},
|
||||
"name": "B"
|
||||
},
|
||||
"body": {
|
||||
"type": "ClassBody",
|
||||
"start":48,"end":92,"loc":{"start":{"line":4,"column":18},"end":{"line":8,"column":1}},
|
||||
"body": [
|
||||
{
|
||||
"type": "StaticBlock",
|
||||
"start":52,"end":90,"loc":{"start":{"line":5,"column":2},"end":{"line":7,"column":3}},
|
||||
"body": [
|
||||
{
|
||||
"type": "ExpressionStatement",
|
||||
"start":65,"end":86,"loc":{"start":{"line":6,"column":4},"end":{"line":6,"column":25}},
|
||||
"expression": {
|
||||
"type": "AssignmentExpression",
|
||||
"start":65,"end":85,"loc":{"start":{"line":6,"column":4},"end":{"line":6,"column":24}},
|
||||
"operator": "=",
|
||||
"left": {
|
||||
"type": "MemberExpression",
|
||||
"start":65,"end":73,"loc":{"start":{"line":6,"column":4},"end":{"line":6,"column":12}},
|
||||
"object": {
|
||||
"type": "ThisExpression",
|
||||
"start":65,"end":69,"loc":{"start":{"line":6,"column":4},"end":{"line":6,"column":8}}
|
||||
},
|
||||
"computed": false,
|
||||
"property": {
|
||||
"type": "Identifier",
|
||||
"start":70,"end":73,"loc":{"start":{"line":6,"column":9},"end":{"line":6,"column":12},"identifierName":"bar"},
|
||||
"name": "bar"
|
||||
}
|
||||
},
|
||||
"right": {
|
||||
"type": "MemberExpression",
|
||||
"start":76,"end":85,"loc":{"start":{"line":6,"column":15},"end":{"line":6,"column":24}},
|
||||
"object": {
|
||||
"type": "Super",
|
||||
"start":76,"end":81,"loc":{"start":{"line":6,"column":15},"end":{"line":6,"column":20}}
|
||||
},
|
||||
"computed": false,
|
||||
"property": {
|
||||
"type": "Identifier",
|
||||
"start":82,"end":85,"loc":{"start":{"line":6,"column":21},"end":{"line":6,"column":24},"identifierName":"foo"},
|
||||
"name": "foo"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user