Skip to content

Fixed parsing-error when self-closing #15

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions lib/styles/context/style/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ export class StyleContext {
needReport: eof.inDocumentFragment,
loc: { line: eof.error.lineNumber, column: eof.error.column },
}
} else if (endTag == null) {
} else if (endTag == null && !startTag.selfClosing) {
this.invalid = {
message: "Missing end tag",
needReport: true,
Expand All @@ -148,11 +148,10 @@ export class StyleContext {

this.lang = ((style && getLang(style)) || "css").toLowerCase()

if (!this.invalid && endTag != null) {
this.cssText = sourceCode.text.slice(
startTag.range[1],
endTag.range[0],
)
if (!this.invalid) {
this.cssText = endTag
? sourceCode.text.slice(startTag.range[1], endTag.range[0])
: ""
this.cssNode = parse(
sourceCode,
startTag.loc.end,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "eslint-plugin-vue-scoped-css",
"version": "0.2.1",
"version": "0.2.2",
"description": "ESLint plugin for Scoped CSS in Vue.js",
"main": "dist/index.js",
"scripts": {
Expand Down
4 changes: 4 additions & 0 deletions tests/lib/rules/no-parsing-error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ tester.run("no-parsing-error", rule, {
`
<template></template>
`,
`
<template><!-- When using vue-eslint-parser@5, a template tag is required. --></template>
<style scoped/>
`,
],
invalid: [
{
Expand Down