From e2d9b6bb059a881068b574b2af407ee40ff999cf Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Fri, 13 Jan 2017 14:28:46 -0500 Subject: [PATCH 1/6] -> v0.41.2 --- CHANGELOG.md | 4 ++++ package.json | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cbb5e23..98fbb40 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # rollup changelog +## 0.41.2 + +* Optimize `namespace['foo']` references ([#1240](https://github.com/rollup/rollup/pull/1240)) + ## 0.41.1 * Include `new` expressions where callee is a class with side-effects ([#980](https://github.com/rollup/rollup/issues/980) [#1233](https://github.com/rollup/rollup/issues/1233)) diff --git a/package.json b/package.json index de06261..de461e9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "rollup", - "version": "0.41.1", + "version": "0.41.2", "description": "Next-generation ES6 module bundler", "main": "dist/rollup.js", "module": "dist/rollup.es.js", From 3a8b1c146069c2c489f3dd8efa883ef128505a9f Mon Sep 17 00:00:00 2001 From: Rich-Harris Date: Fri, 13 Jan 2017 19:49:32 -0500 Subject: [PATCH 2/6] dont treat this.foo as possible namespace - fixes #1258 --- src/ast/nodes/MemberExpression.js | 2 +- test/function/this-not-namespace/_config.js | 8 ++++++++ test/function/this-not-namespace/main.js | 5 +++++ 3 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 test/function/this-not-namespace/_config.js create mode 100644 test/function/this-not-namespace/main.js diff --git a/src/ast/nodes/MemberExpression.js b/src/ast/nodes/MemberExpression.js index 9b2313d..5f499ac 100644 --- a/src/ast/nodes/MemberExpression.js +++ b/src/ast/nodes/MemberExpression.js @@ -33,7 +33,7 @@ export default class MemberExpression extends Node { // TODO this code is a bit inefficient const keypath = new Keypath( this ); - if ( !keypath.computed ) { + if ( !keypath.computed && keypath.root.type === 'Identifier' ) { let declaration = scope.findDeclaration( keypath.root.name ); while ( declaration.isNamespace && keypath.parts.length ) { diff --git a/test/function/this-not-namespace/_config.js b/test/function/this-not-namespace/_config.js new file mode 100644 index 0000000..ee9b9f7 --- /dev/null +++ b/test/function/this-not-namespace/_config.js @@ -0,0 +1,8 @@ +const assert = require( 'assert' ); + +module.exports = { + description: 'does not treat this.foo as a possible namespace (#1258)', + exports: exports => { + assert.equal( typeof exports.Foo, 'function' ); + } +}; diff --git a/test/function/this-not-namespace/main.js b/test/function/this-not-namespace/main.js new file mode 100644 index 0000000..f2fdc1f --- /dev/null +++ b/test/function/this-not-namespace/main.js @@ -0,0 +1,5 @@ +export class Foo { + constructor ( name ) { + this.name = undefined; + } +} From 4bbf9fd27227b8c1124dda2b8c5fec4455b34e5a Mon Sep 17 00:00:00 2001 From: Rich-Harris Date: Fri, 13 Jan 2017 19:56:25 -0500 Subject: [PATCH 3/6] -> v0.41.3 --- CHANGELOG.md | 4 ++++ package.json | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 98fbb40..b98ca4a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # rollup changelog +## 0.41.3 + +* Don't treat `this.foo` as possible namespace ([#1258](https://github.com/rollup/rollup/issues/1258)) + ## 0.41.2 * Optimize `namespace['foo']` references ([#1240](https://github.com/rollup/rollup/pull/1240)) diff --git a/package.json b/package.json index de461e9..f9780c8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "rollup", - "version": "0.41.2", + "version": "0.41.3", "description": "Next-generation ES6 module bundler", "main": "dist/rollup.js", "module": "dist/rollup.es.js", From 457be9c96142e589004f4eff73ec5130e3726db0 Mon Sep 17 00:00:00 2001 From: Rich-Harris Date: Sat, 14 Jan 2017 12:54:12 -0500 Subject: [PATCH 4/6] handle multiple export * from external declarations (#1252) --- src/Module.js | 6 ++++++ test/form/export-all-multiple/_config.js | 8 ++++++++ test/form/export-all-multiple/_expected/amd.js | 11 +++++++++++ test/form/export-all-multiple/_expected/cjs.js | 13 +++++++++++++ test/form/export-all-multiple/_expected/es.js | 3 +++ test/form/export-all-multiple/_expected/iife.js | 10 ++++++++++ test/form/export-all-multiple/_expected/umd.js | 13 +++++++++++++ test/form/export-all-multiple/main.js | 3 +++ 8 files changed, 67 insertions(+) create mode 100644 test/form/export-all-multiple/_config.js create mode 100644 test/form/export-all-multiple/_expected/amd.js create mode 100644 test/form/export-all-multiple/_expected/cjs.js create mode 100644 test/form/export-all-multiple/_expected/es.js create mode 100644 test/form/export-all-multiple/_expected/iife.js create mode 100644 test/form/export-all-multiple/_expected/umd.js create mode 100644 test/form/export-all-multiple/main.js diff --git a/src/Module.js b/src/Module.js index 746a96d..41e444c 100644 --- a/src/Module.js +++ b/src/Module.js @@ -410,6 +410,12 @@ export default class Module { } traceExport ( name ) { + // export * from 'external' + if ( name[0] === '*' ) { + const module = this.bundle.moduleById.get( name.slice( 1 ) ); + return module.traceExport( '*' ); + } + // export { foo } from './other.js' const reexportDeclaration = this.reexports[ name ]; if ( reexportDeclaration ) { diff --git a/test/form/export-all-multiple/_config.js b/test/form/export-all-multiple/_config.js new file mode 100644 index 0000000..4199beb --- /dev/null +++ b/test/form/export-all-multiple/_config.js @@ -0,0 +1,8 @@ +module.exports = { + description: 'correctly handles multiple export * declarations (#1252)', + options: { + external: [ 'foo', 'bar', 'baz' ], + globals: { foo: 'foo', bar: 'bar', baz: 'baz' }, + moduleName: 'myBundle' + } +}; diff --git a/test/form/export-all-multiple/_expected/amd.js b/test/form/export-all-multiple/_expected/amd.js new file mode 100644 index 0000000..37ed509 --- /dev/null +++ b/test/form/export-all-multiple/_expected/amd.js @@ -0,0 +1,11 @@ +define(['exports', 'foo', 'bar', 'baz'], function (exports, foo, bar, baz) { 'use strict'; + + + + Object.keys(foo).forEach(function (key) { exports[key] = foo[key]; }); + Object.keys(bar).forEach(function (key) { exports[key] = bar[key]; }); + Object.keys(baz).forEach(function (key) { exports[key] = baz[key]; }); + + Object.defineProperty(exports, '__esModule', { value: true }); + +}); diff --git a/test/form/export-all-multiple/_expected/cjs.js b/test/form/export-all-multiple/_expected/cjs.js new file mode 100644 index 0000000..e3af62c --- /dev/null +++ b/test/form/export-all-multiple/_expected/cjs.js @@ -0,0 +1,13 @@ +'use strict'; + +Object.defineProperty(exports, '__esModule', { value: true }); + +var foo = require('foo'); +var bar = require('bar'); +var baz = require('baz'); + + + +Object.keys(foo).forEach(function (key) { exports[key] = foo[key]; }); +Object.keys(bar).forEach(function (key) { exports[key] = bar[key]; }); +Object.keys(baz).forEach(function (key) { exports[key] = baz[key]; }); diff --git a/test/form/export-all-multiple/_expected/es.js b/test/form/export-all-multiple/_expected/es.js new file mode 100644 index 0000000..03c82c7 --- /dev/null +++ b/test/form/export-all-multiple/_expected/es.js @@ -0,0 +1,3 @@ +export * from 'foo'; +export * from 'bar'; +export * from 'baz'; diff --git a/test/form/export-all-multiple/_expected/iife.js b/test/form/export-all-multiple/_expected/iife.js new file mode 100644 index 0000000..85551a5 --- /dev/null +++ b/test/form/export-all-multiple/_expected/iife.js @@ -0,0 +1,10 @@ +(function (exports,foo,bar,baz) { + 'use strict'; + + + + Object.keys(foo).forEach(function (key) { exports[key] = foo[key]; }); + Object.keys(bar).forEach(function (key) { exports[key] = bar[key]; }); + Object.keys(baz).forEach(function (key) { exports[key] = baz[key]; }); + +}((this.myBundle = this.myBundle || {}),foo,bar,baz)); diff --git a/test/form/export-all-multiple/_expected/umd.js b/test/form/export-all-multiple/_expected/umd.js new file mode 100644 index 0000000..0acef0d --- /dev/null +++ b/test/form/export-all-multiple/_expected/umd.js @@ -0,0 +1,13 @@ +(function (global, factory) { + typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('foo'), require('bar'), require('baz')) : + typeof define === 'function' && define.amd ? define(['exports', 'foo', 'bar', 'baz'], factory) : + (factory((global.myBundle = global.myBundle || {}),global.foo,global.bar,global.baz)); +}(this, (function (exports,foo,bar,baz) { 'use strict'; + + Object.keys(foo).forEach(function (key) { exports[key] = foo[key]; }); + Object.keys(bar).forEach(function (key) { exports[key] = bar[key]; }); + Object.keys(baz).forEach(function (key) { exports[key] = baz[key]; }); + + Object.defineProperty(exports, '__esModule', { value: true }); + +}))); diff --git a/test/form/export-all-multiple/main.js b/test/form/export-all-multiple/main.js new file mode 100644 index 0000000..03c82c7 --- /dev/null +++ b/test/form/export-all-multiple/main.js @@ -0,0 +1,3 @@ +export * from 'foo'; +export * from 'bar'; +export * from 'baz'; From 5c88259abc94157953b97b4b7d3e5fa06abafb0b Mon Sep 17 00:00:00 2001 From: Rich-Harris Date: Sat, 14 Jan 2017 13:28:31 -0500 Subject: [PATCH 5/6] handle call expressions of uncallable things more gracefully (#1257) --- src/ast/nodes/shared/callHasEffects.js | 10 ++++++---- test/function/handle-calling-uncallable/_config.js | 3 +++ test/function/handle-calling-uncallable/foo.js | 3 +++ test/function/handle-calling-uncallable/main.js | 5 +++++ 4 files changed, 17 insertions(+), 4 deletions(-) create mode 100644 test/function/handle-calling-uncallable/_config.js create mode 100644 test/function/handle-calling-uncallable/foo.js create mode 100644 test/function/handle-calling-uncallable/main.js diff --git a/src/ast/nodes/shared/callHasEffects.js b/src/ast/nodes/shared/callHasEffects.js index 2c37442..09d58cc 100644 --- a/src/ast/nodes/shared/callHasEffects.js +++ b/src/ast/nodes/shared/callHasEffects.js @@ -96,12 +96,14 @@ export default function callHasEffects ( scope, callee, isNew ) { } } - else { - if ( !node.gatherPossibleValues ) { - throw new Error( 'TODO' ); - } + else if ( node.gatherPossibleValues ) { node.gatherPossibleValues( values ); } + + else { + // probably an error in the user's code — err on side of caution + return true; + } } return false; diff --git a/test/function/handle-calling-uncallable/_config.js b/test/function/handle-calling-uncallable/_config.js new file mode 100644 index 0000000..74b7d98 --- /dev/null +++ b/test/function/handle-calling-uncallable/_config.js @@ -0,0 +1,3 @@ +module.exports = { + description: 'does not give cryptic error when calling uncallable things (#1257)' +}; diff --git a/test/function/handle-calling-uncallable/foo.js b/test/function/handle-calling-uncallable/foo.js new file mode 100644 index 0000000..505dc43 --- /dev/null +++ b/test/function/handle-calling-uncallable/foo.js @@ -0,0 +1,3 @@ +function foo() {} + +export default { foo }; diff --git a/test/function/handle-calling-uncallable/main.js b/test/function/handle-calling-uncallable/main.js new file mode 100644 index 0000000..57e3120 --- /dev/null +++ b/test/function/handle-calling-uncallable/main.js @@ -0,0 +1,5 @@ +import foo from './foo.js'; + +assert.throws( function () { + foo(); +}, /is not a function/ ); From 80da8ecf3e377820a5fc7ca6fcff8a273339614c Mon Sep 17 00:00:00 2001 From: Rich-Harris Date: Sat, 14 Jan 2017 15:41:48 -0500 Subject: [PATCH 6/6] -> v0.41.4 --- CHANGELOG.md | 5 +++++ package.json | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b98ca4a..69b6fb8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # rollup changelog +## 0.41.4 + +* Fix cases of multiple `export * from 'external'` declarations ([#1252](https://github.com/rollup/rollup/issues/1252)) +* Fix 'TODO' error message ([#1257](https://github.com/rollup/rollup/issues/1257)) + ## 0.41.3 * Don't treat `this.foo` as possible namespace ([#1258](https://github.com/rollup/rollup/issues/1258)) diff --git a/package.json b/package.json index f9780c8..7701259 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "rollup", - "version": "0.41.3", + "version": "0.41.4", "description": "Next-generation ES6 module bundler", "main": "dist/rollup.js", "module": "dist/rollup.es.js",