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 exports" error for multiple assets returned by transformers #8947

Merged
merged 2 commits into from
Apr 28, 2023
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
6 changes: 5 additions & 1 deletion packages/core/core/src/SymbolPropagation.js
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,11 @@ export function propagateSymbols({
assetGraph.getNodeIdByContentKey(incomingDep.id),
);
let resolution = nullthrows(assetGraph.getNode(resolutionNodeId));
invariant(resolution && resolution.type === 'asset_group');
invariant(
resolution &&
(resolution.type === 'asset_group' ||
resolution.type === 'asset'),
);

errors.push({
message: md`${fromProjectPathRelative(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": "@parcel/config-default",
"transformers": {
"*.js": ["parcel-transformer-test", "..."]
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

46 changes: 46 additions & 0 deletions packages/core/integration-tests/test/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,52 @@ parcel-transformer-b`,
assert.equal(await run(b), 2);
});

it('throws when multiple assets returned by a transformer import a missing symbol', async function () {
let source = path.join(
__dirname,
'/integration/multi-asset-transformer-export/index.js',
);
let message = `index.js does not export 'foo'`;

// $FlowFixMe[prop-missing]
await assert.rejects(
() =>
bundle(source, {
defaultTargetOptions: {
shouldScopeHoist: true,
},
}),
{
name: 'BuildError',
message,
diagnostics: [
{
message,
origin: '@parcel/core',
codeFrames: [
{
filePath: source,
language: 'js',
codeHighlights: [
{
start: {
line: 1,
column: 9,
},
end: {
line: 1,
column: 11,
},
},
],
},
],
},
],
},
);
});

it('should allow resolvers to invalidateOnEnvChange', async () => {
async function assertAsset(replacedCode) {
let b = await bundle(
Expand Down