From e34e5ee9da6a0d1d6408e55d818786166f609ace Mon Sep 17 00:00:00 2001 From: Saurav Sahu Date: Fri, 29 Jan 2021 22:28:43 +0530 Subject: [PATCH 1/7] fix: filter out 'this' binding for foreign namespace --- src/compiler/compile/nodes/Element.ts | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/compiler/compile/nodes/Element.ts b/src/compiler/compile/nodes/Element.ts index 8c5b4cb9f5c4..5a1e2ecfae26 100644 --- a/src/compiler/compile/nodes/Element.ts +++ b/src/compiler/compile/nodes/Element.ts @@ -599,12 +599,14 @@ export default class Element extends Node { } validate_bindings_foreign() { - this.bindings.forEach(binding => { - this.component.error(binding, { - code: 'invalid-binding', - message: `'${binding.name}' is not a valid binding. Foreign elements only support bind:this` + this.bindings + .filter(binding => binding.name !== 'this') + .forEach(binding => { + this.component.error(binding, { + code: 'invalid-binding', + message: `'${binding.name}' is not a valid binding. Foreign elements only support bind:this` + }); }); - }); } validate_bindings() { From 446a907187def1c742a1b38561f5557f3824f2bc Mon Sep 17 00:00:00 2001 From: Saurav Sahu Date: Fri, 29 Jan 2021 22:42:14 +0530 Subject: [PATCH 2/7] add test that should not be thrown --- .../errors.json | 15 +++++++++++++++ .../input.svelte | 6 ++++++ 2 files changed, 21 insertions(+) create mode 100644 test/validator/samples/binding-this-invalid-foreign-namespace /errors.json create mode 100644 test/validator/samples/binding-this-invalid-foreign-namespace /input.svelte diff --git a/test/validator/samples/binding-this-invalid-foreign-namespace /errors.json b/test/validator/samples/binding-this-invalid-foreign-namespace /errors.json new file mode 100644 index 000000000000..7ab0f5f16104 --- /dev/null +++ b/test/validator/samples/binding-this-invalid-foreign-namespace /errors.json @@ -0,0 +1,15 @@ +[{ + "code": "invalid-binding", + "message": "'this' is not a valid binding. Foreign elements only support bind:this", + "pos": 81, + "start": { + "line": 6, + "column": 7, + "character": 81 + }, + "end": { + "line": 6, + "column": 27, + "character": 101 + } +}] diff --git a/test/validator/samples/binding-this-invalid-foreign-namespace /input.svelte b/test/validator/samples/binding-this-invalid-foreign-namespace /input.svelte new file mode 100644 index 000000000000..5ac1d09a4182 --- /dev/null +++ b/test/validator/samples/binding-this-invalid-foreign-namespace /input.svelte @@ -0,0 +1,6 @@ + + + + From a6ac9f32a0a504ffac26a09f71008b3258839a7b Mon Sep 17 00:00:00 2001 From: Saurav Sahu Date: Fri, 29 Jan 2021 23:15:14 +0530 Subject: [PATCH 3/7] delete old failing test --- .../errors.json | 15 --------------- .../input.svelte | 6 ------ 2 files changed, 21 deletions(-) delete mode 100644 test/validator/samples/binding-this-invalid-foreign-namespace /errors.json delete mode 100644 test/validator/samples/binding-this-invalid-foreign-namespace /input.svelte diff --git a/test/validator/samples/binding-this-invalid-foreign-namespace /errors.json b/test/validator/samples/binding-this-invalid-foreign-namespace /errors.json deleted file mode 100644 index 7ab0f5f16104..000000000000 --- a/test/validator/samples/binding-this-invalid-foreign-namespace /errors.json +++ /dev/null @@ -1,15 +0,0 @@ -[{ - "code": "invalid-binding", - "message": "'this' is not a valid binding. Foreign elements only support bind:this", - "pos": 81, - "start": { - "line": 6, - "column": 7, - "character": 81 - }, - "end": { - "line": 6, - "column": 27, - "character": 101 - } -}] diff --git a/test/validator/samples/binding-this-invalid-foreign-namespace /input.svelte b/test/validator/samples/binding-this-invalid-foreign-namespace /input.svelte deleted file mode 100644 index 5ac1d09a4182..000000000000 --- a/test/validator/samples/binding-this-invalid-foreign-namespace /input.svelte +++ /dev/null @@ -1,6 +0,0 @@ - - - - From 66af40e3a9e136ce35d35994a65f7ae9abd13b2f Mon Sep 17 00:00:00 2001 From: Saurav Sahu Date: Fri, 29 Jan 2021 23:15:57 +0530 Subject: [PATCH 4/7] add a test which should pass without code change --- src/compiler/compile/nodes/Element.ts | 2 +- test/validator/index.ts | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/compiler/compile/nodes/Element.ts b/src/compiler/compile/nodes/Element.ts index 5a1e2ecfae26..7fb4f4aeef8a 100644 --- a/src/compiler/compile/nodes/Element.ts +++ b/src/compiler/compile/nodes/Element.ts @@ -600,7 +600,7 @@ export default class Element extends Node { validate_bindings_foreign() { this.bindings - .filter(binding => binding.name !== 'this') + // .filter(binding => binding.name !== 'this') .forEach(binding => { this.component.error(binding, { code: 'invalid-binding', diff --git a/test/validator/index.ts b/test/validator/index.ts index 72364ea89a68..030ec59c7530 100644 --- a/test/validator/index.ts +++ b/test/validator/index.ts @@ -119,4 +119,17 @@ describe('validate', () => { }); }, /Invalid namespace 'foriegn' \(did you mean 'foreign'\?\)/); }); + + it('throws an error if \'this\' is bound for foreign element', () => { + assert.throws(() => { + svelte.compile(` + +
`, { + name: 'test', + namespace: 'foreign' + }); + }, /'this' is not a valid binding/) + }) }); From 34d9830cc26ca3af1191dbaf6c7937e2f0248473 Mon Sep 17 00:00:00 2001 From: Saurav Sahu Date: Fri, 29 Jan 2021 23:20:40 +0530 Subject: [PATCH 5/7] test: should not throw error for bind:this --- src/compiler/compile/nodes/Element.ts | 2 +- test/validator/index.ts | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/compiler/compile/nodes/Element.ts b/src/compiler/compile/nodes/Element.ts index 7fb4f4aeef8a..5a1e2ecfae26 100644 --- a/src/compiler/compile/nodes/Element.ts +++ b/src/compiler/compile/nodes/Element.ts @@ -600,7 +600,7 @@ export default class Element extends Node { validate_bindings_foreign() { this.bindings - // .filter(binding => binding.name !== 'this') + .filter(binding => binding.name !== 'this') .forEach(binding => { this.component.error(binding, { code: 'invalid-binding', diff --git a/test/validator/index.ts b/test/validator/index.ts index 030ec59c7530..50673153541c 100644 --- a/test/validator/index.ts +++ b/test/validator/index.ts @@ -120,8 +120,8 @@ describe('validate', () => { }, /Invalid namespace 'foriegn' \(did you mean 'foreign'\?\)/); }); - it('throws an error if \'this\' is bound for foreign element', () => { - assert.throws(() => { + it('does not throw error if \'this\' is bound for foreign element', () => { + assert.doesNotThrow(() => { svelte.compile(`