Skip to content

Commit

Permalink
rebase corrections
Browse files Browse the repository at this point in the history
  • Loading branch information
guybedford committed May 15, 2018
1 parent 00f6410 commit 4766e15
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 21 deletions.
4 changes: 1 addition & 3 deletions src/ast/nodes/Program.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import MagicString from 'magic-string';
import { NodeBase, StatementNode } from './shared/Node';
import * as NodeType from './NodeType';
import { RenderOptions, renderStatementList, findFirstLineBreakOutsideComment } from '../../utils/renderHelpers';
import { RenderOptions, renderStatementList } from '../../utils/renderHelpers';
import { ExecutionPathOptions } from '../ExecutionPathOptions';
import VariableDeclaration from './VariableDeclaration';
import ExpressionStatement from './ExpressionStatement';

export default class Program extends NodeBase {
type: NodeType.tProgram;
Expand Down
54 changes: 37 additions & 17 deletions src/finalisers/cjs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,16 @@ export default function cjs(
importBlock = '';

dependencies.forEach(
({ id, namedExportsMode, isChunk, name, reexports, imports, exportsNames, exportsDefault }) => {
({
id,
namedExportsMode,
isChunk,
name,
reexports,
imports,
exportsNames,
exportsDefault
}) => {
if (!reexports && !imports) {
importBlock += definingVariable ? ';' : ',';
definingVariable = false;
Expand All @@ -62,22 +71,33 @@ export default function cjs(
if (importBlock.length) importBlock += ';';
} else {
importBlock = dependencies
.map(({ id, isChunk, name, reexports, imports, exportsNames, exportsDefault }) => {
if (!reexports && !imports) return `require('${id}');`;

if (!interop || isChunk || !exportsDefault || !namedExportsMode)
return `${varOrConst} ${name} = require('${id}');`;

needsInterop = true;

if (exportsNames)
return (
`${varOrConst} ${name} = require('${id}');` +
`\n${varOrConst} ${name}__default = _interopDefault(${name});`
);

return `${varOrConst} ${name} = _interopDefault(require('${id}'));`;
})
.map(
({
id,
namedExportsMode,
isChunk,
name,
reexports,
imports,
exportsNames,
exportsDefault
}) => {
if (!reexports && !imports) return `require('${id}');`;

if (!interop || isChunk || !exportsDefault || !namedExportsMode)
return `${varOrConst} ${name} = require('${id}');`;

needsInterop = true;

if (exportsNames)
return (
`${varOrConst} ${name} = require('${id}');` +
`\n${varOrConst} ${name}__default = _interopDefault(${name});`
);

return `${varOrConst} ${name} = _interopDefault(require('${id}'));`;
}
)
.join('\n');
}

Expand Down
2 changes: 1 addition & 1 deletion test/form/samples/system-semicolon/_expected.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ System.register([], function (exports, module) {

var main = exports('default', typeof global !== "undefined" ? global :
typeof self !== "undefined" ? self :
typeof window !== "undefined" ? window : {})
typeof window !== "undefined" ? window : {});

}
};
Expand Down

0 comments on commit 4766e15

Please sign in to comment.