Skip to content

Commit d98dd27

Browse files
mbrownegregberge
authored andcommitted
fix(babel-plugin): fix bug when using + concatenation instead of a template literal (#425)
1 parent d4428c6 commit d98dd27

File tree

3 files changed

+54
-0
lines changed

3 files changed

+54
-0
lines changed

packages/babel-plugin/src/__snapshots__/index.test.js.snap

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,45 @@ exports[`plugin simple import should work with * in name 1`] = `
527527
});"
528528
`;
529529
530+
exports[`plugin simple import should work with + concatenation 1`] = `
531+
"loadable({
532+
chunkName() {
533+
return \\"\\";
534+
},
535+
536+
isReady(props) {
537+
if (typeof __webpack_modules__ !== 'undefined') {
538+
return !!__webpack_modules__[this.resolve(props)];
539+
}
540+
541+
return false;
542+
},
543+
544+
requireAsync: () => import(
545+
/* webpackChunkName: \\"\\" */
546+
'./Mod' + 'A'),
547+
548+
requireSync(props) {
549+
const id = this.resolve(props);
550+
551+
if (typeof __webpack_require__ !== 'undefined') {
552+
return __webpack_require__(id);
553+
}
554+
555+
return eval('module.require')(id);
556+
},
557+
558+
resolve() {
559+
if (require.resolveWeak) {
560+
return require.resolveWeak('./Mod' + 'A');
561+
}
562+
563+
return eval('require.resolve')('./Mod' + 'A');
564+
}
565+
566+
});"
567+
`;
568+
530569
exports[`plugin simple import should work with template literal 1`] = `
531570
"loadable({
532571
chunkName() {

packages/babel-plugin/src/index.test.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@ describe('plugin', () => {
2121
expect(result).toMatchSnapshot()
2222
})
2323

24+
it('should work with + concatenation', () => {
25+
const result = testPlugin(`
26+
loadable(() => import('./Mod' + 'A'))
27+
`)
28+
29+
expect(result).toMatchSnapshot()
30+
})
31+
2432
it('should work with * in name', () => {
2533
const result = testPlugin(`
2634
loadable(() => import(\`./foo*\`))

packages/babel-plugin/src/properties/resolve.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@ export default function resolveProperty({ types: t, template }) {
1717
importArg.node.expressions,
1818
)
1919
}
20+
if (importArg.isBinaryExpression()) {
21+
return t.BinaryExpression(
22+
importArg.node.operator,
23+
importArg.node.left,
24+
importArg.node.right,
25+
)
26+
}
2027
return t.stringLiteral(importArg.node.value)
2128
}
2229

0 commit comments

Comments
 (0)