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

Make sure UnknownFooExpressions are included when referenced as return values in a MultiExpression #3559

Merged
merged 1 commit into from
May 15, 2020
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
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');