+
-
+
%sapper.base%
diff --git a/site/src/utils/slug.js b/site/src/utils/slug.js
index 4ad7b96b2a..79b82c12ce 100644
--- a/site/src/utils/slug.js
+++ b/site/src/utils/slug.js
@@ -1,14 +1,20 @@
-import limax from 'limax';
-import {SLUG_LANG, SLUG_SEPARATOR} from '../../config';
+import slugify from '@sindresorhus/slugify';
+import {SLUG_SEPARATOR} from '../../config';
-/* latinizer processor */
+/* url-safe processor */
-export const limaxProcessor = (string, lang = SLUG_LANG) => limax(string, {
- custom: ['$'],
- separator: SLUG_SEPARATOR,
- maintainCase: true,
- lang
-});
+export const urlsafeSlugProcessor = string =>
+ slugify(string, {
+ customReplacements: [ // runs before any other transformations
+ ['$', 'DOLLAR'], // `$destroy` & co
+ ['-', 'DASH'], // conflicts with `separator`
+ ],
+ separator: SLUG_SEPARATOR,
+ decamelize: false,
+ lowercase: false
+ })
+ .replace(/DOLLAR/g, '$')
+ .replace(/DASH/g, '-');
/* unicode-preserver processor */
@@ -40,7 +46,7 @@ export const unicodeSafeProcessor = string =>
.chunks
.reduce((accum, chunk) => {
const processed = chunk.type === 'process'
- ? limaxProcessor(chunk.string)
+ ? urlsafeSlugProcessor(chunk.string)
: chunk.string;
processed.length > 0 && accum.push(processed);
@@ -52,7 +58,7 @@ export const unicodeSafeProcessor = string =>
/* session processor */
export const makeSessionSlugProcessor = (preserveUnicode = false) => {
- const processor = preserveUnicode ? unicodeSafeProcessor : limaxProcessor;
+ const processor = preserveUnicode ? unicodeSafeProcessor : urlsafeSlugProcessor;
const seen = new Set();
return string => {
diff --git a/site/test/utils/slug.js b/site/test/utils/slug.js
index c6d6c96685..17262c5e83 100644
--- a/site/test/utils/slug.js
+++ b/site/test/utils/slug.js
@@ -1,61 +1,61 @@
import {strict as assert} from 'assert';
-import {limaxProcessor, unicodeSafeProcessor} from '../../src/utils/slug';
-import {SLUG_SEPARATOR as _, SLUG_LANG} from '../../config';
+import {urlsafeSlugProcessor, unicodeSafeProcessor} from '../../src/utils/slug';
+import {SLUG_SEPARATOR as _} from '../../config';
describe('slug', () => {
- describe('limaxProcessor (latinize unicode)', () => {
+ describe('urlsafeSlugProcessor', () => {
describe('ascii', () => {
it('space separated words', () => {
assert.equal(
- limaxProcessor('Text expressions'),
- `text${_}expressions`
+ urlsafeSlugProcessor('Text expressions'),
+ `Text${_}expressions`
);
});
it('numbered text', () => {
assert.equal(
- limaxProcessor('1. export creates'),
+ urlsafeSlugProcessor('1. export creates'),
`1${_}export${_}creates`
);
});
it('punctuated text', () => {
assert.equal(
- limaxProcessor('svelte.VERSION'),
- `svelte${_}version`
+ urlsafeSlugProcessor('svelte.VERSION'),
+ `svelte${_}VERSION`
);
});
it('text starting with the dollar sign', () => {
assert.equal(
- limaxProcessor('$destroy method'),
+ urlsafeSlugProcessor('$destroy method'),
`$destroy${_}method`
);
});
it('numbered text containing the dollar sign', () => {
assert.equal(
- limaxProcessor('1. export $destroy'),
+ urlsafeSlugProcessor('1. export $destroy'),
`1${_}export${_}$destroy`
);
});
it('text containing the equal char', () => {
assert.equal(
- limaxProcessor('script context=module'),
+ urlsafeSlugProcessor('script context=module'),
`script${_}context${_}module`
);
});
it('text containing the colon char', () => {
assert.equal(
- limaxProcessor('svelte:body'),
+ urlsafeSlugProcessor('svelte:body'),
`svelte${_}body`
);
});
it('text containing the slash char', () => {
assert.equal(
- limaxProcessor('svelte/motion'),
+ urlsafeSlugProcessor('svelte/motion'),
`svelte${_}motion`
);
});
it('text containing the comma char', () => {
assert.equal(
- limaxProcessor('svelte, motion'),
+ urlsafeSlugProcessor('svelte, motion'),
`svelte${_}motion`
);
});
@@ -63,156 +63,150 @@ describe('slug', () => {
describe('unicode', () => {
it('should translate symbols to English', () => {
assert.equal(
- limaxProcessor('Ich ♥ Deutsch'),
- `ich${_}love${_}deutsch`
+ urlsafeSlugProcessor('Ich ♥ Deutsch'),
+ `Ich${_}love${_}Deutsch`
);
});
it('should remove emoji', () => {
assert.equal(
- limaxProcessor('Ich 😍 Deutsch'),
- `ich${_}deutsch`
- );
- });
- it('should translate symbols to the given language (German)', () => {
- assert.equal(
- limaxProcessor('Ich ♥ Deutsch', 'de'),
- `ich${_}liebe${_}deutsch`
+ urlsafeSlugProcessor('Ich 😍 Deutsch'),
+ `Ich${_}Deutsch`
);
});
});
describe('cyricllic', () => {
it('space separated words', () => {
assert.equal(
- limaxProcessor('Всплытие и перехват событий'),
- `vsplytie${_}i${_}perekhvat${_}sobytii`
+ urlsafeSlugProcessor('Всплытие и перехват событий'),
+ `Vsplytie${_}i${_}perehvat${_}sobytij`
);
});
it('numbered text', () => {
assert.equal(
- limaxProcessor('1 Всплытие и перехват событий'),
- `1${_}vsplytie${_}i${_}perekhvat${_}sobytii`
+ urlsafeSlugProcessor('1 Всплытие и перехват событий'),
+ `1${_}Vsplytie${_}i${_}perehvat${_}sobytij`
);
});
it('punctuated text', () => {
assert.equal(
- limaxProcessor('.Всплытие.и.перехват событий'),
- `vsplytie${_}i${_}perekhvat${_}sobytii`
+ urlsafeSlugProcessor('.Всплытие.и.перехват событий'),
+ `Vsplytie${_}i${_}perehvat${_}sobytij`
);
});
it('text starting with the dollar sign', () => {
assert.equal(
- limaxProcessor('$Всплытие $ перехват событий'),
- `$vsplytie${_}$${_}perekhvat${_}sobytii`
+ urlsafeSlugProcessor('$Всплытие $ перехват событий'),
+ `$Vsplytie${_}$${_}perehvat${_}sobytij`
);
});
it('text containing the dollar sign', () => {
assert.equal(
- limaxProcessor('Всплытие$перехват'),
- `vsplytie$perekhvat`
+ urlsafeSlugProcessor('Всплытие$перехват'),
+ `Vsplytie$perehvat`
);
});
it('text containing the equal char', () => {
assert.equal(
- limaxProcessor('Всплытие = перехват=событий'),
- `vsplytie${_}perekhvat${_}sobytii`
+ urlsafeSlugProcessor('Всплытие = перехват=событий'),
+ `Vsplytie${_}perehvat${_}sobytij`
);
});
it('text containing the colon char', () => {
assert.equal(
- limaxProcessor('Всплытие : перехват:событий'),
- `vsplytie${_}perekhvat${_}sobytii`
+ urlsafeSlugProcessor('Всплытие : перехват:событий'),
+ `Vsplytie${_}perehvat${_}sobytij`
);
});
it('text containing the slash char', () => {
assert.equal(
- limaxProcessor('Всплытие / перехват/событий'),
- `vsplytie${_}perekhvat${_}sobytii`
+ urlsafeSlugProcessor('Всплытие / перехват/событий'),
+ `Vsplytie${_}perehvat${_}sobytij`
);
});
it('text containing the comma char', () => {
assert.equal(
- limaxProcessor('Всплытие, перехват'),
- `vsplytie${_}perekhvat`
+ urlsafeSlugProcessor('Всплытие, перехват'),
+ `Vsplytie${_}perehvat`
);
});
});
describe('ascii + cyricllic', () => {
it('space separated words', () => {
assert.equal(
- limaxProcessor('Всплытие и export перехват событий'),
- `vsplytie${_}i${_}export${_}perekhvat${_}sobytii`
+ urlsafeSlugProcessor('Всплытие и export перехват событий'),
+ `Vsplytie${_}i${_}export${_}perehvat${_}sobytij`
);
});
it('ascii word concatenated to a cyricllic word', () => {
assert.equal(
- limaxProcessor('exportВсплытие'),
- 'exportvsplytie'
+ urlsafeSlugProcessor('exportВсплытие'),
+ 'exportVsplytie'
);
});
it('cyricllic word concatenated to an ascii word', () => {
assert.equal(
- limaxProcessor('Всплытиеexport'),
- `vsplytieexport`
+ urlsafeSlugProcessor('Всплытиеexport'),
+ `Vsplytieexport`
);
});
it('numbered text', () => {
assert.equal(
- limaxProcessor('1 export Всплытие и перехват событий'),
- `1${_}export${_}vsplytie${_}i${_}perekhvat${_}sobytii`
+ urlsafeSlugProcessor('1 export Всплытие и перехват событий'),
+ `1${_}export${_}Vsplytie${_}i${_}perehvat${_}sobytij`
);
});
it('punctuated text', () => {
assert.equal(
- limaxProcessor('.Всплытие.export.и.перехват событий'),
- `vsplytie${_}export${_}i${_}perekhvat${_}sobytii`
+ urlsafeSlugProcessor('.Всплытие.export.и.перехват событий'),
+ `Vsplytie${_}export${_}i${_}perehvat${_}sobytij`
);
});
it('text starting with the dollar sign, followed by ascii char', () => {
assert.equal(
- limaxProcessor('$exportВсплытие перехват событий'),
- `$exportvsplytie${_}perekhvat${_}sobytii`
+ urlsafeSlugProcessor('$exportВсплытие перехват событий'),
+ `$exportVsplytie${_}perehvat${_}sobytij`
);
});
it('text starting with the dollar sign, followed by unicode char', () => {
assert.equal(
- limaxProcessor('$Всплытие export перехват событий'),
- `$vsplytie${_}export${_}perekhvat${_}sobytii`
+ urlsafeSlugProcessor('$Всплытие export перехват событий'),
+ `$Vsplytie${_}export${_}perehvat${_}sobytij`
);
});
it('text containing the dollar sign, followed by ascii char', () => {
assert.equal(
- limaxProcessor('export $destroy a component prop Всплытие и перехват событий'),
- `export${_}$destroy${_}a${_}component${_}prop${_}vsplytie${_}i${_}perekhvat${_}sobytii`
+ urlsafeSlugProcessor('export $destroy a component prop Всплытие и перехват событий'),
+ `export${_}$destroy${_}a${_}component${_}prop${_}Vsplytie${_}i${_}perehvat${_}sobytij`
);
});
it('text containing the dollar sign, followed by unicode char', () => {
assert.equal(
- limaxProcessor('Всплытие export $Всплытие a component prop Всплытие и перехват событий'),
- `vsplytie${_}export${_}$vsplytie${_}a${_}component${_}prop${_}vsplytie${_}i${_}perekhvat${_}sobytii`
+ urlsafeSlugProcessor('Всплытие export $Всплытие a component prop Всплытие и перехват событий'),
+ `Vsplytie${_}export${_}$Vsplytie${_}a${_}component${_}prop${_}Vsplytie${_}i${_}perehvat${_}sobytij`
);
});
it('text containing the equal char', () => {
assert.equal(
- limaxProcessor('script context=module Всплытие=и перехват событий'),
- `script${_}context${_}module${_}vsplytie${_}i${_}perekhvat${_}sobytii`
+ urlsafeSlugProcessor('script context=module Всплытие=и перехват событий'),
+ `script${_}context${_}module${_}Vsplytie${_}i${_}perehvat${_}sobytij`
);
});
it('text containing the colon char', () => {
assert.equal(
- limaxProcessor('svelte:body Всплытие и:перехват событий'),
- `svelte${_}body${_}vsplytie${_}i${_}perekhvat${_}sobytii`
+ urlsafeSlugProcessor('svelte:body Всплытие и:перехват событий'),
+ `svelte${_}body${_}Vsplytie${_}i${_}perehvat${_}sobytij`
);
});
it('text containing the slash char', () => {
assert.equal(
- limaxProcessor('svelte/motion Всплытие и / перехват/событий'),
- `svelte${_}motion${_}vsplytie${_}i${_}perekhvat${_}sobytii`
+ urlsafeSlugProcessor('svelte/motion Всплытие и / перехват/событий'),
+ `svelte${_}motion${_}Vsplytie${_}i${_}perehvat${_}sobytij`
);
});
it('text containing the comma char', () => {
assert.equal(
- limaxProcessor('Всплытие, export'),
- `vsplytie${_}export`
+ urlsafeSlugProcessor('Всплытие, export'),
+ `Vsplytie${_}export`
);
});
});
@@ -223,7 +217,7 @@ describe('slug', () => {
it('space separated words', () => {
assert.equal(
unicodeSafeProcessor('Text expressions'),
- `text${_}expressions`
+ `Text${_}expressions`
);
});
it('numbered text', () => {
@@ -235,7 +229,7 @@ describe('slug', () => {
it('punctuated text', () => {
assert.equal(
unicodeSafeProcessor('svelte.VERSION'),
- `svelte${_}version`
+ `svelte${_}VERSION`
);
});
it('text starting with the dollar sign', () => {
@@ -279,13 +273,13 @@ describe('slug', () => {
it('should preserve symbols', () => {
assert.equal(
unicodeSafeProcessor('Ich ♥ Deutsch'),
- `ich${_}love${_}deutsch`
+ `Ich${_}love${_}Deutsch`
);
});
it('should remove emoji', () => {
assert.equal(
unicodeSafeProcessor('Ich 😍 Deutsch'),
- `ich${_}deutsch`
+ `Ich${_}Deutsch`
);
});
});
diff --git a/src/compile/render-ssr/Renderer.ts b/src/compile/render-ssr/Renderer.ts
index 73f89dba22..c97965de14 100644
--- a/src/compile/render-ssr/Renderer.ts
+++ b/src/compile/render-ssr/Renderer.ts
@@ -11,7 +11,7 @@ import Slot from './handlers/Slot';
import Tag from './handlers/Tag';
import Text from './handlers/Text';
import Title from './handlers/Title';
-import { CompileOptions } from '../../interfaces';
+import { AppendTarget, CompileOptions } from '../../interfaces';
type Handler = (node: any, renderer: Renderer, options: CompileOptions) => void;
@@ -36,8 +36,6 @@ const handlers: Record = {
Window: noop
};
-type AppendTarget = any; // TODO
-
export default class Renderer {
has_bindings = false;
code = '';
diff --git a/src/compile/render-ssr/handlers/InlineComponent.ts b/src/compile/render-ssr/handlers/InlineComponent.ts
index 289f2ff8f8..bc58be5df9 100644
--- a/src/compile/render-ssr/handlers/InlineComponent.ts
+++ b/src/compile/render-ssr/handlers/InlineComponent.ts
@@ -4,8 +4,7 @@ import { snip } from '../../utils/snip';
import Renderer from '../Renderer';
import { stringify_props } from '../../utils/stringify_props';
import { get_slot_scope } from './shared/get_slot_scope';
-
-type AppendTarget = any; // TODO
+import { AppendTarget } from '../../../interfaces';
function stringify_attribute(chunk: Node) {
if (chunk.type === 'Text') {
@@ -111,4 +110,4 @@ export default function(node, renderer: Renderer, options) {
const slots = stringify_props(slot_fns);
renderer.append(`\${@validate_component(${expression}, '${node.name}').$$render($$result, ${props}, ${bindings}, ${slots})}`);
-}
\ No newline at end of file
+}