Skip to content

Commit cc3b8f9

Browse files
committed
get tests to pass
1 parent 76ed968 commit cc3b8f9

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

index.js

+8-6
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ function deprecatePreprocessOptions(options) {
7979
const virtualModuleInstances = new Map();
8080

8181
module.exports = function(source, map) {
82-
if (!virtualModuleInstances.has(this._compiler)) {
82+
if (this._compiler && !virtualModuleInstances.has(this._compiler)) {
8383
virtualModuleInstances.set(this._compiler, new VirtualModules(this._compiler));
8484
}
8585

@@ -94,10 +94,10 @@ module.exports = function(source, map) {
9494
const isProduction = this.minimize || process.env.NODE_ENV === 'production';
9595

9696
options.filename = this.resourcePath;
97-
if (!options.format) options.format = 'es';
98-
if (!options.shared) options.shared = options.format === 'es' && 'svelte/shared.js';
99-
if (!options.name) options.name = capitalize(sanitize(options.filename));
100-
if (!options.onwarn) options.onwarn = warning => this.emitWarning(new Error(warning));
97+
if (!('format' in options)) options.format = 'es';
98+
if (!('shared' in options)) options.shared = options.format === 'es' && 'svelte/shared.js';
99+
if (!('name' in options)) options.name = capitalize(sanitize(options.filename));
100+
if (!('onwarn' in options)) options.onwarn = warning => this.emitWarning(new Error(warning));
101101
if (options.emitCss) options.css = false;
102102

103103
deprecatePreprocessOptions(options);
@@ -120,7 +120,9 @@ module.exports = function(source, map) {
120120
css.code += '\n/*# sourceMappingURL=' + css.map.toUrl() + '*/';
121121
js.code = js.code + `\nimport '${cssFilepath}';\n`;
122122

123-
virtualModules.writeModule(cssFilepath, css.code);
123+
if (virtualModules) {
124+
virtualModules.writeModule(cssFilepath, css.code);
125+
}
124126
}
125127

126128
callback(null, js.code, js.map);

test/loader.spec.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ describe('loader', () => {
191191
expect(code).not.to.contain('import {');
192192
expect(code).not.to.contain('svelte/shared.js');
193193
},
194-
{},
194+
{ shared: false },
195195
1
196196
)
197197
);
@@ -260,7 +260,7 @@ describe('loader', () => {
260260
function(err, code, map) {
261261
expect(err).not.to.exist;
262262

263-
expect(code).to.match(/require\('.+\.css'\);/);
263+
expect(code).to.match(/import '.+\.css';/);
264264
},
265265
{ emitCss: true }
266266
)

0 commit comments

Comments
 (0)