Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ _Note: Gaps between patch versions are faulty, broken or test releases._

## UNRELEASED

* **Improvement**
* 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))

## 4.10.2

* **Bug Fix**
Expand Down
2 changes: 1 addition & 1 deletion src/analyzer.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ function getViewerData(bundleStats, bundleDir, opts) {
let bundleInfo;

try {
bundleInfo = parseBundle(assetFile);
bundleInfo = parseBundle(assetFile, {sourceType: statAsset.info.javascriptModule ? 'module' : 'script'});
} catch (err) {
const msg = (err.code === 'ENOENT') ? 'no such file' : err.message;
logger.warn(`Error parsing bundle asset "${assetFile}": ${msg}`);
Expand Down
8 changes: 6 additions & 2 deletions src/parseUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@ module.exports = {
parseBundle
};

function parseBundle(bundlePath) {
function parseBundle(bundlePath, opts) {
const {
sourceType = 'script'
} = opts || {};

const content = fs.readFileSync(bundlePath, 'utf8');
const ast = acorn.parse(content, {
sourceType: 'script',
sourceType,
// I believe in a bright future of ECMAScript!
// Actually, it's set to `2050` to support the latest ECMAScript version that currently exists.
// Seems like `acorn` supports such weird option value.
Expand Down
Loading