Skip to content

Commit

Permalink
Continued refactoring for upcoming work
Browse files Browse the repository at this point in the history
  • Loading branch information
kristoferbaxter committed Jan 8, 2020
1 parent c7da4ba commit a71f6ba
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 31 deletions.
31 changes: 12 additions & 19 deletions src/parsing/export-details.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,34 +18,27 @@ import { ExportNamedDeclaration, ExportDefaultDeclaration } from 'estree';
import { ExportDetails, Range, ExportClosureMapping } from '../types';

export function NamedDeclaration(declaration: ExportNamedDeclaration): Array<ExportDetails> {
const range: Range = declaration.range as Range;
const exportDetails: Array<ExportDetails> = [];
const source: string | null =
typeof declaration?.source?.value === 'string' ? declaration.source.value : null;

if (declaration.specifiers) {
const exportDetails: Array<ExportDetails> = [];

for (const specifier of declaration.specifiers) {
exportDetails.push({
local: specifier.local.name,
exported: specifier.exported.name,
closureName: specifier.exported.name,
type: ExportClosureMapping.NAMED_CONSTANT,
range,
source,
});
}

return exportDetails;
for (const specifier of declaration.specifiers) {
exportDetails.push({
local: specifier.local.name,
exported: specifier.exported.name,
closureName: specifier.exported.name,
type: ExportClosureMapping.NAMED_CONSTANT,
range: declaration.range as Range,
source,
});
}

return [];
return exportDetails;
}

export function DefaultDeclaration(
defaultDeclaration: ExportDefaultDeclaration,
): Array<ExportDetails> {
const range: Range = defaultDeclaration.range as Range;
const { declaration } = defaultDeclaration;

if (declaration.type === 'Identifier' && declaration.name) {
Expand All @@ -55,7 +48,7 @@ export function DefaultDeclaration(
exported: declaration.name,
closureName: declaration.name,
type: ExportClosureMapping.NAMED_DEFAULT_FUNCTION,
range,
range: defaultDeclaration.range as Range,
source: null,
},
];
Expand Down
12 changes: 1 addition & 11 deletions src/parsing/literal-name.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,9 @@
* limitations under the License.
*/

import { PluginContext } from 'rollup';
import { Literal, SimpleLiteral } from 'estree';

export function literalName(context: PluginContext, literal: Literal): string {
// Literal can either be a SimpleLiteral, or RegExpLiteral
if ('regex' in literal) {
// This is a RegExpLiteral
context.warn(
'Rollup Plugin Closure Compiler found a Regex Literal Named Import. `import foo from "*/.hbs"`',
);
return '';
}

export function literalName(literal: Literal): string {
const literalValue = (literal as SimpleLiteral).value;
return typeof literalValue === 'string' ? literalValue : '';
}
2 changes: 1 addition & 1 deletion src/transformers/imports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ window['${DYNAMIC_IMPORT_REPLACEMENT}'] = ${DYNAMIC_IMPORT_REPLACEMENT};`;

walk.simple(program, {
async ImportDeclaration(node: ImportDeclaration) {
const name = literalName(self.context, node.source);
const name = literalName(node.source);
const range: Range = node.range as Range;

let defaultSpecifier: string | null = null;
Expand Down

0 comments on commit a71f6ba

Please sign in to comment.