Skip to content

Commit efc1bff

Browse files
authored
Merge pull request #51 from sveltejs/gh-41
deprecate options.style etc
2 parents 9e6f47a + c37b7cf commit efc1bff

File tree

2 files changed

+58
-8
lines changed

2 files changed

+58
-8
lines changed

index.js

+21-1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,23 @@ function normalize(compiled) {
6363
return { js, css, ast: compiled.ast };
6464
}
6565

66+
const warned = {};
67+
function deprecatePreprocessOptions(options) {
68+
const preprocessOptions = {};
69+
70+
['markup', 'style', 'script'].forEach(kind => {
71+
if (options[kind]) {
72+
if (!warned[kind]) {
73+
console.warn(`[svelte-loader] DEPRECATION: options.${kind} is now options.preprocess.${kind}`);
74+
warned[kind] = true;
75+
}
76+
preprocessOptions[kind] = options[kind];
77+
}
78+
});
79+
80+
options.preprocess = options.preprocess || preprocessOptions;
81+
}
82+
6683
module.exports = function(source, map) {
6784
this.cacheable();
6885

@@ -86,7 +103,10 @@ module.exports = function(source, map) {
86103

87104
if (!options.onwarn) options.onwarn = warning => this.emitWarning(new Error(warning));
88105

89-
preprocess(source, options).then(processed => {
106+
deprecatePreprocessOptions(options);
107+
options.preprocess.filename = options.filename;
108+
109+
preprocess(source, options.preprocess).then(processed => {
90110
let { js, css, ast } = normalize(compile(processed.toString(), options));
91111

92112
if (options.emitCss && css.code) {

test/loader.spec.js

+37-7
Original file line numberDiff line numberDiff line change
@@ -294,10 +294,12 @@ describe('loader', () => {
294294
});
295295
const callbackSpy = spy(cb);
296296
const options = {
297-
style: ({ content }) => {
298-
return {
299-
code: content.replace(/\$size/gi, '50px'),
300-
};
297+
preprocess: {
298+
style: ({ content }) => {
299+
return {
300+
code: content.replace(/\$size/gi, '50px'),
301+
};
302+
}
301303
},
302304
};
303305

@@ -321,9 +323,11 @@ describe('loader', () => {
321323
const cacheableSpy = spy(() => {
322324
});
323325
const options = {
324-
style: () => {
325-
throw new Error('Error while preprocessing');
326-
},
326+
preprocess: {
327+
style: () => {
328+
throw new Error('Error while preprocessing');
329+
}
330+
}
327331
};
328332

329333
loader.call(
@@ -342,6 +346,32 @@ describe('loader', () => {
342346
});
343347
});
344348

349+
350+
describe('deprecations', () => {
351+
it('should warn on options.style', done => {
352+
const { warn } = console;
353+
const warnings = [];
354+
355+
console.warn = (msg) => {
356+
warnings.push(msg);
357+
};
358+
359+
testLoader('test/fixtures/style-valid.html', (err, code, map) => {
360+
expect(code).to.contain('50px');
361+
expect(warnings).to.deep.equal([
362+
'[svelte-loader] DEPRECATION: options.style is now options.preprocess.style'
363+
]);
364+
console.warn = warn;
365+
}, {
366+
style: ({ content }) => {
367+
return {
368+
code: content.replace(/\$size/gi, '50px'),
369+
};
370+
}
371+
})(done);
372+
});
373+
});
374+
345375
describe('hotReload', () => {
346376
it(
347377
'should configure hotReload=false (default)',

0 commit comments

Comments
 (0)