File tree Expand file tree Collapse file tree 4 files changed +70
-6
lines changed
Expand file tree Collapse file tree 4 files changed +70
-6
lines changed Original file line number Diff line number Diff line change @@ -586,6 +586,63 @@ loadable({
586586});"
587587` ;
588588
589+ exports [` plugin custom signatures (default) should support old named import 1` ] = `
590+ "import loadable from './loadable-utils';
591+ loadable({
592+ resolved : {},
593+
594+ chunkName () {
595+ return \`ModA\`.replace(/[^a -zA -Z0 -9_ !§$ ()= \\\\- ^ °]+/g , \\"-\\");
596+ },
597+
598+ isReady (props ) {
599+ const key = this.resolve(props );
600+
601+ if (this .resolved [key ] !== true ) {
602+ return false ;
603+ }
604+
605+ if (typeof __webpack_modules__ !== 'undefined ') {
606+ return !! __webpack_modules__ [key ];
607+ }
608+
609+ return false;
610+ },
611+
612+ importAsync : () => import (
613+ /* webpackChunkName: \\"ModA\\" */
614+ \` ./ModA\` ),
615+
616+ requireAsync(props) {
617+ const key = this .resolve (props );
618+ this .resolved [key ] = false ;
619+ return this .importAsync (props ).then (resolved => {
620+ this .resolved [key ] = true ;
621+ return resolved ;
622+ });
623+ } ,
624+
625+ requireSync(props) {
626+ const id = this .resolve (props );
627+
628+ if (typeof __webpack_require__ !== ' undefined' ) {
629+ return __webpack_require__(id );
630+ }
631+
632+ return eval (' module.require' )(id );
633+ } ,
634+
635+ resolve() {
636+ if (require .resolveWeak ) {
637+ return require.resolveWeak(\`./ModA \`);
638+ }
639+
640+ return eval (' require.resolve' )(\` ./ModA\` );
641+ }
642+
643+ });"
644+ ` ;
645+
589646exports [` plugin custom signatures named signature should not match default import 1` ] = `
590647"import myLoadable from 'myLoadablePackage';
591648myLoadable(() => import(\` ./ModA\` ));"
Original file line number Diff line number Diff line change @@ -20,12 +20,11 @@ const properties = [
2020
2121const LOADABLE_COMMENT = '#__LOADABLE__'
2222
23+ const DEFAULT_SIGNATURE = [ { name : 'default' , from : '@loadable/component' } ] ;
24+
2325const loadablePlugin = declare ( ( api , {
24- signatures = [ ]
26+ signatures = DEFAULT_SIGNATURE
2527 } ) => {
26- if ( ! signatures . find ( sig => sig . from == '@loadable/component' ) ) {
27- signatures . push ( { name : 'default' , from : '@loadable/component' } )
28- }
2928 const { types : t } = api
3029
3130 function collectImportCallPaths ( startPath ) {
@@ -124,7 +123,8 @@ const loadablePlugin = declare((api, {
124123 Program : {
125124 enter ( programPath ) {
126125 let lazyImportSpecifier = false
127- const loadableSpecifiers = [ ]
126+ // default to "loadable" detection. Remove defaults if signatures are configured
127+ const loadableSpecifiers = signatures === DEFAULT_SIGNATURE ? [ 'loadable' ] : [ ] ;
128128
129129 programPath . traverse ( {
130130 ImportDefaultSpecifier ( path ) {
Original file line number Diff line number Diff line change @@ -203,6 +203,13 @@ describe('plugin', () => {
203203 } )
204204
205205 describe ( 'custom signatures' , ( ) => {
206+ it ( '(default) should support old named import' , ( ) => {
207+ const result = testPlugin ( `
208+ import loadable from './loadable-utils'
209+ loadable(() => import(\`./ModA\`))
210+ ` )
211+ expect ( result ) . toMatchSnapshot ( )
212+ } ) ;
206213 it ( 'should match simple default import' , ( ) => {
207214 const result = testPlugin ( `
208215 import loadable from '@loadable/component'
Original file line number Diff line number Diff line change @@ -45,7 +45,7 @@ describe('ChunkExtrator', () => {
4545 statsFile : path . resolve ( __dirname , '../__fixtures__/stats.json' ) ,
4646 } )
4747
48- expect ( extractor . stats ) . toBe ( stats )
48+ expect ( extractor . stats ) . toEqual ( stats )
4949 } )
5050 } )
5151
You can’t perform that action at this time.
0 commit comments