Skip to content

Commit 1743794

Browse files
committed
Revert "Tree shake parameter defaults (#4498)"
This reverts commit 4624917.
1 parent fc99e96 commit 1743794

104 files changed

Lines changed: 611 additions & 1112 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

rollup.config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import commonjs from '@rollup/plugin-commonjs';
66
import json from '@rollup/plugin-json';
77
import { nodeResolve } from '@rollup/plugin-node-resolve';
88
import typescript from '@rollup/plugin-typescript';
9-
import type { Plugin, RollupOptions, WarningHandlerWithDefault } from 'rollup';
9+
import type { RollupOptions, WarningHandlerWithDefault } from 'rollup';
1010
import { string } from 'rollup-plugin-string';
1111
import { terser } from 'rollup-plugin-terser';
1212
import addCliEntry from './build-plugins/add-cli-entry';
@@ -65,7 +65,7 @@ const treeshake = {
6565
tryCatchDeoptimization: false
6666
};
6767

68-
const nodePlugins: Plugin[] = [
68+
const nodePlugins = [
6969
alias(moduleAliases),
7070
nodeResolve(),
7171
json(),

src/ast/nodes/ArrayExpression.ts

Lines changed: 3 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,8 @@
11
import type { CallOptions } from '../CallOptions';
22
import type { DeoptimizableEntity } from '../DeoptimizableEntity';
33
import type { HasEffectsContext } from '../ExecutionContext';
4-
import { InclusionContext } from '../ExecutionContext';
54
import type { NodeEvent } from '../NodeEvents';
6-
import {
7-
type ObjectPath,
8-
type PathTracker,
9-
UNKNOWN_PATH,
10-
UnknownInteger
11-
} from '../utils/PathTracker';
5+
import { type ObjectPath, type PathTracker, UnknownInteger } from '../utils/PathTracker';
126
import { UNDEFINED_EXPRESSION, UNKNOWN_LITERAL_NUMBER } from '../values';
137
import type * as NodeType from './NodeType';
148
import SpreadElement from './SpreadElement';
@@ -20,7 +14,6 @@ import { ObjectEntity, type ObjectProperty } from './shared/ObjectEntity';
2014
export default class ArrayExpression extends NodeBase {
2115
declare elements: readonly (ExpressionNode | SpreadElement | null)[];
2216
declare type: NodeType.tArrayExpression;
23-
protected deoptimized = false;
2417
private objectEntity: ObjectEntity | null = null;
2518

2619
deoptimizePath(path: ObjectPath): void {
@@ -63,7 +56,7 @@ export default class ArrayExpression extends NodeBase {
6356
);
6457
}
6558

66-
hasEffectsWhenAccessedAtPath(path: ObjectPath, context: HasEffectsContext): boolean | undefined {
59+
hasEffectsWhenAccessedAtPath(path: ObjectPath, context: HasEffectsContext): boolean {
6760
return this.getObjectEntity().hasEffectsWhenAccessedAtPath(path, context);
6861
}
6962

@@ -79,29 +72,6 @@ export default class ArrayExpression extends NodeBase {
7972
return this.getObjectEntity().hasEffectsWhenCalledAtPath(path, callOptions, context);
8073
}
8174

82-
includeArgumentsWhenCalledAtPath(
83-
path: ObjectPath,
84-
context: InclusionContext,
85-
args: readonly (ExpressionEntity | SpreadElement)[]
86-
) {
87-
this.getObjectEntity().includeArgumentsWhenCalledAtPath(path, context, args);
88-
}
89-
90-
protected applyDeoptimizations(): void {
91-
this.deoptimized = true;
92-
let hasSpread = false;
93-
for (let index = 0; index < this.elements.length; index++) {
94-
const element = this.elements[index];
95-
if (hasSpread || element instanceof SpreadElement) {
96-
if (element) {
97-
hasSpread = true;
98-
element.deoptimizePath(UNKNOWN_PATH);
99-
}
100-
}
101-
}
102-
this.context.requestTreeshakingPass();
103-
}
104-
10575
private getObjectEntity(): ObjectEntity {
10676
if (this.objectEntity !== null) {
10777
return this.objectEntity;
@@ -112,7 +82,7 @@ export default class ArrayExpression extends NodeBase {
11282
let hasSpread = false;
11383
for (let index = 0; index < this.elements.length; index++) {
11484
const element = this.elements[index];
115-
if (hasSpread || element instanceof SpreadElement) {
85+
if (element instanceof SpreadElement || hasSpread) {
11686
if (element) {
11787
hasSpread = true;
11888
properties.unshift({ key: UnknownInteger, kind: 'init', property: element });

src/ast/nodes/ArrayPattern.ts

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ export default class ArrayPattern extends NodeBase implements PatternNode {
1616
exportNamesByVariable: ReadonlyMap<Variable, readonly string[]>
1717
): void {
1818
for (const element of this.elements) {
19-
element?.addExportedVariables(variables, exportNamesByVariable);
19+
if (element !== null) {
20+
element.addExportedVariables(variables, exportNamesByVariable);
21+
}
2022
}
2123
}
2224

@@ -30,24 +32,30 @@ export default class ArrayPattern extends NodeBase implements PatternNode {
3032
return variables;
3133
}
3234

33-
// Patterns can only be deoptimized at the empty path at the moment
34-
deoptimizePath(): void {
35-
for (const element of this.elements) {
36-
element?.deoptimizePath(EMPTY_PATH);
35+
deoptimizePath(path: ObjectPath): void {
36+
if (path.length === 0) {
37+
for (const element of this.elements) {
38+
if (element !== null) {
39+
element.deoptimizePath(path);
40+
}
41+
}
3742
}
3843
}
3944

40-
// Patterns are only checked at the emtpy path at the moment
41-
hasEffectsWhenAssignedAtPath(_path: ObjectPath, context: HasEffectsContext): boolean {
45+
hasEffectsWhenAssignedAtPath(path: ObjectPath, context: HasEffectsContext): boolean {
46+
if (path.length > 0) return true;
4247
for (const element of this.elements) {
43-
if (element?.hasEffectsWhenAssignedAtPath(EMPTY_PATH, context)) return true;
48+
if (element !== null && element.hasEffectsWhenAssignedAtPath(EMPTY_PATH, context))
49+
return true;
4450
}
4551
return false;
4652
}
4753

4854
markDeclarationReached(): void {
4955
for (const element of this.elements) {
50-
element?.markDeclarationReached();
56+
if (element !== null) {
57+
element.markDeclarationReached();
58+
}
5159
}
5260
}
5361
}

src/ast/nodes/ArrowFunctionExpression.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import { type CallOptions } from '../CallOptions';
2-
import { type HasEffectsContext } from '../ExecutionContext';
2+
import { type HasEffectsContext, InclusionContext } from '../ExecutionContext';
33
import ReturnValueScope from '../scopes/ReturnValueScope';
44
import type Scope from '../scopes/Scope';
55
import { type ObjectPath } from '../utils/PathTracker';
66
import BlockStatement from './BlockStatement';
7+
import Identifier from './Identifier';
78
import * as NodeType from './NodeType';
89
import FunctionBase from './shared/FunctionBase';
9-
import { type ExpressionNode } from './shared/Node';
10+
import { type ExpressionNode, IncludeChildren } from './shared/Node';
1011
import { ObjectEntity } from './shared/ObjectEntity';
1112
import { OBJECT_PROTOTYPE } from './shared/ObjectPrototype';
1213
import type { PatternNode } from './shared/Pattern';
@@ -47,6 +48,15 @@ export default class ArrowFunctionExpression extends FunctionBase {
4748
return false;
4849
}
4950

51+
include(context: InclusionContext, includeChildrenRecursively: IncludeChildren): void {
52+
super.include(context, includeChildrenRecursively);
53+
for (const param of this.params) {
54+
if (!(param instanceof Identifier)) {
55+
param.include(context, includeChildrenRecursively);
56+
}
57+
}
58+
}
59+
5060
protected getObjectEntity(): ObjectEntity {
5161
if (this.objectEntity !== null) {
5262
return this.objectEntity;

src/ast/nodes/AssignmentExpression.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export default class AssignmentExpression extends NodeBase {
5454
);
5555
}
5656

57-
hasEffectsWhenAccessedAtPath(path: ObjectPath, context: HasEffectsContext): boolean | undefined {
57+
hasEffectsWhenAccessedAtPath(path: ObjectPath, context: HasEffectsContext): boolean {
5858
return path.length > 0 && this.right.hasEffectsWhenAccessedAtPath(path, context);
5959
}
6060

src/ast/nodes/AssignmentPattern.ts

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@ import type MagicString from 'magic-string';
22
import { BLANK } from '../../utils/blank';
33
import type { NodeRenderOptions, RenderOptions } from '../../utils/renderHelpers';
44
import type { HasEffectsContext } from '../ExecutionContext';
5-
import { InclusionContext } from '../ExecutionContext';
65
import { EMPTY_PATH, type ObjectPath, UNKNOWN_PATH } from '../utils/PathTracker';
76
import type LocalVariable from '../variables/LocalVariable';
87
import type Variable from '../variables/Variable';
98
import type * as NodeType from './NodeType';
109
import type { ExpressionEntity } from './shared/Expression';
11-
import { type ExpressionNode, IncludeChildren, NodeBase } from './shared/Node';
10+
import { type ExpressionNode, NodeBase } from './shared/Node';
1211
import type { PatternNode } from './shared/Pattern';
1312

1413
export default class AssignmentPattern extends NodeBase implements PatternNode {
@@ -36,12 +35,6 @@ export default class AssignmentPattern extends NodeBase implements PatternNode {
3635
return path.length > 0 || this.left.hasEffectsWhenAssignedAtPath(EMPTY_PATH, context);
3736
}
3837

39-
include(context: InclusionContext, includeChildrenRecursively: IncludeChildren): void {
40-
this.included = true;
41-
this.left.include(context, includeChildrenRecursively);
42-
this.right.include(context, includeChildrenRecursively);
43-
}
44-
4538
markDeclarationReached(): void {
4639
this.left.markDeclarationReached();
4740
}
@@ -52,11 +45,7 @@ export default class AssignmentPattern extends NodeBase implements PatternNode {
5245
{ isShorthandProperty }: NodeRenderOptions = BLANK
5346
): void {
5447
this.left.render(code, options, { isShorthandProperty });
55-
if (this.right.included) {
56-
this.right.render(code, options);
57-
} else {
58-
code.remove(this.left.end, this.end);
59-
}
48+
this.right.render(code, options);
6049
}
6150

6251
protected applyDeoptimizations(): void {

src/ast/nodes/AwaitExpression.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { InclusionContext } from '../ExecutionContext';
2+
import { UNKNOWN_PATH } from '../utils/PathTracker';
23
import ArrowFunctionExpression from './ArrowFunctionExpression';
34
import type * as NodeType from './NodeType';
45
import FunctionNode from './shared/FunctionNode';
@@ -29,4 +30,10 @@ export default class AwaitExpression extends NodeBase {
2930
}
3031
this.argument.include(context, includeChildrenRecursively);
3132
}
33+
34+
protected applyDeoptimizations(): void {
35+
this.deoptimized = true;
36+
this.argument.deoptimizePath(UNKNOWN_PATH);
37+
this.context.requestTreeshakingPass();
38+
}
3239
}

src/ast/nodes/BinaryExpression.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,18 +60,18 @@ export default class BinaryExpression extends NodeBase implements DeoptimizableE
6060
): LiteralValueOrUnknown {
6161
if (path.length > 0) return UnknownValue;
6262
const leftValue = this.left.getLiteralValueAtPath(EMPTY_PATH, recursionTracker, origin);
63-
if (typeof leftValue === 'symbol') return UnknownValue;
63+
if (leftValue === UnknownValue) return UnknownValue;
6464

6565
const rightValue = this.right.getLiteralValueAtPath(EMPTY_PATH, recursionTracker, origin);
66-
if (typeof rightValue === 'symbol') return UnknownValue;
66+
if (rightValue === UnknownValue) return UnknownValue;
6767

6868
const operatorFn = binaryOperators[this.operator];
6969
if (!operatorFn) return UnknownValue;
7070

7171
return operatorFn(leftValue, rightValue);
7272
}
7373

74-
hasEffects(context: HasEffectsContext): boolean | undefined {
74+
hasEffects(context: HasEffectsContext): boolean {
7575
// support some implicit type coercion runtime errors
7676
if (
7777
this.operator === '+' &&

0 commit comments

Comments
 (0)