Skip to content

Commit

Permalink
Switch to ES2015 output
Browse files Browse the repository at this point in the history
  • Loading branch information
lukastaegert committed May 11, 2019
1 parent 7d669eb commit fdb68b3
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 23 deletions.
8 changes: 4 additions & 4 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ export default command => {
alias(moduleAliases),
resolve(),
json(),
typescript(),
commonjs({ include: 'node_modules/**', namedExports: { micromatch: ['matcher'] } }),
typescript({include: '**/*.{ts,js}'}),
fixAcornEsmImport()
],
// acorn needs to be external as some plugins rely on a shared acorn instance
Expand All @@ -108,8 +108,8 @@ export default command => {
resolve(),
json(),
string({ include: '**/*.md' }),
typescript(),
commonjs({ include: 'node_modules/**' })
commonjs({ include: 'node_modules/**' }),
typescript({include: '**/*.{ts,js}'}),
],
external: ['fs', 'path', 'module', 'events', 'rollup', 'assert', 'os', 'util'],
treeshake: {
Expand Down Expand Up @@ -145,8 +145,8 @@ export default command => {
if (~id.indexOf('path.ts')) return fs.readFileSync('browser/path.ts', 'utf-8');
}
},
typescript(),
commonjs(),
typescript({include: '**/*.{ts,js}'}),
terser({ module: true, output: { comments: 'some' } })
],
treeshake: {
Expand Down
23 changes: 10 additions & 13 deletions src/Chunk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,10 @@ export default class Chunk {
module
}));
for (const { map } of exportVariableMaps) {
for (const exposedVariable of Array.from(map.keys())) {
for (const exposedVariable of map.keys()) {
this.exports.add(exposedVariable);
}
}
const exposedVariables = Array.from(this.exports);
checkNextEntryModule: for (const { map, module } of exportVariableMaps) {
if (!this.graph.preserveModules) {
if (
Expand All @@ -200,14 +199,14 @@ export default class Chunk {
) {
continue checkNextEntryModule;
}
for (const exposedVariable of exposedVariables) {
for (const exposedVariable of this.exports) {
if (!map.has(exposedVariable)) {
continue checkNextEntryModule;
}
}
}
this.facadeModule = module;
for (const [variable, exportNames] of Array.from(map)) {
for (const [variable, exportNames] of map) {
for (const exportName of exportNames) {
this.exportNames[exportName] = variable;
}
Expand Down Expand Up @@ -260,9 +259,8 @@ export default class Chunk {
safeExportName: string;
this.exportNames = Object.create(null);
this.sortedExportNames = null;
const exportedVariables = Array.from(this.exports);
if (mangle) {
for (const variable of exportedVariables) {
for (const variable of this.exports) {
do {
safeExportName = toBase64(++i);
// skip past leading number identifiers
Expand All @@ -274,7 +272,7 @@ export default class Chunk {
this.exportNames[safeExportName] = variable;
}
} else {
for (const variable of exportedVariables) {
for (const variable of this.exports) {
i = 0;
safeExportName = variable.name;
while (this.exportNames[safeExportName]) {
Expand Down Expand Up @@ -361,15 +359,15 @@ export default class Chunk {
this.orderedModules.push(module);
}

for (const variable of Array.from(chunk.imports)) {
for (const variable of chunk.imports) {
if (!this.imports.has(variable) && variable.module.chunk !== this) {
this.imports.add(variable);
}
}

// NB detect when exported variables are orphaned by the merge itself
// (involves reverse tracing dependents)
for (const variable of Array.from(chunk.exports)) {
for (const variable of chunk.exports) {
if (!this.exports.has(variable)) {
this.exports.add(variable);
}
Expand Down Expand Up @@ -475,7 +473,7 @@ export default class Chunk {
};

// Make sure the direct dependencies of a chunk are present to maintain execution order
for (const { module } of Array.from(this.imports)) {
for (const { module } of this.imports) {
const chunkOrExternal = module instanceof Module ? module.chunk : module;
if (this.dependencies.indexOf(chunkOrExternal) === -1) {
this.dependencies.push(chunkOrExternal);
Expand Down Expand Up @@ -863,13 +861,12 @@ export default class Chunk {
exportDeclaration.push({ imported: importName, reexported: exportName, needsLiveBinding });
}

const importsAsArray = Array.from(this.imports);
const renderedImports = new Set<Variable>();
const dependencies: ChunkDependencies = [];

for (const dep of this.dependencies) {
const imports: ImportSpecifier[] = [];
for (const variable of importsAsArray) {
for (const variable of this.imports) {
const renderedVariable =
variable instanceof ExportDefaultVariable && variable.referencesOriginal()
? variable.getOriginalVariable()
Expand Down Expand Up @@ -1071,7 +1068,7 @@ export default class Chunk {
}

private setUpModuleImports(module: Module) {
for (const variable of Array.from(module.imports)) {
for (const variable of module.imports) {
if (variable.module.chunk !== this) {
this.imports.add(variable);
if (variable.module instanceof Module) {
Expand Down
2 changes: 1 addition & 1 deletion src/Graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ export default class Graph {
if (entryModules.length === 0) {
throw new Error('You must supply options.input to rollup');
}
for (const module of Array.from(this.moduleById.values())) {
for (const module of this.moduleById.values()) {
if (module instanceof Module) {
this.modules.push(module);
this.watchFiles[module.id] = true;
Expand Down
4 changes: 2 additions & 2 deletions src/utils/deconflictChunk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ function deconflictImportsEsm(
_dependencies: (ExternalModule | Chunk)[],
interop: boolean
) {
for (const variable of Array.from(imports)) {
for (const variable of imports) {
const module = variable.module;
const name = variable.name;
let proposedName: string;
Expand All @@ -97,7 +97,7 @@ function deconflictImportsOther(
for (const chunkOrExternalModule of dependencies) {
chunkOrExternalModule.variableName = getSafeName(chunkOrExternalModule.variableName, usedNames);
}
for (const variable of Array.from(imports)) {
for (const variable of imports) {
const module = variable.module;
if (module instanceof ExternalModule) {
const name = variable.name;
Expand Down
5 changes: 2 additions & 3 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
"compilerOptions": {
"allowSyntheticDefaultImports": true,
"diagnostics": true,
"downlevelIteration": false,
"lib": ["es5", "es6", "dom"],
"lib": ["es6", "dom"],
"module": "commonjs",
"noEmitOnError": true,
"noImplicitAny": true,
Expand All @@ -12,7 +11,7 @@
"noUnusedParameters": true,
"pretty": true,
"skipLibCheck": true,
"target": "es5"
"target": "es2015"
},
"include": [
"typings/**/*.d.ts",
Expand Down

0 comments on commit fdb68b3

Please sign in to comment.