Skip to content

Commit

Permalink
Improve coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
lukastaegert committed Apr 29, 2020
1 parent e1fe8f2 commit c513681
Show file tree
Hide file tree
Showing 10 changed files with 84 additions and 29 deletions.
14 changes: 3 additions & 11 deletions src/ast/nodes/ExportDefaultDeclaration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ import { ExpressionNode, IncludeChildren, NodeBase } from './shared/Node';
const WHITESPACE = /\s/;

// The header ends at the first non-white-space after "default"
function getDeclarationStart(code: string, start = 0) {
function getDeclarationStart(code: string, start: number) {
start = findFirstOccurrenceOutsideComment(code, 'default', start) + 7;
while (WHITESPACE.test(code[start])) start++;
return start;
}

function getIdInsertPosition(code: string, declarationKeyword: string, start = 0) {
function getIdInsertPosition(code: string, declarationKeyword: string, start: number) {
const declarationEnd =
findFirstOccurrenceOutsideComment(code, declarationKeyword, start) + declarationKeyword.length;
code = code.slice(declarationEnd, findFirstOccurrenceOutsideComment(code, '{', declarationEnd));
Expand Down Expand Up @@ -84,15 +84,7 @@ export default class ExportDefaultDeclaration extends NodeBase {
);
} else if (this.variable.getOriginalVariable() !== this.variable) {
// Remove altogether to prevent re-declaring the same variable
if (options.format === 'system' && this.variable.exportName) {
code.overwrite(
start,
end,
`exports('${this.variable.exportName}', ${this.variable.getName()});`
);
} else {
treeshakeNode(this, code, start, end);
}
treeshakeNode(this, code, start, end);
return;
} else if (this.variable.included) {
this.renderVariableDeclaration(code, declarationStart, options);
Expand Down
18 changes: 0 additions & 18 deletions src/ast/variables/ExportDefaultVariable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,22 +73,4 @@ export default class ExportDefaultVariable extends LocalVariable {
}
return this.originalVariable;
}

setRenderNames(baseName: string | null, name: string | null) {
const original = this.getOriginalVariable();
if (original === this) {
super.setRenderNames(baseName, name);
} else {
original.setRenderNames(baseName, name);
}
}

setSafeName(name: string | null) {
const original = this.getOriginalVariable();
if (original === this) {
super.setSafeName(name);
} else {
original.setSafeName(name);
}
}
}
8 changes: 8 additions & 0 deletions test/form/samples/aaa/_config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module.exports = {
description: 'puts the export after the declaration for default exported classes in SystemJS',
options: {
output: {
name: 'bundle'
}
}
};
11 changes: 11 additions & 0 deletions test/form/samples/aaa/_expected/amd.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
define(function () { 'use strict';

class main {
constructor() {
console.log('class');
}
}

return main;

});
9 changes: 9 additions & 0 deletions test/form/samples/aaa/_expected/cjs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
'use strict';

class main {
constructor() {
console.log('class');
}
}

module.exports = main;
7 changes: 7 additions & 0 deletions test/form/samples/aaa/_expected/es.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class main {
constructor() {
console.log('class');
}
}

export default main;
12 changes: 12 additions & 0 deletions test/form/samples/aaa/_expected/iife.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
var bundle = (function () {
'use strict';

class main {
constructor() {
console.log('class');
}
}

return main;

}());
14 changes: 14 additions & 0 deletions test/form/samples/aaa/_expected/system.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
System.register('bundle', [], function (exports) {
'use strict';
return {
execute: function () {

class main {
constructor() {
console.log('class');
}
} exports('default', main);

}
};
});
15 changes: 15 additions & 0 deletions test/form/samples/aaa/_expected/umd.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
(global = global || self, global.bundle = factory());
}(this, (function () { 'use strict';

class main {
constructor() {
console.log('class');
}
}

return main;

})));
5 changes: 5 additions & 0 deletions test/form/samples/aaa/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export default class {
constructor() {
console.log('class');
}
}

0 comments on commit c513681

Please sign in to comment.