fix: use object type

pull/6835/head
bluwy 5 years ago
parent 797818dc15
commit ea2854ae73

@ -83,7 +83,7 @@ The following options can be passed to the compiler. None are required:
| `preserveComments` | `false` | If `true`, your HTML comments will be preserved during server-side rendering. By default, they are stripped out. | `preserveComments` | `false` | If `true`, your HTML comments will be preserved during server-side rendering. By default, they are stripped out.
| `preserveWhitespace` | `false` | If `true`, whitespace inside and between elements is kept as you typed it, rather than removed or collapsed to a single space where possible. | `preserveWhitespace` | `false` | If `true`, whitespace inside and between elements is kept as you typed it, rather than removed or collapsed to a single space where possible.
| `sourcemap` | `object | string` | An initial sourcemap that will be merged into the final output sourcemap. This is usually the preprocessor sourcemap. | `sourcemap` | `object | string` | An initial sourcemap that will be merged into the final output sourcemap. This is usually the preprocessor sourcemap.
| `enableSourcemap` | `boolean | 'js' | 'css'` | If `true`, Svelte generate sourcemaps for components. Use `js` or `css` for more granular control of sourcemap generation. By default, this is `true`. | `enableSourcemap` | `boolean | { js: boolean; css: boolean; }` | If `true`, Svelte generate sourcemaps for components. Use an object with `js` or `css` for more granular control of sourcemap generation. By default, this is `true`.
| `outputFilename` | `null` | A `string` used for your JavaScript sourcemap. | `outputFilename` | `null` | A `string` used for your JavaScript sourcemap.
| `cssOutputFilename` | `null` | A `string` used for your CSS sourcemap. | `cssOutputFilename` | `null` | A `string` used for your CSS sourcemap.
| `sveltePath` | `"svelte"` | The location of the `svelte` package. Any imports from `svelte` or `svelte/[module]` will be modified accordingly. | `sveltePath` | `"svelte"` | The location of the `svelte` package. Any imports from `svelte` or `svelte/[module]` will be modified accordingly.

@ -36,6 +36,7 @@ import { clone } from '../utils/clone';
import compiler_warnings from './compiler_warnings'; import compiler_warnings from './compiler_warnings';
import compiler_errors from './compiler_errors'; import compiler_errors from './compiler_errors';
import { extract_ignores_above_position, extract_svelte_ignore_from_comments } from '../utils/extract_svelte_ignore'; import { extract_ignores_above_position, extract_svelte_ignore_from_comments } from '../utils/extract_svelte_ignore';
import check_enable_sourcemap from './utils/check_enable_sourcemap';
interface ComponentOptions { interface ComponentOptions {
namespace?: string; namespace?: string;
@ -343,7 +344,7 @@ export default class Component {
? { code: null, map: null } ? { code: null, map: null }
: result.css; : result.css;
const jsSourcemapEnabled = compile_options.enableSourcemap === true || compile_options.enableSourcemap === 'js'; const jsSourcemapEnabled = check_enable_sourcemap(compile_options.enableSourcemap, 'js');
if (!jsSourcemapEnabled) { if (!jsSourcemapEnabled) {
js = print(program); js = print(program);

@ -10,6 +10,7 @@ import { ImportDeclaration, ClassDeclaration, FunctionExpression, Node, Statemen
import { apply_preprocessor_sourcemap } from '../../utils/mapped_code'; import { apply_preprocessor_sourcemap } from '../../utils/mapped_code';
import { RawSourceMap, DecodedSourceMap } from '@ampproject/remapping/dist/types/types'; import { RawSourceMap, DecodedSourceMap } from '@ampproject/remapping/dist/types/types';
import { flatten } from '../../utils/flatten'; import { flatten } from '../../utils/flatten';
import check_enable_sourcemap from '../utils/check_enable_sourcemap';
export default function dom( export default function dom(
component: Component, component: Component,
@ -34,7 +35,7 @@ export default function dom(
const css = component.stylesheet.render(options.filename, !options.customElement); const css = component.stylesheet.render(options.filename, !options.customElement);
const cssSourcemapEnabled = options.enableSourcemap === true || options.enableSourcemap === 'css'; const cssSourcemapEnabled = check_enable_sourcemap(options.enableSourcemap, 'css');
if (cssSourcemapEnabled) { if (cssSourcemapEnabled) {
css.map = apply_preprocessor_sourcemap(options.filename, css.map, options.sourcemap as string | RawSourceMap | DecodedSourceMap); css.map = apply_preprocessor_sourcemap(options.filename, css.map, options.sourcemap as string | RawSourceMap | DecodedSourceMap);

@ -10,6 +10,7 @@ import { extract_names } from 'periscopic';
import { walk } from 'estree-walker'; import { walk } from 'estree-walker';
import { invalidate } from '../render_dom/invalidate'; import { invalidate } from '../render_dom/invalidate';
import check_enable_sourcemap from '../utils/check_enable_sourcemap';
export default function ssr( export default function ssr(
component: Component, component: Component,
@ -200,7 +201,7 @@ export default function ssr(
main main
].filter(Boolean); ].filter(Boolean);
const cssSourcemapEnabled = options.enableSourcemap === true || options.enableSourcemap === 'css'; const cssSourcemapEnabled = check_enable_sourcemap(options.enableSourcemap, 'css');
const js = b` const js = b`
${css.code ? b` ${css.code ? b`

@ -0,0 +1,10 @@
import { EnableSourcemap } from '../../interfaces';
export default function check_enable_sourcemap(
enable_sourcemap: EnableSourcemap,
namespace: keyof Extract<EnableSourcemap, object>
) {
return typeof enable_sourcemap === 'boolean'
? enable_sourcemap
: enable_sourcemap[namespace];
}

@ -131,6 +131,8 @@ export interface Warning {
export type ModuleFormat = 'esm' | 'cjs'; export type ModuleFormat = 'esm' | 'cjs';
export type EnableSourcemap = boolean | { js: boolean; css: boolean };
export type CssHashGetter = (args: { export type CssHashGetter = (args: {
name: string; name: string;
filename: string | undefined; filename: string | undefined;
@ -147,7 +149,7 @@ export interface CompileOptions {
varsReport?: 'full' | 'strict' | false; varsReport?: 'full' | 'strict' | false;
sourcemap?: object | string; sourcemap?: object | string;
enableSourcemap?: boolean | 'js' | 'css'; enableSourcemap?: EnableSourcemap;
outputFilename?: string; outputFilename?: string;
cssOutputFilename?: string; cssOutputFilename?: string;
sveltePath?: string; sveltePath?: string;

@ -1,5 +1,5 @@
export default { export default {
compile_options: { compile_options: {
enableSourcemap: 'css' enableSourcemap: { css: true }
} }
}; };

@ -1,5 +1,5 @@
export default { export default {
compile_options: { compile_options: {
enableSourcemap: 'js' enableSourcemap: { js: true }
} }
}; };

Loading…
Cancel
Save