Skip to content

Commit 455d083

Browse files
authored
refactor: use verbatimModuleSyntax instead of importsNotUsedAsValues (#18360)
1 parent 7338ee3 commit 455d083

File tree

3 files changed

+14
-16
lines changed

3 files changed

+14
-16
lines changed

playground/tsconfig-json-load-error/tsconfig.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"noImplicitReturns": true,
1515

1616
"useDefineForClassFields": true,
17-
"importsNotUsedAsValues": "preserve"
17+
"verbatimModuleSyntax": true
1818
},
1919
"include": ["./src"]
2020
}

playground/tsconfig-json/__tests__/tsconfig-json.spec.ts

+12-14
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@ import { describe, expect, test } from 'vitest'
55
import { browserLogs, isServe, serverLogs } from '~utils'
66

77
test('should respected each `tsconfig.json`s compilerOptions', () => {
8-
// main side effect should be called (because of `"importsNotUsedAsValues": "preserve"`)
8+
// main side effect should be called (because of `"verbatimModuleSyntax": true`)
99
expect(browserLogs).toContain('main side effect')
1010
// main base setter should not be called (because of `"useDefineForClassFields": true"`)
1111
expect(browserLogs).not.toContain('data setter in MainBase')
1212

13-
// nested side effect should not be called (because "importsNotUsedAsValues" is not set, defaults to "remove")
13+
// nested side effect should not be called (because "verbatimModuleSyntax" is not set, defaults to false)
1414
expect(browserLogs).not.toContain('nested side effect')
1515
// nested base setter should be called (because of `"useDefineForClassFields": false"`)
1616
expect(browserLogs).toContain('data setter in NestedBase')
1717

18-
// nested-with-extends side effect should be called (because "importsNotUsedAsValues" is extended from the main tsconfig.json, which is "preserve")
18+
// nested-with-extends side effect should be called (because "verbatimModuleSyntax" is extended from the main tsconfig.json, which is true)
1919
expect(browserLogs).toContain('nested-with-extends side effect')
2020
// nested-with-extends base setter should be called (because of `"useDefineForClassFields": false"`)
2121
expect(browserLogs).toContain('data setter in NestedWithExtendsBase')
@@ -42,8 +42,8 @@ describe('transformWithEsbuild', () => {
4242
},
4343
},
4444
})
45-
// "importsNotUsedAsValues": "preserve" from tsconfig.json should still work
46-
expect(result.code).toContain('import "./not-used-type";')
45+
// "verbatimModuleSyntax": true from tsconfig.json should still work
46+
expect(result.code).toMatch(/import.*".\/not-used-type";/)
4747
})
4848

4949
test('overwrite tsconfigRaw string', async () => {
@@ -56,26 +56,24 @@ describe('transformWithEsbuild', () => {
5656
}
5757
}`,
5858
})
59-
// "importsNotUsedAsValues": "preserve" from tsconfig.json should not be read
60-
// and defaults to "remove"
61-
expect(result.code).not.toContain('import "./not-used-type";')
59+
// "verbatimModuleSyntax": true from from tsconfig.json should not be read
60+
// and defaults to false
61+
expect(result.code).not.toMatch(/import.*".\/not-used-type";/)
6262
})
6363

64-
test('preserveValueImports', async () => {
64+
test('verbatimModuleSyntax', async () => {
6565
const main = path.resolve(__dirname, '../src/main.ts')
6666
const mainContent = fs.readFileSync(main, 'utf-8')
6767
const result = await transformWithEsbuild(mainContent, main, {
6868
tsconfigRaw: {
6969
compilerOptions: {
7070
useDefineForClassFields: false,
71-
preserveValueImports: true,
71+
verbatimModuleSyntax: false,
7272
},
7373
},
7474
})
75-
// "importsNotUsedAsValues": "preserve" from tsconfig.json should still work
76-
expect(result.code).toContain(
77-
'import { MainTypeOnlyClass } from "./not-used-type";',
78-
)
75+
// "verbatimModuleSyntax": false from tsconfig.json should still work
76+
expect(result.code).not.toMatch(/import.*".\/not-used-type";/)
7977
})
8078

8179
test('experimentalDecorators', async () => {

playground/tsconfig-json/tsconfig.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"noImplicitReturns": true,
1515

1616
"useDefineForClassFields": true,
17-
"importsNotUsedAsValues": "preserve",
17+
"verbatimModuleSyntax": true,
1818
"experimentalDecorators": true
1919
},
2020
"include": ["./src"]

0 commit comments

Comments
 (0)