Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ModuleInfo.importedIds does not crash in moduleParsed (#4208)
* fixed: ModuleInfo.importedIds moduleInfo.importedIds return null if resolvedIds[source] if undefined * Only call moduleParsed once importedIds and dynamicallyImportedIds are available * Update documentation Co-authored-by: Lukas Taegert-Atkinson <lukas.taegert-atkinson@tngtech.com>
- Loading branch information
1 parent
69c099c
commit 05fe93d
Showing
7 changed files
with
122 additions
and
46 deletions.
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
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
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
31 changes: 31 additions & 0 deletions
31
test/function/samples/module-parsed-imported-ids/_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,31 @@ | ||
const assert = require('assert'); | ||
const path = require('path'); | ||
|
||
module.exports = { | ||
description: 'provides full importedIds and dynamicallyImportedIds in the moduleParsed hook', | ||
options: { | ||
plugins: [ | ||
{ | ||
load(id) { | ||
const { dynamicallyImportedIds, importedIds } = this.getModuleInfo(id); | ||
assert.deepStrictEqual(importedIds, []); | ||
assert.deepStrictEqual(dynamicallyImportedIds, []); | ||
}, | ||
transform(code, id) { | ||
const { dynamicallyImportedIds, importedIds } = this.getModuleInfo(id); | ||
assert.deepStrictEqual(importedIds, []); | ||
assert.deepStrictEqual(dynamicallyImportedIds, []); | ||
}, | ||
moduleParsed({ dynamicallyImportedIds, id, importedIds }) { | ||
if (id.endsWith('main.js')) { | ||
assert.deepStrictEqual(importedIds, [path.join(__dirname, 'static.js')]); | ||
assert.deepStrictEqual(dynamicallyImportedIds, [path.join(__dirname, 'dynamic.js')]); | ||
} else { | ||
assert.deepStrictEqual(importedIds, []); | ||
assert.deepStrictEqual(dynamicallyImportedIds, []); | ||
} | ||
} | ||
} | ||
] | ||
} | ||
}; |
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 @@ | ||
export const bar = 'dynamic'; |
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,3 @@ | ||
import { foo } from './static.js'; | ||
|
||
export const result = [foo, import('./dynamic.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 @@ | ||
export const foo = 'static'; |