Skip to content

Commit ef885a8

Browse files
authored
Fix bug when script tags are missing and multiple parsers are used (#126)
1 parent 8ce78e8 commit ef885a8

File tree

12 files changed

+795
-0
lines changed

12 files changed

+795
-0
lines changed

scripts/update-fixtures-ast.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ for (const name of TARGETS) {
223223
const tokenRangesPath = path.join(ROOT, `${name}/token-ranges.json`)
224224
const treePath = path.join(ROOT, `${name}/tree.json`)
225225
const scopePath = path.join(ROOT, `${name}/scope.json`)
226+
const servicesPath = path.join(ROOT, `${name}/services.json`)
226227
const source = fs.readFileSync(sourcePath, "utf8")
227228
const options = Object.assign(
228229
{ filePath: sourcePath },
@@ -249,4 +250,10 @@ for (const name of TARGETS) {
249250
scopeToJSON(actual.scopeManager || analyze(actual.ast, options))
250251
)
251252
}
253+
if (fs.existsSync(servicesPath)) {
254+
fs.writeFileSync(
255+
servicesPath,
256+
JSON.stringify(Object.keys(actual.services).sort(), null, 4)
257+
)
258+
}
252259
}

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ export function parseForESLint(
115115
result = parseScript("", {
116116
...options,
117117
ecmaVersion: options.ecmaVersion || DEFAULT_ECMA_VERSION,
118+
parser: scriptParser,
118119
})
119120
} else if (
120121
scripts.length === 2 &&

test/ast.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,13 +175,17 @@ describe("Template AST", () => {
175175
const sourcePath = path.join(ROOT, `${name}/source.vue`)
176176
const optionsPath = path.join(ROOT, `${name}/parser-options.json`)
177177
const requirementsPath = path.join(ROOT, `${name}/requirements.json`)
178+
const servicesPath = path.join(ROOT, `${name}/services.json`)
178179
const source = fs.readFileSync(sourcePath, "utf8")
179180
const parserOptions = fs.existsSync(optionsPath)
180181
? JSON.parse(fs.readFileSync(optionsPath, "utf8"))
181182
: {}
182183
const requirements = fs.existsSync(requirementsPath)
183184
? JSON.parse(fs.readFileSync(requirementsPath, "utf8"))
184185
: {}
186+
const services = fs.existsSync(servicesPath)
187+
? JSON.parse(fs.readFileSync(servicesPath, "utf8"))
188+
: null
185189
const options = Object.assign(
186190
{ filePath: sourcePath },
187191
PARSER_OPTIONS,
@@ -293,6 +297,15 @@ describe("Template AST", () => {
293297
it("should have correct parent properties.", () => {
294298
validateParent(source, parserOptions)
295299
})
300+
301+
if (services) {
302+
it("should have correct services.", () => {
303+
assert.deepStrictEqual(
304+
Object.keys(actual.services).sort(),
305+
services
306+
)
307+
})
308+
}
296309
})
297310
}
298311
})
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[
2+
"defineCustomBlocksVisitor",
3+
"defineDocumentVisitor",
4+
"defineTemplateBodyVisitor",
5+
"esTreeNodeToTSNodeMap",
6+
"getDocumentFragment",
7+
"getTemplateBodyTokenStore",
8+
"hasFullTypeInformation",
9+
"program",
10+
"tsNodeToESTreeNodeMap"
11+
]
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[
2+
"defineCustomBlocksVisitor",
3+
"defineDocumentVisitor",
4+
"defineTemplateBodyVisitor",
5+
"getDocumentFragment",
6+
"getTemplateBodyTokenStore"
7+
]
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[
2+
"defineCustomBlocksVisitor",
3+
"defineDocumentVisitor",
4+
"defineTemplateBodyVisitor",
5+
"esTreeNodeToTSNodeMap",
6+
"getDocumentFragment",
7+
"getTemplateBodyTokenStore",
8+
"hasFullTypeInformation",
9+
"program",
10+
"tsNodeToESTreeNodeMap"
11+
]

0 commit comments

Comments
 (0)