From b5f34b04ced0a955de281dc8381debf23fd5c24d Mon Sep 17 00:00:00 2001 From: Shinyaigeek Date: Sat, 13 Nov 2021 16:06:53 +0900 Subject: [PATCH 1/4] Fix set codeFrames' language from incomingDeps' source type --- packages/core/core/src/requests/AssetGraphRequest.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/core/core/src/requests/AssetGraphRequest.js b/packages/core/core/src/requests/AssetGraphRequest.js index 37896f780f2..5e36188021a 100644 --- a/packages/core/core/src/requests/AssetGraphRequest.js +++ b/packages/core/core/src/requests/AssetGraphRequest.js @@ -554,7 +554,9 @@ export class AssetGraphBuilder { this.options.projectRoot, loc?.filePath, ) ?? undefined, - language: assetNode.value.type, + language: + incomingDep.value.sourceAssetType ?? + assetNode.value.type, codeHighlights: [ { start: loc.start, From 3c10736c151f4a1ef11f227b054cbd59d9020c8c Mon Sep 17 00:00:00 2001 From: Shinyaigeek Date: Sun, 14 Nov 2021 01:36:21 +0900 Subject: [PATCH 2/4] Chore add test for setting correct language in not export error --- .../package.json | 3 ++ .../src/App.jsx | 10 ++++ .../src/app.module.css | 0 .../integration-tests/test/scope-hoisting.js | 47 +++++++++++++++++++ 4 files changed, 60 insertions(+) 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/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/scope-hoisting.js b/packages/core/integration-tests/test/scope-hoisting.js index b871856e0f1..ecba2a93d2c 100644 --- a/packages/core/integration-tests/test/scope-hoisting.js +++ b/packages/core/integration-tests/test/scope-hoisting.js @@ -6081,4 +6081,51 @@ describe('scope hoisting', function () { let output = await run(b); assert.strictEqual(output, 'bar foo bar'); }); + + it("no export error codeFrames' language should be importing source file type", async function () { + await assert.rejects( + () => + bundle( + path.join( + __dirname, + '/integration/no-export-error-with-correct-filetype/src/App.jsx', + ), + + { + shouldDisableCache: 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', + }, + ], + }, + ); + }); }); From 9830609027533258c3b994281b923f9626412a15 Mon Sep 17 00:00:00 2001 From: Shinobu Hayashi Date: Mon, 15 Nov 2021 00:39:00 +0900 Subject: [PATCH 3/4] Update: not set not export error's codeFrame language assetNode.value.type Co-authored-by: Niklas Mischkulnig <4586894+mischnic@users.noreply.github.com> --- packages/core/core/src/requests/AssetGraphRequest.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/packages/core/core/src/requests/AssetGraphRequest.js b/packages/core/core/src/requests/AssetGraphRequest.js index 5e36188021a..791bfd63baf 100644 --- a/packages/core/core/src/requests/AssetGraphRequest.js +++ b/packages/core/core/src/requests/AssetGraphRequest.js @@ -554,9 +554,7 @@ export class AssetGraphBuilder { this.options.projectRoot, loc?.filePath, ) ?? undefined, - language: - incomingDep.value.sourceAssetType ?? - assetNode.value.type, + language: incomingDep.value.sourceAssetType ?? undefined, codeHighlights: [ { start: loc.start, From f5ca1bcb74ab132d58a51bfbdf31fa6a1018089e Mon Sep 17 00:00:00 2001 From: Shinyaigeek Date: Mon, 15 Nov 2021 00:45:56 +0900 Subject: [PATCH 4/4] Chore: mv test for not exporting error into postcss integration test --- .../core/integration-tests/test/postcss.js | 49 +++++++++++++++++++ .../integration-tests/test/scope-hoisting.js | 47 ------------------ 2 files changed, 49 insertions(+), 47 deletions(-) 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', + }, + ], + }, + ); + }); }); diff --git a/packages/core/integration-tests/test/scope-hoisting.js b/packages/core/integration-tests/test/scope-hoisting.js index ecba2a93d2c..b871856e0f1 100644 --- a/packages/core/integration-tests/test/scope-hoisting.js +++ b/packages/core/integration-tests/test/scope-hoisting.js @@ -6081,51 +6081,4 @@ describe('scope hoisting', function () { let output = await run(b); assert.strictEqual(output, 'bar foo bar'); }); - - it("no export error codeFrames' language should be importing source file type", async function () { - await assert.rejects( - () => - bundle( - path.join( - __dirname, - '/integration/no-export-error-with-correct-filetype/src/App.jsx', - ), - - { - shouldDisableCache: 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', - }, - ], - }, - ); - }); });