From cf72b4157575e4a64d73c75dc26fa22bcd25f719 Mon Sep 17 00:00:00 2001 From: nomnomnomnom Date: Tue, 28 Apr 2020 13:49:44 -0700 Subject: [PATCH 1/4] fix misaligned line numbers in sourcemaps (#4738) --- src/compiler/parse/read/script.ts | 3 ++- .../samples/script-after-comment/input.svelte | 9 +++++++++ .../samples/script-after-comment/test.js | 16 ++++++++++++++++ test/sourcemaps/samples/two-scripts/input.svelte | 9 +++++++++ test/sourcemaps/samples/two-scripts/test.js | 16 ++++++++++++++++ 5 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 test/sourcemaps/samples/script-after-comment/input.svelte create mode 100644 test/sourcemaps/samples/script-after-comment/test.js create mode 100644 test/sourcemaps/samples/two-scripts/input.svelte create mode 100644 test/sourcemaps/samples/two-scripts/test.js diff --git a/src/compiler/parse/read/script.ts b/src/compiler/parse/read/script.ts index 130c346ba1..8260894215 100644 --- a/src/compiler/parse/read/script.ts +++ b/src/compiler/parse/read/script.ts @@ -37,7 +37,8 @@ export default function read_script(parser: Parser, start: number, attributes: N message: ` + +{foo.bar.baz} diff --git a/test/sourcemaps/samples/script-after-comment/test.js b/test/sourcemaps/samples/script-after-comment/test.js new file mode 100644 index 0000000000..b473970112 --- /dev/null +++ b/test/sourcemaps/samples/script-after-comment/test.js @@ -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 + }); +} diff --git a/test/sourcemaps/samples/two-scripts/input.svelte b/test/sourcemaps/samples/two-scripts/input.svelte new file mode 100644 index 0000000000..4c869827c0 --- /dev/null +++ b/test/sourcemaps/samples/two-scripts/input.svelte @@ -0,0 +1,9 @@ + + + + +{foo.bar.baz} diff --git a/test/sourcemaps/samples/two-scripts/test.js b/test/sourcemaps/samples/two-scripts/test.js new file mode 100644 index 0000000000..b473970112 --- /dev/null +++ b/test/sourcemaps/samples/two-scripts/test.js @@ -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 + }); +} From 8c4e72647ae119401557a31df77a02568671f8d6 Mon Sep 17 00:00:00 2001 From: Conduitry Date: Tue, 28 Apr 2020 16:50:59 -0400 Subject: [PATCH 2/4] update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3fceb5f2fc..660f834ac6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## 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)) ## 3.21.0 From 56d1af493bb9bf71b2665e9c20228721ce79447b Mon Sep 17 00:00:00 2001 From: Kalan Date: Wed, 29 Apr 2020 06:03:31 +0900 Subject: [PATCH 3/4] a11y: warn about href="javascript:..." (#4733) --- src/compiler/compile/nodes/Element.ts | 2 +- .../samples/a11y-anchor-is-valid/input.svelte | 3 ++- .../samples/a11y-anchor-is-valid/warnings.json | 15 +++++++++++++++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/compiler/compile/nodes/Element.ts b/src/compiler/compile/nodes/Element.ts index 8ff36de31a..f64da919c6 100644 --- a/src/compiler/compile/nodes/Element.ts +++ b/src/compiler/compile/nodes/Element.ts @@ -428,7 +428,7 @@ export default class Element extends Node { if (attribute) { const value = attribute.get_static_value(); - if (value === '' || value === '#') { + if (value === '' || value === '#' || /^\W*javascript:/i.test(value)) { component.warn(attribute, { code: `a11y-invalid-attribute`, message: `A11y: '${value}' is not a valid ${attribute.name} attribute` diff --git a/test/validator/samples/a11y-anchor-is-valid/input.svelte b/test/validator/samples/a11y-anchor-is-valid/input.svelte index 7b14a80c9f..6d0f77a308 100644 --- a/test/validator/samples/a11y-anchor-is-valid/input.svelte +++ b/test/validator/samples/a11y-anchor-is-valid/input.svelte @@ -1,3 +1,4 @@ not actually a link invalid -invalid \ No newline at end of file +invalid +invalid \ No newline at end of file diff --git a/test/validator/samples/a11y-anchor-is-valid/warnings.json b/test/validator/samples/a11y-anchor-is-valid/warnings.json index 532c44ad24..9438a74f5b 100644 --- a/test/validator/samples/a11y-anchor-is-valid/warnings.json +++ b/test/validator/samples/a11y-anchor-is-valid/warnings.json @@ -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 } ] From 628b09d8673c48f53283d339c17b778adfb60235 Mon Sep 17 00:00:00 2001 From: Conduitry Date: Tue, 28 Apr 2020 17:05:06 -0400 Subject: [PATCH 4/4] update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 660f834ac6..459cf656c7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ * 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