Browse Source

Merge branch 'master' into gh-587

gh-669
Rich Harris 9 years ago
parent
commit
4736f2ca3d
  1. 3
      package.json
  2. 6
      src/Bundle.js
  3. 4
      src/ast/attachScopes.js
  4. 6
      test/form/assignment-to-exports-class-declaration/_config.js
  5. 6
      test/form/assignment-to-exports-class-declaration/_expected/amd.js
  6. 4
      test/form/assignment-to-exports-class-declaration/_expected/cjs.js
  7. 4
      test/form/assignment-to-exports-class-declaration/_expected/es6.js
  8. 7
      test/form/assignment-to-exports-class-declaration/_expected/iife.js
  9. 10
      test/form/assignment-to-exports-class-declaration/_expected/umd.js
  10. 2
      test/form/assignment-to-exports-class-declaration/main.js
  11. 15
      test/function/load-returns-string-or-null/_config.js

3
package.json

@ -9,7 +9,7 @@
}, },
"scripts": { "scripts": {
"pretest": "npm run build", "pretest": "npm run build",
"test": "mocha", "test": "mocha --compilers js:buble/register",
"pretest-coverage": "npm run build", "pretest-coverage": "npm run build",
"test-coverage": "rm -rf coverage/* && istanbul cover --report json node_modules/.bin/_mocha -- -u exports -R spec test/test.js", "test-coverage": "rm -rf coverage/* && istanbul cover --report json node_modules/.bin/_mocha -- -u exports -R spec test/test.js",
"posttest-coverage": "remap-istanbul -i coverage/coverage-final.json -o coverage/coverage-remapped.json -b dist && remap-istanbul -i coverage/coverage-final.json -o coverage/coverage-remapped.lcov -t lcovonly -b dist && remap-istanbul -i coverage/coverage-final.json -o coverage/coverage-remapped -t html -b dist", "posttest-coverage": "remap-istanbul -i coverage/coverage-final.json -o coverage/coverage-remapped.json -b dist && remap-istanbul -i coverage/coverage-final.json -o coverage/coverage-remapped.lcov -t lcovonly -b dist && remap-istanbul -i coverage/coverage-final.json -o coverage/coverage-remapped -t html -b dist",
@ -42,6 +42,7 @@
"devDependencies": { "devDependencies": {
"acorn": "^2.6.4", "acorn": "^2.6.4",
"babel-core": "^5.8.32", "babel-core": "^5.8.32",
"buble": "^0.6.4",
"codecov.io": "^0.1.6", "codecov.io": "^0.1.6",
"console-group": "^0.2.0", "console-group": "^0.2.0",
"es6-promise": "^3.0.2", "es6-promise": "^3.0.2",

6
src/Bundle.js

@ -167,6 +167,12 @@ export default class Bundle {
msg += `: ${err.message}`; msg += `: ${err.message}`;
throw new Error( msg ); throw new Error( msg );
}) })
.then( source => {
if ( typeof source === 'string' ) return source;
if ( source && typeof source === 'object' && source.code ) return source;
throw new Error( `Error loading ${id}: load hook should return a string, a { code, map } object, or nothing/null` );
})
.then( source => transform( source, id, this.transformers ) ) .then( source => transform( source, id, this.transformers ) )
.then( source => { .then( source => {
const { code, originalCode, ast, sourceMapChain } = source; const { code, originalCode, ast, sourceMapChain } = source;

4
src/ast/attachScopes.js

@ -29,7 +29,7 @@ export default function attachScopes ( statement ) {
let newScope; let newScope;
// create new function scope // create new function scope
if ( /Function/.test( node.type ) ) { if ( /(Function|Class)/.test( node.type ) ) {
newScope = new Scope({ newScope = new Scope({
parent: scope, parent: scope,
block: false, block: false,
@ -38,7 +38,7 @@ export default function attachScopes ( statement ) {
// named function expressions - the name is considered // named function expressions - the name is considered
// part of the function's scope // part of the function's scope
if ( node.type === 'FunctionExpression' && node.id ) { if ( /(Function|Class)Expression/.test( node.type ) && node.id ) {
newScope.addDeclaration( node, false, false ); newScope.addDeclaration( node, false, false );
} }
} }

6
test/form/assignment-to-exports-class-declaration/_config.js

@ -0,0 +1,6 @@
module.exports = {
description: 'does not rewrite class declaration IDs',
options: {
moduleName: 'myModule'
}
};

6
test/form/assignment-to-exports-class-declaration/_expected/amd.js

@ -0,0 +1,6 @@
define(['exports'], function (exports) { 'use strict';
exports.Foo = class Foo {}
exports.Foo = lol( exports.Foo );
});

4
test/form/assignment-to-exports-class-declaration/_expected/cjs.js

@ -0,0 +1,4 @@
'use strict';
exports.Foo = class Foo {}
exports.Foo = lol( exports.Foo );

4
test/form/assignment-to-exports-class-declaration/_expected/es6.js

@ -0,0 +1,4 @@
Foo = class Foo {}
Foo = lol( Foo );
export { Foo };

7
test/form/assignment-to-exports-class-declaration/_expected/iife.js

@ -0,0 +1,7 @@
(function (exports) {
'use strict';
exports.Foo = class Foo {}
exports.Foo = lol( exports.Foo );
}((this.myModule = this.myModule || {})));

10
test/form/assignment-to-exports-class-declaration/_expected/umd.js

@ -0,0 +1,10 @@
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
typeof define === 'function' && define.amd ? define(['exports'], factory) :
(factory((global.myModule = global.myModule || {})));
}(this, function (exports) { 'use strict';
exports.Foo = class Foo {}
exports.Foo = lol( exports.Foo );
}));

2
test/form/assignment-to-exports-class-declaration/main.js

@ -0,0 +1,2 @@
export let Foo = class Foo {}
Foo = lol( Foo );

15
test/function/load-returns-string-or-null/_config.js

@ -0,0 +1,15 @@
var assert = require( 'assert' );
module.exports = {
description: 'throws error if load returns something wacky',
options: {
plugins: [{
load: function () {
return 42;
}
}]
},
error: function ( err ) {
assert.ok( /load hook should return a string, a \{ code, map \} object, or nothing\/null/.test( err.message ) );
}
};
Loading…
Cancel
Save