Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix 'does not export default' error with scope hoisting and url/worklet pipeline #6803

Merged
merged 4 commits into from
Sep 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/core/core/src/requests/AssetGraphRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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 === '*'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
import jsText from 'bundle-text:./other.js';
output = jsText;
export default jsText;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log('hi');
Original file line number Diff line number Diff line change
@@ -1 +1 @@
console.log('hi');
import './log';
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const colors = ['red', 'green', 'blue'];
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
import url from 'worklet:./worklet';
export default url;
output = url;
Original file line number Diff line number Diff line change
@@ -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++) {
Expand Down
41 changes: 34 additions & 7 deletions packages/core/integration-tests/test/javascript.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
},
]);

Expand Down Expand Up @@ -112,7 +115,7 @@ describe('javascript', function() {
},
{
type: 'js',
assets: ['worklet.js'],
assets: ['worklet.js', 'colors.js', 'esmodule-helpers.js'],
},
]);

Expand Down Expand Up @@ -146,7 +149,7 @@ describe('javascript', function() {
},
{
type: 'js',
assets: ['worklet.js'],
assets: ['worklet.js', 'colors.js', 'esmodule-helpers.js'],
},
]);

Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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'),
Expand Down