Skip to content

Commit a71f6ba

Browse files
Continued refactoring for upcoming work
1 parent c7da4ba commit a71f6ba

File tree

3 files changed

+14
-31
lines changed

3 files changed

+14
-31
lines changed

src/parsing/export-details.ts

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,34 +18,27 @@ import { ExportNamedDeclaration, ExportDefaultDeclaration } from 'estree';
1818
import { ExportDetails, Range, ExportClosureMapping } from '../types';
1919

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

25-
if (declaration.specifiers) {
26-
const exportDetails: Array<ExportDetails> = [];
27-
28-
for (const specifier of declaration.specifiers) {
29-
exportDetails.push({
30-
local: specifier.local.name,
31-
exported: specifier.exported.name,
32-
closureName: specifier.exported.name,
33-
type: ExportClosureMapping.NAMED_CONSTANT,
34-
range,
35-
source,
36-
});
37-
}
38-
39-
return exportDetails;
25+
for (const specifier of declaration.specifiers) {
26+
exportDetails.push({
27+
local: specifier.local.name,
28+
exported: specifier.exported.name,
29+
closureName: specifier.exported.name,
30+
type: ExportClosureMapping.NAMED_CONSTANT,
31+
range: declaration.range as Range,
32+
source,
33+
});
4034
}
4135

42-
return [];
36+
return exportDetails;
4337
}
4438

4539
export function DefaultDeclaration(
4640
defaultDeclaration: ExportDefaultDeclaration,
4741
): Array<ExportDetails> {
48-
const range: Range = defaultDeclaration.range as Range;
4942
const { declaration } = defaultDeclaration;
5043

5144
if (declaration.type === 'Identifier' && declaration.name) {
@@ -55,7 +48,7 @@ export function DefaultDeclaration(
5548
exported: declaration.name,
5649
closureName: declaration.name,
5750
type: ExportClosureMapping.NAMED_DEFAULT_FUNCTION,
58-
range,
51+
range: defaultDeclaration.range as Range,
5952
source: null,
6053
},
6154
];

src/parsing/literal-name.ts

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,9 @@
1414
* limitations under the License.
1515
*/
1616

17-
import { PluginContext } from 'rollup';
1817
import { Literal, SimpleLiteral } from 'estree';
1918

20-
export function literalName(context: PluginContext, literal: Literal): string {
21-
// Literal can either be a SimpleLiteral, or RegExpLiteral
22-
if ('regex' in literal) {
23-
// This is a RegExpLiteral
24-
context.warn(
25-
'Rollup Plugin Closure Compiler found a Regex Literal Named Import. `import foo from "*/.hbs"`',
26-
);
27-
return '';
28-
}
29-
19+
export function literalName(literal: Literal): string {
3020
const literalValue = (literal as SimpleLiteral).value;
3121
return typeof literalValue === 'string' ? literalValue : '';
3222
}

src/transformers/imports.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ window['${DYNAMIC_IMPORT_REPLACEMENT}'] = ${DYNAMIC_IMPORT_REPLACEMENT};`;
102102

103103
walk.simple(program, {
104104
async ImportDeclaration(node: ImportDeclaration) {
105-
const name = literalName(self.context, node.source);
105+
const name = literalName(node.source);
106106
const range: Range = node.range as Range;
107107

108108
let defaultSpecifier: string | null = null;

0 commit comments

Comments
 (0)