File tree Expand file tree Collapse file tree 4 files changed +36
-11
lines changed
test/form/samples/dynamic-import-unresolvable Expand file tree Collapse file tree 4 files changed +36
-11
lines changed Original file line number Diff line number Diff line change @@ -302,18 +302,17 @@ export default class Module {
302302 getDynamicImportExpressions ( ) : ( string | Node ) [ ] {
303303 return this . dynamicImports . map ( ( { node } ) => {
304304 const importArgument = node . parent . arguments [ 0 ] ;
305- if ( importArgument instanceof TemplateLiteral ) {
306- if ( importArgument . expressions . length === 0 && importArgument . quasis . length === 1 ) {
307- return importArgument . quasis [ 0 ] . value . cooked ;
308- }
309- } else if ( importArgument instanceof Literal ) {
310- if ( typeof importArgument . value === 'string' ) {
311- return importArgument . value ;
312- }
313- } else {
314- return importArgument ;
305+ if (
306+ importArgument instanceof TemplateLiteral &&
307+ importArgument . quasis . length === 1 &&
308+ importArgument . quasis [ 0 ] . value . cooked
309+ ) {
310+ return importArgument . quasis [ 0 ] . value . cooked ;
311+ }
312+ if ( importArgument instanceof Literal && typeof importArgument . value === 'string' ) {
313+ return importArgument . value ;
315314 }
316- return undefined as any ;
315+ return importArgument ;
317316 } ) ;
318317 }
319318
Original file line number Diff line number Diff line change 1+ const assert = require ( 'assert' ) ;
2+
3+ module . exports = {
4+ solo : true ,
5+ description : 'Returns the raw AST nodes for unresolvable dynamic imports' ,
6+ options : {
7+ plugins : [
8+ {
9+ resolveDynamicImport ( specifier ) {
10+ assert . ok ( specifier ) ;
11+ assert . strictEqual ( typeof specifier , 'object' ) ;
12+ if ( specifier . type !== 'TemplateLiteral' && specifier . type !== 'Literal' ) {
13+ throw new Error ( `Unexpected specifier type ${ specifier . type } .` ) ;
14+ }
15+ return false ;
16+ }
17+ }
18+ ]
19+ }
20+ } ;
Original file line number Diff line number Diff line change 1+ import ( `${ globalVar } ` ) ;
2+ import ( `My ${ globalVar } ` ) ;
3+ import ( 7 ) ;
Original file line number Diff line number Diff line change 1+ import ( `${ globalVar } ` ) ;
2+ import ( `My ${ globalVar } ` ) ;
3+ import ( 7 ) ;
You can’t perform that action at this time.
0 commit comments