Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix an issue where the same hash was generated when different variables were exported under the same name #2741

Merged
merged 1 commit into from Mar 7, 2019
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/Chunk.ts
Expand Up @@ -30,6 +30,7 @@ import { sortByExecutionOrder } from './utils/executionOrder';
import getIndentString from './utils/getIndentString';
import { makeLegal } from './utils/identifierHelpers';
import { basename, dirname, isAbsolute, normalize, relative, resolve } from './utils/path';
import relativeId from './utils/relativeId';
import renderChunk from './utils/renderChunk';
import { RenderOptions } from './utils/renderHelpers';
import { makeUnique, renderNamePattern } from './utils/renderNamePattern';
Expand Down Expand Up @@ -286,7 +287,16 @@ export default class Chunk {
if (!this.renderedSource) return '';
const hash = sha256();
hash.update(this.renderedSource.toString());
hash.update(Object.keys(this.exportNames).join(','));
hash.update(
Object.keys(this.exportNames)
.map(exportName => {
const variable = this.exportNames[exportName];
return `${relativeId(variable.module.id).replace(/\\/g, '/')}:${
variable.name
}:${exportName}`;
})
.join(',')
);
return (this.renderedHash = hash.digest('hex'));
}

Expand Down

This file was deleted.

@@ -0,0 +1,5 @@
define(['./chunk-main2-ed4460c9-amd.js'], function (main2) { 'use strict';

main2.log(main2.dep);

});
@@ -0,0 +1,7 @@
define(['./chunk-main2-ed4460c9-amd.js'], function (main2) { 'use strict';



return main2.log;

});

This file was deleted.

This file was deleted.

@@ -0,0 +1,5 @@
'use strict';

var main2 = require('./chunk-main2-690ec2d2-cjs.js');

main2.log(main2.dep);
@@ -0,0 +1,7 @@
'use strict';

var main2 = require('./chunk-main2-690ec2d2-cjs.js');



module.exports = main2.log;

This file was deleted.

@@ -0,0 +1,3 @@
import { a as log, b as dep } from './chunk-main2-88db1d1d-esm.js';

log(dep);

This file was deleted.

@@ -0,0 +1 @@
export { a as default } from './chunk-main2-88db1d1d-esm.js';

This file was deleted.

@@ -1,4 +1,4 @@
System.register(['./chunk-main2-d134c6d9-system.js'], function (exports, module) {
System.register(['./chunk-main2-26e1391e-system.js'], function (exports, module) {
'use strict';
var log, dep;
return {
Expand Down
@@ -1,4 +1,4 @@
System.register(['./chunk-main2-d134c6d9-system.js'], function (exports, module) {
System.register(['./chunk-main2-26e1391e-system.js'], function (exports, module) {
'use strict';
return {
setters: [function (module) {
Expand Down
9 changes: 9 additions & 0 deletions test/file-hashes/samples/export-order-2/_config.js
@@ -0,0 +1,9 @@
module.exports = {
description: 'creates different hashes if different variables are exported under the same name',
options1: {
input: ['main1', 'dep']
},
options2: {
input: ['main2', 'dep']
}
};
1 change: 1 addition & 0 deletions test/file-hashes/samples/export-order-2/dep.js
@@ -0,0 +1 @@
export const a = 3;
7 changes: 7 additions & 0 deletions test/file-hashes/samples/export-order-2/main1.js
@@ -0,0 +1,7 @@
import { a as b } from './dep.js';

const a = 1;

console.log(a, b);

export { a };
7 changes: 7 additions & 0 deletions test/file-hashes/samples/export-order-2/main2.js
@@ -0,0 +1,7 @@
import { a as b } from './dep.js';

const a = 1;

console.log(a, b);

export { b as a };
9 changes: 9 additions & 0 deletions test/file-hashes/samples/export-order/_config.js
@@ -0,0 +1,9 @@
module.exports = {
description: 'creates different hashes if different variables are exported under the same name',
options1: {
input: ['main1']
},
options2: {
input: ['main2']
}
};
6 changes: 6 additions & 0 deletions test/file-hashes/samples/export-order/main1.js
@@ -0,0 +1,6 @@
const a = 1;
const b = 2;

console.log(a, b);

export { a };
6 changes: 6 additions & 0 deletions test/file-hashes/samples/export-order/main2.js
@@ -0,0 +1,6 @@
const a = 1;
const b = 2;

console.log(a, b);

export { b as a };
9 changes: 9 additions & 0 deletions test/file-hashes/samples/internal-exports/_config.js
@@ -0,0 +1,9 @@
module.exports = {
description: 'creates different hashes if generated internal exports differ',
options1: {
input: ['main1', 'other']
},
options2: {
input: ['main2', 'other']
}
};
2 changes: 2 additions & 0 deletions test/file-hashes/samples/internal-exports/dep.js
@@ -0,0 +1,2 @@
export const a = 1;
export const b = 2;
3 changes: 3 additions & 0 deletions test/file-hashes/samples/internal-exports/main1.js
@@ -0,0 +1,3 @@
import { b } from './dep.js';

console.log(b);
3 changes: 3 additions & 0 deletions test/file-hashes/samples/internal-exports/main2.js
@@ -0,0 +1,3 @@
import { a } from './dep.js';

console.log(a);
3 changes: 3 additions & 0 deletions test/file-hashes/samples/internal-exports/other.js
@@ -0,0 +1,3 @@
import { a, b } from './dep.js';

console.log(a, b);
2 changes: 1 addition & 1 deletion test/misc/bundle-information.js
Expand Up @@ -26,7 +26,7 @@ describe('The bundle object', () => {
.then(({ output }) => {
assert.deepEqual(
output.map(chunk => chunk.fileName),
['input1-eebe7cfb.js', 'input2-370063a6.js', 'generated-chunk-e9283962.js'],
['input1-91cf8b5e.js', 'input2-28e1210a.js', 'generated-chunk-e9283962.js'],
'fileName'
);
assert.deepEqual(
Expand Down