Skip to content

Commit bb516da

Browse files
thebanjomaticAdam Hines
andauthored
fix: parse extended tsconfigs when transpiling script blocks (#502)
* fix(tsconfig): parse extended tsconfigs when transpiling script blocks A change introduced in v28.1.0 in PR #471 unintentionally changed the behavior of the tsconfig parsing such that configs using "extends" were no longer being considered. Fixes: #495 * chore(cache): cache tsconfig parsing to avoid the cost per vue file / interpolated string Co-authored-by: Adam Hines <ahines@factset.com>
1 parent 62d6ebc commit bb516da

16 files changed

+220
-61
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<template>
2+
<div>
3+
{{ exclamationMarks }}
4+
<type-script-child />
5+
</div>
6+
</template>
7+
8+
<script lang="ts">
9+
import TypeScriptChild from './TypeScriptChild.vue'
10+
11+
import moduleRequiringEsModuleInterop from './ModuleRequiringEsModuleInterop'
12+
13+
// The default import above relies on esModuleInterop being set to true in order to use it from
14+
// an import statement instead of require. This option is configured in the tsconfig.base.json,
15+
// so if we are no longer fully processing the tsconfig options (extended from a base config)
16+
// this test should fail. This was one of the only reliable ways I could get a test to fail if
17+
// these conditions are not being met and happen to be the use-case which was triggering errors
18+
// in my config setup.
19+
20+
if (moduleRequiringEsModuleInterop()) {
21+
throw new Error('Should never hit this')
22+
}
23+
24+
export default {
25+
computed: {
26+
exclamationMarks(): string {
27+
return 'string'
28+
}
29+
},
30+
components: {
31+
TypeScriptChild
32+
}
33+
}
34+
</script>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = () => false

e2e/2.x/basic/test.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ import Jsx from './components/Jsx.vue'
2121
import Constructor from './components/Constructor.vue'
2222
import { compileStyle } from '@vue/component-compiler-utils'
2323
import ScriptSetup from './components/ScriptSetup'
24+
import ExtendedTsConfig from './components/ExtendedTsConfig.vue'
25+
2426
jest.mock('@vue/component-compiler-utils', () => ({
2527
...jest.requireActual('@vue/component-compiler-utils'),
2628
compileStyle: jest.fn(() => ({ errors: [], code: '' }))
@@ -163,6 +165,11 @@ test('processes SFC with <script setup>', () => {
163165
expect(wrapper.html()).toContain('Welcome to Your Vue.js App')
164166
})
165167

168+
test('handles extended tsconfig.json files', () => {
169+
const wrapper = mount(ExtendedTsConfig)
170+
expect(wrapper.element.tagName).toBe('DIV')
171+
})
172+
166173
test('should pass properly "styleOptions" into "preprocessOptions"', () => {
167174
const filePath = resolve(__dirname, './components/Basic.vue')
168175
const fileString = readFileSync(filePath, { encoding: 'utf8' })

e2e/2.x/basic/tsconfig.base.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"compilerOptions": {
3+
"target": "es5",
4+
"lib": ["dom", "es6"],
5+
"module": "es2015",
6+
"moduleResolution": "node",
7+
"types": ["vue-typescript-import-dts", "node"],
8+
"isolatedModules": false,
9+
"experimentalDecorators": true,
10+
"noImplicitAny": true,
11+
"noImplicitThis": true,
12+
"strictNullChecks": true,
13+
"removeComments": true,
14+
"emitDecoratorMetadata": true,
15+
"suppressImplicitAnyIndexErrors": true,
16+
"allowSyntheticDefaultImports": true,
17+
"sourceMap": true,
18+
"esModuleInterop": true,
19+
"allowJs": true
20+
}
21+
}

e2e/2.x/basic/tsconfig.json

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,3 @@
11
{
2-
"compilerOptions": {
3-
"target": "es5",
4-
"lib": ["dom", "es6"],
5-
"module": "es2015",
6-
"moduleResolution": "node",
7-
"types": ["vue-typescript-import-dts", "node"],
8-
"isolatedModules": false,
9-
"experimentalDecorators": true,
10-
"noImplicitAny": true,
11-
"noImplicitThis": true,
12-
"strictNullChecks": true,
13-
"removeComments": true,
14-
"emitDecoratorMetadata": true,
15-
"suppressImplicitAnyIndexErrors": true,
16-
"allowSyntheticDefaultImports": true,
17-
"sourceMap": true,
18-
"allowJs": true
19-
}
2+
"extends": "./tsconfig.base.json"
203
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<template>
2+
<div>
3+
{{ exclamationMarks }}
4+
<type-script-child />
5+
</div>
6+
</template>
7+
8+
<script lang="ts">
9+
import TypeScriptChild from './TypeScriptChild.vue'
10+
11+
import moduleRequiringEsModuleInterop from './ModuleRequiringEsModuleInterop'
12+
13+
// The default import above relies on esModuleInterop being set to true in order to use it from
14+
// an import statement instead of require. This option is configured in the tsconfig.base.json,
15+
// so if we are no longer fully processing the tsconfig options (extended from a base config)
16+
// this test should fail. This was one of the only reliable ways I could get a test to fail if
17+
// these conditions are not being met and happen to be the use-case which was triggering errors
18+
// in my config setup.
19+
20+
if (moduleRequiringEsModuleInterop()) {
21+
throw new Error('Should never hit this')
22+
}
23+
24+
export default {
25+
computed: {
26+
exclamationMarks(): string {
27+
return 'string'
28+
}
29+
},
30+
components: {
31+
TypeScriptChild
32+
}
33+
}
34+
</script>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = () => false

e2e/3.x/basic/test.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import ScriptSetup from './components/ScriptSetup.vue'
2323
import ScriptSetupSugarRef from './components/ScriptSetupSugarRef.vue'
2424
import FunctionalRenderFn from './components/FunctionalRenderFn.vue'
2525
import CompilerDirective from './components/CompilerDirective.vue'
26+
import ExtendedTsConfig from './components/ExtendedTsConfig.vue'
2627

2728
// TODO: JSX for Vue 3? TSX?
2829
import Jsx from './components/Jsx.vue'
@@ -207,3 +208,9 @@ test('ensure compilerOptions is passed down', () => {
207208
const elm = document.querySelector('h1')
208209
expect(elm.hasAttribute('data-test')).toBe(false)
209210
})
211+
212+
test('handles extended tsconfig.json files', () => {
213+
mount(ExtendedTsConfig)
214+
const elm = document.querySelector('div')
215+
expect(elm).toBeDefined()
216+
})

e2e/3.x/basic/tsconfig.base.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"compilerOptions": {
3+
"target": "es5",
4+
"lib": ["dom", "es6"],
5+
"module": "es2015",
6+
"moduleResolution": "node",
7+
"types": ["vue-typescript-import-dts", "node"],
8+
"isolatedModules": false,
9+
"experimentalDecorators": true,
10+
"noImplicitAny": true,
11+
"noImplicitThis": true,
12+
"strictNullChecks": true,
13+
"removeComments": true,
14+
"emitDecoratorMetadata": true,
15+
"suppressImplicitAnyIndexErrors": true,
16+
"allowSyntheticDefaultImports": true,
17+
"sourceMap": true,
18+
"esModuleInterop": true,
19+
"allowJs": true
20+
}
21+
}

e2e/3.x/basic/tsconfig.json

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,3 @@
11
{
2-
"compilerOptions": {
3-
"target": "es5",
4-
"lib": ["dom", "es6"],
5-
"module": "es2015",
6-
"moduleResolution": "node",
7-
"types": ["vue-typescript-import-dts", "node"],
8-
"isolatedModules": false,
9-
"experimentalDecorators": true,
10-
"noImplicitAny": true,
11-
"noImplicitThis": true,
12-
"strictNullChecks": true,
13-
"removeComments": true,
14-
"emitDecoratorMetadata": true,
15-
"suppressImplicitAnyIndexErrors": true,
16-
"allowSyntheticDefaultImports": true,
17-
"sourceMap": true,
18-
"allowJs": true
19-
}
2+
"extends": "./tsconfig.base.json"
203
}

0 commit comments

Comments
 (0)