Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recognize require call with template literals (but no placeholders) #5492

Closed
mischnic opened this issue Dec 17, 2020 · 4 comments · Fixed by #7369
Closed

Recognize require call with template literals (but no placeholders) #5492

mischnic opened this issue Dec 17, 2020 · 4 comments · Fixed by #7369

Comments

@mischnic
Copy link
Member

mischnic commented Dec 17, 2020

🐛 bug report

require(`lodash`)

should behave just like require("lodash") but are currently ignored.


require(`./${thing}`)

should still be ignored.

💁 Possible Solution

This case should be normalized here:

types.isIdentifier(callee) &&
callee.name === 'require' &&
args.length === 1 &&
types.isStringLiteral(args[0]) &&
!hasBinding(ancestors, 'require') &&
!isInFalsyBranch(ancestors);

and also normalized to "lodash".

Add a test similar to this one:

it('should produce a basic JS bundle with CommonJS requires', async function() {
let b = await bundle(
path.join(__dirname, '/integration/commonjs/index.js'),
);
// assert.equal(b.assets.size, 8);
// assert.equal(b.childBundles.size, 1);
let output = await run(b);
assert.equal(typeof output, 'function');
assert.equal(output(), 3);
});

@AceTheCreator
Copy link

@mischnic I'd love to pick up this issue

@DeMoorJasper
Copy link
Member

@alphabet-codes sure, feel free to work on this

@ognjenjevremovic
Copy link

Hey @DeMoorJasper is this issue still open and up for grabs?
This seems to me like a welcoming issue for first time contributors to the project.

May I have a chance to provide a MR for this issue?

Many thanks!

@mischnic
Copy link
Member Author

@ognjenjevremovic Sure

ognjenjevremovic pushed a commit to ognjenjevremovic/parcel that referenced this issue Feb 23, 2021
Requiring packages with CommonJS and using template literals (instead of
string literals) should behave exactly the same. Template literal
expressions are not allowed in the CommonJS require calls.

✅ Closes: parcel-bundler#5492
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants