Skip to content

Commit 9f564da

Browse files
authored
Don't reread the input file on ts linting
This fixes #2786.
1 parent 6708063 commit 9f564da

File tree

1 file changed

+9
-1
lines changed
  • packages/@vue/cli-plugin-typescript/lib

1 file changed

+9
-1
lines changed

packages/@vue/cli-plugin-typescript/lib/tslint.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ module.exports = function lint (args = {}, api, silent) {
2929
if (isVueFile(file)) {
3030
const parts = vueFileCache.get(path.normalize(file))
3131
if (parts) {
32+
parts.content = content;
3233
const { before, after } = parts
3334
content = `${before}\n${content.trim()}\n${after}`
3435
}
@@ -42,12 +43,19 @@ module.exports = function lint (args = {}, api, silent) {
4243
}
4344

4445
const parseTSFromVueFile = file => {
46+
47+
// If the file has already been cached, don't read the file again. Use the cache instead.
48+
if (vueFileCache.has(file)) {
49+
return vueFileCache.get(file).content;
50+
}
51+
4552
const content = fs.readFileSync(file, 'utf-8')
4653
const { script } = vueCompiler.parseComponent(content, { pad: 'line' })
4754
if (script && /^tsx?$/.test(script.lang)) {
4855
vueFileCache.set(file, {
4956
before: content.slice(0, script.start),
50-
after: content.slice(script.end)
57+
after: content.slice(script.end),
58+
content: script.content,
5159
})
5260
return script.content
5361
}

0 commit comments

Comments
 (0)