Skip to content
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

Fix bug when script tags are missing and multiple parsers are used #126

Merged
merged 1 commit into from
Sep 5, 2021
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
7 changes: 7 additions & 0 deletions scripts/update-fixtures-ast.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ for (const name of TARGETS) {
const tokenRangesPath = path.join(ROOT, `${name}/token-ranges.json`)
const treePath = path.join(ROOT, `${name}/tree.json`)
const scopePath = path.join(ROOT, `${name}/scope.json`)
const servicesPath = path.join(ROOT, `${name}/services.json`)
const source = fs.readFileSync(sourcePath, "utf8")
const options = Object.assign(
{ filePath: sourcePath },
Expand All @@ -249,4 +250,10 @@ for (const name of TARGETS) {
scopeToJSON(actual.scopeManager || analyze(actual.ast, options))
)
}
if (fs.existsSync(servicesPath)) {
fs.writeFileSync(
servicesPath,
JSON.stringify(Object.keys(actual.services).sort(), null, 4)
)
}
}
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ export function parseForESLint(
result = parseScript("", {
...options,
ecmaVersion: options.ecmaVersion || DEFAULT_ECMA_VERSION,
parser: scriptParser,
})
} else if (
scripts.length === 2 &&
Expand Down
13 changes: 13 additions & 0 deletions test/ast.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,13 +175,17 @@ describe("Template AST", () => {
const sourcePath = path.join(ROOT, `${name}/source.vue`)
const optionsPath = path.join(ROOT, `${name}/parser-options.json`)
const requirementsPath = path.join(ROOT, `${name}/requirements.json`)
const servicesPath = path.join(ROOT, `${name}/services.json`)
const source = fs.readFileSync(sourcePath, "utf8")
const parserOptions = fs.existsSync(optionsPath)
? JSON.parse(fs.readFileSync(optionsPath, "utf8"))
: {}
const requirements = fs.existsSync(requirementsPath)
? JSON.parse(fs.readFileSync(requirementsPath, "utf8"))
: {}
const services = fs.existsSync(servicesPath)
? JSON.parse(fs.readFileSync(servicesPath, "utf8"))
: null
const options = Object.assign(
{ filePath: sourcePath },
PARSER_OPTIONS,
Expand Down Expand Up @@ -293,6 +297,15 @@ describe("Template AST", () => {
it("should have correct parent properties.", () => {
validateParent(source, parserOptions)
})

if (services) {
it("should have correct services.", () => {
assert.deepStrictEqual(
Object.keys(actual.services).sort(),
services
)
})
}
})
}
})
11 changes: 11 additions & 0 deletions test/fixtures/ast/parser-option-multiple-parsers-1/services.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[
"defineCustomBlocksVisitor",
"defineDocumentVisitor",
"defineTemplateBodyVisitor",
"esTreeNodeToTSNodeMap",
"getDocumentFragment",
"getTemplateBodyTokenStore",
"hasFullTypeInformation",
"program",
"tsNodeToESTreeNodeMap"
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[
"defineCustomBlocksVisitor",
"defineDocumentVisitor",
"defineTemplateBodyVisitor",
"getDocumentFragment",
"getTemplateBodyTokenStore"
]
11 changes: 11 additions & 0 deletions test/fixtures/ast/parser-option-multiple-parsers-3/services.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[
"defineCustomBlocksVisitor",
"defineDocumentVisitor",
"defineTemplateBodyVisitor",
"esTreeNodeToTSNodeMap",
"getDocumentFragment",
"getTemplateBodyTokenStore",
"hasFullTypeInformation",
"program",
"tsNodeToESTreeNodeMap"
]
Loading