Skip to content

Commit

Permalink
Merge branch 'master' into fix/illegal-identifier-exported-in-es
Browse files Browse the repository at this point in the history
  • Loading branch information
lukastaegert committed Apr 18, 2023
2 parents 09208df + f1538ce commit 76fcbbc
Show file tree
Hide file tree
Showing 42 changed files with 330 additions and 282 deletions.
14 changes: 7 additions & 7 deletions .github/workflows/repl-artefacts.yml
Expand Up @@ -74,14 +74,14 @@ jobs:
or load it into the REPL:
https://rollupjs.org/repl/?pr=${{ github.event.number }}
- name: Update comment for Netlify deploy
uses: jakepartusch/wait-for-netlify-action@v1
id: waitForNetlify
- name: Find Vercel preview URL
uses: patrickedqvist/wait-for-vercel-preview@v1.3.1
id: waitForVercel
with:
site_name: "rollupjs"
- name: Update comment for Netlify
token: ${{ secrets.GITHUB_TOKEN }}
- name: Update comment with Vercel preview URL
uses: peter-evans/create-or-update-comment@v3
if: ${{ steps.waitForNetlify.outputs.url }}
if: ${{ steps.waitForVercel.outputs.url }}
with:
comment-id: ${{ steps.createInitialComment.outputs.comment-id }}
issue-number: ${{ github.event.number }}
Expand All @@ -96,4 +96,4 @@ jobs:
```
or load it into the REPL:
${{ steps.waitForNetlify.outputs.url }}/repl/?pr=${{ github.event.number }}
${{ steps.waitForVercel.outputs.url }}/repl/?pr=${{ github.event.number }}
30 changes: 30 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,35 @@
# rollup changelog

## 3.20.4

_2023-04-17_

### Bug Fixes

- Do not remove breaks statements after switch statements with conditional breaks (#4937)

### Pull Requests

- [#4937](https://github.com/rollup/rollup/pull/4937): fix: handle conditional breaks in nested switch statement cases (@TrickyPi and @lukastaegert)

## 3.20.3

_2023-04-16_

### Bug Fixes

- Reduce memory consumption for function call parameter analysis (#4938)
- Fix types for `shouldTransformCachedModule` (#4932)

### Pull Requests

- [#4925](https://github.com/rollup/rollup/pull/4925): chore: repl style add scoped (@btea)
- [#4926](https://github.com/rollup/rollup/pull/4926): docs: Update the x_google_ignorelist url (@jecfish)
- [#4932](https://github.com/rollup/rollup/pull/4932): Allow shouldTransformCachedModule to return null (@bluwy)
- [#4935](https://github.com/rollup/rollup/pull/4935): Bump peter-evans/create-or-update-comment from 2 to 3 (@dependabot[bot])
- [#4936](https://github.com/rollup/rollup/pull/4936): Disable puppeteer sandbox to fix Vercel deployment (@lukastaegert)
- [#4938](https://github.com/rollup/rollup/pull/4938): Improve memory usage for parameter deoptimizations (@lukastaegert)

## 3.20.2

_2023-03-24_
Expand Down
2 changes: 1 addition & 1 deletion browser/package.json
@@ -1,6 +1,6 @@
{
"name": "@rollup/browser",
"version": "3.20.2",
"version": "3.20.4",
"description": "Next-generation ES module bundler browser build",
"main": "dist/rollup.browser.js",
"module": "dist/es/rollup.browser.js",
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "rollup",
"version": "3.20.2",
"version": "3.20.4",
"description": "Next-generation ES module bundler",
"main": "dist/rollup.js",
"module": "dist/es/rollup.js",
Expand Down
18 changes: 10 additions & 8 deletions src/ast/ExecutionContext.ts
Expand Up @@ -11,12 +11,10 @@ interface ExecutionContextIgnore {
this: boolean;
}

export const BROKEN_FLOW_NONE = 0;
export const BROKEN_FLOW_BREAK_CONTINUE = 1;
export const BROKEN_FLOW_ERROR_RETURN_LABEL = 2;

interface ControlFlowContext {
brokenFlow: number;
brokenFlow: boolean;
hasBreak: boolean;
hasContinue: boolean;
includedLabels: Set<string>;
}

Expand All @@ -27,7 +25,7 @@ export interface InclusionContext extends ControlFlowContext {
export interface HasEffectsContext extends ControlFlowContext {
accessed: PathTracker;
assigned: PathTracker;
brokenFlow: number;
brokenFlow: boolean;
called: DiscriminatedPathTracker;
ignore: ExecutionContextIgnore;
instantiated: DiscriminatedPathTracker;
Expand All @@ -36,7 +34,9 @@ export interface HasEffectsContext extends ControlFlowContext {

export function createInclusionContext(): InclusionContext {
return {
brokenFlow: BROKEN_FLOW_NONE,
brokenFlow: false,
hasBreak: false,
hasContinue: false,
includedCallArguments: new Set(),
includedLabels: new Set()
};
Expand All @@ -46,8 +46,10 @@ export function createHasEffectsContext(): HasEffectsContext {
return {
accessed: new PathTracker(),
assigned: new PathTracker(),
brokenFlow: BROKEN_FLOW_NONE,
brokenFlow: false,
called: new DiscriminatedPathTracker(),
hasBreak: false,
hasContinue: false,
ignore: {
breaks: false,
continues: false,
Expand Down
30 changes: 11 additions & 19 deletions src/ast/NodeInteractions.ts
Expand Up @@ -6,53 +6,45 @@ export const INTERACTION_ACCESSED = 0;
export const INTERACTION_ASSIGNED = 1;
export const INTERACTION_CALLED = 2;

// The first argument is the "this" context
export interface NodeInteractionAccessed {
args: null;
thisArg: ExpressionEntity | null;
args: readonly [ExpressionEntity | null];
type: typeof INTERACTION_ACCESSED;
}

export const NODE_INTERACTION_UNKNOWN_ACCESS: NodeInteractionAccessed = {
args: null,
thisArg: null,
args: [null],
type: INTERACTION_ACCESSED
};

// The first argument is the "this" context, the second argument the assigned expression
export interface NodeInteractionAssigned {
args: readonly [ExpressionEntity];
thisArg: ExpressionEntity | null;
args: readonly [ExpressionEntity | null, ExpressionEntity];
type: typeof INTERACTION_ASSIGNED;
}

export const UNKNOWN_ARG = [UNKNOWN_EXPRESSION] as const;

export const NODE_INTERACTION_UNKNOWN_ASSIGNMENT: NodeInteractionAssigned = {
args: UNKNOWN_ARG,
thisArg: null,
args: [null, UNKNOWN_EXPRESSION],
type: INTERACTION_ASSIGNED
};

// The first argument is the "this" context, the other arguments are the actual arguments
export interface NodeInteractionCalled {
args: readonly (ExpressionEntity | SpreadElement)[];
thisArg: ExpressionEntity | null;
args: readonly [ExpressionEntity | null, ...(ExpressionEntity | SpreadElement)[]];
type: typeof INTERACTION_CALLED;
withNew: boolean;
}

export const NO_ARGS = [];

// While this is technically a call without arguments, we can compare against
// this reference in places where precise values or thisArg would make a
// this reference in places where precise values or this argument would make a
// difference
export const NODE_INTERACTION_UNKNOWN_CALL: NodeInteractionCalled = {
args: NO_ARGS,
thisArg: null,
args: [null],
type: INTERACTION_CALLED,
withNew: false
};

// For tracking, called and assigned are uniquely determined by their .args
// while accessed is determined by .thisArg
// For tracking, interactions are uniquely determined by their .args
export type NodeInteraction =
| NodeInteractionAccessed
| NodeInteractionAssigned
Expand Down
15 changes: 6 additions & 9 deletions src/ast/nodes/BreakStatement.ts
@@ -1,9 +1,4 @@
import {
BROKEN_FLOW_BREAK_CONTINUE,
BROKEN_FLOW_ERROR_RETURN_LABEL,
type HasEffectsContext,
type InclusionContext
} from '../ExecutionContext';
import { type HasEffectsContext, type InclusionContext } from '../ExecutionContext';
import type Identifier from './Identifier';
import type * as NodeType from './NodeType';
import { StatementBase } from './shared/Node';
Expand All @@ -16,11 +11,11 @@ export default class BreakStatement extends StatementBase {
if (this.label) {
if (!context.ignore.labels.has(this.label.name)) return true;
context.includedLabels.add(this.label.name);
context.brokenFlow = BROKEN_FLOW_ERROR_RETURN_LABEL;
} else {
if (!context.ignore.breaks) return true;
context.brokenFlow = BROKEN_FLOW_BREAK_CONTINUE;
context.hasBreak = true;
}
context.brokenFlow = true;
return false;
}

Expand All @@ -29,7 +24,9 @@ export default class BreakStatement extends StatementBase {
if (this.label) {
this.label.include();
context.includedLabels.add(this.label.name);
} else {
context.hasBreak = true;
}
context.brokenFlow = this.label ? BROKEN_FLOW_ERROR_RETURN_LABEL : BROKEN_FLOW_BREAK_CONTINUE;
context.brokenFlow = true;
}
}
5 changes: 3 additions & 2 deletions src/ast/nodes/CallExpression.ts
Expand Up @@ -41,11 +41,12 @@ export default class CallExpression
}
}
this.interaction = {
args: this.arguments,
thisArg:
args: [
this.callee instanceof MemberExpression && !this.callee.variable
? this.callee.object
: null,
...this.arguments
],
type: INTERACTION_CALLED,
withNew: false
};
Expand Down
6 changes: 4 additions & 2 deletions src/ast/nodes/ConditionalExpression.ts
@@ -1,5 +1,5 @@
import type MagicString from 'magic-string';
import { BLANK } from '../../utils/blank';
import { BLANK, EMPTY_ARRAY } from '../../utils/blank';
import type { NodeRenderOptions, RenderOptions } from '../../utils/renderHelpers';
import {
findFirstOccurrenceOutsideComment,
Expand Down Expand Up @@ -44,7 +44,9 @@ export default class ConditionalExpression extends NodeBase implements Deoptimiz
const unusedBranch = this.usedBranch === this.consequent ? this.alternate : this.consequent;
this.usedBranch = null;
unusedBranch.deoptimizePath(UNKNOWN_PATH);
for (const expression of this.expressionsToBeDeoptimized) {
const { expressionsToBeDeoptimized } = this;
this.expressionsToBeDeoptimized = EMPTY_ARRAY as unknown as DeoptimizableEntity[];
for (const expression of expressionsToBeDeoptimized) {
expression.deoptimizeCache();
}
}
Expand Down
15 changes: 6 additions & 9 deletions src/ast/nodes/ContinueStatement.ts
@@ -1,9 +1,4 @@
import {
BROKEN_FLOW_BREAK_CONTINUE,
BROKEN_FLOW_ERROR_RETURN_LABEL,
type HasEffectsContext,
type InclusionContext
} from '../ExecutionContext';
import { type HasEffectsContext, type InclusionContext } from '../ExecutionContext';
import type Identifier from './Identifier';
import type * as NodeType from './NodeType';
import { StatementBase } from './shared/Node';
Expand All @@ -16,11 +11,11 @@ export default class ContinueStatement extends StatementBase {
if (this.label) {
if (!context.ignore.labels.has(this.label.name)) return true;
context.includedLabels.add(this.label.name);
context.brokenFlow = BROKEN_FLOW_ERROR_RETURN_LABEL;
} else {
if (!context.ignore.continues) return true;
context.brokenFlow = BROKEN_FLOW_BREAK_CONTINUE;
context.hasContinue = true;
}
context.brokenFlow = true;
return false;
}

Expand All @@ -29,7 +24,9 @@ export default class ContinueStatement extends StatementBase {
if (this.label) {
this.label.include();
context.includedLabels.add(this.label.name);
} else {
context.hasContinue = true;
}
context.brokenFlow = this.label ? BROKEN_FLOW_ERROR_RETURN_LABEL : BROKEN_FLOW_BREAK_CONTINUE;
context.brokenFlow = true;
}
}
15 changes: 3 additions & 12 deletions src/ast/nodes/DoWhileStatement.ts
Expand Up @@ -6,6 +6,7 @@ import {
StatementBase,
type StatementNode
} from './shared/Node';
import { hasLoopBodyEffects, includeLoopBody } from './shared/loops';

export default class DoWhileStatement extends StatementBase {
declare body: StatementNode;
Expand All @@ -14,22 +15,12 @@ export default class DoWhileStatement extends StatementBase {

hasEffects(context: HasEffectsContext): boolean {
if (this.test.hasEffects(context)) return true;
const { brokenFlow, ignore } = context;
const { breaks, continues } = ignore;
ignore.breaks = true;
ignore.continues = true;
if (this.body.hasEffects(context)) return true;
ignore.breaks = breaks;
ignore.continues = continues;
context.brokenFlow = brokenFlow;
return false;
return hasLoopBodyEffects(context, this.body);
}

include(context: InclusionContext, includeChildrenRecursively: IncludeChildren): void {
this.included = true;
this.test.include(context, includeChildrenRecursively);
const { brokenFlow } = context;
this.body.include(context, includeChildrenRecursively, { asSingleStatement: true });
context.brokenFlow = brokenFlow;
includeLoopBody(context, this.body, includeChildrenRecursively);
}
}
15 changes: 3 additions & 12 deletions src/ast/nodes/ForInStatement.ts
Expand Up @@ -15,6 +15,7 @@ import {
type StatementNode
} from './shared/Node';
import type { PatternNode } from './shared/Pattern';
import { hasLoopBodyEffects, includeLoopBody } from './shared/loops';

export default class ForInStatement extends StatementBase {
declare body: StatementNode;
Expand All @@ -30,15 +31,7 @@ export default class ForInStatement extends StatementBase {
const { body, deoptimized, left, right } = this;
if (!deoptimized) this.applyDeoptimizations();
if (left.hasEffectsAsAssignmentTarget(context, false) || right.hasEffects(context)) return true;
const { brokenFlow, ignore } = context;
const { breaks, continues } = ignore;
ignore.breaks = true;
ignore.continues = true;
if (body.hasEffects(context)) return true;
ignore.breaks = breaks;
ignore.continues = continues;
context.brokenFlow = brokenFlow;
return false;
return hasLoopBodyEffects(context, body);
}

include(context: InclusionContext, includeChildrenRecursively: IncludeChildren): void {
Expand All @@ -47,9 +40,7 @@ export default class ForInStatement extends StatementBase {
this.included = true;
left.includeAsAssignmentTarget(context, includeChildrenRecursively || true, false);
right.include(context, includeChildrenRecursively);
const { brokenFlow } = context;
body.include(context, includeChildrenRecursively, { asSingleStatement: true });
context.brokenFlow = brokenFlow;
includeLoopBody(context, body, includeChildrenRecursively);
}

initialise() {
Expand Down
5 changes: 2 additions & 3 deletions src/ast/nodes/ForOfStatement.ts
Expand Up @@ -15,6 +15,7 @@ import {
type StatementNode
} from './shared/Node';
import type { PatternNode } from './shared/Pattern';
import { includeLoopBody } from './shared/loops';

export default class ForOfStatement extends StatementBase {
declare await: boolean;
Expand All @@ -39,9 +40,7 @@ export default class ForOfStatement extends StatementBase {
this.included = true;
left.includeAsAssignmentTarget(context, includeChildrenRecursively || true, false);
right.include(context, includeChildrenRecursively);
const { brokenFlow } = context;
body.include(context, includeChildrenRecursively, { asSingleStatement: true });
context.brokenFlow = brokenFlow;
includeLoopBody(context, body, includeChildrenRecursively);
}

initialise() {
Expand Down

0 comments on commit 76fcbbc

Please sign in to comment.