Skip to content

Commit

Permalink
Merge branch 'master' into gh-4751-namespace-member-tree-shaking
Browse files Browse the repository at this point in the history
  • Loading branch information
lukastaegert committed Dec 17, 2022
2 parents cac0855 + 554ba9f commit 9bceadd
Show file tree
Hide file tree
Showing 19 changed files with 66 additions and 15 deletions.
19 changes: 11 additions & 8 deletions cli/logging.ts
Expand Up @@ -8,32 +8,35 @@ export const stderr = (...parameters: readonly unknown[]) =>
process.stderr.write(`${parameters.join('')}\n`);

export function handleError(error: RollupError, recover = false): void {
const name = error.name || error.cause?.name;
const name = error.name || (error.cause as Error)?.name;
const nameSection = name ? `${name}: ` : '';
const pluginSection = error.plugin ? `(plugin ${error.plugin}) ` : '';
const message = `${pluginSection}${nameSection}${error.message}`;

stderr(bold(red(`[!] ${bold(message.toString())}`)));
const outputLines = [bold(red(`[!] ${bold(message.toString())}`))];

if (error.url) {
stderr(cyan(error.url));
outputLines.push(cyan(error.url));
}

if (error.loc) {
stderr(`${relativeId((error.loc.file || error.id)!)} (${error.loc.line}:${error.loc.column})`);
outputLines.push(
`${relativeId((error.loc.file || error.id)!)} (${error.loc.line}:${error.loc.column})`
);
} else if (error.id) {
stderr(relativeId(error.id));
outputLines.push(relativeId(error.id));
}

if (error.frame) {
stderr(dim(error.frame));
outputLines.push(dim(error.frame));
}

if (error.stack) {
stderr(dim(error.stack));
outputLines.push(dim(error.stack?.replace(`${nameSection}${error.message}\n`, '')));
}

stderr('');
outputLines.push('', '');
stderr(outputLines.join('\n'));

// eslint-disable-next-line unicorn/no-process-exit
if (!recover) process.exit(1);
Expand Down
9 changes: 9 additions & 0 deletions src/ast/variables/ExportDefaultVariable.ts
Expand Up @@ -37,6 +37,15 @@ export default class ExportDefaultVariable extends LocalVariable {
}
}

forbidName(name: string) {
const original = this.getOriginalVariable();
if (original === this) {
super.forbidName(name);
} else {
original.forbidName(name);
}
}

getAssignedVariableName(): string | null {
return (this.originalId && this.originalId.name) || null;
}
Expand Down
2 changes: 1 addition & 1 deletion src/rollup/types.d.ts
Expand Up @@ -19,7 +19,7 @@ export type RollupWarning = RollupLog;

export interface RollupLog {
binding?: string;
cause?: Error;
cause?: unknown;
code?: string;
exporter?: string;
frame?: string;
Expand Down
5 changes: 1 addition & 4 deletions test/cli/samples/custom-frame-with-pos/_config.js
Expand Up @@ -7,9 +7,6 @@ module.exports = {
stderr: stderr =>
assertIncludes(
stderr,
'[!] (plugin at position 1) Error: My error.\n' +
'main.js (1:5)\n' +
'custom code frame\n' +
'Error: My error.'
'[!] (plugin at position 1) Error: My error.\n' + 'main.js (1:5)\n' + 'custom code frame\n'
)
};
2 changes: 1 addition & 1 deletion test/cli/samples/custom-frame/_config.js
Expand Up @@ -8,7 +8,7 @@ module.exports = {
assertIncludes(
stderr,
'[!] (plugin at position 1) Error: My error.\n' +
'main.js\ncustom code frame\nError: My error.\n' +
'main.js\ncustom code frame\n' +
' at Object.'
);
assertIncludes(stderr, 'rollup.config.js:9:19');
Expand Down
2 changes: 1 addition & 1 deletion test/cli/samples/watch/bundle-error/_config.js
Expand Up @@ -16,7 +16,7 @@ module.exports = {
setTimeout(() => unlinkSync(mainFile), 300);
},
abortOnStderr(data) {
if (data.includes('Error: Unexpected token')) {
if (data.includes('[!] RollupError: Unexpected token')) {
setTimeout(() => atomicWriteFileSync(mainFile, 'export default 42;'), 500);
return false;
}
Expand Down
3 changes: 3 additions & 0 deletions test/function/samples/class-name-conflict-3/_config.js
@@ -0,0 +1,3 @@
module.exports = {
description: 'does not shadow variables when preserving class names'
};
1 change: 1 addition & 0 deletions test/function/samples/class-name-conflict-3/foo.js
@@ -0,0 +1 @@
export default class Foo {}
14 changes: 14 additions & 0 deletions test/function/samples/class-name-conflict-3/main.js
@@ -0,0 +1,14 @@
import Bar from './foo';

const wrapper = () => {
class Foo extends Bar {
static assertName() {
assert.strictEqual(this.name, 'Foo');
assert.strictEqual(super.name, 'Foo');
}
}

return Foo;
};

wrapper().assertName();
3 changes: 3 additions & 0 deletions test/function/samples/class-name-conflict-4/_config.js
@@ -0,0 +1,3 @@
module.exports = {
description: 'does not shadow variables when preserving class names'
};
5 changes: 5 additions & 0 deletions test/function/samples/class-name-conflict-4/foo.js
@@ -0,0 +1,5 @@
var Foo = class {};

export default Foo;

Foo = 'reassigned';
14 changes: 14 additions & 0 deletions test/function/samples/class-name-conflict-4/main.js
@@ -0,0 +1,14 @@
import Bar from './reexport';

const wrapper = () => {
class Foo extends Bar {
static assertName() {
assert.strictEqual(this.name, 'Foo');
assert.strictEqual(super.name, 'Foo');
}
}

return Foo;
};

wrapper().assertName();
2 changes: 2 additions & 0 deletions test/function/samples/class-name-conflict-4/reexport.js
@@ -0,0 +1,2 @@
import Foo from './foo';
export default Foo;

0 comments on commit 9bceadd

Please sign in to comment.