Skip to content

Commit

Permalink
Make sure UnknownXYExpressions are included when referenced as return…
Browse files Browse the repository at this point in the history
… values in a MultiExpression (#3559)
  • Loading branch information
lukastaegert committed May 15, 2020
1 parent e5872b0 commit 4ae97b5
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/ast/nodes/shared/MultiExpression.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { CallOptions } from '../../CallOptions';
import { DeoptimizableEntity } from '../../DeoptimizableEntity';
import { HasEffectsContext } from '../../ExecutionContext';
import { HasEffectsContext, InclusionContext } from '../../ExecutionContext';
import { ObjectPath, PathTracker } from '../../utils/PathTracker';
import { LiteralValueOrUnknown, UnknownValue } from '../../values';
import { ExpressionEntity } from './Expression';
import { IncludeChildren } from './Node';

export class MultiExpression implements ExpressionEntity {
included = false;
Expand Down Expand Up @@ -61,7 +62,15 @@ export class MultiExpression implements ExpressionEntity {
return false;
}

include(): void {}
include(context: InclusionContext, includeChildrenRecursively: IncludeChildren): void {
// This is only relevant to include values that do not have an AST representation,
// such as UnknownArrayExpression. Thus we only need to include them once.
for (const expression of this.expressions) {
if (!expression.included) {
expression.include(context, includeChildrenRecursively);
}
}
}

includeCallArguments(): void {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const assert = require('assert');

module.exports = {
description:
'recognizes side-effects when applying mutable array methods to chained array methods (#3555)',
exports(exports) {
assert.deepStrictEqual(exports.a, ['PASS']);
}
};
5 changes: 5 additions & 0 deletions test/function/samples/chained-mutable-array-methods/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
function f(x) {
return (x ? [] : ['FAIL']).map(o => o);
}
export const a = f(0);
a.splice(0, 1, 'PASS');

0 comments on commit 4ae97b5

Please sign in to comment.