Skip to content

Commit

Permalink
🐛 fix: undefined deoptimizePath when the first element is empty str…
Browse files Browse the repository at this point in the history
…ing (#4070)

* 🐛 fix: undefined `deoptimizePath` when the first element is empty string

* Add test

Co-authored-by: Lukas Taegert-Atkinson <lukas.taegert-atkinson@tngtech.com>
Co-authored-by: Lukas Taegert-Atkinson <lukastaegert@users.noreply.github.com>
  • Loading branch information
3 people committed May 15, 2021
1 parent c40d206 commit 3acd536
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/ast/variables/NamespaceVariable.ts
Expand Up @@ -33,12 +33,12 @@ export default class NamespaceVariable extends Variable {
const memberVariables = this.getMemberVariables();
const memberPath = path.length <= 1 ? UNKNOWN_PATH : path.slice(1);
const key = path[0];
if (typeof key !== 'string') {
if (typeof key === 'string') {
memberVariables[key]?.deoptimizePath(memberPath);
} else {
for (const key of Object.keys(memberVariables)) {
memberVariables[key].deoptimizePath(memberPath);
}
} else {
memberVariables[key].deoptimizePath(memberPath);
}
}

Expand Down
@@ -0,0 +1,8 @@
const assert = require('assert');

module.exports = {
description: 'handles deoptimization of non-existing namespace members',
exports(exports) {
assert.strictEqual(exports.bar, undefined);
}
};
@@ -0,0 +1,4 @@
import * as ns from './other.js';

const foo = 'foo';
export const bar = ns[foo];
Empty file.

0 comments on commit 3acd536

Please sign in to comment.