Browse Source

create new scope for classes, with class expression ID (if any) as sole name. fixes #626

gh-669
Rich Harris 9 years ago
parent
commit
d3f092a071
  1. 4
      src/ast/attachScopes.js
  2. 6
      test/form/assignment-to-exports-class-declaration/_config.js
  3. 6
      test/form/assignment-to-exports-class-declaration/_expected/amd.js
  4. 4
      test/form/assignment-to-exports-class-declaration/_expected/cjs.js
  5. 4
      test/form/assignment-to-exports-class-declaration/_expected/es6.js
  6. 7
      test/form/assignment-to-exports-class-declaration/_expected/iife.js
  7. 10
      test/form/assignment-to-exports-class-declaration/_expected/umd.js
  8. 2
      test/form/assignment-to-exports-class-declaration/main.js

4
src/ast/attachScopes.js

@ -29,7 +29,7 @@ export default function attachScopes ( statement ) {
let newScope;
// create new function scope
if ( /Function/.test( node.type ) ) {
if ( /(Function|Class)/.test( node.type ) ) {
newScope = new Scope({
parent: scope,
block: false,
@ -38,7 +38,7 @@ export default function attachScopes ( statement ) {
// named function expressions - the name is considered
// 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 );
}
}

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 );
Loading…
Cancel
Save