Skip to content

Commit

Permalink
Clear scope cache before crawling (#2986)
Browse files Browse the repository at this point in the history
  • Loading branch information
devongovett committed May 8, 2019
1 parent 897cb1c commit f3990f3
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 0 deletions.
@@ -0,0 +1,2 @@
import Test from './b';
output = Test.create();
@@ -0,0 +1,9 @@
export default class Test {
constructor() {
this.foo = 'bar';
}

static create() {
return new Test();
}
}
@@ -0,0 +1,5 @@
{
"name": "default-export-class-rename",
"private": true,
"browserslist": ["last 1 Chrome version"]
}
12 changes: 12 additions & 0 deletions packages/core/integration-tests/test/scope-hoisting.js
Expand Up @@ -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() {
Expand Down
2 changes: 2 additions & 0 deletions packages/core/parcel-bundler/src/scope-hoisting/hoist.js
Expand Up @@ -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');

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit f3990f3

Please sign in to comment.