mirror of
https://github.com/oxc-project/oxc.git
synced 2026-11-04 10:29:58 +00:00
fix(codegen): preserve coverage comments before object properties (#21312)
Closes #21302 --------- Co-authored-by: Dunqing <dengqing0821@gmail.com>
This commit is contained in:
1 parent
d676e0ca5b
commit
00fc13620d
12 files changed
+83
No files matched your search
@@ -21,6 +21,7 @@ for (let i = 0; i <= 64; i++) stringDecodeArrays[i] = Array(i).fill(0);
|
||||
|
||||
const NodeProto = Object.create(Object.prototype, {
|
||||
loc: {
|
||||
// Note: Not configurable
|
||||
get() {
|
||||
return getNodeLoc(this);
|
||||
},
|
||||
@@ -4967,6 +4968,7 @@ function deserializeTSModuleDeclaration(pos) {
|
||||
__proto__: NodeProto,
|
||||
type: "TSModuleDeclaration",
|
||||
id: null,
|
||||
// No `body` field
|
||||
kind,
|
||||
declare,
|
||||
global: false,
|
||||
|
||||
@@ -1586,9 +1586,17 @@ impl GenExpr for ObjectExpression<'_> {
|
||||
}
|
||||
if is_multi_line {
|
||||
p.print_soft_newline();
|
||||
p.print_comments_at(item.span().start);
|
||||
p.print_indent();
|
||||
} else {
|
||||
p.print_soft_space();
|
||||
if let Some(comments) = p.get_comments(item.span().start) {
|
||||
p.print_comments(&comments);
|
||||
if p.print_next_indent_as_space {
|
||||
p.print_hard_space();
|
||||
p.print_next_indent_as_space = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
item.print(p, ctx);
|
||||
}
|
||||
|
||||
@@ -229,6 +229,27 @@ catch (err) // v8 ignore next
|
||||
case 0.5: break;
|
||||
/* istanbul ignore next */
|
||||
default: break;
|
||||
}",
|
||||
// Coverage comment before ObjectExpression property
|
||||
// https://github.com/oxc-project/oxc/issues/21302
|
||||
"const obj = {
|
||||
a: () => 1,
|
||||
/* v8 ignore next */
|
||||
b: () => 2,
|
||||
}",
|
||||
// Coverage comment before single ObjectExpression property
|
||||
"const obj = { /* v8 ignore next */ a: () => 1 }",
|
||||
// Coverage comment before the first ObjectExpression property
|
||||
"const obj = {
|
||||
/* v8 ignore next */
|
||||
a: () => 1,
|
||||
b: () => 2,
|
||||
}",
|
||||
// Coverage comment before a SpreadElement in ObjectExpression
|
||||
"const obj = {
|
||||
a: 1,
|
||||
/* v8 ignore next */
|
||||
...rest,
|
||||
}",
|
||||
];
|
||||
|
||||
|
||||
@@ -158,3 +158,47 @@ switch (Math.random()) {
|
||||
/* istanbul ignore next */
|
||||
default: break;
|
||||
}
|
||||
|
||||
########## 25
|
||||
const obj = {
|
||||
a: () => 1,
|
||||
/* v8 ignore next */
|
||||
b: () => 2,
|
||||
}
|
||||
----------
|
||||
const obj = {
|
||||
a: () => 1,
|
||||
/* v8 ignore next */
|
||||
b: () => 2
|
||||
};
|
||||
|
||||
########## 26
|
||||
const obj = { /* v8 ignore next */ a: () => 1 }
|
||||
----------
|
||||
const obj = { /* v8 ignore next */ a: () => 1 };
|
||||
|
||||
########## 27
|
||||
const obj = {
|
||||
/* v8 ignore next */
|
||||
a: () => 1,
|
||||
b: () => 2,
|
||||
}
|
||||
----------
|
||||
const obj = {
|
||||
/* v8 ignore next */
|
||||
a: () => 1,
|
||||
b: () => 2
|
||||
};
|
||||
|
||||
########## 28
|
||||
const obj = {
|
||||
a: 1,
|
||||
/* v8 ignore next */
|
||||
...rest,
|
||||
}
|
||||
----------
|
||||
const obj = {
|
||||
a: 1,
|
||||
/* v8 ignore next */
|
||||
...rest
|
||||
};
|
||||
@@ -3630,6 +3630,7 @@ function deserializeTSModuleDeclaration(pos) {
|
||||
node = {
|
||||
type: "TSModuleDeclaration",
|
||||
id: null,
|
||||
// No `body` field
|
||||
kind,
|
||||
declare,
|
||||
global: false,
|
||||
|
||||
@@ -4056,6 +4056,7 @@ function deserializeTSModuleDeclaration(pos) {
|
||||
node = parent = {
|
||||
type: "TSModuleDeclaration",
|
||||
id: null,
|
||||
// No `body` field
|
||||
kind,
|
||||
declare,
|
||||
global: false,
|
||||
|
||||
@@ -4065,6 +4065,7 @@ function deserializeTSModuleDeclaration(pos) {
|
||||
node = {
|
||||
type: "TSModuleDeclaration",
|
||||
id: null,
|
||||
// No `body` field
|
||||
kind,
|
||||
declare,
|
||||
global: false,
|
||||
|
||||
@@ -4489,6 +4489,7 @@ function deserializeTSModuleDeclaration(pos) {
|
||||
node = parent = {
|
||||
type: "TSModuleDeclaration",
|
||||
id: null,
|
||||
// No `body` field
|
||||
kind,
|
||||
declare,
|
||||
global: false,
|
||||
|
||||
@@ -3903,6 +3903,7 @@ function deserializeTSModuleDeclaration(pos) {
|
||||
node = {
|
||||
type: "TSModuleDeclaration",
|
||||
id: null,
|
||||
// No `body` field
|
||||
kind,
|
||||
declare,
|
||||
global: false,
|
||||
|
||||
@@ -4359,6 +4359,7 @@ function deserializeTSModuleDeclaration(pos) {
|
||||
node = parent = {
|
||||
type: "TSModuleDeclaration",
|
||||
id: null,
|
||||
// No `body` field
|
||||
kind,
|
||||
declare,
|
||||
global: false,
|
||||
|
||||
@@ -4366,6 +4366,7 @@ function deserializeTSModuleDeclaration(pos) {
|
||||
node = {
|
||||
type: "TSModuleDeclaration",
|
||||
id: null,
|
||||
// No `body` field
|
||||
kind,
|
||||
declare,
|
||||
global: false,
|
||||
|
||||
@@ -4820,6 +4820,7 @@ function deserializeTSModuleDeclaration(pos) {
|
||||
node = parent = {
|
||||
type: "TSModuleDeclaration",
|
||||
id: null,
|
||||
// No `body` field
|
||||
kind,
|
||||
declare,
|
||||
global: false,
|
||||
|
||||
Reference in new issue
Block a user