forked from sveltejs/svelte
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
compile: support classes on inline components
Closes sveltejs#2870
- Loading branch information
Showing
27 changed files
with
510 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.foo.svelte-xyz{color:red} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<script> | ||
const Nested = window.Nested; | ||
|
||
export let clazz = ''; | ||
</script> | ||
|
||
<div class="foo"> | ||
<Nested class={ clazz } /> | ||
</div> | ||
|
||
<style> | ||
.foo { | ||
color: red; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.custom-class.svelte-xyz{color:red} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<script> | ||
const Nested = window.Nested; | ||
|
||
export let prop; | ||
</script> | ||
|
||
<Nested class="custom-class" prop={ prop } /> | ||
|
||
<style> | ||
.custom-class { | ||
color: red; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.foo.svelte-xyz{color:red} |
13 changes: 13 additions & 0 deletions
13
test/css/samples/component-class-no-definition/input.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<script> | ||
const Nested = window.Nested; | ||
</script> | ||
|
||
<div class="foo"> | ||
<Nested class="no-definition" /> | ||
</div> | ||
|
||
<style> | ||
.foo { | ||
color: red; | ||
} | ||
</style> |
25 changes: 25 additions & 0 deletions
25
test/css/samples/component-class-unused-selector/_config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
export default { | ||
warnings: [{ | ||
filename: "SvelteComponent.svelte", | ||
code: `css-unused-selector`, | ||
message: "Unused CSS selector", | ||
start: { | ||
line: 12, | ||
column: 1, | ||
character: 110 | ||
}, | ||
end: { | ||
line: 12, | ||
column: 5, | ||
character: 114 | ||
}, | ||
pos: 110, | ||
frame: ` | ||
10: } | ||
11: | ||
12: .bar { | ||
^ | ||
13: color: blue; | ||
14: }` | ||
}] | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.foo.svelte-xyz{color:red} |
15 changes: 15 additions & 0 deletions
15
test/css/samples/component-class-unused-selector/input.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<script> | ||
const Nested = window.Nested; | ||
</script> | ||
|
||
<Nested class="foo" /> | ||
|
||
<style> | ||
.foo { | ||
color: red; | ||
} | ||
|
||
.bar { | ||
color: blue; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.custom-class.svelte-xyz{color:red} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<script> | ||
const Nested = window.Nested; | ||
</script> | ||
|
||
<Nested class="custom-class" /> | ||
|
||
<style> | ||
.custom-class { | ||
color: red; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.custom.svelte-xyz{color:red}.custom2.svelte-xyz{background:yellow} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<script> | ||
const Nested = window.Nested; | ||
|
||
export let clazz = 'foo'; | ||
</script> | ||
|
||
<Nested class="custom { clazz } custom2" /> | ||
|
||
<style> | ||
.custom { | ||
color: red; | ||
} | ||
|
||
.custom2 { | ||
background: yellow; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* generated by Svelte vX.Y.Z */ | ||
import { | ||
SvelteComponent, | ||
init, | ||
mount_component, | ||
noop, | ||
safe_not_equal | ||
} from "svelte/internal"; | ||
|
||
function create_fragment(ctx) { | ||
var current; | ||
|
||
var nested = new ctx.Nested({ props: { class: "custom" } }); | ||
nested.$on("click", ctx.handleClick); | ||
|
||
return { | ||
c() { | ||
nested.$$.fragment.c(); | ||
}, | ||
|
||
m(target, anchor) { | ||
mount_component(nested, target, anchor); | ||
current = true; | ||
}, | ||
|
||
p: noop, | ||
|
||
i(local) { | ||
if (current) return; | ||
nested.$$.fragment.i(local); | ||
|
||
current = true; | ||
}, | ||
|
||
o(local) { | ||
nested.$$.fragment.o(local); | ||
current = false; | ||
}, | ||
|
||
d(detaching) { | ||
nested.$destroy(detaching); | ||
} | ||
}; | ||
} | ||
|
||
function instance($$self) { | ||
const Nested = window.Nested; | ||
|
||
let handleClick = () => {}; | ||
|
||
return { Nested, handleClick }; | ||
} | ||
|
||
class Component extends SvelteComponent { | ||
constructor(options) { | ||
super(); | ||
init(this, options, instance, create_fragment, safe_not_equal, []); | ||
} | ||
} | ||
|
||
export default Component; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<script> | ||
const Nested = window.Nested; | ||
|
||
let handleClick = () => {}; | ||
</script> | ||
|
||
<Nested class="custom" on:click={ handleClick } /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* generated by Svelte vX.Y.Z */ | ||
import { | ||
SvelteComponent, | ||
append, | ||
detach, | ||
element, | ||
init, | ||
insert, | ||
mount_component, | ||
noop, | ||
safe_not_equal | ||
} from "svelte/internal"; | ||
|
||
function add_css() { | ||
var style = element("style"); | ||
style.id = 'svelte-sg04hs-style'; | ||
style.textContent = ".foo.svelte-sg04hs{color:red}"; | ||
append(document.head, style); | ||
} | ||
|
||
function create_fragment(ctx) { | ||
var div, current; | ||
|
||
var nested = new ctx.Nested({ props: { class: "no-definition" } }); | ||
|
||
return { | ||
c() { | ||
div = element("div"); | ||
nested.$$.fragment.c(); | ||
div.className = "foo svelte-sg04hs"; | ||
}, | ||
|
||
m(target, anchor) { | ||
insert(target, div, anchor); | ||
mount_component(nested, div, null); | ||
current = true; | ||
}, | ||
|
||
p: noop, | ||
|
||
i(local) { | ||
if (current) return; | ||
nested.$$.fragment.i(local); | ||
|
||
current = true; | ||
}, | ||
|
||
o(local) { | ||
nested.$$.fragment.o(local); | ||
current = false; | ||
}, | ||
|
||
d(detaching) { | ||
if (detaching) { | ||
detach(div); | ||
} | ||
|
||
nested.$destroy(); | ||
} | ||
}; | ||
} | ||
|
||
function instance($$self) { | ||
const Nested = window.Nested; | ||
|
||
return { Nested }; | ||
} | ||
|
||
class Component extends SvelteComponent { | ||
constructor(options) { | ||
super(); | ||
if (!document.getElementById("svelte-sg04hs-style")) add_css(); | ||
init(this, options, instance, create_fragment, safe_not_equal, []); | ||
} | ||
} | ||
|
||
export default Component; |
Oops, something went wrong.