From f3990f39429c202bbe70dc8d681f67cf272b1a85 Mon Sep 17 00:00:00 2001 From: Devon Govett Date: Tue, 7 May 2019 18:25:54 -0700 Subject: [PATCH] Clear scope cache before crawling (#2986) --- .../es6/default-export-class-rename/a.js | 2 ++ .../es6/default-export-class-rename/b.js | 9 +++++++++ .../es6/default-export-class-rename/package.json | 5 +++++ .../core/integration-tests/test/scope-hoisting.js | 12 ++++++++++++ .../core/parcel-bundler/src/scope-hoisting/hoist.js | 2 ++ 5 files changed, 30 insertions(+) create mode 100644 packages/core/integration-tests/test/integration/scope-hoisting/es6/default-export-class-rename/a.js create mode 100644 packages/core/integration-tests/test/integration/scope-hoisting/es6/default-export-class-rename/b.js create mode 100644 packages/core/integration-tests/test/integration/scope-hoisting/es6/default-export-class-rename/package.json diff --git a/packages/core/integration-tests/test/integration/scope-hoisting/es6/default-export-class-rename/a.js b/packages/core/integration-tests/test/integration/scope-hoisting/es6/default-export-class-rename/a.js new file mode 100644 index 00000000000..efa0e7d7260 --- /dev/null +++ b/packages/core/integration-tests/test/integration/scope-hoisting/es6/default-export-class-rename/a.js @@ -0,0 +1,2 @@ +import Test from './b'; +output = Test.create(); diff --git a/packages/core/integration-tests/test/integration/scope-hoisting/es6/default-export-class-rename/b.js b/packages/core/integration-tests/test/integration/scope-hoisting/es6/default-export-class-rename/b.js new file mode 100644 index 00000000000..2908f869e18 --- /dev/null +++ b/packages/core/integration-tests/test/integration/scope-hoisting/es6/default-export-class-rename/b.js @@ -0,0 +1,9 @@ +export default class Test { + constructor() { + this.foo = 'bar'; + } + + static create() { + return new Test(); + } +} diff --git a/packages/core/integration-tests/test/integration/scope-hoisting/es6/default-export-class-rename/package.json b/packages/core/integration-tests/test/integration/scope-hoisting/es6/default-export-class-rename/package.json new file mode 100644 index 00000000000..fb6878912e4 --- /dev/null +++ b/packages/core/integration-tests/test/integration/scope-hoisting/es6/default-export-class-rename/package.json @@ -0,0 +1,5 @@ +{ + "name": "default-export-class-rename", + "private": true, + "browserslist": ["last 1 Chrome version"] +} diff --git a/packages/core/integration-tests/test/scope-hoisting.js b/packages/core/integration-tests/test/scope-hoisting.js index 348e5692a97..81e565308b8 100644 --- a/packages/core/integration-tests/test/scope-hoisting.js +++ b/packages/core/integration-tests/test/scope-hoisting.js @@ -568,6 +568,18 @@ describe('scope hoisting', function() { assert(!/bar/.test(contents)); assert(!/displayName/.test(contents)); }); + + it('should correctly rename references to default exported classes', async function() { + let b = await bundle( + path.join( + __dirname, + '/integration/scope-hoisting/es6/default-export-class-rename/a.js' + ) + ); + + let output = await run(b); + assert.deepEqual(output.foo, 'bar'); + }); }); describe('commonjs', function() { diff --git a/packages/core/parcel-bundler/src/scope-hoisting/hoist.js b/packages/core/parcel-bundler/src/scope-hoisting/hoist.js index 27f6bfe3352..2fb83bd236c 100644 --- a/packages/core/parcel-bundler/src/scope-hoisting/hoist.js +++ b/packages/core/parcel-bundler/src/scope-hoisting/hoist.js @@ -2,6 +2,7 @@ const path = require('path'); const mm = require('micromatch'); const t = require('@babel/types'); const template = require('@babel/template').default; +const traverse = require('@babel/traverse').default; const rename = require('./renamer'); const {getName, getIdentifier, getExportIdentifier} = require('./utils'); @@ -51,6 +52,7 @@ function hasSideEffects(asset, {sideEffects} = asset._package) { module.exports = { Program: { enter(path, asset) { + traverse.cache.clearScope(); path.scope.crawl(); asset.cacheData.imports = asset.cacheData.imports || Object.create(null);