Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into fix-windows-config-…
Browse files Browse the repository at this point in the history
…path
  • Loading branch information
pos777 committed May 19, 2022
2 parents 916df46 + fc99e96 commit a0f2a49
Show file tree
Hide file tree
Showing 128 changed files with 1,336 additions and 621 deletions.
21 changes: 21 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,26 @@
# rollup changelog

## 2.74.0

_2022-05-19_

### Features

- Remove unneeded default values for function parameters (#4498)

### Bug Fixes

- Use a consistent mechanism to resolve the config file to avoid issues on Windows (#4501)
- Avoid an inaccurate warning about an event emitter leak for complicated builds (#4502)
- Ensure that reexporting values from other chunks via dynamic imports does not reference non-imported variables (#4499)

### Pull Requests

- [#4498](https://github.com/rollup/rollup/pull/4498): Tree shake parameter defaults (@lukastaegert)
- [#4499](https://github.com/rollup/rollup/pull/4499): Ensure reexports are available for namespaces (@lukastaegert)
- [#4501](https://github.com/rollup/rollup/pull/4501): fix: config path problem on windows (@pos777)
- [#4502](https://github.com/rollup/rollup/pull/4502): Avoid maximum listeners exceeded warning (@lukastaegert)

## 2.73.0

_2022-05-13_
Expand Down
2 changes: 1 addition & 1 deletion 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
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rollup",
"version": "2.73.0",
"version": "2.74.0",
"description": "Next-generation ES module bundler",
"main": "dist/rollup.js",
"module": "dist/es/rollup.js",
Expand Down
4 changes: 2 additions & 2 deletions rollup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import commonjs from '@rollup/plugin-commonjs';
import json from '@rollup/plugin-json';
import { nodeResolve } from '@rollup/plugin-node-resolve';
import typescript from '@rollup/plugin-typescript';
import type { RollupOptions, WarningHandlerWithDefault } from 'rollup';
import type { Plugin, RollupOptions, WarningHandlerWithDefault } from 'rollup';
import { string } from 'rollup-plugin-string';
import { terser } from 'rollup-plugin-terser';
import addCliEntry from './build-plugins/add-cli-entry';
Expand Down Expand Up @@ -65,7 +65,7 @@ const treeshake = {
tryCatchDeoptimization: false
};

const nodePlugins = [
const nodePlugins: Plugin[] = [
alias(moduleAliases),
nodeResolve(),
json(),
Expand Down
22 changes: 21 additions & 1 deletion src/Chunk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ export default class Chunk {
private implicitEntryModules: Module[] = [];
private readonly implicitlyLoadedBefore = new Set<Chunk>();
private readonly imports = new Set<Variable>();
private readonly includedReexportsByModule = new Map<Module, Variable[]>();
private indentString: string = undefined as never;
// This may only be updated in the constructor
private readonly isEmpty: boolean = true;
Expand All @@ -164,6 +165,7 @@ export default class Chunk {
private sortedExportNames: string[] | null = null;
private strictFacade = false;
private usedModules: Module[] = undefined as never;

constructor(
private readonly orderedModules: readonly Module[],
private readonly inputOptions: NormalizedInputOptions,
Expand Down Expand Up @@ -399,6 +401,9 @@ export default class Chunk {
this.exports.add(module.namespace);
}
}
if (!this.outputOptions.preserveModules) {
this.addNecessaryImportsForFacades();
}
return facades;
}

Expand Down Expand Up @@ -832,6 +837,16 @@ export default class Chunk {
}
}

private addNecessaryImportsForFacades() {
for (const [module, variables] of this.includedReexportsByModule) {
if (this.includedNamespaces.has(module)) {
for (const variable of variables) {
this.imports.add(variable);
}
}
}
}

private assignFacadeName({ fileName, name }: FacadeName, facadedModule: Module): void {
if (fileName) {
this.fileName = fileName;
Expand Down Expand Up @@ -892,6 +907,7 @@ export default class Chunk {
}

private ensureReexportsAreAvailableForModule(module: Module): void {
const includedReexports: Variable[] = [];
const map = module.getExportNamesByVariable();
for (const exportedVariable of map.keys()) {
const isSynthetic = exportedVariable instanceof SyntheticNamedExportVariable;
Expand All @@ -905,13 +921,17 @@ export default class Chunk {
const chunk = this.chunkByModule.get(exportingModule);
if (chunk && chunk !== this) {
chunk.exports.add(importedVariable);
includedReexports.push(importedVariable);
if (isSynthetic) {
this.imports.add(importedVariable);
}
}
}
}
}
if (includedReexports.length) {
this.includedReexportsByModule.set(module, includedReexports);
}
}

private finaliseDynamicImports(
Expand Down Expand Up @@ -1345,7 +1365,7 @@ export default class Chunk {
}

private setUpChunkImportsAndExportsForModule(module: Module): void {
const moduleImports = new Set(module.imports);
const moduleImports = new Set(module.includedImports);
// when we are not preserving modules, we need to make all namespace variables available for
// rendering the namespace object
if (!this.outputOptions.preserveModules) {
Expand Down
10 changes: 5 additions & 5 deletions src/Module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,8 @@ export default class Module {
readonly importMetas: MetaProperty[] = [];
importedFromNotTreeshaken = false;
readonly importers: string[] = [];
readonly imports = new Set<Variable>();
readonly includedDynamicImporters: Module[] = [];
readonly includedImports = new Set<Variable>();
readonly info: ModuleInfo;
isExecuted = false;
isUserDefinedEntryPoint = false;
Expand Down Expand Up @@ -383,7 +383,7 @@ export default class Module {
this.relevantDependencies = new Set<Module | ExternalModule>();
const necessaryDependencies = new Set<Module | ExternalModule>();
const alwaysCheckedDependencies = new Set<Module>();
const dependencyVariables = new Set(this.imports);
const dependencyVariables = new Set(this.includedImports);

if (
this.info.isEntry ||
Expand Down Expand Up @@ -1134,12 +1134,12 @@ export default class Module {
if (module instanceof ExternalModule) {
const [externalVariable] = module.getVariableForExportName('*');
externalVariable.include();
this.imports.add(externalVariable);
this.includedImports.add(externalVariable);
externalNamespaces.add(externalVariable);
} else if (module.info.syntheticNamedExports) {
const syntheticNamespace = module.getSyntheticNamespace();
syntheticNamespace.include();
this.imports.add(syntheticNamespace);
this.includedImports.add(syntheticNamespace);
syntheticNamespaces.add(syntheticNamespace);
}
}
Expand Down Expand Up @@ -1183,7 +1183,7 @@ export default class Module {
this.includeVariable(variable);
const variableModule = variable.module;
if (variableModule && variableModule !== this) {
this.imports.add(variable);
this.includedImports.add(variable);
}
}

Expand Down
36 changes: 33 additions & 3 deletions src/ast/nodes/ArrayExpression.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
import type { CallOptions } from '../CallOptions';
import type { DeoptimizableEntity } from '../DeoptimizableEntity';
import type { HasEffectsContext } from '../ExecutionContext';
import { InclusionContext } from '../ExecutionContext';
import type { NodeEvent } from '../NodeEvents';
import { type ObjectPath, type PathTracker, UnknownInteger } from '../utils/PathTracker';
import {
type ObjectPath,
type PathTracker,
UNKNOWN_PATH,
UnknownInteger
} from '../utils/PathTracker';
import { UNDEFINED_EXPRESSION, UNKNOWN_LITERAL_NUMBER } from '../values';
import type * as NodeType from './NodeType';
import SpreadElement from './SpreadElement';
Expand All @@ -14,6 +20,7 @@ import { ObjectEntity, type ObjectProperty } from './shared/ObjectEntity';
export default class ArrayExpression extends NodeBase {
declare elements: readonly (ExpressionNode | SpreadElement | null)[];
declare type: NodeType.tArrayExpression;
protected deoptimized = false;
private objectEntity: ObjectEntity | null = null;

deoptimizePath(path: ObjectPath): void {
Expand Down Expand Up @@ -56,7 +63,7 @@ export default class ArrayExpression extends NodeBase {
);
}

hasEffectsWhenAccessedAtPath(path: ObjectPath, context: HasEffectsContext): boolean {
hasEffectsWhenAccessedAtPath(path: ObjectPath, context: HasEffectsContext): boolean | undefined {
return this.getObjectEntity().hasEffectsWhenAccessedAtPath(path, context);
}

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

includeArgumentsWhenCalledAtPath(
path: ObjectPath,
context: InclusionContext,
args: readonly (ExpressionEntity | SpreadElement)[]
) {
this.getObjectEntity().includeArgumentsWhenCalledAtPath(path, context, args);
}

protected applyDeoptimizations(): void {
this.deoptimized = true;
let hasSpread = false;
for (let index = 0; index < this.elements.length; index++) {
const element = this.elements[index];
if (hasSpread || element instanceof SpreadElement) {
if (element) {
hasSpread = true;
element.deoptimizePath(UNKNOWN_PATH);
}
}
}
this.context.requestTreeshakingPass();
}

private getObjectEntity(): ObjectEntity {
if (this.objectEntity !== null) {
return this.objectEntity;
Expand All @@ -82,7 +112,7 @@ export default class ArrayExpression extends NodeBase {
let hasSpread = false;
for (let index = 0; index < this.elements.length; index++) {
const element = this.elements[index];
if (element instanceof SpreadElement || hasSpread) {
if (hasSpread || element instanceof SpreadElement) {
if (element) {
hasSpread = true;
properties.unshift({ key: UnknownInteger, kind: 'init', property: element });
Expand Down
26 changes: 9 additions & 17 deletions src/ast/nodes/ArrayPattern.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ export default class ArrayPattern extends NodeBase implements PatternNode {
exportNamesByVariable: ReadonlyMap<Variable, readonly string[]>
): void {
for (const element of this.elements) {
if (element !== null) {
element.addExportedVariables(variables, exportNamesByVariable);
}
element?.addExportedVariables(variables, exportNamesByVariable);
}
}

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

deoptimizePath(path: ObjectPath): void {
if (path.length === 0) {
for (const element of this.elements) {
if (element !== null) {
element.deoptimizePath(path);
}
}
// Patterns can only be deoptimized at the empty path at the moment
deoptimizePath(): void {
for (const element of this.elements) {
element?.deoptimizePath(EMPTY_PATH);
}
}

hasEffectsWhenAssignedAtPath(path: ObjectPath, context: HasEffectsContext): boolean {
if (path.length > 0) return true;
// Patterns are only checked at the emtpy path at the moment
hasEffectsWhenAssignedAtPath(_path: ObjectPath, context: HasEffectsContext): boolean {
for (const element of this.elements) {
if (element !== null && element.hasEffectsWhenAssignedAtPath(EMPTY_PATH, context))
return true;
if (element?.hasEffectsWhenAssignedAtPath(EMPTY_PATH, context)) return true;
}
return false;
}

markDeclarationReached(): void {
for (const element of this.elements) {
if (element !== null) {
element.markDeclarationReached();
}
element?.markDeclarationReached();
}
}
}
14 changes: 2 additions & 12 deletions src/ast/nodes/ArrowFunctionExpression.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import { type CallOptions } from '../CallOptions';
import { type HasEffectsContext, InclusionContext } from '../ExecutionContext';
import { type HasEffectsContext } from '../ExecutionContext';
import ReturnValueScope from '../scopes/ReturnValueScope';
import type Scope from '../scopes/Scope';
import { type ObjectPath } from '../utils/PathTracker';
import BlockStatement from './BlockStatement';
import Identifier from './Identifier';
import * as NodeType from './NodeType';
import FunctionBase from './shared/FunctionBase';
import { type ExpressionNode, IncludeChildren } from './shared/Node';
import { type ExpressionNode } from './shared/Node';
import { ObjectEntity } from './shared/ObjectEntity';
import { OBJECT_PROTOTYPE } from './shared/ObjectPrototype';
import type { PatternNode } from './shared/Pattern';
Expand Down Expand Up @@ -48,15 +47,6 @@ export default class ArrowFunctionExpression extends FunctionBase {
return false;
}

include(context: InclusionContext, includeChildrenRecursively: IncludeChildren): void {
super.include(context, includeChildrenRecursively);
for (const param of this.params) {
if (!(param instanceof Identifier)) {
param.include(context, includeChildrenRecursively);
}
}
}

protected getObjectEntity(): ObjectEntity {
if (this.objectEntity !== null) {
return this.objectEntity;
Expand Down
2 changes: 1 addition & 1 deletion src/ast/nodes/AssignmentExpression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export default class AssignmentExpression extends NodeBase {
);
}

hasEffectsWhenAccessedAtPath(path: ObjectPath, context: HasEffectsContext): boolean {
hasEffectsWhenAccessedAtPath(path: ObjectPath, context: HasEffectsContext): boolean | undefined {
return path.length > 0 && this.right.hasEffectsWhenAccessedAtPath(path, context);
}

Expand Down
15 changes: 13 additions & 2 deletions src/ast/nodes/AssignmentPattern.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ import type MagicString from 'magic-string';
import { BLANK } from '../../utils/blank';
import type { NodeRenderOptions, RenderOptions } from '../../utils/renderHelpers';
import type { HasEffectsContext } from '../ExecutionContext';
import { InclusionContext } from '../ExecutionContext';
import { EMPTY_PATH, type ObjectPath, UNKNOWN_PATH } from '../utils/PathTracker';
import type LocalVariable from '../variables/LocalVariable';
import type Variable from '../variables/Variable';
import type * as NodeType from './NodeType';
import type { ExpressionEntity } from './shared/Expression';
import { type ExpressionNode, NodeBase } from './shared/Node';
import { type ExpressionNode, IncludeChildren, NodeBase } from './shared/Node';
import type { PatternNode } from './shared/Pattern';

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

include(context: InclusionContext, includeChildrenRecursively: IncludeChildren): void {
this.included = true;
this.left.include(context, includeChildrenRecursively);
this.right.include(context, includeChildrenRecursively);
}

markDeclarationReached(): void {
this.left.markDeclarationReached();
}
Expand All @@ -45,7 +52,11 @@ export default class AssignmentPattern extends NodeBase implements PatternNode {
{ isShorthandProperty }: NodeRenderOptions = BLANK
): void {
this.left.render(code, options, { isShorthandProperty });
this.right.render(code, options);
if (this.right.included) {
this.right.render(code, options);
} else {
code.remove(this.left.end, this.end);
}
}

protected applyDeoptimizations(): void {
Expand Down

0 comments on commit a0f2a49

Please sign in to comment.