Skip to content

Commit

Permalink
Merge branch 'master' into class-method-effects
Browse files Browse the repository at this point in the history
  • Loading branch information
lukastaegert committed May 15, 2021
2 parents ece8f31 + 07b3a02 commit 275946e
Show file tree
Hide file tree
Showing 28 changed files with 217 additions and 29 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ jobs:
runs-on: windows-2019
strategy:
matrix:
node: ['14', '12', '10']
node: ['10', '12', '14', '16']
name: Node ${{ matrix.node }} (Windows)
steps:
- name: Configure git line-breaks
Expand Down
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
# rollup changelog

## 2.48.0
*2021-05-15*

### Features
* Add replacement to conditionally insert asset extensions in `entryFileNames` when preserving modules (#4077)

### Bug Fixes
* Fix crash when dynamically assigning to namespace members (#4070)
* Do not associate pure annotations in front of a semi-colon or comma with succeeding code (#4068)

### Pull Requests
* [#4068](https://github.com/rollup/rollup/pull/4068): ignore invalid trailing pure annotations (@kzc)
* [#4070](https://github.com/rollup/rollup/pull/4070): undefined `deoptimizePath` when the first element is empty string (@si3nloong)
* [#4071](https://github.com/rollup/rollup/pull/4071): add node.js v16 support (@dnalborczyk)
* [#4077](https://github.com/rollup/rollup/pull/4077): Add assetExtname replacement in entryFileNames (@BPScott)
* [#4080](https://github.com/rollup/rollup/pull/4080): Added Rollup logo in README.md (@priyanshurav)
* [#4081](https://github.com/rollup/rollup/pull/4081): fix comment regarding invalid annotation handling (@kzc)

## 2.47.0
*2021-05-04*

Expand Down
19 changes: 9 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# Rollup
<p align="center">
<a href="https://rollupjs.org/"><img src="https://rollupjs.org/logo.svg" width="150" /></a>
</p>

<p align="center">
<a href="https://www.npmjs.com/package/rollup">
Expand Down Expand Up @@ -27,6 +29,7 @@
</a>
</p>

<h1 align="center">Rollup</h1>

## Overview

Expand Down Expand Up @@ -65,20 +68,20 @@ rollup main.js --format umd --name "myBundle" --file bundle.js

Developing software is usually easier if you break your project into smaller separate pieces, since that often removes unexpected interactions and dramatically reduces the complexity of the problems you'll need to solve, and simply writing smaller projects in the first place [isn't necessarily the answer](https://medium.com/@Rich_Harris/small-modules-it-s-not-quite-that-simple-3ca532d65de4). Unfortunately, JavaScript has not historically included this capability as a core feature in the language.

This finally changed with ES modules support in JavaScript, which provides a syntax for importing and exporting functions and data so they can be shared between separate scripts. Most browsers and Node.js support ES modules. However, Node.js releases before 12.17 support ES modules only behind the `--experimental-modules` flag, and older browsers like Internet Explorer do not support ES modules at all. Rollup allows you to write your code using ES modules, and run your application even in environments that do not support ES modules natively. For environments that support them, Rollup can output optimized ES modules; for environments that don't, Rollup can compile your code to other formats such as CommonJS modules, AMD modules, and IIFE-style scripts. This means that you get to *write future-proof code*, and you also get the tremendous benefits of...
This finally changed with ES modules support in JavaScript, which provides a syntax for importing and exporting functions and data so they can be shared between separate scripts. Most browsers and Node.js support ES modules. However, Node.js releases before 12.17 support ES modules only behind the `--experimental-modules` flag, and older browsers like Internet Explorer do not support ES modules at all. Rollup allows you to write your code using ES modules, and run your application even in environments that do not support ES modules natively. For environments that support them, Rollup can output optimized ES modules; for environments that don't, Rollup can compile your code to other formats such as CommonJS modules, AMD modules, and IIFE-style scripts. This means that you get to _write future-proof code_, and you also get the tremendous benefits of...

## Tree Shaking

In addition to enabling the use of ES modules, Rollup also statically analyzes and optimizes the code you are importing, and will exclude anything that isn't actually used. This allows you to build on top of existing tools and modules without adding extra dependencies or bloating the size of your project.

For example, with CommonJS, the *entire tool or library must be imported*.
For example, with CommonJS, the _entire tool or library must be imported_.

```js
// import the entire utils object with CommonJS
var utils = require( 'utils' );
var utils = require('utils');
var query = 'Rollup';
// use the ajax method of the utils object
utils.ajax( 'https://api.example.com?search=' + query ).then( handleResponse );
utils.ajax('https://api.example.com?search=' + query).then(handleResponse);
```

But with ES modules, instead of importing the whole `utils` object, we can just import the one `ajax` function we need:
Expand All @@ -88,7 +91,7 @@ But with ES modules, instead of importing the whole `utils` object, we can just
import { ajax } from 'utils';
var query = 'Rollup';
// call the ajax function
ajax( 'https://api.example.com?search=' + query ).then( handleResponse );
ajax('https://api.example.com?search=' + query).then(handleResponse);
```

Because Rollup includes the bare minimum, it results in lighter, faster, and less complicated libraries and applications. Since this approach is based on explicit `import` and `export` statements, it is vastly more effective than simply running an automated minifier to detect unused variables in the compiled output code.
Expand All @@ -108,14 +111,12 @@ To make sure your ES modules are immediately usable by tools that work with Comm
This project exists thanks to all the people who contribute. [[Contribute](CONTRIBUTING.md)].
<a href="https://github.com/rollup/rollup/graphs/contributors"><img src="https://opencollective.com/rollup/contributors.svg?width=890" /></a>


## Backers

Thank you to all our backers! 🙏 [[Become a backer](https://opencollective.com/rollup#backer)]

<a href="https://opencollective.com/rollup#backers" target="_blank"><img src="https://opencollective.com/rollup/backers.svg?width=890"></a>


## Sponsors

Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [[Become a sponsor](https://opencollective.com/rollup#sponsor)]
Expand All @@ -131,8 +132,6 @@ Support this project by becoming a sponsor. Your logo will show up here with a l
<a href="https://opencollective.com/rollup/sponsor/8/website" target="_blank"><img src="https://opencollective.com/rollup/sponsor/8/avatar.svg"></a>
<a href="https://opencollective.com/rollup/sponsor/9/website" target="_blank"><img src="https://opencollective.com/rollup/sponsor/9/avatar.svg"></a>



## License

[MIT](https://github.com/rollup/rollup/blob/master/LICENSE.md)
1 change: 1 addition & 0 deletions docs/999-big-list-of-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,7 @@ This pattern will also be used when setting the [`output.preserveModules`](guide
* `[name]`: The file name (without extension) of the file.
* `[ext]`: The extension of the file.
* `[extname]`: The extension of the file, prefixed by `.` if it is not empty.
* `[assetExtname]`: The extension of the file, prefixed by `.` if it is not empty and it is not one of `js`, `jsx`, `ts` or `tsx`.

#### output.extend
Type: `boolean`<br>
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.47.0",
"version": "2.48.0",
"description": "Next-generation ES module bundler",
"main": "dist/rollup.js",
"module": "dist/es/rollup.js",
Expand Down
5 changes: 2 additions & 3 deletions src/Chunk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -441,15 +441,14 @@ export default class Chunk {
if (isAbsolute(id)) {
const extension = extname(id);
const pattern = unsetOptions.has('entryFileNames')
? NON_ASSET_EXTENSIONS.includes(extension)
? '[name].js'
: '[name][extname].js'
? '[name][assetExtname].js'
: options.entryFileNames;
const currentDir = dirname(sanitizedId);
const fileName = renderNamePattern(
typeof pattern === 'function' ? pattern(this.getChunkInfo()) : pattern,
'output.entryFileNames',
{
assetExtname: () => NON_ASSET_EXTENSIONS.includes(extension) ? '' : extension,
ext: () => extension.substr(1),
extname: () => extension,
format: () => options.format as string,
Expand Down
2 changes: 1 addition & 1 deletion src/Graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ export default class Graph {

options.onComment = onCommentOrig;

markPureCallExpressions(comments, ast);
markPureCallExpressions(comments, ast, code);

return ast;
}
Expand Down
6 changes: 3 additions & 3 deletions src/ast/variables/NamespaceVariable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ export default class NamespaceVariable extends Variable {
const memberVariables = this.getMemberVariables();
const memberPath = path.length <= 1 ? UNKNOWN_PATH : path.slice(1);
const key = path[0];
if (typeof key !== 'string') {
if (typeof key === 'string') {
memberVariables[key]?.deoptimizePath(memberPath);
} else {
for (const key of Object.keys(memberVariables)) {
memberVariables[key].deoptimizePath(memberPath);
}
} else {
memberVariables[key].deoptimizePath(memberPath);
}
}

Expand Down
24 changes: 22 additions & 2 deletions src/utils/pureComments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,37 @@ basicWalker.PropertyDefinition = function (node: any, st: any, c: any) {
};

interface CommentState {
code: string;
commentIndex: number;
commentNodes: acorn.Comment[];
}

function isOnlyWhitespaceOrComments(code: string) {
// streamline the typical case
if (/^\s*$/.test(code)) return true;
try {
// successful only if it's a valid Program without statements
const ast = acorn.parse(code, { ecmaVersion: 'latest' }) as any;
return ast.body && ast.body.length === 0;
} catch {
// should only be reached by invalid annotations like:
//
// foo() /*@__PURE__*/ /* other */, bar();
//
// where `code` is " /* other */, "
}
return false;
}

function handlePureAnnotationsOfNode(
node: acorn.Node,
state: CommentState,
type: string = node.type
) {
let commentNode = state.commentNodes[state.commentIndex];
while (commentNode && node.start >= commentNode.end) {
markPureNode(node, commentNode);
const between = state.code.substring(commentNode.end, node.start);
if (isOnlyWhitespaceOrComments(between)) markPureNode(node, commentNode);
commentNode = state.commentNodes[++state.commentIndex];
}
if (commentNode && commentNode.end <= node.end) {
Expand Down Expand Up @@ -62,8 +81,9 @@ function markPureNode(
const pureCommentRegex = /[@#]__PURE__/;
const isPureComment = (comment: acorn.Comment) => pureCommentRegex.test(comment.value);

export function markPureCallExpressions(comments: acorn.Comment[], esTreeAst: acorn.Node) {
export function markPureCallExpressions(comments: acorn.Comment[], esTreeAst: acorn.Node, code: string) {
handlePureAnnotationsOfNode(esTreeAst, {
code,
commentIndex: 0,
commentNodes: comments.filter(isPureComment)
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,25 @@
const path = require('path');

module.exports = {
description: 'entryFileNames pattern supported in combination with preserveModules',
options: {
input: 'src/main.ts',
output: {
entryFileNames: 'entry-[name]-[format]-[ext][extname].js',
entryFileNames: 'entry-[name]-[format]-[ext][extname][assetExtname].js',
preserveModules: true
}
},
plugins: [
{
name: 'str-plugin',
transform(code, id) {
switch (path.extname(id)) {
case '.str':
return { code: `export default "${code.trim()}"` };
default:
return null;
}
}
}
]
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
define(function () { 'use strict';

var lorem = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.";

return lorem;

});
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
define(['exports', './entry-foo-amd-ts.ts', './nested/entry-bar-amd-ts.ts', './nested/entry-baz-amd-ts.ts', './entry-no-ext-amd-'], function (exports, foo, bar, baz, noExt) { 'use strict';
define(['exports', './entry-foo-amd-ts.ts', './nested/entry-bar-amd-ts.ts', './nested/entry-baz-amd-ts.ts', './entry-lorem-amd-str.str.str', './entry-no-ext-amd-'], function (exports, foo, bar, baz, lorem, noExt) { 'use strict';



exports.foo = foo;
exports.bar = bar;
exports.baz = baz;
exports.lorem = lorem;
exports.noExt = noExt;

Object.defineProperty(exports, '__esModule', { value: true });
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'use strict';

var lorem = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.";

module.exports = lorem;
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ Object.defineProperty(exports, '__esModule', { value: true });
var foo = require('./entry-foo-cjs-ts.ts.js');
var bar = require('./nested/entry-bar-cjs-ts.ts.js');
var baz = require('./nested/entry-baz-cjs-ts.ts.js');
var lorem = require('./entry-lorem-cjs-str.str.str.js');
var noExt = require('./entry-no-ext-cjs-.js');



exports.foo = foo;
exports.bar = bar;
exports.baz = baz;
exports.lorem = lorem;
exports.noExt = noExt;

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

Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export { default as foo } from './entry-foo-es-ts.ts.js';
export { default as bar } from './nested/entry-bar-es-ts.ts.js';
export { default as baz } from './nested/entry-baz-es-ts.ts.js';
export { default as lorem } from './entry-lorem-es-str.str.str.js';
export { default as noExt } from './entry-no-ext-es-.js';
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
System.register([], function (exports) {
'use strict';
return {
execute: function () {

var lorem = exports('default', "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.");

}
};
});
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
System.register(['./entry-foo-system-ts.ts.js', './nested/entry-bar-system-ts.ts.js', './nested/entry-baz-system-ts.ts.js', './entry-no-ext-system-.js'], function (exports) {
System.register(['./entry-foo-system-ts.ts.js', './nested/entry-bar-system-ts.ts.js', './nested/entry-baz-system-ts.ts.js', './entry-lorem-system-str.str.str.js', './entry-no-ext-system-.js'], function (exports) {
'use strict';
return {
setters: [function (module) {
Expand All @@ -7,6 +7,8 @@ System.register(['./entry-foo-system-ts.ts.js', './nested/entry-bar-system-ts.ts
exports('bar', module.default);
}, function (module) {
exports('baz', module.default);
}, function (module) {
exports('lorem', module.default);
}, function (module) {
exports('noExt', module.default);
}],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ export { default as bar } from './nested/bar.ts';
// @ts-ignore
export { default as baz } from './nested/baz.ts';
// @ts-ignore
export { default as lorem } from './lorem.str';
// @ts-ignore
export { default as noExt } from './no-ext';
22 changes: 20 additions & 2 deletions test/form/samples/pure-comment-line-break/_expected.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ console.log('should remain impure');
console.log('code');
console.log('should remain impure');

console.log('code');
console.log('code')/*@__PURE__*/;
console.log('should remain impure');
console.log('should remain impure');

Expand All @@ -16,7 +16,7 @@ console.log('should remain impure');
console.log('code'),
console.log('should remain impure');

console.log('code'),
console.log('code')/*@__PURE__*/,
console.log('should remain impure');

console.log('should remain impure');
Expand All @@ -35,3 +35,21 @@ console.log('should remain impure', x);
{
console.log('should remain impure');
}
keep1() /*@__PURE__*/ ; keep2();
keep3() ;
keep4() /*@__PURE__*/ ; /* other comment */ keep5();
keep6() /*@__PURE__*/ ; // other comment
keep7();
keep8() /*@__PURE__*/ && keep9();

/*@__PURE__*/ Drop1(), // FIXME: unrelated issue
Keep1() /*@__PURE__*/ , Keep2(),
Keep3() ,
Keep4() /*@__PURE__*/ , /* other comment */ Keep5(),
Keep6() /*@__PURE__*/ , // other comment
Keep7(),
Keep8() /*@__PURE__*/ && Keep9();

// FIXME: unrelated issue
/*@__PURE__*/ Drop10(),
/*@__PURE__*/ Drop13();

0 comments on commit 275946e

Please sign in to comment.