Skip to content

Commit

Permalink
Slightly improve code
Browse files Browse the repository at this point in the history
  • Loading branch information
lukastaegert committed Oct 16, 2022
1 parent 9bb84b6 commit d6665ee
Show file tree
Hide file tree
Showing 11 changed files with 78 additions and 8 deletions.
14 changes: 6 additions & 8 deletions src/ast/nodes/ClassDeclaration.ts
Expand Up @@ -37,20 +37,18 @@ export default class ClassDeclaration extends ClassNode {
} = options;
if (this.id) {
const { variable, name } = this.id;
if (format === 'system' && exportNamesByVariable.has(variable)) {
code.appendLeft(this.end, `${_}${getSystemExportStatement([variable], options)};`);
}
const renderedVariable = variable.getName(getPropertyAccess);
if (renderedVariable !== name) {
this.superClass?.render(code, options);
this.body.render(code, options);
code.prependRight(this.start, `let ${renderedVariable}${_}=${_}`);
code.appendLeft(this.end, ';');
} else {
super.render(code, options);
code.prependLeft(this.end, ';');
return;
}
} else {
super.render(code, options);
}
if (format === 'system' && this.id && exportNamesByVariable.has(this.id.variable)) {
code.appendLeft(this.end, `${_}${getSystemExportStatement([this.id.variable], options)};`);
}
super.render(code, options);
}
}
@@ -0,0 +1,4 @@
module.exports = {
description: 'handles exporting class declarations with name conflicts in SystemJS',
options: { output: { name: 'bundle' } }
};
@@ -0,0 +1,10 @@
define(['exports'], (function (exports) { 'use strict';

let Foo$1 = class Foo {};

class Foo {}

exports.First = Foo$1;
exports.Second = Foo;

}));
@@ -0,0 +1,8 @@
'use strict';

let Foo$1 = class Foo {};

class Foo {}

exports.First = Foo$1;
exports.Second = Foo;
@@ -0,0 +1,5 @@
let Foo$1 = class Foo {};

class Foo {}

export { Foo$1 as First, Foo as Second };
@@ -0,0 +1,13 @@
var bundle = (function (exports) {
'use strict';

let Foo$1 = class Foo {};

class Foo {}

exports.First = Foo$1;
exports.Second = Foo;

return exports;

})({});
@@ -0,0 +1,12 @@
System.register('bundle', [], (function (exports) {
'use strict';
return {
execute: (function () {

let Foo$1 = class Foo {}; exports('First', Foo$1);

class Foo {} exports('Second', Foo);

})
};
}));
@@ -0,0 +1,14 @@
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
typeof define === 'function' && define.amd ? define(['exports'], factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.bundle = {}));
})(this, (function (exports) { 'use strict';

let Foo$1 = class Foo {};

class Foo {}

exports.First = Foo$1;
exports.Second = Foo;

}));
@@ -0,0 +1,2 @@
class Foo {}
export { Foo };
2 changes: 2 additions & 0 deletions test/form/samples/exported-class-declaration-conflict/main.js
@@ -0,0 +1,2 @@
export { Foo as First } from './first';
export { Foo as Second } from './second';
@@ -0,0 +1,2 @@
class Foo {}
export { Foo };

0 comments on commit d6665ee

Please sign in to comment.