Skip to content

Commit

Permalink
Order object properties
Browse files Browse the repository at this point in the history
  • Loading branch information
lukastaegert committed Feb 28, 2019
1 parent e3c9d9b commit 1fa957e
Show file tree
Hide file tree
Showing 46 changed files with 339 additions and 336 deletions.
44 changes: 22 additions & 22 deletions bin/src/run/batchWarnings.ts
Expand Up @@ -122,17 +122,16 @@ const deferredHandlers: {
};
} = {
UNUSED_EXTERNAL_IMPORT: {
priority: 1,
fn: warnings => {
title('Unused external imports');
warnings.forEach(warning => {
stderr(`${warning.names} imported from external module '${warning.source}' but never used`);
});
}
},
priority: 1
},

UNRESOLVED_IMPORT: {
priority: 1,
fn: warnings => {
title('Unresolved dependencies');
info('https://rollupjs.org/guide/en#warning-treating-module-as-external-dependency');
Expand All @@ -147,11 +146,11 @@ const deferredHandlers: {
const importers = dependencies.get(dependency);
stderr(`${tc.bold(dependency)} (imported by ${importers.join(', ')})`);
});
}
},
priority: 1
},

MISSING_EXPORT: {
priority: 1,
fn: warnings => {
title('Missing exports');
info('https://rollupjs.org/guide/en#error-name-is-not-exported-by-module-');
Expand All @@ -161,37 +160,37 @@ const deferredHandlers: {
stderr(`${warning.missing} is not exported by ${warning.exporter}`);
stderr(tc.gray(warning.frame));
});
}
},
priority: 1
},

THIS_IS_UNDEFINED: {
priority: 1,
fn: warnings => {
title('`this` has been rewritten to `undefined`');
info('https://rollupjs.org/guide/en#error-this-is-undefined');
showTruncatedWarnings(warnings);
}
},
priority: 1
},

EVAL: {
priority: 1,
fn: warnings => {
title('Use of eval is strongly discouraged');
info('https://rollupjs.org/guide/en#avoiding-eval');
showTruncatedWarnings(warnings);
}
},
priority: 1
},

NON_EXISTENT_EXPORT: {
priority: 1,
fn: warnings => {
title(`Import of non-existent ${warnings.length > 1 ? 'exports' : 'export'}`);
showTruncatedWarnings(warnings);
}
},
priority: 1
},

NAMESPACE_CONFLICT: {
priority: 1,
fn: warnings => {
title(`Conflicting re-exports`);
warnings.forEach(warning => {
Expand All @@ -203,11 +202,11 @@ const deferredHandlers: {
)} (will be ignored)`
);
});
}
},
priority: 1
},

MISSING_GLOBAL_NAME: {
priority: 1,
fn: warnings => {
title(`Missing global variable ${warnings.length > 1 ? 'names' : 'name'}`);
stderr(
Expand All @@ -216,11 +215,11 @@ const deferredHandlers: {
warnings.forEach(warning => {
stderr(`${tc.bold(warning.source)} (guessing '${warning.guess}')`);
});
}
},
priority: 1
},

SOURCEMAP_BROKEN: {
priority: 1,
fn: warnings => {
title(`Broken sourcemap`);
info('https://rollupjs.org/guide/en#warning-sourcemap-is-likely-to-be-incorrect');
Expand All @@ -237,11 +236,11 @@ const deferredHandlers: {
: ` (such as '${plugins[0]}')`;

stderr(`Plugins that transform code${detail} should generate accompanying sourcemaps`);
}
},
priority: 1
},

PLUGIN_WARNING: {
priority: 1,
fn: warnings => {
const nestedByPlugin = nest(warnings, 'plugin');

Expand All @@ -266,7 +265,8 @@ const deferredHandlers: {
});
});
});
}
},
priority: 1
}
};

Expand All @@ -286,8 +286,8 @@ function nest<T>(array: T[], prop: string) {
const key = (<any>item)[prop];
if (!lookup.has(key)) {
lookup.set(key, {
key,
items: []
items: [],
key
});

nested.push(lookup.get(key));
Expand Down
2 changes: 1 addition & 1 deletion bin/src/run/index.ts
Expand Up @@ -102,8 +102,8 @@ function execute(configFile: string, configs: InputOptions[], command: any) {
promise = promise.then(() => {
const warnings = batchWarnings();
const { inputOptions, outputOptions, optionError } = mergeOptions({
config,
command,
config,
defaultOnWarnHandler: warnings.add
});

Expand Down
6 changes: 3 additions & 3 deletions bin/src/run/loadConfigFile.ts
Expand Up @@ -23,12 +23,12 @@ export default function loadConfigFile(

return rollup
.rollup({
input: configFile,
treeshake: false,
external: (id: string) => {
return (id[0] !== '.' && !path.isAbsolute(id)) || id.slice(-5, id.length) === '.json';
},
onwarn: warnings.add
input: configFile,
onwarn: warnings.add,
treeshake: false
})
.then((bundle: RollupBuild) => {
if (!silent && warnings.count > 0) {
Expand Down
6 changes: 3 additions & 3 deletions bin/src/run/watch.ts
Expand Up @@ -57,8 +57,8 @@ export default function watch(
function processConfigs(configs: RollupWatchOptions[]): RollupWatchOptions[] {
return configs.map(options => {
const merged = mergeOptions({
config: options,
command,
config: options,
defaultOnWarnHandler: warnings.add
});

Expand All @@ -71,8 +71,8 @@ export default function watch(

if (merged.optionError)
merged.inputOptions.onwarn({
message: merged.optionError,
code: 'UNKNOWN_OPTION'
code: 'UNKNOWN_OPTION',
message: merged.optionError
});

if (
Expand Down
38 changes: 19 additions & 19 deletions src/Chunk.ts
Expand Up @@ -94,11 +94,11 @@ function getGlobalName(
if (hasExports) {
graph.warn({
code: 'MISSING_GLOBAL_NAME',
source: module.id,
guess: module.variableName,
message: `No name was provided for external module '${
module.id
}' in output.globals – guessing '${module.variableName}'`
}' in output.globals – guessing '${module.variableName}'`,
source: module.id
});
return module.variableName;
}
Expand Down Expand Up @@ -172,8 +172,8 @@ export default class Chunk {

generateEntryExportsOrMarkAsTainted() {
const exportVariableMaps = this.entryModules.map(module => ({
module,
map: this.getVariableExportNamesForModule(module)
map: this.getVariableExportNamesForModule(module),
module
}));
for (const { map } of exportVariableMaps) {
for (const exposedVariable of Array.from(map.keys())) {
Expand Down Expand Up @@ -482,10 +482,10 @@ export default class Chunk {

const { renderedExports, removedExports } = module.getRenderedExports();
this.renderedModules[module.id] = {
renderedExports,
originalLength: module.originalCode.length,
removedExports,
renderedLength: source.length(),
originalLength: module.originalCode.length
renderedExports,
renderedLength: source.length()
};

const namespace = module.getOrCreateNamespace();
Expand Down Expand Up @@ -613,12 +613,12 @@ export default class Chunk {
const chunkSourcemapChain: RawSourceMap[] = [];

return renderChunk({
graph: this.graph,
chunk: this,
renderChunk: outputChunk,
code: prevCode,
sourcemapChain: chunkSourcemapChain,
options
graph: this.graph,
options,
renderChunk: outputChunk,
sourcemapChain: chunkSourcemapChain
}).then((code: string) => {
if (options.sourcemap) {
timeStart('sourcemap', 3);
Expand Down Expand Up @@ -865,15 +865,15 @@ export default class Chunk {
}

dependencies.push({
id, // chunk id updated on render
namedExportsMode,
exportsDefault,
exportsNames,
globalName,
name: dep.variableName,
id, // chunk id updated on render
imports: imports.length > 0 ? imports : null,
isChunk: !(<ExternalModule>dep).isExternal,
exportsNames,
exportsDefault,
reexports,
imports: imports.length > 0 ? imports : null
name: dep.variableName,
namedExportsMode,
reexports
});
}

Expand Down Expand Up @@ -909,9 +909,9 @@ export default class Chunk {
const localName = variable.getName();

exports.push({
local: localName,
exported: exportName === '*' ? localName : exportName,
hoisted,
local: localName,
uninitialized
});
}
Expand Down
4 changes: 2 additions & 2 deletions src/ExternalModule.ts
Expand Up @@ -95,9 +95,9 @@ export default class ExternalModule {

this.graph.warn({
code: 'UNUSED_EXTERNAL_IMPORT',
source: this.id,
message: `${names} imported from external module '${this.id}' but never used`,
names: unused,
message: `${names} imported from external module '${this.id}' but never used`
source: this.id
});
}
}
22 changes: 11 additions & 11 deletions src/Graph.ts
Expand Up @@ -102,9 +102,9 @@ export default class Graph {
if (this.treeshake) {
this.treeshakingOptions = options.treeshake
? {
annotations: (<TreeshakingOptions>options.treeshake).annotations !== false,
propertyReadSideEffects:
(<TreeshakingOptions>options.treeshake).propertyReadSideEffects !== false,
annotations: (<TreeshakingOptions>options.treeshake).annotations !== false,
pureExternalModules: (<TreeshakingOptions>options.treeshake).pureExternalModules
}
: { propertyReadSideEffects: true, annotations: true, pureExternalModules: false };
Expand Down Expand Up @@ -467,11 +467,11 @@ export default class Graph {
if (resolvedId !== false) {
this.warn({
code: 'UNRESOLVED_IMPORT',
source,
importer: relativeId(module.id),
message: `'${source}' is imported by ${relativeId(
module.id
)}, but could not be resolved – treating it as an external dependency`,
source,
url:
'https://rollupjs.org/guide/en#warning-treating-module-as-external-dependency'
});
Expand Down Expand Up @@ -554,8 +554,8 @@ export default class Graph {
const sourceDescription: SourceDescription =
typeof source === 'string'
? {
code: source,
ast: null
ast: null,
code: source
}
: source;

Expand Down Expand Up @@ -596,16 +596,16 @@ export default class Graph {
if (name in module.exportsAll) {
this.warn({
code: 'NAMESPACE_CONFLICT',
reexporter: module.id,
name,
sources: [module.exportsAll[name], (<Module>exportAllModule).exportsAll[name]],
message: `Conflicting namespaces: ${relativeId(
module.id
)} re-exports '${name}' from both ${relativeId(
module.exportsAll[name]
)} and ${relativeId(
(<Module>exportAllModule).exportsAll[name]
)} (will be ignored)`
)} (will be ignored)`,
name,
reexporter: module.id,
sources: [module.exportsAll[name], (<Module>exportAllModule).exportsAll[name]]
});
} else {
module.exportsAll[name] = (<Module>exportAllModule).exportsAll[name];
Expand Down Expand Up @@ -714,11 +714,11 @@ export default class Graph {
module.warn(
{
code: 'NON_EXISTENT_EXPORT',
name: importDescription.name,
source: importDescription.module.id,
message: `Non-existent export '${
importDescription.name
}' is imported from ${relativeId(importDescription.module.id)}`
}' is imported from ${relativeId(importDescription.module.id)}`,
name: importDescription.name,
source: importDescription.module.id
},
importDescription.start
);
Expand Down

0 comments on commit 1fa957e

Please sign in to comment.