From 91551b9d43ea085d7b90da6348c49b25918bf999 Mon Sep 17 00:00:00 2001 From: Arpad Borsos Date: Wed, 21 Dec 2016 19:09:06 +0100 Subject: [PATCH] make html validators work inside else blocks --- src/validate/html/index.js | 4 +++ test/validate.js | 6 ++-- test/validator/names/input.html | 24 ++++++++++++++ test/validator/names/names.json | 8 ++++- .../input.html | 28 ++++++++++++++++ .../warnings.json | 32 +++++++++++++++++++ 6 files changed, 99 insertions(+), 3 deletions(-) diff --git a/src/validate/html/index.js b/src/validate/html/index.js index a7feafc42b..09a9816952 100644 --- a/src/validate/html/index.js +++ b/src/validate/html/index.js @@ -23,6 +23,10 @@ export default function validateHtml ( validator, html ) { node.children.forEach( visit ); } + if (node.else ) { + visit( node.else ); + } + if ( node.type === 'Element' ) { elementDepth -= 1; } diff --git a/test/validate.js b/test/validate.js index 4f82cba06b..6708074338 100644 --- a/test/validate.js +++ b/test/validate.js @@ -38,11 +38,13 @@ describe( 'validate', () => { const expectedErrors = tryToLoadJson( `test/validator/${dir}/errors.json` ) || []; const expectedWarnings = tryToLoadJson( `test/validator/${dir}/warnings.json` ) || []; - const expectedNames = tryToLoadJson( `test/validator/${dir}/names.json` ) || []; + const expectedNames = tryToLoadJson( `test/validator/${dir}/names.json` ); assert.deepEqual( errors, expectedErrors ); assert.deepEqual( warnings, expectedWarnings ); - assert.deepEqual( names, expectedNames ); + if ( expectedNames ) { + assert.deepEqual( names, expectedNames ); + } } catch ( err ) { if ( err.name !== 'ParseError' ) throw err; diff --git a/test/validator/names/input.html b/test/validator/names/input.html index a944d5fec0..ba836ddb90 100644 --- a/test/validator/names/input.html +++ b/test/validator/names/input.html @@ -1,3 +1,27 @@ {{#each things as thing, index}} +

{{index}}: {{thing}}

+ +{{else}} + + {{#each things as thingEachElse, indexEachElse}} +

{{indexEachElse}}: {{thingEachElse}}

+ {{/each}} + {{/each}} + +{{#if foo}} + +{{elseif bar}} + + {{#each things as thingIfElse, indexIfElse}} +

{{indexIfElse}}: {{thingIfElse}}

+ {{/each}} + +{{else}} + + {{#each things as thingElse, indexElse}} +

{{indexElse}}: {{thingElse}}

+ {{/each}} + + {{/if}} diff --git a/test/validator/names/names.json b/test/validator/names/names.json index 01151a29fd..e044812999 100644 --- a/test/validator/names/names.json +++ b/test/validator/names/names.json @@ -1,4 +1,10 @@ [ "thing", - "index" + "index", + "thingEachElse", + "indexEachElse", + "thingIfElse", + "indexIfElse", + "thingElse", + "indexElse" ] diff --git a/test/validator/svg-child-component-undeclared-namespace/input.html b/test/validator/svg-child-component-undeclared-namespace/input.html index b9c3fae27b..ab75adcc59 100644 --- a/test/validator/svg-child-component-undeclared-namespace/input.html +++ b/test/validator/svg-child-component-undeclared-namespace/input.html @@ -1 +1,29 @@ + +{{#each foo as bar}} + + + +{{else}} + + {{#each foo as bar}} + + {{/each}} + +{{/each}} + +{{#if foo}} + +{{elseif bar}} + + {{#each foo as bar}} + + {{/each}} + +{{else}} + + {{#each foo as bar}} + + {{/each}} + +{{/if}} diff --git a/test/validator/svg-child-component-undeclared-namespace/warnings.json b/test/validator/svg-child-component-undeclared-namespace/warnings.json index 6faf58a457..d17aa5c53d 100644 --- a/test/validator/svg-child-component-undeclared-namespace/warnings.json +++ b/test/validator/svg-child-component-undeclared-namespace/warnings.json @@ -5,4 +5,36 @@ "column": 0 }, "pos": 0 +}, +{ + "message": " is an SVG element – did you forget to add { namespace: 'svg' } ?", + "loc": { + "column": 1, + "line": 5 + }, + "pos": 90 +}, +{ + "message": " is an SVG element – did you forget to add { namespace: 'svg' } ?", + "loc": { + "column": 2, + "line": 10 + }, + "pos": 191 +}, +{ + "message": " is an SVG element – did you forget to add { namespace: 'svg' } ?", + "loc": { + "column": 2, + "line": 20 + }, + "pos": 333 +}, +{ + "message": " is an SVG element – did you forget to add { namespace: 'svg' } ?", + "loc": { + "column": 2, + "line": 26 + }, + "pos": 445 }]