From 145bfb8243c516765bcf5c59e381d0bc45fc5f9e Mon Sep 17 00:00:00 2001 From: Shinobu Hayashi Date: Mon, 15 Nov 2021 06:29:51 +0900 Subject: [PATCH] Fix RangeError in `not export` error with other file type (#7295) Co-authored-by: Niklas Mischkulnig <4586894+mischnic@users.noreply.github.com> --- .../core/src/requests/AssetGraphRequest.js | 2 +- .../package.json | 3 ++ .../src/App.jsx | 10 ++++ .../src/app.module.css | 0 .../core/integration-tests/test/postcss.js | 49 +++++++++++++++++++ 5 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 packages/core/integration-tests/test/integration/no-export-error-with-correct-filetype/package.json create mode 100644 packages/core/integration-tests/test/integration/no-export-error-with-correct-filetype/src/App.jsx create mode 100644 packages/core/integration-tests/test/integration/no-export-error-with-correct-filetype/src/app.module.css diff --git a/packages/core/core/src/requests/AssetGraphRequest.js b/packages/core/core/src/requests/AssetGraphRequest.js index 37896f780f2..791bfd63baf 100644 --- a/packages/core/core/src/requests/AssetGraphRequest.js +++ b/packages/core/core/src/requests/AssetGraphRequest.js @@ -554,7 +554,7 @@ export class AssetGraphBuilder { this.options.projectRoot, loc?.filePath, ) ?? undefined, - language: assetNode.value.type, + language: incomingDep.value.sourceAssetType ?? undefined, codeHighlights: [ { start: loc.start, diff --git a/packages/core/integration-tests/test/integration/no-export-error-with-correct-filetype/package.json b/packages/core/integration-tests/test/integration/no-export-error-with-correct-filetype/package.json new file mode 100644 index 00000000000..9baad30d43d --- /dev/null +++ b/packages/core/integration-tests/test/integration/no-export-error-with-correct-filetype/package.json @@ -0,0 +1,3 @@ +{ + "source": "src/App.jsx" +} diff --git a/packages/core/integration-tests/test/integration/no-export-error-with-correct-filetype/src/App.jsx b/packages/core/integration-tests/test/integration/no-export-error-with-correct-filetype/src/App.jsx new file mode 100644 index 00000000000..95813b4cc76 --- /dev/null +++ b/packages/core/integration-tests/test/integration/no-export-error-with-correct-filetype/src/App.jsx @@ -0,0 +1,10 @@ +import React from "react"; +import { render } from "react-dom"; + +import * as styles from "./app.module.css" + +const App = function() { + return
+} + +render(, document.getElementById("app")) diff --git a/packages/core/integration-tests/test/integration/no-export-error-with-correct-filetype/src/app.module.css b/packages/core/integration-tests/test/integration/no-export-error-with-correct-filetype/src/app.module.css new file mode 100644 index 00000000000..e69de29bb2d diff --git a/packages/core/integration-tests/test/postcss.js b/packages/core/integration-tests/test/postcss.js index e4efd86bb28..07ebf71e3c4 100644 --- a/packages/core/integration-tests/test/postcss.js +++ b/packages/core/integration-tests/test/postcss.js @@ -623,4 +623,53 @@ describe('postcss', () => { await subscription.unsubscribe(); }); + + it('should throw an error when importing a missing class', async function () { + await assert.rejects( + () => + bundle( + path.join( + __dirname, + '/integration/no-export-error-with-correct-filetype/src/App.jsx', + ), + { + shouldDisableCache: true, + defaultTargetOptions: { + shouldScopeHoist: true, + }, + }, + ), + { + name: 'BuildError', + diagnostics: [ + { + codeFrames: [ + { + filePath: path.join( + __dirname, + '/integration/no-export-error-with-correct-filetype/src/App.jsx', + ), + language: 'js', + codeHighlights: [ + { + end: { + column: 45, + line: 7, + }, + start: { + column: 28, + line: 7, + }, + }, + ], + }, + ], + message: + "integration/no-export-error-with-correct-filetype/src/app.module.css does not export 'notExisting'", + origin: '@parcel/core', + }, + ], + }, + ); + }); });