Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/rollup/rollup into sync-9…
Browse files Browse the repository at this point in the history
…58d5eba
  • Loading branch information
docschina-bot committed Jan 6, 2025
2 parents d313775 + 958d5eb commit e544146
Show file tree
Hide file tree
Showing 19 changed files with 255 additions and 69 deletions.
50 changes: 38 additions & 12 deletions .github/workflows/build-and-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,14 @@ jobs:
id: cache-node-modules
uses: actions/cache/restore@v4
with:
path: node_modules
path: |
node_modules
~/.npm
key: node-modules-${{ runner.os }}-${{ hashFiles('package-lock.json') }}
restore-keys: node-modules-${{ runner.os }}
- name: Install Node dependencies
if: steps.cache-node-modules.outputs.cache-hit != 'true'
run: npm ci --ignore-scripts
run: npm install --ignore-scripts
- name: Lint
run: npm run ci:lint
- name: Vulnerabilities
Expand Down Expand Up @@ -243,16 +246,21 @@ jobs:
id: cache-node-modules
uses: actions/cache/restore@v4
with:
path: node_modules
path: |
node_modules
~/.npm
key: node-modules-${{ runner.os }}-${{ hashFiles('package-lock.json') }}
restore-keys: node-modules-${{ runner.os }}
- name: Install Node dependencies
if: steps.cache-node-modules.outputs.cache-hit != 'true'
run: npm ci --ignore-scripts
run: npm ${{ github.ref == 'refs/heads/master' && 'ci' || 'install' }} --ignore-scripts
- name: Save Node dependencies cache
if: steps.cache-node-modules.outputs.cache-hit != 'true' && github.ref == 'refs/heads/master'
uses: actions/cache/save@v4
with:
path: node_modules
path: |
node_modules
~/.npm
key: node-modules-${{ runner.os }}-${{ hashFiles('package-lock.json') }}
- name: Build in docker
uses: addnab/docker-run-action@v3
Expand Down Expand Up @@ -321,6 +329,15 @@ jobs:
rust/target/
key: ${{ matrix.settings.target }}-cargo-${{ hashFiles('rust/Cargo.lock') }}
restore-keys: ${{ matrix.settings.target }}-cargo
- name: Restore Node dependencies cache
id: cache-node-modules
uses: actions/cache/restore@v4
with:
path: |
node_modules
~/.npm
key: node-modules-${{ runner.os }}-${{ hashFiles('package-lock.json') }}
restore-keys: node-modules-${{ runner.os }}
- name: Build
uses: cross-platform-actions/action@v0.26.0
with:
Expand All @@ -330,7 +347,7 @@ jobs:
memory: 8G
run: |
sudo pkg install -y node npm rust
npm ci --ignore-scripts
${{ steps.cache-node-modules.outputs.cache-hit != 'true' && 'npm install --ignore-scripts' || 'echo Cache hit' }}
npm run build:napi -- --release --target ${{ matrix.settings.target }}
- name: Save Cargo cache
if: github.ref == 'refs/heads/master'
Expand Down Expand Up @@ -395,11 +412,14 @@ jobs:
id: cache-node-modules
uses: actions/cache/restore@v4
with:
path: node_modules
path: |
node_modules
~/.npm
key: node-modules-${{ runner.os }}-${{ hashFiles('package-lock.json') }}
restore-keys: node-modules-${{ runner.os }}
- name: Install Node dependencies
if: steps.cache-node-modules.outputs.cache-hit != 'true'
run: npm ci --ignore-scripts
run: npm install --ignore-scripts
- name: Build JS
run: npm run build:cjs
- name: Download napi artifacts
Expand Down Expand Up @@ -490,11 +510,14 @@ jobs:
id: cache-node-modules
uses: actions/cache/restore@v4
with:
path: node_modules
path: |
node_modules
~/.npm
key: node-modules-${{ runner.os }}-${{ hashFiles('package-lock.json') }}
restore-keys: node-modules-${{ runner.os }}
- name: Install Node dependencies
if: steps.cache-node-modules.outputs.cache-hit != 'true'
run: npm ci --ignore-scripts
run: npm install --ignore-scripts
- name: Download napi artifacts
uses: actions/download-artifact@v4
with:
Expand Down Expand Up @@ -545,11 +568,14 @@ jobs:
id: cache-node-modules
uses: actions/cache/restore@v4
with:
path: node_modules
path: |
node_modules
~/.npm
key: node-modules-${{ runner.os }}-${{ hashFiles('package-lock.json') }}
restore-keys: node-modules-${{ runner.os }}
- name: Install Node dependencies
if: steps.cache-node-modules.outputs.cache-hit != 'true'
run: npm ci --ignore-scripts
run: npm install --ignore-scripts
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
Expand Down
10 changes: 7 additions & 3 deletions .github/workflows/performance-report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,13 @@ jobs:
id: cache-node-modules
uses: actions/cache/restore@v4
with:
path: node_modules
path: |
node_modules
~/.npm
key: node-modules-${{ runner.os }}-${{ hashFiles('package-lock.json') }}
- name: Install Node dependencies
if: steps.cache-node-modules.outputs.cache-hit != 'true'
run: npm ci --ignore-scripts
run: npm install --ignore-scripts
- name: Build artefacts 123
run: npm exec -- concurrently -c green,blue 'npm:build:napi -- --release' 'npm:build:cjs' && npm run build:copy-native && npm run build:bootstrap:cjs && npm run build:copy-native
- name: Upload artifact
Expand Down Expand Up @@ -105,7 +107,9 @@ jobs:
id: cache-node-modules
uses: actions/cache/restore@v4
with:
path: node_modules
path: |
node_modules
~/.npm
key: node-modules-${{ runner.os }}-${{ hashFiles('package-lock.json') }}
- name: Install dependencies
if: steps.cache-node-modules.outputs.cache-hit != 'true'
Expand Down
9 changes: 6 additions & 3 deletions .github/workflows/repl-artefacts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,14 @@ jobs:
id: cache-node-modules
uses: actions/cache/restore@v4
with:
path: node_modules
path: |
node_modules
~/.npm
key: node-modules-${{ runner.os }}-${{ hashFiles('package-lock.json') }}
- name: Install dependencies
restore-keys: node-modules-${{ runner.os }}
- name: Install Node dependencies
if: steps.cache-node-modules.outputs.cache-hit != 'true'
run: npm ci --ignore-scripts
run: npm install --ignore-scripts
- name: Build artefacts
run: npm exec -- concurrently -c green,blue,yellow 'npm:build:napi -- --release' 'npm run build:wasm' 'npm:build:cjs' && npm run build:copy-native && npm run build:bootstrap
- name: Upload "${{ github.event.number }}/rollup.browser.js" to bucket
Expand Down
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
# rollup changelog

## 4.30.0

_2025-01-06_

### Features

- Inline values of resolvable unary expressions for improved tree-shaking (#5775)

### Pull Requests

- [#5775](https://github.com/rollup/rollup/pull/5775): feat: enhance the treehshaking for unary expression (@TrickyPi)
- [#5783](https://github.com/rollup/rollup/pull/5783): Improve CI caching for node_modules (@lukastaegert)

## 4.29.2

_2025-01-05_
Expand Down
2 changes: 1 addition & 1 deletion browser/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rollup/browser",
"version": "4.29.2",
"version": "4.30.0",
"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
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rollup",
"version": "4.29.2",
"version": "4.30.0",
"description": "Next-generation ES module bundler",
"main": "dist/rollup.js",
"module": "dist/es/rollup.js",
Expand Down
78 changes: 76 additions & 2 deletions src/ast/nodes/UnaryExpression.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
import type MagicString from 'magic-string';
import type { RenderOptions } from '../../utils/renderHelpers';
import type { DeoptimizableEntity } from '../DeoptimizableEntity';
import type { HasEffectsContext } from '../ExecutionContext';
import type { HasEffectsContext, InclusionContext } from '../ExecutionContext';
import type { NodeInteraction } from '../NodeInteractions';
import { INTERACTION_ACCESSED, NODE_INTERACTION_UNKNOWN_ASSIGNMENT } from '../NodeInteractions';
import { EMPTY_PATH, type ObjectPath, type PathTracker } from '../utils/PathTracker';
import {
EMPTY_PATH,
type ObjectPath,
type PathTracker,
SHARED_RECURSION_TRACKER
} from '../utils/PathTracker';
import Identifier from './Identifier';
import type { LiteralValue } from './Literal';
import type * as NodeType from './NodeType';
import { Flag, isFlagSet, setFlag } from './shared/BitFlags';
import type { InclusionOptions } from './shared/Expression';
import { type LiteralValueOrUnknown, UnknownValue } from './shared/Expression';
import type { IncludeChildren } from './shared/Node';
import { type ExpressionNode, NodeBase } from './shared/Node';

const unaryOperators: Record<string, (value: LiteralValue) => LiteralValueOrUnknown> = {
Expand All @@ -20,10 +29,13 @@ const unaryOperators: Record<string, (value: LiteralValue) => LiteralValueOrUnkn
'~': value => ~(value as NonNullable<LiteralValue>)
};

const UNASSIGNED = Symbol('Unassigned');

export default class UnaryExpression extends NodeBase {
declare argument: ExpressionNode;
declare operator: '!' | '+' | '-' | 'delete' | 'typeof' | 'void' | '~';
declare type: NodeType.tUnaryExpression;
renderedLiteralValue: string | typeof UnknownValue | typeof UNASSIGNED = UNASSIGNED;

get prefix(): boolean {
return isFlagSet(this.flags, Flag.prefix);
Expand All @@ -32,6 +44,10 @@ export default class UnaryExpression extends NodeBase {
this.flags = setFlag(this.flags, Flag.prefix, value);
}

deoptimizeCache(): void {
this.renderedLiteralValue = UnknownValue;
}

getLiteralValueAtPath(
path: ObjectPath,
recursionTracker: PathTracker,
Expand Down Expand Up @@ -69,4 +85,62 @@ export default class UnaryExpression extends NodeBase {
this.scope.context.requestTreeshakingPass();
}
}

getRenderedLiteralValue(includeChildrenRecursively: IncludeChildren) {
if (this.renderedLiteralValue !== UNASSIGNED) return this.renderedLiteralValue;
return (this.renderedLiteralValue = includeChildrenRecursively
? UnknownValue
: getSimplifiedLiterals(
this.getLiteralValueAtPath(EMPTY_PATH, SHARED_RECURSION_TRACKER, this)
));
}

include(
context: InclusionContext,
includeChildrenRecursively: IncludeChildren,
_options?: InclusionOptions
): void {
if (!this.deoptimized) this.applyDeoptimizations();
this.included = true;
if (
typeof this.getRenderedLiteralValue(includeChildrenRecursively) === 'symbol' ||
this.argument.shouldBeIncluded(context)
) {
this.argument.include(context, includeChildrenRecursively);
this.renderedLiteralValue = UnknownValue;
}
}

render(code: MagicString, options: RenderOptions) {
if (typeof this.renderedLiteralValue === 'symbol') {
super.render(code, options);
} else {
code.overwrite(this.start, this.end, this.renderedLiteralValue);
}
}
}

function getSimplifiedLiterals(value: unknown) {
if (value === undefined || typeof value === 'boolean') {
return String(value);
}
if (typeof value === 'string') {
return JSON.stringify(value);
}
if (typeof value === 'number') {
return getSimplifiedNumber(value);
}
return UnknownValue;
}

function getSimplifiedNumber(value: number) {
if (Object.is(-0, value)) {
return '-0';
}
const exp = value.toExponential();
const [base, exponent] = exp.split('e');
const floatLength = base.split('.')[1]?.length || 0;
const finalizedExp = `${base.replace('.', '')}e${parseInt(exponent) - floatLength}`;
const stringifiedValue = String(value).replace('+', '');
return finalizedExp.length < stringifiedValue.length ? finalizedExp : stringifiedValue;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ define(['exports'], (function (exports) { 'use strict';

console.log('This is the output when a missing export is reexported');

var _missingExportShim$1 = void 0;
var _missingExportShim$1 = undefined;

console.log(_missingExportShim$1);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ var _missingExportShim = void 0;

console.log('This is the output when a missing export is reexported');

var _missingExportShim$1 = void 0;
var _missingExportShim$1 = undefined;

console.log(_missingExportShim$1);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ var _missingExportShim = void 0;

console.log('This is the output when a missing export is reexported');

var _missingExportShim$1 = void 0;
var _missingExportShim$1 = undefined;

console.log(_missingExportShim$1);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ System.register([], (function (exports) {

console.log('This is the output when a missing export is reexported');

var _missingExportShim$1 = exports("previousShimmedExport", void 0);
var _missingExportShim$1 = exports("previousShimmedExport", undefined);

console.log(_missingExportShim$1);

Expand Down
4 changes: 2 additions & 2 deletions test/form/samples/supports-core-js/_expected.js
Original file line number Diff line number Diff line change
Expand Up @@ -9133,7 +9133,7 @@ function requireEs_number_minSafeInteger () {
// `Number.MIN_SAFE_INTEGER` constant
// https://tc39.es/ecma262/#sec-number.min_safe_integer
$({ target: 'Number', stat: true, nonConfigurable: true, nonWritable: true }, {
MIN_SAFE_INTEGER: -0x1FFFFFFFFFFFFF
MIN_SAFE_INTEGER: -9007199254740991
});
return es_number_minSafeInteger;
}
Expand Down Expand Up @@ -9265,7 +9265,7 @@ function requireEs_number_toExponential () {
var stringSlice = uncurryThis(''.slice);

// Edge 17-
var ROUNDS_PROPERLY = nativeToExponential(-6.9e-11, 4) === '-6.9000e-11'
var ROUNDS_PROPERLY = nativeToExponential(-69e-12, 4) === '-6.9000e-11'
// IE11- && Edge 14-
&& nativeToExponential(1.255, 2) === '1.25e+0'
// FF86-, V8 ~ Chrome 49-50
Expand Down
Loading

0 comments on commit e544146

Please sign in to comment.