Skip to content

Commit

Permalink
Merge branch 'master' into feat/treeshake-dynamic-import
Browse files Browse the repository at this point in the history
  • Loading branch information
lukastaegert committed Apr 23, 2023
2 parents 44620db + 5af8799 commit 7a0ab4c
Show file tree
Hide file tree
Showing 11 changed files with 58 additions and 30 deletions.
15 changes: 15 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,20 @@
# rollup changelog

## 3.20.7

_2023-04-21_

### Bug Fixes

- Properly track array element mutations when iterating with a for-of loop (#4949)
- Handle default exporting an anonymous class that extends another class (#4950)

### Pull Requests

- [#4943](https://github.com/rollup/rollup/pull/4943): Add a test for reserved keywords used as import/export specifiers (@Andarist)
- [#4949](https://github.com/rollup/rollup/pull/4949): Deoptimize right side in for-of loops (@lukastaegert)
- [#4950](https://github.com/rollup/rollup/pull/4950): Support default exported classes that extend other classes (@lukastaegert)

## 3.20.6

_2023-04-18_
Expand Down
2 changes: 1 addition & 1 deletion browser/package.json
@@ -1,6 +1,6 @@
{
"name": "@rollup/browser",
"version": "3.20.6",
"version": "3.20.7",
"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.6",
"version": "3.20.7",
"description": "Next-generation ES module bundler",
"main": "dist/rollup.js",
"module": "dist/es/rollup.js",
Expand Down
37 changes: 12 additions & 25 deletions src/ast/nodes/ExportDefaultDeclaration.ts
Expand Up @@ -21,18 +21,10 @@ function getDeclarationStart(code: string, start: number): number {
return findNonWhiteSpace(code, findFirstOccurrenceOutsideComment(code, 'default', start) + 7);
}

function getIdInsertPosition(
code: string,
declarationKeyword: string,
endMarker: string,
start: number
): number {
function getFunctionIdInsertPosition(code: string, start: number): number {
const declarationEnd =
findFirstOccurrenceOutsideComment(code, declarationKeyword, start) + declarationKeyword.length;
code = code.slice(
declarationEnd,
findFirstOccurrenceOutsideComment(code, endMarker, declarationEnd)
);
findFirstOccurrenceOutsideComment(code, 'function', start) + 'function'.length;
code = code.slice(declarationEnd, findFirstOccurrenceOutsideComment(code, '(', declarationEnd));
const generatorStarPos = findFirstOccurrenceOutsideComment(code, '*');
if (generatorStarPos === -1) {
return declarationEnd;
Expand Down Expand Up @@ -76,18 +68,18 @@ export default class ExportDefaultDeclaration extends NodeBase {
this.renderNamedDeclaration(
code,
declarationStart,
'function',
'(',
this.declaration.id === null,
this.declaration.id === null
? getFunctionIdInsertPosition(code.original, declarationStart)
: null,
options
);
} else if (this.declaration instanceof ClassDeclaration) {
this.renderNamedDeclaration(
code,
declarationStart,
'class',
'{',
this.declaration.id === null,
this.declaration.id === null
? findFirstOccurrenceOutsideComment(code.original, 'class', start) + 'class'.length
: null,
options
);
} else if (this.variable.getOriginalVariable() !== this.variable) {
Expand All @@ -114,9 +106,7 @@ export default class ExportDefaultDeclaration extends NodeBase {
private renderNamedDeclaration(
code: MagicString,
declarationStart: number,
declarationKeyword: string,
endMarker: string,
needsId: boolean,
idInsertPosition: number | null,
options: RenderOptions
): void {
const {
Expand All @@ -128,11 +118,8 @@ export default class ExportDefaultDeclaration extends NodeBase {
// Remove `export default`
code.remove(this.start, declarationStart);

if (needsId) {
code.appendLeft(
getIdInsertPosition(code.original, declarationKeyword, endMarker, declarationStart),
` ${name}`
);
if (idInsertPosition !== null) {
code.appendLeft(idInsertPosition, ` ${name}`);
}
if (
format === 'system' &&
Expand Down
3 changes: 2 additions & 1 deletion src/ast/nodes/ForOfStatement.ts
Expand Up @@ -3,7 +3,7 @@ import { NO_SEMICOLON, type RenderOptions } from '../../utils/renderHelpers';
import type { InclusionContext } from '../ExecutionContext';
import BlockScope from '../scopes/BlockScope';
import type Scope from '../scopes/Scope';
import { EMPTY_PATH } from '../utils/PathTracker';
import { EMPTY_PATH, UNKNOWN_PATH } from '../utils/PathTracker';
import type MemberExpression from './MemberExpression';
import type * as NodeType from './NodeType';
import type VariableDeclaration from './VariableDeclaration';
Expand Down Expand Up @@ -60,6 +60,7 @@ export default class ForOfStatement extends StatementBase {
protected applyDeoptimizations(): void {
this.deoptimized = true;
this.left.deoptimizePath(EMPTY_PATH);
this.right.deoptimizePath(UNKNOWN_PATH);
this.context.requestTreeshakingPass();
}
}
@@ -0,0 +1,3 @@
module.exports = {
description: 'handles default exported classes extending a regular expression argument (#4783)'
};
@@ -0,0 +1,7 @@
function foo(val) {
return val;
}

class main extends foo(/1/) {}

export { main as default };
@@ -0,0 +1,5 @@
function foo(val) {
return val;
}

export default class extends foo(/1/) {}
3 changes: 3 additions & 0 deletions test/function/samples/deoptimize-loop-element/_config.js
@@ -0,0 +1,3 @@
module.exports = {
description: 'deoptimizes the loop element when it is reassigned'
};
7 changes: 7 additions & 0 deletions test/function/samples/deoptimize-loop-element/main.js
@@ -0,0 +1,7 @@
const foo = [{ value: 1 }];

for (const item of foo) {
item.value = 0;
}

assert.ok(foo[0].value === 0 ? true : false);

0 comments on commit 7a0ab4c

Please sign in to comment.