Skip to content

Commit b82e5fa

Browse files
authored
Parse bundles as ES modules based on stats JSON information
1 parent f8d4711 commit b82e5fa

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ _Note: Gaps between patch versions are faulty, broken or test releases._
1212

1313
## UNRELEASED
1414

15+
* **Improvement**
16+
* Parse bundles as ES modules based on stats JSON information ([#649](https://github.com/webpack-contrib/webpack-bundle-analyzer/pull/649) by [@eamodio](https://github.com/eamodio))
17+
1518
## 4.10.2
1619

1720
* **Bug Fix**

src/analyzer.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ function getViewerData(bundleStats, bundleDir, opts) {
7777
let bundleInfo;
7878

7979
try {
80-
bundleInfo = parseBundle(assetFile);
80+
bundleInfo = parseBundle(assetFile, {sourceType: statAsset.info.javascriptModule ? 'module' : 'script'});
8181
} catch (err) {
8282
const msg = (err.code === 'ENOENT') ? 'no such file' : err.message;
8383
logger.warn(`Error parsing bundle asset "${assetFile}": ${msg}`);

src/parseUtils.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,14 @@ module.exports = {
66
parseBundle
77
};
88

9-
function parseBundle(bundlePath) {
9+
function parseBundle(bundlePath, opts) {
10+
const {
11+
sourceType = 'script'
12+
} = opts || {};
13+
1014
const content = fs.readFileSync(bundlePath, 'utf8');
1115
const ast = acorn.parse(content, {
12-
sourceType: 'script',
16+
sourceType,
1317
// I believe in a bright future of ECMAScript!
1418
// Actually, it's set to `2050` to support the latest ECMAScript version that currently exists.
1519
// Seems like `acorn` supports such weird option value.

0 commit comments

Comments
 (0)