File tree 2 files changed +49
-1
lines changed
core/integration-tests/test
2 files changed +49
-1
lines changed Original file line number Diff line number Diff line change @@ -1214,6 +1214,48 @@ describe('bundler', function () {
1214
1214
] ) ;
1215
1215
} ) ;
1216
1216
1217
+ it ( 'should support inline constants in async bundles' , async ( ) => {
1218
+ await fsFixture ( overlayFS , __dirname ) `
1219
+ inline-constants-async
1220
+ index.js:
1221
+ import('./async').then(m => console.log(m.value));
1222
+
1223
+ async.js:
1224
+ export const value = 'async value';
1225
+
1226
+ package.json:
1227
+ {
1228
+ "@parcel/transformer-js": {
1229
+ "unstable_inlineConstants": true
1230
+ }
1231
+ }
1232
+
1233
+ yarn.lock:` ;
1234
+
1235
+ let b = await bundle (
1236
+ path . join ( __dirname , 'inline-constants-async/index.js' ) ,
1237
+ {
1238
+ mode : 'production' ,
1239
+ defaultTargetOptions : {
1240
+ shouldScopeHoist : true ,
1241
+ sourceMaps : false ,
1242
+ shouldOptimize : false ,
1243
+ } ,
1244
+ inputFS : overlayFS ,
1245
+ } ,
1246
+ ) ;
1247
+
1248
+ // This will fail when the async bundle does not export it's constant
1249
+ await run ( b ) ;
1250
+
1251
+ // Asset should not be inlined
1252
+ const index = b . getBundles ( ) . find ( b => b . name . startsWith ( 'index' ) ) ;
1253
+ const contents = overlayFS . readFileSync ( index . filePath , 'utf8' ) ;
1254
+ assert (
1255
+ ! contents . includes ( 'async value' ) ,
1256
+ 'async value should not be inlined' ,
1257
+ ) ;
1258
+ } ) ;
1217
1259
describe ( 'manual shared bundles' , ( ) => {
1218
1260
const dir = path . join ( __dirname , 'manual-bundle' ) ;
1219
1261
Original file line number Diff line number Diff line change @@ -317,7 +317,13 @@ export class ScopeHoistingPackager {
317
317
. getIncomingDependencies ( asset )
318
318
. some ( dep => dep . meta . shouldWrap && dep . specifierType !== 'url' )
319
319
) {
320
- if ( ! asset . meta . isConstantModule ) {
320
+ // Don't wrap constant "entry" modules _except_ if they are referenced by any lazy dependency
321
+ if (
322
+ ! asset . meta . isConstantModule ||
323
+ this . bundleGraph
324
+ . getIncomingDependencies ( asset )
325
+ . some ( dep => dep . priority === 'lazy' )
326
+ ) {
321
327
this . wrappedAssets . add ( asset . id ) ;
322
328
wrapped . push ( asset ) ;
323
329
}
You can’t perform that action at this time.
0 commit comments