From e84b4aca9279b7aaff8b46ca425cc58c44ac81a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C2=A7Domenik=20Reitzner?= Date: Wed, 29 Apr 2020 00:46:14 +0200 Subject: [PATCH] fix prefix generation and test cases --- src/compiler/compile/index.ts | 3 ++- src/compiler/compile/utils/get_prefix.ts | 2 +- .../custom-prefix-has-only-disallowed-characters/expected.css | 2 +- .../samples/custom-prefix-has-special-character/expected.css | 2 +- test/css/samples/custom-prefix-has-whitespace/expected.css | 2 +- test/css/samples/custom-prefix-no-string/expected.css | 2 +- test/css/samples/custom-prefix-starts-with-number/expected.css | 2 +- .../samples/custom-prefix-starts-with-whitespace/expected.css | 2 +- test/css/samples/custom-prefix/expected.css | 2 +- 9 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/compiler/compile/index.ts b/src/compiler/compile/index.ts index 12b161aeeb..cff688b09c 100644 --- a/src/compiler/compile/index.ts +++ b/src/compiler/compile/index.ts @@ -26,7 +26,8 @@ const valid_options = [ 'css', 'loopGuardTimeout', 'preserveComments', - 'preserveWhitespace' + 'preserveWhitespace', + 'prefix', ]; function validate_options(options: CompileOptions, warnings: Warning[]) { diff --git a/src/compiler/compile/utils/get_prefix.ts b/src/compiler/compile/utils/get_prefix.ts index 9ea0f7fdaa..cec805115f 100644 --- a/src/compiler/compile/utils/get_prefix.ts +++ b/src/compiler/compile/utils/get_prefix.ts @@ -2,7 +2,7 @@ export default function get_prefix(str?: string): string { const standard_prefix = 'svelte-'; if (!str || typeof str !== 'string') return standard_prefix; - str = str.replace(/^[^_-a-z]+|[^_-a-z0-9]/gi, ''); + str = str.replace(/^[^_\-a-z]+|[^_\-a-z0-9]/gi, ''); return str.length ? str : standard_prefix; diff --git a/test/css/samples/custom-prefix-has-only-disallowed-characters/expected.css b/test/css/samples/custom-prefix-has-only-disallowed-characters/expected.css index 5e31d0bc6b..7d3ce1908f 100644 --- a/test/css/samples/custom-prefix-has-only-disallowed-characters/expected.css +++ b/test/css/samples/custom-prefix-has-only-disallowed-characters/expected.css @@ -1 +1 @@ -div.svelte-xyz{color:blue} \ No newline at end of file +div.svelte-1tjtw78{color:blue} \ No newline at end of file diff --git a/test/css/samples/custom-prefix-has-special-character/expected.css b/test/css/samples/custom-prefix-has-special-character/expected.css index 2af15fb797..5337b4fa44 100644 --- a/test/css/samples/custom-prefix-has-special-character/expected.css +++ b/test/css/samples/custom-prefix-has-special-character/expected.css @@ -1 +1 @@ -div.me-xyz{color:blue} \ No newline at end of file +div.me-1tjtw78{color:blue} \ No newline at end of file diff --git a/test/css/samples/custom-prefix-has-whitespace/expected.css b/test/css/samples/custom-prefix-has-whitespace/expected.css index 2af15fb797..5337b4fa44 100644 --- a/test/css/samples/custom-prefix-has-whitespace/expected.css +++ b/test/css/samples/custom-prefix-has-whitespace/expected.css @@ -1 +1 @@ -div.me-xyz{color:blue} \ No newline at end of file +div.me-1tjtw78{color:blue} \ No newline at end of file diff --git a/test/css/samples/custom-prefix-no-string/expected.css b/test/css/samples/custom-prefix-no-string/expected.css index 5e31d0bc6b..7d3ce1908f 100644 --- a/test/css/samples/custom-prefix-no-string/expected.css +++ b/test/css/samples/custom-prefix-no-string/expected.css @@ -1 +1 @@ -div.svelte-xyz{color:blue} \ No newline at end of file +div.svelte-1tjtw78{color:blue} \ No newline at end of file diff --git a/test/css/samples/custom-prefix-starts-with-number/expected.css b/test/css/samples/custom-prefix-starts-with-number/expected.css index 2af15fb797..5337b4fa44 100644 --- a/test/css/samples/custom-prefix-starts-with-number/expected.css +++ b/test/css/samples/custom-prefix-starts-with-number/expected.css @@ -1 +1 @@ -div.me-xyz{color:blue} \ No newline at end of file +div.me-1tjtw78{color:blue} \ No newline at end of file diff --git a/test/css/samples/custom-prefix-starts-with-whitespace/expected.css b/test/css/samples/custom-prefix-starts-with-whitespace/expected.css index 2af15fb797..5337b4fa44 100644 --- a/test/css/samples/custom-prefix-starts-with-whitespace/expected.css +++ b/test/css/samples/custom-prefix-starts-with-whitespace/expected.css @@ -1 +1 @@ -div.me-xyz{color:blue} \ No newline at end of file +div.me-1tjtw78{color:blue} \ No newline at end of file diff --git a/test/css/samples/custom-prefix/expected.css b/test/css/samples/custom-prefix/expected.css index 2af15fb797..5337b4fa44 100644 --- a/test/css/samples/custom-prefix/expected.css +++ b/test/css/samples/custom-prefix/expected.css @@ -1 +1 @@ -div.me-xyz{color:blue} \ No newline at end of file +div.me-1tjtw78{color:blue} \ No newline at end of file