diff --git a/packages/core/core/src/SymbolPropagation.js b/packages/core/core/src/SymbolPropagation.js index 720a28c1d03..3758c78bc02 100644 --- a/packages/core/core/src/SymbolPropagation.js +++ b/packages/core/core/src/SymbolPropagation.js @@ -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( diff --git a/packages/core/integration-tests/test/integration/multi-asset-transformer-export/.parcelrc b/packages/core/integration-tests/test/integration/multi-asset-transformer-export/.parcelrc new file mode 100644 index 00000000000..d1ccb1a6187 --- /dev/null +++ b/packages/core/integration-tests/test/integration/multi-asset-transformer-export/.parcelrc @@ -0,0 +1,6 @@ +{ + "extends": "@parcel/config-default", + "transformers": { + "*.js": ["parcel-transformer-test", "..."] + } +} diff --git a/packages/core/integration-tests/test/integration/multi-asset-transformer-export/index.js b/packages/core/integration-tests/test/integration/multi-asset-transformer-export/index.js new file mode 100644 index 00000000000..e69de29bb2d diff --git a/packages/core/integration-tests/test/integration/multi-asset-transformer-export/node_modules/parcel-transformer-test/index.js b/packages/core/integration-tests/test/integration/multi-asset-transformer-export/node_modules/parcel-transformer-test/index.js new file mode 100644 index 00000000000..75ca94d6ada --- /dev/null +++ b/packages/core/integration-tests/test/integration/multi-asset-transformer-export/node_modules/parcel-transformer-test/index.js @@ -0,0 +1,11 @@ +const {Transformer} = require('@parcel/plugin'); + +module.exports = new Transformer({ + transform({asset}) { + let a = `import {foo} from "x";\nconsole.log(foo);`; + let b = `export const bar = 2;`; + + asset.setCode(a); + return [asset, {type: 'js', content: b, uniqueKey: 'x'}]; + }, +}); diff --git a/packages/core/integration-tests/test/integration/multi-asset-transformer-export/node_modules/parcel-transformer-test/package.json b/packages/core/integration-tests/test/integration/multi-asset-transformer-export/node_modules/parcel-transformer-test/package.json new file mode 100644 index 00000000000..17b6afe6dc0 --- /dev/null +++ b/packages/core/integration-tests/test/integration/multi-asset-transformer-export/node_modules/parcel-transformer-test/package.json @@ -0,0 +1,4 @@ +{ + "name": "parcel-transformer-test", + "version": "1.0.0" +} diff --git a/packages/core/integration-tests/test/integration/multi-asset-transformer-export/yarn.lock b/packages/core/integration-tests/test/integration/multi-asset-transformer-export/yarn.lock new file mode 100644 index 00000000000..e69de29bb2d diff --git a/packages/core/integration-tests/test/plugin.js b/packages/core/integration-tests/test/plugin.js index 262400b4a9b..1c81cd8081d 100644 --- a/packages/core/integration-tests/test/plugin.js +++ b/packages/core/integration-tests/test/plugin.js @@ -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(