Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: provide json hint when importing a no export json file (#4741)
* fix: add json hint for missing export error * fix: tweak logical & add test Co-authored-by: Lukas Taegert-Atkinson <lukastaegert@users.noreply.github.com>
- Loading branch information
1 parent
156f4d1
commit cc54a24
Showing
4 changed files
with
34 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
test/function/samples/adds-json-hint-for-missing-export-if-is-json-file/_config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
const path = require('node:path'); | ||
const ID_MAIN = path.join(__dirname, 'main.js'); | ||
const ID_ARRAY_JSON = path.join(__dirname, 'array.json'); | ||
|
||
module.exports = { | ||
description: 'should provide json hint when importing a no export json file', | ||
error: { | ||
binding: 'default', | ||
code: 'MISSING_EXPORT', | ||
exporter: ID_ARRAY_JSON, | ||
id: ID_MAIN, | ||
url: 'https://rollupjs.org/guide/en/#error-name-is-not-exported-by-module', | ||
pos: 7, | ||
loc: { | ||
column: 7, | ||
file: ID_MAIN, | ||
line: 1 | ||
}, | ||
frame: ` | ||
1: import theArray from './array.json'; | ||
^ | ||
2: export default theArray; | ||
`, | ||
watchFiles: [ID_ARRAY_JSON, ID_MAIN], | ||
message: | ||
'"default" is not exported by "array.json", imported by "main.js". (Note that you need @rollup/plugin-json to import JSON files)' | ||
} | ||
}; |
1 change: 1 addition & 0 deletions
1
test/function/samples/adds-json-hint-for-missing-export-if-is-json-file/array.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
["foo", "bar"] |
2 changes: 2 additions & 0 deletions
2
test/function/samples/adds-json-hint-for-missing-export-if-is-json-file/main.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
import theArray from './array.json'; | ||
export default theArray; |