Skip to content

Commit 7a8cce6

Browse files
yoyo930021bradzacher
authored andcommitted
fix(typescript-estree): parsing error for vue sfc (#1083)
1 parent 2fc9bd2 commit 7a8cce6

6 files changed

Lines changed: 54 additions & 6 deletions

File tree

packages/typescript-estree/src/create-program/createWatchProgram.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,6 @@ function getProgramsForProjects(
194194
results.push(program);
195195
}
196196

197-
parsedFilesSeen.add(filePath);
198197
return results;
199198
}
200199

@@ -216,11 +215,13 @@ function createWatchProgram(
216215

217216
// ensure readFile reads the code being linted instead of the copy on disk
218217
const oldReadFile = watchCompilerHost.readFile;
219-
watchCompilerHost.readFile = (filePath, encoding): string | undefined =>
220-
path.normalize(filePath) ===
221-
path.normalize(currentLintOperationState.filePath)
218+
watchCompilerHost.readFile = (filePath, encoding): string | undefined => {
219+
parsedFilesSeen.add(filePath);
220+
return path.normalize(filePath) ===
221+
path.normalize(currentLintOperationState.filePath)
222222
? currentLintOperationState.code
223223
: oldReadFile(filePath, encoding);
224+
};
224225

225226
// ensure process reports error on failure instead of exiting process immediately
226227
watchCompilerHost.onUnRecoverableConfigFileDiagnostic = diagnosticReporter;

tests/integration/fixtures/vue-sfc/.eslintrc.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ env:
66
es6: true
77
node: true
88

9+
extends:
10+
plugin:vue/essential
11+
912
parserOptions:
1013
# Local version of @typescript-eslint/parser
1114
parser: '@typescript-eslint/parser'
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<!-- World.vue -->
2+
<template>
3+
<div>
4+
<div :id="name">
5+
{{ enthusiasm }}
6+
</div>
7+
<button @click="decrement">-</button>
8+
<button @click="increment">+</button>
9+
</div>
10+
</template>
11+
12+
<script lang="ts">
13+
import Vue from "vue";
14+
export default Vue.extend({
15+
props: ['name', 'initialEnthusiasm'],
16+
data() {
17+
return {
18+
enthusiasm: this.initialEnthusiasm,
19+
}
20+
},
21+
methods: {
22+
increment() { this.enthusiasm++; },
23+
decrement() {
24+
if (this.enthusiasm > 1) {
25+
this.enthusiasm--;
26+
}
27+
},
28+
}
29+
});
30+
</script>

tests/integration/fixtures/vue-sfc/test.js.snap

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,5 +59,13 @@ export default Vue.extend({
5959
",
6060
"warningCount": 0,
6161
},
62+
Object {
63+
"errorCount": 0,
64+
"filePath": "/usr/linked/World.vue",
65+
"fixableErrorCount": 0,
66+
"fixableWarningCount": 0,
67+
"messages": Array [],
68+
"warningCount": 0,
69+
},
6270
]
6371
`;

tests/integration/fixtures/vue-sfc/test.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ npm install $(npm pack /usr/eslint-plugin | tail -1)
1414
# Install the latest vue-eslint-parser (this may break us occassionally, but it's probably good to get that feedback early)
1515
npm install vue-eslint-parser@latest
1616

17+
# Install the latest eslint-plugin-vue (this may break us occassionally, but it's probably good to get that feedback early)
18+
npm install eslint-plugin-vue@latest
19+
1720
# Run the linting
1821
# (the "|| true" helps make sure that we run our tests on failed linting runs as well)
1922
npx eslint --format json --output-file /usr/lint-output.json --config /usr/linked/.eslintrc.yml /usr/linked/**/*.vue || true
Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
{
22
"compilerOptions": {
33
"strict": true
4-
}
5-
}
4+
},
5+
"include": [
6+
"*.vue"
7+
]
8+
}

0 commit comments

Comments
 (0)