未验证 提交 5c059970 编写于 作者: L Lukas Taegert-Atkinson 提交者: GitHub

Respect propertyReadSideEffects in spread elements (#4119)

上级 b3d130b1
import { NormalizedTreeshakingOptions } from '../../rollup/types';
import { HasEffectsContext } from '../ExecutionContext';
import { NodeEvent } from '../NodeEvents';
import { ObjectPath, PathTracker, UNKNOWN_PATH, UnknownKey } from '../utils/PathTracker';
......@@ -27,9 +28,14 @@ export default class SpreadElement extends NodeBase {
}
hasEffects(context: HasEffectsContext): boolean {
if (!this.deoptimized) this.applyDeoptimizations();
const { propertyReadSideEffects } = this.context.options
.treeshake as NormalizedTreeshakingOptions;
return (
this.argument.hasEffects(context) ||
this.argument.hasEffectsWhenAccessedAtPath(UNKNOWN_PATH, context)
(propertyReadSideEffects &&
(propertyReadSideEffects === 'always' ||
this.argument.hasEffectsWhenAccessedAtPath(UNKNOWN_PATH, context)))
);
}
......
const getter = {
get foo () {
console.log( 'effect' );
get foo() {
console.log('effect');
}
};
const foo1 = getter.foo;
......@@ -13,4 +13,22 @@ function accessArg(arg) {
}
accessArg(null);
const foo4 = globalThis.globalThis.unknown.unknownProperty;
const foo4 = globalThis.unknown.unknownProperty;
const foo5 = {
...{
get prop() {
console.log('effect');
}
}
};
const foo6 = (async function () {
await {
get then() {
console.log('effect');
return () => {};
}
};
return { then() {} };
})();
......@@ -14,3 +14,21 @@ function accessArg(arg) {
accessArg(null);
globalThis.unknown.unknownProperty;
({
...{
get prop() {
console.log('effect');
}
}
});
((async function () {
await {
get then() {
console.log('effect');
return () => {};
}
};
return { then() {} };
}))();
......@@ -14,3 +14,21 @@ function accessArg(arg) {
accessArg(null);
const foo4 = globalThis.unknown.unknownProperty;
const foo5 = {
...{
get prop() {
console.log('effect');
}
}
};
const foo6 = (async function () {
await {
get then() {
console.log('effect');
return () => {};
}
};
return { then() {} };
})();
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册