Skip to content

Commit 581a1f9

Browse files
committed
merge with master
2 parents fc2a258 + 628b09d commit 581a1f9

File tree

9 files changed

+72
-3
lines changed

9 files changed

+72
-3
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
## Unreleased
44

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

79
## 3.21.0
810

src/compiler/compile/nodes/Element.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ export default class Element extends Node {
430430
if (href_attribute) {
431431
const href_value = href_attribute.get_static_value();
432432

433-
if (href_value === '' || href_value === '#') {
433+
if (href_value === '' || href_value === '#' || /^\W*javascript:/i.test(href_value)) {
434434
component.warn(href_attribute, {
435435
code: `a11y-invalid-attribute`,
436436
message: `A11y: '${href_value}' is not a valid ${href_attribute.name} attribute`

src/compiler/parse/read/script.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ export default function read_script(parser: Parser, start: number, attributes: N
3737
message: `<script> must have a closing tag`
3838
});
3939

40-
const source = ' '.repeat(script_start) + parser.template.slice(script_start, script_end);
40+
const source = parser.template.slice(0, script_start).replace(/[^\n]/g, ' ') +
41+
parser.template.slice(script_start, script_end);
4142
parser.index = script_end + script_closing_tag.length;
4243

4344
let ast: Program;
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<!--
2+
Multiline
3+
comment
4+
-->
5+
<script>
6+
function assertThisLine() {}
7+
</script>
8+
9+
{foo.bar.baz}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
export function test({ assert, smc, locateInSource, locateInGenerated }) {
2+
const expected = locateInSource( 'assertThisLine' );
3+
const start = locateInGenerated( 'assertThisLine' );
4+
5+
const actual = smc.originalPositionFor({
6+
line: start.line + 1,
7+
column: start.column
8+
});
9+
10+
assert.deepEqual( actual, {
11+
source: 'input.svelte',
12+
name: null,
13+
line: expected.line + 1,
14+
column: expected.column
15+
});
16+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<script context="module">
2+
export let first;
3+
</script>
4+
5+
<script>
6+
function assertThisLine() {}
7+
</script>
8+
9+
{foo.bar.baz}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
export function test({ assert, smc, locateInSource, locateInGenerated }) {
2+
const expected = locateInSource( 'assertThisLine' );
3+
const start = locateInGenerated( 'assertThisLine' );
4+
5+
const actual = smc.originalPositionFor({
6+
line: start.line + 1,
7+
column: start.column
8+
});
9+
10+
assert.deepEqual( actual, {
11+
source: 'input.svelte',
12+
name: null,
13+
line: expected.line + 1,
14+
column: expected.column
15+
});
16+
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
<a>not actually a link</a>
22
<a href=''>invalid</a>
3-
<a href='#'>invalid</a>
3+
<a href='#'>invalid</a>
4+
<a href="javascript:void(0)">invalid</a>

test/validator/samples/a11y-anchor-is-valid/warnings.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,20 @@
4343
"character": 61
4444
},
4545
"pos": 53
46+
},
47+
{
48+
"code": "a11y-invalid-attribute",
49+
"message": "A11y: 'javascript:void(0)' is not a valid href attribute",
50+
"start": {
51+
"line": 4,
52+
"column": 3,
53+
"character": 77
54+
},
55+
"end": {
56+
"line": 4,
57+
"column": 28,
58+
"character": 102
59+
},
60+
"pos": 77
4661
}
4762
]

0 commit comments

Comments
 (0)