Skip to content

Commit

Permalink
WIP: prefer code already in memory
Browse files Browse the repository at this point in the history
  • Loading branch information
tivac committed Dec 13, 2017
1 parent 9c9f39c commit 3201a5c
Showing 1 changed file with 37 additions and 35 deletions.
72 changes: 37 additions & 35 deletions packages/rollup/rollup.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,48 +55,50 @@ module.exports = function(opts) {
}

return Promise.all(
removed.map((file) =>
processor.file(file)
// Run current file first since it's already in-memory
[ processor.string(id, code) ].concat(
removed.map((file) =>
processor.file(file)
)
)
)
.then(() =>
processor.string(id, code).then((result) => {
var classes = output.join(result.exports),
named = Object.keys(classes),
out = [
`export default ${JSON.stringify(classes, null, 4)};`
];
.then((results) => {
var result = results[0],
classes = output.join(result.exports),
named = Object.keys(classes),
out = [
`export default ${JSON.stringify(classes, null, 4)};`
];

// Add dependencies
out = out.concat(
processor.dependencies(id).map((file) =>
`import "${file.replace(/\\/g, "/")}";`
)
);

// Add dependencies
out = out.concat(
processor.dependencies(id).map((file) =>
`import "${file.replace(/\\/g, "/")}";`
)
);

if(options.namedExports === false) {
return {
code : out.join("\n"),
map
};
}

named.forEach((ident) => {
if(keyword.isReservedWordES6(ident) || !keyword.isIdentifierNameES6(ident)) {
options.onwarn(`Invalid JS identifier "${ident}", unable to export`);

return;
}

out.push(`export var ${ident} = "${classes[ident]}";`);
});

if(options.namedExports === false) {
return {
code : out.join("\n"),
map
};
})
);
}

named.forEach((ident) => {
if(keyword.isReservedWordES6(ident) || !keyword.isIdentifierNameES6(ident)) {
options.onwarn(`Invalid JS identifier "${ident}", unable to export`);

return;
}

out.push(`export var ${ident} = "${classes[ident]}";`);
});

return {
code : out.join("\n"),
map
};
});
},

// Hook for when bundle.generate() is called
Expand Down

0 comments on commit 3201a5c

Please sign in to comment.