Skip to content

Commit

Permalink
Don't reread the input file on ts linting
Browse files Browse the repository at this point in the history
This fixes vuejs#2786.
  • Loading branch information
fourplusone committed Oct 22, 2018
1 parent 6708063 commit 9f564da
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion packages/@vue/cli-plugin-typescript/lib/tslint.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ module.exports = function lint (args = {}, api, silent) {
if (isVueFile(file)) {
const parts = vueFileCache.get(path.normalize(file))
if (parts) {
parts.content = content;
const { before, after } = parts
content = `${before}\n${content.trim()}\n${after}`
}
Expand All @@ -42,12 +43,19 @@ module.exports = function lint (args = {}, api, silent) {
}

const parseTSFromVueFile = file => {

// If the file has already been cached, don't read the file again. Use the cache instead.
if (vueFileCache.has(file)) {
return vueFileCache.get(file).content;
}

const content = fs.readFileSync(file, 'utf-8')
const { script } = vueCompiler.parseComponent(content, { pad: 'line' })
if (script && /^tsx?$/.test(script.lang)) {
vueFileCache.set(file, {
before: content.slice(0, script.start),
after: content.slice(script.end)
after: content.slice(script.end),
content: script.content,
})
return script.content
}
Expand Down

0 comments on commit 9f564da

Please sign in to comment.