Skip to content

Commit

Permalink
Allow break require() argument
Browse files Browse the repository at this point in the history
  • Loading branch information
fisker committed Aug 17, 2023
1 parent c01661f commit 7eee800
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/language-js/print/call-expression.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,11 @@ function isCommonsJsOrAmdCall(node, parentNode) {
}

if (node.callee.name === "require") {
return true;
const args = getCallArguments(node);
return (
(args.length === 1 && isStringLiteral(args[0])) ||
(args.length > 1)
);
}

if (node.callee.name === "define") {
Expand Down
23 changes: 23 additions & 0 deletions tests/format/js/require/__snapshots__/jsfmt.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,19 @@ const { one1, two1, three1, four1, five1, six1, seven1, eight1, nine1, ten1, ele
const MyReallyExtrememlyLongModuleName = require('MyReallyExtrememlyLongModuleName');
const plugin = require(
global.STANDALONE
? path.join(__dirname, "../standalone.js")
: path.join(__dirname, "..")
);
const plugin2 = require(
path.join(
__dirname,
global.STANDALONE ? "../standalone.js" : '..'
)
);
=====================================output=====================================
const {
one,
Expand Down Expand Up @@ -40,5 +53,15 @@ const {
const MyReallyExtrememlyLongModuleName = require("MyReallyExtrememlyLongModuleName");
const plugin = require(
global.STANDALONE
? path.join(__dirname, "../standalone.js")
: path.join(__dirname, ".."),
);
const plugin2 = require(
path.join(__dirname, global.STANDALONE ? "../standalone.js" : ".."),
);
================================================================================
`;
13 changes: 13 additions & 0 deletions tests/format/js/require/require.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,16 @@ const { one, two, three, four, five, six, seven, eight, nine, ten } = require('.
const { one1, two1, three1, four1, five1, six1, seven1, eight1, nine1, ten1, eleven1 } = require('./my-utils');

const MyReallyExtrememlyLongModuleName = require('MyReallyExtrememlyLongModuleName');

const plugin = require(
global.STANDALONE
? path.join(__dirname, "../standalone.js")
: path.join(__dirname, "..")
);

const plugin2 = require(
path.join(
__dirname,
global.STANDALONE ? "../standalone.js" : '..'
)
);

0 comments on commit 7eee800

Please sign in to comment.