diff --git a/packages/core/core/src/requests/AssetGraphRequest.js b/packages/core/core/src/requests/AssetGraphRequest.js index 25a05ebdf1e..89969dff840 100644 --- a/packages/core/core/src/requests/AssetGraphRequest.js +++ b/packages/core/core/src/requests/AssetGraphRequest.js @@ -25,7 +25,7 @@ import nullthrows from 'nullthrows'; import {PromiseQueue} from '@parcel/utils'; import {hashString} from '@parcel/hash'; import ThrowableDiagnostic, {md} from '@parcel/diagnostic'; -import {Priority} from '../types'; +import {BundleBehavior, Priority} from '../types'; import AssetGraph from '../AssetGraph'; import {PARCEL_VERSION} from '../constants'; import createEntryRequest from './EntryRequest'; @@ -471,6 +471,8 @@ export class AssetGraphBuilder { for (let s of incomingDep.usedSymbolsDown) { if ( assetSymbols == null || // Assume everything could be provided if symbols are cleared + assetNode.value.bundleBehavior === BundleBehavior.isolated || + assetNode.value.bundleBehavior === BundleBehavior.inline || assetNode.usedSymbols.has(s) || reexportedSymbols.has(s) || s === '*' diff --git a/packages/core/integration-tests/test/integration/bundle-text/javascript.js b/packages/core/integration-tests/test/integration/bundle-text/javascript.js index b336f67bddb..01ca020b80f 100644 --- a/packages/core/integration-tests/test/integration/bundle-text/javascript.js +++ b/packages/core/integration-tests/test/integration/bundle-text/javascript.js @@ -1,2 +1,3 @@ import jsText from 'bundle-text:./other.js'; +output = jsText; export default jsText; diff --git a/packages/core/integration-tests/test/integration/bundle-text/log.js b/packages/core/integration-tests/test/integration/bundle-text/log.js new file mode 100644 index 00000000000..ec10f3e9de1 --- /dev/null +++ b/packages/core/integration-tests/test/integration/bundle-text/log.js @@ -0,0 +1 @@ +console.log('hi'); diff --git a/packages/core/integration-tests/test/integration/bundle-text/other.js b/packages/core/integration-tests/test/integration/bundle-text/other.js index ec10f3e9de1..a5dd85a5da0 100644 --- a/packages/core/integration-tests/test/integration/bundle-text/other.js +++ b/packages/core/integration-tests/test/integration/bundle-text/other.js @@ -1 +1 @@ -console.log('hi'); +import './log'; diff --git a/packages/core/integration-tests/test/integration/worklet/colors.js b/packages/core/integration-tests/test/integration/worklet/colors.js new file mode 100644 index 00000000000..69d0953d465 --- /dev/null +++ b/packages/core/integration-tests/test/integration/worklet/colors.js @@ -0,0 +1 @@ +export const colors = ['red', 'green', 'blue']; diff --git a/packages/core/integration-tests/test/integration/worklet/worklet-pipeline.js b/packages/core/integration-tests/test/integration/worklet/worklet-pipeline.js index 8a7ff4d129f..680f46d29b7 100644 --- a/packages/core/integration-tests/test/integration/worklet/worklet-pipeline.js +++ b/packages/core/integration-tests/test/integration/worklet/worklet-pipeline.js @@ -1,2 +1,2 @@ import url from 'worklet:./worklet'; -export default url; +output = url; diff --git a/packages/core/integration-tests/test/integration/worklet/worklet.js b/packages/core/integration-tests/test/integration/worklet/worklet.js index 12cdab6833f..c71984e3c11 100644 --- a/packages/core/integration-tests/test/integration/worklet/worklet.js +++ b/packages/core/integration-tests/test/integration/worklet/worklet.js @@ -1,8 +1,9 @@ +import {colors} from './colors'; + // checkerboard.js class CheckerboardPainter { paint(ctx, geom, properties) { // Use "ctx" as if it was a normal canvas - const colors = ['red', 'green', 'blue']; const size = 32; for(let y = 0; y < geom.height/size; y++) { for(let x = 0; x < geom.width/size; x++) { diff --git a/packages/core/integration-tests/test/javascript.js b/packages/core/integration-tests/test/javascript.js index 19834f09302..a82c8ac7b10 100644 --- a/packages/core/integration-tests/test/javascript.js +++ b/packages/core/integration-tests/test/javascript.js @@ -62,16 +62,19 @@ describe('javascript', function() { it('should support url: imports of another javascript file', async function() { let b = await bundle( path.join(__dirname, '/integration/worklet/pipeline.js'), + { + mode: 'production', + }, ); assertBundles(b, [ { name: 'pipeline.js', - assets: ['bundle-url.js', 'pipeline.js', 'esmodule-helpers.js'], + assets: ['bundle-url.js', 'pipeline.js', 'bundle-manifest.js'], }, { type: 'js', - assets: ['worklet.js'], + assets: ['worklet.js', 'colors.js'], }, ]); @@ -112,7 +115,7 @@ describe('javascript', function() { }, { type: 'js', - assets: ['worklet.js'], + assets: ['worklet.js', 'colors.js', 'esmodule-helpers.js'], }, ]); @@ -146,7 +149,7 @@ describe('javascript', function() { }, { type: 'js', - assets: ['worklet.js'], + assets: ['worklet.js', 'colors.js', 'esmodule-helpers.js'], }, ]); @@ -240,21 +243,24 @@ describe('javascript', function() { it('should support audio worklets via a pipeline', async function() { let b = await bundle( path.join(__dirname, '/integration/worklet/worklet-pipeline.js'), + { + mode: 'production', + }, ); assertBundles(b, [ { name: 'worklet-pipeline.js', - assets: ['bundle-url.js', 'esmodule-helpers.js', 'worklet-pipeline.js'], + assets: ['bundle-url.js', 'bundle-manifest.js', 'worklet-pipeline.js'], }, { type: 'js', - assets: ['worklet.js'], + assets: ['worklet.js', 'colors.js'], }, ]); let res = await run(b); - assert(/^http:\/\/localhost\/worklet\.[0-9a-f]+\.js$/.test(res.default)); + assert(/^http:\/\/localhost\/worklet\.[0-9a-f]+\.js$/.test(res)); let name; await runBundle( @@ -4146,6 +4152,27 @@ describe('javascript', function() { assert.equal(log, 'hi'); }); + it("should inline a JS bundle's compiled text with `bundle-text` with symbol propagation", async () => { + let b = await bundle( + path.join(__dirname, '/integration/bundle-text/javascript.js'), + { + mode: 'production', + }, + ); + + let res = await run(b); + let log; + let ctx = vm.createContext({ + console: { + log(x) { + log = x; + }, + }, + }); + vm.runInContext(res, ctx); + assert.equal(log, 'hi'); + }); + it("should inline a bundle's compiled text with `bundle-text` asynchronously", async () => { let b = await bundle( path.join(__dirname, '/integration/bundle-text/async.js'),