Skip to content

Commit 7ae9dbf

Browse files
committed
chore(deps): bump TS to 5.4
1 parent 16174da commit 7ae9dbf

File tree

11 files changed

+127
-72
lines changed

11 files changed

+127
-72
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"test-unit": "vitest -c vitest.unit.config.ts",
2121
"test-e2e": "node scripts/build.js vue -f global -d && vitest -c vitest.e2e.config.ts",
2222
"test-dts": "run-s build-dts test-dts-only",
23-
"test-dts-only": "tsc -p ./packages/dts-test/tsconfig.test.json",
23+
"test-dts-only": "tsc -p packages/dts-built-test/tsconfig.json && tsc -p ./packages/dts-test/tsconfig.test.json",
2424
"test-coverage": "vitest -c vitest.unit.config.ts --coverage",
2525
"test-bench": "vitest bench",
2626
"release": "node scripts/release.js",
@@ -111,7 +111,7 @@
111111
"todomvc-app-css": "^2.4.3",
112112
"tslib": "^2.6.2",
113113
"tsx": "^4.7.2",
114-
"typescript": "^5.2.2",
114+
"typescript": "~5.4.5",
115115
"vite": "^5.2.7",
116116
"vitest": "^1.4.0"
117117
}

packages/compiler-core/src/codegen.ts

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import {
2828
getVNodeHelper,
2929
locStub,
3030
} from './ast'
31-
import { type RawSourceMap, SourceMapGenerator } from 'source-map-js'
31+
import { SourceMapGenerator } from 'source-map-js'
3232
import {
3333
advancePositionWithMutation,
3434
assert,
@@ -56,6 +56,45 @@ import {
5656
} from './runtimeHelpers'
5757
import type { ImportItem } from './transform'
5858

59+
/**
60+
* The `SourceMapGenerator` type from `source-map-js` is a bit incomplete as it
61+
* misses `toJSON()`. We also need to add types for internal properties which we
62+
* need to access for better performance.
63+
*
64+
* Since TS 5.3, dts generation starts to strangely include broken triple slash
65+
* references for source-map-js, so we are inlining all source map related types
66+
* here to to workaround that.
67+
*/
68+
export interface CodegenSourceMapGenerator {
69+
setSourceContent(sourceFile: string, sourceContent: string): void
70+
// SourceMapGenerator has this method but the types do not include it
71+
toJSON(): RawSourceMap
72+
_sources: Set<string>
73+
_names: Set<string>
74+
_mappings: {
75+
add(mapping: MappingItem): void
76+
}
77+
}
78+
79+
export interface RawSourceMap {
80+
file?: string
81+
sourceRoot?: string
82+
version: string
83+
sources: string[]
84+
names: string[]
85+
sourcesContent?: string[]
86+
mappings: string
87+
}
88+
89+
interface MappingItem {
90+
source: string
91+
generatedLine: number
92+
generatedColumn: number
93+
originalLine: number
94+
originalColumn: number
95+
name: string | null
96+
}
97+
5998
const PURE_ANNOTATION = `/*#__PURE__*/`
6099

61100
const aliasHelper = (s: symbol) => `${helperNameMap[s]}: _${helperNameMap[s]}`
@@ -85,7 +124,7 @@ export interface CodegenContext
85124
offset: number
86125
indentLevel: number
87126
pure: boolean
88-
map?: SourceMapGenerator
127+
map?: CodegenSourceMapGenerator
89128
helper(key: symbol): string
90129
push(code: string, newlineIndex?: number, node?: CodegenNode): void
91130
indent(): void
@@ -218,14 +257,14 @@ function createCodegenContext(
218257
generatedLine: context.line,
219258
generatedColumn: context.column - 1,
220259
source: filename,
221-
// @ts-expect-error it is possible to be null
222260
name,
223261
})
224262
}
225263

226264
if (!__BROWSER__ && sourceMap) {
227265
// lazy require source-map implementation, only in non-browser builds
228-
context.map = new SourceMapGenerator()
266+
context.map =
267+
new SourceMapGenerator() as unknown as CodegenSourceMapGenerator
229268
context.map.setSourceContent(filename, context.source)
230269
context.map._sources.add(filename)
231270
}

packages/compiler-core/src/index.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,13 @@ export {
2121
type StructuralDirectiveTransform,
2222
type DirectiveTransform,
2323
} from './transform'
24-
export { generate, type CodegenContext, type CodegenResult } from './codegen'
24+
export {
25+
generate,
26+
type CodegenContext,
27+
type CodegenResult,
28+
type CodegenSourceMapGenerator,
29+
type RawSourceMap,
30+
} from './codegen'
2531
export {
2632
ErrorCodes,
2733
errorMessages,

packages/compiler-sfc/src/parse.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
import {
22
type BindingMetadata,
3+
type CodegenSourceMapGenerator,
34
type CompilerError,
45
type ElementNode,
56
NodeTypes,
67
type ParserOptions,
8+
type RawSourceMap,
79
type RootNode,
810
type SourceLocation,
911
createRoot,
1012
} from '@vue/compiler-core'
1113
import * as CompilerDOM from '@vue/compiler-dom'
12-
import { type RawSourceMap, SourceMapGenerator } from 'source-map-js'
14+
import { SourceMapGenerator } from 'source-map-js'
1315
import type { TemplateCompiler } from './compileTemplate'
1416
import { parseCssVars } from './style/cssVars'
1517
import { createCache } from './cache'
@@ -375,7 +377,7 @@ function generateSourceMap(
375377
const map = new SourceMapGenerator({
376378
file: filename.replace(/\\/g, '/'),
377379
sourceRoot: sourceRoot.replace(/\\/g, '/'),
378-
})
380+
}) as unknown as CodegenSourceMapGenerator
379381
map.setSourceContent(filename, source)
380382
map._sources.add(filename)
381383
generated.split(splitRE).forEach((line, index) => {
@@ -390,7 +392,6 @@ function generateSourceMap(
390392
generatedLine,
391393
generatedColumn: i,
392394
source: filename,
393-
// @ts-expect-error
394395
name: null,
395396
})
396397
}

packages/dts-built-test/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "@vue/dts-built-test",
33
"private": true,
44
"version": "0.0.0",
5-
"types": "dist/dts-built-test.d.ts",
5+
"types": "dist/index.d.ts",
66
"dependencies": {
77
"@vue/shared": "workspace:*",
88
"@vue/reactivity": "workspace:*",

packages/dts-built-test/tsconfig.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"compilerOptions": {
3+
"baseUrl": ".",
4+
"outDir": "dist",
5+
"jsx": "preserve",
6+
"module": "esnext",
7+
"strict": true,
8+
"moduleResolution": "Bundler",
9+
"lib": ["esnext", "dom"],
10+
"declaration": true,
11+
"emitDeclarationOnly": true
12+
},
13+
"include": ["./src"]
14+
}

packages/global.d.ts

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -45,18 +45,6 @@ declare module 'estree-walker' {
4545
)
4646
}
4747

48-
declare module 'source-map-js' {
49-
export interface SourceMapGenerator {
50-
// SourceMapGenerator has this method but the types do not include it
51-
toJSON(): RawSourceMap
52-
_sources: Set<string>
53-
_names: Set<string>
54-
_mappings: {
55-
add(mapping: MappingItem): void
56-
}
57-
}
58-
}
59-
6048
declare interface String {
6149
/**
6250
* @deprecated Please use String.prototype.slice instead of String.prototype.substring in the repository.

packages/reactivity/src/reactive.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -409,5 +409,5 @@ export const toReactive = <T extends unknown>(value: T): T =>
409409
*
410410
* @param value - The value for which a readonly proxy shall be created.
411411
*/
412-
export const toReadonly = <T extends unknown>(value: T): T =>
413-
isObject(value) ? readonly(value) : value
412+
export const toReadonly = <T extends unknown>(value: T): DeepReadonly<T> =>
413+
isObject(value) ? readonly(value) : (value as DeepReadonly<T>)
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
// serve vue to the iframe sandbox during dev.
2-
// @ts-expect-error
32
export * from 'vue/dist/vue.runtime.esm-browser.prod.js'

0 commit comments

Comments
 (0)