Skip to content

Commit

Permalink
Merge pull request #1192 from sveltejs/gh-1118-base36
Browse files Browse the repository at this point in the history
use base 36 for style classes
  • Loading branch information
Rich-Harris authored Mar 8, 2018
2 parents 2f01115 + 3f7f237 commit 7d4958b
Show file tree
Hide file tree
Showing 18 changed files with 39 additions and 39 deletions.
4 changes: 2 additions & 2 deletions src/utils/hash.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// https://github.com/darkskyapp/string-hash/blob/master/index.js
export default function hash(str: string): number {
export default function hash(str: string): string {
let hash = 5381;
let i = str.length;

while (i--) hash = ((hash << 5) - hash) ^ str.charCodeAt(i);
return hash >>> 0;
return (hash >>> 0).toString(36);
}
6 changes: 3 additions & 3 deletions test/css/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ describe('css', () => {
css: read(`test/css/samples/${dir}/expected.css`)
};

assert.equal(dom.css.replace(/svelte-\d+/g, 'svelte-xyz'), expected.css);
assert.equal(dom.css.replace(/svelte(-ref)?-[a-z0-9]+/g, (m, $1) => $1 ? m : 'svelte-xyz'), expected.css);

// verify that the right elements have scoping selectors
if (expected.html !== null) {
Expand All @@ -114,7 +114,7 @@ describe('css', () => {
fs.writeFileSync(`test/css/samples/${dir}/_actual.html`, html);

assert.equal(
normalizeHtml(window, html.replace(/svelte-\d+/g, 'svelte-xyz')),
normalizeHtml(window, html.replace(/svelte(-ref)?-[a-z0-9]+/g, (m, $1) => $1 ? m : 'svelte-xyz')),
normalizeHtml(window, expected.html)
);

Expand All @@ -133,7 +133,7 @@ describe('css', () => {
assert.equal(
normalizeHtml(
window,
component.render(config.data).html.replace(/svelte-\d+/g, 'svelte-xyz')
component.render(config.data).html.replace(/svelte(-ref)?-[a-z0-9]+/g, (m, $1) => $1 ? m : 'svelte-xyz')
),
normalizeHtml(window, expected.html)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,8 @@ function data() {
}
function add_css() {
var style = createElement("style");
style.id = 'svelte-2794052100-style';
style.textContent = "p.svelte-2794052100,.svelte-2794052100 p{color:red}";
style.id = 'svelte-1a7i8ec-style';
style.textContent = "p.svelte-1a7i8ec,.svelte-1a7i8ec p{color:red}";
appendNode(style, document.head);
}

Expand All @@ -212,7 +212,7 @@ function create_main_fragment(component, state) {
},

h: function hydrate() {
p.className = "svelte-2794052100";
p.className = "svelte-1a7i8ec";
},

m: function mount(target, anchor) {
Expand All @@ -238,7 +238,7 @@ function SvelteComponent(options) {
init(this, options);
this._state = assign(data(), options.data);

if (!document.getElementById("svelte-2794052100-style")) add_css();
if (!document.getElementById("svelte-1a7i8ec-style")) add_css();

this._fragment = create_main_fragment(this, this._state);

Expand Down
8 changes: 4 additions & 4 deletions test/js/samples/collapses-text-around-comments/expected.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ function data() {

function add_css() {
var style = createElement("style");
style.id = 'svelte-2794052100-style';
style.textContent = "p.svelte-2794052100,.svelte-2794052100 p{color:red}";
style.id = 'svelte-1a7i8ec-style';
style.textContent = "p.svelte-1a7i8ec,.svelte-1a7i8ec p{color:red}";
appendNode(style, document.head);
}

Expand All @@ -23,7 +23,7 @@ function create_main_fragment(component, state) {
},

h: function hydrate() {
p.className = "svelte-2794052100";
p.className = "svelte-1a7i8ec";
},

m: function mount(target, anchor) {
Expand All @@ -49,7 +49,7 @@ function SvelteComponent(options) {
init(this, options);
this._state = assign(data(), options.data);

if (!document.getElementById("svelte-2794052100-style")) add_css();
if (!document.getElementById("svelte-1a7i8ec-style")) add_css();

this._fragment = create_main_fragment(this, this._state);

Expand Down
8 changes: 4 additions & 4 deletions test/js/samples/css-media-query/expected-bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,8 @@ var proto = {

function add_css() {
var style = createElement("style");
style.id = 'svelte-3905933315-style';
style.textContent = "@media(min-width: 1px){div.svelte-3905933315,.svelte-3905933315 div{color:red}}";
style.id = 'svelte-1slhpfn-style';
style.textContent = "@media(min-width: 1px){div.svelte-1slhpfn,.svelte-1slhpfn div{color:red}}";
appendNode(style, document.head);
}

Expand All @@ -204,7 +204,7 @@ function create_main_fragment(component, state) {
},

h: function hydrate() {
div.className = "svelte-3905933315";
div.className = "svelte-1slhpfn";
},

m: function mount(target, anchor) {
Expand All @@ -225,7 +225,7 @@ function SvelteComponent(options) {
init(this, options);
this._state = assign({}, options.data);

if (!document.getElementById("svelte-3905933315-style")) add_css();
if (!document.getElementById("svelte-1slhpfn-style")) add_css();

this._fragment = create_main_fragment(this, this._state);

Expand Down
8 changes: 4 additions & 4 deletions test/js/samples/css-media-query/expected.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { appendNode, assign, createElement, detachNode, init, insertNode, noop,

function add_css() {
var style = createElement("style");
style.id = 'svelte-3905933315-style';
style.textContent = "@media(min-width: 1px){div.svelte-3905933315,.svelte-3905933315 div{color:red}}";
style.id = 'svelte-1slhpfn-style';
style.textContent = "@media(min-width: 1px){div.svelte-1slhpfn,.svelte-1slhpfn div{color:red}}";
appendNode(style, document.head);
}

Expand All @@ -18,7 +18,7 @@ function create_main_fragment(component, state) {
},

h: function hydrate() {
div.className = "svelte-3905933315";
div.className = "svelte-1slhpfn";
},

m: function mount(target, anchor) {
Expand All @@ -39,7 +39,7 @@ function SvelteComponent(options) {
init(this, options);
this._state = assign({}, options.data);

if (!document.getElementById("svelte-3905933315-style")) add_css();
if (!document.getElementById("svelte-1slhpfn-style")) add_css();

this._fragment = create_main_fragment(this, this._state);

Expand Down
4 changes: 2 additions & 2 deletions test/server-side-rendering/samples/styles-nested/_actual.css
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
div.svelte-724714405,.svelte-724714405 div{color:red}
div.svelte-300476157,.svelte-300476157 div{color:green}
div.svelte-bzh57p,.svelte-bzh57p div{color:red}
div.svelte-4yw8vx,.svelte-4yw8vx div{color:green}
6 changes: 3 additions & 3 deletions test/server-side-rendering/samples/styles-nested/_actual.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<div class="svelte-724714405">red</div>
<div class="svelte-300476157">green: foo</div>
<div class="svelte-bzh57p">red</div>
<div class="svelte-4yw8vx">green: foo</div>



<div class="svelte-300476157">green: bar</div>
<div class="svelte-4yw8vx">green: bar</div>


Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
div.svelte-724714405,.svelte-724714405 div{color:red}
div.svelte-300476157,.svelte-300476157 div{color:green}
div.svelte-bzh57p,.svelte-bzh57p div{color:red}
div.svelte-4yw8vx,.svelte-4yw8vx div{color:green}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<div class="svelte-724714405">red</div>
<div class="svelte-300476157">green: foo</div>
<div class="svelte-bzh57p">red</div>
<div class="svelte-4yw8vx">green: foo</div>



<div class="svelte-300476157">green: bar</div>
<div class="svelte-4yw8vx">green: bar</div>


2 changes: 1 addition & 1 deletion test/server-side-rendering/samples/styles/_actual.css
Original file line number Diff line number Diff line change
@@ -1 +1 @@
div.svelte-724714405,.svelte-724714405 div{color:red}
div.svelte-bzh57p,.svelte-bzh57p div{color:red}
2 changes: 1 addition & 1 deletion test/server-side-rendering/samples/styles/_actual.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<div class="svelte-724714405">red</div>
<div class="svelte-bzh57p">red</div>
2 changes: 1 addition & 1 deletion test/server-side-rendering/samples/styles/_expected.css
Original file line number Diff line number Diff line change
@@ -1 +1 @@
div.svelte-724714405,.svelte-724714405 div{color:red}
div.svelte-bzh57p,.svelte-bzh57p div{color:red}
2 changes: 1 addition & 1 deletion test/server-side-rendering/samples/styles/_expected.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<div class="svelte-724714405">red</div>
<div class="svelte-bzh57p">red</div>
2 changes: 1 addition & 1 deletion test/sourcemaps/samples/css-cascade-false/output.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion test/sourcemaps/samples/css-cascade-false/output.css.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion test/sourcemaps/samples/css/output.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion test/sourcemaps/samples/css/output.css.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 7d4958b

Please sign in to comment.