Skip to content

Commit 2201da1

Browse files
committed
Drop Svelte 2 support
1 parent c4ca347 commit 2201da1

File tree

1 file changed

+7
-34
lines changed

1 file changed

+7
-34
lines changed

index.js

+7-34
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,7 @@ const VirtualModules = require('./lib/virtual');
44

55
const hotApi = require.resolve('./lib/hot-api.js');
66

7-
const { version } = require('svelte/package.json');
8-
const major_version = +version[0];
9-
const { compile, preprocess } = major_version >= 3
10-
? require('svelte/compiler')
11-
: require('svelte');
7+
const { compile, preprocess } = require('svelte/compiler');
128

139
const pluginOptions = {
1410
externalDependencies: true,
@@ -53,19 +49,6 @@ function posixify(file) {
5349
return file.replace(/[/\\]/g, '/');
5450
}
5551

56-
function sanitize(input) {
57-
return basename(input)
58-
.replace(extname(input), '')
59-
.replace(/[^a-zA-Z_$0-9]+/g, '_')
60-
.replace(/^_/, '')
61-
.replace(/_$/, '')
62-
.replace(/^(\d)/, '_$1');
63-
}
64-
65-
function capitalize(str) {
66-
return str[0].toUpperCase() + str.slice(1);
67-
}
68-
6952
function normalize(compiled) {
7053
// svelte.compile signature changed in 1.60 — this avoids
7154
// future deprecation warnings while preserving backwards
@@ -115,19 +98,11 @@ module.exports = function(source, map) {
11598

11699
const compileOptions = {
117100
filename: this.resourcePath,
118-
format: options.format || (major_version >= 3 ? 'esm' : 'es')
101+
format: options.format || 'esm'
119102
};
120103

121104
const handleWarning = warning => this.emitWarning(new Error(warning));
122105

123-
if (major_version >= 3) {
124-
// TODO anything?
125-
} else {
126-
compileOptions.shared = options.shared || 'svelte/shared.js';
127-
compileOptions.name = capitalize(sanitize(compileOptions.filename));
128-
compileOptions.onwarn = options.onwarn || handleWarning;
129-
}
130-
131106
for (const option in options) {
132107
if (!pluginOptions[option]) compileOptions[option] = options[option];
133108
}
@@ -146,13 +121,11 @@ module.exports = function(source, map) {
146121

147122
let { js, css, warnings } = normalize(compile(processed.toString(), compileOptions));
148123

149-
if (major_version >= 3) {
150-
warnings.forEach(
151-
options.onwarn
152-
? warning => options.onwarn(warning, handleWarning)
153-
: handleWarning
154-
);
155-
}
124+
warnings.forEach(
125+
options.onwarn
126+
? warning => options.onwarn(warning, handleWarning)
127+
: handleWarning
128+
);
156129

157130
if (options.hotReload && !isProduction && !isServer) {
158131
const hotOptions = Object.assign({}, options.hotOptions);

0 commit comments

Comments
 (0)