Merge branch 'main' into next

# Conflicts:
#	src/language-js/print/statement.js
This commit is contained in:
fisker Cheung committed 2022-12-01 18:00:40 +08:00
commit 1f9206f219
12 files changed
+607 -2

No files matched your search

@@ -128,6 +128,26 @@ function postprocess(ast, options) {
}
break;
}
// TODO: Remove this when https://github.com/meriyah/meriyah/issues/231 get fixed
case "PropertyDefinition":
if (
options.parser === "meriyah" &&
node.static &&
!node.computed &&
!node.key
) {
const name = "static";
const start = locStart(node);
Object.assign(node, {
static: false,
key: {
type: "Identifier",
name,
range: [start, start + name.length],
},
});
}
break;
}
});
-2
View File
@@ -167,8 +167,6 @@ const isClassProperty = ({ type }) =>
*/
function shouldPrintSemicolonAfterClassProperty(node, nextNode) {
const name = node.key?.name;
// this isn't actually possible yet with most parsers available today
// so isn't properly tested yet.
if (
(name === "static" || name === "get" || name === "set") &&
!node.value &&
@@ -0,0 +1,509 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`async.js - {"semi":false} format 1`] = `
====================================options=====================================
parsers: ["babel", "flow", "typescript"]
printWidth: 80
semi: false
| printWidth
=====================================input======================================
class A {
async;
foo() {};
}
class B {
async = 1;
foo() {}
}
=====================================output=====================================
class A {
async
foo() {}
}
class B {
async = 1
foo() {}
}
================================================================================
`;
exports[`async.js format 1`] = `
====================================options=====================================
parsers: ["babel", "flow", "typescript"]
printWidth: 80
| printWidth
=====================================input======================================
class A {
async;
foo() {};
}
class B {
async = 1;
foo() {}
}
=====================================output=====================================
class A {
async;
foo() {}
}
class B {
async = 1;
foo() {}
}
================================================================================
`;
exports[`get.js - {"semi":false} format 1`] = `
====================================options=====================================
parsers: ["babel", "flow", "typescript"]
printWidth: 80
semi: false
| printWidth
=====================================input======================================
class A {
get;
foo() {}
}
class B {
get = 1;
foo() {}
}
=====================================output=====================================
class A {
get;
foo() {}
}
class B {
get = 1
foo() {}
}
================================================================================
`;
exports[`get.js format 1`] = `
====================================options=====================================
parsers: ["babel", "flow", "typescript"]
printWidth: 80
| printWidth
=====================================input======================================
class A {
get;
foo() {}
}
class B {
get = 1;
foo() {}
}
=====================================output=====================================
class A {
get;
foo() {}
}
class B {
get = 1;
foo() {}
}
================================================================================
`;
exports[`set.js - {"semi":false} format 1`] = `
====================================options=====================================
parsers: ["babel", "flow", "typescript"]
printWidth: 80
semi: false
| printWidth
=====================================input======================================
class A {
set;
foo(v) {}
}
class B {
set = 1;
foo(v) {}
}
=====================================output=====================================
class A {
set;
foo(v) {}
}
class B {
set = 1
foo(v) {}
}
================================================================================
`;
exports[`set.js format 1`] = `
====================================options=====================================
parsers: ["babel", "flow", "typescript"]
printWidth: 80
| printWidth
=====================================input======================================
class A {
set;
foo(v) {}
}
class B {
set = 1;
foo(v) {}
}
=====================================output=====================================
class A {
set;
foo(v) {}
}
class B {
set = 1;
foo(v) {}
}
================================================================================
`;
exports[`static.js [flow] format 1`] = `
"Unexpected token \`;\`, expected an identifier (2:9)
1 | class A {
> 2 | static;
| ^
3 | foo() {};
4 | }
5 |"
`;
exports[`static.js - {"semi":false} [flow] format 1`] = `
"Unexpected token \`;\`, expected an identifier (2:9)
1 | class A {
> 2 | static;
| ^
3 | foo() {};
4 | }
5 |"
`;
exports[`static.js - {"semi":false} format 1`] = `
====================================options=====================================
parsers: ["babel", "flow", "typescript"]
printWidth: 80
semi: false
| printWidth
=====================================input======================================
class A {
static;
foo() {};
}
class B {
static = 1;
foo() {};
}
=====================================output=====================================
class A {
static;
foo() {}
}
class B {
static = 1
foo() {}
}
================================================================================
`;
exports[`static.js format 1`] = `
====================================options=====================================
parsers: ["babel", "flow", "typescript"]
printWidth: 80
| printWidth
=====================================input======================================
class A {
static;
foo() {};
}
class B {
static = 1;
foo() {};
}
=====================================output=====================================
class A {
static;
foo() {}
}
class B {
static = 1;
foo() {}
}
================================================================================
`;
exports[`static-async.js - {"semi":false} format 1`] = `
====================================options=====================================
parsers: ["babel", "flow", "typescript"]
printWidth: 80
semi: false
| printWidth
=====================================input======================================
class A {
static async;
foo() {}
}
class B {
static async = 1;
foo() {}
}
=====================================output=====================================
class A {
static async
foo() {}
}
class B {
static async = 1
foo() {}
}
================================================================================
`;
exports[`static-async.js format 1`] = `
====================================options=====================================
parsers: ["babel", "flow", "typescript"]
printWidth: 80
| printWidth
=====================================input======================================
class A {
static async;
foo() {}
}
class B {
static async = 1;
foo() {}
}
=====================================output=====================================
class A {
static async;
foo() {}
}
class B {
static async = 1;
foo() {}
}
================================================================================
`;
exports[`static-get.js - {"semi":false} format 1`] = `
====================================options=====================================
parsers: ["babel", "flow", "typescript"]
printWidth: 80
semi: false
| printWidth
=====================================input======================================
class A {
static get;
foo() {}
}
class B {
static get = 1;
foo() {}
}
=====================================output=====================================
class A {
static get;
foo() {}
}
class B {
static get = 1
foo() {}
}
================================================================================
`;
exports[`static-get.js format 1`] = `
====================================options=====================================
parsers: ["babel", "flow", "typescript"]
printWidth: 80
| printWidth
=====================================input======================================
class A {
static get;
foo() {}
}
class B {
static get = 1;
foo() {}
}
=====================================output=====================================
class A {
static get;
foo() {}
}
class B {
static get = 1;
foo() {}
}
================================================================================
`;
exports[`static-set.js - {"semi":false} format 1`] = `
====================================options=====================================
parsers: ["babel", "flow", "typescript"]
printWidth: 80
semi: false
| printWidth
=====================================input======================================
class A {
static set;
foo(v) {}
}
class B {
static set = 1;
foo(v) {}
}
=====================================output=====================================
class A {
static set;
foo(v) {}
}
class B {
static set = 1
foo(v) {}
}
================================================================================
`;
exports[`static-set.js format 1`] = `
====================================options=====================================
parsers: ["babel", "flow", "typescript"]
printWidth: 80
| printWidth
=====================================input======================================
class A {
static set;
foo(v) {}
}
class B {
static set = 1;
foo(v) {}
}
=====================================output=====================================
class A {
static set;
foo(v) {}
}
class B {
static set = 1;
foo(v) {}
}
================================================================================
`;
exports[`static-static.js - {"semi":false} format 1`] = `
====================================options=====================================
parsers: ["babel", "flow", "typescript"]
printWidth: 80
semi: false
| printWidth
=====================================input======================================
class A {
static static;
foo() {}
}
class B {
static static = 1;
foo() {}
}
=====================================output=====================================
class A {
static static;
foo() {}
}
class B {
static static = 1
foo() {}
}
================================================================================
`;
exports[`static-static.js format 1`] = `
====================================options=====================================
parsers: ["babel", "flow", "typescript"]
printWidth: 80
| printWidth
=====================================input======================================
class A {
static static;
foo() {}
}
class B {
static static = 1;
foo() {}
}
=====================================output=====================================
class A {
static static;
foo() {}
}
class B {
static static = 1;
foo() {}
}
================================================================================
`;
@@ -0,0 +1,9 @@
class A {
async;
foo() {};
}
class B {
async = 1;
foo() {}
}
@@ -0,0 +1,9 @@
class A {
get;
foo() {}
}
class B {
get = 1;
foo() {}
}
@@ -0,0 +1,6 @@
const errors = {
flow: ["static.js"],
};
run_spec(import.meta, ["babel", "flow", "typescript"], { errors });
run_spec(import.meta, ["babel", "flow", "typescript"], { errors, semi: false });
@@ -0,0 +1,9 @@
class A {
set;
foo(v) {}
}
class B {
set = 1;
foo(v) {}
}
@@ -0,0 +1,9 @@
class A {
static async;
foo() {}
}
class B {
static async = 1;
foo() {}
}
@@ -0,0 +1,9 @@
class A {
static get;
foo() {}
}
class B {
static get = 1;
foo() {}
}
@@ -0,0 +1,9 @@
class A {
static set;
foo(v) {}
}
class B {
static set = 1;
foo(v) {}
}
@@ -0,0 +1,9 @@
class A {
static static;
foo() {}
}
class B {
static static = 1;
foo() {}
}
@@ -0,0 +1,9 @@
class A {
static;
foo() {};
}
class B {
static = 1;
foo() {};
}