merge with master

pull/4739/head
André Lins 6 years ago
commit 581a1f95ca

@ -2,7 +2,9 @@
## Unreleased
* Fix misaligned line numbers in source maps ([#3906](https://github.com/sveltejs/svelte/issues/3906))
* Fix reactivity with imported values that are then mutated ([#4555](https://github.com/sveltejs/svelte/issues/4555))
* Display a11y warning for `href="javascript:..."` ([#4733](https://github.com/sveltejs/svelte/pull/4733))
## 3.21.0

@ -430,7 +430,7 @@ export default class Element extends Node {
if (href_attribute) {
const href_value = href_attribute.get_static_value();
if (href_value === '' || href_value === '#') {
if (href_value === '' || href_value === '#' || /^\W*javascript:/i.test(href_value)) {
component.warn(href_attribute, {
code: `a11y-invalid-attribute`,
message: `A11y: '${href_value}' is not a valid ${href_attribute.name} attribute`

@ -37,7 +37,8 @@ export default function read_script(parser: Parser, start: number, attributes: N
message: `<script> must have a closing tag`
});
const source = ' '.repeat(script_start) + parser.template.slice(script_start, script_end);
const source = parser.template.slice(0, script_start).replace(/[^\n]/g, ' ') +
parser.template.slice(script_start, script_end);
parser.index = script_end + script_closing_tag.length;
let ast: Program;

@ -0,0 +1,9 @@
<!--
Multiline
comment
-->
<script>
function assertThisLine() {}
</script>
{foo.bar.baz}

@ -0,0 +1,16 @@
export function test({ assert, smc, locateInSource, locateInGenerated }) {
const expected = locateInSource( 'assertThisLine' );
const start = locateInGenerated( 'assertThisLine' );
const actual = smc.originalPositionFor({
line: start.line + 1,
column: start.column
});
assert.deepEqual( actual, {
source: 'input.svelte',
name: null,
line: expected.line + 1,
column: expected.column
});
}

@ -0,0 +1,9 @@
<script context="module">
export let first;
</script>
<script>
function assertThisLine() {}
</script>
{foo.bar.baz}

@ -0,0 +1,16 @@
export function test({ assert, smc, locateInSource, locateInGenerated }) {
const expected = locateInSource( 'assertThisLine' );
const start = locateInGenerated( 'assertThisLine' );
const actual = smc.originalPositionFor({
line: start.line + 1,
column: start.column
});
assert.deepEqual( actual, {
source: 'input.svelte',
name: null,
line: expected.line + 1,
column: expected.column
});
}

@ -1,3 +1,4 @@
<a>not actually a link</a>
<a href=''>invalid</a>
<a href='#'>invalid</a>
<a href="javascript:void(0)">invalid</a>

@ -43,5 +43,20 @@
"character": 61
},
"pos": 53
},
{
"code": "a11y-invalid-attribute",
"message": "A11y: 'javascript:void(0)' is not a valid href attribute",
"start": {
"line": 4,
"column": 3,
"character": 77
},
"end": {
"line": 4,
"column": 28,
"character": 102
},
"pos": 77
}
]

Loading…
Cancel
Save