TypeScript: remove extra indentation for arrow function on variable declaration with comment (#7094)
* Remove extra indent * add changelog * Fix postprocess for range of TypeScript * Remove locend from postprocess * Add test for no-smei * Remove hasLeadingComment
This commit is contained in:
1 parent
20d1521417
commit
fa723deee2
5 files changed
+144
-6
No files matched your search
@@ -0,0 +1,26 @@
|
||||
#### Remove extra indentation for arrow function on variable declaration with comment([#7094](https://github.com/prettier/prettier/pull/7094) by [@sosukesuzuki](https://github.com/sosukesuzuki))
|
||||
|
||||
<!-- prettier-ignore -->
|
||||
```ts
|
||||
// Input
|
||||
const foo = () => {
|
||||
return;
|
||||
}
|
||||
|
||||
// foo
|
||||
;
|
||||
|
||||
// Prettier stable
|
||||
const foo = () => {
|
||||
return;
|
||||
};
|
||||
|
||||
// foo
|
||||
|
||||
// Prettier master
|
||||
const foo = () => {
|
||||
return;
|
||||
};
|
||||
|
||||
// foo
|
||||
```
|
||||
@@ -1,7 +1,7 @@
|
||||
"use strict";
|
||||
|
||||
const { getLast } = require("../common/util");
|
||||
const { composeLoc } = require("./loc");
|
||||
const { composeLoc, locEnd } = require("./loc");
|
||||
|
||||
function postprocess(ast, options) {
|
||||
visitNode(ast, node => {
|
||||
@@ -48,7 +48,7 @@ function postprocess(ast, options) {
|
||||
if (options.originalText[locEnd(toOverrideNode)] === ";") {
|
||||
return;
|
||||
}
|
||||
if (options.parser === "flow") {
|
||||
if (Array.isArray(toBeOverriddenNode.range)) {
|
||||
toBeOverriddenNode.range = [
|
||||
toBeOverriddenNode.range[0],
|
||||
toOverrideNode.range[1]
|
||||
@@ -60,10 +60,6 @@ function postprocess(ast, options) {
|
||||
end: toBeOverriddenNode.loc.end
|
||||
});
|
||||
}
|
||||
|
||||
function locEnd(node) {
|
||||
return options.parser === "flow" ? node.range[1] : node.end;
|
||||
}
|
||||
}
|
||||
|
||||
function visitNode(node, fn, parent, property) {
|
||||
|
||||
@@ -40,3 +40,108 @@ app.get("/", (req, res): void => {
|
||||
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`arrow_regression.js 2`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["typescript"]
|
||||
printWidth: 80
|
||||
semi: false
|
||||
| printWidth
|
||||
=====================================input======================================
|
||||
const bar = (...varargs:any[]) => {
|
||||
console.log(varargs);
|
||||
};
|
||||
|
||||
const foo = (x:string):void => (
|
||||
bar(
|
||||
x,
|
||||
() => {},
|
||||
() => {}
|
||||
)
|
||||
);
|
||||
|
||||
app.get("/", (req, res): void => {
|
||||
res.send("Hello world");
|
||||
});
|
||||
|
||||
=====================================output=====================================
|
||||
const bar = (...varargs: any[]) => {
|
||||
console.log(varargs)
|
||||
}
|
||||
|
||||
const foo = (x: string): void =>
|
||||
bar(
|
||||
x,
|
||||
() => {},
|
||||
() => {}
|
||||
)
|
||||
|
||||
app.get("/", (req, res): void => {
|
||||
res.send("Hello world")
|
||||
})
|
||||
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`comments.js 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["typescript"]
|
||||
printWidth: 80
|
||||
| printWidth
|
||||
=====================================input======================================
|
||||
const fn1 = () => {
|
||||
return;
|
||||
} /* foo */;
|
||||
|
||||
const fn2 = () => {
|
||||
return;
|
||||
}
|
||||
|
||||
// foo
|
||||
;
|
||||
|
||||
=====================================output=====================================
|
||||
const fn1 = () => {
|
||||
return;
|
||||
}; /* foo */
|
||||
|
||||
const fn2 = () => {
|
||||
return;
|
||||
};
|
||||
|
||||
// foo
|
||||
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`comments.js 2`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["typescript"]
|
||||
printWidth: 80
|
||||
semi: false
|
||||
| printWidth
|
||||
=====================================input======================================
|
||||
const fn1 = () => {
|
||||
return;
|
||||
} /* foo */;
|
||||
|
||||
const fn2 = () => {
|
||||
return;
|
||||
}
|
||||
|
||||
// foo
|
||||
;
|
||||
|
||||
=====================================output=====================================
|
||||
const fn1 = () => {
|
||||
return
|
||||
} /* foo */
|
||||
|
||||
const fn2 = () => {
|
||||
return
|
||||
}
|
||||
|
||||
// foo
|
||||
|
||||
================================================================================
|
||||
`;
|
||||
@@ -0,0 +1,10 @@
|
||||
const fn1 = () => {
|
||||
return;
|
||||
} /* foo */;
|
||||
|
||||
const fn2 = () => {
|
||||
return;
|
||||
}
|
||||
|
||||
// foo
|
||||
;
|
||||
@@ -1 +1,2 @@
|
||||
run_spec(__dirname, ["typescript"]);
|
||||
run_spec(__dirname, ["typescript"], { semi: false });
|
||||
Reference in new issue
Block a user