fix multiline dynamic import comments (#6025)
parent
1e471a0079
commit
0b07e10833
|
@ -42,9 +42,41 @@ Examples:
|
||||||
|
|
||||||
-->
|
-->
|
||||||
|
|
||||||
|
- JavaScript: Fix multiline dynamic import comments ([#6025] by [@noahsug])
|
||||||
|
|
||||||
|
<!-- prettier-ignore -->
|
||||||
|
```js
|
||||||
|
// Input
|
||||||
|
import(
|
||||||
|
/* Hello */
|
||||||
|
'something'
|
||||||
|
/* Hello */
|
||||||
|
)
|
||||||
|
import(
|
||||||
|
'myreallylongdynamicallyloadedmodulenamemyreallylongdynamicallyloadedmodulename'
|
||||||
|
)
|
||||||
|
|
||||||
|
// Output (Prettier stable)
|
||||||
|
import(/* Hello */
|
||||||
|
"something");
|
||||||
|
/* Hello */
|
||||||
|
import('myreallylongdynamicallyloadedmodulenamemyreallylongdynamicallyloadedmodulename');
|
||||||
|
|
||||||
|
// Output (Prettier master)
|
||||||
|
import(
|
||||||
|
/* Hello */
|
||||||
|
'something'
|
||||||
|
/* Hello */
|
||||||
|
)
|
||||||
|
import(
|
||||||
|
'myreallylongdynamicallyloadedmodulenamemyreallylongdynamicallyloadedmodulename'
|
||||||
|
);
|
||||||
|
```
|
||||||
|
|
||||||
- JavaScript: Add parentheses for immediately-constructed fn/class ([#5996] by [@bakkot])
|
- JavaScript: Add parentheses for immediately-constructed fn/class ([#5996] by [@bakkot])
|
||||||
|
|
||||||
```
|
<!-- prettier-ignore -->
|
||||||
|
```js
|
||||||
// Input
|
// Input
|
||||||
new class {};
|
new class {};
|
||||||
new function() {}
|
new function() {}
|
||||||
|
|
|
@ -1165,7 +1165,6 @@ function printPathNoParens(path, options, print, args) {
|
||||||
(!isNew &&
|
(!isNew &&
|
||||||
n.callee.type === "Identifier" &&
|
n.callee.type === "Identifier" &&
|
||||||
(n.callee.name === "require" || n.callee.name === "define")) ||
|
(n.callee.name === "require" || n.callee.name === "define")) ||
|
||||||
n.callee.type === "Import" ||
|
|
||||||
// Template literals as single arguments
|
// Template literals as single arguments
|
||||||
(n.arguments.length === 1 &&
|
(n.arguments.length === 1 &&
|
||||||
isTemplateOnItsOwnLine(
|
isTemplateOnItsOwnLine(
|
||||||
|
@ -3953,7 +3952,12 @@ function printArgumentsList(path, options, print) {
|
||||||
return concat(parts);
|
return concat(parts);
|
||||||
}, "arguments");
|
}, "arguments");
|
||||||
|
|
||||||
const maybeTrailingComma = shouldPrintComma(options, "all") ? "," : "";
|
const maybeTrailingComma =
|
||||||
|
// Dynamic imports cannot have trailing commas
|
||||||
|
!(node.callee && node.callee.type === "Import") &&
|
||||||
|
shouldPrintComma(options, "all")
|
||||||
|
? ","
|
||||||
|
: "";
|
||||||
|
|
||||||
function allArgsBrokenOut() {
|
function allArgsBrokenOut() {
|
||||||
return group(
|
return group(
|
||||||
|
@ -4051,7 +4055,7 @@ function printArgumentsList(path, options, print) {
|
||||||
concat([
|
concat([
|
||||||
"(",
|
"(",
|
||||||
indent(concat([softline, concat(printedArguments)])),
|
indent(concat([softline, concat(printedArguments)])),
|
||||||
ifBreak(shouldPrintComma(options, "all") ? "," : ""),
|
ifBreak(maybeTrailingComma),
|
||||||
softline,
|
softline,
|
||||||
")"
|
")"
|
||||||
]),
|
]),
|
||||||
|
@ -6435,8 +6439,7 @@ function canAttachComment(node) {
|
||||||
node.type !== "Block" &&
|
node.type !== "Block" &&
|
||||||
node.type !== "EmptyStatement" &&
|
node.type !== "EmptyStatement" &&
|
||||||
node.type !== "TemplateElement" &&
|
node.type !== "TemplateElement" &&
|
||||||
node.type !== "Import" &&
|
node.type !== "Import"
|
||||||
!(node.callee && node.callee.type === "Import")
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -530,6 +530,18 @@ import(/* Hello */ 'something' /* Hello */)
|
||||||
|
|
||||||
import('something' /* Hello */ + 'else')
|
import('something' /* Hello */ + 'else')
|
||||||
|
|
||||||
|
import(
|
||||||
|
/* Hello */
|
||||||
|
'something'
|
||||||
|
/* Hello */
|
||||||
|
)
|
||||||
|
|
||||||
|
wrap(
|
||||||
|
import(/* Hello */
|
||||||
|
'something'
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
=====================================output=====================================
|
=====================================output=====================================
|
||||||
import(/* Hello */ "something");
|
import(/* Hello */ "something");
|
||||||
|
|
||||||
|
@ -539,6 +551,19 @@ import(/* Hello */ "something" /* Hello */);
|
||||||
|
|
||||||
import("something" /* Hello */ + "else");
|
import("something" /* Hello */ + "else");
|
||||||
|
|
||||||
|
import(
|
||||||
|
/* Hello */
|
||||||
|
"something"
|
||||||
|
/* Hello */
|
||||||
|
);
|
||||||
|
|
||||||
|
wrap(
|
||||||
|
import(
|
||||||
|
/* Hello */
|
||||||
|
"something"
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
================================================================================
|
================================================================================
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
|
|
@ -5,3 +5,15 @@ import('something' /* Hello */)
|
||||||
import(/* Hello */ 'something' /* Hello */)
|
import(/* Hello */ 'something' /* Hello */)
|
||||||
|
|
||||||
import('something' /* Hello */ + 'else')
|
import('something' /* Hello */ + 'else')
|
||||||
|
|
||||||
|
import(
|
||||||
|
/* Hello */
|
||||||
|
'something'
|
||||||
|
/* Hello */
|
||||||
|
)
|
||||||
|
|
||||||
|
wrap(
|
||||||
|
import(/* Hello */
|
||||||
|
'something'
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
|
@ -1,44 +0,0 @@
|
||||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
||||||
|
|
||||||
exports[`long.js 1`] = `
|
|
||||||
====================================options=====================================
|
|
||||||
parsers: ["flow", "babel"]
|
|
||||||
printWidth: 80
|
|
||||||
| printWidth
|
|
||||||
=====================================input======================================
|
|
||||||
import(
|
|
||||||
'myreallylongdynamicallyloadedmodulenamemyreallylongdynamicallyloadedmodulename'
|
|
||||||
);
|
|
||||||
|
|
||||||
import(
|
|
||||||
'myreallylongdynamicallyloadedmodulenamemyreallylongdynamicallyloadedmodulename'
|
|
||||||
).then(exports => {
|
|
||||||
});
|
|
||||||
|
|
||||||
=====================================output=====================================
|
|
||||||
import("myreallylongdynamicallyloadedmodulenamemyreallylongdynamicallyloadedmodulename");
|
|
||||||
|
|
||||||
import("myreallylongdynamicallyloadedmodulenamemyreallylongdynamicallyloadedmodulename").then(
|
|
||||||
exports => {}
|
|
||||||
);
|
|
||||||
|
|
||||||
================================================================================
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`then.js 1`] = `
|
|
||||||
====================================options=====================================
|
|
||||||
parsers: ["flow", "babel"]
|
|
||||||
printWidth: 80
|
|
||||||
| printWidth
|
|
||||||
=====================================input======================================
|
|
||||||
const x = import('some-module').then(x => {
|
|
||||||
// ...
|
|
||||||
});
|
|
||||||
|
|
||||||
=====================================output=====================================
|
|
||||||
const x = import("some-module").then(x => {
|
|
||||||
// ...
|
|
||||||
});
|
|
||||||
|
|
||||||
================================================================================
|
|
||||||
`;
|
|
|
@ -1 +0,0 @@
|
||||||
run_spec(__dirname, ["flow", "babel"]);
|
|
|
@ -1,8 +0,0 @@
|
||||||
import(
|
|
||||||
'myreallylongdynamicallyloadedmodulenamemyreallylongdynamicallyloadedmodulename'
|
|
||||||
);
|
|
||||||
|
|
||||||
import(
|
|
||||||
'myreallylongdynamicallyloadedmodulenamemyreallylongdynamicallyloadedmodulename'
|
|
||||||
).then(exports => {
|
|
||||||
});
|
|
|
@ -1,3 +0,0 @@
|
||||||
const x = import('some-module').then(x => {
|
|
||||||
// ...
|
|
||||||
});
|
|
|
@ -1,5 +1,61 @@
|
||||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
|
exports[`dynamic-import.js 1`] = `
|
||||||
|
====================================options=====================================
|
||||||
|
parsers: ["flow", "typescript"]
|
||||||
|
printWidth: 80
|
||||||
|
| printWidth
|
||||||
|
=====================================input======================================
|
||||||
|
import(
|
||||||
|
'myreallylongdynamicallyloadedmodulenamemyreallylongdynamicallyloadedmodulename'
|
||||||
|
);
|
||||||
|
|
||||||
|
=====================================output=====================================
|
||||||
|
import(
|
||||||
|
"myreallylongdynamicallyloadedmodulenamemyreallylongdynamicallyloadedmodulename"
|
||||||
|
);
|
||||||
|
|
||||||
|
================================================================================
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`dynamic-import.js 2`] = `
|
||||||
|
====================================options=====================================
|
||||||
|
parsers: ["flow", "typescript"]
|
||||||
|
printWidth: 80
|
||||||
|
trailingComma: "all"
|
||||||
|
| printWidth
|
||||||
|
=====================================input======================================
|
||||||
|
import(
|
||||||
|
'myreallylongdynamicallyloadedmodulenamemyreallylongdynamicallyloadedmodulename'
|
||||||
|
);
|
||||||
|
|
||||||
|
=====================================output=====================================
|
||||||
|
import(
|
||||||
|
"myreallylongdynamicallyloadedmodulenamemyreallylongdynamicallyloadedmodulename"
|
||||||
|
);
|
||||||
|
|
||||||
|
================================================================================
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`dynamic-import.js 3`] = `
|
||||||
|
====================================options=====================================
|
||||||
|
parsers: ["flow", "typescript"]
|
||||||
|
printWidth: 80
|
||||||
|
trailingComma: "es5"
|
||||||
|
| printWidth
|
||||||
|
=====================================input======================================
|
||||||
|
import(
|
||||||
|
'myreallylongdynamicallyloadedmodulenamemyreallylongdynamicallyloadedmodulename'
|
||||||
|
);
|
||||||
|
|
||||||
|
=====================================output=====================================
|
||||||
|
import(
|
||||||
|
"myreallylongdynamicallyloadedmodulenamemyreallylongdynamicallyloadedmodulename"
|
||||||
|
);
|
||||||
|
|
||||||
|
================================================================================
|
||||||
|
`;
|
||||||
|
|
||||||
exports[`es5.js 1`] = `
|
exports[`es5.js 1`] = `
|
||||||
====================================options=====================================
|
====================================options=====================================
|
||||||
parsers: ["flow", "typescript"]
|
parsers: ["flow", "typescript"]
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
import(
|
||||||
|
'myreallylongdynamicallyloadedmodulenamemyreallylongdynamicallyloadedmodulename'
|
||||||
|
);
|
Loading…
Reference in New Issue