From 6a6543a57cef2401d1ba021bffc995d96fe382c2 Mon Sep 17 00:00:00 2001 From: yosuke ota Date: Thu, 14 Nov 2019 00:12:45 +0900 Subject: [PATCH] Use parserServices.getDocumentFragment --- lib/rules/component-tags-order.js | 11 +++++------ tests/lib/rules/component-tags-order.js | 17 ++++++++++++++--- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/lib/rules/component-tags-order.js b/lib/rules/component-tags-order.js index e7f8f39ac..6f63c2cf0 100644 --- a/lib/rules/component-tags-order.js +++ b/lib/rules/component-tags-order.js @@ -39,12 +39,11 @@ module.exports = { }, create (context) { const order = (context.options[0] && context.options[0].order) || DEFAULT_ORDER + const documentFragment = context.parserServices.getDocumentFragment && context.parserServices.getDocumentFragment() - function getTopLevelHTMLElements (node) { - const templateBody = node.templateBody - if (templateBody) { - const document = templateBody.parent - return document.children + function getTopLevelHTMLElements () { + if (documentFragment) { + return documentFragment.children } return [] } @@ -70,7 +69,7 @@ module.exports = { if (utils.hasInvalidEOF(node)) { return } - const elements = getTopLevelHTMLElements(node) + const elements = getTopLevelHTMLElements() elements.forEach((element, index) => { const expectedIndex = order.indexOf(element.name) diff --git a/tests/lib/rules/component-tags-order.js b/tests/lib/rules/component-tags-order.js index 75702cdff..a9108fb76 100644 --- a/tests/lib/rules/component-tags-order.js +++ b/tests/lib/rules/component-tags-order.js @@ -15,7 +15,7 @@ const RuleTester = require('eslint').RuleTester // ------------------------------------------------------------------------------ const tester = new RuleTester({ - parser: 'vue-eslint-parser' + parser: require.resolve('vue-eslint-parser') }) tester.run('component-tags-order', rule, { @@ -64,8 +64,6 @@ tester.run('component-tags-order', rule, { options: [{ order: ['docs', 'script', 'template', 'style'] }] }, - // No template (can not check) - ``, ``, // Invalid EOF @@ -201,6 +199,19 @@ tester.run('component-tags-order', rule, { line: 5 } ] + }, + // no