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.
Fix backtick string literals not being recognized for the svg property
Failing test for sveltejs#1284 Fixes sveltejs#1284
- Loading branch information
Showing
7 changed files
with
57 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { Node } from '../interfaces'; | ||
|
||
export default function nodeToString(prop: Node) { | ||
if (prop.value.type === 'Literal' && typeof prop.value.value === 'string') { | ||
return prop.value.value; | ||
} else if (prop.value.type === 'TemplateLiteral' | ||
&& prop.value.quasis.length === 1 | ||
&& prop.value.expressions.length === 0) { | ||
return prop.value.quasis[0].value.raw; | ||
} | ||
} |
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
7 changes: 7 additions & 0 deletions
7
test/runtime/samples/svg-child-component-declared-namespace-backtick-string/Rect.html
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 @@ | ||
<rect x='{{x}}' y='{{y}}' width='{{width}}' height='{{height}}'/> | ||
|
||
<script> | ||
export default { | ||
namespace: `svg` | ||
}; | ||
</script> |
21 changes: 21 additions & 0 deletions
21
test/runtime/samples/svg-child-component-declared-namespace-backtick-string/_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,21 @@ | ||
export default { | ||
data: { | ||
x: 0, | ||
y: 0, | ||
width: 100, | ||
height: 100 | ||
}, | ||
|
||
html: `<svg><rect x="0" y="0" width="100" height="100"></rect></svg>`, | ||
|
||
test ( assert, component, target ) { | ||
const svg = target.querySelector( 'svg' ); | ||
const rect = target.querySelector( 'rect' ); | ||
|
||
assert.equal( svg.namespaceURI, 'http://www.w3.org/2000/svg' ); | ||
assert.equal( rect.namespaceURI, 'http://www.w3.org/2000/svg' ); | ||
|
||
component.set({ width: 150, height: 50 }); | ||
assert.equal( target.innerHTML, `<svg><rect x="0" y="0" width="150" height="50"></rect></svg>` ); | ||
}, | ||
}; |
11 changes: 11 additions & 0 deletions
11
test/runtime/samples/svg-child-component-declared-namespace-backtick-string/main.html
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 @@ | ||
<svg> | ||
<Rect x='{{x}}' y='{{y}}' width='{{width}}' height='{{height}}'/> | ||
</svg> | ||
|
||
<script> | ||
import Rect from './Rect.html'; | ||
|
||
export default { | ||
components: { Rect } | ||
}; | ||
</script> |