Skip to content

Commit a8e0a47

Browse files
committed
remove eval format - closes #2084
1 parent 15931af commit a8e0a47

File tree

3 files changed

+3
-117
lines changed

3 files changed

+3
-117
lines changed

src/compile/Component.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,6 @@ export default class Component {
226226
format,
227227
name,
228228
compileOptions,
229-
this.stats,
230229
banner,
231230
compileOptions.sveltePath,
232231
importedHelpers,

src/compile/wrapModule.ts

Lines changed: 2 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
import deindent from '../utils/deindent';
22
import list from '../utils/list';
33
import { CompileOptions, ModuleFormat, Node } from '../interfaces';
4-
import Stats from '../Stats';
54

65
interface Dependency {
76
name: string;
87
statements: string[];
98
source: string;
109
}
1110

12-
const wrappers = { esm, cjs, eval: expr };
11+
const wrappers = { esm, cjs };
1312

1413
type Export = {
1514
name: string;
@@ -21,7 +20,6 @@ export default function wrapModule(
2120
format: ModuleFormat,
2221
name: string,
2322
options: CompileOptions,
24-
stats: Stats,
2523
banner: string,
2624
sveltePath = 'svelte',
2725
helpers: { name: string, alias: string }[],
@@ -36,7 +34,6 @@ export default function wrapModule(
3634
}
3735

3836
if (format === 'cjs') return cjs(code, name, banner, sveltePath, internalPath, helpers, imports, module_exports);
39-
if (format === 'eval') return expr(code, name, options, stats, banner, imports);
4037

4138
throw new Error(`options.format is invalid (must be ${list(Object.keys(wrappers))})`);
4239
}
@@ -142,114 +139,4 @@ function cjs(
142139
${code}
143140
144141
${exports}`
145-
}
146-
147-
function expr(
148-
code: string,
149-
name: string,
150-
options: CompileOptions,
151-
stats: Stats,
152-
banner: string,
153-
imports: Node[]
154-
) {
155-
const dependencies = imports.map((declaration, i) => {
156-
const defaultImport = declaration.specifiers.find(
157-
(x: Node) =>
158-
x.type === 'ImportDefaultSpecifier' ||
159-
(x.type === 'ImportSpecifier' && x.imported.name === 'default')
160-
);
161-
162-
const namespaceImport = declaration.specifiers.find(
163-
(x: Node) => x.type === 'ImportNamespaceSpecifier'
164-
);
165-
166-
const namedImports = declaration.specifiers.filter(
167-
(x: Node) =>
168-
x.type === 'ImportSpecifier' && x.imported.name !== 'default'
169-
);
170-
171-
const name = defaultImport || namespaceImport
172-
? (defaultImport || namespaceImport).local.name
173-
: `__import${i}`;
174-
175-
const statements: string[] = [];
176-
177-
namedImports.forEach((specifier: Node) => {
178-
statements.push(
179-
`var ${specifier.local.name} = ${name}.${specifier.imported.name};`
180-
);
181-
});
182-
183-
if (defaultImport) {
184-
statements.push(
185-
`${name} = (${name} && ${name}.__esModule) ? ${name}["default"] : ${name};`
186-
);
187-
}
188-
189-
return { name, statements, source: declaration.source.value };
190-
});
191-
192-
const globals = getGlobals(dependencies, options, stats);
193-
194-
return deindent`
195-
(function (${paramString(dependencies)}) { "use strict";
196-
${banner}
197-
198-
${getCompatibilityStatements(dependencies)}
199-
200-
${code}
201-
202-
return ${name};
203-
}(${globals.join(', ')}))`;
204-
}
205-
206-
function paramString(dependencies: Dependency[]) {
207-
return dependencies.map(dep => dep.name).join(', ');
208-
}
209-
210-
function getCompatibilityStatements(dependencies: Dependency[]) {
211-
if (!dependencies.length) return null;
212-
213-
const statements: string[] = [];
214-
215-
dependencies.forEach(dependency => {
216-
statements.push(...dependency.statements);
217-
});
218-
219-
return statements.join('\n');
220-
}
221-
222-
function getGlobals(dependencies: Dependency[], options: CompileOptions, stats: Stats) {
223-
const { globals } = options;
224-
const globalFn = getGlobalFn(globals);
225-
226-
return dependencies.map(d => {
227-
let name = globalFn(d.source);
228-
229-
if (!name) {
230-
if (d.name.startsWith('__import')) {
231-
throw new Error(
232-
`Could not determine name for imported module '${d.source}' – use options.globals`
233-
);
234-
} else {
235-
stats.warn({
236-
code: `options-missing-globals`,
237-
message: `No name was supplied for imported module '${d.source}'. Guessing '${d.name}', but you should use options.globals`,
238-
});
239-
}
240-
241-
name = d.name;
242-
}
243-
244-
return name;
245-
});
246-
}
247-
248-
function getGlobalFn(globals: any): (id: string) => string {
249-
if (typeof globals === 'function') return globals;
250-
if (typeof globals === 'object') {
251-
return id => globals[id];
252-
}
253-
254-
return () => undefined;
255-
}
142+
}

src/interfaces.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export interface Warning {
3636
toString: () => string;
3737
}
3838

39-
export type ModuleFormat = 'esm' | 'cjs' | 'eval';
39+
export type ModuleFormat = 'esm' | 'cjs';
4040

4141
export interface CompileOptions {
4242
format?: ModuleFormat;

0 commit comments

Comments
 (0)