Skip to content

Commit

Permalink
remove safeExportName, exportName -> exportNames
Browse files Browse the repository at this point in the history
  • Loading branch information
guybedford committed Jun 2, 2020
1 parent 5463c90 commit 8e50c87
Show file tree
Hide file tree
Showing 11 changed files with 29 additions and 42 deletions.
10 changes: 5 additions & 5 deletions src/Chunk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -819,9 +819,9 @@ export default class Chunk {
renderedResolution,
resolution instanceof Module &&
!(resolution.facadeChunk && resolution.facadeChunk.strictFacade) &&
!!resolution.namespace.exportName &&
!!resolution.namespace.exportNames &&
// We only need one of the export names to bind to
resolution.namespace.exportName[0],
resolution.namespace.exportNames[0],
options
);
}
Expand Down Expand Up @@ -1062,9 +1062,9 @@ export default class Chunk {
if (exportVariable instanceof ExportShimVariable) {
this.needsExportsShim = true;
}
if (!exportVariable.exportName || exportVariable.exportName.includes(exportName))
exportVariable.exportName = [exportName];
else exportVariable.exportName.push(exportName);
if (!exportVariable.exportNames || exportVariable.exportNames.includes(exportName))
exportVariable.exportNames = [exportName];
else exportVariable.exportNames.push(exportName);
if (
options.format !== 'es' &&
options.format !== 'system' &&
Expand Down
4 changes: 1 addition & 3 deletions src/ast/nodes/AssignmentExpression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,7 @@ export default class AssignmentExpression extends NodeBase {
this.left.render(code, options);
this.right.render(code, options);
if (options.format === 'system') {
const exportNames = this.left.variable?.safeExportName
? [this.left.variable?.safeExportName]
: this.left.variable?.exportName;
const exportNames = this.left.variable?.exportNames;
const _ = options.compact ? '' : ' ';
if (exportNames) {
const operatorPos = findFirstOccurrenceOutsideComment(
Expand Down
2 changes: 1 addition & 1 deletion src/ast/nodes/ClassDeclaration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export default class ClassDeclaration extends ClassNode {
}

render(code: MagicString, options: RenderOptions) {
if (options.format === 'system' && this.id && this.id.variable.exportName) {
if (options.format === 'system' && this.id && this.id.variable.exportNames) {
code.appendLeft(this.end, ` ${getSystemExportStatement([this.id.variable], options)};`);
}
super.render(code, options);
Expand Down
12 changes: 6 additions & 6 deletions src/ast/nodes/ExportDefaultDeclaration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ export default class ExportDefaultDeclaration extends NodeBase {
if (
options.format === 'system' &&
this.declaration instanceof ClassDeclaration &&
this.variable.exportName
this.variable.exportNames
) {
code.appendLeft(this.end, ` ${getSystemExportStatement([this.variable], options)};`);
}
Expand All @@ -149,14 +149,14 @@ export default class ExportDefaultDeclaration extends NodeBase {

if (
options.format === 'system' &&
this.variable.exportName &&
this.variable.exportName.length === 1
this.variable.exportNames &&
this.variable.exportNames.length === 1
) {
code.overwrite(
this.start,
declarationStart,
`${options.varOrConst} ${this.variable.getName()} = exports('${
this.variable.exportName[0]
this.variable.exportNames[0]
}', `
);
code.appendRight(
Expand All @@ -176,8 +176,8 @@ export default class ExportDefaultDeclaration extends NodeBase {

if (
options.format === 'system' &&
this.variable.exportName &&
this.variable.exportName.length > 1
this.variable.exportNames &&
this.variable.exportNames.length > 1
) {
code.appendLeft(this.end, ` ${getSystemExportStatement([this.variable], options)};`);
}
Expand Down
2 changes: 1 addition & 1 deletion src/ast/nodes/Identifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export default class Identifier extends NodeBase implements PatternNode {
private bound = false;

addExportedVariables(variables: Variable[]): void {
if (this.variable !== null && this.variable.exportName) {
if (this.variable !== null && this.variable.exportNames) {
variables.push(this.variable);
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/ast/nodes/UpdateExpression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ export default class UpdateExpression extends NodeBase {
render(code: MagicString, options: RenderOptions) {
this.argument.render(code, options);
const variable = this.argument.variable;
if (options.format === 'system' && variable && variable.exportName) {
if (options.format === 'system' && variable && variable.exportNames) {
const _ = options.compact ? '' : ' ';
if (variable.exportName.length === 1) {
if (variable.exportNames.length === 1) {
const name = variable.getName();
if (this.prefix) {
code.overwrite(
this.start,
this.end,
`exports('${variable.exportName[0]}',${_}${this.operator}${name})`
`exports('${variable.exportNames[0]}',${_}${this.operator}${name})`
);
} else {
let op;
Expand All @@ -59,7 +59,7 @@ export default class UpdateExpression extends NodeBase {
code.overwrite(
this.start,
this.end,
`(exports('${variable.exportName[0]}',${_}${op}),${_}${name}${this.operator})`
`(exports('${variable.exportNames[0]}',${_}${op}),${_}${name}${this.operator})`
);
}
} else {
Expand Down
16 changes: 5 additions & 11 deletions src/ast/nodes/VariableDeclaration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ import { IncludeChildren, NodeBase } from './shared/Node';
import VariableDeclarator from './VariableDeclarator';

function isReassignedExportsMember(variable: Variable): boolean {
return variable.renderBaseName !== null && variable.exportName !== null && variable.isReassigned;
return variable.renderBaseName !== null && variable.exportNames !== null && variable.isReassigned;
}

function areAllDeclarationsIncludedAndNotExported(declarations: VariableDeclarator[]): boolean {
for (const declarator of declarations) {
if (!declarator.included) return false;
if (declarator.id.type === NodeType.Identifier) {
if (declarator.id.variable!.exportName) return false;
if (declarator.id.variable!.exportNames) return false;
} else {
const exportedVariables: Variable[] = [];
declarator.id.addExportedVariables(exportedVariables);
Expand Down Expand Up @@ -181,17 +181,11 @@ export default class VariableDeclaration extends NodeBase {
const _ = options.compact ? '' : ' ';
if (node.id.type !== NodeType.Identifier) {
node.id.addExportedVariables(systemPatternExports);
} else if (node.id.variable!.safeExportName) {
code.prependLeft(
code.original.indexOf('=', node.id.end) + 1,
` exports('${node.id.variable!.safeExportName}',`
);
nextSeparatorString += ')';
} else if (node.id.variable!.exportName) {
if (node.id.variable!.exportName.length === 1) {
} else if (node.id.variable!.exportNames) {
if (node.id.variable!.exportNames.length === 1) {
code.prependLeft(
code.original.indexOf('=', node.id.end) + 1,
` exports('${node.id.variable!.exportName[0]}',`
` exports('${node.id.variable!.exportNames[0]}',`
);
nextSeparatorString += ')';
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/ast/scopes/ChildScope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export default class ChildScope extends Scope {
for (const variable of this.accessedOutsideVariables.values()) {
if (variable.included) {
usedNames.add(variable.getBaseVariableName());
if (variable.exportName && format === 'system') {
if (variable.exportNames && format === 'system') {
usedNames.add('exports');
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/ast/variables/NamespaceVariable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export default class NamespaceVariable extends Variable {
const name = this.getName();
output = `${options.varOrConst} ${name}${_}=${_}${output};`;

if (options.format === 'system' && this.exportName) {
if (options.format === 'system' && this.exportNames) {
output += `${n}${getSystemExportStatement([this], options)};`;
}

Expand Down
3 changes: 1 addition & 2 deletions src/ast/variables/Variable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { LiteralValueOrUnknown, UnknownValue, UNKNOWN_EXPRESSION } from '../valu

export default class Variable implements ExpressionEntity {
alwaysRendered = false;
exportName: string[] | null = null;
exportNames: string[] | null = null;
included = false;
isId = false;
// both NamespaceVariable and ExternalVariable can be namespaces
Expand All @@ -22,7 +22,6 @@ export default class Variable implements ExpressionEntity {
name: string;
renderBaseName: string | null = null;
renderName: string | null = null;
safeExportName: string | null = null;

constructor(name: string) {
this.name = name;
Expand Down
10 changes: 3 additions & 7 deletions src/utils/systemJsRendering.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,15 @@ export function getSystemExportStatement(
options: RenderOptions
): string {
const _ = options.compact ? '' : ' ';
if (
exportedVariables.length === 1 &&
(exportedVariables[0].safeExportName || exportedVariables[0].exportName?.length === 1)
) {
if (exportedVariables.length === 1 && exportedVariables[0].exportNames?.length === 1) {
return `exports('${
exportedVariables[0].safeExportName || exportedVariables[0].exportName![0]
exportedVariables[0].exportNames[0]
}',${_}${exportedVariables[0].getName()})`;
} else {
return `exports({${exportedVariables
.map(variable => {
if (variable.safeExportName) return `${variable.safeExportName}:${_}${variable.getName()}`;
return variable
.exportName!.map(exportName => `${exportName}:${_}${variable.getName()}`)
.exportNames!.map(exportName => `${exportName}:${_}${variable.getName()}`)
.join(`,${_}`);
})
.join(`,${_}`)}})`;
Expand Down

0 comments on commit 8e50c87

Please sign in to comment.