Skip to content

Commit

Permalink
Do not include namespace for conflicting member access
Browse files Browse the repository at this point in the history
  • Loading branch information
lukastaegert committed May 4, 2021
1 parent 3c031cf commit 33c1254
Show file tree
Hide file tree
Showing 16 changed files with 25 additions and 136 deletions.
11 changes: 3 additions & 8 deletions src/ast/nodes/MemberExpression.ts
Expand Up @@ -123,14 +123,9 @@ export default class MemberExpression extends NodeBase implements DeoptimizableE
if (path.length === 0) this.disallowNamespaceReassignment();
if (this.variable) {
this.variable.deoptimizePath(path);
} else {
const propertyKey = this.getPropertyKey();
if (propertyKey === UnknownKey) {
this.object.deoptimizePath(UNKNOWN_PATH);
} else {
this.wasPathDeoptimizedWhileOptimized = true;
this.object.deoptimizePath([propertyKey, ...path]);
}
} else if (!this.replacement) {
this.wasPathDeoptimizedWhileOptimized = true;
this.object.deoptimizePath([this.getPropertyKey(), ...path]);
}
}

Expand Down
18 changes: 10 additions & 8 deletions src/ast/variables/NamespaceVariable.ts
Expand Up @@ -3,7 +3,7 @@ import { RenderOptions } from '../../utils/renderHelpers';
import { RESERVED_NAMES } from '../../utils/reservedNames';
import { getSystemExportStatement } from '../../utils/systemJsRendering';
import Identifier from '../nodes/Identifier';
import { UNKNOWN_PATH } from '../utils/PathTracker';
import { ObjectPath, UNKNOWN_PATH } from '../utils/PathTracker';
import Variable from './Variable';

export default class NamespaceVariable extends Variable {
Expand All @@ -29,14 +29,16 @@ export default class NamespaceVariable extends Variable {
this.name = identifier.name;
}

// This is only called if "UNKNOWN_PATH" is reassigned as in all other situations, either the
// build fails due to an illegal namespace reassignment or MemberExpression already forwards
// the reassignment to the right variable. This means we lost track of this variable and thus
// need to reassign all exports.
deoptimizePath() {
deoptimizePath(path: ObjectPath) {
const memberVariables = this.getMemberVariables();
for (const key of Object.keys(memberVariables)) {
memberVariables[key].deoptimizePath(UNKNOWN_PATH);
const memberPath = path.length <= 1 ? UNKNOWN_PATH : path.slice(1);
const key = path[0];
if (typeof key !== 'string') {
for (const key of Object.keys(memberVariables)) {
memberVariables[key].deoptimizePath(memberPath);
}
} else {
memberVariables[key]?.deoptimizePath(memberPath);
}
}

Expand Down
21 changes: 0 additions & 21 deletions test/form/samples/mutations-in-imports/_expected/amd.js

This file was deleted.

19 changes: 0 additions & 19 deletions test/form/samples/mutations-in-imports/_expected/cjs.js

This file was deleted.

22 changes: 0 additions & 22 deletions test/form/samples/mutations-in-imports/_expected/iife.js

This file was deleted.

26 changes: 0 additions & 26 deletions test/form/samples/mutations-in-imports/_expected/system.js

This file was deleted.

24 changes: 0 additions & 24 deletions test/form/samples/mutations-in-imports/_expected/umd.js

This file was deleted.

4 changes: 4 additions & 0 deletions test/form/samples/namespace-conflict/_config.js
@@ -0,0 +1,4 @@
module.exports = {
description: 'replaces conflicting namespace properties with undefined',
expectedWarnings: ['NAMESPACE_CONFLICT', 'MISSING_EXPORT']
};
1 change: 1 addition & 0 deletions test/form/samples/namespace-conflict/_expected.js
@@ -0,0 +1 @@
console.log(undefined);
1 change: 1 addition & 0 deletions test/form/samples/namespace-conflict/first.js
@@ -0,0 +1 @@
export const foo = 1;
3 changes: 3 additions & 0 deletions test/form/samples/namespace-conflict/main.js
@@ -0,0 +1,3 @@
import * as ns from './reexport';

console.log(ns.foo);
2 changes: 2 additions & 0 deletions test/form/samples/namespace-conflict/reexport.js
@@ -0,0 +1,2 @@
export * from './first';
export * from './second';
1 change: 1 addition & 0 deletions test/form/samples/namespace-conflict/second.js
@@ -0,0 +1 @@
export const foo = 2;
6 changes: 0 additions & 6 deletions test/function/samples/pattern-encodings/_config.js

This file was deleted.

2 changes: 0 additions & 2 deletions test/function/samples/pattern-encodings/main.js

This file was deleted.

0 comments on commit 33c1254

Please sign in to comment.