Skip to content

Commit 651ddc7

Browse files
authored
Fixed parsing-error when self-closing (#15)
1 parent 2175019 commit 651ddc7

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

lib/styles/context/style/index.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ export class StyleContext {
136136
needReport: eof.inDocumentFragment,
137137
loc: { line: eof.error.lineNumber, column: eof.error.column },
138138
}
139-
} else if (endTag == null) {
139+
} else if (endTag == null && !startTag.selfClosing) {
140140
this.invalid = {
141141
message: "Missing end tag",
142142
needReport: true,
@@ -148,11 +148,10 @@ export class StyleContext {
148148

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

151-
if (!this.invalid && endTag != null) {
152-
this.cssText = sourceCode.text.slice(
153-
startTag.range[1],
154-
endTag.range[0],
155-
)
151+
if (!this.invalid) {
152+
this.cssText = endTag
153+
? sourceCode.text.slice(startTag.range[1], endTag.range[0])
154+
: ""
156155
this.cssNode = parse(
157156
sourceCode,
158157
startTag.loc.end,

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "eslint-plugin-vue-scoped-css",
3-
"version": "0.2.1",
3+
"version": "0.2.2",
44
"description": "ESLint plugin for Scoped CSS in Vue.js",
55
"main": "dist/index.js",
66
"scripts": {

tests/lib/rules/no-parsing-error.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ tester.run("no-parsing-error", rule, {
2222
`
2323
<template></template>
2424
`,
25+
`
26+
<template><!-- When using vue-eslint-parser@5, a template tag is required. --></template>
27+
<style scoped/>
28+
`,
2529
],
2630
invalid: [
2731
{

0 commit comments

Comments
 (0)