Skip to content

Commit

Permalink
Fix incorrect rendering of export declarations in SystemJS (#4202)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukastaegert committed Aug 8, 2021
1 parent ffd5cad commit 039420b
Show file tree
Hide file tree
Showing 10 changed files with 82 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/ast/nodes/VariableDeclaration.ts
Expand Up @@ -176,6 +176,7 @@ export default class VariableDeclaration extends NodeBase {
code.remove(start, end);
continue;
}
node.render(code, options);
leadingString = '';
nextSeparatorString = '';
if (
Expand Down Expand Up @@ -217,7 +218,6 @@ export default class VariableDeclaration extends NodeBase {
code.overwrite(lastSeparatorPos, lastSeparatorPos + 1, separatorString);
code.appendLeft(renderedContentEnd, leadingString);
}
node.render(code, options);
actualContentEnd = contentEnd;
renderedContentEnd = end;
hasRenderedContent = true;
Expand Down
4 changes: 4 additions & 0 deletions test/form/samples/simplified-initializer/_config.js
@@ -0,0 +1,4 @@
module.exports = {
description: 'handles simplified variable initializers',
options: { output: { name: 'bundle' } }
};
13 changes: 13 additions & 0 deletions test/form/samples/simplified-initializer/_expected/amd.js
@@ -0,0 +1,13 @@
define(['exports'], function (exports) { 'use strict';

const a = window.config ? 1 : 2;
const b = 1 ;
const c = 2;

exports.a = a;
exports.b = b;
exports.c = c;

Object.defineProperty(exports, '__esModule', { value: true });

});
11 changes: 11 additions & 0 deletions test/form/samples/simplified-initializer/_expected/cjs.js
@@ -0,0 +1,11 @@
'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

const a = window.config ? 1 : 2;
const b = 1 ;
const c = 2;

exports.a = a;
exports.b = b;
exports.c = c;
5 changes: 5 additions & 0 deletions test/form/samples/simplified-initializer/_expected/es.js
@@ -0,0 +1,5 @@
const a = window.config ? 1 : 2;
const b = 1 ;
const c = 2;

export { a, b, c };
16 changes: 16 additions & 0 deletions test/form/samples/simplified-initializer/_expected/iife.js
@@ -0,0 +1,16 @@
var bundle = (function (exports) {
'use strict';

const a = window.config ? 1 : 2;
const b = 1 ;
const c = 2;

exports.a = a;
exports.b = b;
exports.c = c;

Object.defineProperty(exports, '__esModule', { value: true });

return exports;

}({}));
12 changes: 12 additions & 0 deletions test/form/samples/simplified-initializer/_expected/system.js
@@ -0,0 +1,12 @@
System.register('bundle', [], function (exports) {
'use strict';
return {
execute: function () {

const a = exports('a', window.config ? 1 : 2);
const b = exports('b', 1 );
const c = exports('c', 2);

}
};
});
17 changes: 17 additions & 0 deletions test/form/samples/simplified-initializer/_expected/umd.js
@@ -0,0 +1,17 @@
(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';

const a = window.config ? 1 : 2;
const b = 1 ;
const c = 2;

exports.a = a;
exports.b = b;
exports.c = c;

Object.defineProperty(exports, '__esModule', { value: true });

})));
3 changes: 3 additions & 0 deletions test/form/samples/simplified-initializer/main.js
@@ -0,0 +1,3 @@
export const a = window.config ? 1 : 2
export const b = true ? 1 : 2
export const c = false ? 1 : 2
Expand Up @@ -21,7 +21,6 @@ module.exports = {
},
before() {
fs.readFile = (path, options, callback) => {
console.log('mock read');
currentReads++;
maxReads = Math.max(maxReads, currentReads);
fsReadFile(path, options, (err, data) => {
Expand Down

0 comments on commit 039420b

Please sign in to comment.