forked from vitejs/vite
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: respect tsconfig options that affects compilation results (vite…
- Loading branch information
1 parent
0403b00
commit 803b1a6
Showing
15 changed files
with
256 additions
and
1 deletion.
There are no files selected for viewing
16 changes: 16 additions & 0 deletions
16
packages/playground/tsconfig-json/__tests__/tsconfig-json.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
test('should respected each `tsconfig.json`s compilerOptions', () => { | ||
// main side effect should be called (because of `"importsNotUsedAsValues": "preserve"`) | ||
expect(browserLogs).toContain('main side effect') | ||
// main base setter should not be called (because of `"useDefineForClassFields": true"`) | ||
expect(browserLogs).not.toContain('data setter in MainBase') | ||
|
||
// nested side effect should not be called (because "importsNotUsedAsValues" is not set, defaults to "remove") | ||
expect(browserLogs).not.toContain('nested side effect') | ||
// nested base setter should be called (because of `"useDefineForClassFields": false"`) | ||
expect(browserLogs).toContain('data setter in NestedBase') | ||
|
||
// nested-with-extends side effect should be called (because "importsNotUsedAsValues" is extended from the main tsconfig.json, which is "preserve") | ||
expect(browserLogs).toContain('nested-with-extends side effect') | ||
// nested-with-extends base setter should be called (because of `"useDefineForClassFields": false"`) | ||
expect(browserLogs).toContain('data setter in NestedWithExtendsBase') | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>Vite App</title> | ||
</head> | ||
<body> | ||
<div id="app"><!--app-html--></div> | ||
<script type="module" src="/src/main.ts"></script> | ||
</body> | ||
</html> |
17 changes: 17 additions & 0 deletions
17
packages/playground/tsconfig-json/nested-with-extends/main.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// @ts-nocheck | ||
import { NestedWithExtendsTypeOnlyClass } from './not-used-type' | ||
|
||
class NestedWithExtendsBase { | ||
set data(value: string) { | ||
console.log('data setter in NestedWithExtendsBase') | ||
} | ||
} | ||
class NestedWithExtendsDerived extends NestedWithExtendsBase { | ||
// No longer triggers a 'console.log' | ||
// when using 'useDefineForClassFields'. | ||
data = 10 | ||
|
||
foo?: NestedWithExtendsTypeOnlyClass | ||
} | ||
|
||
const d = new NestedWithExtendsDerived() |
3 changes: 3 additions & 0 deletions
3
packages/playground/tsconfig-json/nested-with-extends/not-used-type.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
console.log('nested-with-extends side effect') | ||
|
||
export class NestedWithExtendsTypeOnlyClass {} |
7 changes: 7 additions & 0 deletions
7
packages/playground/tsconfig-json/nested-with-extends/tsconfig.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"extends": "../tsconfig.json", | ||
"include": ["./"], | ||
"compilerOptions": { | ||
"useDefineForClassFields": false | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// @ts-nocheck | ||
import { NestedTypeOnlyClass } from './not-used-type' | ||
|
||
class NestedBase { | ||
set data(value: string) { | ||
console.log('data setter in NestedBase') | ||
} | ||
} | ||
class NestedDerived extends NestedBase { | ||
// No longer triggers a 'console.log' | ||
// when using 'useDefineForClassFields'. | ||
data = 10 | ||
|
||
foo?: NestedTypeOnlyClass | ||
} | ||
|
||
const d = new NestedDerived() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
console.log('nested side effect') | ||
|
||
export class NestedTypeOnlyClass {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"include": ["./"], | ||
"compilerOptions": { | ||
"target": "ESNext", | ||
"module": "ESNext", | ||
"lib": ["ESNext", "DOM"], | ||
"moduleResolution": "Node", | ||
"strict": true, | ||
"sourceMap": true, | ||
"resolveJsonModule": true, | ||
"esModuleInterop": true, | ||
"noEmit": true, | ||
"noUnusedLocals": true, | ||
"noUnusedParameters": true, | ||
"noImplicitReturns": true, | ||
|
||
"useDefineForClassFields": false | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"name": "tsconfig-json", | ||
"private": true, | ||
"version": "0.0.0", | ||
"scripts": { | ||
"dev": "vite", | ||
"build": "vite build", | ||
"debug": "node --inspect-brk ../../vite/bin/vite", | ||
"serve": "vite preview" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// @ts-nocheck | ||
import '../nested/main' | ||
import '../nested-with-extends/main' | ||
|
||
import { MainTypeOnlyClass } from './not-used-type' | ||
|
||
class MainBase { | ||
set data(value: string) { | ||
console.log('data setter in MainBase') | ||
} | ||
} | ||
class MainDerived extends MainBase { | ||
// No longer triggers a 'console.log' | ||
// when using 'useDefineForClassFields'. | ||
data = 10 | ||
|
||
foo?: MainTypeOnlyClass | ||
} | ||
|
||
const d = new MainDerived() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
console.log('main side effect') | ||
|
||
export class MainTypeOnlyClass {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "ESNext", | ||
"module": "ESNext", | ||
"lib": ["ESNext", "DOM"], | ||
"moduleResolution": "Node", | ||
"strict": true, | ||
"sourceMap": true, | ||
"resolveJsonModule": true, | ||
"esModuleInterop": true, | ||
"noEmit": true, | ||
"noUnusedLocals": true, | ||
"noUnusedParameters": true, | ||
"noImplicitReturns": true, | ||
|
||
"useDefineForClassFields": true, | ||
"importsNotUsedAsValues": "preserve" | ||
}, | ||
"include": ["./src"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters